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>
97 #if defined(CONFIG_SYSCTL)
99 /* External variables not in a header file. */
100 extern int max_threads
;
101 extern int suid_dumpable
;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid
;
104 extern char core_pattern
[];
105 extern unsigned int core_pipe_limit
;
108 extern int pid_max_min
, pid_max_max
;
109 extern int percpu_pagelist_fraction
;
110 extern int compat_log
;
111 extern int latencytop_enabled
;
112 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
114 extern int sysctl_nr_trim_pages
;
117 /* Constants used for minimum and maximum */
118 #ifdef CONFIG_LOCKUP_DETECTOR
119 static int sixty
= 60;
122 static int __maybe_unused neg_one
= -1;
125 static int __maybe_unused one
= 1;
126 static int __maybe_unused two
= 2;
127 static int __maybe_unused four
= 4;
128 static unsigned long one_ul
= 1;
129 static int one_hundred
= 100;
131 static int ten_thousand
= 10000;
134 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
135 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
137 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
138 static int maxolduid
= 65535;
139 static int minolduid
;
141 static int ngroups_max
= NGROUPS_MAX
;
142 static const int cap_last_cap
= CAP_LAST_CAP
;
144 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
145 #ifdef CONFIG_DETECT_HUNG_TASK
146 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
149 #ifdef CONFIG_INOTIFY_USER
150 #include <linux/inotify.h>
156 extern int pwrsw_enabled
;
159 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
160 extern int unaligned_enabled
;
164 extern int unaligned_dump_stack
;
167 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168 extern int no_unaligned_warning
;
171 #ifdef CONFIG_PROC_SYSCTL
173 #define SYSCTL_WRITES_LEGACY -1
174 #define SYSCTL_WRITES_WARN 0
175 #define SYSCTL_WRITES_STRICT 1
177 static int sysctl_writes_strict
= SYSCTL_WRITES_WARN
;
179 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
180 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
181 static int proc_taint(struct ctl_table
*table
, int write
,
182 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
186 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
187 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
190 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
191 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
192 #ifdef CONFIG_COREDUMP
193 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
194 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
197 #ifdef CONFIG_MAGIC_SYSRQ
198 /* Note: sysrq code uses it's own private copy */
199 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
201 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
202 void __user
*buffer
, size_t *lenp
,
207 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
212 sysrq_toggle_support(__sysrq_enabled
);
219 static struct ctl_table kern_table
[];
220 static struct ctl_table vm_table
[];
221 static struct ctl_table fs_table
[];
222 static struct ctl_table debug_table
[];
223 static struct ctl_table dev_table
[];
224 extern struct ctl_table random_table
[];
226 extern struct ctl_table epoll_table
[];
229 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
230 int sysctl_legacy_va_layout
;
233 /* The default sysctl tables: */
235 static struct ctl_table sysctl_base_table
[] = {
237 .procname
= "kernel",
254 .child
= debug_table
,
264 #ifdef CONFIG_SCHED_DEBUG
265 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
266 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
267 static int min_wakeup_granularity_ns
; /* 0 usecs */
268 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
270 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
271 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
272 #endif /* CONFIG_SMP */
273 #endif /* CONFIG_SCHED_DEBUG */
275 #ifdef CONFIG_COMPACTION
276 static int min_extfrag_threshold
;
277 static int max_extfrag_threshold
= 1000;
280 static struct ctl_table kern_table
[] = {
282 .procname
= "sched_child_runs_first",
283 .data
= &sysctl_sched_child_runs_first
,
284 .maxlen
= sizeof(unsigned int),
286 .proc_handler
= proc_dointvec
,
288 #ifdef CONFIG_SCHED_DEBUG
290 .procname
= "sched_min_granularity_ns",
291 .data
= &sysctl_sched_min_granularity
,
292 .maxlen
= sizeof(unsigned int),
294 .proc_handler
= sched_proc_update_handler
,
295 .extra1
= &min_sched_granularity_ns
,
296 .extra2
= &max_sched_granularity_ns
,
299 .procname
= "sched_latency_ns",
300 .data
= &sysctl_sched_latency
,
301 .maxlen
= sizeof(unsigned int),
303 .proc_handler
= sched_proc_update_handler
,
304 .extra1
= &min_sched_granularity_ns
,
305 .extra2
= &max_sched_granularity_ns
,
308 .procname
= "sched_wakeup_granularity_ns",
309 .data
= &sysctl_sched_wakeup_granularity
,
310 .maxlen
= sizeof(unsigned int),
312 .proc_handler
= sched_proc_update_handler
,
313 .extra1
= &min_wakeup_granularity_ns
,
314 .extra2
= &max_wakeup_granularity_ns
,
318 .procname
= "sched_tunable_scaling",
319 .data
= &sysctl_sched_tunable_scaling
,
320 .maxlen
= sizeof(enum sched_tunable_scaling
),
322 .proc_handler
= sched_proc_update_handler
,
323 .extra1
= &min_sched_tunable_scaling
,
324 .extra2
= &max_sched_tunable_scaling
,
327 .procname
= "sched_migration_cost_ns",
328 .data
= &sysctl_sched_migration_cost
,
329 .maxlen
= sizeof(unsigned int),
331 .proc_handler
= proc_dointvec
,
334 .procname
= "sched_nr_migrate",
335 .data
= &sysctl_sched_nr_migrate
,
336 .maxlen
= sizeof(unsigned int),
338 .proc_handler
= proc_dointvec
,
341 .procname
= "sched_time_avg_ms",
342 .data
= &sysctl_sched_time_avg
,
343 .maxlen
= sizeof(unsigned int),
345 .proc_handler
= proc_dointvec
,
348 .procname
= "sched_shares_window_ns",
349 .data
= &sysctl_sched_shares_window
,
350 .maxlen
= sizeof(unsigned int),
352 .proc_handler
= proc_dointvec
,
355 .procname
= "timer_migration",
356 .data
= &sysctl_timer_migration
,
357 .maxlen
= sizeof(unsigned int),
359 .proc_handler
= proc_dointvec_minmax
,
363 #endif /* CONFIG_SMP */
364 #ifdef CONFIG_NUMA_BALANCING
366 .procname
= "numa_balancing_scan_delay_ms",
367 .data
= &sysctl_numa_balancing_scan_delay
,
368 .maxlen
= sizeof(unsigned int),
370 .proc_handler
= proc_dointvec
,
373 .procname
= "numa_balancing_scan_period_min_ms",
374 .data
= &sysctl_numa_balancing_scan_period_min
,
375 .maxlen
= sizeof(unsigned int),
377 .proc_handler
= proc_dointvec
,
380 .procname
= "numa_balancing_scan_period_max_ms",
381 .data
= &sysctl_numa_balancing_scan_period_max
,
382 .maxlen
= sizeof(unsigned int),
384 .proc_handler
= proc_dointvec
,
387 .procname
= "numa_balancing_scan_size_mb",
388 .data
= &sysctl_numa_balancing_scan_size
,
389 .maxlen
= sizeof(unsigned int),
391 .proc_handler
= proc_dointvec_minmax
,
395 .procname
= "numa_balancing",
396 .data
= NULL
, /* filled in by handler */
397 .maxlen
= sizeof(unsigned int),
399 .proc_handler
= sysctl_numa_balancing
,
403 #endif /* CONFIG_NUMA_BALANCING */
404 #endif /* CONFIG_SCHED_DEBUG */
406 .procname
= "sched_rt_period_us",
407 .data
= &sysctl_sched_rt_period
,
408 .maxlen
= sizeof(unsigned int),
410 .proc_handler
= sched_rt_handler
,
413 .procname
= "sched_rt_runtime_us",
414 .data
= &sysctl_sched_rt_runtime
,
415 .maxlen
= sizeof(int),
417 .proc_handler
= sched_rt_handler
,
420 .procname
= "sched_rr_timeslice_ms",
421 .data
= &sched_rr_timeslice
,
422 .maxlen
= sizeof(int),
424 .proc_handler
= sched_rr_handler
,
426 #ifdef CONFIG_SCHED_AUTOGROUP
428 .procname
= "sched_autogroup_enabled",
429 .data
= &sysctl_sched_autogroup_enabled
,
430 .maxlen
= sizeof(unsigned int),
432 .proc_handler
= proc_dointvec_minmax
,
437 #ifdef CONFIG_CFS_BANDWIDTH
439 .procname
= "sched_cfs_bandwidth_slice_us",
440 .data
= &sysctl_sched_cfs_bandwidth_slice
,
441 .maxlen
= sizeof(unsigned int),
443 .proc_handler
= proc_dointvec_minmax
,
447 #ifdef CONFIG_PROVE_LOCKING
449 .procname
= "prove_locking",
450 .data
= &prove_locking
,
451 .maxlen
= sizeof(int),
453 .proc_handler
= proc_dointvec
,
456 #ifdef CONFIG_LOCK_STAT
458 .procname
= "lock_stat",
460 .maxlen
= sizeof(int),
462 .proc_handler
= proc_dointvec
,
467 .data
= &panic_timeout
,
468 .maxlen
= sizeof(int),
470 .proc_handler
= proc_dointvec
,
472 #ifdef CONFIG_COREDUMP
474 .procname
= "core_uses_pid",
475 .data
= &core_uses_pid
,
476 .maxlen
= sizeof(int),
478 .proc_handler
= proc_dointvec
,
481 .procname
= "core_pattern",
482 .data
= core_pattern
,
483 .maxlen
= CORENAME_MAX_SIZE
,
485 .proc_handler
= proc_dostring_coredump
,
488 .procname
= "core_pipe_limit",
489 .data
= &core_pipe_limit
,
490 .maxlen
= sizeof(unsigned int),
492 .proc_handler
= proc_dointvec
,
495 #ifdef CONFIG_PROC_SYSCTL
497 .procname
= "tainted",
498 .maxlen
= sizeof(long),
500 .proc_handler
= proc_taint
,
503 .procname
= "sysctl_writes_strict",
504 .data
= &sysctl_writes_strict
,
505 .maxlen
= sizeof(int),
507 .proc_handler
= proc_dointvec_minmax
,
512 #ifdef CONFIG_LATENCYTOP
514 .procname
= "latencytop",
515 .data
= &latencytop_enabled
,
516 .maxlen
= sizeof(int),
518 .proc_handler
= proc_dointvec
,
521 #ifdef CONFIG_BLK_DEV_INITRD
523 .procname
= "real-root-dev",
524 .data
= &real_root_dev
,
525 .maxlen
= sizeof(int),
527 .proc_handler
= proc_dointvec
,
531 .procname
= "print-fatal-signals",
532 .data
= &print_fatal_signals
,
533 .maxlen
= sizeof(int),
535 .proc_handler
= proc_dointvec
,
539 .procname
= "reboot-cmd",
540 .data
= reboot_command
,
543 .proc_handler
= proc_dostring
,
546 .procname
= "stop-a",
547 .data
= &stop_a_enabled
,
548 .maxlen
= sizeof (int),
550 .proc_handler
= proc_dointvec
,
553 .procname
= "scons-poweroff",
554 .data
= &scons_pwroff
,
555 .maxlen
= sizeof (int),
557 .proc_handler
= proc_dointvec
,
560 #ifdef CONFIG_SPARC64
562 .procname
= "tsb-ratio",
563 .data
= &sysctl_tsb_ratio
,
564 .maxlen
= sizeof (int),
566 .proc_handler
= proc_dointvec
,
571 .procname
= "soft-power",
572 .data
= &pwrsw_enabled
,
573 .maxlen
= sizeof (int),
575 .proc_handler
= proc_dointvec
,
578 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
580 .procname
= "unaligned-trap",
581 .data
= &unaligned_enabled
,
582 .maxlen
= sizeof (int),
584 .proc_handler
= proc_dointvec
,
588 .procname
= "ctrl-alt-del",
590 .maxlen
= sizeof(int),
592 .proc_handler
= proc_dointvec
,
594 #ifdef CONFIG_FUNCTION_TRACER
596 .procname
= "ftrace_enabled",
597 .data
= &ftrace_enabled
,
598 .maxlen
= sizeof(int),
600 .proc_handler
= ftrace_enable_sysctl
,
603 #ifdef CONFIG_STACK_TRACER
605 .procname
= "stack_tracer_enabled",
606 .data
= &stack_tracer_enabled
,
607 .maxlen
= sizeof(int),
609 .proc_handler
= stack_trace_sysctl
,
612 #ifdef CONFIG_TRACING
614 .procname
= "ftrace_dump_on_oops",
615 .data
= &ftrace_dump_on_oops
,
616 .maxlen
= sizeof(int),
618 .proc_handler
= proc_dointvec
,
621 .procname
= "traceoff_on_warning",
622 .data
= &__disable_trace_on_warning
,
623 .maxlen
= sizeof(__disable_trace_on_warning
),
625 .proc_handler
= proc_dointvec
,
628 .procname
= "tracepoint_printk",
629 .data
= &tracepoint_printk
,
630 .maxlen
= sizeof(tracepoint_printk
),
632 .proc_handler
= proc_dointvec
,
637 .procname
= "kexec_load_disabled",
638 .data
= &kexec_load_disabled
,
639 .maxlen
= sizeof(int),
641 /* only handle a transition from default "0" to "1" */
642 .proc_handler
= proc_dointvec_minmax
,
647 #ifdef CONFIG_MODULES
649 .procname
= "modprobe",
650 .data
= &modprobe_path
,
651 .maxlen
= KMOD_PATH_LEN
,
653 .proc_handler
= proc_dostring
,
656 .procname
= "modules_disabled",
657 .data
= &modules_disabled
,
658 .maxlen
= sizeof(int),
660 /* only handle a transition from default "0" to "1" */
661 .proc_handler
= proc_dointvec_minmax
,
666 #ifdef CONFIG_UEVENT_HELPER
668 .procname
= "hotplug",
669 .data
= &uevent_helper
,
670 .maxlen
= UEVENT_HELPER_PATH_LEN
,
672 .proc_handler
= proc_dostring
,
675 #ifdef CONFIG_CHR_DEV_SG
677 .procname
= "sg-big-buff",
678 .data
= &sg_big_buff
,
679 .maxlen
= sizeof (int),
681 .proc_handler
= proc_dointvec
,
684 #ifdef CONFIG_BSD_PROCESS_ACCT
688 .maxlen
= 3*sizeof(int),
690 .proc_handler
= proc_dointvec
,
693 #ifdef CONFIG_MAGIC_SYSRQ
696 .data
= &__sysrq_enabled
,
697 .maxlen
= sizeof (int),
699 .proc_handler
= sysrq_sysctl_handler
,
702 #ifdef CONFIG_PROC_SYSCTL
704 .procname
= "cad_pid",
706 .maxlen
= sizeof (int),
708 .proc_handler
= proc_do_cad_pid
,
712 .procname
= "threads-max",
713 .data
= &max_threads
,
714 .maxlen
= sizeof(int),
716 .proc_handler
= proc_dointvec
,
719 .procname
= "random",
721 .child
= random_table
,
724 .procname
= "usermodehelper",
726 .child
= usermodehelper_table
,
729 .procname
= "overflowuid",
730 .data
= &overflowuid
,
731 .maxlen
= sizeof(int),
733 .proc_handler
= proc_dointvec_minmax
,
734 .extra1
= &minolduid
,
735 .extra2
= &maxolduid
,
738 .procname
= "overflowgid",
739 .data
= &overflowgid
,
740 .maxlen
= sizeof(int),
742 .proc_handler
= proc_dointvec_minmax
,
743 .extra1
= &minolduid
,
744 .extra2
= &maxolduid
,
747 #ifdef CONFIG_MATHEMU
749 .procname
= "ieee_emulation_warnings",
750 .data
= &sysctl_ieee_emulation_warnings
,
751 .maxlen
= sizeof(int),
753 .proc_handler
= proc_dointvec
,
757 .procname
= "userprocess_debug",
758 .data
= &show_unhandled_signals
,
759 .maxlen
= sizeof(int),
761 .proc_handler
= proc_dointvec
,
765 .procname
= "pid_max",
767 .maxlen
= sizeof (int),
769 .proc_handler
= proc_dointvec_minmax
,
770 .extra1
= &pid_max_min
,
771 .extra2
= &pid_max_max
,
774 .procname
= "panic_on_oops",
775 .data
= &panic_on_oops
,
776 .maxlen
= sizeof(int),
778 .proc_handler
= proc_dointvec
,
780 #if defined CONFIG_PRINTK
782 .procname
= "printk",
783 .data
= &console_loglevel
,
784 .maxlen
= 4*sizeof(int),
786 .proc_handler
= proc_dointvec
,
789 .procname
= "printk_ratelimit",
790 .data
= &printk_ratelimit_state
.interval
,
791 .maxlen
= sizeof(int),
793 .proc_handler
= proc_dointvec_jiffies
,
796 .procname
= "printk_ratelimit_burst",
797 .data
= &printk_ratelimit_state
.burst
,
798 .maxlen
= sizeof(int),
800 .proc_handler
= proc_dointvec
,
803 .procname
= "printk_delay",
804 .data
= &printk_delay_msec
,
805 .maxlen
= sizeof(int),
807 .proc_handler
= proc_dointvec_minmax
,
809 .extra2
= &ten_thousand
,
812 .procname
= "dmesg_restrict",
813 .data
= &dmesg_restrict
,
814 .maxlen
= sizeof(int),
816 .proc_handler
= proc_dointvec_minmax_sysadmin
,
821 .procname
= "kptr_restrict",
822 .data
= &kptr_restrict
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= proc_dointvec_minmax_sysadmin
,
831 .procname
= "ngroups_max",
832 .data
= &ngroups_max
,
833 .maxlen
= sizeof (int),
835 .proc_handler
= proc_dointvec
,
838 .procname
= "cap_last_cap",
839 .data
= (void *)&cap_last_cap
,
840 .maxlen
= sizeof(int),
842 .proc_handler
= proc_dointvec
,
844 #if defined(CONFIG_LOCKUP_DETECTOR)
846 .procname
= "watchdog",
847 .data
= &watchdog_user_enabled
,
848 .maxlen
= sizeof (int),
850 .proc_handler
= proc_watchdog
,
855 .procname
= "watchdog_thresh",
856 .data
= &watchdog_thresh
,
857 .maxlen
= sizeof(int),
859 .proc_handler
= proc_watchdog_thresh
,
864 .procname
= "nmi_watchdog",
865 .data
= &nmi_watchdog_enabled
,
866 .maxlen
= sizeof (int),
868 .proc_handler
= proc_nmi_watchdog
,
870 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
877 .procname
= "soft_watchdog",
878 .data
= &soft_watchdog_enabled
,
879 .maxlen
= sizeof (int),
881 .proc_handler
= proc_soft_watchdog
,
886 .procname
= "softlockup_panic",
887 .data
= &softlockup_panic
,
888 .maxlen
= sizeof(int),
890 .proc_handler
= proc_dointvec_minmax
,
896 .procname
= "softlockup_all_cpu_backtrace",
897 .data
= &sysctl_softlockup_all_cpu_backtrace
,
898 .maxlen
= sizeof(int),
900 .proc_handler
= proc_dointvec_minmax
,
904 #endif /* CONFIG_SMP */
906 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
908 .procname
= "unknown_nmi_panic",
909 .data
= &unknown_nmi_panic
,
910 .maxlen
= sizeof (int),
912 .proc_handler
= proc_dointvec
,
915 #if defined(CONFIG_X86)
917 .procname
= "panic_on_unrecovered_nmi",
918 .data
= &panic_on_unrecovered_nmi
,
919 .maxlen
= sizeof(int),
921 .proc_handler
= proc_dointvec
,
924 .procname
= "panic_on_io_nmi",
925 .data
= &panic_on_io_nmi
,
926 .maxlen
= sizeof(int),
928 .proc_handler
= proc_dointvec
,
930 #ifdef CONFIG_DEBUG_STACKOVERFLOW
932 .procname
= "panic_on_stackoverflow",
933 .data
= &sysctl_panic_on_stackoverflow
,
934 .maxlen
= sizeof(int),
936 .proc_handler
= proc_dointvec
,
940 .procname
= "bootloader_type",
941 .data
= &bootloader_type
,
942 .maxlen
= sizeof (int),
944 .proc_handler
= proc_dointvec
,
947 .procname
= "bootloader_version",
948 .data
= &bootloader_version
,
949 .maxlen
= sizeof (int),
951 .proc_handler
= proc_dointvec
,
954 .procname
= "kstack_depth_to_print",
955 .data
= &kstack_depth_to_print
,
956 .maxlen
= sizeof(int),
958 .proc_handler
= proc_dointvec
,
961 .procname
= "io_delay_type",
962 .data
= &io_delay_type
,
963 .maxlen
= sizeof(int),
965 .proc_handler
= proc_dointvec
,
968 #if defined(CONFIG_MMU)
970 .procname
= "randomize_va_space",
971 .data
= &randomize_va_space
,
972 .maxlen
= sizeof(int),
974 .proc_handler
= proc_dointvec
,
977 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
979 .procname
= "spin_retry",
981 .maxlen
= sizeof (int),
983 .proc_handler
= proc_dointvec
,
986 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
988 .procname
= "acpi_video_flags",
989 .data
= &acpi_realmode_flags
,
990 .maxlen
= sizeof (unsigned long),
992 .proc_handler
= proc_doulongvec_minmax
,
995 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
997 .procname
= "ignore-unaligned-usertrap",
998 .data
= &no_unaligned_warning
,
999 .maxlen
= sizeof (int),
1001 .proc_handler
= proc_dointvec
,
1006 .procname
= "unaligned-dump-stack",
1007 .data
= &unaligned_dump_stack
,
1008 .maxlen
= sizeof (int),
1010 .proc_handler
= proc_dointvec
,
1013 #ifdef CONFIG_DETECT_HUNG_TASK
1015 .procname
= "hung_task_panic",
1016 .data
= &sysctl_hung_task_panic
,
1017 .maxlen
= sizeof(int),
1019 .proc_handler
= proc_dointvec_minmax
,
1024 .procname
= "hung_task_check_count",
1025 .data
= &sysctl_hung_task_check_count
,
1026 .maxlen
= sizeof(int),
1028 .proc_handler
= proc_dointvec_minmax
,
1032 .procname
= "hung_task_timeout_secs",
1033 .data
= &sysctl_hung_task_timeout_secs
,
1034 .maxlen
= sizeof(unsigned long),
1036 .proc_handler
= proc_dohung_task_timeout_secs
,
1037 .extra2
= &hung_task_timeout_max
,
1040 .procname
= "hung_task_warnings",
1041 .data
= &sysctl_hung_task_warnings
,
1042 .maxlen
= sizeof(int),
1044 .proc_handler
= proc_dointvec_minmax
,
1048 #ifdef CONFIG_COMPAT
1050 .procname
= "compat-log",
1051 .data
= &compat_log
,
1052 .maxlen
= sizeof (int),
1054 .proc_handler
= proc_dointvec
,
1057 #ifdef CONFIG_RT_MUTEXES
1059 .procname
= "max_lock_depth",
1060 .data
= &max_lock_depth
,
1061 .maxlen
= sizeof(int),
1063 .proc_handler
= proc_dointvec
,
1067 .procname
= "poweroff_cmd",
1068 .data
= &poweroff_cmd
,
1069 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1071 .proc_handler
= proc_dostring
,
1077 .child
= key_sysctls
,
1080 #ifdef CONFIG_PERF_EVENTS
1082 * User-space scripts rely on the existence of this file
1083 * as a feature check for perf_events being enabled.
1085 * So it's an ABI, do not remove!
1088 .procname
= "perf_event_paranoid",
1089 .data
= &sysctl_perf_event_paranoid
,
1090 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1092 .proc_handler
= proc_dointvec
,
1095 .procname
= "perf_event_mlock_kb",
1096 .data
= &sysctl_perf_event_mlock
,
1097 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1099 .proc_handler
= proc_dointvec
,
1102 .procname
= "perf_event_max_sample_rate",
1103 .data
= &sysctl_perf_event_sample_rate
,
1104 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1106 .proc_handler
= perf_proc_update_handler
,
1110 .procname
= "perf_cpu_time_max_percent",
1111 .data
= &sysctl_perf_cpu_time_max_percent
,
1112 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1114 .proc_handler
= perf_cpu_time_max_percent_handler
,
1116 .extra2
= &one_hundred
,
1119 #ifdef CONFIG_KMEMCHECK
1121 .procname
= "kmemcheck",
1122 .data
= &kmemcheck_enabled
,
1123 .maxlen
= sizeof(int),
1125 .proc_handler
= proc_dointvec
,
1129 .procname
= "panic_on_warn",
1130 .data
= &panic_on_warn
,
1131 .maxlen
= sizeof(int),
1133 .proc_handler
= proc_dointvec_minmax
,
1140 static struct ctl_table vm_table
[] = {
1142 .procname
= "overcommit_memory",
1143 .data
= &sysctl_overcommit_memory
,
1144 .maxlen
= sizeof(sysctl_overcommit_memory
),
1146 .proc_handler
= proc_dointvec_minmax
,
1151 .procname
= "panic_on_oom",
1152 .data
= &sysctl_panic_on_oom
,
1153 .maxlen
= sizeof(sysctl_panic_on_oom
),
1155 .proc_handler
= proc_dointvec_minmax
,
1160 .procname
= "oom_kill_allocating_task",
1161 .data
= &sysctl_oom_kill_allocating_task
,
1162 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1164 .proc_handler
= proc_dointvec
,
1167 .procname
= "oom_dump_tasks",
1168 .data
= &sysctl_oom_dump_tasks
,
1169 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1171 .proc_handler
= proc_dointvec
,
1174 .procname
= "overcommit_ratio",
1175 .data
= &sysctl_overcommit_ratio
,
1176 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1178 .proc_handler
= overcommit_ratio_handler
,
1181 .procname
= "overcommit_kbytes",
1182 .data
= &sysctl_overcommit_kbytes
,
1183 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1185 .proc_handler
= overcommit_kbytes_handler
,
1188 .procname
= "page-cluster",
1189 .data
= &page_cluster
,
1190 .maxlen
= sizeof(int),
1192 .proc_handler
= proc_dointvec_minmax
,
1196 .procname
= "dirty_background_ratio",
1197 .data
= &dirty_background_ratio
,
1198 .maxlen
= sizeof(dirty_background_ratio
),
1200 .proc_handler
= dirty_background_ratio_handler
,
1202 .extra2
= &one_hundred
,
1205 .procname
= "dirty_background_bytes",
1206 .data
= &dirty_background_bytes
,
1207 .maxlen
= sizeof(dirty_background_bytes
),
1209 .proc_handler
= dirty_background_bytes_handler
,
1213 .procname
= "dirty_ratio",
1214 .data
= &vm_dirty_ratio
,
1215 .maxlen
= sizeof(vm_dirty_ratio
),
1217 .proc_handler
= dirty_ratio_handler
,
1219 .extra2
= &one_hundred
,
1222 .procname
= "dirty_bytes",
1223 .data
= &vm_dirty_bytes
,
1224 .maxlen
= sizeof(vm_dirty_bytes
),
1226 .proc_handler
= dirty_bytes_handler
,
1227 .extra1
= &dirty_bytes_min
,
1230 .procname
= "dirty_writeback_centisecs",
1231 .data
= &dirty_writeback_interval
,
1232 .maxlen
= sizeof(dirty_writeback_interval
),
1234 .proc_handler
= dirty_writeback_centisecs_handler
,
1237 .procname
= "dirty_expire_centisecs",
1238 .data
= &dirty_expire_interval
,
1239 .maxlen
= sizeof(dirty_expire_interval
),
1241 .proc_handler
= proc_dointvec_minmax
,
1245 .procname
= "dirtytime_expire_seconds",
1246 .data
= &dirtytime_expire_interval
,
1247 .maxlen
= sizeof(dirty_expire_interval
),
1249 .proc_handler
= dirtytime_interval_handler
,
1253 .procname
= "nr_pdflush_threads",
1254 .mode
= 0444 /* read-only */,
1255 .proc_handler
= pdflush_proc_obsolete
,
1258 .procname
= "swappiness",
1259 .data
= &vm_swappiness
,
1260 .maxlen
= sizeof(vm_swappiness
),
1262 .proc_handler
= proc_dointvec_minmax
,
1264 .extra2
= &one_hundred
,
1266 #ifdef CONFIG_HUGETLB_PAGE
1268 .procname
= "nr_hugepages",
1270 .maxlen
= sizeof(unsigned long),
1272 .proc_handler
= hugetlb_sysctl_handler
,
1276 .procname
= "nr_hugepages_mempolicy",
1278 .maxlen
= sizeof(unsigned long),
1280 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1284 .procname
= "hugetlb_shm_group",
1285 .data
= &sysctl_hugetlb_shm_group
,
1286 .maxlen
= sizeof(gid_t
),
1288 .proc_handler
= proc_dointvec
,
1291 .procname
= "hugepages_treat_as_movable",
1292 .data
= &hugepages_treat_as_movable
,
1293 .maxlen
= sizeof(int),
1295 .proc_handler
= proc_dointvec
,
1298 .procname
= "nr_overcommit_hugepages",
1300 .maxlen
= sizeof(unsigned long),
1302 .proc_handler
= hugetlb_overcommit_handler
,
1306 .procname
= "lowmem_reserve_ratio",
1307 .data
= &sysctl_lowmem_reserve_ratio
,
1308 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1310 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1313 .procname
= "drop_caches",
1314 .data
= &sysctl_drop_caches
,
1315 .maxlen
= sizeof(int),
1317 .proc_handler
= drop_caches_sysctl_handler
,
1321 #ifdef CONFIG_COMPACTION
1323 .procname
= "compact_memory",
1324 .data
= &sysctl_compact_memory
,
1325 .maxlen
= sizeof(int),
1327 .proc_handler
= sysctl_compaction_handler
,
1330 .procname
= "extfrag_threshold",
1331 .data
= &sysctl_extfrag_threshold
,
1332 .maxlen
= sizeof(int),
1334 .proc_handler
= sysctl_extfrag_handler
,
1335 .extra1
= &min_extfrag_threshold
,
1336 .extra2
= &max_extfrag_threshold
,
1339 .procname
= "compact_unevictable_allowed",
1340 .data
= &sysctl_compact_unevictable_allowed
,
1341 .maxlen
= sizeof(int),
1343 .proc_handler
= proc_dointvec
,
1348 #endif /* CONFIG_COMPACTION */
1350 .procname
= "min_free_kbytes",
1351 .data
= &min_free_kbytes
,
1352 .maxlen
= sizeof(min_free_kbytes
),
1354 .proc_handler
= min_free_kbytes_sysctl_handler
,
1358 .procname
= "percpu_pagelist_fraction",
1359 .data
= &percpu_pagelist_fraction
,
1360 .maxlen
= sizeof(percpu_pagelist_fraction
),
1362 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1367 .procname
= "max_map_count",
1368 .data
= &sysctl_max_map_count
,
1369 .maxlen
= sizeof(sysctl_max_map_count
),
1371 .proc_handler
= proc_dointvec_minmax
,
1376 .procname
= "nr_trim_pages",
1377 .data
= &sysctl_nr_trim_pages
,
1378 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1380 .proc_handler
= proc_dointvec_minmax
,
1385 .procname
= "laptop_mode",
1386 .data
= &laptop_mode
,
1387 .maxlen
= sizeof(laptop_mode
),
1389 .proc_handler
= proc_dointvec_jiffies
,
1392 .procname
= "block_dump",
1393 .data
= &block_dump
,
1394 .maxlen
= sizeof(block_dump
),
1396 .proc_handler
= proc_dointvec
,
1400 .procname
= "vfs_cache_pressure",
1401 .data
= &sysctl_vfs_cache_pressure
,
1402 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1404 .proc_handler
= proc_dointvec
,
1407 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1409 .procname
= "legacy_va_layout",
1410 .data
= &sysctl_legacy_va_layout
,
1411 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1413 .proc_handler
= proc_dointvec
,
1419 .procname
= "zone_reclaim_mode",
1420 .data
= &zone_reclaim_mode
,
1421 .maxlen
= sizeof(zone_reclaim_mode
),
1423 .proc_handler
= proc_dointvec
,
1427 .procname
= "min_unmapped_ratio",
1428 .data
= &sysctl_min_unmapped_ratio
,
1429 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1431 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1433 .extra2
= &one_hundred
,
1436 .procname
= "min_slab_ratio",
1437 .data
= &sysctl_min_slab_ratio
,
1438 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1440 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1442 .extra2
= &one_hundred
,
1447 .procname
= "stat_interval",
1448 .data
= &sysctl_stat_interval
,
1449 .maxlen
= sizeof(sysctl_stat_interval
),
1451 .proc_handler
= proc_dointvec_jiffies
,
1456 .procname
= "mmap_min_addr",
1457 .data
= &dac_mmap_min_addr
,
1458 .maxlen
= sizeof(unsigned long),
1460 .proc_handler
= mmap_min_addr_handler
,
1465 .procname
= "numa_zonelist_order",
1466 .data
= &numa_zonelist_order
,
1467 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1469 .proc_handler
= numa_zonelist_order_handler
,
1472 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1473 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1475 .procname
= "vdso_enabled",
1476 #ifdef CONFIG_X86_32
1477 .data
= &vdso32_enabled
,
1478 .maxlen
= sizeof(vdso32_enabled
),
1480 .data
= &vdso_enabled
,
1481 .maxlen
= sizeof(vdso_enabled
),
1484 .proc_handler
= proc_dointvec
,
1488 #ifdef CONFIG_HIGHMEM
1490 .procname
= "highmem_is_dirtyable",
1491 .data
= &vm_highmem_is_dirtyable
,
1492 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1494 .proc_handler
= proc_dointvec_minmax
,
1499 #ifdef CONFIG_MEMORY_FAILURE
1501 .procname
= "memory_failure_early_kill",
1502 .data
= &sysctl_memory_failure_early_kill
,
1503 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1505 .proc_handler
= proc_dointvec_minmax
,
1510 .procname
= "memory_failure_recovery",
1511 .data
= &sysctl_memory_failure_recovery
,
1512 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1514 .proc_handler
= proc_dointvec_minmax
,
1520 .procname
= "user_reserve_kbytes",
1521 .data
= &sysctl_user_reserve_kbytes
,
1522 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1524 .proc_handler
= proc_doulongvec_minmax
,
1527 .procname
= "admin_reserve_kbytes",
1528 .data
= &sysctl_admin_reserve_kbytes
,
1529 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1531 .proc_handler
= proc_doulongvec_minmax
,
1536 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1537 static struct ctl_table binfmt_misc_table
[] = {
1542 static struct ctl_table fs_table
[] = {
1544 .procname
= "inode-nr",
1545 .data
= &inodes_stat
,
1546 .maxlen
= 2*sizeof(long),
1548 .proc_handler
= proc_nr_inodes
,
1551 .procname
= "inode-state",
1552 .data
= &inodes_stat
,
1553 .maxlen
= 7*sizeof(long),
1555 .proc_handler
= proc_nr_inodes
,
1558 .procname
= "file-nr",
1559 .data
= &files_stat
,
1560 .maxlen
= sizeof(files_stat
),
1562 .proc_handler
= proc_nr_files
,
1565 .procname
= "file-max",
1566 .data
= &files_stat
.max_files
,
1567 .maxlen
= sizeof(files_stat
.max_files
),
1569 .proc_handler
= proc_doulongvec_minmax
,
1572 .procname
= "nr_open",
1573 .data
= &sysctl_nr_open
,
1574 .maxlen
= sizeof(int),
1576 .proc_handler
= proc_dointvec_minmax
,
1577 .extra1
= &sysctl_nr_open_min
,
1578 .extra2
= &sysctl_nr_open_max
,
1581 .procname
= "dentry-state",
1582 .data
= &dentry_stat
,
1583 .maxlen
= 6*sizeof(long),
1585 .proc_handler
= proc_nr_dentry
,
1588 .procname
= "overflowuid",
1589 .data
= &fs_overflowuid
,
1590 .maxlen
= sizeof(int),
1592 .proc_handler
= proc_dointvec_minmax
,
1593 .extra1
= &minolduid
,
1594 .extra2
= &maxolduid
,
1597 .procname
= "overflowgid",
1598 .data
= &fs_overflowgid
,
1599 .maxlen
= sizeof(int),
1601 .proc_handler
= proc_dointvec_minmax
,
1602 .extra1
= &minolduid
,
1603 .extra2
= &maxolduid
,
1605 #ifdef CONFIG_FILE_LOCKING
1607 .procname
= "leases-enable",
1608 .data
= &leases_enable
,
1609 .maxlen
= sizeof(int),
1611 .proc_handler
= proc_dointvec
,
1614 #ifdef CONFIG_DNOTIFY
1616 .procname
= "dir-notify-enable",
1617 .data
= &dir_notify_enable
,
1618 .maxlen
= sizeof(int),
1620 .proc_handler
= proc_dointvec
,
1624 #ifdef CONFIG_FILE_LOCKING
1626 .procname
= "lease-break-time",
1627 .data
= &lease_break_time
,
1628 .maxlen
= sizeof(int),
1630 .proc_handler
= proc_dointvec
,
1635 .procname
= "aio-nr",
1637 .maxlen
= sizeof(aio_nr
),
1639 .proc_handler
= proc_doulongvec_minmax
,
1642 .procname
= "aio-max-nr",
1643 .data
= &aio_max_nr
,
1644 .maxlen
= sizeof(aio_max_nr
),
1646 .proc_handler
= proc_doulongvec_minmax
,
1648 #endif /* CONFIG_AIO */
1649 #ifdef CONFIG_INOTIFY_USER
1651 .procname
= "inotify",
1653 .child
= inotify_table
,
1658 .procname
= "epoll",
1660 .child
= epoll_table
,
1665 .procname
= "protected_symlinks",
1666 .data
= &sysctl_protected_symlinks
,
1667 .maxlen
= sizeof(int),
1669 .proc_handler
= proc_dointvec_minmax
,
1674 .procname
= "protected_hardlinks",
1675 .data
= &sysctl_protected_hardlinks
,
1676 .maxlen
= sizeof(int),
1678 .proc_handler
= proc_dointvec_minmax
,
1683 .procname
= "suid_dumpable",
1684 .data
= &suid_dumpable
,
1685 .maxlen
= sizeof(int),
1687 .proc_handler
= proc_dointvec_minmax_coredump
,
1691 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1693 .procname
= "binfmt_misc",
1695 .child
= binfmt_misc_table
,
1699 .procname
= "pipe-max-size",
1700 .data
= &pipe_max_size
,
1701 .maxlen
= sizeof(int),
1703 .proc_handler
= &pipe_proc_fn
,
1704 .extra1
= &pipe_min_size
,
1709 static struct ctl_table debug_table
[] = {
1710 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1712 .procname
= "exception-trace",
1713 .data
= &show_unhandled_signals
,
1714 .maxlen
= sizeof(int),
1716 .proc_handler
= proc_dointvec
1719 #if defined(CONFIG_OPTPROBES)
1721 .procname
= "kprobes-optimization",
1722 .data
= &sysctl_kprobes_optimization
,
1723 .maxlen
= sizeof(int),
1725 .proc_handler
= proc_kprobes_optimization_handler
,
1733 static struct ctl_table dev_table
[] = {
1737 int __init
sysctl_init(void)
1739 struct ctl_table_header
*hdr
;
1741 hdr
= register_sysctl_table(sysctl_base_table
);
1742 kmemleak_not_leak(hdr
);
1746 #endif /* CONFIG_SYSCTL */
1752 #ifdef CONFIG_PROC_SYSCTL
1754 static int _proc_do_string(char *data
, int maxlen
, int write
,
1755 char __user
*buffer
,
1756 size_t *lenp
, loff_t
*ppos
)
1762 if (!data
|| !maxlen
|| !*lenp
) {
1768 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1769 /* Only continue writes not past the end of buffer. */
1771 if (len
> maxlen
- 1)
1778 /* Start writing from beginning of buffer. */
1784 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1785 if (get_user(c
, p
++))
1787 if (c
== 0 || c
== '\n')
1808 if (copy_to_user(buffer
, data
, len
))
1811 if (put_user('\n', buffer
+ len
))
1821 static void warn_sysctl_write(struct ctl_table
*table
)
1823 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1824 "This will not be supported in the future. To silence this\n"
1825 "warning, set kernel.sysctl_writes_strict = -1\n",
1826 current
->comm
, table
->procname
);
1830 * proc_dostring - read a string sysctl
1831 * @table: the sysctl table
1832 * @write: %TRUE if this is a write to the sysctl file
1833 * @buffer: the user buffer
1834 * @lenp: the size of the user buffer
1835 * @ppos: file position
1837 * Reads/writes a string from/to the user buffer. If the kernel
1838 * buffer provided is not large enough to hold the string, the
1839 * string is truncated. The copied string is %NULL-terminated.
1840 * If the string is being read by the user process, it is copied
1841 * and a newline '\n' is added. It is truncated if the buffer is
1844 * Returns 0 on success.
1846 int proc_dostring(struct ctl_table
*table
, int write
,
1847 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1849 if (write
&& *ppos
&& sysctl_writes_strict
== SYSCTL_WRITES_WARN
)
1850 warn_sysctl_write(table
);
1852 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
1853 (char __user
*)buffer
, lenp
, ppos
);
1856 static size_t proc_skip_spaces(char **buf
)
1859 char *tmp
= skip_spaces(*buf
);
1865 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1875 #define TMPBUFLEN 22
1877 * proc_get_long - reads an ASCII formatted integer from a user buffer
1879 * @buf: a kernel buffer
1880 * @size: size of the kernel buffer
1881 * @val: this is where the number will be stored
1882 * @neg: set to %TRUE if number is negative
1883 * @perm_tr: a vector which contains the allowed trailers
1884 * @perm_tr_len: size of the perm_tr vector
1885 * @tr: pointer to store the trailer character
1887 * In case of success %0 is returned and @buf and @size are updated with
1888 * the amount of bytes read. If @tr is non-NULL and a trailing
1889 * character exists (size is non-zero after returning from this
1890 * function), @tr is updated with the trailing character.
1892 static int proc_get_long(char **buf
, size_t *size
,
1893 unsigned long *val
, bool *neg
,
1894 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1897 char *p
, tmp
[TMPBUFLEN
];
1903 if (len
> TMPBUFLEN
- 1)
1904 len
= TMPBUFLEN
- 1;
1906 memcpy(tmp
, *buf
, len
);
1910 if (*p
== '-' && *size
> 1) {
1918 *val
= simple_strtoul(p
, &p
, 0);
1922 /* We don't know if the next char is whitespace thus we may accept
1923 * invalid integers (e.g. 1234...a) or two integers instead of one
1924 * (e.g. 123...1). So lets not allow such large numbers. */
1925 if (len
== TMPBUFLEN
- 1)
1928 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1931 if (tr
&& (len
< *size
))
1941 * proc_put_long - converts an integer to a decimal ASCII formatted string
1943 * @buf: the user buffer
1944 * @size: the size of the user buffer
1945 * @val: the integer to be converted
1946 * @neg: sign of the number, %TRUE for negative
1948 * In case of success %0 is returned and @buf and @size are updated with
1949 * the amount of bytes written.
1951 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1955 char tmp
[TMPBUFLEN
], *p
= tmp
;
1957 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1961 if (copy_to_user(*buf
, tmp
, len
))
1969 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1972 char __user
**buffer
= (char __user
**)buf
;
1973 if (put_user(c
, *buffer
))
1975 (*size
)--, (*buffer
)++;
1981 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1983 int write
, void *data
)
1986 *valp
= *negp
? -*lvalp
: *lvalp
;
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
);