diff mbox series

[net-next] tcp: Check space before adding MPTCP options

Message ID 20241204034946.10794-1-moyuanhao3676@163.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] tcp: Check space before adding MPTCP options | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 304 this patch: 304
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-12-04--09-00 (tests: 759)

Commit Message

MoYuanhao Dec. 4, 2024, 3:49 a.m. UTC
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.

Signed-off-by: MoYuanhao <moyuanhao3676@163.com>
---
 net/ipv4/tcp_output.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Eric Dumazet Dec. 4, 2024, 7:35 a.m. UTC | #1
On Wed, Dec 4, 2024 at 5:07 AM MoYuanhao <moyuanhao3676@163.com> 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.
>
> Signed-off-by: MoYuanhao <moyuanhao3676@163.com>
> ---

If this is happening, then this would be a bug, and a Fixes: tag would
be needed.

If this is not yet happening, but would happen in the future, this
patch would hide a bug.

You forgot to CC MPTCP maintainers and reviewers ?

Matthieu Baerts <matttbe@kernel.org> (maintainer:NETWORKING [MPTCP])
Mat Martineau <martineau@kernel.org> (maintainer:NETWORKING [MPTCP])
Geliang Tang <geliang@kernel.org> (reviewer:NETWORKING [MPTCP])

In my  opinion, we should pass @remaining to mptcp_syn_options()
arguments to avoid side effects.
diff mbox series

Patch

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 5485a70b5fe5..0e5b9a654254 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -883,8 +883,10 @@  static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 		unsigned int size;
 
 		if (mptcp_syn_options(sk, skb, &size, &opts->mptcp)) {
-			opts->options |= OPTION_MPTCP;
-			remaining -= size;
+			if (remaining >= size) {
+				opts->options |= OPTION_MPTCP;
+				remaining -= size;
+			}
 		}
 	}