DragonFlyBSD Kernel Audit
DF-1959 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/dev/disk/dm/dm_ioctl.c b/sys/dev/disk/dm/dm_ioctl.c
--- a/sys/dev/disk/dm/dm_ioctl.c
+++ b/sys/dev/disk/dm/dm_ioctl.c
@@ -353,11 +353,14 @@
 
 	is_open = dmv->is_open;
 
-	dm_dev_unbusy(dmv);
-
-	if (is_open)
+	if (is_open) {
+		dm_dev_unbusy(dmv);
 		return EBUSY;
+	}
+
 
+	/* Pass the busy reference through to dm_dev_remove so
+	 * the device cannot be torn down concurrently. */
 	return dm_dev_remove(dmv);
 }