Skip to content

Commit

Permalink
mptcp: hold mptcp socket before calling tcp_done
Browse files Browse the repository at this point in the history
When processing options from tcp reset path its possible that
tcp_done(ssk) drops the last reference on the mptcp socket which
results in use-after-free.

Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
  • Loading branch information
Florian Westphal authored and jenkins-tessares committed Dec 9, 2020
1 parent 3630500 commit 4598a67
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion net/mptcp/subflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,17 @@ void mptcp_subflow_reset(struct sock *ssk)
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
struct sock *sk = subflow->conn;

/* must hold: tcp_done() could drop last reference on parent */
sock_hold(sk);

tcp_set_state(ssk, TCP_CLOSE);
tcp_send_active_reset(ssk, GFP_ATOMIC);
tcp_done(ssk);
if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &mptcp_sk(sk)->flags) &&
schedule_work(&mptcp_sk(sk)->work))
sock_hold(sk);
return; /* worker will put sk for us */

sock_put(sk);
}

static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
Expand Down

0 comments on commit 4598a67

Please sign in to comment.