History

Merge tag 'vfs-6.17-rc1.nsfs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull namespace updates from Christian Brauner: "This contains namespace updates. This time specifically for nsfs: - Userspace heavily relies on the root inode numbers for namespaces to identify the initial namespaces. That's already a hard dependency. So we cannot change that anymore. Move the initial inode numbers to a public header and align the only two namespaces that currently don't do that with all the other namespaces. - The root inode of /proc having a fixed inode number has been part of the core kernel ABI since its inception, and recently some userspace programs (mainly container runtimes) have started to explicitly depend on this behaviour. The main reason this is useful to userspace is that by checking that a suspect /proc handle has fstype PROC_SUPER_MAGIC and is PROCFS_ROOT_INO, they can then use openat2() together with RESOLVE_{NO_{XDEV,MAGICLINK},BENEATH} to ensure that there isn't a bind-mount that replaces some procfs file with a different one. This kind of attack has lead to security issues in container runtimes in the past (such as CVE-2019-19921) and libraries like libpathrs[1] use this feature of procfs to provide safe procfs handling functions" * tag 'vfs-6.17-rc1.nsfs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: uapi: export PROCFS_ROOT_INO mntns: use stable inode number for initial mount ns netns: use stable inode number for initial mount ns nsfs: move root inode number to uapi

Linus Torvalds committed 1 year ago

Commit f70d24c2 parents 934600d 76fdb7e6 files · +47 −13Browse files

Showing the changes to include/uapi (2 of 6 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/fs.h +11 −0
  2. include/uapi/linux/nsfs.h +11 −0
include/uapi/linux/fs.h+11−0
@@ -60,6 +60,17 @@ · 59 unmodified lines
6060 #define RENAME_EXCHANGE (1 << 1) /* Exchange source and dest */
6161 #define RENAME_WHITEOUT (1 << 2) /* Whiteout source */
6262
63+/*
64+ * The root inode of procfs is guaranteed to always have the same inode number.
65+ * For programs that make heavy use of procfs, verifying that the root is a
66+ * real procfs root and using openat2(RESOLVE_{NO_{XDEV,MAGICLINKS},BENEATH})
67+ * will allow you to make sure you are never tricked into operating on the
68+ * wrong procfs file.
69+ */
70+enum procfs_ino {
71+ PROCFS_ROOT_INO = 1,
72+};
73+
6374 struct file_clone_range {
6475 __s64 src_fd;
6576 __u64 src_offset;
include/uapi/linux/nsfs.h+11−0
@@ -42,4 +42,15 @@ struct mnt_ns_info { · 41 unmodified lines
4242 /* Get previous namespace. */
4343 #define NS_MNT_GET_PREV _IOR(NSIO, 12, struct mnt_ns_info)
4444
45+enum init_ns_ino {
46+ IPC_NS_INIT_INO = 0xEFFFFFFFU,
47+ UTS_NS_INIT_INO = 0xEFFFFFFEU,
48+ USER_NS_INIT_INO = 0xEFFFFFFDU,
49+ PID_NS_INIT_INO = 0xEFFFFFFCU,
50+ CGROUP_NS_INIT_INO = 0xEFFFFFFBU,
51+ TIME_NS_INIT_INO = 0xEFFFFFFAU,
52+ NET_NS_INIT_INO = 0xEFFFFFF9U,
53+ MNT_NS_INIT_INO = 0xEFFFFFF8U,
54+};
55+
4556 #endif /* __LINUX_NSFS_H */