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>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
71 #include <asm/stacktrace.h>
75 #include <asm/setup.h>
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
86 #ifdef CONFIG_CHR_DEV_SG
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory
;
99 extern int sysctl_overcommit_ratio
;
100 extern int max_threads
;
101 extern int suid_dumpable
;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid
;
104 extern char core_pattern
[];
105 extern unsigned int core_pipe_limit
;
108 extern int pid_max_min
, pid_max_max
;
109 extern int percpu_pagelist_fraction
;
110 extern int compat_log
;
111 extern int latencytop_enabled
;
112 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
114 extern int sysctl_nr_trim_pages
;
117 extern int blk_iopoll_enabled
;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty
= 60;
123 static int 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 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
148 #ifdef CONFIG_DETECT_HUNG_TASK
149 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
152 #ifdef CONFIG_INOTIFY_USER
153 #include <linux/inotify.h>
158 #ifdef CONFIG_SPARC64
159 extern int sysctl_tsb_ratio
;
163 extern int pwrsw_enabled
;
166 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
167 extern int unaligned_enabled
;
171 extern int unaligned_dump_stack
;
174 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
175 extern int no_unaligned_warning
;
178 #ifdef CONFIG_PROC_SYSCTL
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
= SYSRQ_DEFAULT_ENABLE
;
201 static int sysrq_sysctl_handler(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_reset",
381 .data
= &sysctl_numa_balancing_scan_period_reset
,
382 .maxlen
= sizeof(unsigned int),
384 .proc_handler
= proc_dointvec
,
387 .procname
= "numa_balancing_scan_period_max_ms",
388 .data
= &sysctl_numa_balancing_scan_period_max
,
389 .maxlen
= sizeof(unsigned int),
391 .proc_handler
= proc_dointvec
,
394 .procname
= "numa_balancing_scan_size_mb",
395 .data
= &sysctl_numa_balancing_scan_size
,
396 .maxlen
= sizeof(unsigned int),
398 .proc_handler
= proc_dointvec
,
400 #endif /* CONFIG_NUMA_BALANCING */
401 #endif /* CONFIG_SCHED_DEBUG */
403 .procname
= "sched_rt_period_us",
404 .data
= &sysctl_sched_rt_period
,
405 .maxlen
= sizeof(unsigned int),
407 .proc_handler
= sched_rt_handler
,
410 .procname
= "sched_rt_runtime_us",
411 .data
= &sysctl_sched_rt_runtime
,
412 .maxlen
= sizeof(int),
414 .proc_handler
= sched_rt_handler
,
417 .procname
= "sched_rr_timeslice_ms",
418 .data
= &sched_rr_timeslice
,
419 .maxlen
= sizeof(int),
421 .proc_handler
= sched_rr_handler
,
423 #ifdef CONFIG_SCHED_AUTOGROUP
425 .procname
= "sched_autogroup_enabled",
426 .data
= &sysctl_sched_autogroup_enabled
,
427 .maxlen
= sizeof(unsigned int),
429 .proc_handler
= proc_dointvec_minmax
,
434 #ifdef CONFIG_CFS_BANDWIDTH
436 .procname
= "sched_cfs_bandwidth_slice_us",
437 .data
= &sysctl_sched_cfs_bandwidth_slice
,
438 .maxlen
= sizeof(unsigned int),
440 .proc_handler
= proc_dointvec_minmax
,
444 #ifdef CONFIG_PROVE_LOCKING
446 .procname
= "prove_locking",
447 .data
= &prove_locking
,
448 .maxlen
= sizeof(int),
450 .proc_handler
= proc_dointvec
,
453 #ifdef CONFIG_LOCK_STAT
455 .procname
= "lock_stat",
457 .maxlen
= sizeof(int),
459 .proc_handler
= proc_dointvec
,
464 .data
= &panic_timeout
,
465 .maxlen
= sizeof(int),
467 .proc_handler
= proc_dointvec
,
469 #ifdef CONFIG_COREDUMP
471 .procname
= "core_uses_pid",
472 .data
= &core_uses_pid
,
473 .maxlen
= sizeof(int),
475 .proc_handler
= proc_dointvec
,
478 .procname
= "core_pattern",
479 .data
= core_pattern
,
480 .maxlen
= CORENAME_MAX_SIZE
,
482 .proc_handler
= proc_dostring_coredump
,
485 .procname
= "core_pipe_limit",
486 .data
= &core_pipe_limit
,
487 .maxlen
= sizeof(unsigned int),
489 .proc_handler
= proc_dointvec
,
492 #ifdef CONFIG_PROC_SYSCTL
494 .procname
= "tainted",
495 .maxlen
= sizeof(long),
497 .proc_handler
= proc_taint
,
500 #ifdef CONFIG_LATENCYTOP
502 .procname
= "latencytop",
503 .data
= &latencytop_enabled
,
504 .maxlen
= sizeof(int),
506 .proc_handler
= proc_dointvec
,
509 #ifdef CONFIG_BLK_DEV_INITRD
511 .procname
= "real-root-dev",
512 .data
= &real_root_dev
,
513 .maxlen
= sizeof(int),
515 .proc_handler
= proc_dointvec
,
519 .procname
= "print-fatal-signals",
520 .data
= &print_fatal_signals
,
521 .maxlen
= sizeof(int),
523 .proc_handler
= proc_dointvec
,
527 .procname
= "reboot-cmd",
528 .data
= reboot_command
,
531 .proc_handler
= proc_dostring
,
534 .procname
= "stop-a",
535 .data
= &stop_a_enabled
,
536 .maxlen
= sizeof (int),
538 .proc_handler
= proc_dointvec
,
541 .procname
= "scons-poweroff",
542 .data
= &scons_pwroff
,
543 .maxlen
= sizeof (int),
545 .proc_handler
= proc_dointvec
,
548 #ifdef CONFIG_SPARC64
550 .procname
= "tsb-ratio",
551 .data
= &sysctl_tsb_ratio
,
552 .maxlen
= sizeof (int),
554 .proc_handler
= proc_dointvec
,
559 .procname
= "soft-power",
560 .data
= &pwrsw_enabled
,
561 .maxlen
= sizeof (int),
563 .proc_handler
= proc_dointvec
,
566 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
568 .procname
= "unaligned-trap",
569 .data
= &unaligned_enabled
,
570 .maxlen
= sizeof (int),
572 .proc_handler
= proc_dointvec
,
576 .procname
= "ctrl-alt-del",
578 .maxlen
= sizeof(int),
580 .proc_handler
= proc_dointvec
,
582 #ifdef CONFIG_FUNCTION_TRACER
584 .procname
= "ftrace_enabled",
585 .data
= &ftrace_enabled
,
586 .maxlen
= sizeof(int),
588 .proc_handler
= ftrace_enable_sysctl
,
591 #ifdef CONFIG_STACK_TRACER
593 .procname
= "stack_tracer_enabled",
594 .data
= &stack_tracer_enabled
,
595 .maxlen
= sizeof(int),
597 .proc_handler
= stack_trace_sysctl
,
600 #ifdef CONFIG_TRACING
602 .procname
= "ftrace_dump_on_oops",
603 .data
= &ftrace_dump_on_oops
,
604 .maxlen
= sizeof(int),
606 .proc_handler
= proc_dointvec
,
609 #ifdef CONFIG_MODULES
611 .procname
= "modprobe",
612 .data
= &modprobe_path
,
613 .maxlen
= KMOD_PATH_LEN
,
615 .proc_handler
= proc_dostring
,
618 .procname
= "modules_disabled",
619 .data
= &modules_disabled
,
620 .maxlen
= sizeof(int),
622 /* only handle a transition from default "0" to "1" */
623 .proc_handler
= proc_dointvec_minmax
,
630 .procname
= "hotplug",
631 .data
= &uevent_helper
,
632 .maxlen
= UEVENT_HELPER_PATH_LEN
,
634 .proc_handler
= proc_dostring
,
637 #ifdef CONFIG_CHR_DEV_SG
639 .procname
= "sg-big-buff",
640 .data
= &sg_big_buff
,
641 .maxlen
= sizeof (int),
643 .proc_handler
= proc_dointvec
,
646 #ifdef CONFIG_BSD_PROCESS_ACCT
650 .maxlen
= 3*sizeof(int),
652 .proc_handler
= proc_dointvec
,
655 #ifdef CONFIG_MAGIC_SYSRQ
658 .data
= &__sysrq_enabled
,
659 .maxlen
= sizeof (int),
661 .proc_handler
= sysrq_sysctl_handler
,
664 #ifdef CONFIG_PROC_SYSCTL
666 .procname
= "cad_pid",
668 .maxlen
= sizeof (int),
670 .proc_handler
= proc_do_cad_pid
,
674 .procname
= "threads-max",
675 .data
= &max_threads
,
676 .maxlen
= sizeof(int),
678 .proc_handler
= proc_dointvec
,
681 .procname
= "random",
683 .child
= random_table
,
686 .procname
= "usermodehelper",
688 .child
= usermodehelper_table
,
691 .procname
= "overflowuid",
692 .data
= &overflowuid
,
693 .maxlen
= sizeof(int),
695 .proc_handler
= proc_dointvec_minmax
,
696 .extra1
= &minolduid
,
697 .extra2
= &maxolduid
,
700 .procname
= "overflowgid",
701 .data
= &overflowgid
,
702 .maxlen
= sizeof(int),
704 .proc_handler
= proc_dointvec_minmax
,
705 .extra1
= &minolduid
,
706 .extra2
= &maxolduid
,
709 #ifdef CONFIG_MATHEMU
711 .procname
= "ieee_emulation_warnings",
712 .data
= &sysctl_ieee_emulation_warnings
,
713 .maxlen
= sizeof(int),
715 .proc_handler
= proc_dointvec
,
719 .procname
= "userprocess_debug",
720 .data
= &show_unhandled_signals
,
721 .maxlen
= sizeof(int),
723 .proc_handler
= proc_dointvec
,
727 .procname
= "pid_max",
729 .maxlen
= sizeof (int),
731 .proc_handler
= proc_dointvec_minmax
,
732 .extra1
= &pid_max_min
,
733 .extra2
= &pid_max_max
,
736 .procname
= "panic_on_oops",
737 .data
= &panic_on_oops
,
738 .maxlen
= sizeof(int),
740 .proc_handler
= proc_dointvec
,
742 #if defined CONFIG_PRINTK
744 .procname
= "printk",
745 .data
= &console_loglevel
,
746 .maxlen
= 4*sizeof(int),
748 .proc_handler
= proc_dointvec
,
751 .procname
= "printk_ratelimit",
752 .data
= &printk_ratelimit_state
.interval
,
753 .maxlen
= sizeof(int),
755 .proc_handler
= proc_dointvec_jiffies
,
758 .procname
= "printk_ratelimit_burst",
759 .data
= &printk_ratelimit_state
.burst
,
760 .maxlen
= sizeof(int),
762 .proc_handler
= proc_dointvec
,
765 .procname
= "printk_delay",
766 .data
= &printk_delay_msec
,
767 .maxlen
= sizeof(int),
769 .proc_handler
= proc_dointvec_minmax
,
771 .extra2
= &ten_thousand
,
774 .procname
= "dmesg_restrict",
775 .data
= &dmesg_restrict
,
776 .maxlen
= sizeof(int),
778 .proc_handler
= proc_dointvec_minmax_sysadmin
,
783 .procname
= "kptr_restrict",
784 .data
= &kptr_restrict
,
785 .maxlen
= sizeof(int),
787 .proc_handler
= proc_dointvec_minmax_sysadmin
,
793 .procname
= "ngroups_max",
794 .data
= &ngroups_max
,
795 .maxlen
= sizeof (int),
797 .proc_handler
= proc_dointvec
,
800 .procname
= "cap_last_cap",
801 .data
= (void *)&cap_last_cap
,
802 .maxlen
= sizeof(int),
804 .proc_handler
= proc_dointvec
,
806 #if defined(CONFIG_LOCKUP_DETECTOR)
808 .procname
= "watchdog",
809 .data
= &watchdog_enabled
,
810 .maxlen
= sizeof (int),
812 .proc_handler
= proc_dowatchdog
,
817 .procname
= "watchdog_thresh",
818 .data
= &watchdog_thresh
,
819 .maxlen
= sizeof(int),
821 .proc_handler
= proc_dowatchdog
,
826 .procname
= "softlockup_panic",
827 .data
= &softlockup_panic
,
828 .maxlen
= sizeof(int),
830 .proc_handler
= proc_dointvec_minmax
,
835 .procname
= "nmi_watchdog",
836 .data
= &watchdog_enabled
,
837 .maxlen
= sizeof (int),
839 .proc_handler
= proc_dowatchdog
,
844 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
846 .procname
= "unknown_nmi_panic",
847 .data
= &unknown_nmi_panic
,
848 .maxlen
= sizeof (int),
850 .proc_handler
= proc_dointvec
,
853 #if defined(CONFIG_X86)
855 .procname
= "panic_on_unrecovered_nmi",
856 .data
= &panic_on_unrecovered_nmi
,
857 .maxlen
= sizeof(int),
859 .proc_handler
= proc_dointvec
,
862 .procname
= "panic_on_io_nmi",
863 .data
= &panic_on_io_nmi
,
864 .maxlen
= sizeof(int),
866 .proc_handler
= proc_dointvec
,
868 #ifdef CONFIG_DEBUG_STACKOVERFLOW
870 .procname
= "panic_on_stackoverflow",
871 .data
= &sysctl_panic_on_stackoverflow
,
872 .maxlen
= sizeof(int),
874 .proc_handler
= proc_dointvec
,
878 .procname
= "bootloader_type",
879 .data
= &bootloader_type
,
880 .maxlen
= sizeof (int),
882 .proc_handler
= proc_dointvec
,
885 .procname
= "bootloader_version",
886 .data
= &bootloader_version
,
887 .maxlen
= sizeof (int),
889 .proc_handler
= proc_dointvec
,
892 .procname
= "kstack_depth_to_print",
893 .data
= &kstack_depth_to_print
,
894 .maxlen
= sizeof(int),
896 .proc_handler
= proc_dointvec
,
899 .procname
= "io_delay_type",
900 .data
= &io_delay_type
,
901 .maxlen
= sizeof(int),
903 .proc_handler
= proc_dointvec
,
906 #if defined(CONFIG_MMU)
908 .procname
= "randomize_va_space",
909 .data
= &randomize_va_space
,
910 .maxlen
= sizeof(int),
912 .proc_handler
= proc_dointvec
,
915 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
917 .procname
= "spin_retry",
919 .maxlen
= sizeof (int),
921 .proc_handler
= proc_dointvec
,
924 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
926 .procname
= "acpi_video_flags",
927 .data
= &acpi_realmode_flags
,
928 .maxlen
= sizeof (unsigned long),
930 .proc_handler
= proc_doulongvec_minmax
,
933 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
935 .procname
= "ignore-unaligned-usertrap",
936 .data
= &no_unaligned_warning
,
937 .maxlen
= sizeof (int),
939 .proc_handler
= proc_dointvec
,
944 .procname
= "unaligned-dump-stack",
945 .data
= &unaligned_dump_stack
,
946 .maxlen
= sizeof (int),
948 .proc_handler
= proc_dointvec
,
951 #ifdef CONFIG_DETECT_HUNG_TASK
953 .procname
= "hung_task_panic",
954 .data
= &sysctl_hung_task_panic
,
955 .maxlen
= sizeof(int),
957 .proc_handler
= proc_dointvec_minmax
,
962 .procname
= "hung_task_check_count",
963 .data
= &sysctl_hung_task_check_count
,
964 .maxlen
= sizeof(unsigned long),
966 .proc_handler
= proc_doulongvec_minmax
,
969 .procname
= "hung_task_timeout_secs",
970 .data
= &sysctl_hung_task_timeout_secs
,
971 .maxlen
= sizeof(unsigned long),
973 .proc_handler
= proc_dohung_task_timeout_secs
,
974 .extra2
= &hung_task_timeout_max
,
977 .procname
= "hung_task_warnings",
978 .data
= &sysctl_hung_task_warnings
,
979 .maxlen
= sizeof(unsigned long),
981 .proc_handler
= proc_doulongvec_minmax
,
986 .procname
= "compat-log",
988 .maxlen
= sizeof (int),
990 .proc_handler
= proc_dointvec
,
993 #ifdef CONFIG_RT_MUTEXES
995 .procname
= "max_lock_depth",
996 .data
= &max_lock_depth
,
997 .maxlen
= sizeof(int),
999 .proc_handler
= proc_dointvec
,
1003 .procname
= "poweroff_cmd",
1004 .data
= &poweroff_cmd
,
1005 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1007 .proc_handler
= proc_dostring
,
1013 .child
= key_sysctls
,
1016 #ifdef CONFIG_RCU_TORTURE_TEST
1018 .procname
= "rcutorture_runnable",
1019 .data
= &rcutorture_runnable
,
1020 .maxlen
= sizeof(int),
1022 .proc_handler
= proc_dointvec
,
1025 #ifdef CONFIG_PERF_EVENTS
1027 * User-space scripts rely on the existence of this file
1028 * as a feature check for perf_events being enabled.
1030 * So it's an ABI, do not remove!
1033 .procname
= "perf_event_paranoid",
1034 .data
= &sysctl_perf_event_paranoid
,
1035 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1037 .proc_handler
= proc_dointvec
,
1040 .procname
= "perf_event_mlock_kb",
1041 .data
= &sysctl_perf_event_mlock
,
1042 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1044 .proc_handler
= proc_dointvec
,
1047 .procname
= "perf_event_max_sample_rate",
1048 .data
= &sysctl_perf_event_sample_rate
,
1049 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1051 .proc_handler
= perf_proc_update_handler
,
1054 #ifdef CONFIG_KMEMCHECK
1056 .procname
= "kmemcheck",
1057 .data
= &kmemcheck_enabled
,
1058 .maxlen
= sizeof(int),
1060 .proc_handler
= proc_dointvec
,
1065 .procname
= "blk_iopoll",
1066 .data
= &blk_iopoll_enabled
,
1067 .maxlen
= sizeof(int),
1069 .proc_handler
= proc_dointvec
,
1075 static struct ctl_table vm_table
[] = {
1077 .procname
= "overcommit_memory",
1078 .data
= &sysctl_overcommit_memory
,
1079 .maxlen
= sizeof(sysctl_overcommit_memory
),
1081 .proc_handler
= proc_dointvec_minmax
,
1086 .procname
= "panic_on_oom",
1087 .data
= &sysctl_panic_on_oom
,
1088 .maxlen
= sizeof(sysctl_panic_on_oom
),
1090 .proc_handler
= proc_dointvec_minmax
,
1095 .procname
= "oom_kill_allocating_task",
1096 .data
= &sysctl_oom_kill_allocating_task
,
1097 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1099 .proc_handler
= proc_dointvec
,
1102 .procname
= "oom_dump_tasks",
1103 .data
= &sysctl_oom_dump_tasks
,
1104 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1106 .proc_handler
= proc_dointvec
,
1109 .procname
= "overcommit_ratio",
1110 .data
= &sysctl_overcommit_ratio
,
1111 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1113 .proc_handler
= proc_dointvec
,
1116 .procname
= "page-cluster",
1117 .data
= &page_cluster
,
1118 .maxlen
= sizeof(int),
1120 .proc_handler
= proc_dointvec_minmax
,
1124 .procname
= "dirty_background_ratio",
1125 .data
= &dirty_background_ratio
,
1126 .maxlen
= sizeof(dirty_background_ratio
),
1128 .proc_handler
= dirty_background_ratio_handler
,
1130 .extra2
= &one_hundred
,
1133 .procname
= "dirty_background_bytes",
1134 .data
= &dirty_background_bytes
,
1135 .maxlen
= sizeof(dirty_background_bytes
),
1137 .proc_handler
= dirty_background_bytes_handler
,
1141 .procname
= "dirty_ratio",
1142 .data
= &vm_dirty_ratio
,
1143 .maxlen
= sizeof(vm_dirty_ratio
),
1145 .proc_handler
= dirty_ratio_handler
,
1147 .extra2
= &one_hundred
,
1150 .procname
= "dirty_bytes",
1151 .data
= &vm_dirty_bytes
,
1152 .maxlen
= sizeof(vm_dirty_bytes
),
1154 .proc_handler
= dirty_bytes_handler
,
1155 .extra1
= &dirty_bytes_min
,
1158 .procname
= "dirty_writeback_centisecs",
1159 .data
= &dirty_writeback_interval
,
1160 .maxlen
= sizeof(dirty_writeback_interval
),
1162 .proc_handler
= dirty_writeback_centisecs_handler
,
1165 .procname
= "dirty_expire_centisecs",
1166 .data
= &dirty_expire_interval
,
1167 .maxlen
= sizeof(dirty_expire_interval
),
1169 .proc_handler
= proc_dointvec_minmax
,
1173 .procname
= "nr_pdflush_threads",
1174 .mode
= 0444 /* read-only */,
1175 .proc_handler
= pdflush_proc_obsolete
,
1178 .procname
= "swappiness",
1179 .data
= &vm_swappiness
,
1180 .maxlen
= sizeof(vm_swappiness
),
1182 .proc_handler
= proc_dointvec_minmax
,
1184 .extra2
= &one_hundred
,
1186 #ifdef CONFIG_HUGETLB_PAGE
1188 .procname
= "nr_hugepages",
1190 .maxlen
= sizeof(unsigned long),
1192 .proc_handler
= hugetlb_sysctl_handler
,
1193 .extra1
= (void *)&hugetlb_zero
,
1194 .extra2
= (void *)&hugetlb_infinity
,
1198 .procname
= "nr_hugepages_mempolicy",
1200 .maxlen
= sizeof(unsigned long),
1202 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1203 .extra1
= (void *)&hugetlb_zero
,
1204 .extra2
= (void *)&hugetlb_infinity
,
1208 .procname
= "hugetlb_shm_group",
1209 .data
= &sysctl_hugetlb_shm_group
,
1210 .maxlen
= sizeof(gid_t
),
1212 .proc_handler
= proc_dointvec
,
1215 .procname
= "hugepages_treat_as_movable",
1216 .data
= &hugepages_treat_as_movable
,
1217 .maxlen
= sizeof(int),
1219 .proc_handler
= hugetlb_treat_movable_handler
,
1222 .procname
= "nr_overcommit_hugepages",
1224 .maxlen
= sizeof(unsigned long),
1226 .proc_handler
= hugetlb_overcommit_handler
,
1227 .extra1
= (void *)&hugetlb_zero
,
1228 .extra2
= (void *)&hugetlb_infinity
,
1232 .procname
= "lowmem_reserve_ratio",
1233 .data
= &sysctl_lowmem_reserve_ratio
,
1234 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1236 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1239 .procname
= "drop_caches",
1240 .data
= &sysctl_drop_caches
,
1241 .maxlen
= sizeof(int),
1243 .proc_handler
= drop_caches_sysctl_handler
,
1247 #ifdef CONFIG_COMPACTION
1249 .procname
= "compact_memory",
1250 .data
= &sysctl_compact_memory
,
1251 .maxlen
= sizeof(int),
1253 .proc_handler
= sysctl_compaction_handler
,
1256 .procname
= "extfrag_threshold",
1257 .data
= &sysctl_extfrag_threshold
,
1258 .maxlen
= sizeof(int),
1260 .proc_handler
= sysctl_extfrag_handler
,
1261 .extra1
= &min_extfrag_threshold
,
1262 .extra2
= &max_extfrag_threshold
,
1265 #endif /* CONFIG_COMPACTION */
1267 .procname
= "min_free_kbytes",
1268 .data
= &min_free_kbytes
,
1269 .maxlen
= sizeof(min_free_kbytes
),
1271 .proc_handler
= min_free_kbytes_sysctl_handler
,
1275 .procname
= "percpu_pagelist_fraction",
1276 .data
= &percpu_pagelist_fraction
,
1277 .maxlen
= sizeof(percpu_pagelist_fraction
),
1279 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1280 .extra1
= &min_percpu_pagelist_fract
,
1284 .procname
= "max_map_count",
1285 .data
= &sysctl_max_map_count
,
1286 .maxlen
= sizeof(sysctl_max_map_count
),
1288 .proc_handler
= proc_dointvec_minmax
,
1293 .procname
= "nr_trim_pages",
1294 .data
= &sysctl_nr_trim_pages
,
1295 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1297 .proc_handler
= proc_dointvec_minmax
,
1302 .procname
= "laptop_mode",
1303 .data
= &laptop_mode
,
1304 .maxlen
= sizeof(laptop_mode
),
1306 .proc_handler
= proc_dointvec_jiffies
,
1309 .procname
= "block_dump",
1310 .data
= &block_dump
,
1311 .maxlen
= sizeof(block_dump
),
1313 .proc_handler
= proc_dointvec
,
1317 .procname
= "vfs_cache_pressure",
1318 .data
= &sysctl_vfs_cache_pressure
,
1319 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1321 .proc_handler
= proc_dointvec
,
1324 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1326 .procname
= "legacy_va_layout",
1327 .data
= &sysctl_legacy_va_layout
,
1328 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1330 .proc_handler
= proc_dointvec
,
1336 .procname
= "zone_reclaim_mode",
1337 .data
= &zone_reclaim_mode
,
1338 .maxlen
= sizeof(zone_reclaim_mode
),
1340 .proc_handler
= proc_dointvec
,
1344 .procname
= "min_unmapped_ratio",
1345 .data
= &sysctl_min_unmapped_ratio
,
1346 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1348 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1350 .extra2
= &one_hundred
,
1353 .procname
= "min_slab_ratio",
1354 .data
= &sysctl_min_slab_ratio
,
1355 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1357 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1359 .extra2
= &one_hundred
,
1364 .procname
= "stat_interval",
1365 .data
= &sysctl_stat_interval
,
1366 .maxlen
= sizeof(sysctl_stat_interval
),
1368 .proc_handler
= proc_dointvec_jiffies
,
1373 .procname
= "mmap_min_addr",
1374 .data
= &dac_mmap_min_addr
,
1375 .maxlen
= sizeof(unsigned long),
1377 .proc_handler
= mmap_min_addr_handler
,
1382 .procname
= "numa_zonelist_order",
1383 .data
= &numa_zonelist_order
,
1384 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1386 .proc_handler
= numa_zonelist_order_handler
,
1389 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1390 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1392 .procname
= "vdso_enabled",
1393 .data
= &vdso_enabled
,
1394 .maxlen
= sizeof(vdso_enabled
),
1396 .proc_handler
= proc_dointvec
,
1400 #ifdef CONFIG_HIGHMEM
1402 .procname
= "highmem_is_dirtyable",
1403 .data
= &vm_highmem_is_dirtyable
,
1404 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1406 .proc_handler
= proc_dointvec_minmax
,
1412 .procname
= "scan_unevictable_pages",
1413 .data
= &scan_unevictable_pages
,
1414 .maxlen
= sizeof(scan_unevictable_pages
),
1416 .proc_handler
= scan_unevictable_handler
,
1418 #ifdef CONFIG_MEMORY_FAILURE
1420 .procname
= "memory_failure_early_kill",
1421 .data
= &sysctl_memory_failure_early_kill
,
1422 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1424 .proc_handler
= proc_dointvec_minmax
,
1429 .procname
= "memory_failure_recovery",
1430 .data
= &sysctl_memory_failure_recovery
,
1431 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1433 .proc_handler
= proc_dointvec_minmax
,
1439 .procname
= "user_reserve_kbytes",
1440 .data
= &sysctl_user_reserve_kbytes
,
1441 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1443 .proc_handler
= proc_doulongvec_minmax
,
1446 .procname
= "admin_reserve_kbytes",
1447 .data
= &sysctl_admin_reserve_kbytes
,
1448 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1450 .proc_handler
= proc_doulongvec_minmax
,
1455 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1456 static struct ctl_table binfmt_misc_table
[] = {
1461 static struct ctl_table fs_table
[] = {
1463 .procname
= "inode-nr",
1464 .data
= &inodes_stat
,
1465 .maxlen
= 2*sizeof(int),
1467 .proc_handler
= proc_nr_inodes
,
1470 .procname
= "inode-state",
1471 .data
= &inodes_stat
,
1472 .maxlen
= 7*sizeof(int),
1474 .proc_handler
= proc_nr_inodes
,
1477 .procname
= "file-nr",
1478 .data
= &files_stat
,
1479 .maxlen
= sizeof(files_stat
),
1481 .proc_handler
= proc_nr_files
,
1484 .procname
= "file-max",
1485 .data
= &files_stat
.max_files
,
1486 .maxlen
= sizeof(files_stat
.max_files
),
1488 .proc_handler
= proc_doulongvec_minmax
,
1491 .procname
= "nr_open",
1492 .data
= &sysctl_nr_open
,
1493 .maxlen
= sizeof(int),
1495 .proc_handler
= proc_dointvec_minmax
,
1496 .extra1
= &sysctl_nr_open_min
,
1497 .extra2
= &sysctl_nr_open_max
,
1500 .procname
= "dentry-state",
1501 .data
= &dentry_stat
,
1502 .maxlen
= 6*sizeof(int),
1504 .proc_handler
= proc_nr_dentry
,
1507 .procname
= "overflowuid",
1508 .data
= &fs_overflowuid
,
1509 .maxlen
= sizeof(int),
1511 .proc_handler
= proc_dointvec_minmax
,
1512 .extra1
= &minolduid
,
1513 .extra2
= &maxolduid
,
1516 .procname
= "overflowgid",
1517 .data
= &fs_overflowgid
,
1518 .maxlen
= sizeof(int),
1520 .proc_handler
= proc_dointvec_minmax
,
1521 .extra1
= &minolduid
,
1522 .extra2
= &maxolduid
,
1524 #ifdef CONFIG_FILE_LOCKING
1526 .procname
= "leases-enable",
1527 .data
= &leases_enable
,
1528 .maxlen
= sizeof(int),
1530 .proc_handler
= proc_dointvec
,
1533 #ifdef CONFIG_DNOTIFY
1535 .procname
= "dir-notify-enable",
1536 .data
= &dir_notify_enable
,
1537 .maxlen
= sizeof(int),
1539 .proc_handler
= proc_dointvec
,
1543 #ifdef CONFIG_FILE_LOCKING
1545 .procname
= "lease-break-time",
1546 .data
= &lease_break_time
,
1547 .maxlen
= sizeof(int),
1549 .proc_handler
= proc_dointvec
,
1554 .procname
= "aio-nr",
1556 .maxlen
= sizeof(aio_nr
),
1558 .proc_handler
= proc_doulongvec_minmax
,
1561 .procname
= "aio-max-nr",
1562 .data
= &aio_max_nr
,
1563 .maxlen
= sizeof(aio_max_nr
),
1565 .proc_handler
= proc_doulongvec_minmax
,
1567 #endif /* CONFIG_AIO */
1568 #ifdef CONFIG_INOTIFY_USER
1570 .procname
= "inotify",
1572 .child
= inotify_table
,
1577 .procname
= "epoll",
1579 .child
= epoll_table
,
1584 .procname
= "protected_symlinks",
1585 .data
= &sysctl_protected_symlinks
,
1586 .maxlen
= sizeof(int),
1588 .proc_handler
= proc_dointvec_minmax
,
1593 .procname
= "protected_hardlinks",
1594 .data
= &sysctl_protected_hardlinks
,
1595 .maxlen
= sizeof(int),
1597 .proc_handler
= proc_dointvec_minmax
,
1602 .procname
= "suid_dumpable",
1603 .data
= &suid_dumpable
,
1604 .maxlen
= sizeof(int),
1606 .proc_handler
= proc_dointvec_minmax_coredump
,
1610 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1612 .procname
= "binfmt_misc",
1614 .child
= binfmt_misc_table
,
1618 .procname
= "pipe-max-size",
1619 .data
= &pipe_max_size
,
1620 .maxlen
= sizeof(int),
1622 .proc_handler
= &pipe_proc_fn
,
1623 .extra1
= &pipe_min_size
,
1628 static struct ctl_table debug_table
[] = {
1629 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1631 .procname
= "exception-trace",
1632 .data
= &show_unhandled_signals
,
1633 .maxlen
= sizeof(int),
1635 .proc_handler
= proc_dointvec
1638 #if defined(CONFIG_OPTPROBES)
1640 .procname
= "kprobes-optimization",
1641 .data
= &sysctl_kprobes_optimization
,
1642 .maxlen
= sizeof(int),
1644 .proc_handler
= proc_kprobes_optimization_handler
,
1652 static struct ctl_table dev_table
[] = {
1656 int __init
sysctl_init(void)
1658 struct ctl_table_header
*hdr
;
1660 hdr
= register_sysctl_table(sysctl_base_table
);
1661 kmemleak_not_leak(hdr
);
1665 #endif /* CONFIG_SYSCTL */
1671 #ifdef CONFIG_PROC_SYSCTL
1673 static int _proc_do_string(void* data
, int maxlen
, int write
,
1674 void __user
*buffer
,
1675 size_t *lenp
, loff_t
*ppos
)
1681 if (!data
|| !maxlen
|| !*lenp
) {
1689 while (len
< *lenp
) {
1690 if (get_user(c
, p
++))
1692 if (c
== 0 || c
== '\n')
1698 if(copy_from_user(data
, buffer
, len
))
1700 ((char *) data
)[len
] = 0;
1718 if(copy_to_user(buffer
, data
, len
))
1721 if(put_user('\n', ((char __user
*) buffer
) + len
))
1732 * proc_dostring - read a string sysctl
1733 * @table: the sysctl table
1734 * @write: %TRUE if this is a write to the sysctl file
1735 * @buffer: the user buffer
1736 * @lenp: the size of the user buffer
1737 * @ppos: file position
1739 * Reads/writes a string from/to the user buffer. If the kernel
1740 * buffer provided is not large enough to hold the string, the
1741 * string is truncated. The copied string is %NULL-terminated.
1742 * If the string is being read by the user process, it is copied
1743 * and a newline '\n' is added. It is truncated if the buffer is
1746 * Returns 0 on success.
1748 int proc_dostring(struct ctl_table
*table
, int write
,
1749 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1751 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1752 buffer
, lenp
, ppos
);
1755 static size_t proc_skip_spaces(char **buf
)
1758 char *tmp
= skip_spaces(*buf
);
1764 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1774 #define TMPBUFLEN 22
1776 * proc_get_long - reads an ASCII formatted integer from a user buffer
1778 * @buf: a kernel buffer
1779 * @size: size of the kernel buffer
1780 * @val: this is where the number will be stored
1781 * @neg: set to %TRUE if number is negative
1782 * @perm_tr: a vector which contains the allowed trailers
1783 * @perm_tr_len: size of the perm_tr vector
1784 * @tr: pointer to store the trailer character
1786 * In case of success %0 is returned and @buf and @size are updated with
1787 * the amount of bytes read. If @tr is non-NULL and a trailing
1788 * character exists (size is non-zero after returning from this
1789 * function), @tr is updated with the trailing character.
1791 static int proc_get_long(char **buf
, size_t *size
,
1792 unsigned long *val
, bool *neg
,
1793 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1796 char *p
, tmp
[TMPBUFLEN
];
1802 if (len
> TMPBUFLEN
- 1)
1803 len
= TMPBUFLEN
- 1;
1805 memcpy(tmp
, *buf
, len
);
1809 if (*p
== '-' && *size
> 1) {
1817 *val
= simple_strtoul(p
, &p
, 0);
1821 /* We don't know if the next char is whitespace thus we may accept
1822 * invalid integers (e.g. 1234...a) or two integers instead of one
1823 * (e.g. 123...1). So lets not allow such large numbers. */
1824 if (len
== TMPBUFLEN
- 1)
1827 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1830 if (tr
&& (len
< *size
))
1840 * proc_put_long - converts an integer to a decimal ASCII formatted string
1842 * @buf: the user buffer
1843 * @size: the size of the user buffer
1844 * @val: the integer to be converted
1845 * @neg: sign of the number, %TRUE for negative
1847 * In case of success %0 is returned and @buf and @size are updated with
1848 * the amount of bytes written.
1850 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1854 char tmp
[TMPBUFLEN
], *p
= tmp
;
1856 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1860 if (copy_to_user(*buf
, tmp
, len
))
1868 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1871 char __user
**buffer
= (char __user
**)buf
;
1872 if (put_user(c
, *buffer
))
1874 (*size
)--, (*buffer
)++;
1880 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1882 int write
, void *data
)
1885 *valp
= *negp
? -*lvalp
: *lvalp
;
1890 *lvalp
= (unsigned long)-val
;
1893 *lvalp
= (unsigned long)val
;
1899 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1901 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1902 int write
, void __user
*buffer
,
1903 size_t *lenp
, loff_t
*ppos
,
1904 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1905 int write
, void *data
),
1908 int *i
, vleft
, first
= 1, err
= 0;
1909 unsigned long page
= 0;
1913 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1918 i
= (int *) tbl_data
;
1919 vleft
= table
->maxlen
/ sizeof(*i
);
1923 conv
= do_proc_dointvec_conv
;
1926 if (left
> PAGE_SIZE
- 1)
1927 left
= PAGE_SIZE
- 1;
1928 page
= __get_free_page(GFP_TEMPORARY
);
1929 kbuf
= (char *) page
;
1932 if (copy_from_user(kbuf
, buffer
, left
)) {
1939 for (; left
&& vleft
--; i
++, first
=0) {
1944 left
-= proc_skip_spaces(&kbuf
);
1948 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1950 sizeof(proc_wspace_sep
), NULL
);
1953 if (conv(&neg
, &lval
, i
, 1, data
)) {
1958 if (conv(&neg
, &lval
, i
, 0, data
)) {
1963 err
= proc_put_char(&buffer
, &left
, '\t');
1966 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1972 if (!write
&& !first
&& left
&& !err
)
1973 err
= proc_put_char(&buffer
, &left
, '\n');
1974 if (write
&& !err
&& left
)
1975 left
-= proc_skip_spaces(&kbuf
);
1980 return err
? : -EINVAL
;
1987 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1988 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1989 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1990 int write
, void *data
),
1993 return __do_proc_dointvec(table
->data
, table
, write
,
1994 buffer
, lenp
, ppos
, conv
, data
);
1998 * proc_dointvec - read a vector of integers
1999 * @table: the sysctl table
2000 * @write: %TRUE if this is a write to the sysctl file
2001 * @buffer: the user buffer
2002 * @lenp: the size of the user buffer
2003 * @ppos: file position
2005 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2006 * values from/to the user buffer, treated as an ASCII string.
2008 * Returns 0 on success.
2010 int proc_dointvec(struct ctl_table
*table
, int write
,
2011 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2013 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2018 * Taint values can only be increased
2019 * This means we can safely use a temporary.
2021 static int proc_taint(struct ctl_table
*table
, int write
,
2022 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2025 unsigned long tmptaint
= get_taint();
2028 if (write
&& !capable(CAP_SYS_ADMIN
))
2033 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2039 * Poor man's atomic or. Not worth adding a primitive
2040 * to everyone's atomic.h for this
2043 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2044 if ((tmptaint
>> i
) & 1)
2045 add_taint(i
, LOCKDEP_STILL_OK
);
2052 #ifdef CONFIG_PRINTK
2053 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2054 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2056 if (write
&& !capable(CAP_SYS_ADMIN
))
2059 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2063 struct do_proc_dointvec_minmax_conv_param
{
2068 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2070 int write
, void *data
)
2072 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2074 int val
= *negp
? -*lvalp
: *lvalp
;
2075 if ((param
->min
&& *param
->min
> val
) ||
2076 (param
->max
&& *param
->max
< val
))
2083 *lvalp
= (unsigned long)-val
;
2086 *lvalp
= (unsigned long)val
;
2093 * proc_dointvec_minmax - read a vector of integers with min/max values
2094 * @table: the sysctl table
2095 * @write: %TRUE if this is a write to the sysctl file
2096 * @buffer: the user buffer
2097 * @lenp: the size of the user buffer
2098 * @ppos: file position
2100 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2101 * values from/to the user buffer, treated as an ASCII string.
2103 * This routine will ensure the values are within the range specified by
2104 * table->extra1 (min) and table->extra2 (max).
2106 * Returns 0 on success.
2108 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2109 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2111 struct do_proc_dointvec_minmax_conv_param param
= {
2112 .min
= (int *) table
->extra1
,
2113 .max
= (int *) table
->extra2
,
2115 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2116 do_proc_dointvec_minmax_conv
, ¶m
);
2119 static void validate_coredump_safety(void)
2121 #ifdef CONFIG_COREDUMP
2122 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2123 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2124 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2125 "suid_dumpable=2. Pipe handler or fully qualified "\
2126 "core dump path required.\n");
2131 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2132 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2134 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2136 validate_coredump_safety();
2140 #ifdef CONFIG_COREDUMP
2141 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2142 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2144 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2146 validate_coredump_safety();
2151 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2152 void __user
*buffer
,
2153 size_t *lenp
, loff_t
*ppos
,
2154 unsigned long convmul
,
2155 unsigned long convdiv
)
2157 unsigned long *i
, *min
, *max
;
2158 int vleft
, first
= 1, err
= 0;
2159 unsigned long page
= 0;
2163 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2168 i
= (unsigned long *) data
;
2169 min
= (unsigned long *) table
->extra1
;
2170 max
= (unsigned long *) table
->extra2
;
2171 vleft
= table
->maxlen
/ sizeof(unsigned long);
2175 if (left
> PAGE_SIZE
- 1)
2176 left
= PAGE_SIZE
- 1;
2177 page
= __get_free_page(GFP_TEMPORARY
);
2178 kbuf
= (char *) page
;
2181 if (copy_from_user(kbuf
, buffer
, left
)) {
2188 for (; left
&& vleft
--; i
++, first
= 0) {
2194 left
-= proc_skip_spaces(&kbuf
);
2196 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2198 sizeof(proc_wspace_sep
), NULL
);
2203 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2207 val
= convdiv
* (*i
) / convmul
;
2209 err
= proc_put_char(&buffer
, &left
, '\t');
2210 err
= proc_put_long(&buffer
, &left
, val
, false);
2216 if (!write
&& !first
&& left
&& !err
)
2217 err
= proc_put_char(&buffer
, &left
, '\n');
2219 left
-= proc_skip_spaces(&kbuf
);
2224 return err
? : -EINVAL
;
2231 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2232 void __user
*buffer
,
2233 size_t *lenp
, loff_t
*ppos
,
2234 unsigned long convmul
,
2235 unsigned long convdiv
)
2237 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2238 buffer
, lenp
, ppos
, convmul
, convdiv
);
2242 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2243 * @table: the sysctl table
2244 * @write: %TRUE if this is a write to the sysctl file
2245 * @buffer: the user buffer
2246 * @lenp: the size of the user buffer
2247 * @ppos: file position
2249 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2250 * values from/to the user buffer, treated as an ASCII string.
2252 * This routine will ensure the values are within the range specified by
2253 * table->extra1 (min) and table->extra2 (max).
2255 * Returns 0 on success.
2257 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2258 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2260 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2264 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2265 * @table: the sysctl table
2266 * @write: %TRUE if this is a write to the sysctl file
2267 * @buffer: the user buffer
2268 * @lenp: the size of the user buffer
2269 * @ppos: file position
2271 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2272 * values from/to the user buffer, treated as an ASCII string. The values
2273 * are treated as milliseconds, and converted to jiffies when they are stored.
2275 * This routine will ensure the values are within the range specified by
2276 * table->extra1 (min) and table->extra2 (max).
2278 * Returns 0 on success.
2280 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2281 void __user
*buffer
,
2282 size_t *lenp
, loff_t
*ppos
)
2284 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2285 lenp
, ppos
, HZ
, 1000l);
2289 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2291 int write
, void *data
)
2294 if (*lvalp
> LONG_MAX
/ HZ
)
2296 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2302 lval
= (unsigned long)-val
;
2305 lval
= (unsigned long)val
;
2312 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2314 int write
, void *data
)
2317 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2319 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2325 lval
= (unsigned long)-val
;
2328 lval
= (unsigned long)val
;
2330 *lvalp
= jiffies_to_clock_t(lval
);
2335 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2337 int write
, void *data
)
2340 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2346 lval
= (unsigned long)-val
;
2349 lval
= (unsigned long)val
;
2351 *lvalp
= jiffies_to_msecs(lval
);
2357 * proc_dointvec_jiffies - read a vector of integers as seconds
2358 * @table: the sysctl table
2359 * @write: %TRUE if this is a write to the sysctl file
2360 * @buffer: the user buffer
2361 * @lenp: the size of the user buffer
2362 * @ppos: file position
2364 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2365 * values from/to the user buffer, treated as an ASCII string.
2366 * The values read are assumed to be in seconds, and are converted into
2369 * Returns 0 on success.
2371 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2372 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2374 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2375 do_proc_dointvec_jiffies_conv
,NULL
);
2379 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2380 * @table: the sysctl table
2381 * @write: %TRUE if this is a write to the sysctl file
2382 * @buffer: the user buffer
2383 * @lenp: the size of the user buffer
2384 * @ppos: pointer to the file position
2386 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2387 * values from/to the user buffer, treated as an ASCII string.
2388 * The values read are assumed to be in 1/USER_HZ seconds, and
2389 * are converted into jiffies.
2391 * Returns 0 on success.
2393 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2394 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2396 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2397 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2401 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2402 * @table: the sysctl table
2403 * @write: %TRUE if this is a write to the sysctl file
2404 * @buffer: the user buffer
2405 * @lenp: the size of the user buffer
2406 * @ppos: file position
2407 * @ppos: the current position in the file
2409 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2410 * values from/to the user buffer, treated as an ASCII string.
2411 * The values read are assumed to be in 1/1000 seconds, and
2412 * are converted into jiffies.
2414 * Returns 0 on success.
2416 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2417 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2419 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2420 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2423 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2424 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2426 struct pid
*new_pid
;
2430 tmp
= pid_vnr(cad_pid
);
2432 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2433 lenp
, ppos
, NULL
, NULL
);
2437 new_pid
= find_get_pid(tmp
);
2441 put_pid(xchg(&cad_pid
, new_pid
));
2446 * proc_do_large_bitmap - read/write from/to a large bitmap
2447 * @table: the sysctl table
2448 * @write: %TRUE if this is a write to the sysctl file
2449 * @buffer: the user buffer
2450 * @lenp: the size of the user buffer
2451 * @ppos: file position
2453 * The bitmap is stored at table->data and the bitmap length (in bits)
2456 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2457 * large bitmaps may be represented in a compact manner. Writing into
2458 * the file will clear the bitmap then update it with the given input.
2460 * Returns 0 on success.
2462 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2463 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2467 size_t left
= *lenp
;
2468 unsigned long bitmap_len
= table
->maxlen
;
2469 unsigned long *bitmap
= (unsigned long *) table
->data
;
2470 unsigned long *tmp_bitmap
= NULL
;
2471 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2473 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2479 unsigned long page
= 0;
2482 if (left
> PAGE_SIZE
- 1)
2483 left
= PAGE_SIZE
- 1;
2485 page
= __get_free_page(GFP_TEMPORARY
);
2486 kbuf
= (char *) page
;
2489 if (copy_from_user(kbuf
, buffer
, left
)) {
2495 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2501 proc_skip_char(&kbuf
, &left
, '\n');
2502 while (!err
&& left
) {
2503 unsigned long val_a
, val_b
;
2506 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2510 if (val_a
>= bitmap_len
|| neg
) {
2522 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2523 &neg
, tr_b
, sizeof(tr_b
),
2527 if (val_b
>= bitmap_len
|| neg
||
2538 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2540 proc_skip_char(&kbuf
, &left
, '\n');
2544 unsigned long bit_a
, bit_b
= 0;
2547 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2548 if (bit_a
>= bitmap_len
)
2550 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2554 err
= proc_put_char(&buffer
, &left
, ',');
2558 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2561 if (bit_a
!= bit_b
) {
2562 err
= proc_put_char(&buffer
, &left
, '-');
2565 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2573 err
= proc_put_char(&buffer
, &left
, '\n');
2579 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2581 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2593 #else /* CONFIG_PROC_SYSCTL */
2595 int proc_dostring(struct ctl_table
*table
, int write
,
2596 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2601 int proc_dointvec(struct ctl_table
*table
, int write
,
2602 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2607 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2608 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2613 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2614 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2619 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2620 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2625 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2626 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2631 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2632 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2637 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2638 void __user
*buffer
,
2639 size_t *lenp
, loff_t
*ppos
)
2645 #endif /* CONFIG_PROC_SYSCTL */
2648 * No sense putting this after each symbol definition, twice,
2649 * exception granted :-)
2651 EXPORT_SYMBOL(proc_dointvec
);
2652 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2653 EXPORT_SYMBOL(proc_dointvec_minmax
);
2654 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2655 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2656 EXPORT_SYMBOL(proc_dostring
);
2657 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2658 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);