From: WenTao Liang <vulab@iscas.ac.cn>
To: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: horms@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, WenTao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] net: af_key: fix refcount leak in pfkey_spdadd()
Date: Fri, 12 Jun 2026 00:37:43 +0800 [thread overview]
Message-ID: <20260611163743.99526-1-vulab@iscas.ac.cn> (raw)
In pfkey_spdadd(), an xfrm policy is allocated via xfrm_policy_alloc()
with a refcount of 1. On the success path the policy is eventually freed
by xfrm_pol_put(), which decrements the refcount and calls
xfrm_policy_destroy() only when it reaches zero. However, all error
paths directly call xfrm_policy_destroy() without releasing the initial
reference, leaking the policy object.
Fix the leak by replacing the direct xfrm_policy_destroy() call with
xfrm_pol_put() in the error unwind. Keep the xp->walk.dead assignment
as it is required by xfrm_policy_destroy()'s BUG_ON check.
Cc: stable@vger.kernel.org
Fixes: 64c31b3f7648 ("[XFRM] xfrm_policy_destroy: Rename and relative fixes.")
Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
---
net/key/af_key.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 9cffeef18cd9..013592086f1e 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -2370,7 +2370,7 @@ static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, const struct sadb_
out:
xp->walk.dead = 1;
- xfrm_policy_destroy(xp);
+ xfrm_pol_put(xp);
return err;
}
--
2.50.1 (Apple Git-155)
next reply other threads:[~2026-06-11 16:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 16:37 WenTao Liang [this message]
2026-06-11 17:49 ` Sabrina Dubroca
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260611163743.99526-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®