Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F141864656
D1914.id3876.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D1914.id3876.diff
View Options
Index: sys/netipsec/ipsec.h
===================================================================
--- sys/netipsec/ipsec.h
+++ sys/netipsec/ipsec.h
@@ -89,6 +89,9 @@
/* if policy == IPSEC else this value == NULL.*/
u_int refcnt; /* reference count */
u_int policy; /* policy_type per pfkeyv2.h */
+ u_int state;
+#define IPSEC_SPSTATE_DEAD 0
+#define IPSEC_SPSTATE_ALIVE 1
u_int32_t id; /* It's unique number on the system. */
/*
* lifetime handler.
Index: sys/netipsec/key.c
===================================================================
--- sys/netipsec/key.c
+++ sys/netipsec/key.c
@@ -1198,8 +1198,14 @@
SPTREE_UNLOCK_ASSERT();
SPTREE_WLOCK();
+ if (sp->state == IPSEC_SPSTATE_DEAD) {
+ SPTREE_WUNLOCK();
+ return;
+ }
+ sp->state = IPSEC_SPSTATE_DEAD;
TAILQ_REMOVE(&V_sptree[sp->spidx.dir], sp, chain);
SPTREE_WUNLOCK();
+ KEY_FREESP(&sp);
}
/*
@@ -1900,6 +1906,7 @@
SPTREE_WLOCK();
TAILQ_INSERT_TAIL(&V_sptree[newsp->spidx.dir], newsp, chain);
+ newsp->state = IPSEC_SPSTATE_ALIVE;
SPTREE_WUNLOCK();
/* delete the entry in spacqtree */
@@ -2335,6 +2342,12 @@
for (dir = 0; dir < IPSEC_DIR_MAX; dir++) {
TAILQ_CONCAT(&drainq, &V_sptree[dir], chain);
}
+ /*
+ * We need to set state to DEAD for each policy to be sure,
+ * that another thread won't try to unlink it.
+ */
+ TAILQ_FOREACH(sp, &drainq, chain)
+ sp->state = IPSEC_SPSTATE_DEAD;
SPTREE_WUNLOCK();
sp = TAILQ_FIRST(&drainq);
while (sp != NULL) {
@@ -4209,9 +4222,10 @@
now - sp->created > sp->lifetime) ||
(sp->validtime &&
now - sp->lastused > sp->validtime)) {
+ SP_ADDREF(sp);
SPTREE_RUNLOCK();
- key_unlink(sp);
key_spdexpire(sp);
+ key_unlink(sp);
KEY_FREESP(&sp);
goto restart;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 12, 3:47 PM (1 h, 14 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27620323
Default Alt Text
D1914.id3876.diff (1 KB)
Attached To
Mode
D1914: Fix memory leak and several races in IPsec policies management code
Attached
Detach File
Event Timeline
Log In to Comment