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
,
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 .data
= &vdso_enabled
,
1422 .maxlen
= sizeof(vdso_enabled
),
1424 .proc_handler
= proc_dointvec
,
1428 #ifdef CONFIG_HIGHMEM
1430 .procname
= "highmem_is_dirtyable",
1431 .data
= &vm_highmem_is_dirtyable
,
1432 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1434 .proc_handler
= proc_dointvec_minmax
,
1440 .procname
= "scan_unevictable_pages",
1441 .data
= &scan_unevictable_pages
,
1442 .maxlen
= sizeof(scan_unevictable_pages
),
1444 .proc_handler
= scan_unevictable_handler
,
1446 #ifdef CONFIG_MEMORY_FAILURE
1448 .procname
= "memory_failure_early_kill",
1449 .data
= &sysctl_memory_failure_early_kill
,
1450 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1452 .proc_handler
= proc_dointvec_minmax
,
1457 .procname
= "memory_failure_recovery",
1458 .data
= &sysctl_memory_failure_recovery
,
1459 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1461 .proc_handler
= proc_dointvec_minmax
,
1467 .procname
= "user_reserve_kbytes",
1468 .data
= &sysctl_user_reserve_kbytes
,
1469 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1471 .proc_handler
= proc_doulongvec_minmax
,
1474 .procname
= "admin_reserve_kbytes",
1475 .data
= &sysctl_admin_reserve_kbytes
,
1476 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1478 .proc_handler
= proc_doulongvec_minmax
,
1483 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1484 static struct ctl_table binfmt_misc_table
[] = {
1489 static struct ctl_table fs_table
[] = {
1491 .procname
= "inode-nr",
1492 .data
= &inodes_stat
,
1493 .maxlen
= 2*sizeof(long),
1495 .proc_handler
= proc_nr_inodes
,
1498 .procname
= "inode-state",
1499 .data
= &inodes_stat
,
1500 .maxlen
= 7*sizeof(long),
1502 .proc_handler
= proc_nr_inodes
,
1505 .procname
= "file-nr",
1506 .data
= &files_stat
,
1507 .maxlen
= sizeof(files_stat
),
1509 .proc_handler
= proc_nr_files
,
1512 .procname
= "file-max",
1513 .data
= &files_stat
.max_files
,
1514 .maxlen
= sizeof(files_stat
.max_files
),
1516 .proc_handler
= proc_doulongvec_minmax
,
1519 .procname
= "nr_open",
1520 .data
= &sysctl_nr_open
,
1521 .maxlen
= sizeof(int),
1523 .proc_handler
= proc_dointvec_minmax
,
1524 .extra1
= &sysctl_nr_open_min
,
1525 .extra2
= &sysctl_nr_open_max
,
1528 .procname
= "dentry-state",
1529 .data
= &dentry_stat
,
1530 .maxlen
= 6*sizeof(long),
1532 .proc_handler
= proc_nr_dentry
,
1535 .procname
= "overflowuid",
1536 .data
= &fs_overflowuid
,
1537 .maxlen
= sizeof(int),
1539 .proc_handler
= proc_dointvec_minmax
,
1540 .extra1
= &minolduid
,
1541 .extra2
= &maxolduid
,
1544 .procname
= "overflowgid",
1545 .data
= &fs_overflowgid
,
1546 .maxlen
= sizeof(int),
1548 .proc_handler
= proc_dointvec_minmax
,
1549 .extra1
= &minolduid
,
1550 .extra2
= &maxolduid
,
1552 #ifdef CONFIG_FILE_LOCKING
1554 .procname
= "leases-enable",
1555 .data
= &leases_enable
,
1556 .maxlen
= sizeof(int),
1558 .proc_handler
= proc_dointvec
,
1561 #ifdef CONFIG_DNOTIFY
1563 .procname
= "dir-notify-enable",
1564 .data
= &dir_notify_enable
,
1565 .maxlen
= sizeof(int),
1567 .proc_handler
= proc_dointvec
,
1571 #ifdef CONFIG_FILE_LOCKING
1573 .procname
= "lease-break-time",
1574 .data
= &lease_break_time
,
1575 .maxlen
= sizeof(int),
1577 .proc_handler
= proc_dointvec
,
1582 .procname
= "aio-nr",
1584 .maxlen
= sizeof(aio_nr
),
1586 .proc_handler
= proc_doulongvec_minmax
,
1589 .procname
= "aio-max-nr",
1590 .data
= &aio_max_nr
,
1591 .maxlen
= sizeof(aio_max_nr
),
1593 .proc_handler
= proc_doulongvec_minmax
,
1595 #endif /* CONFIG_AIO */
1596 #ifdef CONFIG_INOTIFY_USER
1598 .procname
= "inotify",
1600 .child
= inotify_table
,
1605 .procname
= "epoll",
1607 .child
= epoll_table
,
1612 .procname
= "protected_symlinks",
1613 .data
= &sysctl_protected_symlinks
,
1614 .maxlen
= sizeof(int),
1616 .proc_handler
= proc_dointvec_minmax
,
1621 .procname
= "protected_hardlinks",
1622 .data
= &sysctl_protected_hardlinks
,
1623 .maxlen
= sizeof(int),
1625 .proc_handler
= proc_dointvec_minmax
,
1630 .procname
= "suid_dumpable",
1631 .data
= &suid_dumpable
,
1632 .maxlen
= sizeof(int),
1634 .proc_handler
= proc_dointvec_minmax_coredump
,
1638 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1640 .procname
= "binfmt_misc",
1642 .child
= binfmt_misc_table
,
1646 .procname
= "pipe-max-size",
1647 .data
= &pipe_max_size
,
1648 .maxlen
= sizeof(int),
1650 .proc_handler
= &pipe_proc_fn
,
1651 .extra1
= &pipe_min_size
,
1656 static struct ctl_table debug_table
[] = {
1657 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1659 .procname
= "exception-trace",
1660 .data
= &show_unhandled_signals
,
1661 .maxlen
= sizeof(int),
1663 .proc_handler
= proc_dointvec
1666 #if defined(CONFIG_OPTPROBES)
1668 .procname
= "kprobes-optimization",
1669 .data
= &sysctl_kprobes_optimization
,
1670 .maxlen
= sizeof(int),
1672 .proc_handler
= proc_kprobes_optimization_handler
,
1680 static struct ctl_table dev_table
[] = {
1684 int __init
sysctl_init(void)
1686 struct ctl_table_header
*hdr
;
1688 hdr
= register_sysctl_table(sysctl_base_table
);
1689 kmemleak_not_leak(hdr
);
1693 #endif /* CONFIG_SYSCTL */
1699 #ifdef CONFIG_PROC_SYSCTL
1701 static int _proc_do_string(void* data
, int maxlen
, int write
,
1702 void __user
*buffer
,
1703 size_t *lenp
, loff_t
*ppos
)
1709 if (!data
|| !maxlen
|| !*lenp
) {
1717 while (len
< *lenp
) {
1718 if (get_user(c
, p
++))
1720 if (c
== 0 || c
== '\n')
1726 if(copy_from_user(data
, buffer
, len
))
1728 ((char *) data
)[len
] = 0;
1746 if(copy_to_user(buffer
, data
, len
))
1749 if(put_user('\n', ((char __user
*) buffer
) + len
))
1760 * proc_dostring - read a string sysctl
1761 * @table: the sysctl table
1762 * @write: %TRUE if this is a write to the sysctl file
1763 * @buffer: the user buffer
1764 * @lenp: the size of the user buffer
1765 * @ppos: file position
1767 * Reads/writes a string from/to the user buffer. If the kernel
1768 * buffer provided is not large enough to hold the string, the
1769 * string is truncated. The copied string is %NULL-terminated.
1770 * If the string is being read by the user process, it is copied
1771 * and a newline '\n' is added. It is truncated if the buffer is
1774 * Returns 0 on success.
1776 int proc_dostring(struct ctl_table
*table
, int write
,
1777 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1779 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1780 buffer
, lenp
, ppos
);
1783 static size_t proc_skip_spaces(char **buf
)
1786 char *tmp
= skip_spaces(*buf
);
1792 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1802 #define TMPBUFLEN 22
1804 * proc_get_long - reads an ASCII formatted integer from a user buffer
1806 * @buf: a kernel buffer
1807 * @size: size of the kernel buffer
1808 * @val: this is where the number will be stored
1809 * @neg: set to %TRUE if number is negative
1810 * @perm_tr: a vector which contains the allowed trailers
1811 * @perm_tr_len: size of the perm_tr vector
1812 * @tr: pointer to store the trailer character
1814 * In case of success %0 is returned and @buf and @size are updated with
1815 * the amount of bytes read. If @tr is non-NULL and a trailing
1816 * character exists (size is non-zero after returning from this
1817 * function), @tr is updated with the trailing character.
1819 static int proc_get_long(char **buf
, size_t *size
,
1820 unsigned long *val
, bool *neg
,
1821 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1824 char *p
, tmp
[TMPBUFLEN
];
1830 if (len
> TMPBUFLEN
- 1)
1831 len
= TMPBUFLEN
- 1;
1833 memcpy(tmp
, *buf
, len
);
1837 if (*p
== '-' && *size
> 1) {
1845 *val
= simple_strtoul(p
, &p
, 0);
1849 /* We don't know if the next char is whitespace thus we may accept
1850 * invalid integers (e.g. 1234...a) or two integers instead of one
1851 * (e.g. 123...1). So lets not allow such large numbers. */
1852 if (len
== TMPBUFLEN
- 1)
1855 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1858 if (tr
&& (len
< *size
))
1868 * proc_put_long - converts an integer to a decimal ASCII formatted string
1870 * @buf: the user buffer
1871 * @size: the size of the user buffer
1872 * @val: the integer to be converted
1873 * @neg: sign of the number, %TRUE for negative
1875 * In case of success %0 is returned and @buf and @size are updated with
1876 * the amount of bytes written.
1878 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1882 char tmp
[TMPBUFLEN
], *p
= tmp
;
1884 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1888 if (copy_to_user(*buf
, tmp
, len
))
1896 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1899 char __user
**buffer
= (char __user
**)buf
;
1900 if (put_user(c
, *buffer
))
1902 (*size
)--, (*buffer
)++;
1908 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1910 int write
, void *data
)
1913 *valp
= *negp
? -*lvalp
: *lvalp
;
1918 *lvalp
= (unsigned long)-val
;
1921 *lvalp
= (unsigned long)val
;
1927 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1929 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1930 int write
, void __user
*buffer
,
1931 size_t *lenp
, loff_t
*ppos
,
1932 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1933 int write
, void *data
),
1936 int *i
, vleft
, first
= 1, err
= 0;
1937 unsigned long page
= 0;
1941 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1946 i
= (int *) tbl_data
;
1947 vleft
= table
->maxlen
/ sizeof(*i
);
1951 conv
= do_proc_dointvec_conv
;
1954 if (left
> PAGE_SIZE
- 1)
1955 left
= PAGE_SIZE
- 1;
1956 page
= __get_free_page(GFP_TEMPORARY
);
1957 kbuf
= (char *) page
;
1960 if (copy_from_user(kbuf
, buffer
, left
)) {
1967 for (; left
&& vleft
--; i
++, first
=0) {
1972 left
-= proc_skip_spaces(&kbuf
);
1976 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1978 sizeof(proc_wspace_sep
), NULL
);
1981 if (conv(&neg
, &lval
, i
, 1, data
)) {
1986 if (conv(&neg
, &lval
, i
, 0, data
)) {
1991 err
= proc_put_char(&buffer
, &left
, '\t');
1994 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2000 if (!write
&& !first
&& left
&& !err
)
2001 err
= proc_put_char(&buffer
, &left
, '\n');
2002 if (write
&& !err
&& left
)
2003 left
-= proc_skip_spaces(&kbuf
);
2008 return err
? : -EINVAL
;
2015 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2016 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2017 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2018 int write
, void *data
),
2021 return __do_proc_dointvec(table
->data
, table
, write
,
2022 buffer
, lenp
, ppos
, conv
, data
);
2026 * proc_dointvec - read a vector of integers
2027 * @table: the sysctl table
2028 * @write: %TRUE if this is a write to the sysctl file
2029 * @buffer: the user buffer
2030 * @lenp: the size of the user buffer
2031 * @ppos: file position
2033 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2034 * values from/to the user buffer, treated as an ASCII string.
2036 * Returns 0 on success.
2038 int proc_dointvec(struct ctl_table
*table
, int write
,
2039 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2041 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2046 * Taint values can only be increased
2047 * This means we can safely use a temporary.
2049 static int proc_taint(struct ctl_table
*table
, int write
,
2050 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2053 unsigned long tmptaint
= get_taint();
2056 if (write
&& !capable(CAP_SYS_ADMIN
))
2061 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2067 * Poor man's atomic or. Not worth adding a primitive
2068 * to everyone's atomic.h for this
2071 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2072 if ((tmptaint
>> i
) & 1)
2073 add_taint(i
, LOCKDEP_STILL_OK
);
2080 #ifdef CONFIG_PRINTK
2081 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2082 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2084 if (write
&& !capable(CAP_SYS_ADMIN
))
2087 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2091 struct do_proc_dointvec_minmax_conv_param
{
2096 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2098 int write
, void *data
)
2100 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2102 int val
= *negp
? -*lvalp
: *lvalp
;
2103 if ((param
->min
&& *param
->min
> val
) ||
2104 (param
->max
&& *param
->max
< val
))
2111 *lvalp
= (unsigned long)-val
;
2114 *lvalp
= (unsigned long)val
;
2121 * proc_dointvec_minmax - read a vector of integers with min/max values
2122 * @table: the sysctl table
2123 * @write: %TRUE if this is a write to the sysctl file
2124 * @buffer: the user buffer
2125 * @lenp: the size of the user buffer
2126 * @ppos: file position
2128 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2129 * values from/to the user buffer, treated as an ASCII string.
2131 * This routine will ensure the values are within the range specified by
2132 * table->extra1 (min) and table->extra2 (max).
2134 * Returns 0 on success.
2136 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2137 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2139 struct do_proc_dointvec_minmax_conv_param param
= {
2140 .min
= (int *) table
->extra1
,
2141 .max
= (int *) table
->extra2
,
2143 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2144 do_proc_dointvec_minmax_conv
, ¶m
);
2147 static void validate_coredump_safety(void)
2149 #ifdef CONFIG_COREDUMP
2150 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2151 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2152 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2153 "suid_dumpable=2. Pipe handler or fully qualified "\
2154 "core dump path required.\n");
2159 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2160 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2162 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2164 validate_coredump_safety();
2168 #ifdef CONFIG_COREDUMP
2169 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2172 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2174 validate_coredump_safety();
2179 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2180 void __user
*buffer
,
2181 size_t *lenp
, loff_t
*ppos
,
2182 unsigned long convmul
,
2183 unsigned long convdiv
)
2185 unsigned long *i
, *min
, *max
;
2186 int vleft
, first
= 1, err
= 0;
2187 unsigned long page
= 0;
2191 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2196 i
= (unsigned long *) data
;
2197 min
= (unsigned long *) table
->extra1
;
2198 max
= (unsigned long *) table
->extra2
;
2199 vleft
= table
->maxlen
/ sizeof(unsigned long);
2203 if (left
> PAGE_SIZE
- 1)
2204 left
= PAGE_SIZE
- 1;
2205 page
= __get_free_page(GFP_TEMPORARY
);
2206 kbuf
= (char *) page
;
2209 if (copy_from_user(kbuf
, buffer
, left
)) {
2216 for (; left
&& vleft
--; i
++, first
= 0) {
2222 left
-= proc_skip_spaces(&kbuf
);
2224 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2226 sizeof(proc_wspace_sep
), NULL
);
2231 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2235 val
= convdiv
* (*i
) / convmul
;
2237 err
= proc_put_char(&buffer
, &left
, '\t');
2241 err
= proc_put_long(&buffer
, &left
, val
, false);
2247 if (!write
&& !first
&& left
&& !err
)
2248 err
= proc_put_char(&buffer
, &left
, '\n');
2250 left
-= proc_skip_spaces(&kbuf
);
2255 return err
? : -EINVAL
;
2262 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2263 void __user
*buffer
,
2264 size_t *lenp
, loff_t
*ppos
,
2265 unsigned long convmul
,
2266 unsigned long convdiv
)
2268 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2269 buffer
, lenp
, ppos
, convmul
, convdiv
);
2273 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2274 * @table: the sysctl table
2275 * @write: %TRUE if this is a write to the sysctl file
2276 * @buffer: the user buffer
2277 * @lenp: the size of the user buffer
2278 * @ppos: file position
2280 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2281 * values from/to the user buffer, treated as an ASCII string.
2283 * This routine will ensure the values are within the range specified by
2284 * table->extra1 (min) and table->extra2 (max).
2286 * Returns 0 on success.
2288 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2289 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2291 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2295 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2296 * @table: the sysctl table
2297 * @write: %TRUE if this is a write to the sysctl file
2298 * @buffer: the user buffer
2299 * @lenp: the size of the user buffer
2300 * @ppos: file position
2302 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2303 * values from/to the user buffer, treated as an ASCII string. The values
2304 * are treated as milliseconds, and converted to jiffies when they are stored.
2306 * This routine will ensure the values are within the range specified by
2307 * table->extra1 (min) and table->extra2 (max).
2309 * Returns 0 on success.
2311 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2312 void __user
*buffer
,
2313 size_t *lenp
, loff_t
*ppos
)
2315 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2316 lenp
, ppos
, HZ
, 1000l);
2320 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2322 int write
, void *data
)
2325 if (*lvalp
> LONG_MAX
/ HZ
)
2327 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2333 lval
= (unsigned long)-val
;
2336 lval
= (unsigned long)val
;
2343 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2345 int write
, void *data
)
2348 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2350 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2356 lval
= (unsigned long)-val
;
2359 lval
= (unsigned long)val
;
2361 *lvalp
= jiffies_to_clock_t(lval
);
2366 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2368 int write
, void *data
)
2371 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2381 lval
= (unsigned long)-val
;
2384 lval
= (unsigned long)val
;
2386 *lvalp
= jiffies_to_msecs(lval
);
2392 * proc_dointvec_jiffies - read a vector of integers as seconds
2393 * @table: the sysctl table
2394 * @write: %TRUE if this is a write to the sysctl file
2395 * @buffer: the user buffer
2396 * @lenp: the size of the user buffer
2397 * @ppos: file position
2399 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2400 * values from/to the user buffer, treated as an ASCII string.
2401 * The values read are assumed to be in seconds, and are converted into
2404 * Returns 0 on success.
2406 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2407 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2409 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2410 do_proc_dointvec_jiffies_conv
,NULL
);
2414 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2415 * @table: the sysctl table
2416 * @write: %TRUE if this is a write to the sysctl file
2417 * @buffer: the user buffer
2418 * @lenp: the size of the user buffer
2419 * @ppos: pointer to the file position
2421 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2422 * values from/to the user buffer, treated as an ASCII string.
2423 * The values read are assumed to be in 1/USER_HZ seconds, and
2424 * are converted into jiffies.
2426 * Returns 0 on success.
2428 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2429 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2431 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2432 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2436 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2437 * @table: the sysctl table
2438 * @write: %TRUE if this is a write to the sysctl file
2439 * @buffer: the user buffer
2440 * @lenp: the size of the user buffer
2441 * @ppos: file position
2442 * @ppos: the current position in the file
2444 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2445 * values from/to the user buffer, treated as an ASCII string.
2446 * The values read are assumed to be in 1/1000 seconds, and
2447 * are converted into jiffies.
2449 * Returns 0 on success.
2451 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2452 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2454 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2455 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2458 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2459 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2461 struct pid
*new_pid
;
2465 tmp
= pid_vnr(cad_pid
);
2467 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2468 lenp
, ppos
, NULL
, NULL
);
2472 new_pid
= find_get_pid(tmp
);
2476 put_pid(xchg(&cad_pid
, new_pid
));
2481 * proc_do_large_bitmap - read/write from/to a large bitmap
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
2484 * @buffer: the user buffer
2485 * @lenp: the size of the user buffer
2486 * @ppos: file position
2488 * The bitmap is stored at table->data and the bitmap length (in bits)
2491 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2492 * large bitmaps may be represented in a compact manner. Writing into
2493 * the file will clear the bitmap then update it with the given input.
2495 * Returns 0 on success.
2497 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2498 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2502 size_t left
= *lenp
;
2503 unsigned long bitmap_len
= table
->maxlen
;
2504 unsigned long *bitmap
= (unsigned long *) table
->data
;
2505 unsigned long *tmp_bitmap
= NULL
;
2506 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2508 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2514 unsigned long page
= 0;
2517 if (left
> PAGE_SIZE
- 1)
2518 left
= PAGE_SIZE
- 1;
2520 page
= __get_free_page(GFP_TEMPORARY
);
2521 kbuf
= (char *) page
;
2524 if (copy_from_user(kbuf
, buffer
, left
)) {
2530 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2536 proc_skip_char(&kbuf
, &left
, '\n');
2537 while (!err
&& left
) {
2538 unsigned long val_a
, val_b
;
2541 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2545 if (val_a
>= bitmap_len
|| neg
) {
2557 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2558 &neg
, tr_b
, sizeof(tr_b
),
2562 if (val_b
>= bitmap_len
|| neg
||
2573 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2575 proc_skip_char(&kbuf
, &left
, '\n');
2579 unsigned long bit_a
, bit_b
= 0;
2582 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2583 if (bit_a
>= bitmap_len
)
2585 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2589 err
= proc_put_char(&buffer
, &left
, ',');
2593 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2596 if (bit_a
!= bit_b
) {
2597 err
= proc_put_char(&buffer
, &left
, '-');
2600 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2608 err
= proc_put_char(&buffer
, &left
, '\n');
2614 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2616 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2628 #else /* CONFIG_PROC_SYSCTL */
2630 int proc_dostring(struct ctl_table
*table
, int write
,
2631 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2636 int proc_dointvec(struct ctl_table
*table
, int write
,
2637 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2642 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2643 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2648 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2649 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2654 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2655 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2660 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2661 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2666 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2667 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2672 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2673 void __user
*buffer
,
2674 size_t *lenp
, loff_t
*ppos
)
2680 #endif /* CONFIG_PROC_SYSCTL */
2683 * No sense putting this after each symbol definition, twice,
2684 * exception granted :-)
2686 EXPORT_SYMBOL(proc_dointvec
);
2687 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2688 EXPORT_SYMBOL(proc_dointvec_minmax
);
2689 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2690 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2691 EXPORT_SYMBOL(proc_dostring
);
2692 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2693 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);