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 extra_free_kbytes
;
109 extern int min_free_order_shift
;
110 extern int pid_max_min
, pid_max_max
;
111 extern int percpu_pagelist_fraction
;
112 extern int compat_log
;
113 extern int latencytop_enabled
;
114 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
116 extern int sysctl_nr_trim_pages
;
119 extern int blk_iopoll_enabled
;
122 /* Constants used for minimum and maximum */
123 #ifdef CONFIG_LOCKUP_DETECTOR
124 static int sixty
= 60;
125 static int neg_one
= -1;
129 static int __maybe_unused one
= 1;
130 static int __maybe_unused two
= 2;
131 static int __maybe_unused three
= 3;
132 static unsigned long one_ul
= 1;
133 static int one_hundred
= 100;
135 static int ten_thousand
= 10000;
138 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
141 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142 static int maxolduid
= 65535;
143 static int minolduid
;
144 static int min_percpu_pagelist_fract
= 8;
146 static int ngroups_max
= NGROUPS_MAX
;
147 static const int cap_last_cap
= CAP_LAST_CAP
;
149 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
150 #ifdef CONFIG_DETECT_HUNG_TASK
151 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
154 #ifdef CONFIG_INOTIFY_USER
155 #include <linux/inotify.h>
160 #ifdef CONFIG_SPARC64
161 extern int sysctl_tsb_ratio
;
165 extern int pwrsw_enabled
;
168 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
169 extern int unaligned_enabled
;
173 extern int unaligned_dump_stack
;
176 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
177 extern int no_unaligned_warning
;
180 #ifdef CONFIG_PROC_SYSCTL
181 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
182 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
183 static int proc_taint(struct ctl_table
*table
, int write
,
184 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
188 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
189 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
192 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
193 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
194 #ifdef CONFIG_COREDUMP
195 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
196 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
199 #ifdef CONFIG_MAGIC_SYSRQ
200 /* Note: sysrq code uses it's own private copy */
201 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
203 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
204 void __user
*buffer
, size_t *lenp
,
209 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
214 sysrq_toggle_support(__sysrq_enabled
);
221 static struct ctl_table kern_table
[];
222 static struct ctl_table vm_table
[];
223 static struct ctl_table fs_table
[];
224 static struct ctl_table debug_table
[];
225 static struct ctl_table dev_table
[];
226 extern struct ctl_table random_table
[];
228 extern struct ctl_table epoll_table
[];
231 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
232 int sysctl_legacy_va_layout
;
235 /* The default sysctl tables: */
237 static struct ctl_table sysctl_base_table
[] = {
239 .procname
= "kernel",
256 .child
= debug_table
,
266 #ifdef CONFIG_SCHED_DEBUG
267 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
268 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
269 static int min_wakeup_granularity_ns
; /* 0 usecs */
270 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
272 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
273 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
274 #endif /* CONFIG_SMP */
275 #endif /* CONFIG_SCHED_DEBUG */
277 #ifdef CONFIG_COMPACTION
278 static int min_extfrag_threshold
;
279 static int max_extfrag_threshold
= 1000;
282 static struct ctl_table kern_table
[] = {
284 .procname
= "sched_child_runs_first",
285 .data
= &sysctl_sched_child_runs_first
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= proc_dointvec
,
290 #ifdef CONFIG_SCHED_DEBUG
292 .procname
= "sched_min_granularity_ns",
293 .data
= &sysctl_sched_min_granularity
,
294 .maxlen
= sizeof(unsigned int),
296 .proc_handler
= sched_proc_update_handler
,
297 .extra1
= &min_sched_granularity_ns
,
298 .extra2
= &max_sched_granularity_ns
,
301 .procname
= "sched_latency_ns",
302 .data
= &sysctl_sched_latency
,
303 .maxlen
= sizeof(unsigned int),
305 .proc_handler
= sched_proc_update_handler
,
306 .extra1
= &min_sched_granularity_ns
,
307 .extra2
= &max_sched_granularity_ns
,
310 .procname
= "sched_wakeup_granularity_ns",
311 .data
= &sysctl_sched_wakeup_granularity
,
312 .maxlen
= sizeof(unsigned int),
314 .proc_handler
= sched_proc_update_handler
,
315 .extra1
= &min_wakeup_granularity_ns
,
316 .extra2
= &max_wakeup_granularity_ns
,
320 .procname
= "sched_tunable_scaling",
321 .data
= &sysctl_sched_tunable_scaling
,
322 .maxlen
= sizeof(enum sched_tunable_scaling
),
324 .proc_handler
= sched_proc_update_handler
,
325 .extra1
= &min_sched_tunable_scaling
,
326 .extra2
= &max_sched_tunable_scaling
,
329 .procname
= "sched_migration_cost_ns",
330 .data
= &sysctl_sched_migration_cost
,
331 .maxlen
= sizeof(unsigned int),
333 .proc_handler
= proc_dointvec
,
336 .procname
= "sched_nr_migrate",
337 .data
= &sysctl_sched_nr_migrate
,
338 .maxlen
= sizeof(unsigned int),
340 .proc_handler
= proc_dointvec
,
343 .procname
= "sched_time_avg_ms",
344 .data
= &sysctl_sched_time_avg
,
345 .maxlen
= sizeof(unsigned int),
347 .proc_handler
= proc_dointvec
,
350 .procname
= "sched_shares_window_ns",
351 .data
= &sysctl_sched_shares_window
,
352 .maxlen
= sizeof(unsigned int),
354 .proc_handler
= proc_dointvec
,
357 .procname
= "timer_migration",
358 .data
= &sysctl_timer_migration
,
359 .maxlen
= sizeof(unsigned int),
361 .proc_handler
= proc_dointvec_minmax
,
365 #endif /* CONFIG_SMP */
366 #ifdef CONFIG_NUMA_BALANCING
368 .procname
= "numa_balancing_scan_delay_ms",
369 .data
= &sysctl_numa_balancing_scan_delay
,
370 .maxlen
= sizeof(unsigned int),
372 .proc_handler
= proc_dointvec
,
375 .procname
= "numa_balancing_scan_period_min_ms",
376 .data
= &sysctl_numa_balancing_scan_period_min
,
377 .maxlen
= sizeof(unsigned int),
379 .proc_handler
= proc_dointvec
,
382 .procname
= "numa_balancing_scan_period_reset",
383 .data
= &sysctl_numa_balancing_scan_period_reset
,
384 .maxlen
= sizeof(unsigned int),
386 .proc_handler
= proc_dointvec
,
389 .procname
= "numa_balancing_scan_period_max_ms",
390 .data
= &sysctl_numa_balancing_scan_period_max
,
391 .maxlen
= sizeof(unsigned int),
393 .proc_handler
= proc_dointvec
,
396 .procname
= "numa_balancing_scan_size_mb",
397 .data
= &sysctl_numa_balancing_scan_size
,
398 .maxlen
= sizeof(unsigned int),
400 .proc_handler
= proc_dointvec
,
402 #endif /* CONFIG_NUMA_BALANCING */
403 #endif /* CONFIG_SCHED_DEBUG */
405 .procname
= "sched_rt_period_us",
406 .data
= &sysctl_sched_rt_period
,
407 .maxlen
= sizeof(unsigned int),
409 .proc_handler
= sched_rt_handler
,
412 .procname
= "sched_rt_runtime_us",
413 .data
= &sysctl_sched_rt_runtime
,
414 .maxlen
= sizeof(int),
416 .proc_handler
= sched_rt_handler
,
419 .procname
= "sched_rr_timeslice_ms",
420 .data
= &sched_rr_timeslice
,
421 .maxlen
= sizeof(int),
423 .proc_handler
= sched_rr_handler
,
425 #ifdef CONFIG_SCHED_AUTOGROUP
427 .procname
= "sched_autogroup_enabled",
428 .data
= &sysctl_sched_autogroup_enabled
,
429 .maxlen
= sizeof(unsigned int),
431 .proc_handler
= proc_dointvec_minmax
,
436 #ifdef CONFIG_CFS_BANDWIDTH
438 .procname
= "sched_cfs_bandwidth_slice_us",
439 .data
= &sysctl_sched_cfs_bandwidth_slice
,
440 .maxlen
= sizeof(unsigned int),
442 .proc_handler
= proc_dointvec_minmax
,
446 #ifdef CONFIG_PROVE_LOCKING
448 .procname
= "prove_locking",
449 .data
= &prove_locking
,
450 .maxlen
= sizeof(int),
452 .proc_handler
= proc_dointvec
,
455 #ifdef CONFIG_LOCK_STAT
457 .procname
= "lock_stat",
459 .maxlen
= sizeof(int),
461 .proc_handler
= proc_dointvec
,
466 .data
= &panic_timeout
,
467 .maxlen
= sizeof(int),
469 .proc_handler
= proc_dointvec
,
471 #ifdef CONFIG_COREDUMP
473 .procname
= "core_uses_pid",
474 .data
= &core_uses_pid
,
475 .maxlen
= sizeof(int),
477 .proc_handler
= proc_dointvec
,
480 .procname
= "core_pattern",
481 .data
= core_pattern
,
482 .maxlen
= CORENAME_MAX_SIZE
,
484 .proc_handler
= proc_dostring_coredump
,
487 .procname
= "core_pipe_limit",
488 .data
= &core_pipe_limit
,
489 .maxlen
= sizeof(unsigned int),
491 .proc_handler
= proc_dointvec
,
494 #ifdef CONFIG_PROC_SYSCTL
496 .procname
= "tainted",
497 .maxlen
= sizeof(long),
499 .proc_handler
= proc_taint
,
502 #ifdef CONFIG_LATENCYTOP
504 .procname
= "latencytop",
505 .data
= &latencytop_enabled
,
506 .maxlen
= sizeof(int),
508 .proc_handler
= proc_dointvec
,
511 #ifdef CONFIG_BLK_DEV_INITRD
513 .procname
= "real-root-dev",
514 .data
= &real_root_dev
,
515 .maxlen
= sizeof(int),
517 .proc_handler
= proc_dointvec
,
521 .procname
= "print-fatal-signals",
522 .data
= &print_fatal_signals
,
523 .maxlen
= sizeof(int),
525 .proc_handler
= proc_dointvec
,
529 .procname
= "reboot-cmd",
530 .data
= reboot_command
,
533 .proc_handler
= proc_dostring
,
536 .procname
= "stop-a",
537 .data
= &stop_a_enabled
,
538 .maxlen
= sizeof (int),
540 .proc_handler
= proc_dointvec
,
543 .procname
= "scons-poweroff",
544 .data
= &scons_pwroff
,
545 .maxlen
= sizeof (int),
547 .proc_handler
= proc_dointvec
,
550 #ifdef CONFIG_SPARC64
552 .procname
= "tsb-ratio",
553 .data
= &sysctl_tsb_ratio
,
554 .maxlen
= sizeof (int),
556 .proc_handler
= proc_dointvec
,
561 .procname
= "soft-power",
562 .data
= &pwrsw_enabled
,
563 .maxlen
= sizeof (int),
565 .proc_handler
= proc_dointvec
,
568 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
570 .procname
= "unaligned-trap",
571 .data
= &unaligned_enabled
,
572 .maxlen
= sizeof (int),
574 .proc_handler
= proc_dointvec
,
578 .procname
= "ctrl-alt-del",
580 .maxlen
= sizeof(int),
582 .proc_handler
= proc_dointvec
,
584 #ifdef CONFIG_FUNCTION_TRACER
586 .procname
= "ftrace_enabled",
587 .data
= &ftrace_enabled
,
588 .maxlen
= sizeof(int),
590 .proc_handler
= ftrace_enable_sysctl
,
593 #ifdef CONFIG_STACK_TRACER
595 .procname
= "stack_tracer_enabled",
596 .data
= &stack_tracer_enabled
,
597 .maxlen
= sizeof(int),
599 .proc_handler
= stack_trace_sysctl
,
602 #ifdef CONFIG_TRACING
604 .procname
= "ftrace_dump_on_oops",
605 .data
= &ftrace_dump_on_oops
,
606 .maxlen
= sizeof(int),
608 .proc_handler
= proc_dointvec
,
611 #ifdef CONFIG_MODULES
613 .procname
= "modprobe",
614 .data
= &modprobe_path
,
615 .maxlen
= KMOD_PATH_LEN
,
617 .proc_handler
= proc_dostring
,
620 .procname
= "modules_disabled",
621 .data
= &modules_disabled
,
622 .maxlen
= sizeof(int),
624 /* only handle a transition from default "0" to "1" */
625 .proc_handler
= proc_dointvec_minmax
,
632 .procname
= "hotplug",
633 .data
= &uevent_helper
,
634 .maxlen
= UEVENT_HELPER_PATH_LEN
,
636 .proc_handler
= proc_dostring
,
639 #ifdef CONFIG_CHR_DEV_SG
641 .procname
= "sg-big-buff",
642 .data
= &sg_big_buff
,
643 .maxlen
= sizeof (int),
645 .proc_handler
= proc_dointvec
,
648 #ifdef CONFIG_BSD_PROCESS_ACCT
652 .maxlen
= 3*sizeof(int),
654 .proc_handler
= proc_dointvec
,
657 #ifdef CONFIG_MAGIC_SYSRQ
660 .data
= &__sysrq_enabled
,
661 .maxlen
= sizeof (int),
663 .proc_handler
= sysrq_sysctl_handler
,
666 #ifdef CONFIG_PROC_SYSCTL
668 .procname
= "cad_pid",
670 .maxlen
= sizeof (int),
672 .proc_handler
= proc_do_cad_pid
,
676 .procname
= "threads-max",
677 .data
= &max_threads
,
678 .maxlen
= sizeof(int),
680 .proc_handler
= proc_dointvec
,
683 .procname
= "random",
685 .child
= random_table
,
688 .procname
= "usermodehelper",
690 .child
= usermodehelper_table
,
693 .procname
= "overflowuid",
694 .data
= &overflowuid
,
695 .maxlen
= sizeof(int),
697 .proc_handler
= proc_dointvec_minmax
,
698 .extra1
= &minolduid
,
699 .extra2
= &maxolduid
,
702 .procname
= "overflowgid",
703 .data
= &overflowgid
,
704 .maxlen
= sizeof(int),
706 .proc_handler
= proc_dointvec_minmax
,
707 .extra1
= &minolduid
,
708 .extra2
= &maxolduid
,
711 #ifdef CONFIG_MATHEMU
713 .procname
= "ieee_emulation_warnings",
714 .data
= &sysctl_ieee_emulation_warnings
,
715 .maxlen
= sizeof(int),
717 .proc_handler
= proc_dointvec
,
721 .procname
= "userprocess_debug",
722 .data
= &show_unhandled_signals
,
723 .maxlen
= sizeof(int),
725 .proc_handler
= proc_dointvec
,
729 .procname
= "pid_max",
731 .maxlen
= sizeof (int),
733 .proc_handler
= proc_dointvec_minmax
,
734 .extra1
= &pid_max_min
,
735 .extra2
= &pid_max_max
,
738 .procname
= "panic_on_oops",
739 .data
= &panic_on_oops
,
740 .maxlen
= sizeof(int),
742 .proc_handler
= proc_dointvec
,
744 #if defined CONFIG_PRINTK
746 .procname
= "printk",
747 .data
= &console_loglevel
,
748 .maxlen
= 4*sizeof(int),
750 .proc_handler
= proc_dointvec
,
753 .procname
= "printk_ratelimit",
754 .data
= &printk_ratelimit_state
.interval
,
755 .maxlen
= sizeof(int),
757 .proc_handler
= proc_dointvec_jiffies
,
760 .procname
= "printk_ratelimit_burst",
761 .data
= &printk_ratelimit_state
.burst
,
762 .maxlen
= sizeof(int),
764 .proc_handler
= proc_dointvec
,
767 .procname
= "printk_delay",
768 .data
= &printk_delay_msec
,
769 .maxlen
= sizeof(int),
771 .proc_handler
= proc_dointvec_minmax
,
773 .extra2
= &ten_thousand
,
776 .procname
= "dmesg_restrict",
777 .data
= &dmesg_restrict
,
778 .maxlen
= sizeof(int),
780 .proc_handler
= proc_dointvec_minmax_sysadmin
,
785 .procname
= "kptr_restrict",
786 .data
= &kptr_restrict
,
787 .maxlen
= sizeof(int),
789 .proc_handler
= proc_dointvec_minmax_sysadmin
,
795 .procname
= "ngroups_max",
796 .data
= &ngroups_max
,
797 .maxlen
= sizeof (int),
799 .proc_handler
= proc_dointvec
,
802 .procname
= "cap_last_cap",
803 .data
= (void *)&cap_last_cap
,
804 .maxlen
= sizeof(int),
806 .proc_handler
= proc_dointvec
,
808 #if defined(CONFIG_LOCKUP_DETECTOR)
810 .procname
= "watchdog",
811 .data
= &watchdog_enabled
,
812 .maxlen
= sizeof (int),
814 .proc_handler
= proc_dowatchdog
,
819 .procname
= "watchdog_thresh",
820 .data
= &watchdog_thresh
,
821 .maxlen
= sizeof(int),
823 .proc_handler
= proc_dowatchdog
,
828 .procname
= "softlockup_panic",
829 .data
= &softlockup_panic
,
830 .maxlen
= sizeof(int),
832 .proc_handler
= proc_dointvec_minmax
,
837 .procname
= "nmi_watchdog",
838 .data
= &watchdog_enabled
,
839 .maxlen
= sizeof (int),
841 .proc_handler
= proc_dowatchdog
,
846 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
848 .procname
= "unknown_nmi_panic",
849 .data
= &unknown_nmi_panic
,
850 .maxlen
= sizeof (int),
852 .proc_handler
= proc_dointvec
,
855 #if defined(CONFIG_X86)
857 .procname
= "panic_on_unrecovered_nmi",
858 .data
= &panic_on_unrecovered_nmi
,
859 .maxlen
= sizeof(int),
861 .proc_handler
= proc_dointvec
,
864 .procname
= "panic_on_io_nmi",
865 .data
= &panic_on_io_nmi
,
866 .maxlen
= sizeof(int),
868 .proc_handler
= proc_dointvec
,
870 #ifdef CONFIG_DEBUG_STACKOVERFLOW
872 .procname
= "panic_on_stackoverflow",
873 .data
= &sysctl_panic_on_stackoverflow
,
874 .maxlen
= sizeof(int),
876 .proc_handler
= proc_dointvec
,
880 .procname
= "bootloader_type",
881 .data
= &bootloader_type
,
882 .maxlen
= sizeof (int),
884 .proc_handler
= proc_dointvec
,
887 .procname
= "bootloader_version",
888 .data
= &bootloader_version
,
889 .maxlen
= sizeof (int),
891 .proc_handler
= proc_dointvec
,
894 .procname
= "kstack_depth_to_print",
895 .data
= &kstack_depth_to_print
,
896 .maxlen
= sizeof(int),
898 .proc_handler
= proc_dointvec
,
901 .procname
= "io_delay_type",
902 .data
= &io_delay_type
,
903 .maxlen
= sizeof(int),
905 .proc_handler
= proc_dointvec
,
908 #if defined(CONFIG_MMU)
910 .procname
= "randomize_va_space",
911 .data
= &randomize_va_space
,
912 .maxlen
= sizeof(int),
914 .proc_handler
= proc_dointvec
,
917 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
919 .procname
= "spin_retry",
921 .maxlen
= sizeof (int),
923 .proc_handler
= proc_dointvec
,
926 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
928 .procname
= "acpi_video_flags",
929 .data
= &acpi_realmode_flags
,
930 .maxlen
= sizeof (unsigned long),
932 .proc_handler
= proc_doulongvec_minmax
,
935 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
937 .procname
= "ignore-unaligned-usertrap",
938 .data
= &no_unaligned_warning
,
939 .maxlen
= sizeof (int),
941 .proc_handler
= proc_dointvec
,
946 .procname
= "unaligned-dump-stack",
947 .data
= &unaligned_dump_stack
,
948 .maxlen
= sizeof (int),
950 .proc_handler
= proc_dointvec
,
953 #ifdef CONFIG_DETECT_HUNG_TASK
955 .procname
= "hung_task_panic",
956 .data
= &sysctl_hung_task_panic
,
957 .maxlen
= sizeof(int),
959 .proc_handler
= proc_dointvec_minmax
,
964 .procname
= "hung_task_check_count",
965 .data
= &sysctl_hung_task_check_count
,
966 .maxlen
= sizeof(unsigned long),
968 .proc_handler
= proc_doulongvec_minmax
,
971 .procname
= "hung_task_timeout_secs",
972 .data
= &sysctl_hung_task_timeout_secs
,
973 .maxlen
= sizeof(unsigned long),
975 .proc_handler
= proc_dohung_task_timeout_secs
,
976 .extra2
= &hung_task_timeout_max
,
979 .procname
= "hung_task_warnings",
980 .data
= &sysctl_hung_task_warnings
,
981 .maxlen
= sizeof(unsigned long),
983 .proc_handler
= proc_doulongvec_minmax
,
988 .procname
= "compat-log",
990 .maxlen
= sizeof (int),
992 .proc_handler
= proc_dointvec
,
995 #ifdef CONFIG_RT_MUTEXES
997 .procname
= "max_lock_depth",
998 .data
= &max_lock_depth
,
999 .maxlen
= sizeof(int),
1001 .proc_handler
= proc_dointvec
,
1005 .procname
= "poweroff_cmd",
1006 .data
= &poweroff_cmd
,
1007 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1009 .proc_handler
= proc_dostring
,
1015 .child
= key_sysctls
,
1018 #ifdef CONFIG_RCU_TORTURE_TEST
1020 .procname
= "rcutorture_runnable",
1021 .data
= &rcutorture_runnable
,
1022 .maxlen
= sizeof(int),
1024 .proc_handler
= proc_dointvec
,
1027 #ifdef CONFIG_PERF_EVENTS
1029 * User-space scripts rely on the existence of this file
1030 * as a feature check for perf_events being enabled.
1032 * So it's an ABI, do not remove!
1035 .procname
= "perf_event_paranoid",
1036 .data
= &sysctl_perf_event_paranoid
,
1037 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1039 .proc_handler
= proc_dointvec
,
1042 .procname
= "perf_event_mlock_kb",
1043 .data
= &sysctl_perf_event_mlock
,
1044 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1046 .proc_handler
= proc_dointvec
,
1049 .procname
= "perf_event_max_sample_rate",
1050 .data
= &sysctl_perf_event_sample_rate
,
1051 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1053 .proc_handler
= perf_proc_update_handler
,
1057 .procname
= "perf_cpu_time_max_percent",
1058 .data
= &sysctl_perf_cpu_time_max_percent
,
1059 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1061 .proc_handler
= perf_cpu_time_max_percent_handler
,
1063 .extra2
= &one_hundred
,
1066 #ifdef CONFIG_KMEMCHECK
1068 .procname
= "kmemcheck",
1069 .data
= &kmemcheck_enabled
,
1070 .maxlen
= sizeof(int),
1072 .proc_handler
= proc_dointvec
,
1077 .procname
= "blk_iopoll",
1078 .data
= &blk_iopoll_enabled
,
1079 .maxlen
= sizeof(int),
1081 .proc_handler
= proc_dointvec
,
1087 static struct ctl_table vm_table
[] = {
1089 .procname
= "overcommit_memory",
1090 .data
= &sysctl_overcommit_memory
,
1091 .maxlen
= sizeof(sysctl_overcommit_memory
),
1093 .proc_handler
= proc_dointvec_minmax
,
1098 .procname
= "panic_on_oom",
1099 .data
= &sysctl_panic_on_oom
,
1100 .maxlen
= sizeof(sysctl_panic_on_oom
),
1102 .proc_handler
= proc_dointvec_minmax
,
1107 .procname
= "oom_kill_allocating_task",
1108 .data
= &sysctl_oom_kill_allocating_task
,
1109 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1111 .proc_handler
= proc_dointvec
,
1114 .procname
= "oom_dump_tasks",
1115 .data
= &sysctl_oom_dump_tasks
,
1116 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1118 .proc_handler
= proc_dointvec
,
1121 .procname
= "overcommit_ratio",
1122 .data
= &sysctl_overcommit_ratio
,
1123 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1125 .proc_handler
= proc_dointvec
,
1128 .procname
= "page-cluster",
1129 .data
= &page_cluster
,
1130 .maxlen
= sizeof(int),
1132 .proc_handler
= proc_dointvec_minmax
,
1136 .procname
= "dirty_background_ratio",
1137 .data
= &dirty_background_ratio
,
1138 .maxlen
= sizeof(dirty_background_ratio
),
1140 .proc_handler
= dirty_background_ratio_handler
,
1142 .extra2
= &one_hundred
,
1145 .procname
= "dirty_background_bytes",
1146 .data
= &dirty_background_bytes
,
1147 .maxlen
= sizeof(dirty_background_bytes
),
1149 .proc_handler
= dirty_background_bytes_handler
,
1153 .procname
= "dirty_ratio",
1154 .data
= &vm_dirty_ratio
,
1155 .maxlen
= sizeof(vm_dirty_ratio
),
1157 .proc_handler
= dirty_ratio_handler
,
1159 .extra2
= &one_hundred
,
1162 .procname
= "dirty_bytes",
1163 .data
= &vm_dirty_bytes
,
1164 .maxlen
= sizeof(vm_dirty_bytes
),
1166 .proc_handler
= dirty_bytes_handler
,
1167 .extra1
= &dirty_bytes_min
,
1170 .procname
= "dirty_writeback_centisecs",
1171 .data
= &dirty_writeback_interval
,
1172 .maxlen
= sizeof(dirty_writeback_interval
),
1174 .proc_handler
= dirty_writeback_centisecs_handler
,
1177 .procname
= "dirty_expire_centisecs",
1178 .data
= &dirty_expire_interval
,
1179 .maxlen
= sizeof(dirty_expire_interval
),
1181 .proc_handler
= proc_dointvec_minmax
,
1185 .procname
= "nr_pdflush_threads",
1186 .mode
= 0444 /* read-only */,
1187 .proc_handler
= pdflush_proc_obsolete
,
1190 .procname
= "swappiness",
1191 .data
= &vm_swappiness
,
1192 .maxlen
= sizeof(vm_swappiness
),
1194 .proc_handler
= proc_dointvec_minmax
,
1196 .extra2
= &one_hundred
,
1198 #ifdef CONFIG_HUGETLB_PAGE
1200 .procname
= "nr_hugepages",
1202 .maxlen
= sizeof(unsigned long),
1204 .proc_handler
= hugetlb_sysctl_handler
,
1205 .extra1
= (void *)&hugetlb_zero
,
1206 .extra2
= (void *)&hugetlb_infinity
,
1210 .procname
= "nr_hugepages_mempolicy",
1212 .maxlen
= sizeof(unsigned long),
1214 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1215 .extra1
= (void *)&hugetlb_zero
,
1216 .extra2
= (void *)&hugetlb_infinity
,
1220 .procname
= "hugetlb_shm_group",
1221 .data
= &sysctl_hugetlb_shm_group
,
1222 .maxlen
= sizeof(gid_t
),
1224 .proc_handler
= proc_dointvec
,
1227 .procname
= "hugepages_treat_as_movable",
1228 .data
= &hugepages_treat_as_movable
,
1229 .maxlen
= sizeof(int),
1231 .proc_handler
= hugetlb_treat_movable_handler
,
1234 .procname
= "nr_overcommit_hugepages",
1236 .maxlen
= sizeof(unsigned long),
1238 .proc_handler
= hugetlb_overcommit_handler
,
1239 .extra1
= (void *)&hugetlb_zero
,
1240 .extra2
= (void *)&hugetlb_infinity
,
1244 .procname
= "lowmem_reserve_ratio",
1245 .data
= &sysctl_lowmem_reserve_ratio
,
1246 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1248 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1251 .procname
= "drop_caches",
1252 .data
= &sysctl_drop_caches
,
1253 .maxlen
= sizeof(int),
1255 .proc_handler
= drop_caches_sysctl_handler
,
1259 #ifdef CONFIG_COMPACTION
1261 .procname
= "compact_memory",
1262 .data
= &sysctl_compact_memory
,
1263 .maxlen
= sizeof(int),
1265 .proc_handler
= sysctl_compaction_handler
,
1268 .procname
= "extfrag_threshold",
1269 .data
= &sysctl_extfrag_threshold
,
1270 .maxlen
= sizeof(int),
1272 .proc_handler
= sysctl_extfrag_handler
,
1273 .extra1
= &min_extfrag_threshold
,
1274 .extra2
= &max_extfrag_threshold
,
1277 #endif /* CONFIG_COMPACTION */
1279 .procname
= "min_free_kbytes",
1280 .data
= &min_free_kbytes
,
1281 .maxlen
= sizeof(min_free_kbytes
),
1283 .proc_handler
= min_free_kbytes_sysctl_handler
,
1287 .procname
= "extra_free_kbytes",
1288 .data
= &extra_free_kbytes
,
1289 .maxlen
= sizeof(extra_free_kbytes
),
1291 .proc_handler
= min_free_kbytes_sysctl_handler
,
1295 .procname
= "min_free_order_shift",
1296 .data
= &min_free_order_shift
,
1297 .maxlen
= sizeof(min_free_order_shift
),
1299 .proc_handler
= &proc_dointvec
1302 .procname
= "percpu_pagelist_fraction",
1303 .data
= &percpu_pagelist_fraction
,
1304 .maxlen
= sizeof(percpu_pagelist_fraction
),
1306 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1307 .extra1
= &min_percpu_pagelist_fract
,
1311 .procname
= "max_map_count",
1312 .data
= &sysctl_max_map_count
,
1313 .maxlen
= sizeof(sysctl_max_map_count
),
1315 .proc_handler
= proc_dointvec_minmax
,
1320 .procname
= "nr_trim_pages",
1321 .data
= &sysctl_nr_trim_pages
,
1322 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1324 .proc_handler
= proc_dointvec_minmax
,
1329 .procname
= "laptop_mode",
1330 .data
= &laptop_mode
,
1331 .maxlen
= sizeof(laptop_mode
),
1333 .proc_handler
= proc_dointvec_jiffies
,
1336 .procname
= "block_dump",
1337 .data
= &block_dump
,
1338 .maxlen
= sizeof(block_dump
),
1340 .proc_handler
= proc_dointvec
,
1344 .procname
= "vfs_cache_pressure",
1345 .data
= &sysctl_vfs_cache_pressure
,
1346 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1348 .proc_handler
= proc_dointvec
,
1351 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1353 .procname
= "legacy_va_layout",
1354 .data
= &sysctl_legacy_va_layout
,
1355 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1357 .proc_handler
= proc_dointvec
,
1363 .procname
= "zone_reclaim_mode",
1364 .data
= &zone_reclaim_mode
,
1365 .maxlen
= sizeof(zone_reclaim_mode
),
1367 .proc_handler
= proc_dointvec
,
1371 .procname
= "min_unmapped_ratio",
1372 .data
= &sysctl_min_unmapped_ratio
,
1373 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1375 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1377 .extra2
= &one_hundred
,
1380 .procname
= "min_slab_ratio",
1381 .data
= &sysctl_min_slab_ratio
,
1382 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1384 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1386 .extra2
= &one_hundred
,
1391 .procname
= "stat_interval",
1392 .data
= &sysctl_stat_interval
,
1393 .maxlen
= sizeof(sysctl_stat_interval
),
1395 .proc_handler
= proc_dointvec_jiffies
,
1400 .procname
= "mmap_min_addr",
1401 .data
= &dac_mmap_min_addr
,
1402 .maxlen
= sizeof(unsigned long),
1404 .proc_handler
= mmap_min_addr_handler
,
1409 .procname
= "numa_zonelist_order",
1410 .data
= &numa_zonelist_order
,
1411 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1413 .proc_handler
= numa_zonelist_order_handler
,
1416 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1417 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1419 .procname
= "vdso_enabled",
1420 .data
= &vdso_enabled
,
1421 .maxlen
= sizeof(vdso_enabled
),
1423 .proc_handler
= proc_dointvec
,
1427 #ifdef CONFIG_HIGHMEM
1429 .procname
= "highmem_is_dirtyable",
1430 .data
= &vm_highmem_is_dirtyable
,
1431 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1433 .proc_handler
= proc_dointvec_minmax
,
1439 .procname
= "scan_unevictable_pages",
1440 .data
= &scan_unevictable_pages
,
1441 .maxlen
= sizeof(scan_unevictable_pages
),
1443 .proc_handler
= scan_unevictable_handler
,
1445 #ifdef CONFIG_MEMORY_FAILURE
1447 .procname
= "memory_failure_early_kill",
1448 .data
= &sysctl_memory_failure_early_kill
,
1449 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1451 .proc_handler
= proc_dointvec_minmax
,
1456 .procname
= "memory_failure_recovery",
1457 .data
= &sysctl_memory_failure_recovery
,
1458 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1460 .proc_handler
= proc_dointvec_minmax
,
1466 .procname
= "user_reserve_kbytes",
1467 .data
= &sysctl_user_reserve_kbytes
,
1468 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1470 .proc_handler
= proc_doulongvec_minmax
,
1473 .procname
= "admin_reserve_kbytes",
1474 .data
= &sysctl_admin_reserve_kbytes
,
1475 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1477 .proc_handler
= proc_doulongvec_minmax
,
1479 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1481 .procname
= "mmap_rnd_bits",
1482 .data
= &mmap_rnd_bits
,
1483 .maxlen
= sizeof(mmap_rnd_bits
),
1485 .proc_handler
= proc_dointvec_minmax
,
1486 .extra1
= (void *)&mmap_rnd_bits_min
,
1487 .extra2
= (void *)&mmap_rnd_bits_max
,
1490 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1492 .procname
= "mmap_rnd_compat_bits",
1493 .data
= &mmap_rnd_compat_bits
,
1494 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1496 .proc_handler
= proc_dointvec_minmax
,
1497 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1498 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1504 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1505 static struct ctl_table binfmt_misc_table
[] = {
1510 static struct ctl_table fs_table
[] = {
1512 .procname
= "inode-nr",
1513 .data
= &inodes_stat
,
1514 .maxlen
= 2*sizeof(int),
1516 .proc_handler
= proc_nr_inodes
,
1519 .procname
= "inode-state",
1520 .data
= &inodes_stat
,
1521 .maxlen
= 7*sizeof(int),
1523 .proc_handler
= proc_nr_inodes
,
1526 .procname
= "file-nr",
1527 .data
= &files_stat
,
1528 .maxlen
= sizeof(files_stat
),
1530 .proc_handler
= proc_nr_files
,
1533 .procname
= "file-max",
1534 .data
= &files_stat
.max_files
,
1535 .maxlen
= sizeof(files_stat
.max_files
),
1537 .proc_handler
= proc_doulongvec_minmax
,
1540 .procname
= "nr_open",
1541 .data
= &sysctl_nr_open
,
1542 .maxlen
= sizeof(int),
1544 .proc_handler
= proc_dointvec_minmax
,
1545 .extra1
= &sysctl_nr_open_min
,
1546 .extra2
= &sysctl_nr_open_max
,
1549 .procname
= "dentry-state",
1550 .data
= &dentry_stat
,
1551 .maxlen
= 6*sizeof(int),
1553 .proc_handler
= proc_nr_dentry
,
1556 .procname
= "overflowuid",
1557 .data
= &fs_overflowuid
,
1558 .maxlen
= sizeof(int),
1560 .proc_handler
= proc_dointvec_minmax
,
1561 .extra1
= &minolduid
,
1562 .extra2
= &maxolduid
,
1565 .procname
= "overflowgid",
1566 .data
= &fs_overflowgid
,
1567 .maxlen
= sizeof(int),
1569 .proc_handler
= proc_dointvec_minmax
,
1570 .extra1
= &minolduid
,
1571 .extra2
= &maxolduid
,
1573 #ifdef CONFIG_FILE_LOCKING
1575 .procname
= "leases-enable",
1576 .data
= &leases_enable
,
1577 .maxlen
= sizeof(int),
1579 .proc_handler
= proc_dointvec
,
1582 #ifdef CONFIG_DNOTIFY
1584 .procname
= "dir-notify-enable",
1585 .data
= &dir_notify_enable
,
1586 .maxlen
= sizeof(int),
1588 .proc_handler
= proc_dointvec
,
1592 #ifdef CONFIG_FILE_LOCKING
1594 .procname
= "lease-break-time",
1595 .data
= &lease_break_time
,
1596 .maxlen
= sizeof(int),
1598 .proc_handler
= proc_dointvec
,
1603 .procname
= "aio-nr",
1605 .maxlen
= sizeof(aio_nr
),
1607 .proc_handler
= proc_doulongvec_minmax
,
1610 .procname
= "aio-max-nr",
1611 .data
= &aio_max_nr
,
1612 .maxlen
= sizeof(aio_max_nr
),
1614 .proc_handler
= proc_doulongvec_minmax
,
1616 #endif /* CONFIG_AIO */
1617 #ifdef CONFIG_INOTIFY_USER
1619 .procname
= "inotify",
1621 .child
= inotify_table
,
1626 .procname
= "epoll",
1628 .child
= epoll_table
,
1633 .procname
= "protected_symlinks",
1634 .data
= &sysctl_protected_symlinks
,
1635 .maxlen
= sizeof(int),
1637 .proc_handler
= proc_dointvec_minmax
,
1642 .procname
= "protected_hardlinks",
1643 .data
= &sysctl_protected_hardlinks
,
1644 .maxlen
= sizeof(int),
1646 .proc_handler
= proc_dointvec_minmax
,
1651 .procname
= "suid_dumpable",
1652 .data
= &suid_dumpable
,
1653 .maxlen
= sizeof(int),
1655 .proc_handler
= proc_dointvec_minmax_coredump
,
1659 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1661 .procname
= "binfmt_misc",
1663 .child
= binfmt_misc_table
,
1667 .procname
= "pipe-max-size",
1668 .data
= &pipe_max_size
,
1669 .maxlen
= sizeof(int),
1671 .proc_handler
= &pipe_proc_fn
,
1672 .extra1
= &pipe_min_size
,
1675 .procname
= "pipe-user-pages-hard",
1676 .data
= &pipe_user_pages_hard
,
1677 .maxlen
= sizeof(pipe_user_pages_hard
),
1679 .proc_handler
= proc_doulongvec_minmax
,
1682 .procname
= "pipe-user-pages-soft",
1683 .data
= &pipe_user_pages_soft
,
1684 .maxlen
= sizeof(pipe_user_pages_soft
),
1686 .proc_handler
= proc_doulongvec_minmax
,
1691 static struct ctl_table debug_table
[] = {
1692 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1694 .procname
= "exception-trace",
1695 .data
= &show_unhandled_signals
,
1696 .maxlen
= sizeof(int),
1698 .proc_handler
= proc_dointvec
1701 #if defined(CONFIG_OPTPROBES)
1703 .procname
= "kprobes-optimization",
1704 .data
= &sysctl_kprobes_optimization
,
1705 .maxlen
= sizeof(int),
1707 .proc_handler
= proc_kprobes_optimization_handler
,
1715 static struct ctl_table dev_table
[] = {
1719 int __init
sysctl_init(void)
1721 struct ctl_table_header
*hdr
;
1723 hdr
= register_sysctl_table(sysctl_base_table
);
1724 kmemleak_not_leak(hdr
);
1728 #endif /* CONFIG_SYSCTL */
1734 #ifdef CONFIG_PROC_SYSCTL
1736 static int _proc_do_string(void* data
, int maxlen
, int write
,
1737 void __user
*buffer
,
1738 size_t *lenp
, loff_t
*ppos
)
1744 if (!data
|| !maxlen
|| !*lenp
) {
1752 while (len
< *lenp
) {
1755 if (c
== 0 || c
== '\n')
1762 if(copy_from_user(data
, buffer
, len
))
1764 ((char *) data
)[len
] = 0;
1782 if(copy_to_user(buffer
, data
, len
))
1785 if(put_user('\n', ((char __user
*) buffer
) + len
))
1796 * proc_dostring - read a string sysctl
1797 * @table: the sysctl table
1798 * @write: %TRUE if this is a write to the sysctl file
1799 * @buffer: the user buffer
1800 * @lenp: the size of the user buffer
1801 * @ppos: file position
1803 * Reads/writes a string from/to the user buffer. If the kernel
1804 * buffer provided is not large enough to hold the string, the
1805 * string is truncated. The copied string is %NULL-terminated.
1806 * If the string is being read by the user process, it is copied
1807 * and a newline '\n' is added. It is truncated if the buffer is
1810 * Returns 0 on success.
1812 int proc_dostring(struct ctl_table
*table
, int write
,
1813 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1815 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1816 buffer
, lenp
, ppos
);
1819 static size_t proc_skip_spaces(char **buf
)
1822 char *tmp
= skip_spaces(*buf
);
1828 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1838 #define TMPBUFLEN 22
1840 * proc_get_long - reads an ASCII formatted integer from a user buffer
1842 * @buf: a kernel buffer
1843 * @size: size of the kernel buffer
1844 * @val: this is where the number will be stored
1845 * @neg: set to %TRUE if number is negative
1846 * @perm_tr: a vector which contains the allowed trailers
1847 * @perm_tr_len: size of the perm_tr vector
1848 * @tr: pointer to store the trailer character
1850 * In case of success %0 is returned and @buf and @size are updated with
1851 * the amount of bytes read. If @tr is non-NULL and a trailing
1852 * character exists (size is non-zero after returning from this
1853 * function), @tr is updated with the trailing character.
1855 static int proc_get_long(char **buf
, size_t *size
,
1856 unsigned long *val
, bool *neg
,
1857 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1860 char *p
, tmp
[TMPBUFLEN
];
1866 if (len
> TMPBUFLEN
- 1)
1867 len
= TMPBUFLEN
- 1;
1869 memcpy(tmp
, *buf
, len
);
1873 if (*p
== '-' && *size
> 1) {
1881 *val
= simple_strtoul(p
, &p
, 0);
1885 /* We don't know if the next char is whitespace thus we may accept
1886 * invalid integers (e.g. 1234...a) or two integers instead of one
1887 * (e.g. 123...1). So lets not allow such large numbers. */
1888 if (len
== TMPBUFLEN
- 1)
1891 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1894 if (tr
&& (len
< *size
))
1904 * proc_put_long - converts an integer to a decimal ASCII formatted string
1906 * @buf: the user buffer
1907 * @size: the size of the user buffer
1908 * @val: the integer to be converted
1909 * @neg: sign of the number, %TRUE for negative
1911 * In case of success %0 is returned and @buf and @size are updated with
1912 * the amount of bytes written.
1914 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1918 char tmp
[TMPBUFLEN
], *p
= tmp
;
1920 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1924 if (copy_to_user(*buf
, tmp
, len
))
1932 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1935 char __user
**buffer
= (char __user
**)buf
;
1936 if (put_user(c
, *buffer
))
1938 (*size
)--, (*buffer
)++;
1944 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1946 int write
, void *data
)
1949 *valp
= *negp
? -*lvalp
: *lvalp
;
1954 *lvalp
= (unsigned long)-val
;
1957 *lvalp
= (unsigned long)val
;
1963 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1965 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1966 int write
, void __user
*buffer
,
1967 size_t *lenp
, loff_t
*ppos
,
1968 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1969 int write
, void *data
),
1972 int *i
, vleft
, first
= 1, err
= 0;
1973 unsigned long page
= 0;
1977 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1982 i
= (int *) tbl_data
;
1983 vleft
= table
->maxlen
/ sizeof(*i
);
1987 conv
= do_proc_dointvec_conv
;
1990 if (left
> PAGE_SIZE
- 1)
1991 left
= PAGE_SIZE
- 1;
1992 page
= __get_free_page(GFP_TEMPORARY
);
1993 kbuf
= (char *) page
;
1996 if (copy_from_user(kbuf
, buffer
, left
)) {
2003 for (; left
&& vleft
--; i
++, first
=0) {
2008 left
-= proc_skip_spaces(&kbuf
);
2012 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2014 sizeof(proc_wspace_sep
), NULL
);
2017 if (conv(&neg
, &lval
, i
, 1, data
)) {
2022 if (conv(&neg
, &lval
, i
, 0, data
)) {
2027 err
= proc_put_char(&buffer
, &left
, '\t');
2030 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2036 if (!write
&& !first
&& left
&& !err
)
2037 err
= proc_put_char(&buffer
, &left
, '\n');
2038 if (write
&& !err
&& left
)
2039 left
-= proc_skip_spaces(&kbuf
);
2044 return err
? : -EINVAL
;
2051 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2052 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2053 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2054 int write
, void *data
),
2057 return __do_proc_dointvec(table
->data
, table
, write
,
2058 buffer
, lenp
, ppos
, conv
, data
);
2062 * proc_dointvec - read a vector of integers
2063 * @table: the sysctl table
2064 * @write: %TRUE if this is a write to the sysctl file
2065 * @buffer: the user buffer
2066 * @lenp: the size of the user buffer
2067 * @ppos: file position
2069 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2070 * values from/to the user buffer, treated as an ASCII string.
2072 * Returns 0 on success.
2074 int proc_dointvec(struct ctl_table
*table
, int write
,
2075 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2077 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2082 * Taint values can only be increased
2083 * This means we can safely use a temporary.
2085 static int proc_taint(struct ctl_table
*table
, int write
,
2086 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2089 unsigned long tmptaint
= get_taint();
2092 if (write
&& !capable(CAP_SYS_ADMIN
))
2097 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2103 * Poor man's atomic or. Not worth adding a primitive
2104 * to everyone's atomic.h for this
2107 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2108 if ((tmptaint
>> i
) & 1)
2109 add_taint(i
, LOCKDEP_STILL_OK
);
2116 #ifdef CONFIG_PRINTK
2117 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2118 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2120 if (write
&& !capable(CAP_SYS_ADMIN
))
2123 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2127 struct do_proc_dointvec_minmax_conv_param
{
2132 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2134 int write
, void *data
)
2136 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2138 int val
= *negp
? -*lvalp
: *lvalp
;
2139 if ((param
->min
&& *param
->min
> val
) ||
2140 (param
->max
&& *param
->max
< val
))
2147 *lvalp
= (unsigned long)-val
;
2150 *lvalp
= (unsigned long)val
;
2157 * proc_dointvec_minmax - read a vector of integers with min/max values
2158 * @table: the sysctl table
2159 * @write: %TRUE if this is a write to the sysctl file
2160 * @buffer: the user buffer
2161 * @lenp: the size of the user buffer
2162 * @ppos: file position
2164 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2165 * values from/to the user buffer, treated as an ASCII string.
2167 * This routine will ensure the values are within the range specified by
2168 * table->extra1 (min) and table->extra2 (max).
2170 * Returns 0 on success.
2172 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2173 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2175 struct do_proc_dointvec_minmax_conv_param param
= {
2176 .min
= (int *) table
->extra1
,
2177 .max
= (int *) table
->extra2
,
2179 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2180 do_proc_dointvec_minmax_conv
, ¶m
);
2183 static void validate_coredump_safety(void)
2185 #ifdef CONFIG_COREDUMP
2186 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2187 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2188 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2189 "suid_dumpable=2. Pipe handler or fully qualified "\
2190 "core dump path required.\n");
2195 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2196 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2198 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2200 validate_coredump_safety();
2204 #ifdef CONFIG_COREDUMP
2205 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2206 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2208 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2210 validate_coredump_safety();
2215 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2216 void __user
*buffer
,
2217 size_t *lenp
, loff_t
*ppos
,
2218 unsigned long convmul
,
2219 unsigned long convdiv
)
2221 unsigned long *i
, *min
, *max
;
2222 int vleft
, first
= 1, err
= 0;
2223 unsigned long page
= 0;
2227 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2232 i
= (unsigned long *) data
;
2233 min
= (unsigned long *) table
->extra1
;
2234 max
= (unsigned long *) table
->extra2
;
2235 vleft
= table
->maxlen
/ sizeof(unsigned long);
2239 if (left
> PAGE_SIZE
- 1)
2240 left
= PAGE_SIZE
- 1;
2241 page
= __get_free_page(GFP_TEMPORARY
);
2242 kbuf
= (char *) page
;
2245 if (copy_from_user(kbuf
, buffer
, left
)) {
2252 for (; left
&& vleft
--; i
++, first
= 0) {
2258 left
-= proc_skip_spaces(&kbuf
);
2260 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2262 sizeof(proc_wspace_sep
), NULL
);
2267 val
= convmul
* val
/ convdiv
;
2268 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2272 val
= convdiv
* (*i
) / convmul
;
2274 err
= proc_put_char(&buffer
, &left
, '\t');
2275 err
= proc_put_long(&buffer
, &left
, val
, false);
2281 if (!write
&& !first
&& left
&& !err
)
2282 err
= proc_put_char(&buffer
, &left
, '\n');
2284 left
-= proc_skip_spaces(&kbuf
);
2289 return err
? : -EINVAL
;
2296 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2297 void __user
*buffer
,
2298 size_t *lenp
, loff_t
*ppos
,
2299 unsigned long convmul
,
2300 unsigned long convdiv
)
2302 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2303 buffer
, lenp
, ppos
, convmul
, convdiv
);
2307 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2308 * @table: the sysctl table
2309 * @write: %TRUE if this is a write to the sysctl file
2310 * @buffer: the user buffer
2311 * @lenp: the size of the user buffer
2312 * @ppos: file position
2314 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2315 * values from/to the user buffer, treated as an ASCII string.
2317 * This routine will ensure the values are within the range specified by
2318 * table->extra1 (min) and table->extra2 (max).
2320 * Returns 0 on success.
2322 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2323 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2325 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2329 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2330 * @table: the sysctl table
2331 * @write: %TRUE if this is a write to the sysctl file
2332 * @buffer: the user buffer
2333 * @lenp: the size of the user buffer
2334 * @ppos: file position
2336 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2337 * values from/to the user buffer, treated as an ASCII string. The values
2338 * are treated as milliseconds, and converted to jiffies when they are stored.
2340 * This routine will ensure the values are within the range specified by
2341 * table->extra1 (min) and table->extra2 (max).
2343 * Returns 0 on success.
2345 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2346 void __user
*buffer
,
2347 size_t *lenp
, loff_t
*ppos
)
2349 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2350 lenp
, ppos
, HZ
, 1000l);
2354 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2356 int write
, void *data
)
2359 if (*lvalp
> LONG_MAX
/ HZ
)
2361 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2367 lval
= (unsigned long)-val
;
2370 lval
= (unsigned long)val
;
2377 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2379 int write
, void *data
)
2382 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2384 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2390 lval
= (unsigned long)-val
;
2393 lval
= (unsigned long)val
;
2395 *lvalp
= jiffies_to_clock_t(lval
);
2400 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2402 int write
, void *data
)
2405 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2411 lval
= (unsigned long)-val
;
2414 lval
= (unsigned long)val
;
2416 *lvalp
= jiffies_to_msecs(lval
);
2422 * proc_dointvec_jiffies - read a vector of integers as seconds
2423 * @table: the sysctl table
2424 * @write: %TRUE if this is a write to the sysctl file
2425 * @buffer: the user buffer
2426 * @lenp: the size of the user buffer
2427 * @ppos: file position
2429 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2430 * values from/to the user buffer, treated as an ASCII string.
2431 * The values read are assumed to be in seconds, and are converted into
2434 * Returns 0 on success.
2436 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2437 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2439 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2440 do_proc_dointvec_jiffies_conv
,NULL
);
2444 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2445 * @table: the sysctl table
2446 * @write: %TRUE if this is a write to the sysctl file
2447 * @buffer: the user buffer
2448 * @lenp: the size of the user buffer
2449 * @ppos: pointer to the file position
2451 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2452 * values from/to the user buffer, treated as an ASCII string.
2453 * The values read are assumed to be in 1/USER_HZ seconds, and
2454 * are converted into jiffies.
2456 * Returns 0 on success.
2458 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2459 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2461 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2462 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2466 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2467 * @table: the sysctl table
2468 * @write: %TRUE if this is a write to the sysctl file
2469 * @buffer: the user buffer
2470 * @lenp: the size of the user buffer
2471 * @ppos: file position
2472 * @ppos: the current position in the file
2474 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2475 * values from/to the user buffer, treated as an ASCII string.
2476 * The values read are assumed to be in 1/1000 seconds, and
2477 * are converted into jiffies.
2479 * Returns 0 on success.
2481 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2482 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2484 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2485 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2488 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2489 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2491 struct pid
*new_pid
;
2495 tmp
= pid_vnr(cad_pid
);
2497 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2498 lenp
, ppos
, NULL
, NULL
);
2502 new_pid
= find_get_pid(tmp
);
2506 put_pid(xchg(&cad_pid
, new_pid
));
2511 * proc_do_large_bitmap - read/write from/to a large bitmap
2512 * @table: the sysctl table
2513 * @write: %TRUE if this is a write to the sysctl file
2514 * @buffer: the user buffer
2515 * @lenp: the size of the user buffer
2516 * @ppos: file position
2518 * The bitmap is stored at table->data and the bitmap length (in bits)
2521 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2522 * large bitmaps may be represented in a compact manner. Writing into
2523 * the file will clear the bitmap then update it with the given input.
2525 * Returns 0 on success.
2527 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2528 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2532 size_t left
= *lenp
;
2533 unsigned long bitmap_len
= table
->maxlen
;
2534 unsigned long *bitmap
= (unsigned long *) table
->data
;
2535 unsigned long *tmp_bitmap
= NULL
;
2536 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2538 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2544 unsigned long page
= 0;
2547 if (left
> PAGE_SIZE
- 1)
2548 left
= PAGE_SIZE
- 1;
2550 page
= __get_free_page(GFP_TEMPORARY
);
2551 kbuf
= (char *) page
;
2554 if (copy_from_user(kbuf
, buffer
, left
)) {
2560 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2566 proc_skip_char(&kbuf
, &left
, '\n');
2567 while (!err
&& left
) {
2568 unsigned long val_a
, val_b
;
2571 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2575 if (val_a
>= bitmap_len
|| neg
) {
2587 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2588 &neg
, tr_b
, sizeof(tr_b
),
2592 if (val_b
>= bitmap_len
|| neg
||
2603 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2605 proc_skip_char(&kbuf
, &left
, '\n');
2609 unsigned long bit_a
, bit_b
= 0;
2612 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2613 if (bit_a
>= bitmap_len
)
2615 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2619 err
= proc_put_char(&buffer
, &left
, ',');
2623 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2626 if (bit_a
!= bit_b
) {
2627 err
= proc_put_char(&buffer
, &left
, '-');
2630 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2638 err
= proc_put_char(&buffer
, &left
, '\n');
2644 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2646 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2658 #else /* CONFIG_PROC_SYSCTL */
2660 int proc_dostring(struct ctl_table
*table
, int write
,
2661 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2666 int proc_dointvec(struct ctl_table
*table
, int write
,
2667 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2672 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2673 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2678 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2679 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2684 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2685 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2690 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2691 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2696 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2697 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2702 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2703 void __user
*buffer
,
2704 size_t *lenp
, loff_t
*ppos
)
2710 #endif /* CONFIG_PROC_SYSCTL */
2713 * No sense putting this after each symbol definition, twice,
2714 * exception granted :-)
2716 EXPORT_SYMBOL(proc_dointvec
);
2717 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2718 EXPORT_SYMBOL(proc_dointvec_minmax
);
2719 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2720 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2721 EXPORT_SYMBOL(proc_dostring
);
2722 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2723 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);