Skip to content

Commit

Permalink
mptcp: fix NULL ptr dereference in MP_JOIN error path
Browse files Browse the repository at this point in the history
When token lookup on MP_JOIN 3rd ack fails, the server
socket closes with a reset the incoming child. Such socket
has the 'is_mptcp' flag set, but no msk socket associated
- due to the failed lookup.

While crafting the reset packet mptcp_established_options_mp()
will try to dereference the child's master socket, causing
a NULL ptr dereference.

This change addresses the issue with explicit fallback to
TCP in such error path.

Fixes: 729cd64 ("mptcp: cope better with MP_JOIN failure")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Paolo Abeni authored and David S. Miller committed May 31, 2020
1 parent b0c19ed commit 3988460
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions net/mptcp/subflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,20 @@ static void subflow_ulp_fallback(struct sock *sk,
tcp_sk(sk)->is_mptcp = 0;
}

static void subflow_drop_ctx(struct sock *ssk)
{
struct mptcp_subflow_context *ctx = mptcp_subflow_ctx(ssk);

if (!ctx)
return;

subflow_ulp_fallback(ssk, ctx);
if (ctx->conn)
sock_put(ctx->conn);

kfree_rcu(ctx, rcu);
}

static struct sock *subflow_syn_recv_sock(const struct sock *sk,
struct sk_buff *skb,
struct request_sock *req,
Expand Down Expand Up @@ -485,10 +499,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
if (fallback_is_fatal)
goto dispose_child;

if (ctx) {
subflow_ulp_fallback(child, ctx);
kfree_rcu(ctx, rcu);
}
subflow_drop_ctx(child);
goto out;
}

Expand Down Expand Up @@ -537,6 +548,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
return child;

dispose_child:
subflow_drop_ctx(child);
tcp_rsk(req)->drop_req = true;
tcp_send_active_reset(child, GFP_ATOMIC);
inet_csk_prepare_for_destroy_sock(child);
Expand Down

0 comments on commit 3988460

Please sign in to comment.