Skip to contentSkip to conversation

Squash to "ADD_ADDR: ports support v4"

PATCH In review Geliang Tang 3 participants 7 messages Nov 16, 2020 – Nov 17, 2020

Subsystems (3)
lore
Share & tools
lore

Geliang Tang

author
#0 lore raw

cover Squash to "ADD_ADDR: ports support v4"

This patchset includes a squash-to patch and two new patch. They all should be squashed into the "ADD_ADDR: ports support v4" series.

The first new patch should be inserted into the patchset after the 8th patch "mptcp: print out port and ahmac when receiving ADD_ADDR".

The second new patch should be inserted into the patchset after the 9th patch "mptcp: add port number check for MP_JOIN".

Geliang Tang (3):
mptcp: create listening socket for new port
mptcp: add new flag listen_new_port
Squash to "selftests: mptcp: add testcases for ADD_ADDR with port"

 net/mptcp/pm_netlink.c                        |  3 +
 net/mptcp/protocol.h                          |  4 +-
 net/mptcp/subflow.c                           | 59 +++++++++++++++----
 .../testing/selftests/net/mptcp/mptcp_join.sh | 29 ++++++---
 4 files changed, 77 insertions(+), 18 deletions(-)
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH 1/3 mptcp: create listening socket for new port

This patch created the listening socket from the kernel side, binded the new port to the listening socket, then listened.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>

---
mptcp_subflow_create_socket will fail here since the sk->sk_socket is null. I simply dropped this null checking which was been added by Paolo in the commit "adf7341064982 (mptcp: be careful on subflow creation)".

---
 net/mptcp/pm_netlink.c |  3 +++
 net/mptcp/protocol.h   |  1 +
 net/mptcp/subflow.c    | 55 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 50 insertions(+), 9 deletions(-)
net/mptcp/pm_netlink.c +3 -0
index b325d04e65e7..b3514e8c01d3 100644
@@ -347,6 +347,9 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 			if (mptcp_pm_alloc_anno_list(msk, local)) {
 				msk->pm.add_addr_signaled++;
 				mptcp_pm_announce_addr(msk, &local->addr, false, local->addr.port);
+				spin_unlock_bh(&msk->pm.lock);
+				mptcp_subflow_listen_new_port(msk, local->addr.port);
+				spin_lock_bh(&msk->pm.lock);
 				mptcp_pm_nl_add_addr_send_ack(msk);
 			}
 		} else {
net/mptcp/protocol.h +1 -0
index 37c7d77d4376..0ee63f6b54b4 100644
@@ -445,6 +445,7 @@ void mptcp_subflow_reset(struct sock *ssk);
 int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 			    const struct mptcp_addr_info *remote);
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
+void mptcp_subflow_listen_new_port(struct mptcp_sock *msk, __be16 port);
 
 static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
 					      struct mptcp_subflow_context *ctx)
net/mptcp/subflow.c +46 -9

73 lines not on this page · raw message

Signature · 1 line
2.26.2
author
#2 lore raw

PATCH 2/3 mptcp: add new flag listen_new_port

This patch added a new flag listen_new_port, to mark the new port has been listened in the kernel side. If the new port has been listened from the userspace, kernel_bind() in mptcp_subflow_listen_new_port will fail, the listen_new_port flag will be not set, then the connection will be aborted in subflow_init_req.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/protocol.h | 3 ++-
 net/mptcp/subflow.c  | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)
net/mptcp/protocol.h +2 -1
index 0ee63f6b54b4..6508ca895f02 100644
@@ -372,7 +372,8 @@ struct mptcp_subflow_context {
 		backup : 1,
 		rx_eof : 1,
 		can_ack : 1,        /* only after processing the remote a key */
-		disposable : 1;	    /* ctx can be free at ulp release time */
+		disposable : 1,	    /* ctx can be free at ulp release time */
+		listen_new_port : 1;
 	enum mptcp_data_avail data_avail;
 	u32	remote_nonce;
 	u64	thmac;
net/mptcp/subflow.c +3 -1
index 38a77cc98d2b..47826e4c9534 100644
@@ -192,7 +192,8 @@ static void subflow_init_req(struct request_sock *req,
 			pr_debug("syn inet_sport=%d %d",
 				 ntohs(inet_sk(sk_listener)->inet_sport),
 				 ntohs(inet_sk((struct sock *)subflow_req->msk)->inet_sport));
-			if (!mptcp_pm_sport_in_anno_list(subflow_req->msk, sk_listener)) {
+			if (!mptcp_pm_sport_in_anno_list(subflow_req->msk, sk_listener) ||
+			    !listener->listen_new_port) {
 				subflow_req->mp_join = 0;
 				return;
 			}
@@ -1209,6 +1210,7 @@ void mptcp_subflow_listen_new_port(struct mptcp_sock *msk, __be16 port)
 	if (err)
 		return;
 
+	subflow->listen_new_port = 1;
 	pr_debug("listen_new_port done");
 }
 
Signature · 1 line
2.26.2
author
#3 lore raw

PATCH 3/3 Squash to "selftests: mptcp: add testcases for ADD_ADDR with port"

Added a new test for listening the new port from userspace.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 29 ++++++++++++++-----
 1 file changed, 22 insertions(+), 7 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +22 -7
index 8fe184a5ef25..e5669f79b1ad 100755
@@ -257,6 +257,7 @@ do_transfer()
 	if [ "$with_port" -gt 0 ];then
 		ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $with_port \
 			-s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
+		spid_with_port=$!
 	fi
 
 	sleep 1
@@ -298,6 +299,11 @@ do_transfer()
 	wait $spid
 	rets=$?
 
+	if [ "$with_port" -gt 0 ];then
+		sleep 1
+		kill $spid_with_port
+	fi
+
 	if [ $capture -eq 1 ]; then
 	    sleep 1
 	    kill $cappid
@@ -437,9 +443,9 @@ chk_add_nr()
 	local add_nr=$1
 	local echo_nr=$2
 	local port_nr=${3:-0}
-	local syn_nr=$port_nr
-	local syn_ack_nr=$port_nr
-	local ack_nr=$port_nr
+	local syn_nr=${4:-$port_nr}
+	local syn_ack_nr=${5:-$port_nr}
+	local ack_nr=${6:-$port_nr}
 	local count
 	local dump_stats
 
@@ -781,7 +787,7 @@ reset
 ip netns exec $ns1 ./pm_nl_ctl limits 0 1
 ip netns exec $ns2 ./pm_nl_ctl limits 1 1
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
-run_tests $ns1 $ns2 10.0.1.1 0 0 0 fast 10100
+run_tests $ns1 $ns2 10.0.1.1 0 0 0 fast
 chk_join_nr "signal address with port" 1 1 1
 chk_add_nr 1 1 1
 
@@ -791,7 +797,7 @@ ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
 ip netns exec $ns1 ./pm_nl_ctl limits 0 2
 ip netns exec $ns2 ./pm_nl_ctl limits 1 2
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
-run_tests $ns1 $ns2 10.0.1.1 0 0 0 fast 10100
+run_tests $ns1 $ns2 10.0.1.1 0 0 0 fast
 chk_join_nr "subflow and signal with port" 2 2 2
 chk_add_nr 1 1 1
 
@@ -800,7 +806,7 @@ reset
 ip netns exec $ns1 ./pm_nl_ctl limits 0 1
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
 ip netns exec $ns2 ./pm_nl_ctl limits 1 1
-run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow 10100
+run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
 chk_join_nr "remove single address with port" 1 1 1
 chk_add_nr 1 1 1
 chk_rm_nr 0 0
@@ -811,11 +817,20 @@ ip netns exec $ns1 ./pm_nl_ctl limits 0 2
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
 ip netns exec $ns2 ./pm_nl_ctl limits 1 2
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
-run_tests $ns1 $ns2 10.0.1.1 0 1 1 slow 10100
+run_tests $ns1 $ns2 10.0.1.1 0 1 1 slow
 chk_join_nr "remove subflow and signal with port" 2 2 2
 chk_add_nr 1 1 1
 chk_rm_nr 1 1
 
+# signal address with port, userspace
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl limits 1 1
+ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
+run_tests $ns1 $ns2 10.0.1.1 0 0 0 fast 10100
+chk_join_nr "signal address with port, userspace" 1 0 0
+chk_add_nr 1 1 1 0 0 0
+
 # single subflow, syncookies
 reset_with_cookies
 ip netns exec $ns1 ./pm_nl_ctl limits 0 1
Signature · 1 line
2.26.2
#4 lore raw

[MPTCP] Re: [MPTCP][PATCH mptcp-next 1/3] mptcp: create listening socket for new port

In reply to Geliang Tang
Quoted 70 lines · Geliang Tang

This patch created the listening socket from the kernel side, binded the new port to the listening socket, then listened.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>

---
mptcp_subflow_create_socket will fail here since the sk->sk_socket is null. I simply dropped this null checking which was been added by Paolo in the commit "adf7341064982 (mptcp: be careful on subflow creation)".

---
 net/mptcp/pm_netlink.c |  3 +++
 net/mptcp/protocol.h   |  1 +
 net/mptcp/subflow.c    | 55 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 50 insertions(+), 9 deletions(-)
net/mptcp/pm_netlink.c +3 -0
index b325d04e65e7..b3514e8c01d3 100644
@@ -347,6 +347,9 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 			if (mptcp_pm_alloc_anno_list(msk, local)) {
 				msk->pm.add_addr_signaled++;
 				mptcp_pm_announce_addr(msk, &local->addr, false, local->addr.port);
+				spin_unlock_bh(&msk->pm.lock);
+				mptcp_subflow_listen_new_port(msk, local->addr.port);
+				spin_lock_bh(&msk->pm.lock);
 				mptcp_pm_nl_add_addr_send_ack(msk);
 			}
 		} else {
net/mptcp/protocol.h +1 -0
index 37c7d77d4376..0ee63f6b54b4 100644
@@ -445,6 +445,7 @@ void mptcp_subflow_reset(struct sock *ssk);
 int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 			    const struct mptcp_addr_info *remote);
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
+void mptcp_subflow_listen_new_port(struct mptcp_sock *msk, __be16 port);
 
 static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
 					      struct mptcp_subflow_context *ctx)
net/mptcp/subflow.c +22 -0
index e83f93d10612..38a77cc98d2b 100644
@@ -1172,6 +1172,46 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 	return err;
 }
 
+void mptcp_subflow_listen_new_port(struct mptcp_sock *msk, __be16 port)
+{
+	struct mptcp_subflow_context *subflow;
+	struct sock *sk = (struct sock *)msk;
+	struct mptcp_addr_info local;
+	struct sockaddr_storage addr;
+	struct socket *sf;
+	int backlog = 20;
+	int addrlen;
+	int err;
+
+	if (!port)
+		return;
+
+	if (!mptcp_is_fully_established(sk))
+		return;
+
+	err = mptcp_subflow_create_socket(sk, &sf);
+	if (err)
+		return;
+
+	subflow = mptcp_subflow_ctx(sf->sk);

net/mptcp/subflow.c int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, · line 1206

Quoted 10 lines
net/mptcp/subflow.c +10 -0
+	subflow->request_mptcp = 1;
+
+	memset(&local, 0, sizeof(local));
+	local.family = AF_INET;
+	local.port = port;
+	mptcp_info2sockaddr(&local, &addr);
+	addrlen = sizeof(struct sockaddr_in);
+	err = kernel_bind(sf, (struct sockaddr *)&addr, addrlen);
+	if (err)
+		return;

I think there are some problems with this approach:

1) if we have multiple MPTCP sockets, only the first one per netns will use the endpoint with the additional ports - the following will try to, and bind() will fail.

2) what if the msk socket does fallback to TCP after that the additional listening socket is created?

3) ownership for the listening socket could be wrong, see below...

Quoted 27 lines
net/mptcp/subflow.c +8 -6
+
+	err = sf->ops->listen(sf, backlog);
+	if (err)
+		return;
+
+	pr_debug("listen_new_port done");
+}
+
 static void mptcp_attach_cgroup(struct sock *parent, struct sock *child)
 {
 #ifdef CONFIG_SOCK_CGROUP_DATA
@@ -1203,12 +1243,6 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)
 	struct socket *sf;
 	int err;
 
-	/* un-accepted server sockets can reach here - on bad configuration
-	 * bail early to avoid greater trouble later
-	 */
-	if (unlikely(!sk->sk_socket))
-		return -EINVAL;
-
 	err = sock_create_kern(net, sk->sk_family, SOCK_STREAM, IPPROTO_TCP,
 			       &sf);
 	if (err)
@@ -1241,9 +1275,12 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)
 	 * procfs/diag interaces really show this one belonging to the correct
 	 * user.

net/mptcp/subflow.c int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock) · line 1283

Quoted 10 lines
net/mptcp/subflow.c +6 -3
 	 */
-	SOCK_INODE(sf)->i_ino = SOCK_INODE(sk->sk_socket)->i_ino;
-	SOCK_INODE(sf)->i_uid = SOCK_INODE(sk->sk_socket)->i_uid;
-	SOCK_INODE(sf)->i_gid = SOCK_INODE(sk->sk_socket)->i_gid;
+
+	if (sk->sk_socket) {
+		SOCK_INODE(sf)->i_ino = SOCK_INODE(sk->sk_socket)->i_ino;
+		SOCK_INODE(sf)->i_uid = SOCK_INODE(sk->sk_socket)->i_uid;
+		SOCK_INODE(sf)->i_gid = SOCK_INODE(sk->sk_socket)->i_gid;
+	}

When we hit the !sk->sk_socket scenario, ownership for the newly created socket will be uncorrect.

Possibly a more important point: does the above ensure proper isolation between processes and sockets ?

If I follow the code correctly, once that additional listening socket is created, any join request landing there will be able to attach to any msk - even outside the current netns with the current token infra.

I'm wondering if we could instead create a single listening socket per netns - when the first msk socket is created. That should avoid bind and fallback issues. Ownership should probably set explicitly to root, and the isolation issue will be still there.

Cheers,

Paolo

#5 lore raw

[MPTCP] Re: [MPTCP][PATCH mptcp-next 1/3] mptcp: create listening socket for new port

Quoted 15 lines · Paolo Abeni
Quoted 14 lines · Geliang Tang

This patch created the listening socket from the kernel side, binded the new port to the listening socket, then listened.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>

---
mptcp_subflow_create_socket will fail here since the sk->sk_socket is null. I simply dropped this null checking which was been added by Paolo in the commit "adf7341064982 (mptcp: be careful on subflow creation)".

---
 net/mptcp/pm_netlink.c |  3 +++
 net/mptcp/protocol.h   |  1 +
 net/mptcp/subflow.c    | 55 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 50 insertions(+), 9 deletions(-)

...

Quoted 11 lines

When we hit the !sk->sk_socket scenario, ownership for the newly created socket will be uncorrect.

Possibly a more important point: does the above ensure proper isolation between processes and sockets ?

If I follow the code correctly, once that additional listening socket is created, any join request landing there will be able to attach to any msk - even outside the current netns with the current token infra.

Does the per-msk port number checking in patch 9/13 (ADD_ADDR ports v4 series) address part of this?

https://patchwork.ozlabs.org/project/mptcp/patch/c32afb7d145744ba936bf37097c4120bd51c6c1a.1604984546.git.geliangtang(a)gmail.com/

Quoted 5 lines

I'm wondering if we could instead create a single listening socket per netns - when the first msk socket is created. That should avoid bind and fallback issues. Ownership should probably set explicitly to root, and the isolation issue will be still there.

Paolo's idea for a single listening socket per netns sounds good to me.

--
Mat Martineau
Intel

#6 lore raw

[MPTCP] Re: [MPTCP][PATCH mptcp-next 1/3] mptcp: create listening socket for new port

Quoted 31 lines · Mat Martineau
Quoted 15 lines · Paolo Abeni
Quoted 14 lines · Geliang Tang

This patch created the listening socket from the kernel side, binded the new port to the listening socket, then listened.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>

---
mptcp_subflow_create_socket will fail here since the sk->sk_socket is null. I simply dropped this null checking which was been added by Paolo in the commit "adf7341064982 (mptcp: be careful on subflow creation)".

---
 net/mptcp/pm_netlink.c |  3 +++
 net/mptcp/protocol.h   |  1 +
 net/mptcp/subflow.c    | 55 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 50 insertions(+), 9 deletions(-)

...

Quoted 10 lines

When we hit the !sk->sk_socket scenario, ownership for the newly created socket will be uncorrect.

Possibly a more important point: does the above ensure proper isolation between processes and sockets ?

If I follow the code correctly, once that additional listening socket is created, any join request landing there will be able to attach to any msk - even outside the current netns with the current token infra.

Quoted 4 lines

Does the per-msk port number checking in patch 9/13 (ADD_ADDR ports v4 series) address part of this?

https://patchwork.ozlabs.org/project/mptcp/patch/c32afb7d145744ba936bf37097c4120bd51c6c1a.1604984546.git.geliangtang(a)gmail.com/

Ooops, I missed that piece. Yes, looks safe to me. It should applies nicely also to alternative schema using a single listening socket per netns.

Cheers,

Paolo