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. */
99 extern int deny_new_usb
;
101 extern int sysctl_overcommit_memory
;
102 extern int sysctl_overcommit_ratio
;
103 extern int max_threads
;
104 extern int suid_dumpable
;
105 #ifdef CONFIG_COREDUMP
106 extern int core_uses_pid
;
107 extern char core_pattern
[];
108 extern unsigned int core_pipe_limit
;
111 extern int extra_free_kbytes
;
112 extern int min_free_order_shift
;
113 extern int pid_max_min
, pid_max_max
;
114 extern int percpu_pagelist_fraction
;
115 extern int compat_log
;
116 extern int latencytop_enabled
;
117 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
119 extern int sysctl_nr_trim_pages
;
122 extern int blk_iopoll_enabled
;
125 /* Constants used for minimum and maximum */
126 #ifdef CONFIG_LOCKUP_DETECTOR
127 static int sixty
= 60;
128 static int neg_one
= -1;
132 static int __maybe_unused one
= 1;
133 static int __maybe_unused two
= 2;
134 static int __maybe_unused three
= 3;
135 static int __maybe_unused four
= 4;
136 static unsigned long one_ul
= 1;
137 static int one_hundred
= 100;
138 #ifdef CONFIG_INCREASE_MAXIMUM_SWAPPINESS
139 static int max_swappiness
= 200;
142 static int ten_thousand
= 10000;
145 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
146 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
148 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
149 static int maxolduid
= 65535;
150 static int minolduid
;
151 static int min_percpu_pagelist_fract
= 8;
153 static int ngroups_max
= NGROUPS_MAX
;
154 static const int cap_last_cap
= CAP_LAST_CAP
;
156 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
157 #ifdef CONFIG_DETECT_HUNG_TASK
158 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
161 #ifdef CONFIG_INOTIFY_USER
162 #include <linux/inotify.h>
167 #ifdef CONFIG_SPARC64
168 extern int sysctl_tsb_ratio
;
172 extern int pwrsw_enabled
;
175 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
176 extern int unaligned_enabled
;
180 extern int unaligned_dump_stack
;
183 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
184 extern int no_unaligned_warning
;
187 #ifdef CONFIG_PROC_SYSCTL
188 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
189 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
190 static int proc_taint(struct ctl_table
*table
, int write
,
191 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
195 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
196 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
199 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
200 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
201 #ifdef CONFIG_COREDUMP
202 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
203 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
206 #ifdef CONFIG_MAGIC_SYSRQ
207 /* Note: sysrq code uses it's own private copy */
208 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
210 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
211 void __user
*buffer
, size_t *lenp
,
216 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
221 sysrq_toggle_support(__sysrq_enabled
);
228 static struct ctl_table kern_table
[];
229 static struct ctl_table vm_table
[];
230 static struct ctl_table fs_table
[];
231 static struct ctl_table debug_table
[];
232 static struct ctl_table dev_table
[];
233 extern struct ctl_table random_table
[];
235 extern struct ctl_table epoll_table
[];
238 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
239 int sysctl_legacy_va_layout
;
242 /* The default sysctl tables: */
244 static struct ctl_table sysctl_base_table
[] = {
246 .procname
= "kernel",
263 .child
= debug_table
,
273 #ifdef CONFIG_SCHED_DEBUG
274 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
275 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
276 static int min_wakeup_granularity_ns
; /* 0 usecs */
277 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
279 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
280 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
281 #endif /* CONFIG_SMP */
282 #endif /* CONFIG_SCHED_DEBUG */
284 #ifdef CONFIG_COMPACTION
285 static int min_extfrag_threshold
;
286 static int max_extfrag_threshold
= 1000;
289 static struct ctl_table kern_table
[] = {
291 .procname
= "sched_child_runs_first",
292 .data
= &sysctl_sched_child_runs_first
,
293 .maxlen
= sizeof(unsigned int),
295 .proc_handler
= proc_dointvec
,
297 #ifdef CONFIG_SCHED_DEBUG
299 .procname
= "sched_min_granularity_ns",
300 .data
= &sysctl_sched_min_granularity
,
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_latency_ns",
309 .data
= &sysctl_sched_latency
,
310 .maxlen
= sizeof(unsigned int),
312 .proc_handler
= sched_proc_update_handler
,
313 .extra1
= &min_sched_granularity_ns
,
314 .extra2
= &max_sched_granularity_ns
,
317 .procname
= "sched_wakeup_granularity_ns",
318 .data
= &sysctl_sched_wakeup_granularity
,
319 .maxlen
= sizeof(unsigned int),
321 .proc_handler
= sched_proc_update_handler
,
322 .extra1
= &min_wakeup_granularity_ns
,
323 .extra2
= &max_wakeup_granularity_ns
,
327 .procname
= "sched_tunable_scaling",
328 .data
= &sysctl_sched_tunable_scaling
,
329 .maxlen
= sizeof(enum sched_tunable_scaling
),
331 .proc_handler
= sched_proc_update_handler
,
332 .extra1
= &min_sched_tunable_scaling
,
333 .extra2
= &max_sched_tunable_scaling
,
336 .procname
= "sched_migration_cost_ns",
337 .data
= &sysctl_sched_migration_cost
,
338 .maxlen
= sizeof(unsigned int),
340 .proc_handler
= proc_dointvec
,
343 .procname
= "sched_nr_migrate",
344 .data
= &sysctl_sched_nr_migrate
,
345 .maxlen
= sizeof(unsigned int),
347 .proc_handler
= proc_dointvec
,
350 .procname
= "sched_time_avg_ms",
351 .data
= &sysctl_sched_time_avg
,
352 .maxlen
= sizeof(unsigned int),
354 .proc_handler
= proc_dointvec
,
357 .procname
= "sched_shares_window_ns",
358 .data
= &sysctl_sched_shares_window
,
359 .maxlen
= sizeof(unsigned int),
361 .proc_handler
= proc_dointvec
,
364 .procname
= "timer_migration",
365 .data
= &sysctl_timer_migration
,
366 .maxlen
= sizeof(unsigned int),
368 .proc_handler
= proc_dointvec_minmax
,
372 #endif /* CONFIG_SMP */
373 #ifdef CONFIG_NUMA_BALANCING
375 .procname
= "numa_balancing_scan_delay_ms",
376 .data
= &sysctl_numa_balancing_scan_delay
,
377 .maxlen
= sizeof(unsigned int),
379 .proc_handler
= proc_dointvec
,
382 .procname
= "numa_balancing_scan_period_min_ms",
383 .data
= &sysctl_numa_balancing_scan_period_min
,
384 .maxlen
= sizeof(unsigned int),
386 .proc_handler
= proc_dointvec
,
389 .procname
= "numa_balancing_scan_period_reset",
390 .data
= &sysctl_numa_balancing_scan_period_reset
,
391 .maxlen
= sizeof(unsigned int),
393 .proc_handler
= proc_dointvec
,
396 .procname
= "numa_balancing_scan_period_max_ms",
397 .data
= &sysctl_numa_balancing_scan_period_max
,
398 .maxlen
= sizeof(unsigned int),
400 .proc_handler
= proc_dointvec
,
403 .procname
= "numa_balancing_scan_size_mb",
404 .data
= &sysctl_numa_balancing_scan_size
,
405 .maxlen
= sizeof(unsigned int),
407 .proc_handler
= proc_dointvec
,
409 #endif /* CONFIG_NUMA_BALANCING */
410 #endif /* CONFIG_SCHED_DEBUG */
412 .procname
= "sched_rt_period_us",
413 .data
= &sysctl_sched_rt_period
,
414 .maxlen
= sizeof(unsigned int),
416 .proc_handler
= sched_rt_handler
,
419 .procname
= "sched_rt_runtime_us",
420 .data
= &sysctl_sched_rt_runtime
,
421 .maxlen
= sizeof(int),
423 .proc_handler
= sched_rt_handler
,
426 .procname
= "sched_rr_timeslice_ms",
427 .data
= &sched_rr_timeslice
,
428 .maxlen
= sizeof(int),
430 .proc_handler
= sched_rr_handler
,
432 #ifdef CONFIG_SCHED_AUTOGROUP
434 .procname
= "sched_autogroup_enabled",
435 .data
= &sysctl_sched_autogroup_enabled
,
436 .maxlen
= sizeof(unsigned int),
438 .proc_handler
= proc_dointvec_minmax
,
443 #ifdef CONFIG_CFS_BANDWIDTH
445 .procname
= "sched_cfs_bandwidth_slice_us",
446 .data
= &sysctl_sched_cfs_bandwidth_slice
,
447 .maxlen
= sizeof(unsigned int),
449 .proc_handler
= proc_dointvec_minmax
,
453 #ifdef CONFIG_PROVE_LOCKING
455 .procname
= "prove_locking",
456 .data
= &prove_locking
,
457 .maxlen
= sizeof(int),
459 .proc_handler
= proc_dointvec
,
462 #ifdef CONFIG_LOCK_STAT
464 .procname
= "lock_stat",
466 .maxlen
= sizeof(int),
468 .proc_handler
= proc_dointvec
,
473 .data
= &panic_timeout
,
474 .maxlen
= sizeof(int),
476 .proc_handler
= proc_dointvec
,
478 #ifdef CONFIG_COREDUMP
480 .procname
= "core_uses_pid",
481 .data
= &core_uses_pid
,
482 .maxlen
= sizeof(int),
484 .proc_handler
= proc_dointvec
,
487 .procname
= "core_pattern",
488 .data
= core_pattern
,
489 .maxlen
= CORENAME_MAX_SIZE
,
491 .proc_handler
= proc_dostring_coredump
,
494 .procname
= "core_pipe_limit",
495 .data
= &core_pipe_limit
,
496 .maxlen
= sizeof(unsigned int),
498 .proc_handler
= proc_dointvec
,
501 #ifdef CONFIG_PROC_SYSCTL
503 .procname
= "tainted",
504 .maxlen
= sizeof(long),
506 .proc_handler
= proc_taint
,
509 #ifdef CONFIG_LATENCYTOP
511 .procname
= "latencytop",
512 .data
= &latencytop_enabled
,
513 .maxlen
= sizeof(int),
515 .proc_handler
= proc_dointvec
,
518 #ifdef CONFIG_BLK_DEV_INITRD
520 .procname
= "real-root-dev",
521 .data
= &real_root_dev
,
522 .maxlen
= sizeof(int),
524 .proc_handler
= proc_dointvec
,
528 .procname
= "print-fatal-signals",
529 .data
= &print_fatal_signals
,
530 .maxlen
= sizeof(int),
532 .proc_handler
= proc_dointvec
,
536 .procname
= "reboot-cmd",
537 .data
= reboot_command
,
540 .proc_handler
= proc_dostring
,
543 .procname
= "stop-a",
544 .data
= &stop_a_enabled
,
545 .maxlen
= sizeof (int),
547 .proc_handler
= proc_dointvec
,
550 .procname
= "scons-poweroff",
551 .data
= &scons_pwroff
,
552 .maxlen
= sizeof (int),
554 .proc_handler
= proc_dointvec
,
557 #ifdef CONFIG_SPARC64
559 .procname
= "tsb-ratio",
560 .data
= &sysctl_tsb_ratio
,
561 .maxlen
= sizeof (int),
563 .proc_handler
= proc_dointvec
,
568 .procname
= "soft-power",
569 .data
= &pwrsw_enabled
,
570 .maxlen
= sizeof (int),
572 .proc_handler
= proc_dointvec
,
575 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
577 .procname
= "unaligned-trap",
578 .data
= &unaligned_enabled
,
579 .maxlen
= sizeof (int),
581 .proc_handler
= proc_dointvec
,
585 .procname
= "ctrl-alt-del",
587 .maxlen
= sizeof(int),
589 .proc_handler
= proc_dointvec
,
591 #ifdef CONFIG_FUNCTION_TRACER
593 .procname
= "ftrace_enabled",
594 .data
= &ftrace_enabled
,
595 .maxlen
= sizeof(int),
597 .proc_handler
= ftrace_enable_sysctl
,
600 #ifdef CONFIG_STACK_TRACER
602 .procname
= "stack_tracer_enabled",
603 .data
= &stack_tracer_enabled
,
604 .maxlen
= sizeof(int),
606 .proc_handler
= stack_trace_sysctl
,
609 #ifdef CONFIG_TRACING
611 .procname
= "ftrace_dump_on_oops",
612 .data
= &ftrace_dump_on_oops
,
613 .maxlen
= sizeof(int),
615 .proc_handler
= proc_dointvec
,
618 #ifdef CONFIG_MODULES
620 .procname
= "modprobe",
621 .data
= &modprobe_path
,
622 .maxlen
= KMOD_PATH_LEN
,
624 .proc_handler
= proc_dostring
,
627 .procname
= "modules_disabled",
628 .data
= &modules_disabled
,
629 .maxlen
= sizeof(int),
631 /* only handle a transition from default "0" to "1" */
632 .proc_handler
= proc_dointvec_minmax
,
639 .procname
= "hotplug",
640 .data
= &uevent_helper
,
641 .maxlen
= UEVENT_HELPER_PATH_LEN
,
643 .proc_handler
= proc_dostring
,
646 #ifdef CONFIG_CHR_DEV_SG
648 .procname
= "sg-big-buff",
649 .data
= &sg_big_buff
,
650 .maxlen
= sizeof (int),
652 .proc_handler
= proc_dointvec
,
655 #ifdef CONFIG_BSD_PROCESS_ACCT
659 .maxlen
= 3*sizeof(int),
661 .proc_handler
= proc_dointvec
,
664 #ifdef CONFIG_MAGIC_SYSRQ
667 .data
= &__sysrq_enabled
,
668 .maxlen
= sizeof (int),
670 .proc_handler
= sysrq_sysctl_handler
,
673 #ifdef CONFIG_PROC_SYSCTL
675 .procname
= "cad_pid",
677 .maxlen
= sizeof (int),
679 .proc_handler
= proc_do_cad_pid
,
683 .procname
= "threads-max",
684 .data
= &max_threads
,
685 .maxlen
= sizeof(int),
687 .proc_handler
= proc_dointvec
,
690 .procname
= "random",
692 .child
= random_table
,
695 .procname
= "usermodehelper",
697 .child
= usermodehelper_table
,
700 .procname
= "overflowuid",
701 .data
= &overflowuid
,
702 .maxlen
= sizeof(int),
704 .proc_handler
= proc_dointvec_minmax
,
705 .extra1
= &minolduid
,
706 .extra2
= &maxolduid
,
709 .procname
= "overflowgid",
710 .data
= &overflowgid
,
711 .maxlen
= sizeof(int),
713 .proc_handler
= proc_dointvec_minmax
,
714 .extra1
= &minolduid
,
715 .extra2
= &maxolduid
,
718 #ifdef CONFIG_MATHEMU
720 .procname
= "ieee_emulation_warnings",
721 .data
= &sysctl_ieee_emulation_warnings
,
722 .maxlen
= sizeof(int),
724 .proc_handler
= proc_dointvec
,
728 .procname
= "userprocess_debug",
729 .data
= &show_unhandled_signals
,
730 .maxlen
= sizeof(int),
732 .proc_handler
= proc_dointvec
,
736 .procname
= "pid_max",
738 .maxlen
= sizeof (int),
740 .proc_handler
= proc_dointvec_minmax
,
741 .extra1
= &pid_max_min
,
742 .extra2
= &pid_max_max
,
745 .procname
= "panic_on_oops",
746 .data
= &panic_on_oops
,
747 .maxlen
= sizeof(int),
749 .proc_handler
= proc_dointvec
,
751 #if defined CONFIG_PRINTK
753 .procname
= "printk",
754 .data
= &console_loglevel
,
755 .maxlen
= 4*sizeof(int),
757 .proc_handler
= proc_dointvec
,
760 .procname
= "printk_ratelimit",
761 .data
= &printk_ratelimit_state
.interval
,
762 .maxlen
= sizeof(int),
764 .proc_handler
= proc_dointvec_jiffies
,
767 .procname
= "printk_ratelimit_burst",
768 .data
= &printk_ratelimit_state
.burst
,
769 .maxlen
= sizeof(int),
771 .proc_handler
= proc_dointvec
,
774 .procname
= "printk_delay",
775 .data
= &printk_delay_msec
,
776 .maxlen
= sizeof(int),
778 .proc_handler
= proc_dointvec_minmax
,
780 .extra2
= &ten_thousand
,
783 .procname
= "dmesg_restrict",
784 .data
= &dmesg_restrict
,
785 .maxlen
= sizeof(int),
787 .proc_handler
= proc_dointvec_minmax_sysadmin
,
792 .procname
= "kptr_restrict",
793 .data
= &kptr_restrict
,
794 .maxlen
= sizeof(int),
796 .proc_handler
= proc_dointvec_minmax_sysadmin
,
803 .procname
= "deny_new_usb",
804 .data
= &deny_new_usb
,
805 .maxlen
= sizeof(int),
807 .proc_handler
= proc_dointvec_minmax_sysadmin
,
813 .procname
= "ngroups_max",
814 .data
= &ngroups_max
,
815 .maxlen
= sizeof (int),
817 .proc_handler
= proc_dointvec
,
820 .procname
= "cap_last_cap",
821 .data
= (void *)&cap_last_cap
,
822 .maxlen
= sizeof(int),
824 .proc_handler
= proc_dointvec
,
826 #if defined(CONFIG_LOCKUP_DETECTOR)
828 .procname
= "watchdog",
829 .data
= &watchdog_enabled
,
830 .maxlen
= sizeof (int),
832 .proc_handler
= proc_dowatchdog
,
837 .procname
= "watchdog_thresh",
838 .data
= &watchdog_thresh
,
839 .maxlen
= sizeof(int),
841 .proc_handler
= proc_dowatchdog
,
846 .procname
= "softlockup_panic",
847 .data
= &softlockup_panic
,
848 .maxlen
= sizeof(int),
850 .proc_handler
= proc_dointvec_minmax
,
855 .procname
= "nmi_watchdog",
856 .data
= &watchdog_enabled
,
857 .maxlen
= sizeof (int),
859 .proc_handler
= proc_dowatchdog
,
864 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
866 .procname
= "unknown_nmi_panic",
867 .data
= &unknown_nmi_panic
,
868 .maxlen
= sizeof (int),
870 .proc_handler
= proc_dointvec
,
873 #if defined(CONFIG_X86)
875 .procname
= "panic_on_unrecovered_nmi",
876 .data
= &panic_on_unrecovered_nmi
,
877 .maxlen
= sizeof(int),
879 .proc_handler
= proc_dointvec
,
882 .procname
= "panic_on_io_nmi",
883 .data
= &panic_on_io_nmi
,
884 .maxlen
= sizeof(int),
886 .proc_handler
= proc_dointvec
,
888 #ifdef CONFIG_DEBUG_STACKOVERFLOW
890 .procname
= "panic_on_stackoverflow",
891 .data
= &sysctl_panic_on_stackoverflow
,
892 .maxlen
= sizeof(int),
894 .proc_handler
= proc_dointvec
,
898 .procname
= "bootloader_type",
899 .data
= &bootloader_type
,
900 .maxlen
= sizeof (int),
902 .proc_handler
= proc_dointvec
,
905 .procname
= "bootloader_version",
906 .data
= &bootloader_version
,
907 .maxlen
= sizeof (int),
909 .proc_handler
= proc_dointvec
,
912 .procname
= "kstack_depth_to_print",
913 .data
= &kstack_depth_to_print
,
914 .maxlen
= sizeof(int),
916 .proc_handler
= proc_dointvec
,
919 .procname
= "io_delay_type",
920 .data
= &io_delay_type
,
921 .maxlen
= sizeof(int),
923 .proc_handler
= proc_dointvec
,
926 #if defined(CONFIG_MMU)
928 .procname
= "randomize_va_space",
929 .data
= &randomize_va_space
,
930 .maxlen
= sizeof(int),
932 .proc_handler
= proc_dointvec
,
935 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
937 .procname
= "spin_retry",
939 .maxlen
= sizeof (int),
941 .proc_handler
= proc_dointvec
,
944 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
946 .procname
= "acpi_video_flags",
947 .data
= &acpi_realmode_flags
,
948 .maxlen
= sizeof (unsigned long),
950 .proc_handler
= proc_doulongvec_minmax
,
953 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
955 .procname
= "ignore-unaligned-usertrap",
956 .data
= &no_unaligned_warning
,
957 .maxlen
= sizeof (int),
959 .proc_handler
= proc_dointvec
,
964 .procname
= "unaligned-dump-stack",
965 .data
= &unaligned_dump_stack
,
966 .maxlen
= sizeof (int),
968 .proc_handler
= proc_dointvec
,
971 #ifdef CONFIG_DETECT_HUNG_TASK
973 .procname
= "hung_task_panic",
974 .data
= &sysctl_hung_task_panic
,
975 .maxlen
= sizeof(int),
977 .proc_handler
= proc_dointvec_minmax
,
982 .procname
= "hung_task_check_count",
983 .data
= &sysctl_hung_task_check_count
,
984 .maxlen
= sizeof(unsigned long),
986 .proc_handler
= proc_doulongvec_minmax
,
989 .procname
= "hung_task_timeout_secs",
990 .data
= &sysctl_hung_task_timeout_secs
,
991 .maxlen
= sizeof(unsigned long),
993 .proc_handler
= proc_dohung_task_timeout_secs
,
994 .extra2
= &hung_task_timeout_max
,
997 .procname
= "hung_task_warnings",
998 .data
= &sysctl_hung_task_warnings
,
999 .maxlen
= sizeof(unsigned long),
1001 .proc_handler
= proc_doulongvec_minmax
,
1004 #ifdef CONFIG_COMPAT
1006 .procname
= "compat-log",
1007 .data
= &compat_log
,
1008 .maxlen
= sizeof (int),
1010 .proc_handler
= proc_dointvec
,
1013 #ifdef CONFIG_RT_MUTEXES
1015 .procname
= "max_lock_depth",
1016 .data
= &max_lock_depth
,
1017 .maxlen
= sizeof(int),
1019 .proc_handler
= proc_dointvec
,
1023 .procname
= "poweroff_cmd",
1024 .data
= &poweroff_cmd
,
1025 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1027 .proc_handler
= proc_dostring
,
1033 .child
= key_sysctls
,
1036 #ifdef CONFIG_RCU_TORTURE_TEST
1038 .procname
= "rcutorture_runnable",
1039 .data
= &rcutorture_runnable
,
1040 .maxlen
= sizeof(int),
1042 .proc_handler
= proc_dointvec
,
1045 #ifdef CONFIG_PERF_EVENTS
1047 * User-space scripts rely on the existence of this file
1048 * as a feature check for perf_events being enabled.
1050 * So it's an ABI, do not remove!
1053 .procname
= "perf_event_paranoid",
1054 .data
= &sysctl_perf_event_paranoid
,
1055 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1057 .proc_handler
= proc_dointvec
,
1060 .procname
= "perf_event_mlock_kb",
1061 .data
= &sysctl_perf_event_mlock
,
1062 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1064 .proc_handler
= proc_dointvec
,
1067 .procname
= "perf_event_max_sample_rate",
1068 .data
= &sysctl_perf_event_sample_rate
,
1069 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1071 .proc_handler
= perf_proc_update_handler
,
1075 .procname
= "perf_cpu_time_max_percent",
1076 .data
= &sysctl_perf_cpu_time_max_percent
,
1077 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1079 .proc_handler
= perf_cpu_time_max_percent_handler
,
1081 .extra2
= &one_hundred
,
1084 #ifdef CONFIG_KMEMCHECK
1086 .procname
= "kmemcheck",
1087 .data
= &kmemcheck_enabled
,
1088 .maxlen
= sizeof(int),
1090 .proc_handler
= proc_dointvec
,
1095 .procname
= "blk_iopoll",
1096 .data
= &blk_iopoll_enabled
,
1097 .maxlen
= sizeof(int),
1099 .proc_handler
= proc_dointvec
,
1105 static struct ctl_table vm_table
[] = {
1107 .procname
= "overcommit_memory",
1108 .data
= &sysctl_overcommit_memory
,
1109 .maxlen
= sizeof(sysctl_overcommit_memory
),
1111 .proc_handler
= proc_dointvec_minmax
,
1116 .procname
= "panic_on_oom",
1117 .data
= &sysctl_panic_on_oom
,
1118 .maxlen
= sizeof(sysctl_panic_on_oom
),
1120 .proc_handler
= proc_dointvec_minmax
,
1125 .procname
= "oom_kill_allocating_task",
1126 .data
= &sysctl_oom_kill_allocating_task
,
1127 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1129 .proc_handler
= proc_dointvec
,
1132 .procname
= "oom_dump_tasks",
1133 .data
= &sysctl_oom_dump_tasks
,
1134 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1136 .proc_handler
= proc_dointvec
,
1139 .procname
= "overcommit_ratio",
1140 .data
= &sysctl_overcommit_ratio
,
1141 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1143 .proc_handler
= proc_dointvec
,
1146 .procname
= "page-cluster",
1147 .data
= &page_cluster
,
1148 .maxlen
= sizeof(int),
1150 .proc_handler
= proc_dointvec_minmax
,
1154 .procname
= "dirty_background_ratio",
1155 .data
= &dirty_background_ratio
,
1156 .maxlen
= sizeof(dirty_background_ratio
),
1158 .proc_handler
= dirty_background_ratio_handler
,
1160 .extra2
= &one_hundred
,
1163 .procname
= "dirty_background_bytes",
1164 .data
= &dirty_background_bytes
,
1165 .maxlen
= sizeof(dirty_background_bytes
),
1167 .proc_handler
= dirty_background_bytes_handler
,
1171 .procname
= "dirty_ratio",
1172 .data
= &vm_dirty_ratio
,
1173 .maxlen
= sizeof(vm_dirty_ratio
),
1175 .proc_handler
= dirty_ratio_handler
,
1177 .extra2
= &one_hundred
,
1180 .procname
= "dirty_bytes",
1181 .data
= &vm_dirty_bytes
,
1182 .maxlen
= sizeof(vm_dirty_bytes
),
1184 .proc_handler
= dirty_bytes_handler
,
1185 .extra1
= &dirty_bytes_min
,
1188 .procname
= "dirty_writeback_centisecs",
1189 .data
= &dirty_writeback_interval
,
1190 .maxlen
= sizeof(dirty_writeback_interval
),
1192 .proc_handler
= dirty_writeback_centisecs_handler
,
1195 .procname
= "dirty_expire_centisecs",
1196 .data
= &dirty_expire_interval
,
1197 .maxlen
= sizeof(dirty_expire_interval
),
1199 .proc_handler
= proc_dointvec_minmax
,
1203 .procname
= "nr_pdflush_threads",
1204 .mode
= 0444 /* read-only */,
1205 .proc_handler
= pdflush_proc_obsolete
,
1208 .procname
= "swappiness",
1209 .data
= &vm_swappiness
,
1210 .maxlen
= sizeof(vm_swappiness
),
1212 .proc_handler
= proc_dointvec_minmax
,
1214 #ifdef CONFIG_INCREASE_MAXIMUM_SWAPPINESS
1215 .extra2
= &max_swappiness
,
1217 .extra2
= &one_hundred
,
1220 #ifdef CONFIG_HUGETLB_PAGE
1222 .procname
= "nr_hugepages",
1224 .maxlen
= sizeof(unsigned long),
1226 .proc_handler
= hugetlb_sysctl_handler
,
1227 .extra1
= (void *)&hugetlb_zero
,
1228 .extra2
= (void *)&hugetlb_infinity
,
1232 .procname
= "nr_hugepages_mempolicy",
1234 .maxlen
= sizeof(unsigned long),
1236 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1237 .extra1
= (void *)&hugetlb_zero
,
1238 .extra2
= (void *)&hugetlb_infinity
,
1242 .procname
= "hugetlb_shm_group",
1243 .data
= &sysctl_hugetlb_shm_group
,
1244 .maxlen
= sizeof(gid_t
),
1246 .proc_handler
= proc_dointvec
,
1249 .procname
= "hugepages_treat_as_movable",
1250 .data
= &hugepages_treat_as_movable
,
1251 .maxlen
= sizeof(int),
1253 .proc_handler
= hugetlb_treat_movable_handler
,
1256 .procname
= "nr_overcommit_hugepages",
1258 .maxlen
= sizeof(unsigned long),
1260 .proc_handler
= hugetlb_overcommit_handler
,
1261 .extra1
= (void *)&hugetlb_zero
,
1262 .extra2
= (void *)&hugetlb_infinity
,
1266 .procname
= "lowmem_reserve_ratio",
1267 .data
= &sysctl_lowmem_reserve_ratio
,
1268 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1270 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1273 .procname
= "drop_caches",
1274 .data
= &sysctl_drop_caches
,
1275 .maxlen
= sizeof(int),
1277 .proc_handler
= drop_caches_sysctl_handler
,
1281 #ifdef CONFIG_COMPACTION
1283 .procname
= "compact_memory",
1284 .data
= &sysctl_compact_memory
,
1285 .maxlen
= sizeof(int),
1287 .proc_handler
= sysctl_compaction_handler
,
1290 .procname
= "extfrag_threshold",
1291 .data
= &sysctl_extfrag_threshold
,
1292 .maxlen
= sizeof(int),
1294 .proc_handler
= sysctl_extfrag_handler
,
1295 .extra1
= &min_extfrag_threshold
,
1296 .extra2
= &max_extfrag_threshold
,
1299 #endif /* CONFIG_COMPACTION */
1301 .procname
= "min_free_kbytes",
1302 .data
= &min_free_kbytes
,
1303 .maxlen
= sizeof(min_free_kbytes
),
1305 .proc_handler
= min_free_kbytes_sysctl_handler
,
1309 .procname
= "extra_free_kbytes",
1310 .data
= &extra_free_kbytes
,
1311 .maxlen
= sizeof(extra_free_kbytes
),
1313 .proc_handler
= min_free_kbytes_sysctl_handler
,
1317 .procname
= "min_free_order_shift",
1318 .data
= &min_free_order_shift
,
1319 .maxlen
= sizeof(min_free_order_shift
),
1321 .proc_handler
= &proc_dointvec
1324 .procname
= "percpu_pagelist_fraction",
1325 .data
= &percpu_pagelist_fraction
,
1326 .maxlen
= sizeof(percpu_pagelist_fraction
),
1328 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1329 .extra1
= &min_percpu_pagelist_fract
,
1333 .procname
= "max_map_count",
1334 .data
= &sysctl_max_map_count
,
1335 .maxlen
= sizeof(sysctl_max_map_count
),
1337 .proc_handler
= proc_dointvec_minmax
,
1342 .procname
= "nr_trim_pages",
1343 .data
= &sysctl_nr_trim_pages
,
1344 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1346 .proc_handler
= proc_dointvec_minmax
,
1351 .procname
= "laptop_mode",
1352 .data
= &laptop_mode
,
1353 .maxlen
= sizeof(laptop_mode
),
1355 .proc_handler
= proc_dointvec_jiffies
,
1358 .procname
= "block_dump",
1359 .data
= &block_dump
,
1360 .maxlen
= sizeof(block_dump
),
1362 .proc_handler
= proc_dointvec
,
1366 .procname
= "vfs_cache_pressure",
1367 .data
= &sysctl_vfs_cache_pressure
,
1368 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1370 .proc_handler
= proc_dointvec
,
1373 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1375 .procname
= "legacy_va_layout",
1376 .data
= &sysctl_legacy_va_layout
,
1377 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1379 .proc_handler
= proc_dointvec
,
1385 .procname
= "zone_reclaim_mode",
1386 .data
= &zone_reclaim_mode
,
1387 .maxlen
= sizeof(zone_reclaim_mode
),
1389 .proc_handler
= proc_dointvec
,
1393 .procname
= "min_unmapped_ratio",
1394 .data
= &sysctl_min_unmapped_ratio
,
1395 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1397 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1399 .extra2
= &one_hundred
,
1402 .procname
= "min_slab_ratio",
1403 .data
= &sysctl_min_slab_ratio
,
1404 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1406 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1408 .extra2
= &one_hundred
,
1413 .procname
= "stat_interval",
1414 .data
= &sysctl_stat_interval
,
1415 .maxlen
= sizeof(sysctl_stat_interval
),
1417 .proc_handler
= proc_dointvec_jiffies
,
1422 .procname
= "mmap_min_addr",
1423 .data
= &dac_mmap_min_addr
,
1424 .maxlen
= sizeof(unsigned long),
1426 .proc_handler
= mmap_min_addr_handler
,
1431 .procname
= "numa_zonelist_order",
1432 .data
= &numa_zonelist_order
,
1433 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1435 .proc_handler
= numa_zonelist_order_handler
,
1438 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1439 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1441 .procname
= "vdso_enabled",
1442 .data
= &vdso_enabled
,
1443 .maxlen
= sizeof(vdso_enabled
),
1445 .proc_handler
= proc_dointvec
,
1449 #ifdef CONFIG_HIGHMEM
1451 .procname
= "highmem_is_dirtyable",
1452 .data
= &vm_highmem_is_dirtyable
,
1453 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1455 .proc_handler
= proc_dointvec_minmax
,
1461 .procname
= "scan_unevictable_pages",
1462 .data
= &scan_unevictable_pages
,
1463 .maxlen
= sizeof(scan_unevictable_pages
),
1465 .proc_handler
= scan_unevictable_handler
,
1467 #ifdef CONFIG_MEMORY_FAILURE
1469 .procname
= "memory_failure_early_kill",
1470 .data
= &sysctl_memory_failure_early_kill
,
1471 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1473 .proc_handler
= proc_dointvec_minmax
,
1478 .procname
= "memory_failure_recovery",
1479 .data
= &sysctl_memory_failure_recovery
,
1480 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1482 .proc_handler
= proc_dointvec_minmax
,
1488 .procname
= "user_reserve_kbytes",
1489 .data
= &sysctl_user_reserve_kbytes
,
1490 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1492 .proc_handler
= proc_doulongvec_minmax
,
1495 .procname
= "admin_reserve_kbytes",
1496 .data
= &sysctl_admin_reserve_kbytes
,
1497 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1499 .proc_handler
= proc_doulongvec_minmax
,
1501 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1503 .procname
= "mmap_rnd_bits",
1504 .data
= &mmap_rnd_bits
,
1505 .maxlen
= sizeof(mmap_rnd_bits
),
1507 .proc_handler
= proc_dointvec_minmax
,
1508 .extra1
= (void *)&mmap_rnd_bits_min
,
1509 .extra2
= (void *)&mmap_rnd_bits_max
,
1512 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1514 .procname
= "mmap_rnd_compat_bits",
1515 .data
= &mmap_rnd_compat_bits
,
1516 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1518 .proc_handler
= proc_dointvec_minmax
,
1519 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1520 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1526 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1527 static struct ctl_table binfmt_misc_table
[] = {
1532 static struct ctl_table fs_table
[] = {
1534 .procname
= "inode-nr",
1535 .data
= &inodes_stat
,
1536 .maxlen
= 2*sizeof(int),
1538 .proc_handler
= proc_nr_inodes
,
1541 .procname
= "inode-state",
1542 .data
= &inodes_stat
,
1543 .maxlen
= 7*sizeof(int),
1545 .proc_handler
= proc_nr_inodes
,
1548 .procname
= "file-nr",
1549 .data
= &files_stat
,
1550 .maxlen
= sizeof(files_stat
),
1552 .proc_handler
= proc_nr_files
,
1555 .procname
= "file-max",
1556 .data
= &files_stat
.max_files
,
1557 .maxlen
= sizeof(files_stat
.max_files
),
1559 .proc_handler
= proc_doulongvec_minmax
,
1562 .procname
= "nr_open",
1563 .data
= &sysctl_nr_open
,
1564 .maxlen
= sizeof(int),
1566 .proc_handler
= proc_dointvec_minmax
,
1567 .extra1
= &sysctl_nr_open_min
,
1568 .extra2
= &sysctl_nr_open_max
,
1571 .procname
= "dentry-state",
1572 .data
= &dentry_stat
,
1573 .maxlen
= 6*sizeof(int),
1575 .proc_handler
= proc_nr_dentry
,
1578 .procname
= "overflowuid",
1579 .data
= &fs_overflowuid
,
1580 .maxlen
= sizeof(int),
1582 .proc_handler
= proc_dointvec_minmax
,
1583 .extra1
= &minolduid
,
1584 .extra2
= &maxolduid
,
1587 .procname
= "overflowgid",
1588 .data
= &fs_overflowgid
,
1589 .maxlen
= sizeof(int),
1591 .proc_handler
= proc_dointvec_minmax
,
1592 .extra1
= &minolduid
,
1593 .extra2
= &maxolduid
,
1595 #ifdef CONFIG_FILE_LOCKING
1597 .procname
= "leases-enable",
1598 .data
= &leases_enable
,
1599 .maxlen
= sizeof(int),
1601 .proc_handler
= proc_dointvec
,
1604 #ifdef CONFIG_DNOTIFY
1606 .procname
= "dir-notify-enable",
1607 .data
= &dir_notify_enable
,
1608 .maxlen
= sizeof(int),
1610 .proc_handler
= proc_dointvec
,
1614 #ifdef CONFIG_FILE_LOCKING
1616 .procname
= "lease-break-time",
1617 .data
= &lease_break_time
,
1618 .maxlen
= sizeof(int),
1620 .proc_handler
= proc_dointvec
,
1625 .procname
= "aio-nr",
1627 .maxlen
= sizeof(aio_nr
),
1629 .proc_handler
= proc_doulongvec_minmax
,
1632 .procname
= "aio-max-nr",
1633 .data
= &aio_max_nr
,
1634 .maxlen
= sizeof(aio_max_nr
),
1636 .proc_handler
= proc_doulongvec_minmax
,
1638 #endif /* CONFIG_AIO */
1639 #ifdef CONFIG_INOTIFY_USER
1641 .procname
= "inotify",
1643 .child
= inotify_table
,
1648 .procname
= "epoll",
1650 .child
= epoll_table
,
1655 .procname
= "protected_symlinks",
1656 .data
= &sysctl_protected_symlinks
,
1657 .maxlen
= sizeof(int),
1659 .proc_handler
= proc_dointvec_minmax
,
1664 .procname
= "protected_hardlinks",
1665 .data
= &sysctl_protected_hardlinks
,
1666 .maxlen
= sizeof(int),
1668 .proc_handler
= proc_dointvec_minmax
,
1673 .procname
= "suid_dumpable",
1674 .data
= &suid_dumpable
,
1675 .maxlen
= sizeof(int),
1677 .proc_handler
= proc_dointvec_minmax_coredump
,
1681 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1683 .procname
= "binfmt_misc",
1685 .child
= binfmt_misc_table
,
1689 .procname
= "pipe-max-size",
1690 .data
= &pipe_max_size
,
1691 .maxlen
= sizeof(int),
1693 .proc_handler
= &pipe_proc_fn
,
1694 .extra1
= &pipe_min_size
,
1697 .procname
= "pipe-user-pages-hard",
1698 .data
= &pipe_user_pages_hard
,
1699 .maxlen
= sizeof(pipe_user_pages_hard
),
1701 .proc_handler
= proc_doulongvec_minmax
,
1704 .procname
= "pipe-user-pages-soft",
1705 .data
= &pipe_user_pages_soft
,
1706 .maxlen
= sizeof(pipe_user_pages_soft
),
1708 .proc_handler
= proc_doulongvec_minmax
,
1713 static struct ctl_table debug_table
[] = {
1714 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1716 .procname
= "exception-trace",
1717 .data
= &show_unhandled_signals
,
1718 .maxlen
= sizeof(int),
1720 .proc_handler
= proc_dointvec
1723 #if defined(CONFIG_OPTPROBES)
1725 .procname
= "kprobes-optimization",
1726 .data
= &sysctl_kprobes_optimization
,
1727 .maxlen
= sizeof(int),
1729 .proc_handler
= proc_kprobes_optimization_handler
,
1737 static struct ctl_table dev_table
[] = {
1741 int __init
sysctl_init(void)
1743 struct ctl_table_header
*hdr
;
1745 hdr
= register_sysctl_table(sysctl_base_table
);
1746 kmemleak_not_leak(hdr
);
1750 #endif /* CONFIG_SYSCTL */
1756 #ifdef CONFIG_PROC_SYSCTL
1758 static int _proc_do_string(void* data
, int maxlen
, int write
,
1759 void __user
*buffer
,
1760 size_t *lenp
, loff_t
*ppos
)
1766 if (!data
|| !maxlen
|| !*lenp
) {
1774 while (len
< *lenp
) {
1775 if (get_user(c
, p
++))
1777 if (c
== 0 || c
== '\n')
1783 if(copy_from_user(data
, buffer
, len
))
1785 ((char *) data
)[len
] = 0;
1803 if(copy_to_user(buffer
, data
, len
))
1806 if(put_user('\n', ((char __user
*) buffer
) + len
))
1817 * proc_dostring - read a string sysctl
1818 * @table: the sysctl table
1819 * @write: %TRUE if this is a write to the sysctl file
1820 * @buffer: the user buffer
1821 * @lenp: the size of the user buffer
1822 * @ppos: file position
1824 * Reads/writes a string from/to the user buffer. If the kernel
1825 * buffer provided is not large enough to hold the string, the
1826 * string is truncated. The copied string is %NULL-terminated.
1827 * If the string is being read by the user process, it is copied
1828 * and a newline '\n' is added. It is truncated if the buffer is
1831 * Returns 0 on success.
1833 int proc_dostring(struct ctl_table
*table
, int write
,
1834 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1836 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1837 buffer
, lenp
, ppos
);
1840 static size_t proc_skip_spaces(char **buf
)
1843 char *tmp
= skip_spaces(*buf
);
1849 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1859 #define TMPBUFLEN 22
1861 * proc_get_long - reads an ASCII formatted integer from a user buffer
1863 * @buf: a kernel buffer
1864 * @size: size of the kernel buffer
1865 * @val: this is where the number will be stored
1866 * @neg: set to %TRUE if number is negative
1867 * @perm_tr: a vector which contains the allowed trailers
1868 * @perm_tr_len: size of the perm_tr vector
1869 * @tr: pointer to store the trailer character
1871 * In case of success %0 is returned and @buf and @size are updated with
1872 * the amount of bytes read. If @tr is non-NULL and a trailing
1873 * character exists (size is non-zero after returning from this
1874 * function), @tr is updated with the trailing character.
1876 static int proc_get_long(char **buf
, size_t *size
,
1877 unsigned long *val
, bool *neg
,
1878 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1881 char *p
, tmp
[TMPBUFLEN
];
1887 if (len
> TMPBUFLEN
- 1)
1888 len
= TMPBUFLEN
- 1;
1890 memcpy(tmp
, *buf
, len
);
1894 if (*p
== '-' && *size
> 1) {
1902 *val
= simple_strtoul(p
, &p
, 0);
1906 /* We don't know if the next char is whitespace thus we may accept
1907 * invalid integers (e.g. 1234...a) or two integers instead of one
1908 * (e.g. 123...1). So lets not allow such large numbers. */
1909 if (len
== TMPBUFLEN
- 1)
1912 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1915 if (tr
&& (len
< *size
))
1925 * proc_put_long - converts an integer to a decimal ASCII formatted string
1927 * @buf: the user buffer
1928 * @size: the size of the user buffer
1929 * @val: the integer to be converted
1930 * @neg: sign of the number, %TRUE for negative
1932 * In case of success %0 is returned and @buf and @size are updated with
1933 * the amount of bytes written.
1935 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1939 char tmp
[TMPBUFLEN
], *p
= tmp
;
1941 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1945 if (copy_to_user(*buf
, tmp
, len
))
1953 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1956 char __user
**buffer
= (char __user
**)buf
;
1957 if (put_user(c
, *buffer
))
1959 (*size
)--, (*buffer
)++;
1965 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1967 int write
, void *data
)
1970 *valp
= *negp
? -*lvalp
: *lvalp
;
1975 *lvalp
= (unsigned long)-val
;
1978 *lvalp
= (unsigned long)val
;
1984 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1986 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1987 int write
, void __user
*buffer
,
1988 size_t *lenp
, loff_t
*ppos
,
1989 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1990 int write
, void *data
),
1993 int *i
, vleft
, first
= 1, err
= 0;
1994 unsigned long page
= 0;
1998 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2003 i
= (int *) tbl_data
;
2004 vleft
= table
->maxlen
/ sizeof(*i
);
2008 conv
= do_proc_dointvec_conv
;
2011 if (left
> PAGE_SIZE
- 1)
2012 left
= PAGE_SIZE
- 1;
2013 page
= __get_free_page(GFP_TEMPORARY
);
2014 kbuf
= (char *) page
;
2017 if (copy_from_user(kbuf
, buffer
, left
)) {
2024 for (; left
&& vleft
--; i
++, first
=0) {
2029 left
-= proc_skip_spaces(&kbuf
);
2033 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2035 sizeof(proc_wspace_sep
), NULL
);
2038 if (conv(&neg
, &lval
, i
, 1, data
)) {
2043 if (conv(&neg
, &lval
, i
, 0, data
)) {
2048 err
= proc_put_char(&buffer
, &left
, '\t');
2051 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2057 if (!write
&& !first
&& left
&& !err
)
2058 err
= proc_put_char(&buffer
, &left
, '\n');
2059 if (write
&& !err
&& left
)
2060 left
-= proc_skip_spaces(&kbuf
);
2065 return err
? : -EINVAL
;
2072 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2073 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2074 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2075 int write
, void *data
),
2078 return __do_proc_dointvec(table
->data
, table
, write
,
2079 buffer
, lenp
, ppos
, conv
, data
);
2083 * proc_dointvec - read a vector of integers
2084 * @table: the sysctl table
2085 * @write: %TRUE if this is a write to the sysctl file
2086 * @buffer: the user buffer
2087 * @lenp: the size of the user buffer
2088 * @ppos: file position
2090 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2091 * values from/to the user buffer, treated as an ASCII string.
2093 * Returns 0 on success.
2095 int proc_dointvec(struct ctl_table
*table
, int write
,
2096 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2098 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2103 * Taint values can only be increased
2104 * This means we can safely use a temporary.
2106 static int proc_taint(struct ctl_table
*table
, int write
,
2107 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2110 unsigned long tmptaint
= get_taint();
2113 if (write
&& !capable(CAP_SYS_ADMIN
))
2118 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2124 * Poor man's atomic or. Not worth adding a primitive
2125 * to everyone's atomic.h for this
2128 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2129 if ((tmptaint
>> i
) & 1)
2130 add_taint(i
, LOCKDEP_STILL_OK
);
2137 #ifdef CONFIG_PRINTK
2138 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2139 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2141 if (write
&& !capable(CAP_SYS_ADMIN
))
2144 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2148 struct do_proc_dointvec_minmax_conv_param
{
2153 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2155 int write
, void *data
)
2157 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2159 int val
= *negp
? -*lvalp
: *lvalp
;
2160 if ((param
->min
&& *param
->min
> val
) ||
2161 (param
->max
&& *param
->max
< val
))
2168 *lvalp
= (unsigned long)-val
;
2171 *lvalp
= (unsigned long)val
;
2178 * proc_dointvec_minmax - read a vector of integers with min/max values
2179 * @table: the sysctl table
2180 * @write: %TRUE if this is a write to the sysctl file
2181 * @buffer: the user buffer
2182 * @lenp: the size of the user buffer
2183 * @ppos: file position
2185 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2186 * values from/to the user buffer, treated as an ASCII string.
2188 * This routine will ensure the values are within the range specified by
2189 * table->extra1 (min) and table->extra2 (max).
2191 * Returns 0 on success.
2193 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2194 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2196 struct do_proc_dointvec_minmax_conv_param param
= {
2197 .min
= (int *) table
->extra1
,
2198 .max
= (int *) table
->extra2
,
2200 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2201 do_proc_dointvec_minmax_conv
, ¶m
);
2204 static void validate_coredump_safety(void)
2206 #ifdef CONFIG_COREDUMP
2207 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2208 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2209 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2210 "suid_dumpable=2. Pipe handler or fully qualified "\
2211 "core dump path required.\n");
2216 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2217 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2219 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2221 validate_coredump_safety();
2225 #ifdef CONFIG_COREDUMP
2226 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2227 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2229 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2231 validate_coredump_safety();
2236 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2237 void __user
*buffer
,
2238 size_t *lenp
, loff_t
*ppos
,
2239 unsigned long convmul
,
2240 unsigned long convdiv
)
2242 unsigned long *i
, *min
, *max
;
2243 int vleft
, first
= 1, err
= 0;
2244 unsigned long page
= 0;
2248 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2253 i
= (unsigned long *) data
;
2254 min
= (unsigned long *) table
->extra1
;
2255 max
= (unsigned long *) table
->extra2
;
2256 vleft
= table
->maxlen
/ sizeof(unsigned long);
2260 if (left
> PAGE_SIZE
- 1)
2261 left
= PAGE_SIZE
- 1;
2262 page
= __get_free_page(GFP_TEMPORARY
);
2263 kbuf
= (char *) page
;
2266 if (copy_from_user(kbuf
, buffer
, left
)) {
2273 for (; left
&& vleft
--; i
++, first
= 0) {
2279 left
-= proc_skip_spaces(&kbuf
);
2281 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2283 sizeof(proc_wspace_sep
), NULL
);
2288 val
= convmul
* val
/ convdiv
;
2289 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2293 val
= convdiv
* (*i
) / convmul
;
2295 err
= proc_put_char(&buffer
, &left
, '\t');
2296 err
= proc_put_long(&buffer
, &left
, val
, false);
2302 if (!write
&& !first
&& left
&& !err
)
2303 err
= proc_put_char(&buffer
, &left
, '\n');
2305 left
-= proc_skip_spaces(&kbuf
);
2310 return err
? : -EINVAL
;
2317 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2318 void __user
*buffer
,
2319 size_t *lenp
, loff_t
*ppos
,
2320 unsigned long convmul
,
2321 unsigned long convdiv
)
2323 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2324 buffer
, lenp
, ppos
, convmul
, convdiv
);
2328 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2329 * @table: the sysctl table
2330 * @write: %TRUE if this is a write to the sysctl file
2331 * @buffer: the user buffer
2332 * @lenp: the size of the user buffer
2333 * @ppos: file position
2335 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2336 * values from/to the user buffer, treated as an ASCII string.
2338 * This routine will ensure the values are within the range specified by
2339 * table->extra1 (min) and table->extra2 (max).
2341 * Returns 0 on success.
2343 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2344 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2346 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2350 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2351 * @table: the sysctl table
2352 * @write: %TRUE if this is a write to the sysctl file
2353 * @buffer: the user buffer
2354 * @lenp: the size of the user buffer
2355 * @ppos: file position
2357 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2358 * values from/to the user buffer, treated as an ASCII string. The values
2359 * are treated as milliseconds, and converted to jiffies when they are stored.
2361 * This routine will ensure the values are within the range specified by
2362 * table->extra1 (min) and table->extra2 (max).
2364 * Returns 0 on success.
2366 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2367 void __user
*buffer
,
2368 size_t *lenp
, loff_t
*ppos
)
2370 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2371 lenp
, ppos
, HZ
, 1000l);
2375 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2377 int write
, void *data
)
2380 if (*lvalp
> LONG_MAX
/ HZ
)
2382 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2388 lval
= (unsigned long)-val
;
2391 lval
= (unsigned long)val
;
2398 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2400 int write
, void *data
)
2403 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2405 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2411 lval
= (unsigned long)-val
;
2414 lval
= (unsigned long)val
;
2416 *lvalp
= jiffies_to_clock_t(lval
);
2421 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2423 int write
, void *data
)
2426 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2432 lval
= (unsigned long)-val
;
2435 lval
= (unsigned long)val
;
2437 *lvalp
= jiffies_to_msecs(lval
);
2443 * proc_dointvec_jiffies - read a vector of integers as seconds
2444 * @table: the sysctl table
2445 * @write: %TRUE if this is a write to the sysctl file
2446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: file position
2450 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2451 * values from/to the user buffer, treated as an ASCII string.
2452 * The values read are assumed to be in seconds, and are converted into
2455 * Returns 0 on success.
2457 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2458 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2460 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2461 do_proc_dointvec_jiffies_conv
,NULL
);
2465 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2466 * @table: the sysctl table
2467 * @write: %TRUE if this is a write to the sysctl file
2468 * @buffer: the user buffer
2469 * @lenp: the size of the user buffer
2470 * @ppos: pointer to the file position
2472 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2473 * values from/to the user buffer, treated as an ASCII string.
2474 * The values read are assumed to be in 1/USER_HZ seconds, and
2475 * are converted into jiffies.
2477 * Returns 0 on success.
2479 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2480 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2482 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2483 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2487 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2488 * @table: the sysctl table
2489 * @write: %TRUE if this is a write to the sysctl file
2490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
2492 * @ppos: file position
2493 * @ppos: the current position in the file
2495 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2496 * values from/to the user buffer, treated as an ASCII string.
2497 * The values read are assumed to be in 1/1000 seconds, and
2498 * are converted into jiffies.
2500 * Returns 0 on success.
2502 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2503 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2505 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2506 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2509 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2510 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2512 struct pid
*new_pid
;
2516 tmp
= pid_vnr(cad_pid
);
2518 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2519 lenp
, ppos
, NULL
, NULL
);
2523 new_pid
= find_get_pid(tmp
);
2527 put_pid(xchg(&cad_pid
, new_pid
));
2532 * proc_do_large_bitmap - read/write from/to a large bitmap
2533 * @table: the sysctl table
2534 * @write: %TRUE if this is a write to the sysctl file
2535 * @buffer: the user buffer
2536 * @lenp: the size of the user buffer
2537 * @ppos: file position
2539 * The bitmap is stored at table->data and the bitmap length (in bits)
2542 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2543 * large bitmaps may be represented in a compact manner. Writing into
2544 * the file will clear the bitmap then update it with the given input.
2546 * Returns 0 on success.
2548 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2549 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2553 size_t left
= *lenp
;
2554 unsigned long bitmap_len
= table
->maxlen
;
2555 unsigned long *bitmap
= (unsigned long *) table
->data
;
2556 unsigned long *tmp_bitmap
= NULL
;
2557 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2559 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2565 unsigned long page
= 0;
2568 if (left
> PAGE_SIZE
- 1)
2569 left
= PAGE_SIZE
- 1;
2571 page
= __get_free_page(GFP_TEMPORARY
);
2572 kbuf
= (char *) page
;
2575 if (copy_from_user(kbuf
, buffer
, left
)) {
2581 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2587 proc_skip_char(&kbuf
, &left
, '\n');
2588 while (!err
&& left
) {
2589 unsigned long val_a
, val_b
;
2592 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2596 if (val_a
>= bitmap_len
|| neg
) {
2608 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2609 &neg
, tr_b
, sizeof(tr_b
),
2613 if (val_b
>= bitmap_len
|| neg
||
2624 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2626 proc_skip_char(&kbuf
, &left
, '\n');
2630 unsigned long bit_a
, bit_b
= 0;
2633 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2634 if (bit_a
>= bitmap_len
)
2636 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2640 err
= proc_put_char(&buffer
, &left
, ',');
2644 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2647 if (bit_a
!= bit_b
) {
2648 err
= proc_put_char(&buffer
, &left
, '-');
2651 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2659 err
= proc_put_char(&buffer
, &left
, '\n');
2665 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2667 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2679 #else /* CONFIG_PROC_SYSCTL */
2681 int proc_dostring(struct ctl_table
*table
, int write
,
2682 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2687 int proc_dointvec(struct ctl_table
*table
, int write
,
2688 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2693 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2694 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2699 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2700 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2705 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2706 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2711 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2712 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2717 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2718 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2723 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2724 void __user
*buffer
,
2725 size_t *lenp
, loff_t
*ppos
)
2731 #endif /* CONFIG_PROC_SYSCTL */
2734 * No sense putting this after each symbol definition, twice,
2735 * exception granted :-)
2737 EXPORT_SYMBOL(proc_dointvec
);
2738 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2739 EXPORT_SYMBOL(proc_dointvec_minmax
);
2740 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2741 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2742 EXPORT_SYMBOL(proc_dostring
);
2743 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2744 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);