Skip to content

Commit e83f0b5

Browse files
committed
nsfs: support exhaustive file handles
Pidfd file handles are exhaustive meaning they don't require a handle on another pidfd to pass to open_by_handle_at() so it can derive the filesystem to decode in. Instead it can be derived from the file handle itself. The same is possible for namespace file handles. Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 5222470 commit e83f0b5

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

fs/fhandle.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/personality.h>
1212
#include <linux/uaccess.h>
1313
#include <linux/compat.h>
14+
#include <linux/nsfs.h>
1415
#include "internal.h"
1516
#include "mount.h"
1617

@@ -189,6 +190,11 @@ static int get_path_anchor(int fd, struct path *root)
189190
return 0;
190191
}
191192

193+
if (fd == FD_NSFS_ROOT) {
194+
nsfs_get_root(root);
195+
return 0;
196+
}
197+
192198
return -EBADF;
193199
}
194200

fs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,4 @@ int anon_inode_getattr(struct mnt_idmap *idmap, const struct path *path,
355355
int anon_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
356356
struct iattr *attr);
357357
void pidfs_get_root(struct path *path);
358+
void nsfs_get_root(struct path *path);

fs/nsfs.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525

2626
static struct vfsmount *nsfs_mnt;
2727

28+
static struct path nsfs_root_path = {};
29+
30+
void nsfs_get_root(struct path *path)
31+
{
32+
*path = nsfs_root_path;
33+
path_get(path);
34+
}
35+
2836
static long ns_ioctl(struct file *filp, unsigned int ioctl,
2937
unsigned long arg);
3038
static const struct file_operations ns_file_operations = {
@@ -598,4 +606,6 @@ void __init nsfs_init(void)
598606
if (IS_ERR(nsfs_mnt))
599607
panic("can't set nsfs up\n");
600608
nsfs_mnt->mnt_sb->s_flags &= ~SB_NOUSER;
609+
nsfs_root_path.mnt = nsfs_mnt;
610+
nsfs_root_path.dentry = nsfs_mnt->mnt_root;
601611
}

include/uapi/linux/fcntl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#define PIDFD_SELF_THREAD_GROUP -10001 /* Current thread group leader. */
112112

113113
#define FD_PIDFS_ROOT -10002 /* Root of the pidfs filesystem */
114+
#define FD_NSFS_ROOT -10003 /* Root of the nsfs filesystem */
114115
#define FD_INVALID -10009 /* Invalid file descriptor: -10000 - EBADF = -10009 */
115116

116117
/* Generic flags for the *at(2) family of syscalls. */

0 commit comments

Comments
 (0)