gfs2: check sb_min_blocksize return value
authorEdward Adam Davis <eadavis@qq.com>
Sat, 12 Apr 2025 05:07:18 +0000 (13:07 +0800)
committerAndreas Gruenbacher <agruenba@redhat.com>
Mon, 21 Apr 2025 16:20:36 +0000 (18:20 +0200)
Check the return value of sb_min_blocksize(): it will be 0 when the
requested block size is invalid.

In addition, check the return value of sb_set_blocksize() as well.

Reported-by: syzbot+b0018b7468b2af33b4d5@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/ops_fstype.c

index 6ce475e1c6d64cc154777a43d8788fb286dc3b67..ea5b3c5c6e1c02840ca3d0a2e6d45710a1a02c3b 100644 (file)
@@ -489,7 +489,9 @@ static int init_sb(struct gfs2_sbd *sdp, int silent)
                       sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
                goto out;
        }
-       sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
+       ret = -EINVAL;
+       if (!sb_set_blocksize(sb, sdp->sd_sb.sb_bsize))
+               goto out;
 
        /* Get the root inode */
        no_addr = sdp->sd_sb.sb_root_dir.no_addr;
@@ -1158,6 +1160,9 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
        /* Set up the buffer cache and fill in some fake block size values
           to allow us to read-in the on-disk superblock. */
        sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, 512);
+       error = -EINVAL;
+       if (!sdp->sd_sb.sb_bsize)
+               goto fail_free;
        sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
        sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - 9;
        sdp->sd_fsb2bb = BIT(sdp->sd_fsb2bb_shift);