Skip to content

Commit

Permalink
fs: sysv: check sbi->s_firstdatazone in complete_read_super
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: Liu Shixin <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Liu Shixin authored and akpm00 committed Apr 29, 2022
1 parent edc73c7 commit f6e2c20
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/sysv/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ static int complete_read_super(struct super_block *sb, int silent, int size)
sbi->s_firstinodezone = 2;

flavour_setup[sbi->s_type](sbi, &sb->s_max_links);

if (sbi->s_firstdatazone < sbi->s_firstinodezone)
return 0;

sbi->s_ndatazones = sbi->s_nzones - sbi->s_firstdatazone;
sbi->s_inodes_per_block = bsize >> 6;
sbi->s_inodes_per_block_1 = (bsize >> 6)-1;
Expand Down

0 comments on commit f6e2c20

Please sign in to comment.