aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/noise.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-11-01 20:05:15 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-11-01 20:08:14 +0100
commit662b948fec1549edd2cbec521a039fd2f9d34065 (patch)
treec614e53bc6d2493f5a0d1fe0b8f823709d616c79 /src/noise.c
parentpeer: kref is most likely to succeed (diff)
downloadwireguard-monolithic-historical-662b948fec1549edd2cbec521a039fd2f9d34065.tar.xz
wireguard-monolithic-historical-662b948fec1549edd2cbec521a039fd2f9d34065.zip
data: do not allow usage of keypair just before hash removal
Diffstat (limited to 'src/noise.c')
-rw-r--r--src/noise.c10
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;