git: 9dee5da7450e - main - Updates to UFS/FFS superblock integrity checks when reading a superblock.

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Mon, 29 Aug 2022 06:15:23 UTC
The branch main has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=9dee5da7450e8530c9fec51c9a16ecd42da78e55

commit 9dee5da7450e8530c9fec51c9a16ecd42da78e55
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2022-08-29 06:14:35 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2022-08-29 06:14:35 +0000

    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
---
 sys/ufs/ffs/ffs_subr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c
index f6c27cb38d62..b71ebf2a0617 100644
--- a/sys/ufs/ffs/ffs_subr.c
+++ b/sys/ufs/ffs/ffs_subr.c
@@ -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);