From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: netdev@vger.kernel.org
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com, josef@toxicpanda.com,
mason@kernel.org, steffen.klassert@secunet.com,
herbert@gondor.apana.org.au
Subject: [PATCH net] net: free the policies if a socket's clone fails late
Date: Sat, 17 Oct 2026 01:39:12 +0000 [thread overview]
Message-ID: <20261017013912.396296-1-alexei.starovoitov@gmail.com> (raw)
From: Josef Bacik <josef@toxicpanda.com>
sk_clone() clones the IPsec policies of the parent and then its BPF socket
storage. If the latter fails, the new socket is freed with sk_destruct
cleared, as it is still a raw copy of the parent. No code which knows about
the policies of a socket gets to see it, and the two policies which have
just been cloned are lost. They also stay on the list of all policies of
the network namespace and in its count of socket policies.
bpf_sk_storage_clone() fails if memory is short, or if the storage doesn't
fit into net.core.optmem_max.
Free the policies before leaving. This can't be done for all users of the
label: if the socket filter could not be charged, sk_policy[] still holds
the pointers of the parent.
Fixes: 8f51dfc73bf1 ("bpf: support cloning sk storage on accept()")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
net/core/sock.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index e8551df8330f..d311f56803ed 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2577,8 +2577,10 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,
goto free;
}
- if (bpf_sk_storage_clone(sk, newsk))
+ if (bpf_sk_storage_clone(sk, newsk)) {
+ xfrm_sk_free_policy(newsk);
goto free;
+ }
/* Clear sk_user_data if parent had the pointer tagged
* as not suitable for copying when cloning.
--
2.55.0
next reply other threads:[~2026-10-17 1:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 1:39 Alexei Starovoitov [this message]
2026-10-17 1:44 ` [PATCH net] net: free the policies if a socket's clone fails late netdev-bot+sinfo
2026-10-17 4:04 ` kuniyu
2026-10-18 2:15 ` netdev-bot+sashiko
2026-10-18 15:31 ` Alexei Starovoitov
2026-10-21 2:20 ` Jakub Kicinski
2026-10-21 3:00 ` Alexei Starovoitov
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=20261017013912.396296-1-alexei.starovoitov@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=josef@toxicpanda.com \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=netdev@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