From: Jakub Kicinski <kuba@kernel.org>
To: Nikolaos Gkarlis <nickgarlis@gmail.com>
Cc: netdev@vger.kernel.org, kuniyu@google.com
Subject: Re: [PATCH net v4] rtnetlink: add missing netlink_ns_capable() check for peer netns
Date: Wed, 1 Apr 2026 19:45:53 -0700 [thread overview]
Message-ID: <20260401194553.6e8a17f8@kernel.org> (raw)
In-Reply-To: <20260328213338.450601-1-nickgarlis@gmail.com>
On Sat, 28 Mar 2026 22:33:38 +0100 Nikolaos Gkarlis wrote:
> -static struct net *rtnl_get_peer_net(const struct rtnl_link_ops *ops,
> +static struct net *rtnl_get_peer_net(struct sk_buff *skb,
> + const struct rtnl_link_ops *ops,
> struct nlattr *tbp[],
> struct nlattr *data[],
> struct netlink_ext_ack *extack)
> {
> struct nlattr *tb[IFLA_MAX + 1];
> + struct net *net;
> int err;
>
> if (!data || !data[ops->peer_type])
There's an early return hiding outside of the context here.
the patch is technically correct, I think, because if we take this
shortcut we end up with the same netns as tgt_net so we'll validate
that it's capable later. But it's probably not obvious to a casual
reader of this code (or AI agents, sigh)
So let's rewrite this along the lines of:
struct nlattr *tb[IFLA_MAX + 1], **attrs;
struct net *net;
int err;
if (!data || !data[ops->peer_type]) {
attrs = tbp;
} else {
err = rtnl_nla_parse_ifinfomsg(tb, data[ops->peer_type], extack);
if (err < 0)
return ERR_PTR(err);
if (ops->validate) {
err = ops->validate(tb, NULL, extack);
if (err < 0)
return ERR_PTR(err);
}
attrs = tb;
}
net = rtnl_link_get_net_ifla(attrs);
if (IS_ERR_OR_NULL(net))
return net;
if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) {
...
?
> @@ -3915,7 +3917,16 @@ static struct net *rtnl_get_peer_net(const struct rtnl_link_ops *ops,
> return ERR_PTR(err);
> }
>
> - return rtnl_link_get_net_ifla(tb);
> + net = rtnl_link_get_net_ifla(tb);
> + if (IS_ERR_OR_NULL(net))
> + return net;
> +
> + if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) {
> + put_net(net);
> + return ERR_PTR(-EPERM);
> + }
> +
> + return net;
next prev parent reply other threads:[~2026-04-02 2:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-28 21:33 [PATCH net v4] rtnetlink: add missing netlink_ns_capable() check for peer netns Nikolaos Gkarlis
2026-03-31 14:43 ` Nikolaos Gkarlis
2026-04-02 2:45 ` Jakub Kicinski [this message]
2026-04-02 17:45 ` Nikolaos Gkarlis
2026-04-02 17:52 ` Kuniyuki Iwashima
2026-04-02 18:17 ` Nikolaos Gkarlis
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=20260401194553.6e8a17f8@kernel.org \
--to=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=nickgarlis@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.