Article View: linux.kernel.netdev
Article #23362Re: [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4 fast paths
From: Xuanqiang Luo
Date: Fri, 27 Nov 2026 06:33
Date: Fri, 27 Nov 2026 06:33
58 lines
12073 bytes
12073 bytes
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.
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.
Thanks,
Xuanqiang
Technical Details
Message-ID:
<bffee809-2992-40eb-97c7-72d919de0aed@linux.dev>Path:
mbox-mo1.pugleaf.net!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-372489-linux-kernel-netdev=dewy.ruReferences:
<20261124130631.1886963-1-xuanqiang.luo@linux.dev> <20261126102058.1fecf50f@pumpkin>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!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-372489-linux-kernel-netdev=dewy.ru From: xuanqiang.luo@linux.dev (Xuanqiang Luo) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4 fast paths Date: Fri, 27 Nov 2026 15:33:15 +0900 Organization: Usenet Network Message-ID: <bffee809-2992-40eb-97c7-72d919de0aed@linux.dev> References: <20261124130631.1886963-1-xuanqiang.luo@linux.dev> <20261126102058.1fecf50f@pumpkin> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="658783"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:4Zk186961udX9fkg0z4yuhCVi1U= sha256:AFls3DQHTSe5f2sOe/1BFfNr2pyao2ALFzlpmJcpRnA= sha1:2p/ocw0GFRVMPMxRXgc+hRhAmiM= sha256:1+xIN/oJhUn587dwmH13jKCgZKcio35scxZvfFC4iuU= 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 07193125F10; Fri, 27 Nov 2026 09:33:56 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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 (1024-bit key) header.d=linux.dev 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 NovqmuWGcbYD; Fri, 27 Nov 2026 09:33:53 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372489-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 92565125F13; Fri, 27 Nov 2026 09:33:43 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 21F4329DC7; Fri, 27 Nov 2026 06:33:40 +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=1795761219; b=VAZ0y9WH4nsli/dfIBtkRuZuvbHYGi5SMFHH5EZY0krEiGN6o9bWteceQhaa3On/LNAE udSkFHWRRIM75/oEsdoPv3yV7FXST9qc9r2GQLDp5Ecg8tFWO6Az1u+r296ZDJAYCWBtE a8s3cL8JvFc/+rjBAbBXowiNJcCx6oTB4zx6jmW5CCm5spe+Mc4goVu7fjTz4+iXtUlf/ Q3Uf5uX1xxAblI7uGJhRF00VITrk05bfLXEYPkvEdUGIx5hF6T4wDzHwT64u5mKG+ZqMj hu4W/h0cpA3fa+upqd7Lhze57PIgc0A+IzLaKJ9aeqolU+Tgdq2T3+hk82PstWoEJ0A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795761219; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=6LC43k933l8Ek/GrSPWgwkIQo2nW1+6+OwznWt8NdeU=; b=bQQxRuiRCqAqE1vk9yHEVYWxElofOeCTnADeixFSeg8DhEMpWadzMoGZXAga7dOVPrbv r36wTZTC7KKBpvjR7o13zqjXoPfJD22RG8KSJA5siXKNVk6z7HI6RICxEQLGeTpin7Irk yvkn1ouUudFtsiKIpfyMC3udgDF18x1k6eJ83PbvgSACKNrsEyeNM0MUQvhwXvMRUBwZN sxqBgPyBDEcmTRj65qPtRpXPA/7LBbLzDwQtdGqMMaFxIdOmUDZ90NYbuqcwtQYjexU7i HEMey6wuQiydtIUs3S4uiYP4ljKpCWNd1ODH/zVdq3yRskux9o+rPNmpy69kmglNFVg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Pyc4YtWB; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; 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 33DAE606A335; Fri, 27 Nov 2026 06:33:39 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Pyc4YtWB X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.155 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795761218; b=NgD8O1MDmdvI9tK4Wl8bD7COki7yxOud+WaEcYukRgo1ZqyIfyAUz33w0zm8m2kXvS1e kKMMBkn3l0f+TjH/hu81fIoi+yVaQEvHI8Hq0Zmhe1aT0IXsXq8v1Il2SRMaVRQ5dzJqN UO/7FYSF5Edv3yKzcqUZKJMZLTcZS7xaqK0zDBMDZlxJdpR6MK81w2sY6fJ3h2cuicWhy ngaIyqydN8aty1+X1NpATjn7vkluDOeNAdJEUhebk8keL3qFH7Ky1nwczonGQ+FbsIG2M 65KQ8B2R6RwFUAnePRy+i85fUyoagYNB32ynRyRB78pmTaB0WhZEEq+/tXopu3g20Tg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795761218; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=6LC43k933l8Ek/GrSPWgwkIQo2nW1+6+OwznWt8NdeU=; b=L6Jlk1UDqC8Y+UvbMVGsOtM7PUe3jA2KskgpabOx2RLO8WerGPFsjgDHar47eGGPo7sG N2H0kxILFci5OjgDpOWYq4gNH9UBd0lnEJNLaymC+Quc4ETWuA7NPp/vy7QJ+AfPUFj7e aDb/+rgJMg5Rx+qKC+BGs2VutMRPacyrr+7Tl3fcf3Tot4aURvH7ySVl66iS8BIMbDd/U tvzaM52OGwmkGjUSOqwfh/k6fiw4TG7gZdxSSzxOpEuGt8m87wv4AKs/QpPSF3BDzeOXL SQrD0Db3yETnlxt4cmqCxLcPFXWFhrF/cyRJ5GtdHJJdE6DYLb/Dq4Zn12CZmHvyp0A== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Pyc4YtWB; arc=none smtp.remote-ip=91.218.175.155 X-Received: from mta0.migadu.com (out-155.mta0.migadu.com [91.218.175.155]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36E98606A31E for <netdev@vger.kernel.org>; Fri, 27 Nov 2026 06:33:36 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 36E98606A31E X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=Aqo9Gh/z13+vrH5nhABhxwXDDFLj9lawY51vL3ULqrs=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795761215; v=1; x=1796366015; b=Pyc4YtWBMb+uDyjRZFohccHRXDcqxjekMGI9XBuOksTtl7RsTdQSl90YeRagfq6ustsfEyj9 RXxSbMkwBQgQSKiCwi2CDTcdMz72XIz3prRT/9iFhHufQspLXgM2e/yR5BFUF99cVMJIl7Yeejd l3jHHduYcvGqugwctNqkEQD4= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id bf87ac2432157dd5; Fri, 27 Nov 2026 06:33:35 +0000 X-Mizu-Trace-ID: bf87ac2432157dd5 X-Migadu-Flow: FLOW_OUT 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-User-Agent: Mozilla Thunderbird X-Cc: 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>, 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> X-In-Reply-To: <20261126102058.1fecf50f@pumpkin>