blob: 000cc0533c3366abe4bea0acb9f0e700381706c8 [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 *);
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 Dobriyand919b332020-04-06 20:09:01 -070044} __randomize_layout;
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080045
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020046/* definitions for hide_pid field */
Alexey Gladkove61bb8b2020-04-19 16:10:57 +020047enum proc_hidepid {
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020048 HIDEPID_OFF = 0,
49 HIDEPID_NO_ACCESS = 1,
50 HIDEPID_INVISIBLE = 2,
Alexey Gladkov24a71ce2020-04-19 16:10:53 +020051 HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020052};
53
Alexey Gladkov6814ef22020-04-19 16:10:54 +020054/* definitions for proc mount option pidonly */
Alexey Gladkove61bb8b2020-04-19 16:10:57 +020055enum proc_pidonly {
Alexey Gladkov6814ef22020-04-19 16:10:54 +020056 PROC_PIDONLY_OFF = 0,
57 PROC_PIDONLY_ON = 1,
58};
59
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020060struct 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 Gladkove61bb8b2020-04-19 16:10:57 +020065 enum proc_hidepid hide_pid;
66 enum proc_pidonly pidonly;
Alexey Gladkovfa10fed2020-04-19 16:10:52 +020067};
68
69static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
70{
71 return sb->s_fs_info;
72}
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#ifdef CONFIG_PROC_FS
75
David Howells564def72018-05-18 11:46:15 +010076typedef int (*proc_write_t)(struct file *, char *, size_t);
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern void proc_root_init(void);
Eric W. Biederman7bc3e6e2020-02-19 18:22:26 -060079extern void proc_flush_pid(struct pid *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern struct proc_dir_entry *proc_symlink(const char *,
82 struct proc_dir_entry *, const char *);
Alexey Dobriyanb202ac92020-12-15 20:42:39 -080083struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
David Howells59d80532013-04-11 13:34:43 +010084extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
David Howells270b5ac2013-04-12 02:48:30 +010085extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
86 struct proc_dir_entry *, void *);
David Howells59d80532013-04-11 13:34:43 +010087extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
88 struct proc_dir_entry *);
Seth Forsheef97df702016-11-14 11:12:56 +000089struct proc_dir_entry *proc_create_mount_point(const char *name);
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020090
Christoph Hellwig44414d82018-04-24 17:05:17 +020091struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020092 struct proc_dir_entry *parent, const struct seq_operations *ops,
Christoph Hellwig44414d82018-04-24 17:05:17 +020093 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 Hellwigfddda2b2018-04-13 19:44:18 +020096#define proc_create_seq(name, mode, parent, ops) \
Christoph Hellwig44414d82018-04-24 17:05:17 +020097 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
Christoph Hellwig3f3942a2018-05-15 15:57:23 +020098struct 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 Howells59d80532013-04-11 13:34:43 +0100103
104extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
105 struct proc_dir_entry *,
Alexey Dobriyand56c0d42020-02-03 17:37:14 -0800106 const struct proc_ops *,
David Howells59d80532013-04-11 13:34:43 +0100107 void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Alexey Dobriyand56c0d42020-02-03 17:37:14 -0800109struct 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 +0100110extern void proc_set_size(struct proc_dir_entry *, loff_t);
111extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
David Howellsc30480b2013-04-12 18:03:36 +0100112extern void *PDE_DATA(const struct inode *);
David Howells4a520d22013-04-12 14:06:01 +0100113extern void *proc_get_parent_data(const struct inode *);
David Howells59d80532013-04-11 13:34:43 +0100114extern void proc_remove(struct proc_dir_entry *);
115extern void remove_proc_entry(const char *, struct proc_dir_entry *);
116extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
117
Christoph Hellwigc3506372018-04-10 19:42:55 +0200118struct 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 Lin9573e8f2019-12-04 16:50:08 -0800121#define proc_create_net(name, mode, parent, ops, state_size) \
122 proc_create_net_data(name, mode, parent, ops, state_size, NULL)
Christoph Hellwig3617d942018-04-13 20:38:35 +0200123struct 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 Howells564def72018-05-18 11:46:15 +0100126struct 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);
131struct 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 Brauner3eb39f42018-11-19 00:51:56 +0100136extern struct pid *tgid_pidfd_to_pid(const struct file *file);
Christoph Hellwigc3506372018-04-10 19:42:55 +0200137
Yonghong Songf9c79272020-07-23 11:41:10 -0700138struct bpf_iter_aux_info;
139extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
Yonghong Song138d0be2020-05-09 10:59:10 -0700140extern void bpf_iter_fini_seq_net(void *priv_data);
141
Aubrey Li68bc30b2019-06-06 09:22:34 +0800142#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 */
147int 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 Howells59d80532013-04-11 13:34:43 +0100151#else /* CONFIG_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Andrew Morton647f0102014-06-04 16:12:20 -0700153static inline void proc_root_init(void)
154{
155}
156
Eric W. Biederman7bc3e6e2020-02-19 18:22:26 -0600157static inline void proc_flush_pid(struct pid *pid)
Pavel Emelyanov60347f62007-10-18 23:40:03 -0700158{
159}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161static inline struct proc_dir_entry *proc_symlink(const char *name,
David Howells59d80532013-04-11 13:34:43 +0100162 struct proc_dir_entry *parent,const char *dest) { return NULL;}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static inline struct proc_dir_entry *proc_mkdir(const char *name,
164 struct proc_dir_entry *parent) {return NULL;}
Seth Forsheef97df702016-11-14 11:12:56 +0000165static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
Alexey Dobriyanb202ac92020-12-15 20:42:39 -0800166static 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 Howells270b5ac2013-04-12 02:48:30 +0100171static 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 Dunlapf12a20f2011-05-17 15:44:12 -0700173static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
Al Virod161a132011-07-24 03:36:29 -0400174 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200175#define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200176#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
177#define proc_create_seq(name, mode, parent, ops) ({NULL;})
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200178#define proc_create_single(name, mode, parent, show) ({NULL;})
179#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
Alexey Dobriyand56c0d42020-02-03 17:37:14 -0800180#define proc_create(name, mode, parent, proc_ops) ({NULL;})
181#define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;})
David Howells59d80532013-04-11 13:34:43 +0100182
David Howells271a15e2013-04-12 00:38:51 +0100183static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
184static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
David Howellsc30480b2013-04-12 18:03:36 +0100185static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
David Howells59d80532013-04-11 13:34:43 +0100186static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
187
188static inline void proc_remove(struct proc_dir_entry *de) {}
189#define remove_proc_entry(name, parent) do {} while (0)
190static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Christoph Hellwigc3506372018-04-10 19:42:55 +0200192#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 Hellwig3617d942018-04-13 20:38:35 +0200194#define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
Christoph Hellwigc3506372018-04-10 19:42:55 +0200195
Christian Brauner3eb39f42018-11-19 00:51:56 +0100196static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
197{
198 return ERR_PTR(-EBADF);
199}
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#endif /* CONFIG_PROC_FS */
202
Jeff Laytonf7790022014-09-12 16:40:20 -0400203struct net;
204
David Howells270b5ac2013-04-12 02:48:30 +0100205static inline struct proc_dir_entry *proc_net_mkdir(
206 struct net *net, const char *name, struct proc_dir_entry *parent)
207{
Alexey Dobriyanb202ac92020-12-15 20:42:39 -0800208 return _proc_mkdir(name, 0, parent, net, true);
David Howells270b5ac2013-04-12 02:48:30 +0100209}
210
Andrey Vaginc62cce22016-10-24 18:29:13 -0700211struct ns_common;
212int open_related_ns(struct ns_common *ns,
213 struct ns_common *(*get_ns)(struct ns_common *ns));
214
Christoph Hellwig76f668b2018-05-16 07:19:01 +0200215/* get the associated pid namespace for a file in procfs */
Alexey Gladkov9d78ede2020-05-18 20:07:38 +0200216static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
Christoph Hellwig76f668b2018-05-16 07:19:01 +0200217{
Alexey Gladkov9d78ede2020-05-18 20:07:38 +0200218 return proc_sb_info(sb)->pid_ns;
Christoph Hellwig76f668b2018-05-16 07:19:01 +0200219}
220
Christian Brauner303cc572020-05-05 16:04:31 +0200221bool proc_ns_file(const struct file *file);
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#endif /* _LINUX_PROC_FS_H */