aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2020-12-15 15:33:28 +0000
committerKristof Provost <kp@FreeBSD.org>2020-12-15 15:33:28 +0000
commitdc5e65b9c39a09b92955832f6788c8c9d06025f0 (patch)
tree1a82266a179c717d8ca2e4aaa75919f2d00d13ef
parent4d3d1b73bedfecdb2e975995572faa4433920d8e (diff)
downloadsrc-dc5e65b9c39a09b92955832f6788c8c9d06025f0.tar.gz
src-dc5e65b9c39a09b92955832f6788c8c9d06025f0.zip
MFC r368237:
if: Fix panic when destroying vnet and epair simultaneously When destroying a vnet and an epair (with one end in the vnet) we often panicked. This was the result of the destruction of the epair, which destroys both ends simultaneously, happening while vnet_if_return() was moving the struct ifnet to its home vnet. This can result in a freed ifnet being re-added to the home vnet V_ifnet list. That in turn panics the next time the ifnet is used. Prevent this race by ensuring that vnet_if_return() cannot run at the same time as if_detach() or epair_clone_destroy(). PR: 238870, 234985, 244703, 250870 Sponsored by: Modirum MDPay
Notes
Notes: svn path=/stable/12/; revision=368663
-rw-r--r--sys/net/if.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index f7c87e7f2814..a5104fe7422f 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -315,6 +315,9 @@ RW_SYSINIT_FLAGS(ifnet_rw, &ifnet_rwlock, "ifnet_rw", RW_RECURSE);
struct sx ifnet_sxlock;
SX_SYSINIT_FLAGS(ifnet_sx, &ifnet_sxlock, "ifnet_sx", SX_RECURSE);
+struct sx ifnet_detach_sxlock;
+SX_SYSINIT(ifnet_detach, &ifnet_detach_sxlock, "ifnet_detach_sx");
+
/*
* The allocation of network interfaces is a rather non-atomic affair; we
* need to select an index before we are ready to expose the interface for
@@ -549,7 +552,9 @@ vnet_if_return(const void *unused __unused)
IFNET_WUNLOCK();
for (int j = 0; j < i; j++) {
+ sx_xlock(&ifnet_detach_sxlock);
if_vmove(pending[j], pending[j]->if_home_vnet);
+ sx_xunlock(&ifnet_detach_sxlock);
}
free(pending, M_IFNET);
@@ -1102,8 +1107,11 @@ if_detach(struct ifnet *ifp)
CURVNET_SET_QUIET(ifp->if_vnet);
found = if_unlink_ifnet(ifp, false);
- if (found)
+ if (found) {
+ sx_slock(&ifnet_detach_sxlock);
if_detach_internal(ifp, 0, NULL);
+ sx_sunlock(&ifnet_detach_sxlock);
+ }
CURVNET_RESTORE();
}
@@ -3141,8 +3149,12 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td)
goto out_noref;
case SIOCIFDESTROY:
error = priv_check(td, PRIV_NET_IFDESTROY);
- if (error == 0)
+
+ if (error == 0) {
+ sx_slock(&ifnet_detach_sxlock);
error = if_clone_destroy(ifr->ifr_name);
+ sx_sunlock(&ifnet_detach_sxlock);
+ }
goto out_noref;
case SIOCIFGCLONERS: