blob: de407e7c3b55fdbd9b5d3cbe93585b1e417a3e20 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * The proc filesystem constants/structures
4 */
David Howells59d80532013-04-11 13:34:43 +01005#ifndef _LINUX_PROC_FS_H
6#define _LINUX_PROC_FS_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Alexey Dobriyand919b332020-04-06 20:09:01 -07008#include <linux/compiler.h>
David Howells59d80532013-04-11 13:34:43 +01009#include <linux/types.h>
10#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
David Howells59d80532013-04-11 13:34:43 +010012struct proc_dir_entry;
Christoph Hellwig3f3942a2018-05-15 15:57:23 +020013struct seq_file;
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020014struct seq_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Alexey Dobriyand919b332020-04-06 20:09:01 -070016enum {
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 Dobriyand56c0d42020-02-03 17:37:14 -080029struct proc_ops {
Alexey Dobriyand919b332020-04-06 20:09:01 -070030 unsigned int proc_flags;
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080031 int (*proc_open)(struct inode *, struct file *);
32 ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *);
Christoph Hellwigfd5a13f2020-09-03 16:22:31 +020033 ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *);
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080034 ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *);
Alexey Dobriyand4455fa2021-05-06 18:02:16 -070035 /* mandatory unless nonseekable_open() or equivalent is used */
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080036 loff_t (*proc_lseek)(struct file *, loff_t, int);
37 int (*proc_release)(struct inode *, struct file *);
38 __poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
39 long (*proc_ioctl)(struct file *, unsigned int, unsigned long);
40#ifdef CONFIG_COMPAT
41 long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long);
42#endif
43 int (*proc_mmap)(struct file *, struct vm_area_struct *);
44 unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
Alexey Dobriyand919b332020-04-06 20:09:01 -070045} __randomize_layout;
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080046
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020047/* definitions for hide_pid field */
Alexey Gladkove61bb8b2020-04-19 16:10:57 +020048enum proc_hidepid {
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020049 HIDEPID_OFF = 0,
50 HIDEPID_NO_ACCESS = 1,
51 HIDEPID_INVISIBLE = 2,
Alexey Gladkov24a71ce2020-04-19 16:10:53 +020052 HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020053};
54
Alexey Gladkov6814ef22020-04-19 16:10:54 +020055/* definitions for proc mount option pidonly */
Alexey Gladkove61bb8b2020-04-19 16:10:57 +020056enum proc_pidonly {
Alexey Gladkov6814ef22020-04-19 16:10:54 +020057 PROC_PIDONLY_OFF = 0,
58 PROC_PIDONLY_ON = 1,
59};
60
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020061struct proc_fs_info {
62 struct pid_namespace *pid_ns;
63 struct dentry *proc_self; /* For /proc/self */
64 struct dentry *proc_thread_self; /* For /proc/thread-self */
65 kgid_t pid_gid;
Alexey Gladkove61bb8b2020-04-19 16:10:57 +020066 enum proc_hidepid hide_pid;
67 enum proc_pidonly pidonly;
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020068};
69
70static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
71{
72 return sb->s_fs_info;
73}
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#ifdef CONFIG_PROC_FS
76
David Howells564def72018-05-18 11:46:15 +010077typedef int (*proc_write_t)(struct file *, char *, size_t);
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern void proc_root_init(void);
Eric W. Biederman7bc3e6e2020-02-19 18:22:26 -060080extern void proc_flush_pid(struct pid *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern struct proc_dir_entry *proc_symlink(const char *,
83 struct proc_dir_entry *, const char *);
Alexey Dobriyanc6c75de2020-12-15 20:42:39 -080084struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
David Howells59d80532013-04-11 13:34:43 +010085extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
David Howells270b5ac2013-04-12 02:48:30 +010086extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
87 struct proc_dir_entry *, void *);
David Howells59d80532013-04-11 13:34:43 +010088extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
89 struct proc_dir_entry *);
Seth Forsheef97df702016-11-14 11:12:56 +000090struct proc_dir_entry *proc_create_mount_point(const char *name);
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020091
Christoph Hellwig44414d82018-04-24 17:05:17 +020092struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020093 struct proc_dir_entry *parent, const struct seq_operations *ops,
Christoph Hellwig44414d82018-04-24 17:05:17 +020094 unsigned int state_size, void *data);
95#define proc_create_seq_data(name, mode, parent, ops, data) \
96 proc_create_seq_private(name, mode, parent, ops, 0, data)
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020097#define proc_create_seq(name, mode, parent, ops) \
Christoph Hellwig44414d82018-04-24 17:05:17 +020098 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
Christoph Hellwig3f3942a2018-05-15 15:57:23 +020099struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
100 struct proc_dir_entry *parent,
101 int (*show)(struct seq_file *, void *), void *data);
102#define proc_create_single(name, mode, parent, show) \
103 proc_create_single_data(name, mode, parent, show, NULL)
David Howells59d80532013-04-11 13:34:43 +0100104
105extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
106 struct proc_dir_entry *,
Alexey Dobriyand56c0d42020-02-03 17:37:14 -0800107 const struct proc_ops *,
David Howells59d80532013-04-11 13:34:43 +0100108 void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Alexey Dobriyand56c0d42020-02-03 17:37:14 -0800110struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
David Howells271a15e2013-04-12 00:38:51 +0100111extern void proc_set_size(struct proc_dir_entry *, loff_t);
112extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
Muchun Song6dfbbae2022-01-21 22:14:20 -0800113
114/*
115 * Obtain the private data passed by user through proc_create_data() or
116 * related.
117 */
118static inline void *pde_data(const struct inode *inode)
119{
120 return inode->i_private;
121}
122
David Howells4a520d22013-04-12 14:06:01 +0100123extern void *proc_get_parent_data(const struct inode *);
David Howells59d80532013-04-11 13:34:43 +0100124extern void proc_remove(struct proc_dir_entry *);
125extern void remove_proc_entry(const char *, struct proc_dir_entry *);
126extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
127
Christoph Hellwigc3506372018-04-10 19:42:55 +0200128struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
129 struct proc_dir_entry *parent, const struct seq_operations *ops,
130 unsigned int state_size, void *data);
Miaohe Lin9573e8f2019-12-04 16:50:08 -0800131#define proc_create_net(name, mode, parent, ops, state_size) \
132 proc_create_net_data(name, mode, parent, ops, state_size, NULL)
Christoph Hellwig3617d942018-04-13 20:38:35 +0200133struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
134 struct proc_dir_entry *parent,
135 int (*show)(struct seq_file *, void *), void *data);
David Howells564def72018-05-18 11:46:15 +0100136struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
137 struct proc_dir_entry *parent,
138 const struct seq_operations *ops,
139 proc_write_t write,
140 unsigned int state_size, void *data);
141struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
142 struct proc_dir_entry *parent,
143 int (*show)(struct seq_file *, void *),
144 proc_write_t write,
145 void *data);
Christian Brauner3eb39f42018-11-19 00:51:56 +0100146extern struct pid *tgid_pidfd_to_pid(const struct file *file);
Christoph Hellwigc3506372018-04-10 19:42:55 +0200147
Yonghong Songf9c79272020-07-23 11:41:10 -0700148struct bpf_iter_aux_info;
149extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
Yonghong Song138d0be2020-05-09 10:59:10 -0700150extern void bpf_iter_fini_seq_net(void *priv_data);
151
Aubrey Li68bc30b2019-06-06 09:22:34 +0800152#ifdef CONFIG_PROC_PID_ARCH_STATUS
153/*
154 * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
155 * provide proc_pid_arch_status() definition.
156 */
157int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
158 struct pid *pid, struct task_struct *task);
159#endif /* CONFIG_PROC_PID_ARCH_STATUS */
160
Arnd Bergmannef104442023-05-16 21:57:29 +0200161void arch_report_meminfo(struct seq_file *m);
Rick Edgecombe0ee44882023-06-12 17:11:02 -0700162void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task);
Arnd Bergmannef104442023-05-16 21:57:29 +0200163
David Howells59d80532013-04-11 13:34:43 +0100164#else /* CONFIG_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Andrew Morton647f0102014-06-04 16:12:20 -0700166static inline void proc_root_init(void)
167{
168}
169
Eric W. Biederman7bc3e6e2020-02-19 18:22:26 -0600170static inline void proc_flush_pid(struct pid *pid)
Pavel Emelyanov60347f62007-10-18 23:40:03 -0700171{
172}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174static inline struct proc_dir_entry *proc_symlink(const char *name,
David Howells59d80532013-04-11 13:34:43 +0100175 struct proc_dir_entry *parent,const char *dest) { return NULL;}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static inline struct proc_dir_entry *proc_mkdir(const char *name,
177 struct proc_dir_entry *parent) {return NULL;}
Seth Forsheef97df702016-11-14 11:12:56 +0000178static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
Alexey Dobriyanc6c75de2020-12-15 20:42:39 -0800179static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
180 struct proc_dir_entry *parent, void *data, bool force_lookup)
181{
182 return NULL;
183}
David Howells270b5ac2013-04-12 02:48:30 +0100184static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
185 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
Randy Dunlapf12a20f2011-05-17 15:44:12 -0700186static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
Al Virod161a132011-07-24 03:36:29 -0400187 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200188#define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200189#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
190#define proc_create_seq(name, mode, parent, ops) ({NULL;})
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200191#define proc_create_single(name, mode, parent, show) ({NULL;})
192#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
Hans de Goedeae62fbe2022-01-19 18:08:00 -0800193
194static inline struct proc_dir_entry *
195proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent,
196 const struct proc_ops *proc_ops)
197{ return NULL; }
198
199static inline struct proc_dir_entry *
200proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *parent,
201 const struct proc_ops *proc_ops, void *data)
202{ return NULL; }
David Howells59d80532013-04-11 13:34:43 +0100203
David Howells271a15e2013-04-12 00:38:51 +0100204static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
205static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
Muchun Song359745d2022-01-21 22:14:23 -0800206static inline void *pde_data(const struct inode *inode) {BUG(); return NULL;}
David Howells59d80532013-04-11 13:34:43 +0100207static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
208
209static inline void proc_remove(struct proc_dir_entry *de) {}
210#define remove_proc_entry(name, parent) do {} while (0)
211static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Christoph Hellwigc3506372018-04-10 19:42:55 +0200213#define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
David Howellsc3d96f62022-10-03 07:34:21 +0100214#define proc_create_net_data_write(name, mode, parent, ops, write, state_size, data) ({NULL;})
Christoph Hellwigc3506372018-04-10 19:42:55 +0200215#define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
Christoph Hellwig3617d942018-04-13 20:38:35 +0200216#define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
David Howellsc3d96f62022-10-03 07:34:21 +0100217#define proc_create_net_single_write(name, mode, parent, show, write, data) ({NULL;})
Christoph Hellwigc3506372018-04-10 19:42:55 +0200218
Christian Brauner3eb39f42018-11-19 00:51:56 +0100219static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
220{
221 return ERR_PTR(-EBADF);
222}
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224#endif /* CONFIG_PROC_FS */
225
Jeff Laytonf7790022014-09-12 16:40:20 -0400226struct net;
227
David Howells270b5ac2013-04-12 02:48:30 +0100228static inline struct proc_dir_entry *proc_net_mkdir(
229 struct net *net, const char *name, struct proc_dir_entry *parent)
230{
Alexey Dobriyanc6c75de2020-12-15 20:42:39 -0800231 return _proc_mkdir(name, 0, parent, net, true);
David Howells270b5ac2013-04-12 02:48:30 +0100232}
233
Andrey Vaginc62cce22016-10-24 18:29:13 -0700234struct ns_common;
235int open_related_ns(struct ns_common *ns,
236 struct ns_common *(*get_ns)(struct ns_common *ns));
237
Christoph Hellwig76f668b2018-05-16 07:19:01 +0200238/* get the associated pid namespace for a file in procfs */
Alexey Gladkov9d78ede2020-05-18 20:07:38 +0200239static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
Christoph Hellwig76f668b2018-05-16 07:19:01 +0200240{
Alexey Gladkov9d78ede2020-05-18 20:07:38 +0200241 return proc_sb_info(sb)->pid_ns;
Christoph Hellwig76f668b2018-05-16 07:19:01 +0200242}
243
Christian Brauner303cc572020-05-05 16:04:31 +0200244bool proc_ns_file(const struct file *file);
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246#endif /* _LINUX_PROC_FS_H */