net: require CAP_NET_ADMIN in the device netns for tunnel changelink
Subsystems (5)
v6 cover net: require CAP_NET_ADMIN in the device netns for tunnel changelink
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 the link netns can rewrite a tunnel that lives in the link netns. Commit 8b484efd5cb4 ("ip6: vti: Use ip6_tnl.net in vti6_siocdevprivate().") added the same check on the ioctl path. This series adds it on the RTM_NEWLINK path.
Each changelink is gated at the top of the op, before any attribute is parsed, because the per-type parsers can update live tunnel fields first (for example ipgre_netlink_parms() sets t->collect_md). The check is skipped when the link netns is dev_net(dev), where the rtnl path already checked the cap.
The check goes through a new helper, rtnl_dev_link_net_capable(), added in patch 1 next to rtnl_get_net_ns_capable() in net/core/rtnetlink.c.
Tested on net/main. For every tunnel type in the series a migrated fake-root changelink is rejected with EPERM. For vti6 SIOCGETTUNNEL confirms the link netns hash is left unchanged. Legit non-migrated changelinks still succeed.
v5 -> v6, addressing Kuniyuki Iwashima's review:
- Correct the Fixes: tags to the commits that first added x-netns support / namespace changing for each tunnel type, where the cap gap has existed, instead of the later "fix namespaces move" commits.
- Add Kuniyuki Iwashima's Reviewed-by to all patches.
v5: https://lore.kernel.org/netdev/[email protected]/
v4: https://lore.kernel.org/netdev/[email protected]/
v3: https://lore.kernel.org/netdev/[email protected]/
v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/
Maoyi Xie (7):
net: ip_gre: require CAP_NET_ADMIN in the device netns for changelink
net: ipip: require CAP_NET_ADMIN in the device netns for changelink
net: ip_vti: require CAP_NET_ADMIN in the device netns for changelink
net: ip6_tunnel: require CAP_NET_ADMIN in the device netns for
changelink
net: ip6_gre: require CAP_NET_ADMIN in the device netns for changelink
net: ip6_vti: require CAP_NET_ADMIN in the device netns for changelink
xfrm: xfrm_interface: require CAP_NET_ADMIN in the device netns for
changelink
include/net/rtnetlink.h | 2 ++ net/core/rtnetlink.c | 8 ++++++++ net/ipv4/ip_gre.c | 6 ++++++ net/ipv4/ip_vti.c | 3 +++ net/ipv4/ipip.c | 3 +++ net/ipv6/ip6_gre.c | 6 ++++++ net/ipv6/ip6_tunnel.c | 3 +++ net/ipv6/ip6_vti.c | 3 +++ net/xfrm/xfrm_interface_core.c | 3 +++ 9 files changed, 37 insertions(+)
base-commit: 512db8267b73a220a64180d95ab5eebe7c4964a8
Signature · 1 line
2.34.1
PATCH v6 1/7 net: ip_gre: require CAP_NET_ADMIN in the device netns for changelink
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.
--- include/net/rtnetlink.h | 2 ++ net/core/rtnetlink.c | 8 ++++++++ net/ipv4/ip_gre.c | 6 ++++++ 3 files changed, 16 insertions(+)
include/net/rtnetlink.h +2 -0
@@ -256,6 +256,8 @@ int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm,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)
net/core/rtnetlink.c +8 -0
@@ -2421,6 +2421,14 @@ struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid) }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)
net/ipv4/ip_gre.c +6 -0
@@ -1457,6 +1457,9 @@ static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[],__u32 fwmark = t->fwmark;int err; +if (!rtnl_dev_link_net_capable (dev, t->net)) +return -EPERM ; + err =ipgre_newlink_encap_setup (dev, data);if (err)return err;
@@ -1486,6 +1489,9 @@ static int erspan_changelink(struct net_device *dev, struct nlattr *tb[],__u32 fwmark = t->fwmark;int err; +if (!rtnl_dev_link_net_capable (dev, t->net)) +return -EPERM ; + err =ipgre_newlink_encap_setup (dev, data);if (err)return err;
Signature · 1 line
2.34.1
PATCH v6 2/7 net: ipip: require CAP_NET_ADMIN in the device netns for changelink
In reply to Maoyi Xieipip_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.
Gate ipip_changelink() on rtnl_dev_link_net_capable() at its top, before any attribute is parsed.
--- net/ipv4/ipip.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv4/ipip.c +3 -0
@@ -494,6 +494,9 @@ static int ipip_changelink(struct net_device *dev, struct nlattr *tb[],bool collect_md;__u32 fwmark = t->fwmark; +if (!rtnl_dev_link_net_capable (dev, t->net)) +return -EPERM ; +if (ip_tunnel_netlink_encap_parms (data, &ipencap)) {int err =ip_tunnel_encap_setup (t, &ipencap);
Signature · 1 line
2.34.1
PATCH v6 3/7 net: ip_vti: require CAP_NET_ADMIN in the device netns for changelink
In reply to Maoyi Xievti_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.
Gate vti_changelink() on rtnl_dev_link_net_capable() at its top, before any attribute is parsed.
--- net/ipv4/ip_vti.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv4/ip_vti.c +3 -0
@@ -596,6 +596,9 @@ static int vti_changelink(struct net_device *dev, struct nlattr *tb[],struct ip_tunnel_parm_kern p;__u32 fwmark = t->fwmark; +if (!rtnl_dev_link_net_capable (dev, t->net)) +return -EPERM ; +vti_netlink_parms (data, &p, &fwmark);return ip_tunnel_changelink (dev, tb, &p, fwmark); }
Signature · 1 line
2.34.1
PATCH v6 4/7 net: ip6_tunnel: require CAP_NET_ADMIN in the device netns for changelink
In reply to Maoyi Xieip6_tnl_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.
Gate ip6_tnl_changelink() on rtnl_dev_link_net_capable() at its top, before any attribute is parsed.
--- net/ipv6/ip6_tunnel.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/ip6_tunnel.c +3 -0
@@ -2102,6 +2102,9 @@ static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],struct ip6_tnl_net *ip6n =net_generic (net, ip6_tnl_net_id);struct ip_tunnel_encap ipencap; +if (!rtnl_dev_link_net_capable (dev, net)) +return -EPERM ; +if (dev == ip6n->fb_tnl_dev) {if (ip_tunnel_netlink_encap_parms (data, &ipencap)) {/* iproute2 always sets TUNNEL_ENCAP_FLAG_CSUM6, so
Signature · 1 line
2.34.1
PATCH v6 5/7 net: ip6_gre: require CAP_NET_ADMIN in the device netns for changelink
In reply to Maoyi Xieip6gre_changelink() and ip6erspan_changelink() operate 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.
Gate both ops on rtnl_dev_link_net_capable() at their top, before any attribute is parsed.
--- net/ipv6/ip6_gre.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/ipv6/ip6_gre.c +6 -0
@@ -2047,6 +2047,9 @@ static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],struct ip6gre_net *ign =net_generic (t->net, ip6gre_net_id);struct __ip6_tnl_parm p; +if (!rtnl_dev_link_net_capable (dev, t->net)) +return -EPERM ; + t =ip6gre_changelink_common (dev, tb, data, &p, extack);if (IS_ERR (t))return PTR_ERR (t);
@@ -2266,6 +2269,9 @@ static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],struct __ip6_tnl_parm p;struct ip6gre_net *ign; +if (!rtnl_dev_link_net_capable (dev, t->net)) +return -EPERM ; + ign =net_generic (t->net, ip6gre_net_id); t =ip6gre_changelink_common (dev, tb, data, &p, extack);if (IS_ERR (t))
Signature · 1 line
2.34.1
PATCH v6 6/7 net: ip6_vti: require CAP_NET_ADMIN in the device netns for changelink
In reply to Maoyi Xievti6_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.
Gate vti6_changelink() on rtnl_dev_link_net_capable() at its top, before any attribute is parsed.
--- net/ipv6/ip6_vti.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/ip6_vti.c +3 -0
@@ -1046,6 +1046,9 @@ static int vti6_changelink(struct net_device *dev, struct nlattr *tb[],struct __ip6_tnl_parm p;struct vti6_net *ip6n; +if (!rtnl_dev_link_net_capable (dev, net)) +return -EPERM ; + ip6n =net_generic (net, vti6_net_id);if (dev == ip6n->fb_tnl_dev)return -EINVAL ;
Signature · 1 line
2.34.1
PATCH v6 7/7 xfrm: xfrm_interface: require CAP_NET_ADMIN in the device netns for changelink
In reply to Maoyi Xiexfrmi_changelink() operates on at most two netns, dev_net(dev) and the interface link netns xi->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 xi->net can rewrite an interface that lives in xi->net.
Gate xfrmi_changelink() on rtnl_dev_link_net_capable() at its top, before any attribute is parsed.
--- net/xfrm/xfrm_interface_core.c | 3 +++ 1 file changed, 3 insertions(+)
net/xfrm/xfrm_interface_core.c +3 -0
@@ -869,6 +869,9 @@ static int xfrmi_changelink(struct net_device *dev, struct nlattr *tb[],struct net *net = xi->net;struct xfrm_if_parms p = {}; +if (!rtnl_dev_link_net_capable (dev, net)) +return -EPERM ; +xfrmi_netlink_parms (data, &p);if (!p.if_id) {NL_SET_ERR_MSG (extack,"if_id must be non zero" );
Signature · 1 line
2.34.1
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 12 Jun 2026 16:59:34 +0800 you wrote:
A tunnel
changelink()operates on at most two netns,dev_net(dev)and the tunnel link netnst->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 checksCAP_NET_ADMINonly againstdev_net(dev), so a caller privileged there but not in the link netns can rewrite a tunnel that lives in the link netns. Commit8b484efd5cb4("ip6: vti: Use ip6_tnl.net invti6_siocdevprivate().") added the same check on the ioctl path. This series adds it on theRTM_NEWLINKpath.[...]
Here is the summary with links:
- [net,v6,1/7] net: ip_gre: require CAP_NET_ADMIN in the device netns for changelink
https://git.kernel.org/netdev/net/c/8165f7ff57d9 - [net,v6,2/7] net: ipip: require CAP_NET_ADMIN in the device netns for changelink https://git.kernel.org/netdev/net/c/8211a2632466 - [net,v6,3/7] net: ip_vti: require CAP_NET_ADMIN in the device netns for changelink https://git.kernel.org/netdev/net/c/95cceadbfd52 - [net,v6,4/7] net: ip6_tunnel: require CAP_NET_ADMIN in the device netns for changelink https://git.kernel.org/netdev/net/c/2496fa0b7d18 - [net,v6,5/7] net: ip6_gre: require CAP_NET_ADMIN in the device netns for changelink https://git.kernel.org/netdev/net/c/f00a50876d28 - [net,v6,6/7] net: ip6_vti: require CAP_NET_ADMIN in the device netns for changelink https://git.kernel.org/netdev/net/c/e2ac3b242c37 - [net,v6,7/7] xfrm: xfrm_interface: require CAP_NET_ADMIN in the device netns for changelink https://git.kernel.org/netdev/net/c/095515d89b19
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html