Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/makefs/ffs Don't store random (from ASLR) pointers ...



details:   https://anonhg.NetBSD.org/src/rev/6de1fd7593f6
branches:  trunk
changeset: 821488:6de1fd7593f6
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Feb 08 04:08:53 2017 +0000

description:
Don't store random (from ASLR) pointers into the superblock. Should be the
last (famous last words) problem with reproducible builds!

diffstat:

 usr.sbin/makefs/ffs/mkfs.c |  29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

diffs (71 lines):

diff -r ed2c9dd8a27e -r 6de1fd7593f6 usr.sbin/makefs/ffs/mkfs.c
--- a/usr.sbin/makefs/ffs/mkfs.c        Wed Feb 08 04:05:13 2017 +0000
+++ b/usr.sbin/makefs/ffs/mkfs.c        Wed Feb 08 04:08:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkfs.c,v 1.34 2016/06/24 19:24:11 christos Exp $       */
+/*     $NetBSD: mkfs.c,v 1.35 2017/02/08 04:08:53 christos Exp $       */
 
 /*
  * Copyright (c) 2002 Networks Associates Technology, Inc.
@@ -48,7 +48,7 @@
 static char sccsid[] = "@(#)mkfs.c     8.11 (Berkeley) 5/3/95";
 #else
 #ifdef __RCSID
-__RCSID("$NetBSD: mkfs.c,v 1.34 2016/06/24 19:24:11 christos Exp $");
+__RCSID("$NetBSD: mkfs.c,v 1.35 2017/02/08 04:08:53 christos Exp $");
 #endif
 #endif
 #endif /* not lint */
@@ -102,7 +102,11 @@
 char *iobuf;
 int iobufsize;
 
-char writebuf[FFS_MAXBSIZE];
+union {
+       struct fs fs;
+       char pad[FFS_MAXBSIZE];
+} wb;
+#define writebuf wb.pad
 
 static int     Oflag;     /* format as an 4.3BSD file system */
 static int64_t fssize;    /* file system size */
@@ -121,6 +125,17 @@
 static int     avgfilesize;       /* expected average file size */
 static int     avgfpdir;          /* expected number of files per directory */
 
+static void
+ffs_sb_copy(struct fs *o, const struct fs *i, size_t l, fsinfo_t *fsopts)
+{
+       memcpy(o, i, l);
+       /* Zero out pointers */
+       o->fs_csp = NULL;
+       o->fs_maxcluster = NULL;
+       if (fsopts->needswap)
+               ffs_sb_swap(i, o);
+}
+
 struct fs *
 ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp)
 {
@@ -508,9 +523,7 @@
         * Make a copy of the superblock into the buffer that we will be
         * writing out in each cylinder group.
         */
-       memcpy(writebuf, &sblock, sbsize);
-       if (fsopts->needswap)
-               ffs_sb_swap(&sblock, (struct fs*)writebuf);
+       ffs_sb_copy(&wb.fs, &sblock, sbsize, fsopts);
        memcpy(iobuf, writebuf, SBLOCKSIZE);
 
        printf("super-block backups (for fsck -b #) at:");
@@ -555,9 +568,7 @@
        saveflag = fs->fs_flags & FS_INTERNAL;
        fs->fs_flags &= ~FS_INTERNAL;
 
-        memcpy(writebuf, &sblock, sbsize);
-       if (fsopts->needswap)
-               ffs_sb_swap(fs, (struct fs*)writebuf);
+       ffs_sb_copy(&wb.fs, &sblock, sbsize, fsopts);
        ffs_wtfs(fs->fs_sblockloc / sectorsize, sbsize, writebuf, fsopts);
 
        /* Write out the duplicate super blocks */



Home | Main Index | Thread Index | Old Index