Skip to contentSkip to conversation

mptcp: Fixes for 5.17

PATCH Applied Mat Martineau 2 participants 5 messages Feb 25, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover mptcp: Fixes for 5.17

Patch 1 fixes an issue with the SIOCOUTQ ioctl in MPTCP sockets that have performed a fallback to TCP.

Patch 2 is a selftest fix to correctly remove temp files.

Patch 3 fixes a shift-out-of-bounds issue found by syzkaller.

Mat Martineau (1):
mptcp: Correctly set DATA_FIN timeout when number of retransmits is
large

Paolo Abeni (2):
mptcp: accurate SIOCOUTQ for fallback socket
selftests: mptcp: do complete cleanup at exit

 net/mptcp/protocol.c                           | 18 ++++++++++++++++--
 .../selftests/net/mptcp/mptcp_connect.sh       |  4 ++--
 2 files changed, 18 insertions(+), 4 deletions(-)

base-commit: d8152cfe2f21d6930c680311b03b169899c8d2a0

Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/3 mptcp: accurate SIOCOUTQ for fallback socket

From: Paolo Abeni <[email protected]>

The MPTCP SIOCOUTQ implementation is not very accurate in case of fallback: it only measures the data in the MPTCP-level write queue, but it does not take in account the subflow write queue utilization. In case of fallback the first can be empty, while the latter is not.

The above produces sporadic self-tests issues and can foul legit user-space application.

Fix the issue additionally querying the subflow in case of fallback.

Fixes 644807e3e462 ("mptcp: add SIOCINQ, OUTQ and OUTQNSD ioctls")
---
 net/mptcp/protocol.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
net/mptcp/protocol.c +11 -0
index f60f01b14fac..12bb28c5007e 100644
@@ -3294,6 +3294,17 @@ static int mptcp_ioctl_outq(const struct mptcp_sock *msk, u64 v)
 		return 0;
 
 	delta = msk->write_seq - v;
+	if (__mptcp_check_fallback(msk) && msk->first) {
+		struct tcp_sock *tp = tcp_sk(msk->first);
+
+		/* the first subflow is disconnected after close - see
+		 * __mptcp_close_ssk(). tcp_disconnect() moves the write_seq
+		 * so ignore that status, too.
+		 */
+		if (!((1 << msk->first->sk_state) &
+		      (TCPF_SYN_SENT | TCPF_SYN_RECV | TCPF_CLOSE)))
+			delta += READ_ONCE(tp->write_seq) - tp->snd_una;
+	}
 	if (delta > INT_MAX)
 		delta = INT_MAX;
 
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/3 selftests: mptcp: do complete cleanup at exit

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

After commit 05be5e273c84 ("selftests: mptcp: add disconnect tests") the mptcp selftests leave behind a couple of tmp files after each run. run_tests_disconnect() misnames a few variables used to track them. Address the issue setting the appropriate global variables

Fixes 05be5e273c84 ("selftests: mptcp: add disconnect tests")
---
 tools/testing/selftests/net/mptcp/mptcp_connect.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.sh +2 -2
index cb5809b89081..f0f4ab96b8f3 100755
@@ -763,8 +763,8 @@ run_tests_disconnect()
 	run_tests_lo "$ns1" "$ns1" dead:beef:1::1 1 "-I 3 -i $old_cin"
 
 	# restore previous status
-	cout=$old_cout
-	cout_disconnect="$cout".disconnect
+	sin=$old_sin
+	sin_disconnect="$cout".disconnect
 	cin=$old_cin
 	cin_disconnect="$cin".disconnect
 	connect_per_transfer=1
Signature · 1 line
2.35.1
#3 lore raw

PATCH 3/3 mptcp: Correctly set DATA_FIN timeout when number of retransmits is large

In reply to Mat Martineau

Syzkaller with UBSAN uncovered a scenario where a large number of DATA_FIN retransmits caused a shift-out-of-bounds in the DATA_FIN timeout calculation:

================================================================================

UBSAN: shift-out-of-bounds in net/mptcp/protocol.c:470:29
shift exponent 32 is too large for 32-bit type 'unsigned int'
CPU: 1 PID: 13059 Comm: kworker/1:0 Not tainted 5.17.0-rc2-00630-g5fbf21c90c60 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
Workqueue: events mptcp_worker
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 ubsan_epilogue+0xb/0x5a lib/ubsan.c:151
 __ubsan_handle_shift_out_of_bounds.cold+0xb2/0x20e lib/ubsan.c:330
 mptcp_set_datafin_timeout net/mptcp/protocol.c:470 [inline]
 __mptcp_retrans.cold+0x72/0x77 net/mptcp/protocol.c:2445
 mptcp_worker+0x58a/0xa70 net/mptcp/protocol.c:2528
 process_one_work+0x9df/0x16d0 kernel/workqueue.c:2307
 worker_thread+0x95/0xe10 kernel/workqueue.c:2454
 kthread+0x2f4/0x3b0 kernel/kthread.c:377
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
 </TASK>
================================================================================

This change limits the maximum timeout by limiting the size of the shift, which keeps all intermediate values in-bounds.

---
 net/mptcp/protocol.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +5 -2
index 12bb28c5007e..1c72f25f083e 100644
@@ -466,9 +466,12 @@ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
 static void mptcp_set_datafin_timeout(const struct sock *sk)
 {
 	struct inet_connection_sock *icsk = inet_csk(sk);
+	u32 retransmits;
 
-	mptcp_sk(sk)->timer_ival = min(TCP_RTO_MAX,
-				       TCP_RTO_MIN << icsk->icsk_retransmits);
+	retransmits = min_t(u32, icsk->icsk_retransmits,
+			    ilog2(TCP_RTO_MAX / TCP_RTO_MIN));
+
+	mptcp_sk(sk)->timer_ival = TCP_RTO_MIN << retransmits;
 }
 
 static void __mptcp_set_timeout(struct sock *sk, long tout)
Signature · 1 line
2.35.1
#4 lore raw
In reply to Mat Martineau
This series was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 24 Feb 2022 16:52:56 -0800 you wrote:

Patch 1 fixes an issue with the SIOCOUTQ ioctl in MPTCP sockets that have performed a fallback to TCP.

Patch 2 is a selftest fix to correctly remove temp files.

Patch 3 fixes a shift-out-of-bounds issue found by syzkaller.

[...]

Here is the summary with links:
- [net,1/3] mptcp: accurate SIOCOUTQ for fallback socket

    https://git.kernel.org/netdev/net/c/07c2c7a3b622
  - [net,2/3] selftests: mptcp: do complete cleanup at exit
    https://git.kernel.org/netdev/net/c/63bb8239d805
  - [net,3/3] mptcp: Correctly set DATA_FIN timeout when number of retransmits is large
    https://git.kernel.org/netdev/net/c/877d11f0332c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html