1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * The proc filesystem constants/structures 4 */ 5 #ifndef _LINUX_PROC_FS_H 6 #define _LINUX_PROC_FS_H 7 8 #include <linux/compiler.h> 9 #include <linux/types.h> 10 #include <linux/fs.h> 11 12 struct proc_dir_entry; 13 struct seq_file; 14 struct seq_operations; 15 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 PROC_ENTRY_proc_read_iter = 1U << 1, 29 PROC_ENTRY_proc_compat_ioctl = 1U << 2, 30 PROC_ENTRY_proc_lseek = 1U << 3, 31 32 PROC_ENTRY_FORCE_LOOKUP = 1U << 7, 33 }; 34 35 struct proc_ops { 36 unsigned int proc_flags; 37 int (*proc_open)(struct inode *, struct file *); 38 ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *); 39 ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *); 40 ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *); 41 /* mandatory unless nonseekable_open() or equivalent is used */ 42 loff_t (*proc_lseek)(struct file *, loff_t, int); 43 int (*proc_release)(struct inode *, struct file *); 44 __poll_t (*proc_poll)(struct file *, struct poll_table_struct *); 45 long (*proc_ioctl)(struct file *, unsigned int, unsigned long); 46 #ifdef CONFIG_COMPAT 47 long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long); 48 #endif 49 int (*proc_mmap)(struct file *, struct vm_area_struct *); 50 unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); 51 } __randomize_layout; 52 53 /* definitions for hide_pid field */ 54 enum proc_hidepid { 55 HIDEPID_OFF = 0, 56 HIDEPID_NO_ACCESS = 1, 57 HIDEPID_INVISIBLE = 2, 58 HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */ 59 }; 60 61 /* definitions for proc mount option pidonly */ 62 enum proc_pidonly { 63 PROC_PIDONLY_OFF = 0, 64 PROC_PIDONLY_ON = 1, 65 }; 66 67 struct proc_fs_info { 68 struct pid_namespace *pid_ns; 69 kgid_t pid_gid; 70 const struct cred *mounter_cred; 71 enum proc_hidepid hide_pid; 72 enum proc_pidonly pidonly; 73 struct rcu_head rcu; 74 }; 75 76 static inline struct proc_fs_info *proc_sb_info(struct super_block *sb) 77 { 78 return sb->s_fs_info; 79 } 80 81 #ifdef CONFIG_PROC_FS 82 83 typedef int (*proc_write_t)(struct file *, char *, size_t); 84 85 extern void proc_root_init(void); 86 extern void proc_flush_pid(struct pid *); 87 88 extern struct proc_dir_entry *proc_symlink(const char *, 89 struct proc_dir_entry *, const char *); 90 struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool); 91 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *); 92 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t, 93 struct proc_dir_entry *, void *); 94 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t, 95 struct proc_dir_entry *); 96 struct proc_dir_entry *proc_create_mount_point(const char *name); 97 98 struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode, 99 struct proc_dir_entry *parent, const struct seq_operations *ops, 100 unsigned int state_size, void *data); 101 #define proc_create_seq_data(name, mode, parent, ops, data) \ 102 proc_create_seq_private(name, mode, parent, ops, 0, data) 103 #define proc_create_seq(name, mode, parent, ops) \ 104 proc_create_seq_private(name, mode, parent, ops, 0, NULL) 105 struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode, 106 struct proc_dir_entry *parent, 107 int (*show)(struct seq_file *, void *), void *data); 108 #define proc_create_single(name, mode, parent, show) \ 109 proc_create_single_data(name, mode, parent, show, NULL) 110 111 extern struct proc_dir_entry *proc_create_data(const char *, umode_t, 112 struct proc_dir_entry *, 113 const struct proc_ops *, 114 void *); 115 116 struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops); 117 extern void proc_set_size(struct proc_dir_entry *, loff_t); 118 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t); 119 120 /* 121 * Obtain the private data passed by user through proc_create_data() or 122 * related. 123 */ 124 static inline void *pde_data(const struct inode *inode) 125 { 126 return inode->i_private; 127 } 128 129 extern void *proc_get_parent_data(const struct inode *); 130 extern void proc_remove(struct proc_dir_entry *); 131 extern void remove_proc_entry(const char *, struct proc_dir_entry *); 132 extern int remove_proc_subtree(const char *, struct proc_dir_entry *); 133 134 struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode, 135 struct proc_dir_entry *parent, const struct seq_operations *ops, 136 unsigned int state_size, void *data); 137 #define proc_create_net(name, mode, parent, ops, state_size) \ 138 proc_create_net_data(name, mode, parent, ops, state_size, NULL) 139 struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode, 140 struct proc_dir_entry *parent, 141 int (*show)(struct seq_file *, void *), void *data); 142 struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode, 143 struct proc_dir_entry *parent, 144 const struct seq_operations *ops, 145 proc_write_t write, 146 unsigned int state_size, void *data); 147 struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode, 148 struct proc_dir_entry *parent, 149 int (*show)(struct seq_file *, void *), 150 proc_write_t write, 151 void *data); 152 extern struct pid *tgid_pidfd_to_pid(const struct file *file); 153 154 struct bpf_iter_aux_info; 155 extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux); 156 extern void bpf_iter_fini_seq_net(void *priv_data); 157 158 #ifdef CONFIG_PROC_PID_ARCH_STATUS 159 /* 160 * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must 161 * provide proc_pid_arch_status() definition. 162 */ 163 int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns, 164 struct pid *pid, struct task_struct *task); 165 #endif /* CONFIG_PROC_PID_ARCH_STATUS */ 166 167 void arch_report_meminfo(struct seq_file *m); 168 void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task); 169 170 #else /* CONFIG_PROC_FS */ 171 172 static inline void proc_root_init(void) 173 { 174 } 175 176 static inline void proc_flush_pid(struct pid *pid) 177 { 178 } 179 180 static inline struct proc_dir_entry *proc_symlink(const char *name, 181 struct proc_dir_entry *parent,const char *dest) { return NULL;} 182 static inline struct proc_dir_entry *proc_mkdir(const char *name, 183 struct proc_dir_entry *parent) {return NULL;} 184 static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; } 185 static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode, 186 struct proc_dir_entry *parent, void *data, bool force_lookup) 187 { 188 return NULL; 189 } 190 static inline struct proc_dir_entry *proc_mkdir_data(const char *name, 191 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; } 192 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name, 193 umode_t mode, struct proc_dir_entry *parent) { return NULL; } 194 #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;}) 195 #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;}) 196 #define proc_create_seq(name, mode, parent, ops) ({NULL;}) 197 #define proc_create_single(name, mode, parent, show) ({NULL;}) 198 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;}) 199 200 static inline struct proc_dir_entry * 201 proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, 202 const struct proc_ops *proc_ops) 203 { return NULL; } 204 205 static inline struct proc_dir_entry * 206 proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *parent, 207 const struct proc_ops *proc_ops, void *data) 208 { return NULL; } 209 210 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {} 211 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {} 212 static inline void *pde_data(const struct inode *inode) {BUG(); return NULL;} 213 static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; } 214 215 static inline void proc_remove(struct proc_dir_entry *de) {} 216 #define remove_proc_entry(name, parent) do {} while (0) 217 static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; } 218 219 #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;}) 220 #define proc_create_net_data_write(name, mode, parent, ops, write, state_size, data) ({NULL;}) 221 #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;}) 222 #define proc_create_net_single(name, mode, parent, show, data) ({NULL;}) 223 #define proc_create_net_single_write(name, mode, parent, show, write, data) ({NULL;}) 224 225 static inline struct pid *tgid_pidfd_to_pid(const struct file *file) 226 { 227 return ERR_PTR(-EBADF); 228 } 229 230 #endif /* CONFIG_PROC_FS */ 231 232 struct net; 233 234 static inline struct proc_dir_entry *proc_net_mkdir( 235 struct net *net, const char *name, struct proc_dir_entry *parent) 236 { 237 return _proc_mkdir(name, 0, parent, net, true); 238 } 239 240 struct ns_common; 241 int open_related_ns(struct ns_common *ns, 242 struct ns_common *(*get_ns)(struct ns_common *ns)); 243 244 /* get the associated pid namespace for a file in procfs */ 245 static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) 246 { 247 return proc_sb_info(sb)->pid_ns; 248 } 249 250 bool proc_ns_file(const struct file *file); 251 252 #if defined CONFIG_PROC_FS && !defined MODULE 253 void impl_proc_make_permanent(struct proc_dir_entry *pde); 254 #endif 255 256 static inline void proc_make_permanent(struct proc_dir_entry *pde) 257 { 258 /* Don't give matches to modules. */ 259 #if defined CONFIG_PROC_FS && !defined MODULE 260 impl_proc_make_permanent(pde); 261 #endif 262 } 263 264 #endif /* _LINUX_PROC_FS_H */ 265