Linux 4.9.243
[linux/fpc-iii.git] / kernel / sysctl.c
blob513e6da318c47ba65cc0fd57e3e176e901cf970e
1 /*
2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/aio.h>
23 #include <linux/mm.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemcheck.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/kexec.h>
67 #include <linux/bpf.h>
68 #include <linux/mount.h>
70 #include <asm/uaccess.h>
71 #include <asm/processor.h>
73 #ifdef CONFIG_X86
74 #include <asm/nmi.h>
75 #include <asm/stacktrace.h>
76 #include <asm/io.h>
77 #endif
78 #ifdef CONFIG_SPARC
79 #include <asm/setup.h>
80 #endif
81 #ifdef CONFIG_BSD_PROCESS_ACCT
82 #include <linux/acct.h>
83 #endif
84 #ifdef CONFIG_RT_MUTEXES
85 #include <linux/rtmutex.h>
86 #endif
87 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
88 #include <linux/lockdep.h>
89 #endif
90 #ifdef CONFIG_CHR_DEV_SG
91 #include <scsi/sg.h>
92 #endif
94 #ifdef CONFIG_LOCKUP_DETECTOR
95 #include <linux/nmi.h>
96 #endif
98 #if defined(CONFIG_SYSCTL)
100 /* External variables not in a header file. */
101 extern int suid_dumpable;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid;
104 extern char core_pattern[];
105 extern unsigned int core_pipe_limit;
106 #endif
107 extern int pid_max;
108 extern int pid_max_min, pid_max_max;
109 extern int percpu_pagelist_fraction;
110 extern int latencytop_enabled;
111 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
112 #ifndef CONFIG_MMU
113 extern int sysctl_nr_trim_pages;
114 #endif
116 /* Constants used for minimum and maximum */
117 #ifdef CONFIG_LOCKUP_DETECTOR
118 static int sixty = 60;
119 #endif
121 static int __maybe_unused neg_one = -1;
123 static int zero;
124 static int __maybe_unused one = 1;
125 static int __maybe_unused two = 2;
126 static int __maybe_unused four = 4;
127 static unsigned long zero_ul;
128 static unsigned long one_ul = 1;
129 static unsigned long long_max = LONG_MAX;
130 static int one_hundred = 100;
131 static int one_thousand = 1000;
132 #ifdef CONFIG_PRINTK
133 static int ten_thousand = 10000;
134 #endif
135 #ifdef CONFIG_PERF_EVENTS
136 static int six_hundred_forty_kb = 640 * 1024;
137 #endif
139 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
140 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
142 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
143 static int maxolduid = 65535;
144 static int minolduid;
146 static int ngroups_max = NGROUPS_MAX;
147 static const int cap_last_cap = CAP_LAST_CAP;
149 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
150 #ifdef CONFIG_DETECT_HUNG_TASK
151 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
152 #endif
154 #ifdef CONFIG_INOTIFY_USER
155 #include <linux/inotify.h>
156 #endif
157 #ifdef CONFIG_SPARC
158 #endif
160 #ifdef __hppa__
161 extern int pwrsw_enabled;
162 #endif
164 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
165 extern int unaligned_enabled;
166 #endif
168 #ifdef CONFIG_IA64
169 extern int unaligned_dump_stack;
170 #endif
172 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
173 extern int no_unaligned_warning;
174 #endif
176 #ifdef CONFIG_PROC_SYSCTL
178 #define SYSCTL_WRITES_LEGACY -1
179 #define SYSCTL_WRITES_WARN 0
180 #define SYSCTL_WRITES_STRICT 1
182 static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
184 static int proc_do_cad_pid(struct ctl_table *table, int write,
185 void __user *buffer, size_t *lenp, loff_t *ppos);
186 static int proc_taint(struct ctl_table *table, int write,
187 void __user *buffer, size_t *lenp, loff_t *ppos);
188 #endif
190 #ifdef CONFIG_PRINTK
191 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
192 void __user *buffer, size_t *lenp, loff_t *ppos);
193 #endif
195 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
196 void __user *buffer, size_t *lenp, loff_t *ppos);
197 #ifdef CONFIG_COREDUMP
198 static int proc_dostring_coredump(struct ctl_table *table, int write,
199 void __user *buffer, size_t *lenp, loff_t *ppos);
200 #endif
202 #ifdef CONFIG_MAGIC_SYSRQ
203 /* Note: sysrq code uses it's own private copy */
204 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
206 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
207 void __user *buffer, size_t *lenp,
208 loff_t *ppos)
210 int error;
212 error = proc_dointvec(table, write, buffer, lenp, ppos);
213 if (error)
214 return error;
216 if (write)
217 sysrq_toggle_support(__sysrq_enabled);
219 return 0;
222 #endif
224 static struct ctl_table kern_table[];
225 static struct ctl_table vm_table[];
226 static struct ctl_table fs_table[];
227 static struct ctl_table debug_table[];
228 static struct ctl_table dev_table[];
229 extern struct ctl_table random_table[];
230 #ifdef CONFIG_EPOLL
231 extern struct ctl_table epoll_table[];
232 #endif
234 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
235 int sysctl_legacy_va_layout;
236 #endif
238 /* The default sysctl tables: */
240 static struct ctl_table sysctl_base_table[] = {
242 .procname = "kernel",
243 .mode = 0555,
244 .child = kern_table,
247 .procname = "vm",
248 .mode = 0555,
249 .child = vm_table,
252 .procname = "fs",
253 .mode = 0555,
254 .child = fs_table,
257 .procname = "debug",
258 .mode = 0555,
259 .child = debug_table,
262 .procname = "dev",
263 .mode = 0555,
264 .child = dev_table,
269 #ifdef CONFIG_SCHED_DEBUG
270 static int min_sched_granularity_ns = 100000; /* 100 usecs */
271 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
272 static int min_wakeup_granularity_ns; /* 0 usecs */
273 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
274 #ifdef CONFIG_SMP
275 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
276 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
277 #endif /* CONFIG_SMP */
278 #endif /* CONFIG_SCHED_DEBUG */
280 #ifdef CONFIG_COMPACTION
281 static int min_extfrag_threshold;
282 static int max_extfrag_threshold = 1000;
283 #endif
285 static struct ctl_table kern_table[] = {
287 .procname = "sched_child_runs_first",
288 .data = &sysctl_sched_child_runs_first,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
291 .proc_handler = proc_dointvec,
293 #ifdef CONFIG_SCHED_DEBUG
295 .procname = "sched_min_granularity_ns",
296 .data = &sysctl_sched_min_granularity,
297 .maxlen = sizeof(unsigned int),
298 .mode = 0644,
299 .proc_handler = sched_proc_update_handler,
300 .extra1 = &min_sched_granularity_ns,
301 .extra2 = &max_sched_granularity_ns,
304 .procname = "sched_latency_ns",
305 .data = &sysctl_sched_latency,
306 .maxlen = sizeof(unsigned int),
307 .mode = 0644,
308 .proc_handler = sched_proc_update_handler,
309 .extra1 = &min_sched_granularity_ns,
310 .extra2 = &max_sched_granularity_ns,
313 .procname = "sched_wakeup_granularity_ns",
314 .data = &sysctl_sched_wakeup_granularity,
315 .maxlen = sizeof(unsigned int),
316 .mode = 0644,
317 .proc_handler = sched_proc_update_handler,
318 .extra1 = &min_wakeup_granularity_ns,
319 .extra2 = &max_wakeup_granularity_ns,
321 #ifdef CONFIG_SMP
323 .procname = "sched_tunable_scaling",
324 .data = &sysctl_sched_tunable_scaling,
325 .maxlen = sizeof(enum sched_tunable_scaling),
326 .mode = 0644,
327 .proc_handler = sched_proc_update_handler,
328 .extra1 = &min_sched_tunable_scaling,
329 .extra2 = &max_sched_tunable_scaling,
332 .procname = "sched_migration_cost_ns",
333 .data = &sysctl_sched_migration_cost,
334 .maxlen = sizeof(unsigned int),
335 .mode = 0644,
336 .proc_handler = proc_dointvec,
339 .procname = "sched_nr_migrate",
340 .data = &sysctl_sched_nr_migrate,
341 .maxlen = sizeof(unsigned int),
342 .mode = 0644,
343 .proc_handler = proc_dointvec,
346 .procname = "sched_time_avg_ms",
347 .data = &sysctl_sched_time_avg,
348 .maxlen = sizeof(unsigned int),
349 .mode = 0644,
350 .proc_handler = proc_dointvec_minmax,
351 .extra1 = &one,
354 .procname = "sched_shares_window_ns",
355 .data = &sysctl_sched_shares_window,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
358 .proc_handler = proc_dointvec,
360 #ifdef CONFIG_SCHEDSTATS
362 .procname = "sched_schedstats",
363 .data = NULL,
364 .maxlen = sizeof(unsigned int),
365 .mode = 0644,
366 .proc_handler = sysctl_schedstats,
367 .extra1 = &zero,
368 .extra2 = &one,
370 #endif /* CONFIG_SCHEDSTATS */
371 #endif /* CONFIG_SMP */
372 #ifdef CONFIG_NUMA_BALANCING
374 .procname = "numa_balancing_scan_delay_ms",
375 .data = &sysctl_numa_balancing_scan_delay,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
378 .proc_handler = proc_dointvec,
381 .procname = "numa_balancing_scan_period_min_ms",
382 .data = &sysctl_numa_balancing_scan_period_min,
383 .maxlen = sizeof(unsigned int),
384 .mode = 0644,
385 .proc_handler = proc_dointvec,
388 .procname = "numa_balancing_scan_period_max_ms",
389 .data = &sysctl_numa_balancing_scan_period_max,
390 .maxlen = sizeof(unsigned int),
391 .mode = 0644,
392 .proc_handler = proc_dointvec,
395 .procname = "numa_balancing_scan_size_mb",
396 .data = &sysctl_numa_balancing_scan_size,
397 .maxlen = sizeof(unsigned int),
398 .mode = 0644,
399 .proc_handler = proc_dointvec_minmax,
400 .extra1 = &one,
403 .procname = "numa_balancing",
404 .data = NULL, /* filled in by handler */
405 .maxlen = sizeof(unsigned int),
406 .mode = 0644,
407 .proc_handler = sysctl_numa_balancing,
408 .extra1 = &zero,
409 .extra2 = &one,
411 #endif /* CONFIG_NUMA_BALANCING */
412 #endif /* CONFIG_SCHED_DEBUG */
414 .procname = "sched_rt_period_us",
415 .data = &sysctl_sched_rt_period,
416 .maxlen = sizeof(unsigned int),
417 .mode = 0644,
418 .proc_handler = sched_rt_handler,
421 .procname = "sched_rt_runtime_us",
422 .data = &sysctl_sched_rt_runtime,
423 .maxlen = sizeof(int),
424 .mode = 0644,
425 .proc_handler = sched_rt_handler,
428 .procname = "sched_rr_timeslice_ms",
429 .data = &sysctl_sched_rr_timeslice,
430 .maxlen = sizeof(int),
431 .mode = 0644,
432 .proc_handler = sched_rr_handler,
434 #ifdef CONFIG_SCHED_AUTOGROUP
436 .procname = "sched_autogroup_enabled",
437 .data = &sysctl_sched_autogroup_enabled,
438 .maxlen = sizeof(unsigned int),
439 .mode = 0644,
440 .proc_handler = proc_dointvec_minmax,
441 .extra1 = &zero,
442 .extra2 = &one,
444 #endif
445 #ifdef CONFIG_CFS_BANDWIDTH
447 .procname = "sched_cfs_bandwidth_slice_us",
448 .data = &sysctl_sched_cfs_bandwidth_slice,
449 .maxlen = sizeof(unsigned int),
450 .mode = 0644,
451 .proc_handler = proc_dointvec_minmax,
452 .extra1 = &one,
454 #endif
455 #ifdef CONFIG_PROVE_LOCKING
457 .procname = "prove_locking",
458 .data = &prove_locking,
459 .maxlen = sizeof(int),
460 .mode = 0644,
461 .proc_handler = proc_dointvec,
463 #endif
464 #ifdef CONFIG_LOCK_STAT
466 .procname = "lock_stat",
467 .data = &lock_stat,
468 .maxlen = sizeof(int),
469 .mode = 0644,
470 .proc_handler = proc_dointvec,
472 #endif
474 .procname = "panic",
475 .data = &panic_timeout,
476 .maxlen = sizeof(int),
477 .mode = 0644,
478 .proc_handler = proc_dointvec,
480 #ifdef CONFIG_COREDUMP
482 .procname = "core_uses_pid",
483 .data = &core_uses_pid,
484 .maxlen = sizeof(int),
485 .mode = 0644,
486 .proc_handler = proc_dointvec,
489 .procname = "core_pattern",
490 .data = core_pattern,
491 .maxlen = CORENAME_MAX_SIZE,
492 .mode = 0644,
493 .proc_handler = proc_dostring_coredump,
496 .procname = "core_pipe_limit",
497 .data = &core_pipe_limit,
498 .maxlen = sizeof(unsigned int),
499 .mode = 0644,
500 .proc_handler = proc_dointvec,
502 #endif
503 #ifdef CONFIG_PROC_SYSCTL
505 .procname = "tainted",
506 .maxlen = sizeof(long),
507 .mode = 0644,
508 .proc_handler = proc_taint,
511 .procname = "sysctl_writes_strict",
512 .data = &sysctl_writes_strict,
513 .maxlen = sizeof(int),
514 .mode = 0644,
515 .proc_handler = proc_dointvec_minmax,
516 .extra1 = &neg_one,
517 .extra2 = &one,
519 #endif
520 #ifdef CONFIG_LATENCYTOP
522 .procname = "latencytop",
523 .data = &latencytop_enabled,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = sysctl_latencytop,
528 #endif
529 #ifdef CONFIG_BLK_DEV_INITRD
531 .procname = "real-root-dev",
532 .data = &real_root_dev,
533 .maxlen = sizeof(int),
534 .mode = 0644,
535 .proc_handler = proc_dointvec,
537 #endif
539 .procname = "print-fatal-signals",
540 .data = &print_fatal_signals,
541 .maxlen = sizeof(int),
542 .mode = 0644,
543 .proc_handler = proc_dointvec,
545 #ifdef CONFIG_SPARC
547 .procname = "reboot-cmd",
548 .data = reboot_command,
549 .maxlen = 256,
550 .mode = 0644,
551 .proc_handler = proc_dostring,
554 .procname = "stop-a",
555 .data = &stop_a_enabled,
556 .maxlen = sizeof (int),
557 .mode = 0644,
558 .proc_handler = proc_dointvec,
561 .procname = "scons-poweroff",
562 .data = &scons_pwroff,
563 .maxlen = sizeof (int),
564 .mode = 0644,
565 .proc_handler = proc_dointvec,
567 #endif
568 #ifdef CONFIG_SPARC64
570 .procname = "tsb-ratio",
571 .data = &sysctl_tsb_ratio,
572 .maxlen = sizeof (int),
573 .mode = 0644,
574 .proc_handler = proc_dointvec,
576 #endif
577 #ifdef __hppa__
579 .procname = "soft-power",
580 .data = &pwrsw_enabled,
581 .maxlen = sizeof (int),
582 .mode = 0644,
583 .proc_handler = proc_dointvec,
585 #endif
586 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
588 .procname = "unaligned-trap",
589 .data = &unaligned_enabled,
590 .maxlen = sizeof (int),
591 .mode = 0644,
592 .proc_handler = proc_dointvec,
594 #endif
596 .procname = "ctrl-alt-del",
597 .data = &C_A_D,
598 .maxlen = sizeof(int),
599 .mode = 0644,
600 .proc_handler = proc_dointvec,
602 #ifdef CONFIG_FUNCTION_TRACER
604 .procname = "ftrace_enabled",
605 .data = &ftrace_enabled,
606 .maxlen = sizeof(int),
607 .mode = 0644,
608 .proc_handler = ftrace_enable_sysctl,
610 #endif
611 #ifdef CONFIG_STACK_TRACER
613 .procname = "stack_tracer_enabled",
614 .data = &stack_tracer_enabled,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = stack_trace_sysctl,
619 #endif
620 #ifdef CONFIG_TRACING
622 .procname = "ftrace_dump_on_oops",
623 .data = &ftrace_dump_on_oops,
624 .maxlen = sizeof(int),
625 .mode = 0644,
626 .proc_handler = proc_dointvec,
629 .procname = "traceoff_on_warning",
630 .data = &__disable_trace_on_warning,
631 .maxlen = sizeof(__disable_trace_on_warning),
632 .mode = 0644,
633 .proc_handler = proc_dointvec,
636 .procname = "tracepoint_printk",
637 .data = &tracepoint_printk,
638 .maxlen = sizeof(tracepoint_printk),
639 .mode = 0644,
640 .proc_handler = proc_dointvec,
642 #endif
643 #ifdef CONFIG_KEXEC_CORE
645 .procname = "kexec_load_disabled",
646 .data = &kexec_load_disabled,
647 .maxlen = sizeof(int),
648 .mode = 0644,
649 /* only handle a transition from default "0" to "1" */
650 .proc_handler = proc_dointvec_minmax,
651 .extra1 = &one,
652 .extra2 = &one,
654 #endif
655 #ifdef CONFIG_MODULES
657 .procname = "modprobe",
658 .data = &modprobe_path,
659 .maxlen = KMOD_PATH_LEN,
660 .mode = 0644,
661 .proc_handler = proc_dostring,
664 .procname = "modules_disabled",
665 .data = &modules_disabled,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 /* only handle a transition from default "0" to "1" */
669 .proc_handler = proc_dointvec_minmax,
670 .extra1 = &one,
671 .extra2 = &one,
673 #endif
674 #ifdef CONFIG_UEVENT_HELPER
676 .procname = "hotplug",
677 .data = &uevent_helper,
678 .maxlen = UEVENT_HELPER_PATH_LEN,
679 .mode = 0644,
680 .proc_handler = proc_dostring,
682 #endif
683 #ifdef CONFIG_CHR_DEV_SG
685 .procname = "sg-big-buff",
686 .data = &sg_big_buff,
687 .maxlen = sizeof (int),
688 .mode = 0444,
689 .proc_handler = proc_dointvec,
691 #endif
692 #ifdef CONFIG_BSD_PROCESS_ACCT
694 .procname = "acct",
695 .data = &acct_parm,
696 .maxlen = 3*sizeof(int),
697 .mode = 0644,
698 .proc_handler = proc_dointvec,
700 #endif
701 #ifdef CONFIG_MAGIC_SYSRQ
703 .procname = "sysrq",
704 .data = &__sysrq_enabled,
705 .maxlen = sizeof (int),
706 .mode = 0644,
707 .proc_handler = sysrq_sysctl_handler,
709 #endif
710 #ifdef CONFIG_PROC_SYSCTL
712 .procname = "cad_pid",
713 .data = NULL,
714 .maxlen = sizeof (int),
715 .mode = 0600,
716 .proc_handler = proc_do_cad_pid,
718 #endif
720 .procname = "threads-max",
721 .data = NULL,
722 .maxlen = sizeof(int),
723 .mode = 0644,
724 .proc_handler = sysctl_max_threads,
727 .procname = "random",
728 .mode = 0555,
729 .child = random_table,
732 .procname = "usermodehelper",
733 .mode = 0555,
734 .child = usermodehelper_table,
737 .procname = "overflowuid",
738 .data = &overflowuid,
739 .maxlen = sizeof(int),
740 .mode = 0644,
741 .proc_handler = proc_dointvec_minmax,
742 .extra1 = &minolduid,
743 .extra2 = &maxolduid,
746 .procname = "overflowgid",
747 .data = &overflowgid,
748 .maxlen = sizeof(int),
749 .mode = 0644,
750 .proc_handler = proc_dointvec_minmax,
751 .extra1 = &minolduid,
752 .extra2 = &maxolduid,
754 #ifdef CONFIG_S390
755 #ifdef CONFIG_MATHEMU
757 .procname = "ieee_emulation_warnings",
758 .data = &sysctl_ieee_emulation_warnings,
759 .maxlen = sizeof(int),
760 .mode = 0644,
761 .proc_handler = proc_dointvec,
763 #endif
765 .procname = "userprocess_debug",
766 .data = &show_unhandled_signals,
767 .maxlen = sizeof(int),
768 .mode = 0644,
769 .proc_handler = proc_dointvec,
771 #endif
773 .procname = "pid_max",
774 .data = &pid_max,
775 .maxlen = sizeof (int),
776 .mode = 0644,
777 .proc_handler = proc_dointvec_minmax,
778 .extra1 = &pid_max_min,
779 .extra2 = &pid_max_max,
782 .procname = "panic_on_oops",
783 .data = &panic_on_oops,
784 .maxlen = sizeof(int),
785 .mode = 0644,
786 .proc_handler = proc_dointvec,
788 #if defined CONFIG_PRINTK
790 .procname = "printk",
791 .data = &console_loglevel,
792 .maxlen = 4*sizeof(int),
793 .mode = 0644,
794 .proc_handler = proc_dointvec,
797 .procname = "printk_ratelimit",
798 .data = &printk_ratelimit_state.interval,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = proc_dointvec_jiffies,
804 .procname = "printk_ratelimit_burst",
805 .data = &printk_ratelimit_state.burst,
806 .maxlen = sizeof(int),
807 .mode = 0644,
808 .proc_handler = proc_dointvec,
811 .procname = "printk_delay",
812 .data = &printk_delay_msec,
813 .maxlen = sizeof(int),
814 .mode = 0644,
815 .proc_handler = proc_dointvec_minmax,
816 .extra1 = &zero,
817 .extra2 = &ten_thousand,
820 .procname = "printk_devkmsg",
821 .data = devkmsg_log_str,
822 .maxlen = DEVKMSG_STR_MAX_SIZE,
823 .mode = 0644,
824 .proc_handler = devkmsg_sysctl_set_loglvl,
827 .procname = "dmesg_restrict",
828 .data = &dmesg_restrict,
829 .maxlen = sizeof(int),
830 .mode = 0644,
831 .proc_handler = proc_dointvec_minmax_sysadmin,
832 .extra1 = &zero,
833 .extra2 = &one,
836 .procname = "kptr_restrict",
837 .data = &kptr_restrict,
838 .maxlen = sizeof(int),
839 .mode = 0644,
840 .proc_handler = proc_dointvec_minmax_sysadmin,
841 .extra1 = &zero,
842 .extra2 = &two,
844 #endif
846 .procname = "ngroups_max",
847 .data = &ngroups_max,
848 .maxlen = sizeof (int),
849 .mode = 0444,
850 .proc_handler = proc_dointvec,
853 .procname = "cap_last_cap",
854 .data = (void *)&cap_last_cap,
855 .maxlen = sizeof(int),
856 .mode = 0444,
857 .proc_handler = proc_dointvec,
859 #if defined(CONFIG_LOCKUP_DETECTOR)
861 .procname = "watchdog",
862 .data = &watchdog_user_enabled,
863 .maxlen = sizeof (int),
864 .mode = 0644,
865 .proc_handler = proc_watchdog,
866 .extra1 = &zero,
867 .extra2 = &one,
870 .procname = "watchdog_thresh",
871 .data = &watchdog_thresh,
872 .maxlen = sizeof(int),
873 .mode = 0644,
874 .proc_handler = proc_watchdog_thresh,
875 .extra1 = &zero,
876 .extra2 = &sixty,
879 .procname = "nmi_watchdog",
880 .data = &nmi_watchdog_enabled,
881 .maxlen = sizeof (int),
882 .mode = 0644,
883 .proc_handler = proc_nmi_watchdog,
884 .extra1 = &zero,
885 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
886 .extra2 = &one,
887 #else
888 .extra2 = &zero,
889 #endif
892 .procname = "soft_watchdog",
893 .data = &soft_watchdog_enabled,
894 .maxlen = sizeof (int),
895 .mode = 0644,
896 .proc_handler = proc_soft_watchdog,
897 .extra1 = &zero,
898 .extra2 = &one,
901 .procname = "watchdog_cpumask",
902 .data = &watchdog_cpumask_bits,
903 .maxlen = NR_CPUS,
904 .mode = 0644,
905 .proc_handler = proc_watchdog_cpumask,
908 .procname = "softlockup_panic",
909 .data = &softlockup_panic,
910 .maxlen = sizeof(int),
911 .mode = 0644,
912 .proc_handler = proc_dointvec_minmax,
913 .extra1 = &zero,
914 .extra2 = &one,
916 #ifdef CONFIG_HARDLOCKUP_DETECTOR
918 .procname = "hardlockup_panic",
919 .data = &hardlockup_panic,
920 .maxlen = sizeof(int),
921 .mode = 0644,
922 .proc_handler = proc_dointvec_minmax,
923 .extra1 = &zero,
924 .extra2 = &one,
926 #endif
927 #ifdef CONFIG_SMP
929 .procname = "softlockup_all_cpu_backtrace",
930 .data = &sysctl_softlockup_all_cpu_backtrace,
931 .maxlen = sizeof(int),
932 .mode = 0644,
933 .proc_handler = proc_dointvec_minmax,
934 .extra1 = &zero,
935 .extra2 = &one,
938 .procname = "hardlockup_all_cpu_backtrace",
939 .data = &sysctl_hardlockup_all_cpu_backtrace,
940 .maxlen = sizeof(int),
941 .mode = 0644,
942 .proc_handler = proc_dointvec_minmax,
943 .extra1 = &zero,
944 .extra2 = &one,
946 #endif /* CONFIG_SMP */
947 #endif
948 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
950 .procname = "unknown_nmi_panic",
951 .data = &unknown_nmi_panic,
952 .maxlen = sizeof (int),
953 .mode = 0644,
954 .proc_handler = proc_dointvec,
956 #endif
957 #if defined(CONFIG_X86)
959 .procname = "panic_on_unrecovered_nmi",
960 .data = &panic_on_unrecovered_nmi,
961 .maxlen = sizeof(int),
962 .mode = 0644,
963 .proc_handler = proc_dointvec,
966 .procname = "panic_on_io_nmi",
967 .data = &panic_on_io_nmi,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = proc_dointvec,
972 #ifdef CONFIG_DEBUG_STACKOVERFLOW
974 .procname = "panic_on_stackoverflow",
975 .data = &sysctl_panic_on_stackoverflow,
976 .maxlen = sizeof(int),
977 .mode = 0644,
978 .proc_handler = proc_dointvec,
980 #endif
982 .procname = "bootloader_type",
983 .data = &bootloader_type,
984 .maxlen = sizeof (int),
985 .mode = 0444,
986 .proc_handler = proc_dointvec,
989 .procname = "bootloader_version",
990 .data = &bootloader_version,
991 .maxlen = sizeof (int),
992 .mode = 0444,
993 .proc_handler = proc_dointvec,
996 .procname = "kstack_depth_to_print",
997 .data = &kstack_depth_to_print,
998 .maxlen = sizeof(int),
999 .mode = 0644,
1000 .proc_handler = proc_dointvec,
1003 .procname = "io_delay_type",
1004 .data = &io_delay_type,
1005 .maxlen = sizeof(int),
1006 .mode = 0644,
1007 .proc_handler = proc_dointvec,
1009 #endif
1010 #if defined(CONFIG_MMU)
1012 .procname = "randomize_va_space",
1013 .data = &randomize_va_space,
1014 .maxlen = sizeof(int),
1015 .mode = 0644,
1016 .proc_handler = proc_dointvec,
1018 #endif
1019 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1021 .procname = "spin_retry",
1022 .data = &spin_retry,
1023 .maxlen = sizeof (int),
1024 .mode = 0644,
1025 .proc_handler = proc_dointvec,
1027 #endif
1028 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1030 .procname = "acpi_video_flags",
1031 .data = &acpi_realmode_flags,
1032 .maxlen = sizeof (unsigned long),
1033 .mode = 0644,
1034 .proc_handler = proc_doulongvec_minmax,
1036 #endif
1037 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1039 .procname = "ignore-unaligned-usertrap",
1040 .data = &no_unaligned_warning,
1041 .maxlen = sizeof (int),
1042 .mode = 0644,
1043 .proc_handler = proc_dointvec,
1045 #endif
1046 #ifdef CONFIG_IA64
1048 .procname = "unaligned-dump-stack",
1049 .data = &unaligned_dump_stack,
1050 .maxlen = sizeof (int),
1051 .mode = 0644,
1052 .proc_handler = proc_dointvec,
1054 #endif
1055 #ifdef CONFIG_DETECT_HUNG_TASK
1057 .procname = "hung_task_panic",
1058 .data = &sysctl_hung_task_panic,
1059 .maxlen = sizeof(int),
1060 .mode = 0644,
1061 .proc_handler = proc_dointvec_minmax,
1062 .extra1 = &zero,
1063 .extra2 = &one,
1066 .procname = "hung_task_check_count",
1067 .data = &sysctl_hung_task_check_count,
1068 .maxlen = sizeof(int),
1069 .mode = 0644,
1070 .proc_handler = proc_dointvec_minmax,
1071 .extra1 = &zero,
1074 .procname = "hung_task_timeout_secs",
1075 .data = &sysctl_hung_task_timeout_secs,
1076 .maxlen = sizeof(unsigned long),
1077 .mode = 0644,
1078 .proc_handler = proc_dohung_task_timeout_secs,
1079 .extra2 = &hung_task_timeout_max,
1082 .procname = "hung_task_warnings",
1083 .data = &sysctl_hung_task_warnings,
1084 .maxlen = sizeof(int),
1085 .mode = 0644,
1086 .proc_handler = proc_dointvec_minmax,
1087 .extra1 = &neg_one,
1089 #endif
1090 #ifdef CONFIG_RT_MUTEXES
1092 .procname = "max_lock_depth",
1093 .data = &max_lock_depth,
1094 .maxlen = sizeof(int),
1095 .mode = 0644,
1096 .proc_handler = proc_dointvec,
1098 #endif
1100 .procname = "poweroff_cmd",
1101 .data = &poweroff_cmd,
1102 .maxlen = POWEROFF_CMD_PATH_LEN,
1103 .mode = 0644,
1104 .proc_handler = proc_dostring,
1106 #ifdef CONFIG_KEYS
1108 .procname = "keys",
1109 .mode = 0555,
1110 .child = key_sysctls,
1112 #endif
1113 #ifdef CONFIG_PERF_EVENTS
1115 * User-space scripts rely on the existence of this file
1116 * as a feature check for perf_events being enabled.
1118 * So it's an ABI, do not remove!
1121 .procname = "perf_event_paranoid",
1122 .data = &sysctl_perf_event_paranoid,
1123 .maxlen = sizeof(sysctl_perf_event_paranoid),
1124 .mode = 0644,
1125 .proc_handler = proc_dointvec,
1128 .procname = "perf_event_mlock_kb",
1129 .data = &sysctl_perf_event_mlock,
1130 .maxlen = sizeof(sysctl_perf_event_mlock),
1131 .mode = 0644,
1132 .proc_handler = proc_dointvec,
1135 .procname = "perf_event_max_sample_rate",
1136 .data = &sysctl_perf_event_sample_rate,
1137 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1138 .mode = 0644,
1139 .proc_handler = perf_proc_update_handler,
1140 .extra1 = &one,
1143 .procname = "perf_cpu_time_max_percent",
1144 .data = &sysctl_perf_cpu_time_max_percent,
1145 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1146 .mode = 0644,
1147 .proc_handler = perf_cpu_time_max_percent_handler,
1148 .extra1 = &zero,
1149 .extra2 = &one_hundred,
1152 .procname = "perf_event_max_stack",
1153 .data = &sysctl_perf_event_max_stack,
1154 .maxlen = sizeof(sysctl_perf_event_max_stack),
1155 .mode = 0644,
1156 .proc_handler = perf_event_max_stack_handler,
1157 .extra1 = &zero,
1158 .extra2 = &six_hundred_forty_kb,
1161 .procname = "perf_event_max_contexts_per_stack",
1162 .data = &sysctl_perf_event_max_contexts_per_stack,
1163 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1164 .mode = 0644,
1165 .proc_handler = perf_event_max_stack_handler,
1166 .extra1 = &zero,
1167 .extra2 = &one_thousand,
1169 #endif
1170 #ifdef CONFIG_KMEMCHECK
1172 .procname = "kmemcheck",
1173 .data = &kmemcheck_enabled,
1174 .maxlen = sizeof(int),
1175 .mode = 0644,
1176 .proc_handler = proc_dointvec,
1178 #endif
1180 .procname = "panic_on_warn",
1181 .data = &panic_on_warn,
1182 .maxlen = sizeof(int),
1183 .mode = 0644,
1184 .proc_handler = proc_dointvec_minmax,
1185 .extra1 = &zero,
1186 .extra2 = &one,
1188 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1190 .procname = "timer_migration",
1191 .data = &sysctl_timer_migration,
1192 .maxlen = sizeof(unsigned int),
1193 .mode = 0644,
1194 .proc_handler = timer_migration_handler,
1195 .extra1 = &zero,
1196 .extra2 = &one,
1198 #endif
1199 #ifdef CONFIG_BPF_SYSCALL
1201 .procname = "unprivileged_bpf_disabled",
1202 .data = &sysctl_unprivileged_bpf_disabled,
1203 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1204 .mode = 0644,
1205 /* only handle a transition from default "0" to "1" */
1206 .proc_handler = proc_dointvec_minmax,
1207 .extra1 = &one,
1208 .extra2 = &one,
1210 #endif
1211 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1213 .procname = "panic_on_rcu_stall",
1214 .data = &sysctl_panic_on_rcu_stall,
1215 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1216 .mode = 0644,
1217 .proc_handler = proc_dointvec_minmax,
1218 .extra1 = &zero,
1219 .extra2 = &one,
1221 #endif
1225 static struct ctl_table vm_table[] = {
1227 .procname = "overcommit_memory",
1228 .data = &sysctl_overcommit_memory,
1229 .maxlen = sizeof(sysctl_overcommit_memory),
1230 .mode = 0644,
1231 .proc_handler = proc_dointvec_minmax,
1232 .extra1 = &zero,
1233 .extra2 = &two,
1236 .procname = "panic_on_oom",
1237 .data = &sysctl_panic_on_oom,
1238 .maxlen = sizeof(sysctl_panic_on_oom),
1239 .mode = 0644,
1240 .proc_handler = proc_dointvec_minmax,
1241 .extra1 = &zero,
1242 .extra2 = &two,
1245 .procname = "oom_kill_allocating_task",
1246 .data = &sysctl_oom_kill_allocating_task,
1247 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1248 .mode = 0644,
1249 .proc_handler = proc_dointvec,
1252 .procname = "oom_dump_tasks",
1253 .data = &sysctl_oom_dump_tasks,
1254 .maxlen = sizeof(sysctl_oom_dump_tasks),
1255 .mode = 0644,
1256 .proc_handler = proc_dointvec,
1259 .procname = "overcommit_ratio",
1260 .data = &sysctl_overcommit_ratio,
1261 .maxlen = sizeof(sysctl_overcommit_ratio),
1262 .mode = 0644,
1263 .proc_handler = overcommit_ratio_handler,
1266 .procname = "overcommit_kbytes",
1267 .data = &sysctl_overcommit_kbytes,
1268 .maxlen = sizeof(sysctl_overcommit_kbytes),
1269 .mode = 0644,
1270 .proc_handler = overcommit_kbytes_handler,
1273 .procname = "page-cluster",
1274 .data = &page_cluster,
1275 .maxlen = sizeof(int),
1276 .mode = 0644,
1277 .proc_handler = proc_dointvec_minmax,
1278 .extra1 = &zero,
1281 .procname = "dirty_background_ratio",
1282 .data = &dirty_background_ratio,
1283 .maxlen = sizeof(dirty_background_ratio),
1284 .mode = 0644,
1285 .proc_handler = dirty_background_ratio_handler,
1286 .extra1 = &zero,
1287 .extra2 = &one_hundred,
1290 .procname = "dirty_background_bytes",
1291 .data = &dirty_background_bytes,
1292 .maxlen = sizeof(dirty_background_bytes),
1293 .mode = 0644,
1294 .proc_handler = dirty_background_bytes_handler,
1295 .extra1 = &one_ul,
1298 .procname = "dirty_ratio",
1299 .data = &vm_dirty_ratio,
1300 .maxlen = sizeof(vm_dirty_ratio),
1301 .mode = 0644,
1302 .proc_handler = dirty_ratio_handler,
1303 .extra1 = &zero,
1304 .extra2 = &one_hundred,
1307 .procname = "dirty_bytes",
1308 .data = &vm_dirty_bytes,
1309 .maxlen = sizeof(vm_dirty_bytes),
1310 .mode = 0644,
1311 .proc_handler = dirty_bytes_handler,
1312 .extra1 = &dirty_bytes_min,
1315 .procname = "dirty_writeback_centisecs",
1316 .data = &dirty_writeback_interval,
1317 .maxlen = sizeof(dirty_writeback_interval),
1318 .mode = 0644,
1319 .proc_handler = dirty_writeback_centisecs_handler,
1322 .procname = "dirty_expire_centisecs",
1323 .data = &dirty_expire_interval,
1324 .maxlen = sizeof(dirty_expire_interval),
1325 .mode = 0644,
1326 .proc_handler = proc_dointvec_minmax,
1327 .extra1 = &zero,
1330 .procname = "dirtytime_expire_seconds",
1331 .data = &dirtytime_expire_interval,
1332 .maxlen = sizeof(dirty_expire_interval),
1333 .mode = 0644,
1334 .proc_handler = dirtytime_interval_handler,
1335 .extra1 = &zero,
1338 .procname = "nr_pdflush_threads",
1339 .mode = 0444 /* read-only */,
1340 .proc_handler = pdflush_proc_obsolete,
1343 .procname = "swappiness",
1344 .data = &vm_swappiness,
1345 .maxlen = sizeof(vm_swappiness),
1346 .mode = 0644,
1347 .proc_handler = proc_dointvec_minmax,
1348 .extra1 = &zero,
1349 .extra2 = &one_hundred,
1351 #ifdef CONFIG_HUGETLB_PAGE
1353 .procname = "nr_hugepages",
1354 .data = NULL,
1355 .maxlen = sizeof(unsigned long),
1356 .mode = 0644,
1357 .proc_handler = hugetlb_sysctl_handler,
1359 #ifdef CONFIG_NUMA
1361 .procname = "nr_hugepages_mempolicy",
1362 .data = NULL,
1363 .maxlen = sizeof(unsigned long),
1364 .mode = 0644,
1365 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1367 #endif
1369 .procname = "hugetlb_shm_group",
1370 .data = &sysctl_hugetlb_shm_group,
1371 .maxlen = sizeof(gid_t),
1372 .mode = 0644,
1373 .proc_handler = proc_dointvec,
1376 .procname = "hugepages_treat_as_movable",
1377 .data = &hugepages_treat_as_movable,
1378 .maxlen = sizeof(int),
1379 .mode = 0644,
1380 .proc_handler = proc_dointvec,
1383 .procname = "nr_overcommit_hugepages",
1384 .data = NULL,
1385 .maxlen = sizeof(unsigned long),
1386 .mode = 0644,
1387 .proc_handler = hugetlb_overcommit_handler,
1389 #endif
1391 .procname = "lowmem_reserve_ratio",
1392 .data = &sysctl_lowmem_reserve_ratio,
1393 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1394 .mode = 0644,
1395 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1398 .procname = "drop_caches",
1399 .data = &sysctl_drop_caches,
1400 .maxlen = sizeof(int),
1401 .mode = 0200,
1402 .proc_handler = drop_caches_sysctl_handler,
1403 .extra1 = &one,
1404 .extra2 = &four,
1406 #ifdef CONFIG_COMPACTION
1408 .procname = "compact_memory",
1409 .data = &sysctl_compact_memory,
1410 .maxlen = sizeof(int),
1411 .mode = 0200,
1412 .proc_handler = sysctl_compaction_handler,
1415 .procname = "extfrag_threshold",
1416 .data = &sysctl_extfrag_threshold,
1417 .maxlen = sizeof(int),
1418 .mode = 0644,
1419 .proc_handler = sysctl_extfrag_handler,
1420 .extra1 = &min_extfrag_threshold,
1421 .extra2 = &max_extfrag_threshold,
1424 .procname = "compact_unevictable_allowed",
1425 .data = &sysctl_compact_unevictable_allowed,
1426 .maxlen = sizeof(int),
1427 .mode = 0644,
1428 .proc_handler = proc_dointvec,
1429 .extra1 = &zero,
1430 .extra2 = &one,
1433 #endif /* CONFIG_COMPACTION */
1435 .procname = "min_free_kbytes",
1436 .data = &min_free_kbytes,
1437 .maxlen = sizeof(min_free_kbytes),
1438 .mode = 0644,
1439 .proc_handler = min_free_kbytes_sysctl_handler,
1440 .extra1 = &zero,
1443 .procname = "watermark_scale_factor",
1444 .data = &watermark_scale_factor,
1445 .maxlen = sizeof(watermark_scale_factor),
1446 .mode = 0644,
1447 .proc_handler = watermark_scale_factor_sysctl_handler,
1448 .extra1 = &one,
1449 .extra2 = &one_thousand,
1452 .procname = "percpu_pagelist_fraction",
1453 .data = &percpu_pagelist_fraction,
1454 .maxlen = sizeof(percpu_pagelist_fraction),
1455 .mode = 0644,
1456 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1457 .extra1 = &zero,
1459 #ifdef CONFIG_MMU
1461 .procname = "max_map_count",
1462 .data = &sysctl_max_map_count,
1463 .maxlen = sizeof(sysctl_max_map_count),
1464 .mode = 0644,
1465 .proc_handler = proc_dointvec_minmax,
1466 .extra1 = &zero,
1468 #else
1470 .procname = "nr_trim_pages",
1471 .data = &sysctl_nr_trim_pages,
1472 .maxlen = sizeof(sysctl_nr_trim_pages),
1473 .mode = 0644,
1474 .proc_handler = proc_dointvec_minmax,
1475 .extra1 = &zero,
1477 #endif
1479 .procname = "laptop_mode",
1480 .data = &laptop_mode,
1481 .maxlen = sizeof(laptop_mode),
1482 .mode = 0644,
1483 .proc_handler = proc_dointvec_jiffies,
1486 .procname = "block_dump",
1487 .data = &block_dump,
1488 .maxlen = sizeof(block_dump),
1489 .mode = 0644,
1490 .proc_handler = proc_dointvec,
1491 .extra1 = &zero,
1494 .procname = "vfs_cache_pressure",
1495 .data = &sysctl_vfs_cache_pressure,
1496 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1497 .mode = 0644,
1498 .proc_handler = proc_dointvec,
1499 .extra1 = &zero,
1501 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1503 .procname = "legacy_va_layout",
1504 .data = &sysctl_legacy_va_layout,
1505 .maxlen = sizeof(sysctl_legacy_va_layout),
1506 .mode = 0644,
1507 .proc_handler = proc_dointvec,
1508 .extra1 = &zero,
1510 #endif
1511 #ifdef CONFIG_NUMA
1513 .procname = "zone_reclaim_mode",
1514 .data = &node_reclaim_mode,
1515 .maxlen = sizeof(node_reclaim_mode),
1516 .mode = 0644,
1517 .proc_handler = proc_dointvec,
1518 .extra1 = &zero,
1521 .procname = "min_unmapped_ratio",
1522 .data = &sysctl_min_unmapped_ratio,
1523 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1524 .mode = 0644,
1525 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1526 .extra1 = &zero,
1527 .extra2 = &one_hundred,
1530 .procname = "min_slab_ratio",
1531 .data = &sysctl_min_slab_ratio,
1532 .maxlen = sizeof(sysctl_min_slab_ratio),
1533 .mode = 0644,
1534 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1535 .extra1 = &zero,
1536 .extra2 = &one_hundred,
1538 #endif
1539 #ifdef CONFIG_SMP
1541 .procname = "stat_interval",
1542 .data = &sysctl_stat_interval,
1543 .maxlen = sizeof(sysctl_stat_interval),
1544 .mode = 0644,
1545 .proc_handler = proc_dointvec_jiffies,
1548 .procname = "stat_refresh",
1549 .data = NULL,
1550 .maxlen = 0,
1551 .mode = 0600,
1552 .proc_handler = vmstat_refresh,
1554 #endif
1555 #ifdef CONFIG_MMU
1557 .procname = "mmap_min_addr",
1558 .data = &dac_mmap_min_addr,
1559 .maxlen = sizeof(unsigned long),
1560 .mode = 0644,
1561 .proc_handler = mmap_min_addr_handler,
1563 #endif
1564 #ifdef CONFIG_NUMA
1566 .procname = "numa_zonelist_order",
1567 .data = &numa_zonelist_order,
1568 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1569 .mode = 0644,
1570 .proc_handler = numa_zonelist_order_handler,
1572 #endif
1573 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1574 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1576 .procname = "vdso_enabled",
1577 #ifdef CONFIG_X86_32
1578 .data = &vdso32_enabled,
1579 .maxlen = sizeof(vdso32_enabled),
1580 #else
1581 .data = &vdso_enabled,
1582 .maxlen = sizeof(vdso_enabled),
1583 #endif
1584 .mode = 0644,
1585 .proc_handler = proc_dointvec,
1586 .extra1 = &zero,
1588 #endif
1589 #ifdef CONFIG_HIGHMEM
1591 .procname = "highmem_is_dirtyable",
1592 .data = &vm_highmem_is_dirtyable,
1593 .maxlen = sizeof(vm_highmem_is_dirtyable),
1594 .mode = 0644,
1595 .proc_handler = proc_dointvec_minmax,
1596 .extra1 = &zero,
1597 .extra2 = &one,
1599 #endif
1600 #ifdef CONFIG_MEMORY_FAILURE
1602 .procname = "memory_failure_early_kill",
1603 .data = &sysctl_memory_failure_early_kill,
1604 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1605 .mode = 0644,
1606 .proc_handler = proc_dointvec_minmax,
1607 .extra1 = &zero,
1608 .extra2 = &one,
1611 .procname = "memory_failure_recovery",
1612 .data = &sysctl_memory_failure_recovery,
1613 .maxlen = sizeof(sysctl_memory_failure_recovery),
1614 .mode = 0644,
1615 .proc_handler = proc_dointvec_minmax,
1616 .extra1 = &zero,
1617 .extra2 = &one,
1619 #endif
1621 .procname = "user_reserve_kbytes",
1622 .data = &sysctl_user_reserve_kbytes,
1623 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1624 .mode = 0644,
1625 .proc_handler = proc_doulongvec_minmax,
1628 .procname = "admin_reserve_kbytes",
1629 .data = &sysctl_admin_reserve_kbytes,
1630 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1631 .mode = 0644,
1632 .proc_handler = proc_doulongvec_minmax,
1634 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1636 .procname = "mmap_rnd_bits",
1637 .data = &mmap_rnd_bits,
1638 .maxlen = sizeof(mmap_rnd_bits),
1639 .mode = 0600,
1640 .proc_handler = proc_dointvec_minmax,
1641 .extra1 = (void *)&mmap_rnd_bits_min,
1642 .extra2 = (void *)&mmap_rnd_bits_max,
1644 #endif
1645 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1647 .procname = "mmap_rnd_compat_bits",
1648 .data = &mmap_rnd_compat_bits,
1649 .maxlen = sizeof(mmap_rnd_compat_bits),
1650 .mode = 0600,
1651 .proc_handler = proc_dointvec_minmax,
1652 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1653 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1655 #endif
1659 static struct ctl_table fs_table[] = {
1661 .procname = "inode-nr",
1662 .data = &inodes_stat,
1663 .maxlen = 2*sizeof(long),
1664 .mode = 0444,
1665 .proc_handler = proc_nr_inodes,
1668 .procname = "inode-state",
1669 .data = &inodes_stat,
1670 .maxlen = 7*sizeof(long),
1671 .mode = 0444,
1672 .proc_handler = proc_nr_inodes,
1675 .procname = "file-nr",
1676 .data = &files_stat,
1677 .maxlen = sizeof(files_stat),
1678 .mode = 0444,
1679 .proc_handler = proc_nr_files,
1682 .procname = "file-max",
1683 .data = &files_stat.max_files,
1684 .maxlen = sizeof(files_stat.max_files),
1685 .mode = 0644,
1686 .proc_handler = proc_doulongvec_minmax,
1687 .extra1 = &zero_ul,
1688 .extra2 = &long_max,
1691 .procname = "nr_open",
1692 .data = &sysctl_nr_open,
1693 .maxlen = sizeof(unsigned int),
1694 .mode = 0644,
1695 .proc_handler = proc_dointvec_minmax,
1696 .extra1 = &sysctl_nr_open_min,
1697 .extra2 = &sysctl_nr_open_max,
1700 .procname = "dentry-state",
1701 .data = &dentry_stat,
1702 .maxlen = 6*sizeof(long),
1703 .mode = 0444,
1704 .proc_handler = proc_nr_dentry,
1707 .procname = "overflowuid",
1708 .data = &fs_overflowuid,
1709 .maxlen = sizeof(int),
1710 .mode = 0644,
1711 .proc_handler = proc_dointvec_minmax,
1712 .extra1 = &minolduid,
1713 .extra2 = &maxolduid,
1716 .procname = "overflowgid",
1717 .data = &fs_overflowgid,
1718 .maxlen = sizeof(int),
1719 .mode = 0644,
1720 .proc_handler = proc_dointvec_minmax,
1721 .extra1 = &minolduid,
1722 .extra2 = &maxolduid,
1724 #ifdef CONFIG_FILE_LOCKING
1726 .procname = "leases-enable",
1727 .data = &leases_enable,
1728 .maxlen = sizeof(int),
1729 .mode = 0644,
1730 .proc_handler = proc_dointvec,
1732 #endif
1733 #ifdef CONFIG_DNOTIFY
1735 .procname = "dir-notify-enable",
1736 .data = &dir_notify_enable,
1737 .maxlen = sizeof(int),
1738 .mode = 0644,
1739 .proc_handler = proc_dointvec,
1741 #endif
1742 #ifdef CONFIG_MMU
1743 #ifdef CONFIG_FILE_LOCKING
1745 .procname = "lease-break-time",
1746 .data = &lease_break_time,
1747 .maxlen = sizeof(int),
1748 .mode = 0644,
1749 .proc_handler = proc_dointvec,
1751 #endif
1752 #ifdef CONFIG_AIO
1754 .procname = "aio-nr",
1755 .data = &aio_nr,
1756 .maxlen = sizeof(aio_nr),
1757 .mode = 0444,
1758 .proc_handler = proc_doulongvec_minmax,
1761 .procname = "aio-max-nr",
1762 .data = &aio_max_nr,
1763 .maxlen = sizeof(aio_max_nr),
1764 .mode = 0644,
1765 .proc_handler = proc_doulongvec_minmax,
1767 #endif /* CONFIG_AIO */
1768 #ifdef CONFIG_INOTIFY_USER
1770 .procname = "inotify",
1771 .mode = 0555,
1772 .child = inotify_table,
1774 #endif
1775 #ifdef CONFIG_EPOLL
1777 .procname = "epoll",
1778 .mode = 0555,
1779 .child = epoll_table,
1781 #endif
1782 #endif
1784 .procname = "protected_symlinks",
1785 .data = &sysctl_protected_symlinks,
1786 .maxlen = sizeof(int),
1787 .mode = 0600,
1788 .proc_handler = proc_dointvec_minmax,
1789 .extra1 = &zero,
1790 .extra2 = &one,
1793 .procname = "protected_hardlinks",
1794 .data = &sysctl_protected_hardlinks,
1795 .maxlen = sizeof(int),
1796 .mode = 0600,
1797 .proc_handler = proc_dointvec_minmax,
1798 .extra1 = &zero,
1799 .extra2 = &one,
1802 .procname = "protected_fifos",
1803 .data = &sysctl_protected_fifos,
1804 .maxlen = sizeof(int),
1805 .mode = 0600,
1806 .proc_handler = proc_dointvec_minmax,
1807 .extra1 = &zero,
1808 .extra2 = &two,
1811 .procname = "protected_regular",
1812 .data = &sysctl_protected_regular,
1813 .maxlen = sizeof(int),
1814 .mode = 0600,
1815 .proc_handler = proc_dointvec_minmax,
1816 .extra1 = &zero,
1817 .extra2 = &two,
1820 .procname = "suid_dumpable",
1821 .data = &suid_dumpable,
1822 .maxlen = sizeof(int),
1823 .mode = 0644,
1824 .proc_handler = proc_dointvec_minmax_coredump,
1825 .extra1 = &zero,
1826 .extra2 = &two,
1828 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1830 .procname = "binfmt_misc",
1831 .mode = 0555,
1832 .child = sysctl_mount_point,
1834 #endif
1836 .procname = "pipe-max-size",
1837 .data = &pipe_max_size,
1838 .maxlen = sizeof(int),
1839 .mode = 0644,
1840 .proc_handler = &pipe_proc_fn,
1841 .extra1 = &pipe_min_size,
1844 .procname = "pipe-user-pages-hard",
1845 .data = &pipe_user_pages_hard,
1846 .maxlen = sizeof(pipe_user_pages_hard),
1847 .mode = 0644,
1848 .proc_handler = proc_doulongvec_minmax,
1851 .procname = "pipe-user-pages-soft",
1852 .data = &pipe_user_pages_soft,
1853 .maxlen = sizeof(pipe_user_pages_soft),
1854 .mode = 0644,
1855 .proc_handler = proc_doulongvec_minmax,
1858 .procname = "mount-max",
1859 .data = &sysctl_mount_max,
1860 .maxlen = sizeof(unsigned int),
1861 .mode = 0644,
1862 .proc_handler = proc_dointvec_minmax,
1863 .extra1 = &one,
1868 static struct ctl_table debug_table[] = {
1869 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1871 .procname = "exception-trace",
1872 .data = &show_unhandled_signals,
1873 .maxlen = sizeof(int),
1874 .mode = 0644,
1875 .proc_handler = proc_dointvec
1877 #endif
1878 #if defined(CONFIG_OPTPROBES)
1880 .procname = "kprobes-optimization",
1881 .data = &sysctl_kprobes_optimization,
1882 .maxlen = sizeof(int),
1883 .mode = 0644,
1884 .proc_handler = proc_kprobes_optimization_handler,
1885 .extra1 = &zero,
1886 .extra2 = &one,
1888 #endif
1892 static struct ctl_table dev_table[] = {
1896 int __init sysctl_init(void)
1898 struct ctl_table_header *hdr;
1900 hdr = register_sysctl_table(sysctl_base_table);
1901 kmemleak_not_leak(hdr);
1902 return 0;
1905 #endif /* CONFIG_SYSCTL */
1908 * /proc/sys support
1911 #ifdef CONFIG_PROC_SYSCTL
1913 static int _proc_do_string(char *data, int maxlen, int write,
1914 char __user *buffer,
1915 size_t *lenp, loff_t *ppos)
1917 size_t len;
1918 char __user *p;
1919 char c;
1921 if (!data || !maxlen || !*lenp) {
1922 *lenp = 0;
1923 return 0;
1926 if (write) {
1927 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1928 /* Only continue writes not past the end of buffer. */
1929 len = strlen(data);
1930 if (len > maxlen - 1)
1931 len = maxlen - 1;
1933 if (*ppos > len)
1934 return 0;
1935 len = *ppos;
1936 } else {
1937 /* Start writing from beginning of buffer. */
1938 len = 0;
1941 *ppos += *lenp;
1942 p = buffer;
1943 while ((p - buffer) < *lenp && len < maxlen - 1) {
1944 if (get_user(c, p++))
1945 return -EFAULT;
1946 if (c == 0 || c == '\n')
1947 break;
1948 data[len++] = c;
1950 data[len] = 0;
1951 } else {
1952 len = strlen(data);
1953 if (len > maxlen)
1954 len = maxlen;
1956 if (*ppos > len) {
1957 *lenp = 0;
1958 return 0;
1961 data += *ppos;
1962 len -= *ppos;
1964 if (len > *lenp)
1965 len = *lenp;
1966 if (len)
1967 if (copy_to_user(buffer, data, len))
1968 return -EFAULT;
1969 if (len < *lenp) {
1970 if (put_user('\n', buffer + len))
1971 return -EFAULT;
1972 len++;
1974 *lenp = len;
1975 *ppos += len;
1977 return 0;
1980 static void warn_sysctl_write(struct ctl_table *table)
1982 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1983 "This will not be supported in the future. To silence this\n"
1984 "warning, set kernel.sysctl_writes_strict = -1\n",
1985 current->comm, table->procname);
1989 * proc_dostring - read a string sysctl
1990 * @table: the sysctl table
1991 * @write: %TRUE if this is a write to the sysctl file
1992 * @buffer: the user buffer
1993 * @lenp: the size of the user buffer
1994 * @ppos: file position
1996 * Reads/writes a string from/to the user buffer. If the kernel
1997 * buffer provided is not large enough to hold the string, the
1998 * string is truncated. The copied string is %NULL-terminated.
1999 * If the string is being read by the user process, it is copied
2000 * and a newline '\n' is added. It is truncated if the buffer is
2001 * not large enough.
2003 * Returns 0 on success.
2005 int proc_dostring(struct ctl_table *table, int write,
2006 void __user *buffer, size_t *lenp, loff_t *ppos)
2008 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
2009 warn_sysctl_write(table);
2011 return _proc_do_string((char *)(table->data), table->maxlen, write,
2012 (char __user *)buffer, lenp, ppos);
2015 static size_t proc_skip_spaces(char **buf)
2017 size_t ret;
2018 char *tmp = skip_spaces(*buf);
2019 ret = tmp - *buf;
2020 *buf = tmp;
2021 return ret;
2024 static void proc_skip_char(char **buf, size_t *size, const char v)
2026 while (*size) {
2027 if (**buf != v)
2028 break;
2029 (*size)--;
2030 (*buf)++;
2034 #define TMPBUFLEN 22
2036 * proc_get_long - reads an ASCII formatted integer from a user buffer
2038 * @buf: a kernel buffer
2039 * @size: size of the kernel buffer
2040 * @val: this is where the number will be stored
2041 * @neg: set to %TRUE if number is negative
2042 * @perm_tr: a vector which contains the allowed trailers
2043 * @perm_tr_len: size of the perm_tr vector
2044 * @tr: pointer to store the trailer character
2046 * In case of success %0 is returned and @buf and @size are updated with
2047 * the amount of bytes read. If @tr is non-NULL and a trailing
2048 * character exists (size is non-zero after returning from this
2049 * function), @tr is updated with the trailing character.
2051 static int proc_get_long(char **buf, size_t *size,
2052 unsigned long *val, bool *neg,
2053 const char *perm_tr, unsigned perm_tr_len, char *tr)
2055 int len;
2056 char *p, tmp[TMPBUFLEN];
2058 if (!*size)
2059 return -EINVAL;
2061 len = *size;
2062 if (len > TMPBUFLEN - 1)
2063 len = TMPBUFLEN - 1;
2065 memcpy(tmp, *buf, len);
2067 tmp[len] = 0;
2068 p = tmp;
2069 if (*p == '-' && *size > 1) {
2070 *neg = true;
2071 p++;
2072 } else
2073 *neg = false;
2074 if (!isdigit(*p))
2075 return -EINVAL;
2077 *val = simple_strtoul(p, &p, 0);
2079 len = p - tmp;
2081 /* We don't know if the next char is whitespace thus we may accept
2082 * invalid integers (e.g. 1234...a) or two integers instead of one
2083 * (e.g. 123...1). So lets not allow such large numbers. */
2084 if (len == TMPBUFLEN - 1)
2085 return -EINVAL;
2087 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2088 return -EINVAL;
2090 if (tr && (len < *size))
2091 *tr = *p;
2093 *buf += len;
2094 *size -= len;
2096 return 0;
2100 * proc_put_long - converts an integer to a decimal ASCII formatted string
2102 * @buf: the user buffer
2103 * @size: the size of the user buffer
2104 * @val: the integer to be converted
2105 * @neg: sign of the number, %TRUE for negative
2107 * In case of success %0 is returned and @buf and @size are updated with
2108 * the amount of bytes written.
2110 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2111 bool neg)
2113 int len;
2114 char tmp[TMPBUFLEN], *p = tmp;
2116 sprintf(p, "%s%lu", neg ? "-" : "", val);
2117 len = strlen(tmp);
2118 if (len > *size)
2119 len = *size;
2120 if (copy_to_user(*buf, tmp, len))
2121 return -EFAULT;
2122 *size -= len;
2123 *buf += len;
2124 return 0;
2126 #undef TMPBUFLEN
2128 static int proc_put_char(void __user **buf, size_t *size, char c)
2130 if (*size) {
2131 char __user **buffer = (char __user **)buf;
2132 if (put_user(c, *buffer))
2133 return -EFAULT;
2134 (*size)--, (*buffer)++;
2135 *buf = *buffer;
2137 return 0;
2140 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2141 int *valp,
2142 int write, void *data)
2144 if (write) {
2145 if (*negp) {
2146 if (*lvalp > (unsigned long) INT_MAX + 1)
2147 return -EINVAL;
2148 *valp = -*lvalp;
2149 } else {
2150 if (*lvalp > (unsigned long) INT_MAX)
2151 return -EINVAL;
2152 *valp = *lvalp;
2154 } else {
2155 int val = *valp;
2156 if (val < 0) {
2157 *negp = true;
2158 *lvalp = -(unsigned long)val;
2159 } else {
2160 *negp = false;
2161 *lvalp = (unsigned long)val;
2164 return 0;
2167 static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2168 int *valp,
2169 int write, void *data)
2171 if (write) {
2172 if (*negp)
2173 return -EINVAL;
2174 if (*lvalp > UINT_MAX)
2175 return -EINVAL;
2176 *valp = *lvalp;
2177 } else {
2178 unsigned int val = *valp;
2179 *negp = false;
2180 *lvalp = (unsigned long)val;
2182 return 0;
2185 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2187 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2188 int write, void __user *buffer,
2189 size_t *lenp, loff_t *ppos,
2190 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2191 int write, void *data),
2192 void *data)
2194 int *i, vleft, first = 1, err = 0;
2195 size_t left;
2196 char *kbuf = NULL, *p;
2198 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2199 *lenp = 0;
2200 return 0;
2203 i = (int *) tbl_data;
2204 vleft = table->maxlen / sizeof(*i);
2205 left = *lenp;
2207 if (!conv)
2208 conv = do_proc_dointvec_conv;
2210 if (write) {
2211 if (*ppos) {
2212 switch (sysctl_writes_strict) {
2213 case SYSCTL_WRITES_STRICT:
2214 goto out;
2215 case SYSCTL_WRITES_WARN:
2216 warn_sysctl_write(table);
2217 break;
2218 default:
2219 break;
2223 if (left > PAGE_SIZE - 1)
2224 left = PAGE_SIZE - 1;
2225 p = kbuf = memdup_user_nul(buffer, left);
2226 if (IS_ERR(kbuf))
2227 return PTR_ERR(kbuf);
2230 for (; left && vleft--; i++, first=0) {
2231 unsigned long lval;
2232 bool neg;
2234 if (write) {
2235 left -= proc_skip_spaces(&p);
2237 if (!left)
2238 break;
2239 err = proc_get_long(&p, &left, &lval, &neg,
2240 proc_wspace_sep,
2241 sizeof(proc_wspace_sep), NULL);
2242 if (err)
2243 break;
2244 if (conv(&neg, &lval, i, 1, data)) {
2245 err = -EINVAL;
2246 break;
2248 } else {
2249 if (conv(&neg, &lval, i, 0, data)) {
2250 err = -EINVAL;
2251 break;
2253 if (!first)
2254 err = proc_put_char(&buffer, &left, '\t');
2255 if (err)
2256 break;
2257 err = proc_put_long(&buffer, &left, lval, neg);
2258 if (err)
2259 break;
2263 if (!write && !first && left && !err)
2264 err = proc_put_char(&buffer, &left, '\n');
2265 if (write && !err && left)
2266 left -= proc_skip_spaces(&p);
2267 if (write) {
2268 kfree(kbuf);
2269 if (first)
2270 return err ? : -EINVAL;
2272 *lenp -= left;
2273 out:
2274 *ppos += *lenp;
2275 return err;
2278 static int do_proc_dointvec(struct ctl_table *table, int write,
2279 void __user *buffer, size_t *lenp, loff_t *ppos,
2280 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2281 int write, void *data),
2282 void *data)
2284 return __do_proc_dointvec(table->data, table, write,
2285 buffer, lenp, ppos, conv, data);
2289 * proc_dointvec - read a vector of integers
2290 * @table: the sysctl table
2291 * @write: %TRUE if this is a write to the sysctl file
2292 * @buffer: the user buffer
2293 * @lenp: the size of the user buffer
2294 * @ppos: file position
2296 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2297 * values from/to the user buffer, treated as an ASCII string.
2299 * Returns 0 on success.
2301 int proc_dointvec(struct ctl_table *table, int write,
2302 void __user *buffer, size_t *lenp, loff_t *ppos)
2304 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2308 * proc_douintvec - read a vector of unsigned integers
2309 * @table: the sysctl table
2310 * @write: %TRUE if this is a write to the sysctl file
2311 * @buffer: the user buffer
2312 * @lenp: the size of the user buffer
2313 * @ppos: file position
2315 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2316 * values from/to the user buffer, treated as an ASCII string.
2318 * Returns 0 on success.
2320 int proc_douintvec(struct ctl_table *table, int write,
2321 void __user *buffer, size_t *lenp, loff_t *ppos)
2323 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2324 do_proc_douintvec_conv, NULL);
2328 * Taint values can only be increased
2329 * This means we can safely use a temporary.
2331 static int proc_taint(struct ctl_table *table, int write,
2332 void __user *buffer, size_t *lenp, loff_t *ppos)
2334 struct ctl_table t;
2335 unsigned long tmptaint = get_taint();
2336 int err;
2338 if (write && !capable(CAP_SYS_ADMIN))
2339 return -EPERM;
2341 t = *table;
2342 t.data = &tmptaint;
2343 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2344 if (err < 0)
2345 return err;
2347 if (write) {
2349 * Poor man's atomic or. Not worth adding a primitive
2350 * to everyone's atomic.h for this
2352 int i;
2353 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2354 if ((tmptaint >> i) & 1)
2355 add_taint(i, LOCKDEP_STILL_OK);
2359 return err;
2362 #ifdef CONFIG_PRINTK
2363 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2364 void __user *buffer, size_t *lenp, loff_t *ppos)
2366 if (write && !capable(CAP_SYS_ADMIN))
2367 return -EPERM;
2369 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2371 #endif
2373 struct do_proc_dointvec_minmax_conv_param {
2374 int *min;
2375 int *max;
2378 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2379 int *valp,
2380 int write, void *data)
2382 struct do_proc_dointvec_minmax_conv_param *param = data;
2383 if (write) {
2384 int val;
2385 if (*negp) {
2386 if (*lvalp > (unsigned long) INT_MAX + 1)
2387 return -EINVAL;
2388 val = -*lvalp;
2389 } else {
2390 if (*lvalp > (unsigned long) INT_MAX)
2391 return -EINVAL;
2392 val = *lvalp;
2394 if ((param->min && *param->min > val) ||
2395 (param->max && *param->max < val))
2396 return -EINVAL;
2397 *valp = val;
2398 } else {
2399 int val = *valp;
2400 if (val < 0) {
2401 *negp = true;
2402 *lvalp = -(unsigned long)val;
2403 } else {
2404 *negp = false;
2405 *lvalp = (unsigned long)val;
2408 return 0;
2412 * proc_dointvec_minmax - read a vector of integers with min/max values
2413 * @table: the sysctl table
2414 * @write: %TRUE if this is a write to the sysctl file
2415 * @buffer: the user buffer
2416 * @lenp: the size of the user buffer
2417 * @ppos: file position
2419 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2420 * values from/to the user buffer, treated as an ASCII string.
2422 * This routine will ensure the values are within the range specified by
2423 * table->extra1 (min) and table->extra2 (max).
2425 * Returns 0 on success.
2427 int proc_dointvec_minmax(struct ctl_table *table, int write,
2428 void __user *buffer, size_t *lenp, loff_t *ppos)
2430 struct do_proc_dointvec_minmax_conv_param param = {
2431 .min = (int *) table->extra1,
2432 .max = (int *) table->extra2,
2434 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2435 do_proc_dointvec_minmax_conv, &param);
2438 static void validate_coredump_safety(void)
2440 #ifdef CONFIG_COREDUMP
2441 if (suid_dumpable == SUID_DUMP_ROOT &&
2442 core_pattern[0] != '/' && core_pattern[0] != '|') {
2443 printk(KERN_WARNING "Unsafe core_pattern used with "\
2444 "suid_dumpable=2. Pipe handler or fully qualified "\
2445 "core dump path required.\n");
2447 #endif
2450 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2451 void __user *buffer, size_t *lenp, loff_t *ppos)
2453 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2454 if (!error)
2455 validate_coredump_safety();
2456 return error;
2459 #ifdef CONFIG_COREDUMP
2460 static int proc_dostring_coredump(struct ctl_table *table, int write,
2461 void __user *buffer, size_t *lenp, loff_t *ppos)
2463 int error = proc_dostring(table, write, buffer, lenp, ppos);
2464 if (!error)
2465 validate_coredump_safety();
2466 return error;
2468 #endif
2470 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2471 void __user *buffer,
2472 size_t *lenp, loff_t *ppos,
2473 unsigned long convmul,
2474 unsigned long convdiv)
2476 unsigned long *i, *min, *max;
2477 int vleft, first = 1, err = 0;
2478 size_t left;
2479 char *kbuf = NULL, *p;
2481 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2482 *lenp = 0;
2483 return 0;
2486 i = (unsigned long *) data;
2487 min = (unsigned long *) table->extra1;
2488 max = (unsigned long *) table->extra2;
2489 vleft = table->maxlen / sizeof(unsigned long);
2490 left = *lenp;
2492 if (write) {
2493 if (*ppos) {
2494 switch (sysctl_writes_strict) {
2495 case SYSCTL_WRITES_STRICT:
2496 goto out;
2497 case SYSCTL_WRITES_WARN:
2498 warn_sysctl_write(table);
2499 break;
2500 default:
2501 break;
2505 if (left > PAGE_SIZE - 1)
2506 left = PAGE_SIZE - 1;
2507 p = kbuf = memdup_user_nul(buffer, left);
2508 if (IS_ERR(kbuf))
2509 return PTR_ERR(kbuf);
2512 for (; left && vleft--; i++, first = 0) {
2513 unsigned long val;
2515 if (write) {
2516 bool neg;
2518 left -= proc_skip_spaces(&p);
2519 if (!left)
2520 break;
2522 err = proc_get_long(&p, &left, &val, &neg,
2523 proc_wspace_sep,
2524 sizeof(proc_wspace_sep), NULL);
2525 if (err)
2526 break;
2527 if (neg)
2528 continue;
2529 val = convmul * val / convdiv;
2530 if ((min && val < *min) || (max && val > *max)) {
2531 err = -EINVAL;
2532 break;
2534 *i = val;
2535 } else {
2536 val = convdiv * (*i) / convmul;
2537 if (!first) {
2538 err = proc_put_char(&buffer, &left, '\t');
2539 if (err)
2540 break;
2542 err = proc_put_long(&buffer, &left, val, false);
2543 if (err)
2544 break;
2548 if (!write && !first && left && !err)
2549 err = proc_put_char(&buffer, &left, '\n');
2550 if (write && !err)
2551 left -= proc_skip_spaces(&p);
2552 if (write) {
2553 kfree(kbuf);
2554 if (first)
2555 return err ? : -EINVAL;
2557 *lenp -= left;
2558 out:
2559 *ppos += *lenp;
2560 return err;
2563 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2564 void __user *buffer,
2565 size_t *lenp, loff_t *ppos,
2566 unsigned long convmul,
2567 unsigned long convdiv)
2569 return __do_proc_doulongvec_minmax(table->data, table, write,
2570 buffer, lenp, ppos, convmul, convdiv);
2574 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2575 * @table: the sysctl table
2576 * @write: %TRUE if this is a write to the sysctl file
2577 * @buffer: the user buffer
2578 * @lenp: the size of the user buffer
2579 * @ppos: file position
2581 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2582 * values from/to the user buffer, treated as an ASCII string.
2584 * This routine will ensure the values are within the range specified by
2585 * table->extra1 (min) and table->extra2 (max).
2587 * Returns 0 on success.
2589 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2590 void __user *buffer, size_t *lenp, loff_t *ppos)
2592 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2596 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2597 * @table: the sysctl table
2598 * @write: %TRUE if this is a write to the sysctl file
2599 * @buffer: the user buffer
2600 * @lenp: the size of the user buffer
2601 * @ppos: file position
2603 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2604 * values from/to the user buffer, treated as an ASCII string. The values
2605 * are treated as milliseconds, and converted to jiffies when they are stored.
2607 * This routine will ensure the values are within the range specified by
2608 * table->extra1 (min) and table->extra2 (max).
2610 * Returns 0 on success.
2612 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2613 void __user *buffer,
2614 size_t *lenp, loff_t *ppos)
2616 return do_proc_doulongvec_minmax(table, write, buffer,
2617 lenp, ppos, HZ, 1000l);
2621 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2622 int *valp,
2623 int write, void *data)
2625 if (write) {
2626 if (*lvalp > LONG_MAX / HZ)
2627 return 1;
2628 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2629 } else {
2630 int val = *valp;
2631 unsigned long lval;
2632 if (val < 0) {
2633 *negp = true;
2634 lval = -(unsigned long)val;
2635 } else {
2636 *negp = false;
2637 lval = (unsigned long)val;
2639 *lvalp = lval / HZ;
2641 return 0;
2644 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2645 int *valp,
2646 int write, void *data)
2648 if (write) {
2649 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2650 return 1;
2651 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2652 } else {
2653 int val = *valp;
2654 unsigned long lval;
2655 if (val < 0) {
2656 *negp = true;
2657 lval = -(unsigned long)val;
2658 } else {
2659 *negp = false;
2660 lval = (unsigned long)val;
2662 *lvalp = jiffies_to_clock_t(lval);
2664 return 0;
2667 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2668 int *valp,
2669 int write, void *data)
2671 if (write) {
2672 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2674 if (jif > INT_MAX)
2675 return 1;
2676 *valp = (int)jif;
2677 } else {
2678 int val = *valp;
2679 unsigned long lval;
2680 if (val < 0) {
2681 *negp = true;
2682 lval = -(unsigned long)val;
2683 } else {
2684 *negp = false;
2685 lval = (unsigned long)val;
2687 *lvalp = jiffies_to_msecs(lval);
2689 return 0;
2693 * proc_dointvec_jiffies - read a vector of integers as seconds
2694 * @table: the sysctl table
2695 * @write: %TRUE if this is a write to the sysctl file
2696 * @buffer: the user buffer
2697 * @lenp: the size of the user buffer
2698 * @ppos: file position
2700 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2701 * values from/to the user buffer, treated as an ASCII string.
2702 * The values read are assumed to be in seconds, and are converted into
2703 * jiffies.
2705 * Returns 0 on success.
2707 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2708 void __user *buffer, size_t *lenp, loff_t *ppos)
2710 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2711 do_proc_dointvec_jiffies_conv,NULL);
2715 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2716 * @table: the sysctl table
2717 * @write: %TRUE if this is a write to the sysctl file
2718 * @buffer: the user buffer
2719 * @lenp: the size of the user buffer
2720 * @ppos: pointer to the file position
2722 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2723 * values from/to the user buffer, treated as an ASCII string.
2724 * The values read are assumed to be in 1/USER_HZ seconds, and
2725 * are converted into jiffies.
2727 * Returns 0 on success.
2729 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2730 void __user *buffer, size_t *lenp, loff_t *ppos)
2732 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2733 do_proc_dointvec_userhz_jiffies_conv,NULL);
2737 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2738 * @table: the sysctl table
2739 * @write: %TRUE if this is a write to the sysctl file
2740 * @buffer: the user buffer
2741 * @lenp: the size of the user buffer
2742 * @ppos: file position
2743 * @ppos: the current position in the file
2745 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2746 * values from/to the user buffer, treated as an ASCII string.
2747 * The values read are assumed to be in 1/1000 seconds, and
2748 * are converted into jiffies.
2750 * Returns 0 on success.
2752 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2753 void __user *buffer, size_t *lenp, loff_t *ppos)
2755 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2756 do_proc_dointvec_ms_jiffies_conv, NULL);
2759 static int proc_do_cad_pid(struct ctl_table *table, int write,
2760 void __user *buffer, size_t *lenp, loff_t *ppos)
2762 struct pid *new_pid;
2763 pid_t tmp;
2764 int r;
2766 tmp = pid_vnr(cad_pid);
2768 r = __do_proc_dointvec(&tmp, table, write, buffer,
2769 lenp, ppos, NULL, NULL);
2770 if (r || !write)
2771 return r;
2773 new_pid = find_get_pid(tmp);
2774 if (!new_pid)
2775 return -ESRCH;
2777 put_pid(xchg(&cad_pid, new_pid));
2778 return 0;
2782 * proc_do_large_bitmap - read/write from/to a large bitmap
2783 * @table: the sysctl table
2784 * @write: %TRUE if this is a write to the sysctl file
2785 * @buffer: the user buffer
2786 * @lenp: the size of the user buffer
2787 * @ppos: file position
2789 * The bitmap is stored at table->data and the bitmap length (in bits)
2790 * in table->maxlen.
2792 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2793 * large bitmaps may be represented in a compact manner. Writing into
2794 * the file will clear the bitmap then update it with the given input.
2796 * Returns 0 on success.
2798 int proc_do_large_bitmap(struct ctl_table *table, int write,
2799 void __user *buffer, size_t *lenp, loff_t *ppos)
2801 int err = 0;
2802 bool first = 1;
2803 size_t left = *lenp;
2804 unsigned long bitmap_len = table->maxlen;
2805 unsigned long *bitmap = *(unsigned long **) table->data;
2806 unsigned long *tmp_bitmap = NULL;
2807 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2809 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2810 *lenp = 0;
2811 return 0;
2814 if (write) {
2815 char *kbuf, *p;
2817 if (left > PAGE_SIZE - 1)
2818 left = PAGE_SIZE - 1;
2820 p = kbuf = memdup_user_nul(buffer, left);
2821 if (IS_ERR(kbuf))
2822 return PTR_ERR(kbuf);
2824 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2825 GFP_KERNEL);
2826 if (!tmp_bitmap) {
2827 kfree(kbuf);
2828 return -ENOMEM;
2830 proc_skip_char(&p, &left, '\n');
2831 while (!err && left) {
2832 unsigned long val_a, val_b;
2833 bool neg;
2835 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
2836 sizeof(tr_a), &c);
2837 if (err)
2838 break;
2839 if (val_a >= bitmap_len || neg) {
2840 err = -EINVAL;
2841 break;
2844 val_b = val_a;
2845 if (left) {
2846 p++;
2847 left--;
2850 if (c == '-') {
2851 err = proc_get_long(&p, &left, &val_b,
2852 &neg, tr_b, sizeof(tr_b),
2853 &c);
2854 if (err)
2855 break;
2856 if (val_b >= bitmap_len || neg ||
2857 val_a > val_b) {
2858 err = -EINVAL;
2859 break;
2861 if (left) {
2862 p++;
2863 left--;
2867 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2868 first = 0;
2869 proc_skip_char(&p, &left, '\n');
2871 kfree(kbuf);
2872 } else {
2873 unsigned long bit_a, bit_b = 0;
2875 while (left) {
2876 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2877 if (bit_a >= bitmap_len)
2878 break;
2879 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2880 bit_a + 1) - 1;
2882 if (!first) {
2883 err = proc_put_char(&buffer, &left, ',');
2884 if (err)
2885 break;
2887 err = proc_put_long(&buffer, &left, bit_a, false);
2888 if (err)
2889 break;
2890 if (bit_a != bit_b) {
2891 err = proc_put_char(&buffer, &left, '-');
2892 if (err)
2893 break;
2894 err = proc_put_long(&buffer, &left, bit_b, false);
2895 if (err)
2896 break;
2899 first = 0; bit_b++;
2901 if (!err)
2902 err = proc_put_char(&buffer, &left, '\n');
2905 if (!err) {
2906 if (write) {
2907 if (*ppos)
2908 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2909 else
2910 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2912 kfree(tmp_bitmap);
2913 *lenp -= left;
2914 *ppos += *lenp;
2915 return 0;
2916 } else {
2917 kfree(tmp_bitmap);
2918 return err;
2922 #else /* CONFIG_PROC_SYSCTL */
2924 int proc_dostring(struct ctl_table *table, int write,
2925 void __user *buffer, size_t *lenp, loff_t *ppos)
2927 return -ENOSYS;
2930 int proc_dointvec(struct ctl_table *table, int write,
2931 void __user *buffer, size_t *lenp, loff_t *ppos)
2933 return -ENOSYS;
2936 int proc_douintvec(struct ctl_table *table, int write,
2937 void __user *buffer, size_t *lenp, loff_t *ppos)
2939 return -ENOSYS;
2942 int proc_dointvec_minmax(struct ctl_table *table, int write,
2943 void __user *buffer, size_t *lenp, loff_t *ppos)
2945 return -ENOSYS;
2948 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2949 void __user *buffer, size_t *lenp, loff_t *ppos)
2951 return -ENOSYS;
2954 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2955 void __user *buffer, size_t *lenp, loff_t *ppos)
2957 return -ENOSYS;
2960 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2961 void __user *buffer, size_t *lenp, loff_t *ppos)
2963 return -ENOSYS;
2966 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2967 void __user *buffer, size_t *lenp, loff_t *ppos)
2969 return -ENOSYS;
2972 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2973 void __user *buffer,
2974 size_t *lenp, loff_t *ppos)
2976 return -ENOSYS;
2980 #endif /* CONFIG_PROC_SYSCTL */
2983 * No sense putting this after each symbol definition, twice,
2984 * exception granted :-)
2986 EXPORT_SYMBOL(proc_dointvec);
2987 EXPORT_SYMBOL(proc_douintvec);
2988 EXPORT_SYMBOL(proc_dointvec_jiffies);
2989 EXPORT_SYMBOL(proc_dointvec_minmax);
2990 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2991 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2992 EXPORT_SYMBOL(proc_dostring);
2993 EXPORT_SYMBOL(proc_doulongvec_minmax);
2994 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);