* [PATCH v2] fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable
@ 2025-06-30 10:40 Pankaj Raghav
2025-06-30 11:38 ` Baokun Li
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Pankaj Raghav @ 2025-06-30 10:40 UTC (permalink / raw)
To: Alexander Viro, Jan Kara, mcgrof, Christian Brauner
Cc: Baokun Li, linux-kernel, kernel, Zhang Yi, linux-fsdevel,
gost.dev, Pankaj Raghav
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/20240822135018.1931258-1-kernel@pankajraghav.com/
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
Changes since v1:
- Removed the unnecessary parantheses.
- Added RVB from Jan Kara (Thanks).
fs/libfs.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/libfs.c b/fs/libfs.c
index 4d1862f589e8..f99ecc300647 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -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
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable
2025-06-30 10:40 [PATCH v2] fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable Pankaj Raghav
@ 2025-06-30 11:38 ` Baokun Li
2025-06-30 11:57 ` Zhang Yi
2025-07-01 11:57 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Baokun Li @ 2025-06-30 11:38 UTC (permalink / raw)
To: Pankaj Raghav
Cc: Christian Brauner, mcgrof, Jan Kara, Alexander Viro, linux-kernel,
kernel, Zhang Yi, linux-fsdevel, gost.dev, Yang Erkun
On 2025/6/30 18:40, Pankaj Raghav wrote:
> 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/20240822135018.1931258-1-kernel@pankajraghav.com/
>
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Looks good. Feel free to add:
Reviewed-by: Baokun Li <libaokun1@huawei.com>
> ---
> Changes since v1:
> - Removed the unnecessary parantheses.
> - Added RVB from Jan Kara (Thanks).
>
> fs/libfs.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/fs/libfs.c b/fs/libfs.c
> index 4d1862f589e8..f99ecc300647 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable
2025-06-30 10:40 [PATCH v2] fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable Pankaj Raghav
2025-06-30 11:38 ` Baokun Li
@ 2025-06-30 11:57 ` Zhang Yi
2025-07-01 11:57 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Zhang Yi @ 2025-06-30 11:57 UTC (permalink / raw)
To: Pankaj Raghav
Cc: Baokun Li, linux-kernel, kernel, linux-fsdevel, gost.dev,
Alexander Viro, Jan Kara, mcgrof, Christian Brauner
On 2025/6/30 18:40, Pankaj Raghav wrote:
> 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/20240822135018.1931258-1-kernel@pankajraghav.com/
>
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Looks good to me.
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
> ---
> Changes since v1:
> - Removed the unnecessary parantheses.
> - Added RVB from Jan Kara (Thanks).
>
> fs/libfs.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/fs/libfs.c b/fs/libfs.c
> index 4d1862f589e8..f99ecc300647 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable
2025-06-30 10:40 [PATCH v2] fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable Pankaj Raghav
2025-06-30 11:38 ` Baokun Li
2025-06-30 11:57 ` Zhang Yi
@ 2025-07-01 11:57 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2025-07-01 11:57 UTC (permalink / raw)
To: Pankaj Raghav
Cc: Christian Brauner, Baokun Li, linux-kernel, kernel, Zhang Yi,
linux-fsdevel, gost.dev, Alexander Viro, Jan Kara, mcgrof
On Mon, 30 Jun 2025 12:40:18 +0200, Pankaj Raghav wrote:
> 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/20240822135018.1931258-1-kernel@pankajraghav.com/
>
> [...]
Applied to the vfs-6.17.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.17.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.17.misc
[1/1] fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable
https://git.kernel.org/vfs/vfs/c/c2d3651387f8
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-01 11:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-30 10:40 [PATCH v2] fs/libfs: don't assume blocksize <= PAGE_SIZE in generic_check_addressable Pankaj Raghav
2025-06-30 11:38 ` Baokun Li
2025-06-30 11:57 ` Zhang Yi
2025-07-01 11:57 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).