From: Florian Westphal <fw@strlen.de>
To: Sanghyun Park <sanghyun.park.cnu@gmail.com>
Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] xfrm: policy: Fix use-after-free on inexact bin in xfrm_policy_bysel_ctx()
Date: Fri, 29 May 2026 14:26:42 +0200 [thread overview]
Message-ID: <ahmGAgwpJx0OFKe7@strlen.de> (raw)
In-Reply-To: <CAOrxSK7v1BK_KsrfreHHAbfthAMDCZOBpOrCtzAjff1Wx-gr6w@mail.gmail.com>
Sanghyun Park <sanghyun.park.cnu@gmail.com> wrote:
> Fix by pruning the bin while still holding xfrm_policy_lock, before
> dropping it. Use __xfrm_policy_inexact_prune_bin() directly since the
> lock is already held. This is safe because the function uses
> kfree_rcu() for the actual free, which is non-blocking. The wrapper
> xfrm_policy_inexact_prune_bin() becomes unused and is removed.
>
> Race:
>
> CPU0 (XFRM_MSG_DELPOLICY) CPU1 (XFRM_MSG_NEWSPDINFO)
> ============================ ==========================
> xfrm_policy_bysel_ctx():
> spin_lock_bh(xfrm_policy_lock)
> bin = xfrm_policy_inexact_lookup()
> __xfrm_policy_unlink(pol)
> spin_unlock_bh(xfrm_policy_lock)
> xfrm_policy_kill(ret)
> // wide window, lock not held
> xfrm_hash_rebuild():
> spin_lock_bh(xfrm_policy_lock)
> __xfrm_policy_inexact_flush():
> kfree_rcu(bin) // bin freed
> spin_unlock_bh(xfrm_policy_lock)
> xfrm_policy_inexact_prune_bin(bin)
> // UAF: bin is freed
This changelog is fine, rest is too verbose.
> Fixes: 9cf545ebd5d8 ("xfrm: policy: implement selector-based inexact lookup")
There is no such commit, neither ID nor subject.
If you use AI assistance, please check for hallucinations.
Probably:
Fixes: 6be3b0db6db8 ("xfrm: policy: add inexact policy search tree infrastructure")
> + if (bin && ret && delete)
> + __xfrm_policy_inexact_prune_bin(bin, false);
Looks like this patch is whitespace-damaged.
Could you also say in changelog why you added the 3rd criterion?
> - if (bin && delete)
Became (bin && ret && delete).
prev parent reply other threads:[~2026-05-29 12:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 8:06 [PATCH] xfrm: policy: Fix use-after-free on inexact bin in xfrm_policy_bysel_ctx() Sanghyun Park
2026-05-29 12:26 ` Florian Westphal [this message]
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=ahmGAgwpJx0OFKe7@strlen.de \
--to=fw@strlen.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sanghyun.park.cnu@gmail.com \
--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