aboutsummaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2011-01-24 22:21:58 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2011-01-24 22:21:58 +0000
commit5f3b301a43c68d4a8eac808098c750af879fe6fb (patch)
treefeb4b2394b2a42cf3fb86c5796fccc18a9a76372 /sys/net
parentf1fb96475a9ccfa8c7e5f3c52cb6b3a7908ae31f (diff)
downloadsrc-5f3b301a43c68d4a8eac808098c750af879fe6fb.tar.gz
src-5f3b301a43c68d4a8eac808098c750af879fe6fb.zip
Fix a LOR by dropping the global ifnet locks while allocating a new ifnet
table in if_grow(). The order of the SYSINIT's for ifnet state were swapped so that the various locks were initialized before being used. Reviewed by: pluknet, bz MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=217805
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 41e8e8f145e8..b8a4c8ba27ad 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -266,6 +266,7 @@ ifindex_alloc_locked(u_short *idxp)
IFNET_WLOCK_ASSERT();
+retry:
/*
* Try to find an empty slot below V_if_index. If we fail, take the
* next slot.
@@ -278,10 +279,12 @@ ifindex_alloc_locked(u_short *idxp)
/* Catch if_index overflow. */
if (idx < 1)
return (ENOSPC);
+ if (idx >= V_if_indexlim) {
+ if_grow();
+ goto retry;
+ }
if (idx > V_if_index)
V_if_index = idx;
- if (V_if_index >= V_if_indexlim)
- if_grow();
*idxp = idx;
return (0);
}
@@ -351,10 +354,12 @@ vnet_if_init(const void *unused __unused)
TAILQ_INIT(&V_ifnet);
TAILQ_INIT(&V_ifg_head);
+ IFNET_WLOCK();
if_grow(); /* create initial table */
+ IFNET_WUNLOCK();
vnet_if_clone_init();
}
-VNET_SYSINIT(vnet_if_init, SI_SUB_INIT_IF, SI_ORDER_FIRST, vnet_if_init,
+VNET_SYSINIT(vnet_if_init, SI_SUB_INIT_IF, SI_ORDER_SECOND, vnet_if_init,
NULL);
/* ARGSUSED*/
@@ -365,7 +370,7 @@ if_init(void *dummy __unused)
IFNET_LOCK_INIT();
if_clone_init();
}
-SYSINIT(interfaces, SI_SUB_INIT_IF, SI_ORDER_SECOND, if_init, NULL);
+SYSINIT(interfaces, SI_SUB_INIT_IF, SI_ORDER_FIRST, if_init, NULL);
#ifdef VIMAGE
@@ -385,16 +390,25 @@ VNET_SYSUNINIT(vnet_if_uninit, SI_SUB_INIT_IF, SI_ORDER_FIRST,
static void
if_grow(void)
{
+ int oldlim;
u_int n;
struct ifindex_entry *e;
- V_if_indexlim <<= 1;
- n = V_if_indexlim * sizeof(*e);
+ IFNET_WLOCK_ASSERT();
+ oldlim = V_if_indexlim;
+ IFNET_WUNLOCK();
+ n = (oldlim << 1) * sizeof(*e);
e = malloc(n, M_IFNET, M_WAITOK | M_ZERO);
+ IFNET_WLOCK();
+ if (V_if_indexlim != oldlim) {
+ free(e, M_IFNET);
+ return;
+ }
if (V_ifindex_table != NULL) {
memcpy((caddr_t)e, (caddr_t)V_ifindex_table, n/2);
free((caddr_t)V_ifindex_table, M_IFNET);
}
+ V_if_indexlim <<= 1;
V_ifindex_table = e;
}