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 suid_dumpable
;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid
;
103 extern char core_pattern
[];
104 extern unsigned int core_pipe_limit
;
107 extern int min_free_kbytes
;
108 extern int pid_max_min
, pid_max_max
;
109 extern int sysctl_drop_caches
;
110 extern int percpu_pagelist_fraction
;
111 extern int compat_log
;
112 extern int latencytop_enabled
;
113 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
115 extern int sysctl_nr_trim_pages
;
118 extern int blk_iopoll_enabled
;
121 /* Constants used for minimum and maximum */
122 #ifdef CONFIG_LOCKUP_DETECTOR
123 static int sixty
= 60;
124 static int neg_one
= -1;
128 static int __maybe_unused one
= 1;
129 static int __maybe_unused two
= 2;
130 static int __maybe_unused three
= 3;
131 static unsigned long one_ul
= 1;
132 static int one_hundred
= 100;
134 static int ten_thousand
= 10000;
137 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
140 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141 static int maxolduid
= 65535;
142 static int minolduid
;
143 static int min_percpu_pagelist_fract
= 8;
145 static int ngroups_max
= NGROUPS_MAX
;
146 static const int cap_last_cap
= CAP_LAST_CAP
;
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
154 #ifdef CONFIG_SPARC64
155 extern int sysctl_tsb_ratio
;
159 extern int pwrsw_enabled
;
160 extern int unaligned_enabled
;
164 extern int no_unaligned_warning
;
165 extern int unaligned_dump_stack
;
168 #ifdef CONFIG_PROC_SYSCTL
169 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
171 static int proc_taint(struct ctl_table
*table
, int write
,
172 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
176 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
177 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
180 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
181 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
182 #ifdef CONFIG_COREDUMP
183 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
184 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
187 #ifdef CONFIG_MAGIC_SYSRQ
188 /* Note: sysrq code uses it's own private copy */
189 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
191 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
192 void __user
*buffer
, size_t *lenp
,
197 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
202 sysrq_toggle_support(__sysrq_enabled
);
209 static struct ctl_table kern_table
[];
210 static struct ctl_table vm_table
[];
211 static struct ctl_table fs_table
[];
212 static struct ctl_table debug_table
[];
213 static struct ctl_table dev_table
[];
214 extern struct ctl_table random_table
[];
216 extern struct ctl_table epoll_table
[];
219 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220 int sysctl_legacy_va_layout
;
223 /* The default sysctl tables: */
225 static struct ctl_table sysctl_base_table
[] = {
227 .procname
= "kernel",
244 .child
= debug_table
,
254 #ifdef CONFIG_SCHED_DEBUG
255 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
256 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
257 static int min_wakeup_granularity_ns
; /* 0 usecs */
258 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
259 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
260 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
263 #ifdef CONFIG_COMPACTION
264 static int min_extfrag_threshold
;
265 static int max_extfrag_threshold
= 1000;
268 static struct ctl_table kern_table
[] = {
270 .procname
= "sched_child_runs_first",
271 .data
= &sysctl_sched_child_runs_first
,
272 .maxlen
= sizeof(unsigned int),
274 .proc_handler
= proc_dointvec
,
276 #ifdef CONFIG_SCHED_DEBUG
278 .procname
= "sched_min_granularity_ns",
279 .data
= &sysctl_sched_min_granularity
,
280 .maxlen
= sizeof(unsigned int),
282 .proc_handler
= sched_proc_update_handler
,
283 .extra1
= &min_sched_granularity_ns
,
284 .extra2
= &max_sched_granularity_ns
,
287 .procname
= "sched_latency_ns",
288 .data
= &sysctl_sched_latency
,
289 .maxlen
= sizeof(unsigned int),
291 .proc_handler
= sched_proc_update_handler
,
292 .extra1
= &min_sched_granularity_ns
,
293 .extra2
= &max_sched_granularity_ns
,
296 .procname
= "sched_wakeup_granularity_ns",
297 .data
= &sysctl_sched_wakeup_granularity
,
298 .maxlen
= sizeof(unsigned int),
300 .proc_handler
= sched_proc_update_handler
,
301 .extra1
= &min_wakeup_granularity_ns
,
302 .extra2
= &max_wakeup_granularity_ns
,
305 .procname
= "sched_tunable_scaling",
306 .data
= &sysctl_sched_tunable_scaling
,
307 .maxlen
= sizeof(enum sched_tunable_scaling
),
309 .proc_handler
= sched_proc_update_handler
,
310 .extra1
= &min_sched_tunable_scaling
,
311 .extra2
= &max_sched_tunable_scaling
,
314 .procname
= "sched_migration_cost_ns",
315 .data
= &sysctl_sched_migration_cost
,
316 .maxlen
= sizeof(unsigned int),
318 .proc_handler
= proc_dointvec
,
321 .procname
= "sched_nr_migrate",
322 .data
= &sysctl_sched_nr_migrate
,
323 .maxlen
= sizeof(unsigned int),
325 .proc_handler
= proc_dointvec
,
328 .procname
= "sched_time_avg_ms",
329 .data
= &sysctl_sched_time_avg
,
330 .maxlen
= sizeof(unsigned int),
332 .proc_handler
= proc_dointvec
,
335 .procname
= "sched_shares_window_ns",
336 .data
= &sysctl_sched_shares_window
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= proc_dointvec
,
342 .procname
= "timer_migration",
343 .data
= &sysctl_timer_migration
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= proc_dointvec_minmax
,
352 .procname
= "sched_rt_period_us",
353 .data
= &sysctl_sched_rt_period
,
354 .maxlen
= sizeof(unsigned int),
356 .proc_handler
= sched_rt_handler
,
359 .procname
= "sched_rt_runtime_us",
360 .data
= &sysctl_sched_rt_runtime
,
361 .maxlen
= sizeof(int),
363 .proc_handler
= sched_rt_handler
,
365 #ifdef CONFIG_SCHED_AUTOGROUP
367 .procname
= "sched_autogroup_enabled",
368 .data
= &sysctl_sched_autogroup_enabled
,
369 .maxlen
= sizeof(unsigned int),
371 .proc_handler
= proc_dointvec
,
374 #ifdef CONFIG_CFS_BANDWIDTH
376 .procname
= "sched_cfs_bandwidth_slice_us",
377 .data
= &sysctl_sched_cfs_bandwidth_slice
,
378 .maxlen
= sizeof(unsigned int),
380 .proc_handler
= proc_dointvec_minmax
,
384 #ifdef CONFIG_PROVE_LOCKING
386 .procname
= "prove_locking",
387 .data
= &prove_locking
,
388 .maxlen
= sizeof(int),
390 .proc_handler
= proc_dointvec
,
393 #ifdef CONFIG_LOCK_STAT
395 .procname
= "lock_stat",
397 .maxlen
= sizeof(int),
399 .proc_handler
= proc_dointvec
,
404 .data
= &panic_timeout
,
405 .maxlen
= sizeof(int),
407 .proc_handler
= proc_dointvec
,
409 #ifdef CONFIG_COREDUMP
411 .procname
= "core_uses_pid",
412 .data
= &core_uses_pid
,
413 .maxlen
= sizeof(int),
415 .proc_handler
= proc_dointvec
,
418 .procname
= "core_pattern",
419 .data
= core_pattern
,
420 .maxlen
= CORENAME_MAX_SIZE
,
422 .proc_handler
= proc_dostring_coredump
,
425 .procname
= "core_pipe_limit",
426 .data
= &core_pipe_limit
,
427 .maxlen
= sizeof(unsigned int),
429 .proc_handler
= proc_dointvec
,
432 #ifdef CONFIG_PROC_SYSCTL
434 .procname
= "tainted",
435 .maxlen
= sizeof(long),
437 .proc_handler
= proc_taint
,
440 #ifdef CONFIG_LATENCYTOP
442 .procname
= "latencytop",
443 .data
= &latencytop_enabled
,
444 .maxlen
= sizeof(int),
446 .proc_handler
= proc_dointvec
,
449 #ifdef CONFIG_BLK_DEV_INITRD
451 .procname
= "real-root-dev",
452 .data
= &real_root_dev
,
453 .maxlen
= sizeof(int),
455 .proc_handler
= proc_dointvec
,
459 .procname
= "print-fatal-signals",
460 .data
= &print_fatal_signals
,
461 .maxlen
= sizeof(int),
463 .proc_handler
= proc_dointvec
,
467 .procname
= "reboot-cmd",
468 .data
= reboot_command
,
471 .proc_handler
= proc_dostring
,
474 .procname
= "stop-a",
475 .data
= &stop_a_enabled
,
476 .maxlen
= sizeof (int),
478 .proc_handler
= proc_dointvec
,
481 .procname
= "scons-poweroff",
482 .data
= &scons_pwroff
,
483 .maxlen
= sizeof (int),
485 .proc_handler
= proc_dointvec
,
488 #ifdef CONFIG_SPARC64
490 .procname
= "tsb-ratio",
491 .data
= &sysctl_tsb_ratio
,
492 .maxlen
= sizeof (int),
494 .proc_handler
= proc_dointvec
,
499 .procname
= "soft-power",
500 .data
= &pwrsw_enabled
,
501 .maxlen
= sizeof (int),
503 .proc_handler
= proc_dointvec
,
506 .procname
= "unaligned-trap",
507 .data
= &unaligned_enabled
,
508 .maxlen
= sizeof (int),
510 .proc_handler
= proc_dointvec
,
514 .procname
= "ctrl-alt-del",
516 .maxlen
= sizeof(int),
518 .proc_handler
= proc_dointvec
,
520 #ifdef CONFIG_FUNCTION_TRACER
522 .procname
= "ftrace_enabled",
523 .data
= &ftrace_enabled
,
524 .maxlen
= sizeof(int),
526 .proc_handler
= ftrace_enable_sysctl
,
529 #ifdef CONFIG_STACK_TRACER
531 .procname
= "stack_tracer_enabled",
532 .data
= &stack_tracer_enabled
,
533 .maxlen
= sizeof(int),
535 .proc_handler
= stack_trace_sysctl
,
538 #ifdef CONFIG_TRACING
540 .procname
= "ftrace_dump_on_oops",
541 .data
= &ftrace_dump_on_oops
,
542 .maxlen
= sizeof(int),
544 .proc_handler
= proc_dointvec
,
547 #ifdef CONFIG_MODULES
549 .procname
= "modprobe",
550 .data
= &modprobe_path
,
551 .maxlen
= KMOD_PATH_LEN
,
553 .proc_handler
= proc_dostring
,
556 .procname
= "modules_disabled",
557 .data
= &modules_disabled
,
558 .maxlen
= sizeof(int),
560 /* only handle a transition from default "0" to "1" */
561 .proc_handler
= proc_dointvec_minmax
,
566 #ifdef CONFIG_HOTPLUG
568 .procname
= "hotplug",
569 .data
= &uevent_helper
,
570 .maxlen
= UEVENT_HELPER_PATH_LEN
,
572 .proc_handler
= proc_dostring
,
575 #ifdef CONFIG_CHR_DEV_SG
577 .procname
= "sg-big-buff",
578 .data
= &sg_big_buff
,
579 .maxlen
= sizeof (int),
581 .proc_handler
= proc_dointvec
,
584 #ifdef CONFIG_BSD_PROCESS_ACCT
588 .maxlen
= 3*sizeof(int),
590 .proc_handler
= proc_dointvec
,
593 #ifdef CONFIG_MAGIC_SYSRQ
596 .data
= &__sysrq_enabled
,
597 .maxlen
= sizeof (int),
599 .proc_handler
= sysrq_sysctl_handler
,
602 #ifdef CONFIG_PROC_SYSCTL
604 .procname
= "cad_pid",
606 .maxlen
= sizeof (int),
608 .proc_handler
= proc_do_cad_pid
,
612 .procname
= "threads-max",
613 .data
= &max_threads
,
614 .maxlen
= sizeof(int),
616 .proc_handler
= proc_dointvec
,
619 .procname
= "random",
621 .child
= random_table
,
624 .procname
= "usermodehelper",
626 .child
= usermodehelper_table
,
629 .procname
= "overflowuid",
630 .data
= &overflowuid
,
631 .maxlen
= sizeof(int),
633 .proc_handler
= proc_dointvec_minmax
,
634 .extra1
= &minolduid
,
635 .extra2
= &maxolduid
,
638 .procname
= "overflowgid",
639 .data
= &overflowgid
,
640 .maxlen
= sizeof(int),
642 .proc_handler
= proc_dointvec_minmax
,
643 .extra1
= &minolduid
,
644 .extra2
= &maxolduid
,
647 #ifdef CONFIG_MATHEMU
649 .procname
= "ieee_emulation_warnings",
650 .data
= &sysctl_ieee_emulation_warnings
,
651 .maxlen
= sizeof(int),
653 .proc_handler
= proc_dointvec
,
657 .procname
= "userprocess_debug",
658 .data
= &show_unhandled_signals
,
659 .maxlen
= sizeof(int),
661 .proc_handler
= proc_dointvec
,
665 .procname
= "pid_max",
667 .maxlen
= sizeof (int),
669 .proc_handler
= proc_dointvec_minmax
,
670 .extra1
= &pid_max_min
,
671 .extra2
= &pid_max_max
,
674 .procname
= "panic_on_oops",
675 .data
= &panic_on_oops
,
676 .maxlen
= sizeof(int),
678 .proc_handler
= proc_dointvec
,
680 #if defined CONFIG_PRINTK
682 .procname
= "printk",
683 .data
= &console_loglevel
,
684 .maxlen
= 4*sizeof(int),
686 .proc_handler
= proc_dointvec
,
689 .procname
= "printk_ratelimit",
690 .data
= &printk_ratelimit_state
.interval
,
691 .maxlen
= sizeof(int),
693 .proc_handler
= proc_dointvec_jiffies
,
696 .procname
= "printk_ratelimit_burst",
697 .data
= &printk_ratelimit_state
.burst
,
698 .maxlen
= sizeof(int),
700 .proc_handler
= proc_dointvec
,
703 .procname
= "printk_delay",
704 .data
= &printk_delay_msec
,
705 .maxlen
= sizeof(int),
707 .proc_handler
= proc_dointvec_minmax
,
709 .extra2
= &ten_thousand
,
712 .procname
= "dmesg_restrict",
713 .data
= &dmesg_restrict
,
714 .maxlen
= sizeof(int),
716 .proc_handler
= proc_dointvec_minmax_sysadmin
,
721 .procname
= "kptr_restrict",
722 .data
= &kptr_restrict
,
723 .maxlen
= sizeof(int),
725 .proc_handler
= proc_dointvec_minmax_sysadmin
,
731 .procname
= "ngroups_max",
732 .data
= &ngroups_max
,
733 .maxlen
= sizeof (int),
735 .proc_handler
= proc_dointvec
,
738 .procname
= "cap_last_cap",
739 .data
= (void *)&cap_last_cap
,
740 .maxlen
= sizeof(int),
742 .proc_handler
= proc_dointvec
,
744 #if defined(CONFIG_LOCKUP_DETECTOR)
746 .procname
= "watchdog",
747 .data
= &watchdog_enabled
,
748 .maxlen
= sizeof (int),
750 .proc_handler
= proc_dowatchdog
,
755 .procname
= "watchdog_thresh",
756 .data
= &watchdog_thresh
,
757 .maxlen
= sizeof(int),
759 .proc_handler
= proc_dowatchdog
,
764 .procname
= "softlockup_panic",
765 .data
= &softlockup_panic
,
766 .maxlen
= sizeof(int),
768 .proc_handler
= proc_dointvec_minmax
,
773 .procname
= "nmi_watchdog",
774 .data
= &watchdog_enabled
,
775 .maxlen
= sizeof (int),
777 .proc_handler
= proc_dowatchdog
,
782 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
784 .procname
= "unknown_nmi_panic",
785 .data
= &unknown_nmi_panic
,
786 .maxlen
= sizeof (int),
788 .proc_handler
= proc_dointvec
,
791 #if defined(CONFIG_X86)
793 .procname
= "panic_on_unrecovered_nmi",
794 .data
= &panic_on_unrecovered_nmi
,
795 .maxlen
= sizeof(int),
797 .proc_handler
= proc_dointvec
,
800 .procname
= "panic_on_io_nmi",
801 .data
= &panic_on_io_nmi
,
802 .maxlen
= sizeof(int),
804 .proc_handler
= proc_dointvec
,
806 #ifdef CONFIG_DEBUG_STACKOVERFLOW
808 .procname
= "panic_on_stackoverflow",
809 .data
= &sysctl_panic_on_stackoverflow
,
810 .maxlen
= sizeof(int),
812 .proc_handler
= proc_dointvec
,
816 .procname
= "bootloader_type",
817 .data
= &bootloader_type
,
818 .maxlen
= sizeof (int),
820 .proc_handler
= proc_dointvec
,
823 .procname
= "bootloader_version",
824 .data
= &bootloader_version
,
825 .maxlen
= sizeof (int),
827 .proc_handler
= proc_dointvec
,
830 .procname
= "kstack_depth_to_print",
831 .data
= &kstack_depth_to_print
,
832 .maxlen
= sizeof(int),
834 .proc_handler
= proc_dointvec
,
837 .procname
= "io_delay_type",
838 .data
= &io_delay_type
,
839 .maxlen
= sizeof(int),
841 .proc_handler
= proc_dointvec
,
844 #if defined(CONFIG_MMU)
846 .procname
= "randomize_va_space",
847 .data
= &randomize_va_space
,
848 .maxlen
= sizeof(int),
850 .proc_handler
= proc_dointvec
,
853 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
855 .procname
= "spin_retry",
857 .maxlen
= sizeof (int),
859 .proc_handler
= proc_dointvec
,
862 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
864 .procname
= "acpi_video_flags",
865 .data
= &acpi_realmode_flags
,
866 .maxlen
= sizeof (unsigned long),
868 .proc_handler
= proc_doulongvec_minmax
,
873 .procname
= "ignore-unaligned-usertrap",
874 .data
= &no_unaligned_warning
,
875 .maxlen
= sizeof (int),
877 .proc_handler
= proc_dointvec
,
880 .procname
= "unaligned-dump-stack",
881 .data
= &unaligned_dump_stack
,
882 .maxlen
= sizeof (int),
884 .proc_handler
= proc_dointvec
,
887 #ifdef CONFIG_DETECT_HUNG_TASK
889 .procname
= "hung_task_panic",
890 .data
= &sysctl_hung_task_panic
,
891 .maxlen
= sizeof(int),
893 .proc_handler
= proc_dointvec_minmax
,
898 .procname
= "hung_task_check_count",
899 .data
= &sysctl_hung_task_check_count
,
900 .maxlen
= sizeof(unsigned long),
902 .proc_handler
= proc_doulongvec_minmax
,
905 .procname
= "hung_task_timeout_secs",
906 .data
= &sysctl_hung_task_timeout_secs
,
907 .maxlen
= sizeof(unsigned long),
909 .proc_handler
= proc_dohung_task_timeout_secs
,
912 .procname
= "hung_task_warnings",
913 .data
= &sysctl_hung_task_warnings
,
914 .maxlen
= sizeof(unsigned long),
916 .proc_handler
= proc_doulongvec_minmax
,
921 .procname
= "compat-log",
923 .maxlen
= sizeof (int),
925 .proc_handler
= proc_dointvec
,
928 #ifdef CONFIG_RT_MUTEXES
930 .procname
= "max_lock_depth",
931 .data
= &max_lock_depth
,
932 .maxlen
= sizeof(int),
934 .proc_handler
= proc_dointvec
,
938 .procname
= "poweroff_cmd",
939 .data
= &poweroff_cmd
,
940 .maxlen
= POWEROFF_CMD_PATH_LEN
,
942 .proc_handler
= proc_dostring
,
948 .child
= key_sysctls
,
951 #ifdef CONFIG_RCU_TORTURE_TEST
953 .procname
= "rcutorture_runnable",
954 .data
= &rcutorture_runnable
,
955 .maxlen
= sizeof(int),
957 .proc_handler
= proc_dointvec
,
960 #ifdef CONFIG_PERF_EVENTS
962 * User-space scripts rely on the existence of this file
963 * as a feature check for perf_events being enabled.
965 * So it's an ABI, do not remove!
968 .procname
= "perf_event_paranoid",
969 .data
= &sysctl_perf_event_paranoid
,
970 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
972 .proc_handler
= proc_dointvec
,
975 .procname
= "perf_event_mlock_kb",
976 .data
= &sysctl_perf_event_mlock
,
977 .maxlen
= sizeof(sysctl_perf_event_mlock
),
979 .proc_handler
= proc_dointvec
,
982 .procname
= "perf_event_max_sample_rate",
983 .data
= &sysctl_perf_event_sample_rate
,
984 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
986 .proc_handler
= perf_proc_update_handler
,
989 #ifdef CONFIG_KMEMCHECK
991 .procname
= "kmemcheck",
992 .data
= &kmemcheck_enabled
,
993 .maxlen
= sizeof(int),
995 .proc_handler
= proc_dointvec
,
1000 .procname
= "blk_iopoll",
1001 .data
= &blk_iopoll_enabled
,
1002 .maxlen
= sizeof(int),
1004 .proc_handler
= proc_dointvec
,
1010 static struct ctl_table vm_table
[] = {
1012 .procname
= "overcommit_memory",
1013 .data
= &sysctl_overcommit_memory
,
1014 .maxlen
= sizeof(sysctl_overcommit_memory
),
1016 .proc_handler
= proc_dointvec_minmax
,
1021 .procname
= "panic_on_oom",
1022 .data
= &sysctl_panic_on_oom
,
1023 .maxlen
= sizeof(sysctl_panic_on_oom
),
1025 .proc_handler
= proc_dointvec_minmax
,
1030 .procname
= "oom_kill_allocating_task",
1031 .data
= &sysctl_oom_kill_allocating_task
,
1032 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1034 .proc_handler
= proc_dointvec
,
1037 .procname
= "oom_dump_tasks",
1038 .data
= &sysctl_oom_dump_tasks
,
1039 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1041 .proc_handler
= proc_dointvec
,
1044 .procname
= "overcommit_ratio",
1045 .data
= &sysctl_overcommit_ratio
,
1046 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1048 .proc_handler
= proc_dointvec
,
1051 .procname
= "page-cluster",
1052 .data
= &page_cluster
,
1053 .maxlen
= sizeof(int),
1055 .proc_handler
= proc_dointvec_minmax
,
1059 .procname
= "dirty_background_ratio",
1060 .data
= &dirty_background_ratio
,
1061 .maxlen
= sizeof(dirty_background_ratio
),
1063 .proc_handler
= dirty_background_ratio_handler
,
1065 .extra2
= &one_hundred
,
1068 .procname
= "dirty_background_bytes",
1069 .data
= &dirty_background_bytes
,
1070 .maxlen
= sizeof(dirty_background_bytes
),
1072 .proc_handler
= dirty_background_bytes_handler
,
1076 .procname
= "dirty_ratio",
1077 .data
= &vm_dirty_ratio
,
1078 .maxlen
= sizeof(vm_dirty_ratio
),
1080 .proc_handler
= dirty_ratio_handler
,
1082 .extra2
= &one_hundred
,
1085 .procname
= "dirty_bytes",
1086 .data
= &vm_dirty_bytes
,
1087 .maxlen
= sizeof(vm_dirty_bytes
),
1089 .proc_handler
= dirty_bytes_handler
,
1090 .extra1
= &dirty_bytes_min
,
1093 .procname
= "dirty_writeback_centisecs",
1094 .data
= &dirty_writeback_interval
,
1095 .maxlen
= sizeof(dirty_writeback_interval
),
1097 .proc_handler
= dirty_writeback_centisecs_handler
,
1100 .procname
= "dirty_expire_centisecs",
1101 .data
= &dirty_expire_interval
,
1102 .maxlen
= sizeof(dirty_expire_interval
),
1104 .proc_handler
= proc_dointvec_minmax
,
1108 .procname
= "nr_pdflush_threads",
1109 .mode
= 0444 /* read-only */,
1110 .proc_handler
= pdflush_proc_obsolete
,
1113 .procname
= "swappiness",
1114 .data
= &vm_swappiness
,
1115 .maxlen
= sizeof(vm_swappiness
),
1117 .proc_handler
= proc_dointvec_minmax
,
1119 .extra2
= &one_hundred
,
1121 #ifdef CONFIG_HUGETLB_PAGE
1123 .procname
= "nr_hugepages",
1125 .maxlen
= sizeof(unsigned long),
1127 .proc_handler
= hugetlb_sysctl_handler
,
1128 .extra1
= (void *)&hugetlb_zero
,
1129 .extra2
= (void *)&hugetlb_infinity
,
1133 .procname
= "nr_hugepages_mempolicy",
1135 .maxlen
= sizeof(unsigned long),
1137 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1138 .extra1
= (void *)&hugetlb_zero
,
1139 .extra2
= (void *)&hugetlb_infinity
,
1143 .procname
= "hugetlb_shm_group",
1144 .data
= &sysctl_hugetlb_shm_group
,
1145 .maxlen
= sizeof(gid_t
),
1147 .proc_handler
= proc_dointvec
,
1150 .procname
= "hugepages_treat_as_movable",
1151 .data
= &hugepages_treat_as_movable
,
1152 .maxlen
= sizeof(int),
1154 .proc_handler
= hugetlb_treat_movable_handler
,
1157 .procname
= "nr_overcommit_hugepages",
1159 .maxlen
= sizeof(unsigned long),
1161 .proc_handler
= hugetlb_overcommit_handler
,
1162 .extra1
= (void *)&hugetlb_zero
,
1163 .extra2
= (void *)&hugetlb_infinity
,
1167 .procname
= "lowmem_reserve_ratio",
1168 .data
= &sysctl_lowmem_reserve_ratio
,
1169 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1171 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1174 .procname
= "drop_caches",
1175 .data
= &sysctl_drop_caches
,
1176 .maxlen
= sizeof(int),
1178 .proc_handler
= drop_caches_sysctl_handler
,
1182 #ifdef CONFIG_COMPACTION
1184 .procname
= "compact_memory",
1185 .data
= &sysctl_compact_memory
,
1186 .maxlen
= sizeof(int),
1188 .proc_handler
= sysctl_compaction_handler
,
1191 .procname
= "extfrag_threshold",
1192 .data
= &sysctl_extfrag_threshold
,
1193 .maxlen
= sizeof(int),
1195 .proc_handler
= sysctl_extfrag_handler
,
1196 .extra1
= &min_extfrag_threshold
,
1197 .extra2
= &max_extfrag_threshold
,
1200 #endif /* CONFIG_COMPACTION */
1202 .procname
= "min_free_kbytes",
1203 .data
= &min_free_kbytes
,
1204 .maxlen
= sizeof(min_free_kbytes
),
1206 .proc_handler
= min_free_kbytes_sysctl_handler
,
1210 .procname
= "percpu_pagelist_fraction",
1211 .data
= &percpu_pagelist_fraction
,
1212 .maxlen
= sizeof(percpu_pagelist_fraction
),
1214 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1215 .extra1
= &min_percpu_pagelist_fract
,
1219 .procname
= "max_map_count",
1220 .data
= &sysctl_max_map_count
,
1221 .maxlen
= sizeof(sysctl_max_map_count
),
1223 .proc_handler
= proc_dointvec_minmax
,
1228 .procname
= "nr_trim_pages",
1229 .data
= &sysctl_nr_trim_pages
,
1230 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1232 .proc_handler
= proc_dointvec_minmax
,
1237 .procname
= "laptop_mode",
1238 .data
= &laptop_mode
,
1239 .maxlen
= sizeof(laptop_mode
),
1241 .proc_handler
= proc_dointvec_jiffies
,
1244 .procname
= "block_dump",
1245 .data
= &block_dump
,
1246 .maxlen
= sizeof(block_dump
),
1248 .proc_handler
= proc_dointvec
,
1252 .procname
= "vfs_cache_pressure",
1253 .data
= &sysctl_vfs_cache_pressure
,
1254 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1256 .proc_handler
= proc_dointvec
,
1259 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1261 .procname
= "legacy_va_layout",
1262 .data
= &sysctl_legacy_va_layout
,
1263 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1265 .proc_handler
= proc_dointvec
,
1271 .procname
= "zone_reclaim_mode",
1272 .data
= &zone_reclaim_mode
,
1273 .maxlen
= sizeof(zone_reclaim_mode
),
1275 .proc_handler
= proc_dointvec
,
1279 .procname
= "min_unmapped_ratio",
1280 .data
= &sysctl_min_unmapped_ratio
,
1281 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1283 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1285 .extra2
= &one_hundred
,
1288 .procname
= "min_slab_ratio",
1289 .data
= &sysctl_min_slab_ratio
,
1290 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1292 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1294 .extra2
= &one_hundred
,
1299 .procname
= "stat_interval",
1300 .data
= &sysctl_stat_interval
,
1301 .maxlen
= sizeof(sysctl_stat_interval
),
1303 .proc_handler
= proc_dointvec_jiffies
,
1308 .procname
= "mmap_min_addr",
1309 .data
= &dac_mmap_min_addr
,
1310 .maxlen
= sizeof(unsigned long),
1312 .proc_handler
= mmap_min_addr_handler
,
1317 .procname
= "numa_zonelist_order",
1318 .data
= &numa_zonelist_order
,
1319 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1321 .proc_handler
= numa_zonelist_order_handler
,
1324 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1325 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1327 .procname
= "vdso_enabled",
1328 .data
= &vdso_enabled
,
1329 .maxlen
= sizeof(vdso_enabled
),
1331 .proc_handler
= proc_dointvec
,
1335 #ifdef CONFIG_HIGHMEM
1337 .procname
= "highmem_is_dirtyable",
1338 .data
= &vm_highmem_is_dirtyable
,
1339 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1341 .proc_handler
= proc_dointvec_minmax
,
1347 .procname
= "scan_unevictable_pages",
1348 .data
= &scan_unevictable_pages
,
1349 .maxlen
= sizeof(scan_unevictable_pages
),
1351 .proc_handler
= scan_unevictable_handler
,
1353 #ifdef CONFIG_MEMORY_FAILURE
1355 .procname
= "memory_failure_early_kill",
1356 .data
= &sysctl_memory_failure_early_kill
,
1357 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1359 .proc_handler
= proc_dointvec_minmax
,
1364 .procname
= "memory_failure_recovery",
1365 .data
= &sysctl_memory_failure_recovery
,
1366 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1368 .proc_handler
= proc_dointvec_minmax
,
1376 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1377 static struct ctl_table binfmt_misc_table
[] = {
1382 static struct ctl_table fs_table
[] = {
1384 .procname
= "inode-nr",
1385 .data
= &inodes_stat
,
1386 .maxlen
= 2*sizeof(int),
1388 .proc_handler
= proc_nr_inodes
,
1391 .procname
= "inode-state",
1392 .data
= &inodes_stat
,
1393 .maxlen
= 7*sizeof(int),
1395 .proc_handler
= proc_nr_inodes
,
1398 .procname
= "file-nr",
1399 .data
= &files_stat
,
1400 .maxlen
= sizeof(files_stat
),
1402 .proc_handler
= proc_nr_files
,
1405 .procname
= "file-max",
1406 .data
= &files_stat
.max_files
,
1407 .maxlen
= sizeof(files_stat
.max_files
),
1409 .proc_handler
= proc_doulongvec_minmax
,
1412 .procname
= "nr_open",
1413 .data
= &sysctl_nr_open
,
1414 .maxlen
= sizeof(int),
1416 .proc_handler
= proc_dointvec_minmax
,
1417 .extra1
= &sysctl_nr_open_min
,
1418 .extra2
= &sysctl_nr_open_max
,
1421 .procname
= "dentry-state",
1422 .data
= &dentry_stat
,
1423 .maxlen
= 6*sizeof(int),
1425 .proc_handler
= proc_nr_dentry
,
1428 .procname
= "overflowuid",
1429 .data
= &fs_overflowuid
,
1430 .maxlen
= sizeof(int),
1432 .proc_handler
= proc_dointvec_minmax
,
1433 .extra1
= &minolduid
,
1434 .extra2
= &maxolduid
,
1437 .procname
= "overflowgid",
1438 .data
= &fs_overflowgid
,
1439 .maxlen
= sizeof(int),
1441 .proc_handler
= proc_dointvec_minmax
,
1442 .extra1
= &minolduid
,
1443 .extra2
= &maxolduid
,
1445 #ifdef CONFIG_FILE_LOCKING
1447 .procname
= "leases-enable",
1448 .data
= &leases_enable
,
1449 .maxlen
= sizeof(int),
1451 .proc_handler
= proc_dointvec
,
1454 #ifdef CONFIG_DNOTIFY
1456 .procname
= "dir-notify-enable",
1457 .data
= &dir_notify_enable
,
1458 .maxlen
= sizeof(int),
1460 .proc_handler
= proc_dointvec
,
1464 #ifdef CONFIG_FILE_LOCKING
1466 .procname
= "lease-break-time",
1467 .data
= &lease_break_time
,
1468 .maxlen
= sizeof(int),
1470 .proc_handler
= proc_dointvec
,
1475 .procname
= "aio-nr",
1477 .maxlen
= sizeof(aio_nr
),
1479 .proc_handler
= proc_doulongvec_minmax
,
1482 .procname
= "aio-max-nr",
1483 .data
= &aio_max_nr
,
1484 .maxlen
= sizeof(aio_max_nr
),
1486 .proc_handler
= proc_doulongvec_minmax
,
1488 #endif /* CONFIG_AIO */
1489 #ifdef CONFIG_INOTIFY_USER
1491 .procname
= "inotify",
1493 .child
= inotify_table
,
1498 .procname
= "epoll",
1500 .child
= epoll_table
,
1505 .procname
= "protected_symlinks",
1506 .data
= &sysctl_protected_symlinks
,
1507 .maxlen
= sizeof(int),
1509 .proc_handler
= proc_dointvec_minmax
,
1514 .procname
= "protected_hardlinks",
1515 .data
= &sysctl_protected_hardlinks
,
1516 .maxlen
= sizeof(int),
1518 .proc_handler
= proc_dointvec_minmax
,
1523 .procname
= "suid_dumpable",
1524 .data
= &suid_dumpable
,
1525 .maxlen
= sizeof(int),
1527 .proc_handler
= proc_dointvec_minmax_coredump
,
1531 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1533 .procname
= "binfmt_misc",
1535 .child
= binfmt_misc_table
,
1539 .procname
= "pipe-max-size",
1540 .data
= &pipe_max_size
,
1541 .maxlen
= sizeof(int),
1543 .proc_handler
= &pipe_proc_fn
,
1544 .extra1
= &pipe_min_size
,
1549 static struct ctl_table debug_table
[] = {
1550 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1552 .procname
= "exception-trace",
1553 .data
= &show_unhandled_signals
,
1554 .maxlen
= sizeof(int),
1556 .proc_handler
= proc_dointvec
1559 #if defined(CONFIG_OPTPROBES)
1561 .procname
= "kprobes-optimization",
1562 .data
= &sysctl_kprobes_optimization
,
1563 .maxlen
= sizeof(int),
1565 .proc_handler
= proc_kprobes_optimization_handler
,
1573 static struct ctl_table dev_table
[] = {
1577 int __init
sysctl_init(void)
1579 struct ctl_table_header
*hdr
;
1581 hdr
= register_sysctl_table(sysctl_base_table
);
1582 kmemleak_not_leak(hdr
);
1586 #endif /* CONFIG_SYSCTL */
1592 #ifdef CONFIG_PROC_SYSCTL
1594 static int _proc_do_string(void* data
, int maxlen
, int write
,
1595 void __user
*buffer
,
1596 size_t *lenp
, loff_t
*ppos
)
1602 if (!data
|| !maxlen
|| !*lenp
) {
1610 while (len
< *lenp
) {
1611 if (get_user(c
, p
++))
1613 if (c
== 0 || c
== '\n')
1619 if(copy_from_user(data
, buffer
, len
))
1621 ((char *) data
)[len
] = 0;
1639 if(copy_to_user(buffer
, data
, len
))
1642 if(put_user('\n', ((char __user
*) buffer
) + len
))
1653 * proc_dostring - read a string sysctl
1654 * @table: the sysctl table
1655 * @write: %TRUE if this is a write to the sysctl file
1656 * @buffer: the user buffer
1657 * @lenp: the size of the user buffer
1658 * @ppos: file position
1660 * Reads/writes a string from/to the user buffer. If the kernel
1661 * buffer provided is not large enough to hold the string, the
1662 * string is truncated. The copied string is %NULL-terminated.
1663 * If the string is being read by the user process, it is copied
1664 * and a newline '\n' is added. It is truncated if the buffer is
1667 * Returns 0 on success.
1669 int proc_dostring(struct ctl_table
*table
, int write
,
1670 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1672 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1673 buffer
, lenp
, ppos
);
1676 static size_t proc_skip_spaces(char **buf
)
1679 char *tmp
= skip_spaces(*buf
);
1685 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1695 #define TMPBUFLEN 22
1697 * proc_get_long - reads an ASCII formatted integer from a user buffer
1699 * @buf: a kernel buffer
1700 * @size: size of the kernel buffer
1701 * @val: this is where the number will be stored
1702 * @neg: set to %TRUE if number is negative
1703 * @perm_tr: a vector which contains the allowed trailers
1704 * @perm_tr_len: size of the perm_tr vector
1705 * @tr: pointer to store the trailer character
1707 * In case of success %0 is returned and @buf and @size are updated with
1708 * the amount of bytes read. If @tr is non-NULL and a trailing
1709 * character exists (size is non-zero after returning from this
1710 * function), @tr is updated with the trailing character.
1712 static int proc_get_long(char **buf
, size_t *size
,
1713 unsigned long *val
, bool *neg
,
1714 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1717 char *p
, tmp
[TMPBUFLEN
];
1723 if (len
> TMPBUFLEN
- 1)
1724 len
= TMPBUFLEN
- 1;
1726 memcpy(tmp
, *buf
, len
);
1730 if (*p
== '-' && *size
> 1) {
1738 *val
= simple_strtoul(p
, &p
, 0);
1742 /* We don't know if the next char is whitespace thus we may accept
1743 * invalid integers (e.g. 1234...a) or two integers instead of one
1744 * (e.g. 123...1). So lets not allow such large numbers. */
1745 if (len
== TMPBUFLEN
- 1)
1748 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1751 if (tr
&& (len
< *size
))
1761 * proc_put_long - converts an integer to a decimal ASCII formatted string
1763 * @buf: the user buffer
1764 * @size: the size of the user buffer
1765 * @val: the integer to be converted
1766 * @neg: sign of the number, %TRUE for negative
1768 * In case of success %0 is returned and @buf and @size are updated with
1769 * the amount of bytes written.
1771 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1775 char tmp
[TMPBUFLEN
], *p
= tmp
;
1777 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1781 if (copy_to_user(*buf
, tmp
, len
))
1789 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1792 char __user
**buffer
= (char __user
**)buf
;
1793 if (put_user(c
, *buffer
))
1795 (*size
)--, (*buffer
)++;
1801 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1803 int write
, void *data
)
1806 *valp
= *negp
? -*lvalp
: *lvalp
;
1811 *lvalp
= (unsigned long)-val
;
1814 *lvalp
= (unsigned long)val
;
1820 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1822 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1823 int write
, void __user
*buffer
,
1824 size_t *lenp
, loff_t
*ppos
,
1825 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1826 int write
, void *data
),
1829 int *i
, vleft
, first
= 1, err
= 0;
1830 unsigned long page
= 0;
1834 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1839 i
= (int *) tbl_data
;
1840 vleft
= table
->maxlen
/ sizeof(*i
);
1844 conv
= do_proc_dointvec_conv
;
1847 if (left
> PAGE_SIZE
- 1)
1848 left
= PAGE_SIZE
- 1;
1849 page
= __get_free_page(GFP_TEMPORARY
);
1850 kbuf
= (char *) page
;
1853 if (copy_from_user(kbuf
, buffer
, left
)) {
1860 for (; left
&& vleft
--; i
++, first
=0) {
1865 left
-= proc_skip_spaces(&kbuf
);
1869 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1871 sizeof(proc_wspace_sep
), NULL
);
1874 if (conv(&neg
, &lval
, i
, 1, data
)) {
1879 if (conv(&neg
, &lval
, i
, 0, data
)) {
1884 err
= proc_put_char(&buffer
, &left
, '\t');
1887 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1893 if (!write
&& !first
&& left
&& !err
)
1894 err
= proc_put_char(&buffer
, &left
, '\n');
1895 if (write
&& !err
&& left
)
1896 left
-= proc_skip_spaces(&kbuf
);
1901 return err
? : -EINVAL
;
1908 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1909 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1910 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1911 int write
, void *data
),
1914 return __do_proc_dointvec(table
->data
, table
, write
,
1915 buffer
, lenp
, ppos
, conv
, data
);
1919 * proc_dointvec - read a vector of integers
1920 * @table: the sysctl table
1921 * @write: %TRUE if this is a write to the sysctl file
1922 * @buffer: the user buffer
1923 * @lenp: the size of the user buffer
1924 * @ppos: file position
1926 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1927 * values from/to the user buffer, treated as an ASCII string.
1929 * Returns 0 on success.
1931 int proc_dointvec(struct ctl_table
*table
, int write
,
1932 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1934 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
1939 * Taint values can only be increased
1940 * This means we can safely use a temporary.
1942 static int proc_taint(struct ctl_table
*table
, int write
,
1943 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1946 unsigned long tmptaint
= get_taint();
1949 if (write
&& !capable(CAP_SYS_ADMIN
))
1954 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
1960 * Poor man's atomic or. Not worth adding a primitive
1961 * to everyone's atomic.h for this
1964 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
1965 if ((tmptaint
>> i
) & 1)
1973 #ifdef CONFIG_PRINTK
1974 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
1975 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1977 if (write
&& !capable(CAP_SYS_ADMIN
))
1980 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
1984 struct do_proc_dointvec_minmax_conv_param
{
1989 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
1991 int write
, void *data
)
1993 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1995 int val
= *negp
? -*lvalp
: *lvalp
;
1996 if ((param
->min
&& *param
->min
> val
) ||
1997 (param
->max
&& *param
->max
< val
))
2004 *lvalp
= (unsigned long)-val
;
2007 *lvalp
= (unsigned long)val
;
2014 * proc_dointvec_minmax - read a vector of integers with min/max values
2015 * @table: the sysctl table
2016 * @write: %TRUE if this is a write to the sysctl file
2017 * @buffer: the user buffer
2018 * @lenp: the size of the user buffer
2019 * @ppos: file position
2021 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2022 * values from/to the user buffer, treated as an ASCII string.
2024 * This routine will ensure the values are within the range specified by
2025 * table->extra1 (min) and table->extra2 (max).
2027 * Returns 0 on success.
2029 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2030 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2032 struct do_proc_dointvec_minmax_conv_param param
= {
2033 .min
= (int *) table
->extra1
,
2034 .max
= (int *) table
->extra2
,
2036 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2037 do_proc_dointvec_minmax_conv
, ¶m
);
2040 static void validate_coredump_safety(void)
2042 #ifdef CONFIG_COREDUMP
2043 if (suid_dumpable
== SUID_DUMPABLE_SAFE
&&
2044 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2045 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2046 "suid_dumpable=2. Pipe handler or fully qualified "\
2047 "core dump path required.\n");
2052 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2053 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2055 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2057 validate_coredump_safety();
2061 #ifdef CONFIG_COREDUMP
2062 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2063 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2065 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2067 validate_coredump_safety();
2072 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2073 void __user
*buffer
,
2074 size_t *lenp
, loff_t
*ppos
,
2075 unsigned long convmul
,
2076 unsigned long convdiv
)
2078 unsigned long *i
, *min
, *max
;
2079 int vleft
, first
= 1, err
= 0;
2080 unsigned long page
= 0;
2084 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2089 i
= (unsigned long *) data
;
2090 min
= (unsigned long *) table
->extra1
;
2091 max
= (unsigned long *) table
->extra2
;
2092 vleft
= table
->maxlen
/ sizeof(unsigned long);
2096 if (left
> PAGE_SIZE
- 1)
2097 left
= PAGE_SIZE
- 1;
2098 page
= __get_free_page(GFP_TEMPORARY
);
2099 kbuf
= (char *) page
;
2102 if (copy_from_user(kbuf
, buffer
, left
)) {
2109 for (; left
&& vleft
--; i
++, first
= 0) {
2115 left
-= proc_skip_spaces(&kbuf
);
2117 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2119 sizeof(proc_wspace_sep
), NULL
);
2124 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2128 val
= convdiv
* (*i
) / convmul
;
2130 err
= proc_put_char(&buffer
, &left
, '\t');
2131 err
= proc_put_long(&buffer
, &left
, val
, false);
2137 if (!write
&& !first
&& left
&& !err
)
2138 err
= proc_put_char(&buffer
, &left
, '\n');
2140 left
-= proc_skip_spaces(&kbuf
);
2145 return err
? : -EINVAL
;
2152 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2153 void __user
*buffer
,
2154 size_t *lenp
, loff_t
*ppos
,
2155 unsigned long convmul
,
2156 unsigned long convdiv
)
2158 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2159 buffer
, lenp
, ppos
, convmul
, convdiv
);
2163 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2164 * @table: the sysctl table
2165 * @write: %TRUE if this is a write to the sysctl file
2166 * @buffer: the user buffer
2167 * @lenp: the size of the user buffer
2168 * @ppos: file position
2170 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2171 * values from/to the user buffer, treated as an ASCII string.
2173 * This routine will ensure the values are within the range specified by
2174 * table->extra1 (min) and table->extra2 (max).
2176 * Returns 0 on success.
2178 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2179 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2181 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2185 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2186 * @table: the sysctl table
2187 * @write: %TRUE if this is a write to the sysctl file
2188 * @buffer: the user buffer
2189 * @lenp: the size of the user buffer
2190 * @ppos: file position
2192 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2193 * values from/to the user buffer, treated as an ASCII string. The values
2194 * are treated as milliseconds, and converted to jiffies when they are stored.
2196 * This routine will ensure the values are within the range specified by
2197 * table->extra1 (min) and table->extra2 (max).
2199 * Returns 0 on success.
2201 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2202 void __user
*buffer
,
2203 size_t *lenp
, loff_t
*ppos
)
2205 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2206 lenp
, ppos
, HZ
, 1000l);
2210 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2212 int write
, void *data
)
2215 if (*lvalp
> LONG_MAX
/ HZ
)
2217 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2223 lval
= (unsigned long)-val
;
2226 lval
= (unsigned long)val
;
2233 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2235 int write
, void *data
)
2238 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2240 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2246 lval
= (unsigned long)-val
;
2249 lval
= (unsigned long)val
;
2251 *lvalp
= jiffies_to_clock_t(lval
);
2256 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2258 int write
, void *data
)
2261 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2267 lval
= (unsigned long)-val
;
2270 lval
= (unsigned long)val
;
2272 *lvalp
= jiffies_to_msecs(lval
);
2278 * proc_dointvec_jiffies - read a vector of integers as seconds
2279 * @table: the sysctl table
2280 * @write: %TRUE if this is a write to the sysctl file
2281 * @buffer: the user buffer
2282 * @lenp: the size of the user buffer
2283 * @ppos: file position
2285 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2286 * values from/to the user buffer, treated as an ASCII string.
2287 * The values read are assumed to be in seconds, and are converted into
2290 * Returns 0 on success.
2292 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2293 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2295 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2296 do_proc_dointvec_jiffies_conv
,NULL
);
2300 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2301 * @table: the sysctl table
2302 * @write: %TRUE if this is a write to the sysctl file
2303 * @buffer: the user buffer
2304 * @lenp: the size of the user buffer
2305 * @ppos: pointer to the file position
2307 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2308 * values from/to the user buffer, treated as an ASCII string.
2309 * The values read are assumed to be in 1/USER_HZ seconds, and
2310 * are converted into jiffies.
2312 * Returns 0 on success.
2314 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2315 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2317 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2318 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2322 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2323 * @table: the sysctl table
2324 * @write: %TRUE if this is a write to the sysctl file
2325 * @buffer: the user buffer
2326 * @lenp: the size of the user buffer
2327 * @ppos: file position
2328 * @ppos: the current position in the file
2330 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2331 * values from/to the user buffer, treated as an ASCII string.
2332 * The values read are assumed to be in 1/1000 seconds, and
2333 * are converted into jiffies.
2335 * Returns 0 on success.
2337 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2338 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2340 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2341 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2344 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2345 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2347 struct pid
*new_pid
;
2351 tmp
= pid_vnr(cad_pid
);
2353 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2354 lenp
, ppos
, NULL
, NULL
);
2358 new_pid
= find_get_pid(tmp
);
2362 put_pid(xchg(&cad_pid
, new_pid
));
2367 * proc_do_large_bitmap - read/write from/to a large bitmap
2368 * @table: the sysctl table
2369 * @write: %TRUE if this is a write to the sysctl file
2370 * @buffer: the user buffer
2371 * @lenp: the size of the user buffer
2372 * @ppos: file position
2374 * The bitmap is stored at table->data and the bitmap length (in bits)
2377 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2378 * large bitmaps may be represented in a compact manner. Writing into
2379 * the file will clear the bitmap then update it with the given input.
2381 * Returns 0 on success.
2383 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2384 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2388 size_t left
= *lenp
;
2389 unsigned long bitmap_len
= table
->maxlen
;
2390 unsigned long *bitmap
= (unsigned long *) table
->data
;
2391 unsigned long *tmp_bitmap
= NULL
;
2392 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2394 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2400 unsigned long page
= 0;
2403 if (left
> PAGE_SIZE
- 1)
2404 left
= PAGE_SIZE
- 1;
2406 page
= __get_free_page(GFP_TEMPORARY
);
2407 kbuf
= (char *) page
;
2410 if (copy_from_user(kbuf
, buffer
, left
)) {
2416 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2422 proc_skip_char(&kbuf
, &left
, '\n');
2423 while (!err
&& left
) {
2424 unsigned long val_a
, val_b
;
2427 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2431 if (val_a
>= bitmap_len
|| neg
) {
2443 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2444 &neg
, tr_b
, sizeof(tr_b
),
2448 if (val_b
>= bitmap_len
|| neg
||
2459 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2461 proc_skip_char(&kbuf
, &left
, '\n');
2465 unsigned long bit_a
, bit_b
= 0;
2468 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2469 if (bit_a
>= bitmap_len
)
2471 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2475 err
= proc_put_char(&buffer
, &left
, ',');
2479 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2482 if (bit_a
!= bit_b
) {
2483 err
= proc_put_char(&buffer
, &left
, '-');
2486 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2494 err
= proc_put_char(&buffer
, &left
, '\n');
2500 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2502 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2514 #else /* CONFIG_PROC_SYSCTL */
2516 int proc_dostring(struct ctl_table
*table
, int write
,
2517 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2522 int proc_dointvec(struct ctl_table
*table
, int write
,
2523 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2528 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2529 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2534 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2535 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2540 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2541 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2546 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2547 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2552 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2553 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2558 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2559 void __user
*buffer
,
2560 size_t *lenp
, loff_t
*ppos
)
2566 #endif /* CONFIG_PROC_SYSCTL */
2569 * No sense putting this after each symbol definition, twice,
2570 * exception granted :-)
2572 EXPORT_SYMBOL(proc_dointvec
);
2573 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2574 EXPORT_SYMBOL(proc_dointvec_minmax
);
2575 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2576 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2577 EXPORT_SYMBOL(proc_dostring
);
2578 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2579 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);