mptcp: fix some mp_join error paths
Subsystems (2)
Paolo Abeni
cover mptcp: fix some mp_join error paths
Currently we do not handle correctly MP_JOIN + syncookie and MP_JOIN failure due to passive socket being already closed.
First patch place the infrastructure needed, the 2nd one addresses the issues.
Note: in such error path, we will end-up creating the child socket just to reset the connection. I don't see an easy way to avoid such allocation and doing differently (reset on syn) could be dangerous (attacker can use the mptcp server to target a victim using spoofed bogus mp_join syn)
Paolo Abeni (2):
mptcp: cache msk on MP_JOIN init_req
mptcp: drop MP_JOIN request sock on syn cookies
net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 56 ++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 30 deletions(-)
Signature · 1 line
2.21.3
Paolo Abeni
PATCH 1/2 mptcp: cache msk on MP_JOIN init_req
The msk ownership is transferred to the child socket at 3rd ack time, so that we avoid more lookups later. If the request does not reach the 3rd ack, the MSK reference is dropped at request sock release time.
This will simplify the next patches.
--- net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 38 ++++++++++++++++---------------------- 2 files changed, 17 insertions(+), 22 deletions(-)
net/mptcp/protocol.h +1 -0
@@ -255,6 +255,7 @@ struct mptcp_subflow_request_sock {u64 thmac;u32 local_nonce;u32 remote_nonce; +struct mptcp_sock *msk;struct hlist_nulls_node token_node; };
net/mptcp/subflow.c +16 -22
@@ -35,6 +35,8 @@ static void subflow_req_destructor(struct request_sock *req)pr_debug ("subflow_req=%p" , subflow_req); +if (subflow_req->msk) +sock_put ((struct sock *)subflow_req->msk);mptcp_token_destroy_request (req); tcp_request_sock_ops.destructor (req); }
@@ -51,8 +53,8 @@ static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2, }/* validate received token and create truncated hmac and nonce for SYN-ACK */ -static bool subflow_token_join_request (struct request_sock *req, -const struct sk_buff *skb) +static struct mptcp_sock *subflow_token_join_request (struct request_sock *req, +const struct sk_buff *skb) {struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req);u8 hmac[SHA256_DIGEST_SIZE ];
@@ -62,13 +64,13 @@ static bool subflow_token_join_request(struct request_sock *req, msk =mptcp_token_get_sock (subflow_req->token);if (!msk) {SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINNOTOKEN ); -return false; +return NULL ; } local_id =mptcp_pm_get_local_id (msk, (struct sock_common *)req);if (local_id <0 ) {sock_put ((struct sock *)msk); -return false; +return NULL ; } subflow_req->local_id = local_id;
@@ -79,9 +81,7 @@ static bool subflow_token_join_request(struct request_sock *req, subflow_req->remote_nonce, hmac); subflow_req->thmac =get_unaligned_be64 (hmac); - -sock_put ((struct sock *)msk); -return true; +return msk; } static void subflow_init_req(struct request_sock *req,
@@ -98,6 +98,7 @@ static void subflow_init_req(struct request_sock *req, subflow_req->mp_capable =0 ; subflow_req->mp_join =0 ; + subflow_req->msk =NULL ;mptcp_token_init_request (req);#ifdef CONFIG_TCP_MD5SIG
@@ -132,12 +133,9 @@ static void subflow_init_req(struct request_sock *req, subflow_req->remote_id = mp_opt.join_id; subflow_req->token = mp_opt.token; subflow_req->remote_nonce = mp_opt.nonce; -pr_debug ("token=%u, remote_nonce=%u" , subflow_req->token, - subflow_req->remote_nonce); -if (!subflow_token_join_request (req, skb)) { - subflow_req->mp_join =0 ; -// @@ need to trigger RST - } + subflow_req->msk =subflow_token_join_request (req, skb); +pr_debug ("token=%u, remote_nonce=%u msk=%p" , subflow_req->token, + subflow_req->remote_nonce, subflow_req->msk); } }
@@ -317,10 +315,9 @@ static bool subflow_hmac_valid(const struct request_sock *req,const struct mptcp_subflow_request_sock *subflow_req;u8 hmac[SHA256_DIGEST_SIZE ];struct mptcp_sock *msk; -bool ret; subflow_req =mptcp_subflow_rsk (req); - msk =mptcp_token_get_sock (subflow_req->token); + msk = subflow_req->msk;if (!msk)return false;
@@ -328,12 +325,7 @@ static bool subflow_hmac_valid(const struct request_sock *req, subflow_req->remote_nonce, subflow_req->local_nonce, hmac); - ret = true; -if (crypto_memneq (hmac, mp_opt->hmac,MPTCPOPT_HMAC_LEN )) - ret = false; - -sock_put ((struct sock *)msk); -return ret; +return !crypto_memneq (hmac, mp_opt->hmac,MPTCPOPT_HMAC_LEN ); }static void mptcp_sock_destruct (struct sock *sk)
@@ -486,10 +478,12 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, }else if (ctx->mp_join) {struct mptcp_sock *owner; - owner =mptcp_token_get_sock (ctx->token); + owner = subflow_req->msk;if (!owner) goto dispose_child; +/* move the msk reference ownership to the subflow */ + subflow_req->msk =NULL ; ctx->conn = (struct sock *)owner;if (!mptcp_finish_join (child)) goto dispose_child;
Signature · 1 line
2.21.3
Paolo Abeni
PATCH 2/2 mptcp: drop MP_JOIN request sock on syn cookies
In reply to Paolo AbeniCurrently any MPTCP socket using syn cookies will fallback to TCP at 3rd ack time. In case of MP_JOIN requests, the RFC mandate closing the child and sockets, but the existing error paths do not handle the syncookie scenario correctly.
Address the issue always forcing the child shutdown in case of MP_JOIN fallback.
--- net/mptcp/subflow.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
net/mptcp/subflow.c +10 -8
@@ -393,22 +393,25 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,struct mptcp_subflow_context *listener =mptcp_subflow_ctx (sk);struct mptcp_subflow_request_sock *subflow_req;struct mptcp_options_received mp_opt; -bool fallback_is_fatal = false; +bool fallback, fallback_is_fatal;struct sock *new_msk =NULL ; -bool fallback = false;struct sock *child;pr_debug ("listener=%p, req=%p, conn=%p" , listener, req, listener->conn); -/* we need later a valid 'mp_capable' value even when options are not -* parsed +/* After child creation we must look for 'mp_capable' even when options +* are not parsed */ mp_opt.mp_capable =0 ; -if (tcp_rsk (req)->is_mptcp ==0 ) + +/* hopefully temporary handling for MP_JOIN+syncookie */ + subflow_req =mptcp_subflow_rsk (req); + fallback_is_fatal = subflow_req->mp_join; + fallback = !tcp_rsk (req)->is_mptcp; +if (fallback) goto create_child;/* if the sk is MP_CAPABLE, we try to fetch the client key */ - subflow_req =mptcp_subflow_rsk (req);if (subflow_req->mp_capable) {if (TCP_SKB_CB (skb)->seq != subflow_req->ssn_offset +1 ) {/* here we can receive and accept an in-window,
@@ -429,12 +432,11 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,if (!new_msk) fallback = true; }else if (subflow_req->mp_join) { - fallback_is_fatal = true;mptcp_get_options (skb, &mp_opt);if (!mp_opt.mp_join || !subflow_hmac_valid (req, &mp_opt)) {SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINACKMAC ); -return NULL ; + fallback = true; } }
Signature · 1 line
2.21.3
Mat Martineau
[MPTCP] Re: [PATCH 2/2] mptcp: drop MP_JOIN request sock on syn cookies
Quoted 53 lines · Paolo Abeni
Currently any MPTCP socket using syn cookies will fallback to TCP at 3rd ack time. In case of
MP_JOINrequests, the RFC mandate closing the child and sockets, but the existing error paths do not handle the syncookie scenario correctly.Address the issue always forcing the child shutdown in case of
MP_JOINfallback.Fixes ae2dd7164943 ("mptcp: handle tcp fallback when using syn cookies")Signed-off-by Paolo Abeni <pabeni(a)redhat.com>---
net/mptcp/subflow.c| 18 ++++++++++--------1 file changed, 10 insertions(+), 8 deletions(-)net/mptcp/subflow.c +9
-6@@ -393,22 +393,25 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,struct mptcp_subflow_context *listener =mptcp_subflow_ctx (sk);struct mptcp_subflow_request_sock *subflow_req;struct mptcp_options_received mp_opt; -bool fallback_is_fatal = false; +bool fallback, fallback_is_fatal;struct sock *new_msk =NULL ; -bool fallback = false;struct sock *child;pr_debug ("listener=%p, req=%p, conn=%p" , listener, req, listener->conn); -/* we need later a valid 'mp_capable' value even when options are not -* parsed +/* After child creation we must look for 'mp_capable' even when options +* are not parsed */ mp_opt.mp_capable =0 ; -if (tcp_rsk (req)->is_mptcp ==0 ) + +/* hopefully temporary handling for MP_JOIN+syncookie */ + subflow_req =mptcp_subflow_rsk (req); + fallback_is_fatal = subflow_req->mp_join; + fallback = !tcp_rsk (req)->is_mptcp; +if (fallback) goto create_child;/* if the sk is MP_CAPABLE, we try to fetch the client key */ - subflow_req =mptcp_subflow_rsk (req);if (subflow_req->mp_capable) {if (TCP_SKB_CB (skb)->seq != subflow_req->ssn_offset +1 ) {/* here we can receive and accept an in-window, @@ -429,12 +432,11 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,if (!new_msk) fallback = true;
net/mptcp/subflow.c static struct sock *subflow_syn_recv_sock(const struct sock *sk, · line 441
Quoted 10 lines
net/mptcp/subflow.c +1
-2}else if (subflow_req->mp_join) { - fallback_is_fatal = true;mptcp_get_options (skb, &mp_opt);if (!mp_opt.mp_join || !subflow_hmac_valid (req, &mp_opt)) {SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINACKMAC ); -return NULL ; + fallback = true; } }
When fallback and fallback_is_fatal are both true when continuing past this block of code, it does look difficult to detect when to *not* send a reset without doing the work of allocating the child. The approach of doing the allocation seems ok, hopefully the extra work to do the allocation is not itself subject to attack :)
--
Mat Martineau
Intel
Matthieu Baerts
Hi Paolo, Mat,
Quoted 8 lines · Paolo Abeni
Currently we do not handle correctly
MP_JOIN+ syncookie andMP_JOINfailure due to passive socket being already closed.First patch place the infrastructure needed, the 2nd one addresses the issues.
Note: in such error path, we will end-up creating the child socket just to reset the connection. I don't see an easy way to avoid such allocation and doing differently (reset on syn) could be dangerous (attacker can use the mptcp server to target a victim using spoofed bogusmp_joinsyn)
Thank you for the patches and the reviews!
I added the two patches before "mptcp: add __init annotation on setup functions".
I had a bit of conflicts when applying the first one and later:
- 0adf8b763a86: mptcp: cache msk on MP_JOIN init_req
- 30896dd8f6df: mptcp: drop MP_JOIN request sock on syn cookies
- 9640eebdb4ff: conflict in t/mptcp-refactor-token-container
Tests are going to be launched soon!
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net