All of lore.kernel.org
 help / color / mirror / Atom feed
* [MPTCP] [PATCH net-next v2 0/3] mptcp: fix MP_JOIN failure handling
@ 2020-05-15 17:22 ` Paolo Abeni
  0 siblings, 0 replies; 18+ messages in thread
From: Paolo Abeni @ 2020-05-15 17:22 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 1532 bytes --]

Currently if we hit an MP_JOIN failure on the third ack, the child socket is
closed with reset, but the request socket is not deleted, causing weird
behaviors.

The main problem is that MPTCP's MP_JOIN code needs to plug it's own
'valid 3rd ack' checks and the current TCP callbacks do not allow that.

This series tries to address the above shortcoming introducing a new MPTCP
specific bit in a 'struct tcp_request_sock' hole, and leveraging that to allow
tcp_check_req releasing the request socket when needed.

The above allows cleaning-up a bit current MPTCP hooking in tcp_check_req().

An alternative solution, possibly cleaner but more invasive, would be
changing the 'bool *own_req' syn_recv_sock() argument into 'int *req_status'
and let MPTCP set it to 'REQ_DROP'.

v1 -> v2:
 - be more conservative about drop_req initialization

RFC -> v1:
 - move the drop_req bit inside tcp_request_sock (Eric)

Paolo Abeni (3):
  mptcp: add new sock flag to deal with join subflows
  inet_connection_sock: factor out destroy helper.
  mptcp: cope better with MP_JOIN failure

 include/linux/tcp.h                |  3 +++
 include/net/inet_connection_sock.h |  8 ++++++++
 include/net/mptcp.h                | 17 ++++++++++-------
 net/ipv4/inet_connection_sock.c    |  6 +-----
 net/ipv4/tcp_minisocks.c           |  2 +-
 net/mptcp/protocol.c               |  7 -------
 net/mptcp/subflow.c                | 18 ++++++++++++------
 7 files changed, 35 insertions(+), 26 deletions(-)

-- 
2.21.3

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

* [PATCH net-next v2 0/3] mptcp: fix MP_JOIN failure handling
@ 2020-05-15 17:22 ` Paolo Abeni
  0 siblings, 0 replies; 18+ messages in thread
From: Paolo Abeni @ 2020-05-15 17:22 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, David S . Miller, Christoph Paasch, mptcp, Mat Martineau

Currently if we hit an MP_JOIN failure on the third ack, the child socket is
closed with reset, but the request socket is not deleted, causing weird
behaviors.

The main problem is that MPTCP's MP_JOIN code needs to plug it's own
'valid 3rd ack' checks and the current TCP callbacks do not allow that.

This series tries to address the above shortcoming introducing a new MPTCP
specific bit in a 'struct tcp_request_sock' hole, and leveraging that to allow
tcp_check_req releasing the request socket when needed.

The above allows cleaning-up a bit current MPTCP hooking in tcp_check_req().

An alternative solution, possibly cleaner but more invasive, would be
changing the 'bool *own_req' syn_recv_sock() argument into 'int *req_status'
and let MPTCP set it to 'REQ_DROP'.

v1 -> v2:
 - be more conservative about drop_req initialization

RFC -> v1:
 - move the drop_req bit inside tcp_request_sock (Eric)

Paolo Abeni (3):
  mptcp: add new sock flag to deal with join subflows
  inet_connection_sock: factor out destroy helper.
  mptcp: cope better with MP_JOIN failure

 include/linux/tcp.h                |  3 +++
 include/net/inet_connection_sock.h |  8 ++++++++
 include/net/mptcp.h                | 17 ++++++++++-------
 net/ipv4/inet_connection_sock.c    |  6 +-----
 net/ipv4/tcp_minisocks.c           |  2 +-
 net/mptcp/protocol.c               |  7 -------
 net/mptcp/subflow.c                | 18 ++++++++++++------
 7 files changed, 35 insertions(+), 26 deletions(-)

-- 
2.21.3


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

* [MPTCP] [PATCH net-next v2 1/3] mptcp: add new sock flag to deal with join subflows
  2020-05-15 17:22 ` Paolo Abeni
@ 2020-05-15 17:22 ` Paolo Abeni
  -1 siblings, 0 replies; 18+ messages in thread
From: Paolo Abeni @ 2020-05-15 17:22 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 5203 bytes --]

MP_JOIN subflows must not land into the accept queue.
Currently tcp_check_req() calls an mptcp specific helper
to detect such scenario.

Such helper leverages the subflow context to check for
MP_JOIN subflows. We need to deal also with MP JOIN
failures, even when the subflow context is not available
due allocation failure.

A possible solution would be changing the syn_recv_sock()
signature to allow returning a more descriptive action/
error code and deal with that in tcp_check_req().

Since the above need is MPTCP specific, this patch instead
uses a TCP request socket hole to add a MPTCP specific flag.
Such flag is used by the MPTCP syn_recv_sock() to tell
tcp_check_req() how to deal with the request socket.

This change is a no-op for !MPTCP build, and makes the
MPTCP code simpler. It allows also the next patch to deal
correctly with MP JOIN failure.

v1 -> v2:
 - be more conservative on drop_req initialization (Mat)

RFC -> v1:
 - move the drop_req bit inside tcp_request_sock (Eric)

Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
---
 include/linux/tcp.h      |  3 +++
 include/net/mptcp.h      | 17 ++++++++++-------
 net/ipv4/tcp_minisocks.c |  2 +-
 net/mptcp/protocol.c     |  7 -------
 net/mptcp/subflow.c      |  3 +++
 5 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index e60db06ec28d..bf44e85d709d 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -120,6 +120,9 @@ struct tcp_request_sock {
 	u64				snt_synack; /* first SYNACK sent time */
 	bool				tfo_listener;
 	bool				is_mptcp;
+#if IS_ENABLED(CONFIG_MPTCP)
+	bool				drop_req;
+#endif
 	u32				txhash;
 	u32				rcv_isn;
 	u32				snt_isn;
diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index e60275659de6..c4a6ef4ba35b 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -68,6 +68,11 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)
 	return tcp_rsk(req)->is_mptcp;
 }
 
+static inline bool rsk_drop_req(const struct request_sock *req)
+{
+	return tcp_rsk(req)->is_mptcp && tcp_rsk(req)->drop_req;
+}
+
 void mptcp_space(const struct sock *ssk, int *space, int *full_space);
 bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
 		       unsigned int *size, struct mptcp_out_options *opts);
@@ -121,8 +126,6 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
 				 skb_ext_find(from, SKB_EXT_MPTCP));
 }
 
-bool mptcp_sk_is_subflow(const struct sock *sk);
-
 void mptcp_seq_show(struct seq_file *seq);
 #else
 
@@ -140,6 +143,11 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)
 	return false;
 }
 
+static inline bool rsk_drop_req(const struct request_sock *req)
+{
+	return false;
+}
+
 static inline void mptcp_parse_option(const struct sk_buff *skb,
 				      const unsigned char *ptr, int opsize,
 				      struct tcp_options_received *opt_rx)
@@ -190,11 +198,6 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
 	return true;
 }
 
-static inline bool mptcp_sk_is_subflow(const struct sock *sk)
-{
-	return false;
-}
-
 static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { }
 static inline void mptcp_seq_show(struct seq_file *seq) { }
 #endif /* CONFIG_MPTCP */
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 7e40322cc5ec..495dda2449fe 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -774,7 +774,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 	if (!child)
 		goto listen_overflow;
 
-	if (own_req && sk_is_mptcp(child) && mptcp_sk_is_subflow(child)) {
+	if (own_req && rsk_drop_req(req)) {
 		reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req);
 		inet_csk_reqsk_queue_drop_and_put(sk, req);
 		return child;
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 6a812dd8b6b6..b974898eb6b5 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1687,13 +1687,6 @@ bool mptcp_finish_join(struct sock *sk)
 	return ret;
 }
 
-bool mptcp_sk_is_subflow(const struct sock *sk)
-{
-	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
-
-	return subflow->mp_join == 1;
-}
-
 static bool mptcp_memory_free(const struct sock *sk, int wake)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 009d5c478062..5e03ed8ae899 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -470,6 +470,8 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 	if (child && *own_req) {
 		struct mptcp_subflow_context *ctx = mptcp_subflow_ctx(child);
 
+		tcp_rsk(req)->drop_req = false;
+
 		/* we need to fallback on ctx allocation failure and on pre-reqs
 		 * checking above. In the latter scenario we additionally need
 		 * to reset the context to non MPTCP status.
@@ -512,6 +514,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 				goto close_child;
 
 			SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINACKRX);
+			tcp_rsk(req)->drop_req = true;
 		}
 	}
 
-- 
2.21.3

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

* [PATCH net-next v2 1/3] mptcp: add new sock flag to deal with join subflows
@ 2020-05-15 17:22 ` Paolo Abeni
  0 siblings, 0 replies; 18+ messages in thread
From: Paolo Abeni @ 2020-05-15 17:22 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, David S . Miller, Christoph Paasch, mptcp, Mat Martineau

MP_JOIN subflows must not land into the accept queue.
Currently tcp_check_req() calls an mptcp specific helper
to detect such scenario.

Such helper leverages the subflow context to check for
MP_JOIN subflows. We need to deal also with MP JOIN
failures, even when the subflow context is not available
due allocation failure.

A possible solution would be changing the syn_recv_sock()
signature to allow returning a more descriptive action/
error code and deal with that in tcp_check_req().

Since the above need is MPTCP specific, this patch instead
uses a TCP request socket hole to add a MPTCP specific flag.
Such flag is used by the MPTCP syn_recv_sock() to tell
tcp_check_req() how to deal with the request socket.

This change is a no-op for !MPTCP build, and makes the
MPTCP code simpler. It allows also the next patch to deal
correctly with MP JOIN failure.

v1 -> v2:
 - be more conservative on drop_req initialization (Mat)

RFC -> v1:
 - move the drop_req bit inside tcp_request_sock (Eric)

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 include/linux/tcp.h      |  3 +++
 include/net/mptcp.h      | 17 ++++++++++-------
 net/ipv4/tcp_minisocks.c |  2 +-
 net/mptcp/protocol.c     |  7 -------
 net/mptcp/subflow.c      |  3 +++
 5 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index e60db06ec28d..bf44e85d709d 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -120,6 +120,9 @@ struct tcp_request_sock {
 	u64				snt_synack; /* first SYNACK sent time */
 	bool				tfo_listener;
 	bool				is_mptcp;
+#if IS_ENABLED(CONFIG_MPTCP)
+	bool				drop_req;
+#endif
 	u32				txhash;
 	u32				rcv_isn;
 	u32				snt_isn;
diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index e60275659de6..c4a6ef4ba35b 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -68,6 +68,11 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)
 	return tcp_rsk(req)->is_mptcp;
 }
 
+static inline bool rsk_drop_req(const struct request_sock *req)
+{
+	return tcp_rsk(req)->is_mptcp && tcp_rsk(req)->drop_req;
+}
+
 void mptcp_space(const struct sock *ssk, int *space, int *full_space);
 bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
 		       unsigned int *size, struct mptcp_out_options *opts);
@@ -121,8 +126,6 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
 				 skb_ext_find(from, SKB_EXT_MPTCP));
 }
 
-bool mptcp_sk_is_subflow(const struct sock *sk);
-
 void mptcp_seq_show(struct seq_file *seq);
 #else
 
@@ -140,6 +143,11 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)
 	return false;
 }
 
+static inline bool rsk_drop_req(const struct request_sock *req)
+{
+	return false;
+}
+
 static inline void mptcp_parse_option(const struct sk_buff *skb,
 				      const unsigned char *ptr, int opsize,
 				      struct tcp_options_received *opt_rx)
@@ -190,11 +198,6 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
 	return true;
 }
 
-static inline bool mptcp_sk_is_subflow(const struct sock *sk)
-{
-	return false;
-}
-
 static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { }
 static inline void mptcp_seq_show(struct seq_file *seq) { }
 #endif /* CONFIG_MPTCP */
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 7e40322cc5ec..495dda2449fe 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -774,7 +774,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 	if (!child)
 		goto listen_overflow;
 
-	if (own_req && sk_is_mptcp(child) && mptcp_sk_is_subflow(child)) {
+	if (own_req && rsk_drop_req(req)) {
 		reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req);
 		inet_csk_reqsk_queue_drop_and_put(sk, req);
 		return child;
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 6a812dd8b6b6..b974898eb6b5 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1687,13 +1687,6 @@ bool mptcp_finish_join(struct sock *sk)
 	return ret;
 }
 
-bool mptcp_sk_is_subflow(const struct sock *sk)
-{
-	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
-
-	return subflow->mp_join == 1;
-}
-
 static bool mptcp_memory_free(const struct sock *sk, int wake)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 009d5c478062..5e03ed8ae899 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -470,6 +470,8 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 	if (child && *own_req) {
 		struct mptcp_subflow_context *ctx = mptcp_subflow_ctx(child);
 
+		tcp_rsk(req)->drop_req = false;
+
 		/* we need to fallback on ctx allocation failure and on pre-reqs
 		 * checking above. In the latter scenario we additionally need
 		 * to reset the context to non MPTCP status.
@@ -512,6 +514,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 				goto close_child;
 
 			SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINACKRX);
+			tcp_rsk(req)->drop_req = true;
 		}
 	}
 
-- 
2.21.3


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

* [MPTCP] [PATCH net-next v2 2/3] inet_connection_sock: factor out destroy helper.
  2020-05-15 17:22 ` Paolo Abeni
@ 2020-05-15 17:22 ` Paolo Abeni
  -1 siblings, 0 replies; 18+ messages in thread
From: Paolo Abeni @ 2020-05-15 17:22 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 1946 bytes --]

Move the steps to prepare an inet_connection_sock for
forced disposal inside a separate helper. No functional
changes inteded, this will just simplify the next patch.

Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
Reviewed-by: Christoph Paasch <cpaasch(a)apple.com>
---
 include/net/inet_connection_sock.h | 8 ++++++++
 net/ipv4/inet_connection_sock.c    | 6 +-----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index a3f076befa4f..2f1f8c3efb26 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -287,6 +287,14 @@ static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
 void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
 void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req);
 
+static inline void inet_csk_prepare_for_destroy_sock(struct sock *sk)
+{
+	/* The below has to be done to allow calling inet_csk_destroy_sock */
+	sock_set_flag(sk, SOCK_DEAD);
+	percpu_counter_inc(sk->sk_prot->orphan_count);
+	inet_sk(sk)->inet_num = 0;
+}
+
 void inet_csk_destroy_sock(struct sock *sk);
 void inet_csk_prepare_forced_close(struct sock *sk);
 
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 5f34eb951627..d6faf3702824 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -896,11 +896,7 @@ void inet_csk_prepare_forced_close(struct sock *sk)
 	/* sk_clone_lock locked the socket and set refcnt to 2 */
 	bh_unlock_sock(sk);
 	sock_put(sk);
-
-	/* The below has to be done to allow calling inet_csk_destroy_sock */
-	sock_set_flag(sk, SOCK_DEAD);
-	percpu_counter_inc(sk->sk_prot->orphan_count);
-	inet_sk(sk)->inet_num = 0;
+	inet_csk_prepare_for_destroy_sock(sk);
 }
 EXPORT_SYMBOL(inet_csk_prepare_forced_close);
 
-- 
2.21.3

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

* [PATCH net-next v2 2/3] inet_connection_sock: factor out destroy helper.
@ 2020-05-15 17:22 ` Paolo Abeni
  0 siblings, 0 replies; 18+ messages in thread
From: Paolo Abeni @ 2020-05-15 17:22 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, David S . Miller, Christoph Paasch, mptcp, Mat Martineau

Move the steps to prepare an inet_connection_sock for
forced disposal inside a separate helper. No functional
changes inteded, this will just simplify the next patch.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Christoph Paasch <cpaasch@apple.com>
---
 include/net/inet_connection_sock.h | 8 ++++++++
 net/ipv4/inet_connection_sock.c    | 6 +-----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index a3f076befa4f..2f1f8c3efb26 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -287,6 +287,14 @@ static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
 void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
 void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req);
 
+static inline void inet_csk_prepare_for_destroy_sock(struct sock *sk)
+{
+	/* The below has to be done to allow calling inet_csk_destroy_sock */
+	sock_set_flag(sk, SOCK_DEAD);
+	percpu_counter_inc(sk->sk_prot->orphan_count);
+	inet_sk(sk)->inet_num = 0;
+}
+
 void inet_csk_destroy_sock(struct sock *sk);
 void inet_csk_prepare_forced_close(struct sock *sk);
 
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 5f34eb951627..d6faf3702824 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -896,11 +896,7 @@ void inet_csk_prepare_forced_close(struct sock *sk)
 	/* sk_clone_lock locked the socket and set refcnt to 2 */
 	bh_unlock_sock(sk);
 	sock_put(sk);
-
-	/* The below has to be done to allow calling inet_csk_destroy_sock */
-	sock_set_flag(sk, SOCK_DEAD);
-	percpu_counter_inc(sk->sk_prot->orphan_count);
-	inet_sk(sk)->inet_num = 0;
+	inet_csk_prepare_for_destroy_sock(sk);
 }
 EXPORT_SYMBOL(inet_csk_prepare_forced_close);
 
-- 
2.21.3


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

* [MPTCP] [PATCH net-next v2 3/3] mptcp: cope better with MP_JOIN failure
  2020-05-15 17:22 ` Paolo Abeni
@ 2020-05-15 17:22 ` Paolo Abeni
  -1 siblings, 0 replies; 18+ messages in thread
From: Paolo Abeni @ 2020-05-15 17:22 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 2308 bytes --]

Currently, on MP_JOIN failure we reset the child
socket, but leave the request socket untouched.

tcp_check_req will deal with it according to the
'tcp_abort_on_overflow' sysctl value - by default the
req socket will stay alive.

The above leads to inconsistent behavior on MP JOIN
failure, and bad listener overflow accounting.

This patch addresses the issue leveraging the infrastructure
just introduced to ask the TCP stack to drop the req on
failure.

The child socket is not freed anymore by subflow_syn_recv_sock(),
instead it's moved to a dead state and will be disposed by the
next sock_put done by the TCP stack, so that listener overflow
accounting is not affected by MP JOIN failure.

Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
Reviewed-by: Christoph Paasch <cpaasch(a)apple.com>
---
 net/mptcp/subflow.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 5e03ed8ae899..3cf2eeea9d80 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -478,7 +478,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 		 */
 		if (!ctx || fallback) {
 			if (fallback_is_fatal)
-				goto close_child;
+				goto dispose_child;
 
 			if (ctx) {
 				subflow_ulp_fallback(child, ctx);
@@ -507,11 +507,11 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 
 			owner = mptcp_token_get_sock(ctx->token);
 			if (!owner)
-				goto close_child;
+				goto dispose_child;
 
 			ctx->conn = (struct sock *)owner;
 			if (!mptcp_finish_join(child))
-				goto close_child;
+				goto dispose_child;
 
 			SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINACKRX);
 			tcp_rsk(req)->drop_req = true;
@@ -531,11 +531,14 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 		      !mptcp_subflow_ctx(child)->conn));
 	return child;
 
-close_child:
+dispose_child:
+	tcp_rsk(req)->drop_req = true;
 	tcp_send_active_reset(child, GFP_ATOMIC);
-	inet_csk_prepare_forced_close(child);
+	inet_csk_prepare_for_destroy_sock(child);
 	tcp_done(child);
-	return NULL;
+
+	/* The last child reference will be released by the caller */
+	return child;
 }
 
 static struct inet_connection_sock_af_ops subflow_specific;
-- 
2.21.3

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

* [PATCH net-next v2 3/3] mptcp: cope better with MP_JOIN failure
@ 2020-05-15 17:22 ` Paolo Abeni
  0 siblings, 0 replies; 18+ messages in thread
From: Paolo Abeni @ 2020-05-15 17:22 UTC (permalink / raw)
  To: netdev
  Cc: Eric Dumazet, David S . Miller, Christoph Paasch, mptcp, Mat Martineau

Currently, on MP_JOIN failure we reset the child
socket, but leave the request socket untouched.

tcp_check_req will deal with it according to the
'tcp_abort_on_overflow' sysctl value - by default the
req socket will stay alive.

The above leads to inconsistent behavior on MP JOIN
failure, and bad listener overflow accounting.

This patch addresses the issue leveraging the infrastructure
just introduced to ask the TCP stack to drop the req on
failure.

The child socket is not freed anymore by subflow_syn_recv_sock(),
instead it's moved to a dead state and will be disposed by the
next sock_put done by the TCP stack, so that listener overflow
accounting is not affected by MP JOIN failure.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Christoph Paasch <cpaasch@apple.com>
---
 net/mptcp/subflow.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 5e03ed8ae899..3cf2eeea9d80 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -478,7 +478,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 		 */
 		if (!ctx || fallback) {
 			if (fallback_is_fatal)
-				goto close_child;
+				goto dispose_child;
 
 			if (ctx) {
 				subflow_ulp_fallback(child, ctx);
@@ -507,11 +507,11 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 
 			owner = mptcp_token_get_sock(ctx->token);
 			if (!owner)
-				goto close_child;
+				goto dispose_child;
 
 			ctx->conn = (struct sock *)owner;
 			if (!mptcp_finish_join(child))
-				goto close_child;
+				goto dispose_child;
 
 			SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINACKRX);
 			tcp_rsk(req)->drop_req = true;
@@ -531,11 +531,14 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 		      !mptcp_subflow_ctx(child)->conn));
 	return child;
 
-close_child:
+dispose_child:
+	tcp_rsk(req)->drop_req = true;
 	tcp_send_active_reset(child, GFP_ATOMIC);
-	inet_csk_prepare_forced_close(child);
+	inet_csk_prepare_for_destroy_sock(child);
 	tcp_done(child);
-	return NULL;
+
+	/* The last child reference will be released by the caller */
+	return child;
 }
 
 static struct inet_connection_sock_af_ops subflow_specific;
-- 
2.21.3


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

* [MPTCP] Re: [PATCH net-next v2 1/3] mptcp: add new sock flag to deal with join subflows
  2020-05-15 17:22 ` Paolo Abeni
@ 2020-05-15 18:09 ` Mat Martineau
  -1 siblings, 0 replies; 18+ messages in thread
From: Mat Martineau @ 2020-05-15 18:09 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 1591 bytes --]


On Fri, 15 May 2020, Paolo Abeni wrote:

> MP_JOIN subflows must not land into the accept queue.
> Currently tcp_check_req() calls an mptcp specific helper
> to detect such scenario.
>
> Such helper leverages the subflow context to check for
> MP_JOIN subflows. We need to deal also with MP JOIN
> failures, even when the subflow context is not available
> due allocation failure.
>
> A possible solution would be changing the syn_recv_sock()
> signature to allow returning a more descriptive action/
> error code and deal with that in tcp_check_req().
>
> Since the above need is MPTCP specific, this patch instead
> uses a TCP request socket hole to add a MPTCP specific flag.
> Such flag is used by the MPTCP syn_recv_sock() to tell
> tcp_check_req() how to deal with the request socket.
>
> This change is a no-op for !MPTCP build, and makes the
> MPTCP code simpler. It allows also the next patch to deal
> correctly with MP JOIN failure.
>
> v1 -> v2:
> - be more conservative on drop_req initialization (Mat)
>
> RFC -> v1:
> - move the drop_req bit inside tcp_request_sock (Eric)
>
> Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
> ---
> include/linux/tcp.h      |  3 +++
> include/net/mptcp.h      | 17 ++++++++++-------
> net/ipv4/tcp_minisocks.c |  2 +-
> net/mptcp/protocol.c     |  7 -------
> net/mptcp/subflow.c      |  3 +++
> 5 files changed, 17 insertions(+), 15 deletions(-)
>

Thanks for the initialization fix, patch looks good.

Reviewed-by: Mat Martineau <mathew.j.martineau(a)linux.intel.com>

--
Mat Martineau
Intel

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

* Re: [PATCH net-next v2 1/3] mptcp: add new sock flag to deal with join subflows
@ 2020-05-15 18:09 ` Mat Martineau
  0 siblings, 0 replies; 18+ messages in thread
From: Mat Martineau @ 2020-05-15 18:09 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: netdev, Eric Dumazet, David S . Miller, Christoph Paasch, mptcp


On Fri, 15 May 2020, Paolo Abeni wrote:

> MP_JOIN subflows must not land into the accept queue.
> Currently tcp_check_req() calls an mptcp specific helper
> to detect such scenario.
>
> Such helper leverages the subflow context to check for
> MP_JOIN subflows. We need to deal also with MP JOIN
> failures, even when the subflow context is not available
> due allocation failure.
>
> A possible solution would be changing the syn_recv_sock()
> signature to allow returning a more descriptive action/
> error code and deal with that in tcp_check_req().
>
> Since the above need is MPTCP specific, this patch instead
> uses a TCP request socket hole to add a MPTCP specific flag.
> Such flag is used by the MPTCP syn_recv_sock() to tell
> tcp_check_req() how to deal with the request socket.
>
> This change is a no-op for !MPTCP build, and makes the
> MPTCP code simpler. It allows also the next patch to deal
> correctly with MP JOIN failure.
>
> v1 -> v2:
> - be more conservative on drop_req initialization (Mat)
>
> RFC -> v1:
> - move the drop_req bit inside tcp_request_sock (Eric)
>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
> include/linux/tcp.h      |  3 +++
> include/net/mptcp.h      | 17 ++++++++++-------
> net/ipv4/tcp_minisocks.c |  2 +-
> net/mptcp/protocol.c     |  7 -------
> net/mptcp/subflow.c      |  3 +++
> 5 files changed, 17 insertions(+), 15 deletions(-)
>

Thanks for the initialization fix, patch looks good.

Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>

--
Mat Martineau
Intel

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

* [MPTCP] Re: [PATCH net-next v2 2/3] inet_connection_sock: factor out destroy helper.
  2020-05-15 17:22 ` Paolo Abeni
@ 2020-05-15 18:09 ` Mat Martineau
  -1 siblings, 0 replies; 18+ messages in thread
From: Mat Martineau @ 2020-05-15 18:09 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 588 bytes --]


On Fri, 15 May 2020, Paolo Abeni wrote:

> Move the steps to prepare an inet_connection_sock for
> forced disposal inside a separate helper. No functional
> changes inteded, this will just simplify the next patch.
>
> Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
> Reviewed-by: Christoph Paasch <cpaasch(a)apple.com>
> ---
> include/net/inet_connection_sock.h | 8 ++++++++
> net/ipv4/inet_connection_sock.c    | 6 +-----
> 2 files changed, 9 insertions(+), 5 deletions(-)
>

Reviewed-by: Mat Martineau <mathew.j.martineau(a)linux.intel.com>

--
Mat Martineau
Intel

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

* Re: [PATCH net-next v2 2/3] inet_connection_sock: factor out destroy helper.
@ 2020-05-15 18:09 ` Mat Martineau
  0 siblings, 0 replies; 18+ messages in thread
From: Mat Martineau @ 2020-05-15 18:09 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: netdev, Eric Dumazet, David S . Miller, Christoph Paasch, mptcp


On Fri, 15 May 2020, Paolo Abeni wrote:

> Move the steps to prepare an inet_connection_sock for
> forced disposal inside a separate helper. No functional
> changes inteded, this will just simplify the next patch.
>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> Reviewed-by: Christoph Paasch <cpaasch@apple.com>
> ---
> include/net/inet_connection_sock.h | 8 ++++++++
> net/ipv4/inet_connection_sock.c    | 6 +-----
> 2 files changed, 9 insertions(+), 5 deletions(-)
>

Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>

--
Mat Martineau
Intel

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

* [MPTCP] Re: [PATCH net-next v2 3/3] mptcp: cope better with MP_JOIN failure
  2020-05-15 17:22 ` Paolo Abeni
@ 2020-05-15 18:10 ` Mat Martineau
  -1 siblings, 0 replies; 18+ messages in thread
From: Mat Martineau @ 2020-05-15 18:10 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]


On Fri, 15 May 2020, Paolo Abeni wrote:

> Currently, on MP_JOIN failure we reset the child
> socket, but leave the request socket untouched.
>
> tcp_check_req will deal with it according to the
> 'tcp_abort_on_overflow' sysctl value - by default the
> req socket will stay alive.
>
> The above leads to inconsistent behavior on MP JOIN
> failure, and bad listener overflow accounting.
>
> This patch addresses the issue leveraging the infrastructure
> just introduced to ask the TCP stack to drop the req on
> failure.
>
> The child socket is not freed anymore by subflow_syn_recv_sock(),
> instead it's moved to a dead state and will be disposed by the
> next sock_put done by the TCP stack, so that listener overflow
> accounting is not affected by MP JOIN failure.
>
> Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
> Reviewed-by: Christoph Paasch <cpaasch(a)apple.com>
> ---
> net/mptcp/subflow.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>

Reviewed-by: Mat Martineau <mathew.j.martineau(a)linux.intel.com>

--
Mat Martineau
Intel

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

* Re: [PATCH net-next v2 3/3] mptcp: cope better with MP_JOIN failure
@ 2020-05-15 18:10 ` Mat Martineau
  0 siblings, 0 replies; 18+ messages in thread
From: Mat Martineau @ 2020-05-15 18:10 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: netdev, Eric Dumazet, David S . Miller, Christoph Paasch, mptcp


On Fri, 15 May 2020, Paolo Abeni wrote:

> Currently, on MP_JOIN failure we reset the child
> socket, but leave the request socket untouched.
>
> tcp_check_req will deal with it according to the
> 'tcp_abort_on_overflow' sysctl value - by default the
> req socket will stay alive.
>
> The above leads to inconsistent behavior on MP JOIN
> failure, and bad listener overflow accounting.
>
> This patch addresses the issue leveraging the infrastructure
> just introduced to ask the TCP stack to drop the req on
> failure.
>
> The child socket is not freed anymore by subflow_syn_recv_sock(),
> instead it's moved to a dead state and will be disposed by the
> next sock_put done by the TCP stack, so that listener overflow
> accounting is not affected by MP JOIN failure.
>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> Reviewed-by: Christoph Paasch <cpaasch@apple.com>
> ---
> net/mptcp/subflow.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>

Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>

--
Mat Martineau
Intel

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

* [MPTCP] Re: [PATCH net-next v2 1/3] mptcp: add new sock flag to deal with join subflows
  2020-05-15 17:22 ` Paolo Abeni
@ 2020-05-15 18:29 ` Christoph Paasch
  -1 siblings, 0 replies; 18+ messages in thread
From: Christoph Paasch @ 2020-05-15 18:29 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 1508 bytes --]

On 15/05/20 - 19:22:15, Paolo Abeni wrote:
> MP_JOIN subflows must not land into the accept queue.
> Currently tcp_check_req() calls an mptcp specific helper
> to detect such scenario.
> 
> Such helper leverages the subflow context to check for
> MP_JOIN subflows. We need to deal also with MP JOIN
> failures, even when the subflow context is not available
> due allocation failure.
> 
> A possible solution would be changing the syn_recv_sock()
> signature to allow returning a more descriptive action/
> error code and deal with that in tcp_check_req().
> 
> Since the above need is MPTCP specific, this patch instead
> uses a TCP request socket hole to add a MPTCP specific flag.
> Such flag is used by the MPTCP syn_recv_sock() to tell
> tcp_check_req() how to deal with the request socket.
> 
> This change is a no-op for !MPTCP build, and makes the
> MPTCP code simpler. It allows also the next patch to deal
> correctly with MP JOIN failure.
> 
> v1 -> v2:
>  - be more conservative on drop_req initialization (Mat)
> 
> RFC -> v1:
>  - move the drop_req bit inside tcp_request_sock (Eric)
> 
> Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
> ---
>  include/linux/tcp.h      |  3 +++
>  include/net/mptcp.h      | 17 ++++++++++-------
>  net/ipv4/tcp_minisocks.c |  2 +-
>  net/mptcp/protocol.c     |  7 -------
>  net/mptcp/subflow.c      |  3 +++
>  5 files changed, 17 insertions(+), 15 deletions(-)


Reviewed-by: Christoph Paasch <cpaasch(a)apple.com>

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

* Re: [PATCH net-next v2 1/3] mptcp: add new sock flag to deal with join subflows
@ 2020-05-15 18:29 ` Christoph Paasch
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Paasch @ 2020-05-15 18:29 UTC (permalink / raw)
  To: Paolo Abeni; +Cc: netdev, Eric Dumazet, David S . Miller, mptcp, Mat Martineau

On 15/05/20 - 19:22:15, Paolo Abeni wrote:
> MP_JOIN subflows must not land into the accept queue.
> Currently tcp_check_req() calls an mptcp specific helper
> to detect such scenario.
> 
> Such helper leverages the subflow context to check for
> MP_JOIN subflows. We need to deal also with MP JOIN
> failures, even when the subflow context is not available
> due allocation failure.
> 
> A possible solution would be changing the syn_recv_sock()
> signature to allow returning a more descriptive action/
> error code and deal with that in tcp_check_req().
> 
> Since the above need is MPTCP specific, this patch instead
> uses a TCP request socket hole to add a MPTCP specific flag.
> Such flag is used by the MPTCP syn_recv_sock() to tell
> tcp_check_req() how to deal with the request socket.
> 
> This change is a no-op for !MPTCP build, and makes the
> MPTCP code simpler. It allows also the next patch to deal
> correctly with MP JOIN failure.
> 
> v1 -> v2:
>  - be more conservative on drop_req initialization (Mat)
> 
> RFC -> v1:
>  - move the drop_req bit inside tcp_request_sock (Eric)
> 
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
>  include/linux/tcp.h      |  3 +++
>  include/net/mptcp.h      | 17 ++++++++++-------
>  net/ipv4/tcp_minisocks.c |  2 +-
>  net/mptcp/protocol.c     |  7 -------
>  net/mptcp/subflow.c      |  3 +++
>  5 files changed, 17 insertions(+), 15 deletions(-)


Reviewed-by: Christoph Paasch <cpaasch@apple.com>


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

* [MPTCP] Re: [PATCH net-next v2 0/3] mptcp: fix MP_JOIN failure handling
  2020-05-15 17:22 ` Paolo Abeni
@ 2020-05-15 19:30 ` David Miller
  -1 siblings, 0 replies; 18+ messages in thread
From: David Miller @ 2020-05-15 19:30 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 1087 bytes --]

From: Paolo Abeni <pabeni(a)redhat.com>
Date: Fri, 15 May 2020 19:22:14 +0200

> Currently if we hit an MP_JOIN failure on the third ack, the child socket is
> closed with reset, but the request socket is not deleted, causing weird
> behaviors.
> 
> The main problem is that MPTCP's MP_JOIN code needs to plug it's own
> 'valid 3rd ack' checks and the current TCP callbacks do not allow that.
> 
> This series tries to address the above shortcoming introducing a new MPTCP
> specific bit in a 'struct tcp_request_sock' hole, and leveraging that to allow
> tcp_check_req releasing the request socket when needed.
> 
> The above allows cleaning-up a bit current MPTCP hooking in tcp_check_req().
> 
> An alternative solution, possibly cleaner but more invasive, would be
> changing the 'bool *own_req' syn_recv_sock() argument into 'int *req_status'
> and let MPTCP set it to 'REQ_DROP'.
> 
> v1 -> v2:
>  - be more conservative about drop_req initialization
> 
> RFC -> v1:
>  - move the drop_req bit inside tcp_request_sock (Eric)

Series applied, thanks Paolo.

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

* Re: [PATCH net-next v2 0/3] mptcp: fix MP_JOIN failure handling
@ 2020-05-15 19:30 ` David Miller
  0 siblings, 0 replies; 18+ messages in thread
From: David Miller @ 2020-05-15 19:30 UTC (permalink / raw)
  To: pabeni; +Cc: netdev, edumazet, cpaasch, mptcp, mathew.j.martineau

From: Paolo Abeni <pabeni@redhat.com>
Date: Fri, 15 May 2020 19:22:14 +0200

> Currently if we hit an MP_JOIN failure on the third ack, the child socket is
> closed with reset, but the request socket is not deleted, causing weird
> behaviors.
> 
> The main problem is that MPTCP's MP_JOIN code needs to plug it's own
> 'valid 3rd ack' checks and the current TCP callbacks do not allow that.
> 
> This series tries to address the above shortcoming introducing a new MPTCP
> specific bit in a 'struct tcp_request_sock' hole, and leveraging that to allow
> tcp_check_req releasing the request socket when needed.
> 
> The above allows cleaning-up a bit current MPTCP hooking in tcp_check_req().
> 
> An alternative solution, possibly cleaner but more invasive, would be
> changing the 'bool *own_req' syn_recv_sock() argument into 'int *req_status'
> and let MPTCP set it to 'REQ_DROP'.
> 
> v1 -> v2:
>  - be more conservative about drop_req initialization
> 
> RFC -> v1:
>  - move the drop_req bit inside tcp_request_sock (Eric)

Series applied, thanks Paolo.

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

end of thread, other threads:[~2020-05-15 19:31 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 17:22 [MPTCP] [PATCH net-next v2 0/3] mptcp: fix MP_JOIN failure handling Paolo Abeni
2020-05-15 17:22 ` Paolo Abeni
2020-05-15 17:22 [MPTCP] [PATCH net-next v2 1/3] mptcp: add new sock flag to deal with join subflows Paolo Abeni
2020-05-15 17:22 ` Paolo Abeni
2020-05-15 17:22 [MPTCP] [PATCH net-next v2 2/3] inet_connection_sock: factor out destroy helper Paolo Abeni
2020-05-15 17:22 ` Paolo Abeni
2020-05-15 17:22 [MPTCP] [PATCH net-next v2 3/3] mptcp: cope better with MP_JOIN failure Paolo Abeni
2020-05-15 17:22 ` Paolo Abeni
2020-05-15 18:09 [MPTCP] Re: [PATCH net-next v2 1/3] mptcp: add new sock flag to deal with join subflows Mat Martineau
2020-05-15 18:09 ` Mat Martineau
2020-05-15 18:09 [MPTCP] Re: [PATCH net-next v2 2/3] inet_connection_sock: factor out destroy helper Mat Martineau
2020-05-15 18:09 ` Mat Martineau
2020-05-15 18:10 [MPTCP] Re: [PATCH net-next v2 3/3] mptcp: cope better with MP_JOIN failure Mat Martineau
2020-05-15 18:10 ` Mat Martineau
2020-05-15 18:29 [MPTCP] Re: [PATCH net-next v2 1/3] mptcp: add new sock flag to deal with join subflows Christoph Paasch
2020-05-15 18:29 ` Christoph Paasch
2020-05-15 19:30 [MPTCP] Re: [PATCH net-next v2 0/3] mptcp: fix MP_JOIN failure handling David Miller
2020-05-15 19:30 ` David Miller

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.