Article View: linux.kernel.netdev
Article #27040Re: [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4 fast paths
From: Simon Horman
Date: Fri, 04 Dec 2026 17:02
Date: Fri, 04 Dec 2026 17:02
75 lines
12490 bytes
12490 bytes
On Fri, Nov 27, 2026 at 10:41:00AM +0000, David Laight wrote:
> On Fri, 27 Nov 2026 15:33:15 +0900
> Xuanqiang Luo <xuanqiang.luo@linux.dev> wrote:
>
> > On 2026/11/26 at 19:20 David Laight wrote:
> > > On Tue, 24 Nov 2026 22:06:25 +0900
> > > Xuanqiang Luo <xuanqiang.luo@linux.dev> wrote:
> > >
> > >> From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
> > >>
> > >> With CONFIG_STACKPROTECTOR_STRONG=y, a function that has a local array or
> > >> passes the address of one of its locals to another function needs a stack
> > >> canary. The canary is set up and checked on every call, also when the
> > >> local is only used on a path that almost never runs.
> > >>
> > >> This series removes the canary from functions of the TCP/IPv4 fast paths,
> > >> by returning results by value, by using storage that is not on the stack,
> > >> or by not calling a function that has nothing to do.
> > >>
> > >> Patch 1 returns the two mptcp_space() values in a structure, so that
> > >> __tcp_select_window() no longer needs a canary.
> > >
> > > While all (I think) architectures can return a big integer in two
> > > registers (dx:ax on x86), not all ABI do the same for small structures.
> > > For those architectures returning a struct by value is implemented by
> > > passing the address of a hidden on stack structure.
> > > So code generation may be worse than passing the values by reference.
> > > I can't remember the list of architectures, mostly old ones - but not
> > > 32bit x86 because the compiler option was set when regparm=3 was added
> > > for 2.6.
> > > (Note that this is different from passing small structures by value.)
> > >
> > > David
> >
> > Hi David,
> >
> > Good point! thanks for bringing that up.
> >
> > The small-struct-by-value pattern in patches 1 and 4 follows the same
> > approach Eric used in commit 7a4cd71fa451 ("net: add
> > vlan_get_protocol_offset_inline() helper"), which returns a 2-field
> > struct vlan_type_depth to avoid stack canaries in callers.
> >
> > I did note the 8-byte struct ABI distinction you mentioned:
> > - On the main 64-bit targets (x86_64, arm64, riscv64, ppc64le, loongarch64)
> > as well as 32-bit x86 (with -mregparm=3 / reg-struct-return), both
> > 8-byte structs (struct mptcp_space_info and struct skb_coalesce_res) are
> > returned in registers and the stack canaries are dropped cleanly.
> > - On ABIs that return structs (> 4 bytes on 32-bit ARM EABI, or any struct
> > on s390x) via a hidden stack buffer, it indeed falls back to a hidden
> > pointer. Even there, the callers previously passed *two* pointers to
> > locals (&space/&full_space in patch 1, &fragstolen/&delta_truesize in
> > patch 4), so passing one hidden 8-byte return slot should not be worse
> > than before, while keeping the code cleaner and type-safe.
>
> There might be a subtle difference in the function itself.
> I think the result structure gets allocated on stack and then a memcpy()
> used to copy that to the caller's buffer during the function return.
> That may, or may not, be faster.
>
> >
> > That said, if maintainers prefer packing the two fields into a u64 so that
> > even 32-bit ARM / s390x return them in registers, I'd be happy to change
> > patches 1 and 4 to do that in v2.
>
> That is horrid ... and you'd need to use a u128 on 64bit.
> It really is a shame that C doesn't have a syntax for returning 2 integers
> even though pretty much all ABI have always supported it.
I think this patch-set takes the right approach.
For the series:
Reviewed-by: Simon Horman <horms@kernel.org>
Technical Details
Message-ID:
<20261204170246.GA192805@horms.kernel.org>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377504-linux-kernel-netdev=dewy.ruReferences:
<20261124130631.1886963-1-xuanqiang.luo@linux.dev> <20261126102058.1fecf50f@pumpkin> <bffee809-2992-40eb-97c7-72d919de0aed@linux.dev> <20261127104100.3c915088@pumpkin>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377504-linux-kernel-netdev=dewy.ru From: horms@kernel.org (Simon Horman) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4 fast paths Date: Fri, 4 Dec 2026 17:02:46 +0000 Organization: Usenet Network Message-ID: <20261204170246.GA192805@horms.kernel.org> References: <20261124130631.1886963-1-xuanqiang.luo@linux.dev> <20261126102058.1fecf50f@pumpkin> <bffee809-2992-40eb-97c7-72d919de0aed@linux.dev> <20261127104100.3c915088@pumpkin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="2813551"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:iOLNaMTJW1DuDIj6hvXl2dY9YGQ= sha256:al87FD6E0kzXqs0HPaTL4mHV2SDi4Xh7AswuOyI1JZo= sha1:n6IwEw49nG0FkmrHJ2mrasBomQE= sha256:Z+4/Ydjc6D9rV8IKHxNUBIhG2GEjMK1yPDTNgsdpPks= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 55424117C77; Fri, 4 Dec 2026 20:03:24 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.642 X-Spam-Status: No, score=-3.642 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xAlo5QHS_dV1; Fri, 4 Dec 2026 20:03:22 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-377504-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id BFA49117C0E; Fri, 4 Dec 2026 20:02:59 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id AFE74607C5B; Fri, 4 Dec 2026 17:02:58 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796403776; b=EUcfR0tlEjmKmCJiA25ouyvfYtcXsRur1O2vCO/aO4v9ur/pXYcag/fhmnTmqSqrs+1x h3NFkTY3ixsP/TPOdd19MvagYenvV6+sDe7O5hCvdajsim1eCwkeNOLe5QpGhzwqss+nv NmOgWa4V3/lUtwg+bgGUYq+1shfDwb0JNwd6+6/G3Vg2fGqCbJ5q71qvWAA2K91srS7xE +/T5SwKEFLMCW9mLR3Z3VnWEsOiq3uSkjpjASq3KSer8GizneAreUSpyP6uJ1V/yuMlYN waa3t34Sbo5Zbo0LNlaoVM0VX9BMafob3W2mtLepsEKh0VIgWt6Z5HzuPFI+wtVFhuA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796403776; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=DtjY2dd+NFR+xqiURxIUX9aBDHFLn2UWlq2hfF/zN0c=; b=jI86pyJI44/rzbsIIBcLGvE+peButkJLP/jTM1nrRDY4j0c1snO1tExYrct/OmaQQ6eL cfFmiaPdyhb+ajsrixdsPymBj2Kc7e3W2+Fq5hR44xrhpkseXiSu+nFiaXz7febu5/g2p APLdsnOw24+bACmo1U7ooT7t60sK0h0G6rN91O6kGPSzkvqen6JvnGDP+5suPhBb0LQC3 ZDeZbnrk8vqPCi0rYI7fRHedCUkXgZokfp2uid0Tttd9O66VW6jiFL6p7jBcPfDM6EUxR KZ8z2vJeKUu7V1E05lq31dN6Po2hyij/HQwVHCPhOZh/nqn8USFlM6xqFGoDd2LJiEw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kV4i0v9k; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1BB9606A682; Fri, 4 Dec 2026 17:02:56 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kV4i0v9k X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796403775; b=MawIS6AxQmHJeCE/L153/NXIrahMTDv1yw3nX3Z8d61rV5W2rkoPGbiiDREH9eLIhBDH JwKTcvlva+WZby0aLN9wpAaHv1Lm6suvZRkBrkWXS2Xmu62mX63Lsm7Vw5nfknDsIY6zS R12y4t67tYPVNgp05fqbjqwc517TaZi3qDCJ7Xt1ZteqNzHujXsaHtQiowNErVRzl0rdh mrq5TsZDxS36gJqIZ5l3Ud9tDGD8DnN4cMb0LHkqcD1tw3/SULPJFQin+/DQijfcY+sME /0nQ8+GjYO4PxdG125cQWKmRc1zZkf2BF8H71LodKEUCm/x0cCQr9RD8e744PsfIl8Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796403775; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=DtjY2dd+NFR+xqiURxIUX9aBDHFLn2UWlq2hfF/zN0c=; b=35BVgEycNu36MYIJlr8kI2YgRBde7KExyzoQAiMGZvYlfXF2m4b34tTg/Fmn7e8Yesh2 w4P+yp3vK4+gzMechhqyOhVYg8C60R3zSYmduS4FyMyyPYtMHLKLOIZbTOHxa5rg37SOT KT9tIjpTVj94ZYG8klTrGqMUNvkFqHTgx5hzlPRtcK6IwJ7jJ8avKaJ23bNqSbyO+TWxY q+8g6ajvxX1kQfI1StyCU5GTOG2HV3VQ6QiLuiImawtGX5uEm8j8Y3jehRUOeTv3I5mw9 rqJYEWF7EL2d7VD9qWD+t4GbhXFR4EoPDiZpbsNiQXcstdFWo0YlqWGmRNvMt3ZTicg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kV4i0v9k; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDE9C606A322; Fri, 4 Dec 2026 17:02:55 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12DC01F00A0F; Fri, 4 Dec 2026 17:02:48 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796403775; bh=DtjY2dd+NFR+xqiURxIUX9aBDHFLn2UWlq2hfF/zN0c=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=kV4i0v9kyn4GF7CxpO6KbPAIGLln/abdkGfOHvE+dlYyrCN3nWofvwPrybYC95j7D CFg1Z0ag/7MT+MvwLUC2R069/blVd3rHNJl97ZQnQ0y43ZXgIMmd95UnsWyuSYkQb4 u/P/wF6pjH+ZIWEyZusNgjTL+RpRT2MLgI7w8HCeZg6OC/O8ziYIVkzpNzrUUMQDCk HkJhdUuRcFPc60UEaLF+l0ZOtF/2rhUqVQXLxTgeLcrsOOes2FTESFbG9V5p/ECmba NTgTEG1ktMc4NTap2wonrwVv2JIRH37+veF51tK3GnTjE7OMjgk61ywxEjB+RkL6Yv hrPPgbD/lI1yQ== X-Cc: Xuanqiang Luo <xuanqiang.luo@linux.dev>, netdev@vger.kernel.org, "David S . Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, 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> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261127104100.3c915088@pumpkin>