diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-11-01 20:05:15 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-11-01 20:08:14 +0100 |
commit | a51f47d58a813a692698ef2a41b50313e3c2efee (patch) | |
tree | 1fee9446557e4bea190d75d7fd28b8a907a257a5 /src/noise.c | |
parent | d90c71a653c13bbbf1abe61f221a0e50aec4fe2e (diff) |
data: do not allow usage of keypair just before hash removal
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/noise.c')
-rw-r--r-- | src/noise.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/noise.c b/src/noise.c index b24b483..cefedee 100644 --- a/src/noise.c +++ b/src/noise.c @@ -95,6 +95,16 @@ void noise_keypair_put(struct noise_keypair *keypair) kref_put(&keypair->refcount, keypair_free_kref); } +struct noise_keypair *noise_keypair_get(struct noise_keypair *keypair) +{ + RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "Calling noise_keypair_get without holding the RCU read lock."); + if (unlikely(!keypair)) + return NULL; + if (unlikely(!kref_get_unless_zero(&keypair->refcount))) + return NULL; + return keypair; +} + void noise_keypairs_clear(struct noise_keypairs *keypairs) { struct noise_keypair *old; |