[PATCH mptcp-next] mptcp: stop using the mptcp_has_another_subflow() helper

Paolo Abeni posted 1 patch 1 year, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/multipath-tcp/mptcp_net-next tags/patchew/5e05ab9275671ea3018eaa02028197817715de65.1652275377.git.pabeni@redhat.com
Maintainers: "David S. Miller" <davem@davemloft.net>, Matthieu Baerts <matthieu.baerts@tessares.net>, Jakub Kicinski <kuba@kernel.org>, Mat Martineau <mathew.j.martineau@linux.intel.com>, Paolo Abeni <pabeni@redhat.com>, Eric Dumazet <edumazet@google.com>, Geliang Tang <geliang.tang@suse.com>
net/mptcp/pm.c       |  2 +-
net/mptcp/protocol.h | 13 -------------
net/mptcp/subflow.c  |  3 +--
3 files changed, 2 insertions(+), 16 deletions(-)
[PATCH mptcp-next] mptcp: stop using the mptcp_has_another_subflow() helper
Posted by Paolo Abeni 1 year, 11 months ago
The mentioned helper requires the msk socket lock, and the
current callers don't own it nor can't acquire it, so the
access is racy.

All the current callers are really checking for infinite mapping
fallback, and the latter condition is explicitly tracked by
the relevant msk variable: we can safely remove the caller usage
- and the caller itself.

The issue is present since MP_FAIL implementation, but the
fix only applies since the infinite fallback support, ence the
somewhat unexpected fixes tag.

Fixes: 0530020a7c8f ("mptcp: track and update contiguous data status")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 net/mptcp/pm.c       |  2 +-
 net/mptcp/protocol.h | 13 -------------
 net/mptcp/subflow.c  |  3 +--
 3 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 59fdab2d0c27..8ba51120f35b 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -303,7 +303,7 @@ void mptcp_pm_mp_fail_received(struct sock *sk, u64 fail_seq)
 
 	pr_debug("fail_seq=%llu", fail_seq);
 
-	if (mptcp_has_another_subflow(sk) || !READ_ONCE(msk->allow_infinite_fallback))
+	if (!READ_ONCE(msk->allow_infinite_fallback))
 		return;
 
 	if (!READ_ONCE(subflow->mp_fail_response_expect)) {
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index f98c27300e60..dbb914def5cc 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -661,19 +661,6 @@ static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
 	inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops;
 }
 
-static inline bool mptcp_has_another_subflow(struct sock *ssk)
-{
-	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk), *tmp;
-	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
-
-	mptcp_for_each_subflow(msk, tmp) {
-		if (tmp != subflow)
-			return true;
-	}
-
-	return false;
-}
-
 void __init mptcp_proto_init(void);
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 int __init mptcp_proto_v6_init(void);
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index b38a02db924b..550c8fbec54d 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1218,8 +1218,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
 	if (!__mptcp_check_fallback(msk)) {
 		/* RFC 8684 section 3.7. */
 		if (subflow->send_mp_fail) {
-			if (mptcp_has_another_subflow(ssk) ||
-			    !READ_ONCE(msk->allow_infinite_fallback)) {
+			if (!READ_ONCE(msk->allow_infinite_fallback)) {
 				ssk->sk_err = EBADMSG;
 				tcp_set_state(ssk, TCP_CLOSE);
 				subflow->reset_transient = 0;
-- 
2.35.3


Re: [PATCH mptcp-next] mptcp: stop using the mptcp_has_another_subflow() helper
Posted by Matthieu Baerts 1 year, 11 months ago
Hi Paolo, Mat, Geliang,

On 11/05/2022 15:23, Paolo Abeni wrote:
> The mentioned helper requires the msk socket lock, and the
> current callers don't own it nor can't acquire it, so the
> access is racy.
> 
> All the current callers are really checking for infinite mapping
> fallback, and the latter condition is explicitly tracked by
> the relevant msk variable: we can safely remove the caller usage
> - and the caller itself.
> 
> The issue is present since MP_FAIL implementation, but the
> fix only applies since the infinite fallback support, ence the
> somewhat unexpected fixes tag.

Thank you for the patch, review and validation!

Just applied in our tree (fixes for net-next) with Mat's RvB and
Geliang's ACK+Test tag.

New patches for t/upstream:

- 9dc556bbb2c6: mptcp: stop using the mptcp_has_another_subflow() helper

- Results: 2cb58f40e877..7e5581f27ee6 (export)

Builds and tests are now in progress:



https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20220516T161647

https://github.com/multipath-tcp/mptcp_net-next/actions/workflows/build-validation.yml?query=branch:export

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

Re: [PATCH mptcp-next] mptcp: stop using the mptcp_has_another_subflow() helper
Posted by Mat Martineau 1 year, 11 months ago
On Wed, 11 May 2022, Paolo Abeni wrote:

> The mentioned helper requires the msk socket lock, and the
> current callers don't own it nor can't acquire it, so the
> access is racy.
>
> All the current callers are really checking for infinite mapping
> fallback, and the latter condition is explicitly tracked by
> the relevant msk variable: we can safely remove the caller usage
> - and the caller itself.
>
> The issue is present since MP_FAIL implementation, but the
> fix only applies since the infinite fallback support, ence the
> somewhat unexpected fixes tag.
>
> Fixes: 0530020a7c8f ("mptcp: track and update contiguous data status")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Looks good to me. I wasn't able to reproduce the CI failure.

Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>



> ---
> net/mptcp/pm.c       |  2 +-
> net/mptcp/protocol.h | 13 -------------
> net/mptcp/subflow.c  |  3 +--
> 3 files changed, 2 insertions(+), 16 deletions(-)
>
> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> index 59fdab2d0c27..8ba51120f35b 100644
> --- a/net/mptcp/pm.c
> +++ b/net/mptcp/pm.c
> @@ -303,7 +303,7 @@ void mptcp_pm_mp_fail_received(struct sock *sk, u64 fail_seq)
>
> 	pr_debug("fail_seq=%llu", fail_seq);
>
> -	if (mptcp_has_another_subflow(sk) || !READ_ONCE(msk->allow_infinite_fallback))
> +	if (!READ_ONCE(msk->allow_infinite_fallback))
> 		return;
>
> 	if (!READ_ONCE(subflow->mp_fail_response_expect)) {
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index f98c27300e60..dbb914def5cc 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -661,19 +661,6 @@ static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
> 	inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops;
> }
>
> -static inline bool mptcp_has_another_subflow(struct sock *ssk)
> -{
> -	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk), *tmp;
> -	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
> -
> -	mptcp_for_each_subflow(msk, tmp) {
> -		if (tmp != subflow)
> -			return true;
> -	}
> -
> -	return false;
> -}
> -
> void __init mptcp_proto_init(void);
> #if IS_ENABLED(CONFIG_MPTCP_IPV6)
> int __init mptcp_proto_v6_init(void);
> diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
> index b38a02db924b..550c8fbec54d 100644
> --- a/net/mptcp/subflow.c
> +++ b/net/mptcp/subflow.c
> @@ -1218,8 +1218,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
> 	if (!__mptcp_check_fallback(msk)) {
> 		/* RFC 8684 section 3.7. */
> 		if (subflow->send_mp_fail) {
> -			if (mptcp_has_another_subflow(ssk) ||
> -			    !READ_ONCE(msk->allow_infinite_fallback)) {
> +			if (!READ_ONCE(msk->allow_infinite_fallback)) {
> 				ssk->sk_err = EBADMSG;
> 				tcp_set_state(ssk, TCP_CLOSE);
> 				subflow->reset_transient = 0;
> -- 
> 2.35.3
>
>
>

--
Mat Martineau
Intel

Re: [PATCH mptcp-next] mptcp: stop using the mptcp_has_another_subflow() helper
Posted by Geliang Tang 1 year, 11 months ago
Mat Martineau <mathew.j.martineau@linux.intel.com> 于2022年5月12日周四 08:15写道:
>
> On Wed, 11 May 2022, Paolo Abeni wrote:
>
> > The mentioned helper requires the msk socket lock, and the
> > current callers don't own it nor can't acquire it, so the
> > access is racy.
> >
> > All the current callers are really checking for infinite mapping
> > fallback, and the latter condition is explicitly tracked by
> > the relevant msk variable: we can safely remove the caller usage
> > - and the caller itself.
> >
> > The issue is present since MP_FAIL implementation, but the
> > fix only applies since the infinite fallback support, ence the
> > somewhat unexpected fixes tag.
> >
> > Fixes: 0530020a7c8f ("mptcp: track and update contiguous data status")
> > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
>
> Looks good to me. I wasn't able to reproduce the CI failure.
>
> Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>

Acked-and-tested-by: Geliang Tang <geliang.tang@suse.com>

CI reported this failure:

[13:54:03.080] # itx[ ok ] - infirx[fail] got 0 infinite map[s] RX expected 1

But it doesn't occur in my test.

Thanks,
-Geliang

>
>
>
> > ---
> > net/mptcp/pm.c       |  2 +-
> > net/mptcp/protocol.h | 13 -------------
> > net/mptcp/subflow.c  |  3 +--
> > 3 files changed, 2 insertions(+), 16 deletions(-)
> >
> > diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> > index 59fdab2d0c27..8ba51120f35b 100644
> > --- a/net/mptcp/pm.c
> > +++ b/net/mptcp/pm.c
> > @@ -303,7 +303,7 @@ void mptcp_pm_mp_fail_received(struct sock *sk, u64 fail_seq)
> >
> >       pr_debug("fail_seq=%llu", fail_seq);
> >
> > -     if (mptcp_has_another_subflow(sk) || !READ_ONCE(msk->allow_infinite_fallback))
> > +     if (!READ_ONCE(msk->allow_infinite_fallback))
> >               return;
> >
> >       if (!READ_ONCE(subflow->mp_fail_response_expect)) {
> > diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> > index f98c27300e60..dbb914def5cc 100644
> > --- a/net/mptcp/protocol.h
> > +++ b/net/mptcp/protocol.h
> > @@ -661,19 +661,6 @@ static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
> >       inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops;
> > }
> >
> > -static inline bool mptcp_has_another_subflow(struct sock *ssk)
> > -{
> > -     struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk), *tmp;
> > -     struct mptcp_sock *msk = mptcp_sk(subflow->conn);
> > -
> > -     mptcp_for_each_subflow(msk, tmp) {
> > -             if (tmp != subflow)
> > -                     return true;
> > -     }
> > -
> > -     return false;
> > -}
> > -
> > void __init mptcp_proto_init(void);
> > #if IS_ENABLED(CONFIG_MPTCP_IPV6)
> > int __init mptcp_proto_v6_init(void);
> > diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
> > index b38a02db924b..550c8fbec54d 100644
> > --- a/net/mptcp/subflow.c
> > +++ b/net/mptcp/subflow.c
> > @@ -1218,8 +1218,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
> >       if (!__mptcp_check_fallback(msk)) {
> >               /* RFC 8684 section 3.7. */
> >               if (subflow->send_mp_fail) {
> > -                     if (mptcp_has_another_subflow(ssk) ||
> > -                         !READ_ONCE(msk->allow_infinite_fallback)) {
> > +                     if (!READ_ONCE(msk->allow_infinite_fallback)) {
> >                               ssk->sk_err = EBADMSG;
> >                               tcp_set_state(ssk, TCP_CLOSE);
> >                               subflow->reset_transient = 0;
> > --
> > 2.35.3
> >
> >
> >
>
> --
> Mat Martineau
> Intel
>