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>
65 #include <asm/uaccess.h>
66 #include <asm/processor.h>
70 #include <asm/stacktrace.h>
74 #include <asm/setup.h>
76 #ifdef CONFIG_BSD_PROCESS_ACCT
77 #include <linux/acct.h>
79 #ifdef CONFIG_RT_MUTEXES
80 #include <linux/rtmutex.h>
82 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
83 #include <linux/lockdep.h>
85 #ifdef CONFIG_CHR_DEV_SG
89 #ifdef CONFIG_LOCKUP_DETECTOR
90 #include <linux/nmi.h>
94 #if defined(CONFIG_SYSCTL)
96 /* External variables not in a header file. */
97 extern int sysctl_overcommit_memory
;
98 extern int sysctl_overcommit_ratio
;
99 extern int max_threads
;
100 extern int core_uses_pid
;
101 extern int suid_dumpable
;
102 extern char core_pattern
[];
103 extern unsigned int core_pipe_limit
;
105 extern int min_free_kbytes
;
106 extern int pid_max_min
, pid_max_max
;
107 extern int sysctl_drop_caches
;
108 extern int percpu_pagelist_fraction
;
109 extern int compat_log
;
110 extern int latencytop_enabled
;
111 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
113 extern int sysctl_nr_trim_pages
;
116 extern int blk_iopoll_enabled
;
119 /* Constants used for minimum and maximum */
120 #ifdef CONFIG_LOCKUP_DETECTOR
121 static int sixty
= 60;
122 static int neg_one
= -1;
126 static int __maybe_unused one
= 1;
127 static int __maybe_unused two
= 2;
128 static int __maybe_unused three
= 3;
129 static unsigned long one_ul
= 1;
130 static int one_hundred
= 100;
132 static int ten_thousand
= 10000;
135 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
136 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
138 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
139 static int maxolduid
= 65535;
140 static int minolduid
;
141 static int min_percpu_pagelist_fract
= 8;
143 static int ngroups_max
= NGROUPS_MAX
;
144 static const int cap_last_cap
= CAP_LAST_CAP
;
146 #ifdef CONFIG_INOTIFY_USER
147 #include <linux/inotify.h>
152 #ifdef CONFIG_SPARC64
153 extern int sysctl_tsb_ratio
;
157 extern int pwrsw_enabled
;
158 extern int unaligned_enabled
;
162 extern int no_unaligned_warning
;
163 extern int unaligned_dump_stack
;
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
168 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
169 static int proc_taint(struct ctl_table
*table
, int write
,
170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
174 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
175 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
178 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
179 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
180 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
181 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
183 #ifdef CONFIG_MAGIC_SYSRQ
184 /* Note: sysrq code uses it's own private copy */
185 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
187 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
188 void __user
*buffer
, size_t *lenp
,
193 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
198 sysrq_toggle_support(__sysrq_enabled
);
205 static struct ctl_table kern_table
[];
206 static struct ctl_table vm_table
[];
207 static struct ctl_table fs_table
[];
208 static struct ctl_table debug_table
[];
209 static struct ctl_table dev_table
[];
210 extern struct ctl_table random_table
[];
212 extern struct ctl_table epoll_table
[];
215 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
216 int sysctl_legacy_va_layout
;
219 /* The default sysctl tables: */
221 static struct ctl_table sysctl_base_table
[] = {
223 .procname
= "kernel",
240 .child
= debug_table
,
250 #ifdef CONFIG_SCHED_DEBUG
251 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
252 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
253 static int min_wakeup_granularity_ns
; /* 0 usecs */
254 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
255 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
256 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
259 #ifdef CONFIG_COMPACTION
260 static int min_extfrag_threshold
;
261 static int max_extfrag_threshold
= 1000;
264 static struct ctl_table kern_table
[] = {
266 .procname
= "sched_child_runs_first",
267 .data
= &sysctl_sched_child_runs_first
,
268 .maxlen
= sizeof(unsigned int),
270 .proc_handler
= proc_dointvec
,
272 #ifdef CONFIG_SCHED_DEBUG
274 .procname
= "sched_min_granularity_ns",
275 .data
= &sysctl_sched_min_granularity
,
276 .maxlen
= sizeof(unsigned int),
278 .proc_handler
= sched_proc_update_handler
,
279 .extra1
= &min_sched_granularity_ns
,
280 .extra2
= &max_sched_granularity_ns
,
283 .procname
= "sched_latency_ns",
284 .data
= &sysctl_sched_latency
,
285 .maxlen
= sizeof(unsigned int),
287 .proc_handler
= sched_proc_update_handler
,
288 .extra1
= &min_sched_granularity_ns
,
289 .extra2
= &max_sched_granularity_ns
,
292 .procname
= "sched_wakeup_granularity_ns",
293 .data
= &sysctl_sched_wakeup_granularity
,
294 .maxlen
= sizeof(unsigned int),
296 .proc_handler
= sched_proc_update_handler
,
297 .extra1
= &min_wakeup_granularity_ns
,
298 .extra2
= &max_wakeup_granularity_ns
,
301 .procname
= "sched_tunable_scaling",
302 .data
= &sysctl_sched_tunable_scaling
,
303 .maxlen
= sizeof(enum sched_tunable_scaling
),
305 .proc_handler
= sched_proc_update_handler
,
306 .extra1
= &min_sched_tunable_scaling
,
307 .extra2
= &max_sched_tunable_scaling
,
310 .procname
= "sched_migration_cost",
311 .data
= &sysctl_sched_migration_cost
,
312 .maxlen
= sizeof(unsigned int),
314 .proc_handler
= proc_dointvec
,
317 .procname
= "sched_nr_migrate",
318 .data
= &sysctl_sched_nr_migrate
,
319 .maxlen
= sizeof(unsigned int),
321 .proc_handler
= proc_dointvec
,
324 .procname
= "sched_time_avg",
325 .data
= &sysctl_sched_time_avg
,
326 .maxlen
= sizeof(unsigned int),
328 .proc_handler
= proc_dointvec
,
331 .procname
= "sched_shares_window",
332 .data
= &sysctl_sched_shares_window
,
333 .maxlen
= sizeof(unsigned int),
335 .proc_handler
= proc_dointvec
,
338 .procname
= "timer_migration",
339 .data
= &sysctl_timer_migration
,
340 .maxlen
= sizeof(unsigned int),
342 .proc_handler
= proc_dointvec_minmax
,
348 .procname
= "sched_rt_period_us",
349 .data
= &sysctl_sched_rt_period
,
350 .maxlen
= sizeof(unsigned int),
352 .proc_handler
= sched_rt_handler
,
355 .procname
= "sched_rt_runtime_us",
356 .data
= &sysctl_sched_rt_runtime
,
357 .maxlen
= sizeof(int),
359 .proc_handler
= sched_rt_handler
,
361 #ifdef CONFIG_SCHED_AUTOGROUP
363 .procname
= "sched_autogroup_enabled",
364 .data
= &sysctl_sched_autogroup_enabled
,
365 .maxlen
= sizeof(unsigned int),
367 .proc_handler
= proc_dointvec_minmax
,
372 #ifdef CONFIG_CFS_BANDWIDTH
374 .procname
= "sched_cfs_bandwidth_slice_us",
375 .data
= &sysctl_sched_cfs_bandwidth_slice
,
376 .maxlen
= sizeof(unsigned int),
378 .proc_handler
= proc_dointvec_minmax
,
382 #ifdef CONFIG_PROVE_LOCKING
384 .procname
= "prove_locking",
385 .data
= &prove_locking
,
386 .maxlen
= sizeof(int),
388 .proc_handler
= proc_dointvec
,
391 #ifdef CONFIG_LOCK_STAT
393 .procname
= "lock_stat",
395 .maxlen
= sizeof(int),
397 .proc_handler
= proc_dointvec
,
402 .data
= &panic_timeout
,
403 .maxlen
= sizeof(int),
405 .proc_handler
= proc_dointvec
,
408 .procname
= "core_uses_pid",
409 .data
= &core_uses_pid
,
410 .maxlen
= sizeof(int),
412 .proc_handler
= proc_dointvec
,
415 .procname
= "core_pattern",
416 .data
= core_pattern
,
417 .maxlen
= CORENAME_MAX_SIZE
,
419 .proc_handler
= proc_dostring_coredump
,
422 .procname
= "core_pipe_limit",
423 .data
= &core_pipe_limit
,
424 .maxlen
= sizeof(unsigned int),
426 .proc_handler
= proc_dointvec
,
428 #ifdef CONFIG_PROC_SYSCTL
430 .procname
= "tainted",
431 .maxlen
= sizeof(long),
433 .proc_handler
= proc_taint
,
436 #ifdef CONFIG_LATENCYTOP
438 .procname
= "latencytop",
439 .data
= &latencytop_enabled
,
440 .maxlen
= sizeof(int),
442 .proc_handler
= proc_dointvec
,
445 #ifdef CONFIG_BLK_DEV_INITRD
447 .procname
= "real-root-dev",
448 .data
= &real_root_dev
,
449 .maxlen
= sizeof(int),
451 .proc_handler
= proc_dointvec
,
455 .procname
= "print-fatal-signals",
456 .data
= &print_fatal_signals
,
457 .maxlen
= sizeof(int),
459 .proc_handler
= proc_dointvec
,
463 .procname
= "reboot-cmd",
464 .data
= reboot_command
,
467 .proc_handler
= proc_dostring
,
470 .procname
= "stop-a",
471 .data
= &stop_a_enabled
,
472 .maxlen
= sizeof (int),
474 .proc_handler
= proc_dointvec
,
477 .procname
= "scons-poweroff",
478 .data
= &scons_pwroff
,
479 .maxlen
= sizeof (int),
481 .proc_handler
= proc_dointvec
,
484 #ifdef CONFIG_SPARC64
486 .procname
= "tsb-ratio",
487 .data
= &sysctl_tsb_ratio
,
488 .maxlen
= sizeof (int),
490 .proc_handler
= proc_dointvec
,
495 .procname
= "soft-power",
496 .data
= &pwrsw_enabled
,
497 .maxlen
= sizeof (int),
499 .proc_handler
= proc_dointvec
,
502 .procname
= "unaligned-trap",
503 .data
= &unaligned_enabled
,
504 .maxlen
= sizeof (int),
506 .proc_handler
= proc_dointvec
,
510 .procname
= "ctrl-alt-del",
512 .maxlen
= sizeof(int),
514 .proc_handler
= proc_dointvec
,
516 #ifdef CONFIG_FUNCTION_TRACER
518 .procname
= "ftrace_enabled",
519 .data
= &ftrace_enabled
,
520 .maxlen
= sizeof(int),
522 .proc_handler
= ftrace_enable_sysctl
,
525 #ifdef CONFIG_STACK_TRACER
527 .procname
= "stack_tracer_enabled",
528 .data
= &stack_tracer_enabled
,
529 .maxlen
= sizeof(int),
531 .proc_handler
= stack_trace_sysctl
,
534 #ifdef CONFIG_TRACING
536 .procname
= "ftrace_dump_on_oops",
537 .data
= &ftrace_dump_on_oops
,
538 .maxlen
= sizeof(int),
540 .proc_handler
= proc_dointvec
,
543 #ifdef CONFIG_MODULES
545 .procname
= "modprobe",
546 .data
= &modprobe_path
,
547 .maxlen
= KMOD_PATH_LEN
,
549 .proc_handler
= proc_dostring
,
552 .procname
= "modules_disabled",
553 .data
= &modules_disabled
,
554 .maxlen
= sizeof(int),
556 /* only handle a transition from default "0" to "1" */
557 .proc_handler
= proc_dointvec_minmax
,
562 #ifdef CONFIG_HOTPLUG
564 .procname
= "hotplug",
565 .data
= &uevent_helper
,
566 .maxlen
= UEVENT_HELPER_PATH_LEN
,
568 .proc_handler
= proc_dostring
,
571 #ifdef CONFIG_CHR_DEV_SG
573 .procname
= "sg-big-buff",
574 .data
= &sg_big_buff
,
575 .maxlen
= sizeof (int),
577 .proc_handler
= proc_dointvec
,
580 #ifdef CONFIG_BSD_PROCESS_ACCT
584 .maxlen
= 3*sizeof(int),
586 .proc_handler
= proc_dointvec
,
589 #ifdef CONFIG_MAGIC_SYSRQ
592 .data
= &__sysrq_enabled
,
593 .maxlen
= sizeof (int),
595 .proc_handler
= sysrq_sysctl_handler
,
598 #ifdef CONFIG_PROC_SYSCTL
600 .procname
= "cad_pid",
602 .maxlen
= sizeof (int),
604 .proc_handler
= proc_do_cad_pid
,
608 .procname
= "threads-max",
609 .data
= &max_threads
,
610 .maxlen
= sizeof(int),
612 .proc_handler
= proc_dointvec
,
615 .procname
= "random",
617 .child
= random_table
,
620 .procname
= "usermodehelper",
622 .child
= usermodehelper_table
,
625 .procname
= "overflowuid",
626 .data
= &overflowuid
,
627 .maxlen
= sizeof(int),
629 .proc_handler
= proc_dointvec_minmax
,
630 .extra1
= &minolduid
,
631 .extra2
= &maxolduid
,
634 .procname
= "overflowgid",
635 .data
= &overflowgid
,
636 .maxlen
= sizeof(int),
638 .proc_handler
= proc_dointvec_minmax
,
639 .extra1
= &minolduid
,
640 .extra2
= &maxolduid
,
643 #ifdef CONFIG_MATHEMU
645 .procname
= "ieee_emulation_warnings",
646 .data
= &sysctl_ieee_emulation_warnings
,
647 .maxlen
= sizeof(int),
649 .proc_handler
= proc_dointvec
,
653 .procname
= "userprocess_debug",
654 .data
= &show_unhandled_signals
,
655 .maxlen
= sizeof(int),
657 .proc_handler
= proc_dointvec
,
661 .procname
= "pid_max",
663 .maxlen
= sizeof (int),
665 .proc_handler
= proc_dointvec_minmax
,
666 .extra1
= &pid_max_min
,
667 .extra2
= &pid_max_max
,
670 .procname
= "panic_on_oops",
671 .data
= &panic_on_oops
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= proc_dointvec
,
676 #if defined CONFIG_PRINTK
678 .procname
= "printk",
679 .data
= &console_loglevel
,
680 .maxlen
= 4*sizeof(int),
682 .proc_handler
= proc_dointvec
,
685 .procname
= "printk_ratelimit",
686 .data
= &printk_ratelimit_state
.interval
,
687 .maxlen
= sizeof(int),
689 .proc_handler
= proc_dointvec_jiffies
,
692 .procname
= "printk_ratelimit_burst",
693 .data
= &printk_ratelimit_state
.burst
,
694 .maxlen
= sizeof(int),
696 .proc_handler
= proc_dointvec
,
699 .procname
= "printk_delay",
700 .data
= &printk_delay_msec
,
701 .maxlen
= sizeof(int),
703 .proc_handler
= proc_dointvec_minmax
,
705 .extra2
= &ten_thousand
,
708 .procname
= "dmesg_restrict",
709 .data
= &dmesg_restrict
,
710 .maxlen
= sizeof(int),
712 .proc_handler
= proc_dointvec_minmax_sysadmin
,
717 .procname
= "kptr_restrict",
718 .data
= &kptr_restrict
,
719 .maxlen
= sizeof(int),
721 .proc_handler
= proc_dointvec_minmax_sysadmin
,
727 .procname
= "ngroups_max",
728 .data
= &ngroups_max
,
729 .maxlen
= sizeof (int),
731 .proc_handler
= proc_dointvec
,
734 .procname
= "cap_last_cap",
735 .data
= (void *)&cap_last_cap
,
736 .maxlen
= sizeof(int),
738 .proc_handler
= proc_dointvec
,
740 #if defined(CONFIG_LOCKUP_DETECTOR)
742 .procname
= "watchdog",
743 .data
= &watchdog_enabled
,
744 .maxlen
= sizeof (int),
746 .proc_handler
= proc_dowatchdog
,
751 .procname
= "watchdog_thresh",
752 .data
= &watchdog_thresh
,
753 .maxlen
= sizeof(int),
755 .proc_handler
= proc_dowatchdog
,
760 .procname
= "softlockup_panic",
761 .data
= &softlockup_panic
,
762 .maxlen
= sizeof(int),
764 .proc_handler
= proc_dointvec_minmax
,
769 .procname
= "nmi_watchdog",
770 .data
= &watchdog_enabled
,
771 .maxlen
= sizeof (int),
773 .proc_handler
= proc_dowatchdog
,
778 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
780 .procname
= "unknown_nmi_panic",
781 .data
= &unknown_nmi_panic
,
782 .maxlen
= sizeof (int),
784 .proc_handler
= proc_dointvec
,
787 #if defined(CONFIG_X86)
789 .procname
= "panic_on_unrecovered_nmi",
790 .data
= &panic_on_unrecovered_nmi
,
791 .maxlen
= sizeof(int),
793 .proc_handler
= proc_dointvec
,
796 .procname
= "panic_on_io_nmi",
797 .data
= &panic_on_io_nmi
,
798 .maxlen
= sizeof(int),
800 .proc_handler
= proc_dointvec
,
802 #ifdef CONFIG_DEBUG_STACKOVERFLOW
804 .procname
= "panic_on_stackoverflow",
805 .data
= &sysctl_panic_on_stackoverflow
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= proc_dointvec
,
812 .procname
= "bootloader_type",
813 .data
= &bootloader_type
,
814 .maxlen
= sizeof (int),
816 .proc_handler
= proc_dointvec
,
819 .procname
= "bootloader_version",
820 .data
= &bootloader_version
,
821 .maxlen
= sizeof (int),
823 .proc_handler
= proc_dointvec
,
826 .procname
= "kstack_depth_to_print",
827 .data
= &kstack_depth_to_print
,
828 .maxlen
= sizeof(int),
830 .proc_handler
= proc_dointvec
,
833 .procname
= "io_delay_type",
834 .data
= &io_delay_type
,
835 .maxlen
= sizeof(int),
837 .proc_handler
= proc_dointvec
,
840 #if defined(CONFIG_MMU)
842 .procname
= "randomize_va_space",
843 .data
= &randomize_va_space
,
844 .maxlen
= sizeof(int),
846 .proc_handler
= proc_dointvec
,
849 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
851 .procname
= "spin_retry",
853 .maxlen
= sizeof (int),
855 .proc_handler
= proc_dointvec
,
858 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
860 .procname
= "acpi_video_flags",
861 .data
= &acpi_realmode_flags
,
862 .maxlen
= sizeof (unsigned long),
864 .proc_handler
= proc_doulongvec_minmax
,
869 .procname
= "ignore-unaligned-usertrap",
870 .data
= &no_unaligned_warning
,
871 .maxlen
= sizeof (int),
873 .proc_handler
= proc_dointvec
,
876 .procname
= "unaligned-dump-stack",
877 .data
= &unaligned_dump_stack
,
878 .maxlen
= sizeof (int),
880 .proc_handler
= proc_dointvec
,
883 #ifdef CONFIG_DETECT_HUNG_TASK
885 .procname
= "hung_task_panic",
886 .data
= &sysctl_hung_task_panic
,
887 .maxlen
= sizeof(int),
889 .proc_handler
= proc_dointvec_minmax
,
894 .procname
= "hung_task_check_count",
895 .data
= &sysctl_hung_task_check_count
,
896 .maxlen
= sizeof(unsigned long),
898 .proc_handler
= proc_doulongvec_minmax
,
901 .procname
= "hung_task_timeout_secs",
902 .data
= &sysctl_hung_task_timeout_secs
,
903 .maxlen
= sizeof(unsigned long),
905 .proc_handler
= proc_dohung_task_timeout_secs
,
908 .procname
= "hung_task_warnings",
909 .data
= &sysctl_hung_task_warnings
,
910 .maxlen
= sizeof(unsigned long),
912 .proc_handler
= proc_doulongvec_minmax
,
917 .procname
= "compat-log",
919 .maxlen
= sizeof (int),
921 .proc_handler
= proc_dointvec
,
924 #ifdef CONFIG_RT_MUTEXES
926 .procname
= "max_lock_depth",
927 .data
= &max_lock_depth
,
928 .maxlen
= sizeof(int),
930 .proc_handler
= proc_dointvec
,
934 .procname
= "poweroff_cmd",
935 .data
= &poweroff_cmd
,
936 .maxlen
= POWEROFF_CMD_PATH_LEN
,
938 .proc_handler
= proc_dostring
,
944 .child
= key_sysctls
,
947 #ifdef CONFIG_RCU_TORTURE_TEST
949 .procname
= "rcutorture_runnable",
950 .data
= &rcutorture_runnable
,
951 .maxlen
= sizeof(int),
953 .proc_handler
= proc_dointvec
,
956 #ifdef CONFIG_PERF_EVENTS
958 * User-space scripts rely on the existence of this file
959 * as a feature check for perf_events being enabled.
961 * So it's an ABI, do not remove!
964 .procname
= "perf_event_paranoid",
965 .data
= &sysctl_perf_event_paranoid
,
966 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
968 .proc_handler
= proc_dointvec
,
971 .procname
= "perf_event_mlock_kb",
972 .data
= &sysctl_perf_event_mlock
,
973 .maxlen
= sizeof(sysctl_perf_event_mlock
),
975 .proc_handler
= proc_dointvec
,
978 .procname
= "perf_event_max_sample_rate",
979 .data
= &sysctl_perf_event_sample_rate
,
980 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
982 .proc_handler
= perf_proc_update_handler
,
985 #ifdef CONFIG_KMEMCHECK
987 .procname
= "kmemcheck",
988 .data
= &kmemcheck_enabled
,
989 .maxlen
= sizeof(int),
991 .proc_handler
= proc_dointvec
,
996 .procname
= "blk_iopoll",
997 .data
= &blk_iopoll_enabled
,
998 .maxlen
= sizeof(int),
1000 .proc_handler
= proc_dointvec
,
1006 static struct ctl_table vm_table
[] = {
1008 .procname
= "overcommit_memory",
1009 .data
= &sysctl_overcommit_memory
,
1010 .maxlen
= sizeof(sysctl_overcommit_memory
),
1012 .proc_handler
= proc_dointvec_minmax
,
1017 .procname
= "panic_on_oom",
1018 .data
= &sysctl_panic_on_oom
,
1019 .maxlen
= sizeof(sysctl_panic_on_oom
),
1021 .proc_handler
= proc_dointvec_minmax
,
1026 .procname
= "oom_kill_allocating_task",
1027 .data
= &sysctl_oom_kill_allocating_task
,
1028 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1030 .proc_handler
= proc_dointvec
,
1033 .procname
= "oom_dump_tasks",
1034 .data
= &sysctl_oom_dump_tasks
,
1035 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1037 .proc_handler
= proc_dointvec
,
1040 .procname
= "overcommit_ratio",
1041 .data
= &sysctl_overcommit_ratio
,
1042 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1044 .proc_handler
= proc_dointvec
,
1047 .procname
= "page-cluster",
1048 .data
= &page_cluster
,
1049 .maxlen
= sizeof(int),
1051 .proc_handler
= proc_dointvec_minmax
,
1055 .procname
= "dirty_background_ratio",
1056 .data
= &dirty_background_ratio
,
1057 .maxlen
= sizeof(dirty_background_ratio
),
1059 .proc_handler
= dirty_background_ratio_handler
,
1061 .extra2
= &one_hundred
,
1064 .procname
= "dirty_background_bytes",
1065 .data
= &dirty_background_bytes
,
1066 .maxlen
= sizeof(dirty_background_bytes
),
1068 .proc_handler
= dirty_background_bytes_handler
,
1072 .procname
= "dirty_ratio",
1073 .data
= &vm_dirty_ratio
,
1074 .maxlen
= sizeof(vm_dirty_ratio
),
1076 .proc_handler
= dirty_ratio_handler
,
1078 .extra2
= &one_hundred
,
1081 .procname
= "dirty_bytes",
1082 .data
= &vm_dirty_bytes
,
1083 .maxlen
= sizeof(vm_dirty_bytes
),
1085 .proc_handler
= dirty_bytes_handler
,
1086 .extra1
= &dirty_bytes_min
,
1089 .procname
= "dirty_writeback_centisecs",
1090 .data
= &dirty_writeback_interval
,
1091 .maxlen
= sizeof(dirty_writeback_interval
),
1093 .proc_handler
= dirty_writeback_centisecs_handler
,
1096 .procname
= "dirty_expire_centisecs",
1097 .data
= &dirty_expire_interval
,
1098 .maxlen
= sizeof(dirty_expire_interval
),
1100 .proc_handler
= proc_dointvec_minmax
,
1104 .procname
= "nr_pdflush_threads",
1105 .mode
= 0444 /* read-only */,
1106 .proc_handler
= pdflush_proc_obsolete
,
1109 .procname
= "swappiness",
1110 .data
= &vm_swappiness
,
1111 .maxlen
= sizeof(vm_swappiness
),
1113 .proc_handler
= proc_dointvec_minmax
,
1115 .extra2
= &one_hundred
,
1117 #ifdef CONFIG_HUGETLB_PAGE
1119 .procname
= "nr_hugepages",
1121 .maxlen
= sizeof(unsigned long),
1123 .proc_handler
= hugetlb_sysctl_handler
,
1124 .extra1
= (void *)&hugetlb_zero
,
1125 .extra2
= (void *)&hugetlb_infinity
,
1129 .procname
= "nr_hugepages_mempolicy",
1131 .maxlen
= sizeof(unsigned long),
1133 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1134 .extra1
= (void *)&hugetlb_zero
,
1135 .extra2
= (void *)&hugetlb_infinity
,
1139 .procname
= "hugetlb_shm_group",
1140 .data
= &sysctl_hugetlb_shm_group
,
1141 .maxlen
= sizeof(gid_t
),
1143 .proc_handler
= proc_dointvec
,
1146 .procname
= "hugepages_treat_as_movable",
1147 .data
= &hugepages_treat_as_movable
,
1148 .maxlen
= sizeof(int),
1150 .proc_handler
= hugetlb_treat_movable_handler
,
1153 .procname
= "nr_overcommit_hugepages",
1155 .maxlen
= sizeof(unsigned long),
1157 .proc_handler
= hugetlb_overcommit_handler
,
1158 .extra1
= (void *)&hugetlb_zero
,
1159 .extra2
= (void *)&hugetlb_infinity
,
1163 .procname
= "lowmem_reserve_ratio",
1164 .data
= &sysctl_lowmem_reserve_ratio
,
1165 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1167 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1170 .procname
= "drop_caches",
1171 .data
= &sysctl_drop_caches
,
1172 .maxlen
= sizeof(int),
1174 .proc_handler
= drop_caches_sysctl_handler
,
1178 #ifdef CONFIG_COMPACTION
1180 .procname
= "compact_memory",
1181 .data
= &sysctl_compact_memory
,
1182 .maxlen
= sizeof(int),
1184 .proc_handler
= sysctl_compaction_handler
,
1187 .procname
= "extfrag_threshold",
1188 .data
= &sysctl_extfrag_threshold
,
1189 .maxlen
= sizeof(int),
1191 .proc_handler
= sysctl_extfrag_handler
,
1192 .extra1
= &min_extfrag_threshold
,
1193 .extra2
= &max_extfrag_threshold
,
1196 #endif /* CONFIG_COMPACTION */
1198 .procname
= "min_free_kbytes",
1199 .data
= &min_free_kbytes
,
1200 .maxlen
= sizeof(min_free_kbytes
),
1202 .proc_handler
= min_free_kbytes_sysctl_handler
,
1206 .procname
= "percpu_pagelist_fraction",
1207 .data
= &percpu_pagelist_fraction
,
1208 .maxlen
= sizeof(percpu_pagelist_fraction
),
1210 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1211 .extra1
= &min_percpu_pagelist_fract
,
1215 .procname
= "max_map_count",
1216 .data
= &sysctl_max_map_count
,
1217 .maxlen
= sizeof(sysctl_max_map_count
),
1219 .proc_handler
= proc_dointvec_minmax
,
1224 .procname
= "nr_trim_pages",
1225 .data
= &sysctl_nr_trim_pages
,
1226 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1228 .proc_handler
= proc_dointvec_minmax
,
1233 .procname
= "laptop_mode",
1234 .data
= &laptop_mode
,
1235 .maxlen
= sizeof(laptop_mode
),
1237 .proc_handler
= proc_dointvec_jiffies
,
1240 .procname
= "block_dump",
1241 .data
= &block_dump
,
1242 .maxlen
= sizeof(block_dump
),
1244 .proc_handler
= proc_dointvec
,
1248 .procname
= "vfs_cache_pressure",
1249 .data
= &sysctl_vfs_cache_pressure
,
1250 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1252 .proc_handler
= proc_dointvec
,
1255 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1257 .procname
= "legacy_va_layout",
1258 .data
= &sysctl_legacy_va_layout
,
1259 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1261 .proc_handler
= proc_dointvec
,
1267 .procname
= "zone_reclaim_mode",
1268 .data
= &zone_reclaim_mode
,
1269 .maxlen
= sizeof(zone_reclaim_mode
),
1271 .proc_handler
= proc_dointvec
,
1275 .procname
= "min_unmapped_ratio",
1276 .data
= &sysctl_min_unmapped_ratio
,
1277 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1279 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1281 .extra2
= &one_hundred
,
1284 .procname
= "min_slab_ratio",
1285 .data
= &sysctl_min_slab_ratio
,
1286 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1288 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1290 .extra2
= &one_hundred
,
1295 .procname
= "stat_interval",
1296 .data
= &sysctl_stat_interval
,
1297 .maxlen
= sizeof(sysctl_stat_interval
),
1299 .proc_handler
= proc_dointvec_jiffies
,
1304 .procname
= "mmap_min_addr",
1305 .data
= &dac_mmap_min_addr
,
1306 .maxlen
= sizeof(unsigned long),
1308 .proc_handler
= mmap_min_addr_handler
,
1313 .procname
= "numa_zonelist_order",
1314 .data
= &numa_zonelist_order
,
1315 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1317 .proc_handler
= numa_zonelist_order_handler
,
1320 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1321 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1323 .procname
= "vdso_enabled",
1324 .data
= &vdso_enabled
,
1325 .maxlen
= sizeof(vdso_enabled
),
1327 .proc_handler
= proc_dointvec
,
1331 #ifdef CONFIG_HIGHMEM
1333 .procname
= "highmem_is_dirtyable",
1334 .data
= &vm_highmem_is_dirtyable
,
1335 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1337 .proc_handler
= proc_dointvec_minmax
,
1343 .procname
= "scan_unevictable_pages",
1344 .data
= &scan_unevictable_pages
,
1345 .maxlen
= sizeof(scan_unevictable_pages
),
1347 .proc_handler
= scan_unevictable_handler
,
1349 #ifdef CONFIG_MEMORY_FAILURE
1351 .procname
= "memory_failure_early_kill",
1352 .data
= &sysctl_memory_failure_early_kill
,
1353 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1355 .proc_handler
= proc_dointvec_minmax
,
1360 .procname
= "memory_failure_recovery",
1361 .data
= &sysctl_memory_failure_recovery
,
1362 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1364 .proc_handler
= proc_dointvec_minmax
,
1372 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1373 static struct ctl_table binfmt_misc_table
[] = {
1378 static struct ctl_table fs_table
[] = {
1380 .procname
= "inode-nr",
1381 .data
= &inodes_stat
,
1382 .maxlen
= 2*sizeof(int),
1384 .proc_handler
= proc_nr_inodes
,
1387 .procname
= "inode-state",
1388 .data
= &inodes_stat
,
1389 .maxlen
= 7*sizeof(int),
1391 .proc_handler
= proc_nr_inodes
,
1394 .procname
= "file-nr",
1395 .data
= &files_stat
,
1396 .maxlen
= sizeof(files_stat
),
1398 .proc_handler
= proc_nr_files
,
1401 .procname
= "file-max",
1402 .data
= &files_stat
.max_files
,
1403 .maxlen
= sizeof(files_stat
.max_files
),
1405 .proc_handler
= proc_doulongvec_minmax
,
1408 .procname
= "nr_open",
1409 .data
= &sysctl_nr_open
,
1410 .maxlen
= sizeof(int),
1412 .proc_handler
= proc_dointvec_minmax
,
1413 .extra1
= &sysctl_nr_open_min
,
1414 .extra2
= &sysctl_nr_open_max
,
1417 .procname
= "dentry-state",
1418 .data
= &dentry_stat
,
1419 .maxlen
= 6*sizeof(int),
1421 .proc_handler
= proc_nr_dentry
,
1424 .procname
= "overflowuid",
1425 .data
= &fs_overflowuid
,
1426 .maxlen
= sizeof(int),
1428 .proc_handler
= proc_dointvec_minmax
,
1429 .extra1
= &minolduid
,
1430 .extra2
= &maxolduid
,
1433 .procname
= "overflowgid",
1434 .data
= &fs_overflowgid
,
1435 .maxlen
= sizeof(int),
1437 .proc_handler
= proc_dointvec_minmax
,
1438 .extra1
= &minolduid
,
1439 .extra2
= &maxolduid
,
1441 #ifdef CONFIG_FILE_LOCKING
1443 .procname
= "leases-enable",
1444 .data
= &leases_enable
,
1445 .maxlen
= sizeof(int),
1447 .proc_handler
= proc_dointvec
,
1450 #ifdef CONFIG_DNOTIFY
1452 .procname
= "dir-notify-enable",
1453 .data
= &dir_notify_enable
,
1454 .maxlen
= sizeof(int),
1456 .proc_handler
= proc_dointvec
,
1460 #ifdef CONFIG_FILE_LOCKING
1462 .procname
= "lease-break-time",
1463 .data
= &lease_break_time
,
1464 .maxlen
= sizeof(int),
1466 .proc_handler
= proc_dointvec
,
1471 .procname
= "aio-nr",
1473 .maxlen
= sizeof(aio_nr
),
1475 .proc_handler
= proc_doulongvec_minmax
,
1478 .procname
= "aio-max-nr",
1479 .data
= &aio_max_nr
,
1480 .maxlen
= sizeof(aio_max_nr
),
1482 .proc_handler
= proc_doulongvec_minmax
,
1484 #endif /* CONFIG_AIO */
1485 #ifdef CONFIG_INOTIFY_USER
1487 .procname
= "inotify",
1489 .child
= inotify_table
,
1494 .procname
= "epoll",
1496 .child
= epoll_table
,
1501 .procname
= "suid_dumpable",
1502 .data
= &suid_dumpable
,
1503 .maxlen
= sizeof(int),
1505 .proc_handler
= proc_dointvec_minmax_coredump
,
1509 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1511 .procname
= "binfmt_misc",
1513 .child
= binfmt_misc_table
,
1517 .procname
= "pipe-max-size",
1518 .data
= &pipe_max_size
,
1519 .maxlen
= sizeof(int),
1521 .proc_handler
= &pipe_proc_fn
,
1522 .extra1
= &pipe_min_size
,
1527 static struct ctl_table debug_table
[] = {
1528 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1529 defined(CONFIG_S390) || defined(CONFIG_TILE)
1531 .procname
= "exception-trace",
1532 .data
= &show_unhandled_signals
,
1533 .maxlen
= sizeof(int),
1535 .proc_handler
= proc_dointvec
1538 #if defined(CONFIG_OPTPROBES)
1540 .procname
= "kprobes-optimization",
1541 .data
= &sysctl_kprobes_optimization
,
1542 .maxlen
= sizeof(int),
1544 .proc_handler
= proc_kprobes_optimization_handler
,
1552 static struct ctl_table dev_table
[] = {
1556 int __init
sysctl_init(void)
1558 struct ctl_table_header
*hdr
;
1560 hdr
= register_sysctl_table(sysctl_base_table
);
1561 kmemleak_not_leak(hdr
);
1565 #endif /* CONFIG_SYSCTL */
1571 #ifdef CONFIG_PROC_SYSCTL
1573 static int _proc_do_string(void* data
, int maxlen
, int write
,
1574 void __user
*buffer
,
1575 size_t *lenp
, loff_t
*ppos
)
1581 if (!data
|| !maxlen
|| !*lenp
) {
1589 while (len
< *lenp
) {
1590 if (get_user(c
, p
++))
1592 if (c
== 0 || c
== '\n')
1598 if(copy_from_user(data
, buffer
, len
))
1600 ((char *) data
)[len
] = 0;
1618 if(copy_to_user(buffer
, data
, len
))
1621 if(put_user('\n', ((char __user
*) buffer
) + len
))
1632 * proc_dostring - read a string sysctl
1633 * @table: the sysctl table
1634 * @write: %TRUE if this is a write to the sysctl file
1635 * @buffer: the user buffer
1636 * @lenp: the size of the user buffer
1637 * @ppos: file position
1639 * Reads/writes a string from/to the user buffer. If the kernel
1640 * buffer provided is not large enough to hold the string, the
1641 * string is truncated. The copied string is %NULL-terminated.
1642 * If the string is being read by the user process, it is copied
1643 * and a newline '\n' is added. It is truncated if the buffer is
1646 * Returns 0 on success.
1648 int proc_dostring(struct ctl_table
*table
, int write
,
1649 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1651 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1652 buffer
, lenp
, ppos
);
1655 static size_t proc_skip_spaces(char **buf
)
1658 char *tmp
= skip_spaces(*buf
);
1664 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1674 #define TMPBUFLEN 22
1676 * proc_get_long - reads an ASCII formatted integer from a user buffer
1678 * @buf: a kernel buffer
1679 * @size: size of the kernel buffer
1680 * @val: this is where the number will be stored
1681 * @neg: set to %TRUE if number is negative
1682 * @perm_tr: a vector which contains the allowed trailers
1683 * @perm_tr_len: size of the perm_tr vector
1684 * @tr: pointer to store the trailer character
1686 * In case of success %0 is returned and @buf and @size are updated with
1687 * the amount of bytes read. If @tr is non-NULL and a trailing
1688 * character exists (size is non-zero after returning from this
1689 * function), @tr is updated with the trailing character.
1691 static int proc_get_long(char **buf
, size_t *size
,
1692 unsigned long *val
, bool *neg
,
1693 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1696 char *p
, tmp
[TMPBUFLEN
];
1702 if (len
> TMPBUFLEN
- 1)
1703 len
= TMPBUFLEN
- 1;
1705 memcpy(tmp
, *buf
, len
);
1709 if (*p
== '-' && *size
> 1) {
1717 *val
= simple_strtoul(p
, &p
, 0);
1721 /* We don't know if the next char is whitespace thus we may accept
1722 * invalid integers (e.g. 1234...a) or two integers instead of one
1723 * (e.g. 123...1). So lets not allow such large numbers. */
1724 if (len
== TMPBUFLEN
- 1)
1727 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1730 if (tr
&& (len
< *size
))
1740 * proc_put_long - converts an integer to a decimal ASCII formatted string
1742 * @buf: the user buffer
1743 * @size: the size of the user buffer
1744 * @val: the integer to be converted
1745 * @neg: sign of the number, %TRUE for negative
1747 * In case of success %0 is returned and @buf and @size are updated with
1748 * the amount of bytes written.
1750 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1754 char tmp
[TMPBUFLEN
], *p
= tmp
;
1756 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1760 if (copy_to_user(*buf
, tmp
, len
))
1768 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1771 char __user
**buffer
= (char __user
**)buf
;
1772 if (put_user(c
, *buffer
))
1774 (*size
)--, (*buffer
)++;
1780 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1782 int write
, void *data
)
1785 *valp
= *negp
? -*lvalp
: *lvalp
;
1790 *lvalp
= (unsigned long)-val
;
1793 *lvalp
= (unsigned long)val
;
1799 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1801 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1802 int write
, void __user
*buffer
,
1803 size_t *lenp
, loff_t
*ppos
,
1804 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1805 int write
, void *data
),
1808 int *i
, vleft
, first
= 1, err
= 0;
1809 unsigned long page
= 0;
1813 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1818 i
= (int *) tbl_data
;
1819 vleft
= table
->maxlen
/ sizeof(*i
);
1823 conv
= do_proc_dointvec_conv
;
1826 if (left
> PAGE_SIZE
- 1)
1827 left
= PAGE_SIZE
- 1;
1828 page
= __get_free_page(GFP_TEMPORARY
);
1829 kbuf
= (char *) page
;
1832 if (copy_from_user(kbuf
, buffer
, left
)) {
1839 for (; left
&& vleft
--; i
++, first
=0) {
1844 left
-= proc_skip_spaces(&kbuf
);
1848 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1850 sizeof(proc_wspace_sep
), NULL
);
1853 if (conv(&neg
, &lval
, i
, 1, data
)) {
1858 if (conv(&neg
, &lval
, i
, 0, data
)) {
1863 err
= proc_put_char(&buffer
, &left
, '\t');
1866 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1872 if (!write
&& !first
&& left
&& !err
)
1873 err
= proc_put_char(&buffer
, &left
, '\n');
1874 if (write
&& !err
&& left
)
1875 left
-= proc_skip_spaces(&kbuf
);
1880 return err
? : -EINVAL
;
1887 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1888 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1889 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1890 int write
, void *data
),
1893 return __do_proc_dointvec(table
->data
, table
, write
,
1894 buffer
, lenp
, ppos
, conv
, data
);
1898 * proc_dointvec - read a vector of integers
1899 * @table: the sysctl table
1900 * @write: %TRUE if this is a write to the sysctl file
1901 * @buffer: the user buffer
1902 * @lenp: the size of the user buffer
1903 * @ppos: file position
1905 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1906 * values from/to the user buffer, treated as an ASCII string.
1908 * Returns 0 on success.
1910 int proc_dointvec(struct ctl_table
*table
, int write
,
1911 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1913 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
1918 * Taint values can only be increased
1919 * This means we can safely use a temporary.
1921 static int proc_taint(struct ctl_table
*table
, int write
,
1922 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1925 unsigned long tmptaint
= get_taint();
1928 if (write
&& !capable(CAP_SYS_ADMIN
))
1933 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
1939 * Poor man's atomic or. Not worth adding a primitive
1940 * to everyone's atomic.h for this
1943 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
1944 if ((tmptaint
>> i
) & 1)
1952 #ifdef CONFIG_PRINTK
1953 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
1954 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1956 if (write
&& !capable(CAP_SYS_ADMIN
))
1959 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
1963 struct do_proc_dointvec_minmax_conv_param
{
1968 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
1970 int write
, void *data
)
1972 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1974 int val
= *negp
? -*lvalp
: *lvalp
;
1975 if ((param
->min
&& *param
->min
> val
) ||
1976 (param
->max
&& *param
->max
< val
))
1983 *lvalp
= (unsigned long)-val
;
1986 *lvalp
= (unsigned long)val
;
1993 * proc_dointvec_minmax - read a vector of integers with min/max values
1994 * @table: the sysctl table
1995 * @write: %TRUE if this is a write to the sysctl file
1996 * @buffer: the user buffer
1997 * @lenp: the size of the user buffer
1998 * @ppos: file position
2000 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2001 * values from/to the user buffer, treated as an ASCII string.
2003 * This routine will ensure the values are within the range specified by
2004 * table->extra1 (min) and table->extra2 (max).
2006 * Returns 0 on success.
2008 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2009 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2011 struct do_proc_dointvec_minmax_conv_param param
= {
2012 .min
= (int *) table
->extra1
,
2013 .max
= (int *) table
->extra2
,
2015 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2016 do_proc_dointvec_minmax_conv
, ¶m
);
2019 static void validate_coredump_safety(void)
2021 if (suid_dumpable
== SUID_DUMPABLE_SAFE
&&
2022 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2023 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2024 "suid_dumpable=2. Pipe handler or fully qualified "\
2025 "core dump path required.\n");
2029 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2030 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2032 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2034 validate_coredump_safety();
2038 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2039 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2041 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2043 validate_coredump_safety();
2047 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2048 void __user
*buffer
,
2049 size_t *lenp
, loff_t
*ppos
,
2050 unsigned long convmul
,
2051 unsigned long convdiv
)
2053 unsigned long *i
, *min
, *max
;
2054 int vleft
, first
= 1, err
= 0;
2055 unsigned long page
= 0;
2059 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2064 i
= (unsigned long *) data
;
2065 min
= (unsigned long *) table
->extra1
;
2066 max
= (unsigned long *) table
->extra2
;
2067 vleft
= table
->maxlen
/ sizeof(unsigned long);
2071 if (left
> PAGE_SIZE
- 1)
2072 left
= PAGE_SIZE
- 1;
2073 page
= __get_free_page(GFP_TEMPORARY
);
2074 kbuf
= (char *) page
;
2077 if (copy_from_user(kbuf
, buffer
, left
)) {
2084 for (; left
&& vleft
--; i
++, first
= 0) {
2090 left
-= proc_skip_spaces(&kbuf
);
2092 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2094 sizeof(proc_wspace_sep
), NULL
);
2099 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2103 val
= convdiv
* (*i
) / convmul
;
2105 err
= proc_put_char(&buffer
, &left
, '\t');
2106 err
= proc_put_long(&buffer
, &left
, val
, false);
2112 if (!write
&& !first
&& left
&& !err
)
2113 err
= proc_put_char(&buffer
, &left
, '\n');
2115 left
-= proc_skip_spaces(&kbuf
);
2120 return err
? : -EINVAL
;
2127 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2128 void __user
*buffer
,
2129 size_t *lenp
, loff_t
*ppos
,
2130 unsigned long convmul
,
2131 unsigned long convdiv
)
2133 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2134 buffer
, lenp
, ppos
, convmul
, convdiv
);
2138 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2139 * @table: the sysctl table
2140 * @write: %TRUE if this is a write to the sysctl file
2141 * @buffer: the user buffer
2142 * @lenp: the size of the user buffer
2143 * @ppos: file position
2145 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2146 * values from/to the user buffer, treated as an ASCII string.
2148 * This routine will ensure the values are within the range specified by
2149 * table->extra1 (min) and table->extra2 (max).
2151 * Returns 0 on success.
2153 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2154 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2156 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2160 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2161 * @table: the sysctl table
2162 * @write: %TRUE if this is a write to the sysctl file
2163 * @buffer: the user buffer
2164 * @lenp: the size of the user buffer
2165 * @ppos: file position
2167 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2168 * values from/to the user buffer, treated as an ASCII string. The values
2169 * are treated as milliseconds, and converted to jiffies when they are stored.
2171 * This routine will ensure the values are within the range specified by
2172 * table->extra1 (min) and table->extra2 (max).
2174 * Returns 0 on success.
2176 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2177 void __user
*buffer
,
2178 size_t *lenp
, loff_t
*ppos
)
2180 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2181 lenp
, ppos
, HZ
, 1000l);
2185 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2187 int write
, void *data
)
2190 if (*lvalp
> LONG_MAX
/ HZ
)
2192 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2198 lval
= (unsigned long)-val
;
2201 lval
= (unsigned long)val
;
2208 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2210 int write
, void *data
)
2213 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2215 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2221 lval
= (unsigned long)-val
;
2224 lval
= (unsigned long)val
;
2226 *lvalp
= jiffies_to_clock_t(lval
);
2231 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2233 int write
, void *data
)
2236 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2242 lval
= (unsigned long)-val
;
2245 lval
= (unsigned long)val
;
2247 *lvalp
= jiffies_to_msecs(lval
);
2253 * proc_dointvec_jiffies - read a vector of integers as seconds
2254 * @table: the sysctl table
2255 * @write: %TRUE if this is a write to the sysctl file
2256 * @buffer: the user buffer
2257 * @lenp: the size of the user buffer
2258 * @ppos: file position
2260 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2261 * values from/to the user buffer, treated as an ASCII string.
2262 * The values read are assumed to be in seconds, and are converted into
2265 * Returns 0 on success.
2267 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2268 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2270 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2271 do_proc_dointvec_jiffies_conv
,NULL
);
2275 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2276 * @table: the sysctl table
2277 * @write: %TRUE if this is a write to the sysctl file
2278 * @buffer: the user buffer
2279 * @lenp: the size of the user buffer
2280 * @ppos: pointer to the file position
2282 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2283 * values from/to the user buffer, treated as an ASCII string.
2284 * The values read are assumed to be in 1/USER_HZ seconds, and
2285 * are converted into jiffies.
2287 * Returns 0 on success.
2289 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2290 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2292 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2293 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2297 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2298 * @table: the sysctl table
2299 * @write: %TRUE if this is a write to the sysctl file
2300 * @buffer: the user buffer
2301 * @lenp: the size of the user buffer
2302 * @ppos: file position
2303 * @ppos: the current position in the file
2305 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2306 * values from/to the user buffer, treated as an ASCII string.
2307 * The values read are assumed to be in 1/1000 seconds, and
2308 * are converted into jiffies.
2310 * Returns 0 on success.
2312 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2313 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2315 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2316 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2319 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2320 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2322 struct pid
*new_pid
;
2326 tmp
= pid_vnr(cad_pid
);
2328 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2329 lenp
, ppos
, NULL
, NULL
);
2333 new_pid
= find_get_pid(tmp
);
2337 put_pid(xchg(&cad_pid
, new_pid
));
2342 * proc_do_large_bitmap - read/write from/to a large bitmap
2343 * @table: the sysctl table
2344 * @write: %TRUE if this is a write to the sysctl file
2345 * @buffer: the user buffer
2346 * @lenp: the size of the user buffer
2347 * @ppos: file position
2349 * The bitmap is stored at table->data and the bitmap length (in bits)
2352 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2353 * large bitmaps may be represented in a compact manner. Writing into
2354 * the file will clear the bitmap then update it with the given input.
2356 * Returns 0 on success.
2358 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2359 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2363 size_t left
= *lenp
;
2364 unsigned long bitmap_len
= table
->maxlen
;
2365 unsigned long *bitmap
= (unsigned long *) table
->data
;
2366 unsigned long *tmp_bitmap
= NULL
;
2367 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2369 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2375 unsigned long page
= 0;
2378 if (left
> PAGE_SIZE
- 1)
2379 left
= PAGE_SIZE
- 1;
2381 page
= __get_free_page(GFP_TEMPORARY
);
2382 kbuf
= (char *) page
;
2385 if (copy_from_user(kbuf
, buffer
, left
)) {
2391 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2397 proc_skip_char(&kbuf
, &left
, '\n');
2398 while (!err
&& left
) {
2399 unsigned long val_a
, val_b
;
2402 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2406 if (val_a
>= bitmap_len
|| neg
) {
2418 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2419 &neg
, tr_b
, sizeof(tr_b
),
2423 if (val_b
>= bitmap_len
|| neg
||
2434 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2436 proc_skip_char(&kbuf
, &left
, '\n');
2440 unsigned long bit_a
, bit_b
= 0;
2443 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2444 if (bit_a
>= bitmap_len
)
2446 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2450 err
= proc_put_char(&buffer
, &left
, ',');
2454 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2457 if (bit_a
!= bit_b
) {
2458 err
= proc_put_char(&buffer
, &left
, '-');
2461 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2469 err
= proc_put_char(&buffer
, &left
, '\n');
2475 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2477 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2489 #else /* CONFIG_PROC_SYSCTL */
2491 int proc_dostring(struct ctl_table
*table
, int write
,
2492 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2497 int proc_dointvec(struct ctl_table
*table
, int write
,
2498 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2503 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2504 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2509 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2510 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2515 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2516 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2521 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2522 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2527 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2528 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2533 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2534 void __user
*buffer
,
2535 size_t *lenp
, loff_t
*ppos
)
2541 #endif /* CONFIG_PROC_SYSCTL */
2544 * No sense putting this after each symbol definition, twice,
2545 * exception granted :-)
2547 EXPORT_SYMBOL(proc_dointvec
);
2548 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2549 EXPORT_SYMBOL(proc_dointvec_minmax
);
2550 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2551 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2552 EXPORT_SYMBOL(proc_dostring
);
2553 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2554 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);