Skip to content

Commit f861225

Browse files
committed
nsfs: add missing id retrieval support
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>
1 parent e83f0b5 commit f861225

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

fs/nsfs.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ static bool nsfs_ioctl_valid(unsigned int cmd)
177177
case NS_GET_TGID_FROM_PIDNS:
178178
case NS_GET_PID_IN_PIDNS:
179179
case NS_GET_TGID_IN_PIDNS:
180+
case NS_GET_ID:
180181
return true;
181182
}
182183

@@ -226,18 +227,6 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
226227
argp = (uid_t __user *) arg;
227228
uid = from_kuid_munged(current_user_ns(), user_ns->owner);
228229
return put_user(uid, argp);
229-
case NS_GET_MNTNS_ID: {
230-
__u64 __user *idp;
231-
__u64 id;
232-
233-
if (ns->ops->type != CLONE_NEWNS)
234-
return -EINVAL;
235-
236-
mnt_ns = container_of(ns, struct mnt_namespace, ns);
237-
idp = (__u64 __user *)arg;
238-
id = mnt_ns->ns.ns_id;
239-
return put_user(id, idp);
240-
}
241230
case NS_GET_PID_FROM_PIDNS:
242231
fallthrough;
243232
case NS_GET_TGID_FROM_PIDNS:
@@ -283,6 +272,18 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
283272
ret = -ESRCH;
284273
return ret;
285274
}
275+
case NS_GET_MNTNS_ID:
276+
if (ns->ops->type != CLONE_NEWNS)
277+
return -EINVAL;
278+
fallthrough;
279+
case NS_GET_ID: {
280+
__u64 __user *idp;
281+
__u64 id;
282+
283+
idp = (__u64 __user *)arg;
284+
id = ns->ns_id;
285+
return put_user(id, idp);
286+
}
286287
}
287288

288289
/* extensible ioctls */

include/uapi/linux/nsfs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#define NS_GET_NSTYPE _IO(NSIO, 0x3)
1717
/* Get owner UID (in the caller's user namespace) for a user namespace */
1818
#define NS_GET_OWNER_UID _IO(NSIO, 0x4)
19-
/* Get the id for a mount namespace */
20-
#define NS_GET_MNTNS_ID _IOR(NSIO, 0x5, __u64)
2119
/* Translate pid from target pid namespace into the caller's pid namespace. */
2220
#define NS_GET_PID_FROM_PIDNS _IOR(NSIO, 0x6, int)
2321
/* Return thread-group leader id of pid in the callers pid namespace. */
@@ -42,6 +40,10 @@ struct mnt_ns_info {
4240
/* Get previous namespace. */
4341
#define NS_MNT_GET_PREV _IOR(NSIO, 12, struct mnt_ns_info)
4442

43+
/* Retrieve namespace identifiers. */
44+
#define NS_GET_MNTNS_ID _IOR(NSIO, 5, __u64)
45+
#define NS_GET_ID _IOR(NSIO, 13, __u64)
46+
4547
enum init_ns_ino {
4648
IPC_NS_INIT_INO = 0xEFFFFFFFU,
4749
UTS_NS_INIT_INO = 0xEFFFFFFEU,

0 commit comments

Comments
 (0)