Module Name: src
Committed By: christos
Date: Wed Feb 8 04:08:53 UTC 2017
Modified Files:
src/usr.sbin/makefs/ffs: mkfs.c
Log Message:
Don't store random (from ASLR) pointers into the superblock. Should be the
last (famous last words) problem with reproducible builds!
To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.sbin/makefs/ffs/mkfs.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/makefs/ffs/mkfs.c
diff -u src/usr.sbin/makefs/ffs/mkfs.c:1.34 src/usr.sbin/makefs/ffs/mkfs.c:1.35
--- src/usr.sbin/makefs/ffs/mkfs.c:1.34 Fri Jun 24 15:24:11 2016
+++ src/usr.sbin/makefs/ffs/mkfs.c Tue Feb 7 23:08:53 2017
@@ -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 @@ union {
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 sbsize; /* superblock
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 @@ ffs_mkfs(const char *fsys, const fsinfo_
* 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 @@ ffs_write_superblock(struct fs *fs, cons
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 */