Always check if softraid0 is NULL before dereferencing it.
authorkrw <krw@openbsd.org>
Sun, 20 Mar 2022 13:14:02 +0000 (13:14 +0000)
committerkrw <krw@openbsd.org>
Sun, 20 Mar 2022 13:14:02 +0000 (13:14 +0000)
Avoids panic on reboot when softraid has been disabled.

Discovered by, diagnosed, first diff from & fix tested by Scott
Nicholas.

ok bluhm@

sys/dev/softraid.c

index 50ef9d6..bca68aa 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid.c,v 1.421 2022/01/09 05:42:37 jsg Exp $ */
+/* $OpenBSD: softraid.c,v 1.422 2022/03/20 13:14:02 krw Exp $ */
 /*
  * Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us>
  * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org>
@@ -1508,11 +1508,11 @@ sr_map_root(void)
        u_char                  duid[8];
        int                     i;
 
-       DNPRINTF(SR_D_MISC, "%s: sr_map_root\n", DEVNAME(sc));
-
        if (sc == NULL)
                return;
 
+       DNPRINTF(SR_D_MISC, "%s: sr_map_root\n", DEVNAME(sc));
+
        bzero(duid, sizeof(duid));
        if (bcmp(rootduid, duid, sizeof(duid)) == 0) {
                DNPRINTF(SR_D_MISC, "%s: root duid is zero\n", DEVNAME(sc));
@@ -4538,6 +4538,9 @@ sr_quiesce(void)
        struct sr_softc         *sc = softraid0;
        struct sr_discipline    *sd, *nsd;
 
+       if (sc == NULL)
+               return;
+
        /* Shutdown disciplines in reverse attach order. */
        TAILQ_FOREACH_REVERSE_SAFE(sd, &sc->sc_dis_list,
            sr_discipline_list, sd_link, nsd)
@@ -4550,6 +4553,9 @@ sr_shutdown(int dying)
        struct sr_softc         *sc = softraid0;
        struct sr_discipline    *sd;
 
+       if (sc == NULL)
+               return;
+
        DNPRINTF(SR_D_MISC, "%s: sr_shutdown\n", DEVNAME(sc));
 
        /*