summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortom <tom@openbsd.org>2006-07-19 10:44:23 +0000
committertom <tom@openbsd.org>2006-07-19 10:44:23 +0000
commita4168683f443e7ced4ebbafce72ed1de20b21433 (patch)
tree1778bcd58f20dc408e84a56f63d8b3165cb2e8b3
parentsd, ses, and safte do not attach to mpi, they attach to scsibus. you can (diff)
downloadwireguard-openbsd-a4168683f443e7ced4ebbafce72ed1de20b21433.tar.xz
wireguard-openbsd-a4168683f443e7ced4ebbafce72ed1de20b21433.zip
Only compare important parts of the boot block with the backup copy,
since some vendor utilities will change one without changing the other. Raised most recently by Nick Guenther; fix is similar to what is in NetBSD, but includes an idea from Steven E. Kalbach <kalbachs (at) kalbachsoft (dot) com>, posted to bugs@ over 5 years ago. ok tedu@, pedro@
-rw-r--r--sbin/fsck_msdos/boot.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/sbin/fsck_msdos/boot.c b/sbin/fsck_msdos/boot.c
index ddfa5fac2ff..3a86b1164bd 100644
--- a/sbin/fsck_msdos/boot.c
+++ b/sbin/fsck_msdos/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.11 2006/05/27 22:30:09 thib Exp $ */
+/* $OpenBSD: boot.c,v 1.12 2006/07/19 10:44:23 tom Exp $ */
/* $NetBSD: boot.c,v 1.5 1997/10/17 11:19:23 ws Exp $ */
/*
@@ -35,7 +35,7 @@
#ifndef lint
-static char rcsid[] = "$OpenBSD: boot.c,v 1.11 2006/05/27 22:30:09 thib Exp $";
+static char rcsid[] = "$OpenBSD: boot.c,v 1.12 2006/07/19 10:44:23 tom Exp $";
#endif /* not lint */
#include <stdlib.h>
@@ -156,8 +156,23 @@ readboot(int dosfs, struct bootblock *boot)
xperror("could not read backup bootblock");
return FSFATAL;
}
- if (memcmp(block, backup, DOSBOOTBLOCKSIZE)) {
- /* Correct? XXX */
+
+ /*
+ * Check that the backup boot block matches the primary one.
+ * We don't check every byte, since some vendor utilities
+ * seem to overwrite the boot code when they feel like it,
+ * without changing the backup block. Specifically, we check
+ * the two-byte signature at the end, the BIOS parameter
+ * block (which starts after the 3-byte JMP and the 8-byte
+ * OEM name/version) and the filesystem information that
+ * follows the BPB (bsPBP[53] and bsExt[26] for FAT32, so we
+ * check 79 bytes).
+ */
+ if (backup[510] != 0x55 || backup[511] != 0xaa) {
+ pfatal("Invalid signature in backup boot block: %02x%02x\n", backup[511], backup[510]);
+ return FSFATAL;
+ }
+ if (memcmp(block + 11, backup + 11, 79)) {
pfatal("backup doesn't compare to primary bootblock\n");
return FSFATAL;
}