Skip to contentSkip to conversation

net: add missing ns_capable check for peer netns

PATCH New Maximilian Heyne 2 participants 2 messages Jun 17 – Jun 18

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: add missing ns_capable check for peer netns

The upstream commit 7b735ef81286 ("rtnetlink: add missing netlink_ns_capable() check for peer netns") doesn't apply on older stable kernels due to refactoring. Therefore, this patch is an attempt to implement the same capability check just directly in the respective interface types.

Approximate the netlink_ns_capable check with an ns_capable check. As the newlink operation is synchronous this should result in the same behavior.

Without this commit, for example, the following command creating a veth device in network namespace of pid 1 succeeds:

$ unshare -U -r -n -- bash -c '
  ip link add veth0 type veth peer name foobar netns 1
  sleep 60' &
$ ip link show foobar
13: foobar@if2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 96:09:69:92:92:cc brd ff:ff:ff:ff:ff:ff link-netnsid 1

With this patch, it's returning -EPERM.

This fixes CVE-2026-31692

Fixes 81adee47dfb6 ("net: Support specifying the network namespace upon device creation.")
Assisted-by Kiro:claude
---
 drivers/net/can/vxcan.c | 5 +++++
 drivers/net/veth.c      | 5 +++++
 2 files changed, 10 insertions(+)
drivers/net/can/vxcan.c +5 -0
index 1bfede407270d..05fcbfacc3433 100644
@@ -198,6 +198,11 @@ static int vxcan_newlink(struct net *net, struct net_device *dev,
 	if (IS_ERR(peer_net))
 		return PTR_ERR(peer_net);
 
+	if (!ns_capable(peer_net->user_ns, CAP_NET_ADMIN)) {
+		put_net(peer_net);
+		return -EPERM;
+	}
+
 	peer = rtnl_create_link(peer_net, ifname, name_assign_type,
 				&vxcan_link_ops, tbp, extack);
 	if (IS_ERR(peer)) {
drivers/net/veth.c +5 -0
index 743716ebebdb9..bda3add65c76e 100644
@@ -1341,6 +1341,11 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
 	if (IS_ERR(net))
 		return PTR_ERR(net);
 
+	if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) {
+		put_net(net);
+		return -EPERM;
+	}
+
 	peer = rtnl_create_link(net, ifname, name_assign_type,
 				&veth_link_ops, tbp, extack);
 	if (IS_ERR(peer)) {
Signature · 12 lines
2.50.1




Amazon Web Services Development Center Germany GmbH
Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] The use of `ns_capable()` instead of `netlink_ns_capable()` introduces a Confused Deputy…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] The use of ns_capable() instead of netlink_ns_capable() introduces a Confused Deputy vulnerability, leading to an incomplete CVE fix. --

commit d08a46769cbdf6769103f5b2c4165c49f427aec5
Author: Maximilian Heyne <[email protected]>

net: add missing ns_capable check for peer netns

This commit attempts to fix CVE-2026-31692 on older stable kernels by adding an ns_capable check directly to interface types like veth and vxcan. It is intended to approximate the upstream netlink_ns_capable check.

drivers/net/can/vxcan.c static int vxcan_newlink(struct net *net, struct net_device *dev, · line 201

Quoted 8 lines
drivers/net/can/vxcan.c +1 -0
@@ -198,6 +198,11 @@ static int vxcan_newlink(struct net *net, struct net_device *dev,
 	if (IS_ERR(peer_net))
 		return PTR_ERR(peer_net);
 
+	if (!ns_capable(peer_net->user_ns, CAP_NET_ADMIN)) {
        ^^^^^^^^^^

[Severity: Critical]
Does using ns_capable() instead of netlink_ns_capable() leave open a confused deputy vulnerability?

Since ns_capable() only evaluates the credentials of the current executing task, an unprivileged user might be able to open a netlink socket, prepare a malicious RTM_NEWLINK payload, and pass the socket file descriptor to a privileged process.

If the privileged process writes to the socket, ns_capable() will check the privileged current task instead of the netlink socket creator's credentials and incorrectly allow the operation.

Quoted 7 lines
drivers/net/can/vxcan.c +4 -0
+		put_net(peer_net);
+		return -EPERM;
+	}
+
 	peer = rtnl_create_link(peer_net, ifname, name_assign_type,
 				&vxcan_link_ops, tbp, extack);
 	if (IS_ERR(peer)) {

[ ... ]

drivers/net/veth.c static int veth_newlink(struct net *src_net, struct net_device *dev, · line 1344

Quoted 8 lines
drivers/net/veth.c +1 -0
@@ -1341,6 +1341,11 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
 	if (IS_ERR(net))
 		return PTR_ERR(net);
 
+	if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) {
        ^^^^^^^^^^

[Severity: Critical]
Is it possible this check suffers from the same confused deputy issue as the one in vxcan_newlink(), where it evaluates the current task instead of the socket creator?

Quoted 7 lines
drivers/net/veth.c +4 -0
+		put_net(net);
+		return -EPERM;
+	}
+
 	peer = rtnl_create_link(net, ifname, name_assign_type,
 				&veth_link_ops, tbp, extack);
 	if (IS_ERR(peer)) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260617-thaws-enid-af4ad67d@mheyne-amazon?part=1