summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2011-12-28 16:02:46 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2011-12-28 16:02:46 +0000
commita7ea4e0a0bb8bbac90652f9ff777c76cd5fcfb34 (patch)
treec0fd414b652b1e1b125dc4f63bef03c75b5ccc66 /sys
parenta39761aa469e3d31cf17dcbe5d31e3d906cf7a79 (diff)
Avoid the use of an invalid disklabel by setting a DK_LABELVALID flag
if we correctly read and validated the disklabel. Always check that this flag is set before using the DUID from the disklabel. Discussed with deraadt@ ok krw@
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/softraid.c3
-rw-r--r--sys/kern/subr_disk.c16
-rw-r--r--sys/sys/disk.h3
3 files changed, 15 insertions, 7 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c
index 1eee7e40c93..a30870140e2 100644
--- a/sys/dev/softraid.c
+++ b/sys/dev/softraid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid.c,v 1.260 2011/12/26 14:54:52 jsing Exp $ */
+/* $OpenBSD: softraid.c,v 1.261 2011/12/28 16:02:45 jsing Exp $ */
/*
* Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org>
@@ -3389,6 +3389,7 @@ sr_ioctl_installboot(struct sr_softc *sc, struct bioc_installboot *bb)
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) {
printf("%s: failed to get DUID for softraid volume!\n",
DEVNAME(sd->sd_sc));
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index ae347fff99d..35664552ebc 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.134 2011/12/28 14:34:13 jsing Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.135 2011/12/28 16:02:45 jsing Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -866,17 +866,21 @@ disk_attach_callback(void *arg1, void *arg2)
if (dk->dk_devno == dev)
break;
}
- if (dk == NULL || (dk->dk_flags & (DKF_OPENED | DKF_NOLABELREAD)))
+ if (dk == NULL || (dk->dk_flags & (DKF_OPENED | DKF_NOLABELREAD))) {
+ wakeup(dk);
return;
+ }
/* XXX: Assumes dk is part of the device softc. */
device_ref(dk->dk_device);
/* Read disklabel. */
- disk_readlabel(&dl, dev, errbuf, sizeof(errbuf));
+ if (disk_readlabel(&dl, dev, errbuf, sizeof(errbuf)) == NULL)
+ dk->dk_flags |= DKF_LABELVALID;
dk->dk_flags |= DKF_OPENED;
device_unref(dk->dk_device);
+ wakeup(dk);
}
/*
@@ -1265,7 +1269,8 @@ gotswap:
bzero(&duid, sizeof(duid));
if (bcmp(rootduid, &duid, sizeof(rootduid)) != 0) {
TAILQ_FOREACH(dk, &disklist, dk_link)
- if (dk->dk_label && bcmp(dk->dk_label->d_uid,
+ if ((dk->dk_flags & DKF_LABELVALID) &&
+ dk->dk_label && bcmp(dk->dk_label->d_uid,
&rootduid, sizeof(rootduid)) == 0)
break;
if (dk == NULL)
@@ -1497,7 +1502,8 @@ disk_map(char *path, char *mappath, int size, int flags)
mdk = NULL;
TAILQ_FOREACH(dk, &disklist, dk_link) {
- if (dk->dk_label && bcmp(dk->dk_label->d_uid, uid,
+ if ((dk->dk_flags & DKF_LABELVALID) && dk->dk_label &&
+ bcmp(dk->dk_label->d_uid, uid,
sizeof(dk->dk_label->d_uid)) == 0) {
/* Fail if there are duplicate UIDs! */
if (mdk != NULL)
diff --git a/sys/sys/disk.h b/sys/sys/disk.h
index 95a77629419..32b4f0eb9db 100644
--- a/sys/sys/disk.h
+++ b/sys/sys/disk.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.h,v 1.32 2011/09/21 21:43:57 deraadt Exp $ */
+/* $OpenBSD: disk.h,v 1.33 2011/12/28 16:02:45 jsing Exp $ */
/* $NetBSD: disk.h,v 1.11 1996/04/28 20:22:50 thorpej Exp $ */
/*
@@ -83,6 +83,7 @@ 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