From: Xuanqiang Luo <xuanqiang.luo@linux.dev>
To: netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Matthieu Baerts <matttbe@kernel.org>,
Mat Martineau <martineau@kernel.org>,
Geliang Tang <geliang@kernel.org>,
David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Neal Cardwell <ncardwell@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Pablo Neira Ayuso <pablo@netfilter.org>,
Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
mptcp@lists.linux.dev, netfilter-devel@vger.kernel.org,
coreteam@netfilter.org, Xuanqiang Luo <luoxuanqiang@kylinos.cn>
Subject: [PATCH net-next v1 1/6] tcp: avoid a stack canary in __tcp_select_window()
Date: Tue, 24 Nov 2026 22:06:26 +0900 [thread overview]
Message-ID: <20261124130631.1886963-2-xuanqiang.luo@linux.dev> (raw)
In-Reply-To: <20261124130631.1886963-1-xuanqiang.luo@linux.dev>
From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
__tcp_select_window() passes the address of two locals to
mptcp_space(), but only for MPTCP subflows.
With CONFIG_STACKPROTECTOR_STRONG=y, this forces a stack canary in
__tcp_select_window() for all TCP sockets.
Return both values in a small structure instead.
While we are at it, do not compute tcp_space() and tcp_full_space()
for MPTCP subflows, their values were overwritten.
$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new
add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-51 (-51)
Function old new delta
mptcp_space 87 86 -1
tcp_connect 5892 5876 -16
__tcp_select_window 706 672 -34
Total: Before=24068967, After=24068916, chg -0.00%
Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
---
include/net/mptcp.h | 13 +++++++++++--
net/ipv4/tcp_output.c | 14 ++++++++++----
net/mptcp/subflow.c | 9 ++++++---
3 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index ad7005b574bb..95ebcfd5950d 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -126,6 +126,12 @@ struct mptcp_pm_ops {
void (*release)(struct mptcp_sock *msk);
} ____cacheline_aligned_in_smp;
+/* Result of mptcp_space(). */
+struct mptcp_space_info {
+ int space;
+ int full_space;
+};
+
#ifdef CONFIG_MPTCP
void mptcp_init(void);
@@ -144,7 +150,7 @@ static inline bool rsk_drop_req(const struct request_sock *req)
return tcp_rsk(req)->is_mptcp && tcp_rsk(req)->drop_req;
}
-void mptcp_space(const struct sock *ssk, int *space, int *full_space);
+struct mptcp_space_info mptcp_space(const struct sock *ssk);
bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
unsigned int *size, struct mptcp_out_options *opts);
bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
@@ -291,7 +297,10 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
return true;
}
-static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { }
+static inline struct mptcp_space_info mptcp_space(const struct sock *ssk)
+{
+ return (struct mptcp_space_info){ };
+}
static inline void mptcp_seq_show(struct seq_file *seq) { }
static inline int mptcp_subflow_init_cookie_req(struct request_sock *req,
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 08d0d4a639fe..c2022fc9ad52 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -3391,12 +3391,18 @@ u32 __tcp_select_window(struct sock *sk)
* fluctuations. --SAW 1998/11/1
*/
int mss = icsk->icsk_ack.rcv_mss;
- int free_space = tcp_space(sk);
- int allowed_space = tcp_full_space(sk);
+ int free_space, allowed_space;
int full_space, window;
- if (sk_is_mptcp(sk))
- mptcp_space(sk, &free_space, &allowed_space);
+ if (sk_is_mptcp(sk)) {
+ struct mptcp_space_info info = mptcp_space(sk);
+
+ free_space = info.space;
+ allowed_space = info.full_space;
+ } else {
+ free_space = tcp_space(sk);
+ allowed_space = tcp_full_space(sk);
+ }
full_space = min_t(int, tp->window_clamp, allowed_space);
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 00677fb3efcd..d22ee068f599 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1532,13 +1532,16 @@ bool mptcp_subflow_data_available(struct sock *sk)
* as far as mptcp peer is concerned that data is still inflight.
* DSS ACK is updated when skb is moved to the mptcp rx queue.
*/
-void mptcp_space(const struct sock *ssk, int *space, int *full_space)
+struct mptcp_space_info mptcp_space(const struct sock *ssk)
{
const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
const struct sock *sk = subflow->conn;
+ struct mptcp_space_info info;
- *space = __mptcp_space(sk);
- *full_space = mptcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf));
+ info.space = __mptcp_space(sk);
+ info.full_space = mptcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf));
+
+ return info;
}
static void subflow_error_report(struct sock *ssk)
--
2.43.0
next prev parent reply other threads:[~2026-11-24 13:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 13:06 [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4 fast paths Xuanqiang Luo
2026-11-24 13:06 ` Xuanqiang Luo [this message]
2026-11-24 13:06 ` [PATCH net-next v1 2/6] ipv4: avoid a stack canary in ip_finish_output2() Xuanqiang Luo
2026-11-24 13:06 ` [PATCH net-next v1 3/6] ipv4: raw: do not use skb_header_pointer() in icmp_filter() Xuanqiang Luo
2026-11-24 13:06 ` [PATCH net-next v1 4/6] net: avoid stack canaries in skb_try_coalesce() callers Xuanqiang Luo
2026-11-24 13:06 ` [PATCH net-next v1 5/6] tcp: avoid a stack canary in tcp_rcv_established() Xuanqiang Luo
2026-11-24 13:06 ` [PATCH net-next v1 6/6] tcp: do not call bpf_skops_write_hdr_opt() unless needed Xuanqiang Luo
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=20261124130631.1886963-2-xuanqiang.luo@linux.dev \
--to=xuanqiang.luo@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=coreteam@netfilter.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=fw@strlen.de \
--cc=geliang@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luoxuanqiang@kylinos.cn \
--cc=martin.lau@linux.dev \
--cc=martineau@kernel.org \
--cc=matttbe@kernel.org \
--cc=memxor@gmail.com \
--cc=mptcp@lists.linux.dev \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@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