From 5e51fc7902835be90856014803958c0a56589d21 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 25 Jun 2026 09:56:06 +0200 Subject: [PATCH] tnc-pdp: Fix lock type when adding/replacing a connection The entry was updated and the previous EAP method and IKE SA destroyed under a read lock, which is not safe (there could be threads in get_state(), or even some that called it before and now still hold that read lock while interacting with the EAP method). Fixes: 37884ab10f0f ("Add locking to TNC-PDP connections") --- src/libcharon/plugins/tnc_pdp/tnc_pdp_connections.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libcharon/plugins/tnc_pdp/tnc_pdp_connections.c b/src/libcharon/plugins/tnc_pdp/tnc_pdp_connections.c index da317a894..42ecb0d3d 100644 --- a/src/libcharon/plugins/tnc_pdp/tnc_pdp_connections.c +++ b/src/libcharon/plugins/tnc_pdp/tnc_pdp_connections.c @@ -174,7 +174,7 @@ METHOD(tnc_pdp_connections_t, add, void, ike_sa_id->destroy(ike_sa_id); ike_sa->set_other_id(ike_sa, peer); - this->lock->read_lock(this->lock); + this->lock->write_lock(this->lock); enumerator = this->list->create_enumerator(this->list); while (enumerator->enumerate(enumerator, &entry)) { @@ -191,7 +191,6 @@ METHOD(tnc_pdp_connections_t, add, void, } } enumerator->destroy(enumerator); - this->lock->unlock(this->lock); if (!found) { @@ -202,10 +201,9 @@ METHOD(tnc_pdp_connections_t, add, void, .ike_sa = ike_sa, .created = time_monotonic(NULL), ); - this->lock->write_lock(this->lock); this->list->insert_last(this->list, entry); - this->lock->unlock(this->lock); } + this->lock->unlock(this->lock); /* schedule timeout checking */ lib->scheduler->schedule_job_ms(lib->scheduler,