public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize()
@ 2025-03-05  1:53 Luis Chamberlain
  2025-03-05  6:04 ` Matthew Wilcox
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Luis Chamberlain @ 2025-03-05  1:53 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() can
happen in-kernel given mkfs utilities *can* create for example an
ext4 32k block size filesystem on x86_64, the issue we want to prevent
is mounting it on x86_64 unless the filesystem supports LBS.

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 linux-next, so just do the easier thing and bring back
the PAGE_SIZE check for sb_set_blocksize() users.

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>
---

Christian, a small fixup for a crash when running generic/466 on ext4
in a loop. The issue is obvious, and we just need to ensure we don't
break old filesystem expectations of sb_set_blocksize().

This still allows XFS with 32k block size and I even tested with XFS
with 32k block size and a 32k sector size set.

 block/bdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/bdev.c b/block/bdev.c
index 3bd948e6438d..de9ebc3e5d15 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -181,7 +181,7 @@ EXPORT_SYMBOL(set_blocksize);
 
 int sb_set_blocksize(struct super_block *sb, int size)
 {
-	if (set_blocksize(sb->s_bdev_file, size))
+	if (size > PAGE_SIZE || set_blocksize(sb->s_bdev_file, size))
 		return 0;
 	/* If we get here, we know size is validated */
 	sb->s_blocksize = size;
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-03-07  1:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-05  1:53 [PATCH] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize() Luis Chamberlain
2025-03-05  6:04 ` Matthew Wilcox
2025-03-05  6:33   ` Darrick J. Wong
2025-03-05 14:15     ` Matthew Wilcox
2025-03-05 17:04       ` [PATCH] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize()' Luis Chamberlain
2025-03-05 18:48         ` Darrick J. Wong
2025-03-05 19:55           ` Luis Chamberlain
2025-03-05  7:18 ` [PATCH] bdev: add back PAGE_SIZE block size validation for sb_set_blocksize() Hannes Reinecke
2025-03-05 17:05   ` Luis Chamberlain
2025-03-06 18:39 ` Kent Overstreet
2025-03-07  0:45   ` Luis Chamberlain
2025-03-07  1:43     ` Kent Overstreet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox