Source-Changes-HG archive

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

[src/trunk]: src/sys/net Fix panic when doing ioctl to multiple pseudo interf...



details:   https://anonhg.NetBSD.org/src/rev/a34fab7de597
branches:  trunk
changeset: 445232:a34fab7de597
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Fri Oct 19 00:12:56 2018 +0000

description:
Fix panic when doing ioctl to multiple pseudo interfaces. Pointed out by k-goda@IIJ.

XXX pullup-8

diffstat:

 sys/net/if_gif.c   |  13 ++++++-------
 sys/net/if_gif.h   |   4 +++-
 sys/net/if_ipsec.c |  12 ++++++------
 sys/net/if_ipsec.h |   4 +++-
 sys/net/if_l2tp.c  |   8 +++++---
 sys/net/if_l2tp.h  |   4 +++-
 sys/net/if_vlan.c  |   5 +++--
 7 files changed, 29 insertions(+), 21 deletions(-)

diffs (283 lines):

diff -r 10fdea853383 -r a34fab7de597 sys/net/if_gif.c
--- a/sys/net/if_gif.c  Fri Oct 19 00:11:48 2018 +0000
+++ b/sys/net/if_gif.c  Fri Oct 19 00:12:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_gif.c,v 1.143 2018/06/26 06:48:02 msaitoh Exp $     */
+/*     $NetBSD: if_gif.c,v 1.144 2018/10/19 00:12:56 knakahara Exp $   */
 /*     $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $    */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.143 2018/06/26 06:48:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.144 2018/10/19 00:12:56 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -103,7 +103,6 @@
        kmutex_t lock;
 } gif_softcs __cacheline_aligned;
 
-pserialize_t gif_psz __read_mostly;
 struct psref_class *gv_psref_class __read_mostly;
 
 static void    gif_ro_init_pc(void *, void *, struct cpu_info *);
@@ -222,7 +221,6 @@
        LIST_INIT(&gif_softcs.list);
        if_clone_attach(&gif_cloner);
 
-       gif_psz = pserialize_create();
        gv_psref_class = psref_class_create("gifvar", IPL_SOFTNET);
 
        gif_sysctl_setup();
@@ -241,7 +239,6 @@
 
        if (error == 0) {
                psref_class_destroy(gv_psref_class);
-               pserialize_destroy(gif_psz);
 
                if_clone_detach(&gif_cloner);
                sysctl_teardown(&gif_sysctl);
@@ -273,9 +270,10 @@
 
        sc->gif_var = var;
        mutex_init(&sc->gif_lock, MUTEX_DEFAULT, IPL_NONE);
+       sc->gif_psz = pserialize_create();
+
        sc->gif_ro_percpu = percpu_alloc(sizeof(struct gif_ro));
        percpu_foreach(sc->gif_ro_percpu, gif_ro_init_pc, NULL);
-
        mutex_enter(&gif_softcs.lock);
        LIST_INSERT_HEAD(&gif_softcs.list, sc, gif_list);
        mutex_exit(&gif_softcs.lock);
@@ -353,6 +351,7 @@
        percpu_foreach(sc->gif_ro_percpu, gif_ro_fini_pc, NULL);
        percpu_free(sc->gif_ro_percpu, sizeof(struct gif_ro));
 
+       pserialize_destroy(sc->gif_psz);
        mutex_destroy(&sc->gif_lock);
 
        var = sc->gif_var;
@@ -1171,7 +1170,7 @@
        KASSERT(mutex_owned(&sc->gif_lock));
 
        sc->gif_var = nvar;
-       pserialize_perform(gif_psz);
+       pserialize_perform(sc->gif_psz);
        psref_target_destroy(&ovar->gv_psref, gv_psref_class);
 
        if (nvar->gv_psrc != NULL && nvar->gv_pdst != NULL)
diff -r 10fdea853383 -r a34fab7de597 sys/net/if_gif.h
--- a/sys/net/if_gif.h  Fri Oct 19 00:11:48 2018 +0000
+++ b/sys/net/if_gif.h  Fri Oct 19 00:12:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_gif.h,v 1.31 2018/04/27 09:55:27 knakahara Exp $    */
+/*     $NetBSD: if_gif.h,v 1.32 2018/10/19 00:12:56 knakahara Exp $    */
 /*     $KAME: if_gif.h,v 1.23 2001/07/27 09:21:42 itojun Exp $ */
 
 /*
@@ -40,6 +40,7 @@
 #include <sys/queue.h>
 #include <sys/percpu.h>
 #ifdef _KERNEL
+#include <sys/pserialize.h>
 #include <sys/psref.h>
 #endif
 
@@ -78,6 +79,7 @@
                                         * instead of direct dereference.
                                         */
        kmutex_t gif_lock;              /* writer lock for gif_var */
+       pserialize_t gif_psz;
 
        LIST_ENTRY(gif_softc) gif_list; /* list of all gifs */
 };
diff -r 10fdea853383 -r a34fab7de597 sys/net/if_ipsec.c
--- a/sys/net/if_ipsec.c        Fri Oct 19 00:11:48 2018 +0000
+++ b/sys/net/if_ipsec.c        Fri Oct 19 00:12:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ipsec.c,v 1.17 2018/06/26 06:48:02 msaitoh Exp $  */
+/*     $NetBSD: if_ipsec.c,v 1.18 2018/10/19 00:12:56 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.17 2018/06/26 06:48:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.18 2018/10/19 00:12:56 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -145,7 +145,6 @@
        kmutex_t lock;
 } ipsec_softcs __cacheline_aligned;
 
-pserialize_t ipsec_psz __read_mostly;
 struct psref_class *iv_psref_class __read_mostly;
 
 struct if_clone ipsec_cloner =
@@ -160,7 +159,6 @@
        mutex_init(&ipsec_softcs.lock, MUTEX_DEFAULT, IPL_NONE);
        LIST_INIT(&ipsec_softcs.list);
 
-       ipsec_psz = pserialize_create();
        iv_psref_class = psref_class_create("ipsecvar", IPL_SOFTNET);
 
        if_clone_attach(&ipsec_cloner);
@@ -184,6 +182,7 @@
 
        sc->ipsec_var = var;
        mutex_init(&sc->ipsec_lock, MUTEX_DEFAULT, IPL_NONE);
+       sc->ipsec_psz = pserialize_create();
        sc->ipsec_ro_percpu = percpu_alloc(sizeof(struct ipsec_ro));
        percpu_foreach(sc->ipsec_ro_percpu, if_ipsec_ro_init_pc, NULL);
 
@@ -254,6 +253,7 @@
        percpu_foreach(sc->ipsec_ro_percpu, if_ipsec_ro_fini_pc, NULL);
        percpu_free(sc->ipsec_ro_percpu, sizeof(struct ipsec_ro));
 
+       pserialize_destroy(sc->ipsec_psz);
        mutex_destroy(&sc->ipsec_lock);
 
        var = sc->ipsec_var;
@@ -1785,7 +1785,7 @@
         * "null" config variant to sc->ipsec_var.
         */
        sc->ipsec_var = nullvar;
-       pserialize_perform(ipsec_psz);
+       pserialize_perform(sc->ipsec_psz);
        psref_target_destroy(&ovar->iv_psref, iv_psref_class);
 
        error = if_ipsec_replace_sp(sc, ovar, nvar);
@@ -1796,7 +1796,7 @@
                psref_target_init(&ovar->iv_psref, iv_psref_class);
        }
 
-       pserialize_perform(ipsec_psz);
+       pserialize_perform(sc->ipsec_psz);
        psref_target_destroy(&nullvar->iv_psref, iv_psref_class);
 
        if (if_ipsec_variant_is_configured(sc->ipsec_var))
diff -r 10fdea853383 -r a34fab7de597 sys/net/if_ipsec.h
--- a/sys/net/if_ipsec.h        Fri Oct 19 00:11:48 2018 +0000
+++ b/sys/net/if_ipsec.h        Fri Oct 19 00:12:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ipsec.h,v 1.3 2018/04/27 09:55:27 knakahara Exp $  */
+/*     $NetBSD: if_ipsec.h,v 1.4 2018/10/19 00:12:56 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -35,6 +35,7 @@
 
 #include <sys/queue.h>
 #ifdef _KERNEL
+#include <sys/pserialize.h>
 #include <sys/psref.h>
 #endif
 
@@ -98,6 +99,7 @@
                                          * instead of direct dereference.
                                          */
        kmutex_t ipsec_lock;            /* writer lock for ipsec_var */
+       pserialize_t ipsec_psz;
 
        LIST_ENTRY(ipsec_softc) ipsec_list; /* list of all gifs */
 };
diff -r 10fdea853383 -r a34fab7de597 sys/net/if_l2tp.c
--- a/sys/net/if_l2tp.c Fri Oct 19 00:11:48 2018 +0000
+++ b/sys/net/if_l2tp.c Fri Oct 19 00:12:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_l2tp.c,v 1.29 2018/06/26 06:48:02 msaitoh Exp $     */
+/*     $NetBSD: if_l2tp.c,v 1.30 2018/10/19 00:12:56 knakahara Exp $   */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.29 2018/06/26 06:48:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.30 2018/10/19 00:12:56 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -243,6 +243,7 @@
 
        sc->l2tp_var = var;
        mutex_init(&sc->l2tp_lock, MUTEX_DEFAULT, IPL_NONE);
+       sc->l2tp_psz = pserialize_create();
        PSLIST_ENTRY_INIT(sc, l2tp_hash);
 
        sc->l2tp_ro_percpu = percpu_alloc(sizeof(struct l2tp_ro));
@@ -337,6 +338,7 @@
        percpu_free(sc->l2tp_ro_percpu, sizeof(struct l2tp_ro));
 
        kmem_free(var, sizeof(struct l2tp_variant));
+       pserialize_destroy(sc->l2tp_psz);
        mutex_destroy(&sc->l2tp_lock);
        kmem_free(sc, sizeof(struct l2tp_softc));
 
@@ -1194,7 +1196,7 @@
        KASSERT(mutex_owned(&sc->l2tp_lock));
 
        sc->l2tp_var = nvar;
-       pserialize_perform(l2tp_psz);
+       pserialize_perform(sc->l2tp_psz);
        psref_target_destroy(&ovar->lv_psref, lv_psref_class);
 
        /*
diff -r 10fdea853383 -r a34fab7de597 sys/net/if_l2tp.h
--- a/sys/net/if_l2tp.h Fri Oct 19 00:11:48 2018 +0000
+++ b/sys/net/if_l2tp.h Fri Oct 19 00:12:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_l2tp.h,v 1.5 2018/04/27 09:55:27 knakahara Exp $    */
+/*     $NetBSD: if_l2tp.h,v 1.6 2018/10/19 00:12:56 knakahara Exp $    */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -36,6 +36,7 @@
 #include <sys/queue.h>
 #include <sys/ioccom.h>
 #ifdef _KERNEL
+#include <sys/pserialize.h>
 #include <sys/psref.h>
 #include <sys/pslist.h>
 #endif
@@ -104,6 +105,7 @@
                                        * instead of direct dereference.
                                        */
        kmutex_t l2tp_lock;             /* writer lock for l2tp_var */
+       pserialize_t l2tp_psz;
 
        LIST_ENTRY(l2tp_softc) l2tp_list; /* list of all l2tps */
        struct pslist_entry l2tp_hash;  /* hashed list to lookup by session id */
diff -r 10fdea853383 -r a34fab7de597 sys/net/if_vlan.c
--- a/sys/net/if_vlan.c Fri Oct 19 00:11:48 2018 +0000
+++ b/sys/net/if_vlan.c Fri Oct 19 00:12:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vlan.c,v 1.132 2018/10/18 11:34:54 knakahara Exp $  */
+/*     $NetBSD: if_vlan.c,v 1.133 2018/10/19 00:12:56 knakahara Exp $  */
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.132 2018/10/18 11:34:54 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.133 2018/10/19 00:12:56 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -415,6 +415,7 @@
 
        psref_target_destroy(&ifv->ifv_mib->ifvm_psref, ifvm_psref_class);
        kmem_free(ifv->ifv_mib, sizeof(struct ifvlan_linkmib));
+       pserialize_destroy(ifv->ifv_psz);
        mutex_destroy(&ifv->ifv_lock);
        free(ifv, M_DEVBUF);
 



Home | Main Index | Thread Index | Old Index