2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/kexec.h>
67 #include <asm/uaccess.h>
68 #include <asm/processor.h>
72 #include <asm/stacktrace.h>
76 #include <asm/setup.h>
78 #ifdef CONFIG_BSD_PROCESS_ACCT
79 #include <linux/acct.h>
81 #ifdef CONFIG_RT_MUTEXES
82 #include <linux/rtmutex.h>
84 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85 #include <linux/lockdep.h>
87 #ifdef CONFIG_CHR_DEV_SG
91 #ifdef CONFIG_LOCKUP_DETECTOR
92 #include <linux/nmi.h>
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
99 extern int max_threads
;
100 extern int suid_dumpable
;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid
;
103 extern char core_pattern
[];
104 extern unsigned int core_pipe_limit
;
107 extern int pid_max_min
, pid_max_max
;
108 extern int percpu_pagelist_fraction
;
109 extern int compat_log
;
110 extern int latencytop_enabled
;
111 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
113 extern int sysctl_nr_trim_pages
;
116 /* Constants used for minimum and maximum */
117 #ifdef CONFIG_LOCKUP_DETECTOR
118 static int sixty
= 60;
121 static int __maybe_unused neg_one
= -1;
124 static int __maybe_unused one
= 1;
125 static int __maybe_unused two
= 2;
126 static int __maybe_unused four
= 4;
127 static unsigned long one_ul
= 1;
128 static int one_hundred
= 100;
130 static int ten_thousand
= 10000;
133 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
134 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
136 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
137 static int maxolduid
= 65535;
138 static int minolduid
;
139 static int min_percpu_pagelist_fract
= 8;
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>
155 #ifdef CONFIG_SPARC64
156 extern int sysctl_tsb_ratio
;
160 extern int pwrsw_enabled
;
163 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
164 extern int unaligned_enabled
;
168 extern int unaligned_dump_stack
;
171 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172 extern int no_unaligned_warning
;
175 #ifdef CONFIG_PROC_SYSCTL
177 #define SYSCTL_WRITES_LEGACY -1
178 #define SYSCTL_WRITES_WARN 0
179 #define SYSCTL_WRITES_STRICT 1
181 static int sysctl_writes_strict
= SYSCTL_WRITES_WARN
;
183 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
184 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
185 static int proc_taint(struct ctl_table
*table
, int write
,
186 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
190 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
191 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
194 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
195 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
196 #ifdef CONFIG_COREDUMP
197 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
198 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
201 #ifdef CONFIG_MAGIC_SYSRQ
202 /* Note: sysrq code uses it's own private copy */
203 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
205 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
206 void __user
*buffer
, size_t *lenp
,
211 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
216 sysrq_toggle_support(__sysrq_enabled
);
223 static struct ctl_table kern_table
[];
224 static struct ctl_table vm_table
[];
225 static struct ctl_table fs_table
[];
226 static struct ctl_table debug_table
[];
227 static struct ctl_table dev_table
[];
228 extern struct ctl_table random_table
[];
230 extern struct ctl_table epoll_table
[];
233 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
234 int sysctl_legacy_va_layout
;
237 /* The default sysctl tables: */
239 static struct ctl_table sysctl_base_table
[] = {
241 .procname
= "kernel",
258 .child
= debug_table
,
268 #ifdef CONFIG_SCHED_DEBUG
269 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
270 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
271 static int min_wakeup_granularity_ns
; /* 0 usecs */
272 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
274 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
275 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
276 #endif /* CONFIG_SMP */
277 #endif /* CONFIG_SCHED_DEBUG */
279 #ifdef CONFIG_COMPACTION
280 static int min_extfrag_threshold
;
281 static int max_extfrag_threshold
= 1000;
284 static struct ctl_table kern_table
[] = {
286 .procname
= "sched_child_runs_first",
287 .data
= &sysctl_sched_child_runs_first
,
288 .maxlen
= sizeof(unsigned int),
290 .proc_handler
= proc_dointvec
,
292 #ifdef CONFIG_SCHED_DEBUG
294 .procname
= "sched_min_granularity_ns",
295 .data
= &sysctl_sched_min_granularity
,
296 .maxlen
= sizeof(unsigned int),
298 .proc_handler
= sched_proc_update_handler
,
299 .extra1
= &min_sched_granularity_ns
,
300 .extra2
= &max_sched_granularity_ns
,
303 .procname
= "sched_latency_ns",
304 .data
= &sysctl_sched_latency
,
305 .maxlen
= sizeof(unsigned int),
307 .proc_handler
= sched_proc_update_handler
,
308 .extra1
= &min_sched_granularity_ns
,
309 .extra2
= &max_sched_granularity_ns
,
312 .procname
= "sched_wakeup_granularity_ns",
313 .data
= &sysctl_sched_wakeup_granularity
,
314 .maxlen
= sizeof(unsigned int),
316 .proc_handler
= sched_proc_update_handler
,
317 .extra1
= &min_wakeup_granularity_ns
,
318 .extra2
= &max_wakeup_granularity_ns
,
322 .procname
= "sched_tunable_scaling",
323 .data
= &sysctl_sched_tunable_scaling
,
324 .maxlen
= sizeof(enum sched_tunable_scaling
),
326 .proc_handler
= sched_proc_update_handler
,
327 .extra1
= &min_sched_tunable_scaling
,
328 .extra2
= &max_sched_tunable_scaling
,
331 .procname
= "sched_migration_cost_ns",
332 .data
= &sysctl_sched_migration_cost
,
333 .maxlen
= sizeof(unsigned int),
335 .proc_handler
= proc_dointvec
,
338 .procname
= "sched_nr_migrate",
339 .data
= &sysctl_sched_nr_migrate
,
340 .maxlen
= sizeof(unsigned int),
342 .proc_handler
= proc_dointvec
,
345 .procname
= "sched_time_avg_ms",
346 .data
= &sysctl_sched_time_avg
,
347 .maxlen
= sizeof(unsigned int),
349 .proc_handler
= proc_dointvec
,
352 .procname
= "sched_shares_window_ns",
353 .data
= &sysctl_sched_shares_window
,
354 .maxlen
= sizeof(unsigned int),
356 .proc_handler
= proc_dointvec
,
359 .procname
= "timer_migration",
360 .data
= &sysctl_timer_migration
,
361 .maxlen
= sizeof(unsigned int),
363 .proc_handler
= proc_dointvec_minmax
,
367 #endif /* CONFIG_SMP */
368 #ifdef CONFIG_NUMA_BALANCING
370 .procname
= "numa_balancing_scan_delay_ms",
371 .data
= &sysctl_numa_balancing_scan_delay
,
372 .maxlen
= sizeof(unsigned int),
374 .proc_handler
= proc_dointvec
,
377 .procname
= "numa_balancing_scan_period_min_ms",
378 .data
= &sysctl_numa_balancing_scan_period_min
,
379 .maxlen
= sizeof(unsigned int),
381 .proc_handler
= proc_dointvec
,
384 .procname
= "numa_balancing_scan_period_max_ms",
385 .data
= &sysctl_numa_balancing_scan_period_max
,
386 .maxlen
= sizeof(unsigned int),
388 .proc_handler
= proc_dointvec
,
391 .procname
= "numa_balancing_scan_size_mb",
392 .data
= &sysctl_numa_balancing_scan_size
,
393 .maxlen
= sizeof(unsigned int),
395 .proc_handler
= proc_dointvec
,
398 .procname
= "numa_balancing",
399 .data
= NULL
, /* filled in by handler */
400 .maxlen
= sizeof(unsigned int),
402 .proc_handler
= sysctl_numa_balancing
,
406 #endif /* CONFIG_NUMA_BALANCING */
407 #endif /* CONFIG_SCHED_DEBUG */
409 .procname
= "sched_rt_period_us",
410 .data
= &sysctl_sched_rt_period
,
411 .maxlen
= sizeof(unsigned int),
413 .proc_handler
= sched_rt_handler
,
416 .procname
= "sched_rt_runtime_us",
417 .data
= &sysctl_sched_rt_runtime
,
418 .maxlen
= sizeof(int),
420 .proc_handler
= sched_rt_handler
,
423 .procname
= "sched_rr_timeslice_ms",
424 .data
= &sched_rr_timeslice
,
425 .maxlen
= sizeof(int),
427 .proc_handler
= sched_rr_handler
,
429 #ifdef CONFIG_SCHED_AUTOGROUP
431 .procname
= "sched_autogroup_enabled",
432 .data
= &sysctl_sched_autogroup_enabled
,
433 .maxlen
= sizeof(unsigned int),
435 .proc_handler
= proc_dointvec_minmax
,
440 #ifdef CONFIG_CFS_BANDWIDTH
442 .procname
= "sched_cfs_bandwidth_slice_us",
443 .data
= &sysctl_sched_cfs_bandwidth_slice
,
444 .maxlen
= sizeof(unsigned int),
446 .proc_handler
= proc_dointvec_minmax
,
450 #ifdef CONFIG_PROVE_LOCKING
452 .procname
= "prove_locking",
453 .data
= &prove_locking
,
454 .maxlen
= sizeof(int),
456 .proc_handler
= proc_dointvec
,
459 #ifdef CONFIG_LOCK_STAT
461 .procname
= "lock_stat",
463 .maxlen
= sizeof(int),
465 .proc_handler
= proc_dointvec
,
470 .data
= &panic_timeout
,
471 .maxlen
= sizeof(int),
473 .proc_handler
= proc_dointvec
,
475 #ifdef CONFIG_COREDUMP
477 .procname
= "core_uses_pid",
478 .data
= &core_uses_pid
,
479 .maxlen
= sizeof(int),
481 .proc_handler
= proc_dointvec
,
484 .procname
= "core_pattern",
485 .data
= core_pattern
,
486 .maxlen
= CORENAME_MAX_SIZE
,
488 .proc_handler
= proc_dostring_coredump
,
491 .procname
= "core_pipe_limit",
492 .data
= &core_pipe_limit
,
493 .maxlen
= sizeof(unsigned int),
495 .proc_handler
= proc_dointvec
,
498 #ifdef CONFIG_PROC_SYSCTL
500 .procname
= "tainted",
501 .maxlen
= sizeof(long),
503 .proc_handler
= proc_taint
,
506 .procname
= "sysctl_writes_strict",
507 .data
= &sysctl_writes_strict
,
508 .maxlen
= sizeof(int),
510 .proc_handler
= proc_dointvec_minmax
,
515 #ifdef CONFIG_LATENCYTOP
517 .procname
= "latencytop",
518 .data
= &latencytop_enabled
,
519 .maxlen
= sizeof(int),
521 .proc_handler
= proc_dointvec
,
524 #ifdef CONFIG_BLK_DEV_INITRD
526 .procname
= "real-root-dev",
527 .data
= &real_root_dev
,
528 .maxlen
= sizeof(int),
530 .proc_handler
= proc_dointvec
,
534 .procname
= "print-fatal-signals",
535 .data
= &print_fatal_signals
,
536 .maxlen
= sizeof(int),
538 .proc_handler
= proc_dointvec
,
542 .procname
= "reboot-cmd",
543 .data
= reboot_command
,
546 .proc_handler
= proc_dostring
,
549 .procname
= "stop-a",
550 .data
= &stop_a_enabled
,
551 .maxlen
= sizeof (int),
553 .proc_handler
= proc_dointvec
,
556 .procname
= "scons-poweroff",
557 .data
= &scons_pwroff
,
558 .maxlen
= sizeof (int),
560 .proc_handler
= proc_dointvec
,
563 #ifdef CONFIG_SPARC64
565 .procname
= "tsb-ratio",
566 .data
= &sysctl_tsb_ratio
,
567 .maxlen
= sizeof (int),
569 .proc_handler
= proc_dointvec
,
574 .procname
= "soft-power",
575 .data
= &pwrsw_enabled
,
576 .maxlen
= sizeof (int),
578 .proc_handler
= proc_dointvec
,
581 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
583 .procname
= "unaligned-trap",
584 .data
= &unaligned_enabled
,
585 .maxlen
= sizeof (int),
587 .proc_handler
= proc_dointvec
,
591 .procname
= "ctrl-alt-del",
593 .maxlen
= sizeof(int),
595 .proc_handler
= proc_dointvec
,
597 #ifdef CONFIG_FUNCTION_TRACER
599 .procname
= "ftrace_enabled",
600 .data
= &ftrace_enabled
,
601 .maxlen
= sizeof(int),
603 .proc_handler
= ftrace_enable_sysctl
,
606 #ifdef CONFIG_STACK_TRACER
608 .procname
= "stack_tracer_enabled",
609 .data
= &stack_tracer_enabled
,
610 .maxlen
= sizeof(int),
612 .proc_handler
= stack_trace_sysctl
,
615 #ifdef CONFIG_TRACING
617 .procname
= "ftrace_dump_on_oops",
618 .data
= &ftrace_dump_on_oops
,
619 .maxlen
= sizeof(int),
621 .proc_handler
= proc_dointvec
,
624 .procname
= "traceoff_on_warning",
625 .data
= &__disable_trace_on_warning
,
626 .maxlen
= sizeof(__disable_trace_on_warning
),
628 .proc_handler
= proc_dointvec
,
633 .procname
= "kexec_load_disabled",
634 .data
= &kexec_load_disabled
,
635 .maxlen
= sizeof(int),
637 /* only handle a transition from default "0" to "1" */
638 .proc_handler
= proc_dointvec_minmax
,
643 #ifdef CONFIG_MODULES
645 .procname
= "modprobe",
646 .data
= &modprobe_path
,
647 .maxlen
= KMOD_PATH_LEN
,
649 .proc_handler
= proc_dostring
,
652 .procname
= "modules_disabled",
653 .data
= &modules_disabled
,
654 .maxlen
= sizeof(int),
656 /* only handle a transition from default "0" to "1" */
657 .proc_handler
= proc_dointvec_minmax
,
662 #ifdef CONFIG_UEVENT_HELPER
664 .procname
= "hotplug",
665 .data
= &uevent_helper
,
666 .maxlen
= UEVENT_HELPER_PATH_LEN
,
668 .proc_handler
= proc_dostring
,
671 #ifdef CONFIG_CHR_DEV_SG
673 .procname
= "sg-big-buff",
674 .data
= &sg_big_buff
,
675 .maxlen
= sizeof (int),
677 .proc_handler
= proc_dointvec
,
680 #ifdef CONFIG_BSD_PROCESS_ACCT
684 .maxlen
= 3*sizeof(int),
686 .proc_handler
= proc_dointvec
,
689 #ifdef CONFIG_MAGIC_SYSRQ
692 .data
= &__sysrq_enabled
,
693 .maxlen
= sizeof (int),
695 .proc_handler
= sysrq_sysctl_handler
,
698 #ifdef CONFIG_PROC_SYSCTL
700 .procname
= "cad_pid",
702 .maxlen
= sizeof (int),
704 .proc_handler
= proc_do_cad_pid
,
708 .procname
= "threads-max",
709 .data
= &max_threads
,
710 .maxlen
= sizeof(int),
712 .proc_handler
= proc_dointvec
,
715 .procname
= "random",
717 .child
= random_table
,
720 .procname
= "usermodehelper",
722 .child
= usermodehelper_table
,
725 .procname
= "overflowuid",
726 .data
= &overflowuid
,
727 .maxlen
= sizeof(int),
729 .proc_handler
= proc_dointvec_minmax
,
730 .extra1
= &minolduid
,
731 .extra2
= &maxolduid
,
734 .procname
= "overflowgid",
735 .data
= &overflowgid
,
736 .maxlen
= sizeof(int),
738 .proc_handler
= proc_dointvec_minmax
,
739 .extra1
= &minolduid
,
740 .extra2
= &maxolduid
,
743 #ifdef CONFIG_MATHEMU
745 .procname
= "ieee_emulation_warnings",
746 .data
= &sysctl_ieee_emulation_warnings
,
747 .maxlen
= sizeof(int),
749 .proc_handler
= proc_dointvec
,
753 .procname
= "userprocess_debug",
754 .data
= &show_unhandled_signals
,
755 .maxlen
= sizeof(int),
757 .proc_handler
= proc_dointvec
,
761 .procname
= "pid_max",
763 .maxlen
= sizeof (int),
765 .proc_handler
= proc_dointvec_minmax
,
766 .extra1
= &pid_max_min
,
767 .extra2
= &pid_max_max
,
770 .procname
= "panic_on_oops",
771 .data
= &panic_on_oops
,
772 .maxlen
= sizeof(int),
774 .proc_handler
= proc_dointvec
,
776 #if defined CONFIG_PRINTK
778 .procname
= "printk",
779 .data
= &console_loglevel
,
780 .maxlen
= 4*sizeof(int),
782 .proc_handler
= proc_dointvec
,
785 .procname
= "printk_ratelimit",
786 .data
= &printk_ratelimit_state
.interval
,
787 .maxlen
= sizeof(int),
789 .proc_handler
= proc_dointvec_jiffies
,
792 .procname
= "printk_ratelimit_burst",
793 .data
= &printk_ratelimit_state
.burst
,
794 .maxlen
= sizeof(int),
796 .proc_handler
= proc_dointvec
,
799 .procname
= "printk_delay",
800 .data
= &printk_delay_msec
,
801 .maxlen
= sizeof(int),
803 .proc_handler
= proc_dointvec_minmax
,
805 .extra2
= &ten_thousand
,
808 .procname
= "dmesg_restrict",
809 .data
= &dmesg_restrict
,
810 .maxlen
= sizeof(int),
812 .proc_handler
= proc_dointvec_minmax_sysadmin
,
817 .procname
= "kptr_restrict",
818 .data
= &kptr_restrict
,
819 .maxlen
= sizeof(int),
821 .proc_handler
= proc_dointvec_minmax_sysadmin
,
827 .procname
= "ngroups_max",
828 .data
= &ngroups_max
,
829 .maxlen
= sizeof (int),
831 .proc_handler
= proc_dointvec
,
834 .procname
= "cap_last_cap",
835 .data
= (void *)&cap_last_cap
,
836 .maxlen
= sizeof(int),
838 .proc_handler
= proc_dointvec
,
840 #if defined(CONFIG_LOCKUP_DETECTOR)
842 .procname
= "watchdog",
843 .data
= &watchdog_user_enabled
,
844 .maxlen
= sizeof (int),
846 .proc_handler
= proc_dowatchdog
,
851 .procname
= "watchdog_thresh",
852 .data
= &watchdog_thresh
,
853 .maxlen
= sizeof(int),
855 .proc_handler
= proc_dowatchdog
,
860 .procname
= "softlockup_panic",
861 .data
= &softlockup_panic
,
862 .maxlen
= sizeof(int),
864 .proc_handler
= proc_dointvec_minmax
,
869 .procname
= "nmi_watchdog",
870 .data
= &watchdog_user_enabled
,
871 .maxlen
= sizeof (int),
873 .proc_handler
= proc_dowatchdog
,
878 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
880 .procname
= "unknown_nmi_panic",
881 .data
= &unknown_nmi_panic
,
882 .maxlen
= sizeof (int),
884 .proc_handler
= proc_dointvec
,
887 #if defined(CONFIG_X86)
889 .procname
= "panic_on_unrecovered_nmi",
890 .data
= &panic_on_unrecovered_nmi
,
891 .maxlen
= sizeof(int),
893 .proc_handler
= proc_dointvec
,
896 .procname
= "panic_on_io_nmi",
897 .data
= &panic_on_io_nmi
,
898 .maxlen
= sizeof(int),
900 .proc_handler
= proc_dointvec
,
902 #ifdef CONFIG_DEBUG_STACKOVERFLOW
904 .procname
= "panic_on_stackoverflow",
905 .data
= &sysctl_panic_on_stackoverflow
,
906 .maxlen
= sizeof(int),
908 .proc_handler
= proc_dointvec
,
912 .procname
= "bootloader_type",
913 .data
= &bootloader_type
,
914 .maxlen
= sizeof (int),
916 .proc_handler
= proc_dointvec
,
919 .procname
= "bootloader_version",
920 .data
= &bootloader_version
,
921 .maxlen
= sizeof (int),
923 .proc_handler
= proc_dointvec
,
926 .procname
= "kstack_depth_to_print",
927 .data
= &kstack_depth_to_print
,
928 .maxlen
= sizeof(int),
930 .proc_handler
= proc_dointvec
,
933 .procname
= "io_delay_type",
934 .data
= &io_delay_type
,
935 .maxlen
= sizeof(int),
937 .proc_handler
= proc_dointvec
,
940 #if defined(CONFIG_MMU)
942 .procname
= "randomize_va_space",
943 .data
= &randomize_va_space
,
944 .maxlen
= sizeof(int),
946 .proc_handler
= proc_dointvec
,
949 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
951 .procname
= "spin_retry",
953 .maxlen
= sizeof (int),
955 .proc_handler
= proc_dointvec
,
958 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
960 .procname
= "acpi_video_flags",
961 .data
= &acpi_realmode_flags
,
962 .maxlen
= sizeof (unsigned long),
964 .proc_handler
= proc_doulongvec_minmax
,
967 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
969 .procname
= "ignore-unaligned-usertrap",
970 .data
= &no_unaligned_warning
,
971 .maxlen
= sizeof (int),
973 .proc_handler
= proc_dointvec
,
978 .procname
= "unaligned-dump-stack",
979 .data
= &unaligned_dump_stack
,
980 .maxlen
= sizeof (int),
982 .proc_handler
= proc_dointvec
,
985 #ifdef CONFIG_DETECT_HUNG_TASK
987 .procname
= "hung_task_panic",
988 .data
= &sysctl_hung_task_panic
,
989 .maxlen
= sizeof(int),
991 .proc_handler
= proc_dointvec_minmax
,
996 .procname
= "hung_task_check_count",
997 .data
= &sysctl_hung_task_check_count
,
998 .maxlen
= sizeof(int),
1000 .proc_handler
= proc_dointvec_minmax
,
1004 .procname
= "hung_task_timeout_secs",
1005 .data
= &sysctl_hung_task_timeout_secs
,
1006 .maxlen
= sizeof(unsigned long),
1008 .proc_handler
= proc_dohung_task_timeout_secs
,
1009 .extra2
= &hung_task_timeout_max
,
1012 .procname
= "hung_task_warnings",
1013 .data
= &sysctl_hung_task_warnings
,
1014 .maxlen
= sizeof(int),
1016 .proc_handler
= proc_dointvec_minmax
,
1020 #ifdef CONFIG_COMPAT
1022 .procname
= "compat-log",
1023 .data
= &compat_log
,
1024 .maxlen
= sizeof (int),
1026 .proc_handler
= proc_dointvec
,
1029 #ifdef CONFIG_RT_MUTEXES
1031 .procname
= "max_lock_depth",
1032 .data
= &max_lock_depth
,
1033 .maxlen
= sizeof(int),
1035 .proc_handler
= proc_dointvec
,
1039 .procname
= "poweroff_cmd",
1040 .data
= &poweroff_cmd
,
1041 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1043 .proc_handler
= proc_dostring
,
1049 .child
= key_sysctls
,
1052 #ifdef CONFIG_RCU_TORTURE_TEST
1054 .procname
= "rcutorture_runnable",
1055 .data
= &rcutorture_runnable
,
1056 .maxlen
= sizeof(int),
1058 .proc_handler
= proc_dointvec
,
1061 #ifdef CONFIG_PERF_EVENTS
1063 * User-space scripts rely on the existence of this file
1064 * as a feature check for perf_events being enabled.
1066 * So it's an ABI, do not remove!
1069 .procname
= "perf_event_paranoid",
1070 .data
= &sysctl_perf_event_paranoid
,
1071 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1073 .proc_handler
= proc_dointvec
,
1076 .procname
= "perf_event_mlock_kb",
1077 .data
= &sysctl_perf_event_mlock
,
1078 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1080 .proc_handler
= proc_dointvec
,
1083 .procname
= "perf_event_max_sample_rate",
1084 .data
= &sysctl_perf_event_sample_rate
,
1085 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1087 .proc_handler
= perf_proc_update_handler
,
1091 .procname
= "perf_cpu_time_max_percent",
1092 .data
= &sysctl_perf_cpu_time_max_percent
,
1093 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1095 .proc_handler
= perf_cpu_time_max_percent_handler
,
1097 .extra2
= &one_hundred
,
1100 #ifdef CONFIG_KMEMCHECK
1102 .procname
= "kmemcheck",
1103 .data
= &kmemcheck_enabled
,
1104 .maxlen
= sizeof(int),
1106 .proc_handler
= proc_dointvec
,
1112 static struct ctl_table vm_table
[] = {
1114 .procname
= "overcommit_memory",
1115 .data
= &sysctl_overcommit_memory
,
1116 .maxlen
= sizeof(sysctl_overcommit_memory
),
1118 .proc_handler
= proc_dointvec_minmax
,
1123 .procname
= "panic_on_oom",
1124 .data
= &sysctl_panic_on_oom
,
1125 .maxlen
= sizeof(sysctl_panic_on_oom
),
1127 .proc_handler
= proc_dointvec_minmax
,
1132 .procname
= "oom_kill_allocating_task",
1133 .data
= &sysctl_oom_kill_allocating_task
,
1134 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1136 .proc_handler
= proc_dointvec
,
1139 .procname
= "oom_dump_tasks",
1140 .data
= &sysctl_oom_dump_tasks
,
1141 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1143 .proc_handler
= proc_dointvec
,
1146 .procname
= "overcommit_ratio",
1147 .data
= &sysctl_overcommit_ratio
,
1148 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1150 .proc_handler
= overcommit_ratio_handler
,
1153 .procname
= "overcommit_kbytes",
1154 .data
= &sysctl_overcommit_kbytes
,
1155 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1157 .proc_handler
= overcommit_kbytes_handler
,
1160 .procname
= "page-cluster",
1161 .data
= &page_cluster
,
1162 .maxlen
= sizeof(int),
1164 .proc_handler
= proc_dointvec_minmax
,
1168 .procname
= "dirty_background_ratio",
1169 .data
= &dirty_background_ratio
,
1170 .maxlen
= sizeof(dirty_background_ratio
),
1172 .proc_handler
= dirty_background_ratio_handler
,
1174 .extra2
= &one_hundred
,
1177 .procname
= "dirty_background_bytes",
1178 .data
= &dirty_background_bytes
,
1179 .maxlen
= sizeof(dirty_background_bytes
),
1181 .proc_handler
= dirty_background_bytes_handler
,
1185 .procname
= "dirty_ratio",
1186 .data
= &vm_dirty_ratio
,
1187 .maxlen
= sizeof(vm_dirty_ratio
),
1189 .proc_handler
= dirty_ratio_handler
,
1191 .extra2
= &one_hundred
,
1194 .procname
= "dirty_bytes",
1195 .data
= &vm_dirty_bytes
,
1196 .maxlen
= sizeof(vm_dirty_bytes
),
1198 .proc_handler
= dirty_bytes_handler
,
1199 .extra1
= &dirty_bytes_min
,
1202 .procname
= "dirty_writeback_centisecs",
1203 .data
= &dirty_writeback_interval
,
1204 .maxlen
= sizeof(dirty_writeback_interval
),
1206 .proc_handler
= dirty_writeback_centisecs_handler
,
1209 .procname
= "dirty_expire_centisecs",
1210 .data
= &dirty_expire_interval
,
1211 .maxlen
= sizeof(dirty_expire_interval
),
1213 .proc_handler
= proc_dointvec_minmax
,
1217 .procname
= "nr_pdflush_threads",
1218 .mode
= 0444 /* read-only */,
1219 .proc_handler
= pdflush_proc_obsolete
,
1222 .procname
= "swappiness",
1223 .data
= &vm_swappiness
,
1224 .maxlen
= sizeof(vm_swappiness
),
1226 .proc_handler
= proc_dointvec_minmax
,
1228 .extra2
= &one_hundred
,
1230 #ifdef CONFIG_HUGETLB_PAGE
1232 .procname
= "nr_hugepages",
1234 .maxlen
= sizeof(unsigned long),
1236 .proc_handler
= hugetlb_sysctl_handler
,
1237 .extra1
= (void *)&hugetlb_zero
,
1238 .extra2
= (void *)&hugetlb_infinity
,
1242 .procname
= "nr_hugepages_mempolicy",
1244 .maxlen
= sizeof(unsigned long),
1246 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1247 .extra1
= (void *)&hugetlb_zero
,
1248 .extra2
= (void *)&hugetlb_infinity
,
1252 .procname
= "hugetlb_shm_group",
1253 .data
= &sysctl_hugetlb_shm_group
,
1254 .maxlen
= sizeof(gid_t
),
1256 .proc_handler
= proc_dointvec
,
1259 .procname
= "hugepages_treat_as_movable",
1260 .data
= &hugepages_treat_as_movable
,
1261 .maxlen
= sizeof(int),
1263 .proc_handler
= proc_dointvec
,
1266 .procname
= "nr_overcommit_hugepages",
1268 .maxlen
= sizeof(unsigned long),
1270 .proc_handler
= hugetlb_overcommit_handler
,
1271 .extra1
= (void *)&hugetlb_zero
,
1272 .extra2
= (void *)&hugetlb_infinity
,
1276 .procname
= "lowmem_reserve_ratio",
1277 .data
= &sysctl_lowmem_reserve_ratio
,
1278 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1280 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1283 .procname
= "drop_caches",
1284 .data
= &sysctl_drop_caches
,
1285 .maxlen
= sizeof(int),
1287 .proc_handler
= drop_caches_sysctl_handler
,
1291 #ifdef CONFIG_COMPACTION
1293 .procname
= "compact_memory",
1294 .data
= &sysctl_compact_memory
,
1295 .maxlen
= sizeof(int),
1297 .proc_handler
= sysctl_compaction_handler
,
1300 .procname
= "extfrag_threshold",
1301 .data
= &sysctl_extfrag_threshold
,
1302 .maxlen
= sizeof(int),
1304 .proc_handler
= sysctl_extfrag_handler
,
1305 .extra1
= &min_extfrag_threshold
,
1306 .extra2
= &max_extfrag_threshold
,
1309 #endif /* CONFIG_COMPACTION */
1311 .procname
= "min_free_kbytes",
1312 .data
= &min_free_kbytes
,
1313 .maxlen
= sizeof(min_free_kbytes
),
1315 .proc_handler
= min_free_kbytes_sysctl_handler
,
1319 .procname
= "percpu_pagelist_fraction",
1320 .data
= &percpu_pagelist_fraction
,
1321 .maxlen
= sizeof(percpu_pagelist_fraction
),
1323 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1324 .extra1
= &min_percpu_pagelist_fract
,
1328 .procname
= "max_map_count",
1329 .data
= &sysctl_max_map_count
,
1330 .maxlen
= sizeof(sysctl_max_map_count
),
1332 .proc_handler
= proc_dointvec_minmax
,
1337 .procname
= "nr_trim_pages",
1338 .data
= &sysctl_nr_trim_pages
,
1339 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1341 .proc_handler
= proc_dointvec_minmax
,
1346 .procname
= "laptop_mode",
1347 .data
= &laptop_mode
,
1348 .maxlen
= sizeof(laptop_mode
),
1350 .proc_handler
= proc_dointvec_jiffies
,
1353 .procname
= "block_dump",
1354 .data
= &block_dump
,
1355 .maxlen
= sizeof(block_dump
),
1357 .proc_handler
= proc_dointvec
,
1361 .procname
= "vfs_cache_pressure",
1362 .data
= &sysctl_vfs_cache_pressure
,
1363 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1365 .proc_handler
= proc_dointvec
,
1368 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1370 .procname
= "legacy_va_layout",
1371 .data
= &sysctl_legacy_va_layout
,
1372 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1374 .proc_handler
= proc_dointvec
,
1380 .procname
= "zone_reclaim_mode",
1381 .data
= &zone_reclaim_mode
,
1382 .maxlen
= sizeof(zone_reclaim_mode
),
1384 .proc_handler
= proc_dointvec
,
1388 .procname
= "min_unmapped_ratio",
1389 .data
= &sysctl_min_unmapped_ratio
,
1390 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1392 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1394 .extra2
= &one_hundred
,
1397 .procname
= "min_slab_ratio",
1398 .data
= &sysctl_min_slab_ratio
,
1399 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1401 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1403 .extra2
= &one_hundred
,
1408 .procname
= "stat_interval",
1409 .data
= &sysctl_stat_interval
,
1410 .maxlen
= sizeof(sysctl_stat_interval
),
1412 .proc_handler
= proc_dointvec_jiffies
,
1417 .procname
= "mmap_min_addr",
1418 .data
= &dac_mmap_min_addr
,
1419 .maxlen
= sizeof(unsigned long),
1421 .proc_handler
= mmap_min_addr_handler
,
1426 .procname
= "numa_zonelist_order",
1427 .data
= &numa_zonelist_order
,
1428 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1430 .proc_handler
= numa_zonelist_order_handler
,
1433 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1434 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1436 .procname
= "vdso_enabled",
1437 #ifdef CONFIG_X86_32
1438 .data
= &vdso32_enabled
,
1439 .maxlen
= sizeof(vdso32_enabled
),
1441 .data
= &vdso_enabled
,
1442 .maxlen
= sizeof(vdso_enabled
),
1445 .proc_handler
= proc_dointvec
,
1449 #ifdef CONFIG_HIGHMEM
1451 .procname
= "highmem_is_dirtyable",
1452 .data
= &vm_highmem_is_dirtyable
,
1453 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1455 .proc_handler
= proc_dointvec_minmax
,
1461 .procname
= "scan_unevictable_pages",
1462 .data
= &scan_unevictable_pages
,
1463 .maxlen
= sizeof(scan_unevictable_pages
),
1465 .proc_handler
= scan_unevictable_handler
,
1467 #ifdef CONFIG_MEMORY_FAILURE
1469 .procname
= "memory_failure_early_kill",
1470 .data
= &sysctl_memory_failure_early_kill
,
1471 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1473 .proc_handler
= proc_dointvec_minmax
,
1478 .procname
= "memory_failure_recovery",
1479 .data
= &sysctl_memory_failure_recovery
,
1480 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1482 .proc_handler
= proc_dointvec_minmax
,
1488 .procname
= "user_reserve_kbytes",
1489 .data
= &sysctl_user_reserve_kbytes
,
1490 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1492 .proc_handler
= proc_doulongvec_minmax
,
1495 .procname
= "admin_reserve_kbytes",
1496 .data
= &sysctl_admin_reserve_kbytes
,
1497 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1499 .proc_handler
= proc_doulongvec_minmax
,
1504 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1505 static struct ctl_table binfmt_misc_table
[] = {
1510 static struct ctl_table fs_table
[] = {
1512 .procname
= "inode-nr",
1513 .data
= &inodes_stat
,
1514 .maxlen
= 2*sizeof(long),
1516 .proc_handler
= proc_nr_inodes
,
1519 .procname
= "inode-state",
1520 .data
= &inodes_stat
,
1521 .maxlen
= 7*sizeof(long),
1523 .proc_handler
= proc_nr_inodes
,
1526 .procname
= "file-nr",
1527 .data
= &files_stat
,
1528 .maxlen
= sizeof(files_stat
),
1530 .proc_handler
= proc_nr_files
,
1533 .procname
= "file-max",
1534 .data
= &files_stat
.max_files
,
1535 .maxlen
= sizeof(files_stat
.max_files
),
1537 .proc_handler
= proc_doulongvec_minmax
,
1540 .procname
= "nr_open",
1541 .data
= &sysctl_nr_open
,
1542 .maxlen
= sizeof(int),
1544 .proc_handler
= proc_dointvec_minmax
,
1545 .extra1
= &sysctl_nr_open_min
,
1546 .extra2
= &sysctl_nr_open_max
,
1549 .procname
= "dentry-state",
1550 .data
= &dentry_stat
,
1551 .maxlen
= 6*sizeof(long),
1553 .proc_handler
= proc_nr_dentry
,
1556 .procname
= "overflowuid",
1557 .data
= &fs_overflowuid
,
1558 .maxlen
= sizeof(int),
1560 .proc_handler
= proc_dointvec_minmax
,
1561 .extra1
= &minolduid
,
1562 .extra2
= &maxolduid
,
1565 .procname
= "overflowgid",
1566 .data
= &fs_overflowgid
,
1567 .maxlen
= sizeof(int),
1569 .proc_handler
= proc_dointvec_minmax
,
1570 .extra1
= &minolduid
,
1571 .extra2
= &maxolduid
,
1573 #ifdef CONFIG_FILE_LOCKING
1575 .procname
= "leases-enable",
1576 .data
= &leases_enable
,
1577 .maxlen
= sizeof(int),
1579 .proc_handler
= proc_dointvec
,
1582 #ifdef CONFIG_DNOTIFY
1584 .procname
= "dir-notify-enable",
1585 .data
= &dir_notify_enable
,
1586 .maxlen
= sizeof(int),
1588 .proc_handler
= proc_dointvec
,
1592 #ifdef CONFIG_FILE_LOCKING
1594 .procname
= "lease-break-time",
1595 .data
= &lease_break_time
,
1596 .maxlen
= sizeof(int),
1598 .proc_handler
= proc_dointvec
,
1603 .procname
= "aio-nr",
1605 .maxlen
= sizeof(aio_nr
),
1607 .proc_handler
= proc_doulongvec_minmax
,
1610 .procname
= "aio-max-nr",
1611 .data
= &aio_max_nr
,
1612 .maxlen
= sizeof(aio_max_nr
),
1614 .proc_handler
= proc_doulongvec_minmax
,
1616 #endif /* CONFIG_AIO */
1617 #ifdef CONFIG_INOTIFY_USER
1619 .procname
= "inotify",
1621 .child
= inotify_table
,
1626 .procname
= "epoll",
1628 .child
= epoll_table
,
1633 .procname
= "protected_symlinks",
1634 .data
= &sysctl_protected_symlinks
,
1635 .maxlen
= sizeof(int),
1637 .proc_handler
= proc_dointvec_minmax
,
1642 .procname
= "protected_hardlinks",
1643 .data
= &sysctl_protected_hardlinks
,
1644 .maxlen
= sizeof(int),
1646 .proc_handler
= proc_dointvec_minmax
,
1651 .procname
= "suid_dumpable",
1652 .data
= &suid_dumpable
,
1653 .maxlen
= sizeof(int),
1655 .proc_handler
= proc_dointvec_minmax_coredump
,
1659 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1661 .procname
= "binfmt_misc",
1663 .child
= binfmt_misc_table
,
1667 .procname
= "pipe-max-size",
1668 .data
= &pipe_max_size
,
1669 .maxlen
= sizeof(int),
1671 .proc_handler
= &pipe_proc_fn
,
1672 .extra1
= &pipe_min_size
,
1677 static struct ctl_table debug_table
[] = {
1678 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1680 .procname
= "exception-trace",
1681 .data
= &show_unhandled_signals
,
1682 .maxlen
= sizeof(int),
1684 .proc_handler
= proc_dointvec
1687 #if defined(CONFIG_OPTPROBES)
1689 .procname
= "kprobes-optimization",
1690 .data
= &sysctl_kprobes_optimization
,
1691 .maxlen
= sizeof(int),
1693 .proc_handler
= proc_kprobes_optimization_handler
,
1701 static struct ctl_table dev_table
[] = {
1705 int __init
sysctl_init(void)
1707 struct ctl_table_header
*hdr
;
1709 hdr
= register_sysctl_table(sysctl_base_table
);
1710 kmemleak_not_leak(hdr
);
1714 #endif /* CONFIG_SYSCTL */
1720 #ifdef CONFIG_PROC_SYSCTL
1722 static int _proc_do_string(char *data
, int maxlen
, int write
,
1723 char __user
*buffer
,
1724 size_t *lenp
, loff_t
*ppos
)
1730 if (!data
|| !maxlen
|| !*lenp
) {
1736 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1737 /* Only continue writes not past the end of buffer. */
1739 if (len
> maxlen
- 1)
1746 /* Start writing from beginning of buffer. */
1752 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1753 if (get_user(c
, p
++))
1755 if (c
== 0 || c
== '\n')
1776 if (copy_to_user(buffer
, data
, len
))
1779 if (put_user('\n', buffer
+ len
))
1789 static void warn_sysctl_write(struct ctl_table
*table
)
1791 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1792 "This will not be supported in the future. To silence this\n"
1793 "warning, set kernel.sysctl_writes_strict = -1\n",
1794 current
->comm
, table
->procname
);
1798 * proc_dostring - read a string sysctl
1799 * @table: the sysctl table
1800 * @write: %TRUE if this is a write to the sysctl file
1801 * @buffer: the user buffer
1802 * @lenp: the size of the user buffer
1803 * @ppos: file position
1805 * Reads/writes a string from/to the user buffer. If the kernel
1806 * buffer provided is not large enough to hold the string, the
1807 * string is truncated. The copied string is %NULL-terminated.
1808 * If the string is being read by the user process, it is copied
1809 * and a newline '\n' is added. It is truncated if the buffer is
1812 * Returns 0 on success.
1814 int proc_dostring(struct ctl_table
*table
, int write
,
1815 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1817 if (write
&& *ppos
&& sysctl_writes_strict
== SYSCTL_WRITES_WARN
)
1818 warn_sysctl_write(table
);
1820 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
1821 (char __user
*)buffer
, lenp
, ppos
);
1824 static size_t proc_skip_spaces(char **buf
)
1827 char *tmp
= skip_spaces(*buf
);
1833 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1843 #define TMPBUFLEN 22
1845 * proc_get_long - reads an ASCII formatted integer from a user buffer
1847 * @buf: a kernel buffer
1848 * @size: size of the kernel buffer
1849 * @val: this is where the number will be stored
1850 * @neg: set to %TRUE if number is negative
1851 * @perm_tr: a vector which contains the allowed trailers
1852 * @perm_tr_len: size of the perm_tr vector
1853 * @tr: pointer to store the trailer character
1855 * In case of success %0 is returned and @buf and @size are updated with
1856 * the amount of bytes read. If @tr is non-NULL and a trailing
1857 * character exists (size is non-zero after returning from this
1858 * function), @tr is updated with the trailing character.
1860 static int proc_get_long(char **buf
, size_t *size
,
1861 unsigned long *val
, bool *neg
,
1862 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1865 char *p
, tmp
[TMPBUFLEN
];
1871 if (len
> TMPBUFLEN
- 1)
1872 len
= TMPBUFLEN
- 1;
1874 memcpy(tmp
, *buf
, len
);
1878 if (*p
== '-' && *size
> 1) {
1886 *val
= simple_strtoul(p
, &p
, 0);
1890 /* We don't know if the next char is whitespace thus we may accept
1891 * invalid integers (e.g. 1234...a) or two integers instead of one
1892 * (e.g. 123...1). So lets not allow such large numbers. */
1893 if (len
== TMPBUFLEN
- 1)
1896 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1899 if (tr
&& (len
< *size
))
1909 * proc_put_long - converts an integer to a decimal ASCII formatted string
1911 * @buf: the user buffer
1912 * @size: the size of the user buffer
1913 * @val: the integer to be converted
1914 * @neg: sign of the number, %TRUE for negative
1916 * In case of success %0 is returned and @buf and @size are updated with
1917 * the amount of bytes written.
1919 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1923 char tmp
[TMPBUFLEN
], *p
= tmp
;
1925 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1929 if (copy_to_user(*buf
, tmp
, len
))
1937 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1940 char __user
**buffer
= (char __user
**)buf
;
1941 if (put_user(c
, *buffer
))
1943 (*size
)--, (*buffer
)++;
1949 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1951 int write
, void *data
)
1954 *valp
= *negp
? -*lvalp
: *lvalp
;
1959 *lvalp
= (unsigned long)-val
;
1962 *lvalp
= (unsigned long)val
;
1968 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1970 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1971 int write
, void __user
*buffer
,
1972 size_t *lenp
, loff_t
*ppos
,
1973 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1974 int write
, void *data
),
1977 int *i
, vleft
, first
= 1, err
= 0;
1978 unsigned long page
= 0;
1982 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1987 i
= (int *) tbl_data
;
1988 vleft
= table
->maxlen
/ sizeof(*i
);
1992 conv
= do_proc_dointvec_conv
;
1996 switch (sysctl_writes_strict
) {
1997 case SYSCTL_WRITES_STRICT
:
1999 case SYSCTL_WRITES_WARN
:
2000 warn_sysctl_write(table
);
2007 if (left
> PAGE_SIZE
- 1)
2008 left
= PAGE_SIZE
- 1;
2009 page
= __get_free_page(GFP_TEMPORARY
);
2010 kbuf
= (char *) page
;
2013 if (copy_from_user(kbuf
, buffer
, left
)) {
2020 for (; left
&& vleft
--; i
++, first
=0) {
2025 left
-= proc_skip_spaces(&kbuf
);
2029 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2031 sizeof(proc_wspace_sep
), NULL
);
2034 if (conv(&neg
, &lval
, i
, 1, data
)) {
2039 if (conv(&neg
, &lval
, i
, 0, data
)) {
2044 err
= proc_put_char(&buffer
, &left
, '\t');
2047 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2053 if (!write
&& !first
&& left
&& !err
)
2054 err
= proc_put_char(&buffer
, &left
, '\n');
2055 if (write
&& !err
&& left
)
2056 left
-= proc_skip_spaces(&kbuf
);
2061 return err
? : -EINVAL
;
2069 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2070 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2071 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2072 int write
, void *data
),
2075 return __do_proc_dointvec(table
->data
, table
, write
,
2076 buffer
, lenp
, ppos
, conv
, data
);
2080 * proc_dointvec - read a vector of integers
2081 * @table: the sysctl table
2082 * @write: %TRUE if this is a write to the sysctl file
2083 * @buffer: the user buffer
2084 * @lenp: the size of the user buffer
2085 * @ppos: file position
2087 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2088 * values from/to the user buffer, treated as an ASCII string.
2090 * Returns 0 on success.
2092 int proc_dointvec(struct ctl_table
*table
, int write
,
2093 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2095 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2100 * Taint values can only be increased
2101 * This means we can safely use a temporary.
2103 static int proc_taint(struct ctl_table
*table
, int write
,
2104 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2107 unsigned long tmptaint
= get_taint();
2110 if (write
&& !capable(CAP_SYS_ADMIN
))
2115 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2121 * Poor man's atomic or. Not worth adding a primitive
2122 * to everyone's atomic.h for this
2125 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2126 if ((tmptaint
>> i
) & 1)
2127 add_taint(i
, LOCKDEP_STILL_OK
);
2134 #ifdef CONFIG_PRINTK
2135 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2136 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2138 if (write
&& !capable(CAP_SYS_ADMIN
))
2141 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2145 struct do_proc_dointvec_minmax_conv_param
{
2150 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2152 int write
, void *data
)
2154 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2156 int val
= *negp
? -*lvalp
: *lvalp
;
2157 if ((param
->min
&& *param
->min
> val
) ||
2158 (param
->max
&& *param
->max
< val
))
2165 *lvalp
= (unsigned long)-val
;
2168 *lvalp
= (unsigned long)val
;
2175 * proc_dointvec_minmax - read a vector of integers with min/max values
2176 * @table: the sysctl table
2177 * @write: %TRUE if this is a write to the sysctl file
2178 * @buffer: the user buffer
2179 * @lenp: the size of the user buffer
2180 * @ppos: file position
2182 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2183 * values from/to the user buffer, treated as an ASCII string.
2185 * This routine will ensure the values are within the range specified by
2186 * table->extra1 (min) and table->extra2 (max).
2188 * Returns 0 on success.
2190 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2191 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2193 struct do_proc_dointvec_minmax_conv_param param
= {
2194 .min
= (int *) table
->extra1
,
2195 .max
= (int *) table
->extra2
,
2197 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2198 do_proc_dointvec_minmax_conv
, ¶m
);
2201 static void validate_coredump_safety(void)
2203 #ifdef CONFIG_COREDUMP
2204 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2205 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2206 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2207 "suid_dumpable=2. Pipe handler or fully qualified "\
2208 "core dump path required.\n");
2213 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2214 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2216 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2218 validate_coredump_safety();
2222 #ifdef CONFIG_COREDUMP
2223 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2226 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2228 validate_coredump_safety();
2233 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2234 void __user
*buffer
,
2235 size_t *lenp
, loff_t
*ppos
,
2236 unsigned long convmul
,
2237 unsigned long convdiv
)
2239 unsigned long *i
, *min
, *max
;
2240 int vleft
, first
= 1, err
= 0;
2241 unsigned long page
= 0;
2245 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2250 i
= (unsigned long *) data
;
2251 min
= (unsigned long *) table
->extra1
;
2252 max
= (unsigned long *) table
->extra2
;
2253 vleft
= table
->maxlen
/ sizeof(unsigned long);
2258 switch (sysctl_writes_strict
) {
2259 case SYSCTL_WRITES_STRICT
:
2261 case SYSCTL_WRITES_WARN
:
2262 warn_sysctl_write(table
);
2269 if (left
> PAGE_SIZE
- 1)
2270 left
= PAGE_SIZE
- 1;
2271 page
= __get_free_page(GFP_TEMPORARY
);
2272 kbuf
= (char *) page
;
2275 if (copy_from_user(kbuf
, buffer
, left
)) {
2282 for (; left
&& vleft
--; i
++, first
= 0) {
2288 left
-= proc_skip_spaces(&kbuf
);
2290 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2292 sizeof(proc_wspace_sep
), NULL
);
2297 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2301 val
= convdiv
* (*i
) / convmul
;
2303 err
= proc_put_char(&buffer
, &left
, '\t');
2307 err
= proc_put_long(&buffer
, &left
, val
, false);
2313 if (!write
&& !first
&& left
&& !err
)
2314 err
= proc_put_char(&buffer
, &left
, '\n');
2316 left
-= proc_skip_spaces(&kbuf
);
2321 return err
? : -EINVAL
;
2329 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2330 void __user
*buffer
,
2331 size_t *lenp
, loff_t
*ppos
,
2332 unsigned long convmul
,
2333 unsigned long convdiv
)
2335 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2336 buffer
, lenp
, ppos
, convmul
, convdiv
);
2340 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2341 * @table: the sysctl table
2342 * @write: %TRUE if this is a write to the sysctl file
2343 * @buffer: the user buffer
2344 * @lenp: the size of the user buffer
2345 * @ppos: file position
2347 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2348 * values from/to the user buffer, treated as an ASCII string.
2350 * This routine will ensure the values are within the range specified by
2351 * table->extra1 (min) and table->extra2 (max).
2353 * Returns 0 on success.
2355 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2356 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2358 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2362 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2363 * @table: the sysctl table
2364 * @write: %TRUE if this is a write to the sysctl file
2365 * @buffer: the user buffer
2366 * @lenp: the size of the user buffer
2367 * @ppos: file position
2369 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2370 * values from/to the user buffer, treated as an ASCII string. The values
2371 * are treated as milliseconds, and converted to jiffies when they are stored.
2373 * This routine will ensure the values are within the range specified by
2374 * table->extra1 (min) and table->extra2 (max).
2376 * Returns 0 on success.
2378 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2379 void __user
*buffer
,
2380 size_t *lenp
, loff_t
*ppos
)
2382 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2383 lenp
, ppos
, HZ
, 1000l);
2387 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2389 int write
, void *data
)
2392 if (*lvalp
> LONG_MAX
/ HZ
)
2394 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2400 lval
= (unsigned long)-val
;
2403 lval
= (unsigned long)val
;
2410 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2412 int write
, void *data
)
2415 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2417 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2423 lval
= (unsigned long)-val
;
2426 lval
= (unsigned long)val
;
2428 *lvalp
= jiffies_to_clock_t(lval
);
2433 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2435 int write
, void *data
)
2438 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2448 lval
= (unsigned long)-val
;
2451 lval
= (unsigned long)val
;
2453 *lvalp
= jiffies_to_msecs(lval
);
2459 * proc_dointvec_jiffies - read a vector of integers as seconds
2460 * @table: the sysctl table
2461 * @write: %TRUE if this is a write to the sysctl file
2462 * @buffer: the user buffer
2463 * @lenp: the size of the user buffer
2464 * @ppos: file position
2466 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2467 * values from/to the user buffer, treated as an ASCII string.
2468 * The values read are assumed to be in seconds, and are converted into
2471 * Returns 0 on success.
2473 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2474 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2476 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2477 do_proc_dointvec_jiffies_conv
,NULL
);
2481 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
2484 * @buffer: the user buffer
2485 * @lenp: the size of the user buffer
2486 * @ppos: pointer to the file position
2488 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2489 * values from/to the user buffer, treated as an ASCII string.
2490 * The values read are assumed to be in 1/USER_HZ seconds, and
2491 * are converted into jiffies.
2493 * Returns 0 on success.
2495 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2496 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2498 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2499 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2503 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2504 * @table: the sysctl table
2505 * @write: %TRUE if this is a write to the sysctl file
2506 * @buffer: the user buffer
2507 * @lenp: the size of the user buffer
2508 * @ppos: file position
2509 * @ppos: the current position in the file
2511 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2512 * values from/to the user buffer, treated as an ASCII string.
2513 * The values read are assumed to be in 1/1000 seconds, and
2514 * are converted into jiffies.
2516 * Returns 0 on success.
2518 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2519 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2521 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2522 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2525 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2526 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2528 struct pid
*new_pid
;
2532 tmp
= pid_vnr(cad_pid
);
2534 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2535 lenp
, ppos
, NULL
, NULL
);
2539 new_pid
= find_get_pid(tmp
);
2543 put_pid(xchg(&cad_pid
, new_pid
));
2548 * proc_do_large_bitmap - read/write from/to a large bitmap
2549 * @table: the sysctl table
2550 * @write: %TRUE if this is a write to the sysctl file
2551 * @buffer: the user buffer
2552 * @lenp: the size of the user buffer
2553 * @ppos: file position
2555 * The bitmap is stored at table->data and the bitmap length (in bits)
2558 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2559 * large bitmaps may be represented in a compact manner. Writing into
2560 * the file will clear the bitmap then update it with the given input.
2562 * Returns 0 on success.
2564 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2565 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2569 size_t left
= *lenp
;
2570 unsigned long bitmap_len
= table
->maxlen
;
2571 unsigned long *bitmap
= (unsigned long *) table
->data
;
2572 unsigned long *tmp_bitmap
= NULL
;
2573 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2575 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2581 unsigned long page
= 0;
2584 if (left
> PAGE_SIZE
- 1)
2585 left
= PAGE_SIZE
- 1;
2587 page
= __get_free_page(GFP_TEMPORARY
);
2588 kbuf
= (char *) page
;
2591 if (copy_from_user(kbuf
, buffer
, left
)) {
2597 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2603 proc_skip_char(&kbuf
, &left
, '\n');
2604 while (!err
&& left
) {
2605 unsigned long val_a
, val_b
;
2608 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2612 if (val_a
>= bitmap_len
|| neg
) {
2624 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2625 &neg
, tr_b
, sizeof(tr_b
),
2629 if (val_b
>= bitmap_len
|| neg
||
2640 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2642 proc_skip_char(&kbuf
, &left
, '\n');
2646 unsigned long bit_a
, bit_b
= 0;
2649 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2650 if (bit_a
>= bitmap_len
)
2652 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2656 err
= proc_put_char(&buffer
, &left
, ',');
2660 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2663 if (bit_a
!= bit_b
) {
2664 err
= proc_put_char(&buffer
, &left
, '-');
2667 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2675 err
= proc_put_char(&buffer
, &left
, '\n');
2681 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2683 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2695 #else /* CONFIG_PROC_SYSCTL */
2697 int proc_dostring(struct ctl_table
*table
, int write
,
2698 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2703 int proc_dointvec(struct ctl_table
*table
, int write
,
2704 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2709 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2710 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2715 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2716 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2721 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2722 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2727 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2728 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2733 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2734 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2739 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2740 void __user
*buffer
,
2741 size_t *lenp
, loff_t
*ppos
)
2747 #endif /* CONFIG_PROC_SYSCTL */
2750 * No sense putting this after each symbol definition, twice,
2751 * exception granted :-)
2753 EXPORT_SYMBOL(proc_dointvec
);
2754 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2755 EXPORT_SYMBOL(proc_dointvec_minmax
);
2756 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2757 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2758 EXPORT_SYMBOL(proc_dostring
);
2759 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2760 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);