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,
352 #endif /* CONFIG_SMP */
353 #ifdef CONFIG_NUMA_BALANCING
355 .procname = "numa_balancing_scan_delay_ms",
356 .data = &sysctl_numa_balancing_scan_delay,
357 .maxlen = sizeof(unsigned int),
359 .proc_handler = proc_dointvec,
362 .procname = "numa_balancing_scan_period_min_ms",
363 .data = &sysctl_numa_balancing_scan_period_min,
364 .maxlen = sizeof(unsigned int),
366 .proc_handler = proc_dointvec,
369 .procname = "numa_balancing_scan_period_max_ms",
370 .data = &sysctl_numa_balancing_scan_period_max,
371 .maxlen = sizeof(unsigned int),
373 .proc_handler = proc_dointvec,
376 .procname = "numa_balancing_scan_size_mb",
377 .data = &sysctl_numa_balancing_scan_size,
378 .maxlen = sizeof(unsigned int),
380 .proc_handler = proc_dointvec_minmax,
384 .procname = "numa_balancing",
385 .data = NULL, /* filled in by handler */
386 .maxlen = sizeof(unsigned int),
388 .proc_handler = sysctl_numa_balancing,
392 #endif /* CONFIG_NUMA_BALANCING */
393 #endif /* CONFIG_SCHED_DEBUG */
395 .procname = "sched_rt_period_us",
396 .data = &sysctl_sched_rt_period,
397 .maxlen = sizeof(unsigned int),
399 .proc_handler = sched_rt_handler,
402 .procname = "sched_rt_runtime_us",
403 .data = &sysctl_sched_rt_runtime,
404 .maxlen = sizeof(int),
406 .proc_handler = sched_rt_handler,
409 .procname = "sched_rr_timeslice_ms",
410 .data = &sched_rr_timeslice,
411 .maxlen = sizeof(int),
413 .proc_handler = sched_rr_handler,
415 #ifdef CONFIG_SCHED_AUTOGROUP
417 .procname = "sched_autogroup_enabled",
418 .data = &sysctl_sched_autogroup_enabled,
419 .maxlen = sizeof(unsigned int),
421 .proc_handler = proc_dointvec_minmax,
426 #ifdef CONFIG_CFS_BANDWIDTH
428 .procname = "sched_cfs_bandwidth_slice_us",
429 .data = &sysctl_sched_cfs_bandwidth_slice,
430 .maxlen = sizeof(unsigned int),
432 .proc_handler = proc_dointvec_minmax,
436 #ifdef CONFIG_PROVE_LOCKING
438 .procname = "prove_locking",
439 .data = &prove_locking,
440 .maxlen = sizeof(int),
442 .proc_handler = proc_dointvec,
445 #ifdef CONFIG_LOCK_STAT
447 .procname = "lock_stat",
449 .maxlen = sizeof(int),
451 .proc_handler = proc_dointvec,
456 .data = &panic_timeout,
457 .maxlen = sizeof(int),
459 .proc_handler = proc_dointvec,
461 #ifdef CONFIG_COREDUMP
463 .procname = "core_uses_pid",
464 .data = &core_uses_pid,
465 .maxlen = sizeof(int),
467 .proc_handler = proc_dointvec,
470 .procname = "core_pattern",
471 .data = core_pattern,
472 .maxlen = CORENAME_MAX_SIZE,
474 .proc_handler = proc_dostring_coredump,
477 .procname = "core_pipe_limit",
478 .data = &core_pipe_limit,
479 .maxlen = sizeof(unsigned int),
481 .proc_handler = proc_dointvec,
484 #ifdef CONFIG_PROC_SYSCTL
486 .procname = "tainted",
487 .maxlen = sizeof(long),
489 .proc_handler = proc_taint,
492 .procname = "sysctl_writes_strict",
493 .data = &sysctl_writes_strict,
494 .maxlen = sizeof(int),
496 .proc_handler = proc_dointvec_minmax,
501 #ifdef CONFIG_LATENCYTOP
503 .procname = "latencytop",
504 .data = &latencytop_enabled,
505 .maxlen = sizeof(int),
507 .proc_handler = proc_dointvec,
510 #ifdef CONFIG_BLK_DEV_INITRD
512 .procname = "real-root-dev",
513 .data = &real_root_dev,
514 .maxlen = sizeof(int),
516 .proc_handler = proc_dointvec,
520 .procname = "print-fatal-signals",
521 .data = &print_fatal_signals,
522 .maxlen = sizeof(int),
524 .proc_handler = proc_dointvec,
528 .procname = "reboot-cmd",
529 .data = reboot_command,
532 .proc_handler = proc_dostring,
535 .procname = "stop-a",
536 .data = &stop_a_enabled,
537 .maxlen = sizeof (int),
539 .proc_handler = proc_dointvec,
542 .procname = "scons-poweroff",
543 .data = &scons_pwroff,
544 .maxlen = sizeof (int),
546 .proc_handler = proc_dointvec,
549 #ifdef CONFIG_SPARC64
551 .procname = "tsb-ratio",
552 .data = &sysctl_tsb_ratio,
553 .maxlen = sizeof (int),
555 .proc_handler = proc_dointvec,
560 .procname = "soft-power",
561 .data = &pwrsw_enabled,
562 .maxlen = sizeof (int),
564 .proc_handler = proc_dointvec,
567 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
569 .procname = "unaligned-trap",
570 .data = &unaligned_enabled,
571 .maxlen = sizeof (int),
573 .proc_handler = proc_dointvec,
577 .procname = "ctrl-alt-del",
579 .maxlen = sizeof(int),
581 .proc_handler = proc_dointvec,
583 #ifdef CONFIG_FUNCTION_TRACER
585 .procname = "ftrace_enabled",
586 .data = &ftrace_enabled,
587 .maxlen = sizeof(int),
589 .proc_handler = ftrace_enable_sysctl,
592 #ifdef CONFIG_STACK_TRACER
594 .procname = "stack_tracer_enabled",
595 .data = &stack_tracer_enabled,
596 .maxlen = sizeof(int),
598 .proc_handler = stack_trace_sysctl,
601 #ifdef CONFIG_TRACING
603 .procname = "ftrace_dump_on_oops",
604 .data = &ftrace_dump_on_oops,
605 .maxlen = sizeof(int),
607 .proc_handler = proc_dointvec,
610 .procname = "traceoff_on_warning",
611 .data = &__disable_trace_on_warning,
612 .maxlen = sizeof(__disable_trace_on_warning),
614 .proc_handler = proc_dointvec,
617 .procname = "tracepoint_printk",
618 .data = &tracepoint_printk,
619 .maxlen = sizeof(tracepoint_printk),
621 .proc_handler = proc_dointvec,
626 .procname = "kexec_load_disabled",
627 .data = &kexec_load_disabled,
628 .maxlen = sizeof(int),
630 /* only handle a transition from default "0" to "1" */
631 .proc_handler = proc_dointvec_minmax,
636 #ifdef CONFIG_MODULES
638 .procname = "modprobe",
639 .data = &modprobe_path,
640 .maxlen = KMOD_PATH_LEN,
642 .proc_handler = proc_dostring,
645 .procname = "modules_disabled",
646 .data = &modules_disabled,
647 .maxlen = sizeof(int),
649 /* only handle a transition from default "0" to "1" */
650 .proc_handler = proc_dointvec_minmax,
655 #ifdef CONFIG_UEVENT_HELPER
657 .procname = "hotplug",
658 .data = &uevent_helper,
659 .maxlen = UEVENT_HELPER_PATH_LEN,
661 .proc_handler = proc_dostring,
664 #ifdef CONFIG_CHR_DEV_SG
666 .procname = "sg-big-buff",
667 .data = &sg_big_buff,
668 .maxlen = sizeof (int),
670 .proc_handler = proc_dointvec,
673 #ifdef CONFIG_BSD_PROCESS_ACCT
677 .maxlen = 3*sizeof(int),
679 .proc_handler = proc_dointvec,
682 #ifdef CONFIG_MAGIC_SYSRQ
685 .data = &__sysrq_enabled,
686 .maxlen = sizeof (int),
688 .proc_handler = sysrq_sysctl_handler,
691 #ifdef CONFIG_PROC_SYSCTL
693 .procname = "cad_pid",
695 .maxlen = sizeof (int),
697 .proc_handler = proc_do_cad_pid,
701 .procname = "threads-max",
703 .maxlen = sizeof(int),
705 .proc_handler = sysctl_max_threads,
708 .procname = "random",
710 .child = random_table,
713 .procname = "usermodehelper",
715 .child = usermodehelper_table,
718 .procname = "overflowuid",
719 .data = &overflowuid,
720 .maxlen = sizeof(int),
722 .proc_handler = proc_dointvec_minmax,
723 .extra1 = &minolduid,
724 .extra2 = &maxolduid,
727 .procname = "overflowgid",
728 .data = &overflowgid,
729 .maxlen = sizeof(int),
731 .proc_handler = proc_dointvec_minmax,
732 .extra1 = &minolduid,
733 .extra2 = &maxolduid,
736 #ifdef CONFIG_MATHEMU
738 .procname = "ieee_emulation_warnings",
739 .data = &sysctl_ieee_emulation_warnings,
740 .maxlen = sizeof(int),
742 .proc_handler = proc_dointvec,
746 .procname = "userprocess_debug",
747 .data = &show_unhandled_signals,
748 .maxlen = sizeof(int),
750 .proc_handler = proc_dointvec,
754 .procname = "pid_max",
756 .maxlen = sizeof (int),
758 .proc_handler = proc_dointvec_minmax,
759 .extra1 = &pid_max_min,
760 .extra2 = &pid_max_max,
763 .procname = "panic_on_oops",
764 .data = &panic_on_oops,
765 .maxlen = sizeof(int),
767 .proc_handler = proc_dointvec,
769 #if defined CONFIG_PRINTK
771 .procname = "printk",
772 .data = &console_loglevel,
773 .maxlen = 4*sizeof(int),
775 .proc_handler = proc_dointvec,
778 .procname = "printk_ratelimit",
779 .data = &printk_ratelimit_state.interval,
780 .maxlen = sizeof(int),
782 .proc_handler = proc_dointvec_jiffies,
785 .procname = "printk_ratelimit_burst",
786 .data = &printk_ratelimit_state.burst,
787 .maxlen = sizeof(int),
789 .proc_handler = proc_dointvec,
792 .procname = "printk_delay",
793 .data = &printk_delay_msec,
794 .maxlen = sizeof(int),
796 .proc_handler = proc_dointvec_minmax,
798 .extra2 = &ten_thousand,
801 .procname = "dmesg_restrict",
802 .data = &dmesg_restrict,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dointvec_minmax_sysadmin,
810 .procname = "kptr_restrict",
811 .data = &kptr_restrict,
812 .maxlen = sizeof(int),
814 .proc_handler = proc_dointvec_minmax_sysadmin,
820 .procname = "ngroups_max",
821 .data = &ngroups_max,
822 .maxlen = sizeof (int),
824 .proc_handler = proc_dointvec,
827 .procname = "cap_last_cap",
828 .data = (void *)&cap_last_cap,
829 .maxlen = sizeof(int),
831 .proc_handler = proc_dointvec,
833 #if defined(CONFIG_LOCKUP_DETECTOR)
835 .procname = "watchdog",
836 .data = &watchdog_user_enabled,
837 .maxlen = sizeof (int),
839 .proc_handler = proc_watchdog,
844 .procname = "watchdog_thresh",
845 .data = &watchdog_thresh,
846 .maxlen = sizeof(int),
848 .proc_handler = proc_watchdog_thresh,
853 .procname = "nmi_watchdog",
854 .data = &nmi_watchdog_enabled,
855 .maxlen = sizeof (int),
857 .proc_handler = proc_nmi_watchdog,
859 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
866 .procname = "soft_watchdog",
867 .data = &soft_watchdog_enabled,
868 .maxlen = sizeof (int),
870 .proc_handler = proc_soft_watchdog,
875 .procname = "watchdog_cpumask",
876 .data = &watchdog_cpumask_bits,
879 .proc_handler = proc_watchdog_cpumask,
882 .procname = "softlockup_panic",
883 .data = &softlockup_panic,
884 .maxlen = sizeof(int),
886 .proc_handler = proc_dointvec_minmax,
892 .procname = "softlockup_all_cpu_backtrace",
893 .data = &sysctl_softlockup_all_cpu_backtrace,
894 .maxlen = sizeof(int),
896 .proc_handler = proc_dointvec_minmax,
900 #endif /* CONFIG_SMP */
902 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
904 .procname = "unknown_nmi_panic",
905 .data = &unknown_nmi_panic,
906 .maxlen = sizeof (int),
908 .proc_handler = proc_dointvec,
911 #if defined(CONFIG_X86)
913 .procname = "panic_on_unrecovered_nmi",
914 .data = &panic_on_unrecovered_nmi,
915 .maxlen = sizeof(int),
917 .proc_handler = proc_dointvec,
920 .procname = "panic_on_io_nmi",
921 .data = &panic_on_io_nmi,
922 .maxlen = sizeof(int),
924 .proc_handler = proc_dointvec,
926 #ifdef CONFIG_DEBUG_STACKOVERFLOW
928 .procname = "panic_on_stackoverflow",
929 .data = &sysctl_panic_on_stackoverflow,
930 .maxlen = sizeof(int),
932 .proc_handler = proc_dointvec,
936 .procname = "bootloader_type",
937 .data = &bootloader_type,
938 .maxlen = sizeof (int),
940 .proc_handler = proc_dointvec,
943 .procname = "bootloader_version",
944 .data = &bootloader_version,
945 .maxlen = sizeof (int),
947 .proc_handler = proc_dointvec,
950 .procname = "kstack_depth_to_print",
951 .data = &kstack_depth_to_print,
952 .maxlen = sizeof(int),
954 .proc_handler = proc_dointvec,
957 .procname = "io_delay_type",
958 .data = &io_delay_type,
959 .maxlen = sizeof(int),
961 .proc_handler = proc_dointvec,
964 #if defined(CONFIG_MMU)
966 .procname = "randomize_va_space",
967 .data = &randomize_va_space,
968 .maxlen = sizeof(int),
970 .proc_handler = proc_dointvec,
973 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
975 .procname = "spin_retry",
977 .maxlen = sizeof (int),
979 .proc_handler = proc_dointvec,
982 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
984 .procname = "acpi_video_flags",
985 .data = &acpi_realmode_flags,
986 .maxlen = sizeof (unsigned long),
988 .proc_handler = proc_doulongvec_minmax,
991 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
993 .procname = "ignore-unaligned-usertrap",
994 .data = &no_unaligned_warning,
995 .maxlen = sizeof (int),
997 .proc_handler = proc_dointvec,
1002 .procname = "unaligned-dump-stack",
1003 .data = &unaligned_dump_stack,
1004 .maxlen = sizeof (int),
1006 .proc_handler = proc_dointvec,
1009 #ifdef CONFIG_DETECT_HUNG_TASK
1011 .procname = "hung_task_panic",
1012 .data = &sysctl_hung_task_panic,
1013 .maxlen = sizeof(int),
1015 .proc_handler = proc_dointvec_minmax,
1020 .procname = "hung_task_check_count",
1021 .data = &sysctl_hung_task_check_count,
1022 .maxlen = sizeof(int),
1024 .proc_handler = proc_dointvec_minmax,
1028 .procname = "hung_task_timeout_secs",
1029 .data = &sysctl_hung_task_timeout_secs,
1030 .maxlen = sizeof(unsigned long),
1032 .proc_handler = proc_dohung_task_timeout_secs,
1033 .extra2 = &hung_task_timeout_max,
1036 .procname = "hung_task_warnings",
1037 .data = &sysctl_hung_task_warnings,
1038 .maxlen = sizeof(int),
1040 .proc_handler = proc_dointvec_minmax,
1044 #ifdef CONFIG_COMPAT
1046 .procname = "compat-log",
1047 .data = &compat_log,
1048 .maxlen = sizeof (int),
1050 .proc_handler = proc_dointvec,
1053 #ifdef CONFIG_RT_MUTEXES
1055 .procname = "max_lock_depth",
1056 .data = &max_lock_depth,
1057 .maxlen = sizeof(int),
1059 .proc_handler = proc_dointvec,
1063 .procname = "poweroff_cmd",
1064 .data = &poweroff_cmd,
1065 .maxlen = POWEROFF_CMD_PATH_LEN,
1067 .proc_handler = proc_dostring,
1073 .child = key_sysctls,
1076 #ifdef CONFIG_PERF_EVENTS
1078 * User-space scripts rely on the existence of this file
1079 * as a feature check for perf_events being enabled.
1081 * So it's an ABI, do not remove!
1084 .procname = "perf_event_paranoid",
1085 .data = &sysctl_perf_event_paranoid,
1086 .maxlen = sizeof(sysctl_perf_event_paranoid),
1088 .proc_handler = proc_dointvec,
1091 .procname = "perf_event_mlock_kb",
1092 .data = &sysctl_perf_event_mlock,
1093 .maxlen = sizeof(sysctl_perf_event_mlock),
1095 .proc_handler = proc_dointvec,
1098 .procname = "perf_event_max_sample_rate",
1099 .data = &sysctl_perf_event_sample_rate,
1100 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1102 .proc_handler = perf_proc_update_handler,
1106 .procname = "perf_cpu_time_max_percent",
1107 .data = &sysctl_perf_cpu_time_max_percent,
1108 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1110 .proc_handler = perf_cpu_time_max_percent_handler,
1112 .extra2 = &one_hundred,
1115 #ifdef CONFIG_KMEMCHECK
1117 .procname = "kmemcheck",
1118 .data = &kmemcheck_enabled,
1119 .maxlen = sizeof(int),
1121 .proc_handler = proc_dointvec,
1125 .procname = "panic_on_warn",
1126 .data = &panic_on_warn,
1127 .maxlen = sizeof(int),
1129 .proc_handler = proc_dointvec_minmax,
1133 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1135 .procname = "timer_migration",
1136 .data = &sysctl_timer_migration,
1137 .maxlen = sizeof(unsigned int),
1139 .proc_handler = timer_migration_handler,
1145 static struct ctl_table vm_table[] = {
1147 .procname = "overcommit_memory",
1148 .data = &sysctl_overcommit_memory,
1149 .maxlen = sizeof(sysctl_overcommit_memory),
1151 .proc_handler = proc_dointvec_minmax,
1156 .procname = "panic_on_oom",
1157 .data = &sysctl_panic_on_oom,
1158 .maxlen = sizeof(sysctl_panic_on_oom),
1160 .proc_handler = proc_dointvec_minmax,
1165 .procname = "oom_kill_allocating_task",
1166 .data = &sysctl_oom_kill_allocating_task,
1167 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1169 .proc_handler = proc_dointvec,
1172 .procname = "oom_dump_tasks",
1173 .data = &sysctl_oom_dump_tasks,
1174 .maxlen = sizeof(sysctl_oom_dump_tasks),
1176 .proc_handler = proc_dointvec,
1179 .procname = "overcommit_ratio",
1180 .data = &sysctl_overcommit_ratio,
1181 .maxlen = sizeof(sysctl_overcommit_ratio),
1183 .proc_handler = overcommit_ratio_handler,
1186 .procname = "overcommit_kbytes",
1187 .data = &sysctl_overcommit_kbytes,
1188 .maxlen = sizeof(sysctl_overcommit_kbytes),
1190 .proc_handler = overcommit_kbytes_handler,
1193 .procname = "page-cluster",
1194 .data = &page_cluster,
1195 .maxlen = sizeof(int),
1197 .proc_handler = proc_dointvec_minmax,
1201 .procname = "dirty_background_ratio",
1202 .data = &dirty_background_ratio,
1203 .maxlen = sizeof(dirty_background_ratio),
1205 .proc_handler = dirty_background_ratio_handler,
1207 .extra2 = &one_hundred,
1210 .procname = "dirty_background_bytes",
1211 .data = &dirty_background_bytes,
1212 .maxlen = sizeof(dirty_background_bytes),
1214 .proc_handler = dirty_background_bytes_handler,
1218 .procname = "dirty_ratio",
1219 .data = &vm_dirty_ratio,
1220 .maxlen = sizeof(vm_dirty_ratio),
1222 .proc_handler = dirty_ratio_handler,
1224 .extra2 = &one_hundred,
1227 .procname = "dirty_bytes",
1228 .data = &vm_dirty_bytes,
1229 .maxlen = sizeof(vm_dirty_bytes),
1231 .proc_handler = dirty_bytes_handler,
1232 .extra1 = &dirty_bytes_min,
1235 .procname = "dirty_writeback_centisecs",
1236 .data = &dirty_writeback_interval,
1237 .maxlen = sizeof(dirty_writeback_interval),
1239 .proc_handler = dirty_writeback_centisecs_handler,
1242 .procname = "dirty_expire_centisecs",
1243 .data = &dirty_expire_interval,
1244 .maxlen = sizeof(dirty_expire_interval),
1246 .proc_handler = proc_dointvec_minmax,
1250 .procname = "dirtytime_expire_seconds",
1251 .data = &dirtytime_expire_interval,
1252 .maxlen = sizeof(dirty_expire_interval),
1254 .proc_handler = dirtytime_interval_handler,
1258 .procname = "nr_pdflush_threads",
1259 .mode = 0444 /* read-only */,
1260 .proc_handler = pdflush_proc_obsolete,
1263 .procname = "swappiness",
1264 .data = &vm_swappiness,
1265 .maxlen = sizeof(vm_swappiness),
1267 .proc_handler = proc_dointvec_minmax,
1269 .extra2 = &one_hundred,
1271 #ifdef CONFIG_HUGETLB_PAGE
1273 .procname = "nr_hugepages",
1275 .maxlen = sizeof(unsigned long),
1277 .proc_handler = hugetlb_sysctl_handler,
1281 .procname = "nr_hugepages_mempolicy",
1283 .maxlen = sizeof(unsigned long),
1285 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1289 .procname = "hugetlb_shm_group",
1290 .data = &sysctl_hugetlb_shm_group,
1291 .maxlen = sizeof(gid_t),
1293 .proc_handler = proc_dointvec,
1296 .procname = "hugepages_treat_as_movable",
1297 .data = &hugepages_treat_as_movable,
1298 .maxlen = sizeof(int),
1300 .proc_handler = proc_dointvec,
1303 .procname = "nr_overcommit_hugepages",
1305 .maxlen = sizeof(unsigned long),
1307 .proc_handler = hugetlb_overcommit_handler,
1311 .procname = "lowmem_reserve_ratio",
1312 .data = &sysctl_lowmem_reserve_ratio,
1313 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1315 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1318 .procname = "drop_caches",
1319 .data = &sysctl_drop_caches,
1320 .maxlen = sizeof(int),
1322 .proc_handler = drop_caches_sysctl_handler,
1326 #ifdef CONFIG_COMPACTION
1328 .procname = "compact_memory",
1329 .data = &sysctl_compact_memory,
1330 .maxlen = sizeof(int),
1332 .proc_handler = sysctl_compaction_handler,
1335 .procname = "extfrag_threshold",
1336 .data = &sysctl_extfrag_threshold,
1337 .maxlen = sizeof(int),
1339 .proc_handler = sysctl_extfrag_handler,
1340 .extra1 = &min_extfrag_threshold,
1341 .extra2 = &max_extfrag_threshold,
1344 .procname = "compact_unevictable_allowed",
1345 .data = &sysctl_compact_unevictable_allowed,
1346 .maxlen = sizeof(int),
1348 .proc_handler = proc_dointvec,
1353 #endif /* CONFIG_COMPACTION */
1355 .procname = "min_free_kbytes",
1356 .data = &min_free_kbytes,
1357 .maxlen = sizeof(min_free_kbytes),
1359 .proc_handler = min_free_kbytes_sysctl_handler,
1363 .procname = "percpu_pagelist_fraction",
1364 .data = &percpu_pagelist_fraction,
1365 .maxlen = sizeof(percpu_pagelist_fraction),
1367 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1372 .procname = "max_map_count",
1373 .data = &sysctl_max_map_count,
1374 .maxlen = sizeof(sysctl_max_map_count),
1376 .proc_handler = proc_dointvec_minmax,
1381 .procname = "nr_trim_pages",
1382 .data = &sysctl_nr_trim_pages,
1383 .maxlen = sizeof(sysctl_nr_trim_pages),
1385 .proc_handler = proc_dointvec_minmax,
1390 .procname = "laptop_mode",
1391 .data = &laptop_mode,
1392 .maxlen = sizeof(laptop_mode),
1394 .proc_handler = proc_dointvec_jiffies,
1397 .procname = "block_dump",
1398 .data = &block_dump,
1399 .maxlen = sizeof(block_dump),
1401 .proc_handler = proc_dointvec,
1405 .procname = "vfs_cache_pressure",
1406 .data = &sysctl_vfs_cache_pressure,
1407 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1409 .proc_handler = proc_dointvec,
1412 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1414 .procname = "legacy_va_layout",
1415 .data = &sysctl_legacy_va_layout,
1416 .maxlen = sizeof(sysctl_legacy_va_layout),
1418 .proc_handler = proc_dointvec,
1424 .procname = "zone_reclaim_mode",
1425 .data = &zone_reclaim_mode,
1426 .maxlen = sizeof(zone_reclaim_mode),
1428 .proc_handler = proc_dointvec,
1432 .procname = "min_unmapped_ratio",
1433 .data = &sysctl_min_unmapped_ratio,
1434 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1436 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1438 .extra2 = &one_hundred,
1441 .procname = "min_slab_ratio",
1442 .data = &sysctl_min_slab_ratio,
1443 .maxlen = sizeof(sysctl_min_slab_ratio),
1445 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1447 .extra2 = &one_hundred,
1452 .procname = "stat_interval",
1453 .data = &sysctl_stat_interval,
1454 .maxlen = sizeof(sysctl_stat_interval),
1456 .proc_handler = proc_dointvec_jiffies,
1461 .procname = "mmap_min_addr",
1462 .data = &dac_mmap_min_addr,
1463 .maxlen = sizeof(unsigned long),
1465 .proc_handler = mmap_min_addr_handler,
1470 .procname = "numa_zonelist_order",
1471 .data = &numa_zonelist_order,
1472 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1474 .proc_handler = numa_zonelist_order_handler,
1477 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1478 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1480 .procname = "vdso_enabled",
1481 #ifdef CONFIG_X86_32
1482 .data = &vdso32_enabled,
1483 .maxlen = sizeof(vdso32_enabled),
1485 .data = &vdso_enabled,
1486 .maxlen = sizeof(vdso_enabled),
1489 .proc_handler = proc_dointvec,
1493 #ifdef CONFIG_HIGHMEM
1495 .procname = "highmem_is_dirtyable",
1496 .data = &vm_highmem_is_dirtyable,
1497 .maxlen = sizeof(vm_highmem_is_dirtyable),
1499 .proc_handler = proc_dointvec_minmax,
1504 #ifdef CONFIG_MEMORY_FAILURE
1506 .procname = "memory_failure_early_kill",
1507 .data = &sysctl_memory_failure_early_kill,
1508 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1510 .proc_handler = proc_dointvec_minmax,
1515 .procname = "memory_failure_recovery",
1516 .data = &sysctl_memory_failure_recovery,
1517 .maxlen = sizeof(sysctl_memory_failure_recovery),
1519 .proc_handler = proc_dointvec_minmax,
1525 .procname = "user_reserve_kbytes",
1526 .data = &sysctl_user_reserve_kbytes,
1527 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1529 .proc_handler = proc_doulongvec_minmax,
1532 .procname = "admin_reserve_kbytes",
1533 .data = &sysctl_admin_reserve_kbytes,
1534 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1536 .proc_handler = proc_doulongvec_minmax,
1541 static struct ctl_table fs_table[] = {
1543 .procname = "inode-nr",
1544 .data = &inodes_stat,
1545 .maxlen = 2*sizeof(long),
1547 .proc_handler = proc_nr_inodes,
1550 .procname = "inode-state",
1551 .data = &inodes_stat,
1552 .maxlen = 7*sizeof(long),
1554 .proc_handler = proc_nr_inodes,
1557 .procname = "file-nr",
1558 .data = &files_stat,
1559 .maxlen = sizeof(files_stat),
1561 .proc_handler = proc_nr_files,
1564 .procname = "file-max",
1565 .data = &files_stat.max_files,
1566 .maxlen = sizeof(files_stat.max_files),
1568 .proc_handler = proc_doulongvec_minmax,
1571 .procname = "nr_open",
1572 .data = &sysctl_nr_open,
1573 .maxlen = sizeof(int),
1575 .proc_handler = proc_dointvec_minmax,
1576 .extra1 = &sysctl_nr_open_min,
1577 .extra2 = &sysctl_nr_open_max,
1580 .procname = "dentry-state",
1581 .data = &dentry_stat,
1582 .maxlen = 6*sizeof(long),
1584 .proc_handler = proc_nr_dentry,
1587 .procname = "overflowuid",
1588 .data = &fs_overflowuid,
1589 .maxlen = sizeof(int),
1591 .proc_handler = proc_dointvec_minmax,
1592 .extra1 = &minolduid,
1593 .extra2 = &maxolduid,
1596 .procname = "overflowgid",
1597 .data = &fs_overflowgid,
1598 .maxlen = sizeof(int),
1600 .proc_handler = proc_dointvec_minmax,
1601 .extra1 = &minolduid,
1602 .extra2 = &maxolduid,
1604 #ifdef CONFIG_FILE_LOCKING
1606 .procname = "leases-enable",
1607 .data = &leases_enable,
1608 .maxlen = sizeof(int),
1610 .proc_handler = proc_dointvec,
1613 #ifdef CONFIG_DNOTIFY
1615 .procname = "dir-notify-enable",
1616 .data = &dir_notify_enable,
1617 .maxlen = sizeof(int),
1619 .proc_handler = proc_dointvec,
1623 #ifdef CONFIG_FILE_LOCKING
1625 .procname = "lease-break-time",
1626 .data = &lease_break_time,
1627 .maxlen = sizeof(int),
1629 .proc_handler = proc_dointvec,
1634 .procname = "aio-nr",
1636 .maxlen = sizeof(aio_nr),
1638 .proc_handler = proc_doulongvec_minmax,
1641 .procname = "aio-max-nr",
1642 .data = &aio_max_nr,
1643 .maxlen = sizeof(aio_max_nr),
1645 .proc_handler = proc_doulongvec_minmax,
1647 #endif /* CONFIG_AIO */
1648 #ifdef CONFIG_INOTIFY_USER
1650 .procname = "inotify",
1652 .child = inotify_table,
1657 .procname = "epoll",
1659 .child = epoll_table,
1664 .procname = "protected_symlinks",
1665 .data = &sysctl_protected_symlinks,
1666 .maxlen = sizeof(int),
1668 .proc_handler = proc_dointvec_minmax,
1673 .procname = "protected_hardlinks",
1674 .data = &sysctl_protected_hardlinks,
1675 .maxlen = sizeof(int),
1677 .proc_handler = proc_dointvec_minmax,
1682 .procname = "suid_dumpable",
1683 .data = &suid_dumpable,
1684 .maxlen = sizeof(int),
1686 .proc_handler = proc_dointvec_minmax_coredump,
1690 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1692 .procname = "binfmt_misc",
1694 .child = sysctl_mount_point,
1698 .procname = "pipe-max-size",
1699 .data = &pipe_max_size,
1700 .maxlen = sizeof(int),
1702 .proc_handler = &pipe_proc_fn,
1703 .extra1 = &pipe_min_size,
1708 static struct ctl_table debug_table[] = {
1709 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1711 .procname = "exception-trace",
1712 .data = &show_unhandled_signals,
1713 .maxlen = sizeof(int),
1715 .proc_handler = proc_dointvec
1718 #if defined(CONFIG_OPTPROBES)
1720 .procname = "kprobes-optimization",
1721 .data = &sysctl_kprobes_optimization,
1722 .maxlen = sizeof(int),
1724 .proc_handler = proc_kprobes_optimization_handler,
1732 static struct ctl_table dev_table[] = {
1736 int __init sysctl_init(void)
1738 struct ctl_table_header *hdr;
1740 hdr = register_sysctl_table(sysctl_base_table);
1741 kmemleak_not_leak(hdr);
1745 #endif /* CONFIG_SYSCTL */
1751 #ifdef CONFIG_PROC_SYSCTL
1753 static int _proc_do_string(char *data, int maxlen, int write,
1754 char __user *buffer,
1755 size_t *lenp, loff_t *ppos)
1761 if (!data || !maxlen || !*lenp) {
1767 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1768 /* Only continue writes not past the end of buffer. */
1770 if (len > maxlen - 1)
1777 /* Start writing from beginning of buffer. */
1783 while ((p - buffer) < *lenp && len < maxlen - 1) {
1784 if (get_user(c, p++))
1786 if (c == 0 || c == '\n')
1807 if (copy_to_user(buffer, data, len))
1810 if (put_user('\n', buffer + len))
1820 static void warn_sysctl_write(struct ctl_table *table)
1822 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1823 "This will not be supported in the future. To silence this\n"
1824 "warning, set kernel.sysctl_writes_strict = -1\n",
1825 current->comm, table->procname);
1829 * proc_dostring - read a string sysctl
1830 * @table: the sysctl table
1831 * @write: %TRUE if this is a write to the sysctl file
1832 * @buffer: the user buffer
1833 * @lenp: the size of the user buffer
1834 * @ppos: file position
1836 * Reads/writes a string from/to the user buffer. If the kernel
1837 * buffer provided is not large enough to hold the string, the
1838 * string is truncated. The copied string is %NULL-terminated.
1839 * If the string is being read by the user process, it is copied
1840 * and a newline '\n' is added. It is truncated if the buffer is
1843 * Returns 0 on success.
1845 int proc_dostring(struct ctl_table *table, int write,
1846 void __user *buffer, size_t *lenp, loff_t *ppos)
1848 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1849 warn_sysctl_write(table);
1851 return _proc_do_string((char *)(table->data), table->maxlen, write,
1852 (char __user *)buffer, lenp, ppos);
1855 static size_t proc_skip_spaces(char **buf)
1858 char *tmp = skip_spaces(*buf);
1864 static void proc_skip_char(char **buf, size_t *size, const char v)
1874 #define TMPBUFLEN 22
1876 * proc_get_long - reads an ASCII formatted integer from a user buffer
1878 * @buf: a kernel buffer
1879 * @size: size of the kernel buffer
1880 * @val: this is where the number will be stored
1881 * @neg: set to %TRUE if number is negative
1882 * @perm_tr: a vector which contains the allowed trailers
1883 * @perm_tr_len: size of the perm_tr vector
1884 * @tr: pointer to store the trailer character
1886 * In case of success %0 is returned and @buf and @size are updated with
1887 * the amount of bytes read. If @tr is non-NULL and a trailing
1888 * character exists (size is non-zero after returning from this
1889 * function), @tr is updated with the trailing character.
1891 static int proc_get_long(char **buf, size_t *size,
1892 unsigned long *val, bool *neg,
1893 const char *perm_tr, unsigned perm_tr_len, char *tr)
1896 char *p, tmp[TMPBUFLEN];
1902 if (len > TMPBUFLEN - 1)
1903 len = TMPBUFLEN - 1;
1905 memcpy(tmp, *buf, len);
1909 if (*p == '-' && *size > 1) {
1917 *val = simple_strtoul(p, &p, 0);
1921 /* We don't know if the next char is whitespace thus we may accept
1922 * invalid integers (e.g. 1234...a) or two integers instead of one
1923 * (e.g. 123...1). So lets not allow such large numbers. */
1924 if (len == TMPBUFLEN - 1)
1927 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1930 if (tr && (len < *size))
1940 * proc_put_long - converts an integer to a decimal ASCII formatted string
1942 * @buf: the user buffer
1943 * @size: the size of the user buffer
1944 * @val: the integer to be converted
1945 * @neg: sign of the number, %TRUE for negative
1947 * In case of success %0 is returned and @buf and @size are updated with
1948 * the amount of bytes written.
1950 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1954 char tmp[TMPBUFLEN], *p = tmp;
1956 sprintf(p, "%s%lu", neg ? "-" : "", val);
1960 if (copy_to_user(*buf, tmp, len))
1968 static int proc_put_char(void __user **buf, size_t *size, char c)
1971 char __user **buffer = (char __user **)buf;
1972 if (put_user(c, *buffer))
1974 (*size)--, (*buffer)++;
1980 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1982 int write, void *data)
1986 if (*lvalp > (unsigned long) INT_MAX + 1)
1990 if (*lvalp > (unsigned long) INT_MAX)
1998 *lvalp = (unsigned long)-val;
2001 *lvalp = (unsigned long)val;
2007 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2009 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2010 int write, void __user *buffer,
2011 size_t *lenp, loff_t *ppos,
2012 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2013 int write, void *data),
2016 int *i, vleft, first = 1, err = 0;
2017 unsigned long page = 0;
2021 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2026 i = (int *) tbl_data;
2027 vleft = table->maxlen / sizeof(*i);
2031 conv = do_proc_dointvec_conv;
2035 switch (sysctl_writes_strict) {
2036 case SYSCTL_WRITES_STRICT:
2038 case SYSCTL_WRITES_WARN:
2039 warn_sysctl_write(table);
2046 if (left > PAGE_SIZE - 1)
2047 left = PAGE_SIZE - 1;
2048 page = __get_free_page(GFP_TEMPORARY);
2049 kbuf = (char *) page;
2052 if (copy_from_user(kbuf, buffer, left)) {
2059 for (; left && vleft--; i++, first=0) {
2064 left -= proc_skip_spaces(&kbuf);
2068 err = proc_get_long(&kbuf, &left, &lval, &neg,
2070 sizeof(proc_wspace_sep), NULL);
2073 if (conv(&neg, &lval, i, 1, data)) {
2078 if (conv(&neg, &lval, i, 0, data)) {
2083 err = proc_put_char(&buffer, &left, '\t');
2086 err = proc_put_long(&buffer, &left, lval, neg);
2092 if (!write && !first && left && !err)
2093 err = proc_put_char(&buffer, &left, '\n');
2094 if (write && !err && left)
2095 left -= proc_skip_spaces(&kbuf);
2100 return err ? : -EINVAL;
2108 static int do_proc_dointvec(struct ctl_table *table, int write,
2109 void __user *buffer, size_t *lenp, loff_t *ppos,
2110 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2111 int write, void *data),
2114 return __do_proc_dointvec(table->data, table, write,
2115 buffer, lenp, ppos, conv, data);
2119 * proc_dointvec - read a vector of integers
2120 * @table: the sysctl table
2121 * @write: %TRUE if this is a write to the sysctl file
2122 * @buffer: the user buffer
2123 * @lenp: the size of the user buffer
2124 * @ppos: file position
2126 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2127 * values from/to the user buffer, treated as an ASCII string.
2129 * Returns 0 on success.
2131 int proc_dointvec(struct ctl_table *table, int write,
2132 void __user *buffer, size_t *lenp, loff_t *ppos)
2134 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2139 * Taint values can only be increased
2140 * This means we can safely use a temporary.
2142 static int proc_taint(struct ctl_table *table, int write,
2143 void __user *buffer, size_t *lenp, loff_t *ppos)
2146 unsigned long tmptaint = get_taint();
2149 if (write && !capable(CAP_SYS_ADMIN))
2154 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2160 * Poor man's atomic or. Not worth adding a primitive
2161 * to everyone's atomic.h for this
2164 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2165 if ((tmptaint >> i) & 1)
2166 add_taint(i, LOCKDEP_STILL_OK);
2173 #ifdef CONFIG_PRINTK
2174 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2175 void __user *buffer, size_t *lenp, loff_t *ppos)
2177 if (write && !capable(CAP_SYS_ADMIN))
2180 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2184 struct do_proc_dointvec_minmax_conv_param {
2189 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2191 int write, void *data)
2193 struct do_proc_dointvec_minmax_conv_param *param = data;
2195 int val = *negp ? -*lvalp : *lvalp;
2196 if ((param->min && *param->min > val) ||
2197 (param->max && *param->max < val))
2204 *lvalp = (unsigned long)-val;
2207 *lvalp = (unsigned long)val;
2214 * proc_dointvec_minmax - read a vector of integers with min/max values
2215 * @table: the sysctl table
2216 * @write: %TRUE if this is a write to the sysctl file
2217 * @buffer: the user buffer
2218 * @lenp: the size of the user buffer
2219 * @ppos: file position
2221 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2222 * values from/to the user buffer, treated as an ASCII string.
2224 * This routine will ensure the values are within the range specified by
2225 * table->extra1 (min) and table->extra2 (max).
2227 * Returns 0 on success.
2229 int proc_dointvec_minmax(struct ctl_table *table, int write,
2230 void __user *buffer, size_t *lenp, loff_t *ppos)
2232 struct do_proc_dointvec_minmax_conv_param param = {
2233 .min = (int *) table->extra1,
2234 .max = (int *) table->extra2,
2236 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2237 do_proc_dointvec_minmax_conv, ¶m);
2240 static void validate_coredump_safety(void)
2242 #ifdef CONFIG_COREDUMP
2243 if (suid_dumpable == SUID_DUMP_ROOT &&
2244 core_pattern[0] != '/' && core_pattern[0] != '|') {
2245 printk(KERN_WARNING "Unsafe core_pattern used with "\
2246 "suid_dumpable=2. Pipe handler or fully qualified "\
2247 "core dump path required.\n");
2252 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2253 void __user *buffer, size_t *lenp, loff_t *ppos)
2255 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2257 validate_coredump_safety();
2261 #ifdef CONFIG_COREDUMP
2262 static int proc_dostring_coredump(struct ctl_table *table, int write,
2263 void __user *buffer, size_t *lenp, loff_t *ppos)
2265 int error = proc_dostring(table, write, buffer, lenp, ppos);
2267 validate_coredump_safety();
2272 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2273 void __user *buffer,
2274 size_t *lenp, loff_t *ppos,
2275 unsigned long convmul,
2276 unsigned long convdiv)
2278 unsigned long *i, *min, *max;
2279 int vleft, first = 1, err = 0;
2280 unsigned long page = 0;
2284 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2289 i = (unsigned long *) data;
2290 min = (unsigned long *) table->extra1;
2291 max = (unsigned long *) table->extra2;
2292 vleft = table->maxlen / sizeof(unsigned long);
2297 switch (sysctl_writes_strict) {
2298 case SYSCTL_WRITES_STRICT:
2300 case SYSCTL_WRITES_WARN:
2301 warn_sysctl_write(table);
2308 if (left > PAGE_SIZE - 1)
2309 left = PAGE_SIZE - 1;
2310 page = __get_free_page(GFP_TEMPORARY);
2311 kbuf = (char *) page;
2314 if (copy_from_user(kbuf, buffer, left)) {
2321 for (; left && vleft--; i++, first = 0) {
2327 left -= proc_skip_spaces(&kbuf);
2329 err = proc_get_long(&kbuf, &left, &val, &neg,
2331 sizeof(proc_wspace_sep), NULL);
2336 if ((min && val < *min) || (max && val > *max))
2340 val = convdiv * (*i) / convmul;
2342 err = proc_put_char(&buffer, &left, '\t');
2346 err = proc_put_long(&buffer, &left, val, false);
2352 if (!write && !first && left && !err)
2353 err = proc_put_char(&buffer, &left, '\n');
2355 left -= proc_skip_spaces(&kbuf);
2360 return err ? : -EINVAL;
2368 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2369 void __user *buffer,
2370 size_t *lenp, loff_t *ppos,
2371 unsigned long convmul,
2372 unsigned long convdiv)
2374 return __do_proc_doulongvec_minmax(table->data, table, write,
2375 buffer, lenp, ppos, convmul, convdiv);
2379 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2380 * @table: the sysctl table
2381 * @write: %TRUE if this is a write to the sysctl file
2382 * @buffer: the user buffer
2383 * @lenp: the size of the user buffer
2384 * @ppos: file position
2386 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2387 * values from/to the user buffer, treated as an ASCII string.
2389 * This routine will ensure the values are within the range specified by
2390 * table->extra1 (min) and table->extra2 (max).
2392 * Returns 0 on success.
2394 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2395 void __user *buffer, size_t *lenp, loff_t *ppos)
2397 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2401 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2402 * @table: the sysctl table
2403 * @write: %TRUE if this is a write to the sysctl file
2404 * @buffer: the user buffer
2405 * @lenp: the size of the user buffer
2406 * @ppos: file position
2408 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2409 * values from/to the user buffer, treated as an ASCII string. The values
2410 * are treated as milliseconds, and converted to jiffies when they are stored.
2412 * This routine will ensure the values are within the range specified by
2413 * table->extra1 (min) and table->extra2 (max).
2415 * Returns 0 on success.
2417 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2418 void __user *buffer,
2419 size_t *lenp, loff_t *ppos)
2421 return do_proc_doulongvec_minmax(table, write, buffer,
2422 lenp, ppos, HZ, 1000l);
2426 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2428 int write, void *data)
2431 if (*lvalp > LONG_MAX / HZ)
2433 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2439 lval = (unsigned long)-val;
2442 lval = (unsigned long)val;
2449 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2451 int write, void *data)
2454 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2456 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2462 lval = (unsigned long)-val;
2465 lval = (unsigned long)val;
2467 *lvalp = jiffies_to_clock_t(lval);
2472 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2474 int write, void *data)
2477 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2487 lval = (unsigned long)-val;
2490 lval = (unsigned long)val;
2492 *lvalp = jiffies_to_msecs(lval);
2498 * proc_dointvec_jiffies - read a vector of integers as seconds
2499 * @table: the sysctl table
2500 * @write: %TRUE if this is a write to the sysctl file
2501 * @buffer: the user buffer
2502 * @lenp: the size of the user buffer
2503 * @ppos: file position
2505 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2506 * values from/to the user buffer, treated as an ASCII string.
2507 * The values read are assumed to be in seconds, and are converted into
2510 * Returns 0 on success.
2512 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2513 void __user *buffer, size_t *lenp, loff_t *ppos)
2515 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2516 do_proc_dointvec_jiffies_conv,NULL);
2520 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2521 * @table: the sysctl table
2522 * @write: %TRUE if this is a write to the sysctl file
2523 * @buffer: the user buffer
2524 * @lenp: the size of the user buffer
2525 * @ppos: pointer to the file position
2527 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2528 * values from/to the user buffer, treated as an ASCII string.
2529 * The values read are assumed to be in 1/USER_HZ seconds, and
2530 * are converted into jiffies.
2532 * Returns 0 on success.
2534 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2535 void __user *buffer, size_t *lenp, loff_t *ppos)
2537 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2538 do_proc_dointvec_userhz_jiffies_conv,NULL);
2542 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2543 * @table: the sysctl table
2544 * @write: %TRUE if this is a write to the sysctl file
2545 * @buffer: the user buffer
2546 * @lenp: the size of the user buffer
2547 * @ppos: file position
2548 * @ppos: the current position in the file
2550 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2551 * values from/to the user buffer, treated as an ASCII string.
2552 * The values read are assumed to be in 1/1000 seconds, and
2553 * are converted into jiffies.
2555 * Returns 0 on success.
2557 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2558 void __user *buffer, size_t *lenp, loff_t *ppos)
2560 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2561 do_proc_dointvec_ms_jiffies_conv, NULL);
2564 static int proc_do_cad_pid(struct ctl_table *table, int write,
2565 void __user *buffer, size_t *lenp, loff_t *ppos)
2567 struct pid *new_pid;
2571 tmp = pid_vnr(cad_pid);
2573 r = __do_proc_dointvec(&tmp, table, write, buffer,
2574 lenp, ppos, NULL, NULL);
2578 new_pid = find_get_pid(tmp);
2582 put_pid(xchg(&cad_pid, new_pid));
2587 * proc_do_large_bitmap - read/write from/to a large bitmap
2588 * @table: the sysctl table
2589 * @write: %TRUE if this is a write to the sysctl file
2590 * @buffer: the user buffer
2591 * @lenp: the size of the user buffer
2592 * @ppos: file position
2594 * The bitmap is stored at table->data and the bitmap length (in bits)
2597 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2598 * large bitmaps may be represented in a compact manner. Writing into
2599 * the file will clear the bitmap then update it with the given input.
2601 * Returns 0 on success.
2603 int proc_do_large_bitmap(struct ctl_table *table, int write,
2604 void __user *buffer, size_t *lenp, loff_t *ppos)
2608 size_t left = *lenp;
2609 unsigned long bitmap_len = table->maxlen;
2610 unsigned long *bitmap = *(unsigned long **) table->data;
2611 unsigned long *tmp_bitmap = NULL;
2612 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2614 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2620 unsigned long page = 0;
2623 if (left > PAGE_SIZE - 1)
2624 left = PAGE_SIZE - 1;
2626 page = __get_free_page(GFP_TEMPORARY);
2627 kbuf = (char *) page;
2630 if (copy_from_user(kbuf, buffer, left)) {
2636 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2642 proc_skip_char(&kbuf, &left, '\n');
2643 while (!err && left) {
2644 unsigned long val_a, val_b;
2647 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2651 if (val_a >= bitmap_len || neg) {
2663 err = proc_get_long(&kbuf, &left, &val_b,
2664 &neg, tr_b, sizeof(tr_b),
2668 if (val_b >= bitmap_len || neg ||
2679 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2681 proc_skip_char(&kbuf, &left, '\n');
2685 unsigned long bit_a, bit_b = 0;
2688 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2689 if (bit_a >= bitmap_len)
2691 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2695 err = proc_put_char(&buffer, &left, ',');
2699 err = proc_put_long(&buffer, &left, bit_a, false);
2702 if (bit_a != bit_b) {
2703 err = proc_put_char(&buffer, &left, '-');
2706 err = proc_put_long(&buffer, &left, bit_b, false);
2714 err = proc_put_char(&buffer, &left, '\n');
2720 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2722 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2734 #else /* CONFIG_PROC_SYSCTL */
2736 int proc_dostring(struct ctl_table *table, int write,
2737 void __user *buffer, size_t *lenp, loff_t *ppos)
2742 int proc_dointvec(struct ctl_table *table, int write,
2743 void __user *buffer, size_t *lenp, loff_t *ppos)
2748 int proc_dointvec_minmax(struct ctl_table *table, int write,
2749 void __user *buffer, size_t *lenp, loff_t *ppos)
2754 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2755 void __user *buffer, size_t *lenp, loff_t *ppos)
2760 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2761 void __user *buffer, size_t *lenp, loff_t *ppos)
2766 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2767 void __user *buffer, size_t *lenp, loff_t *ppos)
2772 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2773 void __user *buffer, size_t *lenp, loff_t *ppos)
2778 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2779 void __user *buffer,
2780 size_t *lenp, loff_t *ppos)
2786 #endif /* CONFIG_PROC_SYSCTL */
2789 * No sense putting this after each symbol definition, twice,
2790 * exception granted :-)
2792 EXPORT_SYMBOL(proc_dointvec);
2793 EXPORT_SYMBOL(proc_dointvec_jiffies);
2794 EXPORT_SYMBOL(proc_dointvec_minmax);
2795 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2796 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2797 EXPORT_SYMBOL(proc_dostring);
2798 EXPORT_SYMBOL(proc_doulongvec_minmax);
2799 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);