Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: sysv: check sbi->s_firstdatazone in complete_read_super

sbi->s_firstinodezone is initialized to 2 and sbi->s_firstdatazone is read
from sbd. There's no guarantee that sbi->s_firstdatazone must bigger than
sbi->s_firstinodezone. If sbi->s_firstdatazone less than 2, the
filesystem can still be mounted unexpetly. At this point, sbi->s_ninodes
flip to very large value and this filesystem is broken. We can observe
this by executing 'df' command. When we execute, we will get an error
message:

"sysv_count_free_inodes: unable to read inode table"

Link: https://lkml.kernel.org/r/20220330104215.530223-1-liushixin2@huawei.com
Signed-off-by: Liu Shixin <liushixin2@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Liu Shixin and committed by
akpm
f6e2c20c edc73c72

+3 -1
+3 -1
fs/sysv/super.c
··· 312 312 sbi->s_firstinodezone = 2; 313 313 314 314 flavour_setup[sbi->s_type](sbi, &sb->s_max_links); 315 - 315 + if (sbi->s_firstdatazone < sbi->s_firstinodezone) 316 + return 0; 317 + 316 318 sbi->s_ndatazones = sbi->s_nzones - sbi->s_firstdatazone; 317 319 sbi->s_inodes_per_block = bsize >> 6; 318 320 sbi->s_inodes_per_block_1 = (bsize >> 6)-1;