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>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/kexec.h>
67 #include <asm/uaccess.h>
68 #include <asm/processor.h>
72 #include <asm/stacktrace.h>
76 #include <asm/setup.h>
78 #ifdef CONFIG_BSD_PROCESS_ACCT
79 #include <linux/acct.h>
81 #ifdef CONFIG_RT_MUTEXES
82 #include <linux/rtmutex.h>
84 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85 #include <linux/lockdep.h>
87 #ifdef CONFIG_CHR_DEV_SG
91 #ifdef CONFIG_LOCKUP_DETECTOR
92 #include <linux/nmi.h>
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
99 extern int max_threads;
100 extern int suid_dumpable;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid;
103 extern char core_pattern[];
104 extern unsigned int core_pipe_limit;
107 extern int extra_free_kbytes;
108 extern int pid_max_min, pid_max_max;
109 extern int percpu_pagelist_fraction;
110 extern int compat_log;
111 extern int latencytop_enabled;
112 extern 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;
131 static int ten_thousand = 10000;
134 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
135 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
137 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
138 static int maxolduid = 65535;
139 static int minolduid;
141 static int ngroups_max = NGROUPS_MAX;
142 static const int cap_last_cap = CAP_LAST_CAP;
144 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
145 #ifdef CONFIG_DETECT_HUNG_TASK
146 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
149 #ifdef CONFIG_INOTIFY_USER
150 #include <linux/inotify.h>
156 extern int pwrsw_enabled;
159 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
160 extern int unaligned_enabled;
164 extern int unaligned_dump_stack;
167 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168 extern int no_unaligned_warning;
171 #ifdef CONFIG_PROC_SYSCTL
173 #define SYSCTL_WRITES_LEGACY -1
174 #define SYSCTL_WRITES_WARN 0
175 #define SYSCTL_WRITES_STRICT 1
177 static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
179 static int proc_do_cad_pid(struct ctl_table *table, int write,
180 void __user *buffer, size_t *lenp, loff_t *ppos);
181 static int proc_taint(struct ctl_table *table, int write,
182 void __user *buffer, size_t *lenp, loff_t *ppos);
186 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
187 void __user *buffer, size_t *lenp, loff_t *ppos);
190 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
192 #ifdef CONFIG_COREDUMP
193 static int proc_dostring_coredump(struct ctl_table *table, int write,
194 void __user *buffer, size_t *lenp, loff_t *ppos);
197 #ifdef CONFIG_MAGIC_SYSRQ
198 /* Note: sysrq code uses it's own private copy */
199 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
201 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
202 void __user *buffer, size_t *lenp,
207 error = proc_dointvec(table, write, buffer, lenp, ppos);
212 sysrq_toggle_support(__sysrq_enabled);
219 static struct ctl_table kern_table[];
220 static struct ctl_table vm_table[];
221 static struct ctl_table fs_table[];
222 static struct ctl_table debug_table[];
223 static struct ctl_table dev_table[];
224 extern struct ctl_table random_table[];
226 extern struct ctl_table epoll_table[];
229 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
230 int sysctl_legacy_va_layout;
233 /* The default sysctl tables: */
235 static struct ctl_table sysctl_base_table[] = {
237 .procname = "kernel",
254 .child = debug_table,
264 #ifdef CONFIG_SCHED_DEBUG
265 static int min_sched_granularity_ns = 100000; /* 100 usecs */
266 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
267 static int min_wakeup_granularity_ns; /* 0 usecs */
268 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
270 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
271 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
272 #endif /* CONFIG_SMP */
273 #endif /* CONFIG_SCHED_DEBUG */
275 #ifdef CONFIG_COMPACTION
276 static int min_extfrag_threshold;
277 static int max_extfrag_threshold = 1000;
280 static struct ctl_table kern_table[] = {
282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = proc_dointvec,
288 #ifdef CONFIG_SCHED_DEBUG
290 .procname = "sched_min_granularity_ns",
291 .data = &sysctl_sched_min_granularity,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = sched_proc_update_handler,
295 .extra1 = &min_sched_granularity_ns,
296 .extra2 = &max_sched_granularity_ns,
299 .procname = "sched_latency_ns",
300 .data = &sysctl_sched_latency,
301 .maxlen = sizeof(unsigned int),
303 .proc_handler = sched_proc_update_handler,
304 .extra1 = &min_sched_granularity_ns,
305 .extra2 = &max_sched_granularity_ns,
308 .procname = "sched_wakeup_granularity_ns",
309 .data = &sysctl_sched_wakeup_granularity,
310 .maxlen = sizeof(unsigned int),
312 .proc_handler = sched_proc_update_handler,
313 .extra1 = &min_wakeup_granularity_ns,
314 .extra2 = &max_wakeup_granularity_ns,
318 .procname = "sched_tunable_scaling",
319 .data = &sysctl_sched_tunable_scaling,
320 .maxlen = sizeof(enum sched_tunable_scaling),
322 .proc_handler = sched_proc_update_handler,
323 .extra1 = &min_sched_tunable_scaling,
324 .extra2 = &max_sched_tunable_scaling,
327 .procname = "sched_migration_cost_ns",
328 .data = &sysctl_sched_migration_cost,
329 .maxlen = sizeof(unsigned int),
331 .proc_handler = proc_dointvec,
334 .procname = "sched_nr_migrate",
335 .data = &sysctl_sched_nr_migrate,
336 .maxlen = sizeof(unsigned int),
338 .proc_handler = proc_dointvec,
341 .procname = "sched_time_avg_ms",
342 .data = &sysctl_sched_time_avg,
343 .maxlen = sizeof(unsigned int),
345 .proc_handler = proc_dointvec,
348 .procname = "sched_shares_window_ns",
349 .data = &sysctl_sched_shares_window,
350 .maxlen = sizeof(unsigned int),
352 .proc_handler = proc_dointvec,
355 .procname = "timer_migration",
356 .data = &sysctl_timer_migration,
357 .maxlen = sizeof(unsigned int),
359 .proc_handler = proc_dointvec_minmax,
363 #endif /* CONFIG_SMP */
364 #ifdef CONFIG_NUMA_BALANCING
366 .procname = "numa_balancing_scan_delay_ms",
367 .data = &sysctl_numa_balancing_scan_delay,
368 .maxlen = sizeof(unsigned int),
370 .proc_handler = proc_dointvec,
373 .procname = "numa_balancing_scan_period_min_ms",
374 .data = &sysctl_numa_balancing_scan_period_min,
375 .maxlen = sizeof(unsigned int),
377 .proc_handler = proc_dointvec,
380 .procname = "numa_balancing_scan_period_max_ms",
381 .data = &sysctl_numa_balancing_scan_period_max,
382 .maxlen = sizeof(unsigned int),
384 .proc_handler = proc_dointvec,
387 .procname = "numa_balancing_scan_size_mb",
388 .data = &sysctl_numa_balancing_scan_size,
389 .maxlen = sizeof(unsigned int),
391 .proc_handler = proc_dointvec_minmax,
395 .procname = "numa_balancing",
396 .data = NULL, /* filled in by handler */
397 .maxlen = sizeof(unsigned int),
399 .proc_handler = sysctl_numa_balancing,
403 #endif /* CONFIG_NUMA_BALANCING */
404 #endif /* CONFIG_SCHED_DEBUG */
406 .procname = "sched_rt_period_us",
407 .data = &sysctl_sched_rt_period,
408 .maxlen = sizeof(unsigned int),
410 .proc_handler = sched_rt_handler,
413 .procname = "sched_rt_runtime_us",
414 .data = &sysctl_sched_rt_runtime,
415 .maxlen = sizeof(int),
417 .proc_handler = sched_rt_handler,
420 .procname = "sched_rr_timeslice_ms",
421 .data = &sched_rr_timeslice,
422 .maxlen = sizeof(int),
424 .proc_handler = sched_rr_handler,
426 #ifdef CONFIG_SCHED_AUTOGROUP
428 .procname = "sched_autogroup_enabled",
429 .data = &sysctl_sched_autogroup_enabled,
430 .maxlen = sizeof(unsigned int),
432 .proc_handler = proc_dointvec_minmax,
437 #ifdef CONFIG_CFS_BANDWIDTH
439 .procname = "sched_cfs_bandwidth_slice_us",
440 .data = &sysctl_sched_cfs_bandwidth_slice,
441 .maxlen = sizeof(unsigned int),
443 .proc_handler = proc_dointvec_minmax,
447 #ifdef CONFIG_PROVE_LOCKING
449 .procname = "prove_locking",
450 .data = &prove_locking,
451 .maxlen = sizeof(int),
453 .proc_handler = proc_dointvec,
456 #ifdef CONFIG_LOCK_STAT
458 .procname = "lock_stat",
460 .maxlen = sizeof(int),
462 .proc_handler = proc_dointvec,
467 .data = &panic_timeout,
468 .maxlen = sizeof(int),
470 .proc_handler = proc_dointvec,
472 #ifdef CONFIG_COREDUMP
474 .procname = "core_uses_pid",
475 .data = &core_uses_pid,
476 .maxlen = sizeof(int),
478 .proc_handler = proc_dointvec,
481 .procname = "core_pattern",
482 .data = core_pattern,
483 .maxlen = CORENAME_MAX_SIZE,
485 .proc_handler = proc_dostring_coredump,
488 .procname = "core_pipe_limit",
489 .data = &core_pipe_limit,
490 .maxlen = sizeof(unsigned int),
492 .proc_handler = proc_dointvec,
495 #ifdef CONFIG_PROC_SYSCTL
497 .procname = "tainted",
498 .maxlen = sizeof(long),
500 .proc_handler = proc_taint,
503 .procname = "sysctl_writes_strict",
504 .data = &sysctl_writes_strict,
505 .maxlen = sizeof(int),
507 .proc_handler = proc_dointvec_minmax,
512 #ifdef CONFIG_LATENCYTOP
514 .procname = "latencytop",
515 .data = &latencytop_enabled,
516 .maxlen = sizeof(int),
518 .proc_handler = proc_dointvec,
521 #ifdef CONFIG_BLK_DEV_INITRD
523 .procname = "real-root-dev",
524 .data = &real_root_dev,
525 .maxlen = sizeof(int),
527 .proc_handler = proc_dointvec,
531 .procname = "print-fatal-signals",
532 .data = &print_fatal_signals,
533 .maxlen = sizeof(int),
535 .proc_handler = proc_dointvec,
539 .procname = "reboot-cmd",
540 .data = reboot_command,
543 .proc_handler = proc_dostring,
546 .procname = "stop-a",
547 .data = &stop_a_enabled,
548 .maxlen = sizeof (int),
550 .proc_handler = proc_dointvec,
553 .procname = "scons-poweroff",
554 .data = &scons_pwroff,
555 .maxlen = sizeof (int),
557 .proc_handler = proc_dointvec,
560 #ifdef CONFIG_SPARC64
562 .procname = "tsb-ratio",
563 .data = &sysctl_tsb_ratio,
564 .maxlen = sizeof (int),
566 .proc_handler = proc_dointvec,
571 .procname = "soft-power",
572 .data = &pwrsw_enabled,
573 .maxlen = sizeof (int),
575 .proc_handler = proc_dointvec,
578 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
580 .procname = "unaligned-trap",
581 .data = &unaligned_enabled,
582 .maxlen = sizeof (int),
584 .proc_handler = proc_dointvec,
588 .procname = "ctrl-alt-del",
590 .maxlen = sizeof(int),
592 .proc_handler = proc_dointvec,
594 #ifdef CONFIG_FUNCTION_TRACER
596 .procname = "ftrace_enabled",
597 .data = &ftrace_enabled,
598 .maxlen = sizeof(int),
600 .proc_handler = ftrace_enable_sysctl,
603 #ifdef CONFIG_STACK_TRACER
605 .procname = "stack_tracer_enabled",
606 .data = &stack_tracer_enabled,
607 .maxlen = sizeof(int),
609 .proc_handler = stack_trace_sysctl,
612 #ifdef CONFIG_TRACING
614 .procname = "ftrace_dump_on_oops",
615 .data = &ftrace_dump_on_oops,
616 .maxlen = sizeof(int),
618 .proc_handler = proc_dointvec,
621 .procname = "traceoff_on_warning",
622 .data = &__disable_trace_on_warning,
623 .maxlen = sizeof(__disable_trace_on_warning),
625 .proc_handler = proc_dointvec,
628 .procname = "tracepoint_printk",
629 .data = &tracepoint_printk,
630 .maxlen = sizeof(tracepoint_printk),
632 .proc_handler = proc_dointvec,
637 .procname = "kexec_load_disabled",
638 .data = &kexec_load_disabled,
639 .maxlen = sizeof(int),
641 /* only handle a transition from default "0" to "1" */
642 .proc_handler = proc_dointvec_minmax,
647 #ifdef CONFIG_MODULES
649 .procname = "modprobe",
650 .data = &modprobe_path,
651 .maxlen = KMOD_PATH_LEN,
653 .proc_handler = proc_dostring,
656 .procname = "modules_disabled",
657 .data = &modules_disabled,
658 .maxlen = sizeof(int),
660 /* only handle a transition from default "0" to "1" */
661 .proc_handler = proc_dointvec_minmax,
666 #ifdef CONFIG_UEVENT_HELPER
668 .procname = "hotplug",
669 .data = &uevent_helper,
670 .maxlen = UEVENT_HELPER_PATH_LEN,
672 .proc_handler = proc_dostring,
675 #ifdef CONFIG_CHR_DEV_SG
677 .procname = "sg-big-buff",
678 .data = &sg_big_buff,
679 .maxlen = sizeof (int),
681 .proc_handler = proc_dointvec,
684 #ifdef CONFIG_BSD_PROCESS_ACCT
688 .maxlen = 3*sizeof(int),
690 .proc_handler = proc_dointvec,
693 #ifdef CONFIG_MAGIC_SYSRQ
696 .data = &__sysrq_enabled,
697 .maxlen = sizeof (int),
699 .proc_handler = sysrq_sysctl_handler,
702 #ifdef CONFIG_PROC_SYSCTL
704 .procname = "cad_pid",
706 .maxlen = sizeof (int),
708 .proc_handler = proc_do_cad_pid,
712 .procname = "threads-max",
713 .data = &max_threads,
714 .maxlen = sizeof(int),
716 .proc_handler = proc_dointvec,
719 .procname = "random",
721 .child = random_table,
724 .procname = "usermodehelper",
726 .child = usermodehelper_table,
729 .procname = "overflowuid",
730 .data = &overflowuid,
731 .maxlen = sizeof(int),
733 .proc_handler = proc_dointvec_minmax,
734 .extra1 = &minolduid,
735 .extra2 = &maxolduid,
738 .procname = "overflowgid",
739 .data = &overflowgid,
740 .maxlen = sizeof(int),
742 .proc_handler = proc_dointvec_minmax,
743 .extra1 = &minolduid,
744 .extra2 = &maxolduid,
747 #ifdef CONFIG_MATHEMU
749 .procname = "ieee_emulation_warnings",
750 .data = &sysctl_ieee_emulation_warnings,
751 .maxlen = sizeof(int),
753 .proc_handler = proc_dointvec,
757 .procname = "userprocess_debug",
758 .data = &show_unhandled_signals,
759 .maxlen = sizeof(int),
761 .proc_handler = proc_dointvec,
765 .procname = "pid_max",
767 .maxlen = sizeof (int),
769 .proc_handler = proc_dointvec_minmax,
770 .extra1 = &pid_max_min,
771 .extra2 = &pid_max_max,
774 .procname = "panic_on_oops",
775 .data = &panic_on_oops,
776 .maxlen = sizeof(int),
778 .proc_handler = proc_dointvec,
780 #if defined CONFIG_PRINTK
782 .procname = "printk",
783 .data = &console_loglevel,
784 .maxlen = 4*sizeof(int),
786 .proc_handler = proc_dointvec,
789 .procname = "printk_ratelimit",
790 .data = &printk_ratelimit_state.interval,
791 .maxlen = sizeof(int),
793 .proc_handler = proc_dointvec_jiffies,
796 .procname = "printk_ratelimit_burst",
797 .data = &printk_ratelimit_state.burst,
798 .maxlen = sizeof(int),
800 .proc_handler = proc_dointvec,
803 .procname = "printk_delay",
804 .data = &printk_delay_msec,
805 .maxlen = sizeof(int),
807 .proc_handler = proc_dointvec_minmax,
809 .extra2 = &ten_thousand,
812 .procname = "dmesg_restrict",
813 .data = &dmesg_restrict,
814 .maxlen = sizeof(int),
816 .proc_handler = proc_dointvec_minmax_sysadmin,
821 .procname = "kptr_restrict",
822 .data = &kptr_restrict,
823 .maxlen = sizeof(int),
825 .proc_handler = proc_dointvec_minmax_sysadmin,
831 .procname = "ngroups_max",
832 .data = &ngroups_max,
833 .maxlen = sizeof (int),
835 .proc_handler = proc_dointvec,
838 .procname = "cap_last_cap",
839 .data = (void *)&cap_last_cap,
840 .maxlen = sizeof(int),
842 .proc_handler = proc_dointvec,
844 #if defined(CONFIG_LOCKUP_DETECTOR)
846 .procname = "watchdog",
847 .data = &watchdog_user_enabled,
848 .maxlen = sizeof (int),
850 .proc_handler = proc_dowatchdog,
855 .procname = "watchdog_thresh",
856 .data = &watchdog_thresh,
857 .maxlen = sizeof(int),
859 .proc_handler = proc_dowatchdog,
864 .procname = "softlockup_panic",
865 .data = &softlockup_panic,
866 .maxlen = sizeof(int),
868 .proc_handler = proc_dointvec_minmax,
874 .procname = "softlockup_all_cpu_backtrace",
875 .data = &sysctl_softlockup_all_cpu_backtrace,
876 .maxlen = sizeof(int),
878 .proc_handler = proc_dointvec_minmax,
882 #endif /* CONFIG_SMP */
884 .procname = "nmi_watchdog",
885 .data = &watchdog_user_enabled,
886 .maxlen = sizeof (int),
888 .proc_handler = proc_dowatchdog,
893 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
895 .procname = "unknown_nmi_panic",
896 .data = &unknown_nmi_panic,
897 .maxlen = sizeof (int),
899 .proc_handler = proc_dointvec,
902 #if defined(CONFIG_X86)
904 .procname = "panic_on_unrecovered_nmi",
905 .data = &panic_on_unrecovered_nmi,
906 .maxlen = sizeof(int),
908 .proc_handler = proc_dointvec,
911 .procname = "panic_on_io_nmi",
912 .data = &panic_on_io_nmi,
913 .maxlen = sizeof(int),
915 .proc_handler = proc_dointvec,
917 #ifdef CONFIG_DEBUG_STACKOVERFLOW
919 .procname = "panic_on_stackoverflow",
920 .data = &sysctl_panic_on_stackoverflow,
921 .maxlen = sizeof(int),
923 .proc_handler = proc_dointvec,
927 .procname = "bootloader_type",
928 .data = &bootloader_type,
929 .maxlen = sizeof (int),
931 .proc_handler = proc_dointvec,
934 .procname = "bootloader_version",
935 .data = &bootloader_version,
936 .maxlen = sizeof (int),
938 .proc_handler = proc_dointvec,
941 .procname = "kstack_depth_to_print",
942 .data = &kstack_depth_to_print,
943 .maxlen = sizeof(int),
945 .proc_handler = proc_dointvec,
948 .procname = "io_delay_type",
949 .data = &io_delay_type,
950 .maxlen = sizeof(int),
952 .proc_handler = proc_dointvec,
955 #if defined(CONFIG_MMU)
957 .procname = "randomize_va_space",
958 .data = &randomize_va_space,
959 .maxlen = sizeof(int),
961 .proc_handler = proc_dointvec,
964 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
966 .procname = "spin_retry",
968 .maxlen = sizeof (int),
970 .proc_handler = proc_dointvec,
973 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
975 .procname = "acpi_video_flags",
976 .data = &acpi_realmode_flags,
977 .maxlen = sizeof (unsigned long),
979 .proc_handler = proc_doulongvec_minmax,
982 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
984 .procname = "ignore-unaligned-usertrap",
985 .data = &no_unaligned_warning,
986 .maxlen = sizeof (int),
988 .proc_handler = proc_dointvec,
993 .procname = "unaligned-dump-stack",
994 .data = &unaligned_dump_stack,
995 .maxlen = sizeof (int),
997 .proc_handler = proc_dointvec,
1000 #ifdef CONFIG_DETECT_HUNG_TASK
1002 .procname = "hung_task_panic",
1003 .data = &sysctl_hung_task_panic,
1004 .maxlen = sizeof(int),
1006 .proc_handler = proc_dointvec_minmax,
1011 .procname = "hung_task_check_count",
1012 .data = &sysctl_hung_task_check_count,
1013 .maxlen = sizeof(int),
1015 .proc_handler = proc_dointvec_minmax,
1019 .procname = "hung_task_timeout_secs",
1020 .data = &sysctl_hung_task_timeout_secs,
1021 .maxlen = sizeof(unsigned long),
1023 .proc_handler = proc_dohung_task_timeout_secs,
1024 .extra2 = &hung_task_timeout_max,
1027 .procname = "hung_task_warnings",
1028 .data = &sysctl_hung_task_warnings,
1029 .maxlen = sizeof(int),
1031 .proc_handler = proc_dointvec_minmax,
1035 #ifdef CONFIG_COMPAT
1037 .procname = "compat-log",
1038 .data = &compat_log,
1039 .maxlen = sizeof (int),
1041 .proc_handler = proc_dointvec,
1044 #ifdef CONFIG_RT_MUTEXES
1046 .procname = "max_lock_depth",
1047 .data = &max_lock_depth,
1048 .maxlen = sizeof(int),
1050 .proc_handler = proc_dointvec,
1054 .procname = "poweroff_cmd",
1055 .data = &poweroff_cmd,
1056 .maxlen = POWEROFF_CMD_PATH_LEN,
1058 .proc_handler = proc_dostring,
1064 .child = key_sysctls,
1067 #ifdef CONFIG_PERF_EVENTS
1069 * User-space scripts rely on the existence of this file
1070 * as a feature check for perf_events being enabled.
1072 * So it's an ABI, do not remove!
1075 .procname = "perf_event_paranoid",
1076 .data = &sysctl_perf_event_paranoid,
1077 .maxlen = sizeof(sysctl_perf_event_paranoid),
1079 .proc_handler = proc_dointvec,
1082 .procname = "perf_event_mlock_kb",
1083 .data = &sysctl_perf_event_mlock,
1084 .maxlen = sizeof(sysctl_perf_event_mlock),
1086 .proc_handler = proc_dointvec,
1089 .procname = "perf_event_max_sample_rate",
1090 .data = &sysctl_perf_event_sample_rate,
1091 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1093 .proc_handler = perf_proc_update_handler,
1097 .procname = "perf_cpu_time_max_percent",
1098 .data = &sysctl_perf_cpu_time_max_percent,
1099 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1101 .proc_handler = perf_cpu_time_max_percent_handler,
1103 .extra2 = &one_hundred,
1106 #ifdef CONFIG_KMEMCHECK
1108 .procname = "kmemcheck",
1109 .data = &kmemcheck_enabled,
1110 .maxlen = sizeof(int),
1112 .proc_handler = proc_dointvec,
1116 .procname = "panic_on_warn",
1117 .data = &panic_on_warn,
1118 .maxlen = sizeof(int),
1120 .proc_handler = proc_dointvec_minmax,
1127 static struct ctl_table vm_table[] = {
1129 .procname = "overcommit_memory",
1130 .data = &sysctl_overcommit_memory,
1131 .maxlen = sizeof(sysctl_overcommit_memory),
1133 .proc_handler = proc_dointvec_minmax,
1138 .procname = "panic_on_oom",
1139 .data = &sysctl_panic_on_oom,
1140 .maxlen = sizeof(sysctl_panic_on_oom),
1142 .proc_handler = proc_dointvec_minmax,
1147 .procname = "oom_kill_allocating_task",
1148 .data = &sysctl_oom_kill_allocating_task,
1149 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1151 .proc_handler = proc_dointvec,
1154 .procname = "oom_dump_tasks",
1155 .data = &sysctl_oom_dump_tasks,
1156 .maxlen = sizeof(sysctl_oom_dump_tasks),
1158 .proc_handler = proc_dointvec,
1161 .procname = "overcommit_ratio",
1162 .data = &sysctl_overcommit_ratio,
1163 .maxlen = sizeof(sysctl_overcommit_ratio),
1165 .proc_handler = overcommit_ratio_handler,
1168 .procname = "overcommit_kbytes",
1169 .data = &sysctl_overcommit_kbytes,
1170 .maxlen = sizeof(sysctl_overcommit_kbytes),
1172 .proc_handler = overcommit_kbytes_handler,
1175 .procname = "page-cluster",
1176 .data = &page_cluster,
1177 .maxlen = sizeof(int),
1179 .proc_handler = proc_dointvec_minmax,
1183 .procname = "dirty_background_ratio",
1184 .data = &dirty_background_ratio,
1185 .maxlen = sizeof(dirty_background_ratio),
1187 .proc_handler = dirty_background_ratio_handler,
1189 .extra2 = &one_hundred,
1192 .procname = "dirty_background_bytes",
1193 .data = &dirty_background_bytes,
1194 .maxlen = sizeof(dirty_background_bytes),
1196 .proc_handler = dirty_background_bytes_handler,
1200 .procname = "dirty_ratio",
1201 .data = &vm_dirty_ratio,
1202 .maxlen = sizeof(vm_dirty_ratio),
1204 .proc_handler = dirty_ratio_handler,
1206 .extra2 = &one_hundred,
1209 .procname = "dirty_bytes",
1210 .data = &vm_dirty_bytes,
1211 .maxlen = sizeof(vm_dirty_bytes),
1213 .proc_handler = dirty_bytes_handler,
1214 .extra1 = &dirty_bytes_min,
1217 .procname = "dirty_writeback_centisecs",
1218 .data = &dirty_writeback_interval,
1219 .maxlen = sizeof(dirty_writeback_interval),
1221 .proc_handler = dirty_writeback_centisecs_handler,
1224 .procname = "dirty_expire_centisecs",
1225 .data = &dirty_expire_interval,
1226 .maxlen = sizeof(dirty_expire_interval),
1228 .proc_handler = proc_dointvec_minmax,
1232 .procname = "dirtytime_expire_seconds",
1233 .data = &dirtytime_expire_interval,
1234 .maxlen = sizeof(dirty_expire_interval),
1236 .proc_handler = dirtytime_interval_handler,
1240 .procname = "nr_pdflush_threads",
1241 .mode = 0444 /* read-only */,
1242 .proc_handler = pdflush_proc_obsolete,
1245 .procname = "swappiness",
1246 .data = &vm_swappiness,
1247 .maxlen = sizeof(vm_swappiness),
1249 .proc_handler = proc_dointvec_minmax,
1251 .extra2 = &one_hundred,
1253 #ifdef CONFIG_HUGETLB_PAGE
1255 .procname = "nr_hugepages",
1257 .maxlen = sizeof(unsigned long),
1259 .proc_handler = hugetlb_sysctl_handler,
1263 .procname = "nr_hugepages_mempolicy",
1265 .maxlen = sizeof(unsigned long),
1267 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1271 .procname = "hugetlb_shm_group",
1272 .data = &sysctl_hugetlb_shm_group,
1273 .maxlen = sizeof(gid_t),
1275 .proc_handler = proc_dointvec,
1278 .procname = "hugepages_treat_as_movable",
1279 .data = &hugepages_treat_as_movable,
1280 .maxlen = sizeof(int),
1282 .proc_handler = proc_dointvec,
1285 .procname = "nr_overcommit_hugepages",
1287 .maxlen = sizeof(unsigned long),
1289 .proc_handler = hugetlb_overcommit_handler,
1293 .procname = "lowmem_reserve_ratio",
1294 .data = &sysctl_lowmem_reserve_ratio,
1295 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1297 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1300 .procname = "drop_caches",
1301 .data = &sysctl_drop_caches,
1302 .maxlen = sizeof(int),
1304 .proc_handler = drop_caches_sysctl_handler,
1308 #ifdef CONFIG_COMPACTION
1310 .procname = "compact_memory",
1311 .data = &sysctl_compact_memory,
1312 .maxlen = sizeof(int),
1314 .proc_handler = sysctl_compaction_handler,
1317 .procname = "extfrag_threshold",
1318 .data = &sysctl_extfrag_threshold,
1319 .maxlen = sizeof(int),
1321 .proc_handler = sysctl_extfrag_handler,
1322 .extra1 = &min_extfrag_threshold,
1323 .extra2 = &max_extfrag_threshold,
1326 #endif /* CONFIG_COMPACTION */
1328 .procname = "min_free_kbytes",
1329 .data = &min_free_kbytes,
1330 .maxlen = sizeof(min_free_kbytes),
1332 .proc_handler = min_free_kbytes_sysctl_handler,
1336 .procname = "extra_free_kbytes",
1337 .data = &extra_free_kbytes,
1338 .maxlen = sizeof(extra_free_kbytes),
1340 .proc_handler = min_free_kbytes_sysctl_handler,
1344 .procname = "percpu_pagelist_fraction",
1345 .data = &percpu_pagelist_fraction,
1346 .maxlen = sizeof(percpu_pagelist_fraction),
1348 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1353 .procname = "max_map_count",
1354 .data = &sysctl_max_map_count,
1355 .maxlen = sizeof(sysctl_max_map_count),
1357 .proc_handler = proc_dointvec_minmax,
1362 .procname = "nr_trim_pages",
1363 .data = &sysctl_nr_trim_pages,
1364 .maxlen = sizeof(sysctl_nr_trim_pages),
1366 .proc_handler = proc_dointvec_minmax,
1371 .procname = "laptop_mode",
1372 .data = &laptop_mode,
1373 .maxlen = sizeof(laptop_mode),
1375 .proc_handler = proc_dointvec_jiffies,
1378 .procname = "block_dump",
1379 .data = &block_dump,
1380 .maxlen = sizeof(block_dump),
1382 .proc_handler = proc_dointvec,
1386 .procname = "vfs_cache_pressure",
1387 .data = &sysctl_vfs_cache_pressure,
1388 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1390 .proc_handler = proc_dointvec,
1393 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1395 .procname = "legacy_va_layout",
1396 .data = &sysctl_legacy_va_layout,
1397 .maxlen = sizeof(sysctl_legacy_va_layout),
1399 .proc_handler = proc_dointvec,
1405 .procname = "zone_reclaim_mode",
1406 .data = &zone_reclaim_mode,
1407 .maxlen = sizeof(zone_reclaim_mode),
1409 .proc_handler = proc_dointvec,
1413 .procname = "min_unmapped_ratio",
1414 .data = &sysctl_min_unmapped_ratio,
1415 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1417 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1419 .extra2 = &one_hundred,
1422 .procname = "min_slab_ratio",
1423 .data = &sysctl_min_slab_ratio,
1424 .maxlen = sizeof(sysctl_min_slab_ratio),
1426 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1428 .extra2 = &one_hundred,
1433 .procname = "stat_interval",
1434 .data = &sysctl_stat_interval,
1435 .maxlen = sizeof(sysctl_stat_interval),
1437 .proc_handler = proc_dointvec_jiffies,
1442 .procname = "mmap_min_addr",
1443 .data = &dac_mmap_min_addr,
1444 .maxlen = sizeof(unsigned long),
1446 .proc_handler = mmap_min_addr_handler,
1451 .procname = "numa_zonelist_order",
1452 .data = &numa_zonelist_order,
1453 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1455 .proc_handler = numa_zonelist_order_handler,
1458 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1459 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1461 .procname = "vdso_enabled",
1462 #ifdef CONFIG_X86_32
1463 .data = &vdso32_enabled,
1464 .maxlen = sizeof(vdso32_enabled),
1466 .data = &vdso_enabled,
1467 .maxlen = sizeof(vdso_enabled),
1470 .proc_handler = proc_dointvec,
1474 #ifdef CONFIG_HIGHMEM
1476 .procname = "highmem_is_dirtyable",
1477 .data = &vm_highmem_is_dirtyable,
1478 .maxlen = sizeof(vm_highmem_is_dirtyable),
1480 .proc_handler = proc_dointvec_minmax,
1485 #ifdef CONFIG_MEMORY_FAILURE
1487 .procname = "memory_failure_early_kill",
1488 .data = &sysctl_memory_failure_early_kill,
1489 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1491 .proc_handler = proc_dointvec_minmax,
1496 .procname = "memory_failure_recovery",
1497 .data = &sysctl_memory_failure_recovery,
1498 .maxlen = sizeof(sysctl_memory_failure_recovery),
1500 .proc_handler = proc_dointvec_minmax,
1506 .procname = "user_reserve_kbytes",
1507 .data = &sysctl_user_reserve_kbytes,
1508 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1510 .proc_handler = proc_doulongvec_minmax,
1513 .procname = "admin_reserve_kbytes",
1514 .data = &sysctl_admin_reserve_kbytes,
1515 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1517 .proc_handler = proc_doulongvec_minmax,
1522 static struct ctl_table fs_table[] = {
1524 .procname = "inode-nr",
1525 .data = &inodes_stat,
1526 .maxlen = 2*sizeof(long),
1528 .proc_handler = proc_nr_inodes,
1531 .procname = "inode-state",
1532 .data = &inodes_stat,
1533 .maxlen = 7*sizeof(long),
1535 .proc_handler = proc_nr_inodes,
1538 .procname = "file-nr",
1539 .data = &files_stat,
1540 .maxlen = sizeof(files_stat),
1542 .proc_handler = proc_nr_files,
1545 .procname = "file-max",
1546 .data = &files_stat.max_files,
1547 .maxlen = sizeof(files_stat.max_files),
1549 .proc_handler = proc_doulongvec_minmax,
1552 .procname = "nr_open",
1553 .data = &sysctl_nr_open,
1554 .maxlen = sizeof(int),
1556 .proc_handler = proc_dointvec_minmax,
1557 .extra1 = &sysctl_nr_open_min,
1558 .extra2 = &sysctl_nr_open_max,
1561 .procname = "dentry-state",
1562 .data = &dentry_stat,
1563 .maxlen = 6*sizeof(long),
1565 .proc_handler = proc_nr_dentry,
1568 .procname = "overflowuid",
1569 .data = &fs_overflowuid,
1570 .maxlen = sizeof(int),
1572 .proc_handler = proc_dointvec_minmax,
1573 .extra1 = &minolduid,
1574 .extra2 = &maxolduid,
1577 .procname = "overflowgid",
1578 .data = &fs_overflowgid,
1579 .maxlen = sizeof(int),
1581 .proc_handler = proc_dointvec_minmax,
1582 .extra1 = &minolduid,
1583 .extra2 = &maxolduid,
1585 #ifdef CONFIG_FILE_LOCKING
1587 .procname = "leases-enable",
1588 .data = &leases_enable,
1589 .maxlen = sizeof(int),
1591 .proc_handler = proc_dointvec,
1594 #ifdef CONFIG_DNOTIFY
1596 .procname = "dir-notify-enable",
1597 .data = &dir_notify_enable,
1598 .maxlen = sizeof(int),
1600 .proc_handler = proc_dointvec,
1604 #ifdef CONFIG_FILE_LOCKING
1606 .procname = "lease-break-time",
1607 .data = &lease_break_time,
1608 .maxlen = sizeof(int),
1610 .proc_handler = proc_dointvec,
1615 .procname = "aio-nr",
1617 .maxlen = sizeof(aio_nr),
1619 .proc_handler = proc_doulongvec_minmax,
1622 .procname = "aio-max-nr",
1623 .data = &aio_max_nr,
1624 .maxlen = sizeof(aio_max_nr),
1626 .proc_handler = proc_doulongvec_minmax,
1628 #endif /* CONFIG_AIO */
1629 #ifdef CONFIG_INOTIFY_USER
1631 .procname = "inotify",
1633 .child = inotify_table,
1638 .procname = "epoll",
1640 .child = epoll_table,
1645 .procname = "protected_symlinks",
1646 .data = &sysctl_protected_symlinks,
1647 .maxlen = sizeof(int),
1649 .proc_handler = proc_dointvec_minmax,
1654 .procname = "protected_hardlinks",
1655 .data = &sysctl_protected_hardlinks,
1656 .maxlen = sizeof(int),
1658 .proc_handler = proc_dointvec_minmax,
1663 .procname = "suid_dumpable",
1664 .data = &suid_dumpable,
1665 .maxlen = sizeof(int),
1667 .proc_handler = proc_dointvec_minmax_coredump,
1671 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1673 .procname = "binfmt_misc",
1675 .child = sysctl_mount_point,
1679 .procname = "pipe-max-size",
1680 .data = &pipe_max_size,
1681 .maxlen = sizeof(int),
1683 .proc_handler = &pipe_proc_fn,
1684 .extra1 = &pipe_min_size,
1689 static struct ctl_table debug_table[] = {
1690 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1692 .procname = "exception-trace",
1693 .data = &show_unhandled_signals,
1694 .maxlen = sizeof(int),
1696 .proc_handler = proc_dointvec
1699 #if defined(CONFIG_OPTPROBES)
1701 .procname = "kprobes-optimization",
1702 .data = &sysctl_kprobes_optimization,
1703 .maxlen = sizeof(int),
1705 .proc_handler = proc_kprobes_optimization_handler,
1713 static struct ctl_table dev_table[] = {
1717 int __init sysctl_init(void)
1719 struct ctl_table_header *hdr;
1721 hdr = register_sysctl_table(sysctl_base_table);
1722 kmemleak_not_leak(hdr);
1726 #endif /* CONFIG_SYSCTL */
1732 #ifdef CONFIG_PROC_SYSCTL
1734 static int _proc_do_string(char *data, int maxlen, int write,
1735 char __user *buffer,
1736 size_t *lenp, loff_t *ppos)
1742 if (!data || !maxlen || !*lenp) {
1748 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1749 /* Only continue writes not past the end of buffer. */
1751 if (len > maxlen - 1)
1758 /* Start writing from beginning of buffer. */
1764 while ((p - buffer) < *lenp && len < maxlen - 1) {
1765 if (get_user(c, p++))
1767 if (c == 0 || c == '\n')
1788 if (copy_to_user(buffer, data, len))
1791 if (put_user('\n', buffer + len))
1801 static void warn_sysctl_write(struct ctl_table *table)
1803 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1804 "This will not be supported in the future. To silence this\n"
1805 "warning, set kernel.sysctl_writes_strict = -1\n",
1806 current->comm, table->procname);
1810 * proc_dostring - read a string sysctl
1811 * @table: the sysctl table
1812 * @write: %TRUE if this is a write to the sysctl file
1813 * @buffer: the user buffer
1814 * @lenp: the size of the user buffer
1815 * @ppos: file position
1817 * Reads/writes a string from/to the user buffer. If the kernel
1818 * buffer provided is not large enough to hold the string, the
1819 * string is truncated. The copied string is %NULL-terminated.
1820 * If the string is being read by the user process, it is copied
1821 * and a newline '\n' is added. It is truncated if the buffer is
1824 * Returns 0 on success.
1826 int proc_dostring(struct ctl_table *table, int write,
1827 void __user *buffer, size_t *lenp, loff_t *ppos)
1829 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1830 warn_sysctl_write(table);
1832 return _proc_do_string((char *)(table->data), table->maxlen, write,
1833 (char __user *)buffer, lenp, ppos);
1836 static size_t proc_skip_spaces(char **buf)
1839 char *tmp = skip_spaces(*buf);
1845 static void proc_skip_char(char **buf, size_t *size, const char v)
1855 #define TMPBUFLEN 22
1857 * proc_get_long - reads an ASCII formatted integer from a user buffer
1859 * @buf: a kernel buffer
1860 * @size: size of the kernel buffer
1861 * @val: this is where the number will be stored
1862 * @neg: set to %TRUE if number is negative
1863 * @perm_tr: a vector which contains the allowed trailers
1864 * @perm_tr_len: size of the perm_tr vector
1865 * @tr: pointer to store the trailer character
1867 * In case of success %0 is returned and @buf and @size are updated with
1868 * the amount of bytes read. If @tr is non-NULL and a trailing
1869 * character exists (size is non-zero after returning from this
1870 * function), @tr is updated with the trailing character.
1872 static int proc_get_long(char **buf, size_t *size,
1873 unsigned long *val, bool *neg,
1874 const char *perm_tr, unsigned perm_tr_len, char *tr)
1877 char *p, tmp[TMPBUFLEN];
1883 if (len > TMPBUFLEN - 1)
1884 len = TMPBUFLEN - 1;
1886 memcpy(tmp, *buf, len);
1890 if (*p == '-' && *size > 1) {
1898 *val = simple_strtoul(p, &p, 0);
1902 /* We don't know if the next char is whitespace thus we may accept
1903 * invalid integers (e.g. 1234...a) or two integers instead of one
1904 * (e.g. 123...1). So lets not allow such large numbers. */
1905 if (len == TMPBUFLEN - 1)
1908 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1911 if (tr && (len < *size))
1921 * proc_put_long - converts an integer to a decimal ASCII formatted string
1923 * @buf: the user buffer
1924 * @size: the size of the user buffer
1925 * @val: the integer to be converted
1926 * @neg: sign of the number, %TRUE for negative
1928 * In case of success %0 is returned and @buf and @size are updated with
1929 * the amount of bytes written.
1931 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1935 char tmp[TMPBUFLEN], *p = tmp;
1937 sprintf(p, "%s%lu", neg ? "-" : "", val);
1941 if (copy_to_user(*buf, tmp, len))
1949 static int proc_put_char(void __user **buf, size_t *size, char c)
1952 char __user **buffer = (char __user **)buf;
1953 if (put_user(c, *buffer))
1955 (*size)--, (*buffer)++;
1961 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1963 int write, void *data)
1966 *valp = *negp ? -*lvalp : *lvalp;
1971 *lvalp = (unsigned long)-val;
1974 *lvalp = (unsigned long)val;
1980 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1982 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1983 int write, void __user *buffer,
1984 size_t *lenp, loff_t *ppos,
1985 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1986 int write, void *data),
1989 int *i, vleft, first = 1, err = 0;
1990 unsigned long page = 0;
1994 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1999 i = (int *) tbl_data;
2000 vleft = table->maxlen / sizeof(*i);
2004 conv = do_proc_dointvec_conv;
2008 switch (sysctl_writes_strict) {
2009 case SYSCTL_WRITES_STRICT:
2011 case SYSCTL_WRITES_WARN:
2012 warn_sysctl_write(table);
2019 if (left > PAGE_SIZE - 1)
2020 left = PAGE_SIZE - 1;
2021 page = __get_free_page(GFP_TEMPORARY);
2022 kbuf = (char *) page;
2025 if (copy_from_user(kbuf, buffer, left)) {
2032 for (; left && vleft--; i++, first=0) {
2037 left -= proc_skip_spaces(&kbuf);
2041 err = proc_get_long(&kbuf, &left, &lval, &neg,
2043 sizeof(proc_wspace_sep), NULL);
2046 if (conv(&neg, &lval, i, 1, data)) {
2051 if (conv(&neg, &lval, i, 0, data)) {
2056 err = proc_put_char(&buffer, &left, '\t');
2059 err = proc_put_long(&buffer, &left, lval, neg);
2065 if (!write && !first && left && !err)
2066 err = proc_put_char(&buffer, &left, '\n');
2067 if (write && !err && left)
2068 left -= proc_skip_spaces(&kbuf);
2073 return err ? : -EINVAL;
2081 static int do_proc_dointvec(struct ctl_table *table, int write,
2082 void __user *buffer, size_t *lenp, loff_t *ppos,
2083 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2084 int write, void *data),
2087 return __do_proc_dointvec(table->data, table, write,
2088 buffer, lenp, ppos, conv, data);
2092 * proc_dointvec - read a vector of integers
2093 * @table: the sysctl table
2094 * @write: %TRUE if this is a write to the sysctl file
2095 * @buffer: the user buffer
2096 * @lenp: the size of the user buffer
2097 * @ppos: file position
2099 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2100 * values from/to the user buffer, treated as an ASCII string.
2102 * Returns 0 on success.
2104 int proc_dointvec(struct ctl_table *table, int write,
2105 void __user *buffer, size_t *lenp, loff_t *ppos)
2107 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2112 * Taint values can only be increased
2113 * This means we can safely use a temporary.
2115 static int proc_taint(struct ctl_table *table, int write,
2116 void __user *buffer, size_t *lenp, loff_t *ppos)
2119 unsigned long tmptaint = get_taint();
2122 if (write && !capable(CAP_SYS_ADMIN))
2127 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2133 * Poor man's atomic or. Not worth adding a primitive
2134 * to everyone's atomic.h for this
2137 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2138 if ((tmptaint >> i) & 1)
2139 add_taint(i, LOCKDEP_STILL_OK);
2146 #ifdef CONFIG_PRINTK
2147 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2148 void __user *buffer, size_t *lenp, loff_t *ppos)
2150 if (write && !capable(CAP_SYS_ADMIN))
2153 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2157 struct do_proc_dointvec_minmax_conv_param {
2162 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2164 int write, void *data)
2166 struct do_proc_dointvec_minmax_conv_param *param = data;
2168 int val = *negp ? -*lvalp : *lvalp;
2169 if ((param->min && *param->min > val) ||
2170 (param->max && *param->max < val))
2177 *lvalp = (unsigned long)-val;
2180 *lvalp = (unsigned long)val;
2187 * proc_dointvec_minmax - read a vector of integers with min/max values
2188 * @table: the sysctl table
2189 * @write: %TRUE if this is a write to the sysctl file
2190 * @buffer: the user buffer
2191 * @lenp: the size of the user buffer
2192 * @ppos: file position
2194 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2195 * values from/to the user buffer, treated as an ASCII string.
2197 * This routine will ensure the values are within the range specified by
2198 * table->extra1 (min) and table->extra2 (max).
2200 * Returns 0 on success.
2202 int proc_dointvec_minmax(struct ctl_table *table, int write,
2203 void __user *buffer, size_t *lenp, loff_t *ppos)
2205 struct do_proc_dointvec_minmax_conv_param param = {
2206 .min = (int *) table->extra1,
2207 .max = (int *) table->extra2,
2209 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2210 do_proc_dointvec_minmax_conv, ¶m);
2213 static void validate_coredump_safety(void)
2215 #ifdef CONFIG_COREDUMP
2216 if (suid_dumpable == SUID_DUMP_ROOT &&
2217 core_pattern[0] != '/' && core_pattern[0] != '|') {
2218 printk(KERN_WARNING "Unsafe core_pattern used with "\
2219 "suid_dumpable=2. Pipe handler or fully qualified "\
2220 "core dump path required.\n");
2225 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2226 void __user *buffer, size_t *lenp, loff_t *ppos)
2228 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2230 validate_coredump_safety();
2234 #ifdef CONFIG_COREDUMP
2235 static int proc_dostring_coredump(struct ctl_table *table, int write,
2236 void __user *buffer, size_t *lenp, loff_t *ppos)
2238 int error = proc_dostring(table, write, buffer, lenp, ppos);
2240 validate_coredump_safety();
2245 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2246 void __user *buffer,
2247 size_t *lenp, loff_t *ppos,
2248 unsigned long convmul,
2249 unsigned long convdiv)
2251 unsigned long *i, *min, *max;
2252 int vleft, first = 1, err = 0;
2253 unsigned long page = 0;
2257 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2262 i = (unsigned long *) data;
2263 min = (unsigned long *) table->extra1;
2264 max = (unsigned long *) table->extra2;
2265 vleft = table->maxlen / sizeof(unsigned long);
2270 switch (sysctl_writes_strict) {
2271 case SYSCTL_WRITES_STRICT:
2273 case SYSCTL_WRITES_WARN:
2274 warn_sysctl_write(table);
2281 if (left > PAGE_SIZE - 1)
2282 left = PAGE_SIZE - 1;
2283 page = __get_free_page(GFP_TEMPORARY);
2284 kbuf = (char *) page;
2287 if (copy_from_user(kbuf, buffer, left)) {
2294 for (; left && vleft--; i++, first = 0) {
2300 left -= proc_skip_spaces(&kbuf);
2302 err = proc_get_long(&kbuf, &left, &val, &neg,
2304 sizeof(proc_wspace_sep), NULL);
2309 if ((min && val < *min) || (max && val > *max))
2313 val = convdiv * (*i) / convmul;
2315 err = proc_put_char(&buffer, &left, '\t');
2319 err = proc_put_long(&buffer, &left, val, false);
2325 if (!write && !first && left && !err)
2326 err = proc_put_char(&buffer, &left, '\n');
2328 left -= proc_skip_spaces(&kbuf);
2333 return err ? : -EINVAL;
2341 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2342 void __user *buffer,
2343 size_t *lenp, loff_t *ppos,
2344 unsigned long convmul,
2345 unsigned long convdiv)
2347 return __do_proc_doulongvec_minmax(table->data, table, write,
2348 buffer, lenp, ppos, convmul, convdiv);
2352 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2353 * @table: the sysctl table
2354 * @write: %TRUE if this is a write to the sysctl file
2355 * @buffer: the user buffer
2356 * @lenp: the size of the user buffer
2357 * @ppos: file position
2359 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2360 * values from/to the user buffer, treated as an ASCII string.
2362 * This routine will ensure the values are within the range specified by
2363 * table->extra1 (min) and table->extra2 (max).
2365 * Returns 0 on success.
2367 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2368 void __user *buffer, size_t *lenp, loff_t *ppos)
2370 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2374 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2375 * @table: the sysctl table
2376 * @write: %TRUE if this is a write to the sysctl file
2377 * @buffer: the user buffer
2378 * @lenp: the size of the user buffer
2379 * @ppos: file position
2381 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2382 * values from/to the user buffer, treated as an ASCII string. The values
2383 * are treated as milliseconds, and converted to jiffies when they are stored.
2385 * This routine will ensure the values are within the range specified by
2386 * table->extra1 (min) and table->extra2 (max).
2388 * Returns 0 on success.
2390 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2391 void __user *buffer,
2392 size_t *lenp, loff_t *ppos)
2394 return do_proc_doulongvec_minmax(table, write, buffer,
2395 lenp, ppos, HZ, 1000l);
2399 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2401 int write, void *data)
2404 if (*lvalp > LONG_MAX / HZ)
2406 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2412 lval = (unsigned long)-val;
2415 lval = (unsigned long)val;
2422 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2424 int write, void *data)
2427 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2429 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2435 lval = (unsigned long)-val;
2438 lval = (unsigned long)val;
2440 *lvalp = jiffies_to_clock_t(lval);
2445 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2447 int write, void *data)
2450 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2460 lval = (unsigned long)-val;
2463 lval = (unsigned long)val;
2465 *lvalp = jiffies_to_msecs(lval);
2471 * proc_dointvec_jiffies - read a vector of integers as seconds
2472 * @table: the sysctl table
2473 * @write: %TRUE if this is a write to the sysctl file
2474 * @buffer: the user buffer
2475 * @lenp: the size of the user buffer
2476 * @ppos: file position
2478 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2479 * values from/to the user buffer, treated as an ASCII string.
2480 * The values read are assumed to be in seconds, and are converted into
2483 * Returns 0 on success.
2485 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2486 void __user *buffer, size_t *lenp, loff_t *ppos)
2488 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2489 do_proc_dointvec_jiffies_conv,NULL);
2493 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2494 * @table: the sysctl table
2495 * @write: %TRUE if this is a write to the sysctl file
2496 * @buffer: the user buffer
2497 * @lenp: the size of the user buffer
2498 * @ppos: pointer to the file position
2500 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2501 * values from/to the user buffer, treated as an ASCII string.
2502 * The values read are assumed to be in 1/USER_HZ seconds, and
2503 * are converted into jiffies.
2505 * Returns 0 on success.
2507 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2508 void __user *buffer, size_t *lenp, loff_t *ppos)
2510 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2511 do_proc_dointvec_userhz_jiffies_conv,NULL);
2515 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2516 * @table: the sysctl table
2517 * @write: %TRUE if this is a write to the sysctl file
2518 * @buffer: the user buffer
2519 * @lenp: the size of the user buffer
2520 * @ppos: file position
2521 * @ppos: the current position in the file
2523 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2524 * values from/to the user buffer, treated as an ASCII string.
2525 * The values read are assumed to be in 1/1000 seconds, and
2526 * are converted into jiffies.
2528 * Returns 0 on success.
2530 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2531 void __user *buffer, size_t *lenp, loff_t *ppos)
2533 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2534 do_proc_dointvec_ms_jiffies_conv, NULL);
2537 static int proc_do_cad_pid(struct ctl_table *table, int write,
2538 void __user *buffer, size_t *lenp, loff_t *ppos)
2540 struct pid *new_pid;
2544 tmp = pid_vnr(cad_pid);
2546 r = __do_proc_dointvec(&tmp, table, write, buffer,
2547 lenp, ppos, NULL, NULL);
2551 new_pid = find_get_pid(tmp);
2555 put_pid(xchg(&cad_pid, new_pid));
2560 * proc_do_large_bitmap - read/write from/to a large bitmap
2561 * @table: the sysctl table
2562 * @write: %TRUE if this is a write to the sysctl file
2563 * @buffer: the user buffer
2564 * @lenp: the size of the user buffer
2565 * @ppos: file position
2567 * The bitmap is stored at table->data and the bitmap length (in bits)
2570 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2571 * large bitmaps may be represented in a compact manner. Writing into
2572 * the file will clear the bitmap then update it with the given input.
2574 * Returns 0 on success.
2576 int proc_do_large_bitmap(struct ctl_table *table, int write,
2577 void __user *buffer, size_t *lenp, loff_t *ppos)
2581 size_t left = *lenp;
2582 unsigned long bitmap_len = table->maxlen;
2583 unsigned long *bitmap = *(unsigned long **) table->data;
2584 unsigned long *tmp_bitmap = NULL;
2585 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2587 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2593 unsigned long page = 0;
2596 if (left > PAGE_SIZE - 1)
2597 left = PAGE_SIZE - 1;
2599 page = __get_free_page(GFP_TEMPORARY);
2600 kbuf = (char *) page;
2603 if (copy_from_user(kbuf, buffer, left)) {
2609 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2615 proc_skip_char(&kbuf, &left, '\n');
2616 while (!err && left) {
2617 unsigned long val_a, val_b;
2620 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2624 if (val_a >= bitmap_len || neg) {
2636 err = proc_get_long(&kbuf, &left, &val_b,
2637 &neg, tr_b, sizeof(tr_b),
2641 if (val_b >= bitmap_len || neg ||
2652 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2654 proc_skip_char(&kbuf, &left, '\n');
2658 unsigned long bit_a, bit_b = 0;
2661 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2662 if (bit_a >= bitmap_len)
2664 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2668 err = proc_put_char(&buffer, &left, ',');
2672 err = proc_put_long(&buffer, &left, bit_a, false);
2675 if (bit_a != bit_b) {
2676 err = proc_put_char(&buffer, &left, '-');
2679 err = proc_put_long(&buffer, &left, bit_b, false);
2687 err = proc_put_char(&buffer, &left, '\n');
2693 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2695 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2707 #else /* CONFIG_PROC_SYSCTL */
2709 int proc_dostring(struct ctl_table *table, int write,
2710 void __user *buffer, size_t *lenp, loff_t *ppos)
2715 int proc_dointvec(struct ctl_table *table, int write,
2716 void __user *buffer, size_t *lenp, loff_t *ppos)
2721 int proc_dointvec_minmax(struct ctl_table *table, int write,
2722 void __user *buffer, size_t *lenp, loff_t *ppos)
2727 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2728 void __user *buffer, size_t *lenp, loff_t *ppos)
2733 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2734 void __user *buffer, size_t *lenp, loff_t *ppos)
2739 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2740 void __user *buffer, size_t *lenp, loff_t *ppos)
2745 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2746 void __user *buffer, size_t *lenp, loff_t *ppos)
2751 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2752 void __user *buffer,
2753 size_t *lenp, loff_t *ppos)
2759 #endif /* CONFIG_PROC_SYSCTL */
2762 * No sense putting this after each symbol definition, twice,
2763 * exception granted :-)
2765 EXPORT_SYMBOL(proc_dointvec);
2766 EXPORT_SYMBOL(proc_dointvec_jiffies);
2767 EXPORT_SYMBOL(proc_dointvec_minmax);
2768 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2769 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2770 EXPORT_SYMBOL(proc_dostring);
2771 EXPORT_SYMBOL(proc_doulongvec_minmax);
2772 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);