From: sashiko-bot@kernel.org
To: "Michal Luczaj" <mhal@rbox.co>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf 3/3] bpf: Unconditionally take socket references in lookup helpers
Date: Thu, 23 Jul 2026 16:20:20 +0000 [thread overview]
Message-ID: <20260723162021.3BB4D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723-sockmap-lookup-tcp-leak-v1-3-1bbdc58ce514@rbox.co>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] bpf_sk_assign() and sock_pfree() are vulnerable to the exact same reference leak via SOCK_RCU_FREE state transition that this patch fixes for bpf_sk_release().
--
--- Patch [3]: [PATCH bpf 3/3] bpf: Unconditionally take socket references in lookup helpers ---
commit a73ae21a3d81c1ea14d30abf4a0636c703e1fcfa
Author: Michal Luczaj <mhal@rbox.co>
bpf: Unconditionally take socket references in lookup helpers
This commit addresses a socket reference leak in BPF lookup helpers.
A socket refcounted at acquire time can gain SOCK_RCU_FREE before release,
causing the release to skip the put. The patch makes acquire and release
unconditional to fix this issue.
Closes: https://lore.kernel.org/bpf/20260701235552.2B0AA1F00A3F@smtp.kernel.org/
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 403aba3ce8913..4bc0b59668fae 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
[ ... ]
> @@ -7273,7 +7284,7 @@ static const struct bpf_func_proto bpf_tc_sk_lookup_udp_proto = {
>
> BPF_CALL_1(bpf_sk_release, struct sock *, sk)
> {
> - if (sk && sk_is_refcounted(sk))
> + if (sk)
> sock_gen_put(sk);
> return 0;
> }
[Severity: High]
This is a pre-existing issue, but bpf_sk_assign() and sock_pfree() appear to
be vulnerable to the exact same reference leak via SOCK_RCU_FREE state
transitions that this patch fixes for bpf_sk_release().
If a BPF program calls bpf_sk_assign() on an unbound or established socket,
it conditionally acquires a reference:
net/core/filter.c:bpf_sk_assign() {
...
if (sk_is_refcounted(sk) &&
unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
return -ENOENT;
skb_orphan(skb);
skb->sk = sk;
skb->destructor = sock_pfree;
...
}
Before the skb is freed, if the application calls listen() on the socket,
granting it the SOCK_RCU_FREE flag, what happens during destruction?
When the skb is destroyed, sock_pfree() dynamically re-evaluates
sk_is_refcounted(sk), which would now return false:
net/core/sock.c:sock_pfree() {
...
if (!sk_is_refcounted(sk))
return;
...
sock_gen_put(sk);
}
Would this cause sock_pfree() to return early and permanently leak the
reference acquired in bpf_sk_assign()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260723-sockmap-lookup-tcp-leak-v1-0-1bbdc58ce514@rbox.co?part=3
next prev parent reply other threads:[~2026-07-23 16:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260723-sockmap-lookup-tcp-leak-v1-0-1bbdc58ce514@rbox.co>
[not found] ` <20260723-sockmap-lookup-tcp-leak-v1-3-1bbdc58ce514@rbox.co>
2026-07-23 15:25 ` [PATCH bpf 3/3] bpf: Unconditionally take socket references in lookup helpers bot+bpf-ci
2026-07-23 16:20 ` sashiko-bot [this message]
[not found] ` <20260723-sockmap-lookup-tcp-leak-v1-1-1bbdc58ce514@rbox.co>
2026-07-25 0:00 ` [PATCH bpf 1/3] bpf, sockmap: Use sock_hold() instead of refcount_inc_not_zero() in lookup John Fastabend
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=20260723162021.3BB4D1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=mhal@rbox.co \
--cc=sashiko-reviews@lists.linux.dev \
/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