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
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
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>
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>
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>
71 #include <linux/uaccess.h>
72 #include <asm/processor.h>
76 #include <asm/stacktrace.h>
80 #include <asm/setup.h>
82 #ifdef CONFIG_BSD_PROCESS_ACCT
83 #include <linux/acct.h>
85 #ifdef CONFIG_RT_MUTEXES
86 #include <linux/rtmutex.h>
88 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
89 #include <linux/lockdep.h>
91 #ifdef CONFIG_CHR_DEV_SG
95 #ifdef CONFIG_LOCKUP_DETECTOR
96 #include <linux/nmi.h>
99 #if defined(CONFIG_SYSCTL)
101 /* External variables not in a header file. */
102 extern int suid_dumpable;
103 #ifdef CONFIG_COREDUMP
104 extern int core_uses_pid;
105 extern char core_pattern[];
106 extern unsigned int core_pipe_limit;
109 extern int pid_max_min, pid_max_max;
110 extern int percpu_pagelist_fraction;
111 extern int latencytop_enabled;
112 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
114 extern int sysctl_nr_trim_pages;
117 /* Constants used for minimum and maximum */
118 #ifdef CONFIG_LOCKUP_DETECTOR
119 static int sixty = 60;
122 static int __maybe_unused neg_one = -1;
125 static int __maybe_unused one = 1;
126 static int __maybe_unused two = 2;
127 static int __maybe_unused four = 4;
128 static unsigned long one_ul = 1;
129 static int one_hundred = 100;
130 static int one_thousand = 1000;
132 static int ten_thousand = 10000;
134 #ifdef CONFIG_PERF_EVENTS
135 static int six_hundred_forty_kb = 640 * 1024;
138 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
141 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142 static int maxolduid = 65535;
143 static int minolduid;
145 static int ngroups_max = NGROUPS_MAX;
146 static const int cap_last_cap = CAP_LAST_CAP;
148 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
149 #ifdef CONFIG_DETECT_HUNG_TASK
150 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
153 #ifdef CONFIG_INOTIFY_USER
154 #include <linux/inotify.h>
160 extern int pwrsw_enabled;
163 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
164 extern int unaligned_enabled;
168 extern int unaligned_dump_stack;
171 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172 extern int no_unaligned_warning;
175 #ifdef CONFIG_PROC_SYSCTL
177 #define SYSCTL_WRITES_LEGACY -1
178 #define SYSCTL_WRITES_WARN 0
179 #define SYSCTL_WRITES_STRICT 1
181 static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
183 static int proc_do_cad_pid(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
185 static int proc_taint(struct ctl_table *table, int write,
186 void __user *buffer, size_t *lenp, loff_t *ppos);
190 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
194 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
195 void __user *buffer, size_t *lenp, loff_t *ppos);
196 #ifdef CONFIG_COREDUMP
197 static int proc_dostring_coredump(struct ctl_table *table, int write,
198 void __user *buffer, size_t *lenp, loff_t *ppos);
201 #ifdef CONFIG_MAGIC_SYSRQ
202 /* Note: sysrq code uses it's own private copy */
203 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
205 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
206 void __user *buffer, size_t *lenp,
211 error = proc_dointvec(table, write, buffer, lenp, ppos);
216 sysrq_toggle_support(__sysrq_enabled);
223 static struct ctl_table kern_table[];
224 static struct ctl_table vm_table[];
225 static struct ctl_table fs_table[];
226 static struct ctl_table debug_table[];
227 static struct ctl_table dev_table[];
228 extern struct ctl_table random_table[];
230 extern struct ctl_table epoll_table[];
233 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
234 int sysctl_legacy_va_layout;
237 /* The default sysctl tables: */
239 static struct ctl_table sysctl_base_table[] = {
241 .procname = "kernel",
258 .child = debug_table,
268 #ifdef CONFIG_SCHED_DEBUG
269 static int min_sched_granularity_ns = 100000; /* 100 usecs */
270 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
271 static int min_wakeup_granularity_ns; /* 0 usecs */
272 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
274 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
275 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
276 #endif /* CONFIG_SMP */
277 #endif /* CONFIG_SCHED_DEBUG */
279 #ifdef CONFIG_COMPACTION
280 static int min_extfrag_threshold;
281 static int max_extfrag_threshold = 1000;
284 static struct ctl_table kern_table[] = {
286 .procname = "sched_child_runs_first",
287 .data = &sysctl_sched_child_runs_first,
288 .maxlen = sizeof(unsigned int),
290 .proc_handler = proc_dointvec,
292 #ifdef CONFIG_SCHED_DEBUG
294 .procname = "sched_min_granularity_ns",
295 .data = &sysctl_sched_min_granularity,
296 .maxlen = sizeof(unsigned int),
298 .proc_handler = sched_proc_update_handler,
299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
303 .procname = "sched_latency_ns",
304 .data = &sysctl_sched_latency,
305 .maxlen = sizeof(unsigned int),
307 .proc_handler = sched_proc_update_handler,
308 .extra1 = &min_sched_granularity_ns,
309 .extra2 = &max_sched_granularity_ns,
312 .procname = "sched_wakeup_granularity_ns",
313 .data = &sysctl_sched_wakeup_granularity,
314 .maxlen = sizeof(unsigned int),
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_wakeup_granularity_ns,
318 .extra2 = &max_wakeup_granularity_ns,
322 .procname = "sched_tunable_scaling",
323 .data = &sysctl_sched_tunable_scaling,
324 .maxlen = sizeof(enum sched_tunable_scaling),
326 .proc_handler = sched_proc_update_handler,
327 .extra1 = &min_sched_tunable_scaling,
328 .extra2 = &max_sched_tunable_scaling,
331 .procname = "sched_migration_cost_ns",
332 .data = &sysctl_sched_migration_cost,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = proc_dointvec,
338 .procname = "sched_nr_migrate",
339 .data = &sysctl_sched_nr_migrate,
340 .maxlen = sizeof(unsigned int),
342 .proc_handler = proc_dointvec,
345 .procname = "sched_time_avg_ms",
346 .data = &sysctl_sched_time_avg,
347 .maxlen = sizeof(unsigned int),
349 .proc_handler = proc_dointvec,
351 #ifdef CONFIG_SCHEDSTATS
353 .procname = "sched_schedstats",
355 .maxlen = sizeof(unsigned int),
357 .proc_handler = sysctl_schedstats,
361 #endif /* CONFIG_SCHEDSTATS */
362 #endif /* CONFIG_SMP */
363 #ifdef CONFIG_NUMA_BALANCING
365 .procname = "numa_balancing_scan_delay_ms",
366 .data = &sysctl_numa_balancing_scan_delay,
367 .maxlen = sizeof(unsigned int),
369 .proc_handler = proc_dointvec,
372 .procname = "numa_balancing_scan_period_min_ms",
373 .data = &sysctl_numa_balancing_scan_period_min,
374 .maxlen = sizeof(unsigned int),
376 .proc_handler = proc_dointvec,
379 .procname = "numa_balancing_scan_period_max_ms",
380 .data = &sysctl_numa_balancing_scan_period_max,
381 .maxlen = sizeof(unsigned int),
383 .proc_handler = proc_dointvec,
386 .procname = "numa_balancing_scan_size_mb",
387 .data = &sysctl_numa_balancing_scan_size,
388 .maxlen = sizeof(unsigned int),
390 .proc_handler = proc_dointvec_minmax,
394 .procname = "numa_balancing",
395 .data = NULL, /* filled in by handler */
396 .maxlen = sizeof(unsigned int),
398 .proc_handler = sysctl_numa_balancing,
402 #endif /* CONFIG_NUMA_BALANCING */
403 #endif /* CONFIG_SCHED_DEBUG */
405 .procname = "sched_rt_period_us",
406 .data = &sysctl_sched_rt_period,
407 .maxlen = sizeof(unsigned int),
409 .proc_handler = sched_rt_handler,
412 .procname = "sched_rt_runtime_us",
413 .data = &sysctl_sched_rt_runtime,
414 .maxlen = sizeof(int),
416 .proc_handler = sched_rt_handler,
419 .procname = "sched_rr_timeslice_ms",
420 .data = &sysctl_sched_rr_timeslice,
421 .maxlen = sizeof(int),
423 .proc_handler = sched_rr_handler,
425 #ifdef CONFIG_SCHED_AUTOGROUP
427 .procname = "sched_autogroup_enabled",
428 .data = &sysctl_sched_autogroup_enabled,
429 .maxlen = sizeof(unsigned int),
431 .proc_handler = proc_dointvec_minmax,
436 #ifdef CONFIG_CFS_BANDWIDTH
438 .procname = "sched_cfs_bandwidth_slice_us",
439 .data = &sysctl_sched_cfs_bandwidth_slice,
440 .maxlen = sizeof(unsigned int),
442 .proc_handler = proc_dointvec_minmax,
446 #ifdef CONFIG_PROVE_LOCKING
448 .procname = "prove_locking",
449 .data = &prove_locking,
450 .maxlen = sizeof(int),
452 .proc_handler = proc_dointvec,
455 #ifdef CONFIG_LOCK_STAT
457 .procname = "lock_stat",
459 .maxlen = sizeof(int),
461 .proc_handler = proc_dointvec,
466 .data = &panic_timeout,
467 .maxlen = sizeof(int),
469 .proc_handler = proc_dointvec,
471 #ifdef CONFIG_COREDUMP
473 .procname = "core_uses_pid",
474 .data = &core_uses_pid,
475 .maxlen = sizeof(int),
477 .proc_handler = proc_dointvec,
480 .procname = "core_pattern",
481 .data = core_pattern,
482 .maxlen = CORENAME_MAX_SIZE,
484 .proc_handler = proc_dostring_coredump,
487 .procname = "core_pipe_limit",
488 .data = &core_pipe_limit,
489 .maxlen = sizeof(unsigned int),
491 .proc_handler = proc_dointvec,
494 #ifdef CONFIG_PROC_SYSCTL
496 .procname = "tainted",
497 .maxlen = sizeof(long),
499 .proc_handler = proc_taint,
502 .procname = "sysctl_writes_strict",
503 .data = &sysctl_writes_strict,
504 .maxlen = sizeof(int),
506 .proc_handler = proc_dointvec_minmax,
511 #ifdef CONFIG_LATENCYTOP
513 .procname = "latencytop",
514 .data = &latencytop_enabled,
515 .maxlen = sizeof(int),
517 .proc_handler = sysctl_latencytop,
520 #ifdef CONFIG_BLK_DEV_INITRD
522 .procname = "real-root-dev",
523 .data = &real_root_dev,
524 .maxlen = sizeof(int),
526 .proc_handler = proc_dointvec,
530 .procname = "print-fatal-signals",
531 .data = &print_fatal_signals,
532 .maxlen = sizeof(int),
534 .proc_handler = proc_dointvec,
538 .procname = "reboot-cmd",
539 .data = reboot_command,
542 .proc_handler = proc_dostring,
545 .procname = "stop-a",
546 .data = &stop_a_enabled,
547 .maxlen = sizeof (int),
549 .proc_handler = proc_dointvec,
552 .procname = "scons-poweroff",
553 .data = &scons_pwroff,
554 .maxlen = sizeof (int),
556 .proc_handler = proc_dointvec,
559 #ifdef CONFIG_SPARC64
561 .procname = "tsb-ratio",
562 .data = &sysctl_tsb_ratio,
563 .maxlen = sizeof (int),
565 .proc_handler = proc_dointvec,
570 .procname = "soft-power",
571 .data = &pwrsw_enabled,
572 .maxlen = sizeof (int),
574 .proc_handler = proc_dointvec,
577 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
579 .procname = "unaligned-trap",
580 .data = &unaligned_enabled,
581 .maxlen = sizeof (int),
583 .proc_handler = proc_dointvec,
587 .procname = "ctrl-alt-del",
589 .maxlen = sizeof(int),
591 .proc_handler = proc_dointvec,
593 #ifdef CONFIG_FUNCTION_TRACER
595 .procname = "ftrace_enabled",
596 .data = &ftrace_enabled,
597 .maxlen = sizeof(int),
599 .proc_handler = ftrace_enable_sysctl,
602 #ifdef CONFIG_STACK_TRACER
604 .procname = "stack_tracer_enabled",
605 .data = &stack_tracer_enabled,
606 .maxlen = sizeof(int),
608 .proc_handler = stack_trace_sysctl,
611 #ifdef CONFIG_TRACING
613 .procname = "ftrace_dump_on_oops",
614 .data = &ftrace_dump_on_oops,
615 .maxlen = sizeof(int),
617 .proc_handler = proc_dointvec,
620 .procname = "traceoff_on_warning",
621 .data = &__disable_trace_on_warning,
622 .maxlen = sizeof(__disable_trace_on_warning),
624 .proc_handler = proc_dointvec,
627 .procname = "tracepoint_printk",
628 .data = &tracepoint_printk,
629 .maxlen = sizeof(tracepoint_printk),
631 .proc_handler = tracepoint_printk_sysctl,
634 #ifdef CONFIG_KEXEC_CORE
636 .procname = "kexec_load_disabled",
637 .data = &kexec_load_disabled,
638 .maxlen = sizeof(int),
640 /* only handle a transition from default "0" to "1" */
641 .proc_handler = proc_dointvec_minmax,
646 #ifdef CONFIG_MODULES
648 .procname = "modprobe",
649 .data = &modprobe_path,
650 .maxlen = KMOD_PATH_LEN,
652 .proc_handler = proc_dostring,
655 .procname = "modules_disabled",
656 .data = &modules_disabled,
657 .maxlen = sizeof(int),
659 /* only handle a transition from default "0" to "1" */
660 .proc_handler = proc_dointvec_minmax,
665 #ifdef CONFIG_UEVENT_HELPER
667 .procname = "hotplug",
668 .data = &uevent_helper,
669 .maxlen = UEVENT_HELPER_PATH_LEN,
671 .proc_handler = proc_dostring,
674 #ifdef CONFIG_CHR_DEV_SG
676 .procname = "sg-big-buff",
677 .data = &sg_big_buff,
678 .maxlen = sizeof (int),
680 .proc_handler = proc_dointvec,
683 #ifdef CONFIG_BSD_PROCESS_ACCT
687 .maxlen = 3*sizeof(int),
689 .proc_handler = proc_dointvec,
692 #ifdef CONFIG_MAGIC_SYSRQ
695 .data = &__sysrq_enabled,
696 .maxlen = sizeof (int),
698 .proc_handler = sysrq_sysctl_handler,
701 #ifdef CONFIG_PROC_SYSCTL
703 .procname = "cad_pid",
705 .maxlen = sizeof (int),
707 .proc_handler = proc_do_cad_pid,
711 .procname = "threads-max",
713 .maxlen = sizeof(int),
715 .proc_handler = sysctl_max_threads,
718 .procname = "random",
720 .child = random_table,
723 .procname = "usermodehelper",
725 .child = usermodehelper_table,
728 .procname = "overflowuid",
729 .data = &overflowuid,
730 .maxlen = sizeof(int),
732 .proc_handler = proc_dointvec_minmax,
733 .extra1 = &minolduid,
734 .extra2 = &maxolduid,
737 .procname = "overflowgid",
738 .data = &overflowgid,
739 .maxlen = sizeof(int),
741 .proc_handler = proc_dointvec_minmax,
742 .extra1 = &minolduid,
743 .extra2 = &maxolduid,
746 #ifdef CONFIG_MATHEMU
748 .procname = "ieee_emulation_warnings",
749 .data = &sysctl_ieee_emulation_warnings,
750 .maxlen = sizeof(int),
752 .proc_handler = proc_dointvec,
756 .procname = "userprocess_debug",
757 .data = &show_unhandled_signals,
758 .maxlen = sizeof(int),
760 .proc_handler = proc_dointvec,
764 .procname = "pid_max",
766 .maxlen = sizeof (int),
768 .proc_handler = proc_dointvec_minmax,
769 .extra1 = &pid_max_min,
770 .extra2 = &pid_max_max,
773 .procname = "panic_on_oops",
774 .data = &panic_on_oops,
775 .maxlen = sizeof(int),
777 .proc_handler = proc_dointvec,
779 #if defined CONFIG_PRINTK
781 .procname = "printk",
782 .data = &console_loglevel,
783 .maxlen = 4*sizeof(int),
785 .proc_handler = proc_dointvec,
788 .procname = "printk_ratelimit",
789 .data = &printk_ratelimit_state.interval,
790 .maxlen = sizeof(int),
792 .proc_handler = proc_dointvec_jiffies,
795 .procname = "printk_ratelimit_burst",
796 .data = &printk_ratelimit_state.burst,
797 .maxlen = sizeof(int),
799 .proc_handler = proc_dointvec,
802 .procname = "printk_delay",
803 .data = &printk_delay_msec,
804 .maxlen = sizeof(int),
806 .proc_handler = proc_dointvec_minmax,
808 .extra2 = &ten_thousand,
811 .procname = "printk_devkmsg",
812 .data = devkmsg_log_str,
813 .maxlen = DEVKMSG_STR_MAX_SIZE,
815 .proc_handler = devkmsg_sysctl_set_loglvl,
818 .procname = "dmesg_restrict",
819 .data = &dmesg_restrict,
820 .maxlen = sizeof(int),
822 .proc_handler = proc_dointvec_minmax_sysadmin,
827 .procname = "kptr_restrict",
828 .data = &kptr_restrict,
829 .maxlen = sizeof(int),
831 .proc_handler = proc_dointvec_minmax_sysadmin,
837 .procname = "ngroups_max",
838 .data = &ngroups_max,
839 .maxlen = sizeof (int),
841 .proc_handler = proc_dointvec,
844 .procname = "cap_last_cap",
845 .data = (void *)&cap_last_cap,
846 .maxlen = sizeof(int),
848 .proc_handler = proc_dointvec,
850 #if defined(CONFIG_LOCKUP_DETECTOR)
852 .procname = "watchdog",
853 .data = &watchdog_user_enabled,
854 .maxlen = sizeof (int),
856 .proc_handler = proc_watchdog,
861 .procname = "watchdog_thresh",
862 .data = &watchdog_thresh,
863 .maxlen = sizeof(int),
865 .proc_handler = proc_watchdog_thresh,
870 .procname = "nmi_watchdog",
871 .data = &nmi_watchdog_enabled,
872 .maxlen = sizeof (int),
874 .proc_handler = proc_nmi_watchdog,
876 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
883 .procname = "soft_watchdog",
884 .data = &soft_watchdog_enabled,
885 .maxlen = sizeof (int),
887 .proc_handler = proc_soft_watchdog,
892 .procname = "watchdog_cpumask",
893 .data = &watchdog_cpumask_bits,
896 .proc_handler = proc_watchdog_cpumask,
899 .procname = "softlockup_panic",
900 .data = &softlockup_panic,
901 .maxlen = sizeof(int),
903 .proc_handler = proc_dointvec_minmax,
907 #ifdef CONFIG_HARDLOCKUP_DETECTOR
909 .procname = "hardlockup_panic",
910 .data = &hardlockup_panic,
911 .maxlen = sizeof(int),
913 .proc_handler = proc_dointvec_minmax,
920 .procname = "softlockup_all_cpu_backtrace",
921 .data = &sysctl_softlockup_all_cpu_backtrace,
922 .maxlen = sizeof(int),
924 .proc_handler = proc_dointvec_minmax,
929 .procname = "hardlockup_all_cpu_backtrace",
930 .data = &sysctl_hardlockup_all_cpu_backtrace,
931 .maxlen = sizeof(int),
933 .proc_handler = proc_dointvec_minmax,
937 #endif /* CONFIG_SMP */
939 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
941 .procname = "unknown_nmi_panic",
942 .data = &unknown_nmi_panic,
943 .maxlen = sizeof (int),
945 .proc_handler = proc_dointvec,
948 #if defined(CONFIG_X86)
950 .procname = "panic_on_unrecovered_nmi",
951 .data = &panic_on_unrecovered_nmi,
952 .maxlen = sizeof(int),
954 .proc_handler = proc_dointvec,
957 .procname = "panic_on_io_nmi",
958 .data = &panic_on_io_nmi,
959 .maxlen = sizeof(int),
961 .proc_handler = proc_dointvec,
963 #ifdef CONFIG_DEBUG_STACKOVERFLOW
965 .procname = "panic_on_stackoverflow",
966 .data = &sysctl_panic_on_stackoverflow,
967 .maxlen = sizeof(int),
969 .proc_handler = proc_dointvec,
973 .procname = "bootloader_type",
974 .data = &bootloader_type,
975 .maxlen = sizeof (int),
977 .proc_handler = proc_dointvec,
980 .procname = "bootloader_version",
981 .data = &bootloader_version,
982 .maxlen = sizeof (int),
984 .proc_handler = proc_dointvec,
987 .procname = "io_delay_type",
988 .data = &io_delay_type,
989 .maxlen = sizeof(int),
991 .proc_handler = proc_dointvec,
994 #if defined(CONFIG_MMU)
996 .procname = "randomize_va_space",
997 .data = &randomize_va_space,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec,
1003 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1005 .procname = "spin_retry",
1006 .data = &spin_retry,
1007 .maxlen = sizeof (int),
1009 .proc_handler = proc_dointvec,
1012 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1014 .procname = "acpi_video_flags",
1015 .data = &acpi_realmode_flags,
1016 .maxlen = sizeof (unsigned long),
1018 .proc_handler = proc_doulongvec_minmax,
1021 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1023 .procname = "ignore-unaligned-usertrap",
1024 .data = &no_unaligned_warning,
1025 .maxlen = sizeof (int),
1027 .proc_handler = proc_dointvec,
1032 .procname = "unaligned-dump-stack",
1033 .data = &unaligned_dump_stack,
1034 .maxlen = sizeof (int),
1036 .proc_handler = proc_dointvec,
1039 #ifdef CONFIG_DETECT_HUNG_TASK
1041 .procname = "hung_task_panic",
1042 .data = &sysctl_hung_task_panic,
1043 .maxlen = sizeof(int),
1045 .proc_handler = proc_dointvec_minmax,
1050 .procname = "hung_task_check_count",
1051 .data = &sysctl_hung_task_check_count,
1052 .maxlen = sizeof(int),
1054 .proc_handler = proc_dointvec_minmax,
1058 .procname = "hung_task_timeout_secs",
1059 .data = &sysctl_hung_task_timeout_secs,
1060 .maxlen = sizeof(unsigned long),
1062 .proc_handler = proc_dohung_task_timeout_secs,
1063 .extra2 = &hung_task_timeout_max,
1066 .procname = "hung_task_warnings",
1067 .data = &sysctl_hung_task_warnings,
1068 .maxlen = sizeof(int),
1070 .proc_handler = proc_dointvec_minmax,
1074 #ifdef CONFIG_RT_MUTEXES
1076 .procname = "max_lock_depth",
1077 .data = &max_lock_depth,
1078 .maxlen = sizeof(int),
1080 .proc_handler = proc_dointvec,
1084 .procname = "poweroff_cmd",
1085 .data = &poweroff_cmd,
1086 .maxlen = POWEROFF_CMD_PATH_LEN,
1088 .proc_handler = proc_dostring,
1094 .child = key_sysctls,
1097 #ifdef CONFIG_PERF_EVENTS
1099 * User-space scripts rely on the existence of this file
1100 * as a feature check for perf_events being enabled.
1102 * So it's an ABI, do not remove!
1105 .procname = "perf_event_paranoid",
1106 .data = &sysctl_perf_event_paranoid,
1107 .maxlen = sizeof(sysctl_perf_event_paranoid),
1109 .proc_handler = proc_dointvec,
1112 .procname = "perf_event_mlock_kb",
1113 .data = &sysctl_perf_event_mlock,
1114 .maxlen = sizeof(sysctl_perf_event_mlock),
1116 .proc_handler = proc_dointvec,
1119 .procname = "perf_event_max_sample_rate",
1120 .data = &sysctl_perf_event_sample_rate,
1121 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1123 .proc_handler = perf_proc_update_handler,
1127 .procname = "perf_cpu_time_max_percent",
1128 .data = &sysctl_perf_cpu_time_max_percent,
1129 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1131 .proc_handler = perf_cpu_time_max_percent_handler,
1133 .extra2 = &one_hundred,
1136 .procname = "perf_event_max_stack",
1137 .data = &sysctl_perf_event_max_stack,
1138 .maxlen = sizeof(sysctl_perf_event_max_stack),
1140 .proc_handler = perf_event_max_stack_handler,
1142 .extra2 = &six_hundred_forty_kb,
1145 .procname = "perf_event_max_contexts_per_stack",
1146 .data = &sysctl_perf_event_max_contexts_per_stack,
1147 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1149 .proc_handler = perf_event_max_stack_handler,
1151 .extra2 = &one_thousand,
1154 #ifdef CONFIG_KMEMCHECK
1156 .procname = "kmemcheck",
1157 .data = &kmemcheck_enabled,
1158 .maxlen = sizeof(int),
1160 .proc_handler = proc_dointvec,
1164 .procname = "panic_on_warn",
1165 .data = &panic_on_warn,
1166 .maxlen = sizeof(int),
1168 .proc_handler = proc_dointvec_minmax,
1172 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1174 .procname = "timer_migration",
1175 .data = &sysctl_timer_migration,
1176 .maxlen = sizeof(unsigned int),
1178 .proc_handler = timer_migration_handler,
1183 #ifdef CONFIG_BPF_SYSCALL
1185 .procname = "unprivileged_bpf_disabled",
1186 .data = &sysctl_unprivileged_bpf_disabled,
1187 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1189 /* only handle a transition from default "0" to "1" */
1190 .proc_handler = proc_dointvec_minmax,
1195 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1197 .procname = "panic_on_rcu_stall",
1198 .data = &sysctl_panic_on_rcu_stall,
1199 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1201 .proc_handler = proc_dointvec_minmax,
1209 static struct ctl_table vm_table[] = {
1211 .procname = "overcommit_memory",
1212 .data = &sysctl_overcommit_memory,
1213 .maxlen = sizeof(sysctl_overcommit_memory),
1215 .proc_handler = proc_dointvec_minmax,
1220 .procname = "panic_on_oom",
1221 .data = &sysctl_panic_on_oom,
1222 .maxlen = sizeof(sysctl_panic_on_oom),
1224 .proc_handler = proc_dointvec_minmax,
1229 .procname = "oom_kill_allocating_task",
1230 .data = &sysctl_oom_kill_allocating_task,
1231 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1233 .proc_handler = proc_dointvec,
1236 .procname = "oom_dump_tasks",
1237 .data = &sysctl_oom_dump_tasks,
1238 .maxlen = sizeof(sysctl_oom_dump_tasks),
1240 .proc_handler = proc_dointvec,
1243 .procname = "overcommit_ratio",
1244 .data = &sysctl_overcommit_ratio,
1245 .maxlen = sizeof(sysctl_overcommit_ratio),
1247 .proc_handler = overcommit_ratio_handler,
1250 .procname = "overcommit_kbytes",
1251 .data = &sysctl_overcommit_kbytes,
1252 .maxlen = sizeof(sysctl_overcommit_kbytes),
1254 .proc_handler = overcommit_kbytes_handler,
1257 .procname = "page-cluster",
1258 .data = &page_cluster,
1259 .maxlen = sizeof(int),
1261 .proc_handler = proc_dointvec_minmax,
1265 .procname = "dirty_background_ratio",
1266 .data = &dirty_background_ratio,
1267 .maxlen = sizeof(dirty_background_ratio),
1269 .proc_handler = dirty_background_ratio_handler,
1271 .extra2 = &one_hundred,
1274 .procname = "dirty_background_bytes",
1275 .data = &dirty_background_bytes,
1276 .maxlen = sizeof(dirty_background_bytes),
1278 .proc_handler = dirty_background_bytes_handler,
1282 .procname = "dirty_ratio",
1283 .data = &vm_dirty_ratio,
1284 .maxlen = sizeof(vm_dirty_ratio),
1286 .proc_handler = dirty_ratio_handler,
1288 .extra2 = &one_hundred,
1291 .procname = "dirty_bytes",
1292 .data = &vm_dirty_bytes,
1293 .maxlen = sizeof(vm_dirty_bytes),
1295 .proc_handler = dirty_bytes_handler,
1296 .extra1 = &dirty_bytes_min,
1299 .procname = "dirty_writeback_centisecs",
1300 .data = &dirty_writeback_interval,
1301 .maxlen = sizeof(dirty_writeback_interval),
1303 .proc_handler = dirty_writeback_centisecs_handler,
1306 .procname = "dirty_expire_centisecs",
1307 .data = &dirty_expire_interval,
1308 .maxlen = sizeof(dirty_expire_interval),
1310 .proc_handler = proc_dointvec_minmax,
1314 .procname = "dirtytime_expire_seconds",
1315 .data = &dirtytime_expire_interval,
1316 .maxlen = sizeof(dirty_expire_interval),
1318 .proc_handler = dirtytime_interval_handler,
1322 .procname = "nr_pdflush_threads",
1323 .mode = 0444 /* read-only */,
1324 .proc_handler = pdflush_proc_obsolete,
1327 .procname = "swappiness",
1328 .data = &vm_swappiness,
1329 .maxlen = sizeof(vm_swappiness),
1331 .proc_handler = proc_dointvec_minmax,
1333 .extra2 = &one_hundred,
1335 #ifdef CONFIG_HUGETLB_PAGE
1337 .procname = "nr_hugepages",
1339 .maxlen = sizeof(unsigned long),
1341 .proc_handler = hugetlb_sysctl_handler,
1345 .procname = "nr_hugepages_mempolicy",
1347 .maxlen = sizeof(unsigned long),
1349 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1353 .procname = "hugetlb_shm_group",
1354 .data = &sysctl_hugetlb_shm_group,
1355 .maxlen = sizeof(gid_t),
1357 .proc_handler = proc_dointvec,
1360 .procname = "hugepages_treat_as_movable",
1361 .data = &hugepages_treat_as_movable,
1362 .maxlen = sizeof(int),
1364 .proc_handler = proc_dointvec,
1367 .procname = "nr_overcommit_hugepages",
1369 .maxlen = sizeof(unsigned long),
1371 .proc_handler = hugetlb_overcommit_handler,
1375 .procname = "lowmem_reserve_ratio",
1376 .data = &sysctl_lowmem_reserve_ratio,
1377 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1379 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1382 .procname = "drop_caches",
1383 .data = &sysctl_drop_caches,
1384 .maxlen = sizeof(int),
1386 .proc_handler = drop_caches_sysctl_handler,
1390 #ifdef CONFIG_COMPACTION
1392 .procname = "compact_memory",
1393 .data = &sysctl_compact_memory,
1394 .maxlen = sizeof(int),
1396 .proc_handler = sysctl_compaction_handler,
1399 .procname = "extfrag_threshold",
1400 .data = &sysctl_extfrag_threshold,
1401 .maxlen = sizeof(int),
1403 .proc_handler = sysctl_extfrag_handler,
1404 .extra1 = &min_extfrag_threshold,
1405 .extra2 = &max_extfrag_threshold,
1408 .procname = "compact_unevictable_allowed",
1409 .data = &sysctl_compact_unevictable_allowed,
1410 .maxlen = sizeof(int),
1412 .proc_handler = proc_dointvec,
1417 #endif /* CONFIG_COMPACTION */
1419 .procname = "min_free_kbytes",
1420 .data = &min_free_kbytes,
1421 .maxlen = sizeof(min_free_kbytes),
1423 .proc_handler = min_free_kbytes_sysctl_handler,
1427 .procname = "watermark_scale_factor",
1428 .data = &watermark_scale_factor,
1429 .maxlen = sizeof(watermark_scale_factor),
1431 .proc_handler = watermark_scale_factor_sysctl_handler,
1433 .extra2 = &one_thousand,
1436 .procname = "percpu_pagelist_fraction",
1437 .data = &percpu_pagelist_fraction,
1438 .maxlen = sizeof(percpu_pagelist_fraction),
1440 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1445 .procname = "max_map_count",
1446 .data = &sysctl_max_map_count,
1447 .maxlen = sizeof(sysctl_max_map_count),
1449 .proc_handler = proc_dointvec_minmax,
1454 .procname = "nr_trim_pages",
1455 .data = &sysctl_nr_trim_pages,
1456 .maxlen = sizeof(sysctl_nr_trim_pages),
1458 .proc_handler = proc_dointvec_minmax,
1463 .procname = "laptop_mode",
1464 .data = &laptop_mode,
1465 .maxlen = sizeof(laptop_mode),
1467 .proc_handler = proc_dointvec_jiffies,
1470 .procname = "block_dump",
1471 .data = &block_dump,
1472 .maxlen = sizeof(block_dump),
1474 .proc_handler = proc_dointvec,
1478 .procname = "vfs_cache_pressure",
1479 .data = &sysctl_vfs_cache_pressure,
1480 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1482 .proc_handler = proc_dointvec,
1485 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1487 .procname = "legacy_va_layout",
1488 .data = &sysctl_legacy_va_layout,
1489 .maxlen = sizeof(sysctl_legacy_va_layout),
1491 .proc_handler = proc_dointvec,
1497 .procname = "zone_reclaim_mode",
1498 .data = &node_reclaim_mode,
1499 .maxlen = sizeof(node_reclaim_mode),
1501 .proc_handler = proc_dointvec,
1505 .procname = "min_unmapped_ratio",
1506 .data = &sysctl_min_unmapped_ratio,
1507 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1509 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1511 .extra2 = &one_hundred,
1514 .procname = "min_slab_ratio",
1515 .data = &sysctl_min_slab_ratio,
1516 .maxlen = sizeof(sysctl_min_slab_ratio),
1518 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1520 .extra2 = &one_hundred,
1525 .procname = "stat_interval",
1526 .data = &sysctl_stat_interval,
1527 .maxlen = sizeof(sysctl_stat_interval),
1529 .proc_handler = proc_dointvec_jiffies,
1532 .procname = "stat_refresh",
1536 .proc_handler = vmstat_refresh,
1541 .procname = "mmap_min_addr",
1542 .data = &dac_mmap_min_addr,
1543 .maxlen = sizeof(unsigned long),
1545 .proc_handler = mmap_min_addr_handler,
1550 .procname = "numa_zonelist_order",
1551 .data = &numa_zonelist_order,
1552 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1554 .proc_handler = numa_zonelist_order_handler,
1557 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1558 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1560 .procname = "vdso_enabled",
1561 #ifdef CONFIG_X86_32
1562 .data = &vdso32_enabled,
1563 .maxlen = sizeof(vdso32_enabled),
1565 .data = &vdso_enabled,
1566 .maxlen = sizeof(vdso_enabled),
1569 .proc_handler = proc_dointvec,
1573 #ifdef CONFIG_HIGHMEM
1575 .procname = "highmem_is_dirtyable",
1576 .data = &vm_highmem_is_dirtyable,
1577 .maxlen = sizeof(vm_highmem_is_dirtyable),
1579 .proc_handler = proc_dointvec_minmax,
1584 #ifdef CONFIG_MEMORY_FAILURE
1586 .procname = "memory_failure_early_kill",
1587 .data = &sysctl_memory_failure_early_kill,
1588 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1590 .proc_handler = proc_dointvec_minmax,
1595 .procname = "memory_failure_recovery",
1596 .data = &sysctl_memory_failure_recovery,
1597 .maxlen = sizeof(sysctl_memory_failure_recovery),
1599 .proc_handler = proc_dointvec_minmax,
1605 .procname = "user_reserve_kbytes",
1606 .data = &sysctl_user_reserve_kbytes,
1607 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1609 .proc_handler = proc_doulongvec_minmax,
1612 .procname = "admin_reserve_kbytes",
1613 .data = &sysctl_admin_reserve_kbytes,
1614 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1616 .proc_handler = proc_doulongvec_minmax,
1618 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1620 .procname = "mmap_rnd_bits",
1621 .data = &mmap_rnd_bits,
1622 .maxlen = sizeof(mmap_rnd_bits),
1624 .proc_handler = proc_dointvec_minmax,
1625 .extra1 = (void *)&mmap_rnd_bits_min,
1626 .extra2 = (void *)&mmap_rnd_bits_max,
1629 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1631 .procname = "mmap_rnd_compat_bits",
1632 .data = &mmap_rnd_compat_bits,
1633 .maxlen = sizeof(mmap_rnd_compat_bits),
1635 .proc_handler = proc_dointvec_minmax,
1636 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1637 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1643 static struct ctl_table fs_table[] = {
1645 .procname = "inode-nr",
1646 .data = &inodes_stat,
1647 .maxlen = 2*sizeof(long),
1649 .proc_handler = proc_nr_inodes,
1652 .procname = "inode-state",
1653 .data = &inodes_stat,
1654 .maxlen = 7*sizeof(long),
1656 .proc_handler = proc_nr_inodes,
1659 .procname = "file-nr",
1660 .data = &files_stat,
1661 .maxlen = sizeof(files_stat),
1663 .proc_handler = proc_nr_files,
1666 .procname = "file-max",
1667 .data = &files_stat.max_files,
1668 .maxlen = sizeof(files_stat.max_files),
1670 .proc_handler = proc_doulongvec_minmax,
1673 .procname = "nr_open",
1674 .data = &sysctl_nr_open,
1675 .maxlen = sizeof(unsigned int),
1677 .proc_handler = proc_dointvec_minmax,
1678 .extra1 = &sysctl_nr_open_min,
1679 .extra2 = &sysctl_nr_open_max,
1682 .procname = "dentry-state",
1683 .data = &dentry_stat,
1684 .maxlen = 6*sizeof(long),
1686 .proc_handler = proc_nr_dentry,
1689 .procname = "overflowuid",
1690 .data = &fs_overflowuid,
1691 .maxlen = sizeof(int),
1693 .proc_handler = proc_dointvec_minmax,
1694 .extra1 = &minolduid,
1695 .extra2 = &maxolduid,
1698 .procname = "overflowgid",
1699 .data = &fs_overflowgid,
1700 .maxlen = sizeof(int),
1702 .proc_handler = proc_dointvec_minmax,
1703 .extra1 = &minolduid,
1704 .extra2 = &maxolduid,
1706 #ifdef CONFIG_FILE_LOCKING
1708 .procname = "leases-enable",
1709 .data = &leases_enable,
1710 .maxlen = sizeof(int),
1712 .proc_handler = proc_dointvec,
1715 #ifdef CONFIG_DNOTIFY
1717 .procname = "dir-notify-enable",
1718 .data = &dir_notify_enable,
1719 .maxlen = sizeof(int),
1721 .proc_handler = proc_dointvec,
1725 #ifdef CONFIG_FILE_LOCKING
1727 .procname = "lease-break-time",
1728 .data = &lease_break_time,
1729 .maxlen = sizeof(int),
1731 .proc_handler = proc_dointvec,
1736 .procname = "aio-nr",
1738 .maxlen = sizeof(aio_nr),
1740 .proc_handler = proc_doulongvec_minmax,
1743 .procname = "aio-max-nr",
1744 .data = &aio_max_nr,
1745 .maxlen = sizeof(aio_max_nr),
1747 .proc_handler = proc_doulongvec_minmax,
1749 #endif /* CONFIG_AIO */
1750 #ifdef CONFIG_INOTIFY_USER
1752 .procname = "inotify",
1754 .child = inotify_table,
1759 .procname = "epoll",
1761 .child = epoll_table,
1766 .procname = "protected_symlinks",
1767 .data = &sysctl_protected_symlinks,
1768 .maxlen = sizeof(int),
1770 .proc_handler = proc_dointvec_minmax,
1775 .procname = "protected_hardlinks",
1776 .data = &sysctl_protected_hardlinks,
1777 .maxlen = sizeof(int),
1779 .proc_handler = proc_dointvec_minmax,
1784 .procname = "suid_dumpable",
1785 .data = &suid_dumpable,
1786 .maxlen = sizeof(int),
1788 .proc_handler = proc_dointvec_minmax_coredump,
1792 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1794 .procname = "binfmt_misc",
1796 .child = sysctl_mount_point,
1800 .procname = "pipe-max-size",
1801 .data = &pipe_max_size,
1802 .maxlen = sizeof(int),
1804 .proc_handler = &pipe_proc_fn,
1805 .extra1 = &pipe_min_size,
1808 .procname = "pipe-user-pages-hard",
1809 .data = &pipe_user_pages_hard,
1810 .maxlen = sizeof(pipe_user_pages_hard),
1812 .proc_handler = proc_doulongvec_minmax,
1815 .procname = "pipe-user-pages-soft",
1816 .data = &pipe_user_pages_soft,
1817 .maxlen = sizeof(pipe_user_pages_soft),
1819 .proc_handler = proc_doulongvec_minmax,
1822 .procname = "mount-max",
1823 .data = &sysctl_mount_max,
1824 .maxlen = sizeof(unsigned int),
1826 .proc_handler = proc_dointvec_minmax,
1832 static struct ctl_table debug_table[] = {
1833 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1835 .procname = "exception-trace",
1836 .data = &show_unhandled_signals,
1837 .maxlen = sizeof(int),
1839 .proc_handler = proc_dointvec
1842 #if defined(CONFIG_OPTPROBES)
1844 .procname = "kprobes-optimization",
1845 .data = &sysctl_kprobes_optimization,
1846 .maxlen = sizeof(int),
1848 .proc_handler = proc_kprobes_optimization_handler,
1856 static struct ctl_table dev_table[] = {
1860 int __init sysctl_init(void)
1862 struct ctl_table_header *hdr;
1864 hdr = register_sysctl_table(sysctl_base_table);
1865 kmemleak_not_leak(hdr);
1869 #endif /* CONFIG_SYSCTL */
1875 #ifdef CONFIG_PROC_SYSCTL
1877 static int _proc_do_string(char *data, int maxlen, int write,
1878 char __user *buffer,
1879 size_t *lenp, loff_t *ppos)
1885 if (!data || !maxlen || !*lenp) {
1891 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1892 /* Only continue writes not past the end of buffer. */
1894 if (len > maxlen - 1)
1901 /* Start writing from beginning of buffer. */
1907 while ((p - buffer) < *lenp && len < maxlen - 1) {
1908 if (get_user(c, p++))
1910 if (c == 0 || c == '\n')
1931 if (copy_to_user(buffer, data, len))
1934 if (put_user('\n', buffer + len))
1944 static void warn_sysctl_write(struct ctl_table *table)
1946 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1947 "This will not be supported in the future. To silence this\n"
1948 "warning, set kernel.sysctl_writes_strict = -1\n",
1949 current->comm, table->procname);
1953 * proc_dostring - read a string sysctl
1954 * @table: the sysctl table
1955 * @write: %TRUE if this is a write to the sysctl file
1956 * @buffer: the user buffer
1957 * @lenp: the size of the user buffer
1958 * @ppos: file position
1960 * Reads/writes a string from/to the user buffer. If the kernel
1961 * buffer provided is not large enough to hold the string, the
1962 * string is truncated. The copied string is %NULL-terminated.
1963 * If the string is being read by the user process, it is copied
1964 * and a newline '\n' is added. It is truncated if the buffer is
1967 * Returns 0 on success.
1969 int proc_dostring(struct ctl_table *table, int write,
1970 void __user *buffer, size_t *lenp, loff_t *ppos)
1972 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1973 warn_sysctl_write(table);
1975 return _proc_do_string((char *)(table->data), table->maxlen, write,
1976 (char __user *)buffer, lenp, ppos);
1979 static size_t proc_skip_spaces(char **buf)
1982 char *tmp = skip_spaces(*buf);
1988 static void proc_skip_char(char **buf, size_t *size, const char v)
1998 #define TMPBUFLEN 22
2000 * proc_get_long - reads an ASCII formatted integer from a user buffer
2002 * @buf: a kernel buffer
2003 * @size: size of the kernel buffer
2004 * @val: this is where the number will be stored
2005 * @neg: set to %TRUE if number is negative
2006 * @perm_tr: a vector which contains the allowed trailers
2007 * @perm_tr_len: size of the perm_tr vector
2008 * @tr: pointer to store the trailer character
2010 * In case of success %0 is returned and @buf and @size are updated with
2011 * the amount of bytes read. If @tr is non-NULL and a trailing
2012 * character exists (size is non-zero after returning from this
2013 * function), @tr is updated with the trailing character.
2015 static int proc_get_long(char **buf, size_t *size,
2016 unsigned long *val, bool *neg,
2017 const char *perm_tr, unsigned perm_tr_len, char *tr)
2020 char *p, tmp[TMPBUFLEN];
2026 if (len > TMPBUFLEN - 1)
2027 len = TMPBUFLEN - 1;
2029 memcpy(tmp, *buf, len);
2033 if (*p == '-' && *size > 1) {
2041 *val = simple_strtoul(p, &p, 0);
2045 /* We don't know if the next char is whitespace thus we may accept
2046 * invalid integers (e.g. 1234...a) or two integers instead of one
2047 * (e.g. 123...1). So lets not allow such large numbers. */
2048 if (len == TMPBUFLEN - 1)
2051 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2054 if (tr && (len < *size))
2064 * proc_put_long - converts an integer to a decimal ASCII formatted string
2066 * @buf: the user buffer
2067 * @size: the size of the user buffer
2068 * @val: the integer to be converted
2069 * @neg: sign of the number, %TRUE for negative
2071 * In case of success %0 is returned and @buf and @size are updated with
2072 * the amount of bytes written.
2074 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2078 char tmp[TMPBUFLEN], *p = tmp;
2080 sprintf(p, "%s%lu", neg ? "-" : "", val);
2084 if (copy_to_user(*buf, tmp, len))
2092 static int proc_put_char(void __user **buf, size_t *size, char c)
2095 char __user **buffer = (char __user **)buf;
2096 if (put_user(c, *buffer))
2098 (*size)--, (*buffer)++;
2104 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2106 int write, void *data)
2110 if (*lvalp > (unsigned long) INT_MAX + 1)
2114 if (*lvalp > (unsigned long) INT_MAX)
2122 *lvalp = -(unsigned long)val;
2125 *lvalp = (unsigned long)val;
2131 static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2133 int write, void *data)
2138 if (*lvalp > UINT_MAX)
2142 unsigned int val = *valp;
2144 *lvalp = (unsigned long)val;
2149 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2151 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2152 int write, void __user *buffer,
2153 size_t *lenp, loff_t *ppos,
2154 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2155 int write, void *data),
2158 int *i, vleft, first = 1, err = 0;
2160 char *kbuf = NULL, *p;
2162 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2167 i = (int *) tbl_data;
2168 vleft = table->maxlen / sizeof(*i);
2172 conv = do_proc_dointvec_conv;
2176 switch (sysctl_writes_strict) {
2177 case SYSCTL_WRITES_STRICT:
2179 case SYSCTL_WRITES_WARN:
2180 warn_sysctl_write(table);
2187 if (left > PAGE_SIZE - 1)
2188 left = PAGE_SIZE - 1;
2189 p = kbuf = memdup_user_nul(buffer, left);
2191 return PTR_ERR(kbuf);
2194 for (; left && vleft--; i++, first=0) {
2199 left -= proc_skip_spaces(&p);
2203 err = proc_get_long(&p, &left, &lval, &neg,
2205 sizeof(proc_wspace_sep), NULL);
2208 if (conv(&neg, &lval, i, 1, data)) {
2213 if (conv(&neg, &lval, i, 0, data)) {
2218 err = proc_put_char(&buffer, &left, '\t');
2221 err = proc_put_long(&buffer, &left, lval, neg);
2227 if (!write && !first && left && !err)
2228 err = proc_put_char(&buffer, &left, '\n');
2229 if (write && !err && left)
2230 left -= proc_skip_spaces(&p);
2234 return err ? : -EINVAL;
2242 static int do_proc_dointvec(struct ctl_table *table, int write,
2243 void __user *buffer, size_t *lenp, loff_t *ppos,
2244 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2245 int write, void *data),
2248 return __do_proc_dointvec(table->data, table, write,
2249 buffer, lenp, ppos, conv, data);
2253 * proc_dointvec - read a vector of integers
2254 * @table: the sysctl table
2255 * @write: %TRUE if this is a write to the sysctl file
2256 * @buffer: the user buffer
2257 * @lenp: the size of the user buffer
2258 * @ppos: file position
2260 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2261 * values from/to the user buffer, treated as an ASCII string.
2263 * Returns 0 on success.
2265 int proc_dointvec(struct ctl_table *table, int write,
2266 void __user *buffer, size_t *lenp, loff_t *ppos)
2268 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2272 * proc_douintvec - read a vector of unsigned integers
2273 * @table: the sysctl table
2274 * @write: %TRUE if this is a write to the sysctl file
2275 * @buffer: the user buffer
2276 * @lenp: the size of the user buffer
2277 * @ppos: file position
2279 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2280 * values from/to the user buffer, treated as an ASCII string.
2282 * Returns 0 on success.
2284 int proc_douintvec(struct ctl_table *table, int write,
2285 void __user *buffer, size_t *lenp, loff_t *ppos)
2287 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2288 do_proc_douintvec_conv, NULL);
2292 * Taint values can only be increased
2293 * This means we can safely use a temporary.
2295 static int proc_taint(struct ctl_table *table, int write,
2296 void __user *buffer, size_t *lenp, loff_t *ppos)
2299 unsigned long tmptaint = get_taint();
2302 if (write && !capable(CAP_SYS_ADMIN))
2307 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2313 * Poor man's atomic or. Not worth adding a primitive
2314 * to everyone's atomic.h for this
2317 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2318 if ((tmptaint >> i) & 1)
2319 add_taint(i, LOCKDEP_STILL_OK);
2326 #ifdef CONFIG_PRINTK
2327 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2328 void __user *buffer, size_t *lenp, loff_t *ppos)
2330 if (write && !capable(CAP_SYS_ADMIN))
2333 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2337 struct do_proc_dointvec_minmax_conv_param {
2342 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2344 int write, void *data)
2346 struct do_proc_dointvec_minmax_conv_param *param = data;
2348 int val = *negp ? -*lvalp : *lvalp;
2349 if ((param->min && *param->min > val) ||
2350 (param->max && *param->max < val))
2357 *lvalp = -(unsigned long)val;
2360 *lvalp = (unsigned long)val;
2367 * proc_dointvec_minmax - read a vector of integers with min/max values
2368 * @table: the sysctl table
2369 * @write: %TRUE if this is a write to the sysctl file
2370 * @buffer: the user buffer
2371 * @lenp: the size of the user buffer
2372 * @ppos: file position
2374 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2375 * values from/to the user buffer, treated as an ASCII string.
2377 * This routine will ensure the values are within the range specified by
2378 * table->extra1 (min) and table->extra2 (max).
2380 * Returns 0 on success.
2382 int proc_dointvec_minmax(struct ctl_table *table, int write,
2383 void __user *buffer, size_t *lenp, loff_t *ppos)
2385 struct do_proc_dointvec_minmax_conv_param param = {
2386 .min = (int *) table->extra1,
2387 .max = (int *) table->extra2,
2389 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2390 do_proc_dointvec_minmax_conv, ¶m);
2393 static void validate_coredump_safety(void)
2395 #ifdef CONFIG_COREDUMP
2396 if (suid_dumpable == SUID_DUMP_ROOT &&
2397 core_pattern[0] != '/' && core_pattern[0] != '|') {
2399 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2400 "Pipe handler or fully qualified core dump path required.\n"
2401 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2407 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2408 void __user *buffer, size_t *lenp, loff_t *ppos)
2410 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2412 validate_coredump_safety();
2416 #ifdef CONFIG_COREDUMP
2417 static int proc_dostring_coredump(struct ctl_table *table, int write,
2418 void __user *buffer, size_t *lenp, loff_t *ppos)
2420 int error = proc_dostring(table, write, buffer, lenp, ppos);
2422 validate_coredump_safety();
2427 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2428 void __user *buffer,
2429 size_t *lenp, loff_t *ppos,
2430 unsigned long convmul,
2431 unsigned long convdiv)
2433 unsigned long *i, *min, *max;
2434 int vleft, first = 1, err = 0;
2436 char *kbuf = NULL, *p;
2438 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2443 i = (unsigned long *) data;
2444 min = (unsigned long *) table->extra1;
2445 max = (unsigned long *) table->extra2;
2446 vleft = table->maxlen / sizeof(unsigned long);
2451 switch (sysctl_writes_strict) {
2452 case SYSCTL_WRITES_STRICT:
2454 case SYSCTL_WRITES_WARN:
2455 warn_sysctl_write(table);
2462 if (left > PAGE_SIZE - 1)
2463 left = PAGE_SIZE - 1;
2464 p = kbuf = memdup_user_nul(buffer, left);
2466 return PTR_ERR(kbuf);
2469 for (; left && vleft--; i++, first = 0) {
2475 left -= proc_skip_spaces(&p);
2477 err = proc_get_long(&p, &left, &val, &neg,
2479 sizeof(proc_wspace_sep), NULL);
2484 val = convmul * val / convdiv;
2485 if ((min && val < *min) || (max && val > *max))
2489 val = convdiv * (*i) / convmul;
2491 err = proc_put_char(&buffer, &left, '\t');
2495 err = proc_put_long(&buffer, &left, val, false);
2501 if (!write && !first && left && !err)
2502 err = proc_put_char(&buffer, &left, '\n');
2504 left -= proc_skip_spaces(&p);
2508 return err ? : -EINVAL;
2516 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2517 void __user *buffer,
2518 size_t *lenp, loff_t *ppos,
2519 unsigned long convmul,
2520 unsigned long convdiv)
2522 return __do_proc_doulongvec_minmax(table->data, table, write,
2523 buffer, lenp, ppos, convmul, convdiv);
2527 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2528 * @table: the sysctl table
2529 * @write: %TRUE if this is a write to the sysctl file
2530 * @buffer: the user buffer
2531 * @lenp: the size of the user buffer
2532 * @ppos: file position
2534 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2535 * values from/to the user buffer, treated as an ASCII string.
2537 * This routine will ensure the values are within the range specified by
2538 * table->extra1 (min) and table->extra2 (max).
2540 * Returns 0 on success.
2542 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2543 void __user *buffer, size_t *lenp, loff_t *ppos)
2545 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2549 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2550 * @table: the sysctl table
2551 * @write: %TRUE if this is a write to the sysctl file
2552 * @buffer: the user buffer
2553 * @lenp: the size of the user buffer
2554 * @ppos: file position
2556 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2557 * values from/to the user buffer, treated as an ASCII string. The values
2558 * are treated as milliseconds, and converted to jiffies when they are stored.
2560 * This routine will ensure the values are within the range specified by
2561 * table->extra1 (min) and table->extra2 (max).
2563 * Returns 0 on success.
2565 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2566 void __user *buffer,
2567 size_t *lenp, loff_t *ppos)
2569 return do_proc_doulongvec_minmax(table, write, buffer,
2570 lenp, ppos, HZ, 1000l);
2574 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2576 int write, void *data)
2579 if (*lvalp > INT_MAX / HZ)
2581 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2587 lval = -(unsigned long)val;
2590 lval = (unsigned long)val;
2597 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2599 int write, void *data)
2602 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2604 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2610 lval = -(unsigned long)val;
2613 lval = (unsigned long)val;
2615 *lvalp = jiffies_to_clock_t(lval);
2620 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2622 int write, void *data)
2625 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2635 lval = -(unsigned long)val;
2638 lval = (unsigned long)val;
2640 *lvalp = jiffies_to_msecs(lval);
2646 * proc_dointvec_jiffies - read a vector of integers as seconds
2647 * @table: the sysctl table
2648 * @write: %TRUE if this is a write to the sysctl file
2649 * @buffer: the user buffer
2650 * @lenp: the size of the user buffer
2651 * @ppos: file position
2653 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2654 * values from/to the user buffer, treated as an ASCII string.
2655 * The values read are assumed to be in seconds, and are converted into
2658 * Returns 0 on success.
2660 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2661 void __user *buffer, size_t *lenp, loff_t *ppos)
2663 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2664 do_proc_dointvec_jiffies_conv,NULL);
2668 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2669 * @table: the sysctl table
2670 * @write: %TRUE if this is a write to the sysctl file
2671 * @buffer: the user buffer
2672 * @lenp: the size of the user buffer
2673 * @ppos: pointer to the file position
2675 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2676 * values from/to the user buffer, treated as an ASCII string.
2677 * The values read are assumed to be in 1/USER_HZ seconds, and
2678 * are converted into jiffies.
2680 * Returns 0 on success.
2682 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2683 void __user *buffer, size_t *lenp, loff_t *ppos)
2685 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2686 do_proc_dointvec_userhz_jiffies_conv,NULL);
2690 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2691 * @table: the sysctl table
2692 * @write: %TRUE if this is a write to the sysctl file
2693 * @buffer: the user buffer
2694 * @lenp: the size of the user buffer
2695 * @ppos: file position
2696 * @ppos: the current position in the file
2698 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2699 * values from/to the user buffer, treated as an ASCII string.
2700 * The values read are assumed to be in 1/1000 seconds, and
2701 * are converted into jiffies.
2703 * Returns 0 on success.
2705 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2706 void __user *buffer, size_t *lenp, loff_t *ppos)
2708 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2709 do_proc_dointvec_ms_jiffies_conv, NULL);
2712 static int proc_do_cad_pid(struct ctl_table *table, int write,
2713 void __user *buffer, size_t *lenp, loff_t *ppos)
2715 struct pid *new_pid;
2719 tmp = pid_vnr(cad_pid);
2721 r = __do_proc_dointvec(&tmp, table, write, buffer,
2722 lenp, ppos, NULL, NULL);
2726 new_pid = find_get_pid(tmp);
2730 put_pid(xchg(&cad_pid, new_pid));
2735 * proc_do_large_bitmap - read/write from/to a large bitmap
2736 * @table: the sysctl table
2737 * @write: %TRUE if this is a write to the sysctl file
2738 * @buffer: the user buffer
2739 * @lenp: the size of the user buffer
2740 * @ppos: file position
2742 * The bitmap is stored at table->data and the bitmap length (in bits)
2745 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2746 * large bitmaps may be represented in a compact manner. Writing into
2747 * the file will clear the bitmap then update it with the given input.
2749 * Returns 0 on success.
2751 int proc_do_large_bitmap(struct ctl_table *table, int write,
2752 void __user *buffer, size_t *lenp, loff_t *ppos)
2756 size_t left = *lenp;
2757 unsigned long bitmap_len = table->maxlen;
2758 unsigned long *bitmap = *(unsigned long **) table->data;
2759 unsigned long *tmp_bitmap = NULL;
2760 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2762 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2770 if (left > PAGE_SIZE - 1)
2771 left = PAGE_SIZE - 1;
2773 p = kbuf = memdup_user_nul(buffer, left);
2775 return PTR_ERR(kbuf);
2777 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2783 proc_skip_char(&p, &left, '\n');
2784 while (!err && left) {
2785 unsigned long val_a, val_b;
2788 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
2792 if (val_a >= bitmap_len || neg) {
2804 err = proc_get_long(&p, &left, &val_b,
2805 &neg, tr_b, sizeof(tr_b),
2809 if (val_b >= bitmap_len || neg ||
2820 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2822 proc_skip_char(&p, &left, '\n');
2826 unsigned long bit_a, bit_b = 0;
2829 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2830 if (bit_a >= bitmap_len)
2832 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2836 err = proc_put_char(&buffer, &left, ',');
2840 err = proc_put_long(&buffer, &left, bit_a, false);
2843 if (bit_a != bit_b) {
2844 err = proc_put_char(&buffer, &left, '-');
2847 err = proc_put_long(&buffer, &left, bit_b, false);
2855 err = proc_put_char(&buffer, &left, '\n');
2861 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2863 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2875 #else /* CONFIG_PROC_SYSCTL */
2877 int proc_dostring(struct ctl_table *table, int write,
2878 void __user *buffer, size_t *lenp, loff_t *ppos)
2883 int proc_dointvec(struct ctl_table *table, int write,
2884 void __user *buffer, size_t *lenp, loff_t *ppos)
2889 int proc_douintvec(struct ctl_table *table, int write,
2890 void __user *buffer, size_t *lenp, loff_t *ppos)
2895 int proc_dointvec_minmax(struct ctl_table *table, int write,
2896 void __user *buffer, size_t *lenp, loff_t *ppos)
2901 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2902 void __user *buffer, size_t *lenp, loff_t *ppos)
2907 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2908 void __user *buffer, size_t *lenp, loff_t *ppos)
2913 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2914 void __user *buffer, size_t *lenp, loff_t *ppos)
2919 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2920 void __user *buffer, size_t *lenp, loff_t *ppos)
2925 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2926 void __user *buffer,
2927 size_t *lenp, loff_t *ppos)
2933 #endif /* CONFIG_PROC_SYSCTL */
2936 * No sense putting this after each symbol definition, twice,
2937 * exception granted :-)
2939 EXPORT_SYMBOL(proc_dointvec);
2940 EXPORT_SYMBOL(proc_douintvec);
2941 EXPORT_SYMBOL(proc_dointvec_jiffies);
2942 EXPORT_SYMBOL(proc_dointvec_minmax);
2943 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2944 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2945 EXPORT_SYMBOL(proc_dostring);
2946 EXPORT_SYMBOL(proc_doulongvec_minmax);
2947 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);