]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nsfs: add missing id retrieval support
authorChristian Brauner <brauner@kernel.org>
Fri, 12 Sep 2025 11:52:53 +0000 (13:52 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 19 Sep 2025 12:26:16 +0000 (14:26 +0200)
The mount namespace has supported id retrieval for a while already.
Add support for the other types as well.

Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/nsfs.c
include/uapi/linux/nsfs.h

index 22765fcab18e6d6d861a5afe23213e5d46251737..8484bc4dd3debce80fbeb13972c4b13357f89a30 100644 (file)
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -177,6 +177,7 @@ static bool nsfs_ioctl_valid(unsigned int cmd)
        case NS_GET_TGID_FROM_PIDNS:
        case NS_GET_PID_IN_PIDNS:
        case NS_GET_TGID_IN_PIDNS:
+       case NS_GET_ID:
                return true;
        }
 
@@ -226,18 +227,6 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
                argp = (uid_t __user *) arg;
                uid = from_kuid_munged(current_user_ns(), user_ns->owner);
                return put_user(uid, argp);
-       case NS_GET_MNTNS_ID: {
-               __u64 __user *idp;
-               __u64 id;
-
-               if (ns->ops->type != CLONE_NEWNS)
-                       return -EINVAL;
-
-               mnt_ns = container_of(ns, struct mnt_namespace, ns);
-               idp = (__u64 __user *)arg;
-               id = mnt_ns->ns.ns_id;
-               return put_user(id, idp);
-       }
        case NS_GET_PID_FROM_PIDNS:
                fallthrough;
        case NS_GET_TGID_FROM_PIDNS:
@@ -283,6 +272,18 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
                        ret = -ESRCH;
                return ret;
        }
+       case NS_GET_MNTNS_ID:
+               if (ns->ops->type != CLONE_NEWNS)
+                       return -EINVAL;
+               fallthrough;
+       case NS_GET_ID: {
+               __u64 __user *idp;
+               __u64 id;
+
+               idp = (__u64 __user *)arg;
+               id = ns->ns_id;
+               return put_user(id, idp);
+       }
        }
 
        /* extensible ioctls */
index fa86fe3c8bd3b4c3b93df4ee579fec68d3a9b779..5d5bf22464c92e29d1ea0d8e458e8c39c8239c4b 100644 (file)
@@ -16,8 +16,6 @@
 #define NS_GET_NSTYPE          _IO(NSIO, 0x3)
 /* Get owner UID (in the caller's user namespace) for a user namespace */
 #define NS_GET_OWNER_UID       _IO(NSIO, 0x4)
-/* Get the id for a mount namespace */
-#define NS_GET_MNTNS_ID                _IOR(NSIO, 0x5, __u64)
 /* Translate pid from target pid namespace into the caller's pid namespace. */
 #define NS_GET_PID_FROM_PIDNS  _IOR(NSIO, 0x6, int)
 /* Return thread-group leader id of pid in the callers pid namespace. */
@@ -42,6 +40,10 @@ struct mnt_ns_info {
 /* Get previous namespace. */
 #define NS_MNT_GET_PREV                _IOR(NSIO, 12, struct mnt_ns_info)
 
+/* Retrieve namespace identifiers. */
+#define NS_GET_MNTNS_ID                _IOR(NSIO, 5,  __u64)
+#define NS_GET_ID              _IOR(NSIO, 13, __u64)
+
 enum init_ns_ino {
        IPC_NS_INIT_INO         = 0xEFFFFFFFU,
        UTS_NS_INIT_INO         = 0xEFFFFFFEU,