Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+17 -14
+13 -12
fs/nsfs.c
··· 177 177 case NS_GET_TGID_FROM_PIDNS: 178 178 case NS_GET_PID_IN_PIDNS: 179 179 case NS_GET_TGID_IN_PIDNS: 180 + case NS_GET_ID: 180 181 return true; 181 182 } 182 183 ··· 227 226 argp = (uid_t __user *) arg; 228 227 uid = from_kuid_munged(current_user_ns(), user_ns->owner); 229 228 return put_user(uid, argp); 230 - case NS_GET_MNTNS_ID: { 231 - __u64 __user *idp; 232 - __u64 id; 233 - 234 - if (ns->ops->type != CLONE_NEWNS) 235 - return -EINVAL; 236 - 237 - mnt_ns = container_of(ns, struct mnt_namespace, ns); 238 - idp = (__u64 __user *)arg; 239 - id = mnt_ns->ns.ns_id; 240 - return put_user(id, idp); 241 - } 242 229 case NS_GET_PID_FROM_PIDNS: 243 230 fallthrough; 244 231 case NS_GET_TGID_FROM_PIDNS: ··· 271 282 if (!ret) 272 283 ret = -ESRCH; 273 284 return ret; 285 + } 286 + case NS_GET_MNTNS_ID: 287 + if (ns->ops->type != CLONE_NEWNS) 288 + return -EINVAL; 289 + fallthrough; 290 + case NS_GET_ID: { 291 + __u64 __user *idp; 292 + __u64 id; 293 + 294 + idp = (__u64 __user *)arg; 295 + id = ns->ns_id; 296 + return put_user(id, idp); 274 297 } 275 298 } 276 299
+4 -2
include/uapi/linux/nsfs.h
··· 16 16 #define NS_GET_NSTYPE _IO(NSIO, 0x3) 17 17 /* Get owner UID (in the caller's user namespace) for a user namespace */ 18 18 #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) 21 19 /* Translate pid from target pid namespace into the caller's pid namespace. */ 22 20 #define NS_GET_PID_FROM_PIDNS _IOR(NSIO, 0x6, int) 23 21 /* Return thread-group leader id of pid in the callers pid namespace. */ ··· 39 41 #define NS_MNT_GET_NEXT _IOR(NSIO, 11, struct mnt_ns_info) 40 42 /* Get previous namespace. */ 41 43 #define NS_MNT_GET_PREV _IOR(NSIO, 12, struct mnt_ns_info) 44 + 45 + /* Retrieve namespace identifiers. */ 46 + #define NS_GET_MNTNS_ID _IOR(NSIO, 5, __u64) 47 + #define NS_GET_ID _IOR(NSIO, 13, __u64) 42 48 43 49 enum init_ns_ino { 44 50 IPC_NS_INIT_INO = 0xEFFFFFFFU,