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>
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
,
394 .procname
= "numa_balancing",
395 .data
= NULL
, /* filled in by handler */
396 .maxlen
= sizeof(unsigned int),
398 .proc_handler
= sysctl_numa_balancing
,
402 #endif /* CONFIG_NUMA_BALANCING */
403 #endif /* CONFIG_SCHED_DEBUG */
405 .procname
= "sched_rt_period_us",
406 .data
= &sysctl_sched_rt_period
,
407 .maxlen
= sizeof(unsigned int),
409 .proc_handler
= sched_rt_handler
,
412 .procname
= "sched_rt_runtime_us",
413 .data
= &sysctl_sched_rt_runtime
,
414 .maxlen
= sizeof(int),
416 .proc_handler
= sched_rt_handler
,
419 .procname
= "sched_rr_timeslice_ms",
420 .data
= &sched_rr_timeslice
,
421 .maxlen
= sizeof(int),
423 .proc_handler
= sched_rr_handler
,
425 #ifdef CONFIG_SCHED_AUTOGROUP
427 .procname
= "sched_autogroup_enabled",
428 .data
= &sysctl_sched_autogroup_enabled
,
429 .maxlen
= sizeof(unsigned int),
431 .proc_handler
= proc_dointvec_minmax
,
436 #ifdef CONFIG_CFS_BANDWIDTH
438 .procname
= "sched_cfs_bandwidth_slice_us",
439 .data
= &sysctl_sched_cfs_bandwidth_slice
,
440 .maxlen
= sizeof(unsigned int),
442 .proc_handler
= proc_dointvec_minmax
,
446 #ifdef CONFIG_PROVE_LOCKING
448 .procname
= "prove_locking",
449 .data
= &prove_locking
,
450 .maxlen
= sizeof(int),
452 .proc_handler
= proc_dointvec
,
455 #ifdef CONFIG_LOCK_STAT
457 .procname
= "lock_stat",
459 .maxlen
= sizeof(int),
461 .proc_handler
= proc_dointvec
,
466 .data
= &panic_timeout
,
467 .maxlen
= sizeof(int),
469 .proc_handler
= proc_dointvec
,
471 #ifdef CONFIG_COREDUMP
473 .procname
= "core_uses_pid",
474 .data
= &core_uses_pid
,
475 .maxlen
= sizeof(int),
477 .proc_handler
= proc_dointvec
,
480 .procname
= "core_pattern",
481 .data
= core_pattern
,
482 .maxlen
= CORENAME_MAX_SIZE
,
484 .proc_handler
= proc_dostring_coredump
,
487 .procname
= "core_pipe_limit",
488 .data
= &core_pipe_limit
,
489 .maxlen
= sizeof(unsigned int),
491 .proc_handler
= proc_dointvec
,
494 #ifdef CONFIG_PROC_SYSCTL
496 .procname
= "tainted",
497 .maxlen
= sizeof(long),
499 .proc_handler
= proc_taint
,
502 .procname
= "sysctl_writes_strict",
503 .data
= &sysctl_writes_strict
,
504 .maxlen
= sizeof(int),
506 .proc_handler
= proc_dointvec_minmax
,
511 #ifdef CONFIG_LATENCYTOP
513 .procname
= "latencytop",
514 .data
= &latencytop_enabled
,
515 .maxlen
= sizeof(int),
517 .proc_handler
= proc_dointvec
,
520 #ifdef CONFIG_BLK_DEV_INITRD
522 .procname
= "real-root-dev",
523 .data
= &real_root_dev
,
524 .maxlen
= sizeof(int),
526 .proc_handler
= proc_dointvec
,
530 .procname
= "print-fatal-signals",
531 .data
= &print_fatal_signals
,
532 .maxlen
= sizeof(int),
534 .proc_handler
= proc_dointvec
,
538 .procname
= "reboot-cmd",
539 .data
= reboot_command
,
542 .proc_handler
= proc_dostring
,
545 .procname
= "stop-a",
546 .data
= &stop_a_enabled
,
547 .maxlen
= sizeof (int),
549 .proc_handler
= proc_dointvec
,
552 .procname
= "scons-poweroff",
553 .data
= &scons_pwroff
,
554 .maxlen
= sizeof (int),
556 .proc_handler
= proc_dointvec
,
559 #ifdef CONFIG_SPARC64
561 .procname
= "tsb-ratio",
562 .data
= &sysctl_tsb_ratio
,
563 .maxlen
= sizeof (int),
565 .proc_handler
= proc_dointvec
,
570 .procname
= "soft-power",
571 .data
= &pwrsw_enabled
,
572 .maxlen
= sizeof (int),
574 .proc_handler
= proc_dointvec
,
577 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
579 .procname
= "unaligned-trap",
580 .data
= &unaligned_enabled
,
581 .maxlen
= sizeof (int),
583 .proc_handler
= proc_dointvec
,
587 .procname
= "ctrl-alt-del",
589 .maxlen
= sizeof(int),
591 .proc_handler
= proc_dointvec
,
593 #ifdef CONFIG_FUNCTION_TRACER
595 .procname
= "ftrace_enabled",
596 .data
= &ftrace_enabled
,
597 .maxlen
= sizeof(int),
599 .proc_handler
= ftrace_enable_sysctl
,
602 #ifdef CONFIG_STACK_TRACER
604 .procname
= "stack_tracer_enabled",
605 .data
= &stack_tracer_enabled
,
606 .maxlen
= sizeof(int),
608 .proc_handler
= stack_trace_sysctl
,
611 #ifdef CONFIG_TRACING
613 .procname
= "ftrace_dump_on_oops",
614 .data
= &ftrace_dump_on_oops
,
615 .maxlen
= sizeof(int),
617 .proc_handler
= proc_dointvec
,
620 .procname
= "traceoff_on_warning",
621 .data
= &__disable_trace_on_warning
,
622 .maxlen
= sizeof(__disable_trace_on_warning
),
624 .proc_handler
= proc_dointvec
,
629 .procname
= "kexec_load_disabled",
630 .data
= &kexec_load_disabled
,
631 .maxlen
= sizeof(int),
633 /* only handle a transition from default "0" to "1" */
634 .proc_handler
= proc_dointvec_minmax
,
639 #ifdef CONFIG_MODULES
641 .procname
= "modprobe",
642 .data
= &modprobe_path
,
643 .maxlen
= KMOD_PATH_LEN
,
645 .proc_handler
= proc_dostring
,
648 .procname
= "modules_disabled",
649 .data
= &modules_disabled
,
650 .maxlen
= sizeof(int),
652 /* only handle a transition from default "0" to "1" */
653 .proc_handler
= proc_dointvec_minmax
,
658 #ifdef CONFIG_UEVENT_HELPER
660 .procname
= "hotplug",
661 .data
= &uevent_helper
,
662 .maxlen
= UEVENT_HELPER_PATH_LEN
,
664 .proc_handler
= proc_dostring
,
667 #ifdef CONFIG_CHR_DEV_SG
669 .procname
= "sg-big-buff",
670 .data
= &sg_big_buff
,
671 .maxlen
= sizeof (int),
673 .proc_handler
= proc_dointvec
,
676 #ifdef CONFIG_BSD_PROCESS_ACCT
680 .maxlen
= 3*sizeof(int),
682 .proc_handler
= proc_dointvec
,
685 #ifdef CONFIG_MAGIC_SYSRQ
688 .data
= &__sysrq_enabled
,
689 .maxlen
= sizeof (int),
691 .proc_handler
= sysrq_sysctl_handler
,
694 #ifdef CONFIG_PROC_SYSCTL
696 .procname
= "cad_pid",
698 .maxlen
= sizeof (int),
700 .proc_handler
= proc_do_cad_pid
,
704 .procname
= "threads-max",
705 .data
= &max_threads
,
706 .maxlen
= sizeof(int),
708 .proc_handler
= proc_dointvec
,
711 .procname
= "random",
713 .child
= random_table
,
716 .procname
= "usermodehelper",
718 .child
= usermodehelper_table
,
721 .procname
= "overflowuid",
722 .data
= &overflowuid
,
723 .maxlen
= sizeof(int),
725 .proc_handler
= proc_dointvec_minmax
,
726 .extra1
= &minolduid
,
727 .extra2
= &maxolduid
,
730 .procname
= "overflowgid",
731 .data
= &overflowgid
,
732 .maxlen
= sizeof(int),
734 .proc_handler
= proc_dointvec_minmax
,
735 .extra1
= &minolduid
,
736 .extra2
= &maxolduid
,
739 #ifdef CONFIG_MATHEMU
741 .procname
= "ieee_emulation_warnings",
742 .data
= &sysctl_ieee_emulation_warnings
,
743 .maxlen
= sizeof(int),
745 .proc_handler
= proc_dointvec
,
749 .procname
= "userprocess_debug",
750 .data
= &show_unhandled_signals
,
751 .maxlen
= sizeof(int),
753 .proc_handler
= proc_dointvec
,
757 .procname
= "pid_max",
759 .maxlen
= sizeof (int),
761 .proc_handler
= proc_dointvec_minmax
,
762 .extra1
= &pid_max_min
,
763 .extra2
= &pid_max_max
,
766 .procname
= "panic_on_oops",
767 .data
= &panic_on_oops
,
768 .maxlen
= sizeof(int),
770 .proc_handler
= proc_dointvec
,
772 #if defined CONFIG_PRINTK
774 .procname
= "printk",
775 .data
= &console_loglevel
,
776 .maxlen
= 4*sizeof(int),
778 .proc_handler
= proc_dointvec
,
781 .procname
= "printk_ratelimit",
782 .data
= &printk_ratelimit_state
.interval
,
783 .maxlen
= sizeof(int),
785 .proc_handler
= proc_dointvec_jiffies
,
788 .procname
= "printk_ratelimit_burst",
789 .data
= &printk_ratelimit_state
.burst
,
790 .maxlen
= sizeof(int),
792 .proc_handler
= proc_dointvec
,
795 .procname
= "printk_delay",
796 .data
= &printk_delay_msec
,
797 .maxlen
= sizeof(int),
799 .proc_handler
= proc_dointvec_minmax
,
801 .extra2
= &ten_thousand
,
804 .procname
= "dmesg_restrict",
805 .data
= &dmesg_restrict
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= proc_dointvec_minmax_sysadmin
,
813 .procname
= "kptr_restrict",
814 .data
= &kptr_restrict
,
815 .maxlen
= sizeof(int),
817 .proc_handler
= proc_dointvec_minmax_sysadmin
,
823 .procname
= "ngroups_max",
824 .data
= &ngroups_max
,
825 .maxlen
= sizeof (int),
827 .proc_handler
= proc_dointvec
,
830 .procname
= "cap_last_cap",
831 .data
= (void *)&cap_last_cap
,
832 .maxlen
= sizeof(int),
834 .proc_handler
= proc_dointvec
,
836 #if defined(CONFIG_LOCKUP_DETECTOR)
838 .procname
= "watchdog",
839 .data
= &watchdog_user_enabled
,
840 .maxlen
= sizeof (int),
842 .proc_handler
= proc_dowatchdog
,
847 .procname
= "watchdog_thresh",
848 .data
= &watchdog_thresh
,
849 .maxlen
= sizeof(int),
851 .proc_handler
= proc_dowatchdog
,
856 .procname
= "softlockup_panic",
857 .data
= &softlockup_panic
,
858 .maxlen
= sizeof(int),
860 .proc_handler
= proc_dointvec_minmax
,
865 .procname
= "nmi_watchdog",
866 .data
= &watchdog_user_enabled
,
867 .maxlen
= sizeof (int),
869 .proc_handler
= proc_dowatchdog
,
874 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
876 .procname
= "unknown_nmi_panic",
877 .data
= &unknown_nmi_panic
,
878 .maxlen
= sizeof (int),
880 .proc_handler
= proc_dointvec
,
883 #if defined(CONFIG_X86)
885 .procname
= "panic_on_unrecovered_nmi",
886 .data
= &panic_on_unrecovered_nmi
,
887 .maxlen
= sizeof(int),
889 .proc_handler
= proc_dointvec
,
892 .procname
= "panic_on_io_nmi",
893 .data
= &panic_on_io_nmi
,
894 .maxlen
= sizeof(int),
896 .proc_handler
= proc_dointvec
,
898 #ifdef CONFIG_DEBUG_STACKOVERFLOW
900 .procname
= "panic_on_stackoverflow",
901 .data
= &sysctl_panic_on_stackoverflow
,
902 .maxlen
= sizeof(int),
904 .proc_handler
= proc_dointvec
,
908 .procname
= "bootloader_type",
909 .data
= &bootloader_type
,
910 .maxlen
= sizeof (int),
912 .proc_handler
= proc_dointvec
,
915 .procname
= "bootloader_version",
916 .data
= &bootloader_version
,
917 .maxlen
= sizeof (int),
919 .proc_handler
= proc_dointvec
,
922 .procname
= "kstack_depth_to_print",
923 .data
= &kstack_depth_to_print
,
924 .maxlen
= sizeof(int),
926 .proc_handler
= proc_dointvec
,
929 .procname
= "io_delay_type",
930 .data
= &io_delay_type
,
931 .maxlen
= sizeof(int),
933 .proc_handler
= proc_dointvec
,
936 #if defined(CONFIG_MMU)
938 .procname
= "randomize_va_space",
939 .data
= &randomize_va_space
,
940 .maxlen
= sizeof(int),
942 .proc_handler
= proc_dointvec
,
945 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
947 .procname
= "spin_retry",
949 .maxlen
= sizeof (int),
951 .proc_handler
= proc_dointvec
,
954 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
956 .procname
= "acpi_video_flags",
957 .data
= &acpi_realmode_flags
,
958 .maxlen
= sizeof (unsigned long),
960 .proc_handler
= proc_doulongvec_minmax
,
963 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
965 .procname
= "ignore-unaligned-usertrap",
966 .data
= &no_unaligned_warning
,
967 .maxlen
= sizeof (int),
969 .proc_handler
= proc_dointvec
,
974 .procname
= "unaligned-dump-stack",
975 .data
= &unaligned_dump_stack
,
976 .maxlen
= sizeof (int),
978 .proc_handler
= proc_dointvec
,
981 #ifdef CONFIG_DETECT_HUNG_TASK
983 .procname
= "hung_task_panic",
984 .data
= &sysctl_hung_task_panic
,
985 .maxlen
= sizeof(int),
987 .proc_handler
= proc_dointvec_minmax
,
992 .procname
= "hung_task_check_count",
993 .data
= &sysctl_hung_task_check_count
,
994 .maxlen
= sizeof(int),
996 .proc_handler
= proc_dointvec_minmax
,
1000 .procname
= "hung_task_timeout_secs",
1001 .data
= &sysctl_hung_task_timeout_secs
,
1002 .maxlen
= sizeof(unsigned long),
1004 .proc_handler
= proc_dohung_task_timeout_secs
,
1005 .extra2
= &hung_task_timeout_max
,
1008 .procname
= "hung_task_warnings",
1009 .data
= &sysctl_hung_task_warnings
,
1010 .maxlen
= sizeof(int),
1012 .proc_handler
= proc_dointvec_minmax
,
1016 #ifdef CONFIG_COMPAT
1018 .procname
= "compat-log",
1019 .data
= &compat_log
,
1020 .maxlen
= sizeof (int),
1022 .proc_handler
= proc_dointvec
,
1025 #ifdef CONFIG_RT_MUTEXES
1027 .procname
= "max_lock_depth",
1028 .data
= &max_lock_depth
,
1029 .maxlen
= sizeof(int),
1031 .proc_handler
= proc_dointvec
,
1035 .procname
= "poweroff_cmd",
1036 .data
= &poweroff_cmd
,
1037 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1039 .proc_handler
= proc_dostring
,
1045 .child
= key_sysctls
,
1048 #ifdef CONFIG_RCU_TORTURE_TEST
1050 .procname
= "rcutorture_runnable",
1051 .data
= &rcutorture_runnable
,
1052 .maxlen
= sizeof(int),
1054 .proc_handler
= proc_dointvec
,
1057 #ifdef CONFIG_PERF_EVENTS
1059 * User-space scripts rely on the existence of this file
1060 * as a feature check for perf_events being enabled.
1062 * So it's an ABI, do not remove!
1065 .procname
= "perf_event_paranoid",
1066 .data
= &sysctl_perf_event_paranoid
,
1067 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1069 .proc_handler
= proc_dointvec
,
1072 .procname
= "perf_event_mlock_kb",
1073 .data
= &sysctl_perf_event_mlock
,
1074 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1076 .proc_handler
= proc_dointvec
,
1079 .procname
= "perf_event_max_sample_rate",
1080 .data
= &sysctl_perf_event_sample_rate
,
1081 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1083 .proc_handler
= perf_proc_update_handler
,
1087 .procname
= "perf_cpu_time_max_percent",
1088 .data
= &sysctl_perf_cpu_time_max_percent
,
1089 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1091 .proc_handler
= perf_cpu_time_max_percent_handler
,
1093 .extra2
= &one_hundred
,
1096 #ifdef CONFIG_KMEMCHECK
1098 .procname
= "kmemcheck",
1099 .data
= &kmemcheck_enabled
,
1100 .maxlen
= sizeof(int),
1102 .proc_handler
= proc_dointvec
,
1108 static struct ctl_table vm_table
[] = {
1110 .procname
= "overcommit_memory",
1111 .data
= &sysctl_overcommit_memory
,
1112 .maxlen
= sizeof(sysctl_overcommit_memory
),
1114 .proc_handler
= proc_dointvec_minmax
,
1119 .procname
= "panic_on_oom",
1120 .data
= &sysctl_panic_on_oom
,
1121 .maxlen
= sizeof(sysctl_panic_on_oom
),
1123 .proc_handler
= proc_dointvec_minmax
,
1128 .procname
= "oom_kill_allocating_task",
1129 .data
= &sysctl_oom_kill_allocating_task
,
1130 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1132 .proc_handler
= proc_dointvec
,
1135 .procname
= "oom_dump_tasks",
1136 .data
= &sysctl_oom_dump_tasks
,
1137 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1139 .proc_handler
= proc_dointvec
,
1142 .procname
= "overcommit_ratio",
1143 .data
= &sysctl_overcommit_ratio
,
1144 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1146 .proc_handler
= overcommit_ratio_handler
,
1149 .procname
= "overcommit_kbytes",
1150 .data
= &sysctl_overcommit_kbytes
,
1151 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1153 .proc_handler
= overcommit_kbytes_handler
,
1156 .procname
= "page-cluster",
1157 .data
= &page_cluster
,
1158 .maxlen
= sizeof(int),
1160 .proc_handler
= proc_dointvec_minmax
,
1164 .procname
= "dirty_background_ratio",
1165 .data
= &dirty_background_ratio
,
1166 .maxlen
= sizeof(dirty_background_ratio
),
1168 .proc_handler
= dirty_background_ratio_handler
,
1170 .extra2
= &one_hundred
,
1173 .procname
= "dirty_background_bytes",
1174 .data
= &dirty_background_bytes
,
1175 .maxlen
= sizeof(dirty_background_bytes
),
1177 .proc_handler
= dirty_background_bytes_handler
,
1181 .procname
= "dirty_ratio",
1182 .data
= &vm_dirty_ratio
,
1183 .maxlen
= sizeof(vm_dirty_ratio
),
1185 .proc_handler
= dirty_ratio_handler
,
1187 .extra2
= &one_hundred
,
1190 .procname
= "dirty_bytes",
1191 .data
= &vm_dirty_bytes
,
1192 .maxlen
= sizeof(vm_dirty_bytes
),
1194 .proc_handler
= dirty_bytes_handler
,
1195 .extra1
= &dirty_bytes_min
,
1198 .procname
= "dirty_writeback_centisecs",
1199 .data
= &dirty_writeback_interval
,
1200 .maxlen
= sizeof(dirty_writeback_interval
),
1202 .proc_handler
= dirty_writeback_centisecs_handler
,
1205 .procname
= "dirty_expire_centisecs",
1206 .data
= &dirty_expire_interval
,
1207 .maxlen
= sizeof(dirty_expire_interval
),
1209 .proc_handler
= proc_dointvec_minmax
,
1213 .procname
= "nr_pdflush_threads",
1214 .mode
= 0444 /* read-only */,
1215 .proc_handler
= pdflush_proc_obsolete
,
1218 .procname
= "swappiness",
1219 .data
= &vm_swappiness
,
1220 .maxlen
= sizeof(vm_swappiness
),
1222 .proc_handler
= proc_dointvec_minmax
,
1224 .extra2
= &one_hundred
,
1226 #ifdef CONFIG_HUGETLB_PAGE
1228 .procname
= "nr_hugepages",
1230 .maxlen
= sizeof(unsigned long),
1232 .proc_handler
= hugetlb_sysctl_handler
,
1233 .extra1
= (void *)&hugetlb_zero
,
1234 .extra2
= (void *)&hugetlb_infinity
,
1238 .procname
= "nr_hugepages_mempolicy",
1240 .maxlen
= sizeof(unsigned long),
1242 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1243 .extra1
= (void *)&hugetlb_zero
,
1244 .extra2
= (void *)&hugetlb_infinity
,
1248 .procname
= "hugetlb_shm_group",
1249 .data
= &sysctl_hugetlb_shm_group
,
1250 .maxlen
= sizeof(gid_t
),
1252 .proc_handler
= proc_dointvec
,
1255 .procname
= "hugepages_treat_as_movable",
1256 .data
= &hugepages_treat_as_movable
,
1257 .maxlen
= sizeof(int),
1259 .proc_handler
= proc_dointvec
,
1262 .procname
= "nr_overcommit_hugepages",
1264 .maxlen
= sizeof(unsigned long),
1266 .proc_handler
= hugetlb_overcommit_handler
,
1267 .extra1
= (void *)&hugetlb_zero
,
1268 .extra2
= (void *)&hugetlb_infinity
,
1272 .procname
= "lowmem_reserve_ratio",
1273 .data
= &sysctl_lowmem_reserve_ratio
,
1274 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1276 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1279 .procname
= "drop_caches",
1280 .data
= &sysctl_drop_caches
,
1281 .maxlen
= sizeof(int),
1283 .proc_handler
= drop_caches_sysctl_handler
,
1287 #ifdef CONFIG_COMPACTION
1289 .procname
= "compact_memory",
1290 .data
= &sysctl_compact_memory
,
1291 .maxlen
= sizeof(int),
1293 .proc_handler
= sysctl_compaction_handler
,
1296 .procname
= "extfrag_threshold",
1297 .data
= &sysctl_extfrag_threshold
,
1298 .maxlen
= sizeof(int),
1300 .proc_handler
= sysctl_extfrag_handler
,
1301 .extra1
= &min_extfrag_threshold
,
1302 .extra2
= &max_extfrag_threshold
,
1305 #endif /* CONFIG_COMPACTION */
1307 .procname
= "min_free_kbytes",
1308 .data
= &min_free_kbytes
,
1309 .maxlen
= sizeof(min_free_kbytes
),
1311 .proc_handler
= min_free_kbytes_sysctl_handler
,
1315 .procname
= "percpu_pagelist_fraction",
1316 .data
= &percpu_pagelist_fraction
,
1317 .maxlen
= sizeof(percpu_pagelist_fraction
),
1319 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1320 .extra1
= &min_percpu_pagelist_fract
,
1324 .procname
= "max_map_count",
1325 .data
= &sysctl_max_map_count
,
1326 .maxlen
= sizeof(sysctl_max_map_count
),
1328 .proc_handler
= proc_dointvec_minmax
,
1333 .procname
= "nr_trim_pages",
1334 .data
= &sysctl_nr_trim_pages
,
1335 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1337 .proc_handler
= proc_dointvec_minmax
,
1342 .procname
= "laptop_mode",
1343 .data
= &laptop_mode
,
1344 .maxlen
= sizeof(laptop_mode
),
1346 .proc_handler
= proc_dointvec_jiffies
,
1349 .procname
= "block_dump",
1350 .data
= &block_dump
,
1351 .maxlen
= sizeof(block_dump
),
1353 .proc_handler
= proc_dointvec
,
1357 .procname
= "vfs_cache_pressure",
1358 .data
= &sysctl_vfs_cache_pressure
,
1359 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1361 .proc_handler
= proc_dointvec
,
1364 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1366 .procname
= "legacy_va_layout",
1367 .data
= &sysctl_legacy_va_layout
,
1368 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1370 .proc_handler
= proc_dointvec
,
1376 .procname
= "zone_reclaim_mode",
1377 .data
= &zone_reclaim_mode
,
1378 .maxlen
= sizeof(zone_reclaim_mode
),
1380 .proc_handler
= proc_dointvec
,
1384 .procname
= "min_unmapped_ratio",
1385 .data
= &sysctl_min_unmapped_ratio
,
1386 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1388 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1390 .extra2
= &one_hundred
,
1393 .procname
= "min_slab_ratio",
1394 .data
= &sysctl_min_slab_ratio
,
1395 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1397 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1399 .extra2
= &one_hundred
,
1404 .procname
= "stat_interval",
1405 .data
= &sysctl_stat_interval
,
1406 .maxlen
= sizeof(sysctl_stat_interval
),
1408 .proc_handler
= proc_dointvec_jiffies
,
1413 .procname
= "mmap_min_addr",
1414 .data
= &dac_mmap_min_addr
,
1415 .maxlen
= sizeof(unsigned long),
1417 .proc_handler
= mmap_min_addr_handler
,
1422 .procname
= "numa_zonelist_order",
1423 .data
= &numa_zonelist_order
,
1424 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1426 .proc_handler
= numa_zonelist_order_handler
,
1429 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1430 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1432 .procname
= "vdso_enabled",
1433 #ifdef CONFIG_X86_32
1434 .data
= &vdso32_enabled
,
1435 .maxlen
= sizeof(vdso32_enabled
),
1437 .data
= &vdso_enabled
,
1438 .maxlen
= sizeof(vdso_enabled
),
1441 .proc_handler
= proc_dointvec
,
1445 #ifdef CONFIG_HIGHMEM
1447 .procname
= "highmem_is_dirtyable",
1448 .data
= &vm_highmem_is_dirtyable
,
1449 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1451 .proc_handler
= proc_dointvec_minmax
,
1457 .procname
= "scan_unevictable_pages",
1458 .data
= &scan_unevictable_pages
,
1459 .maxlen
= sizeof(scan_unevictable_pages
),
1461 .proc_handler
= scan_unevictable_handler
,
1463 #ifdef CONFIG_MEMORY_FAILURE
1465 .procname
= "memory_failure_early_kill",
1466 .data
= &sysctl_memory_failure_early_kill
,
1467 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1469 .proc_handler
= proc_dointvec_minmax
,
1474 .procname
= "memory_failure_recovery",
1475 .data
= &sysctl_memory_failure_recovery
,
1476 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1478 .proc_handler
= proc_dointvec_minmax
,
1484 .procname
= "user_reserve_kbytes",
1485 .data
= &sysctl_user_reserve_kbytes
,
1486 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1488 .proc_handler
= proc_doulongvec_minmax
,
1491 .procname
= "admin_reserve_kbytes",
1492 .data
= &sysctl_admin_reserve_kbytes
,
1493 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1495 .proc_handler
= proc_doulongvec_minmax
,
1500 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1501 static struct ctl_table binfmt_misc_table
[] = {
1506 static struct ctl_table fs_table
[] = {
1508 .procname
= "inode-nr",
1509 .data
= &inodes_stat
,
1510 .maxlen
= 2*sizeof(long),
1512 .proc_handler
= proc_nr_inodes
,
1515 .procname
= "inode-state",
1516 .data
= &inodes_stat
,
1517 .maxlen
= 7*sizeof(long),
1519 .proc_handler
= proc_nr_inodes
,
1522 .procname
= "file-nr",
1523 .data
= &files_stat
,
1524 .maxlen
= sizeof(files_stat
),
1526 .proc_handler
= proc_nr_files
,
1529 .procname
= "file-max",
1530 .data
= &files_stat
.max_files
,
1531 .maxlen
= sizeof(files_stat
.max_files
),
1533 .proc_handler
= proc_doulongvec_minmax
,
1536 .procname
= "nr_open",
1537 .data
= &sysctl_nr_open
,
1538 .maxlen
= sizeof(int),
1540 .proc_handler
= proc_dointvec_minmax
,
1541 .extra1
= &sysctl_nr_open_min
,
1542 .extra2
= &sysctl_nr_open_max
,
1545 .procname
= "dentry-state",
1546 .data
= &dentry_stat
,
1547 .maxlen
= 6*sizeof(long),
1549 .proc_handler
= proc_nr_dentry
,
1552 .procname
= "overflowuid",
1553 .data
= &fs_overflowuid
,
1554 .maxlen
= sizeof(int),
1556 .proc_handler
= proc_dointvec_minmax
,
1557 .extra1
= &minolduid
,
1558 .extra2
= &maxolduid
,
1561 .procname
= "overflowgid",
1562 .data
= &fs_overflowgid
,
1563 .maxlen
= sizeof(int),
1565 .proc_handler
= proc_dointvec_minmax
,
1566 .extra1
= &minolduid
,
1567 .extra2
= &maxolduid
,
1569 #ifdef CONFIG_FILE_LOCKING
1571 .procname
= "leases-enable",
1572 .data
= &leases_enable
,
1573 .maxlen
= sizeof(int),
1575 .proc_handler
= proc_dointvec
,
1578 #ifdef CONFIG_DNOTIFY
1580 .procname
= "dir-notify-enable",
1581 .data
= &dir_notify_enable
,
1582 .maxlen
= sizeof(int),
1584 .proc_handler
= proc_dointvec
,
1588 #ifdef CONFIG_FILE_LOCKING
1590 .procname
= "lease-break-time",
1591 .data
= &lease_break_time
,
1592 .maxlen
= sizeof(int),
1594 .proc_handler
= proc_dointvec
,
1599 .procname
= "aio-nr",
1601 .maxlen
= sizeof(aio_nr
),
1603 .proc_handler
= proc_doulongvec_minmax
,
1606 .procname
= "aio-max-nr",
1607 .data
= &aio_max_nr
,
1608 .maxlen
= sizeof(aio_max_nr
),
1610 .proc_handler
= proc_doulongvec_minmax
,
1612 #endif /* CONFIG_AIO */
1613 #ifdef CONFIG_INOTIFY_USER
1615 .procname
= "inotify",
1617 .child
= inotify_table
,
1622 .procname
= "epoll",
1624 .child
= epoll_table
,
1629 .procname
= "protected_symlinks",
1630 .data
= &sysctl_protected_symlinks
,
1631 .maxlen
= sizeof(int),
1633 .proc_handler
= proc_dointvec_minmax
,
1638 .procname
= "protected_hardlinks",
1639 .data
= &sysctl_protected_hardlinks
,
1640 .maxlen
= sizeof(int),
1642 .proc_handler
= proc_dointvec_minmax
,
1647 .procname
= "suid_dumpable",
1648 .data
= &suid_dumpable
,
1649 .maxlen
= sizeof(int),
1651 .proc_handler
= proc_dointvec_minmax_coredump
,
1655 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1657 .procname
= "binfmt_misc",
1659 .child
= binfmt_misc_table
,
1663 .procname
= "pipe-max-size",
1664 .data
= &pipe_max_size
,
1665 .maxlen
= sizeof(int),
1667 .proc_handler
= &pipe_proc_fn
,
1668 .extra1
= &pipe_min_size
,
1673 static struct ctl_table debug_table
[] = {
1674 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1676 .procname
= "exception-trace",
1677 .data
= &show_unhandled_signals
,
1678 .maxlen
= sizeof(int),
1680 .proc_handler
= proc_dointvec
1683 #if defined(CONFIG_OPTPROBES)
1685 .procname
= "kprobes-optimization",
1686 .data
= &sysctl_kprobes_optimization
,
1687 .maxlen
= sizeof(int),
1689 .proc_handler
= proc_kprobes_optimization_handler
,
1697 static struct ctl_table dev_table
[] = {
1701 int __init
sysctl_init(void)
1703 struct ctl_table_header
*hdr
;
1705 hdr
= register_sysctl_table(sysctl_base_table
);
1706 kmemleak_not_leak(hdr
);
1710 #endif /* CONFIG_SYSCTL */
1716 #ifdef CONFIG_PROC_SYSCTL
1718 static int _proc_do_string(char *data
, int maxlen
, int write
,
1719 char __user
*buffer
,
1720 size_t *lenp
, loff_t
*ppos
)
1726 if (!data
|| !maxlen
|| !*lenp
) {
1732 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1733 /* Only continue writes not past the end of buffer. */
1735 if (len
> maxlen
- 1)
1742 /* Start writing from beginning of buffer. */
1748 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1749 if (get_user(c
, p
++))
1751 if (c
== 0 || c
== '\n')
1772 if (copy_to_user(buffer
, data
, len
))
1775 if (put_user('\n', buffer
+ len
))
1785 static void warn_sysctl_write(struct ctl_table
*table
)
1787 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1788 "This will not be supported in the future. To silence this\n"
1789 "warning, set kernel.sysctl_writes_strict = -1\n",
1790 current
->comm
, table
->procname
);
1794 * proc_dostring - read a string sysctl
1795 * @table: the sysctl table
1796 * @write: %TRUE if this is a write to the sysctl file
1797 * @buffer: the user buffer
1798 * @lenp: the size of the user buffer
1799 * @ppos: file position
1801 * Reads/writes a string from/to the user buffer. If the kernel
1802 * buffer provided is not large enough to hold the string, the
1803 * string is truncated. The copied string is %NULL-terminated.
1804 * If the string is being read by the user process, it is copied
1805 * and a newline '\n' is added. It is truncated if the buffer is
1808 * Returns 0 on success.
1810 int proc_dostring(struct ctl_table
*table
, int write
,
1811 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1813 if (write
&& *ppos
&& sysctl_writes_strict
== SYSCTL_WRITES_WARN
)
1814 warn_sysctl_write(table
);
1816 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
1817 (char __user
*)buffer
, lenp
, ppos
);
1820 static size_t proc_skip_spaces(char **buf
)
1823 char *tmp
= skip_spaces(*buf
);
1829 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1839 #define TMPBUFLEN 22
1841 * proc_get_long - reads an ASCII formatted integer from a user buffer
1843 * @buf: a kernel buffer
1844 * @size: size of the kernel buffer
1845 * @val: this is where the number will be stored
1846 * @neg: set to %TRUE if number is negative
1847 * @perm_tr: a vector which contains the allowed trailers
1848 * @perm_tr_len: size of the perm_tr vector
1849 * @tr: pointer to store the trailer character
1851 * In case of success %0 is returned and @buf and @size are updated with
1852 * the amount of bytes read. If @tr is non-NULL and a trailing
1853 * character exists (size is non-zero after returning from this
1854 * function), @tr is updated with the trailing character.
1856 static int proc_get_long(char **buf
, size_t *size
,
1857 unsigned long *val
, bool *neg
,
1858 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1861 char *p
, tmp
[TMPBUFLEN
];
1867 if (len
> TMPBUFLEN
- 1)
1868 len
= TMPBUFLEN
- 1;
1870 memcpy(tmp
, *buf
, len
);
1874 if (*p
== '-' && *size
> 1) {
1882 *val
= simple_strtoul(p
, &p
, 0);
1886 /* We don't know if the next char is whitespace thus we may accept
1887 * invalid integers (e.g. 1234...a) or two integers instead of one
1888 * (e.g. 123...1). So lets not allow such large numbers. */
1889 if (len
== TMPBUFLEN
- 1)
1892 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1895 if (tr
&& (len
< *size
))
1905 * proc_put_long - converts an integer to a decimal ASCII formatted string
1907 * @buf: the user buffer
1908 * @size: the size of the user buffer
1909 * @val: the integer to be converted
1910 * @neg: sign of the number, %TRUE for negative
1912 * In case of success %0 is returned and @buf and @size are updated with
1913 * the amount of bytes written.
1915 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1919 char tmp
[TMPBUFLEN
], *p
= tmp
;
1921 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1925 if (copy_to_user(*buf
, tmp
, len
))
1933 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1936 char __user
**buffer
= (char __user
**)buf
;
1937 if (put_user(c
, *buffer
))
1939 (*size
)--, (*buffer
)++;
1945 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1947 int write
, void *data
)
1950 *valp
= *negp
? -*lvalp
: *lvalp
;
1955 *lvalp
= (unsigned long)-val
;
1958 *lvalp
= (unsigned long)val
;
1964 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1966 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1967 int write
, void __user
*buffer
,
1968 size_t *lenp
, loff_t
*ppos
,
1969 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1970 int write
, void *data
),
1973 int *i
, vleft
, first
= 1, err
= 0;
1974 unsigned long page
= 0;
1978 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1983 i
= (int *) tbl_data
;
1984 vleft
= table
->maxlen
/ sizeof(*i
);
1988 conv
= do_proc_dointvec_conv
;
1992 switch (sysctl_writes_strict
) {
1993 case SYSCTL_WRITES_STRICT
:
1995 case SYSCTL_WRITES_WARN
:
1996 warn_sysctl_write(table
);
2003 if (left
> PAGE_SIZE
- 1)
2004 left
= PAGE_SIZE
- 1;
2005 page
= __get_free_page(GFP_TEMPORARY
);
2006 kbuf
= (char *) page
;
2009 if (copy_from_user(kbuf
, buffer
, left
)) {
2016 for (; left
&& vleft
--; i
++, first
=0) {
2021 left
-= proc_skip_spaces(&kbuf
);
2025 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2027 sizeof(proc_wspace_sep
), NULL
);
2030 if (conv(&neg
, &lval
, i
, 1, data
)) {
2035 if (conv(&neg
, &lval
, i
, 0, data
)) {
2040 err
= proc_put_char(&buffer
, &left
, '\t');
2043 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2049 if (!write
&& !first
&& left
&& !err
)
2050 err
= proc_put_char(&buffer
, &left
, '\n');
2051 if (write
&& !err
&& left
)
2052 left
-= proc_skip_spaces(&kbuf
);
2057 return err
? : -EINVAL
;
2065 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2066 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2067 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2068 int write
, void *data
),
2071 return __do_proc_dointvec(table
->data
, table
, write
,
2072 buffer
, lenp
, ppos
, conv
, data
);
2076 * proc_dointvec - read a vector of integers
2077 * @table: the sysctl table
2078 * @write: %TRUE if this is a write to the sysctl file
2079 * @buffer: the user buffer
2080 * @lenp: the size of the user buffer
2081 * @ppos: file position
2083 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2084 * values from/to the user buffer, treated as an ASCII string.
2086 * Returns 0 on success.
2088 int proc_dointvec(struct ctl_table
*table
, int write
,
2089 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2091 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2096 * Taint values can only be increased
2097 * This means we can safely use a temporary.
2099 static int proc_taint(struct ctl_table
*table
, int write
,
2100 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2103 unsigned long tmptaint
= get_taint();
2106 if (write
&& !capable(CAP_SYS_ADMIN
))
2111 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2117 * Poor man's atomic or. Not worth adding a primitive
2118 * to everyone's atomic.h for this
2121 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2122 if ((tmptaint
>> i
) & 1)
2123 add_taint(i
, LOCKDEP_STILL_OK
);
2130 #ifdef CONFIG_PRINTK
2131 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2132 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2134 if (write
&& !capable(CAP_SYS_ADMIN
))
2137 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2141 struct do_proc_dointvec_minmax_conv_param
{
2146 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2148 int write
, void *data
)
2150 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2152 int val
= *negp
? -*lvalp
: *lvalp
;
2153 if ((param
->min
&& *param
->min
> val
) ||
2154 (param
->max
&& *param
->max
< val
))
2161 *lvalp
= (unsigned long)-val
;
2164 *lvalp
= (unsigned long)val
;
2171 * proc_dointvec_minmax - read a vector of integers with min/max values
2172 * @table: the sysctl table
2173 * @write: %TRUE if this is a write to the sysctl file
2174 * @buffer: the user buffer
2175 * @lenp: the size of the user buffer
2176 * @ppos: file position
2178 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2179 * values from/to the user buffer, treated as an ASCII string.
2181 * This routine will ensure the values are within the range specified by
2182 * table->extra1 (min) and table->extra2 (max).
2184 * Returns 0 on success.
2186 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2187 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2189 struct do_proc_dointvec_minmax_conv_param param
= {
2190 .min
= (int *) table
->extra1
,
2191 .max
= (int *) table
->extra2
,
2193 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2194 do_proc_dointvec_minmax_conv
, ¶m
);
2197 static void validate_coredump_safety(void)
2199 #ifdef CONFIG_COREDUMP
2200 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2201 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2202 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2203 "suid_dumpable=2. Pipe handler or fully qualified "\
2204 "core dump path required.\n");
2209 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2210 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2212 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2214 validate_coredump_safety();
2218 #ifdef CONFIG_COREDUMP
2219 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2220 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2222 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2224 validate_coredump_safety();
2229 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2230 void __user
*buffer
,
2231 size_t *lenp
, loff_t
*ppos
,
2232 unsigned long convmul
,
2233 unsigned long convdiv
)
2235 unsigned long *i
, *min
, *max
;
2236 int vleft
, first
= 1, err
= 0;
2237 unsigned long page
= 0;
2241 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2246 i
= (unsigned long *) data
;
2247 min
= (unsigned long *) table
->extra1
;
2248 max
= (unsigned long *) table
->extra2
;
2249 vleft
= table
->maxlen
/ sizeof(unsigned long);
2254 switch (sysctl_writes_strict
) {
2255 case SYSCTL_WRITES_STRICT
:
2257 case SYSCTL_WRITES_WARN
:
2258 warn_sysctl_write(table
);
2265 if (left
> PAGE_SIZE
- 1)
2266 left
= PAGE_SIZE
- 1;
2267 page
= __get_free_page(GFP_TEMPORARY
);
2268 kbuf
= (char *) page
;
2271 if (copy_from_user(kbuf
, buffer
, left
)) {
2278 for (; left
&& vleft
--; i
++, first
= 0) {
2284 left
-= proc_skip_spaces(&kbuf
);
2286 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2288 sizeof(proc_wspace_sep
), NULL
);
2293 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2297 val
= convdiv
* (*i
) / convmul
;
2299 err
= proc_put_char(&buffer
, &left
, '\t');
2303 err
= proc_put_long(&buffer
, &left
, val
, false);
2309 if (!write
&& !first
&& left
&& !err
)
2310 err
= proc_put_char(&buffer
, &left
, '\n');
2312 left
-= proc_skip_spaces(&kbuf
);
2317 return err
? : -EINVAL
;
2325 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2326 void __user
*buffer
,
2327 size_t *lenp
, loff_t
*ppos
,
2328 unsigned long convmul
,
2329 unsigned long convdiv
)
2331 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2332 buffer
, lenp
, ppos
, convmul
, convdiv
);
2336 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2337 * @table: the sysctl table
2338 * @write: %TRUE if this is a write to the sysctl file
2339 * @buffer: the user buffer
2340 * @lenp: the size of the user buffer
2341 * @ppos: file position
2343 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2344 * values from/to the user buffer, treated as an ASCII string.
2346 * This routine will ensure the values are within the range specified by
2347 * table->extra1 (min) and table->extra2 (max).
2349 * Returns 0 on success.
2351 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2352 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2354 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2358 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2359 * @table: the sysctl table
2360 * @write: %TRUE if this is a write to the sysctl file
2361 * @buffer: the user buffer
2362 * @lenp: the size of the user buffer
2363 * @ppos: file position
2365 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2366 * values from/to the user buffer, treated as an ASCII string. The values
2367 * are treated as milliseconds, and converted to jiffies when they are stored.
2369 * This routine will ensure the values are within the range specified by
2370 * table->extra1 (min) and table->extra2 (max).
2372 * Returns 0 on success.
2374 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2375 void __user
*buffer
,
2376 size_t *lenp
, loff_t
*ppos
)
2378 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2379 lenp
, ppos
, HZ
, 1000l);
2383 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2385 int write
, void *data
)
2388 if (*lvalp
> LONG_MAX
/ HZ
)
2390 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2396 lval
= (unsigned long)-val
;
2399 lval
= (unsigned long)val
;
2406 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2408 int write
, void *data
)
2411 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2413 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2419 lval
= (unsigned long)-val
;
2422 lval
= (unsigned long)val
;
2424 *lvalp
= jiffies_to_clock_t(lval
);
2429 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2431 int write
, void *data
)
2434 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2444 lval
= (unsigned long)-val
;
2447 lval
= (unsigned long)val
;
2449 *lvalp
= jiffies_to_msecs(lval
);
2455 * proc_dointvec_jiffies - read a vector of integers as seconds
2456 * @table: the sysctl table
2457 * @write: %TRUE if this is a write to the sysctl file
2458 * @buffer: the user buffer
2459 * @lenp: the size of the user buffer
2460 * @ppos: file position
2462 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2463 * values from/to the user buffer, treated as an ASCII string.
2464 * The values read are assumed to be in seconds, and are converted into
2467 * Returns 0 on success.
2469 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2470 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2472 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2473 do_proc_dointvec_jiffies_conv
,NULL
);
2477 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2478 * @table: the sysctl table
2479 * @write: %TRUE if this is a write to the sysctl file
2480 * @buffer: the user buffer
2481 * @lenp: the size of the user buffer
2482 * @ppos: pointer to the file position
2484 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2485 * values from/to the user buffer, treated as an ASCII string.
2486 * The values read are assumed to be in 1/USER_HZ seconds, and
2487 * are converted into jiffies.
2489 * Returns 0 on success.
2491 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2492 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2494 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2495 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2499 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2500 * @table: the sysctl table
2501 * @write: %TRUE if this is a write to the sysctl file
2502 * @buffer: the user buffer
2503 * @lenp: the size of the user buffer
2504 * @ppos: file position
2505 * @ppos: the current position in the file
2507 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2508 * values from/to the user buffer, treated as an ASCII string.
2509 * The values read are assumed to be in 1/1000 seconds, and
2510 * are converted into jiffies.
2512 * Returns 0 on success.
2514 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2515 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2517 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2518 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2521 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2522 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2524 struct pid
*new_pid
;
2528 tmp
= pid_vnr(cad_pid
);
2530 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2531 lenp
, ppos
, NULL
, NULL
);
2535 new_pid
= find_get_pid(tmp
);
2539 put_pid(xchg(&cad_pid
, new_pid
));
2544 * proc_do_large_bitmap - read/write from/to a large bitmap
2545 * @table: the sysctl table
2546 * @write: %TRUE if this is a write to the sysctl file
2547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2551 * The bitmap is stored at table->data and the bitmap length (in bits)
2554 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2555 * large bitmaps may be represented in a compact manner. Writing into
2556 * the file will clear the bitmap then update it with the given input.
2558 * Returns 0 on success.
2560 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2561 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2565 size_t left
= *lenp
;
2566 unsigned long bitmap_len
= table
->maxlen
;
2567 unsigned long *bitmap
= *(unsigned long **) table
->data
;
2568 unsigned long *tmp_bitmap
= NULL
;
2569 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2571 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2577 unsigned long page
= 0;
2580 if (left
> PAGE_SIZE
- 1)
2581 left
= PAGE_SIZE
- 1;
2583 page
= __get_free_page(GFP_TEMPORARY
);
2584 kbuf
= (char *) page
;
2587 if (copy_from_user(kbuf
, buffer
, left
)) {
2593 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2599 proc_skip_char(&kbuf
, &left
, '\n');
2600 while (!err
&& left
) {
2601 unsigned long val_a
, val_b
;
2604 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2608 if (val_a
>= bitmap_len
|| neg
) {
2620 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2621 &neg
, tr_b
, sizeof(tr_b
),
2625 if (val_b
>= bitmap_len
|| neg
||
2636 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2638 proc_skip_char(&kbuf
, &left
, '\n');
2642 unsigned long bit_a
, bit_b
= 0;
2645 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2646 if (bit_a
>= bitmap_len
)
2648 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2652 err
= proc_put_char(&buffer
, &left
, ',');
2656 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2659 if (bit_a
!= bit_b
) {
2660 err
= proc_put_char(&buffer
, &left
, '-');
2663 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2671 err
= proc_put_char(&buffer
, &left
, '\n');
2677 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2679 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2691 #else /* CONFIG_PROC_SYSCTL */
2693 int proc_dostring(struct ctl_table
*table
, int write
,
2694 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2699 int proc_dointvec(struct ctl_table
*table
, int write
,
2700 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2705 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2706 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2711 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2712 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2717 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2718 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2723 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2724 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2729 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2730 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2735 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2736 void __user
*buffer
,
2737 size_t *lenp
, loff_t
*ppos
)
2743 #endif /* CONFIG_PROC_SYSCTL */
2746 * No sense putting this after each symbol definition, twice,
2747 * exception granted :-)
2749 EXPORT_SYMBOL(proc_dointvec
);
2750 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2751 EXPORT_SYMBOL(proc_dointvec_minmax
);
2752 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2753 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2754 EXPORT_SYMBOL(proc_dostring
);
2755 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2756 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);