diff mbox series

[mptcp-net,v7,4/5] mptcp: avoid processing packet if a subflow reset

Message ID 1624609559-6786-5-git-send-email-wujianguo106@163.com (mailing list archive)
State Superseded, archived
Headers show
Series Fix some mptcp syncookie process bugs | expand

Commit Message

Jianguo Wu June 25, 2021, 8:25 a.m. UTC
From: Jianguo Wu <wujianguo@chinatelecom.cn>

If check_fully_established() causes a subflow reset, it should not
continue to process the packet in tcp_data_queue().
Add a return value to mptcp_incoming_options(), and return 0 if a
subflow has been reset, else return 1. Then drop the packet in
tcp_data_queue()/tcp_rcv_state_process() if mptcp_incoming_options()
return 0.

Fixes: d582484726c4 ("mptcp: fix fallback for MP_JOIN subflows")
Signed-off-by: Jianguo Wu <wujianguo@chinatelecom.cn>
---
 include/net/mptcp.h  |  5 +++--
 net/ipv4/tcp_input.c | 19 +++++++++++++++----
 net/mptcp/options.c  | 22 ++++++++++++++--------
 3 files changed, 32 insertions(+), 14 deletions(-)

Comments

Geliang Tang June 25, 2021, 8:58 a.m. UTC | #1
Hi Jianguo,

Thank you for this patchset!

<wujianguo106@163.com> 于2021年6月25日周五 下午4:26写道:
>
> From: Jianguo Wu <wujianguo@chinatelecom.cn>
>
> If check_fully_established() causes a subflow reset, it should not
> continue to process the packet in tcp_data_queue().
> Add a return value to mptcp_incoming_options(), and return 0 if a
> subflow has been reset, else return 1. Then drop the packet in
> tcp_data_queue()/tcp_rcv_state_process() if mptcp_incoming_options()
> return 0.
>
> Fixes: d582484726c4 ("mptcp: fix fallback for MP_JOIN subflows")
> Signed-off-by: Jianguo Wu <wujianguo@chinatelecom.cn>
> ---
>  include/net/mptcp.h  |  5 +++--
>  net/ipv4/tcp_input.c | 19 +++++++++++++++----
>  net/mptcp/options.c  | 22 ++++++++++++++--------
>  3 files changed, 32 insertions(+), 14 deletions(-)
>
> diff --git a/include/net/mptcp.h b/include/net/mptcp.h
> index cb580b0..cbd511c 100644
> --- a/include/net/mptcp.h
> +++ b/include/net/mptcp.h
> @@ -105,7 +105,7 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
>  bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
>                                unsigned int *size, unsigned int remaining,
>                                struct mptcp_out_options *opts);
> -void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
> +int mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
>
>  void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
>                          struct mptcp_out_options *opts);
> @@ -227,9 +227,10 @@ static inline bool mptcp_established_options(struct sock *sk,
>         return false;
>  }
>
> -static inline void mptcp_incoming_options(struct sock *sk,
> +static inline int mptcp_incoming_options(struct sock *sk,
>                                           struct sk_buff *skb)
>  {
> +       return 1;
>  }
>
>  static inline void mptcp_skb_ext_move(struct sk_buff *to,
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 7d5e59f..4bacd7d 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -4247,6 +4247,9 @@ void tcp_reset(struct sock *sk, struct sk_buff *skb)
>  {
>         trace_tcp_receive_reset(sk);
>
> +       /* mptcp can't tell us to ignore reset pkts,
> +        * so just ignore the return value of mptcp_incoming_options().
> +        */
>         if (sk_is_mptcp(sk))
>                 mptcp_incoming_options(sk, skb);
>
> @@ -4941,8 +4944,13 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
>         bool fragstolen;
>         int eaten;
>
> -       if (sk_is_mptcp(sk))
> -               mptcp_incoming_options(sk, skb);
> +       /* If a subflow has been reset, the packet should not continue
> +        * to be processed, drop the packet.
> +        */
> +       if (sk_is_mptcp(sk) && !mptcp_incoming_options(sk, skb)) {
> +               __kfree_skb(skb);
> +               return;
> +       }
>
>         if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
>                 __kfree_skb(skb);
> @@ -6523,8 +6531,11 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
>         case TCP_CLOSING:
>         case TCP_LAST_ACK:
>                 if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) {
> -                       if (sk_is_mptcp(sk))
> -                               mptcp_incoming_options(sk, skb);
> +                       /* If a subflow has been reset, the packet should not
> +                        * continue to be processed, drop the packet.
> +                        */
> +                       if (sk_is_mptcp(sk) && !mptcp_incoming_options(sk, skb))
> +                               goto discard;
>                         break;
>                 }
>                 fallthrough;
> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> index b5850af..f4842b5 100644
> --- a/net/mptcp/options.c
> +++ b/net/mptcp/options.c
> @@ -856,7 +856,8 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
>  static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
>                                     struct mptcp_subflow_context *subflow,
>                                     struct sk_buff *skb,
> -                                   struct mptcp_options_received *mp_opt)
> +                                   struct mptcp_options_received *mp_opt,
> +                                   bool *subflow_is_rst)
>  {
>         /* here we can process OoO, in-window pkts, only in-sequence 4th ack
>          * will make the subflow fully established
> @@ -938,6 +939,7 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
>         return true;
>
>  reset:
> +       *subflow_is_rst = true;
>         mptcp_subflow_reset(ssk);
>         return false;
>  }
> @@ -1035,12 +1037,14 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,
>         return hmac == mp_opt->ahmac;
>  }
>
> -void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
> +/* Return 0 if a subflow has been reset, else return 1 */

How about returning a bool here, return true or return false?

-Geliang

> +int mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
>  {
>         struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
>         struct mptcp_sock *msk = mptcp_sk(subflow->conn);
>         struct mptcp_options_received mp_opt;
>         struct mptcp_ext *mpext;
> +       bool subflow_is_rst = false;
>
>         if (__mptcp_check_fallback(msk)) {
>                 /* Keep it simple and unconditionally trigger send data cleanup and
> @@ -1053,12 +1057,12 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
>                         __mptcp_check_push(subflow->conn, sk);
>                 __mptcp_data_acked(subflow->conn);
>                 mptcp_data_unlock(subflow->conn);
> -               return;
> +               return 1;
>         }
>
>         mptcp_get_options(sk, skb, &mp_opt);
> -       if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
> -               return;
> +       if (!check_fully_established(msk, sk, subflow, skb, &mp_opt, &subflow_is_rst))
> +               return subflow_is_rst ? 0 : 1;
>
>         if (mp_opt.fastclose &&
>             msk->local_key == mp_opt.rcvr_key) {
> @@ -1100,7 +1104,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
>         }
>
>         if (!mp_opt.dss)
> -               return;
> +               return 1;
>
>         /* we can't wait for recvmsg() to update the ack_seq, otherwise
>          * monodirectional flows will stuck
> @@ -1119,12 +1123,12 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
>                     schedule_work(&msk->work))
>                         sock_hold(subflow->conn);
>
> -               return;
> +               return 1;
>         }
>
>         mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
>         if (!mpext)
> -               return;
> +               return 1;
>
>         memset(mpext, 0, sizeof(*mpext));
>
> @@ -1153,6 +1157,8 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
>                 if (mpext->csum_reqd)
>                         mpext->csum = mp_opt.csum;
>         }
> +
> +       return 1;
>  }
>
>  static void mptcp_set_rwin(const struct tcp_sock *tp)
> --
> 1.8.3.1
>
>
>
Matthieu Baerts June 25, 2021, 9:07 a.m. UTC | #2
Hi Jianguo,

Thank you for working on that!

On 25/06/2021 10:25, wujianguo106@163.com wrote:
> From: Jianguo Wu <wujianguo@chinatelecom.cn>
> 
> If check_fully_established() causes a subflow reset, it should not
> continue to process the packet in tcp_data_queue().
> Add a return value to mptcp_incoming_options(), and return 0 if a
> subflow has been reset, else return 1.

A small detail but it looks strange to me to return +1.
Maybe clearer to return -1 in case of error or return a boolean?

If you decide to return -1, please check for '< 0':

  if (mptcp_incoming_options(...) < 0) // error: we discard
      goto discard;

and not:

  if (mptcp_incoming_options(...)) // no error but we discard??
      goto discard;

(Or replace subflow_is_rst by subflow_is_accepted and return this
variable but it might be strange to return that if you don't have a DSS,
etc.)

But if it is only me who find "strange" to return 0/+1, fine not to
change but it looks uncommon and maybe a source of misinterpretation :)

Cheers,
Matt
Jianguo Wu June 25, 2021, 9:46 a.m. UTC | #3
On 2021/6/25 17:07, Matthieu Baerts wrote:
> Hi Jianguo,
> 
> Thank you for working on that!
> 
> On 25/06/2021 10:25, wujianguo106@163.com wrote:
>> From: Jianguo Wu <wujianguo@chinatelecom.cn>
>>
>> If check_fully_established() causes a subflow reset, it should not
>> continue to process the packet in tcp_data_queue().
>> Add a return value to mptcp_incoming_options(), and return 0 if a
>> subflow has been reset, else return 1.
> 
> A small detail but it looks strange to me to return +1.
> Maybe clearer to return -1 in case of error or return a boolean?
> 

Hi Mat and Geliang,

Based on your comments, I will use boolean type as return value, return false if a subflow has been reset.
Thanks for your review!

> If you decide to return -1, please check for '< 0':
> 
>   if (mptcp_incoming_options(...) < 0) // error: we discard
>       goto discard;
> 
> and not:
> 
>   if (mptcp_incoming_options(...)) // no error but we discard??
>       goto discard;
> 
> (Or replace subflow_is_rst by subflow_is_accepted and return this
> variable but it might be strange to return that if you don't have a DSS,
> etc.)
> 
> But if it is only me who find "strange" to return 0/+1, fine not to
> change but it looks uncommon and maybe a source of misinterpretation :)
> 
> Cheers,
> Matt
>
Paolo Abeni June 25, 2021, 10:38 a.m. UTC | #4
On Fri, 2021-06-25 at 16:25 +0800, wujianguo106@163.com wrote:
> @@ -1035,12 +1037,14 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,
>  	return hmac == mp_opt->ahmac;
>  }
>  
> -void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
> +/* Return 0 if a subflow has been reset, else return 1 */
> +int mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
>  {
>  	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
>  	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
>  	struct mptcp_options_received mp_opt;
>  	struct mptcp_ext *mpext;
> +	bool subflow_is_rst = false;

Additional small detail: please use the reverse xmas tree order for
variables definition.

Thanks!

/P
Paolo Abeni June 25, 2021, 10:45 a.m. UTC | #5
Hi,

I'm sorry for the partial feedback in my previous reply.

On Fri, 2021-06-25 at 16:25 +0800, wujianguo106@163.com wrote:
> @@ -856,7 +856,8 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
>  static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
>  				    struct mptcp_subflow_context *subflow,
>  				    struct sk_buff *skb,
> -				    struct mptcp_options_received *mp_opt)
> +				    struct mptcp_options_received *mp_opt,
> +				    bool *subflow_is_rst)

This additional argument is not needed...

[...]
> @@ -1053,12 +1057,12 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
>  			__mptcp_check_push(subflow->conn, sk);
>  		__mptcp_data_acked(subflow->conn);
>  		mptcp_data_unlock(subflow->conn);
> -		return;
> +		return 1;
>  	}
>  
>  	mptcp_get_options(sk, skb, &mp_opt);
> -	if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
> -		return;
> +	if (!check_fully_established(msk, sk, subflow, skb, &mp_opt, &subflow_is_rst))
> +		return subflow_is_rst ? 0 : 1;


... here you can simply:

		return sk->sk_state != TCP_CLOSE;

plus some comment above alike:

"""the subflow can be in close state only if check_fully_established()
just sent a reset. If so, tell the caller to ignore the current
packet"""

/P
Mat Martineau June 26, 2021, 1:07 a.m. UTC | #6
On Fri, 25 Jun 2021, Jianguo Wu wrote:

>
>
> On 2021/6/25 17:07, Matthieu Baerts wrote:
>> Hi Jianguo,
>>
>> Thank you for working on that!
>>
>> On 25/06/2021 10:25, wujianguo106@163.com wrote:
>>> From: Jianguo Wu <wujianguo@chinatelecom.cn>
>>>
>>> If check_fully_established() causes a subflow reset, it should not
>>> continue to process the packet in tcp_data_queue().
>>> Add a return value to mptcp_incoming_options(), and return 0 if a
>>> subflow has been reset, else return 1.
>>
>> A small detail but it looks strange to me to return +1.
>> Maybe clearer to return -1 in case of error or return a boolean?
>>
>
> Hi Mat and Geliang,
>
> Based on your comments, I will use boolean type as return value, return false if a subflow has been reset.
> Thanks for your review!

Thanks - I think the 'bool' fits better here than -1/0.

-Mat


>
>> If you decide to return -1, please check for '< 0':
>>
>>   if (mptcp_incoming_options(...) < 0) // error: we discard
>>       goto discard;
>>
>> and not:
>>
>>   if (mptcp_incoming_options(...)) // no error but we discard??
>>       goto discard;
>>
>> (Or replace subflow_is_rst by subflow_is_accepted and return this
>> variable but it might be strange to return that if you don't have a DSS,
>> etc.)
>>
>> But if it is only me who find "strange" to return 0/+1, fine not to
>> change but it looks uncommon and maybe a source of misinterpretation :)
>>
>> Cheers,
>> Matt
>>
>
>

--
Mat Martineau
Intel
Jianguo Wu June 26, 2021, 8:59 a.m. UTC | #7
Hi Paolo,

On 2021/6/25 18:45, Paolo Abeni wrote:
> Hi,
> 
> I'm sorry for the partial feedback in my previous reply.
> 
> On Fri, 2021-06-25 at 16:25 +0800, wujianguo106@163.com wrote:
>> @@ -856,7 +856,8 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
>>  static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
>>  				    struct mptcp_subflow_context *subflow,
>>  				    struct sk_buff *skb,
>> -				    struct mptcp_options_received *mp_opt)
>> +				    struct mptcp_options_received *mp_opt,
>> +				    bool *subflow_is_rst)
> 
> This additional argument is not needed...
> 
> [...]
>> @@ -1053,12 +1057,12 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
>>  			__mptcp_check_push(subflow->conn, sk);
>>  		__mptcp_data_acked(subflow->conn);
>>  		mptcp_data_unlock(subflow->conn);
>> -		return;
>> +		return 1;
>>  	}
>>  
>>  	mptcp_get_options(sk, skb, &mp_opt);
>> -	if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
>> -		return;
>> +	if (!check_fully_established(msk, sk, subflow, skb, &mp_opt, &subflow_is_rst))
>> +		return subflow_is_rst ? 0 : 1;
> 
> 
> ... here you can simply:
> 
> 		return sk->sk_state != TCP_CLOSE;
> 
> plus some comment above alike:
> 
> """the subflow can be in close state only if check_fully_established()
> just sent a reset. If so, tell the caller to ignore the current
> packet"""
> 

Thank you for all your reviews and suggestions!New version coming soon.

> /P
>
diff mbox series

Patch

diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index cb580b0..cbd511c 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -105,7 +105,7 @@  bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 			       unsigned int *size, unsigned int remaining,
 			       struct mptcp_out_options *opts);
-void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
+int mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
 
 void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 			 struct mptcp_out_options *opts);
@@ -227,9 +227,10 @@  static inline bool mptcp_established_options(struct sock *sk,
 	return false;
 }
 
-static inline void mptcp_incoming_options(struct sock *sk,
+static inline int mptcp_incoming_options(struct sock *sk,
 					  struct sk_buff *skb)
 {
+	return 1;
 }
 
 static inline void mptcp_skb_ext_move(struct sk_buff *to,
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 7d5e59f..4bacd7d 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4247,6 +4247,9 @@  void tcp_reset(struct sock *sk, struct sk_buff *skb)
 {
 	trace_tcp_receive_reset(sk);
 
+	/* mptcp can't tell us to ignore reset pkts,
+	 * so just ignore the return value of mptcp_incoming_options().
+	 */
 	if (sk_is_mptcp(sk))
 		mptcp_incoming_options(sk, skb);
 
@@ -4941,8 +4944,13 @@  static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 	bool fragstolen;
 	int eaten;
 
-	if (sk_is_mptcp(sk))
-		mptcp_incoming_options(sk, skb);
+	/* If a subflow has been reset, the packet should not continue
+	 * to be processed, drop the packet.
+	 */
+	if (sk_is_mptcp(sk) && !mptcp_incoming_options(sk, skb)) {
+		__kfree_skb(skb);
+		return;
+	}
 
 	if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
 		__kfree_skb(skb);
@@ -6523,8 +6531,11 @@  int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
 	case TCP_CLOSING:
 	case TCP_LAST_ACK:
 		if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) {
-			if (sk_is_mptcp(sk))
-				mptcp_incoming_options(sk, skb);
+			/* If a subflow has been reset, the packet should not
+			 * continue to be processed, drop the packet.
+			 */
+			if (sk_is_mptcp(sk) && !mptcp_incoming_options(sk, skb))
+				goto discard;
 			break;
 		}
 		fallthrough;
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index b5850af..f4842b5 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -856,7 +856,8 @@  bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
 				    struct mptcp_subflow_context *subflow,
 				    struct sk_buff *skb,
-				    struct mptcp_options_received *mp_opt)
+				    struct mptcp_options_received *mp_opt,
+				    bool *subflow_is_rst)
 {
 	/* here we can process OoO, in-window pkts, only in-sequence 4th ack
 	 * will make the subflow fully established
@@ -938,6 +939,7 @@  static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
 	return true;
 
 reset:
+	*subflow_is_rst = true;
 	mptcp_subflow_reset(ssk);
 	return false;
 }
@@ -1035,12 +1037,14 @@  static bool add_addr_hmac_valid(struct mptcp_sock *msk,
 	return hmac == mp_opt->ahmac;
 }
 
-void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
+/* Return 0 if a subflow has been reset, else return 1 */
+int mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 	struct mptcp_options_received mp_opt;
 	struct mptcp_ext *mpext;
+	bool subflow_is_rst = false;
 
 	if (__mptcp_check_fallback(msk)) {
 		/* Keep it simple and unconditionally trigger send data cleanup and
@@ -1053,12 +1057,12 @@  void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
 			__mptcp_check_push(subflow->conn, sk);
 		__mptcp_data_acked(subflow->conn);
 		mptcp_data_unlock(subflow->conn);
-		return;
+		return 1;
 	}
 
 	mptcp_get_options(sk, skb, &mp_opt);
-	if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
-		return;
+	if (!check_fully_established(msk, sk, subflow, skb, &mp_opt, &subflow_is_rst))
+		return subflow_is_rst ? 0 : 1;
 
 	if (mp_opt.fastclose &&
 	    msk->local_key == mp_opt.rcvr_key) {
@@ -1100,7 +1104,7 @@  void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
 	}
 
 	if (!mp_opt.dss)
-		return;
+		return 1;
 
 	/* we can't wait for recvmsg() to update the ack_seq, otherwise
 	 * monodirectional flows will stuck
@@ -1119,12 +1123,12 @@  void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
 		    schedule_work(&msk->work))
 			sock_hold(subflow->conn);
 
-		return;
+		return 1;
 	}
 
 	mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
 	if (!mpext)
-		return;
+		return 1;
 
 	memset(mpext, 0, sizeof(*mpext));
 
@@ -1153,6 +1157,8 @@  void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
 		if (mpext->csum_reqd)
 			mpext->csum = mp_opt.csum;
 	}
+
+	return 1;
 }
 
 static void mptcp_set_rwin(const struct tcp_sock *tp)