Skip to content

Commit 75a4c9a

Browse files
Paolo Abenigregkh
authored andcommitted
mptcp: make fallback action and fallback decision atomic
commit f8a1d9b upstream. Syzkaller reported the following splat: WARNING: CPU: 1 PID: 7704 at net/mptcp/protocol.h:1223 __mptcp_do_fallback net/mptcp/protocol.h:1223 [inline] WARNING: CPU: 1 PID: 7704 at net/mptcp/protocol.h:1223 mptcp_do_fallback net/mptcp/protocol.h:1244 [inline] WARNING: CPU: 1 PID: 7704 at net/mptcp/protocol.h:1223 check_fully_established net/mptcp/options.c:982 [inline] WARNING: CPU: 1 PID: 7704 at net/mptcp/protocol.h:1223 mptcp_incoming_options+0x21a8/0x2510 net/mptcp/options.c:1153 Modules linked in: CPU: 1 UID: 0 PID: 7704 Comm: syz.3.1419 Not tainted 6.16.0-rc3-gbd5ce2324dba #20 PREEMPT(voluntary) Hardware name: QEMU Ubuntu 24.04 PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 RIP: 0010:__mptcp_do_fallback net/mptcp/protocol.h:1223 [inline] RIP: 0010:mptcp_do_fallback net/mptcp/protocol.h:1244 [inline] RIP: 0010:check_fully_established net/mptcp/options.c:982 [inline] RIP: 0010:mptcp_incoming_options+0x21a8/0x2510 net/mptcp/options.c:1153 Code: 24 18 e8 bb 2a 00 fd e9 1b df ff ff e8 b1 21 0f 00 e8 ec 5f c4 fc 44 0f b7 ac 24 b0 00 00 00 e9 54 f1 ff ff e8 d9 5f c4 fc 90 <0f> 0b 90 e9 b8 f4 ff ff e8 8b 2a 00 fd e9 8d e6 ff ff e8 81 2a 00 RSP: 0018:ffff8880a3f08448 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff8880180a8000 RCX: ffffffff84afcf45 RDX: ffff888090223700 RSI: ffffffff84afdaa7 RDI: 0000000000000001 RBP: ffff888017955780 R08: 0000000000000001 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 R13: ffff8880180a8910 R14: ffff8880a3e9d058 R15: 0000000000000000 FS: 00005555791b8500(0000) GS:ffff88811c495000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000110c2800b7 CR3: 0000000058e44000 CR4: 0000000000350ef0 Call Trace: <IRQ> tcp_reset+0x26f/0x2b0 net/ipv4/tcp_input.c:4432 tcp_validate_incoming+0x1057/0x1b60 net/ipv4/tcp_input.c:5975 tcp_rcv_established+0x5b5/0x21f0 net/ipv4/tcp_input.c:6166 tcp_v4_do_rcv+0x5dc/0xa70 net/ipv4/tcp_ipv4.c:1925 tcp_v4_rcv+0x3473/0x44a0 net/ipv4/tcp_ipv4.c:2363 ip_protocol_deliver_rcu+0xba/0x480 net/ipv4/ip_input.c:205 ip_local_deliver_finish+0x2f1/0x500 net/ipv4/ip_input.c:233 NF_HOOK include/linux/netfilter.h:317 [inline] NF_HOOK include/linux/netfilter.h:311 [inline] ip_local_deliver+0x1be/0x560 net/ipv4/ip_input.c:254 dst_input include/net/dst.h:469 [inline] ip_rcv_finish net/ipv4/ip_input.c:447 [inline] NF_HOOK include/linux/netfilter.h:317 [inline] NF_HOOK include/linux/netfilter.h:311 [inline] ip_rcv+0x514/0x810 net/ipv4/ip_input.c:567 __netif_receive_skb_one_core+0x197/0x1e0 net/core/dev.c:5975 __netif_receive_skb+0x1f/0x120 net/core/dev.c:6088 process_backlog+0x301/0x1360 net/core/dev.c:6440 __napi_poll.constprop.0+0xba/0x550 net/core/dev.c:7453 napi_poll net/core/dev.c:7517 [inline] net_rx_action+0xb44/0x1010 net/core/dev.c:7644 handle_softirqs+0x1d0/0x770 kernel/softirq.c:579 do_softirq+0x3f/0x90 kernel/softirq.c:480 </IRQ> <TASK> __local_bh_enable_ip+0xed/0x110 kernel/softirq.c:407 local_bh_enable include/linux/bottom_half.h:33 [inline] inet_csk_listen_stop+0x2c5/0x1070 net/ipv4/inet_connection_sock.c:1524 mptcp_check_listen_stop.part.0+0x1cc/0x220 net/mptcp/protocol.c:2985 mptcp_check_listen_stop net/mptcp/mib.h:118 [inline] __mptcp_close+0x9b9/0xbd0 net/mptcp/protocol.c:3000 mptcp_close+0x2f/0x140 net/mptcp/protocol.c:3066 inet_release+0xed/0x200 net/ipv4/af_inet.c:435 inet6_release+0x4f/0x70 net/ipv6/af_inet6.c:487 __sock_release+0xb3/0x270 net/socket.c:649 sock_close+0x1c/0x30 net/socket.c:1439 __fput+0x402/0xb70 fs/file_table.c:465 task_work_run+0x150/0x240 kernel/task_work.c:227 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline] exit_to_user_mode_loop+0xd4/0xe0 kernel/entry/common.c:114 exit_to_user_mode_prepare include/linux/entry-common.h:330 [inline] syscall_exit_to_user_mode_work include/linux/entry-common.h:414 [inline] syscall_exit_to_user_mode include/linux/entry-common.h:449 [inline] do_syscall_64+0x245/0x360 arch/x86/entry/syscall_64.c:100 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fc92f8a36ad Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffcf52802d8 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4 RAX: 0000000000000000 RBX: 00007ffcf52803a8 RCX: 00007fc92f8a36ad RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003 RBP: 00007fc92fae7ba0 R08: 0000000000000001 R09: 0000002800000000 R10: 00007fc92f700000 R11: 0000000000000246 R12: 00007fc92fae5fac R13: 00007fc92fae5fa0 R14: 0000000000026d00 R15: 0000000000026c51 </TASK> irq event stamp: 4068 hardirqs last enabled at (4076): [<ffffffff81544816>] __up_console_sem+0x76/0x80 kernel/printk/printk.c:344 hardirqs last disabled at (4085): [<ffffffff815447fb>] __up_console_sem+0x5b/0x80 kernel/printk/printk.c:342 softirqs last enabled at (3096): [<ffffffff840e1be0>] local_bh_enable include/linux/bottom_half.h:33 [inline] softirqs last enabled at (3096): [<ffffffff840e1be0>] inet_csk_listen_stop+0x2c0/0x1070 net/ipv4/inet_connection_sock.c:1524 softirqs last disabled at (3097): [<ffffffff813b6b9f>] do_softirq+0x3f/0x90 kernel/softirq.c:480 Since we need to track the 'fallback is possible' condition and the fallback status separately, there are a few possible races open between the check and the actual fallback action. Add a spinlock to protect the fallback related information and use it close all the possible related races. While at it also remove the too-early clearing of allow_infinite_fallback in __mptcp_subflow_connect(): the field will be correctly cleared by subflow_finish_connect() if/when the connection will complete successfully. If fallback is not possible, as per RFC, reset the current subflow. Since the fallback operation can now fail and return value should be checked, rename the helper accordingly. Fixes: 0530020 ("mptcp: track and update contiguous data status") Cc: [email protected] Reported-by: Matthieu Baerts <[email protected]> Closes: multipath-tcp/mptcp_net-next#570 Reported-by: [email protected] Closes: multipath-tcp/mptcp_net-next#555 Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Matthieu Baerts (NGI0) <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> [ Conflicts in protocol.h, because commit 6ebf6f9 ("mptcp: add mptcpi_subflows_total counter") is not in this version, and this causes conflicts in the context. Commit 65b0226 ("mptcp: export mptcp_subflow_early_fallback()") is also not in this version, and moves code from protocol.c to protocol.h, but the modification can still apply there. ] Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 23a5773 commit 75a4c9a

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

net/mptcp/options.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,9 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
979979
if (subflow->mp_join)
980980
goto reset;
981981
subflow->mp_capable = 0;
982+
if (!mptcp_try_fallback(ssk))
983+
goto reset;
982984
pr_fallback(msk);
983-
mptcp_do_fallback(ssk);
984985
return false;
985986
}
986987

net/mptcp/protocol.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,9 @@ static bool mptcp_check_data_fin(struct sock *sk)
623623

624624
static void mptcp_dss_corruption(struct mptcp_sock *msk, struct sock *ssk)
625625
{
626-
if (READ_ONCE(msk->allow_infinite_fallback)) {
626+
if (mptcp_try_fallback(ssk)) {
627627
MPTCP_INC_STATS(sock_net(ssk),
628628
MPTCP_MIB_DSSCORRUPTIONFALLBACK);
629-
mptcp_do_fallback(ssk);
630629
} else {
631630
MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSCORRUPTIONRESET);
632631
mptcp_subflow_reset(ssk);
@@ -887,6 +886,14 @@ static bool __mptcp_finish_join(struct mptcp_sock *msk, struct sock *ssk)
887886
if (sk->sk_state != TCP_ESTABLISHED)
888887
return false;
889888

889+
spin_lock_bh(&msk->fallback_lock);
890+
if (__mptcp_check_fallback(msk)) {
891+
spin_unlock_bh(&msk->fallback_lock);
892+
return false;
893+
}
894+
mptcp_subflow_joined(msk, ssk);
895+
spin_unlock_bh(&msk->fallback_lock);
896+
890897
/* attach to msk socket only after we are sure we will deal with it
891898
* at close time
892899
*/
@@ -895,7 +902,6 @@ static bool __mptcp_finish_join(struct mptcp_sock *msk, struct sock *ssk)
895902

896903
mptcp_subflow_ctx(ssk)->subflow_id = msk->subflow_id++;
897904
mptcp_sockopt_sync_locked(msk, ssk);
898-
mptcp_subflow_joined(msk, ssk);
899905
mptcp_stop_tout_timer(sk);
900906
__mptcp_propagate_sndbuf(sk, ssk);
901907
return true;
@@ -1231,10 +1237,14 @@ static void mptcp_update_infinite_map(struct mptcp_sock *msk,
12311237
mpext->infinite_map = 1;
12321238
mpext->data_len = 0;
12331239

1240+
if (!mptcp_try_fallback(ssk)) {
1241+
mptcp_subflow_reset(ssk);
1242+
return;
1243+
}
1244+
12341245
MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_INFINITEMAPTX);
12351246
mptcp_subflow_ctx(ssk)->send_infinite_map = 0;
12361247
pr_fallback(msk);
1237-
mptcp_do_fallback(ssk);
12381248
}
12391249

12401250
#define MPTCP_MAX_GSO_SIZE (GSO_LEGACY_MAX_SIZE - (MAX_TCP_HEADER + 1))
@@ -2606,9 +2616,9 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
26062616

26072617
static void __mptcp_retrans(struct sock *sk)
26082618
{
2619+
struct mptcp_sendmsg_info info = { .data_lock_held = true, };
26092620
struct mptcp_sock *msk = mptcp_sk(sk);
26102621
struct mptcp_subflow_context *subflow;
2611-
struct mptcp_sendmsg_info info = {};
26122622
struct mptcp_data_frag *dfrag;
26132623
struct sock *ssk;
26142624
int ret, err;
@@ -2653,6 +2663,18 @@ static void __mptcp_retrans(struct sock *sk)
26532663
info.sent = 0;
26542664
info.limit = READ_ONCE(msk->csum_enabled) ? dfrag->data_len :
26552665
dfrag->already_sent;
2666+
2667+
/*
2668+
* make the whole retrans decision, xmit, disallow
2669+
* fallback atomic
2670+
*/
2671+
spin_lock_bh(&msk->fallback_lock);
2672+
if (__mptcp_check_fallback(msk)) {
2673+
spin_unlock_bh(&msk->fallback_lock);
2674+
release_sock(ssk);
2675+
return;
2676+
}
2677+
26562678
while (info.sent < info.limit) {
26572679
ret = mptcp_sendmsg_frag(sk, ssk, dfrag, &info);
26582680
if (ret <= 0)
@@ -2668,6 +2690,7 @@ static void __mptcp_retrans(struct sock *sk)
26682690
info.size_goal);
26692691
WRITE_ONCE(msk->allow_infinite_fallback, false);
26702692
}
2693+
spin_unlock_bh(&msk->fallback_lock);
26712694

26722695
release_sock(ssk);
26732696
}
@@ -2801,6 +2824,7 @@ static void __mptcp_init_sock(struct sock *sk)
28012824
msk->subflow_id = 1;
28022825

28032826
mptcp_pm_data_init(msk);
2827+
spin_lock_init(&msk->fallback_lock);
28042828

28052829
/* re-use the csk retrans timer for MPTCP-level retrans */
28062830
timer_setup(&msk->sk.icsk_retransmit_timer, mptcp_retransmit_timer, 0);
@@ -3599,7 +3623,13 @@ bool mptcp_finish_join(struct sock *ssk)
35993623

36003624
/* active subflow, already present inside the conn_list */
36013625
if (!list_empty(&subflow->node)) {
3626+
spin_lock_bh(&msk->fallback_lock);
3627+
if (__mptcp_check_fallback(msk)) {
3628+
spin_unlock_bh(&msk->fallback_lock);
3629+
return false;
3630+
}
36023631
mptcp_subflow_joined(msk, ssk);
3632+
spin_unlock_bh(&msk->fallback_lock);
36033633
mptcp_propagate_sndbuf(parent, ssk);
36043634
return true;
36053635
}
@@ -3712,7 +3742,7 @@ static void mptcp_subflow_early_fallback(struct mptcp_sock *msk,
37123742
struct mptcp_subflow_context *subflow)
37133743
{
37143744
subflow->request_mptcp = 0;
3715-
__mptcp_do_fallback(msk);
3745+
WARN_ON_ONCE(!__mptcp_try_fallback(msk));
37163746
}
37173747

37183748
static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)

net/mptcp/protocol.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ struct mptcp_sock {
334334
u32 subflow_id;
335335
u32 setsockopt_seq;
336336
char ca_name[TCP_CA_NAME_MAX];
337+
338+
spinlock_t fallback_lock; /* protects fallback and
339+
* allow_infinite_fallback
340+
*/
337341
};
338342

339343
#define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)
@@ -1097,25 +1101,32 @@ static inline bool mptcp_check_fallback(const struct sock *sk)
10971101
return __mptcp_check_fallback(msk);
10981102
}
10991103

1100-
static inline void __mptcp_do_fallback(struct mptcp_sock *msk)
1104+
static inline bool __mptcp_try_fallback(struct mptcp_sock *msk)
11011105
{
11021106
if (test_bit(MPTCP_FALLBACK_DONE, &msk->flags)) {
11031107
pr_debug("TCP fallback already done (msk=%p)\n", msk);
1104-
return;
1108+
return true;
11051109
}
1106-
if (WARN_ON_ONCE(!READ_ONCE(msk->allow_infinite_fallback)))
1107-
return;
1110+
spin_lock_bh(&msk->fallback_lock);
1111+
if (!msk->allow_infinite_fallback) {
1112+
spin_unlock_bh(&msk->fallback_lock);
1113+
return false;
1114+
}
1115+
11081116
set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
1117+
spin_unlock_bh(&msk->fallback_lock);
1118+
return true;
11091119
}
11101120

1111-
static inline void mptcp_do_fallback(struct sock *ssk)
1121+
static inline bool mptcp_try_fallback(struct sock *ssk)
11121122
{
11131123
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
11141124
struct sock *sk = subflow->conn;
11151125
struct mptcp_sock *msk;
11161126

11171127
msk = mptcp_sk(sk);
1118-
__mptcp_do_fallback(msk);
1128+
if (!__mptcp_try_fallback(msk))
1129+
return false;
11191130
if (READ_ONCE(msk->snd_data_fin_enable) && !(ssk->sk_shutdown & SEND_SHUTDOWN)) {
11201131
gfp_t saved_allocation = ssk->sk_allocation;
11211132

@@ -1127,6 +1138,7 @@ static inline void mptcp_do_fallback(struct sock *ssk)
11271138
tcp_shutdown(ssk, SEND_SHUTDOWN);
11281139
ssk->sk_allocation = saved_allocation;
11291140
}
1141+
return true;
11301142
}
11311143

11321144
#define pr_fallback(a) pr_debug("%s:fallback to TCP (msk=%p)\n", __func__, a)

net/mptcp/subflow.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,11 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
524524
mptcp_get_options(skb, &mp_opt);
525525
if (subflow->request_mptcp) {
526526
if (!(mp_opt.suboptions & OPTION_MPTCP_MPC_SYNACK)) {
527+
if (!mptcp_try_fallback(sk))
528+
goto do_reset;
529+
527530
MPTCP_INC_STATS(sock_net(sk),
528531
MPTCP_MIB_MPCAPABLEACTIVEFALLBACK);
529-
mptcp_do_fallback(sk);
530532
pr_fallback(msk);
531533
goto fallback;
532534
}
@@ -1350,7 +1352,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
13501352
return true;
13511353
}
13521354

1353-
if (!READ_ONCE(msk->allow_infinite_fallback)) {
1355+
if (!mptcp_try_fallback(ssk)) {
13541356
/* fatal protocol error, close the socket.
13551357
* subflow_error_report() will introduce the appropriate barriers
13561358
*/
@@ -1366,8 +1368,6 @@ static bool subflow_check_data_avail(struct sock *ssk)
13661368
WRITE_ONCE(subflow->data_avail, MPTCP_SUBFLOW_NODATA);
13671369
return false;
13681370
}
1369-
1370-
mptcp_do_fallback(ssk);
13711371
}
13721372

13731373
skb = skb_peek(&ssk->sk_receive_queue);
@@ -1612,7 +1612,6 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
16121612
/* discard the subflow socket */
16131613
mptcp_sock_graft(ssk, sk->sk_socket);
16141614
iput(SOCK_INODE(sf));
1615-
WRITE_ONCE(msk->allow_infinite_fallback, false);
16161615
mptcp_stop_tout_timer(sk);
16171616
return 0;
16181617

@@ -1790,7 +1789,7 @@ static void subflow_state_change(struct sock *sk)
17901789

17911790
msk = mptcp_sk(parent);
17921791
if (subflow_simultaneous_connect(sk)) {
1793-
mptcp_do_fallback(sk);
1792+
WARN_ON_ONCE(!mptcp_try_fallback(sk));
17941793
pr_fallback(msk);
17951794
subflow->conn_finished = 1;
17961795
mptcp_propagate_state(parent, sk, subflow, NULL);

0 commit comments

Comments
 (0)