From: Nikolaos Gkarlis <nickgarlis@gmail.com>
To: netdev@vger.kernel.org
Cc: kuba@kernel.org, nickgarlis@gmail.com, kuniyu@google.com
Subject: [PATCH net v2] rtnetlink: add missing netlink_ns_capable() check for peer netns
Date: Fri, 27 Mar 2026 23:12:03 +0100 [thread overview]
Message-ID: <20260327221203.430454-1-nickgarlis@gmail.com> (raw)
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.")
Signed-off-by: Nikolaos Gkarlis <nickgarlis@gmail.com>
---
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(-)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index fae8034efbf..ee7d9d65b2c 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -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);
+ }
}
}
--
2.34.1
next reply other threads:[~2026-03-27 22:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 22:12 Nikolaos Gkarlis [this message]
2026-03-27 22:38 ` [PATCH net v2] rtnetlink: add missing netlink_ns_capable() check for peer netns Kuniyuki Iwashima
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=20260327221203.430454-1-nickgarlis@gmail.com \
--to=nickgarlis@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox