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