mptcp: fix MP_JOIN failure handling
Subsystems (4)
Paolo Abeni
maintainercover mptcp: fix MP_JOIN failure handling
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 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'.
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 | 1 + 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 | 17 +++++++++++------ 7 files changed, 32 insertions(+), 26 deletions(-)
Signature · 1 line
2.21.3
Paolo Abeni
maintainerRFC PATCH 1/3 mptcp: add new sock flag to deal with join subflows
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 to 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 socket hole to add an 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.
--- include/linux/tcp.h | 1 + include/net/mptcp.h | 17 ++++++++++------- net/ipv4/tcp_minisocks.c | 2 +- net/mptcp/protocol.c | 7 ------- net/mptcp/subflow.c | 2 ++ 5 files changed, 14 insertions(+), 15 deletions(-)
include/linux/tcp.h +1 -0
@@ -385,6 +385,7 @@ struct tcp_sock {*/ #if IS_ENABLED (CONFIG_MPTCP )bool is_mptcp; +bool drop_req;#endif #ifdef CONFIG_TCP_MD5SIG
include/net/mptcp.h +10 -7
@@ -68,6 +68,11 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)return tcp_rsk (req)->is_mptcp; } +static inline bool sk_drop_req (const struct sock *sk) +{ +return tcp_sk (sk)->is_mptcp &&tcp_sk (sk)->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 sk_drop_req (const struct sock *sk) +{ +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 */
net/ipv4/tcp_minisocks.c +1 -1
@@ -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 &&sk_drop_req (child)) {reqsk_queue_removed (&inet_csk (sk)->icsk_accept_queue, req);inet_csk_reqsk_queue_drop_and_put (sk, req);return child;
net/mptcp/protocol.c +0 -7
@@ -1638,13 +1638,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);
net/mptcp/subflow.c +2 -0
@@ -500,6 +500,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, ctx->remote_key = mp_opt.sndr_key; ctx->fully_established = mp_opt.mp_capable; ctx->can_ack = mp_opt.mp_capable; +tcp_sk (child)->drop_req = false; }else if (ctx->mp_join) {struct mptcp_sock *owner;
@@ -512,6 +513,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, goto close_child;SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINACKRX ); +tcp_sk (child)->drop_req = true; } }
Signature · 1 line
2.21.3
Paolo Abeni
maintainerRFC PATCH 3/3 mptcp: cope better with MP_JOIN failure
In reply to Paolo AbeniCurrently, 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.
--- net/mptcp/subflow.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
net/mptcp/subflow.c +9 -6
@@ -476,7 +476,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);
@@ -506,11 +506,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_sk (child)->drop_req = true;
@@ -530,11 +530,14 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, !mptcp_subflow_ctx(child)->conn));return child; -close_child: +dispose_child: +tcp_sk (child)->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;
Signature · 1 line
2.21.3
Paolo Abeni
maintainerRFC PATCH 2/3 inet_connection_sock: factor out destroy helper.
In reply to Paolo AbeniMove 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.
--- include/net/inet_connection_sock.h | 8 ++++++++ net/ipv4/inet_connection_sock.c | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-)
include/net/inet_connection_sock.h +8 -0
@@ -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);
net/ipv4/inet_connection_sock.c +1 -5
@@ -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);
Signature · 1 line
2.21.3
Re: [RFC PATCH 1/3] mptcp: add new sock flag to deal with join subflows
In reply to Paolo AbeniQuoted 37 lines · Paolo Abeni
MP_JOINsubflows must not land into the accept queue. Currentlytcp_check_req()calls an mptcp specific helper to detect such scenario.Such helper leverages the subflow context to check for
MP_JOINsubflows. We need to deal also with MP JOIN failures, even when the subflow context is not available due to 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 intcp_check_req().Since the above need is MPTCP specific, this patch instead uses a TCP socket hole to add an MPTCP specific flag. Such flag is used by the MPTCP
syn_recv_sock()to telltcp_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.
Signed-off-by Paolo Abeni <[email protected]>--- include/linux/tcp.h | 1 + include/net/mptcp.h | 17 ++++++++++------- net/ipv4/tcp_minisocks.c | 2 +- net/mptcp/protocol.c | 7 ------- net/mptcp/subflow.c | 2 ++ 5 files changed, 14 insertions(+), 15 deletions(-)include/linux/tcp.h +0
-0
include/linux/tcp.h struct tcp_sock { · line 389
Quoted 5 lines
include/linux/tcp.h +1
-0@@ -385,6 +385,7 @@ struct tcp_sock {*/ #if IS_ENABLED (CONFIG_MPTCP )bool is_mptcp; +bool drop_req;#endif
This looks like this should only be needed in struct tcp_request_sock ?
Does this information need to be kept in the TCP socket after accept() ?
Quoted 105 lines
include/linux/tcp.h +0
-0#ifdef CONFIG_TCP_MD5SIG include/net/mptcp.h +10
-7@@ -68,6 +68,11 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)return tcp_rsk (req)->is_mptcp; } +static inline bool sk_drop_req (const struct sock *sk) +{ +return tcp_sk (sk)->is_mptcp &&tcp_sk (sk)->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 sk_drop_req (const struct sock *sk) +{ +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 */ net/ipv4/tcp_minisocks.c +1
-1@@ -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 &&sk_drop_req (child)) {reqsk_queue_removed (&inet_csk (sk)->icsk_accept_queue, req);inet_csk_reqsk_queue_drop_and_put (sk, req);return child;net/mptcp/protocol.c +0
-7@@ -1638,13 +1638,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);net/mptcp/subflow.c +2
-1@@ -500,6 +500,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, ctx->remote_key = mp_opt.sndr_key; ctx->fully_established = mp_opt.mp_capable; ctx->can_ack = mp_opt.mp_capable; +tcp_sk (child)->drop_req = false; }else if (ctx->mp_join) {struct mptcp_sock *owner;@@ -512,6 +513,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, goto close_child;SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINACKRX ); +tcp_sk (child)->drop_req = true; } } --2.21.3
Paolo Abeni
maintainerRe: [RFC PATCH 1/3] mptcp: add new sock flag to deal with join subflows
Hi,
Quoted 45 lines · Eric Dumazet
Quoted 36 lines · Paolo Abeni
MP_JOINsubflows must not land into the accept queue. Currentlytcp_check_req()calls an mptcp specific helper to detect such scenario.Such helper leverages the subflow context to check for
MP_JOINsubflows. We need to deal also with MP JOIN failures, even when the subflow context is not available due to 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 intcp_check_req().Since the above need is MPTCP specific, this patch instead uses a TCP socket hole to add an MPTCP specific flag. Such flag is used by the MPTCP
syn_recv_sock()to telltcp_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.
Signed-off-by Paolo Abeni <[email protected]>--- include/linux/tcp.h | 1 + include/net/mptcp.h | 17 ++++++++++------- net/ipv4/tcp_minisocks.c | 2 +- net/mptcp/protocol.c | 7 ------- net/mptcp/subflow.c | 2 ++ 5 files changed, 14 insertions(+), 15 deletions(-)include/linux/tcp.h +0
-0include/linux/tcp.h struct tcp_sock { · line 389
Quoted 5 lines
include/linux/tcp.h +1
-0@@ -385,6 +385,7 @@ struct tcp_sock {*/ #if IS_ENABLED (CONFIG_MPTCP )bool is_mptcp; +bool drop_req;#endif This looks like this should only be needed in struct
tcp_request_sock?
Quoted 1 line
Does this information need to be kept in the TCP socket after
accept()?
Thank you for the feedback, indeed you are right! this should be moved inside tcp_request_sock. We still have 2 bytes hole there. I will keep the flag under a CONFIG_MPTCP conditional.
Would you be ok with such approach, or do you think we should look for some other schema (like the alternative mentioned in the cover letter)?
Cheers,
Paolo