From: krw Date: Fri, 12 Aug 2022 20:05:49 +0000 (+0000) Subject: Revert to pre-r1.249 more laissez-faire checks for valid MBR X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=8e434e93737cb25921e442bcb5f2ae7ba3e6166e;p=openbsd Revert to pre-r1.249 more laissez-faire checks for valid MBR partitions. miod@ (re)discovered an off-by-one in some device size calculations. Whether the ancient misbehaviour of some devices to confuse number of sectors with highest valid sector address or something newer. Should fix miod@'s octeon boot disk. --- diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 7f65013eb8a..9e12d8a2c71 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.251 2022/08/12 00:32:59 krw Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.252 2022/08/12 20:05:49 krw Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -743,11 +743,16 @@ 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; + start = sector + letoh32(dp[i].dp_start); end = start + letoh32(dp[i].dp_size); - if (start >= end || end > DL_GETDSIZE(lp)) - continue; parts++; if (obsdfound == 0) { labeloff = partoff + DOS_LABELSECTOR;