From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 585AB1F000CE; Fri, 4 Dec 2026 08:22:18 +0000 (UTC) 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== Subject: Re: [PATCH net v5] net: fix stale header length after erspan version change From: netdev-bot+sashiko@kernel.org To: bsdhenrymartin@gmail.com 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 Date: Fri, 04 Dec 2026 08:22:17 +0000 Message-ID: <179637253789.3146.1618090681122841030@kernel.org> In-Reply-To: <20261203072423.147308-1-bsdhenrymartin@gmail.com> References: <20261203072423.147308-1-bsdhenrymartin@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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