aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorPing Yu <ping.yu@intel.com>2018-08-28 18:56:27 -0400
committerFlorin Coras <florin.coras@gmail.com>2018-08-29 17:34:14 +0000
commite6446a3cd5f4b4faab87127c1a310e3c7fbf0e60 (patch)
tree884c6bb97a5c3124d8b98a6373cfc775d90e4484 /src/vnet
parent77eb9073b178e8d4375bf0ef274246586f018ddc (diff)
Fix race condition in tls half open ctx get/put
Change-Id: I603094215162bfe7d41bbff1b9fe8ab974aa3fab Signed-off-by: Ping Yu <ping.yu@intel.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/tls/tls.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c
index b576c00d4e9..4fb0dfb3c91 100644
--- a/src/vnet/tls/tls.c
+++ b/src/vnet/tls/tls.c
@@ -94,16 +94,17 @@ tls_ctx_half_open_alloc (void)
{
clib_rwlock_writer_lock (&tm->half_open_rwlock);
pool_get (tm->half_open_ctx_pool, ctx);
- memset (ctx, 0, sizeof (*ctx));
- ctx_index = ctx - tm->half_open_ctx_pool;
clib_rwlock_writer_unlock (&tm->half_open_rwlock);
}
else
{
+ /* reader lock assumption: only main thread will call pool_get */
+ clib_rwlock_reader_lock (&tm->half_open_rwlock);
pool_get (tm->half_open_ctx_pool, ctx);
- memset (ctx, 0, sizeof (*ctx));
- ctx_index = ctx - tm->half_open_ctx_pool;
+ clib_rwlock_reader_unlock (&tm->half_open_rwlock);
}
+ memset (ctx, 0, sizeof (*ctx));
+ ctx_index = ctx - tm->half_open_ctx_pool;
return ctx_index;
}