Skip to content

Commit

Permalink
fs: add an ioctl to get the mnt ns id from nsfs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Josef Bacik authored and Christian Brauner committed Jun 28, 2024
1 parent 71aacb4 commit e8e43a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fs/nsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <linux/nsfs.h>
#include <linux/uaccess.h>

#include "mount.h"
#include "internal.h"

static struct vfsmount *nsfs_mnt;
Expand Down Expand Up @@ -143,6 +144,19 @@ 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: {
struct mnt_namespace *mnt_ns;
__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->seq;
return put_user(id, idp);
}
default:
return -ENOTTY;
}
Expand Down
2 changes: 2 additions & 0 deletions include/uapi/linux/nsfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
#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 _IO(NSIO, 0x5)

#endif /* __LINUX_NSFS_H */

0 comments on commit e8e43a1

Please sign in to comment.