From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63DCF46EF9C; Tue, 21 Jul 2026 20:11:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784664689; cv=none; b=H7bBOFBE6O1Nj8f2/Q68iK/S1CQQrgKfMmz3t8DNdn6BEFzOgsKzW+2GLHcjLA5H4W8pUEG5Nfkdz0744RU8eL+3lPFoqvbzTYMkcS6TxFgZzqteVzdJs0YmdJUT78BxwpDB4ZaBQVfDuARKUWUmdsDb1ZtBrWr3arkA9zeiXlU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784664689; c=relaxed/simple; bh=4GpvGS3LXlzTUPRnQ94+KgVWdOB8Y3qCgwrjfMqROLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B6DHeiol+5rOFimt4q1UnyxL4A2ayQUCpzdA3OI8pu7L5m8QDRKh5xLK4EyvXN/87ECoZtvWBzuNOmdopaMUR0kTXbKR+5k/+hNmWUgaArv15L821op/6AIgn7EmRpnP0/0t8JkVjKkSshQX4GkmPJCuRnVbpCQap1K/4hKxXrw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jfxQ7HIM; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jfxQ7HIM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C281F1F00A3A; Tue, 21 Jul 2026 20:11:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784664688; bh=chKB0RenNI+xz79lMD05zMGk7wrqp6vCepAy0M6rJTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jfxQ7HIMZaVKMPwryaDUjxlmYE9da9YfyPdp1dwWW11Iu+QBOUsPCtJrPIJYqynZZ QczAQPHpuYo0+TO8HLhq5t558NifAeateBobkM2M9S2cvtYX0bgf5wzjZ13mBpySPS 55wCR1zfWpDlWqODdAtgVXmGX+H6Ob+GjxwCiw9k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xiao Liang , Maoyi Xie , Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0022/1266] net: ip_gre: require CAP_NET_ADMIN in the device netns for changelink Date: Tue, 21 Jul 2026 17:07:39 +0200 Message-ID: <20260721152442.284717718@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maoyi Xie [ Upstream commit 8165f7ff57d9667d2bb477ef6af83ede7fed4ad7 ] A tunnel changelink() operates on at most two netns, dev_net(dev) and the tunnel link netns t->net. They differ once the device is created in or moved to a netns other than the one the request runs in. The rtnl changelink path checks CAP_NET_ADMIN only against dev_net(dev), so a caller privileged there but not in t->net can rewrite a tunnel that lives in t->net. Add rtnl_dev_link_net_capable() next to rtnl_get_net_ns_capable() in net/core/rtnetlink.c. It requires CAP_NET_ADMIN in the link netns and is skipped when the link netns is dev_net(dev), where the rtnl path already checked it. The other patches in this series use the same helper. Gate ipgre_changelink() and erspan_changelink() with it, at the top of the op before any attribute is parsed, because the parsers update live tunnel fields first. ipgre_netlink_parms() sets t->collect_md before ip_tunnel_changelink() runs. Commit 8b484efd5cb4 ("ip6: vti: Use ip6_tnl.net in vti6_siocdevprivate().") added the same check on the ioctl path. This adds it on RTM_NEWLINK. Reported-by: Xiao Liang Closes: https://lore.kernel.org/netdev/CABAhCOSzP1vaThGV35_VnsRCb=87_CPjPVsTHbq905k8A+BuUg@mail.gmail.com/ Fixes: b57708add314 ("gre: add x-netns support") Cc: stable@vger.kernel.org Signed-off-by: Maoyi Xie Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260612085941.3158249-2-maoyixie.tju@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/net/rtnetlink.h | 2 ++ net/core/rtnetlink.c | 8 ++++++++ net/ipv4/ip_gre.c | 6 ++++++ 3 files changed, 16 insertions(+) --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -211,6 +211,8 @@ int rtnl_configure_link(struct net_devic int rtnl_nla_parse_ifinfomsg(struct nlattr **tb, const struct nlattr *nla_peer, struct netlink_ext_ack *exterr); struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid); +bool rtnl_dev_link_net_capable(const struct net_device *dev, + const struct net *link_net); #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind) --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2157,6 +2157,14 @@ struct net *rtnl_get_net_ns_capable(stru } EXPORT_SYMBOL_GPL(rtnl_get_net_ns_capable); +bool rtnl_dev_link_net_capable(const struct net_device *dev, + const struct net *link_net) +{ + return net_eq(link_net, dev_net(dev)) || + ns_capable(link_net->user_ns, CAP_NET_ADMIN); +} +EXPORT_SYMBOL_GPL(rtnl_dev_link_net_capable); + static int rtnl_valid_dump_ifinfo_req(const struct nlmsghdr *nlh, bool strict_check, struct nlattr **tb, struct netlink_ext_ack *extack) --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1412,6 +1412,9 @@ static int ipgre_changelink(struct net_d struct ip_tunnel_parm p; int err; + if (!rtnl_dev_link_net_capable(dev, t->net)) + return -EPERM; + err = ipgre_newlink_encap_setup(dev, data); if (err) return err; @@ -1441,6 +1444,9 @@ static int erspan_changelink(struct net_ struct ip_tunnel_parm p; int err; + if (!rtnl_dev_link_net_capable(dev, t->net)) + return -EPERM; + err = ipgre_newlink_encap_setup(dev, data); if (err) return err;