Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * The proc filesystem constants/structures |
| 4 | */ |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 5 | #ifndef _LINUX_PROC_FS_H |
| 6 | #define _LINUX_PROC_FS_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | |
Alexey Dobriyan | d919b33 | 2020-04-06 20:09:01 -0700 | [diff] [blame] | 8 | #include <linux/compiler.h> |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 9 | #include <linux/types.h> |
| 10 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 12 | struct proc_dir_entry; |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 13 | struct seq_file; |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 14 | struct seq_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Alexey Dobriyan | d919b33 | 2020-04-06 20:09:01 -0700 | [diff] [blame] | 16 | enum { |
| 17 | /* |
| 18 | * All /proc entries using this ->proc_ops instance are never removed. |
| 19 | * |
| 20 | * If in doubt, ignore this flag. |
| 21 | */ |
| 22 | #ifdef MODULE |
| 23 | PROC_ENTRY_PERMANENT = 0U, |
| 24 | #else |
| 25 | PROC_ENTRY_PERMANENT = 1U << 0, |
| 26 | #endif |
| 27 | }; |
| 28 | |
Alexey Dobriyan | d56c0d4 | 2020-02-03 17:37:14 -0800 | [diff] [blame] | 29 | struct proc_ops { |
Alexey Dobriyan | d919b33 | 2020-04-06 20:09:01 -0700 | [diff] [blame] | 30 | unsigned int proc_flags; |
Alexey Dobriyan | d56c0d4 | 2020-02-03 17:37:14 -0800 | [diff] [blame] | 31 | int (*proc_open)(struct inode *, struct file *); |
| 32 | ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *); |
Christoph Hellwig | fd5a13f | 2020-09-03 16:22:31 +0200 | [diff] [blame] | 33 | ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *); |
Alexey Dobriyan | d56c0d4 | 2020-02-03 17:37:14 -0800 | [diff] [blame] | 34 | ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *); |
| 35 | loff_t (*proc_lseek)(struct file *, loff_t, int); |
| 36 | int (*proc_release)(struct inode *, struct file *); |
| 37 | __poll_t (*proc_poll)(struct file *, struct poll_table_struct *); |
| 38 | long (*proc_ioctl)(struct file *, unsigned int, unsigned long); |
| 39 | #ifdef CONFIG_COMPAT |
| 40 | long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long); |
| 41 | #endif |
| 42 | int (*proc_mmap)(struct file *, struct vm_area_struct *); |
| 43 | unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); |
Alexey Dobriyan | d919b33 | 2020-04-06 20:09:01 -0700 | [diff] [blame] | 44 | } __randomize_layout; |
Alexey Dobriyan | d56c0d4 | 2020-02-03 17:37:14 -0800 | [diff] [blame] | 45 | |
Alexey Gladkov | fa10fed | 2020-04-19 16:10:52 +0200 | [diff] [blame] | 46 | /* definitions for hide_pid field */ |
Alexey Gladkov | e61bb8b | 2020-04-19 16:10:57 +0200 | [diff] [blame] | 47 | enum proc_hidepid { |
Alexey Gladkov | fa10fed | 2020-04-19 16:10:52 +0200 | [diff] [blame] | 48 | HIDEPID_OFF = 0, |
| 49 | HIDEPID_NO_ACCESS = 1, |
| 50 | HIDEPID_INVISIBLE = 2, |
Alexey Gladkov | 24a71ce | 2020-04-19 16:10:53 +0200 | [diff] [blame] | 51 | HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */ |
Alexey Gladkov | fa10fed | 2020-04-19 16:10:52 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
Alexey Gladkov | 6814ef2 | 2020-04-19 16:10:54 +0200 | [diff] [blame] | 54 | /* definitions for proc mount option pidonly */ |
Alexey Gladkov | e61bb8b | 2020-04-19 16:10:57 +0200 | [diff] [blame] | 55 | enum proc_pidonly { |
Alexey Gladkov | 6814ef2 | 2020-04-19 16:10:54 +0200 | [diff] [blame] | 56 | PROC_PIDONLY_OFF = 0, |
| 57 | PROC_PIDONLY_ON = 1, |
| 58 | }; |
| 59 | |
Alexey Gladkov | fa10fed | 2020-04-19 16:10:52 +0200 | [diff] [blame] | 60 | struct proc_fs_info { |
| 61 | struct pid_namespace *pid_ns; |
| 62 | struct dentry *proc_self; /* For /proc/self */ |
| 63 | struct dentry *proc_thread_self; /* For /proc/thread-self */ |
| 64 | kgid_t pid_gid; |
Alexey Gladkov | e61bb8b | 2020-04-19 16:10:57 +0200 | [diff] [blame] | 65 | enum proc_hidepid hide_pid; |
| 66 | enum proc_pidonly pidonly; |
Alexey Gladkov | fa10fed | 2020-04-19 16:10:52 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static inline struct proc_fs_info *proc_sb_info(struct super_block *sb) |
| 70 | { |
| 71 | return sb->s_fs_info; |
| 72 | } |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #ifdef CONFIG_PROC_FS |
| 75 | |
David Howells | 564def7 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 76 | typedef int (*proc_write_t)(struct file *, char *, size_t); |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | extern void proc_root_init(void); |
Eric W. Biederman | 7bc3e6e | 2020-02-19 18:22:26 -0600 | [diff] [blame] | 79 | extern void proc_flush_pid(struct pid *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | extern struct proc_dir_entry *proc_symlink(const char *, |
| 82 | struct proc_dir_entry *, const char *); |
Alexey Dobriyan | b202ac9 | 2020-12-15 20:42:39 -0800 | [diff] [blame] | 83 | struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool); |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 84 | extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *); |
David Howells | 270b5ac | 2013-04-12 02:48:30 +0100 | [diff] [blame] | 85 | extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t, |
| 86 | struct proc_dir_entry *, void *); |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 87 | extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t, |
| 88 | struct proc_dir_entry *); |
Seth Forshee | f97df70 | 2016-11-14 11:12:56 +0000 | [diff] [blame] | 89 | struct proc_dir_entry *proc_create_mount_point(const char *name); |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 90 | |
Christoph Hellwig | 44414d8 | 2018-04-24 17:05:17 +0200 | [diff] [blame] | 91 | struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode, |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 92 | struct proc_dir_entry *parent, const struct seq_operations *ops, |
Christoph Hellwig | 44414d8 | 2018-04-24 17:05:17 +0200 | [diff] [blame] | 93 | unsigned int state_size, void *data); |
| 94 | #define proc_create_seq_data(name, mode, parent, ops, data) \ |
| 95 | proc_create_seq_private(name, mode, parent, ops, 0, data) |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 96 | #define proc_create_seq(name, mode, parent, ops) \ |
Christoph Hellwig | 44414d8 | 2018-04-24 17:05:17 +0200 | [diff] [blame] | 97 | proc_create_seq_private(name, mode, parent, ops, 0, NULL) |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 98 | struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode, |
| 99 | struct proc_dir_entry *parent, |
| 100 | int (*show)(struct seq_file *, void *), void *data); |
| 101 | #define proc_create_single(name, mode, parent, show) \ |
| 102 | proc_create_single_data(name, mode, parent, show, NULL) |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 103 | |
| 104 | extern struct proc_dir_entry *proc_create_data(const char *, umode_t, |
| 105 | struct proc_dir_entry *, |
Alexey Dobriyan | d56c0d4 | 2020-02-03 17:37:14 -0800 | [diff] [blame] | 106 | const struct proc_ops *, |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 107 | void *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Alexey Dobriyan | d56c0d4 | 2020-02-03 17:37:14 -0800 | [diff] [blame] | 109 | struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops); |
David Howells | 271a15e | 2013-04-12 00:38:51 +0100 | [diff] [blame] | 110 | extern void proc_set_size(struct proc_dir_entry *, loff_t); |
| 111 | extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t); |
David Howells | c30480b | 2013-04-12 18:03:36 +0100 | [diff] [blame] | 112 | extern void *PDE_DATA(const struct inode *); |
David Howells | 4a520d2 | 2013-04-12 14:06:01 +0100 | [diff] [blame] | 113 | extern void *proc_get_parent_data(const struct inode *); |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 114 | extern void proc_remove(struct proc_dir_entry *); |
| 115 | extern void remove_proc_entry(const char *, struct proc_dir_entry *); |
| 116 | extern int remove_proc_subtree(const char *, struct proc_dir_entry *); |
| 117 | |
Christoph Hellwig | c350637 | 2018-04-10 19:42:55 +0200 | [diff] [blame] | 118 | struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode, |
| 119 | struct proc_dir_entry *parent, const struct seq_operations *ops, |
| 120 | unsigned int state_size, void *data); |
Miaohe Lin | 9573e8f | 2019-12-04 16:50:08 -0800 | [diff] [blame] | 121 | #define proc_create_net(name, mode, parent, ops, state_size) \ |
| 122 | proc_create_net_data(name, mode, parent, ops, state_size, NULL) |
Christoph Hellwig | 3617d94 | 2018-04-13 20:38:35 +0200 | [diff] [blame] | 123 | struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode, |
| 124 | struct proc_dir_entry *parent, |
| 125 | int (*show)(struct seq_file *, void *), void *data); |
David Howells | 564def7 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 126 | struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode, |
| 127 | struct proc_dir_entry *parent, |
| 128 | const struct seq_operations *ops, |
| 129 | proc_write_t write, |
| 130 | unsigned int state_size, void *data); |
| 131 | struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode, |
| 132 | struct proc_dir_entry *parent, |
| 133 | int (*show)(struct seq_file *, void *), |
| 134 | proc_write_t write, |
| 135 | void *data); |
Christian Brauner | 3eb39f4 | 2018-11-19 00:51:56 +0100 | [diff] [blame] | 136 | extern struct pid *tgid_pidfd_to_pid(const struct file *file); |
Christoph Hellwig | c350637 | 2018-04-10 19:42:55 +0200 | [diff] [blame] | 137 | |
Yonghong Song | f9c7927 | 2020-07-23 11:41:10 -0700 | [diff] [blame] | 138 | struct bpf_iter_aux_info; |
| 139 | extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux); |
Yonghong Song | 138d0be | 2020-05-09 10:59:10 -0700 | [diff] [blame] | 140 | extern void bpf_iter_fini_seq_net(void *priv_data); |
| 141 | |
Aubrey Li | 68bc30b | 2019-06-06 09:22:34 +0800 | [diff] [blame] | 142 | #ifdef CONFIG_PROC_PID_ARCH_STATUS |
| 143 | /* |
| 144 | * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must |
| 145 | * provide proc_pid_arch_status() definition. |
| 146 | */ |
| 147 | int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns, |
| 148 | struct pid *pid, struct task_struct *task); |
| 149 | #endif /* CONFIG_PROC_PID_ARCH_STATUS */ |
| 150 | |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 151 | #else /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Andrew Morton | 647f010 | 2014-06-04 16:12:20 -0700 | [diff] [blame] | 153 | static inline void proc_root_init(void) |
| 154 | { |
| 155 | } |
| 156 | |
Eric W. Biederman | 7bc3e6e | 2020-02-19 18:22:26 -0600 | [diff] [blame] | 157 | static inline void proc_flush_pid(struct pid *pid) |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 158 | { |
| 159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | static inline struct proc_dir_entry *proc_symlink(const char *name, |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 162 | struct proc_dir_entry *parent,const char *dest) { return NULL;} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | static inline struct proc_dir_entry *proc_mkdir(const char *name, |
| 164 | struct proc_dir_entry *parent) {return NULL;} |
Seth Forshee | f97df70 | 2016-11-14 11:12:56 +0000 | [diff] [blame] | 165 | static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; } |
Alexey Dobriyan | b202ac9 | 2020-12-15 20:42:39 -0800 | [diff] [blame] | 166 | static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode, |
| 167 | struct proc_dir_entry *parent, void *data, bool force_lookup) |
| 168 | { |
| 169 | return NULL; |
| 170 | } |
David Howells | 270b5ac | 2013-04-12 02:48:30 +0100 | [diff] [blame] | 171 | static inline struct proc_dir_entry *proc_mkdir_data(const char *name, |
| 172 | umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; } |
Randy Dunlap | f12a20f | 2011-05-17 15:44:12 -0700 | [diff] [blame] | 173 | static inline struct proc_dir_entry *proc_mkdir_mode(const char *name, |
Al Viro | d161a13 | 2011-07-24 03:36:29 -0400 | [diff] [blame] | 174 | umode_t mode, struct proc_dir_entry *parent) { return NULL; } |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 175 | #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;}) |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 176 | #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;}) |
| 177 | #define proc_create_seq(name, mode, parent, ops) ({NULL;}) |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 178 | #define proc_create_single(name, mode, parent, show) ({NULL;}) |
| 179 | #define proc_create_single_data(name, mode, parent, show, data) ({NULL;}) |
Alexey Dobriyan | d56c0d4 | 2020-02-03 17:37:14 -0800 | [diff] [blame] | 180 | #define proc_create(name, mode, parent, proc_ops) ({NULL;}) |
| 181 | #define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;}) |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 182 | |
David Howells | 271a15e | 2013-04-12 00:38:51 +0100 | [diff] [blame] | 183 | static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {} |
| 184 | static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {} |
David Howells | c30480b | 2013-04-12 18:03:36 +0100 | [diff] [blame] | 185 | static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;} |
David Howells | 59d8053 | 2013-04-11 13:34:43 +0100 | [diff] [blame] | 186 | static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; } |
| 187 | |
| 188 | static inline void proc_remove(struct proc_dir_entry *de) {} |
| 189 | #define remove_proc_entry(name, parent) do {} while (0) |
| 190 | static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Christoph Hellwig | c350637 | 2018-04-10 19:42:55 +0200 | [diff] [blame] | 192 | #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;}) |
| 193 | #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;}) |
Christoph Hellwig | 3617d94 | 2018-04-13 20:38:35 +0200 | [diff] [blame] | 194 | #define proc_create_net_single(name, mode, parent, show, data) ({NULL;}) |
Christoph Hellwig | c350637 | 2018-04-10 19:42:55 +0200 | [diff] [blame] | 195 | |
Christian Brauner | 3eb39f4 | 2018-11-19 00:51:56 +0100 | [diff] [blame] | 196 | static inline struct pid *tgid_pidfd_to_pid(const struct file *file) |
| 197 | { |
| 198 | return ERR_PTR(-EBADF); |
| 199 | } |
| 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | #endif /* CONFIG_PROC_FS */ |
| 202 | |
Jeff Layton | f779002 | 2014-09-12 16:40:20 -0400 | [diff] [blame] | 203 | struct net; |
| 204 | |
David Howells | 270b5ac | 2013-04-12 02:48:30 +0100 | [diff] [blame] | 205 | static inline struct proc_dir_entry *proc_net_mkdir( |
| 206 | struct net *net, const char *name, struct proc_dir_entry *parent) |
| 207 | { |
Alexey Dobriyan | b202ac9 | 2020-12-15 20:42:39 -0800 | [diff] [blame] | 208 | return _proc_mkdir(name, 0, parent, net, true); |
David Howells | 270b5ac | 2013-04-12 02:48:30 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Andrey Vagin | c62cce2 | 2016-10-24 18:29:13 -0700 | [diff] [blame] | 211 | struct ns_common; |
| 212 | int open_related_ns(struct ns_common *ns, |
| 213 | struct ns_common *(*get_ns)(struct ns_common *ns)); |
| 214 | |
Christoph Hellwig | 76f668b | 2018-05-16 07:19:01 +0200 | [diff] [blame] | 215 | /* get the associated pid namespace for a file in procfs */ |
Alexey Gladkov | 9d78ede | 2020-05-18 20:07:38 +0200 | [diff] [blame] | 216 | static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) |
Christoph Hellwig | 76f668b | 2018-05-16 07:19:01 +0200 | [diff] [blame] | 217 | { |
Alexey Gladkov | 9d78ede | 2020-05-18 20:07:38 +0200 | [diff] [blame] | 218 | return proc_sb_info(sb)->pid_ns; |
Christoph Hellwig | 76f668b | 2018-05-16 07:19:01 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Christian Brauner | 303cc57 | 2020-05-05 16:04:31 +0200 | [diff] [blame] | 221 | bool proc_ns_file(const struct file *file); |
| 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | #endif /* _LINUX_PROC_FS_H */ |