* [PATCH v2] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize()
@ 2025-03-07 2:04 Luis Chamberlain
2025-03-07 4:04 ` Darrick J. Wong
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Luis Chamberlain @ 2025-03-07 2:04 UTC (permalink / raw)
To: brauner, hare, willy, david, djwong
Cc: kbusch, john.g.garry, hch, ritesh.list, linux-fsdevel,
linux-block, gost.dev, p.raghav, da.gomez, kernel, mcgrof,
Kent Overstreet
The commit titled "block/bdev: lift block size restrictions to 64k"
lifted the block layer's max supported block size to 64k inside the
helper blk_validate_block_size() now that we support large folios.
However in lifting the block size we also removed the silly use
cases many filesystems have to use sb_set_blocksize() to *verify*
that the block size <= PAGE_SIZE. The call to sb_set_blocksize() was
used to check the block size <= PAGE_SIZE since historically we've
always supported userspace to create for example 64k block size
filesystems even on 4k page size systems, but what we didn't allow
was mounting them. Older filesystems have been using the check with
sb_set_blocksize() for years.
While, we could argue that such checks should be filesystem specific,
there are much more users of sb_set_blocksize() than LBS enabled
filesystem on upstream, so just do the easier thing and bring back
the PAGE_SIZE check for sb_set_blocksize() users and only skip it
for LBS enabled filesystems.
This will ensure that tests such as generic/466 when run in a loop
against say, ext4, won't try to try to actually mount a filesystem with
a block size larger than your filesystem supports given your PAGE_SIZE
and in the worst case crash.
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
block/bdev.c | 2 ++
fs/bcachefs/fs.c | 2 +-
fs/xfs/xfs_super.c | 3 ++-
include/linux/fs.h | 1 +
4 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index 3bd948e6438d..4844d1e27b6f 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -181,6 +181,8 @@ EXPORT_SYMBOL(set_blocksize);
int sb_set_blocksize(struct super_block *sb, int size)
{
+ if (!(sb->s_type->fs_flags & FS_LBS) && size > PAGE_SIZE)
+ return 0;
if (set_blocksize(sb->s_bdev_file, size))
return 0;
/* If we get here, we know size is validated */
diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
index 8b3be33a1f7a..8624b3b1601f 100644
--- a/fs/bcachefs/fs.c
+++ b/fs/bcachefs/fs.c
@@ -2414,7 +2414,7 @@ static struct file_system_type bcache_fs_type = {
.name = "bcachefs",
.init_fs_context = bch2_init_fs_context,
.kill_sb = bch2_kill_sb,
- .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
+ .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_LBS,
};
MODULE_ALIAS_FS("bcachefs");
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 37898f89b3ea..54a353f52ffb 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -2134,7 +2134,8 @@ static struct file_system_type xfs_fs_type = {
.init_fs_context = xfs_init_fs_context,
.parameters = xfs_fs_parameters,
.kill_sb = xfs_kill_sb,
- .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME,
+ .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME |
+ FS_LBS,
};
MODULE_ALIAS_FS("xfs");
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 110d95d04299..62440a9383dc 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2614,6 +2614,7 @@ struct file_system_type {
#define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */
#define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */
#define FS_MGTIME 64 /* FS uses multigrain timestamps */
+#define FS_LBS 128 /* FS supports LBS */
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
int (*init_fs_context)(struct fs_context *);
const struct fs_parameter_spec *parameters;
--
2.47.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize()
2025-03-07 2:04 [PATCH v2] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize() Luis Chamberlain
@ 2025-03-07 4:04 ` Darrick J. Wong
2025-03-07 11:52 ` Kent Overstreet
2025-03-07 11:56 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2025-03-07 4:04 UTC (permalink / raw)
To: Luis Chamberlain
Cc: brauner, hare, willy, david, kbusch, john.g.garry, hch,
ritesh.list, linux-fsdevel, linux-block, gost.dev, p.raghav,
da.gomez, kernel, Kent Overstreet
On Thu, Mar 06, 2025 at 06:04:03PM -0800, Luis Chamberlain wrote:
> The commit titled "block/bdev: lift block size restrictions to 64k"
> lifted the block layer's max supported block size to 64k inside the
> helper blk_validate_block_size() now that we support large folios.
> However in lifting the block size we also removed the silly use
> cases many filesystems have to use sb_set_blocksize() to *verify*
> that the block size <= PAGE_SIZE. The call to sb_set_blocksize() was
> used to check the block size <= PAGE_SIZE since historically we've
> always supported userspace to create for example 64k block size
> filesystems even on 4k page size systems, but what we didn't allow
> was mounting them. Older filesystems have been using the check with
> sb_set_blocksize() for years.
>
> While, we could argue that such checks should be filesystem specific,
> there are much more users of sb_set_blocksize() than LBS enabled
> filesystem on upstream, so just do the easier thing and bring back
> the PAGE_SIZE check for sb_set_blocksize() users and only skip it
> for LBS enabled filesystems.
>
> This will ensure that tests such as generic/466 when run in a loop
> against say, ext4, won't try to try to actually mount a filesystem with
> a block size larger than your filesystem supports given your PAGE_SIZE
> and in the worst case crash.
>
> Cc: Kent Overstreet <kent.overstreet@linux.dev>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Looks good to me! Now we can support sector size > 32K XFS.
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> block/bdev.c | 2 ++
> fs/bcachefs/fs.c | 2 +-
> fs/xfs/xfs_super.c | 3 ++-
> include/linux/fs.h | 1 +
> 4 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/block/bdev.c b/block/bdev.c
> index 3bd948e6438d..4844d1e27b6f 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -181,6 +181,8 @@ EXPORT_SYMBOL(set_blocksize);
>
> int sb_set_blocksize(struct super_block *sb, int size)
> {
> + if (!(sb->s_type->fs_flags & FS_LBS) && size > PAGE_SIZE)
> + return 0;
> if (set_blocksize(sb->s_bdev_file, size))
> return 0;
> /* If we get here, we know size is validated */
> diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
> index 8b3be33a1f7a..8624b3b1601f 100644
> --- a/fs/bcachefs/fs.c
> +++ b/fs/bcachefs/fs.c
> @@ -2414,7 +2414,7 @@ static struct file_system_type bcache_fs_type = {
> .name = "bcachefs",
> .init_fs_context = bch2_init_fs_context,
> .kill_sb = bch2_kill_sb,
> - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
> + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_LBS,
> };
>
> MODULE_ALIAS_FS("bcachefs");
> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> index 37898f89b3ea..54a353f52ffb 100644
> --- a/fs/xfs/xfs_super.c
> +++ b/fs/xfs/xfs_super.c
> @@ -2134,7 +2134,8 @@ static struct file_system_type xfs_fs_type = {
> .init_fs_context = xfs_init_fs_context,
> .parameters = xfs_fs_parameters,
> .kill_sb = xfs_kill_sb,
> - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME,
> + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME |
> + FS_LBS,
> };
> MODULE_ALIAS_FS("xfs");
>
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 110d95d04299..62440a9383dc 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2614,6 +2614,7 @@ struct file_system_type {
> #define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */
> #define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */
> #define FS_MGTIME 64 /* FS uses multigrain timestamps */
> +#define FS_LBS 128 /* FS supports LBS */
> #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
> int (*init_fs_context)(struct fs_context *);
> const struct fs_parameter_spec *parameters;
> --
> 2.47.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize()
2025-03-07 2:04 [PATCH v2] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize() Luis Chamberlain
2025-03-07 4:04 ` Darrick J. Wong
@ 2025-03-07 11:52 ` Kent Overstreet
2025-03-07 11:56 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Kent Overstreet @ 2025-03-07 11:52 UTC (permalink / raw)
To: Luis Chamberlain
Cc: brauner, hare, willy, david, djwong, kbusch, john.g.garry, hch,
ritesh.list, linux-fsdevel, linux-block, gost.dev, p.raghav,
da.gomez, kernel
On Thu, Mar 06, 2025 at 06:04:03PM -0800, Luis Chamberlain wrote:
> The commit titled "block/bdev: lift block size restrictions to 64k"
> lifted the block layer's max supported block size to 64k inside the
> helper blk_validate_block_size() now that we support large folios.
> However in lifting the block size we also removed the silly use
> cases many filesystems have to use sb_set_blocksize() to *verify*
> that the block size <= PAGE_SIZE. The call to sb_set_blocksize() was
> used to check the block size <= PAGE_SIZE since historically we've
> always supported userspace to create for example 64k block size
> filesystems even on 4k page size systems, but what we didn't allow
> was mounting them. Older filesystems have been using the check with
> sb_set_blocksize() for years.
>
> While, we could argue that such checks should be filesystem specific,
> there are much more users of sb_set_blocksize() than LBS enabled
> filesystem on upstream, so just do the easier thing and bring back
> the PAGE_SIZE check for sb_set_blocksize() users and only skip it
> for LBS enabled filesystems.
>
> This will ensure that tests such as generic/466 when run in a loop
> against say, ext4, won't try to try to actually mount a filesystem with
> a block size larger than your filesystem supports given your PAGE_SIZE
> and in the worst case crash.
>
> Cc: Kent Overstreet <kent.overstreet@linux.dev>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Kent Overstreet <kent.overstreet@linux.dev>
> ---
> block/bdev.c | 2 ++
> fs/bcachefs/fs.c | 2 +-
> fs/xfs/xfs_super.c | 3 ++-
> include/linux/fs.h | 1 +
> 4 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/block/bdev.c b/block/bdev.c
> index 3bd948e6438d..4844d1e27b6f 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -181,6 +181,8 @@ EXPORT_SYMBOL(set_blocksize);
>
> int sb_set_blocksize(struct super_block *sb, int size)
> {
> + if (!(sb->s_type->fs_flags & FS_LBS) && size > PAGE_SIZE)
> + return 0;
> if (set_blocksize(sb->s_bdev_file, size))
> return 0;
> /* If we get here, we know size is validated */
> diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
> index 8b3be33a1f7a..8624b3b1601f 100644
> --- a/fs/bcachefs/fs.c
> +++ b/fs/bcachefs/fs.c
> @@ -2414,7 +2414,7 @@ static struct file_system_type bcache_fs_type = {
> .name = "bcachefs",
> .init_fs_context = bch2_init_fs_context,
> .kill_sb = bch2_kill_sb,
> - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
> + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_LBS,
> };
>
> MODULE_ALIAS_FS("bcachefs");
> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> index 37898f89b3ea..54a353f52ffb 100644
> --- a/fs/xfs/xfs_super.c
> +++ b/fs/xfs/xfs_super.c
> @@ -2134,7 +2134,8 @@ static struct file_system_type xfs_fs_type = {
> .init_fs_context = xfs_init_fs_context,
> .parameters = xfs_fs_parameters,
> .kill_sb = xfs_kill_sb,
> - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME,
> + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME |
> + FS_LBS,
> };
> MODULE_ALIAS_FS("xfs");
>
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 110d95d04299..62440a9383dc 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2614,6 +2614,7 @@ struct file_system_type {
> #define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */
> #define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */
> #define FS_MGTIME 64 /* FS uses multigrain timestamps */
> +#define FS_LBS 128 /* FS supports LBS */
> #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
> int (*init_fs_context)(struct fs_context *);
> const struct fs_parameter_spec *parameters;
> --
> 2.47.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize()
2025-03-07 2:04 [PATCH v2] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize() Luis Chamberlain
2025-03-07 4:04 ` Darrick J. Wong
2025-03-07 11:52 ` Kent Overstreet
@ 2025-03-07 11:56 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2025-03-07 11:56 UTC (permalink / raw)
To: Luis Chamberlain
Cc: Christian Brauner, kbusch, john.g.garry, hch, ritesh.list,
linux-fsdevel, linux-block, gost.dev, p.raghav, da.gomez, kernel,
Kent Overstreet, hare, willy, david, djwong
On Thu, 06 Mar 2025 18:04:03 -0800, Luis Chamberlain wrote:
> The commit titled "block/bdev: lift block size restrictions to 64k"
> lifted the block layer's max supported block size to 64k inside the
> helper blk_validate_block_size() now that we support large folios.
> However in lifting the block size we also removed the silly use
> cases many filesystems have to use sb_set_blocksize() to *verify*
> that the block size <= PAGE_SIZE. The call to sb_set_blocksize() was
> used to check the block size <= PAGE_SIZE since historically we've
> always supported userspace to create for example 64k block size
> filesystems even on 4k page size systems, but what we didn't allow
> was mounting them. Older filesystems have been using the check with
> sb_set_blocksize() for years.
>
> [...]
Applied to the vfs-6.15.pagesize branch of the vfs/vfs.git tree.
Patches in the vfs-6.15.pagesize 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.15.pagesize
[1/1] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize()
https://git.kernel.org/vfs/vfs/c/a64e5a596067
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-07 11:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-07 2:04 [PATCH v2] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize() Luis Chamberlain
2025-03-07 4:04 ` Darrick J. Wong
2025-03-07 11:52 ` Kent Overstreet
2025-03-07 11:56 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox