]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
wifi: nl80211: require CAP_NET_ADMIN over the target netns in SET_WIPHY_NETNS
authorMaoyi Xie <maoyi.xie@ntu.edu.sg>
Wed, 6 May 2026 06:48:53 +0000 (14:48 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 6 May 2026 09:05:52 +0000 (11:05 +0200)
NL80211_CMD_SET_WIPHY_NETNS dispatches with GENL_UNS_ADMIN_PERM, which
verifies that the caller has CAP_NET_ADMIN for the source netns. It
doesn't verify that the caller has CAP_NET_ADMIN over the target netns
selected by NL80211_ATTR_NETNS_FD or NL80211_ATTR_PID.

This diverges from the convention enforced in
net/core/rtnetlink.c::rtnl_get_net_ns_capable():

    /* For now, the caller is required to have CAP_NET_ADMIN in
     * the user namespace owning the target net ns.
     */
    if (!sk_ns_capable(sk, net->user_ns, CAP_NET_ADMIN))
        return ERR_PTR(-EACCES);

A user with CAP_NET_ADMIN in their own user namespace can therefore
push a wiphy into an arbitrary netns (including init_net) over which
they have no privilege.

Mirror the rtnetlink convention by requiring CAP_NET_ADMIN in the
target netns before calling cfg80211_switch_netns().

Signed-off-by: Maoyi Xie <maoyi.xie@ntu.edu.sg>
Link: https://patch.msgid.link/20260506064854.2207105-2-maoyixie.tju@gmail.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/wireless/nl80211.c

index 67088804dcc796f73f09c956721f8cf3f8bbe710..db546dd93d084596c56b149e7da757404501b7fd 100644 (file)
@@ -13867,6 +13867,19 @@ static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
        if (IS_ERR(net))
                return PTR_ERR(net);
 
+       /*
+        * The caller already has CAP_NET_ADMIN over the source netns
+        * (enforced by GENL_UNS_ADMIN_PERM on the genl op). Mirror the
+        * convention used by net/core/rtnetlink.c::rtnl_get_net_ns_capable()
+        * and require CAP_NET_ADMIN over the target netns as well, so that
+        * a caller that is privileged in their own user namespace cannot
+        * push a wiphy into a netns where they have no privilege.
+        */
+       if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) {
+               put_net(net);
+               return -EPERM;
+       }
+
        err = 0;
 
        /* check if anything to do */