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>
22 #include <linux/aio.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemcheck.h>
34 #include <linux/kmemleak.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/kexec.h>
68 #include <asm/uaccess.h>
69 #include <asm/processor.h>
73 #include <asm/stacktrace.h>
77 #include <asm/setup.h>
79 #ifdef CONFIG_BSD_PROCESS_ACCT
80 #include <linux/acct.h>
82 #ifdef CONFIG_RT_MUTEXES
83 #include <linux/rtmutex.h>
85 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
86 #include <linux/lockdep.h>
88 #ifdef CONFIG_CHR_DEV_SG
92 #ifdef CONFIG_LOCKUP_DETECTOR
93 #include <linux/nmi.h>
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
99 extern int suid_dumpable
;
100 #ifdef CONFIG_COREDUMP
101 extern int core_uses_pid
;
102 extern char core_pattern
[];
103 extern unsigned int core_pipe_limit
;
106 extern int pid_max_min
, pid_max_max
;
107 extern int percpu_pagelist_fraction
;
108 extern int compat_log
;
109 extern int latencytop_enabled
;
110 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
112 extern int sysctl_nr_trim_pages
;
115 /* Constants used for minimum and maximum */
116 #ifdef CONFIG_LOCKUP_DETECTOR
117 static int sixty
= 60;
120 static int __maybe_unused neg_one
= -1;
123 static int __maybe_unused one
= 1;
124 static int __maybe_unused two
= 2;
125 static int __maybe_unused four
= 4;
126 static unsigned long one_ul
= 1;
127 static int one_hundred
= 100;
129 static int ten_thousand
= 10000;
132 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
133 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
135 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
136 static int maxolduid
= 65535;
137 static int minolduid
;
139 static int ngroups_max
= NGROUPS_MAX
;
140 static const int cap_last_cap
= CAP_LAST_CAP
;
142 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
143 #ifdef CONFIG_DETECT_HUNG_TASK
144 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
147 #ifdef CONFIG_INOTIFY_USER
148 #include <linux/inotify.h>
154 extern int pwrsw_enabled
;
157 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
158 extern int unaligned_enabled
;
162 extern int unaligned_dump_stack
;
165 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
166 extern int no_unaligned_warning
;
169 #ifdef CONFIG_PROC_SYSCTL
171 #define SYSCTL_WRITES_LEGACY -1
172 #define SYSCTL_WRITES_WARN 0
173 #define SYSCTL_WRITES_STRICT 1
175 static int sysctl_writes_strict
= SYSCTL_WRITES_WARN
;
177 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
178 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
179 static int proc_taint(struct ctl_table
*table
, int write
,
180 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
184 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
185 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
188 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
189 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
190 #ifdef CONFIG_COREDUMP
191 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
192 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
195 #ifdef CONFIG_MAGIC_SYSRQ
196 /* Note: sysrq code uses it's own private copy */
197 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
199 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
200 void __user
*buffer
, size_t *lenp
,
205 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
210 sysrq_toggle_support(__sysrq_enabled
);
217 static struct ctl_table kern_table
[];
218 static struct ctl_table vm_table
[];
219 static struct ctl_table fs_table
[];
220 static struct ctl_table debug_table
[];
221 static struct ctl_table dev_table
[];
222 extern struct ctl_table random_table
[];
224 extern struct ctl_table epoll_table
[];
227 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
228 int sysctl_legacy_va_layout
;
231 /* The default sysctl tables: */
233 static struct ctl_table sysctl_base_table
[] = {
235 .procname
= "kernel",
252 .child
= debug_table
,
262 #ifdef CONFIG_SCHED_DEBUG
263 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
264 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
265 static int min_wakeup_granularity_ns
; /* 0 usecs */
266 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
268 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
269 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
270 #endif /* CONFIG_SMP */
271 #endif /* CONFIG_SCHED_DEBUG */
273 #ifdef CONFIG_COMPACTION
274 static int min_extfrag_threshold
;
275 static int max_extfrag_threshold
= 1000;
278 static struct ctl_table kern_table
[] = {
280 .procname
= "sched_child_runs_first",
281 .data
= &sysctl_sched_child_runs_first
,
282 .maxlen
= sizeof(unsigned int),
284 .proc_handler
= proc_dointvec
,
286 #ifdef CONFIG_SCHED_DEBUG
288 .procname
= "sched_min_granularity_ns",
289 .data
= &sysctl_sched_min_granularity
,
290 .maxlen
= sizeof(unsigned int),
292 .proc_handler
= sched_proc_update_handler
,
293 .extra1
= &min_sched_granularity_ns
,
294 .extra2
= &max_sched_granularity_ns
,
297 .procname
= "sched_latency_ns",
298 .data
= &sysctl_sched_latency
,
299 .maxlen
= sizeof(unsigned int),
301 .proc_handler
= sched_proc_update_handler
,
302 .extra1
= &min_sched_granularity_ns
,
303 .extra2
= &max_sched_granularity_ns
,
306 .procname
= "sched_wakeup_granularity_ns",
307 .data
= &sysctl_sched_wakeup_granularity
,
308 .maxlen
= sizeof(unsigned int),
310 .proc_handler
= sched_proc_update_handler
,
311 .extra1
= &min_wakeup_granularity_ns
,
312 .extra2
= &max_wakeup_granularity_ns
,
316 .procname
= "sched_tunable_scaling",
317 .data
= &sysctl_sched_tunable_scaling
,
318 .maxlen
= sizeof(enum sched_tunable_scaling
),
320 .proc_handler
= sched_proc_update_handler
,
321 .extra1
= &min_sched_tunable_scaling
,
322 .extra2
= &max_sched_tunable_scaling
,
325 .procname
= "sched_migration_cost_ns",
326 .data
= &sysctl_sched_migration_cost
,
327 .maxlen
= sizeof(unsigned int),
329 .proc_handler
= proc_dointvec
,
332 .procname
= "sched_nr_migrate",
333 .data
= &sysctl_sched_nr_migrate
,
334 .maxlen
= sizeof(unsigned int),
336 .proc_handler
= proc_dointvec
,
339 .procname
= "sched_time_avg_ms",
340 .data
= &sysctl_sched_time_avg
,
341 .maxlen
= sizeof(unsigned int),
343 .proc_handler
= proc_dointvec
,
346 .procname
= "sched_shares_window_ns",
347 .data
= &sysctl_sched_shares_window
,
348 .maxlen
= sizeof(unsigned int),
350 .proc_handler
= proc_dointvec
,
353 .procname
= "timer_migration",
354 .data
= &sysctl_timer_migration
,
355 .maxlen
= sizeof(unsigned int),
357 .proc_handler
= proc_dointvec_minmax
,
361 #endif /* CONFIG_SMP */
362 #ifdef CONFIG_NUMA_BALANCING
364 .procname
= "numa_balancing_scan_delay_ms",
365 .data
= &sysctl_numa_balancing_scan_delay
,
366 .maxlen
= sizeof(unsigned int),
368 .proc_handler
= proc_dointvec
,
371 .procname
= "numa_balancing_scan_period_min_ms",
372 .data
= &sysctl_numa_balancing_scan_period_min
,
373 .maxlen
= sizeof(unsigned int),
375 .proc_handler
= proc_dointvec
,
378 .procname
= "numa_balancing_scan_period_max_ms",
379 .data
= &sysctl_numa_balancing_scan_period_max
,
380 .maxlen
= sizeof(unsigned int),
382 .proc_handler
= proc_dointvec
,
385 .procname
= "numa_balancing_scan_size_mb",
386 .data
= &sysctl_numa_balancing_scan_size
,
387 .maxlen
= sizeof(unsigned int),
389 .proc_handler
= proc_dointvec_minmax
,
393 .procname
= "numa_balancing",
394 .data
= NULL
, /* filled in by handler */
395 .maxlen
= sizeof(unsigned int),
397 .proc_handler
= sysctl_numa_balancing
,
401 #endif /* CONFIG_NUMA_BALANCING */
402 #endif /* CONFIG_SCHED_DEBUG */
404 .procname
= "sched_rt_period_us",
405 .data
= &sysctl_sched_rt_period
,
406 .maxlen
= sizeof(unsigned int),
408 .proc_handler
= sched_rt_handler
,
411 .procname
= "sched_rt_runtime_us",
412 .data
= &sysctl_sched_rt_runtime
,
413 .maxlen
= sizeof(int),
415 .proc_handler
= sched_rt_handler
,
418 .procname
= "sched_rr_timeslice_ms",
419 .data
= &sched_rr_timeslice
,
420 .maxlen
= sizeof(int),
422 .proc_handler
= sched_rr_handler
,
424 #ifdef CONFIG_SCHED_AUTOGROUP
426 .procname
= "sched_autogroup_enabled",
427 .data
= &sysctl_sched_autogroup_enabled
,
428 .maxlen
= sizeof(unsigned int),
430 .proc_handler
= proc_dointvec_minmax
,
435 #ifdef CONFIG_CFS_BANDWIDTH
437 .procname
= "sched_cfs_bandwidth_slice_us",
438 .data
= &sysctl_sched_cfs_bandwidth_slice
,
439 .maxlen
= sizeof(unsigned int),
441 .proc_handler
= proc_dointvec_minmax
,
445 #ifdef CONFIG_PROVE_LOCKING
447 .procname
= "prove_locking",
448 .data
= &prove_locking
,
449 .maxlen
= sizeof(int),
451 .proc_handler
= proc_dointvec
,
454 #ifdef CONFIG_LOCK_STAT
456 .procname
= "lock_stat",
458 .maxlen
= sizeof(int),
460 .proc_handler
= proc_dointvec
,
465 .data
= &panic_timeout
,
466 .maxlen
= sizeof(int),
468 .proc_handler
= proc_dointvec
,
470 #ifdef CONFIG_COREDUMP
472 .procname
= "core_uses_pid",
473 .data
= &core_uses_pid
,
474 .maxlen
= sizeof(int),
476 .proc_handler
= proc_dointvec
,
479 .procname
= "core_pattern",
480 .data
= core_pattern
,
481 .maxlen
= CORENAME_MAX_SIZE
,
483 .proc_handler
= proc_dostring_coredump
,
486 .procname
= "core_pipe_limit",
487 .data
= &core_pipe_limit
,
488 .maxlen
= sizeof(unsigned int),
490 .proc_handler
= proc_dointvec
,
493 #ifdef CONFIG_PROC_SYSCTL
495 .procname
= "tainted",
496 .maxlen
= sizeof(long),
498 .proc_handler
= proc_taint
,
501 .procname
= "sysctl_writes_strict",
502 .data
= &sysctl_writes_strict
,
503 .maxlen
= sizeof(int),
505 .proc_handler
= proc_dointvec_minmax
,
510 #ifdef CONFIG_LATENCYTOP
512 .procname
= "latencytop",
513 .data
= &latencytop_enabled
,
514 .maxlen
= sizeof(int),
516 .proc_handler
= proc_dointvec
,
519 #ifdef CONFIG_BLK_DEV_INITRD
521 .procname
= "real-root-dev",
522 .data
= &real_root_dev
,
523 .maxlen
= sizeof(int),
525 .proc_handler
= proc_dointvec
,
529 .procname
= "print-fatal-signals",
530 .data
= &print_fatal_signals
,
531 .maxlen
= sizeof(int),
533 .proc_handler
= proc_dointvec
,
537 .procname
= "reboot-cmd",
538 .data
= reboot_command
,
541 .proc_handler
= proc_dostring
,
544 .procname
= "stop-a",
545 .data
= &stop_a_enabled
,
546 .maxlen
= sizeof (int),
548 .proc_handler
= proc_dointvec
,
551 .procname
= "scons-poweroff",
552 .data
= &scons_pwroff
,
553 .maxlen
= sizeof (int),
555 .proc_handler
= proc_dointvec
,
558 #ifdef CONFIG_SPARC64
560 .procname
= "tsb-ratio",
561 .data
= &sysctl_tsb_ratio
,
562 .maxlen
= sizeof (int),
564 .proc_handler
= proc_dointvec
,
569 .procname
= "soft-power",
570 .data
= &pwrsw_enabled
,
571 .maxlen
= sizeof (int),
573 .proc_handler
= proc_dointvec
,
576 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
578 .procname
= "unaligned-trap",
579 .data
= &unaligned_enabled
,
580 .maxlen
= sizeof (int),
582 .proc_handler
= proc_dointvec
,
586 .procname
= "ctrl-alt-del",
588 .maxlen
= sizeof(int),
590 .proc_handler
= proc_dointvec
,
592 #ifdef CONFIG_FUNCTION_TRACER
594 .procname
= "ftrace_enabled",
595 .data
= &ftrace_enabled
,
596 .maxlen
= sizeof(int),
598 .proc_handler
= ftrace_enable_sysctl
,
601 #ifdef CONFIG_STACK_TRACER
603 .procname
= "stack_tracer_enabled",
604 .data
= &stack_tracer_enabled
,
605 .maxlen
= sizeof(int),
607 .proc_handler
= stack_trace_sysctl
,
610 #ifdef CONFIG_TRACING
612 .procname
= "ftrace_dump_on_oops",
613 .data
= &ftrace_dump_on_oops
,
614 .maxlen
= sizeof(int),
616 .proc_handler
= proc_dointvec
,
619 .procname
= "traceoff_on_warning",
620 .data
= &__disable_trace_on_warning
,
621 .maxlen
= sizeof(__disable_trace_on_warning
),
623 .proc_handler
= proc_dointvec
,
626 .procname
= "tracepoint_printk",
627 .data
= &tracepoint_printk
,
628 .maxlen
= sizeof(tracepoint_printk
),
630 .proc_handler
= proc_dointvec
,
635 .procname
= "kexec_load_disabled",
636 .data
= &kexec_load_disabled
,
637 .maxlen
= sizeof(int),
639 /* only handle a transition from default "0" to "1" */
640 .proc_handler
= proc_dointvec_minmax
,
645 #ifdef CONFIG_MODULES
647 .procname
= "modprobe",
648 .data
= &modprobe_path
,
649 .maxlen
= KMOD_PATH_LEN
,
651 .proc_handler
= proc_dostring
,
654 .procname
= "modules_disabled",
655 .data
= &modules_disabled
,
656 .maxlen
= sizeof(int),
658 /* only handle a transition from default "0" to "1" */
659 .proc_handler
= proc_dointvec_minmax
,
664 #ifdef CONFIG_UEVENT_HELPER
666 .procname
= "hotplug",
667 .data
= &uevent_helper
,
668 .maxlen
= UEVENT_HELPER_PATH_LEN
,
670 .proc_handler
= proc_dostring
,
673 #ifdef CONFIG_CHR_DEV_SG
675 .procname
= "sg-big-buff",
676 .data
= &sg_big_buff
,
677 .maxlen
= sizeof (int),
679 .proc_handler
= proc_dointvec
,
682 #ifdef CONFIG_BSD_PROCESS_ACCT
686 .maxlen
= 3*sizeof(int),
688 .proc_handler
= proc_dointvec
,
691 #ifdef CONFIG_MAGIC_SYSRQ
694 .data
= &__sysrq_enabled
,
695 .maxlen
= sizeof (int),
697 .proc_handler
= sysrq_sysctl_handler
,
700 #ifdef CONFIG_PROC_SYSCTL
702 .procname
= "cad_pid",
704 .maxlen
= sizeof (int),
706 .proc_handler
= proc_do_cad_pid
,
710 .procname
= "threads-max",
712 .maxlen
= sizeof(int),
714 .proc_handler
= sysctl_max_threads
,
717 .procname
= "random",
719 .child
= random_table
,
722 .procname
= "usermodehelper",
724 .child
= usermodehelper_table
,
727 .procname
= "overflowuid",
728 .data
= &overflowuid
,
729 .maxlen
= sizeof(int),
731 .proc_handler
= proc_dointvec_minmax
,
732 .extra1
= &minolduid
,
733 .extra2
= &maxolduid
,
736 .procname
= "overflowgid",
737 .data
= &overflowgid
,
738 .maxlen
= sizeof(int),
740 .proc_handler
= proc_dointvec_minmax
,
741 .extra1
= &minolduid
,
742 .extra2
= &maxolduid
,
745 #ifdef CONFIG_MATHEMU
747 .procname
= "ieee_emulation_warnings",
748 .data
= &sysctl_ieee_emulation_warnings
,
749 .maxlen
= sizeof(int),
751 .proc_handler
= proc_dointvec
,
755 .procname
= "userprocess_debug",
756 .data
= &show_unhandled_signals
,
757 .maxlen
= sizeof(int),
759 .proc_handler
= proc_dointvec
,
763 .procname
= "pid_max",
765 .maxlen
= sizeof (int),
767 .proc_handler
= proc_dointvec_minmax
,
768 .extra1
= &pid_max_min
,
769 .extra2
= &pid_max_max
,
772 .procname
= "panic_on_oops",
773 .data
= &panic_on_oops
,
774 .maxlen
= sizeof(int),
776 .proc_handler
= proc_dointvec
,
778 #if defined CONFIG_PRINTK
780 .procname
= "printk",
781 .data
= &console_loglevel
,
782 .maxlen
= 4*sizeof(int),
784 .proc_handler
= proc_dointvec
,
787 .procname
= "printk_ratelimit",
788 .data
= &printk_ratelimit_state
.interval
,
789 .maxlen
= sizeof(int),
791 .proc_handler
= proc_dointvec_jiffies
,
794 .procname
= "printk_ratelimit_burst",
795 .data
= &printk_ratelimit_state
.burst
,
796 .maxlen
= sizeof(int),
798 .proc_handler
= proc_dointvec
,
801 .procname
= "printk_delay",
802 .data
= &printk_delay_msec
,
803 .maxlen
= sizeof(int),
805 .proc_handler
= proc_dointvec_minmax
,
807 .extra2
= &ten_thousand
,
810 .procname
= "dmesg_restrict",
811 .data
= &dmesg_restrict
,
812 .maxlen
= sizeof(int),
814 .proc_handler
= proc_dointvec_minmax_sysadmin
,
819 .procname
= "kptr_restrict",
820 .data
= &kptr_restrict
,
821 .maxlen
= sizeof(int),
823 .proc_handler
= proc_dointvec_minmax_sysadmin
,
829 .procname
= "ngroups_max",
830 .data
= &ngroups_max
,
831 .maxlen
= sizeof (int),
833 .proc_handler
= proc_dointvec
,
836 .procname
= "cap_last_cap",
837 .data
= (void *)&cap_last_cap
,
838 .maxlen
= sizeof(int),
840 .proc_handler
= proc_dointvec
,
842 #if defined(CONFIG_LOCKUP_DETECTOR)
844 .procname
= "watchdog",
845 .data
= &watchdog_user_enabled
,
846 .maxlen
= sizeof (int),
848 .proc_handler
= proc_watchdog
,
853 .procname
= "watchdog_thresh",
854 .data
= &watchdog_thresh
,
855 .maxlen
= sizeof(int),
857 .proc_handler
= proc_watchdog_thresh
,
862 .procname
= "nmi_watchdog",
863 .data
= &nmi_watchdog_enabled
,
864 .maxlen
= sizeof (int),
866 .proc_handler
= proc_nmi_watchdog
,
868 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
875 .procname
= "soft_watchdog",
876 .data
= &soft_watchdog_enabled
,
877 .maxlen
= sizeof (int),
879 .proc_handler
= proc_soft_watchdog
,
884 .procname
= "softlockup_panic",
885 .data
= &softlockup_panic
,
886 .maxlen
= sizeof(int),
888 .proc_handler
= proc_dointvec_minmax
,
894 .procname
= "softlockup_all_cpu_backtrace",
895 .data
= &sysctl_softlockup_all_cpu_backtrace
,
896 .maxlen
= sizeof(int),
898 .proc_handler
= proc_dointvec_minmax
,
902 #endif /* CONFIG_SMP */
904 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
906 .procname
= "unknown_nmi_panic",
907 .data
= &unknown_nmi_panic
,
908 .maxlen
= sizeof (int),
910 .proc_handler
= proc_dointvec
,
913 #if defined(CONFIG_X86)
915 .procname
= "panic_on_unrecovered_nmi",
916 .data
= &panic_on_unrecovered_nmi
,
917 .maxlen
= sizeof(int),
919 .proc_handler
= proc_dointvec
,
922 .procname
= "panic_on_io_nmi",
923 .data
= &panic_on_io_nmi
,
924 .maxlen
= sizeof(int),
926 .proc_handler
= proc_dointvec
,
928 #ifdef CONFIG_DEBUG_STACKOVERFLOW
930 .procname
= "panic_on_stackoverflow",
931 .data
= &sysctl_panic_on_stackoverflow
,
932 .maxlen
= sizeof(int),
934 .proc_handler
= proc_dointvec
,
938 .procname
= "bootloader_type",
939 .data
= &bootloader_type
,
940 .maxlen
= sizeof (int),
942 .proc_handler
= proc_dointvec
,
945 .procname
= "bootloader_version",
946 .data
= &bootloader_version
,
947 .maxlen
= sizeof (int),
949 .proc_handler
= proc_dointvec
,
952 .procname
= "kstack_depth_to_print",
953 .data
= &kstack_depth_to_print
,
954 .maxlen
= sizeof(int),
956 .proc_handler
= proc_dointvec
,
959 .procname
= "io_delay_type",
960 .data
= &io_delay_type
,
961 .maxlen
= sizeof(int),
963 .proc_handler
= proc_dointvec
,
966 #if defined(CONFIG_MMU)
968 .procname
= "randomize_va_space",
969 .data
= &randomize_va_space
,
970 .maxlen
= sizeof(int),
972 .proc_handler
= proc_dointvec
,
975 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
977 .procname
= "spin_retry",
979 .maxlen
= sizeof (int),
981 .proc_handler
= proc_dointvec
,
984 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
986 .procname
= "acpi_video_flags",
987 .data
= &acpi_realmode_flags
,
988 .maxlen
= sizeof (unsigned long),
990 .proc_handler
= proc_doulongvec_minmax
,
993 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
995 .procname
= "ignore-unaligned-usertrap",
996 .data
= &no_unaligned_warning
,
997 .maxlen
= sizeof (int),
999 .proc_handler
= proc_dointvec
,
1004 .procname
= "unaligned-dump-stack",
1005 .data
= &unaligned_dump_stack
,
1006 .maxlen
= sizeof (int),
1008 .proc_handler
= proc_dointvec
,
1011 #ifdef CONFIG_DETECT_HUNG_TASK
1013 .procname
= "hung_task_panic",
1014 .data
= &sysctl_hung_task_panic
,
1015 .maxlen
= sizeof(int),
1017 .proc_handler
= proc_dointvec_minmax
,
1022 .procname
= "hung_task_check_count",
1023 .data
= &sysctl_hung_task_check_count
,
1024 .maxlen
= sizeof(int),
1026 .proc_handler
= proc_dointvec_minmax
,
1030 .procname
= "hung_task_timeout_secs",
1031 .data
= &sysctl_hung_task_timeout_secs
,
1032 .maxlen
= sizeof(unsigned long),
1034 .proc_handler
= proc_dohung_task_timeout_secs
,
1035 .extra2
= &hung_task_timeout_max
,
1038 .procname
= "hung_task_warnings",
1039 .data
= &sysctl_hung_task_warnings
,
1040 .maxlen
= sizeof(int),
1042 .proc_handler
= proc_dointvec_minmax
,
1046 #ifdef CONFIG_COMPAT
1048 .procname
= "compat-log",
1049 .data
= &compat_log
,
1050 .maxlen
= sizeof (int),
1052 .proc_handler
= proc_dointvec
,
1055 #ifdef CONFIG_RT_MUTEXES
1057 .procname
= "max_lock_depth",
1058 .data
= &max_lock_depth
,
1059 .maxlen
= sizeof(int),
1061 .proc_handler
= proc_dointvec
,
1065 .procname
= "poweroff_cmd",
1066 .data
= &poweroff_cmd
,
1067 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1069 .proc_handler
= proc_dostring
,
1075 .child
= key_sysctls
,
1078 #ifdef CONFIG_PERF_EVENTS
1080 * User-space scripts rely on the existence of this file
1081 * as a feature check for perf_events being enabled.
1083 * So it's an ABI, do not remove!
1086 .procname
= "perf_event_paranoid",
1087 .data
= &sysctl_perf_event_paranoid
,
1088 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1090 .proc_handler
= proc_dointvec
,
1093 .procname
= "perf_event_mlock_kb",
1094 .data
= &sysctl_perf_event_mlock
,
1095 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1097 .proc_handler
= proc_dointvec
,
1100 .procname
= "perf_event_max_sample_rate",
1101 .data
= &sysctl_perf_event_sample_rate
,
1102 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1104 .proc_handler
= perf_proc_update_handler
,
1108 .procname
= "perf_cpu_time_max_percent",
1109 .data
= &sysctl_perf_cpu_time_max_percent
,
1110 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1112 .proc_handler
= perf_cpu_time_max_percent_handler
,
1114 .extra2
= &one_hundred
,
1117 #ifdef CONFIG_KMEMCHECK
1119 .procname
= "kmemcheck",
1120 .data
= &kmemcheck_enabled
,
1121 .maxlen
= sizeof(int),
1123 .proc_handler
= proc_dointvec
,
1127 .procname
= "panic_on_warn",
1128 .data
= &panic_on_warn
,
1129 .maxlen
= sizeof(int),
1131 .proc_handler
= proc_dointvec_minmax
,
1138 static struct ctl_table vm_table
[] = {
1140 .procname
= "overcommit_memory",
1141 .data
= &sysctl_overcommit_memory
,
1142 .maxlen
= sizeof(sysctl_overcommit_memory
),
1144 .proc_handler
= proc_dointvec_minmax
,
1149 .procname
= "panic_on_oom",
1150 .data
= &sysctl_panic_on_oom
,
1151 .maxlen
= sizeof(sysctl_panic_on_oom
),
1153 .proc_handler
= proc_dointvec_minmax
,
1158 .procname
= "oom_kill_allocating_task",
1159 .data
= &sysctl_oom_kill_allocating_task
,
1160 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1162 .proc_handler
= proc_dointvec
,
1165 .procname
= "oom_dump_tasks",
1166 .data
= &sysctl_oom_dump_tasks
,
1167 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1169 .proc_handler
= proc_dointvec
,
1172 .procname
= "overcommit_ratio",
1173 .data
= &sysctl_overcommit_ratio
,
1174 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1176 .proc_handler
= overcommit_ratio_handler
,
1179 .procname
= "overcommit_kbytes",
1180 .data
= &sysctl_overcommit_kbytes
,
1181 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1183 .proc_handler
= overcommit_kbytes_handler
,
1186 .procname
= "page-cluster",
1187 .data
= &page_cluster
,
1188 .maxlen
= sizeof(int),
1190 .proc_handler
= proc_dointvec_minmax
,
1194 .procname
= "dirty_background_ratio",
1195 .data
= &dirty_background_ratio
,
1196 .maxlen
= sizeof(dirty_background_ratio
),
1198 .proc_handler
= dirty_background_ratio_handler
,
1200 .extra2
= &one_hundred
,
1203 .procname
= "dirty_background_bytes",
1204 .data
= &dirty_background_bytes
,
1205 .maxlen
= sizeof(dirty_background_bytes
),
1207 .proc_handler
= dirty_background_bytes_handler
,
1211 .procname
= "dirty_ratio",
1212 .data
= &vm_dirty_ratio
,
1213 .maxlen
= sizeof(vm_dirty_ratio
),
1215 .proc_handler
= dirty_ratio_handler
,
1217 .extra2
= &one_hundred
,
1220 .procname
= "dirty_bytes",
1221 .data
= &vm_dirty_bytes
,
1222 .maxlen
= sizeof(vm_dirty_bytes
),
1224 .proc_handler
= dirty_bytes_handler
,
1225 .extra1
= &dirty_bytes_min
,
1228 .procname
= "dirty_writeback_centisecs",
1229 .data
= &dirty_writeback_interval
,
1230 .maxlen
= sizeof(dirty_writeback_interval
),
1232 .proc_handler
= dirty_writeback_centisecs_handler
,
1235 .procname
= "dirty_expire_centisecs",
1236 .data
= &dirty_expire_interval
,
1237 .maxlen
= sizeof(dirty_expire_interval
),
1239 .proc_handler
= proc_dointvec_minmax
,
1243 .procname
= "dirtytime_expire_seconds",
1244 .data
= &dirtytime_expire_interval
,
1245 .maxlen
= sizeof(dirty_expire_interval
),
1247 .proc_handler
= dirtytime_interval_handler
,
1251 .procname
= "nr_pdflush_threads",
1252 .mode
= 0444 /* read-only */,
1253 .proc_handler
= pdflush_proc_obsolete
,
1256 .procname
= "swappiness",
1257 .data
= &vm_swappiness
,
1258 .maxlen
= sizeof(vm_swappiness
),
1260 .proc_handler
= proc_dointvec_minmax
,
1262 .extra2
= &one_hundred
,
1264 #ifdef CONFIG_HUGETLB_PAGE
1266 .procname
= "nr_hugepages",
1268 .maxlen
= sizeof(unsigned long),
1270 .proc_handler
= hugetlb_sysctl_handler
,
1274 .procname
= "nr_hugepages_mempolicy",
1276 .maxlen
= sizeof(unsigned long),
1278 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1282 .procname
= "hugetlb_shm_group",
1283 .data
= &sysctl_hugetlb_shm_group
,
1284 .maxlen
= sizeof(gid_t
),
1286 .proc_handler
= proc_dointvec
,
1289 .procname
= "hugepages_treat_as_movable",
1290 .data
= &hugepages_treat_as_movable
,
1291 .maxlen
= sizeof(int),
1293 .proc_handler
= proc_dointvec
,
1296 .procname
= "nr_overcommit_hugepages",
1298 .maxlen
= sizeof(unsigned long),
1300 .proc_handler
= hugetlb_overcommit_handler
,
1304 .procname
= "lowmem_reserve_ratio",
1305 .data
= &sysctl_lowmem_reserve_ratio
,
1306 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1308 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1311 .procname
= "drop_caches",
1312 .data
= &sysctl_drop_caches
,
1313 .maxlen
= sizeof(int),
1315 .proc_handler
= drop_caches_sysctl_handler
,
1319 #ifdef CONFIG_COMPACTION
1321 .procname
= "compact_memory",
1322 .data
= &sysctl_compact_memory
,
1323 .maxlen
= sizeof(int),
1325 .proc_handler
= sysctl_compaction_handler
,
1328 .procname
= "extfrag_threshold",
1329 .data
= &sysctl_extfrag_threshold
,
1330 .maxlen
= sizeof(int),
1332 .proc_handler
= sysctl_extfrag_handler
,
1333 .extra1
= &min_extfrag_threshold
,
1334 .extra2
= &max_extfrag_threshold
,
1337 .procname
= "compact_unevictable_allowed",
1338 .data
= &sysctl_compact_unevictable_allowed
,
1339 .maxlen
= sizeof(int),
1341 .proc_handler
= proc_dointvec
,
1346 #endif /* CONFIG_COMPACTION */
1348 .procname
= "min_free_kbytes",
1349 .data
= &min_free_kbytes
,
1350 .maxlen
= sizeof(min_free_kbytes
),
1352 .proc_handler
= min_free_kbytes_sysctl_handler
,
1356 .procname
= "percpu_pagelist_fraction",
1357 .data
= &percpu_pagelist_fraction
,
1358 .maxlen
= sizeof(percpu_pagelist_fraction
),
1360 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1365 .procname
= "max_map_count",
1366 .data
= &sysctl_max_map_count
,
1367 .maxlen
= sizeof(sysctl_max_map_count
),
1369 .proc_handler
= proc_dointvec_minmax
,
1374 .procname
= "nr_trim_pages",
1375 .data
= &sysctl_nr_trim_pages
,
1376 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1378 .proc_handler
= proc_dointvec_minmax
,
1383 .procname
= "laptop_mode",
1384 .data
= &laptop_mode
,
1385 .maxlen
= sizeof(laptop_mode
),
1387 .proc_handler
= proc_dointvec_jiffies
,
1390 .procname
= "block_dump",
1391 .data
= &block_dump
,
1392 .maxlen
= sizeof(block_dump
),
1394 .proc_handler
= proc_dointvec
,
1398 .procname
= "vfs_cache_pressure",
1399 .data
= &sysctl_vfs_cache_pressure
,
1400 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1402 .proc_handler
= proc_dointvec
,
1405 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1407 .procname
= "legacy_va_layout",
1408 .data
= &sysctl_legacy_va_layout
,
1409 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1411 .proc_handler
= proc_dointvec
,
1417 .procname
= "zone_reclaim_mode",
1418 .data
= &zone_reclaim_mode
,
1419 .maxlen
= sizeof(zone_reclaim_mode
),
1421 .proc_handler
= proc_dointvec
,
1425 .procname
= "min_unmapped_ratio",
1426 .data
= &sysctl_min_unmapped_ratio
,
1427 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1429 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1431 .extra2
= &one_hundred
,
1434 .procname
= "min_slab_ratio",
1435 .data
= &sysctl_min_slab_ratio
,
1436 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1438 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1440 .extra2
= &one_hundred
,
1445 .procname
= "stat_interval",
1446 .data
= &sysctl_stat_interval
,
1447 .maxlen
= sizeof(sysctl_stat_interval
),
1449 .proc_handler
= proc_dointvec_jiffies
,
1454 .procname
= "mmap_min_addr",
1455 .data
= &dac_mmap_min_addr
,
1456 .maxlen
= sizeof(unsigned long),
1458 .proc_handler
= mmap_min_addr_handler
,
1463 .procname
= "numa_zonelist_order",
1464 .data
= &numa_zonelist_order
,
1465 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1467 .proc_handler
= numa_zonelist_order_handler
,
1470 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1471 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1473 .procname
= "vdso_enabled",
1474 #ifdef CONFIG_X86_32
1475 .data
= &vdso32_enabled
,
1476 .maxlen
= sizeof(vdso32_enabled
),
1478 .data
= &vdso_enabled
,
1479 .maxlen
= sizeof(vdso_enabled
),
1482 .proc_handler
= proc_dointvec
,
1486 #ifdef CONFIG_HIGHMEM
1488 .procname
= "highmem_is_dirtyable",
1489 .data
= &vm_highmem_is_dirtyable
,
1490 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1492 .proc_handler
= proc_dointvec_minmax
,
1497 #ifdef CONFIG_MEMORY_FAILURE
1499 .procname
= "memory_failure_early_kill",
1500 .data
= &sysctl_memory_failure_early_kill
,
1501 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1503 .proc_handler
= proc_dointvec_minmax
,
1508 .procname
= "memory_failure_recovery",
1509 .data
= &sysctl_memory_failure_recovery
,
1510 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1512 .proc_handler
= proc_dointvec_minmax
,
1518 .procname
= "user_reserve_kbytes",
1519 .data
= &sysctl_user_reserve_kbytes
,
1520 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1522 .proc_handler
= proc_doulongvec_minmax
,
1525 .procname
= "admin_reserve_kbytes",
1526 .data
= &sysctl_admin_reserve_kbytes
,
1527 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1529 .proc_handler
= proc_doulongvec_minmax
,
1534 static struct ctl_table fs_table
[] = {
1536 .procname
= "inode-nr",
1537 .data
= &inodes_stat
,
1538 .maxlen
= 2*sizeof(long),
1540 .proc_handler
= proc_nr_inodes
,
1543 .procname
= "inode-state",
1544 .data
= &inodes_stat
,
1545 .maxlen
= 7*sizeof(long),
1547 .proc_handler
= proc_nr_inodes
,
1550 .procname
= "file-nr",
1551 .data
= &files_stat
,
1552 .maxlen
= sizeof(files_stat
),
1554 .proc_handler
= proc_nr_files
,
1557 .procname
= "file-max",
1558 .data
= &files_stat
.max_files
,
1559 .maxlen
= sizeof(files_stat
.max_files
),
1561 .proc_handler
= proc_doulongvec_minmax
,
1564 .procname
= "nr_open",
1565 .data
= &sysctl_nr_open
,
1566 .maxlen
= sizeof(int),
1568 .proc_handler
= proc_dointvec_minmax
,
1569 .extra1
= &sysctl_nr_open_min
,
1570 .extra2
= &sysctl_nr_open_max
,
1573 .procname
= "dentry-state",
1574 .data
= &dentry_stat
,
1575 .maxlen
= 6*sizeof(long),
1577 .proc_handler
= proc_nr_dentry
,
1580 .procname
= "overflowuid",
1581 .data
= &fs_overflowuid
,
1582 .maxlen
= sizeof(int),
1584 .proc_handler
= proc_dointvec_minmax
,
1585 .extra1
= &minolduid
,
1586 .extra2
= &maxolduid
,
1589 .procname
= "overflowgid",
1590 .data
= &fs_overflowgid
,
1591 .maxlen
= sizeof(int),
1593 .proc_handler
= proc_dointvec_minmax
,
1594 .extra1
= &minolduid
,
1595 .extra2
= &maxolduid
,
1597 #ifdef CONFIG_FILE_LOCKING
1599 .procname
= "leases-enable",
1600 .data
= &leases_enable
,
1601 .maxlen
= sizeof(int),
1603 .proc_handler
= proc_dointvec
,
1606 #ifdef CONFIG_DNOTIFY
1608 .procname
= "dir-notify-enable",
1609 .data
= &dir_notify_enable
,
1610 .maxlen
= sizeof(int),
1612 .proc_handler
= proc_dointvec
,
1616 #ifdef CONFIG_FILE_LOCKING
1618 .procname
= "lease-break-time",
1619 .data
= &lease_break_time
,
1620 .maxlen
= sizeof(int),
1622 .proc_handler
= proc_dointvec
,
1627 .procname
= "aio-nr",
1629 .maxlen
= sizeof(aio_nr
),
1631 .proc_handler
= proc_doulongvec_minmax
,
1634 .procname
= "aio-max-nr",
1635 .data
= &aio_max_nr
,
1636 .maxlen
= sizeof(aio_max_nr
),
1638 .proc_handler
= proc_doulongvec_minmax
,
1640 #endif /* CONFIG_AIO */
1641 #ifdef CONFIG_INOTIFY_USER
1643 .procname
= "inotify",
1645 .child
= inotify_table
,
1650 .procname
= "epoll",
1652 .child
= epoll_table
,
1657 .procname
= "protected_symlinks",
1658 .data
= &sysctl_protected_symlinks
,
1659 .maxlen
= sizeof(int),
1661 .proc_handler
= proc_dointvec_minmax
,
1666 .procname
= "protected_hardlinks",
1667 .data
= &sysctl_protected_hardlinks
,
1668 .maxlen
= sizeof(int),
1670 .proc_handler
= proc_dointvec_minmax
,
1675 .procname
= "suid_dumpable",
1676 .data
= &suid_dumpable
,
1677 .maxlen
= sizeof(int),
1679 .proc_handler
= proc_dointvec_minmax_coredump
,
1683 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1685 .procname
= "binfmt_misc",
1687 .child
= sysctl_mount_point
,
1691 .procname
= "pipe-max-size",
1692 .data
= &pipe_max_size
,
1693 .maxlen
= sizeof(int),
1695 .proc_handler
= &pipe_proc_fn
,
1696 .extra1
= &pipe_min_size
,
1701 static struct ctl_table debug_table
[] = {
1702 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1704 .procname
= "exception-trace",
1705 .data
= &show_unhandled_signals
,
1706 .maxlen
= sizeof(int),
1708 .proc_handler
= proc_dointvec
1711 #if defined(CONFIG_OPTPROBES)
1713 .procname
= "kprobes-optimization",
1714 .data
= &sysctl_kprobes_optimization
,
1715 .maxlen
= sizeof(int),
1717 .proc_handler
= proc_kprobes_optimization_handler
,
1725 static struct ctl_table dev_table
[] = {
1729 int __init
sysctl_init(void)
1731 struct ctl_table_header
*hdr
;
1733 hdr
= register_sysctl_table(sysctl_base_table
);
1734 kmemleak_not_leak(hdr
);
1738 #endif /* CONFIG_SYSCTL */
1744 #ifdef CONFIG_PROC_SYSCTL
1746 static int _proc_do_string(char *data
, int maxlen
, int write
,
1747 char __user
*buffer
,
1748 size_t *lenp
, loff_t
*ppos
)
1754 if (!data
|| !maxlen
|| !*lenp
) {
1760 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1761 /* Only continue writes not past the end of buffer. */
1763 if (len
> maxlen
- 1)
1770 /* Start writing from beginning of buffer. */
1776 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1777 if (get_user(c
, p
++))
1779 if (c
== 0 || c
== '\n')
1800 if (copy_to_user(buffer
, data
, len
))
1803 if (put_user('\n', buffer
+ len
))
1813 static void warn_sysctl_write(struct ctl_table
*table
)
1815 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1816 "This will not be supported in the future. To silence this\n"
1817 "warning, set kernel.sysctl_writes_strict = -1\n",
1818 current
->comm
, table
->procname
);
1822 * proc_dostring - read a string sysctl
1823 * @table: the sysctl table
1824 * @write: %TRUE if this is a write to the sysctl file
1825 * @buffer: the user buffer
1826 * @lenp: the size of the user buffer
1827 * @ppos: file position
1829 * Reads/writes a string from/to the user buffer. If the kernel
1830 * buffer provided is not large enough to hold the string, the
1831 * string is truncated. The copied string is %NULL-terminated.
1832 * If the string is being read by the user process, it is copied
1833 * and a newline '\n' is added. It is truncated if the buffer is
1836 * Returns 0 on success.
1838 int proc_dostring(struct ctl_table
*table
, int write
,
1839 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1841 if (write
&& *ppos
&& sysctl_writes_strict
== SYSCTL_WRITES_WARN
)
1842 warn_sysctl_write(table
);
1844 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
1845 (char __user
*)buffer
, lenp
, ppos
);
1848 static size_t proc_skip_spaces(char **buf
)
1851 char *tmp
= skip_spaces(*buf
);
1857 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1867 #define TMPBUFLEN 22
1869 * proc_get_long - reads an ASCII formatted integer from a user buffer
1871 * @buf: a kernel buffer
1872 * @size: size of the kernel buffer
1873 * @val: this is where the number will be stored
1874 * @neg: set to %TRUE if number is negative
1875 * @perm_tr: a vector which contains the allowed trailers
1876 * @perm_tr_len: size of the perm_tr vector
1877 * @tr: pointer to store the trailer character
1879 * In case of success %0 is returned and @buf and @size are updated with
1880 * the amount of bytes read. If @tr is non-NULL and a trailing
1881 * character exists (size is non-zero after returning from this
1882 * function), @tr is updated with the trailing character.
1884 static int proc_get_long(char **buf
, size_t *size
,
1885 unsigned long *val
, bool *neg
,
1886 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1889 char *p
, tmp
[TMPBUFLEN
];
1895 if (len
> TMPBUFLEN
- 1)
1896 len
= TMPBUFLEN
- 1;
1898 memcpy(tmp
, *buf
, len
);
1902 if (*p
== '-' && *size
> 1) {
1910 *val
= simple_strtoul(p
, &p
, 0);
1914 /* We don't know if the next char is whitespace thus we may accept
1915 * invalid integers (e.g. 1234...a) or two integers instead of one
1916 * (e.g. 123...1). So lets not allow such large numbers. */
1917 if (len
== TMPBUFLEN
- 1)
1920 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1923 if (tr
&& (len
< *size
))
1933 * proc_put_long - converts an integer to a decimal ASCII formatted string
1935 * @buf: the user buffer
1936 * @size: the size of the user buffer
1937 * @val: the integer to be converted
1938 * @neg: sign of the number, %TRUE for negative
1940 * In case of success %0 is returned and @buf and @size are updated with
1941 * the amount of bytes written.
1943 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1947 char tmp
[TMPBUFLEN
], *p
= tmp
;
1949 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1953 if (copy_to_user(*buf
, tmp
, len
))
1961 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1964 char __user
**buffer
= (char __user
**)buf
;
1965 if (put_user(c
, *buffer
))
1967 (*size
)--, (*buffer
)++;
1973 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1975 int write
, void *data
)
1979 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
1983 if (*lvalp
> (unsigned long) INT_MAX
)
1991 *lvalp
= (unsigned long)-val
;
1994 *lvalp
= (unsigned long)val
;
2000 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2002 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2003 int write
, void __user
*buffer
,
2004 size_t *lenp
, loff_t
*ppos
,
2005 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2006 int write
, void *data
),
2009 int *i
, vleft
, first
= 1, err
= 0;
2010 unsigned long page
= 0;
2014 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2019 i
= (int *) tbl_data
;
2020 vleft
= table
->maxlen
/ sizeof(*i
);
2024 conv
= do_proc_dointvec_conv
;
2028 switch (sysctl_writes_strict
) {
2029 case SYSCTL_WRITES_STRICT
:
2031 case SYSCTL_WRITES_WARN
:
2032 warn_sysctl_write(table
);
2039 if (left
> PAGE_SIZE
- 1)
2040 left
= PAGE_SIZE
- 1;
2041 page
= __get_free_page(GFP_TEMPORARY
);
2042 kbuf
= (char *) page
;
2045 if (copy_from_user(kbuf
, buffer
, left
)) {
2052 for (; left
&& vleft
--; i
++, first
=0) {
2057 left
-= proc_skip_spaces(&kbuf
);
2061 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2063 sizeof(proc_wspace_sep
), NULL
);
2066 if (conv(&neg
, &lval
, i
, 1, data
)) {
2071 if (conv(&neg
, &lval
, i
, 0, data
)) {
2076 err
= proc_put_char(&buffer
, &left
, '\t');
2079 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2085 if (!write
&& !first
&& left
&& !err
)
2086 err
= proc_put_char(&buffer
, &left
, '\n');
2087 if (write
&& !err
&& left
)
2088 left
-= proc_skip_spaces(&kbuf
);
2093 return err
? : -EINVAL
;
2101 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2102 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2103 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2104 int write
, void *data
),
2107 return __do_proc_dointvec(table
->data
, table
, write
,
2108 buffer
, lenp
, ppos
, conv
, data
);
2112 * proc_dointvec - read a vector of integers
2113 * @table: the sysctl table
2114 * @write: %TRUE if this is a write to the sysctl file
2115 * @buffer: the user buffer
2116 * @lenp: the size of the user buffer
2117 * @ppos: file position
2119 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2120 * values from/to the user buffer, treated as an ASCII string.
2122 * Returns 0 on success.
2124 int proc_dointvec(struct ctl_table
*table
, int write
,
2125 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2127 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2132 * Taint values can only be increased
2133 * This means we can safely use a temporary.
2135 static int proc_taint(struct ctl_table
*table
, int write
,
2136 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2139 unsigned long tmptaint
= get_taint();
2142 if (write
&& !capable(CAP_SYS_ADMIN
))
2147 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2153 * Poor man's atomic or. Not worth adding a primitive
2154 * to everyone's atomic.h for this
2157 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2158 if ((tmptaint
>> i
) & 1)
2159 add_taint(i
, LOCKDEP_STILL_OK
);
2166 #ifdef CONFIG_PRINTK
2167 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2168 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2170 if (write
&& !capable(CAP_SYS_ADMIN
))
2173 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2177 struct do_proc_dointvec_minmax_conv_param
{
2182 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2184 int write
, void *data
)
2186 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2188 int val
= *negp
? -*lvalp
: *lvalp
;
2189 if ((param
->min
&& *param
->min
> val
) ||
2190 (param
->max
&& *param
->max
< val
))
2197 *lvalp
= (unsigned long)-val
;
2200 *lvalp
= (unsigned long)val
;
2207 * proc_dointvec_minmax - read a vector of integers with min/max values
2208 * @table: the sysctl table
2209 * @write: %TRUE if this is a write to the sysctl file
2210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2214 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2215 * values from/to the user buffer, treated as an ASCII string.
2217 * This routine will ensure the values are within the range specified by
2218 * table->extra1 (min) and table->extra2 (max).
2220 * Returns 0 on success.
2222 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2223 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2225 struct do_proc_dointvec_minmax_conv_param param
= {
2226 .min
= (int *) table
->extra1
,
2227 .max
= (int *) table
->extra2
,
2229 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2230 do_proc_dointvec_minmax_conv
, ¶m
);
2233 static void validate_coredump_safety(void)
2235 #ifdef CONFIG_COREDUMP
2236 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2237 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2238 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2239 "suid_dumpable=2. Pipe handler or fully qualified "\
2240 "core dump path required.\n");
2245 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2246 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2248 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2250 validate_coredump_safety();
2254 #ifdef CONFIG_COREDUMP
2255 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2256 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2258 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2260 validate_coredump_safety();
2265 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2266 void __user
*buffer
,
2267 size_t *lenp
, loff_t
*ppos
,
2268 unsigned long convmul
,
2269 unsigned long convdiv
)
2271 unsigned long *i
, *min
, *max
;
2272 int vleft
, first
= 1, err
= 0;
2273 unsigned long page
= 0;
2277 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2282 i
= (unsigned long *) data
;
2283 min
= (unsigned long *) table
->extra1
;
2284 max
= (unsigned long *) table
->extra2
;
2285 vleft
= table
->maxlen
/ sizeof(unsigned long);
2290 switch (sysctl_writes_strict
) {
2291 case SYSCTL_WRITES_STRICT
:
2293 case SYSCTL_WRITES_WARN
:
2294 warn_sysctl_write(table
);
2301 if (left
> PAGE_SIZE
- 1)
2302 left
= PAGE_SIZE
- 1;
2303 page
= __get_free_page(GFP_TEMPORARY
);
2304 kbuf
= (char *) page
;
2307 if (copy_from_user(kbuf
, buffer
, left
)) {
2314 for (; left
&& vleft
--; i
++, first
= 0) {
2320 left
-= proc_skip_spaces(&kbuf
);
2322 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2324 sizeof(proc_wspace_sep
), NULL
);
2329 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2333 val
= convdiv
* (*i
) / convmul
;
2335 err
= proc_put_char(&buffer
, &left
, '\t');
2339 err
= proc_put_long(&buffer
, &left
, val
, false);
2345 if (!write
&& !first
&& left
&& !err
)
2346 err
= proc_put_char(&buffer
, &left
, '\n');
2348 left
-= proc_skip_spaces(&kbuf
);
2353 return err
? : -EINVAL
;
2361 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2362 void __user
*buffer
,
2363 size_t *lenp
, loff_t
*ppos
,
2364 unsigned long convmul
,
2365 unsigned long convdiv
)
2367 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2368 buffer
, lenp
, ppos
, convmul
, convdiv
);
2372 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2373 * @table: the sysctl table
2374 * @write: %TRUE if this is a write to the sysctl file
2375 * @buffer: the user buffer
2376 * @lenp: the size of the user buffer
2377 * @ppos: file position
2379 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2380 * values from/to the user buffer, treated as an ASCII string.
2382 * This routine will ensure the values are within the range specified by
2383 * table->extra1 (min) and table->extra2 (max).
2385 * Returns 0 on success.
2387 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2388 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2390 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2394 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2395 * @table: the sysctl table
2396 * @write: %TRUE if this is a write to the sysctl file
2397 * @buffer: the user buffer
2398 * @lenp: the size of the user buffer
2399 * @ppos: file position
2401 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2402 * values from/to the user buffer, treated as an ASCII string. The values
2403 * are treated as milliseconds, and converted to jiffies when they are stored.
2405 * This routine will ensure the values are within the range specified by
2406 * table->extra1 (min) and table->extra2 (max).
2408 * Returns 0 on success.
2410 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2411 void __user
*buffer
,
2412 size_t *lenp
, loff_t
*ppos
)
2414 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2415 lenp
, ppos
, HZ
, 1000l);
2419 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2421 int write
, void *data
)
2424 if (*lvalp
> LONG_MAX
/ HZ
)
2426 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2432 lval
= (unsigned long)-val
;
2435 lval
= (unsigned long)val
;
2442 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2444 int write
, void *data
)
2447 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2449 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2455 lval
= (unsigned long)-val
;
2458 lval
= (unsigned long)val
;
2460 *lvalp
= jiffies_to_clock_t(lval
);
2465 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2467 int write
, void *data
)
2470 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2480 lval
= (unsigned long)-val
;
2483 lval
= (unsigned long)val
;
2485 *lvalp
= jiffies_to_msecs(lval
);
2491 * proc_dointvec_jiffies - read a vector of integers as seconds
2492 * @table: the sysctl table
2493 * @write: %TRUE if this is a write to the sysctl file
2494 * @buffer: the user buffer
2495 * @lenp: the size of the user buffer
2496 * @ppos: file position
2498 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2499 * values from/to the user buffer, treated as an ASCII string.
2500 * The values read are assumed to be in seconds, and are converted into
2503 * Returns 0 on success.
2505 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2506 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2508 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2509 do_proc_dointvec_jiffies_conv
,NULL
);
2513 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2514 * @table: the sysctl table
2515 * @write: %TRUE if this is a write to the sysctl file
2516 * @buffer: the user buffer
2517 * @lenp: the size of the user buffer
2518 * @ppos: pointer to the file position
2520 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2521 * values from/to the user buffer, treated as an ASCII string.
2522 * The values read are assumed to be in 1/USER_HZ seconds, and
2523 * are converted into jiffies.
2525 * Returns 0 on success.
2527 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2528 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2530 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2531 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2535 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2536 * @table: the sysctl table
2537 * @write: %TRUE if this is a write to the sysctl file
2538 * @buffer: the user buffer
2539 * @lenp: the size of the user buffer
2540 * @ppos: file position
2541 * @ppos: the current position in the file
2543 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2544 * values from/to the user buffer, treated as an ASCII string.
2545 * The values read are assumed to be in 1/1000 seconds, and
2546 * are converted into jiffies.
2548 * Returns 0 on success.
2550 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2551 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2553 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2554 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2557 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2558 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2560 struct pid
*new_pid
;
2564 tmp
= pid_vnr(cad_pid
);
2566 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2567 lenp
, ppos
, NULL
, NULL
);
2571 new_pid
= find_get_pid(tmp
);
2575 put_pid(xchg(&cad_pid
, new_pid
));
2580 * proc_do_large_bitmap - read/write from/to a large bitmap
2581 * @table: the sysctl table
2582 * @write: %TRUE if this is a write to the sysctl file
2583 * @buffer: the user buffer
2584 * @lenp: the size of the user buffer
2585 * @ppos: file position
2587 * The bitmap is stored at table->data and the bitmap length (in bits)
2590 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2591 * large bitmaps may be represented in a compact manner. Writing into
2592 * the file will clear the bitmap then update it with the given input.
2594 * Returns 0 on success.
2596 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2597 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2601 size_t left
= *lenp
;
2602 unsigned long bitmap_len
= table
->maxlen
;
2603 unsigned long *bitmap
= *(unsigned long **) table
->data
;
2604 unsigned long *tmp_bitmap
= NULL
;
2605 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2607 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2613 unsigned long page
= 0;
2616 if (left
> PAGE_SIZE
- 1)
2617 left
= PAGE_SIZE
- 1;
2619 page
= __get_free_page(GFP_TEMPORARY
);
2620 kbuf
= (char *) page
;
2623 if (copy_from_user(kbuf
, buffer
, left
)) {
2629 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2635 proc_skip_char(&kbuf
, &left
, '\n');
2636 while (!err
&& left
) {
2637 unsigned long val_a
, val_b
;
2640 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2644 if (val_a
>= bitmap_len
|| neg
) {
2656 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2657 &neg
, tr_b
, sizeof(tr_b
),
2661 if (val_b
>= bitmap_len
|| neg
||
2672 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2674 proc_skip_char(&kbuf
, &left
, '\n');
2678 unsigned long bit_a
, bit_b
= 0;
2681 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2682 if (bit_a
>= bitmap_len
)
2684 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2688 err
= proc_put_char(&buffer
, &left
, ',');
2692 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2695 if (bit_a
!= bit_b
) {
2696 err
= proc_put_char(&buffer
, &left
, '-');
2699 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2707 err
= proc_put_char(&buffer
, &left
, '\n');
2713 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2715 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2727 #else /* CONFIG_PROC_SYSCTL */
2729 int proc_dostring(struct ctl_table
*table
, int write
,
2730 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2735 int proc_dointvec(struct ctl_table
*table
, int write
,
2736 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2741 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2742 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2747 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2748 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2753 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2754 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2759 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2760 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2765 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2766 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2771 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2772 void __user
*buffer
,
2773 size_t *lenp
, loff_t
*ppos
)
2779 #endif /* CONFIG_PROC_SYSCTL */
2782 * No sense putting this after each symbol definition, twice,
2783 * exception granted :-)
2785 EXPORT_SYMBOL(proc_dointvec
);
2786 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2787 EXPORT_SYMBOL(proc_dointvec_minmax
);
2788 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2789 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2790 EXPORT_SYMBOL(proc_dostring
);
2791 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2792 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);