jfs: check sb_set_blocksize() return value in jfs_fill_super()
PATCH 1/1 jfs: check sb_set_blocksize() return value in jfs_fill_super()
jfs_fill_super() does not check the return value of sb_set_blocksize(). If the block device's logical block size exceeds PAGE_SIZE, sb_set_blocksize() fails and returns 0, but jfs_fill_super() continues regardless. Subsequent sb_bread() calls then trigger a BUG() in folio_alloc_buffers() because the block size is incompatible with the folio size.
Fix by checking the return value of sb_set_blocksize() and failing the mount with -EINVAL if it returns 0.
fs/jfs/super.c +6 -2
@@ -491,8 +491,12 @@ static int jfs_fill_super(struct super_block *sb, struct fs_context *fc)/* * Initialize blocksize to 4K. */ -sb_set_blocksize (sb,PSIZE ); - +if (!sb_set_blocksize (sb,PSIZE )) { +jfs_err ("block size %lu > page size %lu not supported" , + sb->s_blocksize,PAGE_SIZE ); + ret = -EINVAL ; + goto out_unload; + }/* * Set method vectors. */
---
Quoted 7 lines · Daiki Harada
jfs_fill_super()does not check the return value ofsb_set_blocksize(). If the block device's logical block size exceedsPAGE_SIZE,sb_set_blocksize()fails and returns 0, butjfs_fill_super()continues regardless. Subsequentsb_bread()calls then trigger aBUG()infolio_alloc_buffers()because the block size is incompatible with the folio size.
Quoted 6 lines
Fix by checking the return value of
sb_set_blocksize()and failing the mount with-EINVALif it returns 0.Reported-by [email protected]Signed-off-by Daiki Harada <[email protected]>
I already have a series from Christoph in my tree that fixes all instances of this bug. Thank you for the fix though!