From: krw Date: Sun, 20 Mar 2022 13:14:02 +0000 (+0000) Subject: Always check if softraid0 is NULL before dereferencing it. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0d960dd8f2b5ae5cdec6d76e508c4ca1b623da6d;p=openbsd Always check if softraid0 is NULL before dereferencing it. Avoids panic on reboot when softraid has been disabled. Discovered by, diagnosed, first diff from & fix tested by Scott Nicholas. ok bluhm@ --- diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index 50ef9d655bc..bca68aa55f6 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -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 * Copyright (c) 2008 Chris Kuethe @@ -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)); /*