Article View: linux.kernel.netdev
Article #26832Re: [PATCH net v5] net: fix stale header length after erspan version change
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 08:22
Date: Fri, 04 Dec 2026 08:22
263 lines
17524 bytes
17524 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 (1) · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] When ip_tunnel_changelink() fails, erspan_changelink()
(net/ipv4/ip_gre.c) only restores t->hlen.
- [Medium] The claim that a rejected change leaves the device unchanged
is also false for encap and ignore_df state.
- [Medium] erspan_changelink() updates erspan_ver, then tun_hlen/hlen,
then needed_headroom/mtu, then o_flags.
- [Low] The patch changes ipgre_policy[IFLA_GRE_ERSPAN_VER] from NLA_U8
to NLA_POLICY_MAX(NLA_U8, 2).
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but for
erspan_ver == 0 erspan_calc_hlen() hardcodes tun_hlen = 4, and…
--
net: fix stale header length after erspan version change
This patch recomputes the ERSPAN GRE header lengths in erspan_changelink()
when the version changes, and adjusts needed_headroom and mtu to match. It
also tries to roll back tunnel state when a change is rejected. In addition,
it forces the GRE sequence flag for v1/v2 in erspan_xmit() and limits
IFLA_GRE_ERSPAN_VER to 0..2 in ipgre_policy.
Link: https://lore.kernel.org/netdev/20261123062752.27920-1-yanhaishuang@cmss.chinamobile.com/
Link: https://lore.kernel.org/netdev/20261124014646.7954-1-yanhaishuang@cmss.chinamobile.com/
> diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
> index 5485586fa0e62..4d7b43b1a0f97 100644
> --- a/net/ipv4/ip_gre.c
> +++ b/net/ipv4/ip_gre.c
> @@ -749,6 +749,9 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
> }
>
> __clear_bit(IP_TUNNEL_KEY_BIT, flags);
> + /* v1/v2 always emit an 8-byte GRE header with a sequence word. */
> + if (tunnel->erspan_ver)
> + __set_bit(IP_TUNNEL_SEQ_BIT, flags);
[Severity: Medium]
Can a concurrent transmit still send 4 bytes of uninitialized headroom
while the version is being changed?
erspan_xmit() and __gre_xmit() run without a lock (dev->lltx is set).
erspan_changelink() runs under RTNL. It stores erspan_ver in
erspan_netlink_parms() and only later stores tun_hlen and hlen in
erspan_calc_hlen(). For a v1/v2 to v0 switch:
CPU0 (changelink) CPU1 (erspan_xmit)
erspan_netlink_parms()
t->erspan_ver = 0;
tunnel->erspan_ver == 0
clears SEQ and KEY
__gre_xmit()
gre_build_header(skb,
tunnel->tun_hlen /* still 8 */, ...)
erspan_calc_hlen()
tunnel->tun_hlen = 4;
gre_build_header() pushes 8 bytes but writes only the first 4. That looks
like the leak described in the commit message, just limited to a race
window.
The new check also reads tunnel->erspan_ver a second time. So one packet
can pick its ERSPAN header from one value, its SEQ decision from another,
and tun_hlen from a third read in __gre_xmit().
With tun_hlen 4 and SEQ set, wouldn't gre_build_header() write the
sequence number over the GRE base header?
Could erspan_xmit() read erspan_ver once with READ_ONCE() and use that
copy for the rest of the packet? The stores in erspan_calc_hlen() and in
the rollback path are plain stores. ip_tunnel_encap_setup() uses
WRITE_ONCE() for the same t->hlen.
> __gre_xmit(skb, dev, &tunnel->parms.iph, proto, flags);
> return NETDEV_TX_OK;
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. The new
SEQ forcing covers only v1/v2, and the v0 path still lets GRE_CSUM through.
erspan_validate() returns early for version 0:
if (data[IFLA_GRE_ERSPAN_VER] &&
nla_get_u8(data[IFLA_GRE_ERSPAN_VER]) == 0)
return 0;
ipgre_tunnel_validate() rejects only GRE_VERSION|GRE_ROUTING. So
IFLA_GRE_OFLAGS=GRE_CSUM is accepted on a v0 tunnel. For v0, erspan_xmit()
clears only SEQ and KEY, and erspan_calc_hlen() hardcodes tun_hlen = 4.
In gre_build_header() with hdr_len 4 and CSUM set:
__be32 *ptr = (__be32 *)(((u8 *)greh) + hdr_len - 4);
...
if (test_bit(IP_TUNNEL_CSUM_BIT, flags) &&
...
*ptr = 0;
Here ptr points at greh itself. Doesn't that zero the GRE flags and
protocol that were just written?
In the non CHECKSUM_PARTIAL case, csum_offset = sizeof(*greh) also points
past the 4-byte header into the inner Ethernet frame.
Should the v0 path in erspan_xmit() also clear IP_TUNNEL_CSUM_BIT, or
should erspan_validate() reject CSUM for v0?
[ ... ]
> @@ -1509,17 +1525,46 @@ static int erspan_changelink(struct net_device *dev, struct nlattr *tb[],
> return -EOPNOTSUPP;
> }
>
> + hlen = t->hlen;
> +
> err = ipgre_newlink_encap_setup(dev, data);
> if (err)
> return err;
>
> err = erspan_netlink_parms(dev, data, tb, &p, &fwmark);
> - if (err < 0)
> + if (err < 0) {
> + /* A rejected change must not touch the device. */
> + t->erspan_ver = old_ver;
> + t->index = old_index;
> + t->dir = old_dir;
> + t->hwid = old_hwid;
> + t->hlen = hlen;
> return err;
> + }
[Severity: Medium]
Is this comment accurate when the request also carries encap or
IFLA_GRE_IGNORE_DF attributes?
ipgre_newlink_encap_setup() calls ip_tunnel_encap_setup(), which has
already written to the live tunnel:
WRITE_ONCE(t->encap.type, ipencap->type);
...
WRITE_ONCE(t->encap_hlen, hlen);
WRITE_ONCE(t->hlen, hlen + t->tun_hlen);
ipgre_netlink_parms() has also set t->ignore_df. Neither change is rolled
back here.
erspan_netlink_parms() can still reject the change after that. Examples
are an IFLA_GRE_ERSPAN_INDEX outside INDEX_MASK on a v1 tunnel, or a bad
DIR/HWID on v2, and erspan_validate() checks none of these. In that case
t->hlen goes back to the value sampled before encap setup, but t->encap
and t->encap_hlen keep the new values. The ip_tunnel_changelink() failure
path below has the same problem.
Wouldn't ip_tunnel_xmit() then add the new FOU/GUE header, while t->hlen
(used by tnl_update_pmtu() and ip_tunnel_change_mtu()) does not count it?
> +
> + relink = t->parms.link != p.link || t->fwmark != fwmark;
> +
> + /*
> + * ipgre_newlink_encap_setup() reset t->hlen without the ERSPAN part.
> + * Recompute it before ip_tunnel_changelink(): ip_tunnel_bind_dev()
> + * consumes it when the link changes.
> + */
> + erspan_calc_hlen(dev);
>
> err = ip_tunnel_changelink(dev, tb, &p, fwmark);
> - if (err < 0)
> + if (err < 0) {
> + t->hlen = hlen;
> return err;
> + }
[Severity: High]
Does this error path leave the tunnel half switched to the new version?
When ip_tunnel_changelink() runs, erspan_netlink_parms() has already
written the new t->erspan_ver, t->index, t->dir and t->hwid into the live
tunnel. erspan_calc_hlen() has also set t->tun_hlen for the new version.
Only t->hlen is restored here.
ip_tunnel_changelink() can fail without touching the device:
if (dev == itn->fb_tunnel_dev)
return -EINVAL;
...
if (t) {
if (t->dev != dev) {
err = -EEXIST;
goto out;
This happens for a changelink on erspan0, or when the new
saddr/daddr/key/link collide with another tunnel. The flags and
unregistering checks can also fail.
Take a rejected v0 to v1 change. The device then sends an 8-byte GRE
header plus a 12-byte ERSPAN v1 header. Meanwhile t->hlen (4), dev->mtu
and dev->needed_headroom still describe v0. tnl_update_pmtu() and
ip_tunnel_change_mtu() read t->hlen.
Wouldn't the PMTU then be under-counted by 16 bytes?
The commit message says:
restore the old length, version, index,
direction and hwid on every error path, so a rejected change leaves the
device unchanged.
That restore only happens on the erspan_netlink_parms() error path.
Should this path also restore erspan_ver/index/dir/hwid and recompute
tun_hlen? Alternatively, could all the ERSPAN parameters be validated
before anything is written to the live tunnel?
[ ... ]
> @@ -1683,7 +1728,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
> [IFLA_GRE_IGNORE_DF] = { .type = NLA_U8 },
> [IFLA_GRE_FWMARK] = { .type = NLA_U32 },
> [IFLA_GRE_ERSPAN_INDEX] = { .type = NLA_U32 },
> - [IFLA_GRE_ERSPAN_VER] = { .type = NLA_U8 },
> + [IFLA_GRE_ERSPAN_VER] = NLA_POLICY_MAX(NLA_U8, 2),
[Severity: Low]
Is this policy change meant to apply to gre and gretap as well?
ipgre_policy is shared by ipgre_link_ops, ipgre_tap_ops and
erspan_link_ops. Neither ipgre_netlink_parms() nor ipgre_tunnel_validate()
reads IFLA_GRE_ERSPAN_VER, so gre and gretap used to ignore the attribute.
Now their newlink/changelink requests fail with -ERANGE when the value is
above 2.
For erspan devices, the errno changes from -EINVAL to -ERANGE. This check
in erspan_netlink_parms() can also no longer be reached:
if (t->erspan_ver > 2)
return -EINVAL;
ip6gre_policy in net/ipv6/ip6_gre.c still uses plain NLA_U8 for the same
attribute. The erspan-ver entry in Documentation/netlink/specs/rt-link.yaml
also has no max check.
Since this is tagged for stable, could the commit message body mention
this uAPI change? Right now it only appears in the v4 -> v5 notes after
the --- line.
> [IFLA_GRE_ERSPAN_DIR] = { .type = NLA_U8 },
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203072423.147308-1-bsdhenrymartin%40gmail.com
Technical Details
Message-ID:
<179637253789.3146.1618090681122841030@kernel.org>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377184-linux-kernel-netdev=dewy.ruReferences:
<20261203072423.147308-1-bsdhenrymartin@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377184-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v5] net: fix stale header length after erspan version change Date: Fri, 04 Dec 2026 08:22:17 +0000 Organization: Usenet Network Message-ID: <179637253789.3146.1618090681122841030@kernel.org> References: <20261203072423.147308-1-bsdhenrymartin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2715461"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:aSZWgyuSqRoqkDOdW+NpsMFt+B8= sha256:p1HYzgbfyd2RlRS7t/LdTjJPDe7MI3syfcBDVPRS5jo= sha1:ImceaDAfFel3APrs0WaO+1+VpOY= sha256:jvUuh2l2Vei99wngxWliy9QAR2qxVLeS+WuYE/+bM8Y= 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 12F2E117B67; Fri, 4 Dec 2026 11:22:38 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.639 X-Spam-Status: No, score=-3.639 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, 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, URIBL_BLOCKED=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 D0BczebRc9Gf; Fri, 4 Dec 2026 11:22:33 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377184-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id DD757117B32; Fri, 4 Dec 2026 11:22:22 +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 767722501C; Fri, 4 Dec 2026 08:22:20 +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=1796372540; b=NKyoQJrHXlgWf3KsxDq3vlAqeR+DN8PftzrEF10iqSA5UPdYRRBM+AL/kLNd8gE9NiuY cWxoQetcWEnBVOTjEiZ5kIKSXpNcyED0uIxXdONW9A33x0EDHHiKBn3jjb1QDHe+BjpL0 CSRgZjq2yep24YQu4Gx53CWRUFheqR1ZVozxBOcT63AxGYJeFcdhtdwxDh+7G33NJByWY VHuqkB/NZxGnhKmUSHoQLY3OK0+OoD/pD7GS3zzePRq7DvPrtRhB6N4DJf3OAxITWQcD5 1OLWAm8FEqt3b1kotQrRFbnzplY7mat2ZyHp8RnWvfMYenBGJLRKvgXOm38rWd3bUjg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796372540; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=FM+eiT+DngcZgpxZEKbsCjPmQCW3RsPQvSQjR5SLiSA=; b=ZdfbEc8kyn63263OrAggvEK7dzT14vB2ClnHa1JUfF66fdXgCkvuZzo3ibZNUiU0yIzd VEBGS7XqqShuMNkZxE3bHCbSah2fqJwPtYkfg/q29EYeBCZQtVNEFrJ7cH9vwm0NchMC9 c7qitzHUyhgL2ExFH9b95VEKi+UwiofM+jGGubgad78cYR0er476u6+3V5G8/JRXNVCqK iVIhTl6AzWWDL16xP3hlSZQTonWpv6B8tnH6Tn2Z6JX8K87IbZv9iPN6AbFXi9od/6hsf F3r9F3p/1WVY46HZCokaaI0JXp6EkKAjEySRITJkYPDVXNK9FA2+zXPMOC4bZ1m5WXA== 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=ZLCXp0zf; 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 381CD606A335; Fri, 4 Dec 2026 08:22:20 +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=ZLCXp0zf 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=1796372539; b=DHbBaCqJwYTmuo8YjMyS0GfBhflU4dU7Ql7saWIesxGRA4JgzrG60qDElDzx8cWPifBS XB1obnrtuosIV/q/xWXd7W2Osfz1TiY1qb3fZVRDng234XRhvnQYcL49wuTYwepMyI6pg z1BlBVQPuDN+MxOFdLpdG+y7PnMlkI0rsga8nJ/b8qhUchavdGQ1slYwY0HUkPN5ZWXJS bTSH/92t5fu2J0hBlw17pU0PjKP1Txv2n7tIs233kMAt0R3OxeJKgw5uQW9HcB9+dbMQT Po88917V3cN/z/MAe0W6HmxmVmlZkDLSUzYNdxk3dXnyKYL1yITwRn9J7Y1ClFpV/gw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796372539; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=FM+eiT+DngcZgpxZEKbsCjPmQCW3RsPQvSQjR5SLiSA=; b=adicElinNoFHH6PPslpzQY5hopHo/MCgHwG8bT1rGGYDMGT2rk0KF/2UOz9lXl9R3wzQ +OUZtsEq9CENMjwPQFYt9wdqpUv4AzAPwj0jz9FB4K47jG2iUeFlMB0J/8mXBLSlej0t1 AEOLoTxQfLcBn6Cm0/kHoya8pWz8CqD0DCWgopnkTAbyIxx5FbtutUfM3yyx1Q5malGTz +EGiP2QwescOPkag1Cd2oIH+tK2wihwd5DfUZpuDwKuySAI0tne2Qq0Q3SIx49L6xhUxr Re1O5jYifzHYkog3bRUMOx7fY66HpnmfHA3yoxKBzSbXIQUw9MOW7JkZRJlEhHwzlHw== 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=ZLCXp0zf; 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 58D8B606A322; Fri, 4 Dec 2026 08:22:19 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 585AB1F000CE; Fri, 4 Dec 2026 08:22:18 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796372538; bh=FM+eiT+DngcZgpxZEKbsCjPmQCW3RsPQvSQjR5SLiSA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=ZLCXp0zfWYgQ4iQqGE+lsmHZWA+sKSNc0hwHhvU4YtRuHB4UgnvkZ/8ecFWTWlm73 ihur4dGreP9+vhhUge0VF2at13Ux1pKli22ddxgaibhYaaKv1F3II5xPVNsE/lq/qQ Hjjof2I/lCU9T2SwMfEL1W9vuRYLg6PGHYU5+dalyT3lh6YHjsV2Lgoal4rjZvhYxq bZr1gaxJqdRTybEj4WxIcPgHJ9dPKYbem0tfcS7/voaJAGmz3icPqrhLw9fU66YF6/ RXoHVUhCKEoXNGZBgARxpZVsHdFJRuoRafFOVXJSseUcOSiV4SLDk6KPUJ1s2FSb6l 4uod23EN7/bMg== X-Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, yanhaishuang@cmss.chinamobile.com, horms@kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org X-In-Reply-To: <20261203072423.147308-1-bsdhenrymartin@gmail.com> X-sashiko-severity: High 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-Received-Bytes: 17327