Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Jun 2025 19:54:03 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 8ba7ac5a15e7 - stable/14 - makefs: Ensure that FFS superblocks are reproducible
Message-ID:  <202506011954.551Js3Ww046153@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=8ba7ac5a15e7b5276c6b75934bb604ff5c98ce67

commit 8ba7ac5a15e7b5276c6b75934bb604ff5c98ce67
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-05-08 15:49:53 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-06-01 19:53:29 +0000

    makefs: Ensure that FFS superblocks are reproducible
    
    The superblock structure has space reserved for a pointer to an
    in-memory structure that gets created at mount time.  makefs populates
    it since that simplifies code elsewhere.  However, the pointer value
    ends up in the output file, which breaks reproducibility.
    
    Zero the field when writing the superblock instead, as its on-disk value
    is ignored.
    
    Reviewed by:    emaste
    MFC after:      2 weeks
    Sponsored by:   Klara, Inc.
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D50196
    
    (cherry picked from commit 764ccf410c3c5453c4656113d75cd81fcf01828d)
---
 usr.sbin/makefs/ffs/mkfs.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c
index b579565b6a01..fd7b24a1a6fb 100644
--- a/usr.sbin/makefs/ffs/mkfs.c
+++ b/usr.sbin/makefs/ffs/mkfs.c
@@ -580,13 +580,21 @@ ffs_write_superblock(struct fs *fs, const fsinfo_t *fsopts)
 {
 	int size, blks, i, saveflag;
 	uint32_t cylno;
-	void *space;
+	void *info, *space;
 	char *wrbuf;
 
 	saveflag = fs->fs_flags & FS_INTERNAL;
 	fs->fs_flags &= ~FS_INTERNAL;
 
-        memcpy(writebuf, &sblock, sbsize);
+	/*
+	 * Write out the superblock.  Blank out the summary info field, as it's
+	 * a random pointer that would make the resulting image unreproducible.
+	 */
+	info = fs->fs_si;
+	fs->fs_si = NULL;
+	memcpy(writebuf, fs, sbsize);
+	fs->fs_si = info;
+
 	if (fsopts->needswap)
 		ffs_sb_swap(fs, (struct fs*)writebuf);
 	ffs_wtfs(fs->fs_sblockloc / sectorsize, sbsize, writebuf, fsopts);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202506011954.551Js3Ww046153>