• Brian Foster's avatar
    bcachefs: use u64 for folio end pos to avoid overflows · 6b9857b2
    Brian Foster authored
    Some of the folio_end_*() helpers are prone to overflow of signed
    64-bit types because the mapping is only limited by the max value of
    loff_t and the associated helpers return the start offset of the
    next folio. Therefore, a folio_end_pos() of the max allowable folio in a
    mapping returns a value that overflows loff_t.
    
    This makes it hard to rely on such values when doing folio
    processing across a range of a file, as bcachefs attempts to do with
    the recent folio changes. For example, generic/564 causes problems
    in the buffered write path when testing writes at max boundary
    conditions.
    
    The current understanding is that the pagecache historically limited
    the mapping to one less page to avoid this problem and this was
    dropped with some of the folio conversions, but may be reinstated to
    properly address the problem. In the meantime, update the internal
    folio_end_*() helpers in bcachefs to return a u64, and all of the
    associated code to use or cast to u64 to avoid overflow problems.
    This allows generic/564 to pass and can be reverted back to using
    loff_t if at any point the pagecache subsystem can guarantee these
    boundary conditions will not overflow.
    Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
    Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
    6b9857b2
fs-io.c 94 KB