From: Simon Horman <horms@kernel.org>
To: Kyuwon Cho <kyuwoncho18@gmail.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Josef Bacik <josef@toxicpanda.com>,
Alexei Starovoitov <ast@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>,
netdev@vger.kernel.org, ipsec@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH ipsec v3] net: free the socket policies when sk_clone() fails
Date: Fri, 4 Dec 2026 20:20:11 +0000 [thread overview]
Message-ID: <20261204202011.GH192805@horms.kernel.org> (raw)
In-Reply-To: <179568863376.462699.9896914557163021386@gmail.com>
On Fri, Nov 27, 2026 at 01:58:10PM +0900, Kyuwon Cho wrote:
> sk_clone() clones the parent's socket policies with
> xfrm_sk_clone_policy() and then its BPF socket storage with
> bpf_sk_storage_clone(). If either fails once a policy has been cloned,
> the new socket goes to the "free" label, which only clears sk_destruct
> and calls sk_free(), as the socket is still a raw copy of the parent.
> Nothing frees the cloned policies: they stay on the namespace's policy
> list and in its count, and the namespace teardown warns in
> xfrm_policy_fini().
>
> __xfrm_sk_clone_policy() fails that way when cloning the second policy
> fails, with the clone of the first already in the new socket.
> bpf_sk_storage_clone() fails when memory is short or when the copy does
> not fit into net.core.optmem_max.
>
> Free the policies in a new label at the end of the function. A failed
> filter charge still goes to the old one: xfrm_sk_clone_policy() has not
> run then, and sk_policy[] still holds the parent's pointers.
>
> Fixes: d188ba86dd07 ("xfrm: add rcu protection to sk->sk_policy[]")
> Fixes: 8f51dfc73bf1 ("bpf: support cloning sk storage on accept()")
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
> ---
> v3:
> - Free the policies at the end of sk_clone() instead of in
> __xfrm_sk_clone_policy(), so there is no unwind loop (Steffen), and a
> later failure of bpf_sk_storage_clone() is covered too (the AI review
> Steffen forwarded). This is the unwind Jakub asked for on Josef's
> patch for the second case:
> https://lore.kernel.org/all/20261020192044.7c3a58a1@kernel.org/
> - Hence the new subject; nothing in net/xfrm/ changes any more.
> v2: https://lore.kernel.org/all/179540803323.3139700.5340002553684152759@gmail.com/
> v1: https://lore.kernel.org/netdev/179505710269.3511679.8893709762919027206@gmail.com/
>
> Both cases reproduce as root in a new network namespace with a loopback
> TCP listener that has IP_XFRM_POLICY set in both directions. For the
> first, failslab fails the second clone_policy() (a stack filter on
> __xfrm_sk_clone_policy() and interval 2). For the second, the listener
> also gets an element of a BPF_F_CLONE sk_storage map, and
> net.core.optmem_max is then lowered so that the child's copy cannot be
> charged. Without the patch, the clones are left behind and the
> namespace teardown warns in xfrm_policy_fini(); with it, it does not.
>
> The patch was written with LLM assistance; we reviewed and tested it.
Reviewed-by: Simon Horman <horms@kernel.org>
prev parent reply other threads:[~2026-12-04 20:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 4:58 [PATCH ipsec v3] net: free the socket policies when sk_clone() fails Kyuwon Cho
2026-12-04 20:20 ` Simon Horman [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=20261204202011.GH192805@horms.kernel.org \
--to=horms@kernel.org \
--cc=ast@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=ipsec@lists.linux.dev \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=kyuwoncho18@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=steffen.klassert@secunet.com \
--cc=willemb@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.