mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mo Yuanhao <moyuanhao3676@163.com>
To: matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org,
	edumazet@google.com, davem@davemloft.net, dsahern@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	mptcp@lists.linux.dev, stable@vger.kernel.org
Subject: Re: [PATCH net-next] tcp: Check space before adding MPTCP options
Date: Thu, 5 Dec 2024 15:31:47 +0800	[thread overview]
Message-ID: <dcdeaf17-c3ce-4677-a0c0-c391d8bd951f@163.com> (raw)
In-Reply-To: <80b6603d-ed52-43b7-a434-0253e5de784a@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 2961 bytes --]

在 2024/12/4 19:01, Matthieu Baerts 写道:
> Hi MoYuanhao,
> 
> +Cc MPTCP mailing list.
> 
> (Please cc the MPTCP list next time)
> 
> On 04/12/2024 09:58, MoYuanhao wrote:
>> Ensure enough space before adding MPTCP options in tcp_syn_options()
>> Added a check to verify sufficient remaining space
>> before inserting MPTCP options in SYN packets.
>> This prevents issues when space is insufficient.
> 
> Thank you for this patch. I'm surprised we all missed this check, but
> yes it is missing.
> 
> As mentioned by Eric in his previous email, please add a 'Fixes' tag.
> For bug-fixes, you should also Cc stable and target 'net', not 'net-next':
> 
> Fixes: cec37a6e41aa ("mptcp: Handle MP_CAPABLE options for outgoing
> connections")
> Cc: stable@vger.kernel.org
> 
> 
> Regarding the code, it looks OK to me, as we did exactly that with
> mptcp_synack_options(). In mptcp_established_options(), we pass
> 'remaining' because many MPTCP options can be set, but not here. So I
> guess that's fine to keep the code like that, especially for the 'net' tree.
> 
> 
> Also, and linked to Eric's email, did you have an issue with that, or is
> it to prevent issues in the future?
> 
> 
> One last thing, please don’t repost your patches within one 24h period, see:
> 
>    https://docs.kernel.org/process/maintainer-netdev.html
> 
> 
> Because the code is OK to me, and the same patch has already been sent
> twice to the netdev ML within a few hours, I'm going to apply this patch
> in our MPTCP tree with the suggested modifications. Later on, we will
> send it for inclusion in the net tree.
> 
> pw-bot: awaiting-upstream
> 
> (Not sure this pw-bot instruction will work as no net/mptcp/* files have
> been modified)
> 
> Cheers,
> Matt
Hi Matt,

Thank you for your feedback!

I have made the suggested updates to the patch (version 2):

I’ve added the Fixes tag and Cc'd the stable@vger.kernel.org list.
The target branch has been adjusted to net as per your suggestion.
I will make sure to Cc the MPTCP list in future submissions.

Regarding your question, this patch was created to prevent potential 
issues related to insufficient space for MPTCP options in the future. I 
didn't encounter a specific issue, but it seemed like a necessary 
safeguard to ensure robustness when handling SYN packets with MPTCP options.

Additionally, I have made further optimizations to the patch, which are 
included in the attached version. I believe it would be more elegant to 
introduce a new function, mptcp_set_option(), similar to 
mptcp_set_option_cond(), to handle MPTCP options.

This is my first time replying to a message in a Linux mailing list, so 
if there are any formatting issues or mistakes, please point them out 
and I will make sure to correct them in future submissions.

Thanks again for your review and suggestions. Looking forward to seeing 
the patch applied to the MPTCP tree and later inclusion in the net tree.

Best regards,

MoYuanhao

[-- Attachment #2: 0001-tcp-Check-space-before-adding-MPTCP-options.patch --]
[-- Type: text/x-patch, Size: 1854 bytes --]

From 12904db548bdd8011895fe071d7a420ccc6584f8 Mon Sep 17 00:00:00 2001
From: MoYuanhao <moyuanhao3676@163.com>
Date: Thu, 5 Dec 2024 10:18:15 +0800
Subject: [PATCH net v2] tcp: Check space before adding MPTCP options

Ensure enough space before adding MPTCP options in tcp_syn_options()
Added a check to verify sufficient remaining space
before inserting MPTCP options in SYN packets.
This prevents issues when space is insufficient.

Fixes: cec37a6e41aa ("mptcp: Handle MP_CAPABLE options for outgoing connections")
Signed-off-by: MoYuanhao <moyuanhao3676@163.com>
---
 net/ipv4/tcp_output.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 5485a70b5fe5..401eb14c870d 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -792,6 +792,21 @@ static void smc_set_option_cond(const struct tcp_sock *tp,
 #endif
 }
 
+static void mptcp_set_option(struct sock *sk, const struct sk_buff *skb,
+				struct tcp_out_options *opts, unsigned int *remaining)
+{
+	if (sk_is_mptcp(sk)) {
+		unsigned int size;
+
+		if (mptcp_syn_options(sk, skb, &size, &opts->mptcp)) {
+			if (*remaining >= size) {
+				opts->options |= OPTION_MPTCP;
+				*remaining -= size;
+			}
+		}
+	}
+}
+
 static void mptcp_set_option_cond(const struct request_sock *req,
 				  struct tcp_out_options *opts,
 				  unsigned int *remaining)
@@ -879,14 +894,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 
 	smc_set_option(tp, opts, &remaining);
 
-	if (sk_is_mptcp(sk)) {
-		unsigned int size;
-
-		if (mptcp_syn_options(sk, skb, &size, &opts->mptcp)) {
-			opts->options |= OPTION_MPTCP;
-			remaining -= size;
-		}
-	}
+	mptcp_set_option(sk,skb,opts, &remaining);
 
 	bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts, &remaining);
 
-- 
2.25.1


  reply	other threads:[~2024-12-05  7:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04  8:58 MoYuanhao
2024-12-04 11:01 ` Matthieu Baerts
2024-12-05  7:31   ` Mo Yuanhao [this message]
2024-12-05  7:54     ` Eric Dumazet
2024-12-05  9:24       ` Matthieu Baerts
2024-12-05 10:13         ` MoYuanhao
  -- strict thread matches above, loose matches on Subject: below --
2024-12-04  3:49 MoYuanhao
2024-12-04  7:35 ` Eric Dumazet

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=dcdeaf17-c3ce-4677-a0c0-c391d8bd951f@163.com \
    --to=moyuanhao3676@163.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=geliang@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®