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 core_uses_pid;
101 extern int suid_dumpable;
102 extern char core_pattern[];
103 extern unsigned int core_pipe_limit;
105 extern int min_free_kbytes;
106 extern int pid_max_min, pid_max_max;
107 extern int sysctl_drop_caches;
108 extern int percpu_pagelist_fraction;
109 extern int compat_log;
110 extern int latencytop_enabled;
111 extern int sysctl_nr_open_min, sysctl_nr_open_max;
113 extern int sysctl_nr_trim_pages;
116 extern int blk_iopoll_enabled;
119 /* Constants used for minimum and maximum */
120 #ifdef CONFIG_LOCKUP_DETECTOR
121 static int sixty = 60;
122 static int neg_one = -1;
126 static int __maybe_unused one = 1;
127 static int __maybe_unused two = 2;
128 static int __maybe_unused three = 3;
129 static unsigned long one_ul = 1;
130 static int one_hundred = 100;
132 static int ten_thousand = 10000;
135 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
136 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
138 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
139 static int maxolduid = 65535;
140 static int minolduid;
141 static int min_percpu_pagelist_fract = 8;
143 static int ngroups_max = NGROUPS_MAX;
144 static const int cap_last_cap = CAP_LAST_CAP;
146 #ifdef CONFIG_INOTIFY_USER
147 #include <linux/inotify.h>
152 #ifdef CONFIG_SPARC64
153 extern int sysctl_tsb_ratio;
157 extern int pwrsw_enabled;
158 extern int unaligned_enabled;
162 extern int no_unaligned_warning;
163 extern int unaligned_dump_stack;
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
169 static int proc_taint(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
174 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
175 void __user *buffer, size_t *lenp, loff_t *ppos);
178 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
179 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_dostring_coredump(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
183 #ifdef CONFIG_MAGIC_SYSRQ
184 /* Note: sysrq code uses it's own private copy */
185 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
187 static int sysrq_sysctl_handler(ctl_table *table, int write,
188 void __user *buffer, size_t *lenp,
193 error = proc_dointvec(table, write, buffer, lenp, ppos);
198 sysrq_toggle_support(__sysrq_enabled);
205 static struct ctl_table kern_table[];
206 static struct ctl_table vm_table[];
207 static struct ctl_table fs_table[];
208 static struct ctl_table debug_table[];
209 static struct ctl_table dev_table[];
210 extern struct ctl_table random_table[];
212 extern struct ctl_table epoll_table[];
215 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
216 int sysctl_legacy_va_layout;
219 /* The default sysctl tables: */
221 static struct ctl_table sysctl_base_table[] = {
223 .procname = "kernel",
240 .child = debug_table,
250 #ifdef CONFIG_SCHED_DEBUG
251 static int min_sched_granularity_ns = 100000; /* 100 usecs */
252 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
253 static int min_wakeup_granularity_ns; /* 0 usecs */
254 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
255 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
256 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
259 #ifdef CONFIG_COMPACTION
260 static int min_extfrag_threshold;
261 static int max_extfrag_threshold = 1000;
264 static struct ctl_table kern_table[] = {
266 .procname = "sched_child_runs_first",
267 .data = &sysctl_sched_child_runs_first,
268 .maxlen = sizeof(unsigned int),
270 .proc_handler = proc_dointvec,
272 #ifdef CONFIG_SCHED_DEBUG
274 .procname = "sched_min_granularity_ns",
275 .data = &sysctl_sched_min_granularity,
276 .maxlen = sizeof(unsigned int),
278 .proc_handler = sched_proc_update_handler,
279 .extra1 = &min_sched_granularity_ns,
280 .extra2 = &max_sched_granularity_ns,
283 .procname = "sched_latency_ns",
284 .data = &sysctl_sched_latency,
285 .maxlen = sizeof(unsigned int),
287 .proc_handler = sched_proc_update_handler,
288 .extra1 = &min_sched_granularity_ns,
289 .extra2 = &max_sched_granularity_ns,
292 .procname = "sched_wakeup_granularity_ns",
293 .data = &sysctl_sched_wakeup_granularity,
294 .maxlen = sizeof(unsigned int),
296 .proc_handler = sched_proc_update_handler,
297 .extra1 = &min_wakeup_granularity_ns,
298 .extra2 = &max_wakeup_granularity_ns,
301 .procname = "sched_tunable_scaling",
302 .data = &sysctl_sched_tunable_scaling,
303 .maxlen = sizeof(enum sched_tunable_scaling),
305 .proc_handler = sched_proc_update_handler,
306 .extra1 = &min_sched_tunable_scaling,
307 .extra2 = &max_sched_tunable_scaling,
310 .procname = "sched_migration_cost",
311 .data = &sysctl_sched_migration_cost,
312 .maxlen = sizeof(unsigned int),
314 .proc_handler = proc_dointvec,
317 .procname = "sched_nr_migrate",
318 .data = &sysctl_sched_nr_migrate,
319 .maxlen = sizeof(unsigned int),
321 .proc_handler = proc_dointvec,
324 .procname = "sched_time_avg",
325 .data = &sysctl_sched_time_avg,
326 .maxlen = sizeof(unsigned int),
328 .proc_handler = proc_dointvec,
331 .procname = "sched_shares_window",
332 .data = &sysctl_sched_shares_window,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = proc_dointvec,
338 .procname = "timer_migration",
339 .data = &sysctl_timer_migration,
340 .maxlen = sizeof(unsigned int),
342 .proc_handler = proc_dointvec_minmax,
348 .procname = "sched_rt_period_us",
349 .data = &sysctl_sched_rt_period,
350 .maxlen = sizeof(unsigned int),
352 .proc_handler = sched_rt_handler,
355 .procname = "sched_rt_runtime_us",
356 .data = &sysctl_sched_rt_runtime,
357 .maxlen = sizeof(int),
359 .proc_handler = sched_rt_handler,
361 #ifdef CONFIG_SCHED_AUTOGROUP
363 .procname = "sched_autogroup_enabled",
364 .data = &sysctl_sched_autogroup_enabled,
365 .maxlen = sizeof(unsigned int),
367 .proc_handler = proc_dointvec_minmax,
372 #ifdef CONFIG_CFS_BANDWIDTH
374 .procname = "sched_cfs_bandwidth_slice_us",
375 .data = &sysctl_sched_cfs_bandwidth_slice,
376 .maxlen = sizeof(unsigned int),
378 .proc_handler = proc_dointvec_minmax,
382 #ifdef CONFIG_PROVE_LOCKING
384 .procname = "prove_locking",
385 .data = &prove_locking,
386 .maxlen = sizeof(int),
388 .proc_handler = proc_dointvec,
391 #ifdef CONFIG_LOCK_STAT
393 .procname = "lock_stat",
395 .maxlen = sizeof(int),
397 .proc_handler = proc_dointvec,
402 .data = &panic_timeout,
403 .maxlen = sizeof(int),
405 .proc_handler = proc_dointvec,
408 .procname = "core_uses_pid",
409 .data = &core_uses_pid,
410 .maxlen = sizeof(int),
412 .proc_handler = proc_dointvec,
415 .procname = "core_pattern",
416 .data = core_pattern,
417 .maxlen = CORENAME_MAX_SIZE,
419 .proc_handler = proc_dostring_coredump,
422 .procname = "core_pipe_limit",
423 .data = &core_pipe_limit,
424 .maxlen = sizeof(unsigned int),
426 .proc_handler = proc_dointvec,
428 #ifdef CONFIG_PROC_SYSCTL
430 .procname = "tainted",
431 .maxlen = sizeof(long),
433 .proc_handler = proc_taint,
436 #ifdef CONFIG_LATENCYTOP
438 .procname = "latencytop",
439 .data = &latencytop_enabled,
440 .maxlen = sizeof(int),
442 .proc_handler = proc_dointvec,
445 #ifdef CONFIG_BLK_DEV_INITRD
447 .procname = "real-root-dev",
448 .data = &real_root_dev,
449 .maxlen = sizeof(int),
451 .proc_handler = proc_dointvec,
455 .procname = "print-fatal-signals",
456 .data = &print_fatal_signals,
457 .maxlen = sizeof(int),
459 .proc_handler = proc_dointvec,
463 .procname = "reboot-cmd",
464 .data = reboot_command,
467 .proc_handler = proc_dostring,
470 .procname = "stop-a",
471 .data = &stop_a_enabled,
472 .maxlen = sizeof (int),
474 .proc_handler = proc_dointvec,
477 .procname = "scons-poweroff",
478 .data = &scons_pwroff,
479 .maxlen = sizeof (int),
481 .proc_handler = proc_dointvec,
484 #ifdef CONFIG_SPARC64
486 .procname = "tsb-ratio",
487 .data = &sysctl_tsb_ratio,
488 .maxlen = sizeof (int),
490 .proc_handler = proc_dointvec,
495 .procname = "soft-power",
496 .data = &pwrsw_enabled,
497 .maxlen = sizeof (int),
499 .proc_handler = proc_dointvec,
502 .procname = "unaligned-trap",
503 .data = &unaligned_enabled,
504 .maxlen = sizeof (int),
506 .proc_handler = proc_dointvec,
510 .procname = "ctrl-alt-del",
512 .maxlen = sizeof(int),
514 .proc_handler = proc_dointvec,
516 #ifdef CONFIG_FUNCTION_TRACER
518 .procname = "ftrace_enabled",
519 .data = &ftrace_enabled,
520 .maxlen = sizeof(int),
522 .proc_handler = ftrace_enable_sysctl,
525 #ifdef CONFIG_STACK_TRACER
527 .procname = "stack_tracer_enabled",
528 .data = &stack_tracer_enabled,
529 .maxlen = sizeof(int),
531 .proc_handler = stack_trace_sysctl,
534 #ifdef CONFIG_TRACING
536 .procname = "ftrace_dump_on_oops",
537 .data = &ftrace_dump_on_oops,
538 .maxlen = sizeof(int),
540 .proc_handler = proc_dointvec,
543 #ifdef CONFIG_MODULES
545 .procname = "modprobe",
546 .data = &modprobe_path,
547 .maxlen = KMOD_PATH_LEN,
549 .proc_handler = proc_dostring,
552 .procname = "modules_disabled",
553 .data = &modules_disabled,
554 .maxlen = sizeof(int),
556 /* only handle a transition from default "0" to "1" */
557 .proc_handler = proc_dointvec_minmax,
562 #ifdef CONFIG_HOTPLUG
564 .procname = "hotplug",
565 .data = &uevent_helper,
566 .maxlen = UEVENT_HELPER_PATH_LEN,
568 .proc_handler = proc_dostring,
571 #ifdef CONFIG_CHR_DEV_SG
573 .procname = "sg-big-buff",
574 .data = &sg_big_buff,
575 .maxlen = sizeof (int),
577 .proc_handler = proc_dointvec,
580 #ifdef CONFIG_BSD_PROCESS_ACCT
584 .maxlen = 3*sizeof(int),
586 .proc_handler = proc_dointvec,
589 #ifdef CONFIG_MAGIC_SYSRQ
592 .data = &__sysrq_enabled,
593 .maxlen = sizeof (int),
595 .proc_handler = sysrq_sysctl_handler,
598 #ifdef CONFIG_PROC_SYSCTL
600 .procname = "cad_pid",
602 .maxlen = sizeof (int),
604 .proc_handler = proc_do_cad_pid,
608 .procname = "threads-max",
609 .data = &max_threads,
610 .maxlen = sizeof(int),
612 .proc_handler = proc_dointvec,
615 .procname = "random",
617 .child = random_table,
620 .procname = "usermodehelper",
622 .child = usermodehelper_table,
625 .procname = "overflowuid",
626 .data = &overflowuid,
627 .maxlen = sizeof(int),
629 .proc_handler = proc_dointvec_minmax,
630 .extra1 = &minolduid,
631 .extra2 = &maxolduid,
634 .procname = "overflowgid",
635 .data = &overflowgid,
636 .maxlen = sizeof(int),
638 .proc_handler = proc_dointvec_minmax,
639 .extra1 = &minolduid,
640 .extra2 = &maxolduid,
643 #ifdef CONFIG_MATHEMU
645 .procname = "ieee_emulation_warnings",
646 .data = &sysctl_ieee_emulation_warnings,
647 .maxlen = sizeof(int),
649 .proc_handler = proc_dointvec,
653 .procname = "userprocess_debug",
654 .data = &show_unhandled_signals,
655 .maxlen = sizeof(int),
657 .proc_handler = proc_dointvec,
661 .procname = "pid_max",
663 .maxlen = sizeof (int),
665 .proc_handler = proc_dointvec_minmax,
666 .extra1 = &pid_max_min,
667 .extra2 = &pid_max_max,
670 .procname = "panic_on_oops",
671 .data = &panic_on_oops,
672 .maxlen = sizeof(int),
674 .proc_handler = proc_dointvec,
676 #if defined CONFIG_PRINTK
678 .procname = "printk",
679 .data = &console_loglevel,
680 .maxlen = 4*sizeof(int),
682 .proc_handler = proc_dointvec,
685 .procname = "printk_ratelimit",
686 .data = &printk_ratelimit_state.interval,
687 .maxlen = sizeof(int),
689 .proc_handler = proc_dointvec_jiffies,
692 .procname = "printk_ratelimit_burst",
693 .data = &printk_ratelimit_state.burst,
694 .maxlen = sizeof(int),
696 .proc_handler = proc_dointvec,
699 .procname = "printk_delay",
700 .data = &printk_delay_msec,
701 .maxlen = sizeof(int),
703 .proc_handler = proc_dointvec_minmax,
705 .extra2 = &ten_thousand,
708 .procname = "dmesg_restrict",
709 .data = &dmesg_restrict,
710 .maxlen = sizeof(int),
712 .proc_handler = proc_dointvec_minmax_sysadmin,
717 .procname = "kptr_restrict",
718 .data = &kptr_restrict,
719 .maxlen = sizeof(int),
721 .proc_handler = proc_dointvec_minmax_sysadmin,
727 .procname = "ngroups_max",
728 .data = &ngroups_max,
729 .maxlen = sizeof (int),
731 .proc_handler = proc_dointvec,
734 .procname = "cap_last_cap",
735 .data = (void *)&cap_last_cap,
736 .maxlen = sizeof(int),
738 .proc_handler = proc_dointvec,
740 #if defined(CONFIG_LOCKUP_DETECTOR)
742 .procname = "watchdog",
743 .data = &watchdog_enabled,
744 .maxlen = sizeof (int),
746 .proc_handler = proc_dowatchdog,
751 .procname = "watchdog_thresh",
752 .data = &watchdog_thresh,
753 .maxlen = sizeof(int),
755 .proc_handler = proc_dowatchdog,
760 .procname = "softlockup_panic",
761 .data = &softlockup_panic,
762 .maxlen = sizeof(int),
764 .proc_handler = proc_dointvec_minmax,
769 .procname = "nmi_watchdog",
770 .data = &watchdog_enabled,
771 .maxlen = sizeof (int),
773 .proc_handler = proc_dowatchdog,
778 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
780 .procname = "unknown_nmi_panic",
781 .data = &unknown_nmi_panic,
782 .maxlen = sizeof (int),
784 .proc_handler = proc_dointvec,
787 #if defined(CONFIG_X86)
789 .procname = "panic_on_unrecovered_nmi",
790 .data = &panic_on_unrecovered_nmi,
791 .maxlen = sizeof(int),
793 .proc_handler = proc_dointvec,
796 .procname = "panic_on_io_nmi",
797 .data = &panic_on_io_nmi,
798 .maxlen = sizeof(int),
800 .proc_handler = proc_dointvec,
802 #ifdef CONFIG_DEBUG_STACKOVERFLOW
804 .procname = "panic_on_stackoverflow",
805 .data = &sysctl_panic_on_stackoverflow,
806 .maxlen = sizeof(int),
808 .proc_handler = proc_dointvec,
812 .procname = "bootloader_type",
813 .data = &bootloader_type,
814 .maxlen = sizeof (int),
816 .proc_handler = proc_dointvec,
819 .procname = "bootloader_version",
820 .data = &bootloader_version,
821 .maxlen = sizeof (int),
823 .proc_handler = proc_dointvec,
826 .procname = "kstack_depth_to_print",
827 .data = &kstack_depth_to_print,
828 .maxlen = sizeof(int),
830 .proc_handler = proc_dointvec,
833 .procname = "io_delay_type",
834 .data = &io_delay_type,
835 .maxlen = sizeof(int),
837 .proc_handler = proc_dointvec,
840 #if defined(CONFIG_MMU)
842 .procname = "randomize_va_space",
843 .data = &randomize_va_space,
844 .maxlen = sizeof(int),
846 .proc_handler = proc_dointvec,
849 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
851 .procname = "spin_retry",
853 .maxlen = sizeof (int),
855 .proc_handler = proc_dointvec,
858 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
860 .procname = "acpi_video_flags",
861 .data = &acpi_realmode_flags,
862 .maxlen = sizeof (unsigned long),
864 .proc_handler = proc_doulongvec_minmax,
869 .procname = "ignore-unaligned-usertrap",
870 .data = &no_unaligned_warning,
871 .maxlen = sizeof (int),
873 .proc_handler = proc_dointvec,
876 .procname = "unaligned-dump-stack",
877 .data = &unaligned_dump_stack,
878 .maxlen = sizeof (int),
880 .proc_handler = proc_dointvec,
883 #ifdef CONFIG_DETECT_HUNG_TASK
885 .procname = "hung_task_panic",
886 .data = &sysctl_hung_task_panic,
887 .maxlen = sizeof(int),
889 .proc_handler = proc_dointvec_minmax,
894 .procname = "hung_task_check_count",
895 .data = &sysctl_hung_task_check_count,
896 .maxlen = sizeof(unsigned long),
898 .proc_handler = proc_doulongvec_minmax,
901 .procname = "hung_task_timeout_secs",
902 .data = &sysctl_hung_task_timeout_secs,
903 .maxlen = sizeof(unsigned long),
905 .proc_handler = proc_dohung_task_timeout_secs,
908 .procname = "hung_task_warnings",
909 .data = &sysctl_hung_task_warnings,
910 .maxlen = sizeof(unsigned long),
912 .proc_handler = proc_doulongvec_minmax,
917 .procname = "compat-log",
919 .maxlen = sizeof (int),
921 .proc_handler = proc_dointvec,
924 #ifdef CONFIG_RT_MUTEXES
926 .procname = "max_lock_depth",
927 .data = &max_lock_depth,
928 .maxlen = sizeof(int),
930 .proc_handler = proc_dointvec,
934 .procname = "poweroff_cmd",
935 .data = &poweroff_cmd,
936 .maxlen = POWEROFF_CMD_PATH_LEN,
938 .proc_handler = proc_dostring,
944 .child = key_sysctls,
947 #ifdef CONFIG_RCU_TORTURE_TEST
949 .procname = "rcutorture_runnable",
950 .data = &rcutorture_runnable,
951 .maxlen = sizeof(int),
953 .proc_handler = proc_dointvec,
956 #ifdef CONFIG_PERF_EVENTS
958 * User-space scripts rely on the existence of this file
959 * as a feature check for perf_events being enabled.
961 * So it's an ABI, do not remove!
964 .procname = "perf_event_paranoid",
965 .data = &sysctl_perf_event_paranoid,
966 .maxlen = sizeof(sysctl_perf_event_paranoid),
968 .proc_handler = proc_dointvec,
971 .procname = "perf_event_mlock_kb",
972 .data = &sysctl_perf_event_mlock,
973 .maxlen = sizeof(sysctl_perf_event_mlock),
975 .proc_handler = proc_dointvec,
978 .procname = "perf_event_max_sample_rate",
979 .data = &sysctl_perf_event_sample_rate,
980 .maxlen = sizeof(sysctl_perf_event_sample_rate),
982 .proc_handler = perf_proc_update_handler,
985 #ifdef CONFIG_KMEMCHECK
987 .procname = "kmemcheck",
988 .data = &kmemcheck_enabled,
989 .maxlen = sizeof(int),
991 .proc_handler = proc_dointvec,
996 .procname = "blk_iopoll",
997 .data = &blk_iopoll_enabled,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec,
1006 static struct ctl_table vm_table[] = {
1008 .procname = "overcommit_memory",
1009 .data = &sysctl_overcommit_memory,
1010 .maxlen = sizeof(sysctl_overcommit_memory),
1012 .proc_handler = proc_dointvec_minmax,
1017 .procname = "panic_on_oom",
1018 .data = &sysctl_panic_on_oom,
1019 .maxlen = sizeof(sysctl_panic_on_oom),
1021 .proc_handler = proc_dointvec_minmax,
1026 .procname = "oom_kill_allocating_task",
1027 .data = &sysctl_oom_kill_allocating_task,
1028 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1030 .proc_handler = proc_dointvec,
1033 .procname = "oom_dump_tasks",
1034 .data = &sysctl_oom_dump_tasks,
1035 .maxlen = sizeof(sysctl_oom_dump_tasks),
1037 .proc_handler = proc_dointvec,
1040 .procname = "overcommit_ratio",
1041 .data = &sysctl_overcommit_ratio,
1042 .maxlen = sizeof(sysctl_overcommit_ratio),
1044 .proc_handler = proc_dointvec,
1047 .procname = "page-cluster",
1048 .data = &page_cluster,
1049 .maxlen = sizeof(int),
1051 .proc_handler = proc_dointvec_minmax,
1055 .procname = "dirty_background_ratio",
1056 .data = &dirty_background_ratio,
1057 .maxlen = sizeof(dirty_background_ratio),
1059 .proc_handler = dirty_background_ratio_handler,
1061 .extra2 = &one_hundred,
1064 .procname = "dirty_background_bytes",
1065 .data = &dirty_background_bytes,
1066 .maxlen = sizeof(dirty_background_bytes),
1068 .proc_handler = dirty_background_bytes_handler,
1072 .procname = "dirty_ratio",
1073 .data = &vm_dirty_ratio,
1074 .maxlen = sizeof(vm_dirty_ratio),
1076 .proc_handler = dirty_ratio_handler,
1078 .extra2 = &one_hundred,
1081 .procname = "dirty_bytes",
1082 .data = &vm_dirty_bytes,
1083 .maxlen = sizeof(vm_dirty_bytes),
1085 .proc_handler = dirty_bytes_handler,
1086 .extra1 = &dirty_bytes_min,
1089 .procname = "dirty_writeback_centisecs",
1090 .data = &dirty_writeback_interval,
1091 .maxlen = sizeof(dirty_writeback_interval),
1093 .proc_handler = dirty_writeback_centisecs_handler,
1096 .procname = "dirty_expire_centisecs",
1097 .data = &dirty_expire_interval,
1098 .maxlen = sizeof(dirty_expire_interval),
1100 .proc_handler = proc_dointvec_minmax,
1104 .procname = "nr_pdflush_threads",
1105 .data = &nr_pdflush_threads,
1106 .maxlen = sizeof nr_pdflush_threads,
1107 .mode = 0444 /* read-only*/,
1108 .proc_handler = proc_dointvec,
1111 .procname = "swappiness",
1112 .data = &vm_swappiness,
1113 .maxlen = sizeof(vm_swappiness),
1115 .proc_handler = proc_dointvec_minmax,
1117 .extra2 = &one_hundred,
1119 #ifdef CONFIG_HUGETLB_PAGE
1121 .procname = "nr_hugepages",
1123 .maxlen = sizeof(unsigned long),
1125 .proc_handler = hugetlb_sysctl_handler,
1126 .extra1 = (void *)&hugetlb_zero,
1127 .extra2 = (void *)&hugetlb_infinity,
1131 .procname = "nr_hugepages_mempolicy",
1133 .maxlen = sizeof(unsigned long),
1135 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1136 .extra1 = (void *)&hugetlb_zero,
1137 .extra2 = (void *)&hugetlb_infinity,
1141 .procname = "hugetlb_shm_group",
1142 .data = &sysctl_hugetlb_shm_group,
1143 .maxlen = sizeof(gid_t),
1145 .proc_handler = proc_dointvec,
1148 .procname = "hugepages_treat_as_movable",
1149 .data = &hugepages_treat_as_movable,
1150 .maxlen = sizeof(int),
1152 .proc_handler = hugetlb_treat_movable_handler,
1155 .procname = "nr_overcommit_hugepages",
1157 .maxlen = sizeof(unsigned long),
1159 .proc_handler = hugetlb_overcommit_handler,
1160 .extra1 = (void *)&hugetlb_zero,
1161 .extra2 = (void *)&hugetlb_infinity,
1165 .procname = "lowmem_reserve_ratio",
1166 .data = &sysctl_lowmem_reserve_ratio,
1167 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1169 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1172 .procname = "drop_caches",
1173 .data = &sysctl_drop_caches,
1174 .maxlen = sizeof(int),
1176 .proc_handler = drop_caches_sysctl_handler,
1180 #ifdef CONFIG_COMPACTION
1182 .procname = "compact_memory",
1183 .data = &sysctl_compact_memory,
1184 .maxlen = sizeof(int),
1186 .proc_handler = sysctl_compaction_handler,
1189 .procname = "extfrag_threshold",
1190 .data = &sysctl_extfrag_threshold,
1191 .maxlen = sizeof(int),
1193 .proc_handler = sysctl_extfrag_handler,
1194 .extra1 = &min_extfrag_threshold,
1195 .extra2 = &max_extfrag_threshold,
1198 #endif /* CONFIG_COMPACTION */
1200 .procname = "min_free_kbytes",
1201 .data = &min_free_kbytes,
1202 .maxlen = sizeof(min_free_kbytes),
1204 .proc_handler = min_free_kbytes_sysctl_handler,
1208 .procname = "percpu_pagelist_fraction",
1209 .data = &percpu_pagelist_fraction,
1210 .maxlen = sizeof(percpu_pagelist_fraction),
1212 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1213 .extra1 = &min_percpu_pagelist_fract,
1217 .procname = "max_map_count",
1218 .data = &sysctl_max_map_count,
1219 .maxlen = sizeof(sysctl_max_map_count),
1221 .proc_handler = proc_dointvec_minmax,
1226 .procname = "nr_trim_pages",
1227 .data = &sysctl_nr_trim_pages,
1228 .maxlen = sizeof(sysctl_nr_trim_pages),
1230 .proc_handler = proc_dointvec_minmax,
1235 .procname = "laptop_mode",
1236 .data = &laptop_mode,
1237 .maxlen = sizeof(laptop_mode),
1239 .proc_handler = proc_dointvec_jiffies,
1242 .procname = "block_dump",
1243 .data = &block_dump,
1244 .maxlen = sizeof(block_dump),
1246 .proc_handler = proc_dointvec,
1250 .procname = "vfs_cache_pressure",
1251 .data = &sysctl_vfs_cache_pressure,
1252 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1254 .proc_handler = proc_dointvec,
1257 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1259 .procname = "legacy_va_layout",
1260 .data = &sysctl_legacy_va_layout,
1261 .maxlen = sizeof(sysctl_legacy_va_layout),
1263 .proc_handler = proc_dointvec,
1269 .procname = "zone_reclaim_mode",
1270 .data = &zone_reclaim_mode,
1271 .maxlen = sizeof(zone_reclaim_mode),
1273 .proc_handler = proc_dointvec,
1277 .procname = "min_unmapped_ratio",
1278 .data = &sysctl_min_unmapped_ratio,
1279 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1281 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1283 .extra2 = &one_hundred,
1286 .procname = "min_slab_ratio",
1287 .data = &sysctl_min_slab_ratio,
1288 .maxlen = sizeof(sysctl_min_slab_ratio),
1290 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1292 .extra2 = &one_hundred,
1297 .procname = "stat_interval",
1298 .data = &sysctl_stat_interval,
1299 .maxlen = sizeof(sysctl_stat_interval),
1301 .proc_handler = proc_dointvec_jiffies,
1306 .procname = "mmap_min_addr",
1307 .data = &dac_mmap_min_addr,
1308 .maxlen = sizeof(unsigned long),
1310 .proc_handler = mmap_min_addr_handler,
1315 .procname = "numa_zonelist_order",
1316 .data = &numa_zonelist_order,
1317 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1319 .proc_handler = numa_zonelist_order_handler,
1322 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1323 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1325 .procname = "vdso_enabled",
1326 .data = &vdso_enabled,
1327 .maxlen = sizeof(vdso_enabled),
1329 .proc_handler = proc_dointvec,
1333 #ifdef CONFIG_HIGHMEM
1335 .procname = "highmem_is_dirtyable",
1336 .data = &vm_highmem_is_dirtyable,
1337 .maxlen = sizeof(vm_highmem_is_dirtyable),
1339 .proc_handler = proc_dointvec_minmax,
1345 .procname = "scan_unevictable_pages",
1346 .data = &scan_unevictable_pages,
1347 .maxlen = sizeof(scan_unevictable_pages),
1349 .proc_handler = scan_unevictable_handler,
1351 #ifdef CONFIG_MEMORY_FAILURE
1353 .procname = "memory_failure_early_kill",
1354 .data = &sysctl_memory_failure_early_kill,
1355 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1357 .proc_handler = proc_dointvec_minmax,
1362 .procname = "memory_failure_recovery",
1363 .data = &sysctl_memory_failure_recovery,
1364 .maxlen = sizeof(sysctl_memory_failure_recovery),
1366 .proc_handler = proc_dointvec_minmax,
1374 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1375 static struct ctl_table binfmt_misc_table[] = {
1380 static struct ctl_table fs_table[] = {
1382 .procname = "inode-nr",
1383 .data = &inodes_stat,
1384 .maxlen = 2*sizeof(int),
1386 .proc_handler = proc_nr_inodes,
1389 .procname = "inode-state",
1390 .data = &inodes_stat,
1391 .maxlen = 7*sizeof(int),
1393 .proc_handler = proc_nr_inodes,
1396 .procname = "file-nr",
1397 .data = &files_stat,
1398 .maxlen = sizeof(files_stat),
1400 .proc_handler = proc_nr_files,
1403 .procname = "file-max",
1404 .data = &files_stat.max_files,
1405 .maxlen = sizeof(files_stat.max_files),
1407 .proc_handler = proc_doulongvec_minmax,
1410 .procname = "nr_open",
1411 .data = &sysctl_nr_open,
1412 .maxlen = sizeof(int),
1414 .proc_handler = proc_dointvec_minmax,
1415 .extra1 = &sysctl_nr_open_min,
1416 .extra2 = &sysctl_nr_open_max,
1419 .procname = "dentry-state",
1420 .data = &dentry_stat,
1421 .maxlen = 6*sizeof(int),
1423 .proc_handler = proc_nr_dentry,
1426 .procname = "overflowuid",
1427 .data = &fs_overflowuid,
1428 .maxlen = sizeof(int),
1430 .proc_handler = proc_dointvec_minmax,
1431 .extra1 = &minolduid,
1432 .extra2 = &maxolduid,
1435 .procname = "overflowgid",
1436 .data = &fs_overflowgid,
1437 .maxlen = sizeof(int),
1439 .proc_handler = proc_dointvec_minmax,
1440 .extra1 = &minolduid,
1441 .extra2 = &maxolduid,
1443 #ifdef CONFIG_FILE_LOCKING
1445 .procname = "leases-enable",
1446 .data = &leases_enable,
1447 .maxlen = sizeof(int),
1449 .proc_handler = proc_dointvec,
1452 #ifdef CONFIG_DNOTIFY
1454 .procname = "dir-notify-enable",
1455 .data = &dir_notify_enable,
1456 .maxlen = sizeof(int),
1458 .proc_handler = proc_dointvec,
1462 #ifdef CONFIG_FILE_LOCKING
1464 .procname = "lease-break-time",
1465 .data = &lease_break_time,
1466 .maxlen = sizeof(int),
1468 .proc_handler = proc_dointvec,
1473 .procname = "aio-nr",
1475 .maxlen = sizeof(aio_nr),
1477 .proc_handler = proc_doulongvec_minmax,
1480 .procname = "aio-max-nr",
1481 .data = &aio_max_nr,
1482 .maxlen = sizeof(aio_max_nr),
1484 .proc_handler = proc_doulongvec_minmax,
1486 #endif /* CONFIG_AIO */
1487 #ifdef CONFIG_INOTIFY_USER
1489 .procname = "inotify",
1491 .child = inotify_table,
1496 .procname = "epoll",
1498 .child = epoll_table,
1503 .procname = "suid_dumpable",
1504 .data = &suid_dumpable,
1505 .maxlen = sizeof(int),
1507 .proc_handler = proc_dointvec_minmax_coredump,
1511 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1513 .procname = "binfmt_misc",
1515 .child = binfmt_misc_table,
1519 .procname = "pipe-max-size",
1520 .data = &pipe_max_size,
1521 .maxlen = sizeof(int),
1523 .proc_handler = &pipe_proc_fn,
1524 .extra1 = &pipe_min_size,
1529 static struct ctl_table debug_table[] = {
1530 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1531 defined(CONFIG_S390) || defined(CONFIG_TILE)
1533 .procname = "exception-trace",
1534 .data = &show_unhandled_signals,
1535 .maxlen = sizeof(int),
1537 .proc_handler = proc_dointvec
1540 #if defined(CONFIG_OPTPROBES)
1542 .procname = "kprobes-optimization",
1543 .data = &sysctl_kprobes_optimization,
1544 .maxlen = sizeof(int),
1546 .proc_handler = proc_kprobes_optimization_handler,
1554 static struct ctl_table dev_table[] = {
1558 int __init sysctl_init(void)
1560 struct ctl_table_header *hdr;
1562 hdr = register_sysctl_table(sysctl_base_table);
1563 kmemleak_not_leak(hdr);
1567 #endif /* CONFIG_SYSCTL */
1573 #ifdef CONFIG_PROC_SYSCTL
1575 static int _proc_do_string(void* data, int maxlen, int write,
1576 void __user *buffer,
1577 size_t *lenp, loff_t *ppos)
1583 if (!data || !maxlen || !*lenp) {
1591 while (len < *lenp) {
1592 if (get_user(c, p++))
1594 if (c == 0 || c == '\n')
1600 if(copy_from_user(data, buffer, len))
1602 ((char *) data)[len] = 0;
1620 if(copy_to_user(buffer, data, len))
1623 if(put_user('\n', ((char __user *) buffer) + len))
1634 * proc_dostring - read a string sysctl
1635 * @table: the sysctl table
1636 * @write: %TRUE if this is a write to the sysctl file
1637 * @buffer: the user buffer
1638 * @lenp: the size of the user buffer
1639 * @ppos: file position
1641 * Reads/writes a string from/to the user buffer. If the kernel
1642 * buffer provided is not large enough to hold the string, the
1643 * string is truncated. The copied string is %NULL-terminated.
1644 * If the string is being read by the user process, it is copied
1645 * and a newline '\n' is added. It is truncated if the buffer is
1648 * Returns 0 on success.
1650 int proc_dostring(struct ctl_table *table, int write,
1651 void __user *buffer, size_t *lenp, loff_t *ppos)
1653 return _proc_do_string(table->data, table->maxlen, write,
1654 buffer, lenp, ppos);
1657 static size_t proc_skip_spaces(char **buf)
1660 char *tmp = skip_spaces(*buf);
1666 static void proc_skip_char(char **buf, size_t *size, const char v)
1676 #define TMPBUFLEN 22
1678 * proc_get_long - reads an ASCII formatted integer from a user buffer
1680 * @buf: a kernel buffer
1681 * @size: size of the kernel buffer
1682 * @val: this is where the number will be stored
1683 * @neg: set to %TRUE if number is negative
1684 * @perm_tr: a vector which contains the allowed trailers
1685 * @perm_tr_len: size of the perm_tr vector
1686 * @tr: pointer to store the trailer character
1688 * In case of success %0 is returned and @buf and @size are updated with
1689 * the amount of bytes read. If @tr is non-NULL and a trailing
1690 * character exists (size is non-zero after returning from this
1691 * function), @tr is updated with the trailing character.
1693 static int proc_get_long(char **buf, size_t *size,
1694 unsigned long *val, bool *neg,
1695 const char *perm_tr, unsigned perm_tr_len, char *tr)
1698 char *p, tmp[TMPBUFLEN];
1704 if (len > TMPBUFLEN - 1)
1705 len = TMPBUFLEN - 1;
1707 memcpy(tmp, *buf, len);
1711 if (*p == '-' && *size > 1) {
1719 *val = simple_strtoul(p, &p, 0);
1723 /* We don't know if the next char is whitespace thus we may accept
1724 * invalid integers (e.g. 1234...a) or two integers instead of one
1725 * (e.g. 123...1). So lets not allow such large numbers. */
1726 if (len == TMPBUFLEN - 1)
1729 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1732 if (tr && (len < *size))
1742 * proc_put_long - converts an integer to a decimal ASCII formatted string
1744 * @buf: the user buffer
1745 * @size: the size of the user buffer
1746 * @val: the integer to be converted
1747 * @neg: sign of the number, %TRUE for negative
1749 * In case of success %0 is returned and @buf and @size are updated with
1750 * the amount of bytes written.
1752 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1756 char tmp[TMPBUFLEN], *p = tmp;
1758 sprintf(p, "%s%lu", neg ? "-" : "", val);
1762 if (copy_to_user(*buf, tmp, len))
1770 static int proc_put_char(void __user **buf, size_t *size, char c)
1773 char __user **buffer = (char __user **)buf;
1774 if (put_user(c, *buffer))
1776 (*size)--, (*buffer)++;
1782 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1784 int write, void *data)
1787 *valp = *negp ? -*lvalp : *lvalp;
1792 *lvalp = (unsigned long)-val;
1795 *lvalp = (unsigned long)val;
1801 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1803 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1804 int write, void __user *buffer,
1805 size_t *lenp, loff_t *ppos,
1806 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1807 int write, void *data),
1810 int *i, vleft, first = 1, err = 0;
1811 unsigned long page = 0;
1815 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1820 i = (int *) tbl_data;
1821 vleft = table->maxlen / sizeof(*i);
1825 conv = do_proc_dointvec_conv;
1828 if (left > PAGE_SIZE - 1)
1829 left = PAGE_SIZE - 1;
1830 page = __get_free_page(GFP_TEMPORARY);
1831 kbuf = (char *) page;
1834 if (copy_from_user(kbuf, buffer, left)) {
1841 for (; left && vleft--; i++, first=0) {
1846 left -= proc_skip_spaces(&kbuf);
1850 err = proc_get_long(&kbuf, &left, &lval, &neg,
1852 sizeof(proc_wspace_sep), NULL);
1855 if (conv(&neg, &lval, i, 1, data)) {
1860 if (conv(&neg, &lval, i, 0, data)) {
1865 err = proc_put_char(&buffer, &left, '\t');
1868 err = proc_put_long(&buffer, &left, lval, neg);
1874 if (!write && !first && left && !err)
1875 err = proc_put_char(&buffer, &left, '\n');
1876 if (write && !err && left)
1877 left -= proc_skip_spaces(&kbuf);
1882 return err ? : -EINVAL;
1889 static int do_proc_dointvec(struct ctl_table *table, int write,
1890 void __user *buffer, size_t *lenp, loff_t *ppos,
1891 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1892 int write, void *data),
1895 return __do_proc_dointvec(table->data, table, write,
1896 buffer, lenp, ppos, conv, data);
1900 * proc_dointvec - read a vector of integers
1901 * @table: the sysctl table
1902 * @write: %TRUE if this is a write to the sysctl file
1903 * @buffer: the user buffer
1904 * @lenp: the size of the user buffer
1905 * @ppos: file position
1907 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1908 * values from/to the user buffer, treated as an ASCII string.
1910 * Returns 0 on success.
1912 int proc_dointvec(struct ctl_table *table, int write,
1913 void __user *buffer, size_t *lenp, loff_t *ppos)
1915 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1920 * Taint values can only be increased
1921 * This means we can safely use a temporary.
1923 static int proc_taint(struct ctl_table *table, int write,
1924 void __user *buffer, size_t *lenp, loff_t *ppos)
1927 unsigned long tmptaint = get_taint();
1930 if (write && !capable(CAP_SYS_ADMIN))
1935 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
1941 * Poor man's atomic or. Not worth adding a primitive
1942 * to everyone's atomic.h for this
1945 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
1946 if ((tmptaint >> i) & 1)
1954 #ifdef CONFIG_PRINTK
1955 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
1956 void __user *buffer, size_t *lenp, loff_t *ppos)
1958 if (write && !capable(CAP_SYS_ADMIN))
1961 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1965 struct do_proc_dointvec_minmax_conv_param {
1970 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
1972 int write, void *data)
1974 struct do_proc_dointvec_minmax_conv_param *param = data;
1976 int val = *negp ? -*lvalp : *lvalp;
1977 if ((param->min && *param->min > val) ||
1978 (param->max && *param->max < val))
1985 *lvalp = (unsigned long)-val;
1988 *lvalp = (unsigned long)val;
1995 * proc_dointvec_minmax - read a vector of integers with min/max values
1996 * @table: the sysctl table
1997 * @write: %TRUE if this is a write to the sysctl file
1998 * @buffer: the user buffer
1999 * @lenp: the size of the user buffer
2000 * @ppos: file position
2002 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2003 * values from/to the user buffer, treated as an ASCII string.
2005 * This routine will ensure the values are within the range specified by
2006 * table->extra1 (min) and table->extra2 (max).
2008 * Returns 0 on success.
2010 int proc_dointvec_minmax(struct ctl_table *table, int write,
2011 void __user *buffer, size_t *lenp, loff_t *ppos)
2013 struct do_proc_dointvec_minmax_conv_param param = {
2014 .min = (int *) table->extra1,
2015 .max = (int *) table->extra2,
2017 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2018 do_proc_dointvec_minmax_conv, ¶m);
2021 static void validate_coredump_safety(void)
2023 if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2024 core_pattern[0] != '/' && core_pattern[0] != '|') {
2025 printk(KERN_WARNING "Unsafe core_pattern used with "\
2026 "suid_dumpable=2. Pipe handler or fully qualified "\
2027 "core dump path required.\n");
2031 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2032 void __user *buffer, size_t *lenp, loff_t *ppos)
2034 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2036 validate_coredump_safety();
2040 static int proc_dostring_coredump(struct ctl_table *table, int write,
2041 void __user *buffer, size_t *lenp, loff_t *ppos)
2043 int error = proc_dostring(table, write, buffer, lenp, ppos);
2045 validate_coredump_safety();
2049 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2050 void __user *buffer,
2051 size_t *lenp, loff_t *ppos,
2052 unsigned long convmul,
2053 unsigned long convdiv)
2055 unsigned long *i, *min, *max;
2056 int vleft, first = 1, err = 0;
2057 unsigned long page = 0;
2061 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2066 i = (unsigned long *) data;
2067 min = (unsigned long *) table->extra1;
2068 max = (unsigned long *) table->extra2;
2069 vleft = table->maxlen / sizeof(unsigned long);
2073 if (left > PAGE_SIZE - 1)
2074 left = PAGE_SIZE - 1;
2075 page = __get_free_page(GFP_TEMPORARY);
2076 kbuf = (char *) page;
2079 if (copy_from_user(kbuf, buffer, left)) {
2086 for (; left && vleft--; i++, first = 0) {
2092 left -= proc_skip_spaces(&kbuf);
2094 err = proc_get_long(&kbuf, &left, &val, &neg,
2096 sizeof(proc_wspace_sep), NULL);
2101 if ((min && val < *min) || (max && val > *max))
2105 val = convdiv * (*i) / convmul;
2107 err = proc_put_char(&buffer, &left, '\t');
2108 err = proc_put_long(&buffer, &left, val, false);
2114 if (!write && !first && left && !err)
2115 err = proc_put_char(&buffer, &left, '\n');
2117 left -= proc_skip_spaces(&kbuf);
2122 return err ? : -EINVAL;
2129 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2130 void __user *buffer,
2131 size_t *lenp, loff_t *ppos,
2132 unsigned long convmul,
2133 unsigned long convdiv)
2135 return __do_proc_doulongvec_minmax(table->data, table, write,
2136 buffer, lenp, ppos, convmul, convdiv);
2140 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2141 * @table: the sysctl table
2142 * @write: %TRUE if this is a write to the sysctl file
2143 * @buffer: the user buffer
2144 * @lenp: the size of the user buffer
2145 * @ppos: file position
2147 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2148 * values from/to the user buffer, treated as an ASCII string.
2150 * This routine will ensure the values are within the range specified by
2151 * table->extra1 (min) and table->extra2 (max).
2153 * Returns 0 on success.
2155 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2156 void __user *buffer, size_t *lenp, loff_t *ppos)
2158 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2162 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2163 * @table: the sysctl table
2164 * @write: %TRUE if this is a write to the sysctl file
2165 * @buffer: the user buffer
2166 * @lenp: the size of the user buffer
2167 * @ppos: file position
2169 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2170 * values from/to the user buffer, treated as an ASCII string. The values
2171 * are treated as milliseconds, and converted to jiffies when they are stored.
2173 * This routine will ensure the values are within the range specified by
2174 * table->extra1 (min) and table->extra2 (max).
2176 * Returns 0 on success.
2178 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2179 void __user *buffer,
2180 size_t *lenp, loff_t *ppos)
2182 return do_proc_doulongvec_minmax(table, write, buffer,
2183 lenp, ppos, HZ, 1000l);
2187 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2189 int write, void *data)
2192 if (*lvalp > LONG_MAX / HZ)
2194 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2200 lval = (unsigned long)-val;
2203 lval = (unsigned long)val;
2210 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2212 int write, void *data)
2215 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2217 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2223 lval = (unsigned long)-val;
2226 lval = (unsigned long)val;
2228 *lvalp = jiffies_to_clock_t(lval);
2233 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2235 int write, void *data)
2238 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2244 lval = (unsigned long)-val;
2247 lval = (unsigned long)val;
2249 *lvalp = jiffies_to_msecs(lval);
2255 * proc_dointvec_jiffies - read a vector of integers as seconds
2256 * @table: the sysctl table
2257 * @write: %TRUE if this is a write to the sysctl file
2258 * @buffer: the user buffer
2259 * @lenp: the size of the user buffer
2260 * @ppos: file position
2262 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2263 * values from/to the user buffer, treated as an ASCII string.
2264 * The values read are assumed to be in seconds, and are converted into
2267 * Returns 0 on success.
2269 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2270 void __user *buffer, size_t *lenp, loff_t *ppos)
2272 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2273 do_proc_dointvec_jiffies_conv,NULL);
2277 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2278 * @table: the sysctl table
2279 * @write: %TRUE if this is a write to the sysctl file
2280 * @buffer: the user buffer
2281 * @lenp: the size of the user buffer
2282 * @ppos: pointer to the file position
2284 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2285 * values from/to the user buffer, treated as an ASCII string.
2286 * The values read are assumed to be in 1/USER_HZ seconds, and
2287 * are converted into jiffies.
2289 * Returns 0 on success.
2291 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2292 void __user *buffer, size_t *lenp, loff_t *ppos)
2294 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2295 do_proc_dointvec_userhz_jiffies_conv,NULL);
2299 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2300 * @table: the sysctl table
2301 * @write: %TRUE if this is a write to the sysctl file
2302 * @buffer: the user buffer
2303 * @lenp: the size of the user buffer
2304 * @ppos: file position
2305 * @ppos: the current position in the file
2307 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2308 * values from/to the user buffer, treated as an ASCII string.
2309 * The values read are assumed to be in 1/1000 seconds, and
2310 * are converted into jiffies.
2312 * Returns 0 on success.
2314 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2315 void __user *buffer, size_t *lenp, loff_t *ppos)
2317 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2318 do_proc_dointvec_ms_jiffies_conv, NULL);
2321 static int proc_do_cad_pid(struct ctl_table *table, int write,
2322 void __user *buffer, size_t *lenp, loff_t *ppos)
2324 struct pid *new_pid;
2328 tmp = pid_vnr(cad_pid);
2330 r = __do_proc_dointvec(&tmp, table, write, buffer,
2331 lenp, ppos, NULL, NULL);
2335 new_pid = find_get_pid(tmp);
2339 put_pid(xchg(&cad_pid, new_pid));
2344 * proc_do_large_bitmap - read/write from/to a large bitmap
2345 * @table: the sysctl table
2346 * @write: %TRUE if this is a write to the sysctl file
2347 * @buffer: the user buffer
2348 * @lenp: the size of the user buffer
2349 * @ppos: file position
2351 * The bitmap is stored at table->data and the bitmap length (in bits)
2354 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2355 * large bitmaps may be represented in a compact manner. Writing into
2356 * the file will clear the bitmap then update it with the given input.
2358 * Returns 0 on success.
2360 int proc_do_large_bitmap(struct ctl_table *table, int write,
2361 void __user *buffer, size_t *lenp, loff_t *ppos)
2365 size_t left = *lenp;
2366 unsigned long bitmap_len = table->maxlen;
2367 unsigned long *bitmap = (unsigned long *) table->data;
2368 unsigned long *tmp_bitmap = NULL;
2369 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2371 if (!bitmap_len || !left || (*ppos && !write)) {
2377 unsigned long page = 0;
2380 if (left > PAGE_SIZE - 1)
2381 left = PAGE_SIZE - 1;
2383 page = __get_free_page(GFP_TEMPORARY);
2384 kbuf = (char *) page;
2387 if (copy_from_user(kbuf, buffer, left)) {
2393 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2399 proc_skip_char(&kbuf, &left, '\n');
2400 while (!err && left) {
2401 unsigned long val_a, val_b;
2404 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2408 if (val_a >= bitmap_len || neg) {
2420 err = proc_get_long(&kbuf, &left, &val_b,
2421 &neg, tr_b, sizeof(tr_b),
2425 if (val_b >= bitmap_len || neg ||
2436 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2438 proc_skip_char(&kbuf, &left, '\n');
2442 unsigned long bit_a, bit_b = 0;
2445 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2446 if (bit_a >= bitmap_len)
2448 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2452 err = proc_put_char(&buffer, &left, ',');
2456 err = proc_put_long(&buffer, &left, bit_a, false);
2459 if (bit_a != bit_b) {
2460 err = proc_put_char(&buffer, &left, '-');
2463 err = proc_put_long(&buffer, &left, bit_b, false);
2471 err = proc_put_char(&buffer, &left, '\n');
2477 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2479 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2491 #else /* CONFIG_PROC_SYSCTL */
2493 int proc_dostring(struct ctl_table *table, int write,
2494 void __user *buffer, size_t *lenp, loff_t *ppos)
2499 int proc_dointvec(struct ctl_table *table, int write,
2500 void __user *buffer, size_t *lenp, loff_t *ppos)
2505 int proc_dointvec_minmax(struct ctl_table *table, int write,
2506 void __user *buffer, size_t *lenp, loff_t *ppos)
2511 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2512 void __user *buffer, size_t *lenp, loff_t *ppos)
2517 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2518 void __user *buffer, size_t *lenp, loff_t *ppos)
2523 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2524 void __user *buffer, size_t *lenp, loff_t *ppos)
2529 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2530 void __user *buffer, size_t *lenp, loff_t *ppos)
2535 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2536 void __user *buffer,
2537 size_t *lenp, loff_t *ppos)
2543 #endif /* CONFIG_PROC_SYSCTL */
2546 * No sense putting this after each symbol definition, twice,
2547 * exception granted :-)
2549 EXPORT_SYMBOL(proc_dointvec);
2550 EXPORT_SYMBOL(proc_dointvec_jiffies);
2551 EXPORT_SYMBOL(proc_dointvec_minmax);
2552 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2553 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2554 EXPORT_SYMBOL(proc_dostring);
2555 EXPORT_SYMBOL(proc_doulongvec_minmax);
2556 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);