• Alex Williamson's avatar
    vfio/iommu_type1: Avoid overflow · c8dbca16
    Alex Williamson authored
    Coverity reports use of a tained scalar used as a loop boundary.
    For the most part, any values passed from userspace for a DMA mapping
    size, IOVA, or virtual address are valid, with some alignment
    constraints.  The size is ultimately bound by how many pages the user
    is able to lock, IOVA is tested by the IOMMU driver when doing a map,
    and the virtual address needs to pass get_user_pages.  The only
    problem I can find is that we do expect the __u64 user values to fit
    within our variables, which might not happen on 32bit platforms.  Add
    a test for this and return error on overflow.  Also propagate use of
    the type-correct local variables throughout the function.
    
    The above also points to the 'end' variable, which can be zero if
    we're operating at the very top of the address space.  We try to
    account for this, but our loop botches it.  Rework the loop to use
    the remaining size as our loop condition rather than the IOVA vs end.
    
    Detected by Coverity: CID 714659
    Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
    c8dbca16
vfio_iommu_type1.c 24.2 KB