Skip to content

Commit e8e43a1

Browse files
josefbacikbrauner
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/180449959d5a756af7306d6bda55f41b9d53e3cb.1719243756.git.josef@toxicpanda.com Signed-off-by: Christian Brauner <[email protected]>
1 parent 71aacb4 commit e8e43a1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

fs/nsfs.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/nsfs.h>
1313
#include <linux/uaccess.h>
1414

15+
#include "mount.h"
1516
#include "internal.h"
1617

1718
static struct vfsmount *nsfs_mnt;
@@ -143,6 +144,19 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
143144
argp = (uid_t __user *) arg;
144145
uid = from_kuid_munged(current_user_ns(), user_ns->owner);
145146
return put_user(uid, argp);
147+
case NS_GET_MNTNS_ID: {
148+
struct mnt_namespace *mnt_ns;
149+
__u64 __user *idp;
150+
__u64 id;
151+
152+
if (ns->ops->type != CLONE_NEWNS)
153+
return -EINVAL;
154+
155+
mnt_ns = container_of(ns, struct mnt_namespace, ns);
156+
idp = (__u64 __user *)arg;
157+
id = mnt_ns->seq;
158+
return put_user(id, idp);
159+
}
146160
default:
147161
return -ENOTTY;
148162
}

include/uapi/linux/nsfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@
1515
#define NS_GET_NSTYPE _IO(NSIO, 0x3)
1616
/* Get owner UID (in the caller's user namespace) for a user namespace */
1717
#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)
1820

1921
#endif /* __LINUX_NSFS_H */

0 commit comments

Comments
 (0)