git: 82ee4e1c42d7 - main - Updates to UFS/FFS superblock integrity checks when reading a superblock.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 03 Sep 2022 21:11:45 UTC
The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=82ee4e1c42d70345cbaa1f6dd1874ae98a004910 commit 82ee4e1c42d70345cbaa1f6dd1874ae98a004910 Author: Kirk McKusick <mckusick@FreeBSD.org> AuthorDate: 2022-09-03 21:08:25 +0000 Commit: Kirk McKusick <mckusick@FreeBSD.org> CommitDate: 2022-09-03 21:11:38 +0000 Updates to UFS/FFS superblock integrity checks when reading a superblock. Yet more 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 --- sys/ufs/ffs/ffs_subr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c index b71ebf2a0617..4ffe0412ff69 100644 --- a/sys/ufs/ffs/ffs_subr.c +++ b/sys/ufs/ffs/ffs_subr.c @@ -396,9 +396,6 @@ validate_sblock(struct fs *fs, int flags) FCHK(fs->fs_sblockloc, <, 0, %jd); FCHK(fs->fs_sblockloc, >, SBLOCK_UFS1, %jd); } - FCHK(fs->fs_sbsize, >, SBLOCKSIZE, %jd); - FCHK(fs->fs_sbsize, <, (signed)sizeof(struct fs), %jd); - FCHK(fs->fs_sbsize % fs->fs_fsize, !=, 0, %jd); FCHK(fs->fs_frag, <, 1, %jd); FCHK(fs->fs_frag, >, MAXFRAG, %jd); FCHK(fs->fs_bsize, <, MINBSIZE, %jd); @@ -408,6 +405,9 @@ validate_sblock(struct fs *fs, int flags) FCHK(fs->fs_fsize, <, sectorsize, %jd); FCHK(fs->fs_fsize * fs->fs_frag, !=, fs->fs_bsize, %jd); FCHK(powerof2(fs->fs_fsize), ==, 0, %jd); + FCHK(fs->fs_sbsize, >, SBLOCKSIZE, %jd); + FCHK(fs->fs_sbsize, <, (signed)sizeof(struct fs), %jd); + FCHK(fs->fs_sbsize % fs->fs_fsize, !=, 0, %jd); FCHK(fs->fs_fpg, <, 3 * fs->fs_frag, %jd); FCHK(fs->fs_ncg, <, 1, %jd); FCHK(fs->fs_fsbtodb, !=, ILOG2(fs->fs_fsize / sectorsize), %jd); @@ -482,7 +482,6 @@ validate_sblock(struct fs *fs, int flags) (fs->fs_ipg * fs->fs_ncg) - fs->fs_cstotal.cs_nifree, %jd); FCHK(fs->fs_sbsize, >, SBLOCKSIZE, %jd); FCHK(fs->fs_sbsize, <, (signed)sizeof(struct fs), %jd); - FCHK(fs->fs_sbsize % fs->fs_fsize, !=, 0, %jd); FCHK(fs->fs_maxbsize, <, fs->fs_bsize, %jd); FCHK(powerof2(fs->fs_maxbsize), ==, 0, %jd); FCHK(fs->fs_maxbsize, >, FS_MAXCONTIG * fs->fs_bsize, %jd); @@ -504,6 +503,7 @@ validate_sblock(struct fs *fs, int flags) */ if (error) return (error); + FCHK(fs->fs_sbsize % fs->fs_fsize, !=, 0, %jd); FCHK(fs->fs_ipg % fs->fs_inopb, !=, 0, %jd); FCHK(fs->fs_sblkno, !=, roundup( howmany(fs->fs_sblockloc + SBLOCKSIZE, fs->fs_fsize),