fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable
PATCH 1/1 fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable
Since [1], it is possible for filesystems to have blocksize > PAGE_SIZE of the system.
Remove the assumption and make the check generic for all blocksizes in generic_check_addressable().
[1] https://lore.kernel.org/linux-xfs/[email protected]/
--- fs/libfs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fs/libfs.c +7 -3
@@ -1584,13 +1584,17 @@ EXPORT_SYMBOL(generic_file_fsync);int generic_check_addressable (unsigned blocksize_bits,u64 num_blocks) {u64 last_fs_block = num_blocks -1 ; -u64 last_fs_page = - last_fs_block >> (PAGE_SHIFT - blocksize_bits); +u64 last_fs_page, max_bytes; + +if (check_shl_overflow (num_blocks, blocksize_bits, &max_bytes)) +return -EFBIG ; + + last_fs_page = (max_bytes >>PAGE_SHIFT ) -1 ;if (unlikely (num_blocks ==0 ))return 0 ; -if ((blocksize_bits <9 ) || (blocksize_bits >PAGE_SHIFT )) +if ((blocksize_bits <9 ))return -EINVAL ; if ((last_fs_block > (sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
base-commit: b39f7d75dc41b5f5d028192cd5d66cff71179f35
Signature · 1 line
2.49.0
Quoted 9 lines · Pankaj Raghav
Since [1], it is possible for filesystems to have blocksize >
PAGE_SIZEof the system.Remove the assumption and make the check generic for all blocksizes in
generic_check_addressable().[1] https://lore.kernel.org/linux-xfs/[email protected]/
Signed-off-by Pankaj Raghav <[email protected]>
Looks good. Feel free to add:
One style nit below:
Quoted 12 lines
fs/libfs.c +2
-2@@ -1584,13 +1584,17 @@ EXPORT_SYMBOL(generic_file_fsync);int generic_check_addressable (unsigned blocksize_bits,u64 num_blocks) {u64 last_fs_block = num_blocks -1 ; -u64 last_fs_page = - last_fs_block >> (PAGE_SHIFT - blocksize_bits); +u64 last_fs_page, max_bytes; +
fs/libfs.c EXPORT_SYMBOL(generic_file_fsync); · line 1597
Quoted 10 lines
fs/libfs.c +5
-1+if (check_shl_overflow (num_blocks, blocksize_bits, &max_bytes)) +return -EFBIG ; + + last_fs_page = (max_bytes >>PAGE_SHIFT ) -1 ;if (unlikely (num_blocks ==0 ))return 0 ; -if ((blocksize_bits <9 ) || (blocksize_bits >PAGE_SHIFT )) +if ((blocksize_bits <9 ))
^ extra parentheses here
fs/libfs.c EXPORT_SYMBOL(generic_file_fsync); · line 1600
Quoted 4 lines
fs/libfs.c +0
-0return -EINVAL ; if ((last_fs_block > (sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR