summaryrefslogtreecommitdiffstats
path: root/usr.sbin/installboot
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2018-11-25 17:34:37 +0000
committerkrw <krw@openbsd.org>2018-11-25 17:34:37 +0000
commit7c13e1b985ec35e46506ec840de78715226cd633 (patch)
treee9bf9e5069e971186ccc4a4da3dc2e88a42ac817 /usr.sbin/installboot
parentfix mail.mda so it handles system() exit value correctly (diff)
downloadwireguard-openbsd-7c13e1b985ec35e46506ec840de78715226cd633.tar.xz
wireguard-openbsd-7c13e1b985ec35e46506ec840de78715226cd633.zip
Don't allow the bootstrap to overlap the start of the OpenBSD area of
the disk. Even if the OpenBSD area starts with FS_UNUSED or FS_BOOT partitions. ok deraadt@ as part of larger diff
Diffstat (limited to 'usr.sbin/installboot')
-rw-r--r--usr.sbin/installboot/bootstrap.c37
1 files changed, 10 insertions, 27 deletions
diff --git a/usr.sbin/installboot/bootstrap.c b/usr.sbin/installboot/bootstrap.c
index 0df2145b48b..d55829d17aa 100644
--- a/usr.sbin/installboot/bootstrap.c
+++ b/usr.sbin/installboot/bootstrap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bootstrap.c,v 1.10 2018/09/01 16:55:29 krw Exp $ */
+/* $OpenBSD: bootstrap.c,v 1.11 2018/11/25 17:34:37 krw Exp $ */
/*
* Copyright (c) 2013 Joel Sing <jsing@openbsd.org>
@@ -78,33 +78,16 @@ bootstrap(int devfd, char *dev, char *bootfile)
close(fd);
/*
- * Check that the bootstrap will fit - partitions must not overlap,
- * or if they do, the partition type must be either FS_BOOT or
- * FS_UNUSED. The 'c' partition will always overlap and is ignored.
+ * Check that the bootstrap will not intrude into the OpenBSD area
+ * of the disk.
*/
- if (verbose)
- fprintf(stderr, "ensuring used partitions do not overlap "
- "with bootstrap sectors 0-%zu\n", bootsec);
- for (i = 0; i < dl.d_npartitions; i++) {
- part = 'a' + i;
- pp = &dl.d_partitions[i];
- if (i == RAW_PART)
- continue;
- if (DL_GETPSIZE(pp) == 0)
- continue;
- if ((u_int64_t)bootsec <= DL_GETPOFFSET(pp))
- continue;
- switch (pp->p_fstype) {
- case FS_BOOT:
- break;
- case FS_UNUSED:
- warnx("bootstrap overlaps with unused partition %c",
- part);
- break;
- default:
- errx(1, "bootstrap overlaps with partition %c", part);
- }
- }
+ if (bootsec > DL_GETBSTART(&dl))
+ errx(1, "bootstrap (sectors 0 - %zu) overlaps OpenBSD "
+ " area (sectors %zu - %zu)", bootsec,
+ DL_GETBSTART(&dl), DL_GETBEND(&dl));
+ else if (verbose)
+ fprintf(stderr, "bootstrap (sectors 0 - %zu) does not overlap "
+ "OpenBSD area.\n", bootsec);
/*
* Make sure the bootstrap has left space for the disklabel.