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

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>

+18
+6
fs/fhandle.c
··· 11 11 #include <linux/personality.h> 12 12 #include <linux/uaccess.h> 13 13 #include <linux/compat.h> 14 + #include <linux/nsfs.h> 14 15 #include "internal.h" 15 16 #include "mount.h" 16 17 ··· 187 186 188 187 if (fd == FD_PIDFS_ROOT) { 189 188 pidfs_get_root(root); 189 + return 0; 190 + } 191 + 192 + if (fd == FD_NSFS_ROOT) { 193 + nsfs_get_root(root); 190 194 return 0; 191 195 } 192 196
+1
fs/internal.h
··· 355 355 int anon_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry, 356 356 struct iattr *attr); 357 357 void pidfs_get_root(struct path *path); 358 + void nsfs_get_root(struct path *path);
+10
fs/nsfs.c
··· 25 25 26 26 static struct vfsmount *nsfs_mnt; 27 27 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 + 28 36 static long ns_ioctl(struct file *filp, unsigned int ioctl, 29 37 unsigned long arg); 30 38 static const struct file_operations ns_file_operations = { ··· 606 598 if (IS_ERR(nsfs_mnt)) 607 599 panic("can't set nsfs up\n"); 608 600 nsfs_mnt->mnt_sb->s_flags &= ~SB_NOUSER; 601 + nsfs_root_path.mnt = nsfs_mnt; 602 + nsfs_root_path.dentry = nsfs_mnt->mnt_root; 609 603 }
+1
include/uapi/linux/fcntl.h
··· 111 111 #define PIDFD_SELF_THREAD_GROUP -10001 /* Current thread group leader. */ 112 112 113 113 #define FD_PIDFS_ROOT -10002 /* Root of the pidfs filesystem */ 114 + #define FD_NSFS_ROOT -10003 /* Root of the nsfs filesystem */ 114 115 #define FD_INVALID -10009 /* Invalid file descriptor: -10000 - EBADF = -10009 */ 115 116 116 117 /* Generic flags for the *at(2) family of syscalls. */