git: 110b8112e5eb - stable/13 - stge: fix null pointer dereference

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Thu, 07 Apr 2022 00:31:09 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=110b8112e5ebf2ba0f00479da1b7eafa83684d2e

commit 110b8112e5ebf2ba0f00479da1b7eafa83684d2e
Author:     Tong Zhang <ztong0001@gmail.com>
AuthorDate: 2022-03-31 18:16:55 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-04-07 00:30:45 +0000

    stge: fix null pointer dereference
    
    stge_attach() could fail at line 464, sc->sc_spec remains NULL when
    calling stge_detach(), thus bus_release_resources() at line 704 will
    trigger null pointer dereference. We need to check the nulliness before
    calling bus_release_resources().
    
    PR:             258420
    Reviewed by:    markj
    
    (cherry picked from commit 2108cc72906f274f30306570268434c4f8d23636)
---
 sys/dev/stge/if_stge.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/dev/stge/if_stge.c b/sys/dev/stge/if_stge.c
index c9f71f01278c..a043ca9a6e80 100644
--- a/sys/dev/stge/if_stge.c
+++ b/sys/dev/stge/if_stge.c
@@ -699,7 +699,9 @@ stge_detach(device_t dev)
 		bus_teardown_intr(dev, sc->sc_res[1], sc->sc_ih);
 		sc->sc_ih = NULL;
 	}
-	bus_release_resources(dev, sc->sc_spec, sc->sc_res);
+
+	if (sc->sc_spec)
+		bus_release_resources(dev, sc->sc_spec, sc->sc_res);
 
 	mtx_destroy(&sc->sc_mii_mtx);
 	mtx_destroy(&sc->sc_mtx);