[PATCH] omfs: check sb_set_blocksize return value

Haotian Zhang posted 1 patch 2 months, 3 weeks ago
fs/omfs/inode.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] omfs: check sb_set_blocksize return value
Posted by Haotian Zhang 2 months, 3 weeks ago
The code validates that sbi->s_sys_blocksize does not exceed PAGE_SIZE,
but fails to verify that the block size is a power of two, which could
lead to memory corruption or system crashes.

Check the return value of sb_set_blocksize() and return -EINVAL on failure.

Fixes: 555e3775ced1 ("omfs: add inode routines")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 fs/omfs/inode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/omfs/inode.c b/fs/omfs/inode.c
index 135c49c5d848..24f58d10a93e 100644
--- a/fs/omfs/inode.c
+++ b/fs/omfs/inode.c
@@ -523,7 +523,11 @@ static int omfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	 * Use sys_blocksize as the fs block since it is smaller than a
 	 * page while the fs blocksize can be larger.
 	 */
-	sb_set_blocksize(sb, sbi->s_sys_blocksize);
+	if (!sb_set_blocksize(sb, sbi->s_sys_blocksize)) {
+		pr_err("omfs: Invalid system block size %d\n",
+				sbi->s_sys_blocksize);
+		goto out_brelse_bh;
+	}
 
 	/*
 	 * ...and the difference goes into a shift.  sys_blocksize is always
-- 
2.50.1.windows.1