nsfs: support file handles
A while ago we added support for file handles to pidfs so pidfds can be encoded and decoded as file handles. Userspace has adopted this quickly and it's proven very useful. Implement file handles for namespaces as well. A process is not always able to open /proc/self/ns/. That requires procfs to be mounted and for /proc/self/ or /proc/self/ns/ to not be overmounted. However, userspace can always derive a namespace fd from a pidfd. And that always works for a task's own namespace. There's no need to introduce unnecessary behavioral differences between /proc/self/ns/ fds, pidfd-derived namespace fds, and file-handle-derived namespace fds. So namespace file handles are always decodable if the caller is located in the namespace the file handle refers to. This also allows a task to e.g., store a set of file handles to its namespaces in a file on-disk so it can verify when it gets rexeced that they're still valid and so on. This is akin to the pidfd use-case. Or just plainly for namespace comparison reasons where a file handle to the task's own namespace can be easily compared against others. Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
@@ -53,4 +53,13 @@ enum init_ns_ino {
|
||||
MNT_NS_INIT_INO = 0xEFFFFFF8U,
|
||||
};
|
||||
|
||||
struct nsfs_file_handle {
|
||||
__u64 ns_id;
|
||||
__u32 ns_type;
|
||||
__u32 ns_inum;
|
||||
};
|
||||
|
||||
#define NSFS_FILE_HANDLE_SIZE_VER0 16 /* sizeof first published struct */
|
||||
#define NSFS_FILE_HANDLE_SIZE_LATEST sizeof(struct nsfs_file_handle) /* sizeof latest published struct */
|
||||
|
||||
#endif /* __LINUX_NSFS_H */
|
||||
|
||||
Reference in New Issue
Block a user