Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: af_key: fix refcount leak in pfkey_spdadd()
@ 2026-06-11 16:37 WenTao Liang
  2026-06-11 17:49 ` Sabrina Dubroca
  0 siblings, 1 reply; 2+ messages in thread
From: WenTao Liang @ 2026-06-11 16:37 UTC (permalink / raw)
  To: steffen.klassert, herbert, davem, edumazet, kuba, pabeni
  Cc: horms, netdev, linux-kernel, WenTao Liang, stable

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)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-11 17:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 16:37 [PATCH] net: af_key: fix refcount leak in pfkey_spdadd() WenTao Liang
2026-06-11 17:49 ` Sabrina Dubroca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox