Skip to contentSkip to conversation

rtnetlink: add missing netlink_ns_capable() check for peer netns

PATCH Superseded Nikolaos Gkarlis 2 participants 2 messages Mar 27

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rtnetlink: add missing netlink_ns_capable() check for peer netns

rtnl_newlink() lacks a CAP_NET_ADMIN capability check on the peer network namespace when creating paired devices (veth, vxcan, netkit). This allows an unprivileged user with a user namespace to create interfaces in arbitrary network namespaces, including init_net.

Add a netlink_ns_capable() check for CAP_NET_ADMIN in the peer namespace before allowing device creation to proceed.

Fixes 81adee47dfb6 ("net: Support specifying the network namespace upon device creation.")

---
v2:
- Removed "Reported-by" tag
- Fixed "Fixes" tag with the help of Kuniyuki Iwashima (thanks !)

 net/core/rtnetlink.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/core/rtnetlink.c +8 -1
index fae8034efbf..ee7d9d65b2c 100644
@@ -4059,8 +4059,15 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 				ret = PTR_ERR(peer_net);
 				goto put_ops;
 			}
-			if (peer_net)
+			if (peer_net) {
+				if (!netlink_ns_capable(skb, peer_net->user_ns,
+							CAP_NET_ADMIN)) {
+					put_net(peer_net);
+					ret = -EPERM;
+					goto put_ops;
+				}
 				rtnl_nets_add(&rtnl_nets, peer_net);
+			}
 		}
 	}
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 25 lines · Nikolaos Gkarlis

rtnl_newlink() lacks a CAP_NET_ADMIN capability check on the peer network namespace when creating paired devices (veth, vxcan, netkit). This allows an unprivileged user with a user namespace to create interfaces in arbitrary network namespaces, including init_net.

Add a netlink_ns_capable() check for CAP_NET_ADMIN in the peer namespace before allowing device creation to proceed.

Fixes 81adee47dfb6 ("net: Support specifying the network namespace upon device creation.")

---
v2:
- Removed "Reported-by" tag
- Fixed "Fixes" tag with the help of Kuniyuki Iwashima (thanks !)

 net/core/rtnetlink.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/core/rtnetlink.c +0 -0
index fae8034efbf..ee7d9d65b2c 100644

net/core/rtnetlink.c static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, · line 4064

Quoted 7 lines
net/core/rtnetlink.c +3 -1
@@ -4059,8 +4059,15 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
                                ret = PTR_ERR(peer_net);
                                goto put_ops;
                        }
-                       if (peer_net)
+                       if (peer_net) {
+                               if (!netlink_ns_capable(skb, peer_net->user_ns,
+                                                       CAP_NET_ADMIN)) {

I think this can be moved after the last rtnl_link_get_net_ifla() in rtnl_get_peer_net().

If netns is not fetched from the peer tb, rtnl_link_get_net_capable() just below this chunk will perform the same check redundantly.

Quoted 12 lines
net/core/rtnetlink.c +5 -1
+                                       put_net(peer_net);
+                                       ret = -EPERM;
+                                       goto put_ops;
+                               }
                                rtnl_nets_add(&rtnl_nets, peer_net);
+                       }
                }
        }
 
--

2.34.1