Updates to UFS/FFS superblock integrity checks when reading a superblock.

Further updates based on ways Peter Holm found to corrupt UFS
superblocks in ways that could cause kernel hangs or crashes.

No legitimate superblocks should fail as a result of these changes.

Reported by:  Peter Holm
Tested by:    Peter Holm
Sponsored by: The FreeBSD Foundation
This commit is contained in:
Kirk McKusick 2022-08-28 23:14:35 -07:00
parent 2e4da012d5
commit 9dee5da745

View File

@ -473,7 +473,6 @@ validate_sblock(struct fs *fs, int flags)
FCHK(fs->fs_fpg, <, 3 * fs->fs_frag, %jd);
FCHK(fs->fs_ncg, <, 1, %jd);
FCHK(fs->fs_ipg, <, fs->fs_inopb, %jd);
FCHK(fs->fs_ipg % fs->fs_inopb, !=, 0, %jd);
FCHK(fs->fs_ipg * fs->fs_ncg, >, (((int64_t)(1)) << 32) - INOPB(fs),
%jd);
FCHK(fs->fs_cstotal.cs_nifree, <, 0, %jd);
@ -505,6 +504,7 @@ validate_sblock(struct fs *fs, int flags)
*/
if (error)
return (error);
FCHK(fs->fs_ipg % fs->fs_inopb, !=, 0, %jd);
FCHK(fs->fs_sblkno, !=, roundup(
howmany(fs->fs_sblockloc + SBLOCKSIZE, fs->fs_fsize),
fs->fs_frag), %jd);