GNU Linux-libre 5.10.217-gnu1
[releases.git] / include / linux / sysctl.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * sysctl.h: General linux system control interface
4  *
5  * Begun 24 March 1995, Stephen Tweedie
6  *
7  ****************************************************************
8  ****************************************************************
9  **
10  **  WARNING:
11  **  The values in this file are exported to user space via 
12  **  the sysctl() binary interface.  Do *NOT* change the
13  **  numbering of any existing values here, and do not change
14  **  any numbers within any one set of values.  If you have to
15  **  redefine an existing interface, use a new number for it.
16  **  The kernel will then return -ENOTDIR to any application using
17  **  the old binary interface.
18  **
19  ****************************************************************
20  ****************************************************************
21  */
22 #ifndef _LINUX_SYSCTL_H
23 #define _LINUX_SYSCTL_H
24
25 #include <linux/list.h>
26 #include <linux/rcupdate.h>
27 #include <linux/wait.h>
28 #include <linux/rbtree.h>
29 #include <linux/uidgid.h>
30 #include <uapi/linux/sysctl.h>
31
32 /* For the /proc/sys support */
33 struct completion;
34 struct ctl_table;
35 struct nsproxy;
36 struct ctl_table_root;
37 struct ctl_table_header;
38 struct ctl_dir;
39
40 /* Keep the same order as in fs/proc/proc_sysctl.c */
41 #define SYSCTL_NEG_ONE                  ((void *)&sysctl_vals[0])
42 #define SYSCTL_ZERO                     ((void *)&sysctl_vals[1])
43 #define SYSCTL_ONE                      ((void *)&sysctl_vals[2])
44 #define SYSCTL_TWO                      ((void *)&sysctl_vals[3])
45 #define SYSCTL_FOUR                     ((void *)&sysctl_vals[4])
46 #define SYSCTL_ONE_HUNDRED              ((void *)&sysctl_vals[5])
47 #define SYSCTL_TWO_HUNDRED              ((void *)&sysctl_vals[6])
48 #define SYSCTL_ONE_THOUSAND             ((void *)&sysctl_vals[7])
49 #define SYSCTL_THREE_THOUSAND           ((void *)&sysctl_vals[8])
50 #define SYSCTL_INT_MAX                  ((void *)&sysctl_vals[9])
51
52 extern const int sysctl_vals[];
53
54 typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer,
55                 size_t *lenp, loff_t *ppos);
56
57 int proc_dostring(struct ctl_table *, int, void *, size_t *, loff_t *);
58 int proc_dointvec(struct ctl_table *, int, void *, size_t *, loff_t *);
59 int proc_douintvec(struct ctl_table *, int, void *, size_t *, loff_t *);
60 int proc_dointvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
61 int proc_douintvec_minmax(struct ctl_table *table, int write, void *buffer,
62                 size_t *lenp, loff_t *ppos);
63 int proc_dou8vec_minmax(struct ctl_table *table, int write, void *buffer,
64                         size_t *lenp, loff_t *ppos);
65 int proc_dointvec_jiffies(struct ctl_table *, int, void *, size_t *, loff_t *);
66 int proc_dointvec_userhz_jiffies(struct ctl_table *, int, void *, size_t *,
67                 loff_t *);
68 int proc_dointvec_ms_jiffies(struct ctl_table *, int, void *, size_t *,
69                 loff_t *);
70 int proc_doulongvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
71 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int, void *,
72                 size_t *, loff_t *);
73 int proc_do_large_bitmap(struct ctl_table *, int, void *, size_t *, loff_t *);
74 int proc_do_static_key(struct ctl_table *table, int write, void *buffer,
75                 size_t *lenp, loff_t *ppos);
76
77 /*
78  * Register a set of sysctl names by calling register_sysctl_table
79  * with an initialised array of struct ctl_table's.  An entry with 
80  * NULL procname terminates the table.  table->de will be
81  * set up by the registration and need not be initialised in advance.
82  *
83  * sysctl names can be mirrored automatically under /proc/sys.  The
84  * procname supplied controls /proc naming.
85  *
86  * The table's mode will be honoured for proc-fs access.
87  *
88  * Leaf nodes in the sysctl tree will be represented by a single file
89  * under /proc; non-leaf nodes will be represented by directories.  A
90  * null procname disables /proc mirroring at this node.
91  *
92  * The data and maxlen fields of the ctl_table
93  * struct enable minimal validation of the values being written to be
94  * performed, and the mode field allows minimal authentication.
95  * 
96  * There must be a proc_handler routine for any terminal nodes
97  * mirrored under /proc/sys (non-terminals are handled by a built-in
98  * directory handler).  Several default handlers are available to
99  * cover common cases.
100  */
101
102 /* Support for userspace poll() to watch for changes */
103 struct ctl_table_poll {
104         atomic_t event;
105         wait_queue_head_t wait;
106 };
107
108 static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
109 {
110         return (void *)(unsigned long)atomic_read(&poll->event);
111 }
112
113 #define __CTL_TABLE_POLL_INITIALIZER(name) {                            \
114         .event = ATOMIC_INIT(0),                                        \
115         .wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait) }
116
117 #define DEFINE_CTL_TABLE_POLL(name)                                     \
118         struct ctl_table_poll name = __CTL_TABLE_POLL_INITIALIZER(name)
119
120 /* A sysctl table is an array of struct ctl_table: */
121 struct ctl_table {
122         const char *procname;           /* Text ID for /proc/sys, or zero */
123         void *data;
124         int maxlen;
125         umode_t mode;
126         struct ctl_table *child;        /* Deprecated */
127         proc_handler *proc_handler;     /* Callback for text formatting */
128         struct ctl_table_poll *poll;
129         void *extra1;
130         void *extra2;
131 } __randomize_layout;
132
133 struct ctl_node {
134         struct rb_node node;
135         struct ctl_table_header *header;
136 };
137
138 /* struct ctl_table_header is used to maintain dynamic lists of
139    struct ctl_table trees. */
140 struct ctl_table_header {
141         union {
142                 struct {
143                         struct ctl_table *ctl_table;
144                         int used;
145                         int count;
146                         int nreg;
147                 };
148                 struct rcu_head rcu;
149         };
150         struct completion *unregistering;
151         struct ctl_table *ctl_table_arg;
152         struct ctl_table_root *root;
153         struct ctl_table_set *set;
154         struct ctl_dir *parent;
155         struct ctl_node *node;
156         struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */
157 };
158
159 struct ctl_dir {
160         /* Header must be at the start of ctl_dir */
161         struct ctl_table_header header;
162         struct rb_root root;
163 };
164
165 struct ctl_table_set {
166         int (*is_seen)(struct ctl_table_set *);
167         struct ctl_dir dir;
168 };
169
170 struct ctl_table_root {
171         struct ctl_table_set default_set;
172         struct ctl_table_set *(*lookup)(struct ctl_table_root *root);
173         void (*set_ownership)(struct ctl_table_header *head,
174                               struct ctl_table *table,
175                               kuid_t *uid, kgid_t *gid);
176         int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
177 };
178
179 /* struct ctl_path describes where in the hierarchy a table is added */
180 struct ctl_path {
181         const char *procname;
182 };
183
184 #ifdef CONFIG_SYSCTL
185
186 void proc_sys_poll_notify(struct ctl_table_poll *poll);
187
188 extern void setup_sysctl_set(struct ctl_table_set *p,
189         struct ctl_table_root *root,
190         int (*is_seen)(struct ctl_table_set *));
191 extern void retire_sysctl_set(struct ctl_table_set *set);
192
193 struct ctl_table_header *__register_sysctl_table(
194         struct ctl_table_set *set,
195         const char *path, struct ctl_table *table);
196 struct ctl_table_header *__register_sysctl_paths(
197         struct ctl_table_set *set,
198         const struct ctl_path *path, struct ctl_table *table);
199 struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
200 struct ctl_table_header *register_sysctl_table(struct ctl_table * table);
201 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
202                                                 struct ctl_table *table);
203
204 void unregister_sysctl_table(struct ctl_table_header * table);
205
206 extern int sysctl_init(void);
207 extern void __register_sysctl_init(const char *path, struct ctl_table *table,
208                                  const char *table_name);
209 #define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table)
210 void do_sysctl_args(void);
211
212 extern int pwrsw_enabled;
213 extern int unaligned_enabled;
214 extern int unaligned_dump_stack;
215 extern int no_unaligned_warning;
216
217 extern struct ctl_table sysctl_mount_point[];
218 extern struct ctl_table random_table[];
219 extern struct ctl_table firmware_config_table[];
220 extern struct ctl_table epoll_table[];
221
222 #else /* CONFIG_SYSCTL */
223 static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
224 {
225         return NULL;
226 }
227
228 static inline struct ctl_table_header *register_sysctl_paths(
229                         const struct ctl_path *path, struct ctl_table *table)
230 {
231         return NULL;
232 }
233
234 static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
235 {
236         return NULL;
237 }
238
239 static inline void unregister_sysctl_table(struct ctl_table_header * table)
240 {
241 }
242
243 static inline void setup_sysctl_set(struct ctl_table_set *p,
244         struct ctl_table_root *root,
245         int (*is_seen)(struct ctl_table_set *))
246 {
247 }
248
249 static inline void do_sysctl_args(void)
250 {
251 }
252 #endif /* CONFIG_SYSCTL */
253
254 int sysctl_max_threads(struct ctl_table *table, int write, void *buffer,
255                 size_t *lenp, loff_t *ppos);
256
257 #endif /* _LINUX_SYSCTL_H */