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/cb1efc3bfbdd
branches:  trunk
changeset: 454340:cb1efc3bfbdd
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Sep 14 12:36:35 2019 +0000

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

Found with vHCI.

diffstat:

 sys/dev/usb/if_athn_usb.c |  10 ++++++++--
 sys/dev/usb/if_athn_usb.h |   6 +++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diffs (65 lines):

diff -r d8636edd7b20 -r cb1efc3bfbdd sys/dev/usb/if_athn_usb.c
--- a/sys/dev/usb/if_athn_usb.c Sat Sep 14 12:32:08 2019 +0000
+++ b/sys/dev/usb/if_athn_usb.c Sat Sep 14 12:36:35 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_athn_usb.c,v 1.34 2019/06/03 09:58:31 msaitoh Exp $ */
+/*     $NetBSD: if_athn_usb.c,v 1.35 2019/09/14 12:36:35 maxv Exp $    */
 /*     $OpenBSD: if_athn_usb.c,v 1.12 2013/01/14 09:50:31 jsing Exp $  */
 
 /*-
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_athn_usb.c,v 1.34 2019/06/03 09:58:31 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_athn_usb.c,v 1.35 2019/09/14 12:36:35 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -260,6 +260,7 @@
 
        DPRINTFN(DBG_FN, sc, "\n");
 
+       usc->usc_init_state = ATHN_INIT_NONE;
        usc->usc_athn_attached = 0;
        usc->usc_flags = athn_usb_lookup(uaa->uaa_vendor, uaa->uaa_product)->flags;
        sc->sc_flags |= ATHN_FLAG_USB;
@@ -328,6 +329,8 @@
        if (!pmf_device_register(self, NULL, NULL))
                aprint_error_dev(self, "couldn't establish power handler\n");
 
+       usc->usc_init_state = ATHN_INIT_INITED;
+
        return;
 
  fail:
@@ -478,6 +481,9 @@
 
        DPRINTFN(DBG_FN, usc, "\n");
 
+       if (usc->usc_init_state < ATHN_INIT_INITED)
+               return 0;
+
        pmf_device_deregister(self);
 
        mutex_enter(&usc->usc_lock);
diff -r d8636edd7b20 -r cb1efc3bfbdd sys/dev/usb/if_athn_usb.h
--- a/sys/dev/usb/if_athn_usb.h Sat Sep 14 12:32:08 2019 +0000
+++ b/sys/dev/usb/if_athn_usb.h Sat Sep 14 12:36:35 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_athn_usb.h,v 1.5 2017/01/21 12:45:22 skrll Exp $    */
+/*     $NetBSD: if_athn_usb.h,v 1.6 2019/09/14 12:36:35 maxv Exp $     */
 /*     $OpenBSD: if_athn_usb.h,v 1.3 2012/11/10 14:35:06 mikeb Exp $   */
 
 /*-
@@ -441,6 +441,10 @@
        struct athn_softc               usc_sc;
 #define usc_dev                usc_sc.sc_dev
 
+       enum {
+               ATHN_INIT_NONE,
+               ATHN_INIT_INITED
+       } usc_init_state;
        int                             usc_athn_attached;
 
        kmutex_t                        usc_lock;



Home | Main Index | Thread Index | Old Index