aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2023-12-05 19:08:11 +0000
committerKristof Provost <kp@FreeBSD.org>2023-12-07 12:34:47 +0000
commitbd7b2f95019e9715150c34736279805de0818d09 (patch)
tree59a79c062330a25d5fa381c6f80745df379f64e2
parent3878bbf1bb9e68f8579b57cde7d4e5c77de93320 (diff)
downloadsrc-bd7b2f95019e9715150c34736279805de0818d09.tar.gz
src-bd7b2f95019e9715150c34736279805de0818d09.zip
vnet: (read) lock the vnet list while iterating it
Ensure that the vnet list cannot be modified while we're running through it. Reviewed by: mjg (previous version), zlei (previous version) MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D42927
-rw-r--r--sys/net/vnet.c4
-rw-r--r--sys/netinet/ip_reass.c2
2 files changed, 6 insertions, 0 deletions
diff --git a/sys/net/vnet.c b/sys/net/vnet.c
index ac937125a19d..9668471633f4 100644
--- a/sys/net/vnet.c
+++ b/sys/net/vnet.c
@@ -536,11 +536,13 @@ vnet_register_sysinit(void *arg)
* Invoke the constructor on all the existing vnets when it is
* registered.
*/
+ VNET_LIST_RLOCK();
VNET_FOREACH(vnet) {
CURVNET_SET_QUIET(vnet);
vs->func(vs->arg);
CURVNET_RESTORE();
}
+ VNET_LIST_RUNLOCK();
VNET_SYSINIT_WUNLOCK();
}
@@ -592,6 +594,7 @@ vnet_deregister_sysuninit(void *arg)
* deregistered.
*/
VNET_SYSINIT_WLOCK();
+ VNET_LIST_RLOCK();
VNET_FOREACH(vnet) {
CURVNET_SET_QUIET(vnet);
vs->func(vs->arg);
@@ -601,6 +604,7 @@ vnet_deregister_sysuninit(void *arg)
/* Remove the destructor from the global list of vnet destructors. */
TAILQ_REMOVE(&vnet_destructors, vs, link);
VNET_SYSINIT_WUNLOCK();
+ VNET_LIST_RUNLOCK();
}
/*
diff --git a/sys/netinet/ip_reass.c b/sys/netinet/ip_reass.c
index 219a869c5139..a95780aa2f27 100644
--- a/sys/netinet/ip_reass.c
+++ b/sys/netinet/ip_reass.c
@@ -661,11 +661,13 @@ ipreass_drain(void)
{
VNET_ITERATOR_DECL(vnet_iter);
+ VNET_LIST_RLOCK();
VNET_FOREACH(vnet_iter) {
CURVNET_SET(vnet_iter);
ipreass_drain_vnet();
CURVNET_RESTORE();
}
+ VNET_LIST_RUNLOCK();
}