2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
71 #include <asm/stacktrace.h>
75 #include <asm/setup.h>
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
86 #ifdef CONFIG_CHR_DEV_SG
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory
;
99 extern int sysctl_overcommit_ratio
;
100 extern int max_threads
;
101 extern int suid_dumpable
;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid
;
104 extern char core_pattern
[];
105 extern unsigned int core_pipe_limit
;
108 extern int pid_max_min
, pid_max_max
;
109 extern int sysctl_drop_caches
;
110 extern int percpu_pagelist_fraction
;
111 extern int compat_log
;
112 extern int latencytop_enabled
;
113 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
115 extern int sysctl_nr_trim_pages
;
118 extern int blk_iopoll_enabled
;
121 /* Constants used for minimum and maximum */
122 #ifdef CONFIG_LOCKUP_DETECTOR
123 static int sixty
= 60;
124 static int neg_one
= -1;
128 static int __maybe_unused one
= 1;
129 static int __maybe_unused two
= 2;
130 static int __maybe_unused three
= 3;
131 static unsigned long one_ul
= 1;
132 static int one_hundred
= 100;
134 static int ten_thousand
= 10000;
137 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
140 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141 static int maxolduid
= 65535;
142 static int minolduid
;
143 static int min_percpu_pagelist_fract
= 8;
145 static int ngroups_max
= NGROUPS_MAX
;
146 static const int cap_last_cap
= CAP_LAST_CAP
;
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
154 #ifdef CONFIG_SPARC64
155 extern int sysctl_tsb_ratio
;
159 extern int pwrsw_enabled
;
162 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
163 extern int unaligned_enabled
;
167 extern int unaligned_dump_stack
;
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
171 extern int no_unaligned_warning
;
174 #ifdef CONFIG_PROC_SYSCTL
175 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
176 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
177 static int proc_taint(struct ctl_table
*table
, int write
,
178 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
182 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
183 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
186 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
187 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
188 #ifdef CONFIG_COREDUMP
189 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
190 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
193 #ifdef CONFIG_MAGIC_SYSRQ
194 /* Note: sysrq code uses it's own private copy */
195 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
197 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
198 void __user
*buffer
, size_t *lenp
,
203 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
208 sysrq_toggle_support(__sysrq_enabled
);
215 static struct ctl_table kern_table
[];
216 static struct ctl_table vm_table
[];
217 static struct ctl_table fs_table
[];
218 static struct ctl_table debug_table
[];
219 static struct ctl_table dev_table
[];
220 extern struct ctl_table random_table
[];
222 extern struct ctl_table epoll_table
[];
225 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
226 int sysctl_legacy_va_layout
;
229 /* The default sysctl tables: */
231 static struct ctl_table sysctl_base_table
[] = {
233 .procname
= "kernel",
250 .child
= debug_table
,
260 #ifdef CONFIG_SCHED_DEBUG
261 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
262 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
263 static int min_wakeup_granularity_ns
; /* 0 usecs */
264 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
266 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
267 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
268 #endif /* CONFIG_SMP */
269 #endif /* CONFIG_SCHED_DEBUG */
271 #ifdef CONFIG_COMPACTION
272 static int min_extfrag_threshold
;
273 static int max_extfrag_threshold
= 1000;
276 static struct ctl_table kern_table
[] = {
278 .procname
= "sched_child_runs_first",
279 .data
= &sysctl_sched_child_runs_first
,
280 .maxlen
= sizeof(unsigned int),
282 .proc_handler
= proc_dointvec
,
284 #ifdef CONFIG_SCHED_DEBUG
286 .procname
= "sched_min_granularity_ns",
287 .data
= &sysctl_sched_min_granularity
,
288 .maxlen
= sizeof(unsigned int),
290 .proc_handler
= sched_proc_update_handler
,
291 .extra1
= &min_sched_granularity_ns
,
292 .extra2
= &max_sched_granularity_ns
,
295 .procname
= "sched_latency_ns",
296 .data
= &sysctl_sched_latency
,
297 .maxlen
= sizeof(unsigned int),
299 .proc_handler
= sched_proc_update_handler
,
300 .extra1
= &min_sched_granularity_ns
,
301 .extra2
= &max_sched_granularity_ns
,
304 .procname
= "sched_wakeup_granularity_ns",
305 .data
= &sysctl_sched_wakeup_granularity
,
306 .maxlen
= sizeof(unsigned int),
308 .proc_handler
= sched_proc_update_handler
,
309 .extra1
= &min_wakeup_granularity_ns
,
310 .extra2
= &max_wakeup_granularity_ns
,
314 .procname
= "sched_tunable_scaling",
315 .data
= &sysctl_sched_tunable_scaling
,
316 .maxlen
= sizeof(enum sched_tunable_scaling
),
318 .proc_handler
= sched_proc_update_handler
,
319 .extra1
= &min_sched_tunable_scaling
,
320 .extra2
= &max_sched_tunable_scaling
,
323 .procname
= "sched_migration_cost_ns",
324 .data
= &sysctl_sched_migration_cost
,
325 .maxlen
= sizeof(unsigned int),
327 .proc_handler
= proc_dointvec
,
330 .procname
= "sched_nr_migrate",
331 .data
= &sysctl_sched_nr_migrate
,
332 .maxlen
= sizeof(unsigned int),
334 .proc_handler
= proc_dointvec
,
337 .procname
= "sched_time_avg_ms",
338 .data
= &sysctl_sched_time_avg
,
339 .maxlen
= sizeof(unsigned int),
341 .proc_handler
= proc_dointvec
,
344 .procname
= "sched_shares_window_ns",
345 .data
= &sysctl_sched_shares_window
,
346 .maxlen
= sizeof(unsigned int),
348 .proc_handler
= proc_dointvec
,
351 .procname
= "timer_migration",
352 .data
= &sysctl_timer_migration
,
353 .maxlen
= sizeof(unsigned int),
355 .proc_handler
= proc_dointvec_minmax
,
359 #endif /* CONFIG_SMP */
360 #ifdef CONFIG_NUMA_BALANCING
362 .procname
= "numa_balancing_scan_delay_ms",
363 .data
= &sysctl_numa_balancing_scan_delay
,
364 .maxlen
= sizeof(unsigned int),
366 .proc_handler
= proc_dointvec
,
369 .procname
= "numa_balancing_scan_period_min_ms",
370 .data
= &sysctl_numa_balancing_scan_period_min
,
371 .maxlen
= sizeof(unsigned int),
373 .proc_handler
= proc_dointvec
,
376 .procname
= "numa_balancing_scan_period_reset",
377 .data
= &sysctl_numa_balancing_scan_period_reset
,
378 .maxlen
= sizeof(unsigned int),
380 .proc_handler
= proc_dointvec
,
383 .procname
= "numa_balancing_scan_period_max_ms",
384 .data
= &sysctl_numa_balancing_scan_period_max
,
385 .maxlen
= sizeof(unsigned int),
387 .proc_handler
= proc_dointvec
,
390 .procname
= "numa_balancing_scan_size_mb",
391 .data
= &sysctl_numa_balancing_scan_size
,
392 .maxlen
= sizeof(unsigned int),
394 .proc_handler
= proc_dointvec
,
396 #endif /* CONFIG_NUMA_BALANCING */
397 #endif /* CONFIG_SCHED_DEBUG */
399 .procname
= "sched_rt_period_us",
400 .data
= &sysctl_sched_rt_period
,
401 .maxlen
= sizeof(unsigned int),
403 .proc_handler
= sched_rt_handler
,
406 .procname
= "sched_rt_runtime_us",
407 .data
= &sysctl_sched_rt_runtime
,
408 .maxlen
= sizeof(int),
410 .proc_handler
= sched_rt_handler
,
413 .procname
= "sched_rr_timeslice_ms",
414 .data
= &sched_rr_timeslice
,
415 .maxlen
= sizeof(int),
417 .proc_handler
= sched_rr_handler
,
419 #ifdef CONFIG_SCHED_AUTOGROUP
421 .procname
= "sched_autogroup_enabled",
422 .data
= &sysctl_sched_autogroup_enabled
,
423 .maxlen
= sizeof(unsigned int),
425 .proc_handler
= proc_dointvec_minmax
,
430 #ifdef CONFIG_CFS_BANDWIDTH
432 .procname
= "sched_cfs_bandwidth_slice_us",
433 .data
= &sysctl_sched_cfs_bandwidth_slice
,
434 .maxlen
= sizeof(unsigned int),
436 .proc_handler
= proc_dointvec_minmax
,
440 #ifdef CONFIG_PROVE_LOCKING
442 .procname
= "prove_locking",
443 .data
= &prove_locking
,
444 .maxlen
= sizeof(int),
446 .proc_handler
= proc_dointvec
,
449 #ifdef CONFIG_LOCK_STAT
451 .procname
= "lock_stat",
453 .maxlen
= sizeof(int),
455 .proc_handler
= proc_dointvec
,
460 .data
= &panic_timeout
,
461 .maxlen
= sizeof(int),
463 .proc_handler
= proc_dointvec
,
465 #ifdef CONFIG_COREDUMP
467 .procname
= "core_uses_pid",
468 .data
= &core_uses_pid
,
469 .maxlen
= sizeof(int),
471 .proc_handler
= proc_dointvec
,
474 .procname
= "core_pattern",
475 .data
= core_pattern
,
476 .maxlen
= CORENAME_MAX_SIZE
,
478 .proc_handler
= proc_dostring_coredump
,
481 .procname
= "core_pipe_limit",
482 .data
= &core_pipe_limit
,
483 .maxlen
= sizeof(unsigned int),
485 .proc_handler
= proc_dointvec
,
488 #ifdef CONFIG_PROC_SYSCTL
490 .procname
= "tainted",
491 .maxlen
= sizeof(long),
493 .proc_handler
= proc_taint
,
496 #ifdef CONFIG_LATENCYTOP
498 .procname
= "latencytop",
499 .data
= &latencytop_enabled
,
500 .maxlen
= sizeof(int),
502 .proc_handler
= proc_dointvec
,
505 #ifdef CONFIG_BLK_DEV_INITRD
507 .procname
= "real-root-dev",
508 .data
= &real_root_dev
,
509 .maxlen
= sizeof(int),
511 .proc_handler
= proc_dointvec
,
515 .procname
= "print-fatal-signals",
516 .data
= &print_fatal_signals
,
517 .maxlen
= sizeof(int),
519 .proc_handler
= proc_dointvec
,
523 .procname
= "reboot-cmd",
524 .data
= reboot_command
,
527 .proc_handler
= proc_dostring
,
530 .procname
= "stop-a",
531 .data
= &stop_a_enabled
,
532 .maxlen
= sizeof (int),
534 .proc_handler
= proc_dointvec
,
537 .procname
= "scons-poweroff",
538 .data
= &scons_pwroff
,
539 .maxlen
= sizeof (int),
541 .proc_handler
= proc_dointvec
,
544 #ifdef CONFIG_SPARC64
546 .procname
= "tsb-ratio",
547 .data
= &sysctl_tsb_ratio
,
548 .maxlen
= sizeof (int),
550 .proc_handler
= proc_dointvec
,
555 .procname
= "soft-power",
556 .data
= &pwrsw_enabled
,
557 .maxlen
= sizeof (int),
559 .proc_handler
= proc_dointvec
,
562 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
564 .procname
= "unaligned-trap",
565 .data
= &unaligned_enabled
,
566 .maxlen
= sizeof (int),
568 .proc_handler
= proc_dointvec
,
572 .procname
= "ctrl-alt-del",
574 .maxlen
= sizeof(int),
576 .proc_handler
= proc_dointvec
,
578 #ifdef CONFIG_FUNCTION_TRACER
580 .procname
= "ftrace_enabled",
581 .data
= &ftrace_enabled
,
582 .maxlen
= sizeof(int),
584 .proc_handler
= ftrace_enable_sysctl
,
587 #ifdef CONFIG_STACK_TRACER
589 .procname
= "stack_tracer_enabled",
590 .data
= &stack_tracer_enabled
,
591 .maxlen
= sizeof(int),
593 .proc_handler
= stack_trace_sysctl
,
596 #ifdef CONFIG_TRACING
598 .procname
= "ftrace_dump_on_oops",
599 .data
= &ftrace_dump_on_oops
,
600 .maxlen
= sizeof(int),
602 .proc_handler
= proc_dointvec
,
605 #ifdef CONFIG_MODULES
607 .procname
= "modprobe",
608 .data
= &modprobe_path
,
609 .maxlen
= KMOD_PATH_LEN
,
611 .proc_handler
= proc_dostring
,
614 .procname
= "modules_disabled",
615 .data
= &modules_disabled
,
616 .maxlen
= sizeof(int),
618 /* only handle a transition from default "0" to "1" */
619 .proc_handler
= proc_dointvec_minmax
,
626 .procname
= "hotplug",
627 .data
= &uevent_helper
,
628 .maxlen
= UEVENT_HELPER_PATH_LEN
,
630 .proc_handler
= proc_dostring
,
633 #ifdef CONFIG_CHR_DEV_SG
635 .procname
= "sg-big-buff",
636 .data
= &sg_big_buff
,
637 .maxlen
= sizeof (int),
639 .proc_handler
= proc_dointvec
,
642 #ifdef CONFIG_BSD_PROCESS_ACCT
646 .maxlen
= 3*sizeof(int),
648 .proc_handler
= proc_dointvec
,
651 #ifdef CONFIG_MAGIC_SYSRQ
654 .data
= &__sysrq_enabled
,
655 .maxlen
= sizeof (int),
657 .proc_handler
= sysrq_sysctl_handler
,
660 #ifdef CONFIG_PROC_SYSCTL
662 .procname
= "cad_pid",
664 .maxlen
= sizeof (int),
666 .proc_handler
= proc_do_cad_pid
,
670 .procname
= "threads-max",
671 .data
= &max_threads
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= proc_dointvec
,
677 .procname
= "random",
679 .child
= random_table
,
682 .procname
= "usermodehelper",
684 .child
= usermodehelper_table
,
687 .procname
= "overflowuid",
688 .data
= &overflowuid
,
689 .maxlen
= sizeof(int),
691 .proc_handler
= proc_dointvec_minmax
,
692 .extra1
= &minolduid
,
693 .extra2
= &maxolduid
,
696 .procname
= "overflowgid",
697 .data
= &overflowgid
,
698 .maxlen
= sizeof(int),
700 .proc_handler
= proc_dointvec_minmax
,
701 .extra1
= &minolduid
,
702 .extra2
= &maxolduid
,
705 #ifdef CONFIG_MATHEMU
707 .procname
= "ieee_emulation_warnings",
708 .data
= &sysctl_ieee_emulation_warnings
,
709 .maxlen
= sizeof(int),
711 .proc_handler
= proc_dointvec
,
715 .procname
= "userprocess_debug",
716 .data
= &show_unhandled_signals
,
717 .maxlen
= sizeof(int),
719 .proc_handler
= proc_dointvec
,
723 .procname
= "pid_max",
725 .maxlen
= sizeof (int),
727 .proc_handler
= proc_dointvec_minmax
,
728 .extra1
= &pid_max_min
,
729 .extra2
= &pid_max_max
,
732 .procname
= "panic_on_oops",
733 .data
= &panic_on_oops
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= proc_dointvec
,
738 #if defined CONFIG_PRINTK
740 .procname
= "printk",
741 .data
= &console_loglevel
,
742 .maxlen
= 4*sizeof(int),
744 .proc_handler
= proc_dointvec
,
747 .procname
= "printk_ratelimit",
748 .data
= &printk_ratelimit_state
.interval
,
749 .maxlen
= sizeof(int),
751 .proc_handler
= proc_dointvec_jiffies
,
754 .procname
= "printk_ratelimit_burst",
755 .data
= &printk_ratelimit_state
.burst
,
756 .maxlen
= sizeof(int),
758 .proc_handler
= proc_dointvec
,
761 .procname
= "printk_delay",
762 .data
= &printk_delay_msec
,
763 .maxlen
= sizeof(int),
765 .proc_handler
= proc_dointvec_minmax
,
767 .extra2
= &ten_thousand
,
770 .procname
= "dmesg_restrict",
771 .data
= &dmesg_restrict
,
772 .maxlen
= sizeof(int),
774 .proc_handler
= proc_dointvec_minmax_sysadmin
,
779 .procname
= "kptr_restrict",
780 .data
= &kptr_restrict
,
781 .maxlen
= sizeof(int),
783 .proc_handler
= proc_dointvec_minmax_sysadmin
,
789 .procname
= "ngroups_max",
790 .data
= &ngroups_max
,
791 .maxlen
= sizeof (int),
793 .proc_handler
= proc_dointvec
,
796 .procname
= "cap_last_cap",
797 .data
= (void *)&cap_last_cap
,
798 .maxlen
= sizeof(int),
800 .proc_handler
= proc_dointvec
,
802 #if defined(CONFIG_LOCKUP_DETECTOR)
804 .procname
= "watchdog",
805 .data
= &watchdog_enabled
,
806 .maxlen
= sizeof (int),
808 .proc_handler
= proc_dowatchdog
,
813 .procname
= "watchdog_thresh",
814 .data
= &watchdog_thresh
,
815 .maxlen
= sizeof(int),
817 .proc_handler
= proc_dowatchdog
,
822 .procname
= "softlockup_panic",
823 .data
= &softlockup_panic
,
824 .maxlen
= sizeof(int),
826 .proc_handler
= proc_dointvec_minmax
,
831 .procname
= "nmi_watchdog",
832 .data
= &watchdog_enabled
,
833 .maxlen
= sizeof (int),
835 .proc_handler
= proc_dowatchdog
,
840 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
842 .procname
= "unknown_nmi_panic",
843 .data
= &unknown_nmi_panic
,
844 .maxlen
= sizeof (int),
846 .proc_handler
= proc_dointvec
,
849 #if defined(CONFIG_X86)
851 .procname
= "panic_on_unrecovered_nmi",
852 .data
= &panic_on_unrecovered_nmi
,
853 .maxlen
= sizeof(int),
855 .proc_handler
= proc_dointvec
,
858 .procname
= "panic_on_io_nmi",
859 .data
= &panic_on_io_nmi
,
860 .maxlen
= sizeof(int),
862 .proc_handler
= proc_dointvec
,
864 #ifdef CONFIG_DEBUG_STACKOVERFLOW
866 .procname
= "panic_on_stackoverflow",
867 .data
= &sysctl_panic_on_stackoverflow
,
868 .maxlen
= sizeof(int),
870 .proc_handler
= proc_dointvec
,
874 .procname
= "bootloader_type",
875 .data
= &bootloader_type
,
876 .maxlen
= sizeof (int),
878 .proc_handler
= proc_dointvec
,
881 .procname
= "bootloader_version",
882 .data
= &bootloader_version
,
883 .maxlen
= sizeof (int),
885 .proc_handler
= proc_dointvec
,
888 .procname
= "kstack_depth_to_print",
889 .data
= &kstack_depth_to_print
,
890 .maxlen
= sizeof(int),
892 .proc_handler
= proc_dointvec
,
895 .procname
= "io_delay_type",
896 .data
= &io_delay_type
,
897 .maxlen
= sizeof(int),
899 .proc_handler
= proc_dointvec
,
902 #if defined(CONFIG_MMU)
904 .procname
= "randomize_va_space",
905 .data
= &randomize_va_space
,
906 .maxlen
= sizeof(int),
908 .proc_handler
= proc_dointvec
,
911 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
913 .procname
= "spin_retry",
915 .maxlen
= sizeof (int),
917 .proc_handler
= proc_dointvec
,
920 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
922 .procname
= "acpi_video_flags",
923 .data
= &acpi_realmode_flags
,
924 .maxlen
= sizeof (unsigned long),
926 .proc_handler
= proc_doulongvec_minmax
,
929 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
931 .procname
= "ignore-unaligned-usertrap",
932 .data
= &no_unaligned_warning
,
933 .maxlen
= sizeof (int),
935 .proc_handler
= proc_dointvec
,
940 .procname
= "unaligned-dump-stack",
941 .data
= &unaligned_dump_stack
,
942 .maxlen
= sizeof (int),
944 .proc_handler
= proc_dointvec
,
947 #ifdef CONFIG_DETECT_HUNG_TASK
949 .procname
= "hung_task_panic",
950 .data
= &sysctl_hung_task_panic
,
951 .maxlen
= sizeof(int),
953 .proc_handler
= proc_dointvec_minmax
,
958 .procname
= "hung_task_check_count",
959 .data
= &sysctl_hung_task_check_count
,
960 .maxlen
= sizeof(unsigned long),
962 .proc_handler
= proc_doulongvec_minmax
,
965 .procname
= "hung_task_timeout_secs",
966 .data
= &sysctl_hung_task_timeout_secs
,
967 .maxlen
= sizeof(unsigned long),
969 .proc_handler
= proc_dohung_task_timeout_secs
,
972 .procname
= "hung_task_warnings",
973 .data
= &sysctl_hung_task_warnings
,
974 .maxlen
= sizeof(unsigned long),
976 .proc_handler
= proc_doulongvec_minmax
,
981 .procname
= "compat-log",
983 .maxlen
= sizeof (int),
985 .proc_handler
= proc_dointvec
,
988 #ifdef CONFIG_RT_MUTEXES
990 .procname
= "max_lock_depth",
991 .data
= &max_lock_depth
,
992 .maxlen
= sizeof(int),
994 .proc_handler
= proc_dointvec
,
998 .procname
= "poweroff_cmd",
999 .data
= &poweroff_cmd
,
1000 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1002 .proc_handler
= proc_dostring
,
1008 .child
= key_sysctls
,
1011 #ifdef CONFIG_RCU_TORTURE_TEST
1013 .procname
= "rcutorture_runnable",
1014 .data
= &rcutorture_runnable
,
1015 .maxlen
= sizeof(int),
1017 .proc_handler
= proc_dointvec
,
1020 #ifdef CONFIG_PERF_EVENTS
1022 * User-space scripts rely on the existence of this file
1023 * as a feature check for perf_events being enabled.
1025 * So it's an ABI, do not remove!
1028 .procname
= "perf_event_paranoid",
1029 .data
= &sysctl_perf_event_paranoid
,
1030 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1032 .proc_handler
= proc_dointvec
,
1035 .procname
= "perf_event_mlock_kb",
1036 .data
= &sysctl_perf_event_mlock
,
1037 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1039 .proc_handler
= proc_dointvec
,
1042 .procname
= "perf_event_max_sample_rate",
1043 .data
= &sysctl_perf_event_sample_rate
,
1044 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1046 .proc_handler
= perf_proc_update_handler
,
1049 #ifdef CONFIG_KMEMCHECK
1051 .procname
= "kmemcheck",
1052 .data
= &kmemcheck_enabled
,
1053 .maxlen
= sizeof(int),
1055 .proc_handler
= proc_dointvec
,
1060 .procname
= "blk_iopoll",
1061 .data
= &blk_iopoll_enabled
,
1062 .maxlen
= sizeof(int),
1064 .proc_handler
= proc_dointvec
,
1070 static struct ctl_table vm_table
[] = {
1072 .procname
= "overcommit_memory",
1073 .data
= &sysctl_overcommit_memory
,
1074 .maxlen
= sizeof(sysctl_overcommit_memory
),
1076 .proc_handler
= proc_dointvec_minmax
,
1081 .procname
= "panic_on_oom",
1082 .data
= &sysctl_panic_on_oom
,
1083 .maxlen
= sizeof(sysctl_panic_on_oom
),
1085 .proc_handler
= proc_dointvec_minmax
,
1090 .procname
= "oom_kill_allocating_task",
1091 .data
= &sysctl_oom_kill_allocating_task
,
1092 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1094 .proc_handler
= proc_dointvec
,
1097 .procname
= "oom_dump_tasks",
1098 .data
= &sysctl_oom_dump_tasks
,
1099 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1101 .proc_handler
= proc_dointvec
,
1104 .procname
= "overcommit_ratio",
1105 .data
= &sysctl_overcommit_ratio
,
1106 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1108 .proc_handler
= proc_dointvec
,
1111 .procname
= "page-cluster",
1112 .data
= &page_cluster
,
1113 .maxlen
= sizeof(int),
1115 .proc_handler
= proc_dointvec_minmax
,
1119 .procname
= "dirty_background_ratio",
1120 .data
= &dirty_background_ratio
,
1121 .maxlen
= sizeof(dirty_background_ratio
),
1123 .proc_handler
= dirty_background_ratio_handler
,
1125 .extra2
= &one_hundred
,
1128 .procname
= "dirty_background_bytes",
1129 .data
= &dirty_background_bytes
,
1130 .maxlen
= sizeof(dirty_background_bytes
),
1132 .proc_handler
= dirty_background_bytes_handler
,
1136 .procname
= "dirty_ratio",
1137 .data
= &vm_dirty_ratio
,
1138 .maxlen
= sizeof(vm_dirty_ratio
),
1140 .proc_handler
= dirty_ratio_handler
,
1142 .extra2
= &one_hundred
,
1145 .procname
= "dirty_bytes",
1146 .data
= &vm_dirty_bytes
,
1147 .maxlen
= sizeof(vm_dirty_bytes
),
1149 .proc_handler
= dirty_bytes_handler
,
1150 .extra1
= &dirty_bytes_min
,
1153 .procname
= "dirty_writeback_centisecs",
1154 .data
= &dirty_writeback_interval
,
1155 .maxlen
= sizeof(dirty_writeback_interval
),
1157 .proc_handler
= dirty_writeback_centisecs_handler
,
1160 .procname
= "dirty_expire_centisecs",
1161 .data
= &dirty_expire_interval
,
1162 .maxlen
= sizeof(dirty_expire_interval
),
1164 .proc_handler
= proc_dointvec_minmax
,
1168 .procname
= "nr_pdflush_threads",
1169 .mode
= 0444 /* read-only */,
1170 .proc_handler
= pdflush_proc_obsolete
,
1173 .procname
= "swappiness",
1174 .data
= &vm_swappiness
,
1175 .maxlen
= sizeof(vm_swappiness
),
1177 .proc_handler
= proc_dointvec_minmax
,
1179 .extra2
= &one_hundred
,
1181 #ifdef CONFIG_HUGETLB_PAGE
1183 .procname
= "nr_hugepages",
1185 .maxlen
= sizeof(unsigned long),
1187 .proc_handler
= hugetlb_sysctl_handler
,
1188 .extra1
= (void *)&hugetlb_zero
,
1189 .extra2
= (void *)&hugetlb_infinity
,
1193 .procname
= "nr_hugepages_mempolicy",
1195 .maxlen
= sizeof(unsigned long),
1197 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1198 .extra1
= (void *)&hugetlb_zero
,
1199 .extra2
= (void *)&hugetlb_infinity
,
1203 .procname
= "hugetlb_shm_group",
1204 .data
= &sysctl_hugetlb_shm_group
,
1205 .maxlen
= sizeof(gid_t
),
1207 .proc_handler
= proc_dointvec
,
1210 .procname
= "hugepages_treat_as_movable",
1211 .data
= &hugepages_treat_as_movable
,
1212 .maxlen
= sizeof(int),
1214 .proc_handler
= hugetlb_treat_movable_handler
,
1217 .procname
= "nr_overcommit_hugepages",
1219 .maxlen
= sizeof(unsigned long),
1221 .proc_handler
= hugetlb_overcommit_handler
,
1222 .extra1
= (void *)&hugetlb_zero
,
1223 .extra2
= (void *)&hugetlb_infinity
,
1227 .procname
= "lowmem_reserve_ratio",
1228 .data
= &sysctl_lowmem_reserve_ratio
,
1229 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1231 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1234 .procname
= "drop_caches",
1235 .data
= &sysctl_drop_caches
,
1236 .maxlen
= sizeof(int),
1238 .proc_handler
= drop_caches_sysctl_handler
,
1242 #ifdef CONFIG_COMPACTION
1244 .procname
= "compact_memory",
1245 .data
= &sysctl_compact_memory
,
1246 .maxlen
= sizeof(int),
1248 .proc_handler
= sysctl_compaction_handler
,
1251 .procname
= "extfrag_threshold",
1252 .data
= &sysctl_extfrag_threshold
,
1253 .maxlen
= sizeof(int),
1255 .proc_handler
= sysctl_extfrag_handler
,
1256 .extra1
= &min_extfrag_threshold
,
1257 .extra2
= &max_extfrag_threshold
,
1260 #endif /* CONFIG_COMPACTION */
1262 .procname
= "min_free_kbytes",
1263 .data
= &min_free_kbytes
,
1264 .maxlen
= sizeof(min_free_kbytes
),
1266 .proc_handler
= min_free_kbytes_sysctl_handler
,
1270 .procname
= "percpu_pagelist_fraction",
1271 .data
= &percpu_pagelist_fraction
,
1272 .maxlen
= sizeof(percpu_pagelist_fraction
),
1274 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1275 .extra1
= &min_percpu_pagelist_fract
,
1279 .procname
= "max_map_count",
1280 .data
= &sysctl_max_map_count
,
1281 .maxlen
= sizeof(sysctl_max_map_count
),
1283 .proc_handler
= proc_dointvec_minmax
,
1288 .procname
= "nr_trim_pages",
1289 .data
= &sysctl_nr_trim_pages
,
1290 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1292 .proc_handler
= proc_dointvec_minmax
,
1297 .procname
= "laptop_mode",
1298 .data
= &laptop_mode
,
1299 .maxlen
= sizeof(laptop_mode
),
1301 .proc_handler
= proc_dointvec_jiffies
,
1304 .procname
= "block_dump",
1305 .data
= &block_dump
,
1306 .maxlen
= sizeof(block_dump
),
1308 .proc_handler
= proc_dointvec
,
1312 .procname
= "vfs_cache_pressure",
1313 .data
= &sysctl_vfs_cache_pressure
,
1314 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1316 .proc_handler
= proc_dointvec
,
1319 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1321 .procname
= "legacy_va_layout",
1322 .data
= &sysctl_legacy_va_layout
,
1323 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1325 .proc_handler
= proc_dointvec
,
1331 .procname
= "zone_reclaim_mode",
1332 .data
= &zone_reclaim_mode
,
1333 .maxlen
= sizeof(zone_reclaim_mode
),
1335 .proc_handler
= proc_dointvec
,
1339 .procname
= "min_unmapped_ratio",
1340 .data
= &sysctl_min_unmapped_ratio
,
1341 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1343 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1345 .extra2
= &one_hundred
,
1348 .procname
= "min_slab_ratio",
1349 .data
= &sysctl_min_slab_ratio
,
1350 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1352 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1354 .extra2
= &one_hundred
,
1359 .procname
= "stat_interval",
1360 .data
= &sysctl_stat_interval
,
1361 .maxlen
= sizeof(sysctl_stat_interval
),
1363 .proc_handler
= proc_dointvec_jiffies
,
1368 .procname
= "mmap_min_addr",
1369 .data
= &dac_mmap_min_addr
,
1370 .maxlen
= sizeof(unsigned long),
1372 .proc_handler
= mmap_min_addr_handler
,
1377 .procname
= "numa_zonelist_order",
1378 .data
= &numa_zonelist_order
,
1379 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1381 .proc_handler
= numa_zonelist_order_handler
,
1384 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1385 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1387 .procname
= "vdso_enabled",
1388 .data
= &vdso_enabled
,
1389 .maxlen
= sizeof(vdso_enabled
),
1391 .proc_handler
= proc_dointvec
,
1395 #ifdef CONFIG_HIGHMEM
1397 .procname
= "highmem_is_dirtyable",
1398 .data
= &vm_highmem_is_dirtyable
,
1399 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1401 .proc_handler
= proc_dointvec_minmax
,
1407 .procname
= "scan_unevictable_pages",
1408 .data
= &scan_unevictable_pages
,
1409 .maxlen
= sizeof(scan_unevictable_pages
),
1411 .proc_handler
= scan_unevictable_handler
,
1413 #ifdef CONFIG_MEMORY_FAILURE
1415 .procname
= "memory_failure_early_kill",
1416 .data
= &sysctl_memory_failure_early_kill
,
1417 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1419 .proc_handler
= proc_dointvec_minmax
,
1424 .procname
= "memory_failure_recovery",
1425 .data
= &sysctl_memory_failure_recovery
,
1426 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1428 .proc_handler
= proc_dointvec_minmax
,
1436 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1437 static struct ctl_table binfmt_misc_table
[] = {
1442 static struct ctl_table fs_table
[] = {
1444 .procname
= "inode-nr",
1445 .data
= &inodes_stat
,
1446 .maxlen
= 2*sizeof(int),
1448 .proc_handler
= proc_nr_inodes
,
1451 .procname
= "inode-state",
1452 .data
= &inodes_stat
,
1453 .maxlen
= 7*sizeof(int),
1455 .proc_handler
= proc_nr_inodes
,
1458 .procname
= "file-nr",
1459 .data
= &files_stat
,
1460 .maxlen
= sizeof(files_stat
),
1462 .proc_handler
= proc_nr_files
,
1465 .procname
= "file-max",
1466 .data
= &files_stat
.max_files
,
1467 .maxlen
= sizeof(files_stat
.max_files
),
1469 .proc_handler
= proc_doulongvec_minmax
,
1472 .procname
= "nr_open",
1473 .data
= &sysctl_nr_open
,
1474 .maxlen
= sizeof(int),
1476 .proc_handler
= proc_dointvec_minmax
,
1477 .extra1
= &sysctl_nr_open_min
,
1478 .extra2
= &sysctl_nr_open_max
,
1481 .procname
= "dentry-state",
1482 .data
= &dentry_stat
,
1483 .maxlen
= 6*sizeof(int),
1485 .proc_handler
= proc_nr_dentry
,
1488 .procname
= "overflowuid",
1489 .data
= &fs_overflowuid
,
1490 .maxlen
= sizeof(int),
1492 .proc_handler
= proc_dointvec_minmax
,
1493 .extra1
= &minolduid
,
1494 .extra2
= &maxolduid
,
1497 .procname
= "overflowgid",
1498 .data
= &fs_overflowgid
,
1499 .maxlen
= sizeof(int),
1501 .proc_handler
= proc_dointvec_minmax
,
1502 .extra1
= &minolduid
,
1503 .extra2
= &maxolduid
,
1505 #ifdef CONFIG_FILE_LOCKING
1507 .procname
= "leases-enable",
1508 .data
= &leases_enable
,
1509 .maxlen
= sizeof(int),
1511 .proc_handler
= proc_dointvec
,
1514 #ifdef CONFIG_DNOTIFY
1516 .procname
= "dir-notify-enable",
1517 .data
= &dir_notify_enable
,
1518 .maxlen
= sizeof(int),
1520 .proc_handler
= proc_dointvec
,
1524 #ifdef CONFIG_FILE_LOCKING
1526 .procname
= "lease-break-time",
1527 .data
= &lease_break_time
,
1528 .maxlen
= sizeof(int),
1530 .proc_handler
= proc_dointvec
,
1535 .procname
= "aio-nr",
1537 .maxlen
= sizeof(aio_nr
),
1539 .proc_handler
= proc_doulongvec_minmax
,
1542 .procname
= "aio-max-nr",
1543 .data
= &aio_max_nr
,
1544 .maxlen
= sizeof(aio_max_nr
),
1546 .proc_handler
= proc_doulongvec_minmax
,
1548 #endif /* CONFIG_AIO */
1549 #ifdef CONFIG_INOTIFY_USER
1551 .procname
= "inotify",
1553 .child
= inotify_table
,
1558 .procname
= "epoll",
1560 .child
= epoll_table
,
1565 .procname
= "protected_symlinks",
1566 .data
= &sysctl_protected_symlinks
,
1567 .maxlen
= sizeof(int),
1569 .proc_handler
= proc_dointvec_minmax
,
1574 .procname
= "protected_hardlinks",
1575 .data
= &sysctl_protected_hardlinks
,
1576 .maxlen
= sizeof(int),
1578 .proc_handler
= proc_dointvec_minmax
,
1583 .procname
= "suid_dumpable",
1584 .data
= &suid_dumpable
,
1585 .maxlen
= sizeof(int),
1587 .proc_handler
= proc_dointvec_minmax_coredump
,
1591 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1593 .procname
= "binfmt_misc",
1595 .child
= binfmt_misc_table
,
1599 .procname
= "pipe-max-size",
1600 .data
= &pipe_max_size
,
1601 .maxlen
= sizeof(int),
1603 .proc_handler
= &pipe_proc_fn
,
1604 .extra1
= &pipe_min_size
,
1609 static struct ctl_table debug_table
[] = {
1610 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1612 .procname
= "exception-trace",
1613 .data
= &show_unhandled_signals
,
1614 .maxlen
= sizeof(int),
1616 .proc_handler
= proc_dointvec
1619 #if defined(CONFIG_OPTPROBES)
1621 .procname
= "kprobes-optimization",
1622 .data
= &sysctl_kprobes_optimization
,
1623 .maxlen
= sizeof(int),
1625 .proc_handler
= proc_kprobes_optimization_handler
,
1633 static struct ctl_table dev_table
[] = {
1637 int __init
sysctl_init(void)
1639 struct ctl_table_header
*hdr
;
1641 hdr
= register_sysctl_table(sysctl_base_table
);
1642 kmemleak_not_leak(hdr
);
1646 #endif /* CONFIG_SYSCTL */
1652 #ifdef CONFIG_PROC_SYSCTL
1654 static int _proc_do_string(void* data
, int maxlen
, int write
,
1655 void __user
*buffer
,
1656 size_t *lenp
, loff_t
*ppos
)
1662 if (!data
|| !maxlen
|| !*lenp
) {
1670 while (len
< *lenp
) {
1671 if (get_user(c
, p
++))
1673 if (c
== 0 || c
== '\n')
1679 if(copy_from_user(data
, buffer
, len
))
1681 ((char *) data
)[len
] = 0;
1699 if(copy_to_user(buffer
, data
, len
))
1702 if(put_user('\n', ((char __user
*) buffer
) + len
))
1713 * proc_dostring - read a string sysctl
1714 * @table: the sysctl table
1715 * @write: %TRUE if this is a write to the sysctl file
1716 * @buffer: the user buffer
1717 * @lenp: the size of the user buffer
1718 * @ppos: file position
1720 * Reads/writes a string from/to the user buffer. If the kernel
1721 * buffer provided is not large enough to hold the string, the
1722 * string is truncated. The copied string is %NULL-terminated.
1723 * If the string is being read by the user process, it is copied
1724 * and a newline '\n' is added. It is truncated if the buffer is
1727 * Returns 0 on success.
1729 int proc_dostring(struct ctl_table
*table
, int write
,
1730 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1732 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1733 buffer
, lenp
, ppos
);
1736 static size_t proc_skip_spaces(char **buf
)
1739 char *tmp
= skip_spaces(*buf
);
1745 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1755 #define TMPBUFLEN 22
1757 * proc_get_long - reads an ASCII formatted integer from a user buffer
1759 * @buf: a kernel buffer
1760 * @size: size of the kernel buffer
1761 * @val: this is where the number will be stored
1762 * @neg: set to %TRUE if number is negative
1763 * @perm_tr: a vector which contains the allowed trailers
1764 * @perm_tr_len: size of the perm_tr vector
1765 * @tr: pointer to store the trailer character
1767 * In case of success %0 is returned and @buf and @size are updated with
1768 * the amount of bytes read. If @tr is non-NULL and a trailing
1769 * character exists (size is non-zero after returning from this
1770 * function), @tr is updated with the trailing character.
1772 static int proc_get_long(char **buf
, size_t *size
,
1773 unsigned long *val
, bool *neg
,
1774 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1777 char *p
, tmp
[TMPBUFLEN
];
1783 if (len
> TMPBUFLEN
- 1)
1784 len
= TMPBUFLEN
- 1;
1786 memcpy(tmp
, *buf
, len
);
1790 if (*p
== '-' && *size
> 1) {
1798 *val
= simple_strtoul(p
, &p
, 0);
1802 /* We don't know if the next char is whitespace thus we may accept
1803 * invalid integers (e.g. 1234...a) or two integers instead of one
1804 * (e.g. 123...1). So lets not allow such large numbers. */
1805 if (len
== TMPBUFLEN
- 1)
1808 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1811 if (tr
&& (len
< *size
))
1821 * proc_put_long - converts an integer to a decimal ASCII formatted string
1823 * @buf: the user buffer
1824 * @size: the size of the user buffer
1825 * @val: the integer to be converted
1826 * @neg: sign of the number, %TRUE for negative
1828 * In case of success %0 is returned and @buf and @size are updated with
1829 * the amount of bytes written.
1831 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1835 char tmp
[TMPBUFLEN
], *p
= tmp
;
1837 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1841 if (copy_to_user(*buf
, tmp
, len
))
1849 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1852 char __user
**buffer
= (char __user
**)buf
;
1853 if (put_user(c
, *buffer
))
1855 (*size
)--, (*buffer
)++;
1861 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1863 int write
, void *data
)
1866 *valp
= *negp
? -*lvalp
: *lvalp
;
1871 *lvalp
= (unsigned long)-val
;
1874 *lvalp
= (unsigned long)val
;
1880 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1882 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1883 int write
, void __user
*buffer
,
1884 size_t *lenp
, loff_t
*ppos
,
1885 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1886 int write
, void *data
),
1889 int *i
, vleft
, first
= 1, err
= 0;
1890 unsigned long page
= 0;
1894 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1899 i
= (int *) tbl_data
;
1900 vleft
= table
->maxlen
/ sizeof(*i
);
1904 conv
= do_proc_dointvec_conv
;
1907 if (left
> PAGE_SIZE
- 1)
1908 left
= PAGE_SIZE
- 1;
1909 page
= __get_free_page(GFP_TEMPORARY
);
1910 kbuf
= (char *) page
;
1913 if (copy_from_user(kbuf
, buffer
, left
)) {
1920 for (; left
&& vleft
--; i
++, first
=0) {
1925 left
-= proc_skip_spaces(&kbuf
);
1929 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1931 sizeof(proc_wspace_sep
), NULL
);
1934 if (conv(&neg
, &lval
, i
, 1, data
)) {
1939 if (conv(&neg
, &lval
, i
, 0, data
)) {
1944 err
= proc_put_char(&buffer
, &left
, '\t');
1947 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1953 if (!write
&& !first
&& left
&& !err
)
1954 err
= proc_put_char(&buffer
, &left
, '\n');
1955 if (write
&& !err
&& left
)
1956 left
-= proc_skip_spaces(&kbuf
);
1961 return err
? : -EINVAL
;
1968 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1969 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1970 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1971 int write
, void *data
),
1974 return __do_proc_dointvec(table
->data
, table
, write
,
1975 buffer
, lenp
, ppos
, conv
, data
);
1979 * proc_dointvec - read a vector of integers
1980 * @table: the sysctl table
1981 * @write: %TRUE if this is a write to the sysctl file
1982 * @buffer: the user buffer
1983 * @lenp: the size of the user buffer
1984 * @ppos: file position
1986 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1987 * values from/to the user buffer, treated as an ASCII string.
1989 * Returns 0 on success.
1991 int proc_dointvec(struct ctl_table
*table
, int write
,
1992 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1994 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
1999 * Taint values can only be increased
2000 * This means we can safely use a temporary.
2002 static int proc_taint(struct ctl_table
*table
, int write
,
2003 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2006 unsigned long tmptaint
= get_taint();
2009 if (write
&& !capable(CAP_SYS_ADMIN
))
2014 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2020 * Poor man's atomic or. Not worth adding a primitive
2021 * to everyone's atomic.h for this
2024 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2025 if ((tmptaint
>> i
) & 1)
2026 add_taint(i
, LOCKDEP_STILL_OK
);
2033 #ifdef CONFIG_PRINTK
2034 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2035 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2037 if (write
&& !capable(CAP_SYS_ADMIN
))
2040 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2044 struct do_proc_dointvec_minmax_conv_param
{
2049 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2051 int write
, void *data
)
2053 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2055 int val
= *negp
? -*lvalp
: *lvalp
;
2056 if ((param
->min
&& *param
->min
> val
) ||
2057 (param
->max
&& *param
->max
< val
))
2064 *lvalp
= (unsigned long)-val
;
2067 *lvalp
= (unsigned long)val
;
2074 * proc_dointvec_minmax - read a vector of integers with min/max values
2075 * @table: the sysctl table
2076 * @write: %TRUE if this is a write to the sysctl file
2077 * @buffer: the user buffer
2078 * @lenp: the size of the user buffer
2079 * @ppos: file position
2081 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2082 * values from/to the user buffer, treated as an ASCII string.
2084 * This routine will ensure the values are within the range specified by
2085 * table->extra1 (min) and table->extra2 (max).
2087 * Returns 0 on success.
2089 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2090 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2092 struct do_proc_dointvec_minmax_conv_param param
= {
2093 .min
= (int *) table
->extra1
,
2094 .max
= (int *) table
->extra2
,
2096 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2097 do_proc_dointvec_minmax_conv
, ¶m
);
2100 static void validate_coredump_safety(void)
2102 #ifdef CONFIG_COREDUMP
2103 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2104 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2105 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2106 "suid_dumpable=2. Pipe handler or fully qualified "\
2107 "core dump path required.\n");
2112 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2113 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2115 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2117 validate_coredump_safety();
2121 #ifdef CONFIG_COREDUMP
2122 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2123 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2125 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2127 validate_coredump_safety();
2132 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2133 void __user
*buffer
,
2134 size_t *lenp
, loff_t
*ppos
,
2135 unsigned long convmul
,
2136 unsigned long convdiv
)
2138 unsigned long *i
, *min
, *max
;
2139 int vleft
, first
= 1, err
= 0;
2140 unsigned long page
= 0;
2144 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2149 i
= (unsigned long *) data
;
2150 min
= (unsigned long *) table
->extra1
;
2151 max
= (unsigned long *) table
->extra2
;
2152 vleft
= table
->maxlen
/ sizeof(unsigned long);
2156 if (left
> PAGE_SIZE
- 1)
2157 left
= PAGE_SIZE
- 1;
2158 page
= __get_free_page(GFP_TEMPORARY
);
2159 kbuf
= (char *) page
;
2162 if (copy_from_user(kbuf
, buffer
, left
)) {
2169 for (; left
&& vleft
--; i
++, first
= 0) {
2175 left
-= proc_skip_spaces(&kbuf
);
2177 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2179 sizeof(proc_wspace_sep
), NULL
);
2184 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2188 val
= convdiv
* (*i
) / convmul
;
2190 err
= proc_put_char(&buffer
, &left
, '\t');
2191 err
= proc_put_long(&buffer
, &left
, val
, false);
2197 if (!write
&& !first
&& left
&& !err
)
2198 err
= proc_put_char(&buffer
, &left
, '\n');
2200 left
-= proc_skip_spaces(&kbuf
);
2205 return err
? : -EINVAL
;
2212 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2213 void __user
*buffer
,
2214 size_t *lenp
, loff_t
*ppos
,
2215 unsigned long convmul
,
2216 unsigned long convdiv
)
2218 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2219 buffer
, lenp
, ppos
, convmul
, convdiv
);
2223 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2224 * @table: the sysctl table
2225 * @write: %TRUE if this is a write to the sysctl file
2226 * @buffer: the user buffer
2227 * @lenp: the size of the user buffer
2228 * @ppos: file position
2230 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2231 * values from/to the user buffer, treated as an ASCII string.
2233 * This routine will ensure the values are within the range specified by
2234 * table->extra1 (min) and table->extra2 (max).
2236 * Returns 0 on success.
2238 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2239 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2241 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2245 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2246 * @table: the sysctl table
2247 * @write: %TRUE if this is a write to the sysctl file
2248 * @buffer: the user buffer
2249 * @lenp: the size of the user buffer
2250 * @ppos: file position
2252 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2253 * values from/to the user buffer, treated as an ASCII string. The values
2254 * are treated as milliseconds, and converted to jiffies when they are stored.
2256 * This routine will ensure the values are within the range specified by
2257 * table->extra1 (min) and table->extra2 (max).
2259 * Returns 0 on success.
2261 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2262 void __user
*buffer
,
2263 size_t *lenp
, loff_t
*ppos
)
2265 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2266 lenp
, ppos
, HZ
, 1000l);
2270 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2272 int write
, void *data
)
2275 if (*lvalp
> LONG_MAX
/ HZ
)
2277 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2283 lval
= (unsigned long)-val
;
2286 lval
= (unsigned long)val
;
2293 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2295 int write
, void *data
)
2298 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2300 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2306 lval
= (unsigned long)-val
;
2309 lval
= (unsigned long)val
;
2311 *lvalp
= jiffies_to_clock_t(lval
);
2316 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2318 int write
, void *data
)
2321 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2327 lval
= (unsigned long)-val
;
2330 lval
= (unsigned long)val
;
2332 *lvalp
= jiffies_to_msecs(lval
);
2338 * proc_dointvec_jiffies - read a vector of integers as seconds
2339 * @table: the sysctl table
2340 * @write: %TRUE if this is a write to the sysctl file
2341 * @buffer: the user buffer
2342 * @lenp: the size of the user buffer
2343 * @ppos: file position
2345 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2346 * values from/to the user buffer, treated as an ASCII string.
2347 * The values read are assumed to be in seconds, and are converted into
2350 * Returns 0 on success.
2352 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2353 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2355 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2356 do_proc_dointvec_jiffies_conv
,NULL
);
2360 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2361 * @table: the sysctl table
2362 * @write: %TRUE if this is a write to the sysctl file
2363 * @buffer: the user buffer
2364 * @lenp: the size of the user buffer
2365 * @ppos: pointer to the file position
2367 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2368 * values from/to the user buffer, treated as an ASCII string.
2369 * The values read are assumed to be in 1/USER_HZ seconds, and
2370 * are converted into jiffies.
2372 * Returns 0 on success.
2374 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2375 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2377 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2378 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2382 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2383 * @table: the sysctl table
2384 * @write: %TRUE if this is a write to the sysctl file
2385 * @buffer: the user buffer
2386 * @lenp: the size of the user buffer
2387 * @ppos: file position
2388 * @ppos: the current position in the file
2390 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2391 * values from/to the user buffer, treated as an ASCII string.
2392 * The values read are assumed to be in 1/1000 seconds, and
2393 * are converted into jiffies.
2395 * Returns 0 on success.
2397 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2398 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2400 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2401 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2404 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2405 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2407 struct pid
*new_pid
;
2411 tmp
= pid_vnr(cad_pid
);
2413 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2414 lenp
, ppos
, NULL
, NULL
);
2418 new_pid
= find_get_pid(tmp
);
2422 put_pid(xchg(&cad_pid
, new_pid
));
2427 * proc_do_large_bitmap - read/write from/to a large bitmap
2428 * @table: the sysctl table
2429 * @write: %TRUE if this is a write to the sysctl file
2430 * @buffer: the user buffer
2431 * @lenp: the size of the user buffer
2432 * @ppos: file position
2434 * The bitmap is stored at table->data and the bitmap length (in bits)
2437 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2438 * large bitmaps may be represented in a compact manner. Writing into
2439 * the file will clear the bitmap then update it with the given input.
2441 * Returns 0 on success.
2443 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2444 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2448 size_t left
= *lenp
;
2449 unsigned long bitmap_len
= table
->maxlen
;
2450 unsigned long *bitmap
= (unsigned long *) table
->data
;
2451 unsigned long *tmp_bitmap
= NULL
;
2452 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2454 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2460 unsigned long page
= 0;
2463 if (left
> PAGE_SIZE
- 1)
2464 left
= PAGE_SIZE
- 1;
2466 page
= __get_free_page(GFP_TEMPORARY
);
2467 kbuf
= (char *) page
;
2470 if (copy_from_user(kbuf
, buffer
, left
)) {
2476 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2482 proc_skip_char(&kbuf
, &left
, '\n');
2483 while (!err
&& left
) {
2484 unsigned long val_a
, val_b
;
2487 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2491 if (val_a
>= bitmap_len
|| neg
) {
2503 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2504 &neg
, tr_b
, sizeof(tr_b
),
2508 if (val_b
>= bitmap_len
|| neg
||
2519 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2521 proc_skip_char(&kbuf
, &left
, '\n');
2525 unsigned long bit_a
, bit_b
= 0;
2528 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2529 if (bit_a
>= bitmap_len
)
2531 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2535 err
= proc_put_char(&buffer
, &left
, ',');
2539 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2542 if (bit_a
!= bit_b
) {
2543 err
= proc_put_char(&buffer
, &left
, '-');
2546 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2554 err
= proc_put_char(&buffer
, &left
, '\n');
2560 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2562 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2574 #else /* CONFIG_PROC_SYSCTL */
2576 int proc_dostring(struct ctl_table
*table
, int write
,
2577 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2582 int proc_dointvec(struct ctl_table
*table
, int write
,
2583 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2588 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2589 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2594 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2595 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2600 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2601 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2606 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2607 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2612 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2613 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2618 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2619 void __user
*buffer
,
2620 size_t *lenp
, loff_t
*ppos
)
2626 #endif /* CONFIG_PROC_SYSCTL */
2629 * No sense putting this after each symbol definition, twice,
2630 * exception granted :-)
2632 EXPORT_SYMBOL(proc_dointvec
);
2633 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2634 EXPORT_SYMBOL(proc_dointvec_minmax
);
2635 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2636 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2637 EXPORT_SYMBOL(proc_dostring
);
2638 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2639 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);