summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Cosgrove <tom@cvs.openbsd.org>2006-07-19 10:44:24 +0000
committerTom Cosgrove <tom@cvs.openbsd.org>2006-07-19 10:44:24 +0000
commit063db23d2e9c5d567d4138ce1e0bc6aa8bf69f1c (patch)
tree0be7e99e1d81b92cefd36523e82cf7c79391e63a
parentce038ebddedfe1e60e68d7e46b8f28529f3a8aaa (diff)
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;
}