* [PATCH net 0/2] tcp: fix congestion control UAFs in do_tcp_getsockopt()
@ 2026-08-21 18:24 Cen Zhang (Microsoft)
2026-08-21 18:24 ` [PATCH net 1/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CONGESTION) Cen Zhang (Microsoft)
2026-08-21 18:24 ` [PATCH net 2/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CC_INFO) Cen Zhang (Microsoft)
0 siblings, 2 replies; 5+ messages in thread
From: Cen Zhang (Microsoft) @ 2026-08-21 18:24 UTC (permalink / raw)
To: edumazet, ncardwell, davem, kuba, pabeni
Cc: kuniyu, horms, yhs, kafai, andriin, ast, netdev, bpf,
linux-kernel, AutonomousCodeSecurity, xmei5, tgopinath, kys,
blbllhy
do_tcp_getsockopt() has two lockless reads of icsk_ca_ops. Since BPF
struct_ops congestion control made icsk_ca_ops point to dynamically
allocated memory, a concurrent setsockopt(TCP_CONGESTION) can replace
the pointer and free the old object while either reader is using it.
Patch 1 fixes the TCP_CONGESTION path by copying ca_ops->name to a
stack buffer while holding rcu_read_lock().
Patch 2 fixes the TCP_CC_INFO path by keeping the ca_ops->get_info
lookup and call inside an RCU read-side critical section.
Eric Dumazet's related TCP data-race annotation work [1] adds
READ_ONCE()/WRITE_ONCE() annotations for lockless TCP socket field
accesses. icsk_ca_ops would similarly benefit from such annotations,
but that is an independent data-race concern. This series focuses
solely on the use-after-free fixes via rcu_read_lock().
[1]
https://lore.kernel.org/all/20260416200319.3608680-1-edumazet@google.com/
Cen Zhang (Microsoft) (2):
tcp: fix use-after-free in do_tcp_getsockopt(TCP_CONGESTION)
tcp: fix use-after-free in do_tcp_getsockopt(TCP_CC_INFO)
net/ipv4/tcp.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
base-commit: 746fc0787f616da418ffc04a110296fe95d53491
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net 1/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CONGESTION)
2026-08-21 18:24 [PATCH net 0/2] tcp: fix congestion control UAFs in do_tcp_getsockopt() Cen Zhang (Microsoft)
@ 2026-08-21 18:24 ` Cen Zhang (Microsoft)
2026-08-21 18:24 ` [PATCH net 2/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CC_INFO) Cen Zhang (Microsoft)
1 sibling, 0 replies; 5+ messages in thread
From: Cen Zhang (Microsoft) @ 2026-08-21 18:24 UTC (permalink / raw)
To: edumazet, ncardwell, davem, kuba, pabeni
Cc: kuniyu, horms, yhs, kafai, andriin, ast, netdev, bpf,
linux-kernel, AutonomousCodeSecurity, xmei5, tgopinath, kys,
blbllhy, stable
do_tcp_getsockopt() reads icsk->icsk_ca_ops->name without holding
rcu_read_lock(). Since commit 0baf26b0fcd7 ("bpf: tcp: Support
tcp_congestion_ops in bpf"), icsk_ca_ops can point to dynamically
allocated BPF struct_ops memory that may be freed concurrently via
setsockopt(TCP_CONGESTION), leading to a use-after-free.
BUG: KASAN: slab-use-after-free in _copy_to_user+0x37/0x60
Read of size 16 at addr ffff888013505260 by task exploit/149
_copy_to_user+0x37/0x60
do_tcp_getsockopt+0x158a/0x2460 (net/ipv4/tcp.c:4585)
tcp_getsockopt+0x91/0xf0
__sys_getsockopt+0xf7/0x170
Fix this by holding rcu_read_lock() around the ca_ops->name access and
copying the name to a stack buffer before releasing the lock.
Fixes: 0baf26b0fcd7 ("bpf: tcp: Support tcp_congestion_ops in bpf")
Reported-by: AutonomousCodeSecurity@microsoft.com
Reported-by: Xiang Mei (Microsoft) <xmei5@asu.edu>
Reported-by: Cen Zhang (Microsoft) <blbllhy@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Cen Zhang (Microsoft) <blbllhy@gmail.com>
---
The unsynchronized icsk_ca_ops load also constitutes a data race.
READ_ONCE()/WRITE_ONCE() annotations are intentionally left to a
separate change; related TCP annotation work is available at:
https://lore.kernel.org/all/20260416200319.3608680-1-edumazet@google.com/
net/ipv4/tcp.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index b4237d0e994d..7360ff718f1d 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -4577,16 +4577,23 @@ int do_tcp_getsockopt(struct sock *sk, int level,
val = !inet_csk_in_pingpong_mode(sk);
break;
- case TCP_CONGESTION:
+ case TCP_CONGESTION: {
+ char ca_name[TCP_CA_NAME_MAX] = {};
+
if (copy_from_sockptr(&len, optlen, sizeof(int)))
return -EFAULT;
len = min_t(unsigned int, len, TCP_CA_NAME_MAX);
if (copy_to_sockptr(optlen, &len, sizeof(int)))
return -EFAULT;
- if (copy_to_sockptr(optval, icsk->icsk_ca_ops->name, len))
+
+ rcu_read_lock();
+ memcpy(ca_name, icsk->icsk_ca_ops->name, sizeof(ca_name));
+ rcu_read_unlock();
+
+ if (copy_to_sockptr(optval, ca_name, len))
return -EFAULT;
return 0;
-
+ }
case TCP_ULP:
if (copy_from_sockptr(&len, optlen, sizeof(int)))
return -EFAULT;
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 2/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CC_INFO)
2026-08-21 18:24 [PATCH net 0/2] tcp: fix congestion control UAFs in do_tcp_getsockopt() Cen Zhang (Microsoft)
2026-08-21 18:24 ` [PATCH net 1/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CONGESTION) Cen Zhang (Microsoft)
@ 2026-08-21 18:24 ` Cen Zhang (Microsoft)
2026-08-21 18:39 ` Eric Dumazet
1 sibling, 1 reply; 5+ messages in thread
From: Cen Zhang (Microsoft) @ 2026-08-21 18:24 UTC (permalink / raw)
To: edumazet, ncardwell, davem, kuba, pabeni
Cc: kuniyu, horms, yhs, kafai, andriin, ast, netdev, bpf,
linux-kernel, AutonomousCodeSecurity, xmei5, tgopinath, kys,
blbllhy, stable
do_tcp_getsockopt() reads icsk->icsk_ca_ops and dereferences the
get_info function pointer without rcu_read_lock(). With BPF struct_ops
congestion control, ca_ops can point to dynamically allocated memory
that is freed concurrently, resulting in a use-after-free when the
kernel dereferences or calls through the stale pointer.
BUG: KASAN: slab-use-after-free in do_tcp_getsockopt+0x2037/0x23e0
Read of size 8 at addr ffff888013701258 by task exploit/149
do_tcp_getsockopt+0x2037/0x23e0 (net/ipv4/tcp.c:4564)
tcp_getsockopt+0x91/0xf0
__sys_getsockopt+0xf7/0x170
Fix this by wrapping the ca_ops load and get_info call within
rcu_read_lock()/rcu_read_unlock().
Fixes: 0baf26b0fcd7 ("bpf: tcp: Support tcp_congestion_ops in bpf")
Reported-by: AutonomousCodeSecurity@microsoft.com
Reported-by: Cen Zhang (Microsoft) <blbllhy@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Cen Zhang (Microsoft) <blbllhy@gmail.com>
---
The unsynchronized icsk_ca_ops load also constitutes a data race.
READ_ONCE()/WRITE_ONCE() annotations are intentionally left to a
separate change; related TCP annotation work is available at:
https://lore.kernel.org/all/20260416200319.3608680-1-edumazet@google.com/
net/ipv4/tcp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 7360ff718f1d..43ccd2d37f9c 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -4562,9 +4562,11 @@ int do_tcp_getsockopt(struct sock *sk, int level,
if (copy_from_sockptr(&len, optlen, sizeof(int)))
return -EFAULT;
+ rcu_read_lock();
ca_ops = icsk->icsk_ca_ops;
if (ca_ops && ca_ops->get_info)
sz = ca_ops->get_info(sk, ~0U, &attr, &info);
+ rcu_read_unlock();
len = min_t(unsigned int, len, sz);
if (copy_to_sockptr(optlen, &len, sizeof(int)))
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net 2/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CC_INFO)
2026-08-21 18:24 ` [PATCH net 2/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CC_INFO) Cen Zhang (Microsoft)
@ 2026-08-21 18:39 ` Eric Dumazet
2026-08-21 18:49 ` Cen Zhang (Microsoft)
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2026-08-21 18:39 UTC (permalink / raw)
To: Cen Zhang (Microsoft)
Cc: ncardwell, davem, kuba, pabeni, kuniyu, horms, yhs, kafai,
andriin, ast, netdev, bpf, linux-kernel, AutonomousCodeSecurity,
xmei5, tgopinath, kys, stable
On Fri, Aug 21, 2026 at 8:25 PM Cen Zhang (Microsoft) <blbllhy@gmail.com> wrote:
>
> do_tcp_getsockopt() reads icsk->icsk_ca_ops and dereferences the
> get_info function pointer without rcu_read_lock(). With BPF struct_ops
> congestion control, ca_ops can point to dynamically allocated memory
> that is freed concurrently, resulting in a use-after-free when the
> kernel dereferences or calls through the stale pointer.
>
> BUG: KASAN: slab-use-after-free in do_tcp_getsockopt+0x2037/0x23e0
> Read of size 8 at addr ffff888013701258 by task exploit/149
> do_tcp_getsockopt+0x2037/0x23e0 (net/ipv4/tcp.c:4564)
> tcp_getsockopt+0x91/0xf0
> __sys_getsockopt+0xf7/0x170
>
> Fix this by wrapping the ca_ops load and get_info call within
> rcu_read_lock()/rcu_read_unlock().
>
> Fixes: 0baf26b0fcd7 ("bpf: tcp: Support tcp_congestion_ops in bpf")
> Reported-by: AutonomousCodeSecurity@microsoft.com
> Reported-by: Cen Zhang (Microsoft) <blbllhy@gmail.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Cen Zhang (Microsoft) <blbllhy@gmail.com>
> ---
> The unsynchronized icsk_ca_ops load also constitutes a data race.
> READ_ONCE()/WRITE_ONCE() annotations are intentionally left to a
> separate change; related TCP annotation work is available at:
> https://lore.kernel.org/all/20260416200319.3608680-1-edumazet@google.com/
I don't understand.
This patch is incomplete. Please fix the remaining issues in a single
patch or series.
We have limited time; we don't want to revisit the same area in one month.
pw-bot: cr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net 2/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CC_INFO)
2026-08-21 18:39 ` Eric Dumazet
@ 2026-08-21 18:49 ` Cen Zhang (Microsoft)
0 siblings, 0 replies; 5+ messages in thread
From: Cen Zhang (Microsoft) @ 2026-08-21 18:49 UTC (permalink / raw)
To: edumazet
Cc: AutonomousCodeSecurity, andriin, ast, blbllhy, bpf, davem, horms,
kafai, kuba, kuniyu, kys, linux-kernel, ncardwell, netdev, pabeni,
stable, tgopinath, xmei5, yhs
Thanks for the review, Eric. I will send v2 with the data races fixed as
well.
Thanks,
Cen
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-21 18:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-21 18:24 [PATCH net 0/2] tcp: fix congestion control UAFs in do_tcp_getsockopt() Cen Zhang (Microsoft)
2026-08-21 18:24 ` [PATCH net 1/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CONGESTION) Cen Zhang (Microsoft)
2026-08-21 18:24 ` [PATCH net 2/2] tcp: fix use-after-free in do_tcp_getsockopt(TCP_CC_INFO) Cen Zhang (Microsoft)
2026-08-21 18:39 ` Eric Dumazet
2026-08-21 18:49 ` Cen Zhang (Microsoft)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox