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