• Carlos Maiolino's avatar
    fs: fix guard_bio_eod to check for real EOD errors · dce30ca9
    Carlos Maiolino authored
    guard_bio_eod() can truncate a segment in bio to allow it to do IO on
    odd last sectors of a device.
    
    It already checks if the IO starts past EOD, but it does not consider
    the possibility of an IO request starting within device boundaries can
    contain more than one segment past EOD.
    
    In such cases, truncated_bytes can be bigger than PAGE_SIZE, and will
    underflow bvec->bv_len.
    
    Fix this by checking if truncated_bytes is lower than PAGE_SIZE.
    
    This situation has been found on filesystems such as isofs and vfat,
    which doesn't check the device size before mount, if the device is
    smaller than the filesystem itself, a readahead on such filesystem,
    which spans EOD, can trigger this situation, leading a call to
    zero_user() with a wrong size possibly corrupting memory.
    
    I didn't see any crash, or didn't let the system run long enough to
    check if memory corruption will be hit somewhere, but adding
    instrumentation to guard_bio_end() to check truncated_bytes size, was
    ...
    dce30ca9
buffer.c 90.2 KB