2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/kexec.h>
67 #include <asm/uaccess.h>
68 #include <asm/processor.h>
72 #include <asm/stacktrace.h>
76 #include <asm/setup.h>
78 #ifdef CONFIG_BSD_PROCESS_ACCT
79 #include <linux/acct.h>
81 #ifdef CONFIG_RT_MUTEXES
82 #include <linux/rtmutex.h>
84 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85 #include <linux/lockdep.h>
87 #ifdef CONFIG_CHR_DEV_SG
91 #ifdef CONFIG_LOCKUP_DETECTOR
92 #include <linux/nmi.h>
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
99 extern int max_threads;
100 extern int suid_dumpable;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid;
103 extern char core_pattern[];
104 extern unsigned int core_pipe_limit;
107 extern int pid_max_min, pid_max_max;
108 extern int percpu_pagelist_fraction;
109 extern int compat_log;
110 extern int latencytop_enabled;
111 extern int sysctl_nr_open_min, sysctl_nr_open_max;
113 extern int sysctl_nr_trim_pages;
116 /* Constants used for minimum and maximum */
117 #ifdef CONFIG_LOCKUP_DETECTOR
118 static int sixty = 60;
121 static int __maybe_unused neg_one = -1;
124 static int __maybe_unused one = 1;
125 static int __maybe_unused two = 2;
126 static int __maybe_unused four = 4;
127 static unsigned long one_ul = 1;
128 static int one_hundred = 100;
130 static int ten_thousand = 10000;
133 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
134 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
136 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
137 static int maxolduid = 65535;
138 static int minolduid;
139 static int min_percpu_pagelist_fract = 8;
141 static int ngroups_max = NGROUPS_MAX;
142 static const int cap_last_cap = CAP_LAST_CAP;
144 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
145 #ifdef CONFIG_DETECT_HUNG_TASK
146 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
149 #ifdef CONFIG_INOTIFY_USER
150 #include <linux/inotify.h>
155 #ifdef CONFIG_SPARC64
156 extern int sysctl_tsb_ratio;
160 extern int pwrsw_enabled;
163 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
164 extern int unaligned_enabled;
168 extern int unaligned_dump_stack;
171 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172 extern int no_unaligned_warning;
175 #ifdef CONFIG_PROC_SYSCTL
176 static int proc_do_cad_pid(struct ctl_table *table, int write,
177 void __user *buffer, size_t *lenp, loff_t *ppos);
178 static int proc_taint(struct ctl_table *table, int write,
179 void __user *buffer, size_t *lenp, loff_t *ppos);
183 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
187 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
188 void __user *buffer, size_t *lenp, loff_t *ppos);
189 #ifdef CONFIG_COREDUMP
190 static int proc_dostring_coredump(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
194 #ifdef CONFIG_MAGIC_SYSRQ
195 /* Note: sysrq code uses it's own private copy */
196 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
198 static int sysrq_sysctl_handler(ctl_table *table, int write,
199 void __user *buffer, size_t *lenp,
204 error = proc_dointvec(table, write, buffer, lenp, ppos);
209 sysrq_toggle_support(__sysrq_enabled);
216 static struct ctl_table kern_table[];
217 static struct ctl_table vm_table[];
218 static struct ctl_table fs_table[];
219 static struct ctl_table debug_table[];
220 static struct ctl_table dev_table[];
221 extern struct ctl_table random_table[];
223 extern struct ctl_table epoll_table[];
226 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
227 int sysctl_legacy_va_layout;
230 /* The default sysctl tables: */
232 static struct ctl_table sysctl_base_table[] = {
234 .procname = "kernel",
251 .child = debug_table,
261 #ifdef CONFIG_SCHED_DEBUG
262 static int min_sched_granularity_ns = 100000; /* 100 usecs */
263 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
264 static int min_wakeup_granularity_ns; /* 0 usecs */
265 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
267 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
268 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
269 #endif /* CONFIG_SMP */
270 #endif /* CONFIG_SCHED_DEBUG */
272 #ifdef CONFIG_COMPACTION
273 static int min_extfrag_threshold;
274 static int max_extfrag_threshold = 1000;
277 static struct ctl_table kern_table[] = {
279 .procname = "sched_child_runs_first",
280 .data = &sysctl_sched_child_runs_first,
281 .maxlen = sizeof(unsigned int),
283 .proc_handler = proc_dointvec,
285 #ifdef CONFIG_SCHED_DEBUG
287 .procname = "sched_min_granularity_ns",
288 .data = &sysctl_sched_min_granularity,
289 .maxlen = sizeof(unsigned int),
291 .proc_handler = sched_proc_update_handler,
292 .extra1 = &min_sched_granularity_ns,
293 .extra2 = &max_sched_granularity_ns,
296 .procname = "sched_latency_ns",
297 .data = &sysctl_sched_latency,
298 .maxlen = sizeof(unsigned int),
300 .proc_handler = sched_proc_update_handler,
301 .extra1 = &min_sched_granularity_ns,
302 .extra2 = &max_sched_granularity_ns,
305 .procname = "sched_wakeup_granularity_ns",
306 .data = &sysctl_sched_wakeup_granularity,
307 .maxlen = sizeof(unsigned int),
309 .proc_handler = sched_proc_update_handler,
310 .extra1 = &min_wakeup_granularity_ns,
311 .extra2 = &max_wakeup_granularity_ns,
315 .procname = "sched_tunable_scaling",
316 .data = &sysctl_sched_tunable_scaling,
317 .maxlen = sizeof(enum sched_tunable_scaling),
319 .proc_handler = sched_proc_update_handler,
320 .extra1 = &min_sched_tunable_scaling,
321 .extra2 = &max_sched_tunable_scaling,
324 .procname = "sched_migration_cost_ns",
325 .data = &sysctl_sched_migration_cost,
326 .maxlen = sizeof(unsigned int),
328 .proc_handler = proc_dointvec,
331 .procname = "sched_nr_migrate",
332 .data = &sysctl_sched_nr_migrate,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = proc_dointvec,
338 .procname = "sched_time_avg_ms",
339 .data = &sysctl_sched_time_avg,
340 .maxlen = sizeof(unsigned int),
342 .proc_handler = proc_dointvec,
345 .procname = "sched_shares_window_ns",
346 .data = &sysctl_sched_shares_window,
347 .maxlen = sizeof(unsigned int),
349 .proc_handler = proc_dointvec,
352 .procname = "timer_migration",
353 .data = &sysctl_timer_migration,
354 .maxlen = sizeof(unsigned int),
356 .proc_handler = proc_dointvec_minmax,
360 #endif /* CONFIG_SMP */
361 #ifdef CONFIG_NUMA_BALANCING
363 .procname = "numa_balancing_scan_delay_ms",
364 .data = &sysctl_numa_balancing_scan_delay,
365 .maxlen = sizeof(unsigned int),
367 .proc_handler = proc_dointvec,
370 .procname = "numa_balancing_scan_period_min_ms",
371 .data = &sysctl_numa_balancing_scan_period_min,
372 .maxlen = sizeof(unsigned int),
374 .proc_handler = proc_dointvec,
377 .procname = "numa_balancing_scan_period_max_ms",
378 .data = &sysctl_numa_balancing_scan_period_max,
379 .maxlen = sizeof(unsigned int),
381 .proc_handler = proc_dointvec,
384 .procname = "numa_balancing_scan_size_mb",
385 .data = &sysctl_numa_balancing_scan_size,
386 .maxlen = sizeof(unsigned int),
388 .proc_handler = proc_dointvec,
391 .procname = "numa_balancing",
392 .data = NULL, /* filled in by handler */
393 .maxlen = sizeof(unsigned int),
395 .proc_handler = sysctl_numa_balancing,
399 #endif /* CONFIG_NUMA_BALANCING */
400 #endif /* CONFIG_SCHED_DEBUG */
402 .procname = "sched_rt_period_us",
403 .data = &sysctl_sched_rt_period,
404 .maxlen = sizeof(unsigned int),
406 .proc_handler = sched_rt_handler,
409 .procname = "sched_rt_runtime_us",
410 .data = &sysctl_sched_rt_runtime,
411 .maxlen = sizeof(int),
413 .proc_handler = sched_rt_handler,
416 .procname = "sched_rr_timeslice_ms",
417 .data = &sched_rr_timeslice,
418 .maxlen = sizeof(int),
420 .proc_handler = sched_rr_handler,
422 #ifdef CONFIG_SCHED_AUTOGROUP
424 .procname = "sched_autogroup_enabled",
425 .data = &sysctl_sched_autogroup_enabled,
426 .maxlen = sizeof(unsigned int),
428 .proc_handler = proc_dointvec_minmax,
433 #ifdef CONFIG_CFS_BANDWIDTH
435 .procname = "sched_cfs_bandwidth_slice_us",
436 .data = &sysctl_sched_cfs_bandwidth_slice,
437 .maxlen = sizeof(unsigned int),
439 .proc_handler = proc_dointvec_minmax,
443 #ifdef CONFIG_PROVE_LOCKING
445 .procname = "prove_locking",
446 .data = &prove_locking,
447 .maxlen = sizeof(int),
449 .proc_handler = proc_dointvec,
452 #ifdef CONFIG_LOCK_STAT
454 .procname = "lock_stat",
456 .maxlen = sizeof(int),
458 .proc_handler = proc_dointvec,
463 .data = &panic_timeout,
464 .maxlen = sizeof(int),
466 .proc_handler = proc_dointvec,
468 #ifdef CONFIG_COREDUMP
470 .procname = "core_uses_pid",
471 .data = &core_uses_pid,
472 .maxlen = sizeof(int),
474 .proc_handler = proc_dointvec,
477 .procname = "core_pattern",
478 .data = core_pattern,
479 .maxlen = CORENAME_MAX_SIZE,
481 .proc_handler = proc_dostring_coredump,
484 .procname = "core_pipe_limit",
485 .data = &core_pipe_limit,
486 .maxlen = sizeof(unsigned int),
488 .proc_handler = proc_dointvec,
491 #ifdef CONFIG_PROC_SYSCTL
493 .procname = "tainted",
494 .maxlen = sizeof(long),
496 .proc_handler = proc_taint,
499 #ifdef CONFIG_LATENCYTOP
501 .procname = "latencytop",
502 .data = &latencytop_enabled,
503 .maxlen = sizeof(int),
505 .proc_handler = proc_dointvec,
508 #ifdef CONFIG_BLK_DEV_INITRD
510 .procname = "real-root-dev",
511 .data = &real_root_dev,
512 .maxlen = sizeof(int),
514 .proc_handler = proc_dointvec,
518 .procname = "print-fatal-signals",
519 .data = &print_fatal_signals,
520 .maxlen = sizeof(int),
522 .proc_handler = proc_dointvec,
526 .procname = "reboot-cmd",
527 .data = reboot_command,
530 .proc_handler = proc_dostring,
533 .procname = "stop-a",
534 .data = &stop_a_enabled,
535 .maxlen = sizeof (int),
537 .proc_handler = proc_dointvec,
540 .procname = "scons-poweroff",
541 .data = &scons_pwroff,
542 .maxlen = sizeof (int),
544 .proc_handler = proc_dointvec,
547 #ifdef CONFIG_SPARC64
549 .procname = "tsb-ratio",
550 .data = &sysctl_tsb_ratio,
551 .maxlen = sizeof (int),
553 .proc_handler = proc_dointvec,
558 .procname = "soft-power",
559 .data = &pwrsw_enabled,
560 .maxlen = sizeof (int),
562 .proc_handler = proc_dointvec,
565 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
567 .procname = "unaligned-trap",
568 .data = &unaligned_enabled,
569 .maxlen = sizeof (int),
571 .proc_handler = proc_dointvec,
575 .procname = "ctrl-alt-del",
577 .maxlen = sizeof(int),
579 .proc_handler = proc_dointvec,
581 #ifdef CONFIG_FUNCTION_TRACER
583 .procname = "ftrace_enabled",
584 .data = &ftrace_enabled,
585 .maxlen = sizeof(int),
587 .proc_handler = ftrace_enable_sysctl,
590 #ifdef CONFIG_STACK_TRACER
592 .procname = "stack_tracer_enabled",
593 .data = &stack_tracer_enabled,
594 .maxlen = sizeof(int),
596 .proc_handler = stack_trace_sysctl,
599 #ifdef CONFIG_TRACING
601 .procname = "ftrace_dump_on_oops",
602 .data = &ftrace_dump_on_oops,
603 .maxlen = sizeof(int),
605 .proc_handler = proc_dointvec,
608 .procname = "traceoff_on_warning",
609 .data = &__disable_trace_on_warning,
610 .maxlen = sizeof(__disable_trace_on_warning),
612 .proc_handler = proc_dointvec,
617 .procname = "kexec_load_disabled",
618 .data = &kexec_load_disabled,
619 .maxlen = sizeof(int),
621 /* only handle a transition from default "0" to "1" */
622 .proc_handler = proc_dointvec_minmax,
627 #ifdef CONFIG_MODULES
629 .procname = "modprobe",
630 .data = &modprobe_path,
631 .maxlen = KMOD_PATH_LEN,
633 .proc_handler = proc_dostring,
636 .procname = "modules_disabled",
637 .data = &modules_disabled,
638 .maxlen = sizeof(int),
640 /* only handle a transition from default "0" to "1" */
641 .proc_handler = proc_dointvec_minmax,
646 #ifdef CONFIG_UEVENT_HELPER
648 .procname = "hotplug",
649 .data = &uevent_helper,
650 .maxlen = UEVENT_HELPER_PATH_LEN,
652 .proc_handler = proc_dostring,
655 #ifdef CONFIG_CHR_DEV_SG
657 .procname = "sg-big-buff",
658 .data = &sg_big_buff,
659 .maxlen = sizeof (int),
661 .proc_handler = proc_dointvec,
664 #ifdef CONFIG_BSD_PROCESS_ACCT
668 .maxlen = 3*sizeof(int),
670 .proc_handler = proc_dointvec,
673 #ifdef CONFIG_MAGIC_SYSRQ
676 .data = &__sysrq_enabled,
677 .maxlen = sizeof (int),
679 .proc_handler = sysrq_sysctl_handler,
682 #ifdef CONFIG_PROC_SYSCTL
684 .procname = "cad_pid",
686 .maxlen = sizeof (int),
688 .proc_handler = proc_do_cad_pid,
692 .procname = "threads-max",
693 .data = &max_threads,
694 .maxlen = sizeof(int),
696 .proc_handler = proc_dointvec,
699 .procname = "random",
701 .child = random_table,
704 .procname = "usermodehelper",
706 .child = usermodehelper_table,
709 .procname = "overflowuid",
710 .data = &overflowuid,
711 .maxlen = sizeof(int),
713 .proc_handler = proc_dointvec_minmax,
714 .extra1 = &minolduid,
715 .extra2 = &maxolduid,
718 .procname = "overflowgid",
719 .data = &overflowgid,
720 .maxlen = sizeof(int),
722 .proc_handler = proc_dointvec_minmax,
723 .extra1 = &minolduid,
724 .extra2 = &maxolduid,
727 #ifdef CONFIG_MATHEMU
729 .procname = "ieee_emulation_warnings",
730 .data = &sysctl_ieee_emulation_warnings,
731 .maxlen = sizeof(int),
733 .proc_handler = proc_dointvec,
737 .procname = "userprocess_debug",
738 .data = &show_unhandled_signals,
739 .maxlen = sizeof(int),
741 .proc_handler = proc_dointvec,
745 .procname = "pid_max",
747 .maxlen = sizeof (int),
749 .proc_handler = proc_dointvec_minmax,
750 .extra1 = &pid_max_min,
751 .extra2 = &pid_max_max,
754 .procname = "panic_on_oops",
755 .data = &panic_on_oops,
756 .maxlen = sizeof(int),
758 .proc_handler = proc_dointvec,
760 #if defined CONFIG_PRINTK
762 .procname = "printk",
763 .data = &console_loglevel,
764 .maxlen = 4*sizeof(int),
766 .proc_handler = proc_dointvec,
769 .procname = "printk_ratelimit",
770 .data = &printk_ratelimit_state.interval,
771 .maxlen = sizeof(int),
773 .proc_handler = proc_dointvec_jiffies,
776 .procname = "printk_ratelimit_burst",
777 .data = &printk_ratelimit_state.burst,
778 .maxlen = sizeof(int),
780 .proc_handler = proc_dointvec,
783 .procname = "printk_delay",
784 .data = &printk_delay_msec,
785 .maxlen = sizeof(int),
787 .proc_handler = proc_dointvec_minmax,
789 .extra2 = &ten_thousand,
792 .procname = "dmesg_restrict",
793 .data = &dmesg_restrict,
794 .maxlen = sizeof(int),
796 .proc_handler = proc_dointvec_minmax_sysadmin,
801 .procname = "kptr_restrict",
802 .data = &kptr_restrict,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dointvec_minmax_sysadmin,
811 .procname = "ngroups_max",
812 .data = &ngroups_max,
813 .maxlen = sizeof (int),
815 .proc_handler = proc_dointvec,
818 .procname = "cap_last_cap",
819 .data = (void *)&cap_last_cap,
820 .maxlen = sizeof(int),
822 .proc_handler = proc_dointvec,
824 #if defined(CONFIG_LOCKUP_DETECTOR)
826 .procname = "watchdog",
827 .data = &watchdog_user_enabled,
828 .maxlen = sizeof (int),
830 .proc_handler = proc_dowatchdog,
835 .procname = "watchdog_thresh",
836 .data = &watchdog_thresh,
837 .maxlen = sizeof(int),
839 .proc_handler = proc_dowatchdog,
844 .procname = "softlockup_panic",
845 .data = &softlockup_panic,
846 .maxlen = sizeof(int),
848 .proc_handler = proc_dointvec_minmax,
853 .procname = "nmi_watchdog",
854 .data = &watchdog_user_enabled,
855 .maxlen = sizeof (int),
857 .proc_handler = proc_dowatchdog,
862 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
864 .procname = "unknown_nmi_panic",
865 .data = &unknown_nmi_panic,
866 .maxlen = sizeof (int),
868 .proc_handler = proc_dointvec,
871 #if defined(CONFIG_X86)
873 .procname = "panic_on_unrecovered_nmi",
874 .data = &panic_on_unrecovered_nmi,
875 .maxlen = sizeof(int),
877 .proc_handler = proc_dointvec,
880 .procname = "panic_on_io_nmi",
881 .data = &panic_on_io_nmi,
882 .maxlen = sizeof(int),
884 .proc_handler = proc_dointvec,
886 #ifdef CONFIG_DEBUG_STACKOVERFLOW
888 .procname = "panic_on_stackoverflow",
889 .data = &sysctl_panic_on_stackoverflow,
890 .maxlen = sizeof(int),
892 .proc_handler = proc_dointvec,
896 .procname = "bootloader_type",
897 .data = &bootloader_type,
898 .maxlen = sizeof (int),
900 .proc_handler = proc_dointvec,
903 .procname = "bootloader_version",
904 .data = &bootloader_version,
905 .maxlen = sizeof (int),
907 .proc_handler = proc_dointvec,
910 .procname = "kstack_depth_to_print",
911 .data = &kstack_depth_to_print,
912 .maxlen = sizeof(int),
914 .proc_handler = proc_dointvec,
917 .procname = "io_delay_type",
918 .data = &io_delay_type,
919 .maxlen = sizeof(int),
921 .proc_handler = proc_dointvec,
924 #if defined(CONFIG_MMU)
926 .procname = "randomize_va_space",
927 .data = &randomize_va_space,
928 .maxlen = sizeof(int),
930 .proc_handler = proc_dointvec,
933 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
935 .procname = "spin_retry",
937 .maxlen = sizeof (int),
939 .proc_handler = proc_dointvec,
942 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
944 .procname = "acpi_video_flags",
945 .data = &acpi_realmode_flags,
946 .maxlen = sizeof (unsigned long),
948 .proc_handler = proc_doulongvec_minmax,
951 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
953 .procname = "ignore-unaligned-usertrap",
954 .data = &no_unaligned_warning,
955 .maxlen = sizeof (int),
957 .proc_handler = proc_dointvec,
962 .procname = "unaligned-dump-stack",
963 .data = &unaligned_dump_stack,
964 .maxlen = sizeof (int),
966 .proc_handler = proc_dointvec,
969 #ifdef CONFIG_DETECT_HUNG_TASK
971 .procname = "hung_task_panic",
972 .data = &sysctl_hung_task_panic,
973 .maxlen = sizeof(int),
975 .proc_handler = proc_dointvec_minmax,
980 .procname = "hung_task_check_count",
981 .data = &sysctl_hung_task_check_count,
982 .maxlen = sizeof(int),
984 .proc_handler = proc_dointvec_minmax,
988 .procname = "hung_task_timeout_secs",
989 .data = &sysctl_hung_task_timeout_secs,
990 .maxlen = sizeof(unsigned long),
992 .proc_handler = proc_dohung_task_timeout_secs,
993 .extra2 = &hung_task_timeout_max,
996 .procname = "hung_task_warnings",
997 .data = &sysctl_hung_task_warnings,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec_minmax,
1004 #ifdef CONFIG_COMPAT
1006 .procname = "compat-log",
1007 .data = &compat_log,
1008 .maxlen = sizeof (int),
1010 .proc_handler = proc_dointvec,
1013 #ifdef CONFIG_RT_MUTEXES
1015 .procname = "max_lock_depth",
1016 .data = &max_lock_depth,
1017 .maxlen = sizeof(int),
1019 .proc_handler = proc_dointvec,
1023 .procname = "poweroff_cmd",
1024 .data = &poweroff_cmd,
1025 .maxlen = POWEROFF_CMD_PATH_LEN,
1027 .proc_handler = proc_dostring,
1033 .child = key_sysctls,
1036 #ifdef CONFIG_RCU_TORTURE_TEST
1038 .procname = "rcutorture_runnable",
1039 .data = &rcutorture_runnable,
1040 .maxlen = sizeof(int),
1042 .proc_handler = proc_dointvec,
1045 #ifdef CONFIG_PERF_EVENTS
1047 * User-space scripts rely on the existence of this file
1048 * as a feature check for perf_events being enabled.
1050 * So it's an ABI, do not remove!
1053 .procname = "perf_event_paranoid",
1054 .data = &sysctl_perf_event_paranoid,
1055 .maxlen = sizeof(sysctl_perf_event_paranoid),
1057 .proc_handler = proc_dointvec,
1060 .procname = "perf_event_mlock_kb",
1061 .data = &sysctl_perf_event_mlock,
1062 .maxlen = sizeof(sysctl_perf_event_mlock),
1064 .proc_handler = proc_dointvec,
1067 .procname = "perf_event_max_sample_rate",
1068 .data = &sysctl_perf_event_sample_rate,
1069 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1071 .proc_handler = perf_proc_update_handler,
1075 .procname = "perf_cpu_time_max_percent",
1076 .data = &sysctl_perf_cpu_time_max_percent,
1077 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1079 .proc_handler = perf_cpu_time_max_percent_handler,
1081 .extra2 = &one_hundred,
1084 #ifdef CONFIG_KMEMCHECK
1086 .procname = "kmemcheck",
1087 .data = &kmemcheck_enabled,
1088 .maxlen = sizeof(int),
1090 .proc_handler = proc_dointvec,
1096 static struct ctl_table vm_table[] = {
1098 .procname = "overcommit_memory",
1099 .data = &sysctl_overcommit_memory,
1100 .maxlen = sizeof(sysctl_overcommit_memory),
1102 .proc_handler = proc_dointvec_minmax,
1107 .procname = "panic_on_oom",
1108 .data = &sysctl_panic_on_oom,
1109 .maxlen = sizeof(sysctl_panic_on_oom),
1111 .proc_handler = proc_dointvec_minmax,
1116 .procname = "oom_kill_allocating_task",
1117 .data = &sysctl_oom_kill_allocating_task,
1118 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1120 .proc_handler = proc_dointvec,
1123 .procname = "oom_dump_tasks",
1124 .data = &sysctl_oom_dump_tasks,
1125 .maxlen = sizeof(sysctl_oom_dump_tasks),
1127 .proc_handler = proc_dointvec,
1130 .procname = "overcommit_ratio",
1131 .data = &sysctl_overcommit_ratio,
1132 .maxlen = sizeof(sysctl_overcommit_ratio),
1134 .proc_handler = overcommit_ratio_handler,
1137 .procname = "overcommit_kbytes",
1138 .data = &sysctl_overcommit_kbytes,
1139 .maxlen = sizeof(sysctl_overcommit_kbytes),
1141 .proc_handler = overcommit_kbytes_handler,
1144 .procname = "page-cluster",
1145 .data = &page_cluster,
1146 .maxlen = sizeof(int),
1148 .proc_handler = proc_dointvec_minmax,
1152 .procname = "dirty_background_ratio",
1153 .data = &dirty_background_ratio,
1154 .maxlen = sizeof(dirty_background_ratio),
1156 .proc_handler = dirty_background_ratio_handler,
1158 .extra2 = &one_hundred,
1161 .procname = "dirty_background_bytes",
1162 .data = &dirty_background_bytes,
1163 .maxlen = sizeof(dirty_background_bytes),
1165 .proc_handler = dirty_background_bytes_handler,
1169 .procname = "dirty_ratio",
1170 .data = &vm_dirty_ratio,
1171 .maxlen = sizeof(vm_dirty_ratio),
1173 .proc_handler = dirty_ratio_handler,
1175 .extra2 = &one_hundred,
1178 .procname = "dirty_bytes",
1179 .data = &vm_dirty_bytes,
1180 .maxlen = sizeof(vm_dirty_bytes),
1182 .proc_handler = dirty_bytes_handler,
1183 .extra1 = &dirty_bytes_min,
1186 .procname = "dirty_writeback_centisecs",
1187 .data = &dirty_writeback_interval,
1188 .maxlen = sizeof(dirty_writeback_interval),
1190 .proc_handler = dirty_writeback_centisecs_handler,
1193 .procname = "dirty_expire_centisecs",
1194 .data = &dirty_expire_interval,
1195 .maxlen = sizeof(dirty_expire_interval),
1197 .proc_handler = proc_dointvec_minmax,
1201 .procname = "nr_pdflush_threads",
1202 .mode = 0444 /* read-only */,
1203 .proc_handler = pdflush_proc_obsolete,
1206 .procname = "swappiness",
1207 .data = &vm_swappiness,
1208 .maxlen = sizeof(vm_swappiness),
1210 .proc_handler = proc_dointvec_minmax,
1212 .extra2 = &one_hundred,
1214 #ifdef CONFIG_HUGETLB_PAGE
1216 .procname = "nr_hugepages",
1218 .maxlen = sizeof(unsigned long),
1220 .proc_handler = hugetlb_sysctl_handler,
1221 .extra1 = (void *)&hugetlb_zero,
1222 .extra2 = (void *)&hugetlb_infinity,
1226 .procname = "nr_hugepages_mempolicy",
1228 .maxlen = sizeof(unsigned long),
1230 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1231 .extra1 = (void *)&hugetlb_zero,
1232 .extra2 = (void *)&hugetlb_infinity,
1236 .procname = "hugetlb_shm_group",
1237 .data = &sysctl_hugetlb_shm_group,
1238 .maxlen = sizeof(gid_t),
1240 .proc_handler = proc_dointvec,
1243 .procname = "hugepages_treat_as_movable",
1244 .data = &hugepages_treat_as_movable,
1245 .maxlen = sizeof(int),
1247 .proc_handler = proc_dointvec,
1250 .procname = "nr_overcommit_hugepages",
1252 .maxlen = sizeof(unsigned long),
1254 .proc_handler = hugetlb_overcommit_handler,
1255 .extra1 = (void *)&hugetlb_zero,
1256 .extra2 = (void *)&hugetlb_infinity,
1260 .procname = "lowmem_reserve_ratio",
1261 .data = &sysctl_lowmem_reserve_ratio,
1262 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1264 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1267 .procname = "drop_caches",
1268 .data = &sysctl_drop_caches,
1269 .maxlen = sizeof(int),
1271 .proc_handler = drop_caches_sysctl_handler,
1275 #ifdef CONFIG_COMPACTION
1277 .procname = "compact_memory",
1278 .data = &sysctl_compact_memory,
1279 .maxlen = sizeof(int),
1281 .proc_handler = sysctl_compaction_handler,
1284 .procname = "extfrag_threshold",
1285 .data = &sysctl_extfrag_threshold,
1286 .maxlen = sizeof(int),
1288 .proc_handler = sysctl_extfrag_handler,
1289 .extra1 = &min_extfrag_threshold,
1290 .extra2 = &max_extfrag_threshold,
1293 #endif /* CONFIG_COMPACTION */
1295 .procname = "min_free_kbytes",
1296 .data = &min_free_kbytes,
1297 .maxlen = sizeof(min_free_kbytes),
1299 .proc_handler = min_free_kbytes_sysctl_handler,
1303 .procname = "percpu_pagelist_fraction",
1304 .data = &percpu_pagelist_fraction,
1305 .maxlen = sizeof(percpu_pagelist_fraction),
1307 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1308 .extra1 = &min_percpu_pagelist_fract,
1312 .procname = "max_map_count",
1313 .data = &sysctl_max_map_count,
1314 .maxlen = sizeof(sysctl_max_map_count),
1316 .proc_handler = proc_dointvec_minmax,
1321 .procname = "nr_trim_pages",
1322 .data = &sysctl_nr_trim_pages,
1323 .maxlen = sizeof(sysctl_nr_trim_pages),
1325 .proc_handler = proc_dointvec_minmax,
1330 .procname = "laptop_mode",
1331 .data = &laptop_mode,
1332 .maxlen = sizeof(laptop_mode),
1334 .proc_handler = proc_dointvec_jiffies,
1337 .procname = "block_dump",
1338 .data = &block_dump,
1339 .maxlen = sizeof(block_dump),
1341 .proc_handler = proc_dointvec,
1345 .procname = "vfs_cache_pressure",
1346 .data = &sysctl_vfs_cache_pressure,
1347 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1349 .proc_handler = proc_dointvec,
1352 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1354 .procname = "legacy_va_layout",
1355 .data = &sysctl_legacy_va_layout,
1356 .maxlen = sizeof(sysctl_legacy_va_layout),
1358 .proc_handler = proc_dointvec,
1364 .procname = "zone_reclaim_mode",
1365 .data = &zone_reclaim_mode,
1366 .maxlen = sizeof(zone_reclaim_mode),
1368 .proc_handler = proc_dointvec,
1372 .procname = "min_unmapped_ratio",
1373 .data = &sysctl_min_unmapped_ratio,
1374 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1376 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1378 .extra2 = &one_hundred,
1381 .procname = "min_slab_ratio",
1382 .data = &sysctl_min_slab_ratio,
1383 .maxlen = sizeof(sysctl_min_slab_ratio),
1385 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1387 .extra2 = &one_hundred,
1392 .procname = "stat_interval",
1393 .data = &sysctl_stat_interval,
1394 .maxlen = sizeof(sysctl_stat_interval),
1396 .proc_handler = proc_dointvec_jiffies,
1401 .procname = "mmap_min_addr",
1402 .data = &dac_mmap_min_addr,
1403 .maxlen = sizeof(unsigned long),
1405 .proc_handler = mmap_min_addr_handler,
1410 .procname = "numa_zonelist_order",
1411 .data = &numa_zonelist_order,
1412 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1414 .proc_handler = numa_zonelist_order_handler,
1417 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1418 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1420 .procname = "vdso_enabled",
1421 #ifdef CONFIG_X86_32
1422 .data = &vdso32_enabled,
1423 .maxlen = sizeof(vdso32_enabled),
1425 .data = &vdso_enabled,
1426 .maxlen = sizeof(vdso_enabled),
1429 .proc_handler = proc_dointvec,
1433 #ifdef CONFIG_HIGHMEM
1435 .procname = "highmem_is_dirtyable",
1436 .data = &vm_highmem_is_dirtyable,
1437 .maxlen = sizeof(vm_highmem_is_dirtyable),
1439 .proc_handler = proc_dointvec_minmax,
1445 .procname = "scan_unevictable_pages",
1446 .data = &scan_unevictable_pages,
1447 .maxlen = sizeof(scan_unevictable_pages),
1449 .proc_handler = scan_unevictable_handler,
1451 #ifdef CONFIG_MEMORY_FAILURE
1453 .procname = "memory_failure_early_kill",
1454 .data = &sysctl_memory_failure_early_kill,
1455 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1457 .proc_handler = proc_dointvec_minmax,
1462 .procname = "memory_failure_recovery",
1463 .data = &sysctl_memory_failure_recovery,
1464 .maxlen = sizeof(sysctl_memory_failure_recovery),
1466 .proc_handler = proc_dointvec_minmax,
1472 .procname = "user_reserve_kbytes",
1473 .data = &sysctl_user_reserve_kbytes,
1474 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1476 .proc_handler = proc_doulongvec_minmax,
1479 .procname = "admin_reserve_kbytes",
1480 .data = &sysctl_admin_reserve_kbytes,
1481 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1483 .proc_handler = proc_doulongvec_minmax,
1488 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1489 static struct ctl_table binfmt_misc_table[] = {
1494 static struct ctl_table fs_table[] = {
1496 .procname = "inode-nr",
1497 .data = &inodes_stat,
1498 .maxlen = 2*sizeof(long),
1500 .proc_handler = proc_nr_inodes,
1503 .procname = "inode-state",
1504 .data = &inodes_stat,
1505 .maxlen = 7*sizeof(long),
1507 .proc_handler = proc_nr_inodes,
1510 .procname = "file-nr",
1511 .data = &files_stat,
1512 .maxlen = sizeof(files_stat),
1514 .proc_handler = proc_nr_files,
1517 .procname = "file-max",
1518 .data = &files_stat.max_files,
1519 .maxlen = sizeof(files_stat.max_files),
1521 .proc_handler = proc_doulongvec_minmax,
1524 .procname = "nr_open",
1525 .data = &sysctl_nr_open,
1526 .maxlen = sizeof(int),
1528 .proc_handler = proc_dointvec_minmax,
1529 .extra1 = &sysctl_nr_open_min,
1530 .extra2 = &sysctl_nr_open_max,
1533 .procname = "dentry-state",
1534 .data = &dentry_stat,
1535 .maxlen = 6*sizeof(long),
1537 .proc_handler = proc_nr_dentry,
1540 .procname = "overflowuid",
1541 .data = &fs_overflowuid,
1542 .maxlen = sizeof(int),
1544 .proc_handler = proc_dointvec_minmax,
1545 .extra1 = &minolduid,
1546 .extra2 = &maxolduid,
1549 .procname = "overflowgid",
1550 .data = &fs_overflowgid,
1551 .maxlen = sizeof(int),
1553 .proc_handler = proc_dointvec_minmax,
1554 .extra1 = &minolduid,
1555 .extra2 = &maxolduid,
1557 #ifdef CONFIG_FILE_LOCKING
1559 .procname = "leases-enable",
1560 .data = &leases_enable,
1561 .maxlen = sizeof(int),
1563 .proc_handler = proc_dointvec,
1566 #ifdef CONFIG_DNOTIFY
1568 .procname = "dir-notify-enable",
1569 .data = &dir_notify_enable,
1570 .maxlen = sizeof(int),
1572 .proc_handler = proc_dointvec,
1576 #ifdef CONFIG_FILE_LOCKING
1578 .procname = "lease-break-time",
1579 .data = &lease_break_time,
1580 .maxlen = sizeof(int),
1582 .proc_handler = proc_dointvec,
1587 .procname = "aio-nr",
1589 .maxlen = sizeof(aio_nr),
1591 .proc_handler = proc_doulongvec_minmax,
1594 .procname = "aio-max-nr",
1595 .data = &aio_max_nr,
1596 .maxlen = sizeof(aio_max_nr),
1598 .proc_handler = proc_doulongvec_minmax,
1600 #endif /* CONFIG_AIO */
1601 #ifdef CONFIG_INOTIFY_USER
1603 .procname = "inotify",
1605 .child = inotify_table,
1610 .procname = "epoll",
1612 .child = epoll_table,
1617 .procname = "protected_symlinks",
1618 .data = &sysctl_protected_symlinks,
1619 .maxlen = sizeof(int),
1621 .proc_handler = proc_dointvec_minmax,
1626 .procname = "protected_hardlinks",
1627 .data = &sysctl_protected_hardlinks,
1628 .maxlen = sizeof(int),
1630 .proc_handler = proc_dointvec_minmax,
1635 .procname = "suid_dumpable",
1636 .data = &suid_dumpable,
1637 .maxlen = sizeof(int),
1639 .proc_handler = proc_dointvec_minmax_coredump,
1643 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1645 .procname = "binfmt_misc",
1647 .child = binfmt_misc_table,
1651 .procname = "pipe-max-size",
1652 .data = &pipe_max_size,
1653 .maxlen = sizeof(int),
1655 .proc_handler = &pipe_proc_fn,
1656 .extra1 = &pipe_min_size,
1661 static struct ctl_table debug_table[] = {
1662 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1664 .procname = "exception-trace",
1665 .data = &show_unhandled_signals,
1666 .maxlen = sizeof(int),
1668 .proc_handler = proc_dointvec
1671 #if defined(CONFIG_OPTPROBES)
1673 .procname = "kprobes-optimization",
1674 .data = &sysctl_kprobes_optimization,
1675 .maxlen = sizeof(int),
1677 .proc_handler = proc_kprobes_optimization_handler,
1685 static struct ctl_table dev_table[] = {
1689 int __init sysctl_init(void)
1691 struct ctl_table_header *hdr;
1693 hdr = register_sysctl_table(sysctl_base_table);
1694 kmemleak_not_leak(hdr);
1698 #endif /* CONFIG_SYSCTL */
1704 #ifdef CONFIG_PROC_SYSCTL
1706 static int _proc_do_string(void* data, int maxlen, int write,
1707 void __user *buffer,
1708 size_t *lenp, loff_t *ppos)
1714 if (!data || !maxlen || !*lenp) {
1722 while (len < *lenp) {
1723 if (get_user(c, p++))
1725 if (c == 0 || c == '\n')
1731 if(copy_from_user(data, buffer, len))
1733 ((char *) data)[len] = 0;
1751 if(copy_to_user(buffer, data, len))
1754 if(put_user('\n', ((char __user *) buffer) + len))
1765 * proc_dostring - read a string sysctl
1766 * @table: the sysctl table
1767 * @write: %TRUE if this is a write to the sysctl file
1768 * @buffer: the user buffer
1769 * @lenp: the size of the user buffer
1770 * @ppos: file position
1772 * Reads/writes a string from/to the user buffer. If the kernel
1773 * buffer provided is not large enough to hold the string, the
1774 * string is truncated. The copied string is %NULL-terminated.
1775 * If the string is being read by the user process, it is copied
1776 * and a newline '\n' is added. It is truncated if the buffer is
1779 * Returns 0 on success.
1781 int proc_dostring(struct ctl_table *table, int write,
1782 void __user *buffer, size_t *lenp, loff_t *ppos)
1784 return _proc_do_string(table->data, table->maxlen, write,
1785 buffer, lenp, ppos);
1788 static size_t proc_skip_spaces(char **buf)
1791 char *tmp = skip_spaces(*buf);
1797 static void proc_skip_char(char **buf, size_t *size, const char v)
1807 #define TMPBUFLEN 22
1809 * proc_get_long - reads an ASCII formatted integer from a user buffer
1811 * @buf: a kernel buffer
1812 * @size: size of the kernel buffer
1813 * @val: this is where the number will be stored
1814 * @neg: set to %TRUE if number is negative
1815 * @perm_tr: a vector which contains the allowed trailers
1816 * @perm_tr_len: size of the perm_tr vector
1817 * @tr: pointer to store the trailer character
1819 * In case of success %0 is returned and @buf and @size are updated with
1820 * the amount of bytes read. If @tr is non-NULL and a trailing
1821 * character exists (size is non-zero after returning from this
1822 * function), @tr is updated with the trailing character.
1824 static int proc_get_long(char **buf, size_t *size,
1825 unsigned long *val, bool *neg,
1826 const char *perm_tr, unsigned perm_tr_len, char *tr)
1829 char *p, tmp[TMPBUFLEN];
1835 if (len > TMPBUFLEN - 1)
1836 len = TMPBUFLEN - 1;
1838 memcpy(tmp, *buf, len);
1842 if (*p == '-' && *size > 1) {
1850 *val = simple_strtoul(p, &p, 0);
1854 /* We don't know if the next char is whitespace thus we may accept
1855 * invalid integers (e.g. 1234...a) or two integers instead of one
1856 * (e.g. 123...1). So lets not allow such large numbers. */
1857 if (len == TMPBUFLEN - 1)
1860 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1863 if (tr && (len < *size))
1873 * proc_put_long - converts an integer to a decimal ASCII formatted string
1875 * @buf: the user buffer
1876 * @size: the size of the user buffer
1877 * @val: the integer to be converted
1878 * @neg: sign of the number, %TRUE for negative
1880 * In case of success %0 is returned and @buf and @size are updated with
1881 * the amount of bytes written.
1883 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1887 char tmp[TMPBUFLEN], *p = tmp;
1889 sprintf(p, "%s%lu", neg ? "-" : "", val);
1893 if (copy_to_user(*buf, tmp, len))
1901 static int proc_put_char(void __user **buf, size_t *size, char c)
1904 char __user **buffer = (char __user **)buf;
1905 if (put_user(c, *buffer))
1907 (*size)--, (*buffer)++;
1913 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1915 int write, void *data)
1918 *valp = *negp ? -*lvalp : *lvalp;
1923 *lvalp = (unsigned long)-val;
1926 *lvalp = (unsigned long)val;
1932 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1934 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1935 int write, void __user *buffer,
1936 size_t *lenp, loff_t *ppos,
1937 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1938 int write, void *data),
1941 int *i, vleft, first = 1, err = 0;
1942 unsigned long page = 0;
1946 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1951 i = (int *) tbl_data;
1952 vleft = table->maxlen / sizeof(*i);
1956 conv = do_proc_dointvec_conv;
1959 if (left > PAGE_SIZE - 1)
1960 left = PAGE_SIZE - 1;
1961 page = __get_free_page(GFP_TEMPORARY);
1962 kbuf = (char *) page;
1965 if (copy_from_user(kbuf, buffer, left)) {
1972 for (; left && vleft--; i++, first=0) {
1977 left -= proc_skip_spaces(&kbuf);
1981 err = proc_get_long(&kbuf, &left, &lval, &neg,
1983 sizeof(proc_wspace_sep), NULL);
1986 if (conv(&neg, &lval, i, 1, data)) {
1991 if (conv(&neg, &lval, i, 0, data)) {
1996 err = proc_put_char(&buffer, &left, '\t');
1999 err = proc_put_long(&buffer, &left, lval, neg);
2005 if (!write && !first && left && !err)
2006 err = proc_put_char(&buffer, &left, '\n');
2007 if (write && !err && left)
2008 left -= proc_skip_spaces(&kbuf);
2013 return err ? : -EINVAL;
2020 static int do_proc_dointvec(struct ctl_table *table, int write,
2021 void __user *buffer, size_t *lenp, loff_t *ppos,
2022 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2023 int write, void *data),
2026 return __do_proc_dointvec(table->data, table, write,
2027 buffer, lenp, ppos, conv, data);
2031 * proc_dointvec - read a vector of integers
2032 * @table: the sysctl table
2033 * @write: %TRUE if this is a write to the sysctl file
2034 * @buffer: the user buffer
2035 * @lenp: the size of the user buffer
2036 * @ppos: file position
2038 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2039 * values from/to the user buffer, treated as an ASCII string.
2041 * Returns 0 on success.
2043 int proc_dointvec(struct ctl_table *table, int write,
2044 void __user *buffer, size_t *lenp, loff_t *ppos)
2046 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2051 * Taint values can only be increased
2052 * This means we can safely use a temporary.
2054 static int proc_taint(struct ctl_table *table, int write,
2055 void __user *buffer, size_t *lenp, loff_t *ppos)
2058 unsigned long tmptaint = get_taint();
2061 if (write && !capable(CAP_SYS_ADMIN))
2066 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2072 * Poor man's atomic or. Not worth adding a primitive
2073 * to everyone's atomic.h for this
2076 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2077 if ((tmptaint >> i) & 1)
2078 add_taint(i, LOCKDEP_STILL_OK);
2085 #ifdef CONFIG_PRINTK
2086 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2087 void __user *buffer, size_t *lenp, loff_t *ppos)
2089 if (write && !capable(CAP_SYS_ADMIN))
2092 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2096 struct do_proc_dointvec_minmax_conv_param {
2101 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2103 int write, void *data)
2105 struct do_proc_dointvec_minmax_conv_param *param = data;
2107 int val = *negp ? -*lvalp : *lvalp;
2108 if ((param->min && *param->min > val) ||
2109 (param->max && *param->max < val))
2116 *lvalp = (unsigned long)-val;
2119 *lvalp = (unsigned long)val;
2126 * proc_dointvec_minmax - read a vector of integers with min/max values
2127 * @table: the sysctl table
2128 * @write: %TRUE if this is a write to the sysctl file
2129 * @buffer: the user buffer
2130 * @lenp: the size of the user buffer
2131 * @ppos: file position
2133 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2134 * values from/to the user buffer, treated as an ASCII string.
2136 * This routine will ensure the values are within the range specified by
2137 * table->extra1 (min) and table->extra2 (max).
2139 * Returns 0 on success.
2141 int proc_dointvec_minmax(struct ctl_table *table, int write,
2142 void __user *buffer, size_t *lenp, loff_t *ppos)
2144 struct do_proc_dointvec_minmax_conv_param param = {
2145 .min = (int *) table->extra1,
2146 .max = (int *) table->extra2,
2148 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2149 do_proc_dointvec_minmax_conv, ¶m);
2152 static void validate_coredump_safety(void)
2154 #ifdef CONFIG_COREDUMP
2155 if (suid_dumpable == SUID_DUMP_ROOT &&
2156 core_pattern[0] != '/' && core_pattern[0] != '|') {
2157 printk(KERN_WARNING "Unsafe core_pattern used with "\
2158 "suid_dumpable=2. Pipe handler or fully qualified "\
2159 "core dump path required.\n");
2164 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2165 void __user *buffer, size_t *lenp, loff_t *ppos)
2167 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2169 validate_coredump_safety();
2173 #ifdef CONFIG_COREDUMP
2174 static int proc_dostring_coredump(struct ctl_table *table, int write,
2175 void __user *buffer, size_t *lenp, loff_t *ppos)
2177 int error = proc_dostring(table, write, buffer, lenp, ppos);
2179 validate_coredump_safety();
2184 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2185 void __user *buffer,
2186 size_t *lenp, loff_t *ppos,
2187 unsigned long convmul,
2188 unsigned long convdiv)
2190 unsigned long *i, *min, *max;
2191 int vleft, first = 1, err = 0;
2192 unsigned long page = 0;
2196 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2201 i = (unsigned long *) data;
2202 min = (unsigned long *) table->extra1;
2203 max = (unsigned long *) table->extra2;
2204 vleft = table->maxlen / sizeof(unsigned long);
2208 if (left > PAGE_SIZE - 1)
2209 left = PAGE_SIZE - 1;
2210 page = __get_free_page(GFP_TEMPORARY);
2211 kbuf = (char *) page;
2214 if (copy_from_user(kbuf, buffer, left)) {
2221 for (; left && vleft--; i++, first = 0) {
2227 left -= proc_skip_spaces(&kbuf);
2229 err = proc_get_long(&kbuf, &left, &val, &neg,
2231 sizeof(proc_wspace_sep), NULL);
2236 if ((min && val < *min) || (max && val > *max))
2240 val = convdiv * (*i) / convmul;
2242 err = proc_put_char(&buffer, &left, '\t');
2246 err = proc_put_long(&buffer, &left, val, false);
2252 if (!write && !first && left && !err)
2253 err = proc_put_char(&buffer, &left, '\n');
2255 left -= proc_skip_spaces(&kbuf);
2260 return err ? : -EINVAL;
2267 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2268 void __user *buffer,
2269 size_t *lenp, loff_t *ppos,
2270 unsigned long convmul,
2271 unsigned long convdiv)
2273 return __do_proc_doulongvec_minmax(table->data, table, write,
2274 buffer, lenp, ppos, convmul, convdiv);
2278 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2279 * @table: the sysctl table
2280 * @write: %TRUE if this is a write to the sysctl file
2281 * @buffer: the user buffer
2282 * @lenp: the size of the user buffer
2283 * @ppos: file position
2285 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2286 * values from/to the user buffer, treated as an ASCII string.
2288 * This routine will ensure the values are within the range specified by
2289 * table->extra1 (min) and table->extra2 (max).
2291 * Returns 0 on success.
2293 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2296 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2300 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2301 * @table: the sysctl table
2302 * @write: %TRUE if this is a write to the sysctl file
2303 * @buffer: the user buffer
2304 * @lenp: the size of the user buffer
2305 * @ppos: file position
2307 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2308 * values from/to the user buffer, treated as an ASCII string. The values
2309 * are treated as milliseconds, and converted to jiffies when they are stored.
2311 * This routine will ensure the values are within the range specified by
2312 * table->extra1 (min) and table->extra2 (max).
2314 * Returns 0 on success.
2316 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2317 void __user *buffer,
2318 size_t *lenp, loff_t *ppos)
2320 return do_proc_doulongvec_minmax(table, write, buffer,
2321 lenp, ppos, HZ, 1000l);
2325 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2327 int write, void *data)
2330 if (*lvalp > LONG_MAX / HZ)
2332 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2338 lval = (unsigned long)-val;
2341 lval = (unsigned long)val;
2348 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2350 int write, void *data)
2353 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2355 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2361 lval = (unsigned long)-val;
2364 lval = (unsigned long)val;
2366 *lvalp = jiffies_to_clock_t(lval);
2371 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2373 int write, void *data)
2376 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2386 lval = (unsigned long)-val;
2389 lval = (unsigned long)val;
2391 *lvalp = jiffies_to_msecs(lval);
2397 * proc_dointvec_jiffies - read a vector of integers as seconds
2398 * @table: the sysctl table
2399 * @write: %TRUE if this is a write to the sysctl file
2400 * @buffer: the user buffer
2401 * @lenp: the size of the user buffer
2402 * @ppos: file position
2404 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2405 * values from/to the user buffer, treated as an ASCII string.
2406 * The values read are assumed to be in seconds, and are converted into
2409 * Returns 0 on success.
2411 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2412 void __user *buffer, size_t *lenp, loff_t *ppos)
2414 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2415 do_proc_dointvec_jiffies_conv,NULL);
2419 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2420 * @table: the sysctl table
2421 * @write: %TRUE if this is a write to the sysctl file
2422 * @buffer: the user buffer
2423 * @lenp: the size of the user buffer
2424 * @ppos: pointer to the file position
2426 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2427 * values from/to the user buffer, treated as an ASCII string.
2428 * The values read are assumed to be in 1/USER_HZ seconds, and
2429 * are converted into jiffies.
2431 * Returns 0 on success.
2433 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2434 void __user *buffer, size_t *lenp, loff_t *ppos)
2436 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2437 do_proc_dointvec_userhz_jiffies_conv,NULL);
2441 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: file position
2447 * @ppos: the current position in the file
2449 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2450 * values from/to the user buffer, treated as an ASCII string.
2451 * The values read are assumed to be in 1/1000 seconds, and
2452 * are converted into jiffies.
2454 * Returns 0 on success.
2456 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2457 void __user *buffer, size_t *lenp, loff_t *ppos)
2459 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2460 do_proc_dointvec_ms_jiffies_conv, NULL);
2463 static int proc_do_cad_pid(struct ctl_table *table, int write,
2464 void __user *buffer, size_t *lenp, loff_t *ppos)
2466 struct pid *new_pid;
2470 tmp = pid_vnr(cad_pid);
2472 r = __do_proc_dointvec(&tmp, table, write, buffer,
2473 lenp, ppos, NULL, NULL);
2477 new_pid = find_get_pid(tmp);
2481 put_pid(xchg(&cad_pid, new_pid));
2486 * proc_do_large_bitmap - read/write from/to a large bitmap
2487 * @table: the sysctl table
2488 * @write: %TRUE if this is a write to the sysctl file
2489 * @buffer: the user buffer
2490 * @lenp: the size of the user buffer
2491 * @ppos: file position
2493 * The bitmap is stored at table->data and the bitmap length (in bits)
2496 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2497 * large bitmaps may be represented in a compact manner. Writing into
2498 * the file will clear the bitmap then update it with the given input.
2500 * Returns 0 on success.
2502 int proc_do_large_bitmap(struct ctl_table *table, int write,
2503 void __user *buffer, size_t *lenp, loff_t *ppos)
2507 size_t left = *lenp;
2508 unsigned long bitmap_len = table->maxlen;
2509 unsigned long *bitmap = (unsigned long *) table->data;
2510 unsigned long *tmp_bitmap = NULL;
2511 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2513 if (!bitmap_len || !left || (*ppos && !write)) {
2519 unsigned long page = 0;
2522 if (left > PAGE_SIZE - 1)
2523 left = PAGE_SIZE - 1;
2525 page = __get_free_page(GFP_TEMPORARY);
2526 kbuf = (char *) page;
2529 if (copy_from_user(kbuf, buffer, left)) {
2535 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2541 proc_skip_char(&kbuf, &left, '\n');
2542 while (!err && left) {
2543 unsigned long val_a, val_b;
2546 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2550 if (val_a >= bitmap_len || neg) {
2562 err = proc_get_long(&kbuf, &left, &val_b,
2563 &neg, tr_b, sizeof(tr_b),
2567 if (val_b >= bitmap_len || neg ||
2578 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2580 proc_skip_char(&kbuf, &left, '\n');
2584 unsigned long bit_a, bit_b = 0;
2587 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2588 if (bit_a >= bitmap_len)
2590 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2594 err = proc_put_char(&buffer, &left, ',');
2598 err = proc_put_long(&buffer, &left, bit_a, false);
2601 if (bit_a != bit_b) {
2602 err = proc_put_char(&buffer, &left, '-');
2605 err = proc_put_long(&buffer, &left, bit_b, false);
2613 err = proc_put_char(&buffer, &left, '\n');
2619 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2621 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2633 #else /* CONFIG_PROC_SYSCTL */
2635 int proc_dostring(struct ctl_table *table, int write,
2636 void __user *buffer, size_t *lenp, loff_t *ppos)
2641 int proc_dointvec(struct ctl_table *table, int write,
2642 void __user *buffer, size_t *lenp, loff_t *ppos)
2647 int proc_dointvec_minmax(struct ctl_table *table, int write,
2648 void __user *buffer, size_t *lenp, loff_t *ppos)
2653 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2654 void __user *buffer, size_t *lenp, loff_t *ppos)
2659 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2660 void __user *buffer, size_t *lenp, loff_t *ppos)
2665 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2666 void __user *buffer, size_t *lenp, loff_t *ppos)
2671 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2672 void __user *buffer, size_t *lenp, loff_t *ppos)
2677 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2678 void __user *buffer,
2679 size_t *lenp, loff_t *ppos)
2685 #endif /* CONFIG_PROC_SYSCTL */
2688 * No sense putting this after each symbol definition, twice,
2689 * exception granted :-)
2691 EXPORT_SYMBOL(proc_dointvec);
2692 EXPORT_SYMBOL(proc_dointvec_jiffies);
2693 EXPORT_SYMBOL(proc_dointvec_minmax);
2694 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2695 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2696 EXPORT_SYMBOL(proc_dostring);
2697 EXPORT_SYMBOL(proc_doulongvec_minmax);
2698 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);