Ensure that the disk has been initialized after acquiring the lock and
authoranton <anton@openbsd.org>
Tue, 21 Dec 2021 06:11:16 +0000 (06:11 +0000)
committeranton <anton@openbsd.org>
Tue, 21 Dec 2021 06:11:16 +0000 (06:11 +0000)
not before as we might end up sleeping while acquiring the lock,
introducing a potential race.

Tested in snaps for a couple of days.

ok mpi@

Reported-by: syzbot+c87cdc2905b441c20d39@syzkaller.appspotmail.com
sys/dev/vnd.c

index 9b7b2ce..aee0251 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vnd.c,v 1.174 2021/11/21 23:07:11 deraadt Exp $       */
+/*     $OpenBSD: vnd.c,v 1.175 2021/12/21 06:11:16 anton Exp $ */
 /*     $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $        */
 
 /*
@@ -532,11 +532,12 @@ fail:
                break;
            }
        case VNDIOCCLR:
-               if ((sc->sc_flags & VNF_INITED) == 0)
-                       return (ENXIO);
-
                if ((error = disk_lock(&sc->sc_dk)) != 0)
                        return (error);
+               if ((sc->sc_flags & VNF_INITED) == 0) {
+                       disk_unlock(&sc->sc_dk);
+                       return (ENXIO);
+               }
 
                /*
                 * Don't unconfigure if any other partitions are open