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>
22 #include <linux/aio.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemcheck.h>
34 #include <linux/kmemleak.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/kexec.h>
68 #include <asm/uaccess.h>
69 #include <asm/processor.h>
73 #include <asm/stacktrace.h>
77 #include <asm/setup.h>
79 #ifdef CONFIG_BSD_PROCESS_ACCT
80 #include <linux/acct.h>
82 #ifdef CONFIG_RT_MUTEXES
83 #include <linux/rtmutex.h>
85 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
86 #include <linux/lockdep.h>
88 #ifdef CONFIG_CHR_DEV_SG
92 #ifdef CONFIG_LOCKUP_DETECTOR
93 #include <linux/nmi.h>
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
99 extern int suid_dumpable;
100 #ifdef CONFIG_COREDUMP
101 extern int core_uses_pid;
102 extern char core_pattern[];
103 extern unsigned int core_pipe_limit;
106 extern int pid_max_min, pid_max_max;
107 extern int percpu_pagelist_fraction;
108 extern int compat_log;
109 extern int latencytop_enabled;
110 extern int sysctl_nr_open_min, sysctl_nr_open_max;
112 extern int sysctl_nr_trim_pages;
115 /* Constants used for minimum and maximum */
116 #ifdef CONFIG_LOCKUP_DETECTOR
117 static int sixty = 60;
120 static int __maybe_unused neg_one = -1;
123 static int __maybe_unused one = 1;
124 static int __maybe_unused two = 2;
125 static int __maybe_unused four = 4;
126 static unsigned long one_ul = 1;
127 static int one_hundred = 100;
129 static int ten_thousand = 10000;
132 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
133 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
135 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
136 static int maxolduid = 65535;
137 static int minolduid;
139 static int ngroups_max = NGROUPS_MAX;
140 static const int cap_last_cap = CAP_LAST_CAP;
142 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
143 #ifdef CONFIG_DETECT_HUNG_TASK
144 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
147 #ifdef CONFIG_INOTIFY_USER
148 #include <linux/inotify.h>
154 extern int pwrsw_enabled;
157 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
158 extern int unaligned_enabled;
162 extern int unaligned_dump_stack;
165 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
166 extern int no_unaligned_warning;
169 #ifdef CONFIG_PROC_SYSCTL
171 #define SYSCTL_WRITES_LEGACY -1
172 #define SYSCTL_WRITES_WARN 0
173 #define SYSCTL_WRITES_STRICT 1
175 static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
177 static int proc_do_cad_pid(struct ctl_table *table, int write,
178 void __user *buffer, size_t *lenp, loff_t *ppos);
179 static int proc_taint(struct ctl_table *table, int write,
180 void __user *buffer, size_t *lenp, loff_t *ppos);
184 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
185 void __user *buffer, size_t *lenp, loff_t *ppos);
188 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
189 void __user *buffer, size_t *lenp, loff_t *ppos);
190 #ifdef CONFIG_COREDUMP
191 static int proc_dostring_coredump(struct ctl_table *table, int write,
192 void __user *buffer, size_t *lenp, loff_t *ppos);
195 #ifdef CONFIG_MAGIC_SYSRQ
196 /* Note: sysrq code uses it's own private copy */
197 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
199 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
200 void __user *buffer, size_t *lenp,
205 error = proc_dointvec(table, write, buffer, lenp, ppos);
210 sysrq_toggle_support(__sysrq_enabled);
217 static struct ctl_table kern_table[];
218 static struct ctl_table vm_table[];
219 static struct ctl_table fs_table[];
220 static struct ctl_table debug_table[];
221 static struct ctl_table dev_table[];
222 extern struct ctl_table random_table[];
224 extern struct ctl_table epoll_table[];
227 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
228 int sysctl_legacy_va_layout;
231 /* The default sysctl tables: */
233 static struct ctl_table sysctl_base_table[] = {
235 .procname = "kernel",
252 .child = debug_table,
262 #ifdef CONFIG_SCHED_DEBUG
263 static int min_sched_granularity_ns = 100000; /* 100 usecs */
264 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
265 static int min_wakeup_granularity_ns; /* 0 usecs */
266 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
268 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
269 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
270 #endif /* CONFIG_SMP */
271 #endif /* CONFIG_SCHED_DEBUG */
273 #ifdef CONFIG_COMPACTION
274 static int min_extfrag_threshold;
275 static int max_extfrag_threshold = 1000;
278 static struct ctl_table kern_table[] = {
280 .procname = "sched_child_runs_first",
281 .data = &sysctl_sched_child_runs_first,
282 .maxlen = sizeof(unsigned int),
284 .proc_handler = proc_dointvec,
286 #ifdef CONFIG_SCHED_DEBUG
288 .procname = "sched_min_granularity_ns",
289 .data = &sysctl_sched_min_granularity,
290 .maxlen = sizeof(unsigned int),
292 .proc_handler = sched_proc_update_handler,
293 .extra1 = &min_sched_granularity_ns,
294 .extra2 = &max_sched_granularity_ns,
297 .procname = "sched_latency_ns",
298 .data = &sysctl_sched_latency,
299 .maxlen = sizeof(unsigned int),
301 .proc_handler = sched_proc_update_handler,
302 .extra1 = &min_sched_granularity_ns,
303 .extra2 = &max_sched_granularity_ns,
306 .procname = "sched_wakeup_granularity_ns",
307 .data = &sysctl_sched_wakeup_granularity,
308 .maxlen = sizeof(unsigned int),
310 .proc_handler = sched_proc_update_handler,
311 .extra1 = &min_wakeup_granularity_ns,
312 .extra2 = &max_wakeup_granularity_ns,
316 .procname = "sched_tunable_scaling",
317 .data = &sysctl_sched_tunable_scaling,
318 .maxlen = sizeof(enum sched_tunable_scaling),
320 .proc_handler = sched_proc_update_handler,
321 .extra1 = &min_sched_tunable_scaling,
322 .extra2 = &max_sched_tunable_scaling,
325 .procname = "sched_migration_cost_ns",
326 .data = &sysctl_sched_migration_cost,
327 .maxlen = sizeof(unsigned int),
329 .proc_handler = proc_dointvec,
332 .procname = "sched_nr_migrate",
333 .data = &sysctl_sched_nr_migrate,
334 .maxlen = sizeof(unsigned int),
336 .proc_handler = proc_dointvec,
339 .procname = "sched_time_avg_ms",
340 .data = &sysctl_sched_time_avg,
341 .maxlen = sizeof(unsigned int),
343 .proc_handler = proc_dointvec,
346 .procname = "sched_shares_window_ns",
347 .data = &sysctl_sched_shares_window,
348 .maxlen = sizeof(unsigned int),
350 .proc_handler = proc_dointvec,
353 .procname = "timer_migration",
354 .data = &sysctl_timer_migration,
355 .maxlen = sizeof(unsigned int),
357 .proc_handler = proc_dointvec_minmax,
361 #endif /* CONFIG_SMP */
362 #ifdef CONFIG_NUMA_BALANCING
364 .procname = "numa_balancing_scan_delay_ms",
365 .data = &sysctl_numa_balancing_scan_delay,
366 .maxlen = sizeof(unsigned int),
368 .proc_handler = proc_dointvec,
371 .procname = "numa_balancing_scan_period_min_ms",
372 .data = &sysctl_numa_balancing_scan_period_min,
373 .maxlen = sizeof(unsigned int),
375 .proc_handler = proc_dointvec,
378 .procname = "numa_balancing_scan_period_max_ms",
379 .data = &sysctl_numa_balancing_scan_period_max,
380 .maxlen = sizeof(unsigned int),
382 .proc_handler = proc_dointvec,
385 .procname = "numa_balancing_scan_size_mb",
386 .data = &sysctl_numa_balancing_scan_size,
387 .maxlen = sizeof(unsigned int),
389 .proc_handler = proc_dointvec_minmax,
393 .procname = "numa_balancing",
394 .data = NULL, /* filled in by handler */
395 .maxlen = sizeof(unsigned int),
397 .proc_handler = sysctl_numa_balancing,
401 #endif /* CONFIG_NUMA_BALANCING */
402 #endif /* CONFIG_SCHED_DEBUG */
404 .procname = "sched_rt_period_us",
405 .data = &sysctl_sched_rt_period,
406 .maxlen = sizeof(unsigned int),
408 .proc_handler = sched_rt_handler,
411 .procname = "sched_rt_runtime_us",
412 .data = &sysctl_sched_rt_runtime,
413 .maxlen = sizeof(int),
415 .proc_handler = sched_rt_handler,
418 .procname = "sched_rr_timeslice_ms",
419 .data = &sched_rr_timeslice,
420 .maxlen = sizeof(int),
422 .proc_handler = sched_rr_handler,
424 #ifdef CONFIG_SCHED_AUTOGROUP
426 .procname = "sched_autogroup_enabled",
427 .data = &sysctl_sched_autogroup_enabled,
428 .maxlen = sizeof(unsigned int),
430 .proc_handler = proc_dointvec_minmax,
435 #ifdef CONFIG_CFS_BANDWIDTH
437 .procname = "sched_cfs_bandwidth_slice_us",
438 .data = &sysctl_sched_cfs_bandwidth_slice,
439 .maxlen = sizeof(unsigned int),
441 .proc_handler = proc_dointvec_minmax,
445 #ifdef CONFIG_PROVE_LOCKING
447 .procname = "prove_locking",
448 .data = &prove_locking,
449 .maxlen = sizeof(int),
451 .proc_handler = proc_dointvec,
454 #ifdef CONFIG_LOCK_STAT
456 .procname = "lock_stat",
458 .maxlen = sizeof(int),
460 .proc_handler = proc_dointvec,
465 .data = &panic_timeout,
466 .maxlen = sizeof(int),
468 .proc_handler = proc_dointvec,
470 #ifdef CONFIG_COREDUMP
472 .procname = "core_uses_pid",
473 .data = &core_uses_pid,
474 .maxlen = sizeof(int),
476 .proc_handler = proc_dointvec,
479 .procname = "core_pattern",
480 .data = core_pattern,
481 .maxlen = CORENAME_MAX_SIZE,
483 .proc_handler = proc_dostring_coredump,
486 .procname = "core_pipe_limit",
487 .data = &core_pipe_limit,
488 .maxlen = sizeof(unsigned int),
490 .proc_handler = proc_dointvec,
493 #ifdef CONFIG_PROC_SYSCTL
495 .procname = "tainted",
496 .maxlen = sizeof(long),
498 .proc_handler = proc_taint,
501 .procname = "sysctl_writes_strict",
502 .data = &sysctl_writes_strict,
503 .maxlen = sizeof(int),
505 .proc_handler = proc_dointvec_minmax,
510 #ifdef CONFIG_LATENCYTOP
512 .procname = "latencytop",
513 .data = &latencytop_enabled,
514 .maxlen = sizeof(int),
516 .proc_handler = proc_dointvec,
519 #ifdef CONFIG_BLK_DEV_INITRD
521 .procname = "real-root-dev",
522 .data = &real_root_dev,
523 .maxlen = sizeof(int),
525 .proc_handler = proc_dointvec,
529 .procname = "print-fatal-signals",
530 .data = &print_fatal_signals,
531 .maxlen = sizeof(int),
533 .proc_handler = proc_dointvec,
537 .procname = "reboot-cmd",
538 .data = reboot_command,
541 .proc_handler = proc_dostring,
544 .procname = "stop-a",
545 .data = &stop_a_enabled,
546 .maxlen = sizeof (int),
548 .proc_handler = proc_dointvec,
551 .procname = "scons-poweroff",
552 .data = &scons_pwroff,
553 .maxlen = sizeof (int),
555 .proc_handler = proc_dointvec,
558 #ifdef CONFIG_SPARC64
560 .procname = "tsb-ratio",
561 .data = &sysctl_tsb_ratio,
562 .maxlen = sizeof (int),
564 .proc_handler = proc_dointvec,
569 .procname = "soft-power",
570 .data = &pwrsw_enabled,
571 .maxlen = sizeof (int),
573 .proc_handler = proc_dointvec,
576 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
578 .procname = "unaligned-trap",
579 .data = &unaligned_enabled,
580 .maxlen = sizeof (int),
582 .proc_handler = proc_dointvec,
586 .procname = "ctrl-alt-del",
588 .maxlen = sizeof(int),
590 .proc_handler = proc_dointvec,
592 #ifdef CONFIG_FUNCTION_TRACER
594 .procname = "ftrace_enabled",
595 .data = &ftrace_enabled,
596 .maxlen = sizeof(int),
598 .proc_handler = ftrace_enable_sysctl,
601 #ifdef CONFIG_STACK_TRACER
603 .procname = "stack_tracer_enabled",
604 .data = &stack_tracer_enabled,
605 .maxlen = sizeof(int),
607 .proc_handler = stack_trace_sysctl,
610 #ifdef CONFIG_TRACING
612 .procname = "ftrace_dump_on_oops",
613 .data = &ftrace_dump_on_oops,
614 .maxlen = sizeof(int),
616 .proc_handler = proc_dointvec,
619 .procname = "traceoff_on_warning",
620 .data = &__disable_trace_on_warning,
621 .maxlen = sizeof(__disable_trace_on_warning),
623 .proc_handler = proc_dointvec,
626 .procname = "tracepoint_printk",
627 .data = &tracepoint_printk,
628 .maxlen = sizeof(tracepoint_printk),
630 .proc_handler = proc_dointvec,
635 .procname = "kexec_load_disabled",
636 .data = &kexec_load_disabled,
637 .maxlen = sizeof(int),
639 /* only handle a transition from default "0" to "1" */
640 .proc_handler = proc_dointvec_minmax,
645 #ifdef CONFIG_MODULES
647 .procname = "modprobe",
648 .data = &modprobe_path,
649 .maxlen = KMOD_PATH_LEN,
651 .proc_handler = proc_dostring,
654 .procname = "modules_disabled",
655 .data = &modules_disabled,
656 .maxlen = sizeof(int),
658 /* only handle a transition from default "0" to "1" */
659 .proc_handler = proc_dointvec_minmax,
664 #ifdef CONFIG_UEVENT_HELPER
666 .procname = "hotplug",
667 .data = &uevent_helper,
668 .maxlen = UEVENT_HELPER_PATH_LEN,
670 .proc_handler = proc_dostring,
673 #ifdef CONFIG_CHR_DEV_SG
675 .procname = "sg-big-buff",
676 .data = &sg_big_buff,
677 .maxlen = sizeof (int),
679 .proc_handler = proc_dointvec,
682 #ifdef CONFIG_BSD_PROCESS_ACCT
686 .maxlen = 3*sizeof(int),
688 .proc_handler = proc_dointvec,
691 #ifdef CONFIG_MAGIC_SYSRQ
694 .data = &__sysrq_enabled,
695 .maxlen = sizeof (int),
697 .proc_handler = sysrq_sysctl_handler,
700 #ifdef CONFIG_PROC_SYSCTL
702 .procname = "cad_pid",
704 .maxlen = sizeof (int),
706 .proc_handler = proc_do_cad_pid,
710 .procname = "threads-max",
712 .maxlen = sizeof(int),
714 .proc_handler = sysctl_max_threads,
717 .procname = "random",
719 .child = random_table,
722 .procname = "usermodehelper",
724 .child = usermodehelper_table,
727 .procname = "overflowuid",
728 .data = &overflowuid,
729 .maxlen = sizeof(int),
731 .proc_handler = proc_dointvec_minmax,
732 .extra1 = &minolduid,
733 .extra2 = &maxolduid,
736 .procname = "overflowgid",
737 .data = &overflowgid,
738 .maxlen = sizeof(int),
740 .proc_handler = proc_dointvec_minmax,
741 .extra1 = &minolduid,
742 .extra2 = &maxolduid,
745 #ifdef CONFIG_MATHEMU
747 .procname = "ieee_emulation_warnings",
748 .data = &sysctl_ieee_emulation_warnings,
749 .maxlen = sizeof(int),
751 .proc_handler = proc_dointvec,
755 .procname = "userprocess_debug",
756 .data = &show_unhandled_signals,
757 .maxlen = sizeof(int),
759 .proc_handler = proc_dointvec,
763 .procname = "pid_max",
765 .maxlen = sizeof (int),
767 .proc_handler = proc_dointvec_minmax,
768 .extra1 = &pid_max_min,
769 .extra2 = &pid_max_max,
772 .procname = "panic_on_oops",
773 .data = &panic_on_oops,
774 .maxlen = sizeof(int),
776 .proc_handler = proc_dointvec,
778 #if defined CONFIG_PRINTK
780 .procname = "printk",
781 .data = &console_loglevel,
782 .maxlen = 4*sizeof(int),
784 .proc_handler = proc_dointvec,
787 .procname = "printk_ratelimit",
788 .data = &printk_ratelimit_state.interval,
789 .maxlen = sizeof(int),
791 .proc_handler = proc_dointvec_jiffies,
794 .procname = "printk_ratelimit_burst",
795 .data = &printk_ratelimit_state.burst,
796 .maxlen = sizeof(int),
798 .proc_handler = proc_dointvec,
801 .procname = "printk_delay",
802 .data = &printk_delay_msec,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dointvec_minmax,
807 .extra2 = &ten_thousand,
810 .procname = "dmesg_restrict",
811 .data = &dmesg_restrict,
812 .maxlen = sizeof(int),
814 .proc_handler = proc_dointvec_minmax_sysadmin,
819 .procname = "kptr_restrict",
820 .data = &kptr_restrict,
821 .maxlen = sizeof(int),
823 .proc_handler = proc_dointvec_minmax_sysadmin,
829 .procname = "ngroups_max",
830 .data = &ngroups_max,
831 .maxlen = sizeof (int),
833 .proc_handler = proc_dointvec,
836 .procname = "cap_last_cap",
837 .data = (void *)&cap_last_cap,
838 .maxlen = sizeof(int),
840 .proc_handler = proc_dointvec,
842 #if defined(CONFIG_LOCKUP_DETECTOR)
844 .procname = "watchdog",
845 .data = &watchdog_user_enabled,
846 .maxlen = sizeof (int),
848 .proc_handler = proc_watchdog,
853 .procname = "watchdog_thresh",
854 .data = &watchdog_thresh,
855 .maxlen = sizeof(int),
857 .proc_handler = proc_watchdog_thresh,
862 .procname = "nmi_watchdog",
863 .data = &nmi_watchdog_enabled,
864 .maxlen = sizeof (int),
866 .proc_handler = proc_nmi_watchdog,
868 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
875 .procname = "soft_watchdog",
876 .data = &soft_watchdog_enabled,
877 .maxlen = sizeof (int),
879 .proc_handler = proc_soft_watchdog,
884 .procname = "softlockup_panic",
885 .data = &softlockup_panic,
886 .maxlen = sizeof(int),
888 .proc_handler = proc_dointvec_minmax,
894 .procname = "softlockup_all_cpu_backtrace",
895 .data = &sysctl_softlockup_all_cpu_backtrace,
896 .maxlen = sizeof(int),
898 .proc_handler = proc_dointvec_minmax,
902 #endif /* CONFIG_SMP */
904 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
906 .procname = "unknown_nmi_panic",
907 .data = &unknown_nmi_panic,
908 .maxlen = sizeof (int),
910 .proc_handler = proc_dointvec,
913 #if defined(CONFIG_X86)
915 .procname = "panic_on_unrecovered_nmi",
916 .data = &panic_on_unrecovered_nmi,
917 .maxlen = sizeof(int),
919 .proc_handler = proc_dointvec,
922 .procname = "panic_on_io_nmi",
923 .data = &panic_on_io_nmi,
924 .maxlen = sizeof(int),
926 .proc_handler = proc_dointvec,
928 #ifdef CONFIG_DEBUG_STACKOVERFLOW
930 .procname = "panic_on_stackoverflow",
931 .data = &sysctl_panic_on_stackoverflow,
932 .maxlen = sizeof(int),
934 .proc_handler = proc_dointvec,
938 .procname = "bootloader_type",
939 .data = &bootloader_type,
940 .maxlen = sizeof (int),
942 .proc_handler = proc_dointvec,
945 .procname = "bootloader_version",
946 .data = &bootloader_version,
947 .maxlen = sizeof (int),
949 .proc_handler = proc_dointvec,
952 .procname = "kstack_depth_to_print",
953 .data = &kstack_depth_to_print,
954 .maxlen = sizeof(int),
956 .proc_handler = proc_dointvec,
959 .procname = "io_delay_type",
960 .data = &io_delay_type,
961 .maxlen = sizeof(int),
963 .proc_handler = proc_dointvec,
966 #if defined(CONFIG_MMU)
968 .procname = "randomize_va_space",
969 .data = &randomize_va_space,
970 .maxlen = sizeof(int),
972 .proc_handler = proc_dointvec,
975 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
977 .procname = "spin_retry",
979 .maxlen = sizeof (int),
981 .proc_handler = proc_dointvec,
984 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
986 .procname = "acpi_video_flags",
987 .data = &acpi_realmode_flags,
988 .maxlen = sizeof (unsigned long),
990 .proc_handler = proc_doulongvec_minmax,
993 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
995 .procname = "ignore-unaligned-usertrap",
996 .data = &no_unaligned_warning,
997 .maxlen = sizeof (int),
999 .proc_handler = proc_dointvec,
1004 .procname = "unaligned-dump-stack",
1005 .data = &unaligned_dump_stack,
1006 .maxlen = sizeof (int),
1008 .proc_handler = proc_dointvec,
1011 #ifdef CONFIG_DETECT_HUNG_TASK
1013 .procname = "hung_task_panic",
1014 .data = &sysctl_hung_task_panic,
1015 .maxlen = sizeof(int),
1017 .proc_handler = proc_dointvec_minmax,
1022 .procname = "hung_task_check_count",
1023 .data = &sysctl_hung_task_check_count,
1024 .maxlen = sizeof(int),
1026 .proc_handler = proc_dointvec_minmax,
1030 .procname = "hung_task_timeout_secs",
1031 .data = &sysctl_hung_task_timeout_secs,
1032 .maxlen = sizeof(unsigned long),
1034 .proc_handler = proc_dohung_task_timeout_secs,
1035 .extra2 = &hung_task_timeout_max,
1038 .procname = "hung_task_warnings",
1039 .data = &sysctl_hung_task_warnings,
1040 .maxlen = sizeof(int),
1042 .proc_handler = proc_dointvec_minmax,
1046 #ifdef CONFIG_COMPAT
1048 .procname = "compat-log",
1049 .data = &compat_log,
1050 .maxlen = sizeof (int),
1052 .proc_handler = proc_dointvec,
1055 #ifdef CONFIG_RT_MUTEXES
1057 .procname = "max_lock_depth",
1058 .data = &max_lock_depth,
1059 .maxlen = sizeof(int),
1061 .proc_handler = proc_dointvec,
1065 .procname = "poweroff_cmd",
1066 .data = &poweroff_cmd,
1067 .maxlen = POWEROFF_CMD_PATH_LEN,
1069 .proc_handler = proc_dostring,
1075 .child = key_sysctls,
1078 #ifdef CONFIG_PERF_EVENTS
1080 * User-space scripts rely on the existence of this file
1081 * as a feature check for perf_events being enabled.
1083 * So it's an ABI, do not remove!
1086 .procname = "perf_event_paranoid",
1087 .data = &sysctl_perf_event_paranoid,
1088 .maxlen = sizeof(sysctl_perf_event_paranoid),
1090 .proc_handler = proc_dointvec,
1093 .procname = "perf_event_mlock_kb",
1094 .data = &sysctl_perf_event_mlock,
1095 .maxlen = sizeof(sysctl_perf_event_mlock),
1097 .proc_handler = proc_dointvec,
1100 .procname = "perf_event_max_sample_rate",
1101 .data = &sysctl_perf_event_sample_rate,
1102 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1104 .proc_handler = perf_proc_update_handler,
1108 .procname = "perf_cpu_time_max_percent",
1109 .data = &sysctl_perf_cpu_time_max_percent,
1110 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1112 .proc_handler = perf_cpu_time_max_percent_handler,
1114 .extra2 = &one_hundred,
1117 #ifdef CONFIG_KMEMCHECK
1119 .procname = "kmemcheck",
1120 .data = &kmemcheck_enabled,
1121 .maxlen = sizeof(int),
1123 .proc_handler = proc_dointvec,
1127 .procname = "panic_on_warn",
1128 .data = &panic_on_warn,
1129 .maxlen = sizeof(int),
1131 .proc_handler = proc_dointvec_minmax,
1138 static struct ctl_table vm_table[] = {
1140 .procname = "overcommit_memory",
1141 .data = &sysctl_overcommit_memory,
1142 .maxlen = sizeof(sysctl_overcommit_memory),
1144 .proc_handler = proc_dointvec_minmax,
1149 .procname = "panic_on_oom",
1150 .data = &sysctl_panic_on_oom,
1151 .maxlen = sizeof(sysctl_panic_on_oom),
1153 .proc_handler = proc_dointvec_minmax,
1158 .procname = "oom_kill_allocating_task",
1159 .data = &sysctl_oom_kill_allocating_task,
1160 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1162 .proc_handler = proc_dointvec,
1165 .procname = "oom_dump_tasks",
1166 .data = &sysctl_oom_dump_tasks,
1167 .maxlen = sizeof(sysctl_oom_dump_tasks),
1169 .proc_handler = proc_dointvec,
1172 .procname = "overcommit_ratio",
1173 .data = &sysctl_overcommit_ratio,
1174 .maxlen = sizeof(sysctl_overcommit_ratio),
1176 .proc_handler = overcommit_ratio_handler,
1179 .procname = "overcommit_kbytes",
1180 .data = &sysctl_overcommit_kbytes,
1181 .maxlen = sizeof(sysctl_overcommit_kbytes),
1183 .proc_handler = overcommit_kbytes_handler,
1186 .procname = "page-cluster",
1187 .data = &page_cluster,
1188 .maxlen = sizeof(int),
1190 .proc_handler = proc_dointvec_minmax,
1194 .procname = "dirty_background_ratio",
1195 .data = &dirty_background_ratio,
1196 .maxlen = sizeof(dirty_background_ratio),
1198 .proc_handler = dirty_background_ratio_handler,
1200 .extra2 = &one_hundred,
1203 .procname = "dirty_background_bytes",
1204 .data = &dirty_background_bytes,
1205 .maxlen = sizeof(dirty_background_bytes),
1207 .proc_handler = dirty_background_bytes_handler,
1211 .procname = "dirty_ratio",
1212 .data = &vm_dirty_ratio,
1213 .maxlen = sizeof(vm_dirty_ratio),
1215 .proc_handler = dirty_ratio_handler,
1217 .extra2 = &one_hundred,
1220 .procname = "dirty_bytes",
1221 .data = &vm_dirty_bytes,
1222 .maxlen = sizeof(vm_dirty_bytes),
1224 .proc_handler = dirty_bytes_handler,
1225 .extra1 = &dirty_bytes_min,
1228 .procname = "dirty_writeback_centisecs",
1229 .data = &dirty_writeback_interval,
1230 .maxlen = sizeof(dirty_writeback_interval),
1232 .proc_handler = dirty_writeback_centisecs_handler,
1235 .procname = "dirty_expire_centisecs",
1236 .data = &dirty_expire_interval,
1237 .maxlen = sizeof(dirty_expire_interval),
1239 .proc_handler = proc_dointvec_minmax,
1243 .procname = "dirtytime_expire_seconds",
1244 .data = &dirtytime_expire_interval,
1245 .maxlen = sizeof(dirty_expire_interval),
1247 .proc_handler = dirtytime_interval_handler,
1251 .procname = "nr_pdflush_threads",
1252 .mode = 0444 /* read-only */,
1253 .proc_handler = pdflush_proc_obsolete,
1256 .procname = "swappiness",
1257 .data = &vm_swappiness,
1258 .maxlen = sizeof(vm_swappiness),
1260 .proc_handler = proc_dointvec_minmax,
1262 .extra2 = &one_hundred,
1264 #ifdef CONFIG_HUGETLB_PAGE
1266 .procname = "nr_hugepages",
1268 .maxlen = sizeof(unsigned long),
1270 .proc_handler = hugetlb_sysctl_handler,
1274 .procname = "nr_hugepages_mempolicy",
1276 .maxlen = sizeof(unsigned long),
1278 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1282 .procname = "hugetlb_shm_group",
1283 .data = &sysctl_hugetlb_shm_group,
1284 .maxlen = sizeof(gid_t),
1286 .proc_handler = proc_dointvec,
1289 .procname = "hugepages_treat_as_movable",
1290 .data = &hugepages_treat_as_movable,
1291 .maxlen = sizeof(int),
1293 .proc_handler = proc_dointvec,
1296 .procname = "nr_overcommit_hugepages",
1298 .maxlen = sizeof(unsigned long),
1300 .proc_handler = hugetlb_overcommit_handler,
1304 .procname = "lowmem_reserve_ratio",
1305 .data = &sysctl_lowmem_reserve_ratio,
1306 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1308 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1311 .procname = "drop_caches",
1312 .data = &sysctl_drop_caches,
1313 .maxlen = sizeof(int),
1315 .proc_handler = drop_caches_sysctl_handler,
1319 #ifdef CONFIG_COMPACTION
1321 .procname = "compact_memory",
1322 .data = &sysctl_compact_memory,
1323 .maxlen = sizeof(int),
1325 .proc_handler = sysctl_compaction_handler,
1328 .procname = "extfrag_threshold",
1329 .data = &sysctl_extfrag_threshold,
1330 .maxlen = sizeof(int),
1332 .proc_handler = sysctl_extfrag_handler,
1333 .extra1 = &min_extfrag_threshold,
1334 .extra2 = &max_extfrag_threshold,
1337 .procname = "compact_unevictable_allowed",
1338 .data = &sysctl_compact_unevictable_allowed,
1339 .maxlen = sizeof(int),
1341 .proc_handler = proc_dointvec,
1346 #endif /* CONFIG_COMPACTION */
1348 .procname = "min_free_kbytes",
1349 .data = &min_free_kbytes,
1350 .maxlen = sizeof(min_free_kbytes),
1352 .proc_handler = min_free_kbytes_sysctl_handler,
1356 .procname = "percpu_pagelist_fraction",
1357 .data = &percpu_pagelist_fraction,
1358 .maxlen = sizeof(percpu_pagelist_fraction),
1360 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1365 .procname = "max_map_count",
1366 .data = &sysctl_max_map_count,
1367 .maxlen = sizeof(sysctl_max_map_count),
1369 .proc_handler = proc_dointvec_minmax,
1374 .procname = "nr_trim_pages",
1375 .data = &sysctl_nr_trim_pages,
1376 .maxlen = sizeof(sysctl_nr_trim_pages),
1378 .proc_handler = proc_dointvec_minmax,
1383 .procname = "laptop_mode",
1384 .data = &laptop_mode,
1385 .maxlen = sizeof(laptop_mode),
1387 .proc_handler = proc_dointvec_jiffies,
1390 .procname = "block_dump",
1391 .data = &block_dump,
1392 .maxlen = sizeof(block_dump),
1394 .proc_handler = proc_dointvec,
1398 .procname = "vfs_cache_pressure",
1399 .data = &sysctl_vfs_cache_pressure,
1400 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1402 .proc_handler = proc_dointvec,
1405 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1407 .procname = "legacy_va_layout",
1408 .data = &sysctl_legacy_va_layout,
1409 .maxlen = sizeof(sysctl_legacy_va_layout),
1411 .proc_handler = proc_dointvec,
1417 .procname = "zone_reclaim_mode",
1418 .data = &zone_reclaim_mode,
1419 .maxlen = sizeof(zone_reclaim_mode),
1421 .proc_handler = proc_dointvec,
1425 .procname = "min_unmapped_ratio",
1426 .data = &sysctl_min_unmapped_ratio,
1427 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1429 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1431 .extra2 = &one_hundred,
1434 .procname = "min_slab_ratio",
1435 .data = &sysctl_min_slab_ratio,
1436 .maxlen = sizeof(sysctl_min_slab_ratio),
1438 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1440 .extra2 = &one_hundred,
1445 .procname = "stat_interval",
1446 .data = &sysctl_stat_interval,
1447 .maxlen = sizeof(sysctl_stat_interval),
1449 .proc_handler = proc_dointvec_jiffies,
1454 .procname = "mmap_min_addr",
1455 .data = &dac_mmap_min_addr,
1456 .maxlen = sizeof(unsigned long),
1458 .proc_handler = mmap_min_addr_handler,
1463 .procname = "numa_zonelist_order",
1464 .data = &numa_zonelist_order,
1465 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1467 .proc_handler = numa_zonelist_order_handler,
1470 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1471 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1473 .procname = "vdso_enabled",
1474 #ifdef CONFIG_X86_32
1475 .data = &vdso32_enabled,
1476 .maxlen = sizeof(vdso32_enabled),
1478 .data = &vdso_enabled,
1479 .maxlen = sizeof(vdso_enabled),
1482 .proc_handler = proc_dointvec,
1486 #ifdef CONFIG_HIGHMEM
1488 .procname = "highmem_is_dirtyable",
1489 .data = &vm_highmem_is_dirtyable,
1490 .maxlen = sizeof(vm_highmem_is_dirtyable),
1492 .proc_handler = proc_dointvec_minmax,
1497 #ifdef CONFIG_MEMORY_FAILURE
1499 .procname = "memory_failure_early_kill",
1500 .data = &sysctl_memory_failure_early_kill,
1501 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1503 .proc_handler = proc_dointvec_minmax,
1508 .procname = "memory_failure_recovery",
1509 .data = &sysctl_memory_failure_recovery,
1510 .maxlen = sizeof(sysctl_memory_failure_recovery),
1512 .proc_handler = proc_dointvec_minmax,
1518 .procname = "user_reserve_kbytes",
1519 .data = &sysctl_user_reserve_kbytes,
1520 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1522 .proc_handler = proc_doulongvec_minmax,
1525 .procname = "admin_reserve_kbytes",
1526 .data = &sysctl_admin_reserve_kbytes,
1527 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1529 .proc_handler = proc_doulongvec_minmax,
1534 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1535 static struct ctl_table binfmt_misc_table[] = {
1540 static struct ctl_table fs_table[] = {
1542 .procname = "inode-nr",
1543 .data = &inodes_stat,
1544 .maxlen = 2*sizeof(long),
1546 .proc_handler = proc_nr_inodes,
1549 .procname = "inode-state",
1550 .data = &inodes_stat,
1551 .maxlen = 7*sizeof(long),
1553 .proc_handler = proc_nr_inodes,
1556 .procname = "file-nr",
1557 .data = &files_stat,
1558 .maxlen = sizeof(files_stat),
1560 .proc_handler = proc_nr_files,
1563 .procname = "file-max",
1564 .data = &files_stat.max_files,
1565 .maxlen = sizeof(files_stat.max_files),
1567 .proc_handler = proc_doulongvec_minmax,
1570 .procname = "nr_open",
1571 .data = &sysctl_nr_open,
1572 .maxlen = sizeof(int),
1574 .proc_handler = proc_dointvec_minmax,
1575 .extra1 = &sysctl_nr_open_min,
1576 .extra2 = &sysctl_nr_open_max,
1579 .procname = "dentry-state",
1580 .data = &dentry_stat,
1581 .maxlen = 6*sizeof(long),
1583 .proc_handler = proc_nr_dentry,
1586 .procname = "overflowuid",
1587 .data = &fs_overflowuid,
1588 .maxlen = sizeof(int),
1590 .proc_handler = proc_dointvec_minmax,
1591 .extra1 = &minolduid,
1592 .extra2 = &maxolduid,
1595 .procname = "overflowgid",
1596 .data = &fs_overflowgid,
1597 .maxlen = sizeof(int),
1599 .proc_handler = proc_dointvec_minmax,
1600 .extra1 = &minolduid,
1601 .extra2 = &maxolduid,
1603 #ifdef CONFIG_FILE_LOCKING
1605 .procname = "leases-enable",
1606 .data = &leases_enable,
1607 .maxlen = sizeof(int),
1609 .proc_handler = proc_dointvec,
1612 #ifdef CONFIG_DNOTIFY
1614 .procname = "dir-notify-enable",
1615 .data = &dir_notify_enable,
1616 .maxlen = sizeof(int),
1618 .proc_handler = proc_dointvec,
1622 #ifdef CONFIG_FILE_LOCKING
1624 .procname = "lease-break-time",
1625 .data = &lease_break_time,
1626 .maxlen = sizeof(int),
1628 .proc_handler = proc_dointvec,
1633 .procname = "aio-nr",
1635 .maxlen = sizeof(aio_nr),
1637 .proc_handler = proc_doulongvec_minmax,
1640 .procname = "aio-max-nr",
1641 .data = &aio_max_nr,
1642 .maxlen = sizeof(aio_max_nr),
1644 .proc_handler = proc_doulongvec_minmax,
1646 #endif /* CONFIG_AIO */
1647 #ifdef CONFIG_INOTIFY_USER
1649 .procname = "inotify",
1651 .child = inotify_table,
1656 .procname = "epoll",
1658 .child = epoll_table,
1663 .procname = "protected_symlinks",
1664 .data = &sysctl_protected_symlinks,
1665 .maxlen = sizeof(int),
1667 .proc_handler = proc_dointvec_minmax,
1672 .procname = "protected_hardlinks",
1673 .data = &sysctl_protected_hardlinks,
1674 .maxlen = sizeof(int),
1676 .proc_handler = proc_dointvec_minmax,
1681 .procname = "suid_dumpable",
1682 .data = &suid_dumpable,
1683 .maxlen = sizeof(int),
1685 .proc_handler = proc_dointvec_minmax_coredump,
1689 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1691 .procname = "binfmt_misc",
1693 .child = binfmt_misc_table,
1697 .procname = "pipe-max-size",
1698 .data = &pipe_max_size,
1699 .maxlen = sizeof(int),
1701 .proc_handler = &pipe_proc_fn,
1702 .extra1 = &pipe_min_size,
1707 static struct ctl_table debug_table[] = {
1708 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1710 .procname = "exception-trace",
1711 .data = &show_unhandled_signals,
1712 .maxlen = sizeof(int),
1714 .proc_handler = proc_dointvec
1717 #if defined(CONFIG_OPTPROBES)
1719 .procname = "kprobes-optimization",
1720 .data = &sysctl_kprobes_optimization,
1721 .maxlen = sizeof(int),
1723 .proc_handler = proc_kprobes_optimization_handler,
1731 static struct ctl_table dev_table[] = {
1735 int __init sysctl_init(void)
1737 struct ctl_table_header *hdr;
1739 hdr = register_sysctl_table(sysctl_base_table);
1740 kmemleak_not_leak(hdr);
1744 #endif /* CONFIG_SYSCTL */
1750 #ifdef CONFIG_PROC_SYSCTL
1752 static int _proc_do_string(char *data, int maxlen, int write,
1753 char __user *buffer,
1754 size_t *lenp, loff_t *ppos)
1760 if (!data || !maxlen || !*lenp) {
1766 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1767 /* Only continue writes not past the end of buffer. */
1769 if (len > maxlen - 1)
1776 /* Start writing from beginning of buffer. */
1782 while ((p - buffer) < *lenp && len < maxlen - 1) {
1783 if (get_user(c, p++))
1785 if (c == 0 || c == '\n')
1806 if (copy_to_user(buffer, data, len))
1809 if (put_user('\n', buffer + len))
1819 static void warn_sysctl_write(struct ctl_table *table)
1821 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1822 "This will not be supported in the future. To silence this\n"
1823 "warning, set kernel.sysctl_writes_strict = -1\n",
1824 current->comm, table->procname);
1828 * proc_dostring - read a string sysctl
1829 * @table: the sysctl table
1830 * @write: %TRUE if this is a write to the sysctl file
1831 * @buffer: the user buffer
1832 * @lenp: the size of the user buffer
1833 * @ppos: file position
1835 * Reads/writes a string from/to the user buffer. If the kernel
1836 * buffer provided is not large enough to hold the string, the
1837 * string is truncated. The copied string is %NULL-terminated.
1838 * If the string is being read by the user process, it is copied
1839 * and a newline '\n' is added. It is truncated if the buffer is
1842 * Returns 0 on success.
1844 int proc_dostring(struct ctl_table *table, int write,
1845 void __user *buffer, size_t *lenp, loff_t *ppos)
1847 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1848 warn_sysctl_write(table);
1850 return _proc_do_string((char *)(table->data), table->maxlen, write,
1851 (char __user *)buffer, lenp, ppos);
1854 static size_t proc_skip_spaces(char **buf)
1857 char *tmp = skip_spaces(*buf);
1863 static void proc_skip_char(char **buf, size_t *size, const char v)
1873 #define TMPBUFLEN 22
1875 * proc_get_long - reads an ASCII formatted integer from a user buffer
1877 * @buf: a kernel buffer
1878 * @size: size of the kernel buffer
1879 * @val: this is where the number will be stored
1880 * @neg: set to %TRUE if number is negative
1881 * @perm_tr: a vector which contains the allowed trailers
1882 * @perm_tr_len: size of the perm_tr vector
1883 * @tr: pointer to store the trailer character
1885 * In case of success %0 is returned and @buf and @size are updated with
1886 * the amount of bytes read. If @tr is non-NULL and a trailing
1887 * character exists (size is non-zero after returning from this
1888 * function), @tr is updated with the trailing character.
1890 static int proc_get_long(char **buf, size_t *size,
1891 unsigned long *val, bool *neg,
1892 const char *perm_tr, unsigned perm_tr_len, char *tr)
1895 char *p, tmp[TMPBUFLEN];
1901 if (len > TMPBUFLEN - 1)
1902 len = TMPBUFLEN - 1;
1904 memcpy(tmp, *buf, len);
1908 if (*p == '-' && *size > 1) {
1916 *val = simple_strtoul(p, &p, 0);
1920 /* We don't know if the next char is whitespace thus we may accept
1921 * invalid integers (e.g. 1234...a) or two integers instead of one
1922 * (e.g. 123...1). So lets not allow such large numbers. */
1923 if (len == TMPBUFLEN - 1)
1926 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1929 if (tr && (len < *size))
1939 * proc_put_long - converts an integer to a decimal ASCII formatted string
1941 * @buf: the user buffer
1942 * @size: the size of the user buffer
1943 * @val: the integer to be converted
1944 * @neg: sign of the number, %TRUE for negative
1946 * In case of success %0 is returned and @buf and @size are updated with
1947 * the amount of bytes written.
1949 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1953 char tmp[TMPBUFLEN], *p = tmp;
1955 sprintf(p, "%s%lu", neg ? "-" : "", val);
1959 if (copy_to_user(*buf, tmp, len))
1967 static int proc_put_char(void __user **buf, size_t *size, char c)
1970 char __user **buffer = (char __user **)buf;
1971 if (put_user(c, *buffer))
1973 (*size)--, (*buffer)++;
1979 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1981 int write, void *data)
1985 if (*lvalp > (unsigned long) INT_MAX + 1)
1989 if (*lvalp > (unsigned long) INT_MAX)
1997 *lvalp = (unsigned long)-val;
2000 *lvalp = (unsigned long)val;
2006 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2008 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2009 int write, void __user *buffer,
2010 size_t *lenp, loff_t *ppos,
2011 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2012 int write, void *data),
2015 int *i, vleft, first = 1, err = 0;
2016 unsigned long page = 0;
2020 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2025 i = (int *) tbl_data;
2026 vleft = table->maxlen / sizeof(*i);
2030 conv = do_proc_dointvec_conv;
2034 switch (sysctl_writes_strict) {
2035 case SYSCTL_WRITES_STRICT:
2037 case SYSCTL_WRITES_WARN:
2038 warn_sysctl_write(table);
2045 if (left > PAGE_SIZE - 1)
2046 left = PAGE_SIZE - 1;
2047 page = __get_free_page(GFP_TEMPORARY);
2048 kbuf = (char *) page;
2051 if (copy_from_user(kbuf, buffer, left)) {
2058 for (; left && vleft--; i++, first=0) {
2063 left -= proc_skip_spaces(&kbuf);
2067 err = proc_get_long(&kbuf, &left, &lval, &neg,
2069 sizeof(proc_wspace_sep), NULL);
2072 if (conv(&neg, &lval, i, 1, data)) {
2077 if (conv(&neg, &lval, i, 0, data)) {
2082 err = proc_put_char(&buffer, &left, '\t');
2085 err = proc_put_long(&buffer, &left, lval, neg);
2091 if (!write && !first && left && !err)
2092 err = proc_put_char(&buffer, &left, '\n');
2093 if (write && !err && left)
2094 left -= proc_skip_spaces(&kbuf);
2099 return err ? : -EINVAL;
2107 static int do_proc_dointvec(struct ctl_table *table, int write,
2108 void __user *buffer, size_t *lenp, loff_t *ppos,
2109 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2110 int write, void *data),
2113 return __do_proc_dointvec(table->data, table, write,
2114 buffer, lenp, ppos, conv, data);
2118 * proc_dointvec - read a vector of integers
2119 * @table: the sysctl table
2120 * @write: %TRUE if this is a write to the sysctl file
2121 * @buffer: the user buffer
2122 * @lenp: the size of the user buffer
2123 * @ppos: file position
2125 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2126 * values from/to the user buffer, treated as an ASCII string.
2128 * Returns 0 on success.
2130 int proc_dointvec(struct ctl_table *table, int write,
2131 void __user *buffer, size_t *lenp, loff_t *ppos)
2133 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2138 * Taint values can only be increased
2139 * This means we can safely use a temporary.
2141 static int proc_taint(struct ctl_table *table, int write,
2142 void __user *buffer, size_t *lenp, loff_t *ppos)
2145 unsigned long tmptaint = get_taint();
2148 if (write && !capable(CAP_SYS_ADMIN))
2153 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2159 * Poor man's atomic or. Not worth adding a primitive
2160 * to everyone's atomic.h for this
2163 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2164 if ((tmptaint >> i) & 1)
2165 add_taint(i, LOCKDEP_STILL_OK);
2172 #ifdef CONFIG_PRINTK
2173 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2174 void __user *buffer, size_t *lenp, loff_t *ppos)
2176 if (write && !capable(CAP_SYS_ADMIN))
2179 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2183 struct do_proc_dointvec_minmax_conv_param {
2188 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2190 int write, void *data)
2192 struct do_proc_dointvec_minmax_conv_param *param = data;
2194 int val = *negp ? -*lvalp : *lvalp;
2195 if ((param->min && *param->min > val) ||
2196 (param->max && *param->max < val))
2203 *lvalp = (unsigned long)-val;
2206 *lvalp = (unsigned long)val;
2213 * proc_dointvec_minmax - read a vector of integers with min/max values
2214 * @table: the sysctl table
2215 * @write: %TRUE if this is a write to the sysctl file
2216 * @buffer: the user buffer
2217 * @lenp: the size of the user buffer
2218 * @ppos: file position
2220 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2221 * values from/to the user buffer, treated as an ASCII string.
2223 * This routine will ensure the values are within the range specified by
2224 * table->extra1 (min) and table->extra2 (max).
2226 * Returns 0 on success.
2228 int proc_dointvec_minmax(struct ctl_table *table, int write,
2229 void __user *buffer, size_t *lenp, loff_t *ppos)
2231 struct do_proc_dointvec_minmax_conv_param param = {
2232 .min = (int *) table->extra1,
2233 .max = (int *) table->extra2,
2235 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2236 do_proc_dointvec_minmax_conv, ¶m);
2239 static void validate_coredump_safety(void)
2241 #ifdef CONFIG_COREDUMP
2242 if (suid_dumpable == SUID_DUMP_ROOT &&
2243 core_pattern[0] != '/' && core_pattern[0] != '|') {
2244 printk(KERN_WARNING "Unsafe core_pattern used with "\
2245 "suid_dumpable=2. Pipe handler or fully qualified "\
2246 "core dump path required.\n");
2251 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2252 void __user *buffer, size_t *lenp, loff_t *ppos)
2254 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2256 validate_coredump_safety();
2260 #ifdef CONFIG_COREDUMP
2261 static int proc_dostring_coredump(struct ctl_table *table, int write,
2262 void __user *buffer, size_t *lenp, loff_t *ppos)
2264 int error = proc_dostring(table, write, buffer, lenp, ppos);
2266 validate_coredump_safety();
2271 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2272 void __user *buffer,
2273 size_t *lenp, loff_t *ppos,
2274 unsigned long convmul,
2275 unsigned long convdiv)
2277 unsigned long *i, *min, *max;
2278 int vleft, first = 1, err = 0;
2279 unsigned long page = 0;
2283 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2288 i = (unsigned long *) data;
2289 min = (unsigned long *) table->extra1;
2290 max = (unsigned long *) table->extra2;
2291 vleft = table->maxlen / sizeof(unsigned long);
2296 switch (sysctl_writes_strict) {
2297 case SYSCTL_WRITES_STRICT:
2299 case SYSCTL_WRITES_WARN:
2300 warn_sysctl_write(table);
2307 if (left > PAGE_SIZE - 1)
2308 left = PAGE_SIZE - 1;
2309 page = __get_free_page(GFP_TEMPORARY);
2310 kbuf = (char *) page;
2313 if (copy_from_user(kbuf, buffer, left)) {
2320 for (; left && vleft--; i++, first = 0) {
2326 left -= proc_skip_spaces(&kbuf);
2328 err = proc_get_long(&kbuf, &left, &val, &neg,
2330 sizeof(proc_wspace_sep), NULL);
2335 if ((min && val < *min) || (max && val > *max))
2339 val = convdiv * (*i) / convmul;
2341 err = proc_put_char(&buffer, &left, '\t');
2345 err = proc_put_long(&buffer, &left, val, false);
2351 if (!write && !first && left && !err)
2352 err = proc_put_char(&buffer, &left, '\n');
2354 left -= proc_skip_spaces(&kbuf);
2359 return err ? : -EINVAL;
2367 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2368 void __user *buffer,
2369 size_t *lenp, loff_t *ppos,
2370 unsigned long convmul,
2371 unsigned long convdiv)
2373 return __do_proc_doulongvec_minmax(table->data, table, write,
2374 buffer, lenp, ppos, convmul, convdiv);
2378 * proc_doulongvec_minmax - read a vector of long integers with min/max values
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 long) unsigned long
2386 * values from/to the user buffer, treated as an ASCII string.
2388 * This routine will ensure the values are within the range specified by
2389 * table->extra1 (min) and table->extra2 (max).
2391 * Returns 0 on success.
2393 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2394 void __user *buffer, size_t *lenp, loff_t *ppos)
2396 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2400 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
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: file position
2407 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2408 * values from/to the user buffer, treated as an ASCII string. The values
2409 * are treated as milliseconds, and converted to jiffies when they are stored.
2411 * This routine will ensure the values are within the range specified by
2412 * table->extra1 (min) and table->extra2 (max).
2414 * Returns 0 on success.
2416 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2417 void __user *buffer,
2418 size_t *lenp, loff_t *ppos)
2420 return do_proc_doulongvec_minmax(table, write, buffer,
2421 lenp, ppos, HZ, 1000l);
2425 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2427 int write, void *data)
2430 if (*lvalp > LONG_MAX / HZ)
2432 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2438 lval = (unsigned long)-val;
2441 lval = (unsigned long)val;
2448 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2450 int write, void *data)
2453 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2455 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2461 lval = (unsigned long)-val;
2464 lval = (unsigned long)val;
2466 *lvalp = jiffies_to_clock_t(lval);
2471 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2473 int write, void *data)
2476 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2486 lval = (unsigned long)-val;
2489 lval = (unsigned long)val;
2491 *lvalp = jiffies_to_msecs(lval);
2497 * proc_dointvec_jiffies - read a vector of integers as seconds
2498 * @table: the sysctl table
2499 * @write: %TRUE if this is a write to the sysctl file
2500 * @buffer: the user buffer
2501 * @lenp: the size of the user buffer
2502 * @ppos: file position
2504 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2505 * values from/to the user buffer, treated as an ASCII string.
2506 * The values read are assumed to be in seconds, and are converted into
2509 * Returns 0 on success.
2511 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2512 void __user *buffer, size_t *lenp, loff_t *ppos)
2514 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2515 do_proc_dointvec_jiffies_conv,NULL);
2519 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2520 * @table: the sysctl table
2521 * @write: %TRUE if this is a write to the sysctl file
2522 * @buffer: the user buffer
2523 * @lenp: the size of the user buffer
2524 * @ppos: pointer to the file position
2526 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2527 * values from/to the user buffer, treated as an ASCII string.
2528 * The values read are assumed to be in 1/USER_HZ seconds, and
2529 * are converted into jiffies.
2531 * Returns 0 on success.
2533 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2534 void __user *buffer, size_t *lenp, loff_t *ppos)
2536 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2537 do_proc_dointvec_userhz_jiffies_conv,NULL);
2541 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2542 * @table: the sysctl table
2543 * @write: %TRUE if this is a write to the sysctl file
2544 * @buffer: the user buffer
2545 * @lenp: the size of the user buffer
2546 * @ppos: file position
2547 * @ppos: the current position in the file
2549 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2550 * values from/to the user buffer, treated as an ASCII string.
2551 * The values read are assumed to be in 1/1000 seconds, and
2552 * are converted into jiffies.
2554 * Returns 0 on success.
2556 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2557 void __user *buffer, size_t *lenp, loff_t *ppos)
2559 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2560 do_proc_dointvec_ms_jiffies_conv, NULL);
2563 static int proc_do_cad_pid(struct ctl_table *table, int write,
2564 void __user *buffer, size_t *lenp, loff_t *ppos)
2566 struct pid *new_pid;
2570 tmp = pid_vnr(cad_pid);
2572 r = __do_proc_dointvec(&tmp, table, write, buffer,
2573 lenp, ppos, NULL, NULL);
2577 new_pid = find_get_pid(tmp);
2581 put_pid(xchg(&cad_pid, new_pid));
2586 * proc_do_large_bitmap - read/write from/to a large bitmap
2587 * @table: the sysctl table
2588 * @write: %TRUE if this is a write to the sysctl file
2589 * @buffer: the user buffer
2590 * @lenp: the size of the user buffer
2591 * @ppos: file position
2593 * The bitmap is stored at table->data and the bitmap length (in bits)
2596 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2597 * large bitmaps may be represented in a compact manner. Writing into
2598 * the file will clear the bitmap then update it with the given input.
2600 * Returns 0 on success.
2602 int proc_do_large_bitmap(struct ctl_table *table, int write,
2603 void __user *buffer, size_t *lenp, loff_t *ppos)
2607 size_t left = *lenp;
2608 unsigned long bitmap_len = table->maxlen;
2609 unsigned long *bitmap = *(unsigned long **) table->data;
2610 unsigned long *tmp_bitmap = NULL;
2611 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2613 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2619 unsigned long page = 0;
2622 if (left > PAGE_SIZE - 1)
2623 left = PAGE_SIZE - 1;
2625 page = __get_free_page(GFP_TEMPORARY);
2626 kbuf = (char *) page;
2629 if (copy_from_user(kbuf, buffer, left)) {
2635 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2641 proc_skip_char(&kbuf, &left, '\n');
2642 while (!err && left) {
2643 unsigned long val_a, val_b;
2646 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2650 if (val_a >= bitmap_len || neg) {
2662 err = proc_get_long(&kbuf, &left, &val_b,
2663 &neg, tr_b, sizeof(tr_b),
2667 if (val_b >= bitmap_len || neg ||
2678 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2680 proc_skip_char(&kbuf, &left, '\n');
2684 unsigned long bit_a, bit_b = 0;
2687 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2688 if (bit_a >= bitmap_len)
2690 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2694 err = proc_put_char(&buffer, &left, ',');
2698 err = proc_put_long(&buffer, &left, bit_a, false);
2701 if (bit_a != bit_b) {
2702 err = proc_put_char(&buffer, &left, '-');
2705 err = proc_put_long(&buffer, &left, bit_b, false);
2713 err = proc_put_char(&buffer, &left, '\n');
2719 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2721 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2733 #else /* CONFIG_PROC_SYSCTL */
2735 int proc_dostring(struct ctl_table *table, int write,
2736 void __user *buffer, size_t *lenp, loff_t *ppos)
2741 int proc_dointvec(struct ctl_table *table, int write,
2742 void __user *buffer, size_t *lenp, loff_t *ppos)
2747 int proc_dointvec_minmax(struct ctl_table *table, int write,
2748 void __user *buffer, size_t *lenp, loff_t *ppos)
2753 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2754 void __user *buffer, size_t *lenp, loff_t *ppos)
2759 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2760 void __user *buffer, size_t *lenp, loff_t *ppos)
2765 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2766 void __user *buffer, size_t *lenp, loff_t *ppos)
2771 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2772 void __user *buffer, size_t *lenp, loff_t *ppos)
2777 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2778 void __user *buffer,
2779 size_t *lenp, loff_t *ppos)
2785 #endif /* CONFIG_PROC_SYSCTL */
2788 * No sense putting this after each symbol definition, twice,
2789 * exception granted :-)
2791 EXPORT_SYMBOL(proc_dointvec);
2792 EXPORT_SYMBOL(proc_dointvec_jiffies);
2793 EXPORT_SYMBOL(proc_dointvec_minmax);
2794 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2795 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2796 EXPORT_SYMBOL(proc_dostring);
2797 EXPORT_SYMBOL(proc_doulongvec_minmax);
2798 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);