From: krw Date: Wed, 2 Jun 2021 22:44:26 +0000 (+0000) Subject: Use the same logic in all copies of gpt_chk_mbr(), relaxing the X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=71c0bb0b4bae49e4bfb4827f265e2b4c30bf092a;p=openbsd Use the same logic in all copies of gpt_chk_mbr(), relaxing the media length check to allow EFI GPT partitions to be smaller that the entire disk. Consistently use GPTSECTOR instead of randomly tossing in some literal '1's. ok kettenis@ --- diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index 6ccbc244982..69479fdfda0 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.72 2021/05/27 14:27:41 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.73 2021/06/02 22:44:26 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -315,7 +315,7 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) if (letoh32(dp2->dp_start) != GPTSECTOR) continue; psize = letoh32(dp2->dp_size); - if (psize <= (dsize - 1) || psize == UINT32_MAX) { + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) { efi = i; eficnt++; } diff --git a/sys/arch/amd64/stand/efiboot/efidev.c b/sys/arch/amd64/stand/efiboot/efidev.c index a6ce8fb5bc6..bbf248eb586 100644 --- a/sys/arch/amd64/stand/efiboot/efidev.c +++ b/sys/arch/amd64/stand/efiboot/efidev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efidev.c,v 1.33 2021/03/17 05:41:34 yasuoka Exp $ */ +/* $OpenBSD: efidev.c,v 1.34 2021/06/02 22:44:26 krw Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -175,12 +175,11 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) found++; if (dp2->dp_typ != DOSPTYP_EFI) continue; + if (letoh32(dp2->dp_start) != GPTSECTOR) + continue; psize = letoh32(dp2->dp_size); - if (psize == (dsize - 1) || - psize == UINT32_MAX) { - if (letoh32(dp2->dp_start) == 1) - efi++; - } + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) + efi++; } if (found == 1 && efi == 1) return (0); @@ -308,8 +307,8 @@ findopenbsd_gpt(efi_diskinfo_t ed, const char **err) return (-1); } - /* LBA1: GPT Header */ - lba = 1; + /* GPT Header */ + lba = GPTSECTOR; status = efid_io(F_READ, ed, EFI_SECTOBLK(ed, lba), EFI_BLKSPERSEC(ed), buf); if (EFI_ERROR(status)) { diff --git a/sys/arch/amd64/stand/libsa/softraid_amd64.c b/sys/arch/amd64/stand/libsa/softraid_amd64.c index 7cc13c1312e..4c6099d83de 100644 --- a/sys/arch/amd64/stand/libsa/softraid_amd64.c +++ b/sys/arch/amd64/stand/libsa/softraid_amd64.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_amd64.c,v 1.6 2020/12/09 18:10:18 krw Exp $ */ +/* $OpenBSD: softraid_amd64.c,v 1.7 2021/06/02 22:44:26 krw Exp $ */ /* * Copyright (c) 2012 Joel Sing @@ -410,12 +410,11 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) found++; if (dp2->dp_typ != DOSPTYP_EFI) continue; + if (letoh32(dp2->dp_start) != GPTSECTOR) + continue; psize = letoh32(dp2->dp_size); - if (psize == (dsize - 1) || - psize == UINT32_MAX) { - if (letoh32(dp2->dp_start) == 1) - efi++; - } + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) + efi++; } if (found == 1 && efi == 1) return (0); @@ -463,8 +462,8 @@ findopenbsd_gpt(struct sr_boot_volume *bv, const char **err) } bzero(buf, bv->sbv_secsize); - /* LBA1: GPT Header */ - lba = 1; + /* GPT Header */ + lba = GPTSECTOR; sr_strategy(bv, F_READ, lba * (bv->sbv_secsize / DEV_BSIZE), DEV_BSIZE, buf, NULL); memcpy(&gh, buf, sizeof(gh)); diff --git a/sys/arch/arm64/stand/efiboot/efidev.c b/sys/arch/arm64/stand/efiboot/efidev.c index a877173afe4..902faa7c8ba 100644 --- a/sys/arch/arm64/stand/efiboot/efidev.c +++ b/sys/arch/arm64/stand/efiboot/efidev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efidev.c,v 1.7 2021/06/02 15:31:15 kettenis Exp $ */ +/* $OpenBSD: efidev.c,v 1.8 2021/06/02 22:44:27 krw Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -164,12 +164,11 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) found++; if (dp2->dp_typ != DOSPTYP_EFI) continue; + if (letoh32(dp2->dp_start) != GPTSECTOR) + continue; psize = letoh32(dp2->dp_size); - if (psize == (dsize - 1) || - psize == UINT32_MAX) { - if (letoh32(dp2->dp_start) == 1) - efi++; - } + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) + efi++; } if (found == 1 && efi == 1) return (0); @@ -297,8 +296,8 @@ findopenbsd_gpt(efi_diskinfo_t ed, const char **err) return (-1); } - /* LBA1: GPT Header */ - lba = 1; + /* GPT Header */ + lba = GPTSECTOR; status = efid_io(F_READ, ed, EFI_SECTOBLK(ed, lba), EFI_BLKSPERSEC(ed), buf); if (EFI_ERROR(status)) { diff --git a/sys/arch/arm64/stand/efiboot/softraid_arm64.c b/sys/arch/arm64/stand/efiboot/softraid_arm64.c index 243543904fd..37177303337 100644 --- a/sys/arch/arm64/stand/efiboot/softraid_arm64.c +++ b/sys/arch/arm64/stand/efiboot/softraid_arm64.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_arm64.c,v 1.2 2020/12/09 18:10:18 krw Exp $ */ +/* $OpenBSD: softraid_arm64.c,v 1.3 2021/06/02 22:44:27 krw Exp $ */ /* * Copyright (c) 2012 Joel Sing @@ -402,12 +402,11 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) found++; if (dp2->dp_typ != DOSPTYP_EFI) continue; + if (letoh32(dp2->dp_start) != GPTSECTOR) + continue; psize = letoh32(dp2->dp_size); - if (psize == (dsize - 1) || - psize == UINT32_MAX) { - if (letoh32(dp2->dp_start) == 1) - efi++; - } + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) + efi++; } if (found == 1 && efi == 1) return (0); @@ -455,8 +454,8 @@ findopenbsd_gpt(struct sr_boot_volume *bv, const char **err) } bzero(buf, bv->sbv_secsize); - /* LBA1: GPT Header */ - lba = 1; + /* GPT Header */ + lba = GPTSECTOR; sr_strategy(bv, F_READ, lba * (bv->sbv_secsize / DEV_BSIZE), DEV_BSIZE, buf, NULL); memcpy(&gh, buf, sizeof(gh)); diff --git a/sys/arch/armv7/stand/efiboot/efidev.c b/sys/arch/armv7/stand/efiboot/efidev.c index b79d6bac071..c122750b3ff 100644 --- a/sys/arch/armv7/stand/efiboot/efidev.c +++ b/sys/arch/armv7/stand/efiboot/efidev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efidev.c,v 1.6 2020/12/09 18:10:18 krw Exp $ */ +/* $OpenBSD: efidev.c,v 1.7 2021/06/02 22:44:27 krw Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -150,12 +150,11 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) found++; if (dp2->dp_typ != DOSPTYP_EFI) continue; + if (letoh32(dp2->dp_start) != GPTSECTOR) + continue; psize = letoh32(dp2->dp_size); - if (psize == (dsize - 1) || - psize == UINT32_MAX) { - if (letoh32(dp2->dp_start) == 1) - efi++; - } + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) + efi++; } if (found == 1 && efi == 1) return (0); @@ -283,8 +282,8 @@ findopenbsd_gpt(efi_diskinfo_t ed, const char **err) return (-1); } - /* LBA1: GPT Header */ - lba = 1; + /* GPT Header */ + lba = GPTSECTOR; status = efid_io(F_READ, ed, EFI_SECTOBLK(ed, lba), EFI_BLKSPERSEC(ed), buf); if (EFI_ERROR(status)) { diff --git a/sys/arch/riscv64/stand/efiboot/efidev.c b/sys/arch/riscv64/stand/efiboot/efidev.c index fd8855b4171..ac14ab5c3e3 100644 --- a/sys/arch/riscv64/stand/efiboot/efidev.c +++ b/sys/arch/riscv64/stand/efiboot/efidev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efidev.c,v 1.1 2021/04/28 19:01:00 drahn Exp $ */ +/* $OpenBSD: efidev.c,v 1.2 2021/06/02 22:44:27 krw Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -150,12 +150,11 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) found++; if (dp2->dp_typ != DOSPTYP_EFI) continue; + if (letoh32(dp2->dp_start) != GPTSECTOR) + continue; psize = letoh32(dp2->dp_size); - if (psize == (dsize - 1) || - psize == UINT32_MAX) { - if (letoh32(dp2->dp_start) == 1) - efi++; - } + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) + efi++; } if (found == 1 && efi == 1) return (0); @@ -283,8 +282,8 @@ findopenbsd_gpt(efi_diskinfo_t ed, const char **err) return (-1); } - /* LBA1: GPT Header */ - lba = 1; + /* GPT Header */ + lba = GPTSECTOR; status = efid_io(F_READ, ed, EFI_SECTOBLK(ed, lba), EFI_BLKSPERSEC(ed), buf); if (EFI_ERROR(status)) { diff --git a/sys/arch/riscv64/stand/efiboot/softraid_riscv64.c b/sys/arch/riscv64/stand/efiboot/softraid_riscv64.c index 0a521cc6427..d7691e0c7da 100644 --- a/sys/arch/riscv64/stand/efiboot/softraid_riscv64.c +++ b/sys/arch/riscv64/stand/efiboot/softraid_riscv64.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_riscv64.c,v 1.1 2021/04/28 19:01:00 drahn Exp $ */ +/* $OpenBSD: softraid_riscv64.c,v 1.2 2021/06/02 22:44:27 krw Exp $ */ /* * Copyright (c) 2012 Joel Sing @@ -402,12 +402,11 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) found++; if (dp2->dp_typ != DOSPTYP_EFI) continue; + if (letoh32(dp2->dp_start) != GPTSECTOR) + continue; psize = letoh32(dp2->dp_size); - if (psize == (dsize - 1) || - psize == UINT32_MAX) { - if (letoh32(dp2->dp_start) == 1) - efi++; - } + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) + efi++; } if (found == 1 && efi == 1) return (0); @@ -455,8 +454,8 @@ findopenbsd_gpt(struct sr_boot_volume *bv, const char **err) } bzero(buf, bv->sbv_secsize); - /* LBA1: GPT Header */ - lba = 1; + /* GPT Header */ + lba = GPTSECTOR; sr_strategy(bv, F_READ, lba * (bv->sbv_secsize / DEV_BSIZE), DEV_BSIZE, buf, NULL); memcpy(&gh, buf, sizeof(gh)); diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 31b342ccc83..4e454aefec5 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.243 2021/06/01 22:54:43 krw Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.244 2021/06/02 22:44:27 krw Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -607,7 +607,7 @@ gpt_chk_mbr(struct dos_partition *dp, uint64_t dsize) if (letoh32(dp2->dp_start) != GPTSECTOR) continue; psize = letoh32(dp2->dp_size); - if (psize <= (dsize - 1) || psize == UINT32_MAX) { + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) { efi = i; eficnt++; } diff --git a/usr.sbin/installboot/armv7_installboot.c b/usr.sbin/installboot/armv7_installboot.c index f262549e8e9..951218f1d62 100644 --- a/usr.sbin/installboot/armv7_installboot.c +++ b/usr.sbin/installboot/armv7_installboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: armv7_installboot.c,v 1.7 2021/06/02 16:12:18 kettenis Exp $ */ +/* $OpenBSD: armv7_installboot.c,v 1.8 2021/06/02 22:44:27 krw Exp $ */ /* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */ /* @@ -274,12 +274,11 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) found++; if (dp2->dp_typ != DOSPTYP_EFI) continue; + if (letoh32(dp2->dp_start) != GPTSECTOR) + continue psize = letoh32(dp2->dp_size); - if (psize == (dsize - 1) || - psize == UINT32_MAX) { - if (letoh32(dp2->dp_start) == 1) - efi++; - } + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) + efi++; } if (found == 1 && efi == 1) return (0); diff --git a/usr.sbin/installboot/i386_installboot.c b/usr.sbin/installboot/i386_installboot.c index 3153e0b53f0..4a15560a097 100644 --- a/usr.sbin/installboot/i386_installboot.c +++ b/usr.sbin/installboot/i386_installboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i386_installboot.c,v 1.38 2020/07/22 05:06:38 deraadt Exp $ */ +/* $OpenBSD: i386_installboot.c,v 1.39 2021/06/02 22:44:27 krw Exp $ */ /* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */ /* @@ -473,12 +473,11 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) found++; if (dp2->dp_typ != DOSPTYP_EFI) continue; + if (letoh32(dp2->dp_start) != GPTSECTOR) + continue; psize = letoh32(dp2->dp_size); - if (psize == (dsize - 1) || - psize == UINT32_MAX) { - if (letoh32(dp2->dp_start) == 1) - efi++; - } + if (psize <= (dsize - GPTSECTOR) || psize == UINT32_MAX) + efi++; } if (found == 1 && efi == 1) return (0);