BPF List
 help / color / mirror / Atom feed
* [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check
@ 2026-12-04  9:01 Paul Moses
  2026-12-04  9:01 ` [PATCH bpf v2 1/3] tcp: reset congestion-control state when the route selects a new CA Paul Moses
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Paul Moses @ 2026-12-04  9:01 UTC (permalink / raw)
  To: bpf
  Cc: netdev, ast, daniel, martin.lau, edumazet, ncardwell, kuniyu,
	jiayuan.chen, Paul Moses

Patches 1 and 2 fix the cases Alexei reported [1]: stale CA state
when a route changes the algorithm or a child inherits the listener's
private state. Patch 3 uses the same name for the CDG check and lookup.

Patch 2 needs Jiayuan's fix [2] so the clone hook runs after the
child's CA state is cleared.

I left the callback issue [3] out after reading more historical context.

v1..v2: Add the two TCP fixes. The original BPF fix is patch 3.
v1: https://lore.kernel.org/bpf/20261130065659.621451-1-p@1g4.org/

splats:
p1:  BUG: KASAN: invalid-free in tcp_cdg_release+0x38/0xac
p2:  BUG: KASAN: slab-out-of-bounds in tcp_cdg_cong_avoid+0xe14/0x11c4
p3:  BUG: KASAN: double-free in tcp_cdg_release+0x38/0xac

refs:
[1] https://lore.kernel.org/netdev/DNASOXUN4KAE.1IJL3LGF4E1DO@gmail.com/
[2] https://lore.kernel.org/bpf/20261130041156.295524-1-jiayuan.chen@linux.dev/
[3] https://lore.kernel.org/bpf/2R3IejGOudqccITwe2YD7Iz6tMgFlLhGy12eQ3HWVSx-QgFb0uWBGA_WKHCHq0967iKpsbRJL4sEpxGciBlGFKs6kwBBauQLCWEiza-qes8=@1g4.org/

Paul Moses (3):
  tcp: reset congestion-control state when the route selects a new CA
  tcp: clear inherited congestion-control state for a cloned child
  bpf: check and set TCP congestion control from the same name

 net/core/filter.c        | 11 ++++++++---
 net/ipv4/tcp_minisocks.c |  3 +++
 net/ipv4/tcp_output.c    | 10 ++++++++--
 3 files changed, 19 insertions(+), 5 deletions(-)


base-commit: 007722b8211f7b34fdf21b1e6a9c32497633ea29
prerequisite-patch-id: ccd3c308caecec9d14cd15ceef9b817171f77b1f
-- 
2.56.0.lol.gf7de81456940



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH bpf v2 1/3] tcp: reset congestion-control state when the route selects a new CA
  2026-12-04  9:01 [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Paul Moses
@ 2026-12-04  9:01 ` Paul Moses
  2026-12-04  9:01 ` [PATCH bpf v2 2/3] tcp: clear inherited congestion-control state for a cloned child Paul Moses
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Paul Moses @ 2026-12-04  9:01 UTC (permalink / raw)
  To: bpf
  Cc: netdev, ast, daniel, martin.lau, edumazet, ncardwell, kuniyu,
	jiayuan.chen, Paul Moses, stable

tcp_ca_dst_init() drops the reference to the old CA and installs the
route's CA without calling the old release callback or clearing
icsk_ca_priv. If icsk_ca_initialized is set, tcp_init_transfer()
skips initialization of the new CA. When the route selects CDG,
tcp_cdg_release() can then free a pointer CDG never allocated.

Run tcp_cleanup_congestion_control() and clear icsk_ca_priv before
installing different ops. If the route selects the current ops, drop
only the extra reference and keep the socket's state.

Fixes: 81164413ad09 ("net: tcp: add per route congestion control")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/netdev/DNASOXUN4KAE.1IJL3LGF4E1DO@gmail.com/
Cc: stable@vger.kernel.org
Signed-off-by: Paul Moses <p@1g4.org>
---
 net/ipv4/tcp_output.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 043838d99640..fd78a35edb85 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -4159,9 +4159,15 @@ static void tcp_ca_dst_init(struct sock *sk, const struct dst_entry *dst)
 	rcu_read_lock();
 	ca = tcp_ca_find_key(ca_key);
 	if (likely(ca && bpf_try_module_get(ca, ca->owner))) {
-		bpf_module_put(icsk->icsk_ca_ops, icsk->icsk_ca_ops->owner);
+		if (ca == icsk->icsk_ca_ops) {
+			bpf_module_put(ca, ca->owner);
+		} else {
+			tcp_cleanup_congestion_control(sk);
+			memset(icsk->icsk_ca_priv, 0,
+			       sizeof(icsk->icsk_ca_priv));
+			WRITE_ONCE(icsk->icsk_ca_ops, ca);
+		}
 		icsk->icsk_ca_dst_locked = tcp_ca_dst_locked(dst);
-		WRITE_ONCE(icsk->icsk_ca_ops, ca);
 	}
 	rcu_read_unlock();
 }
-- 
2.56.0.lol.gf7de81456940



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf v2 2/3] tcp: clear inherited congestion-control state for a cloned child
  2026-12-04  9:01 [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Paul Moses
  2026-12-04  9:01 ` [PATCH bpf v2 1/3] tcp: reset congestion-control state when the route selects a new CA Paul Moses
@ 2026-12-04  9:01 ` Paul Moses
  2026-12-04  9:01 ` [PATCH bpf v2 3/3] bpf: check and set TCP congestion control from the same name Paul Moses
  2026-12-04 21:04 ` [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Alexei Starovoitov
  3 siblings, 0 replies; 6+ messages in thread
From: Paul Moses @ 2026-12-04  9:01 UTC (permalink / raw)
  To: bpf
  Cc: netdev, ast, daniel, martin.lau, edumazet, ncardwell, kuniyu,
	jiayuan.chen, Paul Moses, stable

tcp_create_openreq_child() copies icsk_ca_priv and icsk_ca_initialized
from the listener. tcp_ca_openreq_child() can select a different CA
for the child without clearing either field. If the child uses CDG,
tcp_cdg_init() allocates a new gradients array but leaves the copied
tail index in place. That index can be outside the new array.

Clear icsk_ca_priv and reset icsk_ca_initialized before selecting the
child's CA and calling tcp_set_ca_state(). Do not run the listener's
release callback on the copy.

Fixes: 81164413ad09 ("net: tcp: add per route congestion control")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/netdev/DNASOXUN4KAE.1IJL3LGF4E1DO@gmail.com/
Cc: stable@vger.kernel.org
Signed-off-by: Paul Moses <p@1g4.org>
---
Backport prereq: apply Jiayuan Chen's clone-hook ordering fix
                 first, so the child cannot already own CA state 
                 at the reset below:
https://lore.kernel.org/bpf/20261130041156.295524-1-jiayuan.chen@linux.dev/

 net/ipv4/tcp_minisocks.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 934012cdac27..2f9f84bf8768 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -500,6 +500,9 @@ void tcp_ca_openreq_child(struct sock *sk, const struct dst_entry *dst)
 	u32 ca_key = dst_metric(dst, RTAX_CC_ALGO);
 	bool ca_got_dst = false;
 
+	icsk->icsk_ca_initialized = 0;
+	memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));
+
 	if (ca_key != TCP_CA_UNSPEC) {
 		const struct tcp_congestion_ops *ca;
 
-- 
2.56.0.lol.gf7de81456940



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf v2 3/3] bpf: check and set TCP congestion control from the same name
  2026-12-04  9:01 [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Paul Moses
  2026-12-04  9:01 ` [PATCH bpf v2 1/3] tcp: reset congestion-control state when the route selects a new CA Paul Moses
  2026-12-04  9:01 ` [PATCH bpf v2 2/3] tcp: clear inherited congestion-control state for a cloned child Paul Moses
@ 2026-12-04  9:01 ` Paul Moses
  2026-12-04 21:04 ` [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Alexei Starovoitov
  3 siblings, 0 replies; 6+ messages in thread
From: Paul Moses @ 2026-12-04  9:01 UTC (permalink / raw)
  To: bpf
  Cc: netdev, ast, daniel, martin.lau, edumazet, ncardwell, kuniyu,
	jiayuan.chen, Paul Moses, stable

sol_tcp_sockopt_congestion() checks the name in optval and rejects
"cdg". do_tcp_setsockopt() then copies the name from optval for lookup.
If optval points into a shared BPF map, an update between the check and
the copy can select CDG even though the check passed.

Copy the name into a bounded local buffer and use that copy for both
the CDG check and the TCP_CONGESTION request. Keep the check before the
recursion guard so a request for CDG still returns -ENOTSUPP.

Fixes: eb18b49ea758 ("bpf: tcp: Allow bpf-tcp-cc to call bpf_(get|set)sockopt")
Cc: stable@vger.kernel.org
Signed-off-by: Paul Moses <p@1g4.org>
---
 net/core/filter.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index b7d38b075ef3..87d4191339b5 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5692,8 +5692,9 @@ static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname,
 static int sol_tcp_sockopt_congestion(struct sock *sk, char *optval,
 				      int *optlen, bool getopt)
 {
+	char name[TCP_CA_NAME_MAX];
 	struct tcp_sock *tp;
-	int ret;
+	int len, ret;
 
 	if (*optlen < 2)
 		return -EINVAL;
@@ -5708,11 +5709,15 @@ static int sol_tcp_sockopt_congestion(struct sock *sk, char *optval,
 					 KERNEL_SOCKPTR(optlen));
 	}
 
+	len = min_t(int, *optlen, sizeof(name) - 1);
+	memcpy(name, optval, len);
+	name[len] = '\0';
+
 	/* "cdg" is the only cc that alloc a ptr
 	 * in inet_csk_ca area.  The bpf-tcp-cc may
 	 * overwrite this ptr after switching to cdg.
 	 */
-	if (*optlen >= sizeof("cdg") - 1 && !strncmp("cdg", optval, *optlen))
+	if (!strcmp(name, "cdg"))
 		return -ENOTSUPP;
 
 	/* It stops this looping
@@ -5737,7 +5742,7 @@ static int sol_tcp_sockopt_congestion(struct sock *sk, char *optval,
 
 	tp->bpf_chg_cc_inprogress = 1;
 	ret = do_tcp_setsockopt(sk, SOL_TCP, TCP_CONGESTION,
-				KERNEL_SOCKPTR(optval), *optlen);
+				KERNEL_SOCKPTR(name), len);
 	tp->bpf_chg_cc_inprogress = 0;
 	return ret;
 }
-- 
2.56.0.lol.gf7de81456940



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check
  2026-12-04  9:01 [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Paul Moses
                   ` (2 preceding siblings ...)
  2026-12-04  9:01 ` [PATCH bpf v2 3/3] bpf: check and set TCP congestion control from the same name Paul Moses
@ 2026-12-04 21:04 ` Alexei Starovoitov
  2026-12-04 21:26   ` Paul Moses
  3 siblings, 1 reply; 6+ messages in thread
From: Alexei Starovoitov @ 2026-12-04 21:04 UTC (permalink / raw)
  To: Paul Moses, bpf
  Cc: netdev, daniel, martin.lau, edumazet, ncardwell, kuniyu,
	jiayuan.chen

On Fri, Dec 04, 2026 at 01:01 AM Paul Moses <p@1g4.org> wrote:
> Patches 1 and 2 fix the cases Alexei reported [1]: stale CA state
> when a route changes the algorithm or a child inherits the listener's
> private state. Patch 3 uses the same name for the CDG check and lookup.

tcp fixes go via net tree.
Patch 1 fixes a tcp bug. bpf is not needed to hit it.
Use setsockopt("vegas") instead of bpf_cc in the sequence from [1].
tcp_vegas_init() sets minRTT and baseRTT to 0x7fffffff.
They are at offsets 16 and 20 of icsk_ca_priv.
cdg keeps ca->gradients there.
tcp_init_transfer() skips tcp_cdg_init(), so tcp_cdg_grad() and
tcp_cdg_release() see ca->gradients == 0x7fffffff7fffffff.

> Patch 2 needs Jiayuan's fix [2] so the clone hook runs after the
> child's CA state is cleared.

It doesn't.
Without [2] the lsm prog can init a cc on the child before
tcp_ca_openreq_child() runs.
The reset drops that state without ->release().
cdg is the only in-tree cc with ->release(), and bpf_setsockopt()
refuses cdg. So there is nothing to free.
A bpf cc gets ->init() twice. That's all.
Patches 1 and 2 don't depend on [2]. The backports don't either.

> I left the callback issue [3] out after reading more historical context.

In [3] you asked whether bpf_setsockopt(TCP_CONGESTION) can be limited
to .init.
No. It doesn't help.
.init of a bpf cc can write icsk_ca_priv after bpf_setsockopt() returns.

Pls resend patches 1 and 2 as [PATCH net].
Pls resend patch 3 alone as [PATCH bpf v3]. It doesn't depend on them.

pw-bot: cr

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check
  2026-12-04 21:04 ` [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Alexei Starovoitov
@ 2026-12-04 21:26   ` Paul Moses
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Moses @ 2026-12-04 21:26 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: bpf, netdev, daniel, martin.lau, edumazet, ncardwell, kuniyu,
	jiayuan.chen

> > Patch 2 needs Jiayuan's fix [2] so the clone hook runs after the
> > child's CA state is cleared.
> 
> It doesn't.
> Without [2] the lsm prog can init a cc on the child before
> tcp_ca_openreq_child() runs.
> The reset drops that state without ->release().
> cdg is the only in-tree cc with ->release(), and bpf_setsockopt()
> refuses cdg. So there is nothing to free.
> A bpf cc gets ->init() twice. That's all.
> Patches 1 and 2 don't depend on [2]. The backports don't either.
> 

Sorry, I should have been more clear why it's needed.

1. Listener selects ca_noswitch → listener owns the only struct_ops map reference.
2. Link and map fd are closed.
3. Child inherits icsk_ca_ops = ca_noswitch but takes no reference.
4. LSM hook switches child to cubic → tcp_cleanup_congestion_control() drops the
   listener’s map reference.
5. Map is freed.
6. Listener close touches the dangling icsk_ca_ops

Run /init as init process
BPF_LSM_CGROUP attach ret=0 errno=22
listener ca_noswitch ret=0 errno=22
CA LINK/OBJ CLOSED
connect ret=0 errno=22
accept ret=5 errno=22
CHILD_CC=cubic
sleep before listener close
listener closed==================================================================
BUG: KASAN: slab-use-after-free in tcp_cleanup_congestion_control+0xcc/0x170

Read of size 8 at addr ffff000005bcdbb0 by task lsm_mapreg/55

CPU: 0 UID: 0 PID: 55 Comm: lsm_mapreg Not tainted 7.4.0-rc5+ #13 PREEMPT 
DONEHardware name: linux,dummy-virt (DT)
Call trace:

 show_stack+0x1c/0x30 (C)
 __dump_stack+0x24/0x30
 dump_stack_lvl+0x60/0x80
 print_report+0xd4/0x248
 kasan_report+0x88/0xc0
 __asan_report_load8_noabort+0x1c/0x28
 tcp_cleanup_congestion_control+0xcc/0x170
 tcp_v4_destroy_sock+0x14c/0x410
 inet_csk_destroy_sock+0x104/0x210
 __tcp_close+0x77c/0x9e0
 tcp_close+0x30/0xf8
 inet_release+0x114/0x180
 __sock_release+0x9c/0x1b8
 sock_close+0x1c/0x30
 __fput+0x140/0x3c0
 fput_close_sync+0x94/0x1c0
 __arm64_sys_close+0x7c/0xc8
 do_el0_svc+0x134/0x1e0
 el0_svc+0x40/0x100
 el0t_64_sync_handler+0x40/0x100
 el0t_64_sync+0x154/0x158

Allocated by task 55:
 kasan_save_track+0x3c/0x80
 kasan_save_alloc_info+0x3c/0x48
 __kasan_kmalloc+0x98/0xb0
 __kmalloc_node_noprof+0x2e8/0x5f0
 __bpf_map_area_alloc+0x80/0x188
 bpf_map_area_alloc+0x18/0x28
 bpf_struct_ops_map_alloc+0x1b8/0x580
 map_create+0x610/0xfe8
 __sys_bpf+0x190/0x538
 __arm64_sys_bpf+0xd0/0xf0
 do_el0_svc+0x134/0x1e0
 el0_svc+0x40/0x100
 el0t_64_sync_handler+0x40/0x100
 el0t_64_sync+0x154/0x158

Freed by task 41:
 kasan_save_track+0x3c/0x80
 kasan_save_free_info+0x50/0x68
 __kasan_slab_free+0x90/0xc0
 kfree+0x160/0x558
 kvfree+0x34/0x48
 bpf_map_area_free+0x14/0x28
 __bpf_struct_ops_map_free+0x158/0x1b0
 bpf_struct_ops_map_free+0x100/0x130
 bpf_map_free+0x170/0x3f8
 bpf_map_free_deferred+0x98/0xe0
 process_scheduled_works+0x794/0xf80
 worker_thread+0x660/0xa10
 kthread+0x2ac/0x3b0
 ret_from_fork+0x10/0x20

Last potentially related work creation:
 kasan_save_stack+0x3c/0x68
 __kasan_record_aux_stack+0xbc/0xd0
 kasan_record_aux_stack+0x10/0x18
 insert_work+0x40/0x150
 __queue_work+0x950/0xea0
 queue_work_on+0x90/0xc8
 bpf_map_free_in_work+0x100/0x120
 bpf_map_free_rcu_gp+0x18/0x28
 srcu_invoke_callbacks+0x22c/0x4d0
 process_scheduled_works+0x794/0xf80
 worker_thread+0x660/0xa10
 kthread+0x2ac/0x3b0
 ret_from_fork+0x10/0x20

The buggy address belongs to the object at ffff000005bcd800
 which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 944 bytes inside of
 freed 1024-byte region [ffff000005bcd800, ffff000005bcdc00)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x45bc8
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x40(head|zone=0)
page_type: f5(slab)
raw: 0000000000000040 ffff0000048030c0 fffffdffc0315e10 fffffdffc0345010
raw: 0000000000000000 00000000000a000a 00000000f5000000 0000000000000000
head: 0000000000000040 ffff0000048030c0 fffffdffc0315e10 fffffdffc0345010
head: 0000000000000000 00000000000a000a 00000000f5000000 0000000000000000
head: 0000000000000003 fffffdffc016f201 00000000ffffffff 00000000ffffffff
head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff000005bcda80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff000005bcdb00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff000005bcdb80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                     ^
 ffff000005bcdc00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff000005bcdc80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================
Disabling lock debugging due to kernel taint
==================================================================
BUG: KASAN: slab-use-after-free in bpf_map_put+0x2c/0x1a0
Write of size 8 at addr ffff000005bcd918 by task lsm_mapreg/55

CPU: 0 UID: 0 PID: 55 Comm: lsm_mapreg Tainted: G    B               7.4.0-rc5+ #13 PREEMPT 
Tainted: [B]=BAD_PAGE
Hardware name: linux,dummy-virt (DT)
Call trace:
 show_stack+0x1c/0x30 (C)
 __dump_stack+0x24/0x30
 dump_stack_lvl+0x60/0x80
 print_report+0xd4/0x248
 kasan_report+0x88/0xc0
 kasan_check_range+0x174/0x1a8
 __kasan_check_write+0x1c/0x28
 bpf_map_put+0x2c/0x1a0
 bpf_struct_ops_put+0x18/0x28
 tcp_cleanup_congestion_control+0x108/0x170
 tcp_v4_destroy_sock+0x14c/0x410
 inet_csk_destroy_sock+0x104/0x210
 __tcp_close+0x77c/0x9e0
 tcp_close+0x30/0xf8
 inet_release+0x114/0x180
 __sock_release+0x9c/0x1b8
 sock_close+0x1c/0x30
 __fput+0x140/0x3c0
 fput_close_sync+0x94/0x1c0
 __arm64_sys_close+0x7c/0xc8
 do_el0_svc+0x134/0x1e0
 el0_svc+0x40/0x100
 el0t_64_sync_handler+0x40/0x100
 el0t_64_sync+0x154/0x158

Allocated by task 55:
 kasan_save_track+0x3c/0x80
 kasan_save_alloc_info+0x3c/0x48
 __kasan_kmalloc+0x98/0xb0
 __kmalloc_node_noprof+0x2e8/0x5f0
 __bpf_map_area_alloc+0x80/0x188
 bpf_map_area_alloc+0x18/0x28
 bpf_struct_ops_map_alloc+0x1b8/0x580
 map_create+0x610/0xfe8
 __sys_bpf+0x190/0x538
 __arm64_sys_bpf+0xd0/0xf0
 do_el0_svc+0x134/0x1e0
 el0_svc+0x40/0x100
 el0t_64_sync_handler+0x40/0x100
 el0t_64_sync+0x154/0x158

Freed by task 41:
 kasan_save_track+0x3c/0x80
 kasan_save_free_info+0x50/0x68
 __kasan_slab_free+0x90/0xc0
 kfree+0x160/0x558
 kvfree+0x34/0x48
 bpf_map_area_free+0x14/0x28
 __bpf_struct_ops_map_free+0x158/0x1b0
 bpf_struct_ops_map_free+0x100/0x130
 bpf_map_free+0x170/0x3f8
 bpf_map_free_deferred+0x98/0xe0
 process_scheduled_works+0x794/0xf80
 worker_thread+0x660/0xa10
 kthread+0x2ac/0x3b0
 ret_from_fork+0x10/0x20

Last potentially related work creation:
 kasan_save_stack+0x3c/0x68
 __kasan_record_aux_stack+0xbc/0xd0
 kasan_record_aux_stack+0x10/0x18
 insert_work+0x40/0x150
 __queue_work+0x950/0xea0
 queue_work_on+0x90/0xc8
 bpf_map_free_in_work+0x100/0x120
 bpf_map_free_rcu_gp+0x18/0x28
 srcu_invoke_callbacks+0x22c/0x4d0
 process_scheduled_works+0x794/0xf80
 worker_thread+0x660/0xa10
 kthread+0x2ac/0x3b0
 ret_from_fork+0x10/0x20

The buggy address belongs to the object at ffff000005bcd800
 which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 280 bytes inside of
 freed 1024-byte region [ffff000005bcd800, ffff000005bcdc00)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x45bc8
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x40(head|zone=0)
page_type: f5(slab)
raw: 0000000000000040 ffff0000048030c0 fffffdffc0315e10 fffffdffc0345010
raw: 0000000000000000 00000000000a000a 00000000f5000000 0000000000000000
head: 0000000000000040 ffff0000048030c0 fffffdffc0315e10 fffffdffc0345010
head: 0000000000000000 00000000000a000a 00000000f5000000 0000000000000000
head: 0000000000000003 fffffdffc016f201 00000000ffffffff 00000000ffffffff
head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff000005bcd800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff000005bcd880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff000005bcd900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                            ^
 ffff000005bcd980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff000005bcda00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
LSM_MAPREG_EXIT=0
 dump_stack_lvl+0x60/0x80
 print_report+0xd4/0x248
 kasan_report+0x88/0xc0
 __asan_report_load8_noabort+0x1c/0x28
 tcp_cleanup_congestion_control+0xcc/0x170
 tcp_v4_destroy_sock+0x14c/0x410
 inet_csk_destroy_sock+0x104/0x210
 __tcp_close+0x77c/0x9e0
 tcp_close+0x30/0xf8
 inet_release+0x114/0x180
 __sock_release+0x9c/0x1b8
 sock_close+0x1c/0x30
 __fput+0x140/0x3c0
 fput_close_sync+0x94/0x1c0
 __arm64_sys_close+0x7c/0xc8
 do_el0_svc+0x134/0x1e0
 el0_svc+0x40/0x100
 el0t_64_sync_handler+0x40/0x100
 el0t_64_sync+0x154/0x158

Allocated by task 55:
 kasan_save_track+0x3c/0x80
 kasan_save_alloc_info+0x3c/0x48
 __kasan_kmalloc+0x98/0xb0
 __kmalloc_node_noprof+0x2e8/0x5f0
 __bpf_map_area_alloc+0x80/0x188
 bpf_map_area_alloc+0x18/0x28
 bpf_struct_ops_map_alloc+0x1b8/0x580
 map_create+0x610/0xfe8
 __sys_bpf+0x190/0x538
 __arm64_sys_bpf+0xd0/0xf0
 do_el0_svc+0x134/0x1e0
 el0_svc+0x40/0x100
 el0t_64_sync_handler+0x40/0x100
 el0t_64_sync+0x154/0x158

Freed by task 41:
 kasan_save_track+0x3c/0x80
 kasan_save_free_info+0x50/0x68
 __kasan_slab_free+0x90/0xc0
 kfree+0x160/0x558
 kvfree+0x34/0x48
 bpf_map_area_free+0x14/0x28
 __bpf_struct_ops_map_free+0x158/0x1b0
 bpf_struct_ops_map_free+0x100/0x130
 bpf_map_free+0x170/0x3f8
 bpf_map_free_deferred+0x98/0xe0
 process_scheduled_works+0x794/0xf80
 worker_thread+0x660/0xa10
 kthread+0x2ac/0x3b0
 ret_from_fork+0x10/0x20

Last potentially related work creation:
 kasan_save_stack+0x3c/0x68
 __kasan_record_aux_stack+0xbc/0xd0
 kasan_record_aux_stack+0x10/0x18
 insert_work+0x40/0x150
 __queue_work+0x950/0xea0
 queue_work_on+0x90/0xc8
 bpf_map_free_in_work+0x100/0x120
 bpf_map_free_rcu_gp+0x18/0x28
 srcu_invoke_callbacks+0x22c/0x4d0
 process_scheduled_works+0x794/0xf80
 worker_thread+0x660/0xa10
 kthread+0x2ac/0x3b0
 ret_from_fork+0x10/0x20

The buggy address belongs to the object at ffff000005bcd800
 which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 944 bytes inside of
 freed 1024-byte region [ffff000005bcd800, ffff000005bcdc00)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x45bc8
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x40(head|zone=0)
page_type: f5(slab)
raw: 0000000000000040 ffff0000048030c0 fffffdffc0315e10 fffffdffc0345010
raw: 0000000000000000 00000000000a000a 00000000f5000000 0000000000000000
head: 0000000000000040 ffff0000048030c0 fffffdffc0315e10 fffffdffc0345010
head: 0000000000000000 00000000000a000a 00000000f5000000 0000000000000000
head: 0000000000000003 fffffdffc016f201 00000000ffffffff 00000000ffffffff
head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff000005bcda80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff000005bcdb00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff000005bcdb80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                     ^
 ffff000005bcdc00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff000005bcdc80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================
Disabling lock debugging due to kernel taint
==================================================================
BUG: KASAN: slab-use-after-free in bpf_map_put+0x2c/0x1a0
Write of size 8 at addr ffff000005bcd918 by task lsm_mapreg/55

CPU: 0 UID: 0 PID: 55 Comm: lsm_mapreg Tainted: G    B               7.4.0-rc5+ #13 PREEMPT 
Tainted: [B]=BAD_PAGE
Hardware name: linux,dummy-virt (DT)
Call trace:
 show_stack+0x1c/0x30 (C)
 __dump_stack+0x24/0x30
 dump_stack_lvl+0x60/0x80
 print_report+0xd4/0x248
 kasan_report+0x88/0xc0
 kasan_check_range+0x174/0x1a8
 __kasan_check_write+0x1c/0x28
 bpf_map_put+0x2c/0x1a0
 bpf_struct_ops_put+0x18/0x28
 tcp_cleanup_congestion_control+0x108/0x170
 tcp_v4_destroy_sock+0x14c/0x410
 inet_csk_destroy_sock+0x104/0x210
 __tcp_close+0x77c/0x9e0
 tcp_close+0x30/0xf8
 inet_release+0x114/0x180
 __sock_release+0x9c/0x1b8
 sock_close+0x1c/0x30
 __fput+0x140/0x3c0
 fput_close_sync+0x94/0x1c0
 __arm64_sys_close+0x7c/0xc8
 do_el0_svc+0x134/0x1e0
 el0_svc+0x40/0x100
 el0t_64_sync_handler+0x40/0x100
 el0t_64_sync+0x154/0x158

Allocated by task 55:
 kasan_save_track+0x3c/0x80
 kasan_save_alloc_info+0x3c/0x48
 __kasan_kmalloc+0x98/0xb0
 __kmalloc_node_noprof+0x2e8/0x5f0
 __bpf_map_area_alloc+0x80/0x188
 bpf_map_area_alloc+0x18/0x28
 bpf_struct_ops_map_alloc+0x1b8/0x580
 map_create+0x610/0xfe8
 __sys_bpf+0x190/0x538
 __arm64_sys_bpf+0xd0/0xf0
 do_el0_svc+0x134/0x1e0
 el0_svc+0x40/0x100
 el0t_64_sync_handler+0x40/0x100
 el0t_64_sync+0x154/0x158

Freed by task 41:
 kasan_save_track+0x3c/0x80
 kasan_save_free_info+0x50/0x68
 __kasan_slab_free+0x90/0xc0
 kfree+0x160/0x558
 kvfree+0x34/0x48
 bpf_map_area_free+0x14/0x28
 __bpf_struct_ops_map_free+0x158/0x1b0
 bpf_struct_ops_map_free+0x100/0x130
 bpf_map_free+0x170/0x3f8
 bpf_map_free_deferred+0x98/0xe0
 process_scheduled_works+0x794/0xf80
 worker_thread+0x660/0xa10
 kthread+0x2ac/0x3b0
 ret_from_fork+0x10/0x20

Last potentially related work creation:
 kasan_save_stack+0x3c/0x68
 __kasan_record_aux_stack+0xbc/0xd0
 kasan_record_aux_stack+0x10/0x18
 insert_work+0x40/0x150
 __queue_work+0x950/0xea0
 queue_work_on+0x90/0xc8
 bpf_map_free_in_work+0x100/0x120
 bpf_map_free_rcu_gp+0x18/0x28
 srcu_invoke_callbacks+0x22c/0x4d0
 process_scheduled_works+0x794/0xf80
 worker_thread+0x660/0xa10
 kthread+0x2ac/0x3b0
 ret_from_fork+0x10/0x20


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-04 21:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  9:01 [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Paul Moses
2026-12-04  9:01 ` [PATCH bpf v2 1/3] tcp: reset congestion-control state when the route selects a new CA Paul Moses
2026-12-04  9:01 ` [PATCH bpf v2 2/3] tcp: clear inherited congestion-control state for a cloned child Paul Moses
2026-12-04  9:01 ` [PATCH bpf v2 3/3] bpf: check and set TCP congestion control from the same name Paul Moses
2026-12-04 21:04 ` [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Alexei Starovoitov
2026-12-04 21:26   ` Paul Moses

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox