• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_new[0])
42 #define SYSCTL_ZERO			((void *)&sysctl_vals_new[1])
43 #define SYSCTL_ONE			((void *)&sysctl_vals_new[2])
44 #define SYSCTL_TWO			((void *)&sysctl_vals_new[3])
45 #define SYSCTL_FOUR			((void *)&sysctl_vals_new[4])
46 #define SYSCTL_ONE_HUNDRED		((void *)&sysctl_vals_new[5])
47 #define SYSCTL_TWO_HUNDRED		((void *)&sysctl_vals_new[6])
48 #define SYSCTL_ONE_THOUSAND		((void *)&sysctl_vals_new[7])
49 #define SYSCTL_THREE_THOUSAND		((void *)&sysctl_vals_new[8])
50 #define SYSCTL_INT_MAX			((void *)&sysctl_vals_new[9])
51 
52 extern const int sysctl_vals[];
53 extern const int sysctl_vals_new[];
54 
55 typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer,
56 		size_t *lenp, loff_t *ppos);
57 
58 int proc_dostring(struct ctl_table *, int, void *, size_t *, loff_t *);
59 int proc_dobool(struct ctl_table *table, int write, void *buffer,
60 		size_t *lenp, loff_t *ppos);
61 int proc_dointvec(struct ctl_table *, int, void *, size_t *, loff_t *);
62 int proc_douintvec(struct ctl_table *, int, void *, size_t *, loff_t *);
63 int proc_dointvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
64 int proc_douintvec_minmax(struct ctl_table *table, int write, void *buffer,
65 		size_t *lenp, loff_t *ppos);
66 int proc_dou8vec_minmax(struct ctl_table *table, int write, void *buffer,
67 			size_t *lenp, loff_t *ppos);
68 int proc_dointvec_jiffies(struct ctl_table *, int, void *, size_t *, loff_t *);
69 int proc_dointvec_userhz_jiffies(struct ctl_table *, int, void *, size_t *,
70 		loff_t *);
71 int proc_dointvec_ms_jiffies(struct ctl_table *, int, void *, size_t *,
72 		loff_t *);
73 int proc_doulongvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
74 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int, void *,
75 		size_t *, loff_t *);
76 int proc_do_large_bitmap(struct ctl_table *, int, void *, size_t *, loff_t *);
77 int proc_do_static_key(struct ctl_table *table, int write, void *buffer,
78 		size_t *lenp, loff_t *ppos);
79 
80 /*
81  * Register a set of sysctl names by calling register_sysctl_table
82  * with an initialised array of struct ctl_table's.  An entry with
83  * NULL procname terminates the table.  table->de will be
84  * set up by the registration and need not be initialised in advance.
85  *
86  * sysctl names can be mirrored automatically under /proc/sys.  The
87  * procname supplied controls /proc naming.
88  *
89  * The table's mode will be honoured for proc-fs access.
90  *
91  * Leaf nodes in the sysctl tree will be represented by a single file
92  * under /proc; non-leaf nodes will be represented by directories.  A
93  * null procname disables /proc mirroring at this node.
94  *
95  * The data and maxlen fields of the ctl_table
96  * struct enable minimal validation of the values being written to be
97  * performed, and the mode field allows minimal authentication.
98  *
99  * There must be a proc_handler routine for any terminal nodes
100  * mirrored under /proc/sys (non-terminals are handled by a built-in
101  * directory handler).  Several default handlers are available to
102  * cover common cases.
103  */
104 
105 /* Support for userspace poll() to watch for changes */
106 struct ctl_table_poll {
107 	atomic_t event;
108 	wait_queue_head_t wait;
109 };
110 
proc_sys_poll_event(struct ctl_table_poll * poll)111 static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
112 {
113 	return (void *)(unsigned long)atomic_read(&poll->event);
114 }
115 
116 #define __CTL_TABLE_POLL_INITIALIZER(name) {				\
117 	.event = ATOMIC_INIT(0),					\
118 	.wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait) }
119 
120 #define DEFINE_CTL_TABLE_POLL(name)					\
121 	struct ctl_table_poll name = __CTL_TABLE_POLL_INITIALIZER(name)
122 
123 /* A sysctl table is an array of struct ctl_table: */
124 struct ctl_table {
125 	const char *procname;		/* Text ID for /proc/sys, or zero */
126 	void *data;
127 	int maxlen;
128 	umode_t mode;
129 	struct ctl_table *child;	/* Deprecated */
130 	proc_handler *proc_handler;	/* Callback for text formatting */
131 	struct ctl_table_poll *poll;
132 	void *extra1;
133 	void *extra2;
134 } __randomize_layout;
135 
136 struct ctl_node {
137 	struct rb_node node;
138 	struct ctl_table_header *header;
139 };
140 
141 /* struct ctl_table_header is used to maintain dynamic lists of
142    struct ctl_table trees. */
143 struct ctl_table_header {
144 	union {
145 		struct {
146 			struct ctl_table *ctl_table;
147 			int used;
148 			int count;
149 			int nreg;
150 		};
151 		struct rcu_head rcu;
152 	};
153 	struct completion *unregistering;
154 	struct ctl_table *ctl_table_arg;
155 	struct ctl_table_root *root;
156 	struct ctl_table_set *set;
157 	struct ctl_dir *parent;
158 	struct ctl_node *node;
159 	struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */
160 };
161 
162 struct ctl_dir {
163 	/* Header must be at the start of ctl_dir */
164 	struct ctl_table_header header;
165 	struct rb_root root;
166 };
167 
168 struct ctl_table_set {
169 	int (*is_seen)(struct ctl_table_set *);
170 	struct ctl_dir dir;
171 };
172 
173 struct ctl_table_root {
174 	struct ctl_table_set default_set;
175 	struct ctl_table_set *(*lookup)(struct ctl_table_root *root);
176 	void (*set_ownership)(struct ctl_table_header *head,
177 			      struct ctl_table *table,
178 			      kuid_t *uid, kgid_t *gid);
179 	int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
180 };
181 
182 /* struct ctl_path describes where in the hierarchy a table is added */
183 struct ctl_path {
184 	const char *procname;
185 };
186 
187 #ifdef CONFIG_SYSCTL
188 
189 void proc_sys_poll_notify(struct ctl_table_poll *poll);
190 
191 extern void setup_sysctl_set(struct ctl_table_set *p,
192 	struct ctl_table_root *root,
193 	int (*is_seen)(struct ctl_table_set *));
194 extern void retire_sysctl_set(struct ctl_table_set *set);
195 
196 struct ctl_table_header *__register_sysctl_table(
197 	struct ctl_table_set *set,
198 	const char *path, struct ctl_table *table);
199 struct ctl_table_header *__register_sysctl_paths(
200 	struct ctl_table_set *set,
201 	const struct ctl_path *path, struct ctl_table *table);
202 struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
203 struct ctl_table_header *register_sysctl_table(struct ctl_table * table);
204 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
205 						struct ctl_table *table);
206 
207 void unregister_sysctl_table(struct ctl_table_header * table);
208 
209 extern int sysctl_init(void);
210 extern void __register_sysctl_init(const char *path, struct ctl_table *table,
211 				 const char *table_name);
212 #define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table)
213 void do_sysctl_args(void);
214 bool sysctl_is_alias(char *param);
215 
216 extern int pwrsw_enabled;
217 extern int unaligned_enabled;
218 extern int unaligned_dump_stack;
219 extern int no_unaligned_warning;
220 
221 extern struct ctl_table sysctl_mount_point[];
222 extern struct ctl_table random_table[];
223 extern struct ctl_table firmware_config_table[];
224 extern struct ctl_table epoll_table[];
225 
226 #else /* CONFIG_SYSCTL */
register_sysctl_table(struct ctl_table * table)227 static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
228 {
229 	return NULL;
230 }
231 
register_sysctl_paths(const struct ctl_path * path,struct ctl_table * table)232 static inline struct ctl_table_header *register_sysctl_paths(
233 			const struct ctl_path *path, struct ctl_table *table)
234 {
235 	return NULL;
236 }
237 
register_sysctl(const char * path,struct ctl_table * table)238 static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
239 {
240 	return NULL;
241 }
242 
unregister_sysctl_table(struct ctl_table_header * table)243 static inline void unregister_sysctl_table(struct ctl_table_header * table)
244 {
245 }
246 
setup_sysctl_set(struct ctl_table_set * p,struct ctl_table_root * root,int (* is_seen)(struct ctl_table_set *))247 static inline void setup_sysctl_set(struct ctl_table_set *p,
248 	struct ctl_table_root *root,
249 	int (*is_seen)(struct ctl_table_set *))
250 {
251 }
252 
do_sysctl_args(void)253 static inline void do_sysctl_args(void)
254 {
255 }
256 
sysctl_is_alias(char * param)257 static inline bool sysctl_is_alias(char *param)
258 {
259 	return false;
260 }
261 #endif /* CONFIG_SYSCTL */
262 
263 int sysctl_max_threads(struct ctl_table *table, int write, void *buffer,
264 		size_t *lenp, loff_t *ppos);
265 
266 #endif /* _LINUX_SYSCTL_H */
267