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 extern int blk_iopoll_enabled
;
119 /* Constants used for minimum and maximum */
120 #ifdef CONFIG_LOCKUP_DETECTOR
121 static int sixty
= 60;
124 static int __maybe_unused neg_one
= -1;
127 static int __maybe_unused one
= 1;
128 static int __maybe_unused two
= 2;
129 static int __maybe_unused three
= 3;
130 static unsigned long one_ul
= 1;
131 static int one_hundred
= 100;
133 static int ten_thousand
= 10000;
136 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
137 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
139 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
140 static int maxolduid
= 65535;
141 static int minolduid
;
142 static int min_percpu_pagelist_fract
= 8;
144 static int ngroups_max
= NGROUPS_MAX
;
145 static const int cap_last_cap
= CAP_LAST_CAP
;
147 #ifdef CONFIG_INOTIFY_USER
148 #include <linux/inotify.h>
153 #ifdef CONFIG_SPARC64
154 extern int sysctl_tsb_ratio
;
158 extern int pwrsw_enabled
;
161 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
162 extern int unaligned_enabled
;
166 extern int unaligned_dump_stack
;
169 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
170 extern int no_unaligned_warning
;
173 #ifdef CONFIG_PROC_SYSCTL
174 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
175 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
176 static int proc_taint(struct ctl_table
*table
, int write
,
177 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
181 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
182 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
185 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
186 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
187 #ifdef CONFIG_COREDUMP
188 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
189 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
192 #ifdef CONFIG_MAGIC_SYSRQ
193 /* Note: sysrq code uses it's own private copy */
194 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
196 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
197 void __user
*buffer
, size_t *lenp
,
202 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
207 sysrq_toggle_support(__sysrq_enabled
);
214 static struct ctl_table kern_table
[];
215 static struct ctl_table vm_table
[];
216 static struct ctl_table fs_table
[];
217 static struct ctl_table debug_table
[];
218 static struct ctl_table dev_table
[];
219 extern struct ctl_table random_table
[];
221 extern struct ctl_table epoll_table
[];
224 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
225 int sysctl_legacy_va_layout
;
228 /* The default sysctl tables: */
230 static struct ctl_table sysctl_base_table
[] = {
232 .procname
= "kernel",
249 .child
= debug_table
,
259 #ifdef CONFIG_SCHED_DEBUG
260 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
261 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
262 static int min_wakeup_granularity_ns
; /* 0 usecs */
263 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
265 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
266 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
267 #endif /* CONFIG_SMP */
268 #endif /* CONFIG_SCHED_DEBUG */
270 #ifdef CONFIG_COMPACTION
271 static int min_extfrag_threshold
;
272 static int max_extfrag_threshold
= 1000;
275 static struct ctl_table kern_table
[] = {
277 .procname
= "sched_child_runs_first",
278 .data
= &sysctl_sched_child_runs_first
,
279 .maxlen
= sizeof(unsigned int),
281 .proc_handler
= proc_dointvec
,
283 #ifdef CONFIG_SCHED_DEBUG
285 .procname
= "sched_min_granularity_ns",
286 .data
= &sysctl_sched_min_granularity
,
287 .maxlen
= sizeof(unsigned int),
289 .proc_handler
= sched_proc_update_handler
,
290 .extra1
= &min_sched_granularity_ns
,
291 .extra2
= &max_sched_granularity_ns
,
294 .procname
= "sched_latency_ns",
295 .data
= &sysctl_sched_latency
,
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_wakeup_granularity_ns",
304 .data
= &sysctl_sched_wakeup_granularity
,
305 .maxlen
= sizeof(unsigned int),
307 .proc_handler
= sched_proc_update_handler
,
308 .extra1
= &min_wakeup_granularity_ns
,
309 .extra2
= &max_wakeup_granularity_ns
,
313 .procname
= "sched_tunable_scaling",
314 .data
= &sysctl_sched_tunable_scaling
,
315 .maxlen
= sizeof(enum sched_tunable_scaling
),
317 .proc_handler
= sched_proc_update_handler
,
318 .extra1
= &min_sched_tunable_scaling
,
319 .extra2
= &max_sched_tunable_scaling
,
322 .procname
= "sched_migration_cost_ns",
323 .data
= &sysctl_sched_migration_cost
,
324 .maxlen
= sizeof(unsigned int),
326 .proc_handler
= proc_dointvec
,
329 .procname
= "sched_nr_migrate",
330 .data
= &sysctl_sched_nr_migrate
,
331 .maxlen
= sizeof(unsigned int),
333 .proc_handler
= proc_dointvec
,
336 .procname
= "sched_time_avg_ms",
337 .data
= &sysctl_sched_time_avg
,
338 .maxlen
= sizeof(unsigned int),
340 .proc_handler
= proc_dointvec
,
343 .procname
= "sched_shares_window_ns",
344 .data
= &sysctl_sched_shares_window
,
345 .maxlen
= sizeof(unsigned int),
347 .proc_handler
= proc_dointvec
,
350 .procname
= "timer_migration",
351 .data
= &sysctl_timer_migration
,
352 .maxlen
= sizeof(unsigned int),
354 .proc_handler
= proc_dointvec_minmax
,
358 #endif /* CONFIG_SMP */
359 #ifdef CONFIG_NUMA_BALANCING
361 .procname
= "numa_balancing_scan_delay_ms",
362 .data
= &sysctl_numa_balancing_scan_delay
,
363 .maxlen
= sizeof(unsigned int),
365 .proc_handler
= proc_dointvec
,
368 .procname
= "numa_balancing_scan_period_min_ms",
369 .data
= &sysctl_numa_balancing_scan_period_min
,
370 .maxlen
= sizeof(unsigned int),
372 .proc_handler
= proc_dointvec
,
375 .procname
= "numa_balancing_scan_period_max_ms",
376 .data
= &sysctl_numa_balancing_scan_period_max
,
377 .maxlen
= sizeof(unsigned int),
379 .proc_handler
= proc_dointvec
,
382 .procname
= "numa_balancing_scan_size_mb",
383 .data
= &sysctl_numa_balancing_scan_size
,
384 .maxlen
= sizeof(unsigned int),
386 .proc_handler
= proc_dointvec
,
389 .procname
= "numa_balancing_migrate_deferred",
390 .data
= &sysctl_numa_balancing_migrate_deferred
,
391 .maxlen
= sizeof(unsigned int),
393 .proc_handler
= proc_dointvec
,
396 .procname
= "numa_balancing",
397 .data
= NULL
, /* filled in by handler */
398 .maxlen
= sizeof(unsigned int),
400 .proc_handler
= sysctl_numa_balancing
,
404 #endif /* CONFIG_NUMA_BALANCING */
405 #endif /* CONFIG_SCHED_DEBUG */
407 .procname
= "sched_rt_period_us",
408 .data
= &sysctl_sched_rt_period
,
409 .maxlen
= sizeof(unsigned int),
411 .proc_handler
= sched_rt_handler
,
414 .procname
= "sched_rt_runtime_us",
415 .data
= &sysctl_sched_rt_runtime
,
416 .maxlen
= sizeof(int),
418 .proc_handler
= sched_rt_handler
,
421 .procname
= "sched_rr_timeslice_ms",
422 .data
= &sched_rr_timeslice
,
423 .maxlen
= sizeof(int),
425 .proc_handler
= sched_rr_handler
,
427 #ifdef CONFIG_SCHED_AUTOGROUP
429 .procname
= "sched_autogroup_enabled",
430 .data
= &sysctl_sched_autogroup_enabled
,
431 .maxlen
= sizeof(unsigned int),
433 .proc_handler
= proc_dointvec_minmax
,
438 #ifdef CONFIG_CFS_BANDWIDTH
440 .procname
= "sched_cfs_bandwidth_slice_us",
441 .data
= &sysctl_sched_cfs_bandwidth_slice
,
442 .maxlen
= sizeof(unsigned int),
444 .proc_handler
= proc_dointvec_minmax
,
448 #ifdef CONFIG_PROVE_LOCKING
450 .procname
= "prove_locking",
451 .data
= &prove_locking
,
452 .maxlen
= sizeof(int),
454 .proc_handler
= proc_dointvec
,
457 #ifdef CONFIG_LOCK_STAT
459 .procname
= "lock_stat",
461 .maxlen
= sizeof(int),
463 .proc_handler
= proc_dointvec
,
468 .data
= &panic_timeout
,
469 .maxlen
= sizeof(int),
471 .proc_handler
= proc_dointvec
,
473 #ifdef CONFIG_COREDUMP
475 .procname
= "core_uses_pid",
476 .data
= &core_uses_pid
,
477 .maxlen
= sizeof(int),
479 .proc_handler
= proc_dointvec
,
482 .procname
= "core_pattern",
483 .data
= core_pattern
,
484 .maxlen
= CORENAME_MAX_SIZE
,
486 .proc_handler
= proc_dostring_coredump
,
489 .procname
= "core_pipe_limit",
490 .data
= &core_pipe_limit
,
491 .maxlen
= sizeof(unsigned int),
493 .proc_handler
= proc_dointvec
,
496 #ifdef CONFIG_PROC_SYSCTL
498 .procname
= "tainted",
499 .maxlen
= sizeof(long),
501 .proc_handler
= proc_taint
,
504 #ifdef CONFIG_LATENCYTOP
506 .procname
= "latencytop",
507 .data
= &latencytop_enabled
,
508 .maxlen
= sizeof(int),
510 .proc_handler
= proc_dointvec
,
513 #ifdef CONFIG_BLK_DEV_INITRD
515 .procname
= "real-root-dev",
516 .data
= &real_root_dev
,
517 .maxlen
= sizeof(int),
519 .proc_handler
= proc_dointvec
,
523 .procname
= "print-fatal-signals",
524 .data
= &print_fatal_signals
,
525 .maxlen
= sizeof(int),
527 .proc_handler
= proc_dointvec
,
531 .procname
= "reboot-cmd",
532 .data
= reboot_command
,
535 .proc_handler
= proc_dostring
,
538 .procname
= "stop-a",
539 .data
= &stop_a_enabled
,
540 .maxlen
= sizeof (int),
542 .proc_handler
= proc_dointvec
,
545 .procname
= "scons-poweroff",
546 .data
= &scons_pwroff
,
547 .maxlen
= sizeof (int),
549 .proc_handler
= proc_dointvec
,
552 #ifdef CONFIG_SPARC64
554 .procname
= "tsb-ratio",
555 .data
= &sysctl_tsb_ratio
,
556 .maxlen
= sizeof (int),
558 .proc_handler
= proc_dointvec
,
563 .procname
= "soft-power",
564 .data
= &pwrsw_enabled
,
565 .maxlen
= sizeof (int),
567 .proc_handler
= proc_dointvec
,
570 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
572 .procname
= "unaligned-trap",
573 .data
= &unaligned_enabled
,
574 .maxlen
= sizeof (int),
576 .proc_handler
= proc_dointvec
,
580 .procname
= "ctrl-alt-del",
582 .maxlen
= sizeof(int),
584 .proc_handler
= proc_dointvec
,
586 #ifdef CONFIG_FUNCTION_TRACER
588 .procname
= "ftrace_enabled",
589 .data
= &ftrace_enabled
,
590 .maxlen
= sizeof(int),
592 .proc_handler
= ftrace_enable_sysctl
,
595 #ifdef CONFIG_STACK_TRACER
597 .procname
= "stack_tracer_enabled",
598 .data
= &stack_tracer_enabled
,
599 .maxlen
= sizeof(int),
601 .proc_handler
= stack_trace_sysctl
,
604 #ifdef CONFIG_TRACING
606 .procname
= "ftrace_dump_on_oops",
607 .data
= &ftrace_dump_on_oops
,
608 .maxlen
= sizeof(int),
610 .proc_handler
= proc_dointvec
,
613 .procname
= "traceoff_on_warning",
614 .data
= &__disable_trace_on_warning
,
615 .maxlen
= sizeof(__disable_trace_on_warning
),
617 .proc_handler
= proc_dointvec
,
622 .procname
= "kexec_load_disabled",
623 .data
= &kexec_load_disabled
,
624 .maxlen
= sizeof(int),
626 /* only handle a transition from default "0" to "1" */
627 .proc_handler
= proc_dointvec_minmax
,
632 #ifdef CONFIG_MODULES
634 .procname
= "modprobe",
635 .data
= &modprobe_path
,
636 .maxlen
= KMOD_PATH_LEN
,
638 .proc_handler
= proc_dostring
,
641 .procname
= "modules_disabled",
642 .data
= &modules_disabled
,
643 .maxlen
= sizeof(int),
645 /* only handle a transition from default "0" to "1" */
646 .proc_handler
= proc_dointvec_minmax
,
653 .procname
= "hotplug",
654 .data
= &uevent_helper
,
655 .maxlen
= UEVENT_HELPER_PATH_LEN
,
657 .proc_handler
= proc_dostring
,
660 #ifdef CONFIG_CHR_DEV_SG
662 .procname
= "sg-big-buff",
663 .data
= &sg_big_buff
,
664 .maxlen
= sizeof (int),
666 .proc_handler
= proc_dointvec
,
669 #ifdef CONFIG_BSD_PROCESS_ACCT
673 .maxlen
= 3*sizeof(int),
675 .proc_handler
= proc_dointvec
,
678 #ifdef CONFIG_MAGIC_SYSRQ
681 .data
= &__sysrq_enabled
,
682 .maxlen
= sizeof (int),
684 .proc_handler
= sysrq_sysctl_handler
,
687 #ifdef CONFIG_PROC_SYSCTL
689 .procname
= "cad_pid",
691 .maxlen
= sizeof (int),
693 .proc_handler
= proc_do_cad_pid
,
697 .procname
= "threads-max",
698 .data
= &max_threads
,
699 .maxlen
= sizeof(int),
701 .proc_handler
= proc_dointvec
,
704 .procname
= "random",
706 .child
= random_table
,
709 .procname
= "usermodehelper",
711 .child
= usermodehelper_table
,
714 .procname
= "overflowuid",
715 .data
= &overflowuid
,
716 .maxlen
= sizeof(int),
718 .proc_handler
= proc_dointvec_minmax
,
719 .extra1
= &minolduid
,
720 .extra2
= &maxolduid
,
723 .procname
= "overflowgid",
724 .data
= &overflowgid
,
725 .maxlen
= sizeof(int),
727 .proc_handler
= proc_dointvec_minmax
,
728 .extra1
= &minolduid
,
729 .extra2
= &maxolduid
,
732 #ifdef CONFIG_MATHEMU
734 .procname
= "ieee_emulation_warnings",
735 .data
= &sysctl_ieee_emulation_warnings
,
736 .maxlen
= sizeof(int),
738 .proc_handler
= proc_dointvec
,
742 .procname
= "userprocess_debug",
743 .data
= &show_unhandled_signals
,
744 .maxlen
= sizeof(int),
746 .proc_handler
= proc_dointvec
,
750 .procname
= "pid_max",
752 .maxlen
= sizeof (int),
754 .proc_handler
= proc_dointvec_minmax
,
755 .extra1
= &pid_max_min
,
756 .extra2
= &pid_max_max
,
759 .procname
= "panic_on_oops",
760 .data
= &panic_on_oops
,
761 .maxlen
= sizeof(int),
763 .proc_handler
= proc_dointvec
,
765 #if defined CONFIG_PRINTK
767 .procname
= "printk",
768 .data
= &console_loglevel
,
769 .maxlen
= 4*sizeof(int),
771 .proc_handler
= proc_dointvec
,
774 .procname
= "printk_ratelimit",
775 .data
= &printk_ratelimit_state
.interval
,
776 .maxlen
= sizeof(int),
778 .proc_handler
= proc_dointvec_jiffies
,
781 .procname
= "printk_ratelimit_burst",
782 .data
= &printk_ratelimit_state
.burst
,
783 .maxlen
= sizeof(int),
785 .proc_handler
= proc_dointvec
,
788 .procname
= "printk_delay",
789 .data
= &printk_delay_msec
,
790 .maxlen
= sizeof(int),
792 .proc_handler
= proc_dointvec_minmax
,
794 .extra2
= &ten_thousand
,
797 .procname
= "dmesg_restrict",
798 .data
= &dmesg_restrict
,
799 .maxlen
= sizeof(int),
801 .proc_handler
= proc_dointvec_minmax_sysadmin
,
806 .procname
= "kptr_restrict",
807 .data
= &kptr_restrict
,
808 .maxlen
= sizeof(int),
810 .proc_handler
= proc_dointvec_minmax_sysadmin
,
816 .procname
= "ngroups_max",
817 .data
= &ngroups_max
,
818 .maxlen
= sizeof (int),
820 .proc_handler
= proc_dointvec
,
823 .procname
= "cap_last_cap",
824 .data
= (void *)&cap_last_cap
,
825 .maxlen
= sizeof(int),
827 .proc_handler
= proc_dointvec
,
829 #if defined(CONFIG_LOCKUP_DETECTOR)
831 .procname
= "watchdog",
832 .data
= &watchdog_user_enabled
,
833 .maxlen
= sizeof (int),
835 .proc_handler
= proc_dowatchdog
,
840 .procname
= "watchdog_thresh",
841 .data
= &watchdog_thresh
,
842 .maxlen
= sizeof(int),
844 .proc_handler
= proc_dowatchdog
,
849 .procname
= "softlockup_panic",
850 .data
= &softlockup_panic
,
851 .maxlen
= sizeof(int),
853 .proc_handler
= proc_dointvec_minmax
,
858 .procname
= "nmi_watchdog",
859 .data
= &watchdog_user_enabled
,
860 .maxlen
= sizeof (int),
862 .proc_handler
= proc_dowatchdog
,
867 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
869 .procname
= "unknown_nmi_panic",
870 .data
= &unknown_nmi_panic
,
871 .maxlen
= sizeof (int),
873 .proc_handler
= proc_dointvec
,
876 #if defined(CONFIG_X86)
878 .procname
= "panic_on_unrecovered_nmi",
879 .data
= &panic_on_unrecovered_nmi
,
880 .maxlen
= sizeof(int),
882 .proc_handler
= proc_dointvec
,
885 .procname
= "panic_on_io_nmi",
886 .data
= &panic_on_io_nmi
,
887 .maxlen
= sizeof(int),
889 .proc_handler
= proc_dointvec
,
891 #ifdef CONFIG_DEBUG_STACKOVERFLOW
893 .procname
= "panic_on_stackoverflow",
894 .data
= &sysctl_panic_on_stackoverflow
,
895 .maxlen
= sizeof(int),
897 .proc_handler
= proc_dointvec
,
901 .procname
= "bootloader_type",
902 .data
= &bootloader_type
,
903 .maxlen
= sizeof (int),
905 .proc_handler
= proc_dointvec
,
908 .procname
= "bootloader_version",
909 .data
= &bootloader_version
,
910 .maxlen
= sizeof (int),
912 .proc_handler
= proc_dointvec
,
915 .procname
= "kstack_depth_to_print",
916 .data
= &kstack_depth_to_print
,
917 .maxlen
= sizeof(int),
919 .proc_handler
= proc_dointvec
,
922 .procname
= "io_delay_type",
923 .data
= &io_delay_type
,
924 .maxlen
= sizeof(int),
926 .proc_handler
= proc_dointvec
,
929 #if defined(CONFIG_MMU)
931 .procname
= "randomize_va_space",
932 .data
= &randomize_va_space
,
933 .maxlen
= sizeof(int),
935 .proc_handler
= proc_dointvec
,
938 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
940 .procname
= "spin_retry",
942 .maxlen
= sizeof (int),
944 .proc_handler
= proc_dointvec
,
947 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
949 .procname
= "acpi_video_flags",
950 .data
= &acpi_realmode_flags
,
951 .maxlen
= sizeof (unsigned long),
953 .proc_handler
= proc_doulongvec_minmax
,
956 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
958 .procname
= "ignore-unaligned-usertrap",
959 .data
= &no_unaligned_warning
,
960 .maxlen
= sizeof (int),
962 .proc_handler
= proc_dointvec
,
967 .procname
= "unaligned-dump-stack",
968 .data
= &unaligned_dump_stack
,
969 .maxlen
= sizeof (int),
971 .proc_handler
= proc_dointvec
,
974 #ifdef CONFIG_DETECT_HUNG_TASK
976 .procname
= "hung_task_panic",
977 .data
= &sysctl_hung_task_panic
,
978 .maxlen
= sizeof(int),
980 .proc_handler
= proc_dointvec_minmax
,
985 .procname
= "hung_task_check_count",
986 .data
= &sysctl_hung_task_check_count
,
987 .maxlen
= sizeof(int),
989 .proc_handler
= proc_dointvec_minmax
,
993 .procname
= "hung_task_timeout_secs",
994 .data
= &sysctl_hung_task_timeout_secs
,
995 .maxlen
= sizeof(unsigned long),
997 .proc_handler
= proc_dohung_task_timeout_secs
,
1000 .procname
= "hung_task_warnings",
1001 .data
= &sysctl_hung_task_warnings
,
1002 .maxlen
= sizeof(int),
1004 .proc_handler
= proc_dointvec_minmax
,
1008 #ifdef CONFIG_COMPAT
1010 .procname
= "compat-log",
1011 .data
= &compat_log
,
1012 .maxlen
= sizeof (int),
1014 .proc_handler
= proc_dointvec
,
1017 #ifdef CONFIG_RT_MUTEXES
1019 .procname
= "max_lock_depth",
1020 .data
= &max_lock_depth
,
1021 .maxlen
= sizeof(int),
1023 .proc_handler
= proc_dointvec
,
1027 .procname
= "poweroff_cmd",
1028 .data
= &poweroff_cmd
,
1029 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1031 .proc_handler
= proc_dostring
,
1037 .child
= key_sysctls
,
1040 #ifdef CONFIG_RCU_TORTURE_TEST
1042 .procname
= "rcutorture_runnable",
1043 .data
= &rcutorture_runnable
,
1044 .maxlen
= sizeof(int),
1046 .proc_handler
= proc_dointvec
,
1049 #ifdef CONFIG_PERF_EVENTS
1051 * User-space scripts rely on the existence of this file
1052 * as a feature check for perf_events being enabled.
1054 * So it's an ABI, do not remove!
1057 .procname
= "perf_event_paranoid",
1058 .data
= &sysctl_perf_event_paranoid
,
1059 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1061 .proc_handler
= proc_dointvec
,
1064 .procname
= "perf_event_mlock_kb",
1065 .data
= &sysctl_perf_event_mlock
,
1066 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1068 .proc_handler
= proc_dointvec
,
1071 .procname
= "perf_event_max_sample_rate",
1072 .data
= &sysctl_perf_event_sample_rate
,
1073 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1075 .proc_handler
= perf_proc_update_handler
,
1079 .procname
= "perf_cpu_time_max_percent",
1080 .data
= &sysctl_perf_cpu_time_max_percent
,
1081 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1083 .proc_handler
= perf_cpu_time_max_percent_handler
,
1085 .extra2
= &one_hundred
,
1088 #ifdef CONFIG_KMEMCHECK
1090 .procname
= "kmemcheck",
1091 .data
= &kmemcheck_enabled
,
1092 .maxlen
= sizeof(int),
1094 .proc_handler
= proc_dointvec
,
1099 .procname
= "blk_iopoll",
1100 .data
= &blk_iopoll_enabled
,
1101 .maxlen
= sizeof(int),
1103 .proc_handler
= proc_dointvec
,
1109 static struct ctl_table vm_table
[] = {
1111 .procname
= "overcommit_memory",
1112 .data
= &sysctl_overcommit_memory
,
1113 .maxlen
= sizeof(sysctl_overcommit_memory
),
1115 .proc_handler
= proc_dointvec_minmax
,
1120 .procname
= "panic_on_oom",
1121 .data
= &sysctl_panic_on_oom
,
1122 .maxlen
= sizeof(sysctl_panic_on_oom
),
1124 .proc_handler
= proc_dointvec_minmax
,
1129 .procname
= "oom_kill_allocating_task",
1130 .data
= &sysctl_oom_kill_allocating_task
,
1131 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1133 .proc_handler
= proc_dointvec
,
1136 .procname
= "oom_dump_tasks",
1137 .data
= &sysctl_oom_dump_tasks
,
1138 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1140 .proc_handler
= proc_dointvec
,
1143 .procname
= "overcommit_ratio",
1144 .data
= &sysctl_overcommit_ratio
,
1145 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1147 .proc_handler
= overcommit_ratio_handler
,
1150 .procname
= "overcommit_kbytes",
1151 .data
= &sysctl_overcommit_kbytes
,
1152 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1154 .proc_handler
= overcommit_kbytes_handler
,
1157 .procname
= "page-cluster",
1158 .data
= &page_cluster
,
1159 .maxlen
= sizeof(int),
1161 .proc_handler
= proc_dointvec_minmax
,
1165 .procname
= "dirty_background_ratio",
1166 .data
= &dirty_background_ratio
,
1167 .maxlen
= sizeof(dirty_background_ratio
),
1169 .proc_handler
= dirty_background_ratio_handler
,
1171 .extra2
= &one_hundred
,
1174 .procname
= "dirty_background_bytes",
1175 .data
= &dirty_background_bytes
,
1176 .maxlen
= sizeof(dirty_background_bytes
),
1178 .proc_handler
= dirty_background_bytes_handler
,
1182 .procname
= "dirty_ratio",
1183 .data
= &vm_dirty_ratio
,
1184 .maxlen
= sizeof(vm_dirty_ratio
),
1186 .proc_handler
= dirty_ratio_handler
,
1188 .extra2
= &one_hundred
,
1191 .procname
= "dirty_bytes",
1192 .data
= &vm_dirty_bytes
,
1193 .maxlen
= sizeof(vm_dirty_bytes
),
1195 .proc_handler
= dirty_bytes_handler
,
1196 .extra1
= &dirty_bytes_min
,
1199 .procname
= "dirty_writeback_centisecs",
1200 .data
= &dirty_writeback_interval
,
1201 .maxlen
= sizeof(dirty_writeback_interval
),
1203 .proc_handler
= dirty_writeback_centisecs_handler
,
1206 .procname
= "dirty_expire_centisecs",
1207 .data
= &dirty_expire_interval
,
1208 .maxlen
= sizeof(dirty_expire_interval
),
1210 .proc_handler
= proc_dointvec_minmax
,
1214 .procname
= "nr_pdflush_threads",
1215 .mode
= 0444 /* read-only */,
1216 .proc_handler
= pdflush_proc_obsolete
,
1219 .procname
= "swappiness",
1220 .data
= &vm_swappiness
,
1221 .maxlen
= sizeof(vm_swappiness
),
1223 .proc_handler
= proc_dointvec_minmax
,
1225 .extra2
= &one_hundred
,
1227 #ifdef CONFIG_HUGETLB_PAGE
1229 .procname
= "nr_hugepages",
1231 .maxlen
= sizeof(unsigned long),
1233 .proc_handler
= hugetlb_sysctl_handler
,
1234 .extra1
= (void *)&hugetlb_zero
,
1235 .extra2
= (void *)&hugetlb_infinity
,
1239 .procname
= "nr_hugepages_mempolicy",
1241 .maxlen
= sizeof(unsigned long),
1243 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1244 .extra1
= (void *)&hugetlb_zero
,
1245 .extra2
= (void *)&hugetlb_infinity
,
1249 .procname
= "hugetlb_shm_group",
1250 .data
= &sysctl_hugetlb_shm_group
,
1251 .maxlen
= sizeof(gid_t
),
1253 .proc_handler
= proc_dointvec
,
1256 .procname
= "hugepages_treat_as_movable",
1257 .data
= &hugepages_treat_as_movable
,
1258 .maxlen
= sizeof(int),
1260 .proc_handler
= proc_dointvec
,
1263 .procname
= "nr_overcommit_hugepages",
1265 .maxlen
= sizeof(unsigned long),
1267 .proc_handler
= hugetlb_overcommit_handler
,
1268 .extra1
= (void *)&hugetlb_zero
,
1269 .extra2
= (void *)&hugetlb_infinity
,
1273 .procname
= "lowmem_reserve_ratio",
1274 .data
= &sysctl_lowmem_reserve_ratio
,
1275 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1277 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1280 .procname
= "drop_caches",
1281 .data
= &sysctl_drop_caches
,
1282 .maxlen
= sizeof(int),
1284 .proc_handler
= drop_caches_sysctl_handler
,
1288 #ifdef CONFIG_COMPACTION
1290 .procname
= "compact_memory",
1291 .data
= &sysctl_compact_memory
,
1292 .maxlen
= sizeof(int),
1294 .proc_handler
= sysctl_compaction_handler
,
1297 .procname
= "extfrag_threshold",
1298 .data
= &sysctl_extfrag_threshold
,
1299 .maxlen
= sizeof(int),
1301 .proc_handler
= sysctl_extfrag_handler
,
1302 .extra1
= &min_extfrag_threshold
,
1303 .extra2
= &max_extfrag_threshold
,
1306 #endif /* CONFIG_COMPACTION */
1308 .procname
= "min_free_kbytes",
1309 .data
= &min_free_kbytes
,
1310 .maxlen
= sizeof(min_free_kbytes
),
1312 .proc_handler
= min_free_kbytes_sysctl_handler
,
1316 .procname
= "percpu_pagelist_fraction",
1317 .data
= &percpu_pagelist_fraction
,
1318 .maxlen
= sizeof(percpu_pagelist_fraction
),
1320 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1321 .extra1
= &min_percpu_pagelist_fract
,
1325 .procname
= "max_map_count",
1326 .data
= &sysctl_max_map_count
,
1327 .maxlen
= sizeof(sysctl_max_map_count
),
1329 .proc_handler
= proc_dointvec_minmax
,
1334 .procname
= "nr_trim_pages",
1335 .data
= &sysctl_nr_trim_pages
,
1336 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1338 .proc_handler
= proc_dointvec_minmax
,
1343 .procname
= "laptop_mode",
1344 .data
= &laptop_mode
,
1345 .maxlen
= sizeof(laptop_mode
),
1347 .proc_handler
= proc_dointvec_jiffies
,
1350 .procname
= "block_dump",
1351 .data
= &block_dump
,
1352 .maxlen
= sizeof(block_dump
),
1354 .proc_handler
= proc_dointvec
,
1358 .procname
= "vfs_cache_pressure",
1359 .data
= &sysctl_vfs_cache_pressure
,
1360 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1362 .proc_handler
= proc_dointvec
,
1365 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1367 .procname
= "legacy_va_layout",
1368 .data
= &sysctl_legacy_va_layout
,
1369 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1371 .proc_handler
= proc_dointvec
,
1377 .procname
= "zone_reclaim_mode",
1378 .data
= &zone_reclaim_mode
,
1379 .maxlen
= sizeof(zone_reclaim_mode
),
1381 .proc_handler
= proc_dointvec
,
1385 .procname
= "min_unmapped_ratio",
1386 .data
= &sysctl_min_unmapped_ratio
,
1387 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1389 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1391 .extra2
= &one_hundred
,
1394 .procname
= "min_slab_ratio",
1395 .data
= &sysctl_min_slab_ratio
,
1396 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1398 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1400 .extra2
= &one_hundred
,
1405 .procname
= "stat_interval",
1406 .data
= &sysctl_stat_interval
,
1407 .maxlen
= sizeof(sysctl_stat_interval
),
1409 .proc_handler
= proc_dointvec_jiffies
,
1414 .procname
= "mmap_min_addr",
1415 .data
= &dac_mmap_min_addr
,
1416 .maxlen
= sizeof(unsigned long),
1418 .proc_handler
= mmap_min_addr_handler
,
1423 .procname
= "numa_zonelist_order",
1424 .data
= &numa_zonelist_order
,
1425 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1427 .proc_handler
= numa_zonelist_order_handler
,
1430 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1431 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1433 .procname
= "vdso_enabled",
1434 .data
= &vdso_enabled
,
1435 .maxlen
= sizeof(vdso_enabled
),
1437 .proc_handler
= proc_dointvec
,
1441 #ifdef CONFIG_HIGHMEM
1443 .procname
= "highmem_is_dirtyable",
1444 .data
= &vm_highmem_is_dirtyable
,
1445 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1447 .proc_handler
= proc_dointvec_minmax
,
1453 .procname
= "scan_unevictable_pages",
1454 .data
= &scan_unevictable_pages
,
1455 .maxlen
= sizeof(scan_unevictable_pages
),
1457 .proc_handler
= scan_unevictable_handler
,
1459 #ifdef CONFIG_MEMORY_FAILURE
1461 .procname
= "memory_failure_early_kill",
1462 .data
= &sysctl_memory_failure_early_kill
,
1463 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1465 .proc_handler
= proc_dointvec_minmax
,
1470 .procname
= "memory_failure_recovery",
1471 .data
= &sysctl_memory_failure_recovery
,
1472 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1474 .proc_handler
= proc_dointvec_minmax
,
1480 .procname
= "user_reserve_kbytes",
1481 .data
= &sysctl_user_reserve_kbytes
,
1482 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1484 .proc_handler
= proc_doulongvec_minmax
,
1487 .procname
= "admin_reserve_kbytes",
1488 .data
= &sysctl_admin_reserve_kbytes
,
1489 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1491 .proc_handler
= proc_doulongvec_minmax
,
1496 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1497 static struct ctl_table binfmt_misc_table
[] = {
1502 static struct ctl_table fs_table
[] = {
1504 .procname
= "inode-nr",
1505 .data
= &inodes_stat
,
1506 .maxlen
= 2*sizeof(long),
1508 .proc_handler
= proc_nr_inodes
,
1511 .procname
= "inode-state",
1512 .data
= &inodes_stat
,
1513 .maxlen
= 7*sizeof(long),
1515 .proc_handler
= proc_nr_inodes
,
1518 .procname
= "file-nr",
1519 .data
= &files_stat
,
1520 .maxlen
= sizeof(files_stat
),
1522 .proc_handler
= proc_nr_files
,
1525 .procname
= "file-max",
1526 .data
= &files_stat
.max_files
,
1527 .maxlen
= sizeof(files_stat
.max_files
),
1529 .proc_handler
= proc_doulongvec_minmax
,
1532 .procname
= "nr_open",
1533 .data
= &sysctl_nr_open
,
1534 .maxlen
= sizeof(int),
1536 .proc_handler
= proc_dointvec_minmax
,
1537 .extra1
= &sysctl_nr_open_min
,
1538 .extra2
= &sysctl_nr_open_max
,
1541 .procname
= "dentry-state",
1542 .data
= &dentry_stat
,
1543 .maxlen
= 6*sizeof(long),
1545 .proc_handler
= proc_nr_dentry
,
1548 .procname
= "overflowuid",
1549 .data
= &fs_overflowuid
,
1550 .maxlen
= sizeof(int),
1552 .proc_handler
= proc_dointvec_minmax
,
1553 .extra1
= &minolduid
,
1554 .extra2
= &maxolduid
,
1557 .procname
= "overflowgid",
1558 .data
= &fs_overflowgid
,
1559 .maxlen
= sizeof(int),
1561 .proc_handler
= proc_dointvec_minmax
,
1562 .extra1
= &minolduid
,
1563 .extra2
= &maxolduid
,
1565 #ifdef CONFIG_FILE_LOCKING
1567 .procname
= "leases-enable",
1568 .data
= &leases_enable
,
1569 .maxlen
= sizeof(int),
1571 .proc_handler
= proc_dointvec
,
1574 #ifdef CONFIG_DNOTIFY
1576 .procname
= "dir-notify-enable",
1577 .data
= &dir_notify_enable
,
1578 .maxlen
= sizeof(int),
1580 .proc_handler
= proc_dointvec
,
1584 #ifdef CONFIG_FILE_LOCKING
1586 .procname
= "lease-break-time",
1587 .data
= &lease_break_time
,
1588 .maxlen
= sizeof(int),
1590 .proc_handler
= proc_dointvec
,
1595 .procname
= "aio-nr",
1597 .maxlen
= sizeof(aio_nr
),
1599 .proc_handler
= proc_doulongvec_minmax
,
1602 .procname
= "aio-max-nr",
1603 .data
= &aio_max_nr
,
1604 .maxlen
= sizeof(aio_max_nr
),
1606 .proc_handler
= proc_doulongvec_minmax
,
1608 #endif /* CONFIG_AIO */
1609 #ifdef CONFIG_INOTIFY_USER
1611 .procname
= "inotify",
1613 .child
= inotify_table
,
1618 .procname
= "epoll",
1620 .child
= epoll_table
,
1625 .procname
= "protected_symlinks",
1626 .data
= &sysctl_protected_symlinks
,
1627 .maxlen
= sizeof(int),
1629 .proc_handler
= proc_dointvec_minmax
,
1634 .procname
= "protected_hardlinks",
1635 .data
= &sysctl_protected_hardlinks
,
1636 .maxlen
= sizeof(int),
1638 .proc_handler
= proc_dointvec_minmax
,
1643 .procname
= "suid_dumpable",
1644 .data
= &suid_dumpable
,
1645 .maxlen
= sizeof(int),
1647 .proc_handler
= proc_dointvec_minmax_coredump
,
1651 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1653 .procname
= "binfmt_misc",
1655 .child
= binfmt_misc_table
,
1659 .procname
= "pipe-max-size",
1660 .data
= &pipe_max_size
,
1661 .maxlen
= sizeof(int),
1663 .proc_handler
= &pipe_proc_fn
,
1664 .extra1
= &pipe_min_size
,
1669 static struct ctl_table debug_table
[] = {
1670 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1672 .procname
= "exception-trace",
1673 .data
= &show_unhandled_signals
,
1674 .maxlen
= sizeof(int),
1676 .proc_handler
= proc_dointvec
1679 #if defined(CONFIG_OPTPROBES)
1681 .procname
= "kprobes-optimization",
1682 .data
= &sysctl_kprobes_optimization
,
1683 .maxlen
= sizeof(int),
1685 .proc_handler
= proc_kprobes_optimization_handler
,
1693 static struct ctl_table dev_table
[] = {
1697 int __init
sysctl_init(void)
1699 struct ctl_table_header
*hdr
;
1701 hdr
= register_sysctl_table(sysctl_base_table
);
1702 kmemleak_not_leak(hdr
);
1706 #endif /* CONFIG_SYSCTL */
1712 #ifdef CONFIG_PROC_SYSCTL
1714 static int _proc_do_string(void* data
, int maxlen
, int write
,
1715 void __user
*buffer
,
1716 size_t *lenp
, loff_t
*ppos
)
1722 if (!data
|| !maxlen
|| !*lenp
) {
1730 while (len
< *lenp
) {
1731 if (get_user(c
, p
++))
1733 if (c
== 0 || c
== '\n')
1739 if(copy_from_user(data
, buffer
, len
))
1741 ((char *) data
)[len
] = 0;
1759 if(copy_to_user(buffer
, data
, len
))
1762 if(put_user('\n', ((char __user
*) buffer
) + len
))
1773 * proc_dostring - read a string sysctl
1774 * @table: the sysctl table
1775 * @write: %TRUE if this is a write to the sysctl file
1776 * @buffer: the user buffer
1777 * @lenp: the size of the user buffer
1778 * @ppos: file position
1780 * Reads/writes a string from/to the user buffer. If the kernel
1781 * buffer provided is not large enough to hold the string, the
1782 * string is truncated. The copied string is %NULL-terminated.
1783 * If the string is being read by the user process, it is copied
1784 * and a newline '\n' is added. It is truncated if the buffer is
1787 * Returns 0 on success.
1789 int proc_dostring(struct ctl_table
*table
, int write
,
1790 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1792 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1793 buffer
, lenp
, ppos
);
1796 static size_t proc_skip_spaces(char **buf
)
1799 char *tmp
= skip_spaces(*buf
);
1805 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1815 #define TMPBUFLEN 22
1817 * proc_get_long - reads an ASCII formatted integer from a user buffer
1819 * @buf: a kernel buffer
1820 * @size: size of the kernel buffer
1821 * @val: this is where the number will be stored
1822 * @neg: set to %TRUE if number is negative
1823 * @perm_tr: a vector which contains the allowed trailers
1824 * @perm_tr_len: size of the perm_tr vector
1825 * @tr: pointer to store the trailer character
1827 * In case of success %0 is returned and @buf and @size are updated with
1828 * the amount of bytes read. If @tr is non-NULL and a trailing
1829 * character exists (size is non-zero after returning from this
1830 * function), @tr is updated with the trailing character.
1832 static int proc_get_long(char **buf
, size_t *size
,
1833 unsigned long *val
, bool *neg
,
1834 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1837 char *p
, tmp
[TMPBUFLEN
];
1843 if (len
> TMPBUFLEN
- 1)
1844 len
= TMPBUFLEN
- 1;
1846 memcpy(tmp
, *buf
, len
);
1850 if (*p
== '-' && *size
> 1) {
1858 *val
= simple_strtoul(p
, &p
, 0);
1862 /* We don't know if the next char is whitespace thus we may accept
1863 * invalid integers (e.g. 1234...a) or two integers instead of one
1864 * (e.g. 123...1). So lets not allow such large numbers. */
1865 if (len
== TMPBUFLEN
- 1)
1868 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1871 if (tr
&& (len
< *size
))
1881 * proc_put_long - converts an integer to a decimal ASCII formatted string
1883 * @buf: the user buffer
1884 * @size: the size of the user buffer
1885 * @val: the integer to be converted
1886 * @neg: sign of the number, %TRUE for negative
1888 * In case of success %0 is returned and @buf and @size are updated with
1889 * the amount of bytes written.
1891 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1895 char tmp
[TMPBUFLEN
], *p
= tmp
;
1897 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1901 if (copy_to_user(*buf
, tmp
, len
))
1909 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1912 char __user
**buffer
= (char __user
**)buf
;
1913 if (put_user(c
, *buffer
))
1915 (*size
)--, (*buffer
)++;
1921 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1923 int write
, void *data
)
1926 *valp
= *negp
? -*lvalp
: *lvalp
;
1931 *lvalp
= (unsigned long)-val
;
1934 *lvalp
= (unsigned long)val
;
1940 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1942 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1943 int write
, void __user
*buffer
,
1944 size_t *lenp
, loff_t
*ppos
,
1945 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1946 int write
, void *data
),
1949 int *i
, vleft
, first
= 1, err
= 0;
1950 unsigned long page
= 0;
1954 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1959 i
= (int *) tbl_data
;
1960 vleft
= table
->maxlen
/ sizeof(*i
);
1964 conv
= do_proc_dointvec_conv
;
1967 if (left
> PAGE_SIZE
- 1)
1968 left
= PAGE_SIZE
- 1;
1969 page
= __get_free_page(GFP_TEMPORARY
);
1970 kbuf
= (char *) page
;
1973 if (copy_from_user(kbuf
, buffer
, left
)) {
1980 for (; left
&& vleft
--; i
++, first
=0) {
1985 left
-= proc_skip_spaces(&kbuf
);
1989 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1991 sizeof(proc_wspace_sep
), NULL
);
1994 if (conv(&neg
, &lval
, i
, 1, data
)) {
1999 if (conv(&neg
, &lval
, i
, 0, data
)) {
2004 err
= proc_put_char(&buffer
, &left
, '\t');
2007 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2013 if (!write
&& !first
&& left
&& !err
)
2014 err
= proc_put_char(&buffer
, &left
, '\n');
2015 if (write
&& !err
&& left
)
2016 left
-= proc_skip_spaces(&kbuf
);
2021 return err
? : -EINVAL
;
2028 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2029 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2030 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2031 int write
, void *data
),
2034 return __do_proc_dointvec(table
->data
, table
, write
,
2035 buffer
, lenp
, ppos
, conv
, data
);
2039 * proc_dointvec - read a vector of integers
2040 * @table: the sysctl table
2041 * @write: %TRUE if this is a write to the sysctl file
2042 * @buffer: the user buffer
2043 * @lenp: the size of the user buffer
2044 * @ppos: file position
2046 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2047 * values from/to the user buffer, treated as an ASCII string.
2049 * Returns 0 on success.
2051 int proc_dointvec(struct ctl_table
*table
, int write
,
2052 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2054 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2059 * Taint values can only be increased
2060 * This means we can safely use a temporary.
2062 static int proc_taint(struct ctl_table
*table
, int write
,
2063 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2066 unsigned long tmptaint
= get_taint();
2069 if (write
&& !capable(CAP_SYS_ADMIN
))
2074 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2080 * Poor man's atomic or. Not worth adding a primitive
2081 * to everyone's atomic.h for this
2084 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2085 if ((tmptaint
>> i
) & 1)
2086 add_taint(i
, LOCKDEP_STILL_OK
);
2093 #ifdef CONFIG_PRINTK
2094 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2095 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2097 if (write
&& !capable(CAP_SYS_ADMIN
))
2100 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2104 struct do_proc_dointvec_minmax_conv_param
{
2109 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2111 int write
, void *data
)
2113 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2115 int val
= *negp
? -*lvalp
: *lvalp
;
2116 if ((param
->min
&& *param
->min
> val
) ||
2117 (param
->max
&& *param
->max
< val
))
2124 *lvalp
= (unsigned long)-val
;
2127 *lvalp
= (unsigned long)val
;
2134 * proc_dointvec_minmax - read a vector of integers with min/max values
2135 * @table: the sysctl table
2136 * @write: %TRUE if this is a write to the sysctl file
2137 * @buffer: the user buffer
2138 * @lenp: the size of the user buffer
2139 * @ppos: file position
2141 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2142 * values from/to the user buffer, treated as an ASCII string.
2144 * This routine will ensure the values are within the range specified by
2145 * table->extra1 (min) and table->extra2 (max).
2147 * Returns 0 on success.
2149 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2150 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2152 struct do_proc_dointvec_minmax_conv_param param
= {
2153 .min
= (int *) table
->extra1
,
2154 .max
= (int *) table
->extra2
,
2156 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2157 do_proc_dointvec_minmax_conv
, ¶m
);
2160 static void validate_coredump_safety(void)
2162 #ifdef CONFIG_COREDUMP
2163 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2164 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2165 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2166 "suid_dumpable=2. Pipe handler or fully qualified "\
2167 "core dump path required.\n");
2172 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2173 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2175 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2177 validate_coredump_safety();
2181 #ifdef CONFIG_COREDUMP
2182 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2183 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2185 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2187 validate_coredump_safety();
2192 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2193 void __user
*buffer
,
2194 size_t *lenp
, loff_t
*ppos
,
2195 unsigned long convmul
,
2196 unsigned long convdiv
)
2198 unsigned long *i
, *min
, *max
;
2199 int vleft
, first
= 1, err
= 0;
2200 unsigned long page
= 0;
2204 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2209 i
= (unsigned long *) data
;
2210 min
= (unsigned long *) table
->extra1
;
2211 max
= (unsigned long *) table
->extra2
;
2212 vleft
= table
->maxlen
/ sizeof(unsigned long);
2216 if (left
> PAGE_SIZE
- 1)
2217 left
= PAGE_SIZE
- 1;
2218 page
= __get_free_page(GFP_TEMPORARY
);
2219 kbuf
= (char *) page
;
2222 if (copy_from_user(kbuf
, buffer
, left
)) {
2229 for (; left
&& vleft
--; i
++, first
= 0) {
2235 left
-= proc_skip_spaces(&kbuf
);
2237 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2239 sizeof(proc_wspace_sep
), NULL
);
2244 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2248 val
= convdiv
* (*i
) / convmul
;
2250 err
= proc_put_char(&buffer
, &left
, '\t');
2254 err
= proc_put_long(&buffer
, &left
, val
, false);
2260 if (!write
&& !first
&& left
&& !err
)
2261 err
= proc_put_char(&buffer
, &left
, '\n');
2263 left
-= proc_skip_spaces(&kbuf
);
2268 return err
? : -EINVAL
;
2275 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2276 void __user
*buffer
,
2277 size_t *lenp
, loff_t
*ppos
,
2278 unsigned long convmul
,
2279 unsigned long convdiv
)
2281 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2282 buffer
, lenp
, ppos
, convmul
, convdiv
);
2286 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2287 * @table: the sysctl table
2288 * @write: %TRUE if this is a write to the sysctl file
2289 * @buffer: the user buffer
2290 * @lenp: the size of the user buffer
2291 * @ppos: file position
2293 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2294 * values from/to the user buffer, treated as an ASCII string.
2296 * This routine will ensure the values are within the range specified by
2297 * table->extra1 (min) and table->extra2 (max).
2299 * Returns 0 on success.
2301 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2302 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2304 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2308 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2309 * @table: the sysctl table
2310 * @write: %TRUE if this is a write to the sysctl file
2311 * @buffer: the user buffer
2312 * @lenp: the size of the user buffer
2313 * @ppos: file position
2315 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2316 * values from/to the user buffer, treated as an ASCII string. The values
2317 * are treated as milliseconds, and converted to jiffies when they are stored.
2319 * This routine will ensure the values are within the range specified by
2320 * table->extra1 (min) and table->extra2 (max).
2322 * Returns 0 on success.
2324 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2325 void __user
*buffer
,
2326 size_t *lenp
, loff_t
*ppos
)
2328 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2329 lenp
, ppos
, HZ
, 1000l);
2333 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2335 int write
, void *data
)
2338 if (*lvalp
> LONG_MAX
/ HZ
)
2340 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2346 lval
= (unsigned long)-val
;
2349 lval
= (unsigned long)val
;
2356 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2358 int write
, void *data
)
2361 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2363 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2369 lval
= (unsigned long)-val
;
2372 lval
= (unsigned long)val
;
2374 *lvalp
= jiffies_to_clock_t(lval
);
2379 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2381 int write
, void *data
)
2384 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2394 lval
= (unsigned long)-val
;
2397 lval
= (unsigned long)val
;
2399 *lvalp
= jiffies_to_msecs(lval
);
2405 * proc_dointvec_jiffies - read a vector of integers as seconds
2406 * @table: the sysctl table
2407 * @write: %TRUE if this is a write to the sysctl file
2408 * @buffer: the user buffer
2409 * @lenp: the size of the user buffer
2410 * @ppos: file position
2412 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2413 * values from/to the user buffer, treated as an ASCII string.
2414 * The values read are assumed to be in seconds, and are converted into
2417 * Returns 0 on success.
2419 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2420 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2422 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2423 do_proc_dointvec_jiffies_conv
,NULL
);
2427 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2428 * @table: the sysctl table
2429 * @write: %TRUE if this is a write to the sysctl file
2430 * @buffer: the user buffer
2431 * @lenp: the size of the user buffer
2432 * @ppos: pointer to the file position
2434 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2435 * values from/to the user buffer, treated as an ASCII string.
2436 * The values read are assumed to be in 1/USER_HZ seconds, and
2437 * are converted into jiffies.
2439 * Returns 0 on success.
2441 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2442 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2444 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2445 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2449 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2450 * @table: the sysctl table
2451 * @write: %TRUE if this is a write to the sysctl file
2452 * @buffer: the user buffer
2453 * @lenp: the size of the user buffer
2454 * @ppos: file position
2455 * @ppos: the current position in the file
2457 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2458 * values from/to the user buffer, treated as an ASCII string.
2459 * The values read are assumed to be in 1/1000 seconds, and
2460 * are converted into jiffies.
2462 * Returns 0 on success.
2464 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2465 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2467 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2468 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2471 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2472 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2474 struct pid
*new_pid
;
2478 tmp
= pid_vnr(cad_pid
);
2480 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2481 lenp
, ppos
, NULL
, NULL
);
2485 new_pid
= find_get_pid(tmp
);
2489 put_pid(xchg(&cad_pid
, new_pid
));
2494 * proc_do_large_bitmap - read/write from/to a large bitmap
2495 * @table: the sysctl table
2496 * @write: %TRUE if this is a write to the sysctl file
2497 * @buffer: the user buffer
2498 * @lenp: the size of the user buffer
2499 * @ppos: file position
2501 * The bitmap is stored at table->data and the bitmap length (in bits)
2504 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2505 * large bitmaps may be represented in a compact manner. Writing into
2506 * the file will clear the bitmap then update it with the given input.
2508 * Returns 0 on success.
2510 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2511 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2515 size_t left
= *lenp
;
2516 unsigned long bitmap_len
= table
->maxlen
;
2517 unsigned long *bitmap
= (unsigned long *) table
->data
;
2518 unsigned long *tmp_bitmap
= NULL
;
2519 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2521 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2527 unsigned long page
= 0;
2530 if (left
> PAGE_SIZE
- 1)
2531 left
= PAGE_SIZE
- 1;
2533 page
= __get_free_page(GFP_TEMPORARY
);
2534 kbuf
= (char *) page
;
2537 if (copy_from_user(kbuf
, buffer
, left
)) {
2543 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2549 proc_skip_char(&kbuf
, &left
, '\n');
2550 while (!err
&& left
) {
2551 unsigned long val_a
, val_b
;
2554 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2558 if (val_a
>= bitmap_len
|| neg
) {
2570 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2571 &neg
, tr_b
, sizeof(tr_b
),
2575 if (val_b
>= bitmap_len
|| neg
||
2586 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2588 proc_skip_char(&kbuf
, &left
, '\n');
2592 unsigned long bit_a
, bit_b
= 0;
2595 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2596 if (bit_a
>= bitmap_len
)
2598 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2602 err
= proc_put_char(&buffer
, &left
, ',');
2606 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2609 if (bit_a
!= bit_b
) {
2610 err
= proc_put_char(&buffer
, &left
, '-');
2613 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2621 err
= proc_put_char(&buffer
, &left
, '\n');
2627 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2629 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2641 #else /* CONFIG_PROC_SYSCTL */
2643 int proc_dostring(struct ctl_table
*table
, int write
,
2644 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2649 int proc_dointvec(struct ctl_table
*table
, int write
,
2650 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2655 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2656 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2661 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2662 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2667 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2668 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2673 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2674 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2679 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2680 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2685 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2686 void __user
*buffer
,
2687 size_t *lenp
, loff_t
*ppos
)
2693 #endif /* CONFIG_PROC_SYSCTL */
2696 * No sense putting this after each symbol definition, twice,
2697 * exception granted :-)
2699 EXPORT_SYMBOL(proc_dointvec
);
2700 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2701 EXPORT_SYMBOL(proc_dointvec_minmax
);
2702 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2703 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2704 EXPORT_SYMBOL(proc_dostring
);
2705 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2706 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);