All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: khorenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1] net/ip6_gre: fix a host panic adding ip6gre in a CT without ipgre
Date: Wed,  4 Nov 2026 21:07:55 +0100	[thread overview]
Message-ID: <20261104200755.1956316-1-den@openvz.org> (raw)

From: Denis V. Lunev <den@openvz.org>

ip6gre_init_net() frees the ip6gre_net of a netns whose VE lacks
VE_FEATURE_IPGRE, and ip6gre_newlink_common() refuses such a netns with
-EACCES. ip6gre_newlink() and ip6erspan_newlink() reach the NULL
ip6gre_net first, through ip6gre_tunnel_find() or collect_md_tun, so
"ip link add type ip6gre" by root in an ordinary container panics the
node once ip6_gre is loaded:

  BUG: kernel NULL pointer dereference, address: 0000000000000320
  RIP: 0010:ip6gre_tunnel_find+0x46/0xd0 [ip6_gre]
   ip6gre_newlink+0x9b/0x120 [ip6_gre]

The check went into ip6gre_newlink_common(), which ran the tunnel lookup
until upstream commit b80d0b93b991 ("net: ip6_gre: fix tunnel metadata
device sharing.") moved the lookup into the newlink handlers. Move the
check to the top of both handlers. They are the only callers of
ip6gre_newlink_common() and serve as newlink for all three link types
(ip6gre, ip6gretap and ip6erspan), and nothing else in the helper uses
ip6gre_net.

Fixes: 46c13c45f25a ("net/gre: Consider VE_FEATURE_IPGRE on new net creation")

https://virtuozzo.atlassian.net/browse/VSTOR-149645
Feature: ve: per-CT features management
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
 net/ipv6/ip6_gre.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 9060cb17bf25..4a0fc86d9a10 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -2003,15 +2003,6 @@ static int ip6gre_newlink_common(struct net *src_net, struct net_device *dev,
 	struct ip6_tnl *nt;
 	struct ip_tunnel_encap ipencap;
 	int err;
-#ifdef CONFIG_VE
-	struct net *net = dev_net(dev);
-	struct ip6gre_net *ign;
-
-	ign = net_generic(net, ip6gre_net_id);
-
-	if (!ign) /* no VE_FEATURE_IPGRE */
-		return -EACCES;
-#endif
 
 	nt = netdev_priv(dev);
 
@@ -2048,8 +2039,13 @@ static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
 	struct ip6gre_net *ign;
 	int err;
 
-	ip6gre_netlink_parms(data, &nt->parms);
 	ign = net_generic(net, ip6gre_net_id);
+#ifdef CONFIG_VE
+	if (!ign) /* no VE_FEATURE_IPGRE */
+		return -EACCES;
+#endif
+
+	ip6gre_netlink_parms(data, &nt->parms);
 
 	if (nt->parms.collect_md) {
 		if (rtnl_dereference(ign->collect_md_tun))
@@ -2284,9 +2280,14 @@ static int ip6erspan_newlink(struct net *src_net, struct net_device *dev,
 	struct ip6gre_net *ign;
 	int err;
 
+	ign = net_generic(net, ip6gre_net_id);
+#ifdef CONFIG_VE
+	if (!ign) /* no VE_FEATURE_IPGRE */
+		return -EACCES;
+#endif
+
 	ip6gre_netlink_parms(data, &nt->parms);
 	ip6erspan_set_version(data, &nt->parms);
-	ign = net_generic(net, ip6gre_net_id);
 
 	if (nt->parms.collect_md) {
 		if (rtnl_dereference(ign->collect_md_tun_erspan))
-- 
2.53.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

             reply	other threads:[~2026-11-04 20:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 20:07 Denis V. Lunev [this message]
2026-11-04 20:31 ` no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261104200755.1956316-1-den@openvz.org \
    --to=den@openvz.org \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.