aboutsummaryrefslogtreecommitdiff
path: root/sys/net/if.c
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2015-12-22 15:03:45 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2015-12-22 15:03:45 +0000
commitf501e6f136db308cb3828f2f3934f75479ce2365 (patch)
tree0ce71f2e4ecbbcda4df0baed9d120dfe478371a1 /sys/net/if.c
parent616bc4f4760f72918007a25b08a243b8912719f7 (diff)
downloadsrc-f501e6f136db308cb3828f2f3934f75479ce2365.tar.gz
src-f501e6f136db308cb3828f2f3934f75479ce2365.zip
If vnets are torn down while ifconfig runs an ioctl to say, destroy an
epair(4), we may hit if_detach_internal() without holding a lock and by the time we aquire it the interface might be gone. We should not panic() in this case as it is our fault for not holding the lock all the way. It is not ideal to return silently without error to user space, but other callers will all ignore the return values so do not change the entire KPI for little benefit for now. The ifp will be dealt with one way or another still. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Reviewed by: gnn Differential Revision: https://reviews.freebsd.org/D4529
Notes
Notes: svn path=/head/; revision=292604
Diffstat (limited to 'sys/net/if.c')
-rw-r--r--sys/net/if.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index b88c05e765a2..39656efa363d 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -173,7 +173,7 @@ static int if_getgroup(struct ifgroupreq *, struct ifnet *);
static int if_getgroupmembers(struct ifgroupreq *);
static void if_delgroups(struct ifnet *);
static void if_attach_internal(struct ifnet *, int, struct if_clone *);
-static void if_detach_internal(struct ifnet *, int, struct if_clone **);
+static int if_detach_internal(struct ifnet *, int, struct if_clone **);
#ifdef INET6
/*
@@ -884,7 +884,7 @@ if_detach(struct ifnet *ifp)
CURVNET_RESTORE();
}
-static void
+static int
if_detach_internal(struct ifnet *ifp, int vmove, struct if_clone **ifcp)
{
struct ifaddr *ifa;
@@ -906,11 +906,19 @@ if_detach_internal(struct ifnet *ifp, int vmove, struct if_clone **ifcp)
#endif
IFNET_WUNLOCK();
if (!found) {
+ /*
+ * While we would want to panic here, we cannot
+ * guarantee that the interface is indeed still on
+ * the list given we don't hold locks all the way.
+ */
+ return (ENOENT);
+#if 0
if (vmove)
panic("%s: ifp=%p not on the ifnet tailq %p",
__func__, ifp, &V_ifnet);
else
return; /* XXX this should panic as well? */
+#endif
}
/* Check if this is a cloned interface or not. */
@@ -993,6 +1001,8 @@ if_detach_internal(struct ifnet *ifp, int vmove, struct if_clone **ifcp)
(*dp->dom_ifdetach)(ifp,
ifp->if_afdata[dp->dom_family]);
}
+
+ return (0);
}
#ifdef VIMAGE
@@ -1007,12 +1017,16 @@ void
if_vmove(struct ifnet *ifp, struct vnet *new_vnet)
{
struct if_clone *ifc;
+ int rc;
/*
* Detach from current vnet, but preserve LLADDR info, do not
* mark as dead etc. so that the ifnet can be reattached later.
+ * If we cannot find it, we lost the race to someone else.
*/
- if_detach_internal(ifp, 1, &ifc);
+ rc = if_detach_internal(ifp, 1, &ifc);
+ if (rc != 0)
+ return;
/*
* Unlink the ifnet from ifindex_table[] in current vnet, and shrink