Article View: linux.kernel.netdev
Article #23486Re: [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4 fast paths
From: David Laight
Date: Fri, 27 Nov 2026 10:41
Date: Fri, 27 Nov 2026 10:41
74 lines
15343 bytes
15343 bytes
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.
David
>
> Thanks,
> Xuanqiang
Technical Details
Message-ID:
<20261127104100.3c915088@pumpkin>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-372662-linux-kernel-netdev=dewy.ruReferences:
<20261124130631.1886963-1-xuanqiang.luo@linux.dev> <20261126102058.1fecf50f@pumpkin> <bffee809-2992-40eb-97c7-72d919de0aed@linux.dev>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-372662-linux-kernel-netdev=dewy.ru
From: david.laight.linux@gmail.com (David Laight)
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 10:41:00 +0000
Organization: Usenet Network
Message-ID: <20261127104100.3c915088@pumpkin>
References: <20261124130631.1886963-1-xuanqiang.luo@linux.dev>
<20261126102058.1fecf50f@pumpkin>
<bffee809-2992-40eb-97c7-72d919de0aed@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="710571"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ffF32Tvyv5rch60waFxQQS8jWzQ= sha256:ek6yec4NWPRBu4ax6GCvOsqIzHOLF6iVLeLzkhO9BiU=
sha1:Gaqq+GQBhFc4uOwcNu967IahCtE= sha256:e0kEhbReUvkD5qexnHAtO4PqXQjlL1iVOxDdwVpBLV8=
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 3A035125F51; Fri, 27 Nov 2026 13:41:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
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 (2048-bit key)
header.d=gmail.com
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 JreDrE_GZlMw;
Fri, 27 Nov 2026 13:41:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-372662-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id F0BEB125F4E; Fri, 27 Nov 2026 13:41:30 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 12EE439639; Fri, 27 Nov 2026 10:41:16 +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=1795776065;
b=hnaCrzL53N4Tj4M24yVqr8g8MrLHbHFb1wjFvPUbBcxvjoWggqeuRzfGpsYo2iL0lnO7
bYA6U6HEEG8tfZ4cTIDbNYcdcscm/6+VpzYMHDvQ1tEdJ1HSY/h+32O6wCgV/5LY1Jx4q
hpH1k+q3NzD2eq560w8sD5Y/vR8QlFDGm1St3UVECoLYQzKznl0IV6pf62BKcAbBDLJP0
DZRB1pLQwZSAoGMMT30jx/eT7lkP6+RndwGrAQifIoiy9E4ShhIFgUhsivKXdUuwDp/iz
FNXLmsMiNZw3ORwoVhjPDi4+ylZ4MhVKTg5zwvJ21V3scJWySSDIvsvAr47FHP/gWGA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795776065;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=46jt2PFBd8rULQ4Nt62VZapADm8oEY8BfGTGabREOUM=;
b=UajuRqLkDY3/h9v7/w7EH1UDZAKieZ6rkjFqVf64O8zrhNDY1Hi2wtOk9056kywYj6YX
O25NYnhP38stoyubf8eEWGuzDn0xQTY9/NjXjW3ok2lP7SIKwbwkodXt52GTcATpitiXb
UTLsLokzRFEFGrKe6pc5oMGIX3yPL8yt2COCDddgt5HNPyFsQuiZxK9cQtTw52LREr+b6
T5rSSMun4Ize0dxYstpTzNPnTMfwCupQfmnYreJ95xFcxPU2usEtBU7rlLAO3z6P2G5DE
HHGRZ4/PfbntQdpe/qKxeDFIKpwOOBGrLeOGqooxdX172nE218gAt5IwSXgObnouY7w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eDuPgHaR;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 8AD1E606A691;
Fri, 27 Nov 2026 10:41:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eDuPgHaR
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.44
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795776064;
b=Hvv2nMDxohlqYqvq4D/atu6FDQL2//vKeK84BjtEZ/tI3Qv3IWvLmsFfbbJLtNOJQkoG
1rt1mrimbLnoUk1HVjN2L1w/jTEDkRM+QcIrkQi1HatG3RFD9+/IqnxKlL1uXfjR7lWKW
GSzxJfNhZ+mvl7zV8qc5rPwD9AyOkpIMStMb9REh3W20b0/H8QrLr/T/YhRyUfT6cUkOn
MbFsAaXmDEKFd6qq6PMvfNS1rshurVmCqRTt5/3icf4OkzK6P/FHUd8wtLukNn8GuXZ0L
Rs486L/3rblyb3RciPf1KKQhq3B1jZw2ILAQKYs1tTM97rCjNyx+fadJvabP0sENSdg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795776064;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc:
Subject:Message-ID:In-Reply-To:References:X-Mailer:MIME-Version:
Content-Type:Content-Transfer-Encoding;
bh=46jt2PFBd8rULQ4Nt62VZapADm8oEY8BfGTGabREOUM=;
b=QPKOqW/gD19xiMH4SYR5Uc+ebOUXZr6ArlDGHDhxKY2IDCu7y5ycBSkVxfPAe5lr6K1w
bE+MyP8o1rvkOQFywyvy/3KviIVqxR7biC0BDAW6qrSgZOfHucBjGZ/XkmfPJC85KVVwN
r3sy2POUtnIKmXqJtt/ayv1+IfASgyaUqDCA3l9Z7QPGw21QO20op4tBmpYcwQB4KJ7zC
5riv6jn7mll2uF5femUxN2eIlznarhCWVZGQfbgtbz/THuhmKDJox777uewpnzBZDiN0M
9MIv/PTx3CqdEJn412PjagH872xU1dubSClGkQj2RT5XneQ5X7DNFKnria87mToqJlg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eDuPgHaR;
arc=none smtp.remote-ip=209.85.221.44
X-Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44])
(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 5DB08606A6AA
for <netdev@vger.kernel.org>; Fri, 27 Nov 2026 10:41:04 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5DB08606A6AA
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-4a3e706b5dfso4994333f8f.2
for <netdev@vger.kernel.org>; Fri, 27 Nov 2026 02:41:04 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1795776063; x=1796380863; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=46jt2PFBd8rULQ4Nt62VZapADm8oEY8BfGTGabREOUM=;
b=eDuPgHaRC2KPGtaz+A22NSuvwSL5c0S2/zFOdQyD6aCjOhVgcuVtQjzSvQec+NBskO
GFILsA7kxm2ho56P/w+E23h/xEs5Bem7Wa9d4t0P1GDu20HTExFjtSOd1tJGxqBAFBaO
d3L+OTKO/C+IgE/s+bt2WgS1WLbycp27c+LeGecVVa44T/RJWT0vWgzhEgwHJS1d562p
DGdJBkklROvvU8d8szblYMFAHpd/Wl1fSOK+1NkwhzPYY7haLhZraKOtRm5ar0keWauF
k6LnC66mvpVU018A014jCvDM4f8SusXUeDf/IQwGlUpr/Oh9R/TlCUeFQdOt6gadcfak
q22w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795776063; x=1796380863;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=46jt2PFBd8rULQ4Nt62VZapADm8oEY8BfGTGabREOUM=;
b=K4Jouu1EoXi9SqRv9CS2JlGPYE4RxPfNgpsTtRPxlP0X2mG6PXZbazwxtmyNDpwFup
C2tJbFNltz5elByXkzyheGA0Zb8offO9CwaMaLa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593a:f421 with SMTP id ffacd0b85a97d-4abb73b557amr44307973f8f.47.1795776062532;
Fri, 27 Nov 2026 02:41:02 -0800 (PST)
X-Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b10b2c9sm47910577f8f.31.2026.11.27.02.41.01
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 27 Nov 2026 02:41:02 -0800 (PST)
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: <bffee809-2992-40eb-97c7-72d919de0aed@linux.dev>
X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf)
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