From: krw Date: Sat, 20 Aug 2022 13:10:45 +0000 (+0000) Subject: Restore the exemption from start/size checks that OpenBSD (A6) X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1b10218152059da8b8d9dcbf6ba86e3c64ab5bf0;p=openbsd Restore the exemption from start/size checks that OpenBSD (A6) MBR partitions previously enjoyed. Found and fix tested by matthieu@ --- diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 1f0f97ca3bc..822d2415b14 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.253 2022/08/14 01:58:27 jsg Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.254 2022/08/20 13:10:45 krw Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -740,12 +740,17 @@ spoofmbr(struct buf *bp, void (*strat)(struct buf *), const uint8_t *dosbb, } for (i = 0; i < NDOSPART; i++) { - if (letoh32(dp[i].dp_start) > DL_GETDSIZE(lp)) - continue; - if (letoh32(dp[i].dp_size) > DL_GETDSIZE(lp)) - continue; if (letoh32(dp[i].dp_size) == 0) continue; + if (obsdfound && dp[i].dp_typ == DOSPTYP_OPENBSD) + continue; + + if (dp[i].dp_typ != DOSPTYP_OPENBSD) { + if (letoh32(dp[i].dp_start) > DL_GETDSIZE(lp)) + continue; + if (letoh32(dp[i].dp_size) > DL_GETDSIZE(lp)) + continue; + } start = sector + letoh32(dp[i].dp_start); end = start + letoh32(dp[i].dp_size); @@ -760,15 +765,13 @@ spoofmbr(struct buf *bp, void (*strat)(struct buf *), const uint8_t *dosbb, switch (dp[i].dp_typ) { case DOSPTYP_OPENBSD: - if (obsdfound == 0) { - obsdfound = 1; - partoff = DL_SECTOBLK(lp, start); - labeloff = partoff + DOS_LABELSECTOR; - if (labeloff >= DL_SECTOBLK(lp, end)) - partoff = -1; - DL_SETBSTART(lp, start); - DL_SETBEND(lp, end); - } + obsdfound = 1; + partoff = DL_SECTOBLK(lp, start); + labeloff = partoff + DOS_LABELSECTOR; + if (labeloff >= DL_SECTOBLK(lp, end)) + partoff = -1; + DL_SETBSTART(lp, start); + DL_SETBEND(lp, end); continue; case DOSPTYP_EFI: continue;