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>
65 #include <linux/kexec.h>
67 #include <asm/uaccess.h>
68 #include <asm/processor.h>
72 #include <asm/stacktrace.h>
76 #include <asm/setup.h>
78 #ifdef CONFIG_BSD_PROCESS_ACCT
79 #include <linux/acct.h>
81 #ifdef CONFIG_RT_MUTEXES
82 #include <linux/rtmutex.h>
84 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85 #include <linux/lockdep.h>
87 #ifdef CONFIG_CHR_DEV_SG
91 #ifdef CONFIG_LOCKUP_DETECTOR
92 #include <linux/nmi.h>
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
99 extern int max_threads
;
100 extern int suid_dumpable
;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid
;
103 extern char core_pattern
[];
104 extern unsigned int core_pipe_limit
;
107 extern int pid_max_min
, pid_max_max
;
108 extern int percpu_pagelist_fraction
;
109 extern int compat_log
;
110 extern int latencytop_enabled
;
111 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
113 extern int sysctl_nr_trim_pages
;
116 /* Constants used for minimum and maximum */
117 #ifdef CONFIG_LOCKUP_DETECTOR
118 static int sixty
= 60;
121 static int __maybe_unused neg_one
= -1;
124 static int __maybe_unused one
= 1;
125 static int __maybe_unused two
= 2;
126 static int __maybe_unused four
= 4;
127 static unsigned long one_ul
= 1;
128 static int one_hundred
= 100;
130 static int ten_thousand
= 10000;
133 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
134 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
136 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
137 static int maxolduid
= 65535;
138 static int minolduid
;
140 static int ngroups_max
= NGROUPS_MAX
;
141 static const int cap_last_cap
= CAP_LAST_CAP
;
143 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
144 #ifdef CONFIG_DETECT_HUNG_TASK
145 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
155 extern int pwrsw_enabled
;
158 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
159 extern int unaligned_enabled
;
163 extern int unaligned_dump_stack
;
166 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
167 extern int no_unaligned_warning
;
170 #ifdef CONFIG_PROC_SYSCTL
172 #define SYSCTL_WRITES_LEGACY -1
173 #define SYSCTL_WRITES_WARN 0
174 #define SYSCTL_WRITES_STRICT 1
176 static int sysctl_writes_strict
= SYSCTL_WRITES_WARN
;
178 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
179 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
180 static int proc_taint(struct ctl_table
*table
, int write
,
181 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
185 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
186 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
189 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
190 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
191 #ifdef CONFIG_COREDUMP
192 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
193 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
196 #ifdef CONFIG_MAGIC_SYSRQ
197 /* Note: sysrq code uses it's own private copy */
198 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
200 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
201 void __user
*buffer
, size_t *lenp
,
206 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
211 sysrq_toggle_support(__sysrq_enabled
);
218 static struct ctl_table kern_table
[];
219 static struct ctl_table vm_table
[];
220 static struct ctl_table fs_table
[];
221 static struct ctl_table debug_table
[];
222 static struct ctl_table dev_table
[];
223 extern struct ctl_table random_table
[];
225 extern struct ctl_table epoll_table
[];
228 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
229 int sysctl_legacy_va_layout
;
232 /* The default sysctl tables: */
234 static struct ctl_table sysctl_base_table
[] = {
236 .procname
= "kernel",
253 .child
= debug_table
,
263 #ifdef CONFIG_SCHED_DEBUG
264 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
265 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
266 static int min_wakeup_granularity_ns
; /* 0 usecs */
267 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
269 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
270 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
271 #endif /* CONFIG_SMP */
272 #endif /* CONFIG_SCHED_DEBUG */
274 #ifdef CONFIG_COMPACTION
275 static int min_extfrag_threshold
;
276 static int max_extfrag_threshold
= 1000;
279 static struct ctl_table kern_table
[] = {
281 .procname
= "sched_child_runs_first",
282 .data
= &sysctl_sched_child_runs_first
,
283 .maxlen
= sizeof(unsigned int),
285 .proc_handler
= proc_dointvec
,
287 #ifdef CONFIG_SCHED_DEBUG
289 .procname
= "sched_min_granularity_ns",
290 .data
= &sysctl_sched_min_granularity
,
291 .maxlen
= sizeof(unsigned int),
293 .proc_handler
= sched_proc_update_handler
,
294 .extra1
= &min_sched_granularity_ns
,
295 .extra2
= &max_sched_granularity_ns
,
298 .procname
= "sched_latency_ns",
299 .data
= &sysctl_sched_latency
,
300 .maxlen
= sizeof(unsigned int),
302 .proc_handler
= sched_proc_update_handler
,
303 .extra1
= &min_sched_granularity_ns
,
304 .extra2
= &max_sched_granularity_ns
,
307 .procname
= "sched_wakeup_granularity_ns",
308 .data
= &sysctl_sched_wakeup_granularity
,
309 .maxlen
= sizeof(unsigned int),
311 .proc_handler
= sched_proc_update_handler
,
312 .extra1
= &min_wakeup_granularity_ns
,
313 .extra2
= &max_wakeup_granularity_ns
,
317 .procname
= "sched_tunable_scaling",
318 .data
= &sysctl_sched_tunable_scaling
,
319 .maxlen
= sizeof(enum sched_tunable_scaling
),
321 .proc_handler
= sched_proc_update_handler
,
322 .extra1
= &min_sched_tunable_scaling
,
323 .extra2
= &max_sched_tunable_scaling
,
326 .procname
= "sched_migration_cost_ns",
327 .data
= &sysctl_sched_migration_cost
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= proc_dointvec
,
333 .procname
= "sched_nr_migrate",
334 .data
= &sysctl_sched_nr_migrate
,
335 .maxlen
= sizeof(unsigned int),
337 .proc_handler
= proc_dointvec
,
340 .procname
= "sched_time_avg_ms",
341 .data
= &sysctl_sched_time_avg
,
342 .maxlen
= sizeof(unsigned int),
344 .proc_handler
= proc_dointvec
,
347 .procname
= "sched_shares_window_ns",
348 .data
= &sysctl_sched_shares_window
,
349 .maxlen
= sizeof(unsigned int),
351 .proc_handler
= proc_dointvec
,
354 .procname
= "timer_migration",
355 .data
= &sysctl_timer_migration
,
356 .maxlen
= sizeof(unsigned int),
358 .proc_handler
= proc_dointvec_minmax
,
362 #endif /* CONFIG_SMP */
363 #ifdef CONFIG_NUMA_BALANCING
365 .procname
= "numa_balancing_scan_delay_ms",
366 .data
= &sysctl_numa_balancing_scan_delay
,
367 .maxlen
= sizeof(unsigned int),
369 .proc_handler
= proc_dointvec
,
372 .procname
= "numa_balancing_scan_period_min_ms",
373 .data
= &sysctl_numa_balancing_scan_period_min
,
374 .maxlen
= sizeof(unsigned int),
376 .proc_handler
= proc_dointvec
,
379 .procname
= "numa_balancing_scan_period_max_ms",
380 .data
= &sysctl_numa_balancing_scan_period_max
,
381 .maxlen
= sizeof(unsigned int),
383 .proc_handler
= proc_dointvec
,
386 .procname
= "numa_balancing_scan_size_mb",
387 .data
= &sysctl_numa_balancing_scan_size
,
388 .maxlen
= sizeof(unsigned int),
390 .proc_handler
= proc_dointvec_minmax
,
394 .procname
= "numa_balancing",
395 .data
= NULL
, /* filled in by handler */
396 .maxlen
= sizeof(unsigned int),
398 .proc_handler
= sysctl_numa_balancing
,
402 #endif /* CONFIG_NUMA_BALANCING */
403 #endif /* CONFIG_SCHED_DEBUG */
405 .procname
= "sched_rt_period_us",
406 .data
= &sysctl_sched_rt_period
,
407 .maxlen
= sizeof(unsigned int),
409 .proc_handler
= sched_rt_handler
,
412 .procname
= "sched_rt_runtime_us",
413 .data
= &sysctl_sched_rt_runtime
,
414 .maxlen
= sizeof(int),
416 .proc_handler
= sched_rt_handler
,
419 .procname
= "sched_rr_timeslice_ms",
420 .data
= &sched_rr_timeslice
,
421 .maxlen
= sizeof(int),
423 .proc_handler
= sched_rr_handler
,
425 #ifdef CONFIG_SCHED_AUTOGROUP
427 .procname
= "sched_autogroup_enabled",
428 .data
= &sysctl_sched_autogroup_enabled
,
429 .maxlen
= sizeof(unsigned int),
431 .proc_handler
= proc_dointvec_minmax
,
436 #ifdef CONFIG_CFS_BANDWIDTH
438 .procname
= "sched_cfs_bandwidth_slice_us",
439 .data
= &sysctl_sched_cfs_bandwidth_slice
,
440 .maxlen
= sizeof(unsigned int),
442 .proc_handler
= proc_dointvec_minmax
,
446 #ifdef CONFIG_PROVE_LOCKING
448 .procname
= "prove_locking",
449 .data
= &prove_locking
,
450 .maxlen
= sizeof(int),
452 .proc_handler
= proc_dointvec
,
455 #ifdef CONFIG_LOCK_STAT
457 .procname
= "lock_stat",
459 .maxlen
= sizeof(int),
461 .proc_handler
= proc_dointvec
,
466 .data
= &panic_timeout
,
467 .maxlen
= sizeof(int),
469 .proc_handler
= proc_dointvec
,
471 #ifdef CONFIG_COREDUMP
473 .procname
= "core_uses_pid",
474 .data
= &core_uses_pid
,
475 .maxlen
= sizeof(int),
477 .proc_handler
= proc_dointvec
,
480 .procname
= "core_pattern",
481 .data
= core_pattern
,
482 .maxlen
= CORENAME_MAX_SIZE
,
484 .proc_handler
= proc_dostring_coredump
,
487 .procname
= "core_pipe_limit",
488 .data
= &core_pipe_limit
,
489 .maxlen
= sizeof(unsigned int),
491 .proc_handler
= proc_dointvec
,
494 #ifdef CONFIG_PROC_SYSCTL
496 .procname
= "tainted",
497 .maxlen
= sizeof(long),
499 .proc_handler
= proc_taint
,
502 .procname
= "sysctl_writes_strict",
503 .data
= &sysctl_writes_strict
,
504 .maxlen
= sizeof(int),
506 .proc_handler
= proc_dointvec_minmax
,
511 #ifdef CONFIG_LATENCYTOP
513 .procname
= "latencytop",
514 .data
= &latencytop_enabled
,
515 .maxlen
= sizeof(int),
517 .proc_handler
= proc_dointvec
,
520 #ifdef CONFIG_BLK_DEV_INITRD
522 .procname
= "real-root-dev",
523 .data
= &real_root_dev
,
524 .maxlen
= sizeof(int),
526 .proc_handler
= proc_dointvec
,
530 .procname
= "print-fatal-signals",
531 .data
= &print_fatal_signals
,
532 .maxlen
= sizeof(int),
534 .proc_handler
= proc_dointvec
,
538 .procname
= "reboot-cmd",
539 .data
= reboot_command
,
542 .proc_handler
= proc_dostring
,
545 .procname
= "stop-a",
546 .data
= &stop_a_enabled
,
547 .maxlen
= sizeof (int),
549 .proc_handler
= proc_dointvec
,
552 .procname
= "scons-poweroff",
553 .data
= &scons_pwroff
,
554 .maxlen
= sizeof (int),
556 .proc_handler
= proc_dointvec
,
559 #ifdef CONFIG_SPARC64
561 .procname
= "tsb-ratio",
562 .data
= &sysctl_tsb_ratio
,
563 .maxlen
= sizeof (int),
565 .proc_handler
= proc_dointvec
,
570 .procname
= "soft-power",
571 .data
= &pwrsw_enabled
,
572 .maxlen
= sizeof (int),
574 .proc_handler
= proc_dointvec
,
577 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
579 .procname
= "unaligned-trap",
580 .data
= &unaligned_enabled
,
581 .maxlen
= sizeof (int),
583 .proc_handler
= proc_dointvec
,
587 .procname
= "ctrl-alt-del",
589 .maxlen
= sizeof(int),
591 .proc_handler
= proc_dointvec
,
593 #ifdef CONFIG_FUNCTION_TRACER
595 .procname
= "ftrace_enabled",
596 .data
= &ftrace_enabled
,
597 .maxlen
= sizeof(int),
599 .proc_handler
= ftrace_enable_sysctl
,
602 #ifdef CONFIG_STACK_TRACER
604 .procname
= "stack_tracer_enabled",
605 .data
= &stack_tracer_enabled
,
606 .maxlen
= sizeof(int),
608 .proc_handler
= stack_trace_sysctl
,
611 #ifdef CONFIG_TRACING
613 .procname
= "ftrace_dump_on_oops",
614 .data
= &ftrace_dump_on_oops
,
615 .maxlen
= sizeof(int),
617 .proc_handler
= proc_dointvec
,
620 .procname
= "traceoff_on_warning",
621 .data
= &__disable_trace_on_warning
,
622 .maxlen
= sizeof(__disable_trace_on_warning
),
624 .proc_handler
= proc_dointvec
,
627 .procname
= "tracepoint_printk",
628 .data
= &tracepoint_printk
,
629 .maxlen
= sizeof(tracepoint_printk
),
631 .proc_handler
= proc_dointvec
,
636 .procname
= "kexec_load_disabled",
637 .data
= &kexec_load_disabled
,
638 .maxlen
= sizeof(int),
640 /* only handle a transition from default "0" to "1" */
641 .proc_handler
= proc_dointvec_minmax
,
646 #ifdef CONFIG_MODULES
648 .procname
= "modprobe",
649 .data
= &modprobe_path
,
650 .maxlen
= KMOD_PATH_LEN
,
652 .proc_handler
= proc_dostring
,
655 .procname
= "modules_disabled",
656 .data
= &modules_disabled
,
657 .maxlen
= sizeof(int),
659 /* only handle a transition from default "0" to "1" */
660 .proc_handler
= proc_dointvec_minmax
,
665 #ifdef CONFIG_UEVENT_HELPER
667 .procname
= "hotplug",
668 .data
= &uevent_helper
,
669 .maxlen
= UEVENT_HELPER_PATH_LEN
,
671 .proc_handler
= proc_dostring
,
674 #ifdef CONFIG_CHR_DEV_SG
676 .procname
= "sg-big-buff",
677 .data
= &sg_big_buff
,
678 .maxlen
= sizeof (int),
680 .proc_handler
= proc_dointvec
,
683 #ifdef CONFIG_BSD_PROCESS_ACCT
687 .maxlen
= 3*sizeof(int),
689 .proc_handler
= proc_dointvec
,
692 #ifdef CONFIG_MAGIC_SYSRQ
695 .data
= &__sysrq_enabled
,
696 .maxlen
= sizeof (int),
698 .proc_handler
= sysrq_sysctl_handler
,
701 #ifdef CONFIG_PROC_SYSCTL
703 .procname
= "cad_pid",
705 .maxlen
= sizeof (int),
707 .proc_handler
= proc_do_cad_pid
,
711 .procname
= "threads-max",
712 .data
= &max_threads
,
713 .maxlen
= sizeof(int),
715 .proc_handler
= proc_dointvec
,
718 .procname
= "random",
720 .child
= random_table
,
723 .procname
= "usermodehelper",
725 .child
= usermodehelper_table
,
728 .procname
= "overflowuid",
729 .data
= &overflowuid
,
730 .maxlen
= sizeof(int),
732 .proc_handler
= proc_dointvec_minmax
,
733 .extra1
= &minolduid
,
734 .extra2
= &maxolduid
,
737 .procname
= "overflowgid",
738 .data
= &overflowgid
,
739 .maxlen
= sizeof(int),
741 .proc_handler
= proc_dointvec_minmax
,
742 .extra1
= &minolduid
,
743 .extra2
= &maxolduid
,
746 #ifdef CONFIG_MATHEMU
748 .procname
= "ieee_emulation_warnings",
749 .data
= &sysctl_ieee_emulation_warnings
,
750 .maxlen
= sizeof(int),
752 .proc_handler
= proc_dointvec
,
756 .procname
= "userprocess_debug",
757 .data
= &show_unhandled_signals
,
758 .maxlen
= sizeof(int),
760 .proc_handler
= proc_dointvec
,
764 .procname
= "pid_max",
766 .maxlen
= sizeof (int),
768 .proc_handler
= proc_dointvec_minmax
,
769 .extra1
= &pid_max_min
,
770 .extra2
= &pid_max_max
,
773 .procname
= "panic_on_oops",
774 .data
= &panic_on_oops
,
775 .maxlen
= sizeof(int),
777 .proc_handler
= proc_dointvec
,
779 #if defined CONFIG_PRINTK
781 .procname
= "printk",
782 .data
= &console_loglevel
,
783 .maxlen
= 4*sizeof(int),
785 .proc_handler
= proc_dointvec
,
788 .procname
= "printk_ratelimit",
789 .data
= &printk_ratelimit_state
.interval
,
790 .maxlen
= sizeof(int),
792 .proc_handler
= proc_dointvec_jiffies
,
795 .procname
= "printk_ratelimit_burst",
796 .data
= &printk_ratelimit_state
.burst
,
797 .maxlen
= sizeof(int),
799 .proc_handler
= proc_dointvec
,
802 .procname
= "printk_delay",
803 .data
= &printk_delay_msec
,
804 .maxlen
= sizeof(int),
806 .proc_handler
= proc_dointvec_minmax
,
808 .extra2
= &ten_thousand
,
811 .procname
= "dmesg_restrict",
812 .data
= &dmesg_restrict
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= proc_dointvec_minmax_sysadmin
,
820 .procname
= "kptr_restrict",
821 .data
= &kptr_restrict
,
822 .maxlen
= sizeof(int),
824 .proc_handler
= proc_dointvec_minmax_sysadmin
,
830 .procname
= "ngroups_max",
831 .data
= &ngroups_max
,
832 .maxlen
= sizeof (int),
834 .proc_handler
= proc_dointvec
,
837 .procname
= "cap_last_cap",
838 .data
= (void *)&cap_last_cap
,
839 .maxlen
= sizeof(int),
841 .proc_handler
= proc_dointvec
,
843 #if defined(CONFIG_LOCKUP_DETECTOR)
845 .procname
= "watchdog",
846 .data
= &watchdog_user_enabled
,
847 .maxlen
= sizeof (int),
849 .proc_handler
= proc_dowatchdog
,
854 .procname
= "watchdog_thresh",
855 .data
= &watchdog_thresh
,
856 .maxlen
= sizeof(int),
858 .proc_handler
= proc_dowatchdog
,
863 .procname
= "softlockup_panic",
864 .data
= &softlockup_panic
,
865 .maxlen
= sizeof(int),
867 .proc_handler
= proc_dointvec_minmax
,
873 .procname
= "softlockup_all_cpu_backtrace",
874 .data
= &sysctl_softlockup_all_cpu_backtrace
,
875 .maxlen
= sizeof(int),
877 .proc_handler
= proc_dointvec_minmax
,
881 #endif /* CONFIG_SMP */
883 .procname
= "nmi_watchdog",
884 .data
= &watchdog_user_enabled
,
885 .maxlen
= sizeof (int),
887 .proc_handler
= proc_dowatchdog
,
892 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
894 .procname
= "unknown_nmi_panic",
895 .data
= &unknown_nmi_panic
,
896 .maxlen
= sizeof (int),
898 .proc_handler
= proc_dointvec
,
901 #if defined(CONFIG_X86)
903 .procname
= "panic_on_unrecovered_nmi",
904 .data
= &panic_on_unrecovered_nmi
,
905 .maxlen
= sizeof(int),
907 .proc_handler
= proc_dointvec
,
910 .procname
= "panic_on_io_nmi",
911 .data
= &panic_on_io_nmi
,
912 .maxlen
= sizeof(int),
914 .proc_handler
= proc_dointvec
,
916 #ifdef CONFIG_DEBUG_STACKOVERFLOW
918 .procname
= "panic_on_stackoverflow",
919 .data
= &sysctl_panic_on_stackoverflow
,
920 .maxlen
= sizeof(int),
922 .proc_handler
= proc_dointvec
,
926 .procname
= "bootloader_type",
927 .data
= &bootloader_type
,
928 .maxlen
= sizeof (int),
930 .proc_handler
= proc_dointvec
,
933 .procname
= "bootloader_version",
934 .data
= &bootloader_version
,
935 .maxlen
= sizeof (int),
937 .proc_handler
= proc_dointvec
,
940 .procname
= "kstack_depth_to_print",
941 .data
= &kstack_depth_to_print
,
942 .maxlen
= sizeof(int),
944 .proc_handler
= proc_dointvec
,
947 .procname
= "io_delay_type",
948 .data
= &io_delay_type
,
949 .maxlen
= sizeof(int),
951 .proc_handler
= proc_dointvec
,
954 #if defined(CONFIG_MMU)
956 .procname
= "randomize_va_space",
957 .data
= &randomize_va_space
,
958 .maxlen
= sizeof(int),
960 .proc_handler
= proc_dointvec
,
963 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
965 .procname
= "spin_retry",
967 .maxlen
= sizeof (int),
969 .proc_handler
= proc_dointvec
,
972 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
974 .procname
= "acpi_video_flags",
975 .data
= &acpi_realmode_flags
,
976 .maxlen
= sizeof (unsigned long),
978 .proc_handler
= proc_doulongvec_minmax
,
981 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
983 .procname
= "ignore-unaligned-usertrap",
984 .data
= &no_unaligned_warning
,
985 .maxlen
= sizeof (int),
987 .proc_handler
= proc_dointvec
,
992 .procname
= "unaligned-dump-stack",
993 .data
= &unaligned_dump_stack
,
994 .maxlen
= sizeof (int),
996 .proc_handler
= proc_dointvec
,
999 #ifdef CONFIG_DETECT_HUNG_TASK
1001 .procname
= "hung_task_panic",
1002 .data
= &sysctl_hung_task_panic
,
1003 .maxlen
= sizeof(int),
1005 .proc_handler
= proc_dointvec_minmax
,
1010 .procname
= "hung_task_check_count",
1011 .data
= &sysctl_hung_task_check_count
,
1012 .maxlen
= sizeof(int),
1014 .proc_handler
= proc_dointvec_minmax
,
1018 .procname
= "hung_task_timeout_secs",
1019 .data
= &sysctl_hung_task_timeout_secs
,
1020 .maxlen
= sizeof(unsigned long),
1022 .proc_handler
= proc_dohung_task_timeout_secs
,
1023 .extra2
= &hung_task_timeout_max
,
1026 .procname
= "hung_task_warnings",
1027 .data
= &sysctl_hung_task_warnings
,
1028 .maxlen
= sizeof(int),
1030 .proc_handler
= proc_dointvec_minmax
,
1034 #ifdef CONFIG_COMPAT
1036 .procname
= "compat-log",
1037 .data
= &compat_log
,
1038 .maxlen
= sizeof (int),
1040 .proc_handler
= proc_dointvec
,
1043 #ifdef CONFIG_RT_MUTEXES
1045 .procname
= "max_lock_depth",
1046 .data
= &max_lock_depth
,
1047 .maxlen
= sizeof(int),
1049 .proc_handler
= proc_dointvec
,
1053 .procname
= "poweroff_cmd",
1054 .data
= &poweroff_cmd
,
1055 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1057 .proc_handler
= proc_dostring
,
1063 .child
= key_sysctls
,
1066 #ifdef CONFIG_PERF_EVENTS
1068 * User-space scripts rely on the existence of this file
1069 * as a feature check for perf_events being enabled.
1071 * So it's an ABI, do not remove!
1074 .procname
= "perf_event_paranoid",
1075 .data
= &sysctl_perf_event_paranoid
,
1076 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1078 .proc_handler
= proc_dointvec
,
1081 .procname
= "perf_event_mlock_kb",
1082 .data
= &sysctl_perf_event_mlock
,
1083 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1085 .proc_handler
= proc_dointvec
,
1088 .procname
= "perf_event_max_sample_rate",
1089 .data
= &sysctl_perf_event_sample_rate
,
1090 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1092 .proc_handler
= perf_proc_update_handler
,
1096 .procname
= "perf_cpu_time_max_percent",
1097 .data
= &sysctl_perf_cpu_time_max_percent
,
1098 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1100 .proc_handler
= perf_cpu_time_max_percent_handler
,
1102 .extra2
= &one_hundred
,
1105 #ifdef CONFIG_KMEMCHECK
1107 .procname
= "kmemcheck",
1108 .data
= &kmemcheck_enabled
,
1109 .maxlen
= sizeof(int),
1111 .proc_handler
= proc_dointvec
,
1115 .procname
= "panic_on_warn",
1116 .data
= &panic_on_warn
,
1117 .maxlen
= sizeof(int),
1119 .proc_handler
= proc_dointvec_minmax
,
1126 static struct ctl_table vm_table
[] = {
1128 .procname
= "overcommit_memory",
1129 .data
= &sysctl_overcommit_memory
,
1130 .maxlen
= sizeof(sysctl_overcommit_memory
),
1132 .proc_handler
= proc_dointvec_minmax
,
1137 .procname
= "panic_on_oom",
1138 .data
= &sysctl_panic_on_oom
,
1139 .maxlen
= sizeof(sysctl_panic_on_oom
),
1141 .proc_handler
= proc_dointvec_minmax
,
1146 .procname
= "oom_kill_allocating_task",
1147 .data
= &sysctl_oom_kill_allocating_task
,
1148 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1150 .proc_handler
= proc_dointvec
,
1153 .procname
= "oom_dump_tasks",
1154 .data
= &sysctl_oom_dump_tasks
,
1155 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1157 .proc_handler
= proc_dointvec
,
1160 .procname
= "overcommit_ratio",
1161 .data
= &sysctl_overcommit_ratio
,
1162 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1164 .proc_handler
= overcommit_ratio_handler
,
1167 .procname
= "overcommit_kbytes",
1168 .data
= &sysctl_overcommit_kbytes
,
1169 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1171 .proc_handler
= overcommit_kbytes_handler
,
1174 .procname
= "page-cluster",
1175 .data
= &page_cluster
,
1176 .maxlen
= sizeof(int),
1178 .proc_handler
= proc_dointvec_minmax
,
1182 .procname
= "dirty_background_ratio",
1183 .data
= &dirty_background_ratio
,
1184 .maxlen
= sizeof(dirty_background_ratio
),
1186 .proc_handler
= dirty_background_ratio_handler
,
1188 .extra2
= &one_hundred
,
1191 .procname
= "dirty_background_bytes",
1192 .data
= &dirty_background_bytes
,
1193 .maxlen
= sizeof(dirty_background_bytes
),
1195 .proc_handler
= dirty_background_bytes_handler
,
1199 .procname
= "dirty_ratio",
1200 .data
= &vm_dirty_ratio
,
1201 .maxlen
= sizeof(vm_dirty_ratio
),
1203 .proc_handler
= dirty_ratio_handler
,
1205 .extra2
= &one_hundred
,
1208 .procname
= "dirty_bytes",
1209 .data
= &vm_dirty_bytes
,
1210 .maxlen
= sizeof(vm_dirty_bytes
),
1212 .proc_handler
= dirty_bytes_handler
,
1213 .extra1
= &dirty_bytes_min
,
1216 .procname
= "dirty_writeback_centisecs",
1217 .data
= &dirty_writeback_interval
,
1218 .maxlen
= sizeof(dirty_writeback_interval
),
1220 .proc_handler
= dirty_writeback_centisecs_handler
,
1223 .procname
= "dirty_expire_centisecs",
1224 .data
= &dirty_expire_interval
,
1225 .maxlen
= sizeof(dirty_expire_interval
),
1227 .proc_handler
= proc_dointvec_minmax
,
1231 .procname
= "nr_pdflush_threads",
1232 .mode
= 0444 /* read-only */,
1233 .proc_handler
= pdflush_proc_obsolete
,
1236 .procname
= "swappiness",
1237 .data
= &vm_swappiness
,
1238 .maxlen
= sizeof(vm_swappiness
),
1240 .proc_handler
= proc_dointvec_minmax
,
1242 .extra2
= &one_hundred
,
1244 #ifdef CONFIG_HUGETLB_PAGE
1246 .procname
= "nr_hugepages",
1248 .maxlen
= sizeof(unsigned long),
1250 .proc_handler
= hugetlb_sysctl_handler
,
1254 .procname
= "nr_hugepages_mempolicy",
1256 .maxlen
= sizeof(unsigned long),
1258 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1262 .procname
= "hugetlb_shm_group",
1263 .data
= &sysctl_hugetlb_shm_group
,
1264 .maxlen
= sizeof(gid_t
),
1266 .proc_handler
= proc_dointvec
,
1269 .procname
= "hugepages_treat_as_movable",
1270 .data
= &hugepages_treat_as_movable
,
1271 .maxlen
= sizeof(int),
1273 .proc_handler
= proc_dointvec
,
1276 .procname
= "nr_overcommit_hugepages",
1278 .maxlen
= sizeof(unsigned long),
1280 .proc_handler
= hugetlb_overcommit_handler
,
1284 .procname
= "lowmem_reserve_ratio",
1285 .data
= &sysctl_lowmem_reserve_ratio
,
1286 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1288 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1291 .procname
= "drop_caches",
1292 .data
= &sysctl_drop_caches
,
1293 .maxlen
= sizeof(int),
1295 .proc_handler
= drop_caches_sysctl_handler
,
1299 #ifdef CONFIG_COMPACTION
1301 .procname
= "compact_memory",
1302 .data
= &sysctl_compact_memory
,
1303 .maxlen
= sizeof(int),
1305 .proc_handler
= sysctl_compaction_handler
,
1308 .procname
= "extfrag_threshold",
1309 .data
= &sysctl_extfrag_threshold
,
1310 .maxlen
= sizeof(int),
1312 .proc_handler
= sysctl_extfrag_handler
,
1313 .extra1
= &min_extfrag_threshold
,
1314 .extra2
= &max_extfrag_threshold
,
1317 #endif /* CONFIG_COMPACTION */
1319 .procname
= "min_free_kbytes",
1320 .data
= &min_free_kbytes
,
1321 .maxlen
= sizeof(min_free_kbytes
),
1323 .proc_handler
= min_free_kbytes_sysctl_handler
,
1327 .procname
= "percpu_pagelist_fraction",
1328 .data
= &percpu_pagelist_fraction
,
1329 .maxlen
= sizeof(percpu_pagelist_fraction
),
1331 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1336 .procname
= "max_map_count",
1337 .data
= &sysctl_max_map_count
,
1338 .maxlen
= sizeof(sysctl_max_map_count
),
1340 .proc_handler
= proc_dointvec_minmax
,
1345 .procname
= "nr_trim_pages",
1346 .data
= &sysctl_nr_trim_pages
,
1347 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1349 .proc_handler
= proc_dointvec_minmax
,
1354 .procname
= "laptop_mode",
1355 .data
= &laptop_mode
,
1356 .maxlen
= sizeof(laptop_mode
),
1358 .proc_handler
= proc_dointvec_jiffies
,
1361 .procname
= "block_dump",
1362 .data
= &block_dump
,
1363 .maxlen
= sizeof(block_dump
),
1365 .proc_handler
= proc_dointvec
,
1369 .procname
= "vfs_cache_pressure",
1370 .data
= &sysctl_vfs_cache_pressure
,
1371 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1373 .proc_handler
= proc_dointvec
,
1376 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1378 .procname
= "legacy_va_layout",
1379 .data
= &sysctl_legacy_va_layout
,
1380 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1382 .proc_handler
= proc_dointvec
,
1388 .procname
= "zone_reclaim_mode",
1389 .data
= &zone_reclaim_mode
,
1390 .maxlen
= sizeof(zone_reclaim_mode
),
1392 .proc_handler
= proc_dointvec
,
1396 .procname
= "min_unmapped_ratio",
1397 .data
= &sysctl_min_unmapped_ratio
,
1398 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1400 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1402 .extra2
= &one_hundred
,
1405 .procname
= "min_slab_ratio",
1406 .data
= &sysctl_min_slab_ratio
,
1407 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1409 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1411 .extra2
= &one_hundred
,
1416 .procname
= "stat_interval",
1417 .data
= &sysctl_stat_interval
,
1418 .maxlen
= sizeof(sysctl_stat_interval
),
1420 .proc_handler
= proc_dointvec_jiffies
,
1425 .procname
= "mmap_min_addr",
1426 .data
= &dac_mmap_min_addr
,
1427 .maxlen
= sizeof(unsigned long),
1429 .proc_handler
= mmap_min_addr_handler
,
1434 .procname
= "numa_zonelist_order",
1435 .data
= &numa_zonelist_order
,
1436 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1438 .proc_handler
= numa_zonelist_order_handler
,
1441 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1442 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1444 .procname
= "vdso_enabled",
1445 #ifdef CONFIG_X86_32
1446 .data
= &vdso32_enabled
,
1447 .maxlen
= sizeof(vdso32_enabled
),
1449 .data
= &vdso_enabled
,
1450 .maxlen
= sizeof(vdso_enabled
),
1453 .proc_handler
= proc_dointvec
,
1457 #ifdef CONFIG_HIGHMEM
1459 .procname
= "highmem_is_dirtyable",
1460 .data
= &vm_highmem_is_dirtyable
,
1461 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1463 .proc_handler
= proc_dointvec_minmax
,
1468 #ifdef CONFIG_MEMORY_FAILURE
1470 .procname
= "memory_failure_early_kill",
1471 .data
= &sysctl_memory_failure_early_kill
,
1472 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1474 .proc_handler
= proc_dointvec_minmax
,
1479 .procname
= "memory_failure_recovery",
1480 .data
= &sysctl_memory_failure_recovery
,
1481 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1483 .proc_handler
= proc_dointvec_minmax
,
1489 .procname
= "user_reserve_kbytes",
1490 .data
= &sysctl_user_reserve_kbytes
,
1491 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1493 .proc_handler
= proc_doulongvec_minmax
,
1496 .procname
= "admin_reserve_kbytes",
1497 .data
= &sysctl_admin_reserve_kbytes
,
1498 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1500 .proc_handler
= proc_doulongvec_minmax
,
1505 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1506 static struct ctl_table binfmt_misc_table
[] = {
1511 static struct ctl_table fs_table
[] = {
1513 .procname
= "inode-nr",
1514 .data
= &inodes_stat
,
1515 .maxlen
= 2*sizeof(long),
1517 .proc_handler
= proc_nr_inodes
,
1520 .procname
= "inode-state",
1521 .data
= &inodes_stat
,
1522 .maxlen
= 7*sizeof(long),
1524 .proc_handler
= proc_nr_inodes
,
1527 .procname
= "file-nr",
1528 .data
= &files_stat
,
1529 .maxlen
= sizeof(files_stat
),
1531 .proc_handler
= proc_nr_files
,
1534 .procname
= "file-max",
1535 .data
= &files_stat
.max_files
,
1536 .maxlen
= sizeof(files_stat
.max_files
),
1538 .proc_handler
= proc_doulongvec_minmax
,
1541 .procname
= "nr_open",
1542 .data
= &sysctl_nr_open
,
1543 .maxlen
= sizeof(int),
1545 .proc_handler
= proc_dointvec_minmax
,
1546 .extra1
= &sysctl_nr_open_min
,
1547 .extra2
= &sysctl_nr_open_max
,
1550 .procname
= "dentry-state",
1551 .data
= &dentry_stat
,
1552 .maxlen
= 6*sizeof(long),
1554 .proc_handler
= proc_nr_dentry
,
1557 .procname
= "overflowuid",
1558 .data
= &fs_overflowuid
,
1559 .maxlen
= sizeof(int),
1561 .proc_handler
= proc_dointvec_minmax
,
1562 .extra1
= &minolduid
,
1563 .extra2
= &maxolduid
,
1566 .procname
= "overflowgid",
1567 .data
= &fs_overflowgid
,
1568 .maxlen
= sizeof(int),
1570 .proc_handler
= proc_dointvec_minmax
,
1571 .extra1
= &minolduid
,
1572 .extra2
= &maxolduid
,
1574 #ifdef CONFIG_FILE_LOCKING
1576 .procname
= "leases-enable",
1577 .data
= &leases_enable
,
1578 .maxlen
= sizeof(int),
1580 .proc_handler
= proc_dointvec
,
1583 #ifdef CONFIG_DNOTIFY
1585 .procname
= "dir-notify-enable",
1586 .data
= &dir_notify_enable
,
1587 .maxlen
= sizeof(int),
1589 .proc_handler
= proc_dointvec
,
1593 #ifdef CONFIG_FILE_LOCKING
1595 .procname
= "lease-break-time",
1596 .data
= &lease_break_time
,
1597 .maxlen
= sizeof(int),
1599 .proc_handler
= proc_dointvec
,
1604 .procname
= "aio-nr",
1606 .maxlen
= sizeof(aio_nr
),
1608 .proc_handler
= proc_doulongvec_minmax
,
1611 .procname
= "aio-max-nr",
1612 .data
= &aio_max_nr
,
1613 .maxlen
= sizeof(aio_max_nr
),
1615 .proc_handler
= proc_doulongvec_minmax
,
1617 #endif /* CONFIG_AIO */
1618 #ifdef CONFIG_INOTIFY_USER
1620 .procname
= "inotify",
1622 .child
= inotify_table
,
1627 .procname
= "epoll",
1629 .child
= epoll_table
,
1634 .procname
= "protected_symlinks",
1635 .data
= &sysctl_protected_symlinks
,
1636 .maxlen
= sizeof(int),
1638 .proc_handler
= proc_dointvec_minmax
,
1643 .procname
= "protected_hardlinks",
1644 .data
= &sysctl_protected_hardlinks
,
1645 .maxlen
= sizeof(int),
1647 .proc_handler
= proc_dointvec_minmax
,
1652 .procname
= "suid_dumpable",
1653 .data
= &suid_dumpable
,
1654 .maxlen
= sizeof(int),
1656 .proc_handler
= proc_dointvec_minmax_coredump
,
1660 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1662 .procname
= "binfmt_misc",
1664 .child
= binfmt_misc_table
,
1668 .procname
= "pipe-max-size",
1669 .data
= &pipe_max_size
,
1670 .maxlen
= sizeof(int),
1672 .proc_handler
= &pipe_proc_fn
,
1673 .extra1
= &pipe_min_size
,
1678 static struct ctl_table debug_table
[] = {
1679 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1681 .procname
= "exception-trace",
1682 .data
= &show_unhandled_signals
,
1683 .maxlen
= sizeof(int),
1685 .proc_handler
= proc_dointvec
1688 #if defined(CONFIG_OPTPROBES)
1690 .procname
= "kprobes-optimization",
1691 .data
= &sysctl_kprobes_optimization
,
1692 .maxlen
= sizeof(int),
1694 .proc_handler
= proc_kprobes_optimization_handler
,
1702 static struct ctl_table dev_table
[] = {
1706 int __init
sysctl_init(void)
1708 struct ctl_table_header
*hdr
;
1710 hdr
= register_sysctl_table(sysctl_base_table
);
1711 kmemleak_not_leak(hdr
);
1715 #endif /* CONFIG_SYSCTL */
1721 #ifdef CONFIG_PROC_SYSCTL
1723 static int _proc_do_string(char *data
, int maxlen
, int write
,
1724 char __user
*buffer
,
1725 size_t *lenp
, loff_t
*ppos
)
1731 if (!data
|| !maxlen
|| !*lenp
) {
1737 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1738 /* Only continue writes not past the end of buffer. */
1740 if (len
> maxlen
- 1)
1747 /* Start writing from beginning of buffer. */
1753 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1754 if (get_user(c
, p
++))
1756 if (c
== 0 || c
== '\n')
1777 if (copy_to_user(buffer
, data
, len
))
1780 if (put_user('\n', buffer
+ len
))
1790 static void warn_sysctl_write(struct ctl_table
*table
)
1792 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1793 "This will not be supported in the future. To silence this\n"
1794 "warning, set kernel.sysctl_writes_strict = -1\n",
1795 current
->comm
, table
->procname
);
1799 * proc_dostring - read a string sysctl
1800 * @table: the sysctl table
1801 * @write: %TRUE if this is a write to the sysctl file
1802 * @buffer: the user buffer
1803 * @lenp: the size of the user buffer
1804 * @ppos: file position
1806 * Reads/writes a string from/to the user buffer. If the kernel
1807 * buffer provided is not large enough to hold the string, the
1808 * string is truncated. The copied string is %NULL-terminated.
1809 * If the string is being read by the user process, it is copied
1810 * and a newline '\n' is added. It is truncated if the buffer is
1813 * Returns 0 on success.
1815 int proc_dostring(struct ctl_table
*table
, int write
,
1816 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1818 if (write
&& *ppos
&& sysctl_writes_strict
== SYSCTL_WRITES_WARN
)
1819 warn_sysctl_write(table
);
1821 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
1822 (char __user
*)buffer
, lenp
, ppos
);
1825 static size_t proc_skip_spaces(char **buf
)
1828 char *tmp
= skip_spaces(*buf
);
1834 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1844 #define TMPBUFLEN 22
1846 * proc_get_long - reads an ASCII formatted integer from a user buffer
1848 * @buf: a kernel buffer
1849 * @size: size of the kernel buffer
1850 * @val: this is where the number will be stored
1851 * @neg: set to %TRUE if number is negative
1852 * @perm_tr: a vector which contains the allowed trailers
1853 * @perm_tr_len: size of the perm_tr vector
1854 * @tr: pointer to store the trailer character
1856 * In case of success %0 is returned and @buf and @size are updated with
1857 * the amount of bytes read. If @tr is non-NULL and a trailing
1858 * character exists (size is non-zero after returning from this
1859 * function), @tr is updated with the trailing character.
1861 static int proc_get_long(char **buf
, size_t *size
,
1862 unsigned long *val
, bool *neg
,
1863 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1866 char *p
, tmp
[TMPBUFLEN
];
1872 if (len
> TMPBUFLEN
- 1)
1873 len
= TMPBUFLEN
- 1;
1875 memcpy(tmp
, *buf
, len
);
1879 if (*p
== '-' && *size
> 1) {
1887 *val
= simple_strtoul(p
, &p
, 0);
1891 /* We don't know if the next char is whitespace thus we may accept
1892 * invalid integers (e.g. 1234...a) or two integers instead of one
1893 * (e.g. 123...1). So lets not allow such large numbers. */
1894 if (len
== TMPBUFLEN
- 1)
1897 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1900 if (tr
&& (len
< *size
))
1910 * proc_put_long - converts an integer to a decimal ASCII formatted string
1912 * @buf: the user buffer
1913 * @size: the size of the user buffer
1914 * @val: the integer to be converted
1915 * @neg: sign of the number, %TRUE for negative
1917 * In case of success %0 is returned and @buf and @size are updated with
1918 * the amount of bytes written.
1920 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1924 char tmp
[TMPBUFLEN
], *p
= tmp
;
1926 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1930 if (copy_to_user(*buf
, tmp
, len
))
1938 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1941 char __user
**buffer
= (char __user
**)buf
;
1942 if (put_user(c
, *buffer
))
1944 (*size
)--, (*buffer
)++;
1950 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1952 int write
, void *data
)
1955 *valp
= *negp
? -*lvalp
: *lvalp
;
1960 *lvalp
= (unsigned long)-val
;
1963 *lvalp
= (unsigned long)val
;
1969 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1971 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1972 int write
, void __user
*buffer
,
1973 size_t *lenp
, loff_t
*ppos
,
1974 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1975 int write
, void *data
),
1978 int *i
, vleft
, first
= 1, err
= 0;
1979 unsigned long page
= 0;
1983 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1988 i
= (int *) tbl_data
;
1989 vleft
= table
->maxlen
/ sizeof(*i
);
1993 conv
= do_proc_dointvec_conv
;
1997 switch (sysctl_writes_strict
) {
1998 case SYSCTL_WRITES_STRICT
:
2000 case SYSCTL_WRITES_WARN
:
2001 warn_sysctl_write(table
);
2008 if (left
> PAGE_SIZE
- 1)
2009 left
= PAGE_SIZE
- 1;
2010 page
= __get_free_page(GFP_TEMPORARY
);
2011 kbuf
= (char *) page
;
2014 if (copy_from_user(kbuf
, buffer
, left
)) {
2021 for (; left
&& vleft
--; i
++, first
=0) {
2026 left
-= proc_skip_spaces(&kbuf
);
2030 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2032 sizeof(proc_wspace_sep
), NULL
);
2035 if (conv(&neg
, &lval
, i
, 1, data
)) {
2040 if (conv(&neg
, &lval
, i
, 0, data
)) {
2045 err
= proc_put_char(&buffer
, &left
, '\t');
2048 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2054 if (!write
&& !first
&& left
&& !err
)
2055 err
= proc_put_char(&buffer
, &left
, '\n');
2056 if (write
&& !err
&& left
)
2057 left
-= proc_skip_spaces(&kbuf
);
2062 return err
? : -EINVAL
;
2070 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2071 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2072 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2073 int write
, void *data
),
2076 return __do_proc_dointvec(table
->data
, table
, write
,
2077 buffer
, lenp
, ppos
, conv
, data
);
2081 * proc_dointvec - read a vector of integers
2082 * @table: the sysctl table
2083 * @write: %TRUE if this is a write to the sysctl file
2084 * @buffer: the user buffer
2085 * @lenp: the size of the user buffer
2086 * @ppos: file position
2088 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2089 * values from/to the user buffer, treated as an ASCII string.
2091 * Returns 0 on success.
2093 int proc_dointvec(struct ctl_table
*table
, int write
,
2094 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2096 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2101 * Taint values can only be increased
2102 * This means we can safely use a temporary.
2104 static int proc_taint(struct ctl_table
*table
, int write
,
2105 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2108 unsigned long tmptaint
= get_taint();
2111 if (write
&& !capable(CAP_SYS_ADMIN
))
2116 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2122 * Poor man's atomic or. Not worth adding a primitive
2123 * to everyone's atomic.h for this
2126 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2127 if ((tmptaint
>> i
) & 1)
2128 add_taint(i
, LOCKDEP_STILL_OK
);
2135 #ifdef CONFIG_PRINTK
2136 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2137 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2139 if (write
&& !capable(CAP_SYS_ADMIN
))
2142 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2146 struct do_proc_dointvec_minmax_conv_param
{
2151 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2153 int write
, void *data
)
2155 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2157 int val
= *negp
? -*lvalp
: *lvalp
;
2158 if ((param
->min
&& *param
->min
> val
) ||
2159 (param
->max
&& *param
->max
< val
))
2166 *lvalp
= (unsigned long)-val
;
2169 *lvalp
= (unsigned long)val
;
2176 * proc_dointvec_minmax - read a vector of integers with min/max values
2177 * @table: the sysctl table
2178 * @write: %TRUE if this is a write to the sysctl file
2179 * @buffer: the user buffer
2180 * @lenp: the size of the user buffer
2181 * @ppos: file position
2183 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2184 * values from/to the user buffer, treated as an ASCII string.
2186 * This routine will ensure the values are within the range specified by
2187 * table->extra1 (min) and table->extra2 (max).
2189 * Returns 0 on success.
2191 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2192 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2194 struct do_proc_dointvec_minmax_conv_param param
= {
2195 .min
= (int *) table
->extra1
,
2196 .max
= (int *) table
->extra2
,
2198 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2199 do_proc_dointvec_minmax_conv
, ¶m
);
2202 static void validate_coredump_safety(void)
2204 #ifdef CONFIG_COREDUMP
2205 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2206 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2207 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2208 "suid_dumpable=2. Pipe handler or fully qualified "\
2209 "core dump path required.\n");
2214 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2215 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2217 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2219 validate_coredump_safety();
2223 #ifdef CONFIG_COREDUMP
2224 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2225 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2227 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2229 validate_coredump_safety();
2234 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2235 void __user
*buffer
,
2236 size_t *lenp
, loff_t
*ppos
,
2237 unsigned long convmul
,
2238 unsigned long convdiv
)
2240 unsigned long *i
, *min
, *max
;
2241 int vleft
, first
= 1, err
= 0;
2242 unsigned long page
= 0;
2246 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2251 i
= (unsigned long *) data
;
2252 min
= (unsigned long *) table
->extra1
;
2253 max
= (unsigned long *) table
->extra2
;
2254 vleft
= table
->maxlen
/ sizeof(unsigned long);
2259 switch (sysctl_writes_strict
) {
2260 case SYSCTL_WRITES_STRICT
:
2262 case SYSCTL_WRITES_WARN
:
2263 warn_sysctl_write(table
);
2270 if (left
> PAGE_SIZE
- 1)
2271 left
= PAGE_SIZE
- 1;
2272 page
= __get_free_page(GFP_TEMPORARY
);
2273 kbuf
= (char *) page
;
2276 if (copy_from_user(kbuf
, buffer
, left
)) {
2283 for (; left
&& vleft
--; i
++, first
= 0) {
2289 left
-= proc_skip_spaces(&kbuf
);
2291 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2293 sizeof(proc_wspace_sep
), NULL
);
2298 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2302 val
= convdiv
* (*i
) / convmul
;
2304 err
= proc_put_char(&buffer
, &left
, '\t');
2308 err
= proc_put_long(&buffer
, &left
, val
, false);
2314 if (!write
&& !first
&& left
&& !err
)
2315 err
= proc_put_char(&buffer
, &left
, '\n');
2317 left
-= proc_skip_spaces(&kbuf
);
2322 return err
? : -EINVAL
;
2330 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2331 void __user
*buffer
,
2332 size_t *lenp
, loff_t
*ppos
,
2333 unsigned long convmul
,
2334 unsigned long convdiv
)
2336 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2337 buffer
, lenp
, ppos
, convmul
, convdiv
);
2341 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2342 * @table: the sysctl table
2343 * @write: %TRUE if this is a write to the sysctl file
2344 * @buffer: the user buffer
2345 * @lenp: the size of the user buffer
2346 * @ppos: file position
2348 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2349 * values from/to the user buffer, treated as an ASCII string.
2351 * This routine will ensure the values are within the range specified by
2352 * table->extra1 (min) and table->extra2 (max).
2354 * Returns 0 on success.
2356 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2357 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2359 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2363 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2364 * @table: the sysctl table
2365 * @write: %TRUE if this is a write to the sysctl file
2366 * @buffer: the user buffer
2367 * @lenp: the size of the user buffer
2368 * @ppos: file position
2370 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2371 * values from/to the user buffer, treated as an ASCII string. The values
2372 * are treated as milliseconds, and converted to jiffies when they are stored.
2374 * This routine will ensure the values are within the range specified by
2375 * table->extra1 (min) and table->extra2 (max).
2377 * Returns 0 on success.
2379 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2380 void __user
*buffer
,
2381 size_t *lenp
, loff_t
*ppos
)
2383 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2384 lenp
, ppos
, HZ
, 1000l);
2388 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2390 int write
, void *data
)
2393 if (*lvalp
> LONG_MAX
/ HZ
)
2395 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2401 lval
= (unsigned long)-val
;
2404 lval
= (unsigned long)val
;
2411 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2413 int write
, void *data
)
2416 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2418 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2424 lval
= (unsigned long)-val
;
2427 lval
= (unsigned long)val
;
2429 *lvalp
= jiffies_to_clock_t(lval
);
2434 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2436 int write
, void *data
)
2439 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2449 lval
= (unsigned long)-val
;
2452 lval
= (unsigned long)val
;
2454 *lvalp
= jiffies_to_msecs(lval
);
2460 * proc_dointvec_jiffies - read a vector of integers as seconds
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 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2468 * values from/to the user buffer, treated as an ASCII string.
2469 * The values read are assumed to be in seconds, and are converted into
2472 * Returns 0 on success.
2474 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2475 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2477 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2478 do_proc_dointvec_jiffies_conv
,NULL
);
2482 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2483 * @table: the sysctl table
2484 * @write: %TRUE if this is a write to the sysctl file
2485 * @buffer: the user buffer
2486 * @lenp: the size of the user buffer
2487 * @ppos: pointer to the file position
2489 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2490 * values from/to the user buffer, treated as an ASCII string.
2491 * The values read are assumed to be in 1/USER_HZ seconds, and
2492 * are converted into jiffies.
2494 * Returns 0 on success.
2496 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2497 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2499 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2500 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2504 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2505 * @table: the sysctl table
2506 * @write: %TRUE if this is a write to the sysctl file
2507 * @buffer: the user buffer
2508 * @lenp: the size of the user buffer
2509 * @ppos: file position
2510 * @ppos: the current position in the file
2512 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2513 * values from/to the user buffer, treated as an ASCII string.
2514 * The values read are assumed to be in 1/1000 seconds, and
2515 * are converted into jiffies.
2517 * Returns 0 on success.
2519 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2520 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2522 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2523 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2526 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2527 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2529 struct pid
*new_pid
;
2533 tmp
= pid_vnr(cad_pid
);
2535 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2536 lenp
, ppos
, NULL
, NULL
);
2540 new_pid
= find_get_pid(tmp
);
2544 put_pid(xchg(&cad_pid
, new_pid
));
2549 * proc_do_large_bitmap - read/write from/to a large bitmap
2550 * @table: the sysctl table
2551 * @write: %TRUE if this is a write to the sysctl file
2552 * @buffer: the user buffer
2553 * @lenp: the size of the user buffer
2554 * @ppos: file position
2556 * The bitmap is stored at table->data and the bitmap length (in bits)
2559 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2560 * large bitmaps may be represented in a compact manner. Writing into
2561 * the file will clear the bitmap then update it with the given input.
2563 * Returns 0 on success.
2565 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2566 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2570 size_t left
= *lenp
;
2571 unsigned long bitmap_len
= table
->maxlen
;
2572 unsigned long *bitmap
= *(unsigned long **) table
->data
;
2573 unsigned long *tmp_bitmap
= NULL
;
2574 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2576 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2582 unsigned long page
= 0;
2585 if (left
> PAGE_SIZE
- 1)
2586 left
= PAGE_SIZE
- 1;
2588 page
= __get_free_page(GFP_TEMPORARY
);
2589 kbuf
= (char *) page
;
2592 if (copy_from_user(kbuf
, buffer
, left
)) {
2598 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2604 proc_skip_char(&kbuf
, &left
, '\n');
2605 while (!err
&& left
) {
2606 unsigned long val_a
, val_b
;
2609 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2613 if (val_a
>= bitmap_len
|| neg
) {
2625 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2626 &neg
, tr_b
, sizeof(tr_b
),
2630 if (val_b
>= bitmap_len
|| neg
||
2641 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2643 proc_skip_char(&kbuf
, &left
, '\n');
2647 unsigned long bit_a
, bit_b
= 0;
2650 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2651 if (bit_a
>= bitmap_len
)
2653 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2657 err
= proc_put_char(&buffer
, &left
, ',');
2661 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2664 if (bit_a
!= bit_b
) {
2665 err
= proc_put_char(&buffer
, &left
, '-');
2668 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2676 err
= proc_put_char(&buffer
, &left
, '\n');
2682 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2684 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2696 #else /* CONFIG_PROC_SYSCTL */
2698 int proc_dostring(struct ctl_table
*table
, int write
,
2699 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2704 int proc_dointvec(struct ctl_table
*table
, int write
,
2705 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2710 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2711 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2716 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2717 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2722 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2723 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2728 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2729 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2734 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2735 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2740 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2741 void __user
*buffer
,
2742 size_t *lenp
, loff_t
*ppos
)
2748 #endif /* CONFIG_PROC_SYSCTL */
2751 * No sense putting this after each symbol definition, twice,
2752 * exception granted :-)
2754 EXPORT_SYMBOL(proc_dointvec
);
2755 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2756 EXPORT_SYMBOL(proc_dointvec_minmax
);
2757 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2758 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2759 EXPORT_SYMBOL(proc_dostring
);
2760 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2761 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);