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 */
260 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
261 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
262 #endif /* CONFIG_SMP */
263 #endif /* CONFIG_SCHED_DEBUG */
265 #ifdef CONFIG_COMPACTION
266 static int min_extfrag_threshold;
267 static int max_extfrag_threshold = 1000;
270 static struct ctl_table kern_table[] = {
272 .procname = "sched_child_runs_first",
273 .data = &sysctl_sched_child_runs_first,
274 .maxlen = sizeof(unsigned int),
276 .proc_handler = proc_dointvec,
278 #ifdef CONFIG_SCHED_DEBUG
280 .procname = "sched_min_granularity_ns",
281 .data = &sysctl_sched_min_granularity,
282 .maxlen = sizeof(unsigned int),
284 .proc_handler = sched_proc_update_handler,
285 .extra1 = &min_sched_granularity_ns,
286 .extra2 = &max_sched_granularity_ns,
289 .procname = "sched_latency_ns",
290 .data = &sysctl_sched_latency,
291 .maxlen = sizeof(unsigned int),
293 .proc_handler = sched_proc_update_handler,
294 .extra1 = &min_sched_granularity_ns,
295 .extra2 = &max_sched_granularity_ns,
298 .procname = "sched_wakeup_granularity_ns",
299 .data = &sysctl_sched_wakeup_granularity,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = sched_proc_update_handler,
303 .extra1 = &min_wakeup_granularity_ns,
304 .extra2 = &max_wakeup_granularity_ns,
308 .procname = "sched_tunable_scaling",
309 .data = &sysctl_sched_tunable_scaling,
310 .maxlen = sizeof(enum sched_tunable_scaling),
312 .proc_handler = sched_proc_update_handler,
313 .extra1 = &min_sched_tunable_scaling,
314 .extra2 = &max_sched_tunable_scaling,
317 .procname = "sched_migration_cost_ns",
318 .data = &sysctl_sched_migration_cost,
319 .maxlen = sizeof(unsigned int),
321 .proc_handler = proc_dointvec,
324 .procname = "sched_nr_migrate",
325 .data = &sysctl_sched_nr_migrate,
326 .maxlen = sizeof(unsigned int),
328 .proc_handler = proc_dointvec,
331 .procname = "sched_time_avg_ms",
332 .data = &sysctl_sched_time_avg,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = proc_dointvec,
338 .procname = "sched_shares_window_ns",
339 .data = &sysctl_sched_shares_window,
340 .maxlen = sizeof(unsigned int),
342 .proc_handler = proc_dointvec,
345 .procname = "timer_migration",
346 .data = &sysctl_timer_migration,
347 .maxlen = sizeof(unsigned int),
349 .proc_handler = proc_dointvec_minmax,
353 #endif /* CONFIG_SMP */
354 #ifdef CONFIG_NUMA_BALANCING
356 .procname = "numa_balancing_scan_period_min_ms",
357 .data = &sysctl_numa_balancing_scan_period_min,
358 .maxlen = sizeof(unsigned int),
360 .proc_handler = proc_dointvec,
363 .procname = "numa_balancing_scan_period_max_ms",
364 .data = &sysctl_numa_balancing_scan_period_max,
365 .maxlen = sizeof(unsigned int),
367 .proc_handler = proc_dointvec,
370 .procname = "numa_balancing_scan_size_mb",
371 .data = &sysctl_numa_balancing_scan_size,
372 .maxlen = sizeof(unsigned int),
374 .proc_handler = proc_dointvec,
376 #endif /* CONFIG_NUMA_BALANCING */
377 #endif /* CONFIG_SCHED_DEBUG */
379 .procname = "sched_rt_period_us",
380 .data = &sysctl_sched_rt_period,
381 .maxlen = sizeof(unsigned int),
383 .proc_handler = sched_rt_handler,
386 .procname = "sched_rt_runtime_us",
387 .data = &sysctl_sched_rt_runtime,
388 .maxlen = sizeof(int),
390 .proc_handler = sched_rt_handler,
392 #ifdef CONFIG_SCHED_AUTOGROUP
394 .procname = "sched_autogroup_enabled",
395 .data = &sysctl_sched_autogroup_enabled,
396 .maxlen = sizeof(unsigned int),
398 .proc_handler = proc_dointvec_minmax,
403 #ifdef CONFIG_CFS_BANDWIDTH
405 .procname = "sched_cfs_bandwidth_slice_us",
406 .data = &sysctl_sched_cfs_bandwidth_slice,
407 .maxlen = sizeof(unsigned int),
409 .proc_handler = proc_dointvec_minmax,
413 #ifdef CONFIG_PROVE_LOCKING
415 .procname = "prove_locking",
416 .data = &prove_locking,
417 .maxlen = sizeof(int),
419 .proc_handler = proc_dointvec,
422 #ifdef CONFIG_LOCK_STAT
424 .procname = "lock_stat",
426 .maxlen = sizeof(int),
428 .proc_handler = proc_dointvec,
433 .data = &panic_timeout,
434 .maxlen = sizeof(int),
436 .proc_handler = proc_dointvec,
438 #ifdef CONFIG_COREDUMP
440 .procname = "core_uses_pid",
441 .data = &core_uses_pid,
442 .maxlen = sizeof(int),
444 .proc_handler = proc_dointvec,
447 .procname = "core_pattern",
448 .data = core_pattern,
449 .maxlen = CORENAME_MAX_SIZE,
451 .proc_handler = proc_dostring_coredump,
454 .procname = "core_pipe_limit",
455 .data = &core_pipe_limit,
456 .maxlen = sizeof(unsigned int),
458 .proc_handler = proc_dointvec,
461 #ifdef CONFIG_PROC_SYSCTL
463 .procname = "tainted",
464 .maxlen = sizeof(long),
466 .proc_handler = proc_taint,
469 #ifdef CONFIG_LATENCYTOP
471 .procname = "latencytop",
472 .data = &latencytop_enabled,
473 .maxlen = sizeof(int),
475 .proc_handler = proc_dointvec,
478 #ifdef CONFIG_BLK_DEV_INITRD
480 .procname = "real-root-dev",
481 .data = &real_root_dev,
482 .maxlen = sizeof(int),
484 .proc_handler = proc_dointvec,
488 .procname = "print-fatal-signals",
489 .data = &print_fatal_signals,
490 .maxlen = sizeof(int),
492 .proc_handler = proc_dointvec,
496 .procname = "reboot-cmd",
497 .data = reboot_command,
500 .proc_handler = proc_dostring,
503 .procname = "stop-a",
504 .data = &stop_a_enabled,
505 .maxlen = sizeof (int),
507 .proc_handler = proc_dointvec,
510 .procname = "scons-poweroff",
511 .data = &scons_pwroff,
512 .maxlen = sizeof (int),
514 .proc_handler = proc_dointvec,
517 #ifdef CONFIG_SPARC64
519 .procname = "tsb-ratio",
520 .data = &sysctl_tsb_ratio,
521 .maxlen = sizeof (int),
523 .proc_handler = proc_dointvec,
528 .procname = "soft-power",
529 .data = &pwrsw_enabled,
530 .maxlen = sizeof (int),
532 .proc_handler = proc_dointvec,
535 .procname = "unaligned-trap",
536 .data = &unaligned_enabled,
537 .maxlen = sizeof (int),
539 .proc_handler = proc_dointvec,
543 .procname = "ctrl-alt-del",
545 .maxlen = sizeof(int),
547 .proc_handler = proc_dointvec,
549 #ifdef CONFIG_FUNCTION_TRACER
551 .procname = "ftrace_enabled",
552 .data = &ftrace_enabled,
553 .maxlen = sizeof(int),
555 .proc_handler = ftrace_enable_sysctl,
558 #ifdef CONFIG_STACK_TRACER
560 .procname = "stack_tracer_enabled",
561 .data = &stack_tracer_enabled,
562 .maxlen = sizeof(int),
564 .proc_handler = stack_trace_sysctl,
567 #ifdef CONFIG_TRACING
569 .procname = "ftrace_dump_on_oops",
570 .data = &ftrace_dump_on_oops,
571 .maxlen = sizeof(int),
573 .proc_handler = proc_dointvec,
576 #ifdef CONFIG_MODULES
578 .procname = "modprobe",
579 .data = &modprobe_path,
580 .maxlen = KMOD_PATH_LEN,
582 .proc_handler = proc_dostring,
585 .procname = "modules_disabled",
586 .data = &modules_disabled,
587 .maxlen = sizeof(int),
589 /* only handle a transition from default "0" to "1" */
590 .proc_handler = proc_dointvec_minmax,
595 #ifdef CONFIG_HOTPLUG
597 .procname = "hotplug",
598 .data = &uevent_helper,
599 .maxlen = UEVENT_HELPER_PATH_LEN,
601 .proc_handler = proc_dostring,
604 #ifdef CONFIG_CHR_DEV_SG
606 .procname = "sg-big-buff",
607 .data = &sg_big_buff,
608 .maxlen = sizeof (int),
610 .proc_handler = proc_dointvec,
613 #ifdef CONFIG_BSD_PROCESS_ACCT
617 .maxlen = 3*sizeof(int),
619 .proc_handler = proc_dointvec,
622 #ifdef CONFIG_MAGIC_SYSRQ
625 .data = &__sysrq_enabled,
626 .maxlen = sizeof (int),
628 .proc_handler = sysrq_sysctl_handler,
631 #ifdef CONFIG_PROC_SYSCTL
633 .procname = "cad_pid",
635 .maxlen = sizeof (int),
637 .proc_handler = proc_do_cad_pid,
641 .procname = "threads-max",
642 .data = &max_threads,
643 .maxlen = sizeof(int),
645 .proc_handler = proc_dointvec,
648 .procname = "random",
650 .child = random_table,
653 .procname = "usermodehelper",
655 .child = usermodehelper_table,
658 .procname = "overflowuid",
659 .data = &overflowuid,
660 .maxlen = sizeof(int),
662 .proc_handler = proc_dointvec_minmax,
663 .extra1 = &minolduid,
664 .extra2 = &maxolduid,
667 .procname = "overflowgid",
668 .data = &overflowgid,
669 .maxlen = sizeof(int),
671 .proc_handler = proc_dointvec_minmax,
672 .extra1 = &minolduid,
673 .extra2 = &maxolduid,
676 #ifdef CONFIG_MATHEMU
678 .procname = "ieee_emulation_warnings",
679 .data = &sysctl_ieee_emulation_warnings,
680 .maxlen = sizeof(int),
682 .proc_handler = proc_dointvec,
686 .procname = "userprocess_debug",
687 .data = &show_unhandled_signals,
688 .maxlen = sizeof(int),
690 .proc_handler = proc_dointvec,
694 .procname = "pid_max",
696 .maxlen = sizeof (int),
698 .proc_handler = proc_dointvec_minmax,
699 .extra1 = &pid_max_min,
700 .extra2 = &pid_max_max,
703 .procname = "panic_on_oops",
704 .data = &panic_on_oops,
705 .maxlen = sizeof(int),
707 .proc_handler = proc_dointvec,
709 #if defined CONFIG_PRINTK
711 .procname = "printk",
712 .data = &console_loglevel,
713 .maxlen = 4*sizeof(int),
715 .proc_handler = proc_dointvec,
718 .procname = "printk_ratelimit",
719 .data = &printk_ratelimit_state.interval,
720 .maxlen = sizeof(int),
722 .proc_handler = proc_dointvec_jiffies,
725 .procname = "printk_ratelimit_burst",
726 .data = &printk_ratelimit_state.burst,
727 .maxlen = sizeof(int),
729 .proc_handler = proc_dointvec,
732 .procname = "printk_delay",
733 .data = &printk_delay_msec,
734 .maxlen = sizeof(int),
736 .proc_handler = proc_dointvec_minmax,
738 .extra2 = &ten_thousand,
741 .procname = "dmesg_restrict",
742 .data = &dmesg_restrict,
743 .maxlen = sizeof(int),
745 .proc_handler = proc_dointvec_minmax_sysadmin,
750 .procname = "kptr_restrict",
751 .data = &kptr_restrict,
752 .maxlen = sizeof(int),
754 .proc_handler = proc_dointvec_minmax_sysadmin,
760 .procname = "ngroups_max",
761 .data = &ngroups_max,
762 .maxlen = sizeof (int),
764 .proc_handler = proc_dointvec,
767 .procname = "cap_last_cap",
768 .data = (void *)&cap_last_cap,
769 .maxlen = sizeof(int),
771 .proc_handler = proc_dointvec,
773 #if defined(CONFIG_LOCKUP_DETECTOR)
775 .procname = "watchdog",
776 .data = &watchdog_enabled,
777 .maxlen = sizeof (int),
779 .proc_handler = proc_dowatchdog,
784 .procname = "watchdog_thresh",
785 .data = &watchdog_thresh,
786 .maxlen = sizeof(int),
788 .proc_handler = proc_dowatchdog,
793 .procname = "softlockup_panic",
794 .data = &softlockup_panic,
795 .maxlen = sizeof(int),
797 .proc_handler = proc_dointvec_minmax,
802 .procname = "nmi_watchdog",
803 .data = &watchdog_enabled,
804 .maxlen = sizeof (int),
806 .proc_handler = proc_dowatchdog,
811 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
813 .procname = "unknown_nmi_panic",
814 .data = &unknown_nmi_panic,
815 .maxlen = sizeof (int),
817 .proc_handler = proc_dointvec,
820 #if defined(CONFIG_X86)
822 .procname = "panic_on_unrecovered_nmi",
823 .data = &panic_on_unrecovered_nmi,
824 .maxlen = sizeof(int),
826 .proc_handler = proc_dointvec,
829 .procname = "panic_on_io_nmi",
830 .data = &panic_on_io_nmi,
831 .maxlen = sizeof(int),
833 .proc_handler = proc_dointvec,
835 #ifdef CONFIG_DEBUG_STACKOVERFLOW
837 .procname = "panic_on_stackoverflow",
838 .data = &sysctl_panic_on_stackoverflow,
839 .maxlen = sizeof(int),
841 .proc_handler = proc_dointvec,
845 .procname = "bootloader_type",
846 .data = &bootloader_type,
847 .maxlen = sizeof (int),
849 .proc_handler = proc_dointvec,
852 .procname = "bootloader_version",
853 .data = &bootloader_version,
854 .maxlen = sizeof (int),
856 .proc_handler = proc_dointvec,
859 .procname = "kstack_depth_to_print",
860 .data = &kstack_depth_to_print,
861 .maxlen = sizeof(int),
863 .proc_handler = proc_dointvec,
866 .procname = "io_delay_type",
867 .data = &io_delay_type,
868 .maxlen = sizeof(int),
870 .proc_handler = proc_dointvec,
873 #if defined(CONFIG_MMU)
875 .procname = "randomize_va_space",
876 .data = &randomize_va_space,
877 .maxlen = sizeof(int),
879 .proc_handler = proc_dointvec,
882 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
884 .procname = "spin_retry",
886 .maxlen = sizeof (int),
888 .proc_handler = proc_dointvec,
891 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
893 .procname = "acpi_video_flags",
894 .data = &acpi_realmode_flags,
895 .maxlen = sizeof (unsigned long),
897 .proc_handler = proc_doulongvec_minmax,
902 .procname = "ignore-unaligned-usertrap",
903 .data = &no_unaligned_warning,
904 .maxlen = sizeof (int),
906 .proc_handler = proc_dointvec,
909 .procname = "unaligned-dump-stack",
910 .data = &unaligned_dump_stack,
911 .maxlen = sizeof (int),
913 .proc_handler = proc_dointvec,
916 #ifdef CONFIG_DETECT_HUNG_TASK
918 .procname = "hung_task_panic",
919 .data = &sysctl_hung_task_panic,
920 .maxlen = sizeof(int),
922 .proc_handler = proc_dointvec_minmax,
927 .procname = "hung_task_check_count",
928 .data = &sysctl_hung_task_check_count,
929 .maxlen = sizeof(unsigned long),
931 .proc_handler = proc_doulongvec_minmax,
934 .procname = "hung_task_timeout_secs",
935 .data = &sysctl_hung_task_timeout_secs,
936 .maxlen = sizeof(unsigned long),
938 .proc_handler = proc_dohung_task_timeout_secs,
941 .procname = "hung_task_warnings",
942 .data = &sysctl_hung_task_warnings,
943 .maxlen = sizeof(unsigned long),
945 .proc_handler = proc_doulongvec_minmax,
950 .procname = "compat-log",
952 .maxlen = sizeof (int),
954 .proc_handler = proc_dointvec,
957 #ifdef CONFIG_RT_MUTEXES
959 .procname = "max_lock_depth",
960 .data = &max_lock_depth,
961 .maxlen = sizeof(int),
963 .proc_handler = proc_dointvec,
967 .procname = "poweroff_cmd",
968 .data = &poweroff_cmd,
969 .maxlen = POWEROFF_CMD_PATH_LEN,
971 .proc_handler = proc_dostring,
977 .child = key_sysctls,
980 #ifdef CONFIG_RCU_TORTURE_TEST
982 .procname = "rcutorture_runnable",
983 .data = &rcutorture_runnable,
984 .maxlen = sizeof(int),
986 .proc_handler = proc_dointvec,
989 #ifdef CONFIG_PERF_EVENTS
991 * User-space scripts rely on the existence of this file
992 * as a feature check for perf_events being enabled.
994 * So it's an ABI, do not remove!
997 .procname = "perf_event_paranoid",
998 .data = &sysctl_perf_event_paranoid,
999 .maxlen = sizeof(sysctl_perf_event_paranoid),
1001 .proc_handler = proc_dointvec,
1004 .procname = "perf_event_mlock_kb",
1005 .data = &sysctl_perf_event_mlock,
1006 .maxlen = sizeof(sysctl_perf_event_mlock),
1008 .proc_handler = proc_dointvec,
1011 .procname = "perf_event_max_sample_rate",
1012 .data = &sysctl_perf_event_sample_rate,
1013 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1015 .proc_handler = perf_proc_update_handler,
1018 #ifdef CONFIG_KMEMCHECK
1020 .procname = "kmemcheck",
1021 .data = &kmemcheck_enabled,
1022 .maxlen = sizeof(int),
1024 .proc_handler = proc_dointvec,
1029 .procname = "blk_iopoll",
1030 .data = &blk_iopoll_enabled,
1031 .maxlen = sizeof(int),
1033 .proc_handler = proc_dointvec,
1039 static struct ctl_table vm_table[] = {
1041 .procname = "overcommit_memory",
1042 .data = &sysctl_overcommit_memory,
1043 .maxlen = sizeof(sysctl_overcommit_memory),
1045 .proc_handler = proc_dointvec_minmax,
1050 .procname = "panic_on_oom",
1051 .data = &sysctl_panic_on_oom,
1052 .maxlen = sizeof(sysctl_panic_on_oom),
1054 .proc_handler = proc_dointvec_minmax,
1059 .procname = "oom_kill_allocating_task",
1060 .data = &sysctl_oom_kill_allocating_task,
1061 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1063 .proc_handler = proc_dointvec,
1066 .procname = "oom_dump_tasks",
1067 .data = &sysctl_oom_dump_tasks,
1068 .maxlen = sizeof(sysctl_oom_dump_tasks),
1070 .proc_handler = proc_dointvec,
1073 .procname = "overcommit_ratio",
1074 .data = &sysctl_overcommit_ratio,
1075 .maxlen = sizeof(sysctl_overcommit_ratio),
1077 .proc_handler = proc_dointvec,
1080 .procname = "page-cluster",
1081 .data = &page_cluster,
1082 .maxlen = sizeof(int),
1084 .proc_handler = proc_dointvec_minmax,
1088 .procname = "dirty_background_ratio",
1089 .data = &dirty_background_ratio,
1090 .maxlen = sizeof(dirty_background_ratio),
1092 .proc_handler = dirty_background_ratio_handler,
1094 .extra2 = &one_hundred,
1097 .procname = "dirty_background_bytes",
1098 .data = &dirty_background_bytes,
1099 .maxlen = sizeof(dirty_background_bytes),
1101 .proc_handler = dirty_background_bytes_handler,
1105 .procname = "dirty_ratio",
1106 .data = &vm_dirty_ratio,
1107 .maxlen = sizeof(vm_dirty_ratio),
1109 .proc_handler = dirty_ratio_handler,
1111 .extra2 = &one_hundred,
1114 .procname = "dirty_bytes",
1115 .data = &vm_dirty_bytes,
1116 .maxlen = sizeof(vm_dirty_bytes),
1118 .proc_handler = dirty_bytes_handler,
1119 .extra1 = &dirty_bytes_min,
1122 .procname = "dirty_writeback_centisecs",
1123 .data = &dirty_writeback_interval,
1124 .maxlen = sizeof(dirty_writeback_interval),
1126 .proc_handler = dirty_writeback_centisecs_handler,
1129 .procname = "dirty_expire_centisecs",
1130 .data = &dirty_expire_interval,
1131 .maxlen = sizeof(dirty_expire_interval),
1133 .proc_handler = proc_dointvec_minmax,
1137 .procname = "nr_pdflush_threads",
1138 .mode = 0444 /* read-only */,
1139 .proc_handler = pdflush_proc_obsolete,
1142 .procname = "swappiness",
1143 .data = &vm_swappiness,
1144 .maxlen = sizeof(vm_swappiness),
1146 .proc_handler = proc_dointvec_minmax,
1148 .extra2 = &one_hundred,
1150 #ifdef CONFIG_HUGETLB_PAGE
1152 .procname = "nr_hugepages",
1154 .maxlen = sizeof(unsigned long),
1156 .proc_handler = hugetlb_sysctl_handler,
1157 .extra1 = (void *)&hugetlb_zero,
1158 .extra2 = (void *)&hugetlb_infinity,
1162 .procname = "nr_hugepages_mempolicy",
1164 .maxlen = sizeof(unsigned long),
1166 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1167 .extra1 = (void *)&hugetlb_zero,
1168 .extra2 = (void *)&hugetlb_infinity,
1172 .procname = "hugetlb_shm_group",
1173 .data = &sysctl_hugetlb_shm_group,
1174 .maxlen = sizeof(gid_t),
1176 .proc_handler = proc_dointvec,
1179 .procname = "hugepages_treat_as_movable",
1180 .data = &hugepages_treat_as_movable,
1181 .maxlen = sizeof(int),
1183 .proc_handler = hugetlb_treat_movable_handler,
1186 .procname = "nr_overcommit_hugepages",
1188 .maxlen = sizeof(unsigned long),
1190 .proc_handler = hugetlb_overcommit_handler,
1191 .extra1 = (void *)&hugetlb_zero,
1192 .extra2 = (void *)&hugetlb_infinity,
1196 .procname = "lowmem_reserve_ratio",
1197 .data = &sysctl_lowmem_reserve_ratio,
1198 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1200 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1203 .procname = "drop_caches",
1204 .data = &sysctl_drop_caches,
1205 .maxlen = sizeof(int),
1207 .proc_handler = drop_caches_sysctl_handler,
1211 #ifdef CONFIG_COMPACTION
1213 .procname = "compact_memory",
1214 .data = &sysctl_compact_memory,
1215 .maxlen = sizeof(int),
1217 .proc_handler = sysctl_compaction_handler,
1220 .procname = "extfrag_threshold",
1221 .data = &sysctl_extfrag_threshold,
1222 .maxlen = sizeof(int),
1224 .proc_handler = sysctl_extfrag_handler,
1225 .extra1 = &min_extfrag_threshold,
1226 .extra2 = &max_extfrag_threshold,
1229 #endif /* CONFIG_COMPACTION */
1231 .procname = "min_free_kbytes",
1232 .data = &min_free_kbytes,
1233 .maxlen = sizeof(min_free_kbytes),
1235 .proc_handler = min_free_kbytes_sysctl_handler,
1239 .procname = "percpu_pagelist_fraction",
1240 .data = &percpu_pagelist_fraction,
1241 .maxlen = sizeof(percpu_pagelist_fraction),
1243 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1244 .extra1 = &min_percpu_pagelist_fract,
1248 .procname = "max_map_count",
1249 .data = &sysctl_max_map_count,
1250 .maxlen = sizeof(sysctl_max_map_count),
1252 .proc_handler = proc_dointvec_minmax,
1257 .procname = "nr_trim_pages",
1258 .data = &sysctl_nr_trim_pages,
1259 .maxlen = sizeof(sysctl_nr_trim_pages),
1261 .proc_handler = proc_dointvec_minmax,
1266 .procname = "laptop_mode",
1267 .data = &laptop_mode,
1268 .maxlen = sizeof(laptop_mode),
1270 .proc_handler = proc_dointvec_jiffies,
1273 .procname = "block_dump",
1274 .data = &block_dump,
1275 .maxlen = sizeof(block_dump),
1277 .proc_handler = proc_dointvec,
1281 .procname = "vfs_cache_pressure",
1282 .data = &sysctl_vfs_cache_pressure,
1283 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1285 .proc_handler = proc_dointvec,
1288 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1290 .procname = "legacy_va_layout",
1291 .data = &sysctl_legacy_va_layout,
1292 .maxlen = sizeof(sysctl_legacy_va_layout),
1294 .proc_handler = proc_dointvec,
1300 .procname = "zone_reclaim_mode",
1301 .data = &zone_reclaim_mode,
1302 .maxlen = sizeof(zone_reclaim_mode),
1304 .proc_handler = proc_dointvec,
1308 .procname = "min_unmapped_ratio",
1309 .data = &sysctl_min_unmapped_ratio,
1310 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1312 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1314 .extra2 = &one_hundred,
1317 .procname = "min_slab_ratio",
1318 .data = &sysctl_min_slab_ratio,
1319 .maxlen = sizeof(sysctl_min_slab_ratio),
1321 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1323 .extra2 = &one_hundred,
1328 .procname = "stat_interval",
1329 .data = &sysctl_stat_interval,
1330 .maxlen = sizeof(sysctl_stat_interval),
1332 .proc_handler = proc_dointvec_jiffies,
1337 .procname = "mmap_min_addr",
1338 .data = &dac_mmap_min_addr,
1339 .maxlen = sizeof(unsigned long),
1341 .proc_handler = mmap_min_addr_handler,
1346 .procname = "numa_zonelist_order",
1347 .data = &numa_zonelist_order,
1348 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1350 .proc_handler = numa_zonelist_order_handler,
1353 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1354 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1356 .procname = "vdso_enabled",
1357 .data = &vdso_enabled,
1358 .maxlen = sizeof(vdso_enabled),
1360 .proc_handler = proc_dointvec,
1364 #ifdef CONFIG_HIGHMEM
1366 .procname = "highmem_is_dirtyable",
1367 .data = &vm_highmem_is_dirtyable,
1368 .maxlen = sizeof(vm_highmem_is_dirtyable),
1370 .proc_handler = proc_dointvec_minmax,
1376 .procname = "scan_unevictable_pages",
1377 .data = &scan_unevictable_pages,
1378 .maxlen = sizeof(scan_unevictable_pages),
1380 .proc_handler = scan_unevictable_handler,
1382 #ifdef CONFIG_MEMORY_FAILURE
1384 .procname = "memory_failure_early_kill",
1385 .data = &sysctl_memory_failure_early_kill,
1386 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1388 .proc_handler = proc_dointvec_minmax,
1393 .procname = "memory_failure_recovery",
1394 .data = &sysctl_memory_failure_recovery,
1395 .maxlen = sizeof(sysctl_memory_failure_recovery),
1397 .proc_handler = proc_dointvec_minmax,
1405 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1406 static struct ctl_table binfmt_misc_table[] = {
1411 static struct ctl_table fs_table[] = {
1413 .procname = "inode-nr",
1414 .data = &inodes_stat,
1415 .maxlen = 2*sizeof(int),
1417 .proc_handler = proc_nr_inodes,
1420 .procname = "inode-state",
1421 .data = &inodes_stat,
1422 .maxlen = 7*sizeof(int),
1424 .proc_handler = proc_nr_inodes,
1427 .procname = "file-nr",
1428 .data = &files_stat,
1429 .maxlen = sizeof(files_stat),
1431 .proc_handler = proc_nr_files,
1434 .procname = "file-max",
1435 .data = &files_stat.max_files,
1436 .maxlen = sizeof(files_stat.max_files),
1438 .proc_handler = proc_doulongvec_minmax,
1441 .procname = "nr_open",
1442 .data = &sysctl_nr_open,
1443 .maxlen = sizeof(int),
1445 .proc_handler = proc_dointvec_minmax,
1446 .extra1 = &sysctl_nr_open_min,
1447 .extra2 = &sysctl_nr_open_max,
1450 .procname = "dentry-state",
1451 .data = &dentry_stat,
1452 .maxlen = 6*sizeof(int),
1454 .proc_handler = proc_nr_dentry,
1457 .procname = "overflowuid",
1458 .data = &fs_overflowuid,
1459 .maxlen = sizeof(int),
1461 .proc_handler = proc_dointvec_minmax,
1462 .extra1 = &minolduid,
1463 .extra2 = &maxolduid,
1466 .procname = "overflowgid",
1467 .data = &fs_overflowgid,
1468 .maxlen = sizeof(int),
1470 .proc_handler = proc_dointvec_minmax,
1471 .extra1 = &minolduid,
1472 .extra2 = &maxolduid,
1474 #ifdef CONFIG_FILE_LOCKING
1476 .procname = "leases-enable",
1477 .data = &leases_enable,
1478 .maxlen = sizeof(int),
1480 .proc_handler = proc_dointvec,
1483 #ifdef CONFIG_DNOTIFY
1485 .procname = "dir-notify-enable",
1486 .data = &dir_notify_enable,
1487 .maxlen = sizeof(int),
1489 .proc_handler = proc_dointvec,
1493 #ifdef CONFIG_FILE_LOCKING
1495 .procname = "lease-break-time",
1496 .data = &lease_break_time,
1497 .maxlen = sizeof(int),
1499 .proc_handler = proc_dointvec,
1504 .procname = "aio-nr",
1506 .maxlen = sizeof(aio_nr),
1508 .proc_handler = proc_doulongvec_minmax,
1511 .procname = "aio-max-nr",
1512 .data = &aio_max_nr,
1513 .maxlen = sizeof(aio_max_nr),
1515 .proc_handler = proc_doulongvec_minmax,
1517 #endif /* CONFIG_AIO */
1518 #ifdef CONFIG_INOTIFY_USER
1520 .procname = "inotify",
1522 .child = inotify_table,
1527 .procname = "epoll",
1529 .child = epoll_table,
1534 .procname = "protected_symlinks",
1535 .data = &sysctl_protected_symlinks,
1536 .maxlen = sizeof(int),
1538 .proc_handler = proc_dointvec_minmax,
1543 .procname = "protected_hardlinks",
1544 .data = &sysctl_protected_hardlinks,
1545 .maxlen = sizeof(int),
1547 .proc_handler = proc_dointvec_minmax,
1552 .procname = "suid_dumpable",
1553 .data = &suid_dumpable,
1554 .maxlen = sizeof(int),
1556 .proc_handler = proc_dointvec_minmax_coredump,
1560 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1562 .procname = "binfmt_misc",
1564 .child = binfmt_misc_table,
1568 .procname = "pipe-max-size",
1569 .data = &pipe_max_size,
1570 .maxlen = sizeof(int),
1572 .proc_handler = &pipe_proc_fn,
1573 .extra1 = &pipe_min_size,
1578 static struct ctl_table debug_table[] = {
1579 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1581 .procname = "exception-trace",
1582 .data = &show_unhandled_signals,
1583 .maxlen = sizeof(int),
1585 .proc_handler = proc_dointvec
1588 #if defined(CONFIG_OPTPROBES)
1590 .procname = "kprobes-optimization",
1591 .data = &sysctl_kprobes_optimization,
1592 .maxlen = sizeof(int),
1594 .proc_handler = proc_kprobes_optimization_handler,
1602 static struct ctl_table dev_table[] = {
1606 int __init sysctl_init(void)
1608 struct ctl_table_header *hdr;
1610 hdr = register_sysctl_table(sysctl_base_table);
1611 kmemleak_not_leak(hdr);
1615 #endif /* CONFIG_SYSCTL */
1621 #ifdef CONFIG_PROC_SYSCTL
1623 static int _proc_do_string(void* data, int maxlen, int write,
1624 void __user *buffer,
1625 size_t *lenp, loff_t *ppos)
1631 if (!data || !maxlen || !*lenp) {
1639 while (len < *lenp) {
1640 if (get_user(c, p++))
1642 if (c == 0 || c == '\n')
1648 if(copy_from_user(data, buffer, len))
1650 ((char *) data)[len] = 0;
1668 if(copy_to_user(buffer, data, len))
1671 if(put_user('\n', ((char __user *) buffer) + len))
1682 * proc_dostring - read a string sysctl
1683 * @table: the sysctl table
1684 * @write: %TRUE if this is a write to the sysctl file
1685 * @buffer: the user buffer
1686 * @lenp: the size of the user buffer
1687 * @ppos: file position
1689 * Reads/writes a string from/to the user buffer. If the kernel
1690 * buffer provided is not large enough to hold the string, the
1691 * string is truncated. The copied string is %NULL-terminated.
1692 * If the string is being read by the user process, it is copied
1693 * and a newline '\n' is added. It is truncated if the buffer is
1696 * Returns 0 on success.
1698 int proc_dostring(struct ctl_table *table, int write,
1699 void __user *buffer, size_t *lenp, loff_t *ppos)
1701 return _proc_do_string(table->data, table->maxlen, write,
1702 buffer, lenp, ppos);
1705 static size_t proc_skip_spaces(char **buf)
1708 char *tmp = skip_spaces(*buf);
1714 static void proc_skip_char(char **buf, size_t *size, const char v)
1724 #define TMPBUFLEN 22
1726 * proc_get_long - reads an ASCII formatted integer from a user buffer
1728 * @buf: a kernel buffer
1729 * @size: size of the kernel buffer
1730 * @val: this is where the number will be stored
1731 * @neg: set to %TRUE if number is negative
1732 * @perm_tr: a vector which contains the allowed trailers
1733 * @perm_tr_len: size of the perm_tr vector
1734 * @tr: pointer to store the trailer character
1736 * In case of success %0 is returned and @buf and @size are updated with
1737 * the amount of bytes read. If @tr is non-NULL and a trailing
1738 * character exists (size is non-zero after returning from this
1739 * function), @tr is updated with the trailing character.
1741 static int proc_get_long(char **buf, size_t *size,
1742 unsigned long *val, bool *neg,
1743 const char *perm_tr, unsigned perm_tr_len, char *tr)
1746 char *p, tmp[TMPBUFLEN];
1752 if (len > TMPBUFLEN - 1)
1753 len = TMPBUFLEN - 1;
1755 memcpy(tmp, *buf, len);
1759 if (*p == '-' && *size > 1) {
1767 *val = simple_strtoul(p, &p, 0);
1771 /* We don't know if the next char is whitespace thus we may accept
1772 * invalid integers (e.g. 1234...a) or two integers instead of one
1773 * (e.g. 123...1). So lets not allow such large numbers. */
1774 if (len == TMPBUFLEN - 1)
1777 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1780 if (tr && (len < *size))
1790 * proc_put_long - converts an integer to a decimal ASCII formatted string
1792 * @buf: the user buffer
1793 * @size: the size of the user buffer
1794 * @val: the integer to be converted
1795 * @neg: sign of the number, %TRUE for negative
1797 * In case of success %0 is returned and @buf and @size are updated with
1798 * the amount of bytes written.
1800 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1804 char tmp[TMPBUFLEN], *p = tmp;
1806 sprintf(p, "%s%lu", neg ? "-" : "", val);
1810 if (copy_to_user(*buf, tmp, len))
1818 static int proc_put_char(void __user **buf, size_t *size, char c)
1821 char __user **buffer = (char __user **)buf;
1822 if (put_user(c, *buffer))
1824 (*size)--, (*buffer)++;
1830 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1832 int write, void *data)
1835 *valp = *negp ? -*lvalp : *lvalp;
1840 *lvalp = (unsigned long)-val;
1843 *lvalp = (unsigned long)val;
1849 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1851 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1852 int write, void __user *buffer,
1853 size_t *lenp, loff_t *ppos,
1854 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1855 int write, void *data),
1858 int *i, vleft, first = 1, err = 0;
1859 unsigned long page = 0;
1863 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1868 i = (int *) tbl_data;
1869 vleft = table->maxlen / sizeof(*i);
1873 conv = do_proc_dointvec_conv;
1876 if (left > PAGE_SIZE - 1)
1877 left = PAGE_SIZE - 1;
1878 page = __get_free_page(GFP_TEMPORARY);
1879 kbuf = (char *) page;
1882 if (copy_from_user(kbuf, buffer, left)) {
1889 for (; left && vleft--; i++, first=0) {
1894 left -= proc_skip_spaces(&kbuf);
1898 err = proc_get_long(&kbuf, &left, &lval, &neg,
1900 sizeof(proc_wspace_sep), NULL);
1903 if (conv(&neg, &lval, i, 1, data)) {
1908 if (conv(&neg, &lval, i, 0, data)) {
1913 err = proc_put_char(&buffer, &left, '\t');
1916 err = proc_put_long(&buffer, &left, lval, neg);
1922 if (!write && !first && left && !err)
1923 err = proc_put_char(&buffer, &left, '\n');
1924 if (write && !err && left)
1925 left -= proc_skip_spaces(&kbuf);
1930 return err ? : -EINVAL;
1937 static int do_proc_dointvec(struct ctl_table *table, int write,
1938 void __user *buffer, size_t *lenp, loff_t *ppos,
1939 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1940 int write, void *data),
1943 return __do_proc_dointvec(table->data, table, write,
1944 buffer, lenp, ppos, conv, data);
1948 * proc_dointvec - read a vector of integers
1949 * @table: the sysctl table
1950 * @write: %TRUE if this is a write to the sysctl file
1951 * @buffer: the user buffer
1952 * @lenp: the size of the user buffer
1953 * @ppos: file position
1955 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1956 * values from/to the user buffer, treated as an ASCII string.
1958 * Returns 0 on success.
1960 int proc_dointvec(struct ctl_table *table, int write,
1961 void __user *buffer, size_t *lenp, loff_t *ppos)
1963 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1968 * Taint values can only be increased
1969 * This means we can safely use a temporary.
1971 static int proc_taint(struct ctl_table *table, int write,
1972 void __user *buffer, size_t *lenp, loff_t *ppos)
1975 unsigned long tmptaint = get_taint();
1978 if (write && !capable(CAP_SYS_ADMIN))
1983 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
1989 * Poor man's atomic or. Not worth adding a primitive
1990 * to everyone's atomic.h for this
1993 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
1994 if ((tmptaint >> i) & 1)
2002 #ifdef CONFIG_PRINTK
2003 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2004 void __user *buffer, size_t *lenp, loff_t *ppos)
2006 if (write && !capable(CAP_SYS_ADMIN))
2009 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2013 struct do_proc_dointvec_minmax_conv_param {
2018 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2020 int write, void *data)
2022 struct do_proc_dointvec_minmax_conv_param *param = data;
2024 int val = *negp ? -*lvalp : *lvalp;
2025 if ((param->min && *param->min > val) ||
2026 (param->max && *param->max < val))
2033 *lvalp = (unsigned long)-val;
2036 *lvalp = (unsigned long)val;
2043 * proc_dointvec_minmax - read a vector of integers with min/max values
2044 * @table: the sysctl table
2045 * @write: %TRUE if this is a write to the sysctl file
2046 * @buffer: the user buffer
2047 * @lenp: the size of the user buffer
2048 * @ppos: file position
2050 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2051 * values from/to the user buffer, treated as an ASCII string.
2053 * This routine will ensure the values are within the range specified by
2054 * table->extra1 (min) and table->extra2 (max).
2056 * Returns 0 on success.
2058 int proc_dointvec_minmax(struct ctl_table *table, int write,
2059 void __user *buffer, size_t *lenp, loff_t *ppos)
2061 struct do_proc_dointvec_minmax_conv_param param = {
2062 .min = (int *) table->extra1,
2063 .max = (int *) table->extra2,
2065 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2066 do_proc_dointvec_minmax_conv, ¶m);
2069 static void validate_coredump_safety(void)
2071 #ifdef CONFIG_COREDUMP
2072 if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2073 core_pattern[0] != '/' && core_pattern[0] != '|') {
2074 printk(KERN_WARNING "Unsafe core_pattern used with "\
2075 "suid_dumpable=2. Pipe handler or fully qualified "\
2076 "core dump path required.\n");
2081 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2082 void __user *buffer, size_t *lenp, loff_t *ppos)
2084 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2086 validate_coredump_safety();
2090 #ifdef CONFIG_COREDUMP
2091 static int proc_dostring_coredump(struct ctl_table *table, int write,
2092 void __user *buffer, size_t *lenp, loff_t *ppos)
2094 int error = proc_dostring(table, write, buffer, lenp, ppos);
2096 validate_coredump_safety();
2101 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2102 void __user *buffer,
2103 size_t *lenp, loff_t *ppos,
2104 unsigned long convmul,
2105 unsigned long convdiv)
2107 unsigned long *i, *min, *max;
2108 int vleft, first = 1, err = 0;
2109 unsigned long page = 0;
2113 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2118 i = (unsigned long *) data;
2119 min = (unsigned long *) table->extra1;
2120 max = (unsigned long *) table->extra2;
2121 vleft = table->maxlen / sizeof(unsigned long);
2125 if (left > PAGE_SIZE - 1)
2126 left = PAGE_SIZE - 1;
2127 page = __get_free_page(GFP_TEMPORARY);
2128 kbuf = (char *) page;
2131 if (copy_from_user(kbuf, buffer, left)) {
2138 for (; left && vleft--; i++, first = 0) {
2144 left -= proc_skip_spaces(&kbuf);
2146 err = proc_get_long(&kbuf, &left, &val, &neg,
2148 sizeof(proc_wspace_sep), NULL);
2153 if ((min && val < *min) || (max && val > *max))
2157 val = convdiv * (*i) / convmul;
2159 err = proc_put_char(&buffer, &left, '\t');
2160 err = proc_put_long(&buffer, &left, val, false);
2166 if (!write && !first && left && !err)
2167 err = proc_put_char(&buffer, &left, '\n');
2169 left -= proc_skip_spaces(&kbuf);
2174 return err ? : -EINVAL;
2181 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2182 void __user *buffer,
2183 size_t *lenp, loff_t *ppos,
2184 unsigned long convmul,
2185 unsigned long convdiv)
2187 return __do_proc_doulongvec_minmax(table->data, table, write,
2188 buffer, lenp, ppos, convmul, convdiv);
2192 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2193 * @table: the sysctl table
2194 * @write: %TRUE if this is a write to the sysctl file
2195 * @buffer: the user buffer
2196 * @lenp: the size of the user buffer
2197 * @ppos: file position
2199 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2200 * values from/to the user buffer, treated as an ASCII string.
2202 * This routine will ensure the values are within the range specified by
2203 * table->extra1 (min) and table->extra2 (max).
2205 * Returns 0 on success.
2207 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2208 void __user *buffer, size_t *lenp, loff_t *ppos)
2210 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2214 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2215 * @table: the sysctl table
2216 * @write: %TRUE if this is a write to the sysctl file
2217 * @buffer: the user buffer
2218 * @lenp: the size of the user buffer
2219 * @ppos: file position
2221 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2222 * values from/to the user buffer, treated as an ASCII string. The values
2223 * are treated as milliseconds, and converted to jiffies when they are stored.
2225 * This routine will ensure the values are within the range specified by
2226 * table->extra1 (min) and table->extra2 (max).
2228 * Returns 0 on success.
2230 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2231 void __user *buffer,
2232 size_t *lenp, loff_t *ppos)
2234 return do_proc_doulongvec_minmax(table, write, buffer,
2235 lenp, ppos, HZ, 1000l);
2239 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2241 int write, void *data)
2244 if (*lvalp > LONG_MAX / HZ)
2246 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2252 lval = (unsigned long)-val;
2255 lval = (unsigned long)val;
2262 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2264 int write, void *data)
2267 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2269 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2275 lval = (unsigned long)-val;
2278 lval = (unsigned long)val;
2280 *lvalp = jiffies_to_clock_t(lval);
2285 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2287 int write, void *data)
2290 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2296 lval = (unsigned long)-val;
2299 lval = (unsigned long)val;
2301 *lvalp = jiffies_to_msecs(lval);
2307 * proc_dointvec_jiffies - read a vector of integers as seconds
2308 * @table: the sysctl table
2309 * @write: %TRUE if this is a write to the sysctl file
2310 * @buffer: the user buffer
2311 * @lenp: the size of the user buffer
2312 * @ppos: file position
2314 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2315 * values from/to the user buffer, treated as an ASCII string.
2316 * The values read are assumed to be in seconds, and are converted into
2319 * Returns 0 on success.
2321 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2322 void __user *buffer, size_t *lenp, loff_t *ppos)
2324 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2325 do_proc_dointvec_jiffies_conv,NULL);
2329 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2330 * @table: the sysctl table
2331 * @write: %TRUE if this is a write to the sysctl file
2332 * @buffer: the user buffer
2333 * @lenp: the size of the user buffer
2334 * @ppos: pointer to the file position
2336 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2337 * values from/to the user buffer, treated as an ASCII string.
2338 * The values read are assumed to be in 1/USER_HZ seconds, and
2339 * are converted into jiffies.
2341 * Returns 0 on success.
2343 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2344 void __user *buffer, size_t *lenp, loff_t *ppos)
2346 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2347 do_proc_dointvec_userhz_jiffies_conv,NULL);
2351 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2352 * @table: the sysctl table
2353 * @write: %TRUE if this is a write to the sysctl file
2354 * @buffer: the user buffer
2355 * @lenp: the size of the user buffer
2356 * @ppos: file position
2357 * @ppos: the current position in the file
2359 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2360 * values from/to the user buffer, treated as an ASCII string.
2361 * The values read are assumed to be in 1/1000 seconds, and
2362 * are converted into jiffies.
2364 * Returns 0 on success.
2366 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2367 void __user *buffer, size_t *lenp, loff_t *ppos)
2369 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2370 do_proc_dointvec_ms_jiffies_conv, NULL);
2373 static int proc_do_cad_pid(struct ctl_table *table, int write,
2374 void __user *buffer, size_t *lenp, loff_t *ppos)
2376 struct pid *new_pid;
2380 tmp = pid_vnr(cad_pid);
2382 r = __do_proc_dointvec(&tmp, table, write, buffer,
2383 lenp, ppos, NULL, NULL);
2387 new_pid = find_get_pid(tmp);
2391 put_pid(xchg(&cad_pid, new_pid));
2396 * proc_do_large_bitmap - read/write from/to a large bitmap
2397 * @table: the sysctl table
2398 * @write: %TRUE if this is a write to the sysctl file
2399 * @buffer: the user buffer
2400 * @lenp: the size of the user buffer
2401 * @ppos: file position
2403 * The bitmap is stored at table->data and the bitmap length (in bits)
2406 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2407 * large bitmaps may be represented in a compact manner. Writing into
2408 * the file will clear the bitmap then update it with the given input.
2410 * Returns 0 on success.
2412 int proc_do_large_bitmap(struct ctl_table *table, int write,
2413 void __user *buffer, size_t *lenp, loff_t *ppos)
2417 size_t left = *lenp;
2418 unsigned long bitmap_len = table->maxlen;
2419 unsigned long *bitmap = (unsigned long *) table->data;
2420 unsigned long *tmp_bitmap = NULL;
2421 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2423 if (!bitmap_len || !left || (*ppos && !write)) {
2429 unsigned long page = 0;
2432 if (left > PAGE_SIZE - 1)
2433 left = PAGE_SIZE - 1;
2435 page = __get_free_page(GFP_TEMPORARY);
2436 kbuf = (char *) page;
2439 if (copy_from_user(kbuf, buffer, left)) {
2445 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2451 proc_skip_char(&kbuf, &left, '\n');
2452 while (!err && left) {
2453 unsigned long val_a, val_b;
2456 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2460 if (val_a >= bitmap_len || neg) {
2472 err = proc_get_long(&kbuf, &left, &val_b,
2473 &neg, tr_b, sizeof(tr_b),
2477 if (val_b >= bitmap_len || neg ||
2488 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2490 proc_skip_char(&kbuf, &left, '\n');
2494 unsigned long bit_a, bit_b = 0;
2497 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2498 if (bit_a >= bitmap_len)
2500 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2504 err = proc_put_char(&buffer, &left, ',');
2508 err = proc_put_long(&buffer, &left, bit_a, false);
2511 if (bit_a != bit_b) {
2512 err = proc_put_char(&buffer, &left, '-');
2515 err = proc_put_long(&buffer, &left, bit_b, false);
2523 err = proc_put_char(&buffer, &left, '\n');
2529 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2531 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2543 #else /* CONFIG_PROC_SYSCTL */
2545 int proc_dostring(struct ctl_table *table, int write,
2546 void __user *buffer, size_t *lenp, loff_t *ppos)
2551 int proc_dointvec(struct ctl_table *table, int write,
2552 void __user *buffer, size_t *lenp, loff_t *ppos)
2557 int proc_dointvec_minmax(struct ctl_table *table, int write,
2558 void __user *buffer, size_t *lenp, loff_t *ppos)
2563 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2564 void __user *buffer, size_t *lenp, loff_t *ppos)
2569 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2570 void __user *buffer, size_t *lenp, loff_t *ppos)
2575 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2576 void __user *buffer, size_t *lenp, loff_t *ppos)
2581 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2582 void __user *buffer, size_t *lenp, loff_t *ppos)
2587 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2588 void __user *buffer,
2589 size_t *lenp, loff_t *ppos)
2595 #endif /* CONFIG_PROC_SYSCTL */
2598 * No sense putting this after each symbol definition, twice,
2599 * exception granted :-)
2601 EXPORT_SYMBOL(proc_dointvec);
2602 EXPORT_SYMBOL(proc_dointvec_jiffies);
2603 EXPORT_SYMBOL(proc_dointvec_minmax);
2604 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2605 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2606 EXPORT_SYMBOL(proc_dostring);
2607 EXPORT_SYMBOL(proc_doulongvec_minmax);
2608 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);