diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2022-09-11 11:47:56 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2022-09-11 11:47:56 +0000 |
commit | 979f7810d8ef1b40b192dc3d6d3d1a51df280367 (patch) | |
tree | 14dcb40d1cb75af0928185a2500e9a6059b42f39 | |
parent | 2a06b987ff48be845b177cbbd5fb99cf0ed2faf7 (diff) |
Add #define's for GPT partition attribute bits REQUIRED, IGNORE
and BOOTABLE, set BOOTABLE attribute bit instead of using the
incorrect GPTDOSACTIVE value, have 'fdisk -v' print out GPT
partition attributes if any of the 64 bits are set, don't spoof
any partition with REQUIRED bit set.
Prompted by kettenis@ stumbling across a machine with 40+ (!!)
REQUIRED GPT partitions.
Tested & ok kettenis@
-rw-r--r-- | sbin/fdisk/cmd.c | 4 | ||||
-rw-r--r-- | sbin/fdisk/gpt.c | 21 | ||||
-rw-r--r-- | sys/kern/subr_disk.c | 7 | ||||
-rw-r--r-- | sys/sys/disklabel.h | 5 |
4 files changed, 28 insertions, 9 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index dc8698901b9..99146bfc22e 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.164 2022/07/25 17:45:16 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.165 2022/09/11 11:47:55 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -488,7 +488,7 @@ Xflag(const char *args, struct mbr *mbr) if (gh.gh_sig == GPTSIGNATURE) { for (i = 0; i < gh.gh_part_num; i++) { if (i == pn) - gp[i].gp_attrs = GPTDOSACTIVE; + gp[i].gp_attrs = GPTPARTATTR_BOOTABLE; else gp[i].gp_attrs = 0; } diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index 247c7d2699c..c3f66ca7ebb 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.80 2022/08/29 19:39:10 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.81 2022/09/11 11:47:55 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller <mmu@grummel.net> * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org> @@ -437,15 +437,14 @@ GPT_print_part(const unsigned int pn, const char *units, const int verbosity) const struct unit_type *ut; char *guidstr = NULL; double size; - uint64_t end, start; + uint64_t attrs, end, start; uint32_t status; start = gp[pn].gp_lba_start; end = gp[pn].gp_lba_end; size = units_size(units, (start > end) ? 0 : end - start + 1, &ut); - printf("%c%3u: %-36s [%12lld: %12.0f%s]\n", - gp[pn].gp_attrs & GPTDOSACTIVE ? '*' : ' ', pn, + printf(" %3u: %-36s [%12lld: %12.0f%s]\n", pn, PRT_uuid_to_sname(&gp[pn].gp_type), start, size, ut->ut_abbr); if (verbosity == VERBOSE) { @@ -456,6 +455,17 @@ GPT_print_part(const unsigned int pn, const char *units, const int verbosity) printf(" %-36s ", guidstr); printf("%-36s\n", name_to_string(pn)); free(guidstr); + attrs = gp[pn].gp_attrs; + if (attrs) { + printf(" Attributes: (0x%016llx) ", attrs); + if (attrs & GPTPARTATTR_REQUIRED) + printf("Required " ); + if (attrs & GPTPARTATTR_IGNORE) + printf("Ignore "); + if (attrs & GPTPARTATTR_BOOTABLE) + printf("Bootable"); + printf("\n"); + } } if (start > end) @@ -592,7 +602,8 @@ init_gp(const int how) memset(&gp, 0, sizeof(gp)); else { for (pn = 0; pn < gh.gh_part_num; pn++) { - if (PRT_protected_guid(&gp[pn].gp_type)) + if (PRT_protected_guid(&gp[pn].gp_type) || + (gp[pn].gp_attrs & GPTPARTATTR_REQUIRED)) continue; memset(&gp[pn], 0, sizeof(gp[pn])); } diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index b35cbb4e052..6623dd816bc 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.260 2022/09/03 15:29:43 kettenis Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.261 2022/09/11 11:47:55 krw Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -641,6 +641,11 @@ spoofgpt(struct buf *bp, void (*strat)(struct buf *), const uint8_t *dosbb, partoff = DL_SECTOBLK(lp, lbastart); obsdfound = 0; for (i = 0; i < partnum; i++) { + if (letoh64(gp[i].gp_attrs) & GPTPARTATTR_REQUIRED) { + DPRINTF("spoofgpt: Skipping partition %u (REQUIRED)\n"); + continue; + } + start = letoh64(gp[i].gp_lba_start); if (start > lbaend || start < lbastart) continue; diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index bc595f3e826..cff3d005db1 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.80 2022/09/06 14:14:44 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.81 2022/09/11 11:47:55 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */ /* @@ -340,6 +340,9 @@ struct partinfo { /* ASCII string "EFI PART" encoded as 64-bit */ #define GPTREVISION 0x10000 /* GPT header version 1.0 */ #define NGPTPARTITIONS 128 +#define GPTPARTATTR_REQUIRED (1 << 0) +#define GPTPARTATTR_IGNORE (1 << 1) +#define GPTPARTATTR_BOOTABLE (1 << 2) #define GPTDOSACTIVE 0x2 #define GPTMINHDRSIZE 92 #define GPTMINPARTSIZE 128 |