git: 95fc911fe9f2 - stable/13 - Updates to UFS/FFS superblock integrity checks when reading a superblock.

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Wed, 07 Jun 2023 23:15:41 UTC
The branch stable/13 has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=95fc911fe9f258ab9baa6b9fa1b1643f86b103b6

commit 95fc911fe9f258ab9baa6b9fa1b1643f86b103b6
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2023-06-07 23:12:12 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2023-06-07 23:12:12 +0000

    Updates to UFS/FFS superblock integrity checks when reading a superblock.
    
    Reported-by:  Robert Morris
    PR:           271351
    Sponsored-by: The FreeBSD Foundation
    
    (cherry picked from commit c79a1416955a260424a5dd2013b114ff864bc926)
---
 sys/ufs/ffs/ffs_subr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c
index 4ba452b05ec9..813736c9d070 100644
--- a/sys/ufs/ffs/ffs_subr.c
+++ b/sys/ufs/ffs/ffs_subr.c
@@ -505,7 +505,8 @@ validate_sblock(struct fs *fs, int isaltsblk)
 	CHK(fs->fs_csaddr, <, 0, %jd);
 	CHK(fs->fs_cssize, !=,
 	    fragroundup(fs, fs->fs_ncg * sizeof(struct csum)), %jd);
-	CHK(dtog(fs, fs->fs_csaddr), >, fs->fs_ncg, %jd);
+	CHK(fs->fs_csaddr + howmany(fs->fs_cssize, fs->fs_fsize), >,
+	    fs->fs_size, %jd);
 	CHK(fs->fs_csaddr, <, cgdmin(fs, dtog(fs, fs->fs_csaddr)), %jd);
 	CHK(dtog(fs, fs->fs_csaddr + howmany(fs->fs_cssize, fs->fs_fsize)), >,
 	    dtog(fs, fs->fs_csaddr), %jd);