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_dowatchdog
,
855 .procname
= "watchdog_thresh",
856 .data
= &watchdog_thresh
,
857 .maxlen
= sizeof(int),
859 .proc_handler
= proc_dowatchdog
,
864 .procname
= "softlockup_panic",
865 .data
= &softlockup_panic
,
866 .maxlen
= sizeof(int),
868 .proc_handler
= proc_dointvec_minmax
,
874 .procname
= "softlockup_all_cpu_backtrace",
875 .data
= &sysctl_softlockup_all_cpu_backtrace
,
876 .maxlen
= sizeof(int),
878 .proc_handler
= proc_dointvec_minmax
,
882 #endif /* CONFIG_SMP */
884 .procname
= "nmi_watchdog",
885 .data
= &watchdog_user_enabled
,
886 .maxlen
= sizeof (int),
888 .proc_handler
= proc_dowatchdog
,
893 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
895 .procname
= "unknown_nmi_panic",
896 .data
= &unknown_nmi_panic
,
897 .maxlen
= sizeof (int),
899 .proc_handler
= proc_dointvec
,
902 #if defined(CONFIG_X86)
904 .procname
= "panic_on_unrecovered_nmi",
905 .data
= &panic_on_unrecovered_nmi
,
906 .maxlen
= sizeof(int),
908 .proc_handler
= proc_dointvec
,
911 .procname
= "panic_on_io_nmi",
912 .data
= &panic_on_io_nmi
,
913 .maxlen
= sizeof(int),
915 .proc_handler
= proc_dointvec
,
917 #ifdef CONFIG_DEBUG_STACKOVERFLOW
919 .procname
= "panic_on_stackoverflow",
920 .data
= &sysctl_panic_on_stackoverflow
,
921 .maxlen
= sizeof(int),
923 .proc_handler
= proc_dointvec
,
927 .procname
= "bootloader_type",
928 .data
= &bootloader_type
,
929 .maxlen
= sizeof (int),
931 .proc_handler
= proc_dointvec
,
934 .procname
= "bootloader_version",
935 .data
= &bootloader_version
,
936 .maxlen
= sizeof (int),
938 .proc_handler
= proc_dointvec
,
941 .procname
= "kstack_depth_to_print",
942 .data
= &kstack_depth_to_print
,
943 .maxlen
= sizeof(int),
945 .proc_handler
= proc_dointvec
,
948 .procname
= "io_delay_type",
949 .data
= &io_delay_type
,
950 .maxlen
= sizeof(int),
952 .proc_handler
= proc_dointvec
,
955 #if defined(CONFIG_MMU)
957 .procname
= "randomize_va_space",
958 .data
= &randomize_va_space
,
959 .maxlen
= sizeof(int),
961 .proc_handler
= proc_dointvec
,
964 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
966 .procname
= "spin_retry",
968 .maxlen
= sizeof (int),
970 .proc_handler
= proc_dointvec
,
973 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
975 .procname
= "acpi_video_flags",
976 .data
= &acpi_realmode_flags
,
977 .maxlen
= sizeof (unsigned long),
979 .proc_handler
= proc_doulongvec_minmax
,
982 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
984 .procname
= "ignore-unaligned-usertrap",
985 .data
= &no_unaligned_warning
,
986 .maxlen
= sizeof (int),
988 .proc_handler
= proc_dointvec
,
993 .procname
= "unaligned-dump-stack",
994 .data
= &unaligned_dump_stack
,
995 .maxlen
= sizeof (int),
997 .proc_handler
= proc_dointvec
,
1000 #ifdef CONFIG_DETECT_HUNG_TASK
1002 .procname
= "hung_task_panic",
1003 .data
= &sysctl_hung_task_panic
,
1004 .maxlen
= sizeof(int),
1006 .proc_handler
= proc_dointvec_minmax
,
1011 .procname
= "hung_task_check_count",
1012 .data
= &sysctl_hung_task_check_count
,
1013 .maxlen
= sizeof(int),
1015 .proc_handler
= proc_dointvec_minmax
,
1019 .procname
= "hung_task_timeout_secs",
1020 .data
= &sysctl_hung_task_timeout_secs
,
1021 .maxlen
= sizeof(unsigned long),
1023 .proc_handler
= proc_dohung_task_timeout_secs
,
1024 .extra2
= &hung_task_timeout_max
,
1027 .procname
= "hung_task_warnings",
1028 .data
= &sysctl_hung_task_warnings
,
1029 .maxlen
= sizeof(int),
1031 .proc_handler
= proc_dointvec_minmax
,
1035 #ifdef CONFIG_COMPAT
1037 .procname
= "compat-log",
1038 .data
= &compat_log
,
1039 .maxlen
= sizeof (int),
1041 .proc_handler
= proc_dointvec
,
1044 #ifdef CONFIG_RT_MUTEXES
1046 .procname
= "max_lock_depth",
1047 .data
= &max_lock_depth
,
1048 .maxlen
= sizeof(int),
1050 .proc_handler
= proc_dointvec
,
1054 .procname
= "poweroff_cmd",
1055 .data
= &poweroff_cmd
,
1056 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1058 .proc_handler
= proc_dostring
,
1064 .child
= key_sysctls
,
1067 #ifdef CONFIG_PERF_EVENTS
1069 * User-space scripts rely on the existence of this file
1070 * as a feature check for perf_events being enabled.
1072 * So it's an ABI, do not remove!
1075 .procname
= "perf_event_paranoid",
1076 .data
= &sysctl_perf_event_paranoid
,
1077 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1079 .proc_handler
= proc_dointvec
,
1082 .procname
= "perf_event_mlock_kb",
1083 .data
= &sysctl_perf_event_mlock
,
1084 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1086 .proc_handler
= proc_dointvec
,
1089 .procname
= "perf_event_max_sample_rate",
1090 .data
= &sysctl_perf_event_sample_rate
,
1091 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1093 .proc_handler
= perf_proc_update_handler
,
1097 .procname
= "perf_cpu_time_max_percent",
1098 .data
= &sysctl_perf_cpu_time_max_percent
,
1099 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1101 .proc_handler
= perf_cpu_time_max_percent_handler
,
1103 .extra2
= &one_hundred
,
1106 #ifdef CONFIG_KMEMCHECK
1108 .procname
= "kmemcheck",
1109 .data
= &kmemcheck_enabled
,
1110 .maxlen
= sizeof(int),
1112 .proc_handler
= proc_dointvec
,
1116 .procname
= "panic_on_warn",
1117 .data
= &panic_on_warn
,
1118 .maxlen
= sizeof(int),
1120 .proc_handler
= proc_dointvec_minmax
,
1127 static struct ctl_table vm_table
[] = {
1129 .procname
= "overcommit_memory",
1130 .data
= &sysctl_overcommit_memory
,
1131 .maxlen
= sizeof(sysctl_overcommit_memory
),
1133 .proc_handler
= proc_dointvec_minmax
,
1138 .procname
= "panic_on_oom",
1139 .data
= &sysctl_panic_on_oom
,
1140 .maxlen
= sizeof(sysctl_panic_on_oom
),
1142 .proc_handler
= proc_dointvec_minmax
,
1147 .procname
= "oom_kill_allocating_task",
1148 .data
= &sysctl_oom_kill_allocating_task
,
1149 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1151 .proc_handler
= proc_dointvec
,
1154 .procname
= "oom_dump_tasks",
1155 .data
= &sysctl_oom_dump_tasks
,
1156 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1158 .proc_handler
= proc_dointvec
,
1161 .procname
= "overcommit_ratio",
1162 .data
= &sysctl_overcommit_ratio
,
1163 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1165 .proc_handler
= overcommit_ratio_handler
,
1168 .procname
= "overcommit_kbytes",
1169 .data
= &sysctl_overcommit_kbytes
,
1170 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1172 .proc_handler
= overcommit_kbytes_handler
,
1175 .procname
= "page-cluster",
1176 .data
= &page_cluster
,
1177 .maxlen
= sizeof(int),
1179 .proc_handler
= proc_dointvec_minmax
,
1183 .procname
= "dirty_background_ratio",
1184 .data
= &dirty_background_ratio
,
1185 .maxlen
= sizeof(dirty_background_ratio
),
1187 .proc_handler
= dirty_background_ratio_handler
,
1189 .extra2
= &one_hundred
,
1192 .procname
= "dirty_background_bytes",
1193 .data
= &dirty_background_bytes
,
1194 .maxlen
= sizeof(dirty_background_bytes
),
1196 .proc_handler
= dirty_background_bytes_handler
,
1200 .procname
= "dirty_ratio",
1201 .data
= &vm_dirty_ratio
,
1202 .maxlen
= sizeof(vm_dirty_ratio
),
1204 .proc_handler
= dirty_ratio_handler
,
1206 .extra2
= &one_hundred
,
1209 .procname
= "dirty_bytes",
1210 .data
= &vm_dirty_bytes
,
1211 .maxlen
= sizeof(vm_dirty_bytes
),
1213 .proc_handler
= dirty_bytes_handler
,
1214 .extra1
= &dirty_bytes_min
,
1217 .procname
= "dirty_writeback_centisecs",
1218 .data
= &dirty_writeback_interval
,
1219 .maxlen
= sizeof(dirty_writeback_interval
),
1221 .proc_handler
= dirty_writeback_centisecs_handler
,
1224 .procname
= "dirty_expire_centisecs",
1225 .data
= &dirty_expire_interval
,
1226 .maxlen
= sizeof(dirty_expire_interval
),
1228 .proc_handler
= proc_dointvec_minmax
,
1232 .procname
= "dirtytime_expire_seconds",
1233 .data
= &dirtytime_expire_interval
,
1234 .maxlen
= sizeof(dirty_expire_interval
),
1236 .proc_handler
= dirtytime_interval_handler
,
1240 .procname
= "nr_pdflush_threads",
1241 .mode
= 0444 /* read-only */,
1242 .proc_handler
= pdflush_proc_obsolete
,
1245 .procname
= "swappiness",
1246 .data
= &vm_swappiness
,
1247 .maxlen
= sizeof(vm_swappiness
),
1249 .proc_handler
= proc_dointvec_minmax
,
1251 .extra2
= &one_hundred
,
1253 #ifdef CONFIG_HUGETLB_PAGE
1255 .procname
= "nr_hugepages",
1257 .maxlen
= sizeof(unsigned long),
1259 .proc_handler
= hugetlb_sysctl_handler
,
1263 .procname
= "nr_hugepages_mempolicy",
1265 .maxlen
= sizeof(unsigned long),
1267 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1271 .procname
= "hugetlb_shm_group",
1272 .data
= &sysctl_hugetlb_shm_group
,
1273 .maxlen
= sizeof(gid_t
),
1275 .proc_handler
= proc_dointvec
,
1278 .procname
= "hugepages_treat_as_movable",
1279 .data
= &hugepages_treat_as_movable
,
1280 .maxlen
= sizeof(int),
1282 .proc_handler
= proc_dointvec
,
1285 .procname
= "nr_overcommit_hugepages",
1287 .maxlen
= sizeof(unsigned long),
1289 .proc_handler
= hugetlb_overcommit_handler
,
1293 .procname
= "lowmem_reserve_ratio",
1294 .data
= &sysctl_lowmem_reserve_ratio
,
1295 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1297 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1300 .procname
= "drop_caches",
1301 .data
= &sysctl_drop_caches
,
1302 .maxlen
= sizeof(int),
1304 .proc_handler
= drop_caches_sysctl_handler
,
1308 #ifdef CONFIG_COMPACTION
1310 .procname
= "compact_memory",
1311 .data
= &sysctl_compact_memory
,
1312 .maxlen
= sizeof(int),
1314 .proc_handler
= sysctl_compaction_handler
,
1317 .procname
= "extfrag_threshold",
1318 .data
= &sysctl_extfrag_threshold
,
1319 .maxlen
= sizeof(int),
1321 .proc_handler
= sysctl_extfrag_handler
,
1322 .extra1
= &min_extfrag_threshold
,
1323 .extra2
= &max_extfrag_threshold
,
1326 #endif /* CONFIG_COMPACTION */
1328 .procname
= "min_free_kbytes",
1329 .data
= &min_free_kbytes
,
1330 .maxlen
= sizeof(min_free_kbytes
),
1332 .proc_handler
= min_free_kbytes_sysctl_handler
,
1336 .procname
= "percpu_pagelist_fraction",
1337 .data
= &percpu_pagelist_fraction
,
1338 .maxlen
= sizeof(percpu_pagelist_fraction
),
1340 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1345 .procname
= "max_map_count",
1346 .data
= &sysctl_max_map_count
,
1347 .maxlen
= sizeof(sysctl_max_map_count
),
1349 .proc_handler
= proc_dointvec_minmax
,
1354 .procname
= "nr_trim_pages",
1355 .data
= &sysctl_nr_trim_pages
,
1356 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1358 .proc_handler
= proc_dointvec_minmax
,
1363 .procname
= "laptop_mode",
1364 .data
= &laptop_mode
,
1365 .maxlen
= sizeof(laptop_mode
),
1367 .proc_handler
= proc_dointvec_jiffies
,
1370 .procname
= "block_dump",
1371 .data
= &block_dump
,
1372 .maxlen
= sizeof(block_dump
),
1374 .proc_handler
= proc_dointvec
,
1378 .procname
= "vfs_cache_pressure",
1379 .data
= &sysctl_vfs_cache_pressure
,
1380 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1382 .proc_handler
= proc_dointvec
,
1385 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1387 .procname
= "legacy_va_layout",
1388 .data
= &sysctl_legacy_va_layout
,
1389 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1391 .proc_handler
= proc_dointvec
,
1397 .procname
= "zone_reclaim_mode",
1398 .data
= &zone_reclaim_mode
,
1399 .maxlen
= sizeof(zone_reclaim_mode
),
1401 .proc_handler
= proc_dointvec
,
1405 .procname
= "min_unmapped_ratio",
1406 .data
= &sysctl_min_unmapped_ratio
,
1407 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1409 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1411 .extra2
= &one_hundred
,
1414 .procname
= "min_slab_ratio",
1415 .data
= &sysctl_min_slab_ratio
,
1416 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1418 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1420 .extra2
= &one_hundred
,
1425 .procname
= "stat_interval",
1426 .data
= &sysctl_stat_interval
,
1427 .maxlen
= sizeof(sysctl_stat_interval
),
1429 .proc_handler
= proc_dointvec_jiffies
,
1434 .procname
= "mmap_min_addr",
1435 .data
= &dac_mmap_min_addr
,
1436 .maxlen
= sizeof(unsigned long),
1438 .proc_handler
= mmap_min_addr_handler
,
1443 .procname
= "numa_zonelist_order",
1444 .data
= &numa_zonelist_order
,
1445 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1447 .proc_handler
= numa_zonelist_order_handler
,
1450 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1451 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1453 .procname
= "vdso_enabled",
1454 #ifdef CONFIG_X86_32
1455 .data
= &vdso32_enabled
,
1456 .maxlen
= sizeof(vdso32_enabled
),
1458 .data
= &vdso_enabled
,
1459 .maxlen
= sizeof(vdso_enabled
),
1462 .proc_handler
= proc_dointvec
,
1466 #ifdef CONFIG_HIGHMEM
1468 .procname
= "highmem_is_dirtyable",
1469 .data
= &vm_highmem_is_dirtyable
,
1470 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1472 .proc_handler
= proc_dointvec_minmax
,
1477 #ifdef CONFIG_MEMORY_FAILURE
1479 .procname
= "memory_failure_early_kill",
1480 .data
= &sysctl_memory_failure_early_kill
,
1481 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1483 .proc_handler
= proc_dointvec_minmax
,
1488 .procname
= "memory_failure_recovery",
1489 .data
= &sysctl_memory_failure_recovery
,
1490 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1492 .proc_handler
= proc_dointvec_minmax
,
1498 .procname
= "user_reserve_kbytes",
1499 .data
= &sysctl_user_reserve_kbytes
,
1500 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1502 .proc_handler
= proc_doulongvec_minmax
,
1505 .procname
= "admin_reserve_kbytes",
1506 .data
= &sysctl_admin_reserve_kbytes
,
1507 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1509 .proc_handler
= proc_doulongvec_minmax
,
1514 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1515 static struct ctl_table binfmt_misc_table
[] = {
1520 static struct ctl_table fs_table
[] = {
1522 .procname
= "inode-nr",
1523 .data
= &inodes_stat
,
1524 .maxlen
= 2*sizeof(long),
1526 .proc_handler
= proc_nr_inodes
,
1529 .procname
= "inode-state",
1530 .data
= &inodes_stat
,
1531 .maxlen
= 7*sizeof(long),
1533 .proc_handler
= proc_nr_inodes
,
1536 .procname
= "file-nr",
1537 .data
= &files_stat
,
1538 .maxlen
= sizeof(files_stat
),
1540 .proc_handler
= proc_nr_files
,
1543 .procname
= "file-max",
1544 .data
= &files_stat
.max_files
,
1545 .maxlen
= sizeof(files_stat
.max_files
),
1547 .proc_handler
= proc_doulongvec_minmax
,
1550 .procname
= "nr_open",
1551 .data
= &sysctl_nr_open
,
1552 .maxlen
= sizeof(int),
1554 .proc_handler
= proc_dointvec_minmax
,
1555 .extra1
= &sysctl_nr_open_min
,
1556 .extra2
= &sysctl_nr_open_max
,
1559 .procname
= "dentry-state",
1560 .data
= &dentry_stat
,
1561 .maxlen
= 6*sizeof(long),
1563 .proc_handler
= proc_nr_dentry
,
1566 .procname
= "overflowuid",
1567 .data
= &fs_overflowuid
,
1568 .maxlen
= sizeof(int),
1570 .proc_handler
= proc_dointvec_minmax
,
1571 .extra1
= &minolduid
,
1572 .extra2
= &maxolduid
,
1575 .procname
= "overflowgid",
1576 .data
= &fs_overflowgid
,
1577 .maxlen
= sizeof(int),
1579 .proc_handler
= proc_dointvec_minmax
,
1580 .extra1
= &minolduid
,
1581 .extra2
= &maxolduid
,
1583 #ifdef CONFIG_FILE_LOCKING
1585 .procname
= "leases-enable",
1586 .data
= &leases_enable
,
1587 .maxlen
= sizeof(int),
1589 .proc_handler
= proc_dointvec
,
1592 #ifdef CONFIG_DNOTIFY
1594 .procname
= "dir-notify-enable",
1595 .data
= &dir_notify_enable
,
1596 .maxlen
= sizeof(int),
1598 .proc_handler
= proc_dointvec
,
1602 #ifdef CONFIG_FILE_LOCKING
1604 .procname
= "lease-break-time",
1605 .data
= &lease_break_time
,
1606 .maxlen
= sizeof(int),
1608 .proc_handler
= proc_dointvec
,
1613 .procname
= "aio-nr",
1615 .maxlen
= sizeof(aio_nr
),
1617 .proc_handler
= proc_doulongvec_minmax
,
1620 .procname
= "aio-max-nr",
1621 .data
= &aio_max_nr
,
1622 .maxlen
= sizeof(aio_max_nr
),
1624 .proc_handler
= proc_doulongvec_minmax
,
1626 #endif /* CONFIG_AIO */
1627 #ifdef CONFIG_INOTIFY_USER
1629 .procname
= "inotify",
1631 .child
= inotify_table
,
1636 .procname
= "epoll",
1638 .child
= epoll_table
,
1643 .procname
= "protected_symlinks",
1644 .data
= &sysctl_protected_symlinks
,
1645 .maxlen
= sizeof(int),
1647 .proc_handler
= proc_dointvec_minmax
,
1652 .procname
= "protected_hardlinks",
1653 .data
= &sysctl_protected_hardlinks
,
1654 .maxlen
= sizeof(int),
1656 .proc_handler
= proc_dointvec_minmax
,
1661 .procname
= "suid_dumpable",
1662 .data
= &suid_dumpable
,
1663 .maxlen
= sizeof(int),
1665 .proc_handler
= proc_dointvec_minmax_coredump
,
1669 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1671 .procname
= "binfmt_misc",
1673 .child
= binfmt_misc_table
,
1677 .procname
= "pipe-max-size",
1678 .data
= &pipe_max_size
,
1679 .maxlen
= sizeof(int),
1681 .proc_handler
= &pipe_proc_fn
,
1682 .extra1
= &pipe_min_size
,
1687 static struct ctl_table debug_table
[] = {
1688 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1690 .procname
= "exception-trace",
1691 .data
= &show_unhandled_signals
,
1692 .maxlen
= sizeof(int),
1694 .proc_handler
= proc_dointvec
1697 #if defined(CONFIG_OPTPROBES)
1699 .procname
= "kprobes-optimization",
1700 .data
= &sysctl_kprobes_optimization
,
1701 .maxlen
= sizeof(int),
1703 .proc_handler
= proc_kprobes_optimization_handler
,
1711 static struct ctl_table dev_table
[] = {
1715 int __init
sysctl_init(void)
1717 struct ctl_table_header
*hdr
;
1719 hdr
= register_sysctl_table(sysctl_base_table
);
1720 kmemleak_not_leak(hdr
);
1724 #endif /* CONFIG_SYSCTL */
1730 #ifdef CONFIG_PROC_SYSCTL
1732 static int _proc_do_string(char *data
, int maxlen
, int write
,
1733 char __user
*buffer
,
1734 size_t *lenp
, loff_t
*ppos
)
1740 if (!data
|| !maxlen
|| !*lenp
) {
1746 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1747 /* Only continue writes not past the end of buffer. */
1749 if (len
> maxlen
- 1)
1756 /* Start writing from beginning of buffer. */
1762 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1763 if (get_user(c
, p
++))
1765 if (c
== 0 || c
== '\n')
1786 if (copy_to_user(buffer
, data
, len
))
1789 if (put_user('\n', buffer
+ len
))
1799 static void warn_sysctl_write(struct ctl_table
*table
)
1801 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1802 "This will not be supported in the future. To silence this\n"
1803 "warning, set kernel.sysctl_writes_strict = -1\n",
1804 current
->comm
, table
->procname
);
1808 * proc_dostring - read a string sysctl
1809 * @table: the sysctl table
1810 * @write: %TRUE if this is a write to the sysctl file
1811 * @buffer: the user buffer
1812 * @lenp: the size of the user buffer
1813 * @ppos: file position
1815 * Reads/writes a string from/to the user buffer. If the kernel
1816 * buffer provided is not large enough to hold the string, the
1817 * string is truncated. The copied string is %NULL-terminated.
1818 * If the string is being read by the user process, it is copied
1819 * and a newline '\n' is added. It is truncated if the buffer is
1822 * Returns 0 on success.
1824 int proc_dostring(struct ctl_table
*table
, int write
,
1825 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1827 if (write
&& *ppos
&& sysctl_writes_strict
== SYSCTL_WRITES_WARN
)
1828 warn_sysctl_write(table
);
1830 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
1831 (char __user
*)buffer
, lenp
, ppos
);
1834 static size_t proc_skip_spaces(char **buf
)
1837 char *tmp
= skip_spaces(*buf
);
1843 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1853 #define TMPBUFLEN 22
1855 * proc_get_long - reads an ASCII formatted integer from a user buffer
1857 * @buf: a kernel buffer
1858 * @size: size of the kernel buffer
1859 * @val: this is where the number will be stored
1860 * @neg: set to %TRUE if number is negative
1861 * @perm_tr: a vector which contains the allowed trailers
1862 * @perm_tr_len: size of the perm_tr vector
1863 * @tr: pointer to store the trailer character
1865 * In case of success %0 is returned and @buf and @size are updated with
1866 * the amount of bytes read. If @tr is non-NULL and a trailing
1867 * character exists (size is non-zero after returning from this
1868 * function), @tr is updated with the trailing character.
1870 static int proc_get_long(char **buf
, size_t *size
,
1871 unsigned long *val
, bool *neg
,
1872 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1875 char *p
, tmp
[TMPBUFLEN
];
1881 if (len
> TMPBUFLEN
- 1)
1882 len
= TMPBUFLEN
- 1;
1884 memcpy(tmp
, *buf
, len
);
1888 if (*p
== '-' && *size
> 1) {
1896 *val
= simple_strtoul(p
, &p
, 0);
1900 /* We don't know if the next char is whitespace thus we may accept
1901 * invalid integers (e.g. 1234...a) or two integers instead of one
1902 * (e.g. 123...1). So lets not allow such large numbers. */
1903 if (len
== TMPBUFLEN
- 1)
1906 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1909 if (tr
&& (len
< *size
))
1919 * proc_put_long - converts an integer to a decimal ASCII formatted string
1921 * @buf: the user buffer
1922 * @size: the size of the user buffer
1923 * @val: the integer to be converted
1924 * @neg: sign of the number, %TRUE for negative
1926 * In case of success %0 is returned and @buf and @size are updated with
1927 * the amount of bytes written.
1929 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1933 char tmp
[TMPBUFLEN
], *p
= tmp
;
1935 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1939 if (copy_to_user(*buf
, tmp
, len
))
1947 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1950 char __user
**buffer
= (char __user
**)buf
;
1951 if (put_user(c
, *buffer
))
1953 (*size
)--, (*buffer
)++;
1959 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1961 int write
, void *data
)
1964 *valp
= *negp
? -*lvalp
: *lvalp
;
1969 *lvalp
= (unsigned long)-val
;
1972 *lvalp
= (unsigned long)val
;
1978 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1980 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1981 int write
, void __user
*buffer
,
1982 size_t *lenp
, loff_t
*ppos
,
1983 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1984 int write
, void *data
),
1987 int *i
, vleft
, first
= 1, err
= 0;
1988 unsigned long page
= 0;
1992 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1997 i
= (int *) tbl_data
;
1998 vleft
= table
->maxlen
/ sizeof(*i
);
2002 conv
= do_proc_dointvec_conv
;
2006 switch (sysctl_writes_strict
) {
2007 case SYSCTL_WRITES_STRICT
:
2009 case SYSCTL_WRITES_WARN
:
2010 warn_sysctl_write(table
);
2017 if (left
> PAGE_SIZE
- 1)
2018 left
= PAGE_SIZE
- 1;
2019 page
= __get_free_page(GFP_TEMPORARY
);
2020 kbuf
= (char *) page
;
2023 if (copy_from_user(kbuf
, buffer
, left
)) {
2030 for (; left
&& vleft
--; i
++, first
=0) {
2035 left
-= proc_skip_spaces(&kbuf
);
2039 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2041 sizeof(proc_wspace_sep
), NULL
);
2044 if (conv(&neg
, &lval
, i
, 1, data
)) {
2049 if (conv(&neg
, &lval
, i
, 0, data
)) {
2054 err
= proc_put_char(&buffer
, &left
, '\t');
2057 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2063 if (!write
&& !first
&& left
&& !err
)
2064 err
= proc_put_char(&buffer
, &left
, '\n');
2065 if (write
&& !err
&& left
)
2066 left
-= proc_skip_spaces(&kbuf
);
2071 return err
? : -EINVAL
;
2079 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2080 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2081 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2082 int write
, void *data
),
2085 return __do_proc_dointvec(table
->data
, table
, write
,
2086 buffer
, lenp
, ppos
, conv
, data
);
2090 * proc_dointvec - read a vector of integers
2091 * @table: the sysctl table
2092 * @write: %TRUE if this is a write to the sysctl file
2093 * @buffer: the user buffer
2094 * @lenp: the size of the user buffer
2095 * @ppos: file position
2097 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2098 * values from/to the user buffer, treated as an ASCII string.
2100 * Returns 0 on success.
2102 int proc_dointvec(struct ctl_table
*table
, int write
,
2103 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2105 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2110 * Taint values can only be increased
2111 * This means we can safely use a temporary.
2113 static int proc_taint(struct ctl_table
*table
, int write
,
2114 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2117 unsigned long tmptaint
= get_taint();
2120 if (write
&& !capable(CAP_SYS_ADMIN
))
2125 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2131 * Poor man's atomic or. Not worth adding a primitive
2132 * to everyone's atomic.h for this
2135 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2136 if ((tmptaint
>> i
) & 1)
2137 add_taint(i
, LOCKDEP_STILL_OK
);
2144 #ifdef CONFIG_PRINTK
2145 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2146 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2148 if (write
&& !capable(CAP_SYS_ADMIN
))
2151 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2155 struct do_proc_dointvec_minmax_conv_param
{
2160 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2162 int write
, void *data
)
2164 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2166 int val
= *negp
? -*lvalp
: *lvalp
;
2167 if ((param
->min
&& *param
->min
> val
) ||
2168 (param
->max
&& *param
->max
< val
))
2175 *lvalp
= (unsigned long)-val
;
2178 *lvalp
= (unsigned long)val
;
2185 * proc_dointvec_minmax - read a vector of integers with min/max values
2186 * @table: the sysctl table
2187 * @write: %TRUE if this is a write to the sysctl file
2188 * @buffer: the user buffer
2189 * @lenp: the size of the user buffer
2190 * @ppos: file position
2192 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2193 * values from/to the user buffer, treated as an ASCII string.
2195 * This routine will ensure the values are within the range specified by
2196 * table->extra1 (min) and table->extra2 (max).
2198 * Returns 0 on success.
2200 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2201 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2203 struct do_proc_dointvec_minmax_conv_param param
= {
2204 .min
= (int *) table
->extra1
,
2205 .max
= (int *) table
->extra2
,
2207 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2208 do_proc_dointvec_minmax_conv
, ¶m
);
2211 static void validate_coredump_safety(void)
2213 #ifdef CONFIG_COREDUMP
2214 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2215 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2216 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2217 "suid_dumpable=2. Pipe handler or fully qualified "\
2218 "core dump path required.\n");
2223 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2226 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2228 validate_coredump_safety();
2232 #ifdef CONFIG_COREDUMP
2233 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2234 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2236 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2238 validate_coredump_safety();
2243 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2244 void __user
*buffer
,
2245 size_t *lenp
, loff_t
*ppos
,
2246 unsigned long convmul
,
2247 unsigned long convdiv
)
2249 unsigned long *i
, *min
, *max
;
2250 int vleft
, first
= 1, err
= 0;
2251 unsigned long page
= 0;
2255 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2260 i
= (unsigned long *) data
;
2261 min
= (unsigned long *) table
->extra1
;
2262 max
= (unsigned long *) table
->extra2
;
2263 vleft
= table
->maxlen
/ sizeof(unsigned long);
2268 switch (sysctl_writes_strict
) {
2269 case SYSCTL_WRITES_STRICT
:
2271 case SYSCTL_WRITES_WARN
:
2272 warn_sysctl_write(table
);
2279 if (left
> PAGE_SIZE
- 1)
2280 left
= PAGE_SIZE
- 1;
2281 page
= __get_free_page(GFP_TEMPORARY
);
2282 kbuf
= (char *) page
;
2285 if (copy_from_user(kbuf
, buffer
, left
)) {
2292 for (; left
&& vleft
--; i
++, first
= 0) {
2298 left
-= proc_skip_spaces(&kbuf
);
2300 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2302 sizeof(proc_wspace_sep
), NULL
);
2307 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2311 val
= convdiv
* (*i
) / convmul
;
2313 err
= proc_put_char(&buffer
, &left
, '\t');
2317 err
= proc_put_long(&buffer
, &left
, val
, false);
2323 if (!write
&& !first
&& left
&& !err
)
2324 err
= proc_put_char(&buffer
, &left
, '\n');
2326 left
-= proc_skip_spaces(&kbuf
);
2331 return err
? : -EINVAL
;
2339 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2340 void __user
*buffer
,
2341 size_t *lenp
, loff_t
*ppos
,
2342 unsigned long convmul
,
2343 unsigned long convdiv
)
2345 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2346 buffer
, lenp
, ppos
, convmul
, convdiv
);
2350 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2351 * @table: the sysctl table
2352 * @write: %TRUE if this is a write to the sysctl file
2353 * @buffer: the user buffer
2354 * @lenp: the size of the user buffer
2355 * @ppos: file position
2357 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2358 * values from/to the user buffer, treated as an ASCII string.
2360 * This routine will ensure the values are within the range specified by
2361 * table->extra1 (min) and table->extra2 (max).
2363 * Returns 0 on success.
2365 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2366 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2368 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2372 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values 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. The values
2381 * are treated as milliseconds, and converted to jiffies when they are stored.
2383 * This routine will ensure the values are within the range specified by
2384 * table->extra1 (min) and table->extra2 (max).
2386 * Returns 0 on success.
2388 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2389 void __user
*buffer
,
2390 size_t *lenp
, loff_t
*ppos
)
2392 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2393 lenp
, ppos
, HZ
, 1000l);
2397 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2399 int write
, void *data
)
2402 if (*lvalp
> LONG_MAX
/ HZ
)
2404 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2410 lval
= (unsigned long)-val
;
2413 lval
= (unsigned long)val
;
2420 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2422 int write
, void *data
)
2425 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2427 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2433 lval
= (unsigned long)-val
;
2436 lval
= (unsigned long)val
;
2438 *lvalp
= jiffies_to_clock_t(lval
);
2443 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2445 int write
, void *data
)
2448 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2458 lval
= (unsigned long)-val
;
2461 lval
= (unsigned long)val
;
2463 *lvalp
= jiffies_to_msecs(lval
);
2469 * proc_dointvec_jiffies - read a vector of integers as seconds
2470 * @table: the sysctl table
2471 * @write: %TRUE if this is a write to the sysctl file
2472 * @buffer: the user buffer
2473 * @lenp: the size of the user buffer
2474 * @ppos: file position
2476 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2477 * values from/to the user buffer, treated as an ASCII string.
2478 * The values read are assumed to be in seconds, and are converted into
2481 * Returns 0 on success.
2483 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2484 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2486 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2487 do_proc_dointvec_jiffies_conv
,NULL
);
2491 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ 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: pointer to the 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 1/USER_HZ seconds, and
2501 * are converted into jiffies.
2503 * Returns 0 on success.
2505 int proc_dointvec_userhz_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_userhz_jiffies_conv
,NULL
);
2513 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
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: file position
2519 * @ppos: the current position in the file
2521 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2522 * values from/to the user buffer, treated as an ASCII string.
2523 * The values read are assumed to be in 1/1000 seconds, and
2524 * are converted into jiffies.
2526 * Returns 0 on success.
2528 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2529 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2531 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2532 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2535 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2536 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2538 struct pid
*new_pid
;
2542 tmp
= pid_vnr(cad_pid
);
2544 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2545 lenp
, ppos
, NULL
, NULL
);
2549 new_pid
= find_get_pid(tmp
);
2553 put_pid(xchg(&cad_pid
, new_pid
));
2558 * proc_do_large_bitmap - read/write from/to a large bitmap
2559 * @table: the sysctl table
2560 * @write: %TRUE if this is a write to the sysctl file
2561 * @buffer: the user buffer
2562 * @lenp: the size of the user buffer
2563 * @ppos: file position
2565 * The bitmap is stored at table->data and the bitmap length (in bits)
2568 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2569 * large bitmaps may be represented in a compact manner. Writing into
2570 * the file will clear the bitmap then update it with the given input.
2572 * Returns 0 on success.
2574 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2575 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2579 size_t left
= *lenp
;
2580 unsigned long bitmap_len
= table
->maxlen
;
2581 unsigned long *bitmap
= *(unsigned long **) table
->data
;
2582 unsigned long *tmp_bitmap
= NULL
;
2583 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2585 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2591 unsigned long page
= 0;
2594 if (left
> PAGE_SIZE
- 1)
2595 left
= PAGE_SIZE
- 1;
2597 page
= __get_free_page(GFP_TEMPORARY
);
2598 kbuf
= (char *) page
;
2601 if (copy_from_user(kbuf
, buffer
, left
)) {
2607 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2613 proc_skip_char(&kbuf
, &left
, '\n');
2614 while (!err
&& left
) {
2615 unsigned long val_a
, val_b
;
2618 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2622 if (val_a
>= bitmap_len
|| neg
) {
2634 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2635 &neg
, tr_b
, sizeof(tr_b
),
2639 if (val_b
>= bitmap_len
|| neg
||
2650 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2652 proc_skip_char(&kbuf
, &left
, '\n');
2656 unsigned long bit_a
, bit_b
= 0;
2659 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2660 if (bit_a
>= bitmap_len
)
2662 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2666 err
= proc_put_char(&buffer
, &left
, ',');
2670 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2673 if (bit_a
!= bit_b
) {
2674 err
= proc_put_char(&buffer
, &left
, '-');
2677 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2685 err
= proc_put_char(&buffer
, &left
, '\n');
2691 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2693 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2705 #else /* CONFIG_PROC_SYSCTL */
2707 int proc_dostring(struct ctl_table
*table
, int write
,
2708 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2713 int proc_dointvec(struct ctl_table
*table
, int write
,
2714 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2719 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2720 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2725 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2726 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2731 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2732 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2737 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2738 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2743 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2744 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2749 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2750 void __user
*buffer
,
2751 size_t *lenp
, loff_t
*ppos
)
2757 #endif /* CONFIG_PROC_SYSCTL */
2760 * No sense putting this after each symbol definition, twice,
2761 * exception granted :-)
2763 EXPORT_SYMBOL(proc_dointvec
);
2764 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2765 EXPORT_SYMBOL(proc_dointvec_minmax
);
2766 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2767 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2768 EXPORT_SYMBOL(proc_dostring
);
2769 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2770 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);