2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
71 #include <asm/stacktrace.h>
75 #include <asm/setup.h>
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
86 #ifdef CONFIG_CHR_DEV_SG
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory
;
99 extern int sysctl_overcommit_ratio
;
100 extern int max_threads
;
101 extern int suid_dumpable
;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid
;
104 extern char core_pattern
[];
105 extern unsigned int core_pipe_limit
;
108 extern int pid_max_min
, pid_max_max
;
109 extern int percpu_pagelist_fraction
;
110 extern int compat_log
;
111 extern int latencytop_enabled
;
112 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
114 extern int sysctl_nr_trim_pages
;
117 extern int blk_iopoll_enabled
;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty
= 60;
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
;
160 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
161 extern int unaligned_enabled
;
165 extern int unaligned_dump_stack
;
168 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
169 extern int no_unaligned_warning
;
172 #ifdef CONFIG_PROC_SYSCTL
173 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
174 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
175 static int proc_taint(struct ctl_table
*table
, int write
,
176 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
180 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
181 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
184 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
185 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
186 #ifdef CONFIG_COREDUMP
187 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
188 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
191 #ifdef CONFIG_MAGIC_SYSRQ
192 /* Note: sysrq code uses it's own private copy */
193 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
195 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
196 void __user
*buffer
, size_t *lenp
,
201 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
206 sysrq_toggle_support(__sysrq_enabled
);
213 static struct ctl_table kern_table
[];
214 static struct ctl_table vm_table
[];
215 static struct ctl_table fs_table
[];
216 static struct ctl_table debug_table
[];
217 static struct ctl_table dev_table
[];
218 extern struct ctl_table random_table
[];
220 extern struct ctl_table epoll_table
[];
223 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
224 int sysctl_legacy_va_layout
;
227 /* The default sysctl tables: */
229 static struct ctl_table sysctl_base_table
[] = {
231 .procname
= "kernel",
248 .child
= debug_table
,
258 #ifdef CONFIG_SCHED_DEBUG
259 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
260 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
261 static int min_wakeup_granularity_ns
; /* 0 usecs */
262 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
264 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
265 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
266 #endif /* CONFIG_SMP */
267 #endif /* CONFIG_SCHED_DEBUG */
269 #ifdef CONFIG_COMPACTION
270 static int min_extfrag_threshold
;
271 static int max_extfrag_threshold
= 1000;
274 static struct ctl_table kern_table
[] = {
276 .procname
= "sched_child_runs_first",
277 .data
= &sysctl_sched_child_runs_first
,
278 .maxlen
= sizeof(unsigned int),
280 .proc_handler
= proc_dointvec
,
282 #ifdef CONFIG_SCHED_DEBUG
284 .procname
= "sched_min_granularity_ns",
285 .data
= &sysctl_sched_min_granularity
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= sched_proc_update_handler
,
289 .extra1
= &min_sched_granularity_ns
,
290 .extra2
= &max_sched_granularity_ns
,
293 .procname
= "sched_latency_ns",
294 .data
= &sysctl_sched_latency
,
295 .maxlen
= sizeof(unsigned int),
297 .proc_handler
= sched_proc_update_handler
,
298 .extra1
= &min_sched_granularity_ns
,
299 .extra2
= &max_sched_granularity_ns
,
302 .procname
= "sched_wakeup_granularity_ns",
303 .data
= &sysctl_sched_wakeup_granularity
,
304 .maxlen
= sizeof(unsigned int),
306 .proc_handler
= sched_proc_update_handler
,
307 .extra1
= &min_wakeup_granularity_ns
,
308 .extra2
= &max_wakeup_granularity_ns
,
312 .procname
= "sched_tunable_scaling",
313 .data
= &sysctl_sched_tunable_scaling
,
314 .maxlen
= sizeof(enum sched_tunable_scaling
),
316 .proc_handler
= sched_proc_update_handler
,
317 .extra1
= &min_sched_tunable_scaling
,
318 .extra2
= &max_sched_tunable_scaling
,
321 .procname
= "sched_migration_cost_ns",
322 .data
= &sysctl_sched_migration_cost
,
323 .maxlen
= sizeof(unsigned int),
325 .proc_handler
= proc_dointvec
,
328 .procname
= "sched_nr_migrate",
329 .data
= &sysctl_sched_nr_migrate
,
330 .maxlen
= sizeof(unsigned int),
332 .proc_handler
= proc_dointvec
,
335 .procname
= "sched_time_avg_ms",
336 .data
= &sysctl_sched_time_avg
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= proc_dointvec
,
342 .procname
= "sched_shares_window_ns",
343 .data
= &sysctl_sched_shares_window
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= proc_dointvec
,
349 .procname
= "timer_migration",
350 .data
= &sysctl_timer_migration
,
351 .maxlen
= sizeof(unsigned int),
353 .proc_handler
= proc_dointvec_minmax
,
357 #endif /* CONFIG_SMP */
358 #ifdef CONFIG_NUMA_BALANCING
360 .procname
= "numa_balancing_scan_delay_ms",
361 .data
= &sysctl_numa_balancing_scan_delay
,
362 .maxlen
= sizeof(unsigned int),
364 .proc_handler
= proc_dointvec
,
367 .procname
= "numa_balancing_scan_period_min_ms",
368 .data
= &sysctl_numa_balancing_scan_period_min
,
369 .maxlen
= sizeof(unsigned int),
371 .proc_handler
= proc_dointvec
,
374 .procname
= "numa_balancing_scan_period_reset",
375 .data
= &sysctl_numa_balancing_scan_period_reset
,
376 .maxlen
= sizeof(unsigned int),
378 .proc_handler
= proc_dointvec
,
381 .procname
= "numa_balancing_scan_period_max_ms",
382 .data
= &sysctl_numa_balancing_scan_period_max
,
383 .maxlen
= sizeof(unsigned int),
385 .proc_handler
= proc_dointvec
,
388 .procname
= "numa_balancing_scan_size_mb",
389 .data
= &sysctl_numa_balancing_scan_size
,
390 .maxlen
= sizeof(unsigned int),
392 .proc_handler
= proc_dointvec
,
394 #endif /* CONFIG_NUMA_BALANCING */
395 #endif /* CONFIG_SCHED_DEBUG */
397 .procname
= "sched_rt_period_us",
398 .data
= &sysctl_sched_rt_period
,
399 .maxlen
= sizeof(unsigned int),
401 .proc_handler
= sched_rt_handler
,
404 .procname
= "sched_rt_runtime_us",
405 .data
= &sysctl_sched_rt_runtime
,
406 .maxlen
= sizeof(int),
408 .proc_handler
= sched_rt_handler
,
411 .procname
= "sched_rr_timeslice_ms",
412 .data
= &sched_rr_timeslice
,
413 .maxlen
= sizeof(int),
415 .proc_handler
= sched_rr_handler
,
417 #ifdef CONFIG_SCHED_AUTOGROUP
419 .procname
= "sched_autogroup_enabled",
420 .data
= &sysctl_sched_autogroup_enabled
,
421 .maxlen
= sizeof(unsigned int),
423 .proc_handler
= proc_dointvec_minmax
,
428 #ifdef CONFIG_CFS_BANDWIDTH
430 .procname
= "sched_cfs_bandwidth_slice_us",
431 .data
= &sysctl_sched_cfs_bandwidth_slice
,
432 .maxlen
= sizeof(unsigned int),
434 .proc_handler
= proc_dointvec_minmax
,
438 #ifdef CONFIG_PROVE_LOCKING
440 .procname
= "prove_locking",
441 .data
= &prove_locking
,
442 .maxlen
= sizeof(int),
444 .proc_handler
= proc_dointvec
,
447 #ifdef CONFIG_LOCK_STAT
449 .procname
= "lock_stat",
451 .maxlen
= sizeof(int),
453 .proc_handler
= proc_dointvec
,
458 .data
= &panic_timeout
,
459 .maxlen
= sizeof(int),
461 .proc_handler
= proc_dointvec
,
463 #ifdef CONFIG_COREDUMP
465 .procname
= "core_uses_pid",
466 .data
= &core_uses_pid
,
467 .maxlen
= sizeof(int),
469 .proc_handler
= proc_dointvec
,
472 .procname
= "core_pattern",
473 .data
= core_pattern
,
474 .maxlen
= CORENAME_MAX_SIZE
,
476 .proc_handler
= proc_dostring_coredump
,
479 .procname
= "core_pipe_limit",
480 .data
= &core_pipe_limit
,
481 .maxlen
= sizeof(unsigned int),
483 .proc_handler
= proc_dointvec
,
486 #ifdef CONFIG_PROC_SYSCTL
488 .procname
= "tainted",
489 .maxlen
= sizeof(long),
491 .proc_handler
= proc_taint
,
494 #ifdef CONFIG_LATENCYTOP
496 .procname
= "latencytop",
497 .data
= &latencytop_enabled
,
498 .maxlen
= sizeof(int),
500 .proc_handler
= proc_dointvec
,
503 #ifdef CONFIG_BLK_DEV_INITRD
505 .procname
= "real-root-dev",
506 .data
= &real_root_dev
,
507 .maxlen
= sizeof(int),
509 .proc_handler
= proc_dointvec
,
513 .procname
= "print-fatal-signals",
514 .data
= &print_fatal_signals
,
515 .maxlen
= sizeof(int),
517 .proc_handler
= proc_dointvec
,
521 .procname
= "reboot-cmd",
522 .data
= reboot_command
,
525 .proc_handler
= proc_dostring
,
528 .procname
= "stop-a",
529 .data
= &stop_a_enabled
,
530 .maxlen
= sizeof (int),
532 .proc_handler
= proc_dointvec
,
535 .procname
= "scons-poweroff",
536 .data
= &scons_pwroff
,
537 .maxlen
= sizeof (int),
539 .proc_handler
= proc_dointvec
,
542 #ifdef CONFIG_SPARC64
544 .procname
= "tsb-ratio",
545 .data
= &sysctl_tsb_ratio
,
546 .maxlen
= sizeof (int),
548 .proc_handler
= proc_dointvec
,
553 .procname
= "soft-power",
554 .data
= &pwrsw_enabled
,
555 .maxlen
= sizeof (int),
557 .proc_handler
= proc_dointvec
,
560 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
562 .procname
= "unaligned-trap",
563 .data
= &unaligned_enabled
,
564 .maxlen
= sizeof (int),
566 .proc_handler
= proc_dointvec
,
570 .procname
= "ctrl-alt-del",
572 .maxlen
= sizeof(int),
574 .proc_handler
= proc_dointvec
,
576 #ifdef CONFIG_FUNCTION_TRACER
578 .procname
= "ftrace_enabled",
579 .data
= &ftrace_enabled
,
580 .maxlen
= sizeof(int),
582 .proc_handler
= ftrace_enable_sysctl
,
585 #ifdef CONFIG_STACK_TRACER
587 .procname
= "stack_tracer_enabled",
588 .data
= &stack_tracer_enabled
,
589 .maxlen
= sizeof(int),
591 .proc_handler
= stack_trace_sysctl
,
594 #ifdef CONFIG_TRACING
596 .procname
= "ftrace_dump_on_oops",
597 .data
= &ftrace_dump_on_oops
,
598 .maxlen
= sizeof(int),
600 .proc_handler
= proc_dointvec
,
603 .procname
= "traceoff_on_warning",
604 .data
= &__disable_trace_on_warning
,
605 .maxlen
= sizeof(__disable_trace_on_warning
),
607 .proc_handler
= proc_dointvec
,
610 #ifdef CONFIG_MODULES
612 .procname
= "modprobe",
613 .data
= &modprobe_path
,
614 .maxlen
= KMOD_PATH_LEN
,
616 .proc_handler
= proc_dostring
,
619 .procname
= "modules_disabled",
620 .data
= &modules_disabled
,
621 .maxlen
= sizeof(int),
623 /* only handle a transition from default "0" to "1" */
624 .proc_handler
= proc_dointvec_minmax
,
631 .procname
= "hotplug",
632 .data
= &uevent_helper
,
633 .maxlen
= UEVENT_HELPER_PATH_LEN
,
635 .proc_handler
= proc_dostring
,
638 #ifdef CONFIG_CHR_DEV_SG
640 .procname
= "sg-big-buff",
641 .data
= &sg_big_buff
,
642 .maxlen
= sizeof (int),
644 .proc_handler
= proc_dointvec
,
647 #ifdef CONFIG_BSD_PROCESS_ACCT
651 .maxlen
= 3*sizeof(int),
653 .proc_handler
= proc_dointvec
,
656 #ifdef CONFIG_MAGIC_SYSRQ
659 .data
= &__sysrq_enabled
,
660 .maxlen
= sizeof (int),
662 .proc_handler
= sysrq_sysctl_handler
,
665 #ifdef CONFIG_PROC_SYSCTL
667 .procname
= "cad_pid",
669 .maxlen
= sizeof (int),
671 .proc_handler
= proc_do_cad_pid
,
675 .procname
= "threads-max",
676 .data
= &max_threads
,
677 .maxlen
= sizeof(int),
679 .proc_handler
= proc_dointvec
,
682 .procname
= "random",
684 .child
= random_table
,
687 .procname
= "usermodehelper",
689 .child
= usermodehelper_table
,
692 .procname
= "overflowuid",
693 .data
= &overflowuid
,
694 .maxlen
= sizeof(int),
696 .proc_handler
= proc_dointvec_minmax
,
697 .extra1
= &minolduid
,
698 .extra2
= &maxolduid
,
701 .procname
= "overflowgid",
702 .data
= &overflowgid
,
703 .maxlen
= sizeof(int),
705 .proc_handler
= proc_dointvec_minmax
,
706 .extra1
= &minolduid
,
707 .extra2
= &maxolduid
,
710 #ifdef CONFIG_MATHEMU
712 .procname
= "ieee_emulation_warnings",
713 .data
= &sysctl_ieee_emulation_warnings
,
714 .maxlen
= sizeof(int),
716 .proc_handler
= proc_dointvec
,
720 .procname
= "userprocess_debug",
721 .data
= &show_unhandled_signals
,
722 .maxlen
= sizeof(int),
724 .proc_handler
= proc_dointvec
,
728 .procname
= "pid_max",
730 .maxlen
= sizeof (int),
732 .proc_handler
= proc_dointvec_minmax
,
733 .extra1
= &pid_max_min
,
734 .extra2
= &pid_max_max
,
737 .procname
= "panic_on_oops",
738 .data
= &panic_on_oops
,
739 .maxlen
= sizeof(int),
741 .proc_handler
= proc_dointvec
,
743 #if defined CONFIG_PRINTK
745 .procname
= "printk",
746 .data
= &console_loglevel
,
747 .maxlen
= 4*sizeof(int),
749 .proc_handler
= proc_dointvec
,
752 .procname
= "printk_ratelimit",
753 .data
= &printk_ratelimit_state
.interval
,
754 .maxlen
= sizeof(int),
756 .proc_handler
= proc_dointvec_jiffies
,
759 .procname
= "printk_ratelimit_burst",
760 .data
= &printk_ratelimit_state
.burst
,
761 .maxlen
= sizeof(int),
763 .proc_handler
= proc_dointvec
,
766 .procname
= "printk_delay",
767 .data
= &printk_delay_msec
,
768 .maxlen
= sizeof(int),
770 .proc_handler
= proc_dointvec_minmax
,
772 .extra2
= &ten_thousand
,
775 .procname
= "dmesg_restrict",
776 .data
= &dmesg_restrict
,
777 .maxlen
= sizeof(int),
779 .proc_handler
= proc_dointvec_minmax_sysadmin
,
784 .procname
= "kptr_restrict",
785 .data
= &kptr_restrict
,
786 .maxlen
= sizeof(int),
788 .proc_handler
= proc_dointvec_minmax_sysadmin
,
794 .procname
= "ngroups_max",
795 .data
= &ngroups_max
,
796 .maxlen
= sizeof (int),
798 .proc_handler
= proc_dointvec
,
801 .procname
= "cap_last_cap",
802 .data
= (void *)&cap_last_cap
,
803 .maxlen
= sizeof(int),
805 .proc_handler
= proc_dointvec
,
807 #if defined(CONFIG_LOCKUP_DETECTOR)
809 .procname
= "watchdog",
810 .data
= &watchdog_user_enabled
,
811 .maxlen
= sizeof (int),
813 .proc_handler
= proc_dowatchdog
,
818 .procname
= "watchdog_thresh",
819 .data
= &watchdog_thresh
,
820 .maxlen
= sizeof(int),
822 .proc_handler
= proc_dowatchdog
,
827 .procname
= "softlockup_panic",
828 .data
= &softlockup_panic
,
829 .maxlen
= sizeof(int),
831 .proc_handler
= proc_dointvec_minmax
,
836 .procname
= "nmi_watchdog",
837 .data
= &watchdog_user_enabled
,
838 .maxlen
= sizeof (int),
840 .proc_handler
= proc_dowatchdog
,
845 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
847 .procname
= "unknown_nmi_panic",
848 .data
= &unknown_nmi_panic
,
849 .maxlen
= sizeof (int),
851 .proc_handler
= proc_dointvec
,
854 #if defined(CONFIG_X86)
856 .procname
= "panic_on_unrecovered_nmi",
857 .data
= &panic_on_unrecovered_nmi
,
858 .maxlen
= sizeof(int),
860 .proc_handler
= proc_dointvec
,
863 .procname
= "panic_on_io_nmi",
864 .data
= &panic_on_io_nmi
,
865 .maxlen
= sizeof(int),
867 .proc_handler
= proc_dointvec
,
869 #ifdef CONFIG_DEBUG_STACKOVERFLOW
871 .procname
= "panic_on_stackoverflow",
872 .data
= &sysctl_panic_on_stackoverflow
,
873 .maxlen
= sizeof(int),
875 .proc_handler
= proc_dointvec
,
879 .procname
= "bootloader_type",
880 .data
= &bootloader_type
,
881 .maxlen
= sizeof (int),
883 .proc_handler
= proc_dointvec
,
886 .procname
= "bootloader_version",
887 .data
= &bootloader_version
,
888 .maxlen
= sizeof (int),
890 .proc_handler
= proc_dointvec
,
893 .procname
= "kstack_depth_to_print",
894 .data
= &kstack_depth_to_print
,
895 .maxlen
= sizeof(int),
897 .proc_handler
= proc_dointvec
,
900 .procname
= "io_delay_type",
901 .data
= &io_delay_type
,
902 .maxlen
= sizeof(int),
904 .proc_handler
= proc_dointvec
,
907 #if defined(CONFIG_MMU)
909 .procname
= "randomize_va_space",
910 .data
= &randomize_va_space
,
911 .maxlen
= sizeof(int),
913 .proc_handler
= proc_dointvec
,
916 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
918 .procname
= "spin_retry",
920 .maxlen
= sizeof (int),
922 .proc_handler
= proc_dointvec
,
925 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
927 .procname
= "acpi_video_flags",
928 .data
= &acpi_realmode_flags
,
929 .maxlen
= sizeof (unsigned long),
931 .proc_handler
= proc_doulongvec_minmax
,
934 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
936 .procname
= "ignore-unaligned-usertrap",
937 .data
= &no_unaligned_warning
,
938 .maxlen
= sizeof (int),
940 .proc_handler
= proc_dointvec
,
945 .procname
= "unaligned-dump-stack",
946 .data
= &unaligned_dump_stack
,
947 .maxlen
= sizeof (int),
949 .proc_handler
= proc_dointvec
,
952 #ifdef CONFIG_DETECT_HUNG_TASK
954 .procname
= "hung_task_panic",
955 .data
= &sysctl_hung_task_panic
,
956 .maxlen
= sizeof(int),
958 .proc_handler
= proc_dointvec_minmax
,
963 .procname
= "hung_task_check_count",
964 .data
= &sysctl_hung_task_check_count
,
965 .maxlen
= sizeof(unsigned long),
967 .proc_handler
= proc_doulongvec_minmax
,
970 .procname
= "hung_task_timeout_secs",
971 .data
= &sysctl_hung_task_timeout_secs
,
972 .maxlen
= sizeof(unsigned long),
974 .proc_handler
= proc_dohung_task_timeout_secs
,
977 .procname
= "hung_task_warnings",
978 .data
= &sysctl_hung_task_warnings
,
979 .maxlen
= sizeof(unsigned long),
981 .proc_handler
= proc_doulongvec_minmax
,
986 .procname
= "compat-log",
988 .maxlen
= sizeof (int),
990 .proc_handler
= proc_dointvec
,
993 #ifdef CONFIG_RT_MUTEXES
995 .procname
= "max_lock_depth",
996 .data
= &max_lock_depth
,
997 .maxlen
= sizeof(int),
999 .proc_handler
= proc_dointvec
,
1003 .procname
= "poweroff_cmd",
1004 .data
= &poweroff_cmd
,
1005 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1007 .proc_handler
= proc_dostring
,
1013 .child
= key_sysctls
,
1016 #ifdef CONFIG_RCU_TORTURE_TEST
1018 .procname
= "rcutorture_runnable",
1019 .data
= &rcutorture_runnable
,
1020 .maxlen
= sizeof(int),
1022 .proc_handler
= proc_dointvec
,
1025 #ifdef CONFIG_PERF_EVENTS
1027 * User-space scripts rely on the existence of this file
1028 * as a feature check for perf_events being enabled.
1030 * So it's an ABI, do not remove!
1033 .procname
= "perf_event_paranoid",
1034 .data
= &sysctl_perf_event_paranoid
,
1035 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1037 .proc_handler
= proc_dointvec
,
1040 .procname
= "perf_event_mlock_kb",
1041 .data
= &sysctl_perf_event_mlock
,
1042 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1044 .proc_handler
= proc_dointvec
,
1047 .procname
= "perf_event_max_sample_rate",
1048 .data
= &sysctl_perf_event_sample_rate
,
1049 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1051 .proc_handler
= perf_proc_update_handler
,
1055 .procname
= "perf_cpu_time_max_percent",
1056 .data
= &sysctl_perf_cpu_time_max_percent
,
1057 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1059 .proc_handler
= perf_cpu_time_max_percent_handler
,
1061 .extra2
= &one_hundred
,
1064 #ifdef CONFIG_KMEMCHECK
1066 .procname
= "kmemcheck",
1067 .data
= &kmemcheck_enabled
,
1068 .maxlen
= sizeof(int),
1070 .proc_handler
= proc_dointvec
,
1075 .procname
= "blk_iopoll",
1076 .data
= &blk_iopoll_enabled
,
1077 .maxlen
= sizeof(int),
1079 .proc_handler
= proc_dointvec
,
1085 static struct ctl_table vm_table
[] = {
1087 .procname
= "overcommit_memory",
1088 .data
= &sysctl_overcommit_memory
,
1089 .maxlen
= sizeof(sysctl_overcommit_memory
),
1091 .proc_handler
= proc_dointvec_minmax
,
1096 .procname
= "panic_on_oom",
1097 .data
= &sysctl_panic_on_oom
,
1098 .maxlen
= sizeof(sysctl_panic_on_oom
),
1100 .proc_handler
= proc_dointvec_minmax
,
1105 .procname
= "oom_kill_allocating_task",
1106 .data
= &sysctl_oom_kill_allocating_task
,
1107 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1109 .proc_handler
= proc_dointvec
,
1112 .procname
= "oom_dump_tasks",
1113 .data
= &sysctl_oom_dump_tasks
,
1114 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1116 .proc_handler
= proc_dointvec
,
1119 .procname
= "overcommit_ratio",
1120 .data
= &sysctl_overcommit_ratio
,
1121 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1123 .proc_handler
= proc_dointvec
,
1126 .procname
= "page-cluster",
1127 .data
= &page_cluster
,
1128 .maxlen
= sizeof(int),
1130 .proc_handler
= proc_dointvec_minmax
,
1134 .procname
= "dirty_background_ratio",
1135 .data
= &dirty_background_ratio
,
1136 .maxlen
= sizeof(dirty_background_ratio
),
1138 .proc_handler
= dirty_background_ratio_handler
,
1140 .extra2
= &one_hundred
,
1143 .procname
= "dirty_background_bytes",
1144 .data
= &dirty_background_bytes
,
1145 .maxlen
= sizeof(dirty_background_bytes
),
1147 .proc_handler
= dirty_background_bytes_handler
,
1151 .procname
= "dirty_ratio",
1152 .data
= &vm_dirty_ratio
,
1153 .maxlen
= sizeof(vm_dirty_ratio
),
1155 .proc_handler
= dirty_ratio_handler
,
1157 .extra2
= &one_hundred
,
1160 .procname
= "dirty_bytes",
1161 .data
= &vm_dirty_bytes
,
1162 .maxlen
= sizeof(vm_dirty_bytes
),
1164 .proc_handler
= dirty_bytes_handler
,
1165 .extra1
= &dirty_bytes_min
,
1168 .procname
= "dirty_writeback_centisecs",
1169 .data
= &dirty_writeback_interval
,
1170 .maxlen
= sizeof(dirty_writeback_interval
),
1172 .proc_handler
= dirty_writeback_centisecs_handler
,
1175 .procname
= "dirty_expire_centisecs",
1176 .data
= &dirty_expire_interval
,
1177 .maxlen
= sizeof(dirty_expire_interval
),
1179 .proc_handler
= proc_dointvec_minmax
,
1183 .procname
= "nr_pdflush_threads",
1184 .mode
= 0444 /* read-only */,
1185 .proc_handler
= pdflush_proc_obsolete
,
1188 .procname
= "swappiness",
1189 .data
= &vm_swappiness
,
1190 .maxlen
= sizeof(vm_swappiness
),
1192 .proc_handler
= proc_dointvec_minmax
,
1194 .extra2
= &one_hundred
,
1196 #ifdef CONFIG_HUGETLB_PAGE
1198 .procname
= "nr_hugepages",
1200 .maxlen
= sizeof(unsigned long),
1202 .proc_handler
= hugetlb_sysctl_handler
,
1203 .extra1
= (void *)&hugetlb_zero
,
1204 .extra2
= (void *)&hugetlb_infinity
,
1208 .procname
= "nr_hugepages_mempolicy",
1210 .maxlen
= sizeof(unsigned long),
1212 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1213 .extra1
= (void *)&hugetlb_zero
,
1214 .extra2
= (void *)&hugetlb_infinity
,
1218 .procname
= "hugetlb_shm_group",
1219 .data
= &sysctl_hugetlb_shm_group
,
1220 .maxlen
= sizeof(gid_t
),
1222 .proc_handler
= proc_dointvec
,
1225 .procname
= "hugepages_treat_as_movable",
1226 .data
= &hugepages_treat_as_movable
,
1227 .maxlen
= sizeof(int),
1229 .proc_handler
= proc_dointvec
,
1232 .procname
= "nr_overcommit_hugepages",
1234 .maxlen
= sizeof(unsigned long),
1236 .proc_handler
= hugetlb_overcommit_handler
,
1237 .extra1
= (void *)&hugetlb_zero
,
1238 .extra2
= (void *)&hugetlb_infinity
,
1242 .procname
= "lowmem_reserve_ratio",
1243 .data
= &sysctl_lowmem_reserve_ratio
,
1244 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1246 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1249 .procname
= "drop_caches",
1250 .data
= &sysctl_drop_caches
,
1251 .maxlen
= sizeof(int),
1253 .proc_handler
= drop_caches_sysctl_handler
,
1257 #ifdef CONFIG_COMPACTION
1259 .procname
= "compact_memory",
1260 .data
= &sysctl_compact_memory
,
1261 .maxlen
= sizeof(int),
1263 .proc_handler
= sysctl_compaction_handler
,
1266 .procname
= "extfrag_threshold",
1267 .data
= &sysctl_extfrag_threshold
,
1268 .maxlen
= sizeof(int),
1270 .proc_handler
= sysctl_extfrag_handler
,
1271 .extra1
= &min_extfrag_threshold
,
1272 .extra2
= &max_extfrag_threshold
,
1275 #endif /* CONFIG_COMPACTION */
1277 .procname
= "min_free_kbytes",
1278 .data
= &min_free_kbytes
,
1279 .maxlen
= sizeof(min_free_kbytes
),
1281 .proc_handler
= min_free_kbytes_sysctl_handler
,
1285 .procname
= "percpu_pagelist_fraction",
1286 .data
= &percpu_pagelist_fraction
,
1287 .maxlen
= sizeof(percpu_pagelist_fraction
),
1289 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1290 .extra1
= &min_percpu_pagelist_fract
,
1294 .procname
= "max_map_count",
1295 .data
= &sysctl_max_map_count
,
1296 .maxlen
= sizeof(sysctl_max_map_count
),
1298 .proc_handler
= proc_dointvec_minmax
,
1303 .procname
= "nr_trim_pages",
1304 .data
= &sysctl_nr_trim_pages
,
1305 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1307 .proc_handler
= proc_dointvec_minmax
,
1312 .procname
= "laptop_mode",
1313 .data
= &laptop_mode
,
1314 .maxlen
= sizeof(laptop_mode
),
1316 .proc_handler
= proc_dointvec_jiffies
,
1319 .procname
= "block_dump",
1320 .data
= &block_dump
,
1321 .maxlen
= sizeof(block_dump
),
1323 .proc_handler
= proc_dointvec
,
1327 .procname
= "vfs_cache_pressure",
1328 .data
= &sysctl_vfs_cache_pressure
,
1329 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1331 .proc_handler
= proc_dointvec
,
1334 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1336 .procname
= "legacy_va_layout",
1337 .data
= &sysctl_legacy_va_layout
,
1338 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1340 .proc_handler
= proc_dointvec
,
1346 .procname
= "zone_reclaim_mode",
1347 .data
= &zone_reclaim_mode
,
1348 .maxlen
= sizeof(zone_reclaim_mode
),
1350 .proc_handler
= proc_dointvec
,
1354 .procname
= "min_unmapped_ratio",
1355 .data
= &sysctl_min_unmapped_ratio
,
1356 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1358 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1360 .extra2
= &one_hundred
,
1363 .procname
= "min_slab_ratio",
1364 .data
= &sysctl_min_slab_ratio
,
1365 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1367 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1369 .extra2
= &one_hundred
,
1374 .procname
= "stat_interval",
1375 .data
= &sysctl_stat_interval
,
1376 .maxlen
= sizeof(sysctl_stat_interval
),
1378 .proc_handler
= proc_dointvec_jiffies
,
1383 .procname
= "mmap_min_addr",
1384 .data
= &dac_mmap_min_addr
,
1385 .maxlen
= sizeof(unsigned long),
1387 .proc_handler
= mmap_min_addr_handler
,
1392 .procname
= "numa_zonelist_order",
1393 .data
= &numa_zonelist_order
,
1394 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1396 .proc_handler
= numa_zonelist_order_handler
,
1399 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1400 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1402 .procname
= "vdso_enabled",
1403 .data
= &vdso_enabled
,
1404 .maxlen
= sizeof(vdso_enabled
),
1406 .proc_handler
= proc_dointvec
,
1410 #ifdef CONFIG_HIGHMEM
1412 .procname
= "highmem_is_dirtyable",
1413 .data
= &vm_highmem_is_dirtyable
,
1414 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1416 .proc_handler
= proc_dointvec_minmax
,
1422 .procname
= "scan_unevictable_pages",
1423 .data
= &scan_unevictable_pages
,
1424 .maxlen
= sizeof(scan_unevictable_pages
),
1426 .proc_handler
= scan_unevictable_handler
,
1428 #ifdef CONFIG_MEMORY_FAILURE
1430 .procname
= "memory_failure_early_kill",
1431 .data
= &sysctl_memory_failure_early_kill
,
1432 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1434 .proc_handler
= proc_dointvec_minmax
,
1439 .procname
= "memory_failure_recovery",
1440 .data
= &sysctl_memory_failure_recovery
,
1441 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1443 .proc_handler
= proc_dointvec_minmax
,
1449 .procname
= "user_reserve_kbytes",
1450 .data
= &sysctl_user_reserve_kbytes
,
1451 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1453 .proc_handler
= proc_doulongvec_minmax
,
1456 .procname
= "admin_reserve_kbytes",
1457 .data
= &sysctl_admin_reserve_kbytes
,
1458 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1460 .proc_handler
= proc_doulongvec_minmax
,
1465 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1466 static struct ctl_table binfmt_misc_table
[] = {
1471 static struct ctl_table fs_table
[] = {
1473 .procname
= "inode-nr",
1474 .data
= &inodes_stat
,
1475 .maxlen
= 2*sizeof(long),
1477 .proc_handler
= proc_nr_inodes
,
1480 .procname
= "inode-state",
1481 .data
= &inodes_stat
,
1482 .maxlen
= 7*sizeof(long),
1484 .proc_handler
= proc_nr_inodes
,
1487 .procname
= "file-nr",
1488 .data
= &files_stat
,
1489 .maxlen
= sizeof(files_stat
),
1491 .proc_handler
= proc_nr_files
,
1494 .procname
= "file-max",
1495 .data
= &files_stat
.max_files
,
1496 .maxlen
= sizeof(files_stat
.max_files
),
1498 .proc_handler
= proc_doulongvec_minmax
,
1501 .procname
= "nr_open",
1502 .data
= &sysctl_nr_open
,
1503 .maxlen
= sizeof(int),
1505 .proc_handler
= proc_dointvec_minmax
,
1506 .extra1
= &sysctl_nr_open_min
,
1507 .extra2
= &sysctl_nr_open_max
,
1510 .procname
= "dentry-state",
1511 .data
= &dentry_stat
,
1512 .maxlen
= 6*sizeof(long),
1514 .proc_handler
= proc_nr_dentry
,
1517 .procname
= "overflowuid",
1518 .data
= &fs_overflowuid
,
1519 .maxlen
= sizeof(int),
1521 .proc_handler
= proc_dointvec_minmax
,
1522 .extra1
= &minolduid
,
1523 .extra2
= &maxolduid
,
1526 .procname
= "overflowgid",
1527 .data
= &fs_overflowgid
,
1528 .maxlen
= sizeof(int),
1530 .proc_handler
= proc_dointvec_minmax
,
1531 .extra1
= &minolduid
,
1532 .extra2
= &maxolduid
,
1534 #ifdef CONFIG_FILE_LOCKING
1536 .procname
= "leases-enable",
1537 .data
= &leases_enable
,
1538 .maxlen
= sizeof(int),
1540 .proc_handler
= proc_dointvec
,
1543 #ifdef CONFIG_DNOTIFY
1545 .procname
= "dir-notify-enable",
1546 .data
= &dir_notify_enable
,
1547 .maxlen
= sizeof(int),
1549 .proc_handler
= proc_dointvec
,
1553 #ifdef CONFIG_FILE_LOCKING
1555 .procname
= "lease-break-time",
1556 .data
= &lease_break_time
,
1557 .maxlen
= sizeof(int),
1559 .proc_handler
= proc_dointvec
,
1564 .procname
= "aio-nr",
1566 .maxlen
= sizeof(aio_nr
),
1568 .proc_handler
= proc_doulongvec_minmax
,
1571 .procname
= "aio-max-nr",
1572 .data
= &aio_max_nr
,
1573 .maxlen
= sizeof(aio_max_nr
),
1575 .proc_handler
= proc_doulongvec_minmax
,
1577 #endif /* CONFIG_AIO */
1578 #ifdef CONFIG_INOTIFY_USER
1580 .procname
= "inotify",
1582 .child
= inotify_table
,
1587 .procname
= "epoll",
1589 .child
= epoll_table
,
1594 .procname
= "protected_symlinks",
1595 .data
= &sysctl_protected_symlinks
,
1596 .maxlen
= sizeof(int),
1598 .proc_handler
= proc_dointvec_minmax
,
1603 .procname
= "protected_hardlinks",
1604 .data
= &sysctl_protected_hardlinks
,
1605 .maxlen
= sizeof(int),
1607 .proc_handler
= proc_dointvec_minmax
,
1612 .procname
= "suid_dumpable",
1613 .data
= &suid_dumpable
,
1614 .maxlen
= sizeof(int),
1616 .proc_handler
= proc_dointvec_minmax_coredump
,
1620 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1622 .procname
= "binfmt_misc",
1624 .child
= binfmt_misc_table
,
1628 .procname
= "pipe-max-size",
1629 .data
= &pipe_max_size
,
1630 .maxlen
= sizeof(int),
1632 .proc_handler
= &pipe_proc_fn
,
1633 .extra1
= &pipe_min_size
,
1638 static struct ctl_table debug_table
[] = {
1639 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1641 .procname
= "exception-trace",
1642 .data
= &show_unhandled_signals
,
1643 .maxlen
= sizeof(int),
1645 .proc_handler
= proc_dointvec
1648 #if defined(CONFIG_OPTPROBES)
1650 .procname
= "kprobes-optimization",
1651 .data
= &sysctl_kprobes_optimization
,
1652 .maxlen
= sizeof(int),
1654 .proc_handler
= proc_kprobes_optimization_handler
,
1662 static struct ctl_table dev_table
[] = {
1666 int __init
sysctl_init(void)
1668 struct ctl_table_header
*hdr
;
1670 hdr
= register_sysctl_table(sysctl_base_table
);
1671 kmemleak_not_leak(hdr
);
1675 #endif /* CONFIG_SYSCTL */
1681 #ifdef CONFIG_PROC_SYSCTL
1683 static int _proc_do_string(void* data
, int maxlen
, int write
,
1684 void __user
*buffer
,
1685 size_t *lenp
, loff_t
*ppos
)
1691 if (!data
|| !maxlen
|| !*lenp
) {
1699 while (len
< *lenp
) {
1700 if (get_user(c
, p
++))
1702 if (c
== 0 || c
== '\n')
1708 if(copy_from_user(data
, buffer
, len
))
1710 ((char *) data
)[len
] = 0;
1728 if(copy_to_user(buffer
, data
, len
))
1731 if(put_user('\n', ((char __user
*) buffer
) + len
))
1742 * proc_dostring - read a string sysctl
1743 * @table: the sysctl table
1744 * @write: %TRUE if this is a write to the sysctl file
1745 * @buffer: the user buffer
1746 * @lenp: the size of the user buffer
1747 * @ppos: file position
1749 * Reads/writes a string from/to the user buffer. If the kernel
1750 * buffer provided is not large enough to hold the string, the
1751 * string is truncated. The copied string is %NULL-terminated.
1752 * If the string is being read by the user process, it is copied
1753 * and a newline '\n' is added. It is truncated if the buffer is
1756 * Returns 0 on success.
1758 int proc_dostring(struct ctl_table
*table
, int write
,
1759 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1761 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1762 buffer
, lenp
, ppos
);
1765 static size_t proc_skip_spaces(char **buf
)
1768 char *tmp
= skip_spaces(*buf
);
1774 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1784 #define TMPBUFLEN 22
1786 * proc_get_long - reads an ASCII formatted integer from a user buffer
1788 * @buf: a kernel buffer
1789 * @size: size of the kernel buffer
1790 * @val: this is where the number will be stored
1791 * @neg: set to %TRUE if number is negative
1792 * @perm_tr: a vector which contains the allowed trailers
1793 * @perm_tr_len: size of the perm_tr vector
1794 * @tr: pointer to store the trailer character
1796 * In case of success %0 is returned and @buf and @size are updated with
1797 * the amount of bytes read. If @tr is non-NULL and a trailing
1798 * character exists (size is non-zero after returning from this
1799 * function), @tr is updated with the trailing character.
1801 static int proc_get_long(char **buf
, size_t *size
,
1802 unsigned long *val
, bool *neg
,
1803 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1806 char *p
, tmp
[TMPBUFLEN
];
1812 if (len
> TMPBUFLEN
- 1)
1813 len
= TMPBUFLEN
- 1;
1815 memcpy(tmp
, *buf
, len
);
1819 if (*p
== '-' && *size
> 1) {
1827 *val
= simple_strtoul(p
, &p
, 0);
1831 /* We don't know if the next char is whitespace thus we may accept
1832 * invalid integers (e.g. 1234...a) or two integers instead of one
1833 * (e.g. 123...1). So lets not allow such large numbers. */
1834 if (len
== TMPBUFLEN
- 1)
1837 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1840 if (tr
&& (len
< *size
))
1850 * proc_put_long - converts an integer to a decimal ASCII formatted string
1852 * @buf: the user buffer
1853 * @size: the size of the user buffer
1854 * @val: the integer to be converted
1855 * @neg: sign of the number, %TRUE for negative
1857 * In case of success %0 is returned and @buf and @size are updated with
1858 * the amount of bytes written.
1860 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1864 char tmp
[TMPBUFLEN
], *p
= tmp
;
1866 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1870 if (copy_to_user(*buf
, tmp
, len
))
1878 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1881 char __user
**buffer
= (char __user
**)buf
;
1882 if (put_user(c
, *buffer
))
1884 (*size
)--, (*buffer
)++;
1890 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1892 int write
, void *data
)
1895 *valp
= *negp
? -*lvalp
: *lvalp
;
1900 *lvalp
= (unsigned long)-val
;
1903 *lvalp
= (unsigned long)val
;
1909 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1911 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1912 int write
, void __user
*buffer
,
1913 size_t *lenp
, loff_t
*ppos
,
1914 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1915 int write
, void *data
),
1918 int *i
, vleft
, first
= 1, err
= 0;
1919 unsigned long page
= 0;
1923 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1928 i
= (int *) tbl_data
;
1929 vleft
= table
->maxlen
/ sizeof(*i
);
1933 conv
= do_proc_dointvec_conv
;
1936 if (left
> PAGE_SIZE
- 1)
1937 left
= PAGE_SIZE
- 1;
1938 page
= __get_free_page(GFP_TEMPORARY
);
1939 kbuf
= (char *) page
;
1942 if (copy_from_user(kbuf
, buffer
, left
)) {
1949 for (; left
&& vleft
--; i
++, first
=0) {
1954 left
-= proc_skip_spaces(&kbuf
);
1958 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1960 sizeof(proc_wspace_sep
), NULL
);
1963 if (conv(&neg
, &lval
, i
, 1, data
)) {
1968 if (conv(&neg
, &lval
, i
, 0, data
)) {
1973 err
= proc_put_char(&buffer
, &left
, '\t');
1976 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1982 if (!write
&& !first
&& left
&& !err
)
1983 err
= proc_put_char(&buffer
, &left
, '\n');
1984 if (write
&& !err
&& left
)
1985 left
-= proc_skip_spaces(&kbuf
);
1990 return err
? : -EINVAL
;
1997 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1998 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1999 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2000 int write
, void *data
),
2003 return __do_proc_dointvec(table
->data
, table
, write
,
2004 buffer
, lenp
, ppos
, conv
, data
);
2008 * proc_dointvec - read a vector of integers
2009 * @table: the sysctl table
2010 * @write: %TRUE if this is a write to the sysctl file
2011 * @buffer: the user buffer
2012 * @lenp: the size of the user buffer
2013 * @ppos: file position
2015 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2016 * values from/to the user buffer, treated as an ASCII string.
2018 * Returns 0 on success.
2020 int proc_dointvec(struct ctl_table
*table
, int write
,
2021 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2023 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2028 * Taint values can only be increased
2029 * This means we can safely use a temporary.
2031 static int proc_taint(struct ctl_table
*table
, int write
,
2032 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2035 unsigned long tmptaint
= get_taint();
2038 if (write
&& !capable(CAP_SYS_ADMIN
))
2043 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2049 * Poor man's atomic or. Not worth adding a primitive
2050 * to everyone's atomic.h for this
2053 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2054 if ((tmptaint
>> i
) & 1)
2055 add_taint(i
, LOCKDEP_STILL_OK
);
2062 #ifdef CONFIG_PRINTK
2063 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2064 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2066 if (write
&& !capable(CAP_SYS_ADMIN
))
2069 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2073 struct do_proc_dointvec_minmax_conv_param
{
2078 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2080 int write
, void *data
)
2082 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2084 int val
= *negp
? -*lvalp
: *lvalp
;
2085 if ((param
->min
&& *param
->min
> val
) ||
2086 (param
->max
&& *param
->max
< val
))
2093 *lvalp
= (unsigned long)-val
;
2096 *lvalp
= (unsigned long)val
;
2103 * proc_dointvec_minmax - read a vector of integers with min/max values
2104 * @table: the sysctl table
2105 * @write: %TRUE if this is a write to the sysctl file
2106 * @buffer: the user buffer
2107 * @lenp: the size of the user buffer
2108 * @ppos: file position
2110 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2111 * values from/to the user buffer, treated as an ASCII string.
2113 * This routine will ensure the values are within the range specified by
2114 * table->extra1 (min) and table->extra2 (max).
2116 * Returns 0 on success.
2118 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2119 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2121 struct do_proc_dointvec_minmax_conv_param param
= {
2122 .min
= (int *) table
->extra1
,
2123 .max
= (int *) table
->extra2
,
2125 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2126 do_proc_dointvec_minmax_conv
, ¶m
);
2129 static void validate_coredump_safety(void)
2131 #ifdef CONFIG_COREDUMP
2132 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2133 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2134 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2135 "suid_dumpable=2. Pipe handler or fully qualified "\
2136 "core dump path required.\n");
2141 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2142 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2144 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2146 validate_coredump_safety();
2150 #ifdef CONFIG_COREDUMP
2151 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2152 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2154 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2156 validate_coredump_safety();
2161 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2162 void __user
*buffer
,
2163 size_t *lenp
, loff_t
*ppos
,
2164 unsigned long convmul
,
2165 unsigned long convdiv
)
2167 unsigned long *i
, *min
, *max
;
2168 int vleft
, first
= 1, err
= 0;
2169 unsigned long page
= 0;
2173 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2178 i
= (unsigned long *) data
;
2179 min
= (unsigned long *) table
->extra1
;
2180 max
= (unsigned long *) table
->extra2
;
2181 vleft
= table
->maxlen
/ sizeof(unsigned long);
2185 if (left
> PAGE_SIZE
- 1)
2186 left
= PAGE_SIZE
- 1;
2187 page
= __get_free_page(GFP_TEMPORARY
);
2188 kbuf
= (char *) page
;
2191 if (copy_from_user(kbuf
, buffer
, left
)) {
2198 for (; left
&& vleft
--; i
++, first
= 0) {
2204 left
-= proc_skip_spaces(&kbuf
);
2206 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2208 sizeof(proc_wspace_sep
), NULL
);
2213 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2217 val
= convdiv
* (*i
) / convmul
;
2219 err
= proc_put_char(&buffer
, &left
, '\t');
2220 err
= proc_put_long(&buffer
, &left
, val
, false);
2226 if (!write
&& !first
&& left
&& !err
)
2227 err
= proc_put_char(&buffer
, &left
, '\n');
2229 left
-= proc_skip_spaces(&kbuf
);
2234 return err
? : -EINVAL
;
2241 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2242 void __user
*buffer
,
2243 size_t *lenp
, loff_t
*ppos
,
2244 unsigned long convmul
,
2245 unsigned long convdiv
)
2247 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2248 buffer
, lenp
, ppos
, convmul
, convdiv
);
2252 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2253 * @table: the sysctl table
2254 * @write: %TRUE if this is a write to the sysctl file
2255 * @buffer: the user buffer
2256 * @lenp: the size of the user buffer
2257 * @ppos: file position
2259 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2260 * values from/to the user buffer, treated as an ASCII string.
2262 * This routine will ensure the values are within the range specified by
2263 * table->extra1 (min) and table->extra2 (max).
2265 * Returns 0 on success.
2267 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2268 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2270 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2274 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2275 * @table: the sysctl table
2276 * @write: %TRUE if this is a write to the sysctl file
2277 * @buffer: the user buffer
2278 * @lenp: the size of the user buffer
2279 * @ppos: file position
2281 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2282 * values from/to the user buffer, treated as an ASCII string. The values
2283 * are treated as milliseconds, and converted to jiffies when they are stored.
2285 * This routine will ensure the values are within the range specified by
2286 * table->extra1 (min) and table->extra2 (max).
2288 * Returns 0 on success.
2290 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2291 void __user
*buffer
,
2292 size_t *lenp
, loff_t
*ppos
)
2294 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2295 lenp
, ppos
, HZ
, 1000l);
2299 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2301 int write
, void *data
)
2304 if (*lvalp
> LONG_MAX
/ HZ
)
2306 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2312 lval
= (unsigned long)-val
;
2315 lval
= (unsigned long)val
;
2322 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2324 int write
, void *data
)
2327 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2329 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2335 lval
= (unsigned long)-val
;
2338 lval
= (unsigned long)val
;
2340 *lvalp
= jiffies_to_clock_t(lval
);
2345 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2347 int write
, void *data
)
2350 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2360 lval
= (unsigned long)-val
;
2363 lval
= (unsigned long)val
;
2365 *lvalp
= jiffies_to_msecs(lval
);
2371 * proc_dointvec_jiffies - read a vector of integers as seconds
2372 * @table: the sysctl table
2373 * @write: %TRUE if this is a write to the sysctl file
2374 * @buffer: the user buffer
2375 * @lenp: the size of the user buffer
2376 * @ppos: file position
2378 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2379 * values from/to the user buffer, treated as an ASCII string.
2380 * The values read are assumed to be in seconds, and are converted into
2383 * Returns 0 on success.
2385 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2386 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2388 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2389 do_proc_dointvec_jiffies_conv
,NULL
);
2393 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2394 * @table: the sysctl table
2395 * @write: %TRUE if this is a write to the sysctl file
2396 * @buffer: the user buffer
2397 * @lenp: the size of the user buffer
2398 * @ppos: pointer to the file position
2400 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2401 * values from/to the user buffer, treated as an ASCII string.
2402 * The values read are assumed to be in 1/USER_HZ seconds, and
2403 * are converted into jiffies.
2405 * Returns 0 on success.
2407 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2408 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2410 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2411 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2415 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2416 * @table: the sysctl table
2417 * @write: %TRUE if this is a write to the sysctl file
2418 * @buffer: the user buffer
2419 * @lenp: the size of the user buffer
2420 * @ppos: file position
2421 * @ppos: the current position in the file
2423 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2424 * values from/to the user buffer, treated as an ASCII string.
2425 * The values read are assumed to be in 1/1000 seconds, and
2426 * are converted into jiffies.
2428 * Returns 0 on success.
2430 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2431 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2433 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2434 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2437 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2438 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2440 struct pid
*new_pid
;
2444 tmp
= pid_vnr(cad_pid
);
2446 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2447 lenp
, ppos
, NULL
, NULL
);
2451 new_pid
= find_get_pid(tmp
);
2455 put_pid(xchg(&cad_pid
, new_pid
));
2460 * proc_do_large_bitmap - read/write from/to a large bitmap
2461 * @table: the sysctl table
2462 * @write: %TRUE if this is a write to the sysctl file
2463 * @buffer: the user buffer
2464 * @lenp: the size of the user buffer
2465 * @ppos: file position
2467 * The bitmap is stored at table->data and the bitmap length (in bits)
2470 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2471 * large bitmaps may be represented in a compact manner. Writing into
2472 * the file will clear the bitmap then update it with the given input.
2474 * Returns 0 on success.
2476 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2477 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2481 size_t left
= *lenp
;
2482 unsigned long bitmap_len
= table
->maxlen
;
2483 unsigned long *bitmap
= (unsigned long *) table
->data
;
2484 unsigned long *tmp_bitmap
= NULL
;
2485 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2487 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2493 unsigned long page
= 0;
2496 if (left
> PAGE_SIZE
- 1)
2497 left
= PAGE_SIZE
- 1;
2499 page
= __get_free_page(GFP_TEMPORARY
);
2500 kbuf
= (char *) page
;
2503 if (copy_from_user(kbuf
, buffer
, left
)) {
2509 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2515 proc_skip_char(&kbuf
, &left
, '\n');
2516 while (!err
&& left
) {
2517 unsigned long val_a
, val_b
;
2520 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2524 if (val_a
>= bitmap_len
|| neg
) {
2536 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2537 &neg
, tr_b
, sizeof(tr_b
),
2541 if (val_b
>= bitmap_len
|| neg
||
2552 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2554 proc_skip_char(&kbuf
, &left
, '\n');
2558 unsigned long bit_a
, bit_b
= 0;
2561 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2562 if (bit_a
>= bitmap_len
)
2564 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2568 err
= proc_put_char(&buffer
, &left
, ',');
2572 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2575 if (bit_a
!= bit_b
) {
2576 err
= proc_put_char(&buffer
, &left
, '-');
2579 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2587 err
= proc_put_char(&buffer
, &left
, '\n');
2593 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2595 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2607 #else /* CONFIG_PROC_SYSCTL */
2609 int proc_dostring(struct ctl_table
*table
, int write
,
2610 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2615 int proc_dointvec(struct ctl_table
*table
, int write
,
2616 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2621 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2622 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2627 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2628 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2633 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2634 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2639 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2640 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2645 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2646 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2651 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2652 void __user
*buffer
,
2653 size_t *lenp
, loff_t
*ppos
)
2659 #endif /* CONFIG_PROC_SYSCTL */
2662 * No sense putting this after each symbol definition, twice,
2663 * exception granted :-)
2665 EXPORT_SYMBOL(proc_dointvec
);
2666 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2667 EXPORT_SYMBOL(proc_dointvec_minmax
);
2668 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2669 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2670 EXPORT_SYMBOL(proc_dostring
);
2671 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2672 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);