Skip to content

Commit 76fdb7e

Browse files
cypharbrauner
authored andcommitted
uapi: export PROCFS_ROOT_INO
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 <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent cd267cd commit 76fdb7e

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

fs/proc/root.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,12 @@ static const struct inode_operations proc_root_inode_operations = {
363363
* This is the root "inode" in the /proc tree..
364364
*/
365365
struct proc_dir_entry proc_root = {
366-
.low_ino = PROC_ROOT_INO,
367-
.namelen = 5,
368-
.mode = S_IFDIR | S_IRUGO | S_IXUGO,
369-
.nlink = 2,
366+
.low_ino = PROCFS_ROOT_INO,
367+
.namelen = 5,
368+
.mode = S_IFDIR | S_IRUGO | S_IXUGO,
369+
.nlink = 2,
370370
.refcnt = REFCOUNT_INIT(1),
371-
.proc_iops = &proc_root_inode_operations,
371+
.proc_iops = &proc_root_inode_operations,
372372
.proc_dir_ops = &proc_root_operations,
373373
.parent = &proc_root,
374374
.subdir = RB_ROOT,

include/linux/proc_ns.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ extern const struct proc_ns_operations timens_for_children_operations;
4040
* We always define these enumerators
4141
*/
4242
enum {
43-
PROC_ROOT_INO = 1,
4443
PROC_IPC_INIT_INO = IPC_NS_INIT_INO,
4544
PROC_UTS_INIT_INO = UTS_NS_INIT_INO,
4645
PROC_USER_INIT_INO = USER_NS_INIT_INO,

include/uapi/linux/fs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@
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;

0 commit comments

Comments
 (0)