Article View: linux.kernel.netdev
Article #14191Re: [PATCH net-next v2] ip6_gre: fix changelink conflict checks for L2 tunnels
From: Jakub Kicinski
Date: Tue, 10 Nov 2026 20:58
Date: Tue, 10 Nov 2026 20:58
177 lines
13971 bytes
13971 bytes
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
ip6_gre: fix changelink conflict checks for L2 tunnels
This commit changes ip6gre_changelink_common() to use ip6gre_tunnel_find()
with dev->type instead of ip6gre_tunnel_locate(). That way, L2 tunnels are
checked against tunnels of their own type. It also makes
ip6gre_tunnel_find() skip collect_md entries while walking the bucket.
> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index b5d6ed8f0c369..07f7220df938f 100644
> --- a/net/ipv6/ip6_gre.c
> +++ b/net/ipv6/ip6_gre.c
> @@ -306,6 +306,9 @@ static struct ip6_tnl *ip6gre_tunnel_find(struct net *net,
> head = __ip6gre_bucket(ign, parms);
>
> hlist_for_each_entry(t, head, hash_node) {
> + if (t->parms.collect_md)
> + continue;
> +
[Severity: Medium]
Could skipping collect_md entries here reopen the misdelivery this commit
is meant to close, in the case where the other tunnel is collect_md?
ip6gre_tunnel_link() still links collect_md tunnels into the hash buckets
with hlist_add_head_rcu(). The receive walk in ip6gre_tunnel_lookup()
never checks collect_md:
head = &ign->tunnels_wc[h1];
hlist_for_each_entry_rcu(t, head, hash_node) {
if (t->parms.i_key != key ||
!(t->dev->flags & IFF_UP))
continue;
if (ip6gre_tunnel_match(t, dev_type, link, &cand_score, &cand))
return cand;
}
When two entries score the same, the first one in the bucket wins. That
is normally the one linked most recently.
For example:
ip link add md0 type ip6gretap external
ip link add tap1 type ip6gretap
Before this patch, the second command failed with EEXIST because
ip6gre_tunnel_find(..., ARPHRD_ETHER) matched md0. Changing an existing
ordinary ip6gretap to zero params with changelink was rejected too,
because locate matched ip6gre0.
With this patch both succeed. tap1 ends up at the head of tunnels_wc[0]
and takes the keyless traffic md0 used to get, without the metadata dst.
The same looks possible for ip6erspan. It also looks possible for L3
ip6gre collect_md tunnels with explicit params, through
SIOCADDTUNNEL/SIOCCHGTUNNEL and ip6gre_tunnel_locate().
The commit message says:
Skip collect_md entries while walking the bucket: they can coexist with
ordinary tunnels with the same lookup parameters
That holds for the per-net collect_md_tun pointers. Does it also hold for
the receive demux in ip6gre_tunnel_lookup()?
Before this patch, that coexistence could only happen if the ordinary
tunnel was created first.
[Severity: Medium]
The subject and message describe a change to changelink only:
ip6_gre: fix changelink conflict checks for L2 tunnels
...
Use ip6gre_tunnel_find() with dev->type, as the newlink paths do.
The skip is in the shared helper, though. Doesn't it also change
ip6gre_newlink(), ip6erspan_newlink(), and every legacy ioctl that goes
through ip6gre_tunnel_locate()?
These are some differences users can see:
- newlink of an ordinary tunnel whose laddr/raddr/i_key/link/type match an
existing collect_md tunnel used to fail with -EEXIST. It now succeeds.
- SIOCADDTUNNEL with params that match a collect_md ip6gre device used to
return -ENOBUFS through this code in ip6gre_tunnel_locate():
t = ip6gre_tunnel_find(net, parms, ARPHRD_IP6GRE);
if (t && create)
return NULL;
It now registers a new ip6gre%d device.
- SIOCDELTUNNEL on the fallback device with params that match a
collect_md device used to delete that device. It now returns -ENOENT,
or -EPERM for zero params, because the lookup finds ip6gre0 itself.
- SIOCGETTUNNEL on the fallback device used to return the collect_md
tunnel's parms. It now returns the fallback device's own parms.
This also differs from ip_tunnel_find() in net/ipv4/ip_tunnel.c, which
does not skip collect_md entries.
If only changelink should ignore collect_md entries, could the skip go at
that call site, or behind a parameter? If not, could the commit message
describe the newlink and ioctl changes?
[ ... ]
> @@ -2055,7 +2058,7 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
>
> ip6gre_netlink_parms(data, p_p);
>
> - t = ip6gre_tunnel_locate(net, p_p, 0);
> + t = ip6gre_tunnel_find(net, p_p, dev->type);
>
> if (t) {
> if (t->dev != dev)
[Severity: High]
Can this return -EEXIST when a collect_md device changes its own
parameters?
ip6gre_tunnel_find() now skips every collect_md entry. A collect_md
device therefore no longer matches its own hash entry, and the walk moves
on to the next entries.
In every netns, the fallback ip6gre0 sits in tunnels_wc[0] with all-zero
parms and dev->type set to ARPHRD_IP6GRE:
net/ipv6/ip6_gre.c:ip6gre_init_net() {
...
t = netdev_priv(ign->fb_tunnel_dev);
hlist_add_head_rcu(&t->hash_node, &ign->tunnels_wc[0]);
...
}
ip6gre_newlink() never calls ip6gre_tunnel_find() for collect_md devices:
if (nt->parms.collect_md) {
if (rtnl_dereference(ign->collect_md_tun))
err = -EEXIST;
} else {
if (ip6gre_tunnel_find(net, &nt->parms, dev->type))
err = -EEXIST;
}
So "ip link add md0 type ip6gre external" creates md0 with zero params
and links it into tunnels_wc[0] ahead of ip6gre0. A later
"ip link set md0 type ip6gre external ..." then goes:
ip6gre_changelink()
ip6gre_changelink_common()
ip6gre_tunnel_find(net, p_p, ARPHRD_IP6GRE)
skips md0, matches ip6gre0
t->dev != dev -> ERR_PTR(-EEXIST)
Before this patch, ip6gre_tunnel_locate() found md0 first, so
t->dev == dev and the update succeeded.
SIOCCHGTUNNEL on md0 looks affected the same way. In
ip6gre_tunnel_siocdevprivate(), ip6gre_tunnel_locate(net, &p1, 0) now
returns the fallback tunnel, and the t->dev != dev branch sets -EEXIST.
The L2 kinds can hit this too, when a collect_md ip6gretap or ip6erspan
device shares lookup params with an ordinary L2 tunnel. newlink allows
that.
Would it work to skip the ordinary duplicate search when
nt->parms.collect_md is set, as newlink does? Another option is to accept
a match on the device's own entry.
--
pw-bot: cr
Technical Details
Message-ID:
<20261110205838.2246603-1-kuba@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360615-linux-kernel-netdev=dewy.ruReferences:
<20261104150330.70963-1-yanxia@cmss.chinamobile.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360615-linux-kernel-netdev=dewy.ru From: kuba@kernel.org (Jakub Kicinski) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v2] ip6_gre: fix changelink conflict checks for L2 tunnels Date: Tue, 10 Nov 2026 12:58:38 -0800 Organization: Usenet Network Message-ID: <20261110205838.2246603-1-kuba@kernel.org> References: <20261104150330.70963-1-yanxia@cmss.chinamobile.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="702068"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:1xn4qxtC0xCfRsLTR+VWCwHv4FA= sha256:izYxK5Au3U1XNu/cXVi+9DnFqflbH6QIYOpGqnqWt50= sha1:yPsG68ut06+CL516pgUK7kRW/J8= sha256:vlU1ylP4XaswhMIShw/N5QVpj0F1bd8TJD+9+u7I2pM= 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 8BB47113CF8; Wed, 11 Nov 2026 00:00:49 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 3arT5O9l-G2d; Wed, 11 Nov 2026 00:00:46 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-360615-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 C06B7113D33; Wed, 11 Nov 2026 00:00:37 +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 55F6C3FFD9; Tue, 10 Nov 2026 20:58:50 +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=1794344328; b=M7tSEnZC3th7mguR6th/YDSjAyr+NoIGROyq5Rzl9SL58Id+DhM1XN5pRANnz7kQvSdx tBY6suIXHbZxUw6qMQ1WC58T4rpYqy2o145aTPB/4ugU1MaZbtB9iUPECa8FX5osOxu6F +46IHwrDNj2qDAGTEu9I/qKetb6CdTkPFcPO2idzdr9WuKvJvPJpbEc9ClSi7ycHAV/D7 ANwQ5uM1QXSFVwdzEUKH+hLFlU7p7ZH86B91FWDMIt1xvyM2aZE+i46y9aAtBL0CZXxI4 FzvH922mltttVn9BzOdfaC6wpvWrRWdV9GSsXJIbgyMi9AqT69dpsa7n7Vkk5MUEfFQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794344328; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding; bh=ab1Y4a2opdPjndxb5YBYW98/QiDJ0m0oBjPEITs6l+E=; b=yKGbvVkeT45IkAVxIqJuq3cj6FWywOC7t86OhDRsah2LU39m4KhfV4IdphhxsZRjykQT XqaDbQtvxUin3t3K5/Ob20E2bIydCG1B3dqE0B/LZY5JY5cPTvmNGc8O1Zh9LEQWEk93J 7WRokYUL6cYgFRWZuWD71oTle2D9e1JFCQ7y3gR7CoqEUqTGZAONN0wb8vjKfjxv9mt4w 9gAHJF8VV3FKhCCajznUBnOZpQLZJofqwOeaOiK5bkv8uPrBVnxyj6WpmqzHznCi8xKpX UtIeXEyHZ8CEO66H0H9k+xdpHZJvhnaBJeQa3I3wchV13rP9b3N3VzNTtOhc3WZWYLw== 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=D1+s5ZC9; 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 04CB2606A32A; Tue, 10 Nov 2026 20:58:48 +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=D1+s5ZC9 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=1794344322; b=zdkTGu9pcWE7K5EhqQWHPXzUc3gSAh2TIv9wcQXNndj1c4KKcDQ5JPlYRPYplMG7ZcT1 qwfoWTjFA7NZ+Zve6u/4BUI+w9kkVJagrs2SwLE7CKDqxhki2apqU+OB8dIN7PmiwWZk+ 8NUZS4C5jRC0FVDVU31V/OtmNT1WFyhflTZ/TrHu2sGw33oTZ8qMjds1dqCEfydx/5OzL +IQ6YwI0vPqv/YLNH3JkPQZRLSDH7+zNFNkHZyp9jo2rC9NHnpYGZCb1pmFh8ueFGkgH5 VJB1gwvY/XPPrqVZBz069l29RY50jyFt+LuLqoLmezn4HJ5Ip6l14p8tNX37juGxrgw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794344322; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ab1Y4a2opdPjndxb5YBYW98/QiDJ0m0oBjPEITs6l+E=; b=ljUWyIpi4WSalZ76kvjy5JuKKCAFUwQIA0zkXM2jeaubRHD8GTj6s4VgaUzWkDtlqhVe 2euX3fQClkk3UB8bBeok07dbimiDZ4BuvQNYHroMI8CqswGZmQH6FWCHnmtJCm0BEArog vA66Nbi8KJJBSV38wAJ3AFIc9V4YKKUMkvvzDWQRCzEAy0PfcaFZcLcdqFb+5WpbiF1Dq OBXkYbf9A8QSEauzMd4rak+bLKrQcY3jb1EuggKLg5U3W/yYp1u0JA4v0hdUQDX5HVkvT 9DiIKlnokCFFkO1ylP1kJyDr6qQ17PV6Gj+7MNWakZozjXyCB7Jtk2NVo3aiU12odsw== 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=D1+s5ZC9; 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 AEF7A606A32E; Tue, 10 Nov 2026 20:58:41 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D88A31F0089F; Tue, 10 Nov 2026 20:58:40 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794344321; bh=ab1Y4a2opdPjndxb5YBYW98/QiDJ0m0oBjPEITs6l+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=D1+s5ZC9NaCe/pXn8/7c8nfH560r5x6nbafR5BAbOh5MxKbPeY4ZNopGSNnaKhUUl VrxX4Jx3PS/6ICacp+7wf+T7g/r78U5oiDMxJ+2e/TFRPOO5JctOKnZBkdy5uebWE0 UXT8GoiGsd1q/NKQpjh3hDmsU1DZGAy/yfR2x4RRMF84LQZKut9WvVRAcLtIfCvMPJ hwHIzAC/DzFFD4cs94VDUlYwN09iksM7LI+mXvkJJHSyBQbHnap7ByyuIFuLWDB4Rc Jr6BTSvxFmJ0rAaOBHfOOxfN2tZVUs+4W+inKTcVZJr2BYe2pcwCmfKPvCbOjp1Kvg uAgQX7yytUrQQ== X-Cc: Jakub Kicinski <kuba@kernel.org>, netdev@vger.kernel.org, dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-kernel@vger.kernel.org, kuniyu@google.com, xeb@mail.ru, yana06070@163.com, netdev-bot+sashiko@kernel.org X-Mailer: git-send-email 2.56.0 X-In-Reply-To: <20261104150330.70963-1-yanxia@cmss.chinamobile.com> 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