From patchwork Thu Jul 2 11:52:22 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5071 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:1887:b0:869:83bc:8c48 with SMTP id r7csp550855max; Thu, 2 Jul 2026 04:53:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AFNElJ9Jq7nR1DRkTroQyWCpNVQmb/Y9PNcm+QTw5/IL4Ym4ZCot5voAIUZZMnZmwYNB+z2CJkRy6cAB64Q=@openvpn.net X-Received: by 2002:a05:6808:3999:b0:495:d5f7:c63a with SMTP id 5614622812f47-4960ed04ee5mr3885648b6e.4.1782993215336; Thu, 02 Jul 2026 04:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782993215; cv=none; d=google.com; s=arc-20260327; b=PLyvZLUT9AtW8m4kE7b+sMzZ9hh+n2+hkIiHgVNgCS8w68t890Ymshu168+/HFUbHF RI1Nyx4GA6jto6i2/Hp4yfBWBQkWBfdEcEh0JIrxXcDxMedJ+yzhNJ+rsYskf1mYdQme 7WEiazOYn/Mx0v1rHzl0ucBO83O45IIpWu6HnpcOfheuqMTxkWWbHiaWxnHCWbAJ2cd3 znpQhzmbghqHuIWOPZFaRac+yNqyA86I6PaKkMVfl59bi17L9v3682pzMYgOymdRlVNu syvAybl9x8fyFQuy7QusO/T3r4wJwTJRYkcr+R+rI22L26b0iCFykVxcrqvyxcn2ejRz Zktg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=W4GObJKFSkZ2gznX50uTcqghh5GM09ABkPrGbxpq45I=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=aQyu5OJQnYL/yDxEpuGTmSg35t9M9JgoRLJ+6IETqQAn19syl9M68C2ctOFnxfW5T2 Srw9FdNkq7Q4yvW9WxWkUdMwYcxif4wfCXzvV1RliDd8eeY2+VBhB6jA1Ksx5RP+QdFO VcoFJFavBG63TpD17EWZqpy7QKoRgn3MvQDcjeJ2apaeOKX/rgLXzKCl2d2qt39hWq6e AepCWhC5Nf6ZaBtPwaegPtYP2hAK4SpkcoIRDT2U7gdz1f9NsntLeZz2HVvv6O0XByc5 2iKaJ9ARyjaZJt5J9nbSNF62xTTPk6aHQqAP+DM3vOaZTTsZzX1YrpXpml5j2+MP4oCf 6iNg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=II2tTDXj; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Y5v+lNZf; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=iPMw3m2u; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Br5NBVaR; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-497d1839c64si1524340b6e.39.2026.07.02.04.53.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2026 04:53:35 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=II2tTDXj; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Y5v+lNZf; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=iPMw3m2u; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Br5NBVaR; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=W4GObJKFSkZ2gznX50uTcqghh5GM09ABkPrGbxpq45I=; b=II2tTDXjvSUj/5pjFJoOOqXZ6g Ou0DSpj9dvAbVAHX9FyNK0t+Ui+YHL8QizS3xr0g7BRZoVXqOyyq6YEDEud5kfVAYWG69PyQzflD9 FPB5ldDh25A7uPQCW0wRSo1y4dCwFRzz1KfQnvgZtR5oKeDIt1pkML+UFI5FACFPzrSc=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wfFz4-0007u7-PZ; Thu, 02 Jul 2026 11:53:32 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wfFz3-0007ty-WE for openvpn-devel@lists.sourceforge.net; Thu, 02 Jul 2026 11:53:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=gNNWQBHSgiSH6C5d4SGGsWn9cTB7lrv22EjfKfKw/FQ=; b=Y5v+lNZfYKyvnsezNS4oQIUoQB ZyVa0jjwzISUU/g9Vlz6rhQ5nE14EAwf7vAlR15C4lZaxSazpcnQl7LSYXQTzwu4vhtBHyNAtlv/g mThgiOFqjUMarOwDLrAPbfssT205AyL3TM+opRhwN5qRF2wP4hiy6zCvAAd8RJI9029Q=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=gNNWQBHSgiSH6C5d4SGGsWn9cTB7lrv22EjfKfKw/FQ=; b=iPMw3m2uW19HPS5r/rpLQP9cgt eSIc2X3QUd8eLHve+OEASKQej+/iKe+PropubRhlBgMF5EUxYAJlwNyEjtBH66x21yX5ZjplDQXhU 1cAeaBVq9/lVZcmivIo0ImLmf8e7Le3EtZXD9IDPbsDuRLBWRNFdOCWfbRuKSTAjlhHU=; Received: from mout-b-206.mailbox.org ([195.10.208.51]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wfFyz-0004KI-Gx for openvpn-devel@lists.sourceforge.net; Thu, 02 Jul 2026 11:53:31 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-206.mailbox.org (Postfix) with ESMTPS id 4grZyj0KHNz9xsT; Thu, 2 Jul 2026 13:53:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1782993197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gNNWQBHSgiSH6C5d4SGGsWn9cTB7lrv22EjfKfKw/FQ=; b=Br5NBVaRotQo18zNCGbsaooFr6lMfWyK1vh71dhgIA9fYArs4sGOrZ5z/95upng+/+9z6B FHi0+v6JxESiIsUIb21TDEExjvK+P3nBPH8W275yJO6Jkl6tSXxJOnbiKiS6tAHpV/BhgJ 8+IM96iF2fu3ldH2AFZBHojRmPvTC8CCR9gN+uFTlGB5E91iOj4y/6UAwQS9seqgL6wqAQ VkE6fw506YHqSI+x8nZ5eUphHSlBEQmOAaDNeqLgX7jofWm7MuuZdWgnnOBKkOgn+3I1wu lBkDGpSeJRAUF2bxufBo6b1O52VTTujbIpdpIHmEMcK8uBqxJ03i4xskBpM+4Q== From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Thu, 2 Jul 2026 13:52:22 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Epoch key rotation needs to replace encrypt and decrypt key contexts while packets may still hold references from the async AEAD path. Publish key contexts through RCU, add a per-context kref, and let encrypt and decrypt requests hold a context until their completion callback runs. Direct-key behavior is otherwise unchanged. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1wfFyz-0004KI-Gx Subject: [Openvpn-devel] [RFC ovpn net-next v2 07/14] ovpn: make key contexts refcounted X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1869603893577419601 X-GMAIL-MSGID: 1869603893577419601 Epoch key rotation needs to replace encrypt and decrypt key contexts while packets may still hold references from the async AEAD path. Publish key contexts through RCU, add a per-context kref, and let encrypt and decrypt requests hold a context until their completion callback runs. Direct-key behavior is otherwise unchanged. Signed-off-by: Ralf Lici --- No functional changes since v1 https://lore.kernel.org/openvpn-devel/4ae05d37fc69c2c29d83f824616b1aee6315ab6b.1782919654.git.ralf@mandelbit.com/ drivers/net/ovpn/crypto.h | 34 ++++++++++++++++++++-- drivers/net/ovpn/crypto_aead.c | 20 ++++++++++--- drivers/net/ovpn/crypto_key.c | 53 +++++++++++++++++++--------------- drivers/net/ovpn/io.c | 8 +++-- drivers/net/ovpn/skb.h | 2 ++ 5 files changed, 86 insertions(+), 31 deletions(-) diff --git a/drivers/net/ovpn/crypto.h b/drivers/net/ovpn/crypto.h index c36cd8299afd..1d62f2be23c9 100644 --- a/drivers/net/ovpn/crypto.h +++ b/drivers/net/ovpn/crypto.h @@ -10,6 +10,9 @@ #ifndef _NET_OVPN_OVPNCRYPTO_H_ #define _NET_OVPN_OVPNCRYPTO_H_ +#include +#include + #include "crypto_limits.h" #include "pktid.h" #include "proto.h" @@ -47,6 +50,8 @@ struct ovpn_key_ctx { struct ovpn_key_usage usage; atomic64_t decrypt_failures; unsigned long decrypt_failure_flags; + struct kref refcount; + struct rcu_head rcu; }; struct ovpn_crypto_key_slot { @@ -54,8 +59,8 @@ struct ovpn_crypto_key_slot { enum ovpn_cipher_alg cipher_alg; struct ovpn_limit usage_limit; - struct ovpn_key_ctx *encrypt; - struct ovpn_key_ctx *decrypt; + struct ovpn_key_ctx __rcu *encrypt; + struct ovpn_key_ctx __rcu *decrypt; struct kref refcount; struct rcu_head rcu; }; @@ -137,6 +142,31 @@ static inline void ovpn_crypto_key_slot_put(struct ovpn_crypto_key_slot *ks) kref_put(&ks->refcount, ovpn_crypto_key_slot_release); } +void ovpn_key_ctx_release(struct kref *kref); + +static inline void ovpn_key_ctx_put(struct ovpn_key_ctx *key) +{ + if (key) + kref_put(&key->refcount, ovpn_key_ctx_release); +} + +static inline int ovpn_key_ctx_get(struct ovpn_key_ctx **out, + struct ovpn_key_ctx __rcu **rcu_ptr) +{ + struct ovpn_key_ctx *key; + + rcu_read_lock(); + key = rcu_dereference(*rcu_ptr); + if (unlikely(!key || !kref_get_unless_zero(&key->refcount))) { + rcu_read_unlock(); + return -ENOKEY; + } + rcu_read_unlock(); + + *out = key; + return 0; +} + int ovpn_crypto_state_reset(struct ovpn_crypto_state *cs, const struct ovpn_peer_key_reset *pkr); diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 31f5327694d2..39bd320169d3 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -150,8 +150,8 @@ static struct scatterlist *ovpn_aead_crypto_req_sg(struct crypto_aead *aead, int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb) { - struct ovpn_key_ctx *key = ks->encrypt; unsigned int plaintext_len, tag_size; + struct ovpn_key_ctx *key = NULL; struct aead_request *req; struct sk_buff *trailer; struct scatterlist *sg; @@ -164,6 +164,12 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, ovpn_skb_cb(skb)->peer = peer; ovpn_skb_cb(skb)->ks = ks; plaintext_len = skb->len; + + ret = ovpn_key_ctx_get(&key, &ks->encrypt); + if (unlikely(ret)) + return ret; + ovpn_skb_cb(skb)->key = key; + tag_size = crypto_aead_authsize(key->tfm); /* Sample AEAD header format: @@ -263,8 +269,8 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb) { - struct ovpn_key_ctx *key = ks->decrypt; unsigned int payload_offset, tag_size; + struct ovpn_key_ctx *key = NULL; int ret, payload_len, nfrags; struct aead_request *req; struct sk_buff *trailer; @@ -272,13 +278,19 @@ int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, void *tmp; u8 *iv; + ovpn_skb_cb(skb)->peer = peer; + ovpn_skb_cb(skb)->ks = ks; + + ret = ovpn_key_ctx_get(&key, &ks->decrypt); + if (unlikely(ret)) + return ret; + ovpn_skb_cb(skb)->key = key; + tag_size = crypto_aead_authsize(key->tfm); payload_offset = ovpn_aead_direct_payload_offset(tag_size); payload_len = skb->len - payload_offset; ovpn_skb_cb(skb)->payload_offset = payload_offset; - ovpn_skb_cb(skb)->peer = peer; - ovpn_skb_cb(skb)->ks = ks; /* sanity check on packet size, payload size must be >= 0 */ if (unlikely(payload_len < 0)) diff --git a/drivers/net/ovpn/crypto_key.c b/drivers/net/ovpn/crypto_key.c index cdf35e2b241c..44110a0b38eb 100644 --- a/drivers/net/ovpn/crypto_key.c +++ b/drivers/net/ovpn/crypto_key.c @@ -82,6 +82,22 @@ static void ovpn_key_ctx_free(struct ovpn_key_ctx *key) kfree(key); } +static void ovpn_key_ctx_free_rcu(struct rcu_head *head) +{ + struct ovpn_key_ctx *key; + + key = container_of(head, struct ovpn_key_ctx, rcu); + ovpn_key_ctx_free(key); +} + +void ovpn_key_ctx_release(struct kref *kref) +{ + struct ovpn_key_ctx *key; + + key = container_of(kref, struct ovpn_key_ctx, refcount); + call_rcu(&key->rcu, ovpn_key_ctx_free_rcu); +} + static struct ovpn_key_ctx * ovpn_key_ctx_new(const char *title, const char *alg_name, const struct ovpn_key_direction *dir, bool encrypt) @@ -113,6 +129,7 @@ ovpn_key_ctx_new(const char *title, const char *alg_name, ovpn_key_usage_init(&key->usage); atomic64_set(&key->decrypt_failures, 0); key->decrypt_failure_flags = 0; + kref_init(&key->refcount); /* initialize only the packet ID direction this context owns */ if (encrypt) @@ -128,8 +145,8 @@ void ovpn_crypto_key_slot_destroy(struct ovpn_crypto_key_slot *ks) if (!ks) return; - ovpn_key_ctx_free(ks->encrypt); - ovpn_key_ctx_free(ks->decrypt); + ovpn_key_ctx_put(rcu_access_pointer(ks->encrypt)); + ovpn_key_ctx_put(rcu_access_pointer(ks->decrypt)); kfree(ks); } @@ -137,6 +154,7 @@ struct ovpn_crypto_key_slot * ovpn_crypto_key_slot_new(const struct ovpn_key_config *kc) { struct ovpn_crypto_key_slot *ks = NULL; + struct ovpn_key_ctx *key; const char *alg_name; int ret; @@ -168,21 +186,19 @@ ovpn_crypto_key_slot_new(const struct ovpn_key_config *kc) ks->cipher_alg = kc->cipher_alg; ovpn_key_usage_limit_init(&ks->usage_limit, kc->cipher_alg); - ks->encrypt = ovpn_key_ctx_new("encrypt", alg_name, &kc->encrypt, - true); - if (IS_ERR(ks->encrypt)) { - ret = PTR_ERR(ks->encrypt); - ks->encrypt = NULL; + key = ovpn_key_ctx_new("encrypt", alg_name, &kc->encrypt, true); + if (IS_ERR(key)) { + ret = PTR_ERR(key); goto destroy_ks; } + RCU_INIT_POINTER(ks->encrypt, key); - ks->decrypt = ovpn_key_ctx_new("decrypt", alg_name, &kc->decrypt, - false); - if (IS_ERR(ks->decrypt)) { - ret = PTR_ERR(ks->decrypt); - ks->decrypt = NULL; + key = ovpn_key_ctx_new("decrypt", alg_name, &kc->decrypt, false); + if (IS_ERR(key)) { + ret = PTR_ERR(key); goto destroy_ks; } + RCU_INIT_POINTER(ks->decrypt, key); return ks; @@ -193,17 +209,8 @@ ovpn_crypto_key_slot_new(const struct ovpn_key_config *kc) enum ovpn_cipher_alg ovpn_crypto_key_slot_alg(struct ovpn_crypto_key_slot *ks) { - const char *alg_name; - - if (!ks->encrypt || !ks->encrypt->tfm) + if (!ks) return OVPN_CIPHER_ALG_NONE; - alg_name = crypto_tfm_alg_name(crypto_aead_tfm(ks->encrypt->tfm)); - - if (!strcmp(alg_name, ALG_NAME_AES)) - return OVPN_CIPHER_ALG_AES_GCM; - else if (!strcmp(alg_name, ALG_NAME_CHACHAPOLY)) - return OVPN_CIPHER_ALG_CHACHA20_POLY1305; - else - return OVPN_CIPHER_ALG_NONE; + return ks->cipher_alg; } diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index 2b1df68a1b1e..006d83fe3e2a 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -125,14 +125,14 @@ void ovpn_decrypt_post(void *data, int ret) payload_offset = ovpn_skb_cb(skb)->payload_offset; ks = ovpn_skb_cb(skb)->ks; - key = ks->decrypt; + key = ovpn_skb_cb(skb)->key; peer = ovpn_skb_cb(skb)->peer; /* crypto is done, cleanup skb CB and its members */ kfree(ovpn_skb_cb(skb)->crypto_tmp); if (unlikely(ret == -EBADMSG)) { - if (unlikely(ovpn_aead_decrypt_failure_record(key))) + if (key && unlikely(ovpn_aead_decrypt_failure_record(key))) ovpn_nl_key_swap_notify(peer, ks->key_id); goto drop; } @@ -224,6 +224,7 @@ void ovpn_decrypt_post(void *data, int ret) ovpn_peer_put(peer); if (likely(ks)) ovpn_crypto_key_slot_put(ks); + ovpn_key_ctx_put(key); } /* RX path entry point: decrypt packet and forward it to the device */ @@ -256,6 +257,7 @@ void ovpn_encrypt_post(void *data, int ret) struct ovpn_crypto_key_slot *ks; struct sk_buff *skb = data; struct ovpn_socket *sock; + struct ovpn_key_ctx *key; struct ovpn_peer *peer; unsigned int orig_len; @@ -267,6 +269,7 @@ void ovpn_encrypt_post(void *data, int ret) ks = ovpn_skb_cb(skb)->ks; peer = ovpn_skb_cb(skb)->peer; + key = ovpn_skb_cb(skb)->key; /* crypto is done, cleanup skb CB and its members */ kfree(ovpn_skb_cb(skb)->crypto_tmp); @@ -322,6 +325,7 @@ void ovpn_encrypt_post(void *data, int ret) ovpn_peer_put(peer); if (likely(ks)) ovpn_crypto_key_slot_put(ks); + ovpn_key_ctx_put(key); kfree_skb(skb); } diff --git a/drivers/net/ovpn/skb.h b/drivers/net/ovpn/skb.h index 4fb7ea025426..75d64161d774 100644 --- a/drivers/net/ovpn/skb.h +++ b/drivers/net/ovpn/skb.h @@ -22,6 +22,7 @@ * struct ovpn_cb - ovpn skb control block * @peer: the peer this skb was received from/sent to * @ks: the crypto key slot used to encrypt/decrypt this skb + * @key: the key context used to encrypt/decrypt this skb * @crypto_tmp: pointer to temporary memory used for crypto operations * containing the IV, the scatter gather list and the aead request * @payload_offset: offset in the skb where the payload starts @@ -30,6 +31,7 @@ struct ovpn_cb { struct ovpn_peer *peer; struct ovpn_crypto_key_slot *ks; + struct ovpn_key_ctx *key; void *crypto_tmp; unsigned int payload_offset; bool nosignal;