Come to think further about it, I think it is better for diskmap to
always trust disk drivers to either :
- not have any label (dk_label == NULL, or points to zeroed memory)
or
- have a valid label (duid is not zeroes).
The following diff thus relaxes the logic to always trust
dk_label->d_uid, unless it is zero. This passes the vnd test I mailed
yesterday, without the need for a dev/vnd.c change.
Index: sys/dev/softraid.c
===================================================================
RCS file: /OpenBSD/src/sys/dev/softraid.c,v
retrieving revision 1.425
diff -u -p -u -p -r1.425 softraid.c
--- sys/dev/softraid.c 16 Apr 2022 19:19:58 -0000 1.425
+++ sys/dev/softraid.c 17 Aug 2022 05:20:51 -0000
@@ -3685,13 +3685,11 @@ sr_ioctl_installboot(struct sr_softc *sc
}
}
- bzero(duid, sizeof(duid));
TAILQ_FOREACH(dk, &disklist, dk_link)
if (!strncmp(dk->dk_name, bb->bb_dev, sizeof(bb->bb_dev)))
break;
if (dk == NULL || dk->dk_label == NULL ||
- (dk->dk_flags & DKF_LABELVALID) == 0 ||
- bcmp(dk->dk_label->d_uid, &duid, sizeof(duid)) == 0) {
+ duid_iszero(dk->dk_label->d_uid)) {
sr_error(sc, "failed to get DUID for softraid volume");
goto done;
}
Index: sys/kern/subr_disk.c
===================================================================
RCS file: /OpenBSD/src/sys/kern/subr_disk.c,v
retrieving revision 1.253
diff -u -p -u -p -r1.253 subr_disk.c
--- sys/kern/subr_disk.c 14 Aug 2022 01:58:27 -0000 1.253
+++ sys/kern/subr_disk.c 17 Aug 2022 05:20:51 -0000
@@ -1121,7 +1121,6 @@ disk_attach_callback(void *xdat)
/* Read disklabel. */
if (disk_readlabel(&dl, dk->dk_devno, errbuf, sizeof(errbuf)) == NULL) {
enqueue_randomness(dl.d_checksum);
- dk->dk_flags |= DKF_LABELVALID;
}
done:
@@ -1440,14 +1439,14 @@ setroot(struct device *bootdv, int part,
TAILQ_FOREACH(dk, &disklist, dk_link)
if (dk->dk_device == bootdv)
break;
- if (dk && (dk->dk_flags & DKF_LABELVALID))
+ if (dk)
bcopy(dk->dk_label->d_uid, bootduid, sizeof(bootduid));
} else if (bootdv == NULL) {
/* Locate boot disk based on the provided DUID. */
TAILQ_FOREACH(dk, &disklist, dk_link)
if (duid_equal(dk->dk_label->d_uid, bootduid))
break;
- if (dk && (dk->dk_flags & DKF_LABELVALID))
+ if (dk)
bootdv = dk->dk_device;
}
bcopy(bootduid, rootduid, sizeof(rootduid));
@@ -1561,8 +1560,7 @@ gotswap:
if (bootdv->dv_class == DV_DISK) {
if (!duid_iszero(rootduid)) {
TAILQ_FOREACH(dk, &disklist, dk_link)
- if ((dk->dk_flags & DKF_LABELVALID) &&
- dk->dk_label && duid_equal(
+ if (dk->dk_label && duid_equal(
dk->dk_label->d_uid, rootduid))
break;
if (dk == NULL)
@@ -1788,7 +1786,8 @@ disk_map(char *path, char *mappath, int
mdk = NULL;
TAILQ_FOREACH(dk, &disklist, dk_link) {
- if ((dk->dk_flags & DKF_LABELVALID) && dk->dk_label &&
+ if (dk->dk_label &&
+ !duid_iszero(dk->dk_label->d_uid) &&
memcmp(dk->dk_label->d_uid, uid,
sizeof(dk->dk_label->d_uid)) == 0) {
/* Fail if there are duplicate UIDs! */
Index: sys/sys/disk.h
===================================================================
RCS file: /OpenBSD/src/sys/sys/disk.h,v
retrieving revision 1.36
diff -u -p -u -p -r1.36 disk.h
--- sys/sys/disk.h 4 May 2017 22:47:27 -0000 1.36
+++ sys/sys/disk.h 17 Aug 2022 05:20:51 -0000
@@ -83,7 +83,6 @@ struct disk {
#define DKF_CONSTRUCTED 0x0001
#define DKF_OPENED 0x0002
#define DKF_NOLABELREAD 0x0004
-#define DKF_LABELVALID 0x0008
/*
* Metrics data; note that some metrics may have no meaning