Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mptcp: fix race in mptcp_pm_nl_flush_addrs_doit()

syzbot and Eulgyu Kim reported crashes in mptcp_pm_nl_get_local_id()
and/or mptcp_pm_nl_is_backup()

Root cause is list_splice_init() in mptcp_pm_nl_flush_addrs_doit()
which is not RCU ready.

list_splice_init_rcu() can not be called here while holding pernet->lock
spinlock.

Many thanks to Eulgyu Kim for providing a repro and testing our patches.

Fixes: 141694df6573 ("mptcp: remove address when netlink flushes addrs")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot+5498a510ff9de39d37da@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/6970a46d.a00a0220.3ad28e.5cf0.GAE@google.com/T/
Reported-by: Eulgyu Kim <eulgyukim@snu.ac.kr>
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/611
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20260124-net-mptcp-race_nl_flush_addrs-v3-1-b2dc1b613e9d@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
e2a9eeb6 8d7ba71e

+13 -3
+13 -3
net/mptcp/pm_kernel.c
··· 1294 1294 int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb, struct genl_info *info) 1295 1295 { 1296 1296 struct pm_nl_pernet *pernet = genl_info_pm_nl(info); 1297 - LIST_HEAD(free_list); 1297 + struct list_head free_list; 1298 1298 1299 1299 spin_lock_bh(&pernet->lock); 1300 - list_splice_init(&pernet->endp_list, &free_list); 1300 + free_list = pernet->endp_list; 1301 + INIT_LIST_HEAD_RCU(&pernet->endp_list); 1301 1302 __reset_counters(pernet); 1302 1303 pernet->next_id = 1; 1303 1304 bitmap_zero(pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); 1304 1305 spin_unlock_bh(&pernet->lock); 1305 - mptcp_nl_flush_addrs_list(sock_net(skb->sk), &free_list); 1306 + 1307 + if (free_list.next == &pernet->endp_list) 1308 + return 0; 1309 + 1306 1310 synchronize_rcu(); 1311 + 1312 + /* Adjust the pointers to free_list instead of pernet->endp_list */ 1313 + free_list.prev->next = &free_list; 1314 + free_list.next->prev = &free_list; 1315 + 1316 + mptcp_nl_flush_addrs_list(sock_net(skb->sk), &free_list); 1307 1317 __flush_addrs(&free_list); 1308 1318 return 0; 1309 1319 }