Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb Fix error handling, to prevent kernel crashes wh...



details:   https://anonhg.NetBSD.org/src/rev/ca54804bcc70
branches:  trunk
changeset: 463882:ca54804bcc70
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Sep 14 12:53:24 2019 +0000

description:
Fix error handling, to prevent kernel crashes when detaching an upgt0
device.

Found with vHCI.

diffstat:

 sys/dev/usb/if_upgt.c    |  9 +++++++--
 sys/dev/usb/if_upgtvar.h |  6 +++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diffs (64 lines):

diff -r 65baef01e5c7 -r ca54804bcc70 sys/dev/usb/if_upgt.c
--- a/sys/dev/usb/if_upgt.c     Sat Sep 14 12:50:16 2019 +0000
+++ b/sys/dev/usb/if_upgt.c     Sat Sep 14 12:53:24 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_upgt.c,v 1.25 2019/03/06 08:08:25 msaitoh Exp $     */
+/*     $NetBSD: if_upgt.c,v 1.26 2019/09/14 12:53:24 maxv Exp $        */
 /*     $OpenBSD: if_upgt.c,v 1.49 2010/04/20 22:05:43 tedu Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_upgt.c,v 1.25 2019/03/06 08:08:25 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_upgt.c,v 1.26 2019/09/14 12:53:24 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -239,6 +239,7 @@
         */
        sc->sc_dev = self;
        sc->sc_udev = uaa->uaa_device;
+       sc->sc_init_state = UPGT_INIT_NONE;
 
        devinfop = usbd_devinfo_alloc(sc->sc_udev, 0);
        aprint_normal_dev(sc->sc_dev, "%s\n", devinfop);
@@ -306,6 +307,7 @@
        callout_setfunc(&sc->scan_to, upgt_next_scan, sc);
        callout_init(&sc->led_to, 0);
        callout_setfunc(&sc->led_to, upgt_set_led_blink, sc);
+       sc->sc_init_state = UPGT_INIT_INITED;
 
        /*
         * Open TX and RX USB bulk pipes.
@@ -498,6 +500,9 @@
 
        DPRINTF(1, "%s: %s\n", device_xname(sc->sc_dev), __func__);
 
+       if (sc->sc_init_state < UPGT_INIT_INITED)
+               return 0;
+
        s = splnet();
 
        if (ifp->if_flags & IFF_RUNNING)
diff -r 65baef01e5c7 -r ca54804bcc70 sys/dev/usb/if_upgtvar.h
--- a/sys/dev/usb/if_upgtvar.h  Sat Sep 14 12:50:16 2019 +0000
+++ b/sys/dev/usb/if_upgtvar.h  Sat Sep 14 12:53:24 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_upgtvar.h,v 1.2 2016/04/23 10:15:31 skrll Exp $     */
+/*     $NetBSD: if_upgtvar.h,v 1.3 2019/09/14 12:53:24 maxv Exp $      */
 /*     $OpenBSD: if_upgtvar.h,v 1.15 2009/08/10 20:02:19 deraadt Exp $ */
 
 /*
@@ -398,6 +398,10 @@
        struct ethercom          sc_ec;
 #define sc_if  sc_ec.ec_if
 
+       enum {
+               UPGT_INIT_NONE,
+               UPGT_INIT_INITED
+       } sc_init_state;
        struct usbd_device *     sc_udev;
        struct usbd_interface *  sc_iface;
        int                      sc_rx_no;



Home | Main Index | Thread Index | Old Index