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

XXX pullup-8
This commit is contained in:
knakahara 2018-10-19 00:12:56 +00:00
parent c02f7f97b6
commit ebac3c728d
7 changed files with 29 additions and 21 deletions

View File

@ -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 @@ static struct {
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 @@ gifinit(void)
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 @@ gifdetach(void)
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 @@ gif_clone_create(struct if_clone *ifc, int unit)
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 @@ gif_clone_destroy(struct ifnet *ifp)
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 @@ gif_update_variant(struct gif_softc *sc, struct gif_variant *nvar)
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)

View File

@ -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 @@ struct gif_softc {
* 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 */
};

View File

@ -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 @@ static struct {
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 @@ ipsecifattach(int count)
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 @@ if_ipsec_clone_create(struct if_clone *ifc, int unit)
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 @@ if_ipsec_clone_destroy(struct ifnet *ifp)
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 @@ if_ipsec_update_variant(struct ipsec_softc *sc, struct ipsec_variant *nvar,
* "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 @@ if_ipsec_update_variant(struct ipsec_softc *sc, struct ipsec_variant *nvar,
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))

View File

@ -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 @@ struct ipsec_softc {
* 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 */
};

View File

@ -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 @@ l2tp_clone_create(struct if_clone *ifc, int unit)
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 @@ l2tp_clone_destroy(struct ifnet *ifp)
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 @@ l2tp_variant_update(struct l2tp_softc *sc, struct l2tp_variant *nvar)
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);
/*

View File

@ -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 @@ struct l2tp_softc {
* 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 */

View File

@ -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 @@ vlan_clone_destroy(struct ifnet *ifp)
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);