]>
Commit | Line | Data |
---|---|---|
457c8996 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 LT |
2 | /* |
3 | * sysctl.c: General linux system control interface | |
4 | * | |
5 | * Begun 24 March 1995, Stephen Tweedie | |
6 | * Added /proc support, Dec 1995 | |
7 | * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. | |
8 | * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. | |
9 | * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver. | |
10 | * Dynamic registration fixes, Stephen Tweedie. | |
11 | * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn. | |
12 | * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris | |
13 | * Horn. | |
14 | * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer. | |
15 | * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer. | |
16 | * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill | |
17 | * Wendling. | |
18 | * The list_for_each() macro wasn't appropriate for the sysctl loop. | |
19 | * Removed it and replaced it with older style, 03/23/00, Bill Wendling | |
20 | */ | |
21 | ||
1da177e4 | 22 | #include <linux/module.h> |
e2e40f2c | 23 | #include <linux/aio.h> |
1da177e4 LT |
24 | #include <linux/mm.h> |
25 | #include <linux/swap.h> | |
26 | #include <linux/slab.h> | |
27 | #include <linux/sysctl.h> | |
5a04cca6 | 28 | #include <linux/bitmap.h> |
d33ed52d | 29 | #include <linux/signal.h> |
f39650de | 30 | #include <linux/panic.h> |
455cd5ab | 31 | #include <linux/printk.h> |
1da177e4 | 32 | #include <linux/proc_fs.h> |
72c2d582 | 33 | #include <linux/security.h> |
1da177e4 | 34 | #include <linux/ctype.h> |
fd4b616b | 35 | #include <linux/kmemleak.h> |
62239ac2 | 36 | #include <linux/fs.h> |
1da177e4 LT |
37 | #include <linux/init.h> |
38 | #include <linux/kernel.h> | |
0296b228 | 39 | #include <linux/kobject.h> |
20380731 | 40 | #include <linux/net.h> |
1da177e4 LT |
41 | #include <linux/sysrq.h> |
42 | #include <linux/highuid.h> | |
43 | #include <linux/writeback.h> | |
3fff4c42 | 44 | #include <linux/ratelimit.h> |
76ab0f53 | 45 | #include <linux/compaction.h> |
1da177e4 | 46 | #include <linux/hugetlb.h> |
1da177e4 | 47 | #include <linux/initrd.h> |
0b77f5bf | 48 | #include <linux/key.h> |
1da177e4 LT |
49 | #include <linux/times.h> |
50 | #include <linux/limits.h> | |
51 | #include <linux/dcache.h> | |
6e006701 | 52 | #include <linux/dnotify.h> |
1da177e4 | 53 | #include <linux/syscalls.h> |
c748e134 | 54 | #include <linux/vmstat.h> |
c255d844 PM |
55 | #include <linux/nfs_fs.h> |
56 | #include <linux/acpi.h> | |
10a0a8d4 | 57 | #include <linux/reboot.h> |
b0fc494f | 58 | #include <linux/ftrace.h> |
cdd6c482 | 59 | #include <linux/perf_event.h> |
b2be84df | 60 | #include <linux/kprobes.h> |
b492e95b | 61 | #include <linux/pipe_fs_i.h> |
8e4228e1 | 62 | #include <linux/oom.h> |
17f60a7d | 63 | #include <linux/kmod.h> |
73efc039 | 64 | #include <linux/capability.h> |
40401530 | 65 | #include <linux/binfmts.h> |
cf4aebc2 | 66 | #include <linux/sched/sysctl.h> |
f7ccbae4 | 67 | #include <linux/sched/coredump.h> |
7984754b | 68 | #include <linux/kexec.h> |
1be7f75d | 69 | #include <linux/bpf.h> |
d2921684 | 70 | #include <linux/mount.h> |
cefdca0a | 71 | #include <linux/userfaultfd_k.h> |
2374c09b CH |
72 | #include <linux/coredump.h> |
73 | #include <linux/latencytop.h> | |
74 | #include <linux/pid.h> | |
0cd7c741 | 75 | #include <linux/delayacct.h> |
34227646 | 76 | #include <linux/user_namespace.h> |
1da177e4 | 77 | |
7f2923c4 CB |
78 | #include "../lib/kstrtox.h" |
79 | ||
7c0f6ba6 | 80 | #include <linux/uaccess.h> |
1da177e4 LT |
81 | #include <asm/processor.h> |
82 | ||
29cbc78b AK |
83 | #ifdef CONFIG_X86 |
84 | #include <asm/nmi.h> | |
0741f4d2 | 85 | #include <asm/stacktrace.h> |
6e7c4025 | 86 | #include <asm/io.h> |
29cbc78b | 87 | #endif |
d550bbd4 DH |
88 | #ifdef CONFIG_SPARC |
89 | #include <asm/setup.h> | |
90 | #endif | |
c55b7c3e DY |
91 | #ifdef CONFIG_BSD_PROCESS_ACCT |
92 | #include <linux/acct.h> | |
93 | #endif | |
4f0e056f DY |
94 | #ifdef CONFIG_RT_MUTEXES |
95 | #include <linux/rtmutex.h> | |
96 | #endif | |
2edf5e49 DY |
97 | #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT) |
98 | #include <linux/lockdep.h> | |
99 | #endif | |
15485a46 DY |
100 | #ifdef CONFIG_CHR_DEV_SG |
101 | #include <scsi/sg.h> | |
102 | #endif | |
964c9dff AP |
103 | #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE |
104 | #include <linux/stackleak.h> | |
105 | #endif | |
58687acb | 106 | #ifdef CONFIG_LOCKUP_DETECTOR |
504d7cf1 DZ |
107 | #include <linux/nmi.h> |
108 | #endif | |
109 | ||
1da177e4 LT |
110 | #if defined(CONFIG_SYSCTL) |
111 | ||
c4f3b63f | 112 | /* Constants used for minimum and maximum */ |
2508ce18 | 113 | #ifdef CONFIG_LOCKUP_DETECTOR |
c4f3b63f RT |
114 | static int sixty = 60; |
115 | #endif | |
116 | ||
9002b214 | 117 | static unsigned long zero_ul; |
fc3501d4 | 118 | static unsigned long one_ul = 1; |
32a5ad9c | 119 | static unsigned long long_max = LONG_MAX; |
af91322e DY |
120 | #ifdef CONFIG_PRINTK |
121 | static int ten_thousand = 10000; | |
122 | #endif | |
c5dfd78e ACM |
123 | #ifdef CONFIG_PERF_EVENTS |
124 | static int six_hundred_forty_kb = 640 * 1024; | |
125 | #endif | |
c4f3b63f | 126 | |
9e4a5bda AR |
127 | /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */ |
128 | static unsigned long dirty_bytes_min = 2 * PAGE_SIZE; | |
129 | ||
1da177e4 LT |
130 | /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */ |
131 | static int maxolduid = 65535; | |
132 | static int minolduid; | |
133 | ||
134 | static int ngroups_max = NGROUPS_MAX; | |
73efc039 | 135 | static const int cap_last_cap = CAP_LAST_CAP; |
1da177e4 | 136 | |
a2e51445 DV |
137 | /* |
138 | * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs | |
139 | * and hung_task_check_interval_secs | |
140 | */ | |
80df2847 LH |
141 | #ifdef CONFIG_DETECT_HUNG_TASK |
142 | static unsigned long hung_task_timeout_max = (LONG_MAX/HZ); | |
143 | #endif | |
144 | ||
d14f1729 DY |
145 | #ifdef CONFIG_INOTIFY_USER |
146 | #include <linux/inotify.h> | |
147 | #endif | |
5b8fea65 AG |
148 | #ifdef CONFIG_FANOTIFY |
149 | #include <linux/fanotify.h> | |
150 | #endif | |
b6fca725 | 151 | |
d6f8ff73 | 152 | #ifdef CONFIG_PROC_SYSCTL |
f4aacea2 | 153 | |
a19ac337 LR |
154 | /** |
155 | * enum sysctl_writes_mode - supported sysctl write modes | |
156 | * | |
157 | * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value | |
65f50f25 WH |
158 | * to be written, and multiple writes on the same sysctl file descriptor |
159 | * will rewrite the sysctl value, regardless of file position. No warning | |
160 | * is issued when the initial position is not 0. | |
a19ac337 | 161 | * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is |
65f50f25 | 162 | * not 0. |
a19ac337 | 163 | * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at |
65f50f25 WH |
164 | * file position 0 and the value must be fully contained in the buffer |
165 | * sent to the write syscall. If dealing with strings respect the file | |
166 | * position, but restrict this to the max length of the buffer, anything | |
167 | * passed the max length will be ignored. Multiple writes will append | |
168 | * to the buffer. | |
a19ac337 LR |
169 | * |
170 | * These write modes control how current file position affects the behavior of | |
171 | * updating sysctl values through the proc interface on each write. | |
172 | */ | |
173 | enum sysctl_writes_mode { | |
174 | SYSCTL_WRITES_LEGACY = -1, | |
175 | SYSCTL_WRITES_WARN = 0, | |
176 | SYSCTL_WRITES_STRICT = 1, | |
177 | }; | |
f4aacea2 | 178 | |
a19ac337 | 179 | static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT; |
f461d2dc | 180 | #endif /* CONFIG_PROC_SYSCTL */ |
ceb18132 | 181 | |
67f3977f AG |
182 | #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ |
183 | defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) | |
1da177e4 LT |
184 | int sysctl_legacy_va_layout; |
185 | #endif | |
186 | ||
5e771905 MG |
187 | #ifdef CONFIG_COMPACTION |
188 | static int min_extfrag_threshold; | |
189 | static int max_extfrag_threshold = 1000; | |
190 | #endif | |
191 | ||
f461d2dc CH |
192 | #endif /* CONFIG_SYSCTL */ |
193 | ||
5447e8e0 | 194 | #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL) |
d46edd67 | 195 | static int bpf_stats_handler(struct ctl_table *table, int write, |
7787b6fc | 196 | void *buffer, size_t *lenp, loff_t *ppos) |
d46edd67 SL |
197 | { |
198 | struct static_key *key = (struct static_key *)table->data; | |
199 | static int saved_val; | |
200 | int val, ret; | |
201 | struct ctl_table tmp = { | |
202 | .data = &val, | |
203 | .maxlen = sizeof(val), | |
204 | .mode = table->mode, | |
205 | .extra1 = SYSCTL_ZERO, | |
206 | .extra2 = SYSCTL_ONE, | |
207 | }; | |
208 | ||
209 | if (write && !capable(CAP_SYS_ADMIN)) | |
210 | return -EPERM; | |
211 | ||
212 | mutex_lock(&bpf_stats_enabled_mutex); | |
213 | val = saved_val; | |
214 | ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); | |
215 | if (write && !ret && val != saved_val) { | |
216 | if (val) | |
217 | static_key_slow_inc(key); | |
218 | else | |
219 | static_key_slow_dec(key); | |
220 | saved_val = val; | |
221 | } | |
222 | mutex_unlock(&bpf_stats_enabled_mutex); | |
223 | return ret; | |
224 | } | |
08389d88 | 225 | |
534fcc9a JP |
226 | void __weak unpriv_ebpf_notify(int new_state) |
227 | { | |
228 | } | |
229 | ||
08389d88 DB |
230 | static int bpf_unpriv_handler(struct ctl_table *table, int write, |
231 | void *buffer, size_t *lenp, loff_t *ppos) | |
232 | { | |
233 | int ret, unpriv_enable = *(int *)table->data; | |
234 | bool locked_state = unpriv_enable == 1; | |
235 | struct ctl_table tmp = *table; | |
236 | ||
237 | if (write && !capable(CAP_SYS_ADMIN)) | |
238 | return -EPERM; | |
239 | ||
240 | tmp.data = &unpriv_enable; | |
241 | ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); | |
242 | if (write && !ret) { | |
243 | if (locked_state && unpriv_enable != 1) | |
244 | return -EPERM; | |
245 | *(int *)table->data = unpriv_enable; | |
246 | } | |
534fcc9a JP |
247 | |
248 | unpriv_ebpf_notify(unpriv_enable); | |
249 | ||
08389d88 DB |
250 | return ret; |
251 | } | |
252 | #endif /* CONFIG_BPF_SYSCALL && CONFIG_SYSCTL */ | |
d46edd67 | 253 | |
f461d2dc CH |
254 | /* |
255 | * /proc/sys support | |
256 | */ | |
257 | ||
b89a8171 | 258 | #ifdef CONFIG_PROC_SYSCTL |
1da177e4 | 259 | |
f8808300 | 260 | static int _proc_do_string(char *data, int maxlen, int write, |
32927393 | 261 | char *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
262 | { |
263 | size_t len; | |
32927393 | 264 | char c, *p; |
8d060877 ON |
265 | |
266 | if (!data || !maxlen || !*lenp) { | |
1da177e4 LT |
267 | *lenp = 0; |
268 | return 0; | |
269 | } | |
8d060877 | 270 | |
1da177e4 | 271 | if (write) { |
f4aacea2 KC |
272 | if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) { |
273 | /* Only continue writes not past the end of buffer. */ | |
274 | len = strlen(data); | |
275 | if (len > maxlen - 1) | |
276 | len = maxlen - 1; | |
277 | ||
278 | if (*ppos > len) | |
279 | return 0; | |
280 | len = *ppos; | |
281 | } else { | |
282 | /* Start writing from beginning of buffer. */ | |
283 | len = 0; | |
284 | } | |
285 | ||
2ca9bb45 | 286 | *ppos += *lenp; |
1da177e4 | 287 | p = buffer; |
2ca9bb45 | 288 | while ((p - buffer) < *lenp && len < maxlen - 1) { |
32927393 | 289 | c = *(p++); |
1da177e4 LT |
290 | if (c == 0 || c == '\n') |
291 | break; | |
2ca9bb45 | 292 | data[len++] = c; |
1da177e4 | 293 | } |
f8808300 | 294 | data[len] = 0; |
1da177e4 | 295 | } else { |
f5dd3d6f SV |
296 | len = strlen(data); |
297 | if (len > maxlen) | |
298 | len = maxlen; | |
8d060877 ON |
299 | |
300 | if (*ppos > len) { | |
301 | *lenp = 0; | |
302 | return 0; | |
303 | } | |
304 | ||
305 | data += *ppos; | |
306 | len -= *ppos; | |
307 | ||
1da177e4 LT |
308 | if (len > *lenp) |
309 | len = *lenp; | |
310 | if (len) | |
32927393 | 311 | memcpy(buffer, data, len); |
1da177e4 | 312 | if (len < *lenp) { |
32927393 | 313 | buffer[len] = '\n'; |
1da177e4 LT |
314 | len++; |
315 | } | |
316 | *lenp = len; | |
317 | *ppos += len; | |
318 | } | |
319 | return 0; | |
320 | } | |
321 | ||
f4aacea2 KC |
322 | static void warn_sysctl_write(struct ctl_table *table) |
323 | { | |
324 | pr_warn_once("%s wrote to %s when file position was not 0!\n" | |
325 | "This will not be supported in the future. To silence this\n" | |
326 | "warning, set kernel.sysctl_writes_strict = -1\n", | |
327 | current->comm, table->procname); | |
328 | } | |
329 | ||
d383d484 | 330 | /** |
5f733e8a | 331 | * proc_first_pos_non_zero_ignore - check if first position is allowed |
d383d484 LR |
332 | * @ppos: file position |
333 | * @table: the sysctl table | |
334 | * | |
335 | * Returns true if the first position is non-zero and the sysctl_writes_strict | |
336 | * mode indicates this is not allowed for numeric input types. String proc | |
5f733e8a | 337 | * handlers can ignore the return value. |
d383d484 LR |
338 | */ |
339 | static bool proc_first_pos_non_zero_ignore(loff_t *ppos, | |
340 | struct ctl_table *table) | |
341 | { | |
342 | if (!*ppos) | |
343 | return false; | |
344 | ||
345 | switch (sysctl_writes_strict) { | |
346 | case SYSCTL_WRITES_STRICT: | |
347 | return true; | |
348 | case SYSCTL_WRITES_WARN: | |
349 | warn_sysctl_write(table); | |
350 | return false; | |
351 | default: | |
352 | return false; | |
353 | } | |
354 | } | |
355 | ||
f5dd3d6f SV |
356 | /** |
357 | * proc_dostring - read a string sysctl | |
358 | * @table: the sysctl table | |
359 | * @write: %TRUE if this is a write to the sysctl file | |
f5dd3d6f SV |
360 | * @buffer: the user buffer |
361 | * @lenp: the size of the user buffer | |
362 | * @ppos: file position | |
363 | * | |
364 | * Reads/writes a string from/to the user buffer. If the kernel | |
365 | * buffer provided is not large enough to hold the string, the | |
366 | * string is truncated. The copied string is %NULL-terminated. | |
367 | * If the string is being read by the user process, it is copied | |
368 | * and a newline '\n' is added. It is truncated if the buffer is | |
369 | * not large enough. | |
370 | * | |
371 | * Returns 0 on success. | |
372 | */ | |
8d65af78 | 373 | int proc_dostring(struct ctl_table *table, int write, |
32927393 | 374 | void *buffer, size_t *lenp, loff_t *ppos) |
f5dd3d6f | 375 | { |
d383d484 LR |
376 | if (write) |
377 | proc_first_pos_non_zero_ignore(ppos, table); | |
f4aacea2 | 378 | |
32927393 CH |
379 | return _proc_do_string(table->data, table->maxlen, write, buffer, lenp, |
380 | ppos); | |
f5dd3d6f SV |
381 | } |
382 | ||
51644b2c | 383 | static void proc_skip_spaces(char **buf, size_t *size) |
00b7c339 | 384 | { |
51644b2c LT |
385 | while (*size) { |
386 | if (!isspace(**buf)) | |
387 | break; | |
388 | (*size)--; | |
389 | (*buf)++; | |
390 | } | |
00b7c339 AW |
391 | } |
392 | ||
9f977fb7 OP |
393 | static void proc_skip_char(char **buf, size_t *size, const char v) |
394 | { | |
395 | while (*size) { | |
396 | if (**buf != v) | |
397 | break; | |
398 | (*size)--; | |
399 | (*buf)++; | |
400 | } | |
401 | } | |
402 | ||
7f2923c4 CB |
403 | /** |
404 | * strtoul_lenient - parse an ASCII formatted integer from a buffer and only | |
405 | * fail on overflow | |
406 | * | |
407 | * @cp: kernel buffer containing the string to parse | |
408 | * @endp: pointer to store the trailing characters | |
409 | * @base: the base to use | |
410 | * @res: where the parsed integer will be stored | |
411 | * | |
412 | * In case of success 0 is returned and @res will contain the parsed integer, | |
413 | * @endp will hold any trailing characters. | |
414 | * This function will fail the parse on overflow. If there wasn't an overflow | |
415 | * the function will defer the decision what characters count as invalid to the | |
416 | * caller. | |
417 | */ | |
418 | static int strtoul_lenient(const char *cp, char **endp, unsigned int base, | |
419 | unsigned long *res) | |
420 | { | |
421 | unsigned long long result; | |
422 | unsigned int rv; | |
423 | ||
424 | cp = _parse_integer_fixup_radix(cp, &base); | |
425 | rv = _parse_integer(cp, base, &result); | |
426 | if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result)) | |
427 | return -ERANGE; | |
428 | ||
429 | cp += rv; | |
430 | ||
431 | if (endp) | |
432 | *endp = (char *)cp; | |
433 | ||
434 | *res = (unsigned long)result; | |
435 | return 0; | |
436 | } | |
437 | ||
00b7c339 AW |
438 | #define TMPBUFLEN 22 |
439 | /** | |
0fc377bd | 440 | * proc_get_long - reads an ASCII formatted integer from a user buffer |
00b7c339 | 441 | * |
0fc377bd RD |
442 | * @buf: a kernel buffer |
443 | * @size: size of the kernel buffer | |
444 | * @val: this is where the number will be stored | |
445 | * @neg: set to %TRUE if number is negative | |
446 | * @perm_tr: a vector which contains the allowed trailers | |
447 | * @perm_tr_len: size of the perm_tr vector | |
448 | * @tr: pointer to store the trailer character | |
00b7c339 | 449 | * |
0fc377bd RD |
450 | * In case of success %0 is returned and @buf and @size are updated with |
451 | * the amount of bytes read. If @tr is non-NULL and a trailing | |
452 | * character exists (size is non-zero after returning from this | |
453 | * function), @tr is updated with the trailing character. | |
00b7c339 AW |
454 | */ |
455 | static int proc_get_long(char **buf, size_t *size, | |
456 | unsigned long *val, bool *neg, | |
457 | const char *perm_tr, unsigned perm_tr_len, char *tr) | |
458 | { | |
00b7c339 | 459 | char *p, tmp[TMPBUFLEN]; |
2cd21ebb | 460 | ssize_t len = *size; |
00b7c339 | 461 | |
2cd21ebb | 462 | if (len <= 0) |
00b7c339 AW |
463 | return -EINVAL; |
464 | ||
00b7c339 AW |
465 | if (len > TMPBUFLEN - 1) |
466 | len = TMPBUFLEN - 1; | |
467 | ||
468 | memcpy(tmp, *buf, len); | |
469 | ||
470 | tmp[len] = 0; | |
471 | p = tmp; | |
472 | if (*p == '-' && *size > 1) { | |
473 | *neg = true; | |
474 | p++; | |
475 | } else | |
476 | *neg = false; | |
477 | if (!isdigit(*p)) | |
478 | return -EINVAL; | |
479 | ||
7f2923c4 CB |
480 | if (strtoul_lenient(p, &p, 0, val)) |
481 | return -EINVAL; | |
00b7c339 AW |
482 | |
483 | len = p - tmp; | |
484 | ||
485 | /* We don't know if the next char is whitespace thus we may accept | |
486 | * invalid integers (e.g. 1234...a) or two integers instead of one | |
487 | * (e.g. 123...1). So lets not allow such large numbers. */ | |
488 | if (len == TMPBUFLEN - 1) | |
489 | return -EINVAL; | |
490 | ||
491 | if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) | |
492 | return -EINVAL; | |
1da177e4 | 493 | |
00b7c339 AW |
494 | if (tr && (len < *size)) |
495 | *tr = *p; | |
496 | ||
497 | *buf += len; | |
498 | *size -= len; | |
499 | ||
500 | return 0; | |
501 | } | |
502 | ||
503 | /** | |
0fc377bd | 504 | * proc_put_long - converts an integer to a decimal ASCII formatted string |
00b7c339 | 505 | * |
0fc377bd RD |
506 | * @buf: the user buffer |
507 | * @size: the size of the user buffer | |
508 | * @val: the integer to be converted | |
509 | * @neg: sign of the number, %TRUE for negative | |
00b7c339 | 510 | * |
32927393 CH |
511 | * In case of success @buf and @size are updated with the amount of bytes |
512 | * written. | |
00b7c339 | 513 | */ |
32927393 | 514 | static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg) |
00b7c339 AW |
515 | { |
516 | int len; | |
517 | char tmp[TMPBUFLEN], *p = tmp; | |
518 | ||
519 | sprintf(p, "%s%lu", neg ? "-" : "", val); | |
520 | len = strlen(tmp); | |
521 | if (len > *size) | |
522 | len = *size; | |
32927393 | 523 | memcpy(*buf, tmp, len); |
00b7c339 AW |
524 | *size -= len; |
525 | *buf += len; | |
00b7c339 AW |
526 | } |
527 | #undef TMPBUFLEN | |
528 | ||
32927393 | 529 | static void proc_put_char(void **buf, size_t *size, char c) |
00b7c339 AW |
530 | { |
531 | if (*size) { | |
32927393 CH |
532 | char **buffer = (char **)buf; |
533 | **buffer = c; | |
534 | ||
535 | (*size)--; | |
536 | (*buffer)++; | |
00b7c339 AW |
537 | *buf = *buffer; |
538 | } | |
00b7c339 | 539 | } |
1da177e4 | 540 | |
a2071573 JH |
541 | static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp, |
542 | int *valp, | |
543 | int write, void *data) | |
544 | { | |
545 | if (write) { | |
546 | *(bool *)valp = *lvalp; | |
547 | } else { | |
548 | int val = *(bool *)valp; | |
549 | ||
550 | *lvalp = (unsigned long)val; | |
551 | *negp = false; | |
552 | } | |
553 | return 0; | |
554 | } | |
555 | ||
00b7c339 | 556 | static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
557 | int *valp, |
558 | int write, void *data) | |
559 | { | |
560 | if (write) { | |
230633d1 HS |
561 | if (*negp) { |
562 | if (*lvalp > (unsigned long) INT_MAX + 1) | |
563 | return -EINVAL; | |
c6bb43e2 | 564 | WRITE_ONCE(*valp, -*lvalp); |
230633d1 HS |
565 | } else { |
566 | if (*lvalp > (unsigned long) INT_MAX) | |
567 | return -EINVAL; | |
c6bb43e2 | 568 | WRITE_ONCE(*valp, *lvalp); |
230633d1 | 569 | } |
1da177e4 | 570 | } else { |
c6bb43e2 | 571 | int val = READ_ONCE(*valp); |
1da177e4 | 572 | if (val < 0) { |
00b7c339 | 573 | *negp = true; |
9a5bc726 | 574 | *lvalp = -(unsigned long)val; |
1da177e4 | 575 | } else { |
00b7c339 | 576 | *negp = false; |
1da177e4 LT |
577 | *lvalp = (unsigned long)val; |
578 | } | |
579 | } | |
580 | return 0; | |
581 | } | |
582 | ||
4f2fec00 LR |
583 | static int do_proc_douintvec_conv(unsigned long *lvalp, |
584 | unsigned int *valp, | |
585 | int write, void *data) | |
e7d316a0 SAK |
586 | { |
587 | if (write) { | |
425fffd8 LZ |
588 | if (*lvalp > UINT_MAX) |
589 | return -EINVAL; | |
34974c1c | 590 | WRITE_ONCE(*valp, *lvalp); |
e7d316a0 | 591 | } else { |
34974c1c | 592 | unsigned int val = READ_ONCE(*valp); |
e7d316a0 SAK |
593 | *lvalp = (unsigned long)val; |
594 | } | |
595 | return 0; | |
596 | } | |
597 | ||
00b7c339 AW |
598 | static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; |
599 | ||
d8217f07 | 600 | static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, |
32927393 | 601 | int write, void *buffer, |
fcfbd547 | 602 | size_t *lenp, loff_t *ppos, |
00b7c339 | 603 | int (*conv)(bool *negp, unsigned long *lvalp, int *valp, |
1da177e4 LT |
604 | int write, void *data), |
605 | void *data) | |
606 | { | |
00b7c339 | 607 | int *i, vleft, first = 1, err = 0; |
00b7c339 | 608 | size_t left; |
32927393 | 609 | char *p; |
1da177e4 | 610 | |
00b7c339 | 611 | if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { |
1da177e4 LT |
612 | *lenp = 0; |
613 | return 0; | |
614 | } | |
615 | ||
fcfbd547 | 616 | i = (int *) tbl_data; |
1da177e4 LT |
617 | vleft = table->maxlen / sizeof(*i); |
618 | left = *lenp; | |
619 | ||
620 | if (!conv) | |
621 | conv = do_proc_dointvec_conv; | |
622 | ||
00b7c339 | 623 | if (write) { |
d383d484 LR |
624 | if (proc_first_pos_non_zero_ignore(ppos, table)) |
625 | goto out; | |
f4aacea2 | 626 | |
00b7c339 AW |
627 | if (left > PAGE_SIZE - 1) |
628 | left = PAGE_SIZE - 1; | |
32927393 | 629 | p = buffer; |
00b7c339 AW |
630 | } |
631 | ||
1da177e4 | 632 | for (; left && vleft--; i++, first=0) { |
00b7c339 AW |
633 | unsigned long lval; |
634 | bool neg; | |
1da177e4 | 635 | |
00b7c339 | 636 | if (write) { |
51644b2c | 637 | proc_skip_spaces(&p, &left); |
1da177e4 | 638 | |
563b0467 O |
639 | if (!left) |
640 | break; | |
70f6cbb6 | 641 | err = proc_get_long(&p, &left, &lval, &neg, |
00b7c339 AW |
642 | proc_wspace_sep, |
643 | sizeof(proc_wspace_sep), NULL); | |
644 | if (err) | |
1da177e4 | 645 | break; |
00b7c339 AW |
646 | if (conv(&neg, &lval, i, 1, data)) { |
647 | err = -EINVAL; | |
1da177e4 | 648 | break; |
00b7c339 | 649 | } |
1da177e4 | 650 | } else { |
00b7c339 AW |
651 | if (conv(&neg, &lval, i, 0, data)) { |
652 | err = -EINVAL; | |
653 | break; | |
654 | } | |
1da177e4 | 655 | if (!first) |
32927393 CH |
656 | proc_put_char(&buffer, &left, '\t'); |
657 | proc_put_long(&buffer, &left, lval, neg); | |
1da177e4 LT |
658 | } |
659 | } | |
660 | ||
00b7c339 | 661 | if (!write && !first && left && !err) |
32927393 | 662 | proc_put_char(&buffer, &left, '\n'); |
563b0467 | 663 | if (write && !err && left) |
51644b2c | 664 | proc_skip_spaces(&p, &left); |
32927393 CH |
665 | if (write && first) |
666 | return err ? : -EINVAL; | |
1da177e4 | 667 | *lenp -= left; |
f4aacea2 | 668 | out: |
1da177e4 | 669 | *ppos += *lenp; |
00b7c339 | 670 | return err; |
1da177e4 LT |
671 | } |
672 | ||
8d65af78 | 673 | static int do_proc_dointvec(struct ctl_table *table, int write, |
32927393 | 674 | void *buffer, size_t *lenp, loff_t *ppos, |
00b7c339 | 675 | int (*conv)(bool *negp, unsigned long *lvalp, int *valp, |
fcfbd547 KK |
676 | int write, void *data), |
677 | void *data) | |
678 | { | |
8d65af78 | 679 | return __do_proc_dointvec(table->data, table, write, |
fcfbd547 KK |
680 | buffer, lenp, ppos, conv, data); |
681 | } | |
682 | ||
4f2fec00 LR |
683 | static int do_proc_douintvec_w(unsigned int *tbl_data, |
684 | struct ctl_table *table, | |
32927393 | 685 | void *buffer, |
4f2fec00 LR |
686 | size_t *lenp, loff_t *ppos, |
687 | int (*conv)(unsigned long *lvalp, | |
688 | unsigned int *valp, | |
689 | int write, void *data), | |
690 | void *data) | |
691 | { | |
692 | unsigned long lval; | |
693 | int err = 0; | |
694 | size_t left; | |
695 | bool neg; | |
32927393 | 696 | char *p = buffer; |
4f2fec00 LR |
697 | |
698 | left = *lenp; | |
699 | ||
700 | if (proc_first_pos_non_zero_ignore(ppos, table)) | |
701 | goto bail_early; | |
702 | ||
703 | if (left > PAGE_SIZE - 1) | |
704 | left = PAGE_SIZE - 1; | |
705 | ||
51644b2c | 706 | proc_skip_spaces(&p, &left); |
4f2fec00 LR |
707 | if (!left) { |
708 | err = -EINVAL; | |
709 | goto out_free; | |
710 | } | |
711 | ||
712 | err = proc_get_long(&p, &left, &lval, &neg, | |
713 | proc_wspace_sep, | |
714 | sizeof(proc_wspace_sep), NULL); | |
715 | if (err || neg) { | |
716 | err = -EINVAL; | |
717 | goto out_free; | |
718 | } | |
719 | ||
720 | if (conv(&lval, tbl_data, 1, data)) { | |
721 | err = -EINVAL; | |
722 | goto out_free; | |
723 | } | |
724 | ||
725 | if (!err && left) | |
51644b2c | 726 | proc_skip_spaces(&p, &left); |
4f2fec00 LR |
727 | |
728 | out_free: | |
4f2fec00 LR |
729 | if (err) |
730 | return -EINVAL; | |
731 | ||
732 | return 0; | |
733 | ||
734 | /* This is in keeping with old __do_proc_dointvec() */ | |
735 | bail_early: | |
736 | *ppos += *lenp; | |
737 | return err; | |
738 | } | |
739 | ||
32927393 | 740 | static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer, |
4f2fec00 LR |
741 | size_t *lenp, loff_t *ppos, |
742 | int (*conv)(unsigned long *lvalp, | |
743 | unsigned int *valp, | |
744 | int write, void *data), | |
745 | void *data) | |
746 | { | |
747 | unsigned long lval; | |
748 | int err = 0; | |
749 | size_t left; | |
750 | ||
751 | left = *lenp; | |
752 | ||
753 | if (conv(&lval, tbl_data, 0, data)) { | |
754 | err = -EINVAL; | |
755 | goto out; | |
756 | } | |
757 | ||
32927393 CH |
758 | proc_put_long(&buffer, &left, lval, false); |
759 | if (!left) | |
4f2fec00 LR |
760 | goto out; |
761 | ||
32927393 | 762 | proc_put_char(&buffer, &left, '\n'); |
4f2fec00 LR |
763 | |
764 | out: | |
765 | *lenp -= left; | |
766 | *ppos += *lenp; | |
767 | ||
768 | return err; | |
769 | } | |
770 | ||
771 | static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table, | |
32927393 | 772 | int write, void *buffer, |
4f2fec00 LR |
773 | size_t *lenp, loff_t *ppos, |
774 | int (*conv)(unsigned long *lvalp, | |
775 | unsigned int *valp, | |
776 | int write, void *data), | |
777 | void *data) | |
778 | { | |
779 | unsigned int *i, vleft; | |
780 | ||
781 | if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { | |
782 | *lenp = 0; | |
783 | return 0; | |
784 | } | |
785 | ||
786 | i = (unsigned int *) tbl_data; | |
787 | vleft = table->maxlen / sizeof(*i); | |
788 | ||
789 | /* | |
790 | * Arrays are not supported, keep this simple. *Do not* add | |
791 | * support for them. | |
792 | */ | |
793 | if (vleft != 1) { | |
794 | *lenp = 0; | |
795 | return -EINVAL; | |
796 | } | |
797 | ||
798 | if (!conv) | |
799 | conv = do_proc_douintvec_conv; | |
800 | ||
801 | if (write) | |
802 | return do_proc_douintvec_w(i, table, buffer, lenp, ppos, | |
803 | conv, data); | |
804 | return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data); | |
805 | } | |
806 | ||
807 | static int do_proc_douintvec(struct ctl_table *table, int write, | |
32927393 | 808 | void *buffer, size_t *lenp, loff_t *ppos, |
4f2fec00 LR |
809 | int (*conv)(unsigned long *lvalp, |
810 | unsigned int *valp, | |
811 | int write, void *data), | |
812 | void *data) | |
813 | { | |
814 | return __do_proc_douintvec(table->data, table, write, | |
815 | buffer, lenp, ppos, conv, data); | |
816 | } | |
817 | ||
a2071573 JH |
818 | /** |
819 | * proc_dobool - read/write a bool | |
820 | * @table: the sysctl table | |
821 | * @write: %TRUE if this is a write to the sysctl file | |
822 | * @buffer: the user buffer | |
823 | * @lenp: the size of the user buffer | |
824 | * @ppos: file position | |
825 | * | |
826 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
827 | * values from/to the user buffer, treated as an ASCII string. | |
828 | * | |
829 | * Returns 0 on success. | |
830 | */ | |
831 | int proc_dobool(struct ctl_table *table, int write, void *buffer, | |
832 | size_t *lenp, loff_t *ppos) | |
833 | { | |
834 | return do_proc_dointvec(table, write, buffer, lenp, ppos, | |
835 | do_proc_dobool_conv, NULL); | |
836 | } | |
837 | ||
1da177e4 LT |
838 | /** |
839 | * proc_dointvec - read a vector of integers | |
840 | * @table: the sysctl table | |
841 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
842 | * @buffer: the user buffer |
843 | * @lenp: the size of the user buffer | |
844 | * @ppos: file position | |
845 | * | |
846 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
847 | * values from/to the user buffer, treated as an ASCII string. | |
848 | * | |
849 | * Returns 0 on success. | |
850 | */ | |
32927393 CH |
851 | int proc_dointvec(struct ctl_table *table, int write, void *buffer, |
852 | size_t *lenp, loff_t *ppos) | |
1da177e4 | 853 | { |
e7d316a0 SAK |
854 | return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL); |
855 | } | |
856 | ||
6923aa0d SAS |
857 | #ifdef CONFIG_COMPACTION |
858 | static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table, | |
32927393 | 859 | int write, void *buffer, size_t *lenp, loff_t *ppos) |
6923aa0d SAS |
860 | { |
861 | int ret, old; | |
862 | ||
863 | if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write) | |
864 | return proc_dointvec_minmax(table, write, buffer, lenp, ppos); | |
865 | ||
866 | old = *(int *)table->data; | |
867 | ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); | |
868 | if (ret) | |
869 | return ret; | |
870 | if (old != *(int *)table->data) | |
871 | pr_warn_once("sysctl attribute %s changed by %s[%d]\n", | |
872 | table->procname, current->comm, | |
873 | task_pid_nr(current)); | |
874 | return ret; | |
875 | } | |
876 | #endif | |
877 | ||
e7d316a0 SAK |
878 | /** |
879 | * proc_douintvec - read a vector of unsigned integers | |
880 | * @table: the sysctl table | |
881 | * @write: %TRUE if this is a write to the sysctl file | |
882 | * @buffer: the user buffer | |
883 | * @lenp: the size of the user buffer | |
884 | * @ppos: file position | |
885 | * | |
886 | * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer | |
887 | * values from/to the user buffer, treated as an ASCII string. | |
888 | * | |
889 | * Returns 0 on success. | |
890 | */ | |
32927393 CH |
891 | int proc_douintvec(struct ctl_table *table, int write, void *buffer, |
892 | size_t *lenp, loff_t *ppos) | |
e7d316a0 | 893 | { |
4f2fec00 LR |
894 | return do_proc_douintvec(table, write, buffer, lenp, ppos, |
895 | do_proc_douintvec_conv, NULL); | |
1da177e4 LT |
896 | } |
897 | ||
34f5a398 | 898 | /* |
25ddbb18 AK |
899 | * Taint values can only be increased |
900 | * This means we can safely use a temporary. | |
34f5a398 | 901 | */ |
8d65af78 | 902 | static int proc_taint(struct ctl_table *table, int write, |
32927393 | 903 | void *buffer, size_t *lenp, loff_t *ppos) |
34f5a398 | 904 | { |
25ddbb18 AK |
905 | struct ctl_table t; |
906 | unsigned long tmptaint = get_taint(); | |
907 | int err; | |
34f5a398 | 908 | |
91fcd412 | 909 | if (write && !capable(CAP_SYS_ADMIN)) |
34f5a398 TT |
910 | return -EPERM; |
911 | ||
25ddbb18 AK |
912 | t = *table; |
913 | t.data = &tmptaint; | |
8d65af78 | 914 | err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos); |
25ddbb18 AK |
915 | if (err < 0) |
916 | return err; | |
917 | ||
918 | if (write) { | |
db38d5c1 RA |
919 | int i; |
920 | ||
921 | /* | |
922 | * If we are relying on panic_on_taint not producing | |
923 | * false positives due to userspace input, bail out | |
924 | * before setting the requested taint flags. | |
925 | */ | |
926 | if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint)) | |
927 | return -EINVAL; | |
928 | ||
25ddbb18 AK |
929 | /* |
930 | * Poor man's atomic or. Not worth adding a primitive | |
931 | * to everyone's atomic.h for this | |
932 | */ | |
e77132e7 RA |
933 | for (i = 0; i < TAINT_FLAGS_COUNT; i++) |
934 | if ((1UL << i) & tmptaint) | |
373d4d09 | 935 | add_taint(i, LOCKDEP_STILL_OK); |
25ddbb18 AK |
936 | } |
937 | ||
938 | return err; | |
34f5a398 TT |
939 | } |
940 | ||
bfdc0b49 | 941 | #ifdef CONFIG_PRINTK |
620f6e8e | 942 | static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write, |
32927393 | 943 | void *buffer, size_t *lenp, loff_t *ppos) |
bfdc0b49 RW |
944 | { |
945 | if (write && !capable(CAP_SYS_ADMIN)) | |
946 | return -EPERM; | |
947 | ||
948 | return proc_dointvec_minmax(table, write, buffer, lenp, ppos); | |
949 | } | |
950 | #endif | |
951 | ||
24704f36 WL |
952 | /** |
953 | * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure | |
954 | * @min: pointer to minimum allowable value | |
955 | * @max: pointer to maximum allowable value | |
956 | * | |
957 | * The do_proc_dointvec_minmax_conv_param structure provides the | |
958 | * minimum and maximum values for doing range checking for those sysctl | |
959 | * parameters that use the proc_dointvec_minmax() handler. | |
960 | */ | |
1da177e4 LT |
961 | struct do_proc_dointvec_minmax_conv_param { |
962 | int *min; | |
963 | int *max; | |
964 | }; | |
965 | ||
00b7c339 AW |
966 | static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, |
967 | int *valp, | |
1da177e4 LT |
968 | int write, void *data) |
969 | { | |
2bc4fc60 | 970 | int tmp, ret; |
1da177e4 | 971 | struct do_proc_dointvec_minmax_conv_param *param = data; |
2bc4fc60 ZW |
972 | /* |
973 | * If writing, first do so via a temporary local int so we can | |
974 | * bounds-check it before touching *valp. | |
975 | */ | |
976 | int *ip = write ? &tmp : valp; | |
977 | ||
978 | ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data); | |
979 | if (ret) | |
980 | return ret; | |
981 | ||
1da177e4 | 982 | if (write) { |
2bc4fc60 ZW |
983 | if ((param->min && *param->min > tmp) || |
984 | (param->max && *param->max < tmp)) | |
1da177e4 | 985 | return -EINVAL; |
b8fe1497 | 986 | WRITE_ONCE(*valp, tmp); |
1da177e4 | 987 | } |
2bc4fc60 | 988 | |
1da177e4 LT |
989 | return 0; |
990 | } | |
991 | ||
992 | /** | |
993 | * proc_dointvec_minmax - read a vector of integers with min/max values | |
994 | * @table: the sysctl table | |
995 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
996 | * @buffer: the user buffer |
997 | * @lenp: the size of the user buffer | |
998 | * @ppos: file position | |
999 | * | |
1000 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
1001 | * values from/to the user buffer, treated as an ASCII string. | |
1002 | * | |
1003 | * This routine will ensure the values are within the range specified by | |
1004 | * table->extra1 (min) and table->extra2 (max). | |
1005 | * | |
24704f36 | 1006 | * Returns 0 on success or -EINVAL on write when the range check fails. |
1da177e4 | 1007 | */ |
8d65af78 | 1008 | int proc_dointvec_minmax(struct ctl_table *table, int write, |
32927393 | 1009 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
1010 | { |
1011 | struct do_proc_dointvec_minmax_conv_param param = { | |
1012 | .min = (int *) table->extra1, | |
1013 | .max = (int *) table->extra2, | |
1014 | }; | |
8d65af78 | 1015 | return do_proc_dointvec(table, write, buffer, lenp, ppos, |
1da177e4 LT |
1016 | do_proc_dointvec_minmax_conv, ¶m); |
1017 | } | |
1018 | ||
24704f36 WL |
1019 | /** |
1020 | * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure | |
1021 | * @min: pointer to minimum allowable value | |
1022 | * @max: pointer to maximum allowable value | |
1023 | * | |
1024 | * The do_proc_douintvec_minmax_conv_param structure provides the | |
1025 | * minimum and maximum values for doing range checking for those sysctl | |
1026 | * parameters that use the proc_douintvec_minmax() handler. | |
1027 | */ | |
61d9b56a LR |
1028 | struct do_proc_douintvec_minmax_conv_param { |
1029 | unsigned int *min; | |
1030 | unsigned int *max; | |
1031 | }; | |
1032 | ||
1033 | static int do_proc_douintvec_minmax_conv(unsigned long *lvalp, | |
1034 | unsigned int *valp, | |
1035 | int write, void *data) | |
1036 | { | |
2bc4fc60 ZW |
1037 | int ret; |
1038 | unsigned int tmp; | |
61d9b56a | 1039 | struct do_proc_douintvec_minmax_conv_param *param = data; |
2bc4fc60 ZW |
1040 | /* write via temporary local uint for bounds-checking */ |
1041 | unsigned int *up = write ? &tmp : valp; | |
61d9b56a | 1042 | |
2bc4fc60 ZW |
1043 | ret = do_proc_douintvec_conv(lvalp, up, write, data); |
1044 | if (ret) | |
1045 | return ret; | |
fb910c42 | 1046 | |
2bc4fc60 ZW |
1047 | if (write) { |
1048 | if ((param->min && *param->min > tmp) || | |
1049 | (param->max && *param->max < tmp)) | |
61d9b56a LR |
1050 | return -ERANGE; |
1051 | ||
1a35c986 | 1052 | WRITE_ONCE(*valp, tmp); |
61d9b56a LR |
1053 | } |
1054 | ||
1055 | return 0; | |
1056 | } | |
1057 | ||
1058 | /** | |
1059 | * proc_douintvec_minmax - read a vector of unsigned ints with min/max values | |
1060 | * @table: the sysctl table | |
1061 | * @write: %TRUE if this is a write to the sysctl file | |
1062 | * @buffer: the user buffer | |
1063 | * @lenp: the size of the user buffer | |
1064 | * @ppos: file position | |
1065 | * | |
1066 | * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer | |
1067 | * values from/to the user buffer, treated as an ASCII string. Negative | |
1068 | * strings are not allowed. | |
1069 | * | |
1070 | * This routine will ensure the values are within the range specified by | |
1071 | * table->extra1 (min) and table->extra2 (max). There is a final sanity | |
1072 | * check for UINT_MAX to avoid having to support wrap around uses from | |
1073 | * userspace. | |
1074 | * | |
24704f36 | 1075 | * Returns 0 on success or -ERANGE on write when the range check fails. |
61d9b56a LR |
1076 | */ |
1077 | int proc_douintvec_minmax(struct ctl_table *table, int write, | |
32927393 | 1078 | void *buffer, size_t *lenp, loff_t *ppos) |
61d9b56a LR |
1079 | { |
1080 | struct do_proc_douintvec_minmax_conv_param param = { | |
1081 | .min = (unsigned int *) table->extra1, | |
1082 | .max = (unsigned int *) table->extra2, | |
1083 | }; | |
1084 | return do_proc_douintvec(table, write, buffer, lenp, ppos, | |
1085 | do_proc_douintvec_minmax_conv, ¶m); | |
1086 | } | |
1087 | ||
cb944413 ED |
1088 | /** |
1089 | * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values | |
1090 | * @table: the sysctl table | |
1091 | * @write: %TRUE if this is a write to the sysctl file | |
1092 | * @buffer: the user buffer | |
1093 | * @lenp: the size of the user buffer | |
1094 | * @ppos: file position | |
1095 | * | |
1096 | * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars | |
1097 | * values from/to the user buffer, treated as an ASCII string. Negative | |
1098 | * strings are not allowed. | |
1099 | * | |
1100 | * This routine will ensure the values are within the range specified by | |
1101 | * table->extra1 (min) and table->extra2 (max). | |
1102 | * | |
1103 | * Returns 0 on success or an error on write when the range check fails. | |
1104 | */ | |
1105 | int proc_dou8vec_minmax(struct ctl_table *table, int write, | |
1106 | void *buffer, size_t *lenp, loff_t *ppos) | |
1107 | { | |
1108 | struct ctl_table tmp; | |
1109 | unsigned int min = 0, max = 255U, val; | |
1110 | u8 *data = table->data; | |
1111 | struct do_proc_douintvec_minmax_conv_param param = { | |
1112 | .min = &min, | |
1113 | .max = &max, | |
1114 | }; | |
1115 | int res; | |
1116 | ||
1117 | /* Do not support arrays yet. */ | |
1118 | if (table->maxlen != sizeof(u8)) | |
1119 | return -EINVAL; | |
1120 | ||
1121 | if (table->extra1) { | |
1122 | min = *(unsigned int *) table->extra1; | |
1123 | if (min > 255U) | |
1124 | return -EINVAL; | |
1125 | } | |
1126 | if (table->extra2) { | |
1127 | max = *(unsigned int *) table->extra2; | |
1128 | if (max > 255U) | |
1129 | return -EINVAL; | |
1130 | } | |
1131 | ||
1132 | tmp = *table; | |
1133 | ||
1134 | tmp.maxlen = sizeof(val); | |
1135 | tmp.data = &val; | |
d6b0becd | 1136 | val = READ_ONCE(*data); |
cb944413 ED |
1137 | res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos, |
1138 | do_proc_douintvec_minmax_conv, ¶m); | |
1139 | if (res) | |
1140 | return res; | |
1141 | if (write) | |
d6b0becd | 1142 | WRITE_ONCE(*data, val); |
cb944413 ED |
1143 | return 0; |
1144 | } | |
1145 | EXPORT_SYMBOL_GPL(proc_dou8vec_minmax); | |
1146 | ||
7a8d1819 JL |
1147 | static int do_proc_dopipe_max_size_conv(unsigned long *lvalp, |
1148 | unsigned int *valp, | |
1149 | int write, void *data) | |
1150 | { | |
7a8d1819 | 1151 | if (write) { |
fb910c42 | 1152 | unsigned int val; |
7a8d1819 | 1153 | |
fb910c42 | 1154 | val = round_pipe_size(*lvalp); |
7a8d1819 JL |
1155 | if (val == 0) |
1156 | return -EINVAL; | |
1157 | ||
7a8d1819 JL |
1158 | *valp = val; |
1159 | } else { | |
1160 | unsigned int val = *valp; | |
1161 | *lvalp = (unsigned long) val; | |
1162 | } | |
1163 | ||
1164 | return 0; | |
1165 | } | |
1166 | ||
319e0a21 | 1167 | static int proc_dopipe_max_size(struct ctl_table *table, int write, |
32927393 | 1168 | void *buffer, size_t *lenp, loff_t *ppos) |
7a8d1819 | 1169 | { |
7a8d1819 | 1170 | return do_proc_douintvec(table, write, buffer, lenp, ppos, |
4c2e4bef | 1171 | do_proc_dopipe_max_size_conv, NULL); |
7a8d1819 JL |
1172 | } |
1173 | ||
54b50199 KC |
1174 | static void validate_coredump_safety(void) |
1175 | { | |
046d662f | 1176 | #ifdef CONFIG_COREDUMP |
e579d2c2 | 1177 | if (suid_dumpable == SUID_DUMP_ROOT && |
54b50199 | 1178 | core_pattern[0] != '/' && core_pattern[0] != '|') { |
760c6a91 AD |
1179 | printk(KERN_WARNING |
1180 | "Unsafe core_pattern used with fs.suid_dumpable=2.\n" | |
1181 | "Pipe handler or fully qualified core dump path required.\n" | |
1182 | "Set kernel.core_pattern before fs.suid_dumpable.\n" | |
1183 | ); | |
54b50199 | 1184 | } |
046d662f | 1185 | #endif |
54b50199 KC |
1186 | } |
1187 | ||
1188 | static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write, | |
32927393 | 1189 | void *buffer, size_t *lenp, loff_t *ppos) |
54b50199 KC |
1190 | { |
1191 | int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos); | |
1192 | if (!error) | |
1193 | validate_coredump_safety(); | |
1194 | return error; | |
1195 | } | |
1196 | ||
046d662f | 1197 | #ifdef CONFIG_COREDUMP |
54b50199 | 1198 | static int proc_dostring_coredump(struct ctl_table *table, int write, |
32927393 | 1199 | void *buffer, size_t *lenp, loff_t *ppos) |
54b50199 KC |
1200 | { |
1201 | int error = proc_dostring(table, write, buffer, lenp, ppos); | |
1202 | if (!error) | |
1203 | validate_coredump_safety(); | |
1204 | return error; | |
1205 | } | |
046d662f | 1206 | #endif |
54b50199 | 1207 | |
eaee4172 DS |
1208 | #ifdef CONFIG_MAGIC_SYSRQ |
1209 | static int sysrq_sysctl_handler(struct ctl_table *table, int write, | |
32927393 | 1210 | void *buffer, size_t *lenp, loff_t *ppos) |
eaee4172 DS |
1211 | { |
1212 | int tmp, ret; | |
1213 | ||
1214 | tmp = sysrq_mask(); | |
1215 | ||
1216 | ret = __do_proc_dointvec(&tmp, table, write, buffer, | |
1217 | lenp, ppos, NULL, NULL); | |
1218 | if (ret || !write) | |
1219 | return ret; | |
1220 | ||
1221 | if (write) | |
1222 | sysrq_toggle_support(tmp); | |
1223 | ||
1224 | return 0; | |
1225 | } | |
1226 | #endif | |
1227 | ||
32927393 CH |
1228 | static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, |
1229 | int write, void *buffer, size_t *lenp, loff_t *ppos, | |
1230 | unsigned long convmul, unsigned long convdiv) | |
1da177e4 | 1231 | { |
00b7c339 AW |
1232 | unsigned long *i, *min, *max; |
1233 | int vleft, first = 1, err = 0; | |
00b7c339 | 1234 | size_t left; |
32927393 | 1235 | char *p; |
00b7c339 AW |
1236 | |
1237 | if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { | |
1da177e4 LT |
1238 | *lenp = 0; |
1239 | return 0; | |
1240 | } | |
00b7c339 | 1241 | |
fcfbd547 | 1242 | i = (unsigned long *) data; |
1da177e4 LT |
1243 | min = (unsigned long *) table->extra1; |
1244 | max = (unsigned long *) table->extra2; | |
1245 | vleft = table->maxlen / sizeof(unsigned long); | |
1246 | left = *lenp; | |
00b7c339 AW |
1247 | |
1248 | if (write) { | |
d383d484 LR |
1249 | if (proc_first_pos_non_zero_ignore(ppos, table)) |
1250 | goto out; | |
f4aacea2 | 1251 | |
00b7c339 AW |
1252 | if (left > PAGE_SIZE - 1) |
1253 | left = PAGE_SIZE - 1; | |
32927393 | 1254 | p = buffer; |
00b7c339 AW |
1255 | } |
1256 | ||
27b3d80a | 1257 | for (; left && vleft--; i++, first = 0) { |
00b7c339 AW |
1258 | unsigned long val; |
1259 | ||
1da177e4 | 1260 | if (write) { |
00b7c339 AW |
1261 | bool neg; |
1262 | ||
51644b2c | 1263 | proc_skip_spaces(&p, &left); |
09be1784 CL |
1264 | if (!left) |
1265 | break; | |
00b7c339 | 1266 | |
70f6cbb6 | 1267 | err = proc_get_long(&p, &left, &val, &neg, |
00b7c339 AW |
1268 | proc_wspace_sep, |
1269 | sizeof(proc_wspace_sep), NULL); | |
1270 | if (err) | |
1da177e4 LT |
1271 | break; |
1272 | if (neg) | |
1da177e4 | 1273 | continue; |
ff9f8a7c | 1274 | val = convmul * val / convdiv; |
e260ad01 CB |
1275 | if ((min && val < *min) || (max && val > *max)) { |
1276 | err = -EINVAL; | |
1277 | break; | |
1278 | } | |
c16f3914 | 1279 | WRITE_ONCE(*i, val); |
1da177e4 | 1280 | } else { |
c16f3914 | 1281 | val = convdiv * READ_ONCE(*i) / convmul; |
32927393 CH |
1282 | if (!first) |
1283 | proc_put_char(&buffer, &left, '\t'); | |
1284 | proc_put_long(&buffer, &left, val, false); | |
1da177e4 LT |
1285 | } |
1286 | } | |
1287 | ||
00b7c339 | 1288 | if (!write && !first && left && !err) |
32927393 | 1289 | proc_put_char(&buffer, &left, '\n'); |
00b7c339 | 1290 | if (write && !err) |
51644b2c | 1291 | proc_skip_spaces(&p, &left); |
32927393 CH |
1292 | if (write && first) |
1293 | return err ? : -EINVAL; | |
1da177e4 | 1294 | *lenp -= left; |
f4aacea2 | 1295 | out: |
1da177e4 | 1296 | *ppos += *lenp; |
00b7c339 | 1297 | return err; |
1da177e4 LT |
1298 | } |
1299 | ||
d8217f07 | 1300 | static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, |
32927393 CH |
1301 | void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul, |
1302 | unsigned long convdiv) | |
fcfbd547 KK |
1303 | { |
1304 | return __do_proc_doulongvec_minmax(table->data, table, write, | |
8d65af78 | 1305 | buffer, lenp, ppos, convmul, convdiv); |
fcfbd547 KK |
1306 | } |
1307 | ||
1da177e4 LT |
1308 | /** |
1309 | * proc_doulongvec_minmax - read a vector of long integers with min/max values | |
1310 | * @table: the sysctl table | |
1311 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1312 | * @buffer: the user buffer |
1313 | * @lenp: the size of the user buffer | |
1314 | * @ppos: file position | |
1315 | * | |
1316 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
1317 | * values from/to the user buffer, treated as an ASCII string. | |
1318 | * | |
1319 | * This routine will ensure the values are within the range specified by | |
1320 | * table->extra1 (min) and table->extra2 (max). | |
1321 | * | |
1322 | * Returns 0 on success. | |
1323 | */ | |
8d65af78 | 1324 | int proc_doulongvec_minmax(struct ctl_table *table, int write, |
32927393 | 1325 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1326 | { |
8d65af78 | 1327 | return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); |
1da177e4 LT |
1328 | } |
1329 | ||
1330 | /** | |
1331 | * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values | |
1332 | * @table: the sysctl table | |
1333 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1334 | * @buffer: the user buffer |
1335 | * @lenp: the size of the user buffer | |
1336 | * @ppos: file position | |
1337 | * | |
1338 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
1339 | * values from/to the user buffer, treated as an ASCII string. The values | |
1340 | * are treated as milliseconds, and converted to jiffies when they are stored. | |
1341 | * | |
1342 | * This routine will ensure the values are within the range specified by | |
1343 | * table->extra1 (min) and table->extra2 (max). | |
1344 | * | |
1345 | * Returns 0 on success. | |
1346 | */ | |
d8217f07 | 1347 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
32927393 | 1348 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1349 | { |
8d65af78 | 1350 | return do_proc_doulongvec_minmax(table, write, buffer, |
1da177e4 LT |
1351 | lenp, ppos, HZ, 1000l); |
1352 | } | |
1353 | ||
1354 | ||
00b7c339 | 1355 | static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
1356 | int *valp, |
1357 | int write, void *data) | |
1358 | { | |
1359 | if (write) { | |
63259457 | 1360 | if (*lvalp > INT_MAX / HZ) |
cba9f33d | 1361 | return 1; |
51de017a KI |
1362 | if (*negp) |
1363 | WRITE_ONCE(*valp, -*lvalp * HZ); | |
1364 | else | |
1365 | WRITE_ONCE(*valp, *lvalp * HZ); | |
1da177e4 | 1366 | } else { |
51de017a | 1367 | int val = READ_ONCE(*valp); |
1da177e4 LT |
1368 | unsigned long lval; |
1369 | if (val < 0) { | |
00b7c339 | 1370 | *negp = true; |
9a5bc726 | 1371 | lval = -(unsigned long)val; |
1da177e4 | 1372 | } else { |
00b7c339 | 1373 | *negp = false; |
1da177e4 LT |
1374 | lval = (unsigned long)val; |
1375 | } | |
1376 | *lvalp = lval / HZ; | |
1377 | } | |
1378 | return 0; | |
1379 | } | |
1380 | ||
00b7c339 | 1381 | static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
1382 | int *valp, |
1383 | int write, void *data) | |
1384 | { | |
1385 | if (write) { | |
cba9f33d BS |
1386 | if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) |
1387 | return 1; | |
1da177e4 LT |
1388 | *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); |
1389 | } else { | |
1390 | int val = *valp; | |
1391 | unsigned long lval; | |
1392 | if (val < 0) { | |
00b7c339 | 1393 | *negp = true; |
9a5bc726 | 1394 | lval = -(unsigned long)val; |
1da177e4 | 1395 | } else { |
00b7c339 | 1396 | *negp = false; |
1da177e4 LT |
1397 | lval = (unsigned long)val; |
1398 | } | |
1399 | *lvalp = jiffies_to_clock_t(lval); | |
1400 | } | |
1401 | return 0; | |
1402 | } | |
1403 | ||
00b7c339 | 1404 | static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
1405 | int *valp, |
1406 | int write, void *data) | |
1407 | { | |
1408 | if (write) { | |
d738ce8f FF |
1409 | unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); |
1410 | ||
1411 | if (jif > INT_MAX) | |
1412 | return 1; | |
a225fa7f | 1413 | WRITE_ONCE(*valp, (int)jif); |
1da177e4 | 1414 | } else { |
a225fa7f | 1415 | int val = READ_ONCE(*valp); |
1da177e4 LT |
1416 | unsigned long lval; |
1417 | if (val < 0) { | |
00b7c339 | 1418 | *negp = true; |
9a5bc726 | 1419 | lval = -(unsigned long)val; |
1da177e4 | 1420 | } else { |
00b7c339 | 1421 | *negp = false; |
1da177e4 LT |
1422 | lval = (unsigned long)val; |
1423 | } | |
1424 | *lvalp = jiffies_to_msecs(lval); | |
1425 | } | |
1426 | return 0; | |
1427 | } | |
1428 | ||
1429 | /** | |
1430 | * proc_dointvec_jiffies - read a vector of integers as seconds | |
1431 | * @table: the sysctl table | |
1432 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1433 | * @buffer: the user buffer |
1434 | * @lenp: the size of the user buffer | |
1435 | * @ppos: file position | |
1436 | * | |
1437 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
1438 | * values from/to the user buffer, treated as an ASCII string. | |
1439 | * The values read are assumed to be in seconds, and are converted into | |
1440 | * jiffies. | |
1441 | * | |
1442 | * Returns 0 on success. | |
1443 | */ | |
8d65af78 | 1444 | int proc_dointvec_jiffies(struct ctl_table *table, int write, |
32927393 | 1445 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1446 | { |
8d65af78 | 1447 | return do_proc_dointvec(table,write,buffer,lenp,ppos, |
1da177e4 LT |
1448 | do_proc_dointvec_jiffies_conv,NULL); |
1449 | } | |
1450 | ||
1451 | /** | |
1452 | * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds | |
1453 | * @table: the sysctl table | |
1454 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1455 | * @buffer: the user buffer |
1456 | * @lenp: the size of the user buffer | |
1e5d5331 | 1457 | * @ppos: pointer to the file position |
1da177e4 LT |
1458 | * |
1459 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
1460 | * values from/to the user buffer, treated as an ASCII string. | |
1461 | * The values read are assumed to be in 1/USER_HZ seconds, and | |
1462 | * are converted into jiffies. | |
1463 | * | |
1464 | * Returns 0 on success. | |
1465 | */ | |
8d65af78 | 1466 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, |
32927393 | 1467 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1468 | { |
8d65af78 | 1469 | return do_proc_dointvec(table,write,buffer,lenp,ppos, |
1da177e4 LT |
1470 | do_proc_dointvec_userhz_jiffies_conv,NULL); |
1471 | } | |
1472 | ||
1473 | /** | |
1474 | * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds | |
1475 | * @table: the sysctl table | |
1476 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1477 | * @buffer: the user buffer |
1478 | * @lenp: the size of the user buffer | |
67be2dd1 MW |
1479 | * @ppos: file position |
1480 | * @ppos: the current position in the file | |
1da177e4 LT |
1481 | * |
1482 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
a225fa7f KI |
1483 | * values from/to the user buffer, treated as an ASCII string. |
1484 | * The values read are assumed to be in 1/1000 seconds, and | |
1da177e4 LT |
1485 | * are converted into jiffies. |
1486 | * | |
1487 | * Returns 0 on success. | |
1488 | */ | |
32927393 CH |
1489 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer, |
1490 | size_t *lenp, loff_t *ppos) | |
1da177e4 | 1491 | { |
8d65af78 | 1492 | return do_proc_dointvec(table, write, buffer, lenp, ppos, |
1da177e4 LT |
1493 | do_proc_dointvec_ms_jiffies_conv, NULL); |
1494 | } | |
1495 | ||
32927393 CH |
1496 | static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer, |
1497 | size_t *lenp, loff_t *ppos) | |
9ec52099 CLG |
1498 | { |
1499 | struct pid *new_pid; | |
1500 | pid_t tmp; | |
1501 | int r; | |
1502 | ||
6c5f3e7b | 1503 | tmp = pid_vnr(cad_pid); |
9ec52099 | 1504 | |
8d65af78 | 1505 | r = __do_proc_dointvec(&tmp, table, write, buffer, |
9ec52099 CLG |
1506 | lenp, ppos, NULL, NULL); |
1507 | if (r || !write) | |
1508 | return r; | |
1509 | ||
1510 | new_pid = find_get_pid(tmp); | |
1511 | if (!new_pid) | |
1512 | return -ESRCH; | |
1513 | ||
1514 | put_pid(xchg(&cad_pid, new_pid)); | |
1515 | return 0; | |
1516 | } | |
1517 | ||
9f977fb7 OP |
1518 | /** |
1519 | * proc_do_large_bitmap - read/write from/to a large bitmap | |
1520 | * @table: the sysctl table | |
1521 | * @write: %TRUE if this is a write to the sysctl file | |
1522 | * @buffer: the user buffer | |
1523 | * @lenp: the size of the user buffer | |
1524 | * @ppos: file position | |
1525 | * | |
1526 | * The bitmap is stored at table->data and the bitmap length (in bits) | |
1527 | * in table->maxlen. | |
1528 | * | |
1529 | * We use a range comma separated format (e.g. 1,3-4,10-10) so that | |
1530 | * large bitmaps may be represented in a compact manner. Writing into | |
1531 | * the file will clear the bitmap then update it with the given input. | |
1532 | * | |
1533 | * Returns 0 on success. | |
1534 | */ | |
1535 | int proc_do_large_bitmap(struct ctl_table *table, int write, | |
32927393 | 1536 | void *buffer, size_t *lenp, loff_t *ppos) |
9f977fb7 OP |
1537 | { |
1538 | int err = 0; | |
9f977fb7 OP |
1539 | size_t left = *lenp; |
1540 | unsigned long bitmap_len = table->maxlen; | |
122ff243 | 1541 | unsigned long *bitmap = *(unsigned long **) table->data; |
9f977fb7 OP |
1542 | unsigned long *tmp_bitmap = NULL; |
1543 | char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; | |
1544 | ||
122ff243 | 1545 | if (!bitmap || !bitmap_len || !left || (*ppos && !write)) { |
9f977fb7 OP |
1546 | *lenp = 0; |
1547 | return 0; | |
1548 | } | |
1549 | ||
1550 | if (write) { | |
32927393 | 1551 | char *p = buffer; |
3116ad38 | 1552 | size_t skipped = 0; |
9f977fb7 | 1553 | |
3116ad38 | 1554 | if (left > PAGE_SIZE - 1) { |
9f977fb7 | 1555 | left = PAGE_SIZE - 1; |
3116ad38 ES |
1556 | /* How much of the buffer we'll skip this pass */ |
1557 | skipped = *lenp - left; | |
1558 | } | |
9f977fb7 | 1559 | |
475dae38 | 1560 | tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL); |
32927393 | 1561 | if (!tmp_bitmap) |
9f977fb7 | 1562 | return -ENOMEM; |
70f6cbb6 | 1563 | proc_skip_char(&p, &left, '\n'); |
9f977fb7 OP |
1564 | while (!err && left) { |
1565 | unsigned long val_a, val_b; | |
1566 | bool neg; | |
3116ad38 | 1567 | size_t saved_left; |
9f977fb7 | 1568 | |
3116ad38 ES |
1569 | /* In case we stop parsing mid-number, we can reset */ |
1570 | saved_left = left; | |
70f6cbb6 | 1571 | err = proc_get_long(&p, &left, &val_a, &neg, tr_a, |
9f977fb7 | 1572 | sizeof(tr_a), &c); |
3116ad38 ES |
1573 | /* |
1574 | * If we consumed the entirety of a truncated buffer or | |
1575 | * only one char is left (may be a "-"), then stop here, | |
1576 | * reset, & come back for more. | |
1577 | */ | |
1578 | if ((left <= 1) && skipped) { | |
1579 | left = saved_left; | |
1580 | break; | |
1581 | } | |
1582 | ||
9f977fb7 OP |
1583 | if (err) |
1584 | break; | |
1585 | if (val_a >= bitmap_len || neg) { | |
1586 | err = -EINVAL; | |
1587 | break; | |
1588 | } | |
1589 | ||
1590 | val_b = val_a; | |
1591 | if (left) { | |
70f6cbb6 | 1592 | p++; |
9f977fb7 OP |
1593 | left--; |
1594 | } | |
1595 | ||
1596 | if (c == '-') { | |
70f6cbb6 | 1597 | err = proc_get_long(&p, &left, &val_b, |
9f977fb7 OP |
1598 | &neg, tr_b, sizeof(tr_b), |
1599 | &c); | |
3116ad38 ES |
1600 | /* |
1601 | * If we consumed all of a truncated buffer or | |
1602 | * then stop here, reset, & come back for more. | |
1603 | */ | |
1604 | if (!left && skipped) { | |
1605 | left = saved_left; | |
1606 | break; | |
1607 | } | |
1608 | ||
9f977fb7 OP |
1609 | if (err) |
1610 | break; | |
1611 | if (val_b >= bitmap_len || neg || | |
1612 | val_a > val_b) { | |
1613 | err = -EINVAL; | |
1614 | break; | |
1615 | } | |
1616 | if (left) { | |
70f6cbb6 | 1617 | p++; |
9f977fb7 OP |
1618 | left--; |
1619 | } | |
1620 | } | |
1621 | ||
5a04cca6 | 1622 | bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); |
70f6cbb6 | 1623 | proc_skip_char(&p, &left, '\n'); |
9f977fb7 | 1624 | } |
3116ad38 | 1625 | left += skipped; |
9f977fb7 OP |
1626 | } else { |
1627 | unsigned long bit_a, bit_b = 0; | |
9a52c5f3 | 1628 | bool first = 1; |
9f977fb7 OP |
1629 | |
1630 | while (left) { | |
1631 | bit_a = find_next_bit(bitmap, bitmap_len, bit_b); | |
1632 | if (bit_a >= bitmap_len) | |
1633 | break; | |
1634 | bit_b = find_next_zero_bit(bitmap, bitmap_len, | |
1635 | bit_a + 1) - 1; | |
1636 | ||
32927393 CH |
1637 | if (!first) |
1638 | proc_put_char(&buffer, &left, ','); | |
1639 | proc_put_long(&buffer, &left, bit_a, false); | |
9f977fb7 | 1640 | if (bit_a != bit_b) { |
32927393 CH |
1641 | proc_put_char(&buffer, &left, '-'); |
1642 | proc_put_long(&buffer, &left, bit_b, false); | |
9f977fb7 OP |
1643 | } |
1644 | ||
1645 | first = 0; bit_b++; | |
1646 | } | |
32927393 | 1647 | proc_put_char(&buffer, &left, '\n'); |
9f977fb7 OP |
1648 | } |
1649 | ||
1650 | if (!err) { | |
1651 | if (write) { | |
1652 | if (*ppos) | |
1653 | bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); | |
1654 | else | |
5a04cca6 | 1655 | bitmap_copy(bitmap, tmp_bitmap, bitmap_len); |
9f977fb7 | 1656 | } |
9f977fb7 OP |
1657 | *lenp -= left; |
1658 | *ppos += *lenp; | |
9f977fb7 | 1659 | } |
f9eb2fdd | 1660 | |
475dae38 | 1661 | bitmap_free(tmp_bitmap); |
f9eb2fdd | 1662 | return err; |
9f977fb7 OP |
1663 | } |
1664 | ||
55610500 | 1665 | #else /* CONFIG_PROC_SYSCTL */ |
1da177e4 | 1666 | |
8d65af78 | 1667 | int proc_dostring(struct ctl_table *table, int write, |
32927393 | 1668 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
1669 | { |
1670 | return -ENOSYS; | |
1671 | } | |
1672 | ||
a2071573 JH |
1673 | int proc_dobool(struct ctl_table *table, int write, |
1674 | void *buffer, size_t *lenp, loff_t *ppos) | |
1675 | { | |
1676 | return -ENOSYS; | |
1677 | } | |
1678 | ||
f461d2dc | 1679 | int proc_dointvec(struct ctl_table *table, int write, |
32927393 | 1680 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1681 | { |
1682 | return -ENOSYS; | |
1683 | } | |
1684 | ||
1685 | int proc_douintvec(struct ctl_table *table, int write, | |
32927393 | 1686 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1687 | { |
1688 | return -ENOSYS; | |
1689 | } | |
1690 | ||
1691 | int proc_dointvec_minmax(struct ctl_table *table, int write, | |
32927393 | 1692 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1693 | { |
1694 | return -ENOSYS; | |
1695 | } | |
1696 | ||
1697 | int proc_douintvec_minmax(struct ctl_table *table, int write, | |
32927393 | 1698 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1699 | { |
1700 | return -ENOSYS; | |
9f977fb7 OP |
1701 | } |
1702 | ||
cb944413 ED |
1703 | int proc_dou8vec_minmax(struct ctl_table *table, int write, |
1704 | void *buffer, size_t *lenp, loff_t *ppos) | |
1705 | { | |
1706 | return -ENOSYS; | |
1707 | } | |
1708 | ||
f461d2dc | 1709 | int proc_dointvec_jiffies(struct ctl_table *table, int write, |
32927393 | 1710 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1711 | { |
1712 | return -ENOSYS; | |
1713 | } | |
1da177e4 | 1714 | |
f461d2dc | 1715 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, |
32927393 | 1716 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
1717 | { |
1718 | return -ENOSYS; | |
1719 | } | |
1720 | ||
f461d2dc | 1721 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, |
32927393 | 1722 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
1723 | { |
1724 | return -ENOSYS; | |
1725 | } | |
1726 | ||
f461d2dc | 1727 | int proc_doulongvec_minmax(struct ctl_table *table, int write, |
32927393 | 1728 | void *buffer, size_t *lenp, loff_t *ppos) |
e7d316a0 SAK |
1729 | { |
1730 | return -ENOSYS; | |
1731 | } | |
1732 | ||
f461d2dc | 1733 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
32927393 | 1734 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1735 | { |
32927393 | 1736 | return -ENOSYS; |
1da177e4 LT |
1737 | } |
1738 | ||
f461d2dc | 1739 | int proc_do_large_bitmap(struct ctl_table *table, int write, |
32927393 | 1740 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
1741 | { |
1742 | return -ENOSYS; | |
1743 | } | |
1744 | ||
f461d2dc CH |
1745 | #endif /* CONFIG_PROC_SYSCTL */ |
1746 | ||
1747 | #if defined(CONFIG_SYSCTL) | |
1748 | int proc_do_static_key(struct ctl_table *table, int write, | |
32927393 | 1749 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1750 | { |
f461d2dc CH |
1751 | struct static_key *key = (struct static_key *)table->data; |
1752 | static DEFINE_MUTEX(static_key_mutex); | |
1753 | int val, ret; | |
1754 | struct ctl_table tmp = { | |
1755 | .data = &val, | |
1756 | .maxlen = sizeof(val), | |
1757 | .mode = table->mode, | |
1758 | .extra1 = SYSCTL_ZERO, | |
1759 | .extra2 = SYSCTL_ONE, | |
1760 | }; | |
1761 | ||
1762 | if (write && !capable(CAP_SYS_ADMIN)) | |
1763 | return -EPERM; | |
1764 | ||
1765 | mutex_lock(&static_key_mutex); | |
1766 | val = static_key_enabled(key); | |
1767 | ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); | |
1768 | if (write && !ret) { | |
1769 | if (val) | |
1770 | static_key_enable(key); | |
1771 | else | |
1772 | static_key_disable(key); | |
1773 | } | |
1774 | mutex_unlock(&static_key_mutex); | |
1775 | return ret; | |
1da177e4 LT |
1776 | } |
1777 | ||
f461d2dc CH |
1778 | static struct ctl_table kern_table[] = { |
1779 | { | |
1780 | .procname = "sched_child_runs_first", | |
1781 | .data = &sysctl_sched_child_runs_first, | |
1782 | .maxlen = sizeof(unsigned int), | |
1783 | .mode = 0644, | |
1784 | .proc_handler = proc_dointvec, | |
1785 | }, | |
1d1c2509 PZ |
1786 | #ifdef CONFIG_SCHEDSTATS |
1787 | { | |
1788 | .procname = "sched_schedstats", | |
1789 | .data = NULL, | |
1790 | .maxlen = sizeof(unsigned int), | |
1791 | .mode = 0644, | |
1792 | .proc_handler = sysctl_schedstats, | |
1793 | .extra1 = SYSCTL_ZERO, | |
1794 | .extra2 = SYSCTL_ONE, | |
1795 | }, | |
1796 | #endif /* CONFIG_SCHEDSTATS */ | |
0cd7c741 PZ |
1797 | #ifdef CONFIG_TASK_DELAY_ACCT |
1798 | { | |
1799 | .procname = "task_delayacct", | |
1800 | .data = NULL, | |
1801 | .maxlen = sizeof(unsigned int), | |
1802 | .mode = 0644, | |
1803 | .proc_handler = sysctl_delayacct, | |
1804 | .extra1 = SYSCTL_ZERO, | |
1805 | .extra2 = SYSCTL_ONE, | |
1806 | }, | |
1807 | #endif /* CONFIG_TASK_DELAY_ACCT */ | |
b7cc6ec7 | 1808 | #ifdef CONFIG_NUMA_BALANCING |
f461d2dc CH |
1809 | { |
1810 | .procname = "numa_balancing", | |
1811 | .data = NULL, /* filled in by handler */ | |
1812 | .maxlen = sizeof(unsigned int), | |
1813 | .mode = 0644, | |
1814 | .proc_handler = sysctl_numa_balancing, | |
1815 | .extra1 = SYSCTL_ZERO, | |
1816 | .extra2 = SYSCTL_ONE, | |
1817 | }, | |
1818 | #endif /* CONFIG_NUMA_BALANCING */ | |
f461d2dc CH |
1819 | { |
1820 | .procname = "sched_rt_period_us", | |
1821 | .data = &sysctl_sched_rt_period, | |
1822 | .maxlen = sizeof(unsigned int), | |
1823 | .mode = 0644, | |
1824 | .proc_handler = sched_rt_handler, | |
1825 | }, | |
1826 | { | |
1827 | .procname = "sched_rt_runtime_us", | |
1828 | .data = &sysctl_sched_rt_runtime, | |
1829 | .maxlen = sizeof(int), | |
1830 | .mode = 0644, | |
1831 | .proc_handler = sched_rt_handler, | |
1832 | }, | |
b4098bfc PZ |
1833 | { |
1834 | .procname = "sched_deadline_period_max_us", | |
1835 | .data = &sysctl_sched_dl_period_max, | |
1836 | .maxlen = sizeof(unsigned int), | |
1837 | .mode = 0644, | |
1838 | .proc_handler = proc_dointvec, | |
1839 | }, | |
1840 | { | |
1841 | .procname = "sched_deadline_period_min_us", | |
1842 | .data = &sysctl_sched_dl_period_min, | |
1843 | .maxlen = sizeof(unsigned int), | |
1844 | .mode = 0644, | |
1845 | .proc_handler = proc_dointvec, | |
1846 | }, | |
f461d2dc CH |
1847 | { |
1848 | .procname = "sched_rr_timeslice_ms", | |
1849 | .data = &sysctl_sched_rr_timeslice, | |
1850 | .maxlen = sizeof(int), | |
1851 | .mode = 0644, | |
1852 | .proc_handler = sched_rr_handler, | |
1853 | }, | |
1854 | #ifdef CONFIG_UCLAMP_TASK | |
1855 | { | |
1856 | .procname = "sched_util_clamp_min", | |
1857 | .data = &sysctl_sched_uclamp_util_min, | |
1858 | .maxlen = sizeof(unsigned int), | |
1859 | .mode = 0644, | |
1860 | .proc_handler = sysctl_sched_uclamp_handler, | |
1861 | }, | |
1862 | { | |
1863 | .procname = "sched_util_clamp_max", | |
1864 | .data = &sysctl_sched_uclamp_util_max, | |
1865 | .maxlen = sizeof(unsigned int), | |
1866 | .mode = 0644, | |
1867 | .proc_handler = sysctl_sched_uclamp_handler, | |
1868 | }, | |
13685c4a QY |
1869 | { |
1870 | .procname = "sched_util_clamp_min_rt_default", | |
1871 | .data = &sysctl_sched_uclamp_util_min_rt_default, | |
1872 | .maxlen = sizeof(unsigned int), | |
1873 | .mode = 0644, | |
1874 | .proc_handler = sysctl_sched_uclamp_handler, | |
1875 | }, | |
f461d2dc CH |
1876 | #endif |
1877 | #ifdef CONFIG_SCHED_AUTOGROUP | |
1878 | { | |
1879 | .procname = "sched_autogroup_enabled", | |
1880 | .data = &sysctl_sched_autogroup_enabled, | |
1881 | .maxlen = sizeof(unsigned int), | |
1882 | .mode = 0644, | |
1883 | .proc_handler = proc_dointvec_minmax, | |
1884 | .extra1 = SYSCTL_ZERO, | |
1885 | .extra2 = SYSCTL_ONE, | |
1886 | }, | |
1887 | #endif | |
1888 | #ifdef CONFIG_CFS_BANDWIDTH | |
1889 | { | |
1890 | .procname = "sched_cfs_bandwidth_slice_us", | |
1891 | .data = &sysctl_sched_cfs_bandwidth_slice, | |
1892 | .maxlen = sizeof(unsigned int), | |
1893 | .mode = 0644, | |
1894 | .proc_handler = proc_dointvec_minmax, | |
1895 | .extra1 = SYSCTL_ONE, | |
1896 | }, | |
1897 | #endif | |
1898 | #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL) | |
1899 | { | |
1900 | .procname = "sched_energy_aware", | |
1901 | .data = &sysctl_sched_energy_aware, | |
1902 | .maxlen = sizeof(unsigned int), | |
1903 | .mode = 0644, | |
1904 | .proc_handler = sched_energy_aware_handler, | |
1905 | .extra1 = SYSCTL_ZERO, | |
1906 | .extra2 = SYSCTL_ONE, | |
1907 | }, | |
1908 | #endif | |
1909 | #ifdef CONFIG_PROVE_LOCKING | |
1910 | { | |
1911 | .procname = "prove_locking", | |
1912 | .data = &prove_locking, | |
1913 | .maxlen = sizeof(int), | |
1914 | .mode = 0644, | |
1915 | .proc_handler = proc_dointvec, | |
1916 | }, | |
1917 | #endif | |
1918 | #ifdef CONFIG_LOCK_STAT | |
1919 | { | |
1920 | .procname = "lock_stat", | |
1921 | .data = &lock_stat, | |
1922 | .maxlen = sizeof(int), | |
1923 | .mode = 0644, | |
1924 | .proc_handler = proc_dointvec, | |
1925 | }, | |
1926 | #endif | |
1927 | { | |
1928 | .procname = "panic", | |
1929 | .data = &panic_timeout, | |
1930 | .maxlen = sizeof(int), | |
1931 | .mode = 0644, | |
1932 | .proc_handler = proc_dointvec, | |
1933 | }, | |
1934 | #ifdef CONFIG_COREDUMP | |
1935 | { | |
1936 | .procname = "core_uses_pid", | |
1937 | .data = &core_uses_pid, | |
1938 | .maxlen = sizeof(int), | |
1939 | .mode = 0644, | |
1940 | .proc_handler = proc_dointvec, | |
1941 | }, | |
1942 | { | |
1943 | .procname = "core_pattern", | |
1944 | .data = core_pattern, | |
1945 | .maxlen = CORENAME_MAX_SIZE, | |
1946 | .mode = 0644, | |
1947 | .proc_handler = proc_dostring_coredump, | |
1948 | }, | |
1949 | { | |
1950 | .procname = "core_pipe_limit", | |
1951 | .data = &core_pipe_limit, | |
1952 | .maxlen = sizeof(unsigned int), | |
1953 | .mode = 0644, | |
1954 | .proc_handler = proc_dointvec, | |
1955 | }, | |
1956 | #endif | |
34227646 SH |
1957 | #ifdef CONFIG_USER_NS |
1958 | { | |
1959 | .procname = "unprivileged_userns_clone", | |
1960 | .data = &unprivileged_userns_clone, | |
1961 | .maxlen = sizeof(int), | |
1962 | .mode = 0644, | |
1963 | .proc_handler = proc_dointvec, | |
1964 | }, | |
1965 | #endif | |
f461d2dc CH |
1966 | #ifdef CONFIG_PROC_SYSCTL |
1967 | { | |
1968 | .procname = "tainted", | |
1969 | .maxlen = sizeof(long), | |
1970 | .mode = 0644, | |
1971 | .proc_handler = proc_taint, | |
1972 | }, | |
1973 | { | |
1974 | .procname = "sysctl_writes_strict", | |
1975 | .data = &sysctl_writes_strict, | |
1976 | .maxlen = sizeof(int), | |
1977 | .mode = 0644, | |
1978 | .proc_handler = proc_dointvec_minmax, | |
3422786f | 1979 | .extra1 = SYSCTL_NEG_ONE, |
f461d2dc CH |
1980 | .extra2 = SYSCTL_ONE, |
1981 | }, | |
1982 | #endif | |
1983 | #ifdef CONFIG_LATENCYTOP | |
1984 | { | |
1985 | .procname = "latencytop", | |
1986 | .data = &latencytop_enabled, | |
1987 | .maxlen = sizeof(int), | |
1988 | .mode = 0644, | |
1989 | .proc_handler = sysctl_latencytop, | |
1990 | }, | |
1991 | #endif | |
1992 | #ifdef CONFIG_BLK_DEV_INITRD | |
1993 | { | |
1994 | .procname = "real-root-dev", | |
1995 | .data = &real_root_dev, | |
1996 | .maxlen = sizeof(int), | |
1997 | .mode = 0644, | |
1998 | .proc_handler = proc_dointvec, | |
1999 | }, | |
2000 | #endif | |
2001 | { | |
2002 | .procname = "print-fatal-signals", | |
2003 | .data = &print_fatal_signals, | |
2004 | .maxlen = sizeof(int), | |
2005 | .mode = 0644, | |
2006 | .proc_handler = proc_dointvec, | |
2007 | }, | |
2008 | #ifdef CONFIG_SPARC | |
2009 | { | |
2010 | .procname = "reboot-cmd", | |
2011 | .data = reboot_command, | |
2012 | .maxlen = 256, | |
2013 | .mode = 0644, | |
2014 | .proc_handler = proc_dostring, | |
2015 | }, | |
2016 | { | |
2017 | .procname = "stop-a", | |
2018 | .data = &stop_a_enabled, | |
2019 | .maxlen = sizeof (int), | |
2020 | .mode = 0644, | |
2021 | .proc_handler = proc_dointvec, | |
2022 | }, | |
2023 | { | |
2024 | .procname = "scons-poweroff", | |
2025 | .data = &scons_pwroff, | |
2026 | .maxlen = sizeof (int), | |
2027 | .mode = 0644, | |
2028 | .proc_handler = proc_dointvec, | |
2029 | }, | |
2030 | #endif | |
2031 | #ifdef CONFIG_SPARC64 | |
2032 | { | |
2033 | .procname = "tsb-ratio", | |
2034 | .data = &sysctl_tsb_ratio, | |
2035 | .maxlen = sizeof (int), | |
2036 | .mode = 0644, | |
2037 | .proc_handler = proc_dointvec, | |
2038 | }, | |
2039 | #endif | |
2040 | #ifdef CONFIG_PARISC | |
2041 | { | |
2042 | .procname = "soft-power", | |
2043 | .data = &pwrsw_enabled, | |
2044 | .maxlen = sizeof (int), | |
2045 | .mode = 0644, | |
2046 | .proc_handler = proc_dointvec, | |
2047 | }, | |
2048 | #endif | |
2049 | #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW | |
2050 | { | |
2051 | .procname = "unaligned-trap", | |
2052 | .data = &unaligned_enabled, | |
2053 | .maxlen = sizeof (int), | |
2054 | .mode = 0644, | |
2055 | .proc_handler = proc_dointvec, | |
2056 | }, | |
2057 | #endif | |
2058 | { | |
2059 | .procname = "ctrl-alt-del", | |
2060 | .data = &C_A_D, | |
2061 | .maxlen = sizeof(int), | |
2062 | .mode = 0644, | |
2063 | .proc_handler = proc_dointvec, | |
2064 | }, | |
2065 | #ifdef CONFIG_FUNCTION_TRACER | |
2066 | { | |
2067 | .procname = "ftrace_enabled", | |
2068 | .data = &ftrace_enabled, | |
2069 | .maxlen = sizeof(int), | |
2070 | .mode = 0644, | |
2071 | .proc_handler = ftrace_enable_sysctl, | |
2072 | }, | |
2073 | #endif | |
2074 | #ifdef CONFIG_STACK_TRACER | |
2075 | { | |
2076 | .procname = "stack_tracer_enabled", | |
2077 | .data = &stack_tracer_enabled, | |
2078 | .maxlen = sizeof(int), | |
2079 | .mode = 0644, | |
2080 | .proc_handler = stack_trace_sysctl, | |
2081 | }, | |
2082 | #endif | |
2083 | #ifdef CONFIG_TRACING | |
2084 | { | |
2085 | .procname = "ftrace_dump_on_oops", | |
2086 | .data = &ftrace_dump_on_oops, | |
2087 | .maxlen = sizeof(int), | |
2088 | .mode = 0644, | |
2089 | .proc_handler = proc_dointvec, | |
2090 | }, | |
2091 | { | |
2092 | .procname = "traceoff_on_warning", | |
2093 | .data = &__disable_trace_on_warning, | |
2094 | .maxlen = sizeof(__disable_trace_on_warning), | |
2095 | .mode = 0644, | |
2096 | .proc_handler = proc_dointvec, | |
2097 | }, | |
2098 | { | |
2099 | .procname = "tracepoint_printk", | |
2100 | .data = &tracepoint_printk, | |
2101 | .maxlen = sizeof(tracepoint_printk), | |
2102 | .mode = 0644, | |
2103 | .proc_handler = tracepoint_printk_sysctl, | |
2104 | }, | |
2105 | #endif | |
2106 | #ifdef CONFIG_KEXEC_CORE | |
2107 | { | |
2108 | .procname = "kexec_load_disabled", | |
2109 | .data = &kexec_load_disabled, | |
2110 | .maxlen = sizeof(int), | |
2111 | .mode = 0644, | |
2112 | /* only handle a transition from default "0" to "1" */ | |
2113 | .proc_handler = proc_dointvec_minmax, | |
2114 | .extra1 = SYSCTL_ONE, | |
2115 | .extra2 = SYSCTL_ONE, | |
2116 | }, | |
2117 | #endif | |
2118 | #ifdef CONFIG_MODULES | |
2119 | { | |
2120 | .procname = "modprobe", | |
2121 | .data = &modprobe_path, | |
2122 | .maxlen = KMOD_PATH_LEN, | |
2123 | .mode = 0644, | |
2124 | .proc_handler = proc_dostring, | |
2125 | }, | |
2126 | { | |
2127 | .procname = "modules_disabled", | |
2128 | .data = &modules_disabled, | |
2129 | .maxlen = sizeof(int), | |
2130 | .mode = 0644, | |
2131 | /* only handle a transition from default "0" to "1" */ | |
2132 | .proc_handler = proc_dointvec_minmax, | |
2133 | .extra1 = SYSCTL_ONE, | |
2134 | .extra2 = SYSCTL_ONE, | |
2135 | }, | |
2136 | #endif | |
2137 | #ifdef CONFIG_UEVENT_HELPER | |
2138 | { | |
2139 | .procname = "hotplug", | |
2140 | .data = &uevent_helper, | |
2141 | .maxlen = UEVENT_HELPER_PATH_LEN, | |
2142 | .mode = 0644, | |
2143 | .proc_handler = proc_dostring, | |
2144 | }, | |
2145 | #endif | |
2146 | #ifdef CONFIG_CHR_DEV_SG | |
2147 | { | |
2148 | .procname = "sg-big-buff", | |
2149 | .data = &sg_big_buff, | |
2150 | .maxlen = sizeof (int), | |
2151 | .mode = 0444, | |
2152 | .proc_handler = proc_dointvec, | |
2153 | }, | |
2154 | #endif | |
2155 | #ifdef CONFIG_BSD_PROCESS_ACCT | |
2156 | { | |
2157 | .procname = "acct", | |
2158 | .data = &acct_parm, | |
2159 | .maxlen = 3*sizeof(int), | |
2160 | .mode = 0644, | |
2161 | .proc_handler = proc_dointvec, | |
2162 | }, | |
2163 | #endif | |
2164 | #ifdef CONFIG_MAGIC_SYSRQ | |
2165 | { | |
2166 | .procname = "sysrq", | |
2167 | .data = NULL, | |
2168 | .maxlen = sizeof (int), | |
2169 | .mode = 0644, | |
2170 | .proc_handler = sysrq_sysctl_handler, | |
2171 | }, | |
2172 | #endif | |
2173 | #ifdef CONFIG_PROC_SYSCTL | |
2174 | { | |
2175 | .procname = "cad_pid", | |
2176 | .data = NULL, | |
2177 | .maxlen = sizeof (int), | |
2178 | .mode = 0600, | |
2179 | .proc_handler = proc_do_cad_pid, | |
2180 | }, | |
2181 | #endif | |
2182 | { | |
2183 | .procname = "threads-max", | |
2184 | .data = NULL, | |
2185 | .maxlen = sizeof(int), | |
2186 | .mode = 0644, | |
2187 | .proc_handler = sysctl_max_threads, | |
2188 | }, | |
2189 | { | |
2190 | .procname = "random", | |
2191 | .mode = 0555, | |
2192 | .child = random_table, | |
2193 | }, | |
2194 | { | |
2195 | .procname = "usermodehelper", | |
2196 | .mode = 0555, | |
2197 | .child = usermodehelper_table, | |
2198 | }, | |
2199 | #ifdef CONFIG_FW_LOADER_USER_HELPER | |
2200 | { | |
2201 | .procname = "firmware_config", | |
2202 | .mode = 0555, | |
2203 | .child = firmware_config_table, | |
2204 | }, | |
2205 | #endif | |
2206 | { | |
2207 | .procname = "overflowuid", | |
2208 | .data = &overflowuid, | |
2209 | .maxlen = sizeof(int), | |
2210 | .mode = 0644, | |
2211 | .proc_handler = proc_dointvec_minmax, | |
2212 | .extra1 = &minolduid, | |
2213 | .extra2 = &maxolduid, | |
2214 | }, | |
2215 | { | |
2216 | .procname = "overflowgid", | |
2217 | .data = &overflowgid, | |
2218 | .maxlen = sizeof(int), | |
2219 | .mode = 0644, | |
2220 | .proc_handler = proc_dointvec_minmax, | |
2221 | .extra1 = &minolduid, | |
2222 | .extra2 = &maxolduid, | |
2223 | }, | |
2224 | #ifdef CONFIG_S390 | |
2225 | { | |
2226 | .procname = "userprocess_debug", | |
2227 | .data = &show_unhandled_signals, | |
2228 | .maxlen = sizeof(int), | |
2229 | .mode = 0644, | |
2230 | .proc_handler = proc_dointvec, | |
2231 | }, | |
2232 | #endif | |
60c958d8 GP |
2233 | #ifdef CONFIG_SMP |
2234 | { | |
2235 | .procname = "oops_all_cpu_backtrace", | |
2236 | .data = &sysctl_oops_all_cpu_backtrace, | |
2237 | .maxlen = sizeof(int), | |
2238 | .mode = 0644, | |
2239 | .proc_handler = proc_dointvec_minmax, | |
2240 | .extra1 = SYSCTL_ZERO, | |
2241 | .extra2 = SYSCTL_ONE, | |
2242 | }, | |
2243 | #endif /* CONFIG_SMP */ | |
f461d2dc CH |
2244 | { |
2245 | .procname = "pid_max", | |
2246 | .data = &pid_max, | |
2247 | .maxlen = sizeof (int), | |
2248 | .mode = 0644, | |
2249 | .proc_handler = proc_dointvec_minmax, | |
2250 | .extra1 = &pid_max_min, | |
2251 | .extra2 = &pid_max_max, | |
2252 | }, | |
2253 | { | |
2254 | .procname = "panic_on_oops", | |
2255 | .data = &panic_on_oops, | |
2256 | .maxlen = sizeof(int), | |
2257 | .mode = 0644, | |
2258 | .proc_handler = proc_dointvec, | |
2259 | }, | |
2260 | { | |
2261 | .procname = "panic_print", | |
2262 | .data = &panic_print, | |
2263 | .maxlen = sizeof(unsigned long), | |
2264 | .mode = 0644, | |
2265 | .proc_handler = proc_doulongvec_minmax, | |
2266 | }, | |
2267 | #if defined CONFIG_PRINTK | |
2268 | { | |
2269 | .procname = "printk", | |
2270 | .data = &console_loglevel, | |
2271 | .maxlen = 4*sizeof(int), | |
2272 | .mode = 0644, | |
2273 | .proc_handler = proc_dointvec, | |
2274 | }, | |
2275 | { | |
2276 | .procname = "printk_ratelimit", | |
2277 | .data = &printk_ratelimit_state.interval, | |
2278 | .maxlen = sizeof(int), | |
2279 | .mode = 0644, | |
2280 | .proc_handler = proc_dointvec_jiffies, | |
2281 | }, | |
2282 | { | |
2283 | .procname = "printk_ratelimit_burst", | |
2284 | .data = &printk_ratelimit_state.burst, | |
2285 | .maxlen = sizeof(int), | |
2286 | .mode = 0644, | |
2287 | .proc_handler = proc_dointvec, | |
2288 | }, | |
2289 | { | |
2290 | .procname = "printk_delay", | |
2291 | .data = &printk_delay_msec, | |
2292 | .maxlen = sizeof(int), | |
2293 | .mode = 0644, | |
2294 | .proc_handler = proc_dointvec_minmax, | |
2295 | .extra1 = SYSCTL_ZERO, | |
2296 | .extra2 = &ten_thousand, | |
2297 | }, | |
2298 | { | |
2299 | .procname = "printk_devkmsg", | |
2300 | .data = devkmsg_log_str, | |
2301 | .maxlen = DEVKMSG_STR_MAX_SIZE, | |
2302 | .mode = 0644, | |
2303 | .proc_handler = devkmsg_sysctl_set_loglvl, | |
2304 | }, | |
2305 | { | |
2306 | .procname = "dmesg_restrict", | |
2307 | .data = &dmesg_restrict, | |
2308 | .maxlen = sizeof(int), | |
2309 | .mode = 0644, | |
2310 | .proc_handler = proc_dointvec_minmax_sysadmin, | |
2311 | .extra1 = SYSCTL_ZERO, | |
2312 | .extra2 = SYSCTL_ONE, | |
2313 | }, | |
2314 | { | |
2315 | .procname = "kptr_restrict", | |
2316 | .data = &kptr_restrict, | |
2317 | .maxlen = sizeof(int), | |
2318 | .mode = 0644, | |
2319 | .proc_handler = proc_dointvec_minmax_sysadmin, | |
2320 | .extra1 = SYSCTL_ZERO, | |
3422786f | 2321 | .extra2 = SYSCTL_TWO, |
f461d2dc CH |
2322 | }, |
2323 | #endif | |
2324 | { | |
2325 | .procname = "ngroups_max", | |
2326 | .data = &ngroups_max, | |
2327 | .maxlen = sizeof (int), | |
2328 | .mode = 0444, | |
2329 | .proc_handler = proc_dointvec, | |
2330 | }, | |
2331 | { | |
2332 | .procname = "cap_last_cap", | |
2333 | .data = (void *)&cap_last_cap, | |
2334 | .maxlen = sizeof(int), | |
2335 | .mode = 0444, | |
2336 | .proc_handler = proc_dointvec, | |
2337 | }, | |
2338 | #if defined(CONFIG_LOCKUP_DETECTOR) | |
2339 | { | |
2340 | .procname = "watchdog", | |
2341 | .data = &watchdog_user_enabled, | |
2342 | .maxlen = sizeof(int), | |
2343 | .mode = 0644, | |
2344 | .proc_handler = proc_watchdog, | |
2345 | .extra1 = SYSCTL_ZERO, | |
2346 | .extra2 = SYSCTL_ONE, | |
2347 | }, | |
2348 | { | |
2349 | .procname = "watchdog_thresh", | |
2350 | .data = &watchdog_thresh, | |
2351 | .maxlen = sizeof(int), | |
2352 | .mode = 0644, | |
2353 | .proc_handler = proc_watchdog_thresh, | |
2354 | .extra1 = SYSCTL_ZERO, | |
2355 | .extra2 = &sixty, | |
2356 | }, | |
2357 | { | |
2358 | .procname = "nmi_watchdog", | |
2359 | .data = &nmi_watchdog_user_enabled, | |
2360 | .maxlen = sizeof(int), | |
2361 | .mode = NMI_WATCHDOG_SYSCTL_PERM, | |
2362 | .proc_handler = proc_nmi_watchdog, | |
2363 | .extra1 = SYSCTL_ZERO, | |
2364 | .extra2 = SYSCTL_ONE, | |
2365 | }, | |
2366 | { | |
2367 | .procname = "watchdog_cpumask", | |
2368 | .data = &watchdog_cpumask_bits, | |
2369 | .maxlen = NR_CPUS, | |
2370 | .mode = 0644, | |
2371 | .proc_handler = proc_watchdog_cpumask, | |
2372 | }, | |
2373 | #ifdef CONFIG_SOFTLOCKUP_DETECTOR | |
2374 | { | |
2375 | .procname = "soft_watchdog", | |
2376 | .data = &soft_watchdog_user_enabled, | |
2377 | .maxlen = sizeof(int), | |
2378 | .mode = 0644, | |
2379 | .proc_handler = proc_soft_watchdog, | |
2380 | .extra1 = SYSCTL_ZERO, | |
2381 | .extra2 = SYSCTL_ONE, | |
2382 | }, | |
2383 | { | |
2384 | .procname = "softlockup_panic", | |
2385 | .data = &softlockup_panic, | |
2386 | .maxlen = sizeof(int), | |
2387 | .mode = 0644, | |
2388 | .proc_handler = proc_dointvec_minmax, | |
2389 | .extra1 = SYSCTL_ZERO, | |
2390 | .extra2 = SYSCTL_ONE, | |
2391 | }, | |
2392 | #ifdef CONFIG_SMP | |
2393 | { | |
2394 | .procname = "softlockup_all_cpu_backtrace", | |
2395 | .data = &sysctl_softlockup_all_cpu_backtrace, | |
2396 | .maxlen = sizeof(int), | |
2397 | .mode = 0644, | |
2398 | .proc_handler = proc_dointvec_minmax, | |
2399 | .extra1 = SYSCTL_ZERO, | |
2400 | .extra2 = SYSCTL_ONE, | |
2401 | }, | |
2402 | #endif /* CONFIG_SMP */ | |
2403 | #endif | |
2404 | #ifdef CONFIG_HARDLOCKUP_DETECTOR | |
2405 | { | |
2406 | .procname = "hardlockup_panic", | |
2407 | .data = &hardlockup_panic, | |
2408 | .maxlen = sizeof(int), | |
2409 | .mode = 0644, | |
2410 | .proc_handler = proc_dointvec_minmax, | |
2411 | .extra1 = SYSCTL_ZERO, | |
2412 | .extra2 = SYSCTL_ONE, | |
2413 | }, | |
2414 | #ifdef CONFIG_SMP | |
2415 | { | |
2416 | .procname = "hardlockup_all_cpu_backtrace", | |
2417 | .data = &sysctl_hardlockup_all_cpu_backtrace, | |
2418 | .maxlen = sizeof(int), | |
2419 | .mode = 0644, | |
2420 | .proc_handler = proc_dointvec_minmax, | |
2421 | .extra1 = SYSCTL_ZERO, | |
2422 | .extra2 = SYSCTL_ONE, | |
2423 | }, | |
2424 | #endif /* CONFIG_SMP */ | |
2425 | #endif | |
2426 | #endif | |
2427 | ||
2428 | #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) | |
2429 | { | |
2430 | .procname = "unknown_nmi_panic", | |
2431 | .data = &unknown_nmi_panic, | |
2432 | .maxlen = sizeof (int), | |
2433 | .mode = 0644, | |
2434 | .proc_handler = proc_dointvec, | |
2435 | }, | |
2436 | #endif | |
61d9b56a | 2437 | |
cb8e59cc LT |
2438 | #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \ |
2439 | defined(CONFIG_DEBUG_STACKOVERFLOW) | |
f461d2dc | 2440 | { |
cb8e59cc LT |
2441 | .procname = "panic_on_stackoverflow", |
2442 | .data = &sysctl_panic_on_stackoverflow, | |
f461d2dc CH |
2443 | .maxlen = sizeof(int), |
2444 | .mode = 0644, | |
2445 | .proc_handler = proc_dointvec, | |
2446 | }, | |
cb8e59cc LT |
2447 | #endif |
2448 | #if defined(CONFIG_X86) | |
f461d2dc | 2449 | { |
cb8e59cc LT |
2450 | .procname = "panic_on_unrecovered_nmi", |
2451 | .data = &panic_on_unrecovered_nmi, | |
f461d2dc CH |
2452 | .maxlen = sizeof(int), |
2453 | .mode = 0644, | |
2454 | .proc_handler = proc_dointvec, | |
2455 | }, | |
f461d2dc | 2456 | { |
cb8e59cc LT |
2457 | .procname = "panic_on_io_nmi", |
2458 | .data = &panic_on_io_nmi, | |
f461d2dc CH |
2459 | .maxlen = sizeof(int), |
2460 | .mode = 0644, | |
2461 | .proc_handler = proc_dointvec, | |
2462 | }, | |
f461d2dc CH |
2463 | { |
2464 | .procname = "bootloader_type", | |
2465 | .data = &bootloader_type, | |
2466 | .maxlen = sizeof (int), | |
2467 | .mode = 0444, | |
2468 | .proc_handler = proc_dointvec, | |
2469 | }, | |
2470 | { | |
2471 | .procname = "bootloader_version", | |
2472 | .data = &bootloader_version, | |
2473 | .maxlen = sizeof (int), | |
2474 | .mode = 0444, | |
2475 | .proc_handler = proc_dointvec, | |
2476 | }, | |
2477 | { | |
2478 | .procname = "io_delay_type", | |
2479 | .data = &io_delay_type, | |
2480 | .maxlen = sizeof(int), | |
2481 | .mode = 0644, | |
2482 | .proc_handler = proc_dointvec, | |
2483 | }, | |
2484 | #endif | |
2485 | #if defined(CONFIG_MMU) | |
2486 | { | |
2487 | .procname = "randomize_va_space", | |
2488 | .data = &randomize_va_space, | |
2489 | .maxlen = sizeof(int), | |
2490 | .mode = 0644, | |
2491 | .proc_handler = proc_dointvec, | |
2492 | }, | |
2493 | #endif | |
2494 | #if defined(CONFIG_S390) && defined(CONFIG_SMP) | |
2495 | { | |
2496 | .procname = "spin_retry", | |
2497 | .data = &spin_retry, | |
2498 | .maxlen = sizeof (int), | |
2499 | .mode = 0644, | |
2500 | .proc_handler = proc_dointvec, | |
2501 | }, | |
2502 | #endif | |
2503 | #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) | |
2504 | { | |
2505 | .procname = "acpi_video_flags", | |
2506 | .data = &acpi_realmode_flags, | |
2507 | .maxlen = sizeof (unsigned long), | |
2508 | .mode = 0644, | |
2509 | .proc_handler = proc_doulongvec_minmax, | |
2510 | }, | |
2511 | #endif | |
2512 | #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN | |
2513 | { | |
2514 | .procname = "ignore-unaligned-usertrap", | |
2515 | .data = &no_unaligned_warning, | |
2516 | .maxlen = sizeof (int), | |
2517 | .mode = 0644, | |
2518 | .proc_handler = proc_dointvec, | |
2519 | }, | |
2520 | #endif | |
2521 | #ifdef CONFIG_IA64 | |
2522 | { | |
2523 | .procname = "unaligned-dump-stack", | |
2524 | .data = &unaligned_dump_stack, | |
2525 | .maxlen = sizeof (int), | |
2526 | .mode = 0644, | |
2527 | .proc_handler = proc_dointvec, | |
2528 | }, | |
2529 | #endif | |
2530 | #ifdef CONFIG_DETECT_HUNG_TASK | |
0ec9dc9b GP |
2531 | #ifdef CONFIG_SMP |
2532 | { | |
2533 | .procname = "hung_task_all_cpu_backtrace", | |
2534 | .data = &sysctl_hung_task_all_cpu_backtrace, | |
2535 | .maxlen = sizeof(int), | |
2536 | .mode = 0644, | |
2537 | .proc_handler = proc_dointvec_minmax, | |
2538 | .extra1 = SYSCTL_ZERO, | |
2539 | .extra2 = SYSCTL_ONE, | |
2540 | }, | |
2541 | #endif /* CONFIG_SMP */ | |
f461d2dc CH |
2542 | { |
2543 | .procname = "hung_task_panic", | |
2544 | .data = &sysctl_hung_task_panic, | |
2545 | .maxlen = sizeof(int), | |
2546 | .mode = 0644, | |
2547 | .proc_handler = proc_dointvec_minmax, | |
2548 | .extra1 = SYSCTL_ZERO, | |
2549 | .extra2 = SYSCTL_ONE, | |
2550 | }, | |
2551 | { | |
2552 | .procname = "hung_task_check_count", | |
2553 | .data = &sysctl_hung_task_check_count, | |
2554 | .maxlen = sizeof(int), | |
2555 | .mode = 0644, | |
2556 | .proc_handler = proc_dointvec_minmax, | |
2557 | .extra1 = SYSCTL_ZERO, | |
2558 | }, | |
2559 | { | |
2560 | .procname = "hung_task_timeout_secs", | |
2561 | .data = &sysctl_hung_task_timeout_secs, | |
2562 | .maxlen = sizeof(unsigned long), | |
2563 | .mode = 0644, | |
2564 | .proc_handler = proc_dohung_task_timeout_secs, | |
2565 | .extra2 = &hung_task_timeout_max, | |
2566 | }, | |
2567 | { | |
2568 | .procname = "hung_task_check_interval_secs", | |
2569 | .data = &sysctl_hung_task_check_interval_secs, | |
2570 | .maxlen = sizeof(unsigned long), | |
2571 | .mode = 0644, | |
2572 | .proc_handler = proc_dohung_task_timeout_secs, | |
2573 | .extra2 = &hung_task_timeout_max, | |
2574 | }, | |
2575 | { | |
2576 | .procname = "hung_task_warnings", | |
2577 | .data = &sysctl_hung_task_warnings, | |
2578 | .maxlen = sizeof(int), | |
2579 | .mode = 0644, | |
2580 | .proc_handler = proc_dointvec_minmax, | |
3422786f | 2581 | .extra1 = SYSCTL_NEG_ONE, |
f461d2dc CH |
2582 | }, |
2583 | #endif | |
2584 | #ifdef CONFIG_RT_MUTEXES | |
2585 | { | |
2586 | .procname = "max_lock_depth", | |
2587 | .data = &max_lock_depth, | |
2588 | .maxlen = sizeof(int), | |
2589 | .mode = 0644, | |
2590 | .proc_handler = proc_dointvec, | |
2591 | }, | |
2592 | #endif | |
2593 | { | |
2594 | .procname = "poweroff_cmd", | |
2595 | .data = &poweroff_cmd, | |
2596 | .maxlen = POWEROFF_CMD_PATH_LEN, | |
2597 | .mode = 0644, | |
2598 | .proc_handler = proc_dostring, | |
2599 | }, | |
2600 | #ifdef CONFIG_KEYS | |
2601 | { | |
2602 | .procname = "keys", | |
2603 | .mode = 0555, | |
2604 | .child = key_sysctls, | |
2605 | }, | |
2606 | #endif | |
2607 | #ifdef CONFIG_PERF_EVENTS | |
2608 | /* | |
2609 | * User-space scripts rely on the existence of this file | |
2610 | * as a feature check for perf_events being enabled. | |
2611 | * | |
2612 | * So it's an ABI, do not remove! | |
2613 | */ | |
2614 | { | |
2615 | .procname = "perf_event_paranoid", | |
2616 | .data = &sysctl_perf_event_paranoid, | |
2617 | .maxlen = sizeof(sysctl_perf_event_paranoid), | |
2618 | .mode = 0644, | |
2619 | .proc_handler = proc_dointvec, | |
2620 | }, | |
2621 | { | |
2622 | .procname = "perf_event_mlock_kb", | |
2623 | .data = &sysctl_perf_event_mlock, | |
2624 | .maxlen = sizeof(sysctl_perf_event_mlock), | |
2625 | .mode = 0644, | |
2626 | .proc_handler = proc_dointvec, | |
2627 | }, | |
2628 | { | |
2629 | .procname = "perf_event_max_sample_rate", | |
2630 | .data = &sysctl_perf_event_sample_rate, | |
2631 | .maxlen = sizeof(sysctl_perf_event_sample_rate), | |
2632 | .mode = 0644, | |
2633 | .proc_handler = perf_proc_update_handler, | |
2634 | .extra1 = SYSCTL_ONE, | |
2635 | }, | |
2636 | { | |
2637 | .procname = "perf_cpu_time_max_percent", | |
2638 | .data = &sysctl_perf_cpu_time_max_percent, | |
2639 | .maxlen = sizeof(sysctl_perf_cpu_time_max_percent), | |
2640 | .mode = 0644, | |
2641 | .proc_handler = perf_cpu_time_max_percent_handler, | |
2642 | .extra1 = SYSCTL_ZERO, | |
3422786f | 2643 | .extra2 = SYSCTL_ONE_HUNDRED, |
f461d2dc CH |
2644 | }, |
2645 | { | |
2646 | .procname = "perf_event_max_stack", | |
2647 | .data = &sysctl_perf_event_max_stack, | |
2648 | .maxlen = sizeof(sysctl_perf_event_max_stack), | |
2649 | .mode = 0644, | |
2650 | .proc_handler = perf_event_max_stack_handler, | |
2651 | .extra1 = SYSCTL_ZERO, | |
2652 | .extra2 = &six_hundred_forty_kb, | |
2653 | }, | |
2654 | { | |
2655 | .procname = "perf_event_max_contexts_per_stack", | |
2656 | .data = &sysctl_perf_event_max_contexts_per_stack, | |
2657 | .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack), | |
2658 | .mode = 0644, | |
2659 | .proc_handler = perf_event_max_stack_handler, | |
2660 | .extra1 = SYSCTL_ZERO, | |
3422786f | 2661 | .extra2 = SYSCTL_ONE_THOUSAND, |
f461d2dc CH |
2662 | }, |
2663 | #endif | |
2664 | { | |
2665 | .procname = "panic_on_warn", | |
2666 | .data = &panic_on_warn, | |
2667 | .maxlen = sizeof(int), | |
2668 | .mode = 0644, | |
2669 | .proc_handler = proc_dointvec_minmax, | |
2670 | .extra1 = SYSCTL_ZERO, | |
2671 | .extra2 = SYSCTL_ONE, | |
2672 | }, | |
2673 | #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) | |
2674 | { | |
2675 | .procname = "timer_migration", | |
2676 | .data = &sysctl_timer_migration, | |
2677 | .maxlen = sizeof(unsigned int), | |
2678 | .mode = 0644, | |
2679 | .proc_handler = timer_migration_handler, | |
2680 | .extra1 = SYSCTL_ZERO, | |
2681 | .extra2 = SYSCTL_ONE, | |
2682 | }, | |
2683 | #endif | |
2684 | #ifdef CONFIG_BPF_SYSCALL | |
2685 | { | |
2686 | .procname = "unprivileged_bpf_disabled", | |
2687 | .data = &sysctl_unprivileged_bpf_disabled, | |
2688 | .maxlen = sizeof(sysctl_unprivileged_bpf_disabled), | |
2689 | .mode = 0644, | |
08389d88 DB |
2690 | .proc_handler = bpf_unpriv_handler, |
2691 | .extra1 = SYSCTL_ZERO, | |
3422786f | 2692 | .extra2 = SYSCTL_TWO, |
f461d2dc CH |
2693 | }, |
2694 | { | |
2695 | .procname = "bpf_stats_enabled", | |
2696 | .data = &bpf_stats_enabled_key.key, | |
2697 | .maxlen = sizeof(bpf_stats_enabled_key), | |
2698 | .mode = 0644, | |
d46edd67 | 2699 | .proc_handler = bpf_stats_handler, |
f461d2dc CH |
2700 | }, |
2701 | #endif | |
2702 | #if defined(CONFIG_TREE_RCU) | |
2703 | { | |
2704 | .procname = "panic_on_rcu_stall", | |
2705 | .data = &sysctl_panic_on_rcu_stall, | |
2706 | .maxlen = sizeof(sysctl_panic_on_rcu_stall), | |
2707 | .mode = 0644, | |
2708 | .proc_handler = proc_dointvec_minmax, | |
2709 | .extra1 = SYSCTL_ZERO, | |
2710 | .extra2 = SYSCTL_ONE, | |
2711 | }, | |
2712 | #endif | |
dfe56404 | 2713 | #if defined(CONFIG_TREE_RCU) |
2714 | { | |
2715 | .procname = "max_rcu_stall_to_panic", | |
2716 | .data = &sysctl_max_rcu_stall_to_panic, | |
2717 | .maxlen = sizeof(sysctl_max_rcu_stall_to_panic), | |
2718 | .mode = 0644, | |
2719 | .proc_handler = proc_dointvec_minmax, | |
2720 | .extra1 = SYSCTL_ONE, | |
2721 | .extra2 = SYSCTL_INT_MAX, | |
2722 | }, | |
2723 | #endif | |
f461d2dc CH |
2724 | #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE |
2725 | { | |
2726 | .procname = "stack_erasing", | |
2727 | .data = NULL, | |
2728 | .maxlen = sizeof(int), | |
2729 | .mode = 0600, | |
2730 | .proc_handler = stack_erasing_sysctl, | |
2731 | .extra1 = SYSCTL_ZERO, | |
2732 | .extra2 = SYSCTL_ONE, | |
2733 | }, | |
2734 | #endif | |
2735 | { } | |
2736 | }; | |
1da177e4 | 2737 | |
f461d2dc CH |
2738 | static struct ctl_table vm_table[] = { |
2739 | { | |
2740 | .procname = "overcommit_memory", | |
2741 | .data = &sysctl_overcommit_memory, | |
2742 | .maxlen = sizeof(sysctl_overcommit_memory), | |
2743 | .mode = 0644, | |
56f3547b | 2744 | .proc_handler = overcommit_policy_handler, |
f461d2dc | 2745 | .extra1 = SYSCTL_ZERO, |
3422786f | 2746 | .extra2 = SYSCTL_TWO, |
f461d2dc CH |
2747 | }, |
2748 | { | |
2749 | .procname = "panic_on_oom", | |
2750 | .data = &sysctl_panic_on_oom, | |
2751 | .maxlen = sizeof(sysctl_panic_on_oom), | |
2752 | .mode = 0644, | |
2753 | .proc_handler = proc_dointvec_minmax, | |
2754 | .extra1 = SYSCTL_ZERO, | |
3422786f | 2755 | .extra2 = SYSCTL_TWO, |
f461d2dc CH |
2756 | }, |
2757 | { | |
2758 | .procname = "oom_kill_allocating_task", | |
2759 | .data = &sysctl_oom_kill_allocating_task, | |
2760 | .maxlen = sizeof(sysctl_oom_kill_allocating_task), | |
2761 | .mode = 0644, | |
2762 | .proc_handler = proc_dointvec, | |
2763 | }, | |
2764 | { | |
2765 | .procname = "oom_dump_tasks", | |
2766 | .data = &sysctl_oom_dump_tasks, | |
2767 | .maxlen = sizeof(sysctl_oom_dump_tasks), | |
2768 | .mode = 0644, | |
2769 | .proc_handler = proc_dointvec, | |
2770 | }, | |
2771 | { | |
2772 | .procname = "overcommit_ratio", | |
2773 | .data = &sysctl_overcommit_ratio, | |
2774 | .maxlen = sizeof(sysctl_overcommit_ratio), | |
2775 | .mode = 0644, | |
2776 | .proc_handler = overcommit_ratio_handler, | |
2777 | }, | |
2778 | { | |
2779 | .procname = "overcommit_kbytes", | |
2780 | .data = &sysctl_overcommit_kbytes, | |
2781 | .maxlen = sizeof(sysctl_overcommit_kbytes), | |
2782 | .mode = 0644, | |
2783 | .proc_handler = overcommit_kbytes_handler, | |
2784 | }, | |
2785 | { | |
2786 | .procname = "page-cluster", | |
2787 | .data = &page_cluster, | |
2788 | .maxlen = sizeof(int), | |
2789 | .mode = 0644, | |
2790 | .proc_handler = proc_dointvec_minmax, | |
2791 | .extra1 = SYSCTL_ZERO, | |
2792 | }, | |
2793 | { | |
2794 | .procname = "dirty_background_ratio", | |
2795 | .data = &dirty_background_ratio, | |
2796 | .maxlen = sizeof(dirty_background_ratio), | |
2797 | .mode = 0644, | |
2798 | .proc_handler = dirty_background_ratio_handler, | |
2799 | .extra1 = SYSCTL_ZERO, | |
3422786f | 2800 | .extra2 = SYSCTL_ONE_HUNDRED, |
f461d2dc CH |
2801 | }, |
2802 | { | |
2803 | .procname = "dirty_background_bytes", | |
2804 | .data = &dirty_background_bytes, | |
2805 | .maxlen = sizeof(dirty_background_bytes), | |
2806 | .mode = 0644, | |
2807 | .proc_handler = dirty_background_bytes_handler, | |
2808 | .extra1 = &one_ul, | |
2809 | }, | |
2810 | { | |
2811 | .procname = "dirty_ratio", | |
2812 | .data = &vm_dirty_ratio, | |
2813 | .maxlen = sizeof(vm_dirty_ratio), | |
2814 | .mode = 0644, | |
2815 | .proc_handler = dirty_ratio_handler, | |
2816 | .extra1 = SYSCTL_ZERO, | |
3422786f | 2817 | .extra2 = SYSCTL_ONE_HUNDRED, |
f461d2dc CH |
2818 | }, |
2819 | { | |
2820 | .procname = "dirty_bytes", | |
2821 | .data = &vm_dirty_bytes, | |
2822 | .maxlen = sizeof(vm_dirty_bytes), | |
2823 | .mode = 0644, | |
2824 | .proc_handler = dirty_bytes_handler, | |
2825 | .extra1 = &dirty_bytes_min, | |
2826 | }, | |
2827 | { | |
2828 | .procname = "dirty_writeback_centisecs", | |
2829 | .data = &dirty_writeback_interval, | |
2830 | .maxlen = sizeof(dirty_writeback_interval), | |
2831 | .mode = 0644, | |
2832 | .proc_handler = dirty_writeback_centisecs_handler, | |
2833 | }, | |
2834 | { | |
2835 | .procname = "dirty_expire_centisecs", | |
2836 | .data = &dirty_expire_interval, | |
2837 | .maxlen = sizeof(dirty_expire_interval), | |
2838 | .mode = 0644, | |
2839 | .proc_handler = proc_dointvec_minmax, | |
2840 | .extra1 = SYSCTL_ZERO, | |
2841 | }, | |
2842 | { | |
2843 | .procname = "dirtytime_expire_seconds", | |
2844 | .data = &dirtytime_expire_interval, | |
2845 | .maxlen = sizeof(dirtytime_expire_interval), | |
2846 | .mode = 0644, | |
2847 | .proc_handler = dirtytime_interval_handler, | |
2848 | .extra1 = SYSCTL_ZERO, | |
2849 | }, | |
2850 | { | |
2851 | .procname = "swappiness", | |
2852 | .data = &vm_swappiness, | |
2853 | .maxlen = sizeof(vm_swappiness), | |
2854 | .mode = 0644, | |
2855 | .proc_handler = proc_dointvec_minmax, | |
2856 | .extra1 = SYSCTL_ZERO, | |
3422786f | 2857 | .extra2 = SYSCTL_TWO_HUNDRED, |
f461d2dc | 2858 | }, |
bfdc9430 MS |
2859 | #ifdef CONFIG_NUMA |
2860 | { | |
2861 | .procname = "numa_stat", | |
2862 | .data = &sysctl_vm_numa_stat, | |
2863 | .maxlen = sizeof(int), | |
2864 | .mode = 0644, | |
2865 | .proc_handler = sysctl_vm_numa_stat_handler, | |
2866 | .extra1 = SYSCTL_ZERO, | |
2867 | .extra2 = SYSCTL_ONE, | |
2868 | }, | |
2869 | #endif | |
f461d2dc CH |
2870 | #ifdef CONFIG_HUGETLB_PAGE |
2871 | { | |
2872 | .procname = "nr_hugepages", | |
2873 | .data = NULL, | |
2874 | .maxlen = sizeof(unsigned long), | |
2875 | .mode = 0644, | |
2876 | .proc_handler = hugetlb_sysctl_handler, | |
2877 | }, | |
2878 | #ifdef CONFIG_NUMA | |
2879 | { | |
2880 | .procname = "nr_hugepages_mempolicy", | |
2881 | .data = NULL, | |
2882 | .maxlen = sizeof(unsigned long), | |
2883 | .mode = 0644, | |
2884 | .proc_handler = &hugetlb_mempolicy_sysctl_handler, | |
2885 | }, | |
f461d2dc CH |
2886 | #endif |
2887 | { | |
2888 | .procname = "hugetlb_shm_group", | |
2889 | .data = &sysctl_hugetlb_shm_group, | |
2890 | .maxlen = sizeof(gid_t), | |
2891 | .mode = 0644, | |
2892 | .proc_handler = proc_dointvec, | |
2893 | }, | |
2894 | { | |
2895 | .procname = "nr_overcommit_hugepages", | |
2896 | .data = NULL, | |
2897 | .maxlen = sizeof(unsigned long), | |
2898 | .mode = 0644, | |
2899 | .proc_handler = hugetlb_overcommit_handler, | |
2900 | }, | |
2901 | #endif | |
2902 | { | |
2903 | .procname = "lowmem_reserve_ratio", | |
2904 | .data = &sysctl_lowmem_reserve_ratio, | |
2905 | .maxlen = sizeof(sysctl_lowmem_reserve_ratio), | |
2906 | .mode = 0644, | |
2907 | .proc_handler = lowmem_reserve_ratio_sysctl_handler, | |
2908 | }, | |
2909 | { | |
2910 | .procname = "drop_caches", | |
2911 | .data = &sysctl_drop_caches, | |
2912 | .maxlen = sizeof(int), | |
2913 | .mode = 0200, | |
2914 | .proc_handler = drop_caches_sysctl_handler, | |
2915 | .extra1 = SYSCTL_ONE, | |
3422786f | 2916 | .extra2 = SYSCTL_FOUR, |
f461d2dc CH |
2917 | }, |
2918 | #ifdef CONFIG_COMPACTION | |
2919 | { | |
2920 | .procname = "compact_memory", | |
ef498438 | 2921 | .data = NULL, |
f461d2dc CH |
2922 | .maxlen = sizeof(int), |
2923 | .mode = 0200, | |
2924 | .proc_handler = sysctl_compaction_handler, | |
2925 | }, | |
facdaa91 NG |
2926 | { |
2927 | .procname = "compaction_proactiveness", | |
2928 | .data = &sysctl_compaction_proactiveness, | |
d34c0a75 | 2929 | .maxlen = sizeof(sysctl_compaction_proactiveness), |
facdaa91 | 2930 | .mode = 0644, |
65d759c8 | 2931 | .proc_handler = compaction_proactiveness_sysctl_handler, |
facdaa91 | 2932 | .extra1 = SYSCTL_ZERO, |
3422786f | 2933 | .extra2 = SYSCTL_ONE_HUNDRED, |
facdaa91 | 2934 | }, |
f461d2dc CH |
2935 | { |
2936 | .procname = "extfrag_threshold", | |
2937 | .data = &sysctl_extfrag_threshold, | |
2938 | .maxlen = sizeof(int), | |
2939 | .mode = 0644, | |
2940 | .proc_handler = proc_dointvec_minmax, | |
2941 | .extra1 = &min_extfrag_threshold, | |
2942 | .extra2 = &max_extfrag_threshold, | |
2943 | }, | |
2944 | { | |
2945 | .procname = "compact_unevictable_allowed", | |
2946 | .data = &sysctl_compact_unevictable_allowed, | |
2947 | .maxlen = sizeof(int), | |
2948 | .mode = 0644, | |
2949 | .proc_handler = proc_dointvec_minmax_warn_RT_change, | |
2950 | .extra1 = SYSCTL_ZERO, | |
2951 | .extra2 = SYSCTL_ONE, | |
2952 | }, | |
1da177e4 | 2953 | |
f461d2dc CH |
2954 | #endif /* CONFIG_COMPACTION */ |
2955 | { | |
2956 | .procname = "min_free_kbytes", | |
2957 | .data = &min_free_kbytes, | |
2958 | .maxlen = sizeof(min_free_kbytes), | |
2959 | .mode = 0644, | |
2960 | .proc_handler = min_free_kbytes_sysctl_handler, | |
2961 | .extra1 = SYSCTL_ZERO, | |
2962 | }, | |
2963 | { | |
2964 | .procname = "watermark_boost_factor", | |
2965 | .data = &watermark_boost_factor, | |
2966 | .maxlen = sizeof(watermark_boost_factor), | |
2967 | .mode = 0644, | |
2968 | .proc_handler = proc_dointvec_minmax, | |
2969 | .extra1 = SYSCTL_ZERO, | |
2970 | }, | |
2971 | { | |
2972 | .procname = "watermark_scale_factor", | |
2973 | .data = &watermark_scale_factor, | |
2974 | .maxlen = sizeof(watermark_scale_factor), | |
2975 | .mode = 0644, | |
2976 | .proc_handler = watermark_scale_factor_sysctl_handler, | |
2977 | .extra1 = SYSCTL_ONE, | |
3422786f | 2978 | .extra2 = SYSCTL_THREE_THOUSAND, |
f461d2dc CH |
2979 | }, |
2980 | { | |
74f44822 MG |
2981 | .procname = "percpu_pagelist_high_fraction", |
2982 | .data = &percpu_pagelist_high_fraction, | |
2983 | .maxlen = sizeof(percpu_pagelist_high_fraction), | |
f461d2dc | 2984 | .mode = 0644, |
74f44822 | 2985 | .proc_handler = percpu_pagelist_high_fraction_sysctl_handler, |
f461d2dc CH |
2986 | .extra1 = SYSCTL_ZERO, |
2987 | }, | |
5ef64cc8 LT |
2988 | { |
2989 | .procname = "page_lock_unfairness", | |
2990 | .data = &sysctl_page_lock_unfairness, | |
2991 | .maxlen = sizeof(sysctl_page_lock_unfairness), | |
2992 | .mode = 0644, | |
2993 | .proc_handler = proc_dointvec_minmax, | |
2994 | .extra1 = SYSCTL_ZERO, | |
2995 | }, | |
f461d2dc CH |
2996 | #ifdef CONFIG_MMU |
2997 | { | |
2998 | .procname = "max_map_count", | |
2999 | .data = &sysctl_max_map_count, | |
3000 | .maxlen = sizeof(sysctl_max_map_count), | |
3001 | .mode = 0644, | |
3002 | .proc_handler = proc_dointvec_minmax, | |
3003 | .extra1 = SYSCTL_ZERO, | |
3004 | }, | |
3005 | #else | |
3006 | { | |
3007 | .procname = "nr_trim_pages", | |
3008 | .data = &sysctl_nr_trim_pages, | |
3009 | .maxlen = sizeof(sysctl_nr_trim_pages), | |
3010 | .mode = 0644, | |
3011 | .proc_handler = proc_dointvec_minmax, | |
3012 | .extra1 = SYSCTL_ZERO, | |
3013 | }, | |
3014 | #endif | |
3015 | { | |
3016 | .procname = "laptop_mode", | |
3017 | .data = &laptop_mode, | |
3018 | .maxlen = sizeof(laptop_mode), | |
3019 | .mode = 0644, | |
3020 | .proc_handler = proc_dointvec_jiffies, | |
3021 | }, | |
f461d2dc CH |
3022 | { |
3023 | .procname = "vfs_cache_pressure", | |
3024 | .data = &sysctl_vfs_cache_pressure, | |
3025 | .maxlen = sizeof(sysctl_vfs_cache_pressure), | |
3026 | .mode = 0644, | |
3b3376f2 | 3027 | .proc_handler = proc_dointvec_minmax, |
f461d2dc CH |
3028 | .extra1 = SYSCTL_ZERO, |
3029 | }, | |
3030 | #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ | |
3031 | defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) | |
3032 | { | |
3033 | .procname = "legacy_va_layout", | |
3034 | .data = &sysctl_legacy_va_layout, | |
3035 | .maxlen = sizeof(sysctl_legacy_va_layout), | |
3036 | .mode = 0644, | |
3b3376f2 | 3037 | .proc_handler = proc_dointvec_minmax, |
f461d2dc CH |
3038 | .extra1 = SYSCTL_ZERO, |
3039 | }, | |
3040 | #endif | |
3041 | #ifdef CONFIG_NUMA | |
3042 | { | |
3043 | .procname = "zone_reclaim_mode", | |
3044 | .data = &node_reclaim_mode, | |
3045 | .maxlen = sizeof(node_reclaim_mode), | |
3046 | .mode = 0644, | |
3b3376f2 | 3047 | .proc_handler = proc_dointvec_minmax, |
f461d2dc CH |
3048 | .extra1 = SYSCTL_ZERO, |
3049 | }, | |
3050 | { | |
3051 | .procname = "min_unmapped_ratio", | |
3052 | .data = &sysctl_min_unmapped_ratio, | |
3053 | .maxlen = sizeof(sysctl_min_unmapped_ratio), | |
3054 | .mode = 0644, | |
3055 | .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler, | |
3056 | .extra1 = SYSCTL_ZERO, | |
3422786f | 3057 | .extra2 = SYSCTL_ONE_HUNDRED, |
f461d2dc CH |
3058 | }, |
3059 | { | |
3060 | .procname = "min_slab_ratio", | |
3061 | .data = &sysctl_min_slab_ratio, | |
3062 | .maxlen = sizeof(sysctl_min_slab_ratio), | |
3063 | .mode = 0644, | |
3064 | .proc_handler = sysctl_min_slab_ratio_sysctl_handler, | |
3065 | .extra1 = SYSCTL_ZERO, | |
3422786f | 3066 | .extra2 = SYSCTL_ONE_HUNDRED, |
f461d2dc CH |
3067 | }, |
3068 | #endif | |
3069 | #ifdef CONFIG_SMP | |
3070 | { | |
3071 | .procname = "stat_interval", | |
3072 | .data = &sysctl_stat_interval, | |
3073 | .maxlen = sizeof(sysctl_stat_interval), | |
3074 | .mode = 0644, | |
3075 | .proc_handler = proc_dointvec_jiffies, | |
3076 | }, | |
3077 | { | |
3078 | .procname = "stat_refresh", | |
3079 | .data = NULL, | |
3080 | .maxlen = 0, | |
3081 | .mode = 0600, | |
3082 | .proc_handler = vmstat_refresh, | |
3083 | }, | |
3084 | #endif | |
3085 | #ifdef CONFIG_MMU | |
3086 | { | |
3087 | .procname = "mmap_min_addr", | |
3088 | .data = &dac_mmap_min_addr, | |
3089 | .maxlen = sizeof(unsigned long), | |
3090 | .mode = 0644, | |
3091 | .proc_handler = mmap_min_addr_handler, | |
3092 | }, | |
3093 | #endif | |
3094 | #ifdef CONFIG_NUMA | |
3095 | { | |
3096 | .procname = "numa_zonelist_order", | |
3097 | .data = &numa_zonelist_order, | |
3098 | .maxlen = NUMA_ZONELIST_ORDER_LEN, | |
3099 | .mode = 0644, | |
3100 | .proc_handler = numa_zonelist_order_handler, | |
3101 | }, | |
3102 | #endif | |
3103 | #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ | |
3104 | (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) | |
3105 | { | |
3106 | .procname = "vdso_enabled", | |
3107 | #ifdef CONFIG_X86_32 | |
3108 | .data = &vdso32_enabled, | |
3109 | .maxlen = sizeof(vdso32_enabled), | |
3110 | #else | |
3111 | .data = &vdso_enabled, | |
3112 | .maxlen = sizeof(vdso_enabled), | |
3113 | #endif | |
3114 | .mode = 0644, | |
3115 | .proc_handler = proc_dointvec, | |
3116 | .extra1 = SYSCTL_ZERO, | |
3117 | }, | |
3118 | #endif | |
3119 | #ifdef CONFIG_HIGHMEM | |
3120 | { | |
3121 | .procname = "highmem_is_dirtyable", | |
3122 | .data = &vm_highmem_is_dirtyable, | |
3123 | .maxlen = sizeof(vm_highmem_is_dirtyable), | |
3124 | .mode = 0644, | |
3125 | .proc_handler = proc_dointvec_minmax, | |
3126 | .extra1 = SYSCTL_ZERO, | |
3127 | .extra2 = SYSCTL_ONE, | |
3128 | }, | |
3129 | #endif | |
3130 | #ifdef CONFIG_MEMORY_FAILURE | |
3131 | { | |
3132 | .procname = "memory_failure_early_kill", | |
3133 | .data = &sysctl_memory_failure_early_kill, | |
3134 | .maxlen = sizeof(sysctl_memory_failure_early_kill), | |
3135 | .mode = 0644, | |
3136 | .proc_handler = proc_dointvec_minmax, | |
3137 | .extra1 = SYSCTL_ZERO, | |
3138 | .extra2 = SYSCTL_ONE, | |
3139 | }, | |
3140 | { | |
3141 | .procname = "memory_failure_recovery", | |
3142 | .data = &sysctl_memory_failure_recovery, | |
3143 | .maxlen = sizeof(sysctl_memory_failure_recovery), | |
3144 | .mode = 0644, | |
3145 | .proc_handler = proc_dointvec_minmax, | |
3146 | .extra1 = SYSCTL_ZERO, | |
3147 | .extra2 = SYSCTL_ONE, | |
3148 | }, | |
3149 | #endif | |
3150 | { | |
3151 | .procname = "user_reserve_kbytes", | |
3152 | .data = &sysctl_user_reserve_kbytes, | |
3153 | .maxlen = sizeof(sysctl_user_reserve_kbytes), | |
3154 | .mode = 0644, | |
3155 | .proc_handler = proc_doulongvec_minmax, | |
3156 | }, | |
3157 | { | |
3158 | .procname = "admin_reserve_kbytes", | |
3159 | .data = &sysctl_admin_reserve_kbytes, | |
3160 | .maxlen = sizeof(sysctl_admin_reserve_kbytes), | |
3161 | .mode = 0644, | |
3162 | .proc_handler = proc_doulongvec_minmax, | |
3163 | }, | |
3164 | #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS | |
3165 | { | |
3166 | .procname = "mmap_rnd_bits", | |
3167 | .data = &mmap_rnd_bits, | |
3168 | .maxlen = sizeof(mmap_rnd_bits), | |
3169 | .mode = 0600, | |
3170 | .proc_handler = proc_dointvec_minmax, | |
3171 | .extra1 = (void *)&mmap_rnd_bits_min, | |
3172 | .extra2 = (void *)&mmap_rnd_bits_max, | |
3173 | }, | |
3174 | #endif | |
3175 | #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS | |
3176 | { | |
3177 | .procname = "mmap_rnd_compat_bits", | |
3178 | .data = &mmap_rnd_compat_bits, | |
3179 | .maxlen = sizeof(mmap_rnd_compat_bits), | |
3180 | .mode = 0600, | |
3181 | .proc_handler = proc_dointvec_minmax, | |
3182 | .extra1 = (void *)&mmap_rnd_compat_bits_min, | |
3183 | .extra2 = (void *)&mmap_rnd_compat_bits_max, | |
3184 | }, | |
3185 | #endif | |
3186 | #ifdef CONFIG_USERFAULTFD | |
3187 | { | |
3188 | .procname = "unprivileged_userfaultfd", | |
3189 | .data = &sysctl_unprivileged_userfaultfd, | |
3190 | .maxlen = sizeof(sysctl_unprivileged_userfaultfd), | |
3191 | .mode = 0644, | |
3192 | .proc_handler = proc_dointvec_minmax, | |
3193 | .extra1 = SYSCTL_ZERO, | |
3194 | .extra2 = SYSCTL_ONE, | |
3195 | }, | |
3196 | #endif | |
3197 | { } | |
3198 | }; | |
1da177e4 | 3199 | |
f461d2dc CH |
3200 | static struct ctl_table fs_table[] = { |
3201 | { | |
3202 | .procname = "inode-nr", | |
3203 | .data = &inodes_stat, | |
3204 | .maxlen = 2*sizeof(long), | |
3205 | .mode = 0444, | |
3206 | .proc_handler = proc_nr_inodes, | |
3207 | }, | |
3208 | { | |
3209 | .procname = "inode-state", | |
3210 | .data = &inodes_stat, | |
3211 | .maxlen = 7*sizeof(long), | |
3212 | .mode = 0444, | |
3213 | .proc_handler = proc_nr_inodes, | |
3214 | }, | |
3215 | { | |
3216 | .procname = "file-nr", | |
3217 | .data = &files_stat, | |
3218 | .maxlen = sizeof(files_stat), | |
3219 | .mode = 0444, | |
3220 | .proc_handler = proc_nr_files, | |
3221 | }, | |
3222 | { | |
3223 | .procname = "file-max", | |
3224 | .data = &files_stat.max_files, | |
3225 | .maxlen = sizeof(files_stat.max_files), | |
3226 | .mode = 0644, | |
3227 | .proc_handler = proc_doulongvec_minmax, | |
3228 | .extra1 = &zero_ul, | |
3229 | .extra2 = &long_max, | |
3230 | }, | |
3231 | { | |
3232 | .procname = "nr_open", | |
3233 | .data = &sysctl_nr_open, | |
3234 | .maxlen = sizeof(unsigned int), | |
3235 | .mode = 0644, | |
3236 | .proc_handler = proc_dointvec_minmax, | |
3237 | .extra1 = &sysctl_nr_open_min, | |
3238 | .extra2 = &sysctl_nr_open_max, | |
3239 | }, | |
3240 | { | |
3241 | .procname = "dentry-state", | |
3242 | .data = &dentry_stat, | |
3243 | .maxlen = 6*sizeof(long), | |
3244 | .mode = 0444, | |
3245 | .proc_handler = proc_nr_dentry, | |
3246 | }, | |
3247 | { | |
3248 | .procname = "overflowuid", | |
3249 | .data = &fs_overflowuid, | |
3250 | .maxlen = sizeof(int), | |
3251 | .mode = 0644, | |
3252 | .proc_handler = proc_dointvec_minmax, | |
3253 | .extra1 = &minolduid, | |
3254 | .extra2 = &maxolduid, | |
3255 | }, | |
3256 | { | |
3257 | .procname = "overflowgid", | |
3258 | .data = &fs_overflowgid, | |
3259 | .maxlen = sizeof(int), | |
3260 | .mode = 0644, | |
3261 | .proc_handler = proc_dointvec_minmax, | |
3262 | .extra1 = &minolduid, | |
3263 | .extra2 = &maxolduid, | |
3264 | }, | |
3265 | #ifdef CONFIG_FILE_LOCKING | |
3266 | { | |
3267 | .procname = "leases-enable", | |
3268 | .data = &leases_enable, | |
3269 | .maxlen = sizeof(int), | |
3270 | .mode = 0644, | |
3271 | .proc_handler = proc_dointvec, | |
3272 | }, | |
3273 | #endif | |
3274 | #ifdef CONFIG_DNOTIFY | |
3275 | { | |
3276 | .procname = "dir-notify-enable", | |
3277 | .data = &dir_notify_enable, | |
3278 | .maxlen = sizeof(int), | |
3279 | .mode = 0644, | |
3280 | .proc_handler = proc_dointvec, | |
3281 | }, | |
3282 | #endif | |
3283 | #ifdef CONFIG_MMU | |
3284 | #ifdef CONFIG_FILE_LOCKING | |
3285 | { | |
3286 | .procname = "lease-break-time", | |
3287 | .data = &lease_break_time, | |
3288 | .maxlen = sizeof(int), | |
3289 | .mode = 0644, | |
3290 | .proc_handler = proc_dointvec, | |
3291 | }, | |
3292 | #endif | |
3293 | #ifdef CONFIG_AIO | |
3294 | { | |
3295 | .procname = "aio-nr", | |
3296 | .data = &aio_nr, | |
3297 | .maxlen = sizeof(aio_nr), | |
3298 | .mode = 0444, | |
3299 | .proc_handler = proc_doulongvec_minmax, | |
3300 | }, | |
3301 | { | |
3302 | .procname = "aio-max-nr", | |
3303 | .data = &aio_max_nr, | |
3304 | .maxlen = sizeof(aio_max_nr), | |
3305 | .mode = 0644, | |
3306 | .proc_handler = proc_doulongvec_minmax, | |
3307 | }, | |
3308 | #endif /* CONFIG_AIO */ | |
3309 | #ifdef CONFIG_INOTIFY_USER | |
3310 | { | |
3311 | .procname = "inotify", | |
3312 | .mode = 0555, | |
3313 | .child = inotify_table, | |
3314 | }, | |
5b8fea65 AG |
3315 | #endif |
3316 | #ifdef CONFIG_FANOTIFY | |
3317 | { | |
3318 | .procname = "fanotify", | |
3319 | .mode = 0555, | |
3320 | .child = fanotify_table, | |
3321 | }, | |
3322 | #endif | |
f461d2dc CH |
3323 | #ifdef CONFIG_EPOLL |
3324 | { | |
3325 | .procname = "epoll", | |
3326 | .mode = 0555, | |
3327 | .child = epoll_table, | |
3328 | }, | |
3329 | #endif | |
3330 | #endif | |
3331 | { | |
3332 | .procname = "protected_symlinks", | |
3333 | .data = &sysctl_protected_symlinks, | |
3334 | .maxlen = sizeof(int), | |
3335 | .mode = 0600, | |
3336 | .proc_handler = proc_dointvec_minmax, | |
3337 | .extra1 = SYSCTL_ZERO, | |
3338 | .extra2 = SYSCTL_ONE, | |
3339 | }, | |
3340 | { | |
3341 | .procname = "protected_hardlinks", | |
3342 | .data = &sysctl_protected_hardlinks, | |
3343 | .maxlen = sizeof(int), | |
3344 | .mode = 0600, | |
3345 | .proc_handler = proc_dointvec_minmax, | |
3346 | .extra1 = SYSCTL_ZERO, | |
3347 | .extra2 = SYSCTL_ONE, | |
3348 | }, | |
3349 | { | |
3350 | .procname = "protected_fifos", | |
3351 | .data = &sysctl_protected_fifos, | |
3352 | .maxlen = sizeof(int), | |
3353 | .mode = 0600, | |
3354 | .proc_handler = proc_dointvec_minmax, | |
3355 | .extra1 = SYSCTL_ZERO, | |
3422786f | 3356 | .extra2 = SYSCTL_TWO, |
f461d2dc CH |
3357 | }, |
3358 | { | |
3359 | .procname = "protected_regular", | |
3360 | .data = &sysctl_protected_regular, | |
3361 | .maxlen = sizeof(int), | |
3362 | .mode = 0600, | |
3363 | .proc_handler = proc_dointvec_minmax, | |
3364 | .extra1 = SYSCTL_ZERO, | |
3422786f | 3365 | .extra2 = SYSCTL_TWO, |
f461d2dc CH |
3366 | }, |
3367 | { | |
3368 | .procname = "suid_dumpable", | |
3369 | .data = &suid_dumpable, | |
3370 | .maxlen = sizeof(int), | |
3371 | .mode = 0644, | |
3372 | .proc_handler = proc_dointvec_minmax_coredump, | |
3373 | .extra1 = SYSCTL_ZERO, | |
3422786f | 3374 | .extra2 = SYSCTL_TWO, |
f461d2dc CH |
3375 | }, |
3376 | #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) | |
3377 | { | |
3378 | .procname = "binfmt_misc", | |
3379 | .mode = 0555, | |
3380 | .child = sysctl_mount_point, | |
3381 | }, | |
3382 | #endif | |
3383 | { | |
3384 | .procname = "pipe-max-size", | |
3385 | .data = &pipe_max_size, | |
3386 | .maxlen = sizeof(pipe_max_size), | |
3387 | .mode = 0644, | |
3388 | .proc_handler = proc_dopipe_max_size, | |
3389 | }, | |
3390 | { | |
3391 | .procname = "pipe-user-pages-hard", | |
3392 | .data = &pipe_user_pages_hard, | |
3393 | .maxlen = sizeof(pipe_user_pages_hard), | |
3394 | .mode = 0644, | |
3395 | .proc_handler = proc_doulongvec_minmax, | |
3396 | }, | |
3397 | { | |
3398 | .procname = "pipe-user-pages-soft", | |
3399 | .data = &pipe_user_pages_soft, | |
3400 | .maxlen = sizeof(pipe_user_pages_soft), | |
3401 | .mode = 0644, | |
3402 | .proc_handler = proc_doulongvec_minmax, | |
3403 | }, | |
3404 | { | |
3405 | .procname = "mount-max", | |
3406 | .data = &sysctl_mount_max, | |
3407 | .maxlen = sizeof(unsigned int), | |
3408 | .mode = 0644, | |
3409 | .proc_handler = proc_dointvec_minmax, | |
3410 | .extra1 = SYSCTL_ONE, | |
3411 | }, | |
3412 | { } | |
3413 | }; | |
1da177e4 | 3414 | |
f461d2dc CH |
3415 | static struct ctl_table debug_table[] = { |
3416 | #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE | |
3417 | { | |
3418 | .procname = "exception-trace", | |
3419 | .data = &show_unhandled_signals, | |
3420 | .maxlen = sizeof(int), | |
3421 | .mode = 0644, | |
3422 | .proc_handler = proc_dointvec | |
3423 | }, | |
3424 | #endif | |
3425 | #if defined(CONFIG_OPTPROBES) | |
3426 | { | |
3427 | .procname = "kprobes-optimization", | |
3428 | .data = &sysctl_kprobes_optimization, | |
3429 | .maxlen = sizeof(int), | |
3430 | .mode = 0644, | |
3431 | .proc_handler = proc_kprobes_optimization_handler, | |
3432 | .extra1 = SYSCTL_ZERO, | |
3433 | .extra2 = SYSCTL_ONE, | |
3434 | }, | |
3435 | #endif | |
3436 | { } | |
3437 | }; | |
1da177e4 | 3438 | |
f461d2dc CH |
3439 | static struct ctl_table dev_table[] = { |
3440 | { } | |
3441 | }; | |
1da177e4 | 3442 | |
f461d2dc CH |
3443 | static struct ctl_table sysctl_base_table[] = { |
3444 | { | |
3445 | .procname = "kernel", | |
3446 | .mode = 0555, | |
3447 | .child = kern_table, | |
3448 | }, | |
3449 | { | |
3450 | .procname = "vm", | |
3451 | .mode = 0555, | |
3452 | .child = vm_table, | |
3453 | }, | |
3454 | { | |
3455 | .procname = "fs", | |
3456 | .mode = 0555, | |
3457 | .child = fs_table, | |
3458 | }, | |
3459 | { | |
3460 | .procname = "debug", | |
3461 | .mode = 0555, | |
3462 | .child = debug_table, | |
3463 | }, | |
3464 | { | |
3465 | .procname = "dev", | |
3466 | .mode = 0555, | |
3467 | .child = dev_table, | |
3468 | }, | |
3469 | { } | |
3470 | }; | |
1da177e4 | 3471 | |
f461d2dc | 3472 | int __init sysctl_init(void) |
492ecee8 | 3473 | { |
f461d2dc | 3474 | struct ctl_table_header *hdr; |
492ecee8 | 3475 | |
f461d2dc CH |
3476 | hdr = register_sysctl_table(sysctl_base_table); |
3477 | kmemleak_not_leak(hdr); | |
3478 | return 0; | |
492ecee8 | 3479 | } |
f461d2dc | 3480 | #endif /* CONFIG_SYSCTL */ |
1da177e4 LT |
3481 | /* |
3482 | * No sense putting this after each symbol definition, twice, | |
3483 | * exception granted :-) | |
3484 | */ | |
a2071573 | 3485 | EXPORT_SYMBOL(proc_dobool); |
1da177e4 | 3486 | EXPORT_SYMBOL(proc_dointvec); |
e7d316a0 | 3487 | EXPORT_SYMBOL(proc_douintvec); |
1da177e4 LT |
3488 | EXPORT_SYMBOL(proc_dointvec_jiffies); |
3489 | EXPORT_SYMBOL(proc_dointvec_minmax); | |
61d9b56a | 3490 | EXPORT_SYMBOL_GPL(proc_douintvec_minmax); |
1da177e4 LT |
3491 | EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); |
3492 | EXPORT_SYMBOL(proc_dointvec_ms_jiffies); | |
3493 | EXPORT_SYMBOL(proc_dostring); | |
3494 | EXPORT_SYMBOL(proc_doulongvec_minmax); | |
3495 | EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); | |
0bc19985 | 3496 | EXPORT_SYMBOL(proc_do_large_bitmap); |