From: Lin Jiapeng <ljp1205831794@gmail.com>
To: Jiayuan Chen <jiayuan.chen@linux.dev>,
Eric Dumazet <edumazet@kernel.org>,
Kuniyuki Iwashima <kuniyu@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Simon Horman <horms@kernel.org>,
Martin KaFai Lau <kafai@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: TencentOS Corvus AI <corvus@tencent.com>,
stable@vger.kernel.org, Lin Jiapeng <jiapenglin@tencent.com>
Subject: Re: [PATCH net] net: reuseport: avoid duplicate closed socket insertion
Date: Sat, 7 Nov 2026 16:08:03 +0800 [thread overview]
Message-ID: <05e77224-7d3a-42d5-9e08-82c7257cba34@gmail.com> (raw)
In-Reply-To: <6cb5fe89-c6f0-4e84-b753-4425b1aebe1e@linux.dev>
On 2026-11-07 1:02 p.m., Jiayuan Chen wrote:
>
> On 11/6/26 9:58 PM, Lin Jiapeng wrote:
>> Clearing SO_REUSEPORT on a TCP listener clears sk_reuseport but leaves
>> sk_reuseport_cb attached to its reuseport group.
>> ...
>> Repeated connect(AF_UNSPEC)/listen() cycles therefore insert the same
>> socket until num_closed_socks exceeds max_socks. The next insertion
>> writes before socks[], overlapping prog on x86-64 and leading to type
>> confusion when a reuseport program is attached or detached.
>
>
> Is the issue same as Eric's patch ?
>
> https://lore.kernel.org/netdev/20261106084300.2029567-1-edumazet@kernel.org/
These reports may be related, but analysis suggests that they seem
to have different root causes.
Eric's patch seems to prevent attaching a program to the same unhashed,
shutdown listener from resurrecting it into the listening section. My
patch addresses duplicate closed-section insertion after SO_REUSEPORT
is cleared, which may eventually make socks[-1] overwrite reuse->prog.
Eric's patch does not change reuseport_stop_listen_sock(). Also, my PoC
attaches the program on a separate, still-hashed anchor socket, so his
new check may not apply to this path.
I tested Eric's v2 patch with my unmodified PoC. His positive control
returned EINVAL, so the patch seems to be active. However, my PoC still
triggered the same UBSAN/KASAN failure. Since his patch did not stop my
reproducer, and the root causes appear to be different, I think these
may not be the same issue. The two fixes may therefore be complementary.
The following is the UBSAN/KASAN output with Eric's v2 patch applied:
[trigger] cycle 129/129 (vulnerable: socks[-1] overwrites prog)
[trigger] attaching CBPF after closed-region pump
------------[ cut here ]------------
UBSAN: array-index-out-of-bounds in
/Users/m00nb1rd/WorkSpace/vul-findings/reuseport-closed-region-negative-index-bpfprog-as-sock/repro-upstream/linux-eric-v2/net/core/sock_reuseport.c:153:9
index -1 is out of range for type 'struct sock *[]
__counted_by(max_socks)' (aka 'struct sock *[]')
CPU: 0 UID: 65534 PID: 22 Comm: poc Not tainted 7.4.0-rc1+ #1 PREEMPTLAZY
Call Trace:
<TASK>
dump_stack_lvl+0x23/0x30
ubsan_epilogue+0x5/0x30
__ubsan_handle_out_of_bounds+0x91/0xa0
reuseport_stop_listen_sock+0x290/0x310
? reuseport_stop_listen_sock+0x43/0x310
inet_unhash+0xd5/0x400
tcp_set_state+0x125/0x260
tcp_disconnect+0x47/0x1950
__inet_stream_connect+0x2d0/0xab0
? do_iter_readv_writev+0x25b/0x350
? vfs_writev+0x2e0/0x3c0
inet_stream_connect+0x57/0x90
__sys_connect+0x14b/0x1a0
__x64_sys_connect+0x71/0x80
do_syscall_64+0x6c/0x1d0
entry_SYSCALL_64_after_hwframe+0x4b/0x53
RIP: 0033:0x205560
...
...
</TASK>
---[ end trace ]---
Oops: general protection fault, probably for non-canonical address
0xdffffc000000008e: 0000 [#1] KASAN
KASAN: null-ptr-deref in range [0x0000000000000470-0x0000000000000477]
CPU: 0 UID: 65534 PID: 22 Comm: poc Not tainted 7.4.0-rc1+ #1 PREEMPTLAZY
RIP: 0010:call_rcu+0x10d/0x260
...
Call Trace:
<TASK>
? reuseport_attach_prog+0x6c/0x250
reuseport_attach_prog+0xdd/0x250
sk_reuseport_attach_filter+0x97/0xf0
sk_setsockopt+0x973/0x1cc0
do_sock_setsockopt+0xa9/0x120
__sys_setsockopt+0xaa/0xe0
__x64_sys_setsockopt+0xac/0xc0
do_syscall_64+0x6c/0x1d0
entry_SYSCALL_64_after_hwframe+0x4b/0x53
RIP: 0033:0x202f22
...
</TASK>
---[ end trace 0000000000000000 ]---
prev parent reply other threads:[~2026-11-07 8:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 13:58 Lin Jiapeng
2026-11-06 14:01 ` netdev-bot+sinfo
2026-11-06 14:55 ` Lin Jiapeng
2026-11-07 5:02 ` Jiayuan Chen
2026-11-07 8:08 ` Lin Jiapeng [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=05e77224-7d3a-42d5-9e08-82c7257cba34@gmail.com \
--to=ljp1205831794@gmail.com \
--cc=corvus@tencent.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jiapenglin@tencent.com \
--cc=jiayuan.chen@linux.dev \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®