bpf_struct_ops_map_link_update() invokes the subsystem update callback even when the link already uses the new map. For TCP congestion control, tcp_update_congestion_control() then adds and removes the same list entry, which can corrupt tcp_cong_list. Return success without changing the list when the old and new congestion control ops are identical. Fixes: 8fb1a76a0f35 ("net: Update an existing TCP congestion control algorithm.") Suggested-by: Alexei Starovoitov Cc: stable@vger.kernel.org Signed-off-by: Paul Moses --- v2: Handle identical ops in tcp_update_congestion_control() instead of skipping the update callback in generic BPF struct_ops code. (Alexei) v1: https://lore.kernel.org/r/20261202053703.938201-1-p@1g4.org --- CAP_BPF/CAP_PERFMON required. --- list_del corruption, ffff000001e82a78->prev is LIST_POISON2 (dead000000000122) WARNING: lib/list_debug.c:61 at __list_del_entry_valid_or_report+0x100/0x154, CPU#1: fun2/47 CPU: 1 UID: 1000 PID: 47 Comm: fun2 Not tainted 7.4.0-rc4 #1 PREEMPT Hardware name: linux,dummy-virt (DT) pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : __list_del_entry_valid_or_report+0x100/0x154 lr : __list_del_entry_valid_or_report+0xfc/0x154 sp : ffff800080ef3cf0 x29: ffff800080ef3cf0 x28: ffff0000011e6200 x27: 0000000000000000 x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000 x23: 00000000020a0001 x22: dead000000000122 x21: dead000000000122 x20: ffff800080c158c0 x19: ffff000001e82a78 x18: 0000000000000000 x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 x14: 000000000000009c x13: 0000000000000003 x12: ffff80003ee6e000 x11: ffff0000bf9cc508 x10: 0000000000000001 x9 : ffff800080b86cd0 x8 : 0000000100000001 x7 : 505f5453494c2073 x6 : 0000000000000029 x5 : ffff800080c3bd8f x4 : 0000000000000000 x3 : ffff800080ef3988 x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000000 Call trace: __list_del_entry_valid_or_report+0x100/0x154 (P) tcp_unregister_congestion_control+0x24/0x5c bpf_tcp_ca_unreg+0xc/0x14 bpf_struct_ops_map_link_dealloc+0x30/0x4c bpf_link_dealloc+0x34/0x40 bpf_link_free+0xb0/0xbc bpf_link_put_direct+0x20/0x4c bpf_link_release+0x10/0x1c __fput+0x50/0x1cc fput_close_sync+0x38/0xec __arm64_sys_close+0x34/0x70 do_el0_svc+0x88/0xcc el0_svc+0x20/0x54 el0t_64_sync_handler+0x40/0xfc el0t_64_sync+0x154/0x158 ... Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 Mem abort info: ESR = 0x0000000086000006 EC = 0x21: IABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 FSC = 0x06: level 2 translation fault user pgtable: 4k pages, 48-bit VAs, pgdp=00000000412cf000 [0000000000000000] pgd=0800000041ec8403, p4d=0800000041ec8403, pud=0800000041ec9403, pmd=0000000000000000 Internal error: Oops: 0000000086000006 [#1] SMP CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Tainted: G W 7.4.0-rc4 #1 PREEMPT Tainted: [W]=WARN Hardware name: linux,dummy-virt (DT) pstate: 20400005 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : 0x0 lr : tcp_enter_loss+0x16c/0x2dc sp : ffff800080cc3dc0 x29: ffff800080cc3dc0 x28: ffff800080cc3eb8 x27: 0000000000000000 x26: dead000000000122 x25: 000000000000001b x24: 0000000000000000 x23: ffff0000012981c0 x22: ffff800080c95b00 x21: 0000000000000060 x20: 0000000000000000 x19: ffff000001efd340 x18: 000000008cf6d33d x17: 000000009de3d1c8 x16: 0000000037b1d58d x15: 000000001f98cc76 x14: 00000000fd3a0fac x13: 00000000b211991d x12: 00000000c73d125d x11: 000000009518c73b x10: 0000000000000007 x9 : ffff000001e82a00 x8 : 0000000000000000 x7 : 00000000e1575f02 x6 : 00000000bde17e00 x5 : 000000000d8e05e2 x4 : 0000000077937876 x3 : 0000000037f0c725 x2 : 00000000863de794 x1 : ffff0000012981f0 x0 : ffff000001efd340 Call trace: 0x0 (P) tcp_retransmit_timer+0x600/0x860 tcp_write_timer_handler+0xf4/0x1e0 tcp_write_timer+0x78/0x130 call_timer_fn+0x20/0x80 run_timer_softirq+0x290/0x2f4 handle_softirqs+0x10c/0x250 __do_softirq+0x10/0x18 ____do_softirq+0xc/0x14 call_on_irq_stack+0x30/0x4c do_softirq_own_stack+0x18/0x20 irq_exit_rcu+0x40/0xc0 el1_interrupt+0x3c/0x58 el1h_64_irq_handler+0x14/0x1c el1h_64_irq+0x78/0x7c default_idle_call+0x20/0x28 (P) do_idle+0x5c/0xb4 cpu_startup_entry+0x30/0x34 secondary_start_kernel+0x128/0x148 __secondary_switched+0x74/0x78 --- net/ipv4/tcp_cong.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c index 0f99405a78b1..8249cf49c1f8 100644 --- a/net/ipv4/tcp_cong.c +++ b/net/ipv4/tcp_cong.c @@ -148,6 +148,9 @@ int tcp_update_congestion_control(struct tcp_congestion_ops *ca, struct tcp_cong struct tcp_congestion_ops *existing; int ret = 0; + if (ca == old_ca) + return 0; + ca->key = jhash(ca->name, sizeof(ca->name), strlen(ca->name)); spin_lock(&tcp_cong_list_lock); -- 2.56.0.lol.gf7de81456940