mptcp: fix a race in mptcp_pm_del_add_timer()
Subsystems (3)
PATCH v2 1/1 mptcp: fix a race in mptcp_pm_del_add_timer()
mptcp_pm_del_add_timer() can call sk_stop_timer_sync(sk, &entry->add_timer) while another might have free entry already, as reported by syzbot.
Add RCU protection to fix this issue.
Also change confusing add_timer variable with stop_timer boolean.
syzbot report:
BUG: KASAN: slab-use-after-free in __timer_delete_sync+0x372/0x3f0 kernel/time/timer.c:1616
Read of size 4 at addr ffff8880311e4150 by task kworker/1:1/44
CPU: 1 UID: 0 PID: 44 Comm: kworker/1:1 Not tainted syzkaller #0 PREEMPT_{RT,(full)}
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025
Workqueue: events mptcp_worker
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__timer_delete_sync+0x372/0x3f0 kernel/time/timer.c:1616
sk_stop_timer_sync+0x1b/0x90 net/core/sock.c:3631
mptcp_pm_del_add_timer+0x283/0x310 net/mptcp/pm.c:362
mptcp_incoming_options+0x1357/0x1f60 net/mptcp/options.c:1174
tcp_data_queue+0xca/0x6450 net/ipv4/tcp_input.c:5361
tcp_rcv_established+0x1335/0x2670 net/ipv4/tcp_input.c:6441
tcp_v4_do_rcv+0x98b/0xbf0 net/ipv4/tcp_ipv4.c:1931
tcp_v4_rcv+0x252a/0x2dc0 net/ipv4/tcp_ipv4.c:2374
ip_protocol_deliver_rcu+0x221/0x440 net/ipv4/ip_input.c:205
ip_local_deliver_finish+0x3bb/0x6f0 net/ipv4/ip_input.c:239
NF_HOOK+0x30c/0x3a0 include/linux/netfilter.h:318
NF_HOOK+0x30c/0x3a0 include/linux/netfilter.h:318
__netif_receive_skb_one_core net/core/dev.c:6079 [inline]
__netif_receive_skb+0x143/0x380 net/core/dev.c:6192
process_backlog+0x31e/0x900 net/core/dev.c:6544
__napi_poll+0xb6/0x540 net/core/dev.c:7594
napi_poll net/core/dev.c:7657 [inline]
net_rx_action+0x5f7/0xda0 net/core/dev.c:7784
handle_softirqs+0x22f/0x710 kernel/softirq.c:622
__do_softirq kernel/softirq.c:656 [inline]
__local_bh_enable_ip+0x1a0/0x2e0 kernel/softirq.c:302
mptcp_pm_send_ack net/mptcp/pm.c:210 [inline]
mptcp_pm_addr_send_ack+0x41f/0x500 net/mptcp/pm.c:-1
mptcp_pm_worker+0x174/0x320 net/mptcp/pm.c:1002
mptcp_worker+0xd5/0x1170 net/mptcp/protocol.c:2762
process_one_work kernel/workqueue.c:3263 [inline]
process_scheduled_works+0xae1/0x17b0 kernel/workqueue.c:3346
worker_thread+0x8a0/0xda0 kernel/workqueue.c:3427
kthread+0x711/0x8a0 kernel/kthread.c:463
ret_from_fork+0x4bc/0x870 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
Allocated by task 44:
kasan_save_stack mm/kasan/common.c:56 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:77
poison_kmalloc_redzone mm/kasan/common.c:400 [inline]
__kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:417
kasan_kmalloc include/linux/kasan.h:262 [inline]
__kmalloc_cache_noprof+0x1ef/0x6c0 mm/slub.c:5748
kmalloc_noprof include/linux/slab.h:957 [inline]
mptcp_pm_alloc_anno_list+0x104/0x460 net/mptcp/pm.c:385
mptcp_pm_create_subflow_or_signal_addr+0xf9d/0x1360 net/mptcp/pm_kernel.c:355
mptcp_pm_nl_fully_established net/mptcp/pm_kernel.c:409 [inline]
__mptcp_pm_kernel_worker+0x417/0x1ef0 net/mptcp/pm_kernel.c:1529
mptcp_pm_worker+0x1ee/0x320 net/mptcp/pm.c:1008
mptcp_worker+0xd5/0x1170 net/mptcp/protocol.c:2762
process_one_work kernel/workqueue.c:3263 [inline]
process_scheduled_works+0xae1/0x17b0 kernel/workqueue.c:3346
worker_thread+0x8a0/0xda0 kernel/workqueue.c:3427
kthread+0x711/0x8a0 kernel/kthread.c:463
ret_from_fork+0x4bc/0x870 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
Freed by task 6630:
kasan_save_stack mm/kasan/common.c:56 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:77
__kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:587
kasan_save_free_info mm/kasan/kasan.h:406 [inline]
poison_slab_object mm/kasan/common.c:252 [inline]
__kasan_slab_free+0x5c/0x80 mm/kasan/common.c:284
kasan_slab_free include/linux/kasan.h:234 [inline]
slab_free_hook mm/slub.c:2523 [inline]
slab_free mm/slub.c:6611 [inline]
kfree+0x197/0x950 mm/slub.c:6818
mptcp_remove_anno_list_by_saddr+0x2d/0x40 net/mptcp/pm.c:158
mptcp_pm_flush_addrs_and_subflows net/mptcp/pm_kernel.c:1209 [inline]
mptcp_nl_flush_addrs_list net/mptcp/pm_kernel.c:1240 [inline]
mptcp_pm_nl_flush_addrs_doit+0x593/0xbb0 net/mptcp/pm_kernel.c:1281
genl_family_rcv_msg_doit+0x215/0x300 net/netlink/genetlink.c:1115
genl_family_rcv_msg net/netlink/genetlink.c:1195 [inline]
genl_rcv_msg+0x60e/0x790 net/netlink/genetlink.c:1210
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x846/0xa10 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg+0x21c/0x270 net/socket.c:742
____sys_sendmsg+0x508/0x820 net/socket.c:2630
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2684
__sys_sendmsg net/socket.c:2716 [inline]
__do_sys_sendmsg net/socket.c:2721 [inline]
__se_sys_sendmsg net/socket.c:2719 [inline]
__x64_sys_sendmsg+0x1a1/0x260 net/socket.c:2719
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0xfa0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f---
v2: Updated/Added Reported-by:/Closes: tags now syzbot report finally reached netdev@ mailing list.
net/mptcp/pm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
net/mptcp/pm.c +13 -7
@@ -18,6 +18,7 @@ struct mptcp_pm_add_entry {u8 retrans_times;struct timer_list add_timer;struct mptcp_sock *sock; +struct rcu_head rcu; };static DEFINE_SPINLOCK (mptcp_pm_list_lock);
@@ -155,7 +156,7 @@ bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk, entry =mptcp_pm_del_add_timer (msk, addr, false); ret = entry; -kfree (entry); +kfree_rcu (entry, rcu);return ret; }
@@ -345,22 +346,27 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, {struct mptcp_pm_add_entry *entry;struct sock *sk = (struct sock *)msk; -struct timer_list *add_timer =NULL ; +bool stop_timer = false; + +rcu_read_lock ();spin_lock_bh (&msk->pm.lock); entry =mptcp_lookup_anno_list_by_saddr (msk, addr);if (entry && (!check_id || entry->addr.id == addr->id)) { entry->retrans_times =ADD_ADDR_RETRANS_MAX ; - add_timer = &entry->add_timer; + stop_timer = true; }if (!check_id && entry)list_del (&entry->list);spin_unlock_bh (&msk->pm.lock); -/* no lock, because sk_stop_timer_sync() is calling timer_delete_sync() */ -if (add_timer) -sk_stop_timer_sync (sk, add_timer); +/* Note: entry might have been removed by another thread. +* We hold rcu_read_lock() to ensure it is not freed under us. +*/ +if (stop_timer) +sk_stop_timer_sync (sk, &entry->add_timer); +rcu_read_unlock ();return entry; }
@@ -415,7 +421,7 @@ static void mptcp_pm_free_anno_list(struct mptcp_sock *msk)list_for_each_entry_safe (entry, tmp, &free_list, list) {sk_stop_timer_sync (sk, &entry->add_timer); -kfree (entry); +kfree_rcu (entry, rcu); } }
Signature · 1 line
2.52.0.rc1.455.g30608eb744-goog
Hi Eric,
(+cc MPTCP ML)
Quoted 4 lines · Eric Dumazet
mptcp_pm_del_add_timer()can callsk_stop_timer_sync(sk, &entry->add_timer)while another might have free entry already, as reported by syzbot.Add RCU protection to fix this issue.
Thank you for the report and even more for the fix!
Quoted 1 line
Also change confusing
add_timervariable withstop_timerboolean.
Indeed, this name was confusing: 'add_timer' is in fact a (too) short version of "additional address signalling retransmission timer". This new 'stop_timer' boolean makes sense!
Quoted 1 line
syzbot report:
(...)
Quoted 5 lines
Fixes 00cfd77b9063 ("mptcp: retransmit ADD_ADDR when timeout")Reported-by [email protected]Signed-off-by Eric Dumazet <[email protected]>Cc Geliang Tang <[email protected]>
The modification looks good to me:
While at it, just to help me to manage the backports:
Quoted 1 line
v2: Updated/Added Reported-by:/Closes: tags now syzbot report finally reached netdev@ mailing list.
Out of curiosity, is it not OK to reply to the patch with the new Reported-by & Closes tags to have them automatically added when applying the patch? (I was going to do that on the v1, then I saw the v2 just when I was going to press 'Send' :) )
I don't mind having a v2, it is just to save you time later, but maybe there is another reason.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Quoted 35 lines · Matthieu Baerts
Hi Eric,
(+cc MPTCP ML)
Quoted 4 lines · Eric Dumazet
mptcp_pm_del_add_timer()can callsk_stop_timer_sync(sk, &entry->add_timer)while another might have free entry already, as reported by syzbot.Add RCU protection to fix this issue.
Thank you for the report and even more for the fix!
Quoted 1 line
Also change confusing
add_timervariable withstop_timerboolean.Indeed, this name was confusing: '
add_timer' is in fact a (too) short version of "additional address signalling retransmission timer". This new 'stop_timer' boolean makes sense!Quoted 1 line
syzbot report:
(...)
Quoted 5 lines
Fixes 00cfd77b9063 ("mptcp: retransmit ADD_ADDR when timeout")Reported-by [email protected]Signed-off-by Eric Dumazet <[email protected]>Cc Geliang Tang <[email protected]>The modification looks good to me:
Reviewed-by Matthieu Baerts (NGI0) <[email protected]>While at it, just to help me to manage the backports:
Quoted 8 lines
Quoted 1 line
v2: Updated/Added Reported-by:/Closes: tags now syzbot report finally reached netdev@ mailing list.
Out of curiosity, is it not OK to reply to the patch with the new Reported-by & Closes tags to have them automatically added when applying the patch? (I was going to do that on the v1, then I saw the v2 just when I was going to press 'Send' :) )
I am not sure patchwork has been finally changed to understand these two tags.
Quoted 9 lines
I don't mind having a v2, it is just to save you time later, but maybe there is another reason.
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerQuoted 38 lines · Eric Dumazet
Quoted 37 lines · Matthieu Baerts
Hi Eric,
(+cc MPTCP ML)
Quoted 4 lines · Eric Dumazet
mptcp_pm_del_add_timer()can callsk_stop_timer_sync(sk, &entry->add_timer)while another might have free entry already, as reported by syzbot.Add RCU protection to fix this issue.
Thank you for the report and even more for the fix!
Quoted 1 line
Also change confusing
add_timervariable withstop_timerboolean.Indeed, this name was confusing: '
add_timer' is in fact a (too) short version of "additional address signalling retransmission timer". This new 'stop_timer' boolean makes sense!Quoted 1 line
syzbot report:
(...)
Quoted 5 lines
Fixes 00cfd77b9063 ("mptcp: retransmit ADD_ADDR when timeout")Reported-by [email protected]Signed-off-by Eric Dumazet <[email protected]>Cc Geliang Tang <[email protected]>The modification looks good to me:
Reviewed-by Matthieu Baerts (NGI0) <[email protected]>While at it, just to help me to manage the backports:
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
v2: Updated/Added Reported-by:/Closes: tags now syzbot report finally reached netdev@ mailing list.
Out of curiosity, is it not OK to reply to the patch with the new Reported-by & Closes tags to have them automatically added when applying the patch? (I was going to do that on the v1, then I saw the v2 just when I was going to press 'Send' :) )
I am not sure patchwork has been finally changed to understand these two tags.
Ah yes, thank you! If there is a dependence on Patchwork, I think indeed, it doesn't recognise the 'Closes' tag (but I think 'Reported-by' is OK).
While at it, I forgot to add: this patch can be applied in net directly.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Jakub Kicinski
maintainerQuoted 5 lines · On Mon, 17 Nov 2025 11:42:31 +0100 Matthieu Baerts wrote:
Quoted 5 lines
Quoted 4 lines
Out of curiosity, is it not OK to reply to the patch with the new Reported-by & Closes tags to have them automatically added when applying the patch? (I was going to do that on the v1, then I saw the v2 just when I was going to press 'Send' :) )
Quoted 7 lines
Quoted 1 line
I am not sure patchwork has been finally changed to understand these two tags.
Ah yes, thank you! If there is a dependence on Patchwork, I think indeed, it doesn't recognise the 'Closes' tag (but I think 'Reported-by' is OK).
While at it, I forgot to add: this patch can be applied in net directly.
FWIW I have a local script which extracts them from patchwork comments and applies them (same for Fixes tags). But it's always safer to resend.
Matthieu Baerts
maintainerHi Jakub,
Thank you for your reply!
18 Nov 2025 02:05:12 Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Mon, 17 Nov 2025 11:42:31 +0100 Matthieu Baerts wrote:
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Out of curiosity, is it not OK to reply to the patch with the new Reported-by & Closes tags to have them automatically added when applying the patch? (I was going to do that on the v1, then I saw the v2 just when I was going to press 'Send' :) )
I am not sure patchwork has been finally changed to understand these two tags.
Quoted 8 lines
Quoted 5 lines
Ah yes, thank you! If there is a dependence on Patchwork, I think indeed, it doesn't recognise the 'Closes' tag (but I think 'Reported-by' is OK).
While at it, I forgot to add: this patch can be applied in net directly.
FWIW I have a local script which extracts them from patchwork comments and applies them (same for Fixes tags).
Great, good to know, thanks!
(So similar to what "b4 shazam -Msl" would do then.)
Quoted 1 line
But it's always safer to resend.
Indeed.
Cheers,
Matt
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Mon, 17 Nov 2025 10:07:44 +0000 you wrote:
mptcp_pm_del_add_timer()can callsk_stop_timer_sync(sk, &entry->add_timer)while another might have free entry already, as reported by syzbot.Add RCU protection to fix this issue.
Also change confusing
add_timervariable withstop_timerboolean.[...]
Here is the summary with links:
- [v2,net] mptcp: fix a race in mptcp_pm_del_add_timer()
https://git.kernel.org/netdev/net/c/426358d9be7c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html