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_ns",
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_ms",
325 .data
= &sysctl_sched_time_avg
,
326 .maxlen
= sizeof(unsigned int),
328 .proc_handler
= proc_dointvec
,
331 .procname
= "sched_shares_window_ns",
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
= "protected_symlinks",
1502 .data
= &sysctl_protected_symlinks
,
1503 .maxlen
= sizeof(int),
1505 .proc_handler
= proc_dointvec_minmax
,
1510 .procname
= "protected_hardlinks",
1511 .data
= &sysctl_protected_hardlinks
,
1512 .maxlen
= sizeof(int),
1514 .proc_handler
= proc_dointvec_minmax
,
1519 .procname
= "suid_dumpable",
1520 .data
= &suid_dumpable
,
1521 .maxlen
= sizeof(int),
1523 .proc_handler
= proc_dointvec_minmax_coredump
,
1527 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1529 .procname
= "binfmt_misc",
1531 .child
= binfmt_misc_table
,
1535 .procname
= "pipe-max-size",
1536 .data
= &pipe_max_size
,
1537 .maxlen
= sizeof(int),
1539 .proc_handler
= &pipe_proc_fn
,
1540 .extra1
= &pipe_min_size
,
1545 static struct ctl_table debug_table
[] = {
1546 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1547 defined(CONFIG_S390) || defined(CONFIG_TILE) || defined(CONFIG_ARM64)
1549 .procname
= "exception-trace",
1550 .data
= &show_unhandled_signals
,
1551 .maxlen
= sizeof(int),
1553 .proc_handler
= proc_dointvec
1556 #if defined(CONFIG_OPTPROBES)
1558 .procname
= "kprobes-optimization",
1559 .data
= &sysctl_kprobes_optimization
,
1560 .maxlen
= sizeof(int),
1562 .proc_handler
= proc_kprobes_optimization_handler
,
1570 static struct ctl_table dev_table
[] = {
1574 int __init
sysctl_init(void)
1576 struct ctl_table_header
*hdr
;
1578 hdr
= register_sysctl_table(sysctl_base_table
);
1579 kmemleak_not_leak(hdr
);
1583 #endif /* CONFIG_SYSCTL */
1589 #ifdef CONFIG_PROC_SYSCTL
1591 static int _proc_do_string(void* data
, int maxlen
, int write
,
1592 void __user
*buffer
,
1593 size_t *lenp
, loff_t
*ppos
)
1599 if (!data
|| !maxlen
|| !*lenp
) {
1607 while (len
< *lenp
) {
1608 if (get_user(c
, p
++))
1610 if (c
== 0 || c
== '\n')
1616 if(copy_from_user(data
, buffer
, len
))
1618 ((char *) data
)[len
] = 0;
1636 if(copy_to_user(buffer
, data
, len
))
1639 if(put_user('\n', ((char __user
*) buffer
) + len
))
1650 * proc_dostring - read a string sysctl
1651 * @table: the sysctl table
1652 * @write: %TRUE if this is a write to the sysctl file
1653 * @buffer: the user buffer
1654 * @lenp: the size of the user buffer
1655 * @ppos: file position
1657 * Reads/writes a string from/to the user buffer. If the kernel
1658 * buffer provided is not large enough to hold the string, the
1659 * string is truncated. The copied string is %NULL-terminated.
1660 * If the string is being read by the user process, it is copied
1661 * and a newline '\n' is added. It is truncated if the buffer is
1664 * Returns 0 on success.
1666 int proc_dostring(struct ctl_table
*table
, int write
,
1667 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1669 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1670 buffer
, lenp
, ppos
);
1673 static size_t proc_skip_spaces(char **buf
)
1676 char *tmp
= skip_spaces(*buf
);
1682 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1692 #define TMPBUFLEN 22
1694 * proc_get_long - reads an ASCII formatted integer from a user buffer
1696 * @buf: a kernel buffer
1697 * @size: size of the kernel buffer
1698 * @val: this is where the number will be stored
1699 * @neg: set to %TRUE if number is negative
1700 * @perm_tr: a vector which contains the allowed trailers
1701 * @perm_tr_len: size of the perm_tr vector
1702 * @tr: pointer to store the trailer character
1704 * In case of success %0 is returned and @buf and @size are updated with
1705 * the amount of bytes read. If @tr is non-NULL and a trailing
1706 * character exists (size is non-zero after returning from this
1707 * function), @tr is updated with the trailing character.
1709 static int proc_get_long(char **buf
, size_t *size
,
1710 unsigned long *val
, bool *neg
,
1711 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1714 char *p
, tmp
[TMPBUFLEN
];
1720 if (len
> TMPBUFLEN
- 1)
1721 len
= TMPBUFLEN
- 1;
1723 memcpy(tmp
, *buf
, len
);
1727 if (*p
== '-' && *size
> 1) {
1735 *val
= simple_strtoul(p
, &p
, 0);
1739 /* We don't know if the next char is whitespace thus we may accept
1740 * invalid integers (e.g. 1234...a) or two integers instead of one
1741 * (e.g. 123...1). So lets not allow such large numbers. */
1742 if (len
== TMPBUFLEN
- 1)
1745 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1748 if (tr
&& (len
< *size
))
1758 * proc_put_long - converts an integer to a decimal ASCII formatted string
1760 * @buf: the user buffer
1761 * @size: the size of the user buffer
1762 * @val: the integer to be converted
1763 * @neg: sign of the number, %TRUE for negative
1765 * In case of success %0 is returned and @buf and @size are updated with
1766 * the amount of bytes written.
1768 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1772 char tmp
[TMPBUFLEN
], *p
= tmp
;
1774 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1778 if (copy_to_user(*buf
, tmp
, len
))
1786 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1789 char __user
**buffer
= (char __user
**)buf
;
1790 if (put_user(c
, *buffer
))
1792 (*size
)--, (*buffer
)++;
1798 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1800 int write
, void *data
)
1803 *valp
= *negp
? -*lvalp
: *lvalp
;
1808 *lvalp
= (unsigned long)-val
;
1811 *lvalp
= (unsigned long)val
;
1817 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1819 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1820 int write
, void __user
*buffer
,
1821 size_t *lenp
, loff_t
*ppos
,
1822 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1823 int write
, void *data
),
1826 int *i
, vleft
, first
= 1, err
= 0;
1827 unsigned long page
= 0;
1831 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1836 i
= (int *) tbl_data
;
1837 vleft
= table
->maxlen
/ sizeof(*i
);
1841 conv
= do_proc_dointvec_conv
;
1844 if (left
> PAGE_SIZE
- 1)
1845 left
= PAGE_SIZE
- 1;
1846 page
= __get_free_page(GFP_TEMPORARY
);
1847 kbuf
= (char *) page
;
1850 if (copy_from_user(kbuf
, buffer
, left
)) {
1857 for (; left
&& vleft
--; i
++, first
=0) {
1862 left
-= proc_skip_spaces(&kbuf
);
1866 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1868 sizeof(proc_wspace_sep
), NULL
);
1871 if (conv(&neg
, &lval
, i
, 1, data
)) {
1876 if (conv(&neg
, &lval
, i
, 0, data
)) {
1881 err
= proc_put_char(&buffer
, &left
, '\t');
1884 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1890 if (!write
&& !first
&& left
&& !err
)
1891 err
= proc_put_char(&buffer
, &left
, '\n');
1892 if (write
&& !err
&& left
)
1893 left
-= proc_skip_spaces(&kbuf
);
1898 return err
? : -EINVAL
;
1905 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1906 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1907 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1908 int write
, void *data
),
1911 return __do_proc_dointvec(table
->data
, table
, write
,
1912 buffer
, lenp
, ppos
, conv
, data
);
1916 * proc_dointvec - read a vector of integers
1917 * @table: the sysctl table
1918 * @write: %TRUE if this is a write to the sysctl file
1919 * @buffer: the user buffer
1920 * @lenp: the size of the user buffer
1921 * @ppos: file position
1923 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1924 * values from/to the user buffer, treated as an ASCII string.
1926 * Returns 0 on success.
1928 int proc_dointvec(struct ctl_table
*table
, int write
,
1929 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1931 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
1936 * Taint values can only be increased
1937 * This means we can safely use a temporary.
1939 static int proc_taint(struct ctl_table
*table
, int write
,
1940 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1943 unsigned long tmptaint
= get_taint();
1946 if (write
&& !capable(CAP_SYS_ADMIN
))
1951 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
1957 * Poor man's atomic or. Not worth adding a primitive
1958 * to everyone's atomic.h for this
1961 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
1962 if ((tmptaint
>> i
) & 1)
1970 #ifdef CONFIG_PRINTK
1971 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
1972 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1974 if (write
&& !capable(CAP_SYS_ADMIN
))
1977 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
1981 struct do_proc_dointvec_minmax_conv_param
{
1986 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
1988 int write
, void *data
)
1990 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1992 int val
= *negp
? -*lvalp
: *lvalp
;
1993 if ((param
->min
&& *param
->min
> val
) ||
1994 (param
->max
&& *param
->max
< val
))
2001 *lvalp
= (unsigned long)-val
;
2004 *lvalp
= (unsigned long)val
;
2011 * proc_dointvec_minmax - read a vector of integers with min/max values
2012 * @table: the sysctl table
2013 * @write: %TRUE if this is a write to the sysctl file
2014 * @buffer: the user buffer
2015 * @lenp: the size of the user buffer
2016 * @ppos: file position
2018 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2019 * values from/to the user buffer, treated as an ASCII string.
2021 * This routine will ensure the values are within the range specified by
2022 * table->extra1 (min) and table->extra2 (max).
2024 * Returns 0 on success.
2026 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2027 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2029 struct do_proc_dointvec_minmax_conv_param param
= {
2030 .min
= (int *) table
->extra1
,
2031 .max
= (int *) table
->extra2
,
2033 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2034 do_proc_dointvec_minmax_conv
, ¶m
);
2037 static void validate_coredump_safety(void)
2039 if (suid_dumpable
== SUID_DUMPABLE_SAFE
&&
2040 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2041 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2042 "suid_dumpable=2. Pipe handler or fully qualified "\
2043 "core dump path required.\n");
2047 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2048 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2050 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2052 validate_coredump_safety();
2056 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2057 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2059 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2061 validate_coredump_safety();
2065 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2066 void __user
*buffer
,
2067 size_t *lenp
, loff_t
*ppos
,
2068 unsigned long convmul
,
2069 unsigned long convdiv
)
2071 unsigned long *i
, *min
, *max
;
2072 int vleft
, first
= 1, err
= 0;
2073 unsigned long page
= 0;
2077 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2082 i
= (unsigned long *) data
;
2083 min
= (unsigned long *) table
->extra1
;
2084 max
= (unsigned long *) table
->extra2
;
2085 vleft
= table
->maxlen
/ sizeof(unsigned long);
2089 if (left
> PAGE_SIZE
- 1)
2090 left
= PAGE_SIZE
- 1;
2091 page
= __get_free_page(GFP_TEMPORARY
);
2092 kbuf
= (char *) page
;
2095 if (copy_from_user(kbuf
, buffer
, left
)) {
2102 for (; left
&& vleft
--; i
++, first
= 0) {
2108 left
-= proc_skip_spaces(&kbuf
);
2110 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2112 sizeof(proc_wspace_sep
), NULL
);
2117 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2121 val
= convdiv
* (*i
) / convmul
;
2123 err
= proc_put_char(&buffer
, &left
, '\t');
2124 err
= proc_put_long(&buffer
, &left
, val
, false);
2130 if (!write
&& !first
&& left
&& !err
)
2131 err
= proc_put_char(&buffer
, &left
, '\n');
2133 left
-= proc_skip_spaces(&kbuf
);
2138 return err
? : -EINVAL
;
2145 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2146 void __user
*buffer
,
2147 size_t *lenp
, loff_t
*ppos
,
2148 unsigned long convmul
,
2149 unsigned long convdiv
)
2151 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2152 buffer
, lenp
, ppos
, convmul
, convdiv
);
2156 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2157 * @table: the sysctl table
2158 * @write: %TRUE if this is a write to the sysctl file
2159 * @buffer: the user buffer
2160 * @lenp: the size of the user buffer
2161 * @ppos: file position
2163 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2164 * values from/to the user buffer, treated as an ASCII string.
2166 * This routine will ensure the values are within the range specified by
2167 * table->extra1 (min) and table->extra2 (max).
2169 * Returns 0 on success.
2171 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2172 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2174 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2178 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2179 * @table: the sysctl table
2180 * @write: %TRUE if this is a write to the sysctl file
2181 * @buffer: the user buffer
2182 * @lenp: the size of the user buffer
2183 * @ppos: file position
2185 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2186 * values from/to the user buffer, treated as an ASCII string. The values
2187 * are treated as milliseconds, and converted to jiffies when they are stored.
2189 * This routine will ensure the values are within the range specified by
2190 * table->extra1 (min) and table->extra2 (max).
2192 * Returns 0 on success.
2194 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2195 void __user
*buffer
,
2196 size_t *lenp
, loff_t
*ppos
)
2198 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2199 lenp
, ppos
, HZ
, 1000l);
2203 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2205 int write
, void *data
)
2208 if (*lvalp
> LONG_MAX
/ HZ
)
2210 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2216 lval
= (unsigned long)-val
;
2219 lval
= (unsigned long)val
;
2226 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2228 int write
, void *data
)
2231 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2233 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2239 lval
= (unsigned long)-val
;
2242 lval
= (unsigned long)val
;
2244 *lvalp
= jiffies_to_clock_t(lval
);
2249 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2251 int write
, void *data
)
2254 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2260 lval
= (unsigned long)-val
;
2263 lval
= (unsigned long)val
;
2265 *lvalp
= jiffies_to_msecs(lval
);
2271 * proc_dointvec_jiffies - read a vector of integers as seconds
2272 * @table: the sysctl table
2273 * @write: %TRUE if this is a write to the sysctl file
2274 * @buffer: the user buffer
2275 * @lenp: the size of the user buffer
2276 * @ppos: file position
2278 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2279 * values from/to the user buffer, treated as an ASCII string.
2280 * The values read are assumed to be in seconds, and are converted into
2283 * Returns 0 on success.
2285 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2286 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2288 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2289 do_proc_dointvec_jiffies_conv
,NULL
);
2293 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2294 * @table: the sysctl table
2295 * @write: %TRUE if this is a write to the sysctl file
2296 * @buffer: the user buffer
2297 * @lenp: the size of the user buffer
2298 * @ppos: pointer to the file position
2300 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2301 * values from/to the user buffer, treated as an ASCII string.
2302 * The values read are assumed to be in 1/USER_HZ seconds, and
2303 * are converted into jiffies.
2305 * Returns 0 on success.
2307 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2308 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2310 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2311 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2315 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2316 * @table: the sysctl table
2317 * @write: %TRUE if this is a write to the sysctl file
2318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2321 * @ppos: the current position in the file
2323 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2324 * values from/to the user buffer, treated as an ASCII string.
2325 * The values read are assumed to be in 1/1000 seconds, and
2326 * are converted into jiffies.
2328 * Returns 0 on success.
2330 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2331 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2333 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2334 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2337 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2338 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2340 struct pid
*new_pid
;
2344 tmp
= pid_vnr(cad_pid
);
2346 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2347 lenp
, ppos
, NULL
, NULL
);
2351 new_pid
= find_get_pid(tmp
);
2355 put_pid(xchg(&cad_pid
, new_pid
));
2360 * proc_do_large_bitmap - read/write from/to a large bitmap
2361 * @table: the sysctl table
2362 * @write: %TRUE if this is a write to the sysctl file
2363 * @buffer: the user buffer
2364 * @lenp: the size of the user buffer
2365 * @ppos: file position
2367 * The bitmap is stored at table->data and the bitmap length (in bits)
2370 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2371 * large bitmaps may be represented in a compact manner. Writing into
2372 * the file will clear the bitmap then update it with the given input.
2374 * Returns 0 on success.
2376 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2377 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2381 size_t left
= *lenp
;
2382 unsigned long bitmap_len
= table
->maxlen
;
2383 unsigned long *bitmap
= (unsigned long *) table
->data
;
2384 unsigned long *tmp_bitmap
= NULL
;
2385 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2387 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2393 unsigned long page
= 0;
2396 if (left
> PAGE_SIZE
- 1)
2397 left
= PAGE_SIZE
- 1;
2399 page
= __get_free_page(GFP_TEMPORARY
);
2400 kbuf
= (char *) page
;
2403 if (copy_from_user(kbuf
, buffer
, left
)) {
2409 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2415 proc_skip_char(&kbuf
, &left
, '\n');
2416 while (!err
&& left
) {
2417 unsigned long val_a
, val_b
;
2420 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2424 if (val_a
>= bitmap_len
|| neg
) {
2436 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2437 &neg
, tr_b
, sizeof(tr_b
),
2441 if (val_b
>= bitmap_len
|| neg
||
2452 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2454 proc_skip_char(&kbuf
, &left
, '\n');
2458 unsigned long bit_a
, bit_b
= 0;
2461 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2462 if (bit_a
>= bitmap_len
)
2464 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2468 err
= proc_put_char(&buffer
, &left
, ',');
2472 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2475 if (bit_a
!= bit_b
) {
2476 err
= proc_put_char(&buffer
, &left
, '-');
2479 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2487 err
= proc_put_char(&buffer
, &left
, '\n');
2493 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2495 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2507 #else /* CONFIG_PROC_SYSCTL */
2509 int proc_dostring(struct ctl_table
*table
, int write
,
2510 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2515 int proc_dointvec(struct ctl_table
*table
, int write
,
2516 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2521 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2522 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2527 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2528 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2533 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2534 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2539 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2540 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2545 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2546 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2551 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2552 void __user
*buffer
,
2553 size_t *lenp
, loff_t
*ppos
)
2559 #endif /* CONFIG_PROC_SYSCTL */
2562 * No sense putting this after each symbol definition, twice,
2563 * exception granted :-)
2565 EXPORT_SYMBOL(proc_dointvec
);
2566 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2567 EXPORT_SYMBOL(proc_dointvec_minmax
);
2568 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2569 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2570 EXPORT_SYMBOL(proc_dostring
);
2571 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2572 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);