MPTCP Linux Development
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Geliang Tang <geliang.tang@suse.com>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v12 1/5] mptcp: avoid resetting when another subflow available
Date: Tue, 10 Oct 2023 18:20:45 +0200	[thread overview]
Message-ID: <2cd57e92348cea6c9cb00eca44b29c5286023955.camel@redhat.com> (raw)
In-Reply-To: <2b69fa22510db02a12eb101c3e8173dda76f8133.1696831239.git.geliang.tang@suse.com>

On Mon, 2023-10-09 at 14:02 +0800, Geliang Tang wrote:
> When closing the msk->first socket in __mptcp_close_ssk(), if there's
> another subflow available, it's better to avoid resetting it.
> 
> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> ---
>  net/mptcp/protocol.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 30e0c29ae0a4..6346a164ed66 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2396,7 +2396,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
>  		goto out_release;
>  	}
>  
> -	dispose_it = msk->free_first || ssk != msk->first;
> +	dispose_it = msk->free_first || ssk != msk->first || !list_is_singular(&msk->conn_list);
>  	if (dispose_it)
>  		list_del(&subflow->node);

I'm sorry for the late feedback.

We can't do the above, Syzkaller already hit us in the past while
attempting that thing.

We need to be msk->first != NULL and a valid, derefereciable pointer up
to mptcp_destroy() - that is, up to when the msk socket is freed -
otherwise we will hit a number of UaF in many places.

Note that claring msk->first here, and add check for 'msk->first !=
NULL' before every msk access, will not save us, sometimes msk->first
is tested without the msk socket lock. 

I think there are 2 options here:

- the caller (PM NL/PM userspace) could explicitly avoid calling
mptcp_close_ssk() when removing subflow 0 (just shut it down)

- Add a new flags MPTCP_NO_DISCONNECT, and let the caller pass it here.
  When MPTCP_NO_DISCONNECT is set, we invoke tcp_shutdown() instead of
tcp_disconnect()

Both options are actually quite similar, the 2nd is possibly the
cleanest.

Note that looking here for 'this is the last subflow' and avoid the
disconnect otherwise, does not look correct/safe: we want to invoke
tcp_disconnect() even when first is _not_ the last subflow and we are
reaching mptcp_close_ssk() from a different caller - e.g. from
mptcp_disconnect()

/P


  parent reply	other threads:[~2023-10-10 16:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09  6:02 [PATCH mptcp-next v12 0/5] userspace pm remove id 0 subflow & address Geliang Tang
2023-10-09  6:02 ` [PATCH mptcp-next v12 1/5] mptcp: avoid resetting when another subflow available Geliang Tang
2023-10-09 16:13   ` Matthieu Baerts
2023-10-10  6:13     ` Geliang Tang
2023-10-10 12:49       ` Matthieu Baerts
2023-10-10 16:20   ` Paolo Abeni [this message]
2023-10-09  6:02 ` [PATCH mptcp-next v12 2/5] selftests: mptcp: userspace pm remove initial subflow Geliang Tang
2023-10-09  6:02 ` [PATCH mptcp-net v12 3/5] mptcp: userspace pm send RM_ADDR for ID 0 Geliang Tang
2023-10-09  6:02 ` [PATCH mptcp-next v12 4/5] mptcp: userspace pm rename remove_err to out Geliang Tang
2023-10-09  6:03 ` [PATCH mptcp-next v12 5/5] selftests: mptcp: userspace pm send RM_ADDR for ID 0 Geliang Tang
2023-10-09  7:05   ` selftests: mptcp: userspace pm send RM_ADDR for ID 0: Tests Results MPTCP CI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2cd57e92348cea6c9cb00eca44b29c5286023955.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=geliang.tang@suse.com \
    --cc=mptcp@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox