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

fs: add an ioctl to get the mnt ns id from nsfs

In order to utilize the listmount() and statmount() extensions that
allow us to call them on different namespaces we need a way to get the
mnt namespace id from user space. Add an ioctl to nsfs that will allow
us to extract the mnt namespace id in order to make these new extensions
usable.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Link: https://lore.kernel.org/r/180449959d5a756af7306d6bda55f41b9d53e3cb.1719243756.git.josef@toxicpanda.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Josef Bacik and committed by
Christian Brauner
e8e43a1f 71aacb4c

+16
+14
fs/nsfs.c
··· 12 12 #include <linux/nsfs.h> 13 13 #include <linux/uaccess.h> 14 14 15 + #include "mount.h" 15 16 #include "internal.h" 16 17 17 18 static struct vfsmount *nsfs_mnt; ··· 144 143 argp = (uid_t __user *) arg; 145 144 uid = from_kuid_munged(current_user_ns(), user_ns->owner); 146 145 return put_user(uid, argp); 146 + case NS_GET_MNTNS_ID: { 147 + struct mnt_namespace *mnt_ns; 148 + __u64 __user *idp; 149 + __u64 id; 150 + 151 + if (ns->ops->type != CLONE_NEWNS) 152 + return -EINVAL; 153 + 154 + mnt_ns = container_of(ns, struct mnt_namespace, ns); 155 + idp = (__u64 __user *)arg; 156 + id = mnt_ns->seq; 157 + return put_user(id, idp); 158 + } 147 159 default: 148 160 return -ENOTTY; 149 161 }
+2
include/uapi/linux/nsfs.h
··· 15 15 #define NS_GET_NSTYPE _IO(NSIO, 0x3) 16 16 /* Get owner UID (in the caller's user namespace) for a user namespace */ 17 17 #define NS_GET_OWNER_UID _IO(NSIO, 0x4) 18 + /* Get the id for a mount namespace */ 19 + #define NS_GET_MNTNS_ID _IO(NSIO, 0x5) 18 20 19 21 #endif /* __LINUX_NSFS_H */