HomeFreeBSD

Linux: zfs_fillpage() should handle partial pages from end of file

Description

Linux: zfs_fillpage() should handle partial pages from end of file

After 89cd2197b94986d315b9b1be707b645baf59af4f was merged, Clang's
static analyzer began complaining about a dead assignment in
zfs_fillpage(). Upon inspection, I noticed that the dead assignment
was because we are not using the calculated io_len that we should use to
avoid asking the DMU to read past the end of a file. This should result
in dmu_buf_hold_array_by_dnode() calling zfs_panic_recover().

This issue predates 89cd2197b94986d315b9b1be707b645baf59af4f, but its
simplification of zfs_fillpage() eliminated the only use of the
assignment to io_len, which made Clang's static analyzer complain about
the issue.

Also, as a precaution, we add an assertion that io_offset < i_size. If
this ever fails, bad things will happen. Otherwise, we are blindly
trusting the kernel not to give us invalid offsets. We continue to
blindly trust it on non-debug kernels.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14534

Details

Provenance
Richard Yao <richard.yao@alumni.stonybrook.edu>Authored on Mar 1 2023, 9:19 PM
Brian Behlendorf <behlendorf1@llnl.gov>Committed on Apr 21 2023, 8:12 PM
Parents
rGc7db374ac6b8: Fix buffered/direct/mmap I/O race
Branches
Unknown
Tags
Unknown

Event Timeline

Brian Behlendorf <behlendorf1@llnl.gov> committed rG4a5950a1298a: Linux: zfs_fillpage() should handle partial pages from end of file (authored by Richard Yao <richard.yao@alumni.stonybrook.edu>).Apr 21 2023, 8:12 PM