All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs
@ 2021-12-14 23:16 Mat Martineau
  2021-12-14 23:16 ` [PATCH net 1/4] mptcp: remove tcp ulp setsockopt support Mat Martineau
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Mat Martineau @ 2021-12-14 23:16 UTC (permalink / raw)
  To: netdev; +Cc: Mat Martineau, davem, kuba, matthieu.baerts, mptcp

Two of the MPTCP fixes in this set are related to the TCP_ULP socket
option with MPTCP sockets operating in "fallback" mode (the connection
has reverted to regular TCP). The other issues are an observed deadlock
and missing parameter documentation in the MPTCP netlink API.


Patch 1 marks TCP_ULP as unsupported earlier in MPTCP setsockopt code,
so the fallback code path in the MPTCP layer does not pass the TCP_ULP
option down to the subflow TCP socket.

Patch 2 makes sure a TCP fallback socket returned to userspace by
accept()ing on a MPTCP listening socket does not allow use of the
"mptcp" TCP_ULP type. That ULP is intended only for use by in-kernel
MPTCP subflows.

Patch 3 fixes the possible deadlock when sending data and there are
socket option changes to sync to the subflows.

Patch 4 makes sure all MPTCP netlink event parameters are documented
in the MPTCP uapi header.


Florian Westphal (2):
  mptcp: remove tcp ulp setsockopt support
  mptcp: clear 'kern' flag from fallback sockets

Matthieu Baerts (1):
  mptcp: add missing documented NL params

Maxim Galaganov (1):
  mptcp: fix deadlock in __mptcp_push_pending()

 include/uapi/linux/mptcp.h | 18 ++++++++++--------
 net/mptcp/protocol.c       |  6 ++++--
 net/mptcp/sockopt.c        |  1 -
 3 files changed, 14 insertions(+), 11 deletions(-)


base-commit: 3dd7d40b43663f58d11ee7a3d3798813b26a48f1
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net 1/4] mptcp: remove tcp ulp setsockopt support
  2021-12-14 23:16 [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs Mat Martineau
@ 2021-12-14 23:16 ` Mat Martineau
  2021-12-14 23:16 ` [PATCH net 2/4] mptcp: clear 'kern' flag from fallback sockets Mat Martineau
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2021-12-14 23:16 UTC (permalink / raw)
  To: netdev
  Cc: Florian Westphal, davem, kuba, matthieu.baerts, mptcp, pabeni,
	syzbot+1fd9b69cde42967d1add, Mat Martineau

From: Florian Westphal <fw@strlen.de>

TCP_ULP setsockopt cannot be used for mptcp because its already
used internally to plumb subflow (tcp) sockets to the mptcp layer.

syzbot managed to trigger a crash for mptcp connections that are
in fallback mode:

KASAN: null-ptr-deref in range [0x0000000000000020-0x0000000000000027]
CPU: 1 PID: 1083 Comm: syz-executor.3 Not tainted 5.16.0-rc2-syzkaller #0
RIP: 0010:tls_build_proto net/tls/tls_main.c:776 [inline]
[..]
 __tcp_set_ulp net/ipv4/tcp_ulp.c:139 [inline]
 tcp_set_ulp+0x428/0x4c0 net/ipv4/tcp_ulp.c:160
 do_tcp_setsockopt+0x455/0x37c0 net/ipv4/tcp.c:3391
 mptcp_setsockopt+0x1b47/0x2400 net/mptcp/sockopt.c:638

Remove support for TCP_ULP setsockopt.

Fixes: d9e4c1291810 ("mptcp: only admit explicitly supported sockopt")
Reported-by: syzbot+1fd9b69cde42967d1add@syzkaller.appspotmail.com
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 net/mptcp/sockopt.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 0f1e661c2032..f8efd478ac97 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -525,7 +525,6 @@ static bool mptcp_supported_sockopt(int level, int optname)
 		case TCP_NODELAY:
 		case TCP_THIN_LINEAR_TIMEOUTS:
 		case TCP_CONGESTION:
-		case TCP_ULP:
 		case TCP_CORK:
 		case TCP_KEEPIDLE:
 		case TCP_KEEPINTVL:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 2/4] mptcp: clear 'kern' flag from fallback sockets
  2021-12-14 23:16 [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs Mat Martineau
  2021-12-14 23:16 ` [PATCH net 1/4] mptcp: remove tcp ulp setsockopt support Mat Martineau
@ 2021-12-14 23:16 ` Mat Martineau
  2021-12-14 23:16 ` [PATCH net 3/4] mptcp: fix deadlock in __mptcp_push_pending() Mat Martineau
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2021-12-14 23:16 UTC (permalink / raw)
  To: netdev
  Cc: Florian Westphal, davem, kuba, matthieu.baerts, mptcp, Mat Martineau

From: Florian Westphal <fw@strlen.de>

The mptcp ULP extension relies on sk->sk_sock_kern being set correctly:
It prevents setsockopt(fd, IPPROTO_TCP, TCP_ULP, "mptcp", 6); from
working for plain tcp sockets (any userspace-exposed socket).

But in case of fallback, accept() can return a plain tcp sk.
In such case, sk is still tagged as 'kernel' and setsockopt will work.

This will crash the kernel, The subflow extension has a NULL ctx->conn
mptcp socket:

BUG: KASAN: null-ptr-deref in subflow_data_ready+0x181/0x2b0
Call Trace:
 tcp_data_ready+0xf8/0x370
 [..]

Fixes: cf7da0d66cc1 ("mptcp: Create SUBFLOW socket for incoming connections")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---

Note: The original author of cf7da0d66cc1 is not cc'd because the email
address is no longer valid.

---
 net/mptcp/protocol.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index c82a76d2d0bf..6dc1ff07994c 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2879,7 +2879,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		 */
 		if (WARN_ON_ONCE(!new_mptcp_sock)) {
 			tcp_sk(newsk)->is_mptcp = 0;
-			return newsk;
+			goto out;
 		}
 
 		/* acquire the 2nd reference for the owning socket */
@@ -2891,6 +2891,8 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 				MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK);
 	}
 
+out:
+	newsk->sk_kern_sock = kern;
 	return newsk;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 3/4] mptcp: fix deadlock in __mptcp_push_pending()
  2021-12-14 23:16 [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs Mat Martineau
  2021-12-14 23:16 ` [PATCH net 1/4] mptcp: remove tcp ulp setsockopt support Mat Martineau
  2021-12-14 23:16 ` [PATCH net 2/4] mptcp: clear 'kern' flag from fallback sockets Mat Martineau
@ 2021-12-14 23:16 ` Mat Martineau
  2021-12-14 23:16 ` [PATCH net 4/4] mptcp: add missing documented NL params Mat Martineau
  2021-12-15  4:40 ` [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2021-12-14 23:16 UTC (permalink / raw)
  To: netdev
  Cc: Maxim Galaganov, davem, kuba, matthieu.baerts, mptcp, fw, Mat Martineau

From: Maxim Galaganov <max@internet.ru>

__mptcp_push_pending() may call mptcp_flush_join_list() with subflow
socket lock held. If such call hits mptcp_sockopt_sync_all() then
subsequently __mptcp_sockopt_sync() could try to lock the subflow
socket for itself, causing a deadlock.

sysrq: Show Blocked State
task:ss-server       state:D stack:    0 pid:  938 ppid:     1 flags:0x00000000
Call Trace:
 <TASK>
 __schedule+0x2d6/0x10c0
 ? __mod_memcg_state+0x4d/0x70
 ? csum_partial+0xd/0x20
 ? _raw_spin_lock_irqsave+0x26/0x50
 schedule+0x4e/0xc0
 __lock_sock+0x69/0x90
 ? do_wait_intr_irq+0xa0/0xa0
 __lock_sock_fast+0x35/0x50
 mptcp_sockopt_sync_all+0x38/0xc0
 __mptcp_push_pending+0x105/0x200
 mptcp_sendmsg+0x466/0x490
 sock_sendmsg+0x57/0x60
 __sys_sendto+0xf0/0x160
 ? do_wait_intr_irq+0xa0/0xa0
 ? fpregs_restore_userregs+0x12/0xd0
 __x64_sys_sendto+0x20/0x30
 do_syscall_64+0x38/0x90
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f9ba546c2d0
RSP: 002b:00007ffdc3b762d8 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 00007f9ba56c8060 RCX: 00007f9ba546c2d0
RDX: 000000000000077a RSI: 0000000000e5e180 RDI: 0000000000000234
RBP: 0000000000cc57f0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f9ba56c8060
R13: 0000000000b6ba60 R14: 0000000000cc7840 R15: 41d8685b1d7901b8
 </TASK>

Fix the issue by using __mptcp_flush_join_list() instead of plain
mptcp_flush_join_list() inside __mptcp_push_pending(), as suggested by
Florian. The sockopt sync will be deferred to the workqueue.

Fixes: 1b3e7ede1365 ("mptcp: setsockopt: handle SO_KEEPALIVE and SO_PRIORITY")
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/244
Suggested-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Maxim Galaganov <max@internet.ru>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 net/mptcp/protocol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 6dc1ff07994c..54613f5b7521 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1524,7 +1524,7 @@ void __mptcp_push_pending(struct sock *sk, unsigned int flags)
 			int ret = 0;
 
 			prev_ssk = ssk;
-			mptcp_flush_join_list(msk);
+			__mptcp_flush_join_list(msk);
 			ssk = mptcp_subflow_get_send(msk);
 
 			/* First check. If the ssk has changed since
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 4/4] mptcp: add missing documented NL params
  2021-12-14 23:16 [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs Mat Martineau
                   ` (2 preceding siblings ...)
  2021-12-14 23:16 ` [PATCH net 3/4] mptcp: fix deadlock in __mptcp_push_pending() Mat Martineau
@ 2021-12-14 23:16 ` Mat Martineau
  2021-12-15  4:40 ` [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2021-12-14 23:16 UTC (permalink / raw)
  To: netdev; +Cc: Matthieu Baerts, davem, kuba, mptcp, fw, Mat Martineau

From: Matthieu Baerts <matthieu.baerts@tessares.net>

'loc_id' and 'rem_id' are set in all events linked to subflows but those
were missing in the events description in the comments.

Fixes: b911c97c7dc7 ("mptcp: add netlink event support")
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 include/uapi/linux/mptcp.h | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
index c8cc46f80a16..f106a3941cdf 100644
--- a/include/uapi/linux/mptcp.h
+++ b/include/uapi/linux/mptcp.h
@@ -136,19 +136,21 @@ struct mptcp_info {
  * MPTCP_EVENT_REMOVED: token, rem_id
  * An address has been lost by the peer.
  *
- * MPTCP_EVENT_SUB_ESTABLISHED: token, family, saddr4 | saddr6,
- *                              daddr4 | daddr6, sport, dport, backup,
- *                              if_idx [, error]
+ * MPTCP_EVENT_SUB_ESTABLISHED: token, family, loc_id, rem_id,
+ *                              saddr4 | saddr6, daddr4 | daddr6, sport,
+ *                              dport, backup, if_idx [, error]
  * A new subflow has been established. 'error' should not be set.
  *
- * MPTCP_EVENT_SUB_CLOSED: token, family, saddr4 | saddr6, daddr4 | daddr6,
- *                         sport, dport, backup, if_idx [, error]
+ * MPTCP_EVENT_SUB_CLOSED: token, family, loc_id, rem_id, saddr4 | saddr6,
+ *                         daddr4 | daddr6, sport, dport, backup, if_idx
+ *                         [, error]
  * A subflow has been closed. An error (copy of sk_err) could be set if an
  * error has been detected for this subflow.
  *
- * MPTCP_EVENT_SUB_PRIORITY: token, family, saddr4 | saddr6, daddr4 | daddr6,
- *                           sport, dport, backup, if_idx [, error]
- *       The priority of a subflow has changed. 'error' should not be set.
+ * MPTCP_EVENT_SUB_PRIORITY: token, family, loc_id, rem_id, saddr4 | saddr6,
+ *                           daddr4 | daddr6, sport, dport, backup, if_idx
+ *                           [, error]
+ * The priority of a subflow has changed. 'error' should not be set.
  */
 enum mptcp_event_type {
 	MPTCP_EVENT_UNSPEC = 0,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs
  2021-12-14 23:16 [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs Mat Martineau
                   ` (3 preceding siblings ...)
  2021-12-14 23:16 ` [PATCH net 4/4] mptcp: add missing documented NL params Mat Martineau
@ 2021-12-15  4:40 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-15  4:40 UTC (permalink / raw)
  To: Mat Martineau; +Cc: netdev, davem, kuba, matthieu.baerts, mptcp

Hello:

This series was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 14 Dec 2021 15:16:00 -0800 you wrote:
> Two of the MPTCP fixes in this set are related to the TCP_ULP socket
> option with MPTCP sockets operating in "fallback" mode (the connection
> has reverted to regular TCP). The other issues are an observed deadlock
> and missing parameter documentation in the MPTCP netlink API.
> 
> 
> Patch 1 marks TCP_ULP as unsupported earlier in MPTCP setsockopt code,
> so the fallback code path in the MPTCP layer does not pass the TCP_ULP
> option down to the subflow TCP socket.
> 
> [...]

Here is the summary with links:
  - [net,1/4] mptcp: remove tcp ulp setsockopt support
    https://git.kernel.org/netdev/net/c/404cd9a22150
  - [net,2/4] mptcp: clear 'kern' flag from fallback sockets
    https://git.kernel.org/netdev/net/c/d6692b3b97bd
  - [net,3/4] mptcp: fix deadlock in __mptcp_push_pending()
    https://git.kernel.org/netdev/net/c/3d79e3756ca9
  - [net,4/4] mptcp: add missing documented NL params
    https://git.kernel.org/netdev/net/c/6813b1928758

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-15  4:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 23:16 [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs Mat Martineau
2021-12-14 23:16 ` [PATCH net 1/4] mptcp: remove tcp ulp setsockopt support Mat Martineau
2021-12-14 23:16 ` [PATCH net 2/4] mptcp: clear 'kern' flag from fallback sockets Mat Martineau
2021-12-14 23:16 ` [PATCH net 3/4] mptcp: fix deadlock in __mptcp_push_pending() Mat Martineau
2021-12-14 23:16 ` [PATCH net 4/4] mptcp: add missing documented NL params Mat Martineau
2021-12-15  4:40 ` [PATCH net 0/4] mptcp: Fixes for ULP, a deadlock, and netlink docs patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.