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 min_free_kbytes
;
109 extern int pid_max_min
, pid_max_max
;
110 extern int sysctl_drop_caches
;
111 extern int percpu_pagelist_fraction
;
112 extern int compat_log
;
113 extern int latencytop_enabled
;
114 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
116 extern int sysctl_nr_trim_pages
;
119 extern int blk_iopoll_enabled
;
122 /* Constants used for minimum and maximum */
123 #ifdef CONFIG_LOCKUP_DETECTOR
124 static int sixty
= 60;
125 static int neg_one
= -1;
129 static int __maybe_unused one
= 1;
130 static int __maybe_unused two
= 2;
131 static int __maybe_unused three
= 3;
132 static unsigned long one_ul
= 1;
133 static int one_hundred
= 100;
135 static int ten_thousand
= 10000;
138 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
141 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142 static int maxolduid
= 65535;
143 static int minolduid
;
144 static int min_percpu_pagelist_fract
= 8;
146 static int ngroups_max
= NGROUPS_MAX
;
147 static const int cap_last_cap
= CAP_LAST_CAP
;
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
;
161 extern int unaligned_enabled
;
165 extern int no_unaligned_warning
;
166 extern int unaligned_dump_stack
;
169 #ifdef CONFIG_PROC_SYSCTL
170 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
171 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
172 static int proc_taint(struct ctl_table
*table
, int write
,
173 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
177 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
178 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
181 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
182 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
183 #ifdef CONFIG_COREDUMP
184 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
185 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
188 #ifdef CONFIG_MAGIC_SYSRQ
189 /* Note: sysrq code uses it's own private copy */
190 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
192 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
193 void __user
*buffer
, size_t *lenp
,
198 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
203 sysrq_toggle_support(__sysrq_enabled
);
210 static struct ctl_table kern_table
[];
211 static struct ctl_table vm_table
[];
212 static struct ctl_table fs_table
[];
213 static struct ctl_table debug_table
[];
214 static struct ctl_table dev_table
[];
215 extern struct ctl_table random_table
[];
217 extern struct ctl_table epoll_table
[];
220 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
221 int sysctl_legacy_va_layout
;
224 /* The default sysctl tables: */
226 static struct ctl_table sysctl_base_table
[] = {
228 .procname
= "kernel",
245 .child
= debug_table
,
255 #ifdef CONFIG_SCHED_DEBUG
256 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
257 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
258 static int min_wakeup_granularity_ns
; /* 0 usecs */
259 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
261 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
262 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
263 #endif /* CONFIG_SMP */
264 #endif /* CONFIG_SCHED_DEBUG */
266 #ifdef CONFIG_COMPACTION
267 static int min_extfrag_threshold
;
268 static int max_extfrag_threshold
= 1000;
271 static struct ctl_table kern_table
[] = {
273 .procname
= "sched_child_runs_first",
274 .data
= &sysctl_sched_child_runs_first
,
275 .maxlen
= sizeof(unsigned int),
277 .proc_handler
= proc_dointvec
,
279 #ifdef CONFIG_SCHED_DEBUG
281 .procname
= "sched_min_granularity_ns",
282 .data
= &sysctl_sched_min_granularity
,
283 .maxlen
= sizeof(unsigned int),
285 .proc_handler
= sched_proc_update_handler
,
286 .extra1
= &min_sched_granularity_ns
,
287 .extra2
= &max_sched_granularity_ns
,
290 .procname
= "sched_latency_ns",
291 .data
= &sysctl_sched_latency
,
292 .maxlen
= sizeof(unsigned int),
294 .proc_handler
= sched_proc_update_handler
,
295 .extra1
= &min_sched_granularity_ns
,
296 .extra2
= &max_sched_granularity_ns
,
299 .procname
= "sched_wakeup_granularity_ns",
300 .data
= &sysctl_sched_wakeup_granularity
,
301 .maxlen
= sizeof(unsigned int),
303 .proc_handler
= sched_proc_update_handler
,
304 .extra1
= &min_wakeup_granularity_ns
,
305 .extra2
= &max_wakeup_granularity_ns
,
309 .procname
= "sched_tunable_scaling",
310 .data
= &sysctl_sched_tunable_scaling
,
311 .maxlen
= sizeof(enum sched_tunable_scaling
),
313 .proc_handler
= sched_proc_update_handler
,
314 .extra1
= &min_sched_tunable_scaling
,
315 .extra2
= &max_sched_tunable_scaling
,
318 .procname
= "sched_migration_cost_ns",
319 .data
= &sysctl_sched_migration_cost
,
320 .maxlen
= sizeof(unsigned int),
322 .proc_handler
= proc_dointvec
,
325 .procname
= "sched_nr_migrate",
326 .data
= &sysctl_sched_nr_migrate
,
327 .maxlen
= sizeof(unsigned int),
329 .proc_handler
= proc_dointvec
,
332 .procname
= "sched_time_avg_ms",
333 .data
= &sysctl_sched_time_avg
,
334 .maxlen
= sizeof(unsigned int),
336 .proc_handler
= proc_dointvec
,
339 .procname
= "sched_shares_window_ns",
340 .data
= &sysctl_sched_shares_window
,
341 .maxlen
= sizeof(unsigned int),
343 .proc_handler
= proc_dointvec
,
346 .procname
= "timer_migration",
347 .data
= &sysctl_timer_migration
,
348 .maxlen
= sizeof(unsigned int),
350 .proc_handler
= proc_dointvec_minmax
,
354 #endif /* CONFIG_SMP */
355 #ifdef CONFIG_NUMA_BALANCING
357 .procname
= "numa_balancing_scan_delay_ms",
358 .data
= &sysctl_numa_balancing_scan_delay
,
359 .maxlen
= sizeof(unsigned int),
361 .proc_handler
= proc_dointvec
,
364 .procname
= "numa_balancing_scan_period_min_ms",
365 .data
= &sysctl_numa_balancing_scan_period_min
,
366 .maxlen
= sizeof(unsigned int),
368 .proc_handler
= proc_dointvec
,
371 .procname
= "numa_balancing_scan_period_reset",
372 .data
= &sysctl_numa_balancing_scan_period_reset
,
373 .maxlen
= sizeof(unsigned int),
375 .proc_handler
= proc_dointvec
,
378 .procname
= "numa_balancing_scan_period_max_ms",
379 .data
= &sysctl_numa_balancing_scan_period_max
,
380 .maxlen
= sizeof(unsigned int),
382 .proc_handler
= proc_dointvec
,
385 .procname
= "numa_balancing_scan_size_mb",
386 .data
= &sysctl_numa_balancing_scan_size
,
387 .maxlen
= sizeof(unsigned int),
389 .proc_handler
= proc_dointvec
,
391 #endif /* CONFIG_NUMA_BALANCING */
392 #endif /* CONFIG_SCHED_DEBUG */
394 .procname
= "sched_rt_period_us",
395 .data
= &sysctl_sched_rt_period
,
396 .maxlen
= sizeof(unsigned int),
398 .proc_handler
= sched_rt_handler
,
401 .procname
= "sched_rt_runtime_us",
402 .data
= &sysctl_sched_rt_runtime
,
403 .maxlen
= sizeof(int),
405 .proc_handler
= sched_rt_handler
,
408 .procname
= "sched_rr_timeslice_ms",
409 .data
= &sched_rr_timeslice
,
410 .maxlen
= sizeof(int),
412 .proc_handler
= sched_rr_handler
,
414 #ifdef CONFIG_SCHED_AUTOGROUP
416 .procname
= "sched_autogroup_enabled",
417 .data
= &sysctl_sched_autogroup_enabled
,
418 .maxlen
= sizeof(unsigned int),
420 .proc_handler
= proc_dointvec_minmax
,
425 #ifdef CONFIG_CFS_BANDWIDTH
427 .procname
= "sched_cfs_bandwidth_slice_us",
428 .data
= &sysctl_sched_cfs_bandwidth_slice
,
429 .maxlen
= sizeof(unsigned int),
431 .proc_handler
= proc_dointvec_minmax
,
435 #ifdef CONFIG_PROVE_LOCKING
437 .procname
= "prove_locking",
438 .data
= &prove_locking
,
439 .maxlen
= sizeof(int),
441 .proc_handler
= proc_dointvec
,
444 #ifdef CONFIG_LOCK_STAT
446 .procname
= "lock_stat",
448 .maxlen
= sizeof(int),
450 .proc_handler
= proc_dointvec
,
455 .data
= &panic_timeout
,
456 .maxlen
= sizeof(int),
458 .proc_handler
= proc_dointvec
,
460 #ifdef CONFIG_COREDUMP
462 .procname
= "core_uses_pid",
463 .data
= &core_uses_pid
,
464 .maxlen
= sizeof(int),
466 .proc_handler
= proc_dointvec
,
469 .procname
= "core_pattern",
470 .data
= core_pattern
,
471 .maxlen
= CORENAME_MAX_SIZE
,
473 .proc_handler
= proc_dostring_coredump
,
476 .procname
= "core_pipe_limit",
477 .data
= &core_pipe_limit
,
478 .maxlen
= sizeof(unsigned int),
480 .proc_handler
= proc_dointvec
,
483 #ifdef CONFIG_PROC_SYSCTL
485 .procname
= "tainted",
486 .maxlen
= sizeof(long),
488 .proc_handler
= proc_taint
,
491 #ifdef CONFIG_LATENCYTOP
493 .procname
= "latencytop",
494 .data
= &latencytop_enabled
,
495 .maxlen
= sizeof(int),
497 .proc_handler
= proc_dointvec
,
500 #ifdef CONFIG_BLK_DEV_INITRD
502 .procname
= "real-root-dev",
503 .data
= &real_root_dev
,
504 .maxlen
= sizeof(int),
506 .proc_handler
= proc_dointvec
,
510 .procname
= "print-fatal-signals",
511 .data
= &print_fatal_signals
,
512 .maxlen
= sizeof(int),
514 .proc_handler
= proc_dointvec
,
518 .procname
= "reboot-cmd",
519 .data
= reboot_command
,
522 .proc_handler
= proc_dostring
,
525 .procname
= "stop-a",
526 .data
= &stop_a_enabled
,
527 .maxlen
= sizeof (int),
529 .proc_handler
= proc_dointvec
,
532 .procname
= "scons-poweroff",
533 .data
= &scons_pwroff
,
534 .maxlen
= sizeof (int),
536 .proc_handler
= proc_dointvec
,
539 #ifdef CONFIG_SPARC64
541 .procname
= "tsb-ratio",
542 .data
= &sysctl_tsb_ratio
,
543 .maxlen
= sizeof (int),
545 .proc_handler
= proc_dointvec
,
550 .procname
= "soft-power",
551 .data
= &pwrsw_enabled
,
552 .maxlen
= sizeof (int),
554 .proc_handler
= proc_dointvec
,
557 .procname
= "unaligned-trap",
558 .data
= &unaligned_enabled
,
559 .maxlen
= sizeof (int),
561 .proc_handler
= proc_dointvec
,
565 .procname
= "ctrl-alt-del",
567 .maxlen
= sizeof(int),
569 .proc_handler
= proc_dointvec
,
571 #ifdef CONFIG_FUNCTION_TRACER
573 .procname
= "ftrace_enabled",
574 .data
= &ftrace_enabled
,
575 .maxlen
= sizeof(int),
577 .proc_handler
= ftrace_enable_sysctl
,
580 #ifdef CONFIG_STACK_TRACER
582 .procname
= "stack_tracer_enabled",
583 .data
= &stack_tracer_enabled
,
584 .maxlen
= sizeof(int),
586 .proc_handler
= stack_trace_sysctl
,
589 #ifdef CONFIG_TRACING
591 .procname
= "ftrace_dump_on_oops",
592 .data
= &ftrace_dump_on_oops
,
593 .maxlen
= sizeof(int),
595 .proc_handler
= proc_dointvec
,
598 #ifdef CONFIG_MODULES
600 .procname
= "modprobe",
601 .data
= &modprobe_path
,
602 .maxlen
= KMOD_PATH_LEN
,
604 .proc_handler
= proc_dostring
,
607 .procname
= "modules_disabled",
608 .data
= &modules_disabled
,
609 .maxlen
= sizeof(int),
611 /* only handle a transition from default "0" to "1" */
612 .proc_handler
= proc_dointvec_minmax
,
619 .procname
= "hotplug",
620 .data
= &uevent_helper
,
621 .maxlen
= UEVENT_HELPER_PATH_LEN
,
623 .proc_handler
= proc_dostring
,
626 #ifdef CONFIG_CHR_DEV_SG
628 .procname
= "sg-big-buff",
629 .data
= &sg_big_buff
,
630 .maxlen
= sizeof (int),
632 .proc_handler
= proc_dointvec
,
635 #ifdef CONFIG_BSD_PROCESS_ACCT
639 .maxlen
= 3*sizeof(int),
641 .proc_handler
= proc_dointvec
,
644 #ifdef CONFIG_MAGIC_SYSRQ
647 .data
= &__sysrq_enabled
,
648 .maxlen
= sizeof (int),
650 .proc_handler
= sysrq_sysctl_handler
,
653 #ifdef CONFIG_PROC_SYSCTL
655 .procname
= "cad_pid",
657 .maxlen
= sizeof (int),
659 .proc_handler
= proc_do_cad_pid
,
663 .procname
= "threads-max",
664 .data
= &max_threads
,
665 .maxlen
= sizeof(int),
667 .proc_handler
= proc_dointvec
,
670 .procname
= "random",
672 .child
= random_table
,
675 .procname
= "usermodehelper",
677 .child
= usermodehelper_table
,
680 .procname
= "overflowuid",
681 .data
= &overflowuid
,
682 .maxlen
= sizeof(int),
684 .proc_handler
= proc_dointvec_minmax
,
685 .extra1
= &minolduid
,
686 .extra2
= &maxolduid
,
689 .procname
= "overflowgid",
690 .data
= &overflowgid
,
691 .maxlen
= sizeof(int),
693 .proc_handler
= proc_dointvec_minmax
,
694 .extra1
= &minolduid
,
695 .extra2
= &maxolduid
,
698 #ifdef CONFIG_MATHEMU
700 .procname
= "ieee_emulation_warnings",
701 .data
= &sysctl_ieee_emulation_warnings
,
702 .maxlen
= sizeof(int),
704 .proc_handler
= proc_dointvec
,
708 .procname
= "userprocess_debug",
709 .data
= &show_unhandled_signals
,
710 .maxlen
= sizeof(int),
712 .proc_handler
= proc_dointvec
,
716 .procname
= "pid_max",
718 .maxlen
= sizeof (int),
720 .proc_handler
= proc_dointvec_minmax
,
721 .extra1
= &pid_max_min
,
722 .extra2
= &pid_max_max
,
725 .procname
= "panic_on_oops",
726 .data
= &panic_on_oops
,
727 .maxlen
= sizeof(int),
729 .proc_handler
= proc_dointvec
,
731 #if defined CONFIG_PRINTK
733 .procname
= "printk",
734 .data
= &console_loglevel
,
735 .maxlen
= 4*sizeof(int),
737 .proc_handler
= proc_dointvec
,
740 .procname
= "printk_ratelimit",
741 .data
= &printk_ratelimit_state
.interval
,
742 .maxlen
= sizeof(int),
744 .proc_handler
= proc_dointvec_jiffies
,
747 .procname
= "printk_ratelimit_burst",
748 .data
= &printk_ratelimit_state
.burst
,
749 .maxlen
= sizeof(int),
751 .proc_handler
= proc_dointvec
,
754 .procname
= "printk_delay",
755 .data
= &printk_delay_msec
,
756 .maxlen
= sizeof(int),
758 .proc_handler
= proc_dointvec_minmax
,
760 .extra2
= &ten_thousand
,
763 .procname
= "dmesg_restrict",
764 .data
= &dmesg_restrict
,
765 .maxlen
= sizeof(int),
767 .proc_handler
= proc_dointvec_minmax_sysadmin
,
772 .procname
= "kptr_restrict",
773 .data
= &kptr_restrict
,
774 .maxlen
= sizeof(int),
776 .proc_handler
= proc_dointvec_minmax_sysadmin
,
782 .procname
= "ngroups_max",
783 .data
= &ngroups_max
,
784 .maxlen
= sizeof (int),
786 .proc_handler
= proc_dointvec
,
789 .procname
= "cap_last_cap",
790 .data
= (void *)&cap_last_cap
,
791 .maxlen
= sizeof(int),
793 .proc_handler
= proc_dointvec
,
795 #if defined(CONFIG_LOCKUP_DETECTOR)
797 .procname
= "watchdog",
798 .data
= &watchdog_enabled
,
799 .maxlen
= sizeof (int),
801 .proc_handler
= proc_dowatchdog
,
806 .procname
= "watchdog_thresh",
807 .data
= &watchdog_thresh
,
808 .maxlen
= sizeof(int),
810 .proc_handler
= proc_dowatchdog
,
815 .procname
= "softlockup_panic",
816 .data
= &softlockup_panic
,
817 .maxlen
= sizeof(int),
819 .proc_handler
= proc_dointvec_minmax
,
824 .procname
= "nmi_watchdog",
825 .data
= &watchdog_enabled
,
826 .maxlen
= sizeof (int),
828 .proc_handler
= proc_dowatchdog
,
833 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
835 .procname
= "unknown_nmi_panic",
836 .data
= &unknown_nmi_panic
,
837 .maxlen
= sizeof (int),
839 .proc_handler
= proc_dointvec
,
842 #if defined(CONFIG_X86)
844 .procname
= "panic_on_unrecovered_nmi",
845 .data
= &panic_on_unrecovered_nmi
,
846 .maxlen
= sizeof(int),
848 .proc_handler
= proc_dointvec
,
851 .procname
= "panic_on_io_nmi",
852 .data
= &panic_on_io_nmi
,
853 .maxlen
= sizeof(int),
855 .proc_handler
= proc_dointvec
,
857 #ifdef CONFIG_DEBUG_STACKOVERFLOW
859 .procname
= "panic_on_stackoverflow",
860 .data
= &sysctl_panic_on_stackoverflow
,
861 .maxlen
= sizeof(int),
863 .proc_handler
= proc_dointvec
,
867 .procname
= "bootloader_type",
868 .data
= &bootloader_type
,
869 .maxlen
= sizeof (int),
871 .proc_handler
= proc_dointvec
,
874 .procname
= "bootloader_version",
875 .data
= &bootloader_version
,
876 .maxlen
= sizeof (int),
878 .proc_handler
= proc_dointvec
,
881 .procname
= "kstack_depth_to_print",
882 .data
= &kstack_depth_to_print
,
883 .maxlen
= sizeof(int),
885 .proc_handler
= proc_dointvec
,
888 .procname
= "io_delay_type",
889 .data
= &io_delay_type
,
890 .maxlen
= sizeof(int),
892 .proc_handler
= proc_dointvec
,
895 #if defined(CONFIG_MMU)
897 .procname
= "randomize_va_space",
898 .data
= &randomize_va_space
,
899 .maxlen
= sizeof(int),
901 .proc_handler
= proc_dointvec
,
904 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
906 .procname
= "spin_retry",
908 .maxlen
= sizeof (int),
910 .proc_handler
= proc_dointvec
,
913 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
915 .procname
= "acpi_video_flags",
916 .data
= &acpi_realmode_flags
,
917 .maxlen
= sizeof (unsigned long),
919 .proc_handler
= proc_doulongvec_minmax
,
924 .procname
= "ignore-unaligned-usertrap",
925 .data
= &no_unaligned_warning
,
926 .maxlen
= sizeof (int),
928 .proc_handler
= proc_dointvec
,
931 .procname
= "unaligned-dump-stack",
932 .data
= &unaligned_dump_stack
,
933 .maxlen
= sizeof (int),
935 .proc_handler
= proc_dointvec
,
938 #ifdef CONFIG_DETECT_HUNG_TASK
940 .procname
= "hung_task_panic",
941 .data
= &sysctl_hung_task_panic
,
942 .maxlen
= sizeof(int),
944 .proc_handler
= proc_dointvec_minmax
,
949 .procname
= "hung_task_check_count",
950 .data
= &sysctl_hung_task_check_count
,
951 .maxlen
= sizeof(unsigned long),
953 .proc_handler
= proc_doulongvec_minmax
,
956 .procname
= "hung_task_timeout_secs",
957 .data
= &sysctl_hung_task_timeout_secs
,
958 .maxlen
= sizeof(unsigned long),
960 .proc_handler
= proc_dohung_task_timeout_secs
,
963 .procname
= "hung_task_warnings",
964 .data
= &sysctl_hung_task_warnings
,
965 .maxlen
= sizeof(unsigned long),
967 .proc_handler
= proc_doulongvec_minmax
,
972 .procname
= "compat-log",
974 .maxlen
= sizeof (int),
976 .proc_handler
= proc_dointvec
,
979 #ifdef CONFIG_RT_MUTEXES
981 .procname
= "max_lock_depth",
982 .data
= &max_lock_depth
,
983 .maxlen
= sizeof(int),
985 .proc_handler
= proc_dointvec
,
989 .procname
= "poweroff_cmd",
990 .data
= &poweroff_cmd
,
991 .maxlen
= POWEROFF_CMD_PATH_LEN
,
993 .proc_handler
= proc_dostring
,
999 .child
= key_sysctls
,
1002 #ifdef CONFIG_RCU_TORTURE_TEST
1004 .procname
= "rcutorture_runnable",
1005 .data
= &rcutorture_runnable
,
1006 .maxlen
= sizeof(int),
1008 .proc_handler
= proc_dointvec
,
1011 #ifdef CONFIG_PERF_EVENTS
1013 * User-space scripts rely on the existence of this file
1014 * as a feature check for perf_events being enabled.
1016 * So it's an ABI, do not remove!
1019 .procname
= "perf_event_paranoid",
1020 .data
= &sysctl_perf_event_paranoid
,
1021 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1023 .proc_handler
= proc_dointvec
,
1026 .procname
= "perf_event_mlock_kb",
1027 .data
= &sysctl_perf_event_mlock
,
1028 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1030 .proc_handler
= proc_dointvec
,
1033 .procname
= "perf_event_max_sample_rate",
1034 .data
= &sysctl_perf_event_sample_rate
,
1035 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1037 .proc_handler
= perf_proc_update_handler
,
1040 #ifdef CONFIG_KMEMCHECK
1042 .procname
= "kmemcheck",
1043 .data
= &kmemcheck_enabled
,
1044 .maxlen
= sizeof(int),
1046 .proc_handler
= proc_dointvec
,
1051 .procname
= "blk_iopoll",
1052 .data
= &blk_iopoll_enabled
,
1053 .maxlen
= sizeof(int),
1055 .proc_handler
= proc_dointvec
,
1061 static struct ctl_table vm_table
[] = {
1063 .procname
= "overcommit_memory",
1064 .data
= &sysctl_overcommit_memory
,
1065 .maxlen
= sizeof(sysctl_overcommit_memory
),
1067 .proc_handler
= proc_dointvec_minmax
,
1072 .procname
= "panic_on_oom",
1073 .data
= &sysctl_panic_on_oom
,
1074 .maxlen
= sizeof(sysctl_panic_on_oom
),
1076 .proc_handler
= proc_dointvec_minmax
,
1081 .procname
= "oom_kill_allocating_task",
1082 .data
= &sysctl_oom_kill_allocating_task
,
1083 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1085 .proc_handler
= proc_dointvec
,
1088 .procname
= "oom_dump_tasks",
1089 .data
= &sysctl_oom_dump_tasks
,
1090 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1092 .proc_handler
= proc_dointvec
,
1095 .procname
= "overcommit_ratio",
1096 .data
= &sysctl_overcommit_ratio
,
1097 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1099 .proc_handler
= proc_dointvec
,
1102 .procname
= "page-cluster",
1103 .data
= &page_cluster
,
1104 .maxlen
= sizeof(int),
1106 .proc_handler
= proc_dointvec_minmax
,
1110 .procname
= "dirty_background_ratio",
1111 .data
= &dirty_background_ratio
,
1112 .maxlen
= sizeof(dirty_background_ratio
),
1114 .proc_handler
= dirty_background_ratio_handler
,
1116 .extra2
= &one_hundred
,
1119 .procname
= "dirty_background_bytes",
1120 .data
= &dirty_background_bytes
,
1121 .maxlen
= sizeof(dirty_background_bytes
),
1123 .proc_handler
= dirty_background_bytes_handler
,
1127 .procname
= "dirty_ratio",
1128 .data
= &vm_dirty_ratio
,
1129 .maxlen
= sizeof(vm_dirty_ratio
),
1131 .proc_handler
= dirty_ratio_handler
,
1133 .extra2
= &one_hundred
,
1136 .procname
= "dirty_bytes",
1137 .data
= &vm_dirty_bytes
,
1138 .maxlen
= sizeof(vm_dirty_bytes
),
1140 .proc_handler
= dirty_bytes_handler
,
1141 .extra1
= &dirty_bytes_min
,
1144 .procname
= "dirty_writeback_centisecs",
1145 .data
= &dirty_writeback_interval
,
1146 .maxlen
= sizeof(dirty_writeback_interval
),
1148 .proc_handler
= dirty_writeback_centisecs_handler
,
1151 .procname
= "dirty_expire_centisecs",
1152 .data
= &dirty_expire_interval
,
1153 .maxlen
= sizeof(dirty_expire_interval
),
1155 .proc_handler
= proc_dointvec_minmax
,
1159 .procname
= "nr_pdflush_threads",
1160 .mode
= 0444 /* read-only */,
1161 .proc_handler
= pdflush_proc_obsolete
,
1164 .procname
= "swappiness",
1165 .data
= &vm_swappiness
,
1166 .maxlen
= sizeof(vm_swappiness
),
1168 .proc_handler
= proc_dointvec_minmax
,
1170 .extra2
= &one_hundred
,
1172 #ifdef CONFIG_HUGETLB_PAGE
1174 .procname
= "nr_hugepages",
1176 .maxlen
= sizeof(unsigned long),
1178 .proc_handler
= hugetlb_sysctl_handler
,
1179 .extra1
= (void *)&hugetlb_zero
,
1180 .extra2
= (void *)&hugetlb_infinity
,
1184 .procname
= "nr_hugepages_mempolicy",
1186 .maxlen
= sizeof(unsigned long),
1188 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1189 .extra1
= (void *)&hugetlb_zero
,
1190 .extra2
= (void *)&hugetlb_infinity
,
1194 .procname
= "hugetlb_shm_group",
1195 .data
= &sysctl_hugetlb_shm_group
,
1196 .maxlen
= sizeof(gid_t
),
1198 .proc_handler
= proc_dointvec
,
1201 .procname
= "hugepages_treat_as_movable",
1202 .data
= &hugepages_treat_as_movable
,
1203 .maxlen
= sizeof(int),
1205 .proc_handler
= hugetlb_treat_movable_handler
,
1208 .procname
= "nr_overcommit_hugepages",
1210 .maxlen
= sizeof(unsigned long),
1212 .proc_handler
= hugetlb_overcommit_handler
,
1213 .extra1
= (void *)&hugetlb_zero
,
1214 .extra2
= (void *)&hugetlb_infinity
,
1218 .procname
= "lowmem_reserve_ratio",
1219 .data
= &sysctl_lowmem_reserve_ratio
,
1220 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1222 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1225 .procname
= "drop_caches",
1226 .data
= &sysctl_drop_caches
,
1227 .maxlen
= sizeof(int),
1229 .proc_handler
= drop_caches_sysctl_handler
,
1233 #ifdef CONFIG_COMPACTION
1235 .procname
= "compact_memory",
1236 .data
= &sysctl_compact_memory
,
1237 .maxlen
= sizeof(int),
1239 .proc_handler
= sysctl_compaction_handler
,
1242 .procname
= "extfrag_threshold",
1243 .data
= &sysctl_extfrag_threshold
,
1244 .maxlen
= sizeof(int),
1246 .proc_handler
= sysctl_extfrag_handler
,
1247 .extra1
= &min_extfrag_threshold
,
1248 .extra2
= &max_extfrag_threshold
,
1251 #endif /* CONFIG_COMPACTION */
1253 .procname
= "min_free_kbytes",
1254 .data
= &min_free_kbytes
,
1255 .maxlen
= sizeof(min_free_kbytes
),
1257 .proc_handler
= min_free_kbytes_sysctl_handler
,
1261 .procname
= "percpu_pagelist_fraction",
1262 .data
= &percpu_pagelist_fraction
,
1263 .maxlen
= sizeof(percpu_pagelist_fraction
),
1265 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1266 .extra1
= &min_percpu_pagelist_fract
,
1270 .procname
= "max_map_count",
1271 .data
= &sysctl_max_map_count
,
1272 .maxlen
= sizeof(sysctl_max_map_count
),
1274 .proc_handler
= proc_dointvec_minmax
,
1279 .procname
= "nr_trim_pages",
1280 .data
= &sysctl_nr_trim_pages
,
1281 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1283 .proc_handler
= proc_dointvec_minmax
,
1288 .procname
= "laptop_mode",
1289 .data
= &laptop_mode
,
1290 .maxlen
= sizeof(laptop_mode
),
1292 .proc_handler
= proc_dointvec_jiffies
,
1295 .procname
= "block_dump",
1296 .data
= &block_dump
,
1297 .maxlen
= sizeof(block_dump
),
1299 .proc_handler
= proc_dointvec
,
1303 .procname
= "vfs_cache_pressure",
1304 .data
= &sysctl_vfs_cache_pressure
,
1305 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1307 .proc_handler
= proc_dointvec
,
1310 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1312 .procname
= "legacy_va_layout",
1313 .data
= &sysctl_legacy_va_layout
,
1314 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1316 .proc_handler
= proc_dointvec
,
1322 .procname
= "zone_reclaim_mode",
1323 .data
= &zone_reclaim_mode
,
1324 .maxlen
= sizeof(zone_reclaim_mode
),
1326 .proc_handler
= proc_dointvec
,
1330 .procname
= "min_unmapped_ratio",
1331 .data
= &sysctl_min_unmapped_ratio
,
1332 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1334 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1336 .extra2
= &one_hundred
,
1339 .procname
= "min_slab_ratio",
1340 .data
= &sysctl_min_slab_ratio
,
1341 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1343 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1345 .extra2
= &one_hundred
,
1350 .procname
= "stat_interval",
1351 .data
= &sysctl_stat_interval
,
1352 .maxlen
= sizeof(sysctl_stat_interval
),
1354 .proc_handler
= proc_dointvec_jiffies
,
1359 .procname
= "mmap_min_addr",
1360 .data
= &dac_mmap_min_addr
,
1361 .maxlen
= sizeof(unsigned long),
1363 .proc_handler
= mmap_min_addr_handler
,
1368 .procname
= "numa_zonelist_order",
1369 .data
= &numa_zonelist_order
,
1370 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1372 .proc_handler
= numa_zonelist_order_handler
,
1375 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1376 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1378 .procname
= "vdso_enabled",
1379 .data
= &vdso_enabled
,
1380 .maxlen
= sizeof(vdso_enabled
),
1382 .proc_handler
= proc_dointvec
,
1386 #ifdef CONFIG_HIGHMEM
1388 .procname
= "highmem_is_dirtyable",
1389 .data
= &vm_highmem_is_dirtyable
,
1390 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1392 .proc_handler
= proc_dointvec_minmax
,
1398 .procname
= "scan_unevictable_pages",
1399 .data
= &scan_unevictable_pages
,
1400 .maxlen
= sizeof(scan_unevictable_pages
),
1402 .proc_handler
= scan_unevictable_handler
,
1404 #ifdef CONFIG_MEMORY_FAILURE
1406 .procname
= "memory_failure_early_kill",
1407 .data
= &sysctl_memory_failure_early_kill
,
1408 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1410 .proc_handler
= proc_dointvec_minmax
,
1415 .procname
= "memory_failure_recovery",
1416 .data
= &sysctl_memory_failure_recovery
,
1417 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1419 .proc_handler
= proc_dointvec_minmax
,
1427 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1428 static struct ctl_table binfmt_misc_table
[] = {
1433 static struct ctl_table fs_table
[] = {
1435 .procname
= "inode-nr",
1436 .data
= &inodes_stat
,
1437 .maxlen
= 2*sizeof(int),
1439 .proc_handler
= proc_nr_inodes
,
1442 .procname
= "inode-state",
1443 .data
= &inodes_stat
,
1444 .maxlen
= 7*sizeof(int),
1446 .proc_handler
= proc_nr_inodes
,
1449 .procname
= "file-nr",
1450 .data
= &files_stat
,
1451 .maxlen
= sizeof(files_stat
),
1453 .proc_handler
= proc_nr_files
,
1456 .procname
= "file-max",
1457 .data
= &files_stat
.max_files
,
1458 .maxlen
= sizeof(files_stat
.max_files
),
1460 .proc_handler
= proc_doulongvec_minmax
,
1463 .procname
= "nr_open",
1464 .data
= &sysctl_nr_open
,
1465 .maxlen
= sizeof(int),
1467 .proc_handler
= proc_dointvec_minmax
,
1468 .extra1
= &sysctl_nr_open_min
,
1469 .extra2
= &sysctl_nr_open_max
,
1472 .procname
= "dentry-state",
1473 .data
= &dentry_stat
,
1474 .maxlen
= 6*sizeof(int),
1476 .proc_handler
= proc_nr_dentry
,
1479 .procname
= "overflowuid",
1480 .data
= &fs_overflowuid
,
1481 .maxlen
= sizeof(int),
1483 .proc_handler
= proc_dointvec_minmax
,
1484 .extra1
= &minolduid
,
1485 .extra2
= &maxolduid
,
1488 .procname
= "overflowgid",
1489 .data
= &fs_overflowgid
,
1490 .maxlen
= sizeof(int),
1492 .proc_handler
= proc_dointvec_minmax
,
1493 .extra1
= &minolduid
,
1494 .extra2
= &maxolduid
,
1496 #ifdef CONFIG_FILE_LOCKING
1498 .procname
= "leases-enable",
1499 .data
= &leases_enable
,
1500 .maxlen
= sizeof(int),
1502 .proc_handler
= proc_dointvec
,
1505 #ifdef CONFIG_DNOTIFY
1507 .procname
= "dir-notify-enable",
1508 .data
= &dir_notify_enable
,
1509 .maxlen
= sizeof(int),
1511 .proc_handler
= proc_dointvec
,
1515 #ifdef CONFIG_FILE_LOCKING
1517 .procname
= "lease-break-time",
1518 .data
= &lease_break_time
,
1519 .maxlen
= sizeof(int),
1521 .proc_handler
= proc_dointvec
,
1526 .procname
= "aio-nr",
1528 .maxlen
= sizeof(aio_nr
),
1530 .proc_handler
= proc_doulongvec_minmax
,
1533 .procname
= "aio-max-nr",
1534 .data
= &aio_max_nr
,
1535 .maxlen
= sizeof(aio_max_nr
),
1537 .proc_handler
= proc_doulongvec_minmax
,
1539 #endif /* CONFIG_AIO */
1540 #ifdef CONFIG_INOTIFY_USER
1542 .procname
= "inotify",
1544 .child
= inotify_table
,
1549 .procname
= "epoll",
1551 .child
= epoll_table
,
1556 .procname
= "protected_symlinks",
1557 .data
= &sysctl_protected_symlinks
,
1558 .maxlen
= sizeof(int),
1560 .proc_handler
= proc_dointvec_minmax
,
1565 .procname
= "protected_hardlinks",
1566 .data
= &sysctl_protected_hardlinks
,
1567 .maxlen
= sizeof(int),
1569 .proc_handler
= proc_dointvec_minmax
,
1574 .procname
= "suid_dumpable",
1575 .data
= &suid_dumpable
,
1576 .maxlen
= sizeof(int),
1578 .proc_handler
= proc_dointvec_minmax_coredump
,
1582 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1584 .procname
= "binfmt_misc",
1586 .child
= binfmt_misc_table
,
1590 .procname
= "pipe-max-size",
1591 .data
= &pipe_max_size
,
1592 .maxlen
= sizeof(int),
1594 .proc_handler
= &pipe_proc_fn
,
1595 .extra1
= &pipe_min_size
,
1600 static struct ctl_table debug_table
[] = {
1601 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1603 .procname
= "exception-trace",
1604 .data
= &show_unhandled_signals
,
1605 .maxlen
= sizeof(int),
1607 .proc_handler
= proc_dointvec
1610 #if defined(CONFIG_OPTPROBES)
1612 .procname
= "kprobes-optimization",
1613 .data
= &sysctl_kprobes_optimization
,
1614 .maxlen
= sizeof(int),
1616 .proc_handler
= proc_kprobes_optimization_handler
,
1624 static struct ctl_table dev_table
[] = {
1628 int __init
sysctl_init(void)
1630 struct ctl_table_header
*hdr
;
1632 hdr
= register_sysctl_table(sysctl_base_table
);
1633 kmemleak_not_leak(hdr
);
1637 #endif /* CONFIG_SYSCTL */
1643 #ifdef CONFIG_PROC_SYSCTL
1645 static int _proc_do_string(void* data
, int maxlen
, int write
,
1646 void __user
*buffer
,
1647 size_t *lenp
, loff_t
*ppos
)
1653 if (!data
|| !maxlen
|| !*lenp
) {
1661 while (len
< *lenp
) {
1662 if (get_user(c
, p
++))
1664 if (c
== 0 || c
== '\n')
1670 if(copy_from_user(data
, buffer
, len
))
1672 ((char *) data
)[len
] = 0;
1690 if(copy_to_user(buffer
, data
, len
))
1693 if(put_user('\n', ((char __user
*) buffer
) + len
))
1704 * proc_dostring - read a string sysctl
1705 * @table: the sysctl table
1706 * @write: %TRUE if this is a write to the sysctl file
1707 * @buffer: the user buffer
1708 * @lenp: the size of the user buffer
1709 * @ppos: file position
1711 * Reads/writes a string from/to the user buffer. If the kernel
1712 * buffer provided is not large enough to hold the string, the
1713 * string is truncated. The copied string is %NULL-terminated.
1714 * If the string is being read by the user process, it is copied
1715 * and a newline '\n' is added. It is truncated if the buffer is
1718 * Returns 0 on success.
1720 int proc_dostring(struct ctl_table
*table
, int write
,
1721 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1723 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1724 buffer
, lenp
, ppos
);
1727 static size_t proc_skip_spaces(char **buf
)
1730 char *tmp
= skip_spaces(*buf
);
1736 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1746 #define TMPBUFLEN 22
1748 * proc_get_long - reads an ASCII formatted integer from a user buffer
1750 * @buf: a kernel buffer
1751 * @size: size of the kernel buffer
1752 * @val: this is where the number will be stored
1753 * @neg: set to %TRUE if number is negative
1754 * @perm_tr: a vector which contains the allowed trailers
1755 * @perm_tr_len: size of the perm_tr vector
1756 * @tr: pointer to store the trailer character
1758 * In case of success %0 is returned and @buf and @size are updated with
1759 * the amount of bytes read. If @tr is non-NULL and a trailing
1760 * character exists (size is non-zero after returning from this
1761 * function), @tr is updated with the trailing character.
1763 static int proc_get_long(char **buf
, size_t *size
,
1764 unsigned long *val
, bool *neg
,
1765 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1768 char *p
, tmp
[TMPBUFLEN
];
1774 if (len
> TMPBUFLEN
- 1)
1775 len
= TMPBUFLEN
- 1;
1777 memcpy(tmp
, *buf
, len
);
1781 if (*p
== '-' && *size
> 1) {
1789 *val
= simple_strtoul(p
, &p
, 0);
1793 /* We don't know if the next char is whitespace thus we may accept
1794 * invalid integers (e.g. 1234...a) or two integers instead of one
1795 * (e.g. 123...1). So lets not allow such large numbers. */
1796 if (len
== TMPBUFLEN
- 1)
1799 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1802 if (tr
&& (len
< *size
))
1812 * proc_put_long - converts an integer to a decimal ASCII formatted string
1814 * @buf: the user buffer
1815 * @size: the size of the user buffer
1816 * @val: the integer to be converted
1817 * @neg: sign of the number, %TRUE for negative
1819 * In case of success %0 is returned and @buf and @size are updated with
1820 * the amount of bytes written.
1822 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1826 char tmp
[TMPBUFLEN
], *p
= tmp
;
1828 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1832 if (copy_to_user(*buf
, tmp
, len
))
1840 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1843 char __user
**buffer
= (char __user
**)buf
;
1844 if (put_user(c
, *buffer
))
1846 (*size
)--, (*buffer
)++;
1852 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1854 int write
, void *data
)
1857 *valp
= *negp
? -*lvalp
: *lvalp
;
1862 *lvalp
= (unsigned long)-val
;
1865 *lvalp
= (unsigned long)val
;
1871 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1873 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1874 int write
, void __user
*buffer
,
1875 size_t *lenp
, loff_t
*ppos
,
1876 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1877 int write
, void *data
),
1880 int *i
, vleft
, first
= 1, err
= 0;
1881 unsigned long page
= 0;
1885 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1890 i
= (int *) tbl_data
;
1891 vleft
= table
->maxlen
/ sizeof(*i
);
1895 conv
= do_proc_dointvec_conv
;
1898 if (left
> PAGE_SIZE
- 1)
1899 left
= PAGE_SIZE
- 1;
1900 page
= __get_free_page(GFP_TEMPORARY
);
1901 kbuf
= (char *) page
;
1904 if (copy_from_user(kbuf
, buffer
, left
)) {
1911 for (; left
&& vleft
--; i
++, first
=0) {
1916 left
-= proc_skip_spaces(&kbuf
);
1920 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1922 sizeof(proc_wspace_sep
), NULL
);
1925 if (conv(&neg
, &lval
, i
, 1, data
)) {
1930 if (conv(&neg
, &lval
, i
, 0, data
)) {
1935 err
= proc_put_char(&buffer
, &left
, '\t');
1938 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1944 if (!write
&& !first
&& left
&& !err
)
1945 err
= proc_put_char(&buffer
, &left
, '\n');
1946 if (write
&& !err
&& left
)
1947 left
-= proc_skip_spaces(&kbuf
);
1952 return err
? : -EINVAL
;
1959 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1960 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1961 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1962 int write
, void *data
),
1965 return __do_proc_dointvec(table
->data
, table
, write
,
1966 buffer
, lenp
, ppos
, conv
, data
);
1970 * proc_dointvec - read a vector of integers
1971 * @table: the sysctl table
1972 * @write: %TRUE if this is a write to the sysctl file
1973 * @buffer: the user buffer
1974 * @lenp: the size of the user buffer
1975 * @ppos: file position
1977 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1978 * values from/to the user buffer, treated as an ASCII string.
1980 * Returns 0 on success.
1982 int proc_dointvec(struct ctl_table
*table
, int write
,
1983 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1985 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
1990 * Taint values can only be increased
1991 * This means we can safely use a temporary.
1993 static int proc_taint(struct ctl_table
*table
, int write
,
1994 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1997 unsigned long tmptaint
= get_taint();
2000 if (write
&& !capable(CAP_SYS_ADMIN
))
2005 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2011 * Poor man's atomic or. Not worth adding a primitive
2012 * to everyone's atomic.h for this
2015 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2016 if ((tmptaint
>> i
) & 1)
2024 #ifdef CONFIG_PRINTK
2025 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2026 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2028 if (write
&& !capable(CAP_SYS_ADMIN
))
2031 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2035 struct do_proc_dointvec_minmax_conv_param
{
2040 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2042 int write
, void *data
)
2044 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2046 int val
= *negp
? -*lvalp
: *lvalp
;
2047 if ((param
->min
&& *param
->min
> val
) ||
2048 (param
->max
&& *param
->max
< val
))
2055 *lvalp
= (unsigned long)-val
;
2058 *lvalp
= (unsigned long)val
;
2065 * proc_dointvec_minmax - read a vector of integers with min/max values
2066 * @table: the sysctl table
2067 * @write: %TRUE if this is a write to the sysctl file
2068 * @buffer: the user buffer
2069 * @lenp: the size of the user buffer
2070 * @ppos: file position
2072 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2073 * values from/to the user buffer, treated as an ASCII string.
2075 * This routine will ensure the values are within the range specified by
2076 * table->extra1 (min) and table->extra2 (max).
2078 * Returns 0 on success.
2080 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2081 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2083 struct do_proc_dointvec_minmax_conv_param param
= {
2084 .min
= (int *) table
->extra1
,
2085 .max
= (int *) table
->extra2
,
2087 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2088 do_proc_dointvec_minmax_conv
, ¶m
);
2091 static void validate_coredump_safety(void)
2093 #ifdef CONFIG_COREDUMP
2094 if (suid_dumpable
== SUID_DUMPABLE_SAFE
&&
2095 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2096 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2097 "suid_dumpable=2. Pipe handler or fully qualified "\
2098 "core dump path required.\n");
2103 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2104 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2106 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2108 validate_coredump_safety();
2112 #ifdef CONFIG_COREDUMP
2113 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2114 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2116 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2118 validate_coredump_safety();
2123 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2124 void __user
*buffer
,
2125 size_t *lenp
, loff_t
*ppos
,
2126 unsigned long convmul
,
2127 unsigned long convdiv
)
2129 unsigned long *i
, *min
, *max
;
2130 int vleft
, first
= 1, err
= 0;
2131 unsigned long page
= 0;
2135 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2140 i
= (unsigned long *) data
;
2141 min
= (unsigned long *) table
->extra1
;
2142 max
= (unsigned long *) table
->extra2
;
2143 vleft
= table
->maxlen
/ sizeof(unsigned long);
2147 if (left
> PAGE_SIZE
- 1)
2148 left
= PAGE_SIZE
- 1;
2149 page
= __get_free_page(GFP_TEMPORARY
);
2150 kbuf
= (char *) page
;
2153 if (copy_from_user(kbuf
, buffer
, left
)) {
2160 for (; left
&& vleft
--; i
++, first
= 0) {
2166 left
-= proc_skip_spaces(&kbuf
);
2168 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2170 sizeof(proc_wspace_sep
), NULL
);
2175 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2179 val
= convdiv
* (*i
) / convmul
;
2181 err
= proc_put_char(&buffer
, &left
, '\t');
2182 err
= proc_put_long(&buffer
, &left
, val
, false);
2188 if (!write
&& !first
&& left
&& !err
)
2189 err
= proc_put_char(&buffer
, &left
, '\n');
2191 left
-= proc_skip_spaces(&kbuf
);
2196 return err
? : -EINVAL
;
2203 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2204 void __user
*buffer
,
2205 size_t *lenp
, loff_t
*ppos
,
2206 unsigned long convmul
,
2207 unsigned long convdiv
)
2209 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2210 buffer
, lenp
, ppos
, convmul
, convdiv
);
2214 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2215 * @table: the sysctl table
2216 * @write: %TRUE if this is a write to the sysctl file
2217 * @buffer: the user buffer
2218 * @lenp: the size of the user buffer
2219 * @ppos: file position
2221 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2222 * values from/to the user buffer, treated as an ASCII string.
2224 * This routine will ensure the values are within the range specified by
2225 * table->extra1 (min) and table->extra2 (max).
2227 * Returns 0 on success.
2229 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2230 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2232 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2236 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2237 * @table: the sysctl table
2238 * @write: %TRUE if this is a write to the sysctl file
2239 * @buffer: the user buffer
2240 * @lenp: the size of the user buffer
2241 * @ppos: file position
2243 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2244 * values from/to the user buffer, treated as an ASCII string. The values
2245 * are treated as milliseconds, and converted to jiffies when they are stored.
2247 * This routine will ensure the values are within the range specified by
2248 * table->extra1 (min) and table->extra2 (max).
2250 * Returns 0 on success.
2252 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2253 void __user
*buffer
,
2254 size_t *lenp
, loff_t
*ppos
)
2256 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2257 lenp
, ppos
, HZ
, 1000l);
2261 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2263 int write
, void *data
)
2266 if (*lvalp
> LONG_MAX
/ HZ
)
2268 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2274 lval
= (unsigned long)-val
;
2277 lval
= (unsigned long)val
;
2284 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2286 int write
, void *data
)
2289 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2291 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2297 lval
= (unsigned long)-val
;
2300 lval
= (unsigned long)val
;
2302 *lvalp
= jiffies_to_clock_t(lval
);
2307 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2309 int write
, void *data
)
2312 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2318 lval
= (unsigned long)-val
;
2321 lval
= (unsigned long)val
;
2323 *lvalp
= jiffies_to_msecs(lval
);
2329 * proc_dointvec_jiffies - read a vector of integers as seconds
2330 * @table: the sysctl table
2331 * @write: %TRUE if this is a write to the sysctl file
2332 * @buffer: the user buffer
2333 * @lenp: the size of the user buffer
2334 * @ppos: file position
2336 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2337 * values from/to the user buffer, treated as an ASCII string.
2338 * The values read are assumed to be in seconds, and are converted into
2341 * Returns 0 on success.
2343 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2344 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2346 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2347 do_proc_dointvec_jiffies_conv
,NULL
);
2351 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2352 * @table: the sysctl table
2353 * @write: %TRUE if this is a write to the sysctl file
2354 * @buffer: the user buffer
2355 * @lenp: the size of the user buffer
2356 * @ppos: pointer to the file position
2358 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2359 * values from/to the user buffer, treated as an ASCII string.
2360 * The values read are assumed to be in 1/USER_HZ seconds, and
2361 * are converted into jiffies.
2363 * Returns 0 on success.
2365 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2366 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2368 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2369 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2373 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2374 * @table: the sysctl table
2375 * @write: %TRUE if this is a write to the sysctl file
2376 * @buffer: the user buffer
2377 * @lenp: the size of the user buffer
2378 * @ppos: file position
2379 * @ppos: the current position in the file
2381 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2382 * values from/to the user buffer, treated as an ASCII string.
2383 * The values read are assumed to be in 1/1000 seconds, and
2384 * are converted into jiffies.
2386 * Returns 0 on success.
2388 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2389 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2391 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2392 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2395 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2396 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2398 struct pid
*new_pid
;
2402 tmp
= pid_vnr(cad_pid
);
2404 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2405 lenp
, ppos
, NULL
, NULL
);
2409 new_pid
= find_get_pid(tmp
);
2413 put_pid(xchg(&cad_pid
, new_pid
));
2418 * proc_do_large_bitmap - read/write from/to a large bitmap
2419 * @table: the sysctl table
2420 * @write: %TRUE if this is a write to the sysctl file
2421 * @buffer: the user buffer
2422 * @lenp: the size of the user buffer
2423 * @ppos: file position
2425 * The bitmap is stored at table->data and the bitmap length (in bits)
2428 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2429 * large bitmaps may be represented in a compact manner. Writing into
2430 * the file will clear the bitmap then update it with the given input.
2432 * Returns 0 on success.
2434 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2435 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2439 size_t left
= *lenp
;
2440 unsigned long bitmap_len
= table
->maxlen
;
2441 unsigned long *bitmap
= (unsigned long *) table
->data
;
2442 unsigned long *tmp_bitmap
= NULL
;
2443 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2445 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2451 unsigned long page
= 0;
2454 if (left
> PAGE_SIZE
- 1)
2455 left
= PAGE_SIZE
- 1;
2457 page
= __get_free_page(GFP_TEMPORARY
);
2458 kbuf
= (char *) page
;
2461 if (copy_from_user(kbuf
, buffer
, left
)) {
2467 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2473 proc_skip_char(&kbuf
, &left
, '\n');
2474 while (!err
&& left
) {
2475 unsigned long val_a
, val_b
;
2478 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2482 if (val_a
>= bitmap_len
|| neg
) {
2494 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2495 &neg
, tr_b
, sizeof(tr_b
),
2499 if (val_b
>= bitmap_len
|| neg
||
2510 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2512 proc_skip_char(&kbuf
, &left
, '\n');
2516 unsigned long bit_a
, bit_b
= 0;
2519 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2520 if (bit_a
>= bitmap_len
)
2522 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2526 err
= proc_put_char(&buffer
, &left
, ',');
2530 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2533 if (bit_a
!= bit_b
) {
2534 err
= proc_put_char(&buffer
, &left
, '-');
2537 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2545 err
= proc_put_char(&buffer
, &left
, '\n');
2551 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2553 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2565 #else /* CONFIG_PROC_SYSCTL */
2567 int proc_dostring(struct ctl_table
*table
, int write
,
2568 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2573 int proc_dointvec(struct ctl_table
*table
, int write
,
2574 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2579 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2580 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2585 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2586 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2591 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2592 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2597 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2598 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2603 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2604 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2609 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2610 void __user
*buffer
,
2611 size_t *lenp
, loff_t
*ppos
)
2617 #endif /* CONFIG_PROC_SYSCTL */
2620 * No sense putting this after each symbol definition, twice,
2621 * exception granted :-)
2623 EXPORT_SYMBOL(proc_dointvec
);
2624 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2625 EXPORT_SYMBOL(proc_dointvec_minmax
);
2626 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2627 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2628 EXPORT_SYMBOL(proc_dostring
);
2629 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2630 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);