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>
65 #include <asm/uaccess.h>
66 #include <asm/processor.h>
70 #include <asm/stacktrace.h>
74 #include <asm/setup.h>
76 #ifdef CONFIG_BSD_PROCESS_ACCT
77 #include <linux/acct.h>
79 #ifdef CONFIG_RT_MUTEXES
80 #include <linux/rtmutex.h>
82 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
83 #include <linux/lockdep.h>
85 #ifdef CONFIG_CHR_DEV_SG
89 #ifdef CONFIG_LOCKUP_DETECTOR
90 #include <linux/nmi.h>
94 #if defined(CONFIG_SYSCTL)
96 /* External variables not in a header file. */
97 extern int sysctl_overcommit_memory;
98 extern int sysctl_overcommit_ratio;
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 min_free_kbytes;
108 extern int pid_max_min, pid_max_max;
109 extern int sysctl_drop_caches;
110 extern int percpu_pagelist_fraction;
111 extern int compat_log;
112 extern int latencytop_enabled;
113 extern int sysctl_nr_open_min, sysctl_nr_open_max;
115 extern int sysctl_nr_trim_pages;
118 extern int blk_iopoll_enabled;
121 /* Constants used for minimum and maximum */
122 #ifdef CONFIG_LOCKUP_DETECTOR
123 static int sixty = 60;
124 static int neg_one = -1;
128 static int __maybe_unused one = 1;
129 static int __maybe_unused two = 2;
130 static int __maybe_unused three = 3;
131 static unsigned long one_ul = 1;
132 static int one_hundred = 100;
134 static int ten_thousand = 10000;
137 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141 static int maxolduid = 65535;
142 static int minolduid;
143 static int min_percpu_pagelist_fract = 8;
145 static int ngroups_max = NGROUPS_MAX;
146 static const int cap_last_cap = CAP_LAST_CAP;
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
154 #ifdef CONFIG_SPARC64
155 extern int sysctl_tsb_ratio;
159 extern int pwrsw_enabled;
160 extern int unaligned_enabled;
164 extern int no_unaligned_warning;
165 extern int unaligned_dump_stack;
168 #ifdef CONFIG_PROC_SYSCTL
169 static int proc_do_cad_pid(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171 static int proc_taint(struct ctl_table *table, int write,
172 void __user *buffer, size_t *lenp, loff_t *ppos);
176 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
177 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
182 #ifdef CONFIG_COREDUMP
183 static int proc_dostring_coredump(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
187 #ifdef CONFIG_MAGIC_SYSRQ
188 /* Note: sysrq code uses it's own private copy */
189 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
191 static int sysrq_sysctl_handler(ctl_table *table, int write,
192 void __user *buffer, size_t *lenp,
197 error = proc_dointvec(table, write, buffer, lenp, ppos);
202 sysrq_toggle_support(__sysrq_enabled);
209 static struct ctl_table kern_table[];
210 static struct ctl_table vm_table[];
211 static struct ctl_table fs_table[];
212 static struct ctl_table debug_table[];
213 static struct ctl_table dev_table[];
214 extern struct ctl_table random_table[];
216 extern struct ctl_table epoll_table[];
219 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220 int sysctl_legacy_va_layout;
223 /* The default sysctl tables: */
225 static struct ctl_table sysctl_base_table[] = {
227 .procname = "kernel",
244 .child = debug_table,
254 #ifdef CONFIG_SCHED_DEBUG
255 static int min_sched_granularity_ns = 100000; /* 100 usecs */
256 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
257 static int min_wakeup_granularity_ns; /* 0 usecs */
258 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
259 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
260 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
263 #ifdef CONFIG_COMPACTION
264 static int min_extfrag_threshold;
265 static int max_extfrag_threshold = 1000;
268 static struct ctl_table kern_table[] = {
270 .procname = "sched_child_runs_first",
271 .data = &sysctl_sched_child_runs_first,
272 .maxlen = sizeof(unsigned int),
274 .proc_handler = proc_dointvec,
276 #ifdef CONFIG_SCHED_DEBUG
278 .procname = "sched_min_granularity_ns",
279 .data = &sysctl_sched_min_granularity,
280 .maxlen = sizeof(unsigned int),
282 .proc_handler = sched_proc_update_handler,
283 .extra1 = &min_sched_granularity_ns,
284 .extra2 = &max_sched_granularity_ns,
287 .procname = "sched_latency_ns",
288 .data = &sysctl_sched_latency,
289 .maxlen = sizeof(unsigned int),
291 .proc_handler = sched_proc_update_handler,
292 .extra1 = &min_sched_granularity_ns,
293 .extra2 = &max_sched_granularity_ns,
296 .procname = "sched_wakeup_granularity_ns",
297 .data = &sysctl_sched_wakeup_granularity,
298 .maxlen = sizeof(unsigned int),
300 .proc_handler = sched_proc_update_handler,
301 .extra1 = &min_wakeup_granularity_ns,
302 .extra2 = &max_wakeup_granularity_ns,
305 .procname = "sched_tunable_scaling",
306 .data = &sysctl_sched_tunable_scaling,
307 .maxlen = sizeof(enum sched_tunable_scaling),
309 .proc_handler = sched_proc_update_handler,
310 .extra1 = &min_sched_tunable_scaling,
311 .extra2 = &max_sched_tunable_scaling,
314 .procname = "sched_migration_cost_ns",
315 .data = &sysctl_sched_migration_cost,
316 .maxlen = sizeof(unsigned int),
318 .proc_handler = proc_dointvec,
321 .procname = "sched_nr_migrate",
322 .data = &sysctl_sched_nr_migrate,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = proc_dointvec,
328 .procname = "sched_time_avg_ms",
329 .data = &sysctl_sched_time_avg,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = proc_dointvec,
335 .procname = "sched_shares_window_ns",
336 .data = &sysctl_sched_shares_window,
337 .maxlen = sizeof(unsigned int),
339 .proc_handler = proc_dointvec,
342 .procname = "timer_migration",
343 .data = &sysctl_timer_migration,
344 .maxlen = sizeof(unsigned int),
346 .proc_handler = proc_dointvec_minmax,
352 .procname = "sched_rt_period_us",
353 .data = &sysctl_sched_rt_period,
354 .maxlen = sizeof(unsigned int),
356 .proc_handler = sched_rt_handler,
359 .procname = "sched_rt_runtime_us",
360 .data = &sysctl_sched_rt_runtime,
361 .maxlen = sizeof(int),
363 .proc_handler = sched_rt_handler,
365 #ifdef CONFIG_SCHED_AUTOGROUP
367 .procname = "sched_autogroup_enabled",
368 .data = &sysctl_sched_autogroup_enabled,
369 .maxlen = sizeof(unsigned int),
371 .proc_handler = proc_dointvec_minmax,
376 #ifdef CONFIG_CFS_BANDWIDTH
378 .procname = "sched_cfs_bandwidth_slice_us",
379 .data = &sysctl_sched_cfs_bandwidth_slice,
380 .maxlen = sizeof(unsigned int),
382 .proc_handler = proc_dointvec_minmax,
386 #ifdef CONFIG_PROVE_LOCKING
388 .procname = "prove_locking",
389 .data = &prove_locking,
390 .maxlen = sizeof(int),
392 .proc_handler = proc_dointvec,
395 #ifdef CONFIG_LOCK_STAT
397 .procname = "lock_stat",
399 .maxlen = sizeof(int),
401 .proc_handler = proc_dointvec,
406 .data = &panic_timeout,
407 .maxlen = sizeof(int),
409 .proc_handler = proc_dointvec,
411 #ifdef CONFIG_COREDUMP
413 .procname = "core_uses_pid",
414 .data = &core_uses_pid,
415 .maxlen = sizeof(int),
417 .proc_handler = proc_dointvec,
420 .procname = "core_pattern",
421 .data = core_pattern,
422 .maxlen = CORENAME_MAX_SIZE,
424 .proc_handler = proc_dostring_coredump,
427 .procname = "core_pipe_limit",
428 .data = &core_pipe_limit,
429 .maxlen = sizeof(unsigned int),
431 .proc_handler = proc_dointvec,
434 #ifdef CONFIG_PROC_SYSCTL
436 .procname = "tainted",
437 .maxlen = sizeof(long),
439 .proc_handler = proc_taint,
442 #ifdef CONFIG_LATENCYTOP
444 .procname = "latencytop",
445 .data = &latencytop_enabled,
446 .maxlen = sizeof(int),
448 .proc_handler = proc_dointvec,
451 #ifdef CONFIG_BLK_DEV_INITRD
453 .procname = "real-root-dev",
454 .data = &real_root_dev,
455 .maxlen = sizeof(int),
457 .proc_handler = proc_dointvec,
461 .procname = "print-fatal-signals",
462 .data = &print_fatal_signals,
463 .maxlen = sizeof(int),
465 .proc_handler = proc_dointvec,
469 .procname = "reboot-cmd",
470 .data = reboot_command,
473 .proc_handler = proc_dostring,
476 .procname = "stop-a",
477 .data = &stop_a_enabled,
478 .maxlen = sizeof (int),
480 .proc_handler = proc_dointvec,
483 .procname = "scons-poweroff",
484 .data = &scons_pwroff,
485 .maxlen = sizeof (int),
487 .proc_handler = proc_dointvec,
490 #ifdef CONFIG_SPARC64
492 .procname = "tsb-ratio",
493 .data = &sysctl_tsb_ratio,
494 .maxlen = sizeof (int),
496 .proc_handler = proc_dointvec,
501 .procname = "soft-power",
502 .data = &pwrsw_enabled,
503 .maxlen = sizeof (int),
505 .proc_handler = proc_dointvec,
508 .procname = "unaligned-trap",
509 .data = &unaligned_enabled,
510 .maxlen = sizeof (int),
512 .proc_handler = proc_dointvec,
516 .procname = "ctrl-alt-del",
518 .maxlen = sizeof(int),
520 .proc_handler = proc_dointvec,
522 #ifdef CONFIG_FUNCTION_TRACER
524 .procname = "ftrace_enabled",
525 .data = &ftrace_enabled,
526 .maxlen = sizeof(int),
528 .proc_handler = ftrace_enable_sysctl,
531 #ifdef CONFIG_STACK_TRACER
533 .procname = "stack_tracer_enabled",
534 .data = &stack_tracer_enabled,
535 .maxlen = sizeof(int),
537 .proc_handler = stack_trace_sysctl,
540 #ifdef CONFIG_TRACING
542 .procname = "ftrace_dump_on_oops",
543 .data = &ftrace_dump_on_oops,
544 .maxlen = sizeof(int),
546 .proc_handler = proc_dointvec,
549 #ifdef CONFIG_MODULES
551 .procname = "modprobe",
552 .data = &modprobe_path,
553 .maxlen = KMOD_PATH_LEN,
555 .proc_handler = proc_dostring,
558 .procname = "modules_disabled",
559 .data = &modules_disabled,
560 .maxlen = sizeof(int),
562 /* only handle a transition from default "0" to "1" */
563 .proc_handler = proc_dointvec_minmax,
568 #ifdef CONFIG_HOTPLUG
570 .procname = "hotplug",
571 .data = &uevent_helper,
572 .maxlen = UEVENT_HELPER_PATH_LEN,
574 .proc_handler = proc_dostring,
577 #ifdef CONFIG_CHR_DEV_SG
579 .procname = "sg-big-buff",
580 .data = &sg_big_buff,
581 .maxlen = sizeof (int),
583 .proc_handler = proc_dointvec,
586 #ifdef CONFIG_BSD_PROCESS_ACCT
590 .maxlen = 3*sizeof(int),
592 .proc_handler = proc_dointvec,
595 #ifdef CONFIG_MAGIC_SYSRQ
598 .data = &__sysrq_enabled,
599 .maxlen = sizeof (int),
601 .proc_handler = sysrq_sysctl_handler,
604 #ifdef CONFIG_PROC_SYSCTL
606 .procname = "cad_pid",
608 .maxlen = sizeof (int),
610 .proc_handler = proc_do_cad_pid,
614 .procname = "threads-max",
615 .data = &max_threads,
616 .maxlen = sizeof(int),
618 .proc_handler = proc_dointvec,
621 .procname = "random",
623 .child = random_table,
626 .procname = "usermodehelper",
628 .child = usermodehelper_table,
631 .procname = "overflowuid",
632 .data = &overflowuid,
633 .maxlen = sizeof(int),
635 .proc_handler = proc_dointvec_minmax,
636 .extra1 = &minolduid,
637 .extra2 = &maxolduid,
640 .procname = "overflowgid",
641 .data = &overflowgid,
642 .maxlen = sizeof(int),
644 .proc_handler = proc_dointvec_minmax,
645 .extra1 = &minolduid,
646 .extra2 = &maxolduid,
649 #ifdef CONFIG_MATHEMU
651 .procname = "ieee_emulation_warnings",
652 .data = &sysctl_ieee_emulation_warnings,
653 .maxlen = sizeof(int),
655 .proc_handler = proc_dointvec,
659 .procname = "userprocess_debug",
660 .data = &show_unhandled_signals,
661 .maxlen = sizeof(int),
663 .proc_handler = proc_dointvec,
667 .procname = "pid_max",
669 .maxlen = sizeof (int),
671 .proc_handler = proc_dointvec_minmax,
672 .extra1 = &pid_max_min,
673 .extra2 = &pid_max_max,
676 .procname = "panic_on_oops",
677 .data = &panic_on_oops,
678 .maxlen = sizeof(int),
680 .proc_handler = proc_dointvec,
682 #if defined CONFIG_PRINTK
684 .procname = "printk",
685 .data = &console_loglevel,
686 .maxlen = 4*sizeof(int),
688 .proc_handler = proc_dointvec,
691 .procname = "printk_ratelimit",
692 .data = &printk_ratelimit_state.interval,
693 .maxlen = sizeof(int),
695 .proc_handler = proc_dointvec_jiffies,
698 .procname = "printk_ratelimit_burst",
699 .data = &printk_ratelimit_state.burst,
700 .maxlen = sizeof(int),
702 .proc_handler = proc_dointvec,
705 .procname = "printk_delay",
706 .data = &printk_delay_msec,
707 .maxlen = sizeof(int),
709 .proc_handler = proc_dointvec_minmax,
711 .extra2 = &ten_thousand,
714 .procname = "dmesg_restrict",
715 .data = &dmesg_restrict,
716 .maxlen = sizeof(int),
718 .proc_handler = proc_dointvec_minmax_sysadmin,
723 .procname = "kptr_restrict",
724 .data = &kptr_restrict,
725 .maxlen = sizeof(int),
727 .proc_handler = proc_dointvec_minmax_sysadmin,
733 .procname = "ngroups_max",
734 .data = &ngroups_max,
735 .maxlen = sizeof (int),
737 .proc_handler = proc_dointvec,
740 .procname = "cap_last_cap",
741 .data = (void *)&cap_last_cap,
742 .maxlen = sizeof(int),
744 .proc_handler = proc_dointvec,
746 #if defined(CONFIG_LOCKUP_DETECTOR)
748 .procname = "watchdog",
749 .data = &watchdog_enabled,
750 .maxlen = sizeof (int),
752 .proc_handler = proc_dowatchdog,
757 .procname = "watchdog_thresh",
758 .data = &watchdog_thresh,
759 .maxlen = sizeof(int),
761 .proc_handler = proc_dowatchdog,
766 .procname = "softlockup_panic",
767 .data = &softlockup_panic,
768 .maxlen = sizeof(int),
770 .proc_handler = proc_dointvec_minmax,
775 .procname = "nmi_watchdog",
776 .data = &watchdog_enabled,
777 .maxlen = sizeof (int),
779 .proc_handler = proc_dowatchdog,
784 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
786 .procname = "unknown_nmi_panic",
787 .data = &unknown_nmi_panic,
788 .maxlen = sizeof (int),
790 .proc_handler = proc_dointvec,
793 #if defined(CONFIG_X86)
795 .procname = "panic_on_unrecovered_nmi",
796 .data = &panic_on_unrecovered_nmi,
797 .maxlen = sizeof(int),
799 .proc_handler = proc_dointvec,
802 .procname = "panic_on_io_nmi",
803 .data = &panic_on_io_nmi,
804 .maxlen = sizeof(int),
806 .proc_handler = proc_dointvec,
808 #ifdef CONFIG_DEBUG_STACKOVERFLOW
810 .procname = "panic_on_stackoverflow",
811 .data = &sysctl_panic_on_stackoverflow,
812 .maxlen = sizeof(int),
814 .proc_handler = proc_dointvec,
818 .procname = "bootloader_type",
819 .data = &bootloader_type,
820 .maxlen = sizeof (int),
822 .proc_handler = proc_dointvec,
825 .procname = "bootloader_version",
826 .data = &bootloader_version,
827 .maxlen = sizeof (int),
829 .proc_handler = proc_dointvec,
832 .procname = "kstack_depth_to_print",
833 .data = &kstack_depth_to_print,
834 .maxlen = sizeof(int),
836 .proc_handler = proc_dointvec,
839 .procname = "io_delay_type",
840 .data = &io_delay_type,
841 .maxlen = sizeof(int),
843 .proc_handler = proc_dointvec,
846 #if defined(CONFIG_MMU)
848 .procname = "randomize_va_space",
849 .data = &randomize_va_space,
850 .maxlen = sizeof(int),
852 .proc_handler = proc_dointvec,
855 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
857 .procname = "spin_retry",
859 .maxlen = sizeof (int),
861 .proc_handler = proc_dointvec,
864 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
866 .procname = "acpi_video_flags",
867 .data = &acpi_realmode_flags,
868 .maxlen = sizeof (unsigned long),
870 .proc_handler = proc_doulongvec_minmax,
875 .procname = "ignore-unaligned-usertrap",
876 .data = &no_unaligned_warning,
877 .maxlen = sizeof (int),
879 .proc_handler = proc_dointvec,
882 .procname = "unaligned-dump-stack",
883 .data = &unaligned_dump_stack,
884 .maxlen = sizeof (int),
886 .proc_handler = proc_dointvec,
889 #ifdef CONFIG_DETECT_HUNG_TASK
891 .procname = "hung_task_panic",
892 .data = &sysctl_hung_task_panic,
893 .maxlen = sizeof(int),
895 .proc_handler = proc_dointvec_minmax,
900 .procname = "hung_task_check_count",
901 .data = &sysctl_hung_task_check_count,
902 .maxlen = sizeof(unsigned long),
904 .proc_handler = proc_doulongvec_minmax,
907 .procname = "hung_task_timeout_secs",
908 .data = &sysctl_hung_task_timeout_secs,
909 .maxlen = sizeof(unsigned long),
911 .proc_handler = proc_dohung_task_timeout_secs,
914 .procname = "hung_task_warnings",
915 .data = &sysctl_hung_task_warnings,
916 .maxlen = sizeof(unsigned long),
918 .proc_handler = proc_doulongvec_minmax,
923 .procname = "compat-log",
925 .maxlen = sizeof (int),
927 .proc_handler = proc_dointvec,
930 #ifdef CONFIG_RT_MUTEXES
932 .procname = "max_lock_depth",
933 .data = &max_lock_depth,
934 .maxlen = sizeof(int),
936 .proc_handler = proc_dointvec,
940 .procname = "poweroff_cmd",
941 .data = &poweroff_cmd,
942 .maxlen = POWEROFF_CMD_PATH_LEN,
944 .proc_handler = proc_dostring,
950 .child = key_sysctls,
953 #ifdef CONFIG_RCU_TORTURE_TEST
955 .procname = "rcutorture_runnable",
956 .data = &rcutorture_runnable,
957 .maxlen = sizeof(int),
959 .proc_handler = proc_dointvec,
962 #ifdef CONFIG_PERF_EVENTS
964 * User-space scripts rely on the existence of this file
965 * as a feature check for perf_events being enabled.
967 * So it's an ABI, do not remove!
970 .procname = "perf_event_paranoid",
971 .data = &sysctl_perf_event_paranoid,
972 .maxlen = sizeof(sysctl_perf_event_paranoid),
974 .proc_handler = proc_dointvec,
977 .procname = "perf_event_mlock_kb",
978 .data = &sysctl_perf_event_mlock,
979 .maxlen = sizeof(sysctl_perf_event_mlock),
981 .proc_handler = proc_dointvec,
984 .procname = "perf_event_max_sample_rate",
985 .data = &sysctl_perf_event_sample_rate,
986 .maxlen = sizeof(sysctl_perf_event_sample_rate),
988 .proc_handler = perf_proc_update_handler,
991 #ifdef CONFIG_KMEMCHECK
993 .procname = "kmemcheck",
994 .data = &kmemcheck_enabled,
995 .maxlen = sizeof(int),
997 .proc_handler = proc_dointvec,
1002 .procname = "blk_iopoll",
1003 .data = &blk_iopoll_enabled,
1004 .maxlen = sizeof(int),
1006 .proc_handler = proc_dointvec,
1012 static struct ctl_table vm_table[] = {
1014 .procname = "overcommit_memory",
1015 .data = &sysctl_overcommit_memory,
1016 .maxlen = sizeof(sysctl_overcommit_memory),
1018 .proc_handler = proc_dointvec_minmax,
1023 .procname = "panic_on_oom",
1024 .data = &sysctl_panic_on_oom,
1025 .maxlen = sizeof(sysctl_panic_on_oom),
1027 .proc_handler = proc_dointvec_minmax,
1032 .procname = "oom_kill_allocating_task",
1033 .data = &sysctl_oom_kill_allocating_task,
1034 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1036 .proc_handler = proc_dointvec,
1039 .procname = "oom_dump_tasks",
1040 .data = &sysctl_oom_dump_tasks,
1041 .maxlen = sizeof(sysctl_oom_dump_tasks),
1043 .proc_handler = proc_dointvec,
1046 .procname = "overcommit_ratio",
1047 .data = &sysctl_overcommit_ratio,
1048 .maxlen = sizeof(sysctl_overcommit_ratio),
1050 .proc_handler = proc_dointvec,
1053 .procname = "page-cluster",
1054 .data = &page_cluster,
1055 .maxlen = sizeof(int),
1057 .proc_handler = proc_dointvec_minmax,
1061 .procname = "dirty_background_ratio",
1062 .data = &dirty_background_ratio,
1063 .maxlen = sizeof(dirty_background_ratio),
1065 .proc_handler = dirty_background_ratio_handler,
1067 .extra2 = &one_hundred,
1070 .procname = "dirty_background_bytes",
1071 .data = &dirty_background_bytes,
1072 .maxlen = sizeof(dirty_background_bytes),
1074 .proc_handler = dirty_background_bytes_handler,
1078 .procname = "dirty_ratio",
1079 .data = &vm_dirty_ratio,
1080 .maxlen = sizeof(vm_dirty_ratio),
1082 .proc_handler = dirty_ratio_handler,
1084 .extra2 = &one_hundred,
1087 .procname = "dirty_bytes",
1088 .data = &vm_dirty_bytes,
1089 .maxlen = sizeof(vm_dirty_bytes),
1091 .proc_handler = dirty_bytes_handler,
1092 .extra1 = &dirty_bytes_min,
1095 .procname = "dirty_writeback_centisecs",
1096 .data = &dirty_writeback_interval,
1097 .maxlen = sizeof(dirty_writeback_interval),
1099 .proc_handler = dirty_writeback_centisecs_handler,
1102 .procname = "dirty_expire_centisecs",
1103 .data = &dirty_expire_interval,
1104 .maxlen = sizeof(dirty_expire_interval),
1106 .proc_handler = proc_dointvec_minmax,
1110 .procname = "nr_pdflush_threads",
1111 .mode = 0444 /* read-only */,
1112 .proc_handler = pdflush_proc_obsolete,
1115 .procname = "swappiness",
1116 .data = &vm_swappiness,
1117 .maxlen = sizeof(vm_swappiness),
1119 .proc_handler = proc_dointvec_minmax,
1121 .extra2 = &one_hundred,
1123 #ifdef CONFIG_HUGETLB_PAGE
1125 .procname = "nr_hugepages",
1127 .maxlen = sizeof(unsigned long),
1129 .proc_handler = hugetlb_sysctl_handler,
1130 .extra1 = (void *)&hugetlb_zero,
1131 .extra2 = (void *)&hugetlb_infinity,
1135 .procname = "nr_hugepages_mempolicy",
1137 .maxlen = sizeof(unsigned long),
1139 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1140 .extra1 = (void *)&hugetlb_zero,
1141 .extra2 = (void *)&hugetlb_infinity,
1145 .procname = "hugetlb_shm_group",
1146 .data = &sysctl_hugetlb_shm_group,
1147 .maxlen = sizeof(gid_t),
1149 .proc_handler = proc_dointvec,
1152 .procname = "hugepages_treat_as_movable",
1153 .data = &hugepages_treat_as_movable,
1154 .maxlen = sizeof(int),
1156 .proc_handler = hugetlb_treat_movable_handler,
1159 .procname = "nr_overcommit_hugepages",
1161 .maxlen = sizeof(unsigned long),
1163 .proc_handler = hugetlb_overcommit_handler,
1164 .extra1 = (void *)&hugetlb_zero,
1165 .extra2 = (void *)&hugetlb_infinity,
1169 .procname = "lowmem_reserve_ratio",
1170 .data = &sysctl_lowmem_reserve_ratio,
1171 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1173 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1176 .procname = "drop_caches",
1177 .data = &sysctl_drop_caches,
1178 .maxlen = sizeof(int),
1180 .proc_handler = drop_caches_sysctl_handler,
1184 #ifdef CONFIG_COMPACTION
1186 .procname = "compact_memory",
1187 .data = &sysctl_compact_memory,
1188 .maxlen = sizeof(int),
1190 .proc_handler = sysctl_compaction_handler,
1193 .procname = "extfrag_threshold",
1194 .data = &sysctl_extfrag_threshold,
1195 .maxlen = sizeof(int),
1197 .proc_handler = sysctl_extfrag_handler,
1198 .extra1 = &min_extfrag_threshold,
1199 .extra2 = &max_extfrag_threshold,
1202 #endif /* CONFIG_COMPACTION */
1204 .procname = "min_free_kbytes",
1205 .data = &min_free_kbytes,
1206 .maxlen = sizeof(min_free_kbytes),
1208 .proc_handler = min_free_kbytes_sysctl_handler,
1212 .procname = "percpu_pagelist_fraction",
1213 .data = &percpu_pagelist_fraction,
1214 .maxlen = sizeof(percpu_pagelist_fraction),
1216 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1217 .extra1 = &min_percpu_pagelist_fract,
1221 .procname = "max_map_count",
1222 .data = &sysctl_max_map_count,
1223 .maxlen = sizeof(sysctl_max_map_count),
1225 .proc_handler = proc_dointvec_minmax,
1230 .procname = "nr_trim_pages",
1231 .data = &sysctl_nr_trim_pages,
1232 .maxlen = sizeof(sysctl_nr_trim_pages),
1234 .proc_handler = proc_dointvec_minmax,
1239 .procname = "laptop_mode",
1240 .data = &laptop_mode,
1241 .maxlen = sizeof(laptop_mode),
1243 .proc_handler = proc_dointvec_jiffies,
1246 .procname = "block_dump",
1247 .data = &block_dump,
1248 .maxlen = sizeof(block_dump),
1250 .proc_handler = proc_dointvec,
1254 .procname = "vfs_cache_pressure",
1255 .data = &sysctl_vfs_cache_pressure,
1256 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1258 .proc_handler = proc_dointvec,
1261 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1263 .procname = "legacy_va_layout",
1264 .data = &sysctl_legacy_va_layout,
1265 .maxlen = sizeof(sysctl_legacy_va_layout),
1267 .proc_handler = proc_dointvec,
1273 .procname = "zone_reclaim_mode",
1274 .data = &zone_reclaim_mode,
1275 .maxlen = sizeof(zone_reclaim_mode),
1277 .proc_handler = proc_dointvec,
1281 .procname = "min_unmapped_ratio",
1282 .data = &sysctl_min_unmapped_ratio,
1283 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1285 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1287 .extra2 = &one_hundred,
1290 .procname = "min_slab_ratio",
1291 .data = &sysctl_min_slab_ratio,
1292 .maxlen = sizeof(sysctl_min_slab_ratio),
1294 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1296 .extra2 = &one_hundred,
1301 .procname = "stat_interval",
1302 .data = &sysctl_stat_interval,
1303 .maxlen = sizeof(sysctl_stat_interval),
1305 .proc_handler = proc_dointvec_jiffies,
1310 .procname = "mmap_min_addr",
1311 .data = &dac_mmap_min_addr,
1312 .maxlen = sizeof(unsigned long),
1314 .proc_handler = mmap_min_addr_handler,
1319 .procname = "numa_zonelist_order",
1320 .data = &numa_zonelist_order,
1321 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1323 .proc_handler = numa_zonelist_order_handler,
1326 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1327 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1329 .procname = "vdso_enabled",
1330 .data = &vdso_enabled,
1331 .maxlen = sizeof(vdso_enabled),
1333 .proc_handler = proc_dointvec,
1337 #ifdef CONFIG_HIGHMEM
1339 .procname = "highmem_is_dirtyable",
1340 .data = &vm_highmem_is_dirtyable,
1341 .maxlen = sizeof(vm_highmem_is_dirtyable),
1343 .proc_handler = proc_dointvec_minmax,
1349 .procname = "scan_unevictable_pages",
1350 .data = &scan_unevictable_pages,
1351 .maxlen = sizeof(scan_unevictable_pages),
1353 .proc_handler = scan_unevictable_handler,
1355 #ifdef CONFIG_MEMORY_FAILURE
1357 .procname = "memory_failure_early_kill",
1358 .data = &sysctl_memory_failure_early_kill,
1359 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1361 .proc_handler = proc_dointvec_minmax,
1366 .procname = "memory_failure_recovery",
1367 .data = &sysctl_memory_failure_recovery,
1368 .maxlen = sizeof(sysctl_memory_failure_recovery),
1370 .proc_handler = proc_dointvec_minmax,
1378 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1379 static struct ctl_table binfmt_misc_table[] = {
1384 static struct ctl_table fs_table[] = {
1386 .procname = "inode-nr",
1387 .data = &inodes_stat,
1388 .maxlen = 2*sizeof(int),
1390 .proc_handler = proc_nr_inodes,
1393 .procname = "inode-state",
1394 .data = &inodes_stat,
1395 .maxlen = 7*sizeof(int),
1397 .proc_handler = proc_nr_inodes,
1400 .procname = "file-nr",
1401 .data = &files_stat,
1402 .maxlen = sizeof(files_stat),
1404 .proc_handler = proc_nr_files,
1407 .procname = "file-max",
1408 .data = &files_stat.max_files,
1409 .maxlen = sizeof(files_stat.max_files),
1411 .proc_handler = proc_doulongvec_minmax,
1414 .procname = "nr_open",
1415 .data = &sysctl_nr_open,
1416 .maxlen = sizeof(int),
1418 .proc_handler = proc_dointvec_minmax,
1419 .extra1 = &sysctl_nr_open_min,
1420 .extra2 = &sysctl_nr_open_max,
1423 .procname = "dentry-state",
1424 .data = &dentry_stat,
1425 .maxlen = 6*sizeof(int),
1427 .proc_handler = proc_nr_dentry,
1430 .procname = "overflowuid",
1431 .data = &fs_overflowuid,
1432 .maxlen = sizeof(int),
1434 .proc_handler = proc_dointvec_minmax,
1435 .extra1 = &minolduid,
1436 .extra2 = &maxolduid,
1439 .procname = "overflowgid",
1440 .data = &fs_overflowgid,
1441 .maxlen = sizeof(int),
1443 .proc_handler = proc_dointvec_minmax,
1444 .extra1 = &minolduid,
1445 .extra2 = &maxolduid,
1447 #ifdef CONFIG_FILE_LOCKING
1449 .procname = "leases-enable",
1450 .data = &leases_enable,
1451 .maxlen = sizeof(int),
1453 .proc_handler = proc_dointvec,
1456 #ifdef CONFIG_DNOTIFY
1458 .procname = "dir-notify-enable",
1459 .data = &dir_notify_enable,
1460 .maxlen = sizeof(int),
1462 .proc_handler = proc_dointvec,
1466 #ifdef CONFIG_FILE_LOCKING
1468 .procname = "lease-break-time",
1469 .data = &lease_break_time,
1470 .maxlen = sizeof(int),
1472 .proc_handler = proc_dointvec,
1477 .procname = "aio-nr",
1479 .maxlen = sizeof(aio_nr),
1481 .proc_handler = proc_doulongvec_minmax,
1484 .procname = "aio-max-nr",
1485 .data = &aio_max_nr,
1486 .maxlen = sizeof(aio_max_nr),
1488 .proc_handler = proc_doulongvec_minmax,
1490 #endif /* CONFIG_AIO */
1491 #ifdef CONFIG_INOTIFY_USER
1493 .procname = "inotify",
1495 .child = inotify_table,
1500 .procname = "epoll",
1502 .child = epoll_table,
1507 .procname = "protected_symlinks",
1508 .data = &sysctl_protected_symlinks,
1509 .maxlen = sizeof(int),
1511 .proc_handler = proc_dointvec_minmax,
1516 .procname = "protected_hardlinks",
1517 .data = &sysctl_protected_hardlinks,
1518 .maxlen = sizeof(int),
1520 .proc_handler = proc_dointvec_minmax,
1525 .procname = "suid_dumpable",
1526 .data = &suid_dumpable,
1527 .maxlen = sizeof(int),
1529 .proc_handler = proc_dointvec_minmax_coredump,
1533 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1535 .procname = "binfmt_misc",
1537 .child = binfmt_misc_table,
1541 .procname = "pipe-max-size",
1542 .data = &pipe_max_size,
1543 .maxlen = sizeof(int),
1545 .proc_handler = &pipe_proc_fn,
1546 .extra1 = &pipe_min_size,
1551 static struct ctl_table debug_table[] = {
1552 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1553 defined(CONFIG_S390) || defined(CONFIG_TILE) || defined(CONFIG_ARM64)
1555 .procname = "exception-trace",
1556 .data = &show_unhandled_signals,
1557 .maxlen = sizeof(int),
1559 .proc_handler = proc_dointvec
1562 #if defined(CONFIG_OPTPROBES)
1564 .procname = "kprobes-optimization",
1565 .data = &sysctl_kprobes_optimization,
1566 .maxlen = sizeof(int),
1568 .proc_handler = proc_kprobes_optimization_handler,
1576 static struct ctl_table dev_table[] = {
1580 int __init sysctl_init(void)
1582 struct ctl_table_header *hdr;
1584 hdr = register_sysctl_table(sysctl_base_table);
1585 kmemleak_not_leak(hdr);
1589 #endif /* CONFIG_SYSCTL */
1595 #ifdef CONFIG_PROC_SYSCTL
1597 static int _proc_do_string(void* data, int maxlen, int write,
1598 void __user *buffer,
1599 size_t *lenp, loff_t *ppos)
1605 if (!data || !maxlen || !*lenp) {
1613 while (len < *lenp) {
1614 if (get_user(c, p++))
1616 if (c == 0 || c == '\n')
1622 if(copy_from_user(data, buffer, len))
1624 ((char *) data)[len] = 0;
1642 if(copy_to_user(buffer, data, len))
1645 if(put_user('\n', ((char __user *) buffer) + len))
1656 * proc_dostring - read a string sysctl
1657 * @table: the sysctl table
1658 * @write: %TRUE if this is a write to the sysctl file
1659 * @buffer: the user buffer
1660 * @lenp: the size of the user buffer
1661 * @ppos: file position
1663 * Reads/writes a string from/to the user buffer. If the kernel
1664 * buffer provided is not large enough to hold the string, the
1665 * string is truncated. The copied string is %NULL-terminated.
1666 * If the string is being read by the user process, it is copied
1667 * and a newline '\n' is added. It is truncated if the buffer is
1670 * Returns 0 on success.
1672 int proc_dostring(struct ctl_table *table, int write,
1673 void __user *buffer, size_t *lenp, loff_t *ppos)
1675 return _proc_do_string(table->data, table->maxlen, write,
1676 buffer, lenp, ppos);
1679 static size_t proc_skip_spaces(char **buf)
1682 char *tmp = skip_spaces(*buf);
1688 static void proc_skip_char(char **buf, size_t *size, const char v)
1698 #define TMPBUFLEN 22
1700 * proc_get_long - reads an ASCII formatted integer from a user buffer
1702 * @buf: a kernel buffer
1703 * @size: size of the kernel buffer
1704 * @val: this is where the number will be stored
1705 * @neg: set to %TRUE if number is negative
1706 * @perm_tr: a vector which contains the allowed trailers
1707 * @perm_tr_len: size of the perm_tr vector
1708 * @tr: pointer to store the trailer character
1710 * In case of success %0 is returned and @buf and @size are updated with
1711 * the amount of bytes read. If @tr is non-NULL and a trailing
1712 * character exists (size is non-zero after returning from this
1713 * function), @tr is updated with the trailing character.
1715 static int proc_get_long(char **buf, size_t *size,
1716 unsigned long *val, bool *neg,
1717 const char *perm_tr, unsigned perm_tr_len, char *tr)
1720 char *p, tmp[TMPBUFLEN];
1726 if (len > TMPBUFLEN - 1)
1727 len = TMPBUFLEN - 1;
1729 memcpy(tmp, *buf, len);
1733 if (*p == '-' && *size > 1) {
1741 *val = simple_strtoul(p, &p, 0);
1745 /* We don't know if the next char is whitespace thus we may accept
1746 * invalid integers (e.g. 1234...a) or two integers instead of one
1747 * (e.g. 123...1). So lets not allow such large numbers. */
1748 if (len == TMPBUFLEN - 1)
1751 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1754 if (tr && (len < *size))
1764 * proc_put_long - converts an integer to a decimal ASCII formatted string
1766 * @buf: the user buffer
1767 * @size: the size of the user buffer
1768 * @val: the integer to be converted
1769 * @neg: sign of the number, %TRUE for negative
1771 * In case of success %0 is returned and @buf and @size are updated with
1772 * the amount of bytes written.
1774 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1778 char tmp[TMPBUFLEN], *p = tmp;
1780 sprintf(p, "%s%lu", neg ? "-" : "", val);
1784 if (copy_to_user(*buf, tmp, len))
1792 static int proc_put_char(void __user **buf, size_t *size, char c)
1795 char __user **buffer = (char __user **)buf;
1796 if (put_user(c, *buffer))
1798 (*size)--, (*buffer)++;
1804 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1806 int write, void *data)
1809 *valp = *negp ? -*lvalp : *lvalp;
1814 *lvalp = (unsigned long)-val;
1817 *lvalp = (unsigned long)val;
1823 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1825 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1826 int write, void __user *buffer,
1827 size_t *lenp, loff_t *ppos,
1828 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1829 int write, void *data),
1832 int *i, vleft, first = 1, err = 0;
1833 unsigned long page = 0;
1837 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1842 i = (int *) tbl_data;
1843 vleft = table->maxlen / sizeof(*i);
1847 conv = do_proc_dointvec_conv;
1850 if (left > PAGE_SIZE - 1)
1851 left = PAGE_SIZE - 1;
1852 page = __get_free_page(GFP_TEMPORARY);
1853 kbuf = (char *) page;
1856 if (copy_from_user(kbuf, buffer, left)) {
1863 for (; left && vleft--; i++, first=0) {
1868 left -= proc_skip_spaces(&kbuf);
1872 err = proc_get_long(&kbuf, &left, &lval, &neg,
1874 sizeof(proc_wspace_sep), NULL);
1877 if (conv(&neg, &lval, i, 1, data)) {
1882 if (conv(&neg, &lval, i, 0, data)) {
1887 err = proc_put_char(&buffer, &left, '\t');
1890 err = proc_put_long(&buffer, &left, lval, neg);
1896 if (!write && !first && left && !err)
1897 err = proc_put_char(&buffer, &left, '\n');
1898 if (write && !err && left)
1899 left -= proc_skip_spaces(&kbuf);
1904 return err ? : -EINVAL;
1911 static int do_proc_dointvec(struct ctl_table *table, int write,
1912 void __user *buffer, size_t *lenp, loff_t *ppos,
1913 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1914 int write, void *data),
1917 return __do_proc_dointvec(table->data, table, write,
1918 buffer, lenp, ppos, conv, data);
1922 * proc_dointvec - read a vector of integers
1923 * @table: the sysctl table
1924 * @write: %TRUE if this is a write to the sysctl file
1925 * @buffer: the user buffer
1926 * @lenp: the size of the user buffer
1927 * @ppos: file position
1929 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1930 * values from/to the user buffer, treated as an ASCII string.
1932 * Returns 0 on success.
1934 int proc_dointvec(struct ctl_table *table, int write,
1935 void __user *buffer, size_t *lenp, loff_t *ppos)
1937 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1942 * Taint values can only be increased
1943 * This means we can safely use a temporary.
1945 static int proc_taint(struct ctl_table *table, int write,
1946 void __user *buffer, size_t *lenp, loff_t *ppos)
1949 unsigned long tmptaint = get_taint();
1952 if (write && !capable(CAP_SYS_ADMIN))
1957 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
1963 * Poor man's atomic or. Not worth adding a primitive
1964 * to everyone's atomic.h for this
1967 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
1968 if ((tmptaint >> i) & 1)
1976 #ifdef CONFIG_PRINTK
1977 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
1978 void __user *buffer, size_t *lenp, loff_t *ppos)
1980 if (write && !capable(CAP_SYS_ADMIN))
1983 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1987 struct do_proc_dointvec_minmax_conv_param {
1992 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
1994 int write, void *data)
1996 struct do_proc_dointvec_minmax_conv_param *param = data;
1998 int val = *negp ? -*lvalp : *lvalp;
1999 if ((param->min && *param->min > val) ||
2000 (param->max && *param->max < val))
2007 *lvalp = (unsigned long)-val;
2010 *lvalp = (unsigned long)val;
2017 * proc_dointvec_minmax - read a vector of integers with min/max values
2018 * @table: the sysctl table
2019 * @write: %TRUE if this is a write to the sysctl file
2020 * @buffer: the user buffer
2021 * @lenp: the size of the user buffer
2022 * @ppos: file position
2024 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2025 * values from/to the user buffer, treated as an ASCII string.
2027 * This routine will ensure the values are within the range specified by
2028 * table->extra1 (min) and table->extra2 (max).
2030 * Returns 0 on success.
2032 int proc_dointvec_minmax(struct ctl_table *table, int write,
2033 void __user *buffer, size_t *lenp, loff_t *ppos)
2035 struct do_proc_dointvec_minmax_conv_param param = {
2036 .min = (int *) table->extra1,
2037 .max = (int *) table->extra2,
2039 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2040 do_proc_dointvec_minmax_conv, ¶m);
2043 static void validate_coredump_safety(void)
2045 #ifdef CONFIG_COREDUMP
2046 if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2047 core_pattern[0] != '/' && core_pattern[0] != '|') {
2048 printk(KERN_WARNING "Unsafe core_pattern used with "\
2049 "suid_dumpable=2. Pipe handler or fully qualified "\
2050 "core dump path required.\n");
2055 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2056 void __user *buffer, size_t *lenp, loff_t *ppos)
2058 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2060 validate_coredump_safety();
2064 #ifdef CONFIG_COREDUMP
2065 static int proc_dostring_coredump(struct ctl_table *table, int write,
2066 void __user *buffer, size_t *lenp, loff_t *ppos)
2068 int error = proc_dostring(table, write, buffer, lenp, ppos);
2070 validate_coredump_safety();
2075 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2076 void __user *buffer,
2077 size_t *lenp, loff_t *ppos,
2078 unsigned long convmul,
2079 unsigned long convdiv)
2081 unsigned long *i, *min, *max;
2082 int vleft, first = 1, err = 0;
2083 unsigned long page = 0;
2087 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2092 i = (unsigned long *) data;
2093 min = (unsigned long *) table->extra1;
2094 max = (unsigned long *) table->extra2;
2095 vleft = table->maxlen / sizeof(unsigned long);
2099 if (left > PAGE_SIZE - 1)
2100 left = PAGE_SIZE - 1;
2101 page = __get_free_page(GFP_TEMPORARY);
2102 kbuf = (char *) page;
2105 if (copy_from_user(kbuf, buffer, left)) {
2112 for (; left && vleft--; i++, first = 0) {
2118 left -= proc_skip_spaces(&kbuf);
2120 err = proc_get_long(&kbuf, &left, &val, &neg,
2122 sizeof(proc_wspace_sep), NULL);
2127 if ((min && val < *min) || (max && val > *max))
2131 val = convdiv * (*i) / convmul;
2133 err = proc_put_char(&buffer, &left, '\t');
2134 err = proc_put_long(&buffer, &left, val, false);
2140 if (!write && !first && left && !err)
2141 err = proc_put_char(&buffer, &left, '\n');
2143 left -= proc_skip_spaces(&kbuf);
2148 return err ? : -EINVAL;
2155 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2156 void __user *buffer,
2157 size_t *lenp, loff_t *ppos,
2158 unsigned long convmul,
2159 unsigned long convdiv)
2161 return __do_proc_doulongvec_minmax(table->data, table, write,
2162 buffer, lenp, ppos, convmul, convdiv);
2166 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2167 * @table: the sysctl table
2168 * @write: %TRUE if this is a write to the sysctl file
2169 * @buffer: the user buffer
2170 * @lenp: the size of the user buffer
2171 * @ppos: file position
2173 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2174 * values from/to the user buffer, treated as an ASCII string.
2176 * This routine will ensure the values are within the range specified by
2177 * table->extra1 (min) and table->extra2 (max).
2179 * Returns 0 on success.
2181 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2182 void __user *buffer, size_t *lenp, loff_t *ppos)
2184 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2188 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2189 * @table: the sysctl table
2190 * @write: %TRUE if this is a write to the sysctl file
2191 * @buffer: the user buffer
2192 * @lenp: the size of the user buffer
2193 * @ppos: file position
2195 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2196 * values from/to the user buffer, treated as an ASCII string. The values
2197 * are treated as milliseconds, and converted to jiffies when they are stored.
2199 * This routine will ensure the values are within the range specified by
2200 * table->extra1 (min) and table->extra2 (max).
2202 * Returns 0 on success.
2204 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2205 void __user *buffer,
2206 size_t *lenp, loff_t *ppos)
2208 return do_proc_doulongvec_minmax(table, write, buffer,
2209 lenp, ppos, HZ, 1000l);
2213 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2215 int write, void *data)
2218 if (*lvalp > LONG_MAX / HZ)
2220 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2226 lval = (unsigned long)-val;
2229 lval = (unsigned long)val;
2236 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2238 int write, void *data)
2241 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2243 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2249 lval = (unsigned long)-val;
2252 lval = (unsigned long)val;
2254 *lvalp = jiffies_to_clock_t(lval);
2259 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2261 int write, void *data)
2264 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2270 lval = (unsigned long)-val;
2273 lval = (unsigned long)val;
2275 *lvalp = jiffies_to_msecs(lval);
2281 * proc_dointvec_jiffies - read a vector of integers as seconds
2282 * @table: the sysctl table
2283 * @write: %TRUE if this is a write to the sysctl file
2284 * @buffer: the user buffer
2285 * @lenp: the size of the user buffer
2286 * @ppos: file position
2288 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2289 * values from/to the user buffer, treated as an ASCII string.
2290 * The values read are assumed to be in seconds, and are converted into
2293 * Returns 0 on success.
2295 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2296 void __user *buffer, size_t *lenp, loff_t *ppos)
2298 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2299 do_proc_dointvec_jiffies_conv,NULL);
2303 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2304 * @table: the sysctl table
2305 * @write: %TRUE if this is a write to the sysctl file
2306 * @buffer: the user buffer
2307 * @lenp: the size of the user buffer
2308 * @ppos: pointer to the file position
2310 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2311 * values from/to the user buffer, treated as an ASCII string.
2312 * The values read are assumed to be in 1/USER_HZ seconds, and
2313 * are converted into jiffies.
2315 * Returns 0 on success.
2317 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2318 void __user *buffer, size_t *lenp, loff_t *ppos)
2320 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2321 do_proc_dointvec_userhz_jiffies_conv,NULL);
2325 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2326 * @table: the sysctl table
2327 * @write: %TRUE if this is a write to the sysctl file
2328 * @buffer: the user buffer
2329 * @lenp: the size of the user buffer
2330 * @ppos: file position
2331 * @ppos: the current position in the file
2333 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2334 * values from/to the user buffer, treated as an ASCII string.
2335 * The values read are assumed to be in 1/1000 seconds, and
2336 * are converted into jiffies.
2338 * Returns 0 on success.
2340 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2341 void __user *buffer, size_t *lenp, loff_t *ppos)
2343 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2344 do_proc_dointvec_ms_jiffies_conv, NULL);
2347 static int proc_do_cad_pid(struct ctl_table *table, int write,
2348 void __user *buffer, size_t *lenp, loff_t *ppos)
2350 struct pid *new_pid;
2354 tmp = pid_vnr(cad_pid);
2356 r = __do_proc_dointvec(&tmp, table, write, buffer,
2357 lenp, ppos, NULL, NULL);
2361 new_pid = find_get_pid(tmp);
2365 put_pid(xchg(&cad_pid, new_pid));
2370 * proc_do_large_bitmap - read/write from/to a large bitmap
2371 * @table: the sysctl table
2372 * @write: %TRUE if this is a write to the sysctl file
2373 * @buffer: the user buffer
2374 * @lenp: the size of the user buffer
2375 * @ppos: file position
2377 * The bitmap is stored at table->data and the bitmap length (in bits)
2380 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2381 * large bitmaps may be represented in a compact manner. Writing into
2382 * the file will clear the bitmap then update it with the given input.
2384 * Returns 0 on success.
2386 int proc_do_large_bitmap(struct ctl_table *table, int write,
2387 void __user *buffer, size_t *lenp, loff_t *ppos)
2391 size_t left = *lenp;
2392 unsigned long bitmap_len = table->maxlen;
2393 unsigned long *bitmap = (unsigned long *) table->data;
2394 unsigned long *tmp_bitmap = NULL;
2395 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2397 if (!bitmap_len || !left || (*ppos && !write)) {
2403 unsigned long page = 0;
2406 if (left > PAGE_SIZE - 1)
2407 left = PAGE_SIZE - 1;
2409 page = __get_free_page(GFP_TEMPORARY);
2410 kbuf = (char *) page;
2413 if (copy_from_user(kbuf, buffer, left)) {
2419 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2425 proc_skip_char(&kbuf, &left, '\n');
2426 while (!err && left) {
2427 unsigned long val_a, val_b;
2430 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2434 if (val_a >= bitmap_len || neg) {
2446 err = proc_get_long(&kbuf, &left, &val_b,
2447 &neg, tr_b, sizeof(tr_b),
2451 if (val_b >= bitmap_len || neg ||
2462 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2464 proc_skip_char(&kbuf, &left, '\n');
2468 unsigned long bit_a, bit_b = 0;
2471 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2472 if (bit_a >= bitmap_len)
2474 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2478 err = proc_put_char(&buffer, &left, ',');
2482 err = proc_put_long(&buffer, &left, bit_a, false);
2485 if (bit_a != bit_b) {
2486 err = proc_put_char(&buffer, &left, '-');
2489 err = proc_put_long(&buffer, &left, bit_b, false);
2497 err = proc_put_char(&buffer, &left, '\n');
2503 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2505 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2517 #else /* CONFIG_PROC_SYSCTL */
2519 int proc_dostring(struct ctl_table *table, int write,
2520 void __user *buffer, size_t *lenp, loff_t *ppos)
2525 int proc_dointvec(struct ctl_table *table, int write,
2526 void __user *buffer, size_t *lenp, loff_t *ppos)
2531 int proc_dointvec_minmax(struct ctl_table *table, int write,
2532 void __user *buffer, size_t *lenp, loff_t *ppos)
2537 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2538 void __user *buffer, size_t *lenp, loff_t *ppos)
2543 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2544 void __user *buffer, size_t *lenp, loff_t *ppos)
2549 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2550 void __user *buffer, size_t *lenp, loff_t *ppos)
2555 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2556 void __user *buffer, size_t *lenp, loff_t *ppos)
2561 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2562 void __user *buffer,
2563 size_t *lenp, loff_t *ppos)
2569 #endif /* CONFIG_PROC_SYSCTL */
2572 * No sense putting this after each symbol definition, twice,
2573 * exception granted :-)
2575 EXPORT_SYMBOL(proc_dointvec);
2576 EXPORT_SYMBOL(proc_dointvec_jiffies);
2577 EXPORT_SYMBOL(proc_dointvec_minmax);
2578 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2579 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2580 EXPORT_SYMBOL(proc_dostring);
2581 EXPORT_SYMBOL(proc_doulongvec_minmax);
2582 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);