2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
71 #include <asm/stacktrace.h>
75 #include <asm/setup.h>
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
86 #ifdef CONFIG_CHR_DEV_SG
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory;
99 extern int sysctl_overcommit_ratio;
100 extern int max_threads;
101 extern int suid_dumpable;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid;
104 extern char core_pattern[];
105 extern unsigned int core_pipe_limit;
108 extern int pid_max_min, pid_max_max;
109 extern int percpu_pagelist_fraction;
110 extern int compat_log;
111 extern int latencytop_enabled;
112 extern int sysctl_nr_open_min, sysctl_nr_open_max;
114 extern int sysctl_nr_trim_pages;
117 extern int blk_iopoll_enabled;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty = 60;
125 static int __maybe_unused 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;
162 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
163 extern int unaligned_enabled;
167 extern int unaligned_dump_stack;
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
171 extern int no_unaligned_warning;
174 #ifdef CONFIG_PROC_SYSCTL
175 static int proc_do_cad_pid(struct ctl_table *table, int write,
176 void __user *buffer, size_t *lenp, loff_t *ppos);
177 static int proc_taint(struct ctl_table *table, int write,
178 void __user *buffer, size_t *lenp, loff_t *ppos);
182 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
183 void __user *buffer, size_t *lenp, loff_t *ppos);
186 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
187 void __user *buffer, size_t *lenp, loff_t *ppos);
188 #ifdef CONFIG_COREDUMP
189 static int proc_dostring_coredump(struct ctl_table *table, int write,
190 void __user *buffer, size_t *lenp, loff_t *ppos);
193 #ifdef CONFIG_MAGIC_SYSRQ
194 /* Note: sysrq code uses it's own private copy */
195 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
197 static int sysrq_sysctl_handler(ctl_table *table, int write,
198 void __user *buffer, size_t *lenp,
203 error = proc_dointvec(table, write, buffer, lenp, ppos);
208 sysrq_toggle_support(__sysrq_enabled);
215 static struct ctl_table kern_table[];
216 static struct ctl_table vm_table[];
217 static struct ctl_table fs_table[];
218 static struct ctl_table debug_table[];
219 static struct ctl_table dev_table[];
220 extern struct ctl_table random_table[];
222 extern struct ctl_table epoll_table[];
225 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
226 int sysctl_legacy_va_layout;
229 /* The default sysctl tables: */
231 static struct ctl_table sysctl_base_table[] = {
233 .procname = "kernel",
250 .child = debug_table,
260 #ifdef CONFIG_SCHED_DEBUG
261 static int min_sched_granularity_ns = 100000; /* 100 usecs */
262 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
263 static int min_wakeup_granularity_ns; /* 0 usecs */
264 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
266 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
267 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
268 #endif /* CONFIG_SMP */
269 #endif /* CONFIG_SCHED_DEBUG */
271 #ifdef CONFIG_COMPACTION
272 static int min_extfrag_threshold;
273 static int max_extfrag_threshold = 1000;
276 static struct ctl_table kern_table[] = {
278 .procname = "sched_child_runs_first",
279 .data = &sysctl_sched_child_runs_first,
280 .maxlen = sizeof(unsigned int),
282 .proc_handler = proc_dointvec,
284 #ifdef CONFIG_SCHED_DEBUG
286 .procname = "sched_min_granularity_ns",
287 .data = &sysctl_sched_min_granularity,
288 .maxlen = sizeof(unsigned int),
290 .proc_handler = sched_proc_update_handler,
291 .extra1 = &min_sched_granularity_ns,
292 .extra2 = &max_sched_granularity_ns,
295 .procname = "sched_latency_ns",
296 .data = &sysctl_sched_latency,
297 .maxlen = sizeof(unsigned int),
299 .proc_handler = sched_proc_update_handler,
300 .extra1 = &min_sched_granularity_ns,
301 .extra2 = &max_sched_granularity_ns,
304 .procname = "sched_wakeup_granularity_ns",
305 .data = &sysctl_sched_wakeup_granularity,
306 .maxlen = sizeof(unsigned int),
308 .proc_handler = sched_proc_update_handler,
309 .extra1 = &min_wakeup_granularity_ns,
310 .extra2 = &max_wakeup_granularity_ns,
314 .procname = "sched_tunable_scaling",
315 .data = &sysctl_sched_tunable_scaling,
316 .maxlen = sizeof(enum sched_tunable_scaling),
318 .proc_handler = sched_proc_update_handler,
319 .extra1 = &min_sched_tunable_scaling,
320 .extra2 = &max_sched_tunable_scaling,
323 .procname = "sched_migration_cost_ns",
324 .data = &sysctl_sched_migration_cost,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = proc_dointvec,
330 .procname = "sched_nr_migrate",
331 .data = &sysctl_sched_nr_migrate,
332 .maxlen = sizeof(unsigned int),
334 .proc_handler = proc_dointvec,
337 .procname = "sched_time_avg_ms",
338 .data = &sysctl_sched_time_avg,
339 .maxlen = sizeof(unsigned int),
341 .proc_handler = proc_dointvec,
344 .procname = "sched_shares_window_ns",
345 .data = &sysctl_sched_shares_window,
346 .maxlen = sizeof(unsigned int),
348 .proc_handler = proc_dointvec,
351 .procname = "timer_migration",
352 .data = &sysctl_timer_migration,
353 .maxlen = sizeof(unsigned int),
355 .proc_handler = proc_dointvec_minmax,
359 #endif /* CONFIG_SMP */
360 #ifdef CONFIG_NUMA_BALANCING
362 .procname = "numa_balancing_scan_delay_ms",
363 .data = &sysctl_numa_balancing_scan_delay,
364 .maxlen = sizeof(unsigned int),
366 .proc_handler = proc_dointvec,
369 .procname = "numa_balancing_scan_period_min_ms",
370 .data = &sysctl_numa_balancing_scan_period_min,
371 .maxlen = sizeof(unsigned int),
373 .proc_handler = proc_dointvec,
376 .procname = "numa_balancing_scan_period_max_ms",
377 .data = &sysctl_numa_balancing_scan_period_max,
378 .maxlen = sizeof(unsigned int),
380 .proc_handler = proc_dointvec,
383 .procname = "numa_balancing_scan_size_mb",
384 .data = &sysctl_numa_balancing_scan_size,
385 .maxlen = sizeof(unsigned int),
387 .proc_handler = proc_dointvec,
390 .procname = "numa_balancing_migrate_deferred",
391 .data = &sysctl_numa_balancing_migrate_deferred,
392 .maxlen = sizeof(unsigned int),
394 .proc_handler = proc_dointvec,
396 #endif /* CONFIG_NUMA_BALANCING */
397 #endif /* CONFIG_SCHED_DEBUG */
399 .procname = "sched_rt_period_us",
400 .data = &sysctl_sched_rt_period,
401 .maxlen = sizeof(unsigned int),
403 .proc_handler = sched_rt_handler,
406 .procname = "sched_rt_runtime_us",
407 .data = &sysctl_sched_rt_runtime,
408 .maxlen = sizeof(int),
410 .proc_handler = sched_rt_handler,
413 .procname = "sched_rr_timeslice_ms",
414 .data = &sched_rr_timeslice,
415 .maxlen = sizeof(int),
417 .proc_handler = sched_rr_handler,
419 #ifdef CONFIG_SCHED_AUTOGROUP
421 .procname = "sched_autogroup_enabled",
422 .data = &sysctl_sched_autogroup_enabled,
423 .maxlen = sizeof(unsigned int),
425 .proc_handler = proc_dointvec_minmax,
430 #ifdef CONFIG_CFS_BANDWIDTH
432 .procname = "sched_cfs_bandwidth_slice_us",
433 .data = &sysctl_sched_cfs_bandwidth_slice,
434 .maxlen = sizeof(unsigned int),
436 .proc_handler = proc_dointvec_minmax,
440 #ifdef CONFIG_PROVE_LOCKING
442 .procname = "prove_locking",
443 .data = &prove_locking,
444 .maxlen = sizeof(int),
446 .proc_handler = proc_dointvec,
449 #ifdef CONFIG_LOCK_STAT
451 .procname = "lock_stat",
453 .maxlen = sizeof(int),
455 .proc_handler = proc_dointvec,
460 .data = &panic_timeout,
461 .maxlen = sizeof(int),
463 .proc_handler = proc_dointvec,
465 #ifdef CONFIG_COREDUMP
467 .procname = "core_uses_pid",
468 .data = &core_uses_pid,
469 .maxlen = sizeof(int),
471 .proc_handler = proc_dointvec,
474 .procname = "core_pattern",
475 .data = core_pattern,
476 .maxlen = CORENAME_MAX_SIZE,
478 .proc_handler = proc_dostring_coredump,
481 .procname = "core_pipe_limit",
482 .data = &core_pipe_limit,
483 .maxlen = sizeof(unsigned int),
485 .proc_handler = proc_dointvec,
488 #ifdef CONFIG_PROC_SYSCTL
490 .procname = "tainted",
491 .maxlen = sizeof(long),
493 .proc_handler = proc_taint,
496 #ifdef CONFIG_LATENCYTOP
498 .procname = "latencytop",
499 .data = &latencytop_enabled,
500 .maxlen = sizeof(int),
502 .proc_handler = proc_dointvec,
505 #ifdef CONFIG_BLK_DEV_INITRD
507 .procname = "real-root-dev",
508 .data = &real_root_dev,
509 .maxlen = sizeof(int),
511 .proc_handler = proc_dointvec,
515 .procname = "print-fatal-signals",
516 .data = &print_fatal_signals,
517 .maxlen = sizeof(int),
519 .proc_handler = proc_dointvec,
523 .procname = "reboot-cmd",
524 .data = reboot_command,
527 .proc_handler = proc_dostring,
530 .procname = "stop-a",
531 .data = &stop_a_enabled,
532 .maxlen = sizeof (int),
534 .proc_handler = proc_dointvec,
537 .procname = "scons-poweroff",
538 .data = &scons_pwroff,
539 .maxlen = sizeof (int),
541 .proc_handler = proc_dointvec,
544 #ifdef CONFIG_SPARC64
546 .procname = "tsb-ratio",
547 .data = &sysctl_tsb_ratio,
548 .maxlen = sizeof (int),
550 .proc_handler = proc_dointvec,
555 .procname = "soft-power",
556 .data = &pwrsw_enabled,
557 .maxlen = sizeof (int),
559 .proc_handler = proc_dointvec,
562 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
564 .procname = "unaligned-trap",
565 .data = &unaligned_enabled,
566 .maxlen = sizeof (int),
568 .proc_handler = proc_dointvec,
572 .procname = "ctrl-alt-del",
574 .maxlen = sizeof(int),
576 .proc_handler = proc_dointvec,
578 #ifdef CONFIG_FUNCTION_TRACER
580 .procname = "ftrace_enabled",
581 .data = &ftrace_enabled,
582 .maxlen = sizeof(int),
584 .proc_handler = ftrace_enable_sysctl,
587 #ifdef CONFIG_STACK_TRACER
589 .procname = "stack_tracer_enabled",
590 .data = &stack_tracer_enabled,
591 .maxlen = sizeof(int),
593 .proc_handler = stack_trace_sysctl,
596 #ifdef CONFIG_TRACING
598 .procname = "ftrace_dump_on_oops",
599 .data = &ftrace_dump_on_oops,
600 .maxlen = sizeof(int),
602 .proc_handler = proc_dointvec,
605 .procname = "traceoff_on_warning",
606 .data = &__disable_trace_on_warning,
607 .maxlen = sizeof(__disable_trace_on_warning),
609 .proc_handler = proc_dointvec,
612 #ifdef CONFIG_MODULES
614 .procname = "modprobe",
615 .data = &modprobe_path,
616 .maxlen = KMOD_PATH_LEN,
618 .proc_handler = proc_dostring,
621 .procname = "modules_disabled",
622 .data = &modules_disabled,
623 .maxlen = sizeof(int),
625 /* only handle a transition from default "0" to "1" */
626 .proc_handler = proc_dointvec_minmax,
633 .procname = "hotplug",
634 .data = &uevent_helper,
635 .maxlen = UEVENT_HELPER_PATH_LEN,
637 .proc_handler = proc_dostring,
640 #ifdef CONFIG_CHR_DEV_SG
642 .procname = "sg-big-buff",
643 .data = &sg_big_buff,
644 .maxlen = sizeof (int),
646 .proc_handler = proc_dointvec,
649 #ifdef CONFIG_BSD_PROCESS_ACCT
653 .maxlen = 3*sizeof(int),
655 .proc_handler = proc_dointvec,
658 #ifdef CONFIG_MAGIC_SYSRQ
661 .data = &__sysrq_enabled,
662 .maxlen = sizeof (int),
664 .proc_handler = sysrq_sysctl_handler,
667 #ifdef CONFIG_PROC_SYSCTL
669 .procname = "cad_pid",
671 .maxlen = sizeof (int),
673 .proc_handler = proc_do_cad_pid,
677 .procname = "threads-max",
678 .data = &max_threads,
679 .maxlen = sizeof(int),
681 .proc_handler = proc_dointvec,
684 .procname = "random",
686 .child = random_table,
689 .procname = "usermodehelper",
691 .child = usermodehelper_table,
694 .procname = "overflowuid",
695 .data = &overflowuid,
696 .maxlen = sizeof(int),
698 .proc_handler = proc_dointvec_minmax,
699 .extra1 = &minolduid,
700 .extra2 = &maxolduid,
703 .procname = "overflowgid",
704 .data = &overflowgid,
705 .maxlen = sizeof(int),
707 .proc_handler = proc_dointvec_minmax,
708 .extra1 = &minolduid,
709 .extra2 = &maxolduid,
712 #ifdef CONFIG_MATHEMU
714 .procname = "ieee_emulation_warnings",
715 .data = &sysctl_ieee_emulation_warnings,
716 .maxlen = sizeof(int),
718 .proc_handler = proc_dointvec,
722 .procname = "userprocess_debug",
723 .data = &show_unhandled_signals,
724 .maxlen = sizeof(int),
726 .proc_handler = proc_dointvec,
730 .procname = "pid_max",
732 .maxlen = sizeof (int),
734 .proc_handler = proc_dointvec_minmax,
735 .extra1 = &pid_max_min,
736 .extra2 = &pid_max_max,
739 .procname = "panic_on_oops",
740 .data = &panic_on_oops,
741 .maxlen = sizeof(int),
743 .proc_handler = proc_dointvec,
745 #if defined CONFIG_PRINTK
747 .procname = "printk",
748 .data = &console_loglevel,
749 .maxlen = 4*sizeof(int),
751 .proc_handler = proc_dointvec,
754 .procname = "printk_ratelimit",
755 .data = &printk_ratelimit_state.interval,
756 .maxlen = sizeof(int),
758 .proc_handler = proc_dointvec_jiffies,
761 .procname = "printk_ratelimit_burst",
762 .data = &printk_ratelimit_state.burst,
763 .maxlen = sizeof(int),
765 .proc_handler = proc_dointvec,
768 .procname = "printk_delay",
769 .data = &printk_delay_msec,
770 .maxlen = sizeof(int),
772 .proc_handler = proc_dointvec_minmax,
774 .extra2 = &ten_thousand,
777 .procname = "dmesg_restrict",
778 .data = &dmesg_restrict,
779 .maxlen = sizeof(int),
781 .proc_handler = proc_dointvec_minmax_sysadmin,
786 .procname = "kptr_restrict",
787 .data = &kptr_restrict,
788 .maxlen = sizeof(int),
790 .proc_handler = proc_dointvec_minmax_sysadmin,
796 .procname = "ngroups_max",
797 .data = &ngroups_max,
798 .maxlen = sizeof (int),
800 .proc_handler = proc_dointvec,
803 .procname = "cap_last_cap",
804 .data = (void *)&cap_last_cap,
805 .maxlen = sizeof(int),
807 .proc_handler = proc_dointvec,
809 #if defined(CONFIG_LOCKUP_DETECTOR)
811 .procname = "watchdog",
812 .data = &watchdog_user_enabled,
813 .maxlen = sizeof (int),
815 .proc_handler = proc_dowatchdog,
820 .procname = "watchdog_thresh",
821 .data = &watchdog_thresh,
822 .maxlen = sizeof(int),
824 .proc_handler = proc_dowatchdog,
829 .procname = "softlockup_panic",
830 .data = &softlockup_panic,
831 .maxlen = sizeof(int),
833 .proc_handler = proc_dointvec_minmax,
838 .procname = "nmi_watchdog",
839 .data = &watchdog_user_enabled,
840 .maxlen = sizeof (int),
842 .proc_handler = proc_dowatchdog,
847 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
849 .procname = "unknown_nmi_panic",
850 .data = &unknown_nmi_panic,
851 .maxlen = sizeof (int),
853 .proc_handler = proc_dointvec,
856 #if defined(CONFIG_X86)
858 .procname = "panic_on_unrecovered_nmi",
859 .data = &panic_on_unrecovered_nmi,
860 .maxlen = sizeof(int),
862 .proc_handler = proc_dointvec,
865 .procname = "panic_on_io_nmi",
866 .data = &panic_on_io_nmi,
867 .maxlen = sizeof(int),
869 .proc_handler = proc_dointvec,
871 #ifdef CONFIG_DEBUG_STACKOVERFLOW
873 .procname = "panic_on_stackoverflow",
874 .data = &sysctl_panic_on_stackoverflow,
875 .maxlen = sizeof(int),
877 .proc_handler = proc_dointvec,
881 .procname = "bootloader_type",
882 .data = &bootloader_type,
883 .maxlen = sizeof (int),
885 .proc_handler = proc_dointvec,
888 .procname = "bootloader_version",
889 .data = &bootloader_version,
890 .maxlen = sizeof (int),
892 .proc_handler = proc_dointvec,
895 .procname = "kstack_depth_to_print",
896 .data = &kstack_depth_to_print,
897 .maxlen = sizeof(int),
899 .proc_handler = proc_dointvec,
902 .procname = "io_delay_type",
903 .data = &io_delay_type,
904 .maxlen = sizeof(int),
906 .proc_handler = proc_dointvec,
909 #if defined(CONFIG_MMU)
911 .procname = "randomize_va_space",
912 .data = &randomize_va_space,
913 .maxlen = sizeof(int),
915 .proc_handler = proc_dointvec,
918 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
920 .procname = "spin_retry",
922 .maxlen = sizeof (int),
924 .proc_handler = proc_dointvec,
927 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
929 .procname = "acpi_video_flags",
930 .data = &acpi_realmode_flags,
931 .maxlen = sizeof (unsigned long),
933 .proc_handler = proc_doulongvec_minmax,
936 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
938 .procname = "ignore-unaligned-usertrap",
939 .data = &no_unaligned_warning,
940 .maxlen = sizeof (int),
942 .proc_handler = proc_dointvec,
947 .procname = "unaligned-dump-stack",
948 .data = &unaligned_dump_stack,
949 .maxlen = sizeof (int),
951 .proc_handler = proc_dointvec,
954 #ifdef CONFIG_DETECT_HUNG_TASK
956 .procname = "hung_task_panic",
957 .data = &sysctl_hung_task_panic,
958 .maxlen = sizeof(int),
960 .proc_handler = proc_dointvec_minmax,
965 .procname = "hung_task_check_count",
966 .data = &sysctl_hung_task_check_count,
967 .maxlen = sizeof(int),
969 .proc_handler = proc_dointvec_minmax,
973 .procname = "hung_task_timeout_secs",
974 .data = &sysctl_hung_task_timeout_secs,
975 .maxlen = sizeof(unsigned long),
977 .proc_handler = proc_dohung_task_timeout_secs,
980 .procname = "hung_task_warnings",
981 .data = &sysctl_hung_task_warnings,
982 .maxlen = sizeof(int),
984 .proc_handler = proc_dointvec_minmax,
990 .procname = "compat-log",
992 .maxlen = sizeof (int),
994 .proc_handler = proc_dointvec,
997 #ifdef CONFIG_RT_MUTEXES
999 .procname = "max_lock_depth",
1000 .data = &max_lock_depth,
1001 .maxlen = sizeof(int),
1003 .proc_handler = proc_dointvec,
1007 .procname = "poweroff_cmd",
1008 .data = &poweroff_cmd,
1009 .maxlen = POWEROFF_CMD_PATH_LEN,
1011 .proc_handler = proc_dostring,
1017 .child = key_sysctls,
1020 #ifdef CONFIG_RCU_TORTURE_TEST
1022 .procname = "rcutorture_runnable",
1023 .data = &rcutorture_runnable,
1024 .maxlen = sizeof(int),
1026 .proc_handler = proc_dointvec,
1029 #ifdef CONFIG_PERF_EVENTS
1031 * User-space scripts rely on the existence of this file
1032 * as a feature check for perf_events being enabled.
1034 * So it's an ABI, do not remove!
1037 .procname = "perf_event_paranoid",
1038 .data = &sysctl_perf_event_paranoid,
1039 .maxlen = sizeof(sysctl_perf_event_paranoid),
1041 .proc_handler = proc_dointvec,
1044 .procname = "perf_event_mlock_kb",
1045 .data = &sysctl_perf_event_mlock,
1046 .maxlen = sizeof(sysctl_perf_event_mlock),
1048 .proc_handler = proc_dointvec,
1051 .procname = "perf_event_max_sample_rate",
1052 .data = &sysctl_perf_event_sample_rate,
1053 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1055 .proc_handler = perf_proc_update_handler,
1059 .procname = "perf_cpu_time_max_percent",
1060 .data = &sysctl_perf_cpu_time_max_percent,
1061 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1063 .proc_handler = perf_cpu_time_max_percent_handler,
1065 .extra2 = &one_hundred,
1068 #ifdef CONFIG_KMEMCHECK
1070 .procname = "kmemcheck",
1071 .data = &kmemcheck_enabled,
1072 .maxlen = sizeof(int),
1074 .proc_handler = proc_dointvec,
1079 .procname = "blk_iopoll",
1080 .data = &blk_iopoll_enabled,
1081 .maxlen = sizeof(int),
1083 .proc_handler = proc_dointvec,
1089 static struct ctl_table vm_table[] = {
1091 .procname = "overcommit_memory",
1092 .data = &sysctl_overcommit_memory,
1093 .maxlen = sizeof(sysctl_overcommit_memory),
1095 .proc_handler = proc_dointvec_minmax,
1100 .procname = "panic_on_oom",
1101 .data = &sysctl_panic_on_oom,
1102 .maxlen = sizeof(sysctl_panic_on_oom),
1104 .proc_handler = proc_dointvec_minmax,
1109 .procname = "oom_kill_allocating_task",
1110 .data = &sysctl_oom_kill_allocating_task,
1111 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1113 .proc_handler = proc_dointvec,
1116 .procname = "oom_dump_tasks",
1117 .data = &sysctl_oom_dump_tasks,
1118 .maxlen = sizeof(sysctl_oom_dump_tasks),
1120 .proc_handler = proc_dointvec,
1123 .procname = "overcommit_ratio",
1124 .data = &sysctl_overcommit_ratio,
1125 .maxlen = sizeof(sysctl_overcommit_ratio),
1127 .proc_handler = proc_dointvec,
1130 .procname = "page-cluster",
1131 .data = &page_cluster,
1132 .maxlen = sizeof(int),
1134 .proc_handler = proc_dointvec_minmax,
1138 .procname = "dirty_background_ratio",
1139 .data = &dirty_background_ratio,
1140 .maxlen = sizeof(dirty_background_ratio),
1142 .proc_handler = dirty_background_ratio_handler,
1144 .extra2 = &one_hundred,
1147 .procname = "dirty_background_bytes",
1148 .data = &dirty_background_bytes,
1149 .maxlen = sizeof(dirty_background_bytes),
1151 .proc_handler = dirty_background_bytes_handler,
1155 .procname = "dirty_ratio",
1156 .data = &vm_dirty_ratio,
1157 .maxlen = sizeof(vm_dirty_ratio),
1159 .proc_handler = dirty_ratio_handler,
1161 .extra2 = &one_hundred,
1164 .procname = "dirty_bytes",
1165 .data = &vm_dirty_bytes,
1166 .maxlen = sizeof(vm_dirty_bytes),
1168 .proc_handler = dirty_bytes_handler,
1169 .extra1 = &dirty_bytes_min,
1172 .procname = "dirty_writeback_centisecs",
1173 .data = &dirty_writeback_interval,
1174 .maxlen = sizeof(dirty_writeback_interval),
1176 .proc_handler = dirty_writeback_centisecs_handler,
1179 .procname = "dirty_expire_centisecs",
1180 .data = &dirty_expire_interval,
1181 .maxlen = sizeof(dirty_expire_interval),
1183 .proc_handler = proc_dointvec_minmax,
1187 .procname = "nr_pdflush_threads",
1188 .mode = 0444 /* read-only */,
1189 .proc_handler = pdflush_proc_obsolete,
1192 .procname = "swappiness",
1193 .data = &vm_swappiness,
1194 .maxlen = sizeof(vm_swappiness),
1196 .proc_handler = proc_dointvec_minmax,
1198 .extra2 = &one_hundred,
1200 #ifdef CONFIG_HUGETLB_PAGE
1202 .procname = "nr_hugepages",
1204 .maxlen = sizeof(unsigned long),
1206 .proc_handler = hugetlb_sysctl_handler,
1207 .extra1 = (void *)&hugetlb_zero,
1208 .extra2 = (void *)&hugetlb_infinity,
1212 .procname = "nr_hugepages_mempolicy",
1214 .maxlen = sizeof(unsigned long),
1216 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1217 .extra1 = (void *)&hugetlb_zero,
1218 .extra2 = (void *)&hugetlb_infinity,
1222 .procname = "hugetlb_shm_group",
1223 .data = &sysctl_hugetlb_shm_group,
1224 .maxlen = sizeof(gid_t),
1226 .proc_handler = proc_dointvec,
1229 .procname = "hugepages_treat_as_movable",
1230 .data = &hugepages_treat_as_movable,
1231 .maxlen = sizeof(int),
1233 .proc_handler = proc_dointvec,
1236 .procname = "nr_overcommit_hugepages",
1238 .maxlen = sizeof(unsigned long),
1240 .proc_handler = hugetlb_overcommit_handler,
1241 .extra1 = (void *)&hugetlb_zero,
1242 .extra2 = (void *)&hugetlb_infinity,
1246 .procname = "lowmem_reserve_ratio",
1247 .data = &sysctl_lowmem_reserve_ratio,
1248 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1250 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1253 .procname = "drop_caches",
1254 .data = &sysctl_drop_caches,
1255 .maxlen = sizeof(int),
1257 .proc_handler = drop_caches_sysctl_handler,
1261 #ifdef CONFIG_COMPACTION
1263 .procname = "compact_memory",
1264 .data = &sysctl_compact_memory,
1265 .maxlen = sizeof(int),
1267 .proc_handler = sysctl_compaction_handler,
1270 .procname = "extfrag_threshold",
1271 .data = &sysctl_extfrag_threshold,
1272 .maxlen = sizeof(int),
1274 .proc_handler = sysctl_extfrag_handler,
1275 .extra1 = &min_extfrag_threshold,
1276 .extra2 = &max_extfrag_threshold,
1279 #endif /* CONFIG_COMPACTION */
1281 .procname = "min_free_kbytes",
1282 .data = &min_free_kbytes,
1283 .maxlen = sizeof(min_free_kbytes),
1285 .proc_handler = min_free_kbytes_sysctl_handler,
1289 .procname = "percpu_pagelist_fraction",
1290 .data = &percpu_pagelist_fraction,
1291 .maxlen = sizeof(percpu_pagelist_fraction),
1293 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1294 .extra1 = &min_percpu_pagelist_fract,
1298 .procname = "max_map_count",
1299 .data = &sysctl_max_map_count,
1300 .maxlen = sizeof(sysctl_max_map_count),
1302 .proc_handler = proc_dointvec_minmax,
1307 .procname = "nr_trim_pages",
1308 .data = &sysctl_nr_trim_pages,
1309 .maxlen = sizeof(sysctl_nr_trim_pages),
1311 .proc_handler = proc_dointvec_minmax,
1316 .procname = "laptop_mode",
1317 .data = &laptop_mode,
1318 .maxlen = sizeof(laptop_mode),
1320 .proc_handler = proc_dointvec_jiffies,
1323 .procname = "block_dump",
1324 .data = &block_dump,
1325 .maxlen = sizeof(block_dump),
1327 .proc_handler = proc_dointvec,
1331 .procname = "vfs_cache_pressure",
1332 .data = &sysctl_vfs_cache_pressure,
1333 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1335 .proc_handler = proc_dointvec,
1338 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1340 .procname = "legacy_va_layout",
1341 .data = &sysctl_legacy_va_layout,
1342 .maxlen = sizeof(sysctl_legacy_va_layout),
1344 .proc_handler = proc_dointvec,
1350 .procname = "zone_reclaim_mode",
1351 .data = &zone_reclaim_mode,
1352 .maxlen = sizeof(zone_reclaim_mode),
1354 .proc_handler = proc_dointvec,
1358 .procname = "min_unmapped_ratio",
1359 .data = &sysctl_min_unmapped_ratio,
1360 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1362 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1364 .extra2 = &one_hundred,
1367 .procname = "min_slab_ratio",
1368 .data = &sysctl_min_slab_ratio,
1369 .maxlen = sizeof(sysctl_min_slab_ratio),
1371 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1373 .extra2 = &one_hundred,
1378 .procname = "stat_interval",
1379 .data = &sysctl_stat_interval,
1380 .maxlen = sizeof(sysctl_stat_interval),
1382 .proc_handler = proc_dointvec_jiffies,
1387 .procname = "mmap_min_addr",
1388 .data = &dac_mmap_min_addr,
1389 .maxlen = sizeof(unsigned long),
1391 .proc_handler = mmap_min_addr_handler,
1396 .procname = "numa_zonelist_order",
1397 .data = &numa_zonelist_order,
1398 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1400 .proc_handler = numa_zonelist_order_handler,
1403 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1404 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1406 .procname = "vdso_enabled",
1407 .data = &vdso_enabled,
1408 .maxlen = sizeof(vdso_enabled),
1410 .proc_handler = proc_dointvec,
1414 #ifdef CONFIG_HIGHMEM
1416 .procname = "highmem_is_dirtyable",
1417 .data = &vm_highmem_is_dirtyable,
1418 .maxlen = sizeof(vm_highmem_is_dirtyable),
1420 .proc_handler = proc_dointvec_minmax,
1426 .procname = "scan_unevictable_pages",
1427 .data = &scan_unevictable_pages,
1428 .maxlen = sizeof(scan_unevictable_pages),
1430 .proc_handler = scan_unevictable_handler,
1432 #ifdef CONFIG_MEMORY_FAILURE
1434 .procname = "memory_failure_early_kill",
1435 .data = &sysctl_memory_failure_early_kill,
1436 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1438 .proc_handler = proc_dointvec_minmax,
1443 .procname = "memory_failure_recovery",
1444 .data = &sysctl_memory_failure_recovery,
1445 .maxlen = sizeof(sysctl_memory_failure_recovery),
1447 .proc_handler = proc_dointvec_minmax,
1453 .procname = "user_reserve_kbytes",
1454 .data = &sysctl_user_reserve_kbytes,
1455 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1457 .proc_handler = proc_doulongvec_minmax,
1460 .procname = "admin_reserve_kbytes",
1461 .data = &sysctl_admin_reserve_kbytes,
1462 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1464 .proc_handler = proc_doulongvec_minmax,
1469 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1470 static struct ctl_table binfmt_misc_table[] = {
1475 static struct ctl_table fs_table[] = {
1477 .procname = "inode-nr",
1478 .data = &inodes_stat,
1479 .maxlen = 2*sizeof(long),
1481 .proc_handler = proc_nr_inodes,
1484 .procname = "inode-state",
1485 .data = &inodes_stat,
1486 .maxlen = 7*sizeof(long),
1488 .proc_handler = proc_nr_inodes,
1491 .procname = "file-nr",
1492 .data = &files_stat,
1493 .maxlen = sizeof(files_stat),
1495 .proc_handler = proc_nr_files,
1498 .procname = "file-max",
1499 .data = &files_stat.max_files,
1500 .maxlen = sizeof(files_stat.max_files),
1502 .proc_handler = proc_doulongvec_minmax,
1505 .procname = "nr_open",
1506 .data = &sysctl_nr_open,
1507 .maxlen = sizeof(int),
1509 .proc_handler = proc_dointvec_minmax,
1510 .extra1 = &sysctl_nr_open_min,
1511 .extra2 = &sysctl_nr_open_max,
1514 .procname = "dentry-state",
1515 .data = &dentry_stat,
1516 .maxlen = 6*sizeof(long),
1518 .proc_handler = proc_nr_dentry,
1521 .procname = "overflowuid",
1522 .data = &fs_overflowuid,
1523 .maxlen = sizeof(int),
1525 .proc_handler = proc_dointvec_minmax,
1526 .extra1 = &minolduid,
1527 .extra2 = &maxolduid,
1530 .procname = "overflowgid",
1531 .data = &fs_overflowgid,
1532 .maxlen = sizeof(int),
1534 .proc_handler = proc_dointvec_minmax,
1535 .extra1 = &minolduid,
1536 .extra2 = &maxolduid,
1538 #ifdef CONFIG_FILE_LOCKING
1540 .procname = "leases-enable",
1541 .data = &leases_enable,
1542 .maxlen = sizeof(int),
1544 .proc_handler = proc_dointvec,
1547 #ifdef CONFIG_DNOTIFY
1549 .procname = "dir-notify-enable",
1550 .data = &dir_notify_enable,
1551 .maxlen = sizeof(int),
1553 .proc_handler = proc_dointvec,
1557 #ifdef CONFIG_FILE_LOCKING
1559 .procname = "lease-break-time",
1560 .data = &lease_break_time,
1561 .maxlen = sizeof(int),
1563 .proc_handler = proc_dointvec,
1568 .procname = "aio-nr",
1570 .maxlen = sizeof(aio_nr),
1572 .proc_handler = proc_doulongvec_minmax,
1575 .procname = "aio-max-nr",
1576 .data = &aio_max_nr,
1577 .maxlen = sizeof(aio_max_nr),
1579 .proc_handler = proc_doulongvec_minmax,
1581 #endif /* CONFIG_AIO */
1582 #ifdef CONFIG_INOTIFY_USER
1584 .procname = "inotify",
1586 .child = inotify_table,
1591 .procname = "epoll",
1593 .child = epoll_table,
1598 .procname = "protected_symlinks",
1599 .data = &sysctl_protected_symlinks,
1600 .maxlen = sizeof(int),
1602 .proc_handler = proc_dointvec_minmax,
1607 .procname = "protected_hardlinks",
1608 .data = &sysctl_protected_hardlinks,
1609 .maxlen = sizeof(int),
1611 .proc_handler = proc_dointvec_minmax,
1616 .procname = "suid_dumpable",
1617 .data = &suid_dumpable,
1618 .maxlen = sizeof(int),
1620 .proc_handler = proc_dointvec_minmax_coredump,
1624 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1626 .procname = "binfmt_misc",
1628 .child = binfmt_misc_table,
1632 .procname = "pipe-max-size",
1633 .data = &pipe_max_size,
1634 .maxlen = sizeof(int),
1636 .proc_handler = &pipe_proc_fn,
1637 .extra1 = &pipe_min_size,
1642 static struct ctl_table debug_table[] = {
1643 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1645 .procname = "exception-trace",
1646 .data = &show_unhandled_signals,
1647 .maxlen = sizeof(int),
1649 .proc_handler = proc_dointvec
1652 #if defined(CONFIG_OPTPROBES)
1654 .procname = "kprobes-optimization",
1655 .data = &sysctl_kprobes_optimization,
1656 .maxlen = sizeof(int),
1658 .proc_handler = proc_kprobes_optimization_handler,
1666 static struct ctl_table dev_table[] = {
1670 int __init sysctl_init(void)
1672 struct ctl_table_header *hdr;
1674 hdr = register_sysctl_table(sysctl_base_table);
1675 kmemleak_not_leak(hdr);
1679 #endif /* CONFIG_SYSCTL */
1685 #ifdef CONFIG_PROC_SYSCTL
1687 static int _proc_do_string(void* data, int maxlen, int write,
1688 void __user *buffer,
1689 size_t *lenp, loff_t *ppos)
1695 if (!data || !maxlen || !*lenp) {
1703 while (len < *lenp) {
1704 if (get_user(c, p++))
1706 if (c == 0 || c == '\n')
1712 if(copy_from_user(data, buffer, len))
1714 ((char *) data)[len] = 0;
1732 if(copy_to_user(buffer, data, len))
1735 if(put_user('\n', ((char __user *) buffer) + len))
1746 * proc_dostring - read a string sysctl
1747 * @table: the sysctl table
1748 * @write: %TRUE if this is a write to the sysctl file
1749 * @buffer: the user buffer
1750 * @lenp: the size of the user buffer
1751 * @ppos: file position
1753 * Reads/writes a string from/to the user buffer. If the kernel
1754 * buffer provided is not large enough to hold the string, the
1755 * string is truncated. The copied string is %NULL-terminated.
1756 * If the string is being read by the user process, it is copied
1757 * and a newline '\n' is added. It is truncated if the buffer is
1760 * Returns 0 on success.
1762 int proc_dostring(struct ctl_table *table, int write,
1763 void __user *buffer, size_t *lenp, loff_t *ppos)
1765 return _proc_do_string(table->data, table->maxlen, write,
1766 buffer, lenp, ppos);
1769 static size_t proc_skip_spaces(char **buf)
1772 char *tmp = skip_spaces(*buf);
1778 static void proc_skip_char(char **buf, size_t *size, const char v)
1788 #define TMPBUFLEN 22
1790 * proc_get_long - reads an ASCII formatted integer from a user buffer
1792 * @buf: a kernel buffer
1793 * @size: size of the kernel buffer
1794 * @val: this is where the number will be stored
1795 * @neg: set to %TRUE if number is negative
1796 * @perm_tr: a vector which contains the allowed trailers
1797 * @perm_tr_len: size of the perm_tr vector
1798 * @tr: pointer to store the trailer character
1800 * In case of success %0 is returned and @buf and @size are updated with
1801 * the amount of bytes read. If @tr is non-NULL and a trailing
1802 * character exists (size is non-zero after returning from this
1803 * function), @tr is updated with the trailing character.
1805 static int proc_get_long(char **buf, size_t *size,
1806 unsigned long *val, bool *neg,
1807 const char *perm_tr, unsigned perm_tr_len, char *tr)
1810 char *p, tmp[TMPBUFLEN];
1816 if (len > TMPBUFLEN - 1)
1817 len = TMPBUFLEN - 1;
1819 memcpy(tmp, *buf, len);
1823 if (*p == '-' && *size > 1) {
1831 *val = simple_strtoul(p, &p, 0);
1835 /* We don't know if the next char is whitespace thus we may accept
1836 * invalid integers (e.g. 1234...a) or two integers instead of one
1837 * (e.g. 123...1). So lets not allow such large numbers. */
1838 if (len == TMPBUFLEN - 1)
1841 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1844 if (tr && (len < *size))
1854 * proc_put_long - converts an integer to a decimal ASCII formatted string
1856 * @buf: the user buffer
1857 * @size: the size of the user buffer
1858 * @val: the integer to be converted
1859 * @neg: sign of the number, %TRUE for negative
1861 * In case of success %0 is returned and @buf and @size are updated with
1862 * the amount of bytes written.
1864 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1868 char tmp[TMPBUFLEN], *p = tmp;
1870 sprintf(p, "%s%lu", neg ? "-" : "", val);
1874 if (copy_to_user(*buf, tmp, len))
1882 static int proc_put_char(void __user **buf, size_t *size, char c)
1885 char __user **buffer = (char __user **)buf;
1886 if (put_user(c, *buffer))
1888 (*size)--, (*buffer)++;
1894 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1896 int write, void *data)
1899 *valp = *negp ? -*lvalp : *lvalp;
1904 *lvalp = (unsigned long)-val;
1907 *lvalp = (unsigned long)val;
1913 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1915 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1916 int write, void __user *buffer,
1917 size_t *lenp, loff_t *ppos,
1918 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1919 int write, void *data),
1922 int *i, vleft, first = 1, err = 0;
1923 unsigned long page = 0;
1927 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1932 i = (int *) tbl_data;
1933 vleft = table->maxlen / sizeof(*i);
1937 conv = do_proc_dointvec_conv;
1940 if (left > PAGE_SIZE - 1)
1941 left = PAGE_SIZE - 1;
1942 page = __get_free_page(GFP_TEMPORARY);
1943 kbuf = (char *) page;
1946 if (copy_from_user(kbuf, buffer, left)) {
1953 for (; left && vleft--; i++, first=0) {
1958 left -= proc_skip_spaces(&kbuf);
1962 err = proc_get_long(&kbuf, &left, &lval, &neg,
1964 sizeof(proc_wspace_sep), NULL);
1967 if (conv(&neg, &lval, i, 1, data)) {
1972 if (conv(&neg, &lval, i, 0, data)) {
1977 err = proc_put_char(&buffer, &left, '\t');
1980 err = proc_put_long(&buffer, &left, lval, neg);
1986 if (!write && !first && left && !err)
1987 err = proc_put_char(&buffer, &left, '\n');
1988 if (write && !err && left)
1989 left -= proc_skip_spaces(&kbuf);
1994 return err ? : -EINVAL;
2001 static int do_proc_dointvec(struct ctl_table *table, int write,
2002 void __user *buffer, size_t *lenp, loff_t *ppos,
2003 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2004 int write, void *data),
2007 return __do_proc_dointvec(table->data, table, write,
2008 buffer, lenp, ppos, conv, data);
2012 * proc_dointvec - read a vector of integers
2013 * @table: the sysctl table
2014 * @write: %TRUE if this is a write to the sysctl file
2015 * @buffer: the user buffer
2016 * @lenp: the size of the user buffer
2017 * @ppos: file position
2019 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2020 * values from/to the user buffer, treated as an ASCII string.
2022 * Returns 0 on success.
2024 int proc_dointvec(struct ctl_table *table, int write,
2025 void __user *buffer, size_t *lenp, loff_t *ppos)
2027 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2032 * Taint values can only be increased
2033 * This means we can safely use a temporary.
2035 static int proc_taint(struct ctl_table *table, int write,
2036 void __user *buffer, size_t *lenp, loff_t *ppos)
2039 unsigned long tmptaint = get_taint();
2042 if (write && !capable(CAP_SYS_ADMIN))
2047 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2053 * Poor man's atomic or. Not worth adding a primitive
2054 * to everyone's atomic.h for this
2057 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2058 if ((tmptaint >> i) & 1)
2059 add_taint(i, LOCKDEP_STILL_OK);
2066 #ifdef CONFIG_PRINTK
2067 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2068 void __user *buffer, size_t *lenp, loff_t *ppos)
2070 if (write && !capable(CAP_SYS_ADMIN))
2073 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2077 struct do_proc_dointvec_minmax_conv_param {
2082 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2084 int write, void *data)
2086 struct do_proc_dointvec_minmax_conv_param *param = data;
2088 int val = *negp ? -*lvalp : *lvalp;
2089 if ((param->min && *param->min > val) ||
2090 (param->max && *param->max < val))
2097 *lvalp = (unsigned long)-val;
2100 *lvalp = (unsigned long)val;
2107 * proc_dointvec_minmax - read a vector of integers with min/max values
2108 * @table: the sysctl table
2109 * @write: %TRUE if this is a write to the sysctl file
2110 * @buffer: the user buffer
2111 * @lenp: the size of the user buffer
2112 * @ppos: file position
2114 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2115 * values from/to the user buffer, treated as an ASCII string.
2117 * This routine will ensure the values are within the range specified by
2118 * table->extra1 (min) and table->extra2 (max).
2120 * Returns 0 on success.
2122 int proc_dointvec_minmax(struct ctl_table *table, int write,
2123 void __user *buffer, size_t *lenp, loff_t *ppos)
2125 struct do_proc_dointvec_minmax_conv_param param = {
2126 .min = (int *) table->extra1,
2127 .max = (int *) table->extra2,
2129 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2130 do_proc_dointvec_minmax_conv, ¶m);
2133 static void validate_coredump_safety(void)
2135 #ifdef CONFIG_COREDUMP
2136 if (suid_dumpable == SUID_DUMP_ROOT &&
2137 core_pattern[0] != '/' && core_pattern[0] != '|') {
2138 printk(KERN_WARNING "Unsafe core_pattern used with "\
2139 "suid_dumpable=2. Pipe handler or fully qualified "\
2140 "core dump path required.\n");
2145 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2146 void __user *buffer, size_t *lenp, loff_t *ppos)
2148 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2150 validate_coredump_safety();
2154 #ifdef CONFIG_COREDUMP
2155 static int proc_dostring_coredump(struct ctl_table *table, int write,
2156 void __user *buffer, size_t *lenp, loff_t *ppos)
2158 int error = proc_dostring(table, write, buffer, lenp, ppos);
2160 validate_coredump_safety();
2165 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2166 void __user *buffer,
2167 size_t *lenp, loff_t *ppos,
2168 unsigned long convmul,
2169 unsigned long convdiv)
2171 unsigned long *i, *min, *max;
2172 int vleft, first = 1, err = 0;
2173 unsigned long page = 0;
2177 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2182 i = (unsigned long *) data;
2183 min = (unsigned long *) table->extra1;
2184 max = (unsigned long *) table->extra2;
2185 vleft = table->maxlen / sizeof(unsigned long);
2189 if (left > PAGE_SIZE - 1)
2190 left = PAGE_SIZE - 1;
2191 page = __get_free_page(GFP_TEMPORARY);
2192 kbuf = (char *) page;
2195 if (copy_from_user(kbuf, buffer, left)) {
2202 for (; left && vleft--; i++, first = 0) {
2208 left -= proc_skip_spaces(&kbuf);
2210 err = proc_get_long(&kbuf, &left, &val, &neg,
2212 sizeof(proc_wspace_sep), NULL);
2217 if ((min && val < *min) || (max && val > *max))
2221 val = convdiv * (*i) / convmul;
2223 err = proc_put_char(&buffer, &left, '\t');
2227 err = proc_put_long(&buffer, &left, val, false);
2233 if (!write && !first && left && !err)
2234 err = proc_put_char(&buffer, &left, '\n');
2236 left -= proc_skip_spaces(&kbuf);
2241 return err ? : -EINVAL;
2248 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2249 void __user *buffer,
2250 size_t *lenp, loff_t *ppos,
2251 unsigned long convmul,
2252 unsigned long convdiv)
2254 return __do_proc_doulongvec_minmax(table->data, table, write,
2255 buffer, lenp, ppos, convmul, convdiv);
2259 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2260 * @table: the sysctl table
2261 * @write: %TRUE if this is a write to the sysctl file
2262 * @buffer: the user buffer
2263 * @lenp: the size of the user buffer
2264 * @ppos: file position
2266 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2267 * values from/to the user buffer, treated as an ASCII string.
2269 * This routine will ensure the values are within the range specified by
2270 * table->extra1 (min) and table->extra2 (max).
2272 * Returns 0 on success.
2274 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2275 void __user *buffer, size_t *lenp, loff_t *ppos)
2277 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2281 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2282 * @table: the sysctl table
2283 * @write: %TRUE if this is a write to the sysctl file
2284 * @buffer: the user buffer
2285 * @lenp: the size of the user buffer
2286 * @ppos: file position
2288 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2289 * values from/to the user buffer, treated as an ASCII string. The values
2290 * are treated as milliseconds, and converted to jiffies when they are stored.
2292 * This routine will ensure the values are within the range specified by
2293 * table->extra1 (min) and table->extra2 (max).
2295 * Returns 0 on success.
2297 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2298 void __user *buffer,
2299 size_t *lenp, loff_t *ppos)
2301 return do_proc_doulongvec_minmax(table, write, buffer,
2302 lenp, ppos, HZ, 1000l);
2306 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2308 int write, void *data)
2311 if (*lvalp > LONG_MAX / HZ)
2313 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2319 lval = (unsigned long)-val;
2322 lval = (unsigned long)val;
2329 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2331 int write, void *data)
2334 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2336 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2342 lval = (unsigned long)-val;
2345 lval = (unsigned long)val;
2347 *lvalp = jiffies_to_clock_t(lval);
2352 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2354 int write, void *data)
2357 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2367 lval = (unsigned long)-val;
2370 lval = (unsigned long)val;
2372 *lvalp = jiffies_to_msecs(lval);
2378 * proc_dointvec_jiffies - read a vector of integers as seconds
2379 * @table: the sysctl table
2380 * @write: %TRUE if this is a write to the sysctl file
2381 * @buffer: the user buffer
2382 * @lenp: the size of the user buffer
2383 * @ppos: file position
2385 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2386 * values from/to the user buffer, treated as an ASCII string.
2387 * The values read are assumed to be in seconds, and are converted into
2390 * Returns 0 on success.
2392 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2393 void __user *buffer, size_t *lenp, loff_t *ppos)
2395 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2396 do_proc_dointvec_jiffies_conv,NULL);
2400 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2401 * @table: the sysctl table
2402 * @write: %TRUE if this is a write to the sysctl file
2403 * @buffer: the user buffer
2404 * @lenp: the size of the user buffer
2405 * @ppos: pointer to the file position
2407 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2408 * values from/to the user buffer, treated as an ASCII string.
2409 * The values read are assumed to be in 1/USER_HZ seconds, and
2410 * are converted into jiffies.
2412 * Returns 0 on success.
2414 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2415 void __user *buffer, size_t *lenp, loff_t *ppos)
2417 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2418 do_proc_dointvec_userhz_jiffies_conv,NULL);
2422 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2423 * @table: the sysctl table
2424 * @write: %TRUE if this is a write to the sysctl file
2425 * @buffer: the user buffer
2426 * @lenp: the size of the user buffer
2427 * @ppos: file position
2428 * @ppos: the current position in the file
2430 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2431 * values from/to the user buffer, treated as an ASCII string.
2432 * The values read are assumed to be in 1/1000 seconds, and
2433 * are converted into jiffies.
2435 * Returns 0 on success.
2437 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2438 void __user *buffer, size_t *lenp, loff_t *ppos)
2440 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2441 do_proc_dointvec_ms_jiffies_conv, NULL);
2444 static int proc_do_cad_pid(struct ctl_table *table, int write,
2445 void __user *buffer, size_t *lenp, loff_t *ppos)
2447 struct pid *new_pid;
2451 tmp = pid_vnr(cad_pid);
2453 r = __do_proc_dointvec(&tmp, table, write, buffer,
2454 lenp, ppos, NULL, NULL);
2458 new_pid = find_get_pid(tmp);
2462 put_pid(xchg(&cad_pid, new_pid));
2467 * proc_do_large_bitmap - read/write from/to a large bitmap
2468 * @table: the sysctl table
2469 * @write: %TRUE if this is a write to the sysctl file
2470 * @buffer: the user buffer
2471 * @lenp: the size of the user buffer
2472 * @ppos: file position
2474 * The bitmap is stored at table->data and the bitmap length (in bits)
2477 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2478 * large bitmaps may be represented in a compact manner. Writing into
2479 * the file will clear the bitmap then update it with the given input.
2481 * Returns 0 on success.
2483 int proc_do_large_bitmap(struct ctl_table *table, int write,
2484 void __user *buffer, size_t *lenp, loff_t *ppos)
2488 size_t left = *lenp;
2489 unsigned long bitmap_len = table->maxlen;
2490 unsigned long *bitmap = (unsigned long *) table->data;
2491 unsigned long *tmp_bitmap = NULL;
2492 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2494 if (!bitmap_len || !left || (*ppos && !write)) {
2500 unsigned long page = 0;
2503 if (left > PAGE_SIZE - 1)
2504 left = PAGE_SIZE - 1;
2506 page = __get_free_page(GFP_TEMPORARY);
2507 kbuf = (char *) page;
2510 if (copy_from_user(kbuf, buffer, left)) {
2516 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2522 proc_skip_char(&kbuf, &left, '\n');
2523 while (!err && left) {
2524 unsigned long val_a, val_b;
2527 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2531 if (val_a >= bitmap_len || neg) {
2543 err = proc_get_long(&kbuf, &left, &val_b,
2544 &neg, tr_b, sizeof(tr_b),
2548 if (val_b >= bitmap_len || neg ||
2559 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2561 proc_skip_char(&kbuf, &left, '\n');
2565 unsigned long bit_a, bit_b = 0;
2568 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2569 if (bit_a >= bitmap_len)
2571 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2575 err = proc_put_char(&buffer, &left, ',');
2579 err = proc_put_long(&buffer, &left, bit_a, false);
2582 if (bit_a != bit_b) {
2583 err = proc_put_char(&buffer, &left, '-');
2586 err = proc_put_long(&buffer, &left, bit_b, false);
2594 err = proc_put_char(&buffer, &left, '\n');
2600 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2602 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2614 #else /* CONFIG_PROC_SYSCTL */
2616 int proc_dostring(struct ctl_table *table, int write,
2617 void __user *buffer, size_t *lenp, loff_t *ppos)
2622 int proc_dointvec(struct ctl_table *table, int write,
2623 void __user *buffer, size_t *lenp, loff_t *ppos)
2628 int proc_dointvec_minmax(struct ctl_table *table, int write,
2629 void __user *buffer, size_t *lenp, loff_t *ppos)
2634 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2635 void __user *buffer, size_t *lenp, loff_t *ppos)
2640 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2641 void __user *buffer, size_t *lenp, loff_t *ppos)
2646 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2647 void __user *buffer, size_t *lenp, loff_t *ppos)
2652 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2653 void __user *buffer, size_t *lenp, loff_t *ppos)
2658 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2659 void __user *buffer,
2660 size_t *lenp, loff_t *ppos)
2666 #endif /* CONFIG_PROC_SYSCTL */
2669 * No sense putting this after each symbol definition, twice,
2670 * exception granted :-)
2672 EXPORT_SYMBOL(proc_dointvec);
2673 EXPORT_SYMBOL(proc_dointvec_jiffies);
2674 EXPORT_SYMBOL(proc_dointvec_minmax);
2675 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2676 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2677 EXPORT_SYMBOL(proc_dostring);
2678 EXPORT_SYMBOL(proc_doulongvec_minmax);
2679 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);