]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
uapi: export PROCFS_ROOT_INO
authorAleksa Sarai <cyphar@cyphar.com>
Tue, 8 Jul 2025 13:21:51 +0000 (23:21 +1000)
committerChristian Brauner <brauner@kernel.org>
Thu, 10 Jul 2025 07:39:18 +0000 (09:39 +0200)
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(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.

There was also some trailing whitespace in the "struct proc_dir_entry"
initialiser, so fix that up as well.

[1]: https://github.com/openSUSE/libpathrs

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Link: https://lore.kernel.org/20250708-uapi-procfs-root-ino-v1-1-6ae61e97c79b@cyphar.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/proc/root.c
include/linux/proc_ns.h
include/uapi/linux/fs.h

index 06a297a27ba3b31a5e2092fcd08d1ca9eebb5849..ed86ac7103843b46e4936f3ec42d7568bc61d404 100644 (file)
@@ -363,12 +363,12 @@ static const struct inode_operations proc_root_inode_operations = {
  * This is the root "inode" in the /proc tree..
  */
 struct proc_dir_entry proc_root = {
-       .low_ino        = PROC_ROOT_INO, 
-       .namelen        = 5, 
-       .mode           = S_IFDIR | S_IRUGO | S_IXUGO, 
-       .nlink          = 2, 
+       .low_ino        = PROCFS_ROOT_INO,
+       .namelen        = 5,
+       .mode           = S_IFDIR | S_IRUGO | S_IXUGO,
+       .nlink          = 2,
        .refcnt         = REFCOUNT_INIT(1),
-       .proc_iops      = &proc_root_inode_operations, 
+       .proc_iops      = &proc_root_inode_operations,
        .proc_dir_ops   = &proc_root_operations,
        .parent         = &proc_root,
        .subdir         = RB_ROOT,
index 6258455e49a4601ede15d092c5f2fee2732ae001..4b20375f3783e7f6e22083431fae857b1c097e35 100644 (file)
@@ -40,7 +40,6 @@ extern const struct proc_ns_operations timens_for_children_operations;
  * We always define these enumerators
  */
 enum {
-       PROC_ROOT_INO           = 1,
        PROC_IPC_INIT_INO       = IPC_NS_INIT_INO,
        PROC_UTS_INIT_INO       = UTS_NS_INIT_INO,
        PROC_USER_INIT_INO      = USER_NS_INIT_INO,
index 0098b0ce8ccb1f194f67972b31265c8e82f7bf58..28238a3edbc1b000d5415b1d2abd956f859a17ff 100644 (file)
 #define RENAME_EXCHANGE                (1 << 1)        /* Exchange source and dest */
 #define RENAME_WHITEOUT                (1 << 2)        /* Whiteout source */
 
+/*
+ * The root inode of procfs is guaranteed to always have the same inode number.
+ * For programs that make heavy use of procfs, verifying that the root is a
+ * real procfs root and using openat2(RESOLVE_{NO_{XDEV,MAGICLINKS},BENEATH})
+ * will allow you to make sure you are never tricked into operating on the
+ * wrong procfs file.
+ */
+enum procfs_ino {
+       PROCFS_ROOT_INO = 1,
+};
+
 struct file_clone_range {
        __s64 src_fd;
        __u64 src_offset;