public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: David Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	<netdev@vger.kernel.org>
Subject: [PATCH 5/8] xfrm: fix refcount leak in xfrm_migrate_policy_find
Date: Wed, 8 Apr 2026 11:59:01 +0200	[thread overview]
Message-ID: <20260408095925.253681-6-steffen.klassert@secunet.com> (raw)
In-Reply-To: <20260408095925.253681-1-steffen.klassert@secunet.com>

From: Kotlyarov Mihail <mihailkotlyarow@gmail.com>

syzkaller reported a memory leak in xfrm_policy_alloc:

  BUG: memory leak
  unreferenced object 0xffff888114d79000 (size 1024):
    comm "syz.1.17", pid 931
    ...
    xfrm_policy_alloc+0xb3/0x4b0 net/xfrm/xfrm_policy.c:432

The root cause is a double call to xfrm_pol_hold_rcu() in
xfrm_migrate_policy_find(). The lookup function already returns
a policy with held reference, making the second call redundant.

Remove the redundant xfrm_pol_hold_rcu() call to fix the refcount
imbalance and prevent the memory leak.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: 563d5ca93e88 ("xfrm: switch migrate to xfrm_policy_lookup_bytype")
Signed-off-by: Kotlyarov Mihail <mihailkotlyarow@gmail.com>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_policy.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 8f0188e763c7..a872af5610dc 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -4528,9 +4528,6 @@ static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector *
 	pol = xfrm_policy_lookup_bytype(net, type, &fl, sel->family, dir, if_id);
 	if (IS_ERR_OR_NULL(pol))
 		goto out_unlock;
-
-	if (!xfrm_pol_hold_rcu(pol))
-		pol = NULL;
 out_unlock:
 	rcu_read_unlock();
 	return pol;
-- 
2.43.0


  parent reply	other threads:[~2026-04-08  9:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08  9:58 [PATCH 0/8] pull request (net): ipsec 2026-04-08 Steffen Klassert
2026-04-08  9:58 ` [PATCH 1/8] xfrm: clear trailing padding in build_polexpire() Steffen Klassert
2026-04-08  9:58 ` [PATCH 2/8] xfrm: account XFRMA_IF_ID in aevent size calculation Steffen Klassert
2026-04-08  9:58 ` [PATCH 3/8] xfrm: Wait for RCU readers during policy netns exit Steffen Klassert
2026-04-08  9:59 ` [PATCH 4/8] xfrm: hold dev ref until after transport_finish NF_HOOK Steffen Klassert
2026-04-08  9:59 ` Steffen Klassert [this message]
2026-04-08  9:59 ` [PATCH 6/8] xfrm_user: fix info leak in build_mapping() Steffen Klassert
2026-04-08  9:59 ` [PATCH 7/8] xfrm_user: fix info leak in build_report() Steffen Klassert
2026-04-08  9:59 ` [PATCH 8/8] net: af_key: zero aligned sockaddr tail in PF_KEY exports Steffen Klassert

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=20260408095925.253681-6-steffen.klassert@secunet.com \
    --to=steffen.klassert@secunet.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    /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