2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
71 #include <asm/stacktrace.h>
75 #include <asm/setup.h>
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
86 #ifdef CONFIG_CHR_DEV_SG
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory
;
99 extern int sysctl_overcommit_ratio
;
100 extern int max_threads
;
101 extern int suid_dumpable
;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid
;
104 extern char core_pattern
[];
105 extern unsigned int core_pipe_limit
;
108 extern int pid_max_min
, pid_max_max
;
109 extern int percpu_pagelist_fraction
;
110 extern int compat_log
;
111 extern int latencytop_enabled
;
112 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
114 extern int sysctl_nr_trim_pages
;
117 extern int blk_iopoll_enabled
;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty
= 60;
123 static int neg_one
= -1;
127 static int __maybe_unused one
= 1;
128 static int __maybe_unused two
= 2;
129 static int __maybe_unused three
= 3;
130 static unsigned long one_ul
= 1;
131 static int one_hundred
= 100;
133 static int ten_thousand
= 10000;
136 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
137 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
139 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
140 static int maxolduid
= 65535;
141 static int minolduid
;
142 static int min_percpu_pagelist_fract
= 8;
144 static int ngroups_max
= NGROUPS_MAX
;
145 static const int cap_last_cap
= CAP_LAST_CAP
;
147 #ifdef CONFIG_INOTIFY_USER
148 #include <linux/inotify.h>
153 #ifdef CONFIG_SPARC64
154 extern int sysctl_tsb_ratio
;
158 extern int pwrsw_enabled
;
161 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
162 extern int unaligned_enabled
;
166 extern int unaligned_dump_stack
;
169 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
170 extern int no_unaligned_warning
;
173 #ifdef CONFIG_PROC_SYSCTL
174 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
175 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
176 static int proc_taint(struct ctl_table
*table
, int write
,
177 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
181 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
182 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
185 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
186 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
187 #ifdef CONFIG_COREDUMP
188 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
189 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
192 #ifdef CONFIG_MAGIC_SYSRQ
193 /* Note: sysrq code uses it's own private copy */
194 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
196 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
197 void __user
*buffer
, size_t *lenp
,
202 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
207 sysrq_toggle_support(__sysrq_enabled
);
214 static struct ctl_table kern_table
[];
215 static struct ctl_table vm_table
[];
216 static struct ctl_table fs_table
[];
217 static struct ctl_table debug_table
[];
218 static struct ctl_table dev_table
[];
219 extern struct ctl_table random_table
[];
221 extern struct ctl_table epoll_table
[];
224 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
225 int sysctl_legacy_va_layout
;
228 /* The default sysctl tables: */
230 static struct ctl_table sysctl_base_table
[] = {
232 .procname
= "kernel",
249 .child
= debug_table
,
259 #ifdef CONFIG_SCHED_DEBUG
260 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
261 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
262 static int min_wakeup_granularity_ns
; /* 0 usecs */
263 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
265 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
266 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
267 #endif /* CONFIG_SMP */
268 #endif /* CONFIG_SCHED_DEBUG */
270 #ifdef CONFIG_COMPACTION
271 static int min_extfrag_threshold
;
272 static int max_extfrag_threshold
= 1000;
275 static struct ctl_table kern_table
[] = {
277 .procname
= "sched_child_runs_first",
278 .data
= &sysctl_sched_child_runs_first
,
279 .maxlen
= sizeof(unsigned int),
281 .proc_handler
= proc_dointvec
,
283 #ifdef CONFIG_SCHED_DEBUG
285 .procname
= "sched_min_granularity_ns",
286 .data
= &sysctl_sched_min_granularity
,
287 .maxlen
= sizeof(unsigned int),
289 .proc_handler
= sched_proc_update_handler
,
290 .extra1
= &min_sched_granularity_ns
,
291 .extra2
= &max_sched_granularity_ns
,
294 .procname
= "sched_latency_ns",
295 .data
= &sysctl_sched_latency
,
296 .maxlen
= sizeof(unsigned int),
298 .proc_handler
= sched_proc_update_handler
,
299 .extra1
= &min_sched_granularity_ns
,
300 .extra2
= &max_sched_granularity_ns
,
303 .procname
= "sched_wakeup_granularity_ns",
304 .data
= &sysctl_sched_wakeup_granularity
,
305 .maxlen
= sizeof(unsigned int),
307 .proc_handler
= sched_proc_update_handler
,
308 .extra1
= &min_wakeup_granularity_ns
,
309 .extra2
= &max_wakeup_granularity_ns
,
313 .procname
= "sched_tunable_scaling",
314 .data
= &sysctl_sched_tunable_scaling
,
315 .maxlen
= sizeof(enum sched_tunable_scaling
),
317 .proc_handler
= sched_proc_update_handler
,
318 .extra1
= &min_sched_tunable_scaling
,
319 .extra2
= &max_sched_tunable_scaling
,
322 .procname
= "sched_migration_cost_ns",
323 .data
= &sysctl_sched_migration_cost
,
324 .maxlen
= sizeof(unsigned int),
326 .proc_handler
= proc_dointvec
,
329 .procname
= "sched_nr_migrate",
330 .data
= &sysctl_sched_nr_migrate
,
331 .maxlen
= sizeof(unsigned int),
333 .proc_handler
= proc_dointvec
,
336 .procname
= "sched_time_avg_ms",
337 .data
= &sysctl_sched_time_avg
,
338 .maxlen
= sizeof(unsigned int),
340 .proc_handler
= proc_dointvec
,
343 .procname
= "sched_shares_window_ns",
344 .data
= &sysctl_sched_shares_window
,
345 .maxlen
= sizeof(unsigned int),
347 .proc_handler
= proc_dointvec
,
350 .procname
= "timer_migration",
351 .data
= &sysctl_timer_migration
,
352 .maxlen
= sizeof(unsigned int),
354 .proc_handler
= proc_dointvec_minmax
,
358 #endif /* CONFIG_SMP */
359 #ifdef CONFIG_NUMA_BALANCING
361 .procname
= "numa_balancing_scan_delay_ms",
362 .data
= &sysctl_numa_balancing_scan_delay
,
363 .maxlen
= sizeof(unsigned int),
365 .proc_handler
= proc_dointvec
,
368 .procname
= "numa_balancing_scan_period_min_ms",
369 .data
= &sysctl_numa_balancing_scan_period_min
,
370 .maxlen
= sizeof(unsigned int),
372 .proc_handler
= proc_dointvec
,
375 .procname
= "numa_balancing_scan_period_reset",
376 .data
= &sysctl_numa_balancing_scan_period_reset
,
377 .maxlen
= sizeof(unsigned int),
379 .proc_handler
= proc_dointvec
,
382 .procname
= "numa_balancing_scan_period_max_ms",
383 .data
= &sysctl_numa_balancing_scan_period_max
,
384 .maxlen
= sizeof(unsigned int),
386 .proc_handler
= proc_dointvec
,
389 .procname
= "numa_balancing_scan_size_mb",
390 .data
= &sysctl_numa_balancing_scan_size
,
391 .maxlen
= sizeof(unsigned int),
393 .proc_handler
= proc_dointvec
,
395 #endif /* CONFIG_NUMA_BALANCING */
396 #endif /* CONFIG_SCHED_DEBUG */
398 .procname
= "sched_rt_period_us",
399 .data
= &sysctl_sched_rt_period
,
400 .maxlen
= sizeof(unsigned int),
402 .proc_handler
= sched_rt_handler
,
405 .procname
= "sched_rt_runtime_us",
406 .data
= &sysctl_sched_rt_runtime
,
407 .maxlen
= sizeof(int),
409 .proc_handler
= sched_rt_handler
,
412 .procname
= "sched_rr_timeslice_ms",
413 .data
= &sched_rr_timeslice
,
414 .maxlen
= sizeof(int),
416 .proc_handler
= sched_rr_handler
,
418 #ifdef CONFIG_SCHED_AUTOGROUP
420 .procname
= "sched_autogroup_enabled",
421 .data
= &sysctl_sched_autogroup_enabled
,
422 .maxlen
= sizeof(unsigned int),
424 .proc_handler
= proc_dointvec_minmax
,
429 #ifdef CONFIG_CFS_BANDWIDTH
431 .procname
= "sched_cfs_bandwidth_slice_us",
432 .data
= &sysctl_sched_cfs_bandwidth_slice
,
433 .maxlen
= sizeof(unsigned int),
435 .proc_handler
= proc_dointvec_minmax
,
439 #ifdef CONFIG_PROVE_LOCKING
441 .procname
= "prove_locking",
442 .data
= &prove_locking
,
443 .maxlen
= sizeof(int),
445 .proc_handler
= proc_dointvec
,
448 #ifdef CONFIG_LOCK_STAT
450 .procname
= "lock_stat",
452 .maxlen
= sizeof(int),
454 .proc_handler
= proc_dointvec
,
459 .data
= &panic_timeout
,
460 .maxlen
= sizeof(int),
462 .proc_handler
= proc_dointvec
,
464 #ifdef CONFIG_COREDUMP
466 .procname
= "core_uses_pid",
467 .data
= &core_uses_pid
,
468 .maxlen
= sizeof(int),
470 .proc_handler
= proc_dointvec
,
473 .procname
= "core_pattern",
474 .data
= core_pattern
,
475 .maxlen
= CORENAME_MAX_SIZE
,
477 .proc_handler
= proc_dostring_coredump
,
480 .procname
= "core_pipe_limit",
481 .data
= &core_pipe_limit
,
482 .maxlen
= sizeof(unsigned int),
484 .proc_handler
= proc_dointvec
,
487 #ifdef CONFIG_PROC_SYSCTL
489 .procname
= "tainted",
490 .maxlen
= sizeof(long),
492 .proc_handler
= proc_taint
,
495 #ifdef CONFIG_LATENCYTOP
497 .procname
= "latencytop",
498 .data
= &latencytop_enabled
,
499 .maxlen
= sizeof(int),
501 .proc_handler
= proc_dointvec
,
504 #ifdef CONFIG_BLK_DEV_INITRD
506 .procname
= "real-root-dev",
507 .data
= &real_root_dev
,
508 .maxlen
= sizeof(int),
510 .proc_handler
= proc_dointvec
,
514 .procname
= "print-fatal-signals",
515 .data
= &print_fatal_signals
,
516 .maxlen
= sizeof(int),
518 .proc_handler
= proc_dointvec
,
522 .procname
= "reboot-cmd",
523 .data
= reboot_command
,
526 .proc_handler
= proc_dostring
,
529 .procname
= "stop-a",
530 .data
= &stop_a_enabled
,
531 .maxlen
= sizeof (int),
533 .proc_handler
= proc_dointvec
,
536 .procname
= "scons-poweroff",
537 .data
= &scons_pwroff
,
538 .maxlen
= sizeof (int),
540 .proc_handler
= proc_dointvec
,
543 #ifdef CONFIG_SPARC64
545 .procname
= "tsb-ratio",
546 .data
= &sysctl_tsb_ratio
,
547 .maxlen
= sizeof (int),
549 .proc_handler
= proc_dointvec
,
554 .procname
= "soft-power",
555 .data
= &pwrsw_enabled
,
556 .maxlen
= sizeof (int),
558 .proc_handler
= proc_dointvec
,
561 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
563 .procname
= "unaligned-trap",
564 .data
= &unaligned_enabled
,
565 .maxlen
= sizeof (int),
567 .proc_handler
= proc_dointvec
,
571 .procname
= "ctrl-alt-del",
573 .maxlen
= sizeof(int),
575 .proc_handler
= proc_dointvec
,
577 #ifdef CONFIG_FUNCTION_TRACER
579 .procname
= "ftrace_enabled",
580 .data
= &ftrace_enabled
,
581 .maxlen
= sizeof(int),
583 .proc_handler
= ftrace_enable_sysctl
,
586 #ifdef CONFIG_STACK_TRACER
588 .procname
= "stack_tracer_enabled",
589 .data
= &stack_tracer_enabled
,
590 .maxlen
= sizeof(int),
592 .proc_handler
= stack_trace_sysctl
,
595 #ifdef CONFIG_TRACING
597 .procname
= "ftrace_dump_on_oops",
598 .data
= &ftrace_dump_on_oops
,
599 .maxlen
= sizeof(int),
601 .proc_handler
= proc_dointvec
,
604 .procname
= "traceoff_on_warning",
605 .data
= &__disable_trace_on_warning
,
606 .maxlen
= sizeof(__disable_trace_on_warning
),
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
,
978 .procname
= "hung_task_warnings",
979 .data
= &sysctl_hung_task_warnings
,
980 .maxlen
= sizeof(unsigned long),
982 .proc_handler
= proc_doulongvec_minmax
,
987 .procname
= "compat-log",
989 .maxlen
= sizeof (int),
991 .proc_handler
= proc_dointvec
,
994 #ifdef CONFIG_RT_MUTEXES
996 .procname
= "max_lock_depth",
997 .data
= &max_lock_depth
,
998 .maxlen
= sizeof(int),
1000 .proc_handler
= proc_dointvec
,
1004 .procname
= "poweroff_cmd",
1005 .data
= &poweroff_cmd
,
1006 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1008 .proc_handler
= proc_dostring
,
1014 .child
= key_sysctls
,
1017 #ifdef CONFIG_RCU_TORTURE_TEST
1019 .procname
= "rcutorture_runnable",
1020 .data
= &rcutorture_runnable
,
1021 .maxlen
= sizeof(int),
1023 .proc_handler
= proc_dointvec
,
1026 #ifdef CONFIG_PERF_EVENTS
1028 * User-space scripts rely on the existence of this file
1029 * as a feature check for perf_events being enabled.
1031 * So it's an ABI, do not remove!
1034 .procname
= "perf_event_paranoid",
1035 .data
= &sysctl_perf_event_paranoid
,
1036 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1038 .proc_handler
= proc_dointvec
,
1041 .procname
= "perf_event_mlock_kb",
1042 .data
= &sysctl_perf_event_mlock
,
1043 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1045 .proc_handler
= proc_dointvec
,
1048 .procname
= "perf_event_max_sample_rate",
1049 .data
= &sysctl_perf_event_sample_rate
,
1050 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1052 .proc_handler
= perf_proc_update_handler
,
1055 #ifdef CONFIG_KMEMCHECK
1057 .procname
= "kmemcheck",
1058 .data
= &kmemcheck_enabled
,
1059 .maxlen
= sizeof(int),
1061 .proc_handler
= proc_dointvec
,
1066 .procname
= "blk_iopoll",
1067 .data
= &blk_iopoll_enabled
,
1068 .maxlen
= sizeof(int),
1070 .proc_handler
= proc_dointvec
,
1076 static struct ctl_table vm_table
[] = {
1078 .procname
= "overcommit_memory",
1079 .data
= &sysctl_overcommit_memory
,
1080 .maxlen
= sizeof(sysctl_overcommit_memory
),
1082 .proc_handler
= proc_dointvec_minmax
,
1087 .procname
= "panic_on_oom",
1088 .data
= &sysctl_panic_on_oom
,
1089 .maxlen
= sizeof(sysctl_panic_on_oom
),
1091 .proc_handler
= proc_dointvec_minmax
,
1096 .procname
= "oom_kill_allocating_task",
1097 .data
= &sysctl_oom_kill_allocating_task
,
1098 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1100 .proc_handler
= proc_dointvec
,
1103 .procname
= "oom_dump_tasks",
1104 .data
= &sysctl_oom_dump_tasks
,
1105 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1107 .proc_handler
= proc_dointvec
,
1110 .procname
= "overcommit_ratio",
1111 .data
= &sysctl_overcommit_ratio
,
1112 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1114 .proc_handler
= proc_dointvec
,
1117 .procname
= "page-cluster",
1118 .data
= &page_cluster
,
1119 .maxlen
= sizeof(int),
1121 .proc_handler
= proc_dointvec_minmax
,
1125 .procname
= "dirty_background_ratio",
1126 .data
= &dirty_background_ratio
,
1127 .maxlen
= sizeof(dirty_background_ratio
),
1129 .proc_handler
= dirty_background_ratio_handler
,
1131 .extra2
= &one_hundred
,
1134 .procname
= "dirty_background_bytes",
1135 .data
= &dirty_background_bytes
,
1136 .maxlen
= sizeof(dirty_background_bytes
),
1138 .proc_handler
= dirty_background_bytes_handler
,
1142 .procname
= "dirty_ratio",
1143 .data
= &vm_dirty_ratio
,
1144 .maxlen
= sizeof(vm_dirty_ratio
),
1146 .proc_handler
= dirty_ratio_handler
,
1148 .extra2
= &one_hundred
,
1151 .procname
= "dirty_bytes",
1152 .data
= &vm_dirty_bytes
,
1153 .maxlen
= sizeof(vm_dirty_bytes
),
1155 .proc_handler
= dirty_bytes_handler
,
1156 .extra1
= &dirty_bytes_min
,
1159 .procname
= "dirty_writeback_centisecs",
1160 .data
= &dirty_writeback_interval
,
1161 .maxlen
= sizeof(dirty_writeback_interval
),
1163 .proc_handler
= dirty_writeback_centisecs_handler
,
1166 .procname
= "dirty_expire_centisecs",
1167 .data
= &dirty_expire_interval
,
1168 .maxlen
= sizeof(dirty_expire_interval
),
1170 .proc_handler
= proc_dointvec_minmax
,
1174 .procname
= "nr_pdflush_threads",
1175 .mode
= 0444 /* read-only */,
1176 .proc_handler
= pdflush_proc_obsolete
,
1179 .procname
= "swappiness",
1180 .data
= &vm_swappiness
,
1181 .maxlen
= sizeof(vm_swappiness
),
1183 .proc_handler
= proc_dointvec_minmax
,
1185 .extra2
= &one_hundred
,
1187 #ifdef CONFIG_HUGETLB_PAGE
1189 .procname
= "nr_hugepages",
1191 .maxlen
= sizeof(unsigned long),
1193 .proc_handler
= hugetlb_sysctl_handler
,
1194 .extra1
= (void *)&hugetlb_zero
,
1195 .extra2
= (void *)&hugetlb_infinity
,
1199 .procname
= "nr_hugepages_mempolicy",
1201 .maxlen
= sizeof(unsigned long),
1203 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1204 .extra1
= (void *)&hugetlb_zero
,
1205 .extra2
= (void *)&hugetlb_infinity
,
1209 .procname
= "hugetlb_shm_group",
1210 .data
= &sysctl_hugetlb_shm_group
,
1211 .maxlen
= sizeof(gid_t
),
1213 .proc_handler
= proc_dointvec
,
1216 .procname
= "hugepages_treat_as_movable",
1217 .data
= &hugepages_treat_as_movable
,
1218 .maxlen
= sizeof(int),
1220 .proc_handler
= hugetlb_treat_movable_handler
,
1223 .procname
= "nr_overcommit_hugepages",
1225 .maxlen
= sizeof(unsigned long),
1227 .proc_handler
= hugetlb_overcommit_handler
,
1228 .extra1
= (void *)&hugetlb_zero
,
1229 .extra2
= (void *)&hugetlb_infinity
,
1233 .procname
= "lowmem_reserve_ratio",
1234 .data
= &sysctl_lowmem_reserve_ratio
,
1235 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1237 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1240 .procname
= "drop_caches",
1241 .data
= &sysctl_drop_caches
,
1242 .maxlen
= sizeof(int),
1244 .proc_handler
= drop_caches_sysctl_handler
,
1248 #ifdef CONFIG_COMPACTION
1250 .procname
= "compact_memory",
1251 .data
= &sysctl_compact_memory
,
1252 .maxlen
= sizeof(int),
1254 .proc_handler
= sysctl_compaction_handler
,
1257 .procname
= "extfrag_threshold",
1258 .data
= &sysctl_extfrag_threshold
,
1259 .maxlen
= sizeof(int),
1261 .proc_handler
= sysctl_extfrag_handler
,
1262 .extra1
= &min_extfrag_threshold
,
1263 .extra2
= &max_extfrag_threshold
,
1266 #endif /* CONFIG_COMPACTION */
1268 .procname
= "min_free_kbytes",
1269 .data
= &min_free_kbytes
,
1270 .maxlen
= sizeof(min_free_kbytes
),
1272 .proc_handler
= min_free_kbytes_sysctl_handler
,
1276 .procname
= "percpu_pagelist_fraction",
1277 .data
= &percpu_pagelist_fraction
,
1278 .maxlen
= sizeof(percpu_pagelist_fraction
),
1280 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1281 .extra1
= &min_percpu_pagelist_fract
,
1285 .procname
= "max_map_count",
1286 .data
= &sysctl_max_map_count
,
1287 .maxlen
= sizeof(sysctl_max_map_count
),
1289 .proc_handler
= proc_dointvec_minmax
,
1294 .procname
= "nr_trim_pages",
1295 .data
= &sysctl_nr_trim_pages
,
1296 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1298 .proc_handler
= proc_dointvec_minmax
,
1303 .procname
= "laptop_mode",
1304 .data
= &laptop_mode
,
1305 .maxlen
= sizeof(laptop_mode
),
1307 .proc_handler
= proc_dointvec_jiffies
,
1310 .procname
= "block_dump",
1311 .data
= &block_dump
,
1312 .maxlen
= sizeof(block_dump
),
1314 .proc_handler
= proc_dointvec
,
1318 .procname
= "vfs_cache_pressure",
1319 .data
= &sysctl_vfs_cache_pressure
,
1320 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1322 .proc_handler
= proc_dointvec
,
1325 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1327 .procname
= "legacy_va_layout",
1328 .data
= &sysctl_legacy_va_layout
,
1329 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1331 .proc_handler
= proc_dointvec
,
1337 .procname
= "zone_reclaim_mode",
1338 .data
= &zone_reclaim_mode
,
1339 .maxlen
= sizeof(zone_reclaim_mode
),
1341 .proc_handler
= proc_dointvec
,
1345 .procname
= "min_unmapped_ratio",
1346 .data
= &sysctl_min_unmapped_ratio
,
1347 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1349 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1351 .extra2
= &one_hundred
,
1354 .procname
= "min_slab_ratio",
1355 .data
= &sysctl_min_slab_ratio
,
1356 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1358 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1360 .extra2
= &one_hundred
,
1365 .procname
= "stat_interval",
1366 .data
= &sysctl_stat_interval
,
1367 .maxlen
= sizeof(sysctl_stat_interval
),
1369 .proc_handler
= proc_dointvec_jiffies
,
1374 .procname
= "mmap_min_addr",
1375 .data
= &dac_mmap_min_addr
,
1376 .maxlen
= sizeof(unsigned long),
1378 .proc_handler
= mmap_min_addr_handler
,
1383 .procname
= "numa_zonelist_order",
1384 .data
= &numa_zonelist_order
,
1385 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1387 .proc_handler
= numa_zonelist_order_handler
,
1390 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1391 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1393 .procname
= "vdso_enabled",
1394 .data
= &vdso_enabled
,
1395 .maxlen
= sizeof(vdso_enabled
),
1397 .proc_handler
= proc_dointvec
,
1401 #ifdef CONFIG_HIGHMEM
1403 .procname
= "highmem_is_dirtyable",
1404 .data
= &vm_highmem_is_dirtyable
,
1405 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1407 .proc_handler
= proc_dointvec_minmax
,
1413 .procname
= "scan_unevictable_pages",
1414 .data
= &scan_unevictable_pages
,
1415 .maxlen
= sizeof(scan_unevictable_pages
),
1417 .proc_handler
= scan_unevictable_handler
,
1419 #ifdef CONFIG_MEMORY_FAILURE
1421 .procname
= "memory_failure_early_kill",
1422 .data
= &sysctl_memory_failure_early_kill
,
1423 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1425 .proc_handler
= proc_dointvec_minmax
,
1430 .procname
= "memory_failure_recovery",
1431 .data
= &sysctl_memory_failure_recovery
,
1432 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1434 .proc_handler
= proc_dointvec_minmax
,
1440 .procname
= "user_reserve_kbytes",
1441 .data
= &sysctl_user_reserve_kbytes
,
1442 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1444 .proc_handler
= proc_doulongvec_minmax
,
1447 .procname
= "admin_reserve_kbytes",
1448 .data
= &sysctl_admin_reserve_kbytes
,
1449 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1451 .proc_handler
= proc_doulongvec_minmax
,
1456 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1457 static struct ctl_table binfmt_misc_table
[] = {
1462 static struct ctl_table fs_table
[] = {
1464 .procname
= "inode-nr",
1465 .data
= &inodes_stat
,
1466 .maxlen
= 2*sizeof(int),
1468 .proc_handler
= proc_nr_inodes
,
1471 .procname
= "inode-state",
1472 .data
= &inodes_stat
,
1473 .maxlen
= 7*sizeof(int),
1475 .proc_handler
= proc_nr_inodes
,
1478 .procname
= "file-nr",
1479 .data
= &files_stat
,
1480 .maxlen
= sizeof(files_stat
),
1482 .proc_handler
= proc_nr_files
,
1485 .procname
= "file-max",
1486 .data
= &files_stat
.max_files
,
1487 .maxlen
= sizeof(files_stat
.max_files
),
1489 .proc_handler
= proc_doulongvec_minmax
,
1492 .procname
= "nr_open",
1493 .data
= &sysctl_nr_open
,
1494 .maxlen
= sizeof(int),
1496 .proc_handler
= proc_dointvec_minmax
,
1497 .extra1
= &sysctl_nr_open_min
,
1498 .extra2
= &sysctl_nr_open_max
,
1501 .procname
= "dentry-state",
1502 .data
= &dentry_stat
,
1503 .maxlen
= 6*sizeof(int),
1505 .proc_handler
= proc_nr_dentry
,
1508 .procname
= "overflowuid",
1509 .data
= &fs_overflowuid
,
1510 .maxlen
= sizeof(int),
1512 .proc_handler
= proc_dointvec_minmax
,
1513 .extra1
= &minolduid
,
1514 .extra2
= &maxolduid
,
1517 .procname
= "overflowgid",
1518 .data
= &fs_overflowgid
,
1519 .maxlen
= sizeof(int),
1521 .proc_handler
= proc_dointvec_minmax
,
1522 .extra1
= &minolduid
,
1523 .extra2
= &maxolduid
,
1525 #ifdef CONFIG_FILE_LOCKING
1527 .procname
= "leases-enable",
1528 .data
= &leases_enable
,
1529 .maxlen
= sizeof(int),
1531 .proc_handler
= proc_dointvec
,
1534 #ifdef CONFIG_DNOTIFY
1536 .procname
= "dir-notify-enable",
1537 .data
= &dir_notify_enable
,
1538 .maxlen
= sizeof(int),
1540 .proc_handler
= proc_dointvec
,
1544 #ifdef CONFIG_FILE_LOCKING
1546 .procname
= "lease-break-time",
1547 .data
= &lease_break_time
,
1548 .maxlen
= sizeof(int),
1550 .proc_handler
= proc_dointvec
,
1555 .procname
= "aio-nr",
1557 .maxlen
= sizeof(aio_nr
),
1559 .proc_handler
= proc_doulongvec_minmax
,
1562 .procname
= "aio-max-nr",
1563 .data
= &aio_max_nr
,
1564 .maxlen
= sizeof(aio_max_nr
),
1566 .proc_handler
= proc_doulongvec_minmax
,
1568 #endif /* CONFIG_AIO */
1569 #ifdef CONFIG_INOTIFY_USER
1571 .procname
= "inotify",
1573 .child
= inotify_table
,
1578 .procname
= "epoll",
1580 .child
= epoll_table
,
1585 .procname
= "protected_symlinks",
1586 .data
= &sysctl_protected_symlinks
,
1587 .maxlen
= sizeof(int),
1589 .proc_handler
= proc_dointvec_minmax
,
1594 .procname
= "protected_hardlinks",
1595 .data
= &sysctl_protected_hardlinks
,
1596 .maxlen
= sizeof(int),
1598 .proc_handler
= proc_dointvec_minmax
,
1603 .procname
= "suid_dumpable",
1604 .data
= &suid_dumpable
,
1605 .maxlen
= sizeof(int),
1607 .proc_handler
= proc_dointvec_minmax_coredump
,
1611 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1613 .procname
= "binfmt_misc",
1615 .child
= binfmt_misc_table
,
1619 .procname
= "pipe-max-size",
1620 .data
= &pipe_max_size
,
1621 .maxlen
= sizeof(int),
1623 .proc_handler
= &pipe_proc_fn
,
1624 .extra1
= &pipe_min_size
,
1629 static struct ctl_table debug_table
[] = {
1630 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1632 .procname
= "exception-trace",
1633 .data
= &show_unhandled_signals
,
1634 .maxlen
= sizeof(int),
1636 .proc_handler
= proc_dointvec
1639 #if defined(CONFIG_OPTPROBES)
1641 .procname
= "kprobes-optimization",
1642 .data
= &sysctl_kprobes_optimization
,
1643 .maxlen
= sizeof(int),
1645 .proc_handler
= proc_kprobes_optimization_handler
,
1653 static struct ctl_table dev_table
[] = {
1657 int __init
sysctl_init(void)
1659 struct ctl_table_header
*hdr
;
1661 hdr
= register_sysctl_table(sysctl_base_table
);
1662 kmemleak_not_leak(hdr
);
1666 #endif /* CONFIG_SYSCTL */
1672 #ifdef CONFIG_PROC_SYSCTL
1674 static int _proc_do_string(void* data
, int maxlen
, int write
,
1675 void __user
*buffer
,
1676 size_t *lenp
, loff_t
*ppos
)
1682 if (!data
|| !maxlen
|| !*lenp
) {
1690 while (len
< *lenp
) {
1691 if (get_user(c
, p
++))
1693 if (c
== 0 || c
== '\n')
1699 if(copy_from_user(data
, buffer
, len
))
1701 ((char *) data
)[len
] = 0;
1719 if(copy_to_user(buffer
, data
, len
))
1722 if(put_user('\n', ((char __user
*) buffer
) + len
))
1733 * proc_dostring - read a string sysctl
1734 * @table: the sysctl table
1735 * @write: %TRUE if this is a write to the sysctl file
1736 * @buffer: the user buffer
1737 * @lenp: the size of the user buffer
1738 * @ppos: file position
1740 * Reads/writes a string from/to the user buffer. If the kernel
1741 * buffer provided is not large enough to hold the string, the
1742 * string is truncated. The copied string is %NULL-terminated.
1743 * If the string is being read by the user process, it is copied
1744 * and a newline '\n' is added. It is truncated if the buffer is
1747 * Returns 0 on success.
1749 int proc_dostring(struct ctl_table
*table
, int write
,
1750 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1752 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1753 buffer
, lenp
, ppos
);
1756 static size_t proc_skip_spaces(char **buf
)
1759 char *tmp
= skip_spaces(*buf
);
1765 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1775 #define TMPBUFLEN 22
1777 * proc_get_long - reads an ASCII formatted integer from a user buffer
1779 * @buf: a kernel buffer
1780 * @size: size of the kernel buffer
1781 * @val: this is where the number will be stored
1782 * @neg: set to %TRUE if number is negative
1783 * @perm_tr: a vector which contains the allowed trailers
1784 * @perm_tr_len: size of the perm_tr vector
1785 * @tr: pointer to store the trailer character
1787 * In case of success %0 is returned and @buf and @size are updated with
1788 * the amount of bytes read. If @tr is non-NULL and a trailing
1789 * character exists (size is non-zero after returning from this
1790 * function), @tr is updated with the trailing character.
1792 static int proc_get_long(char **buf
, size_t *size
,
1793 unsigned long *val
, bool *neg
,
1794 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1797 char *p
, tmp
[TMPBUFLEN
];
1803 if (len
> TMPBUFLEN
- 1)
1804 len
= TMPBUFLEN
- 1;
1806 memcpy(tmp
, *buf
, len
);
1810 if (*p
== '-' && *size
> 1) {
1818 *val
= simple_strtoul(p
, &p
, 0);
1822 /* We don't know if the next char is whitespace thus we may accept
1823 * invalid integers (e.g. 1234...a) or two integers instead of one
1824 * (e.g. 123...1). So lets not allow such large numbers. */
1825 if (len
== TMPBUFLEN
- 1)
1828 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1831 if (tr
&& (len
< *size
))
1841 * proc_put_long - converts an integer to a decimal ASCII formatted string
1843 * @buf: the user buffer
1844 * @size: the size of the user buffer
1845 * @val: the integer to be converted
1846 * @neg: sign of the number, %TRUE for negative
1848 * In case of success %0 is returned and @buf and @size are updated with
1849 * the amount of bytes written.
1851 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1855 char tmp
[TMPBUFLEN
], *p
= tmp
;
1857 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1861 if (copy_to_user(*buf
, tmp
, len
))
1869 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1872 char __user
**buffer
= (char __user
**)buf
;
1873 if (put_user(c
, *buffer
))
1875 (*size
)--, (*buffer
)++;
1881 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1883 int write
, void *data
)
1886 *valp
= *negp
? -*lvalp
: *lvalp
;
1891 *lvalp
= (unsigned long)-val
;
1894 *lvalp
= (unsigned long)val
;
1900 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1902 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1903 int write
, void __user
*buffer
,
1904 size_t *lenp
, loff_t
*ppos
,
1905 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1906 int write
, void *data
),
1909 int *i
, vleft
, first
= 1, err
= 0;
1910 unsigned long page
= 0;
1914 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1919 i
= (int *) tbl_data
;
1920 vleft
= table
->maxlen
/ sizeof(*i
);
1924 conv
= do_proc_dointvec_conv
;
1927 if (left
> PAGE_SIZE
- 1)
1928 left
= PAGE_SIZE
- 1;
1929 page
= __get_free_page(GFP_TEMPORARY
);
1930 kbuf
= (char *) page
;
1933 if (copy_from_user(kbuf
, buffer
, left
)) {
1940 for (; left
&& vleft
--; i
++, first
=0) {
1945 left
-= proc_skip_spaces(&kbuf
);
1949 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1951 sizeof(proc_wspace_sep
), NULL
);
1954 if (conv(&neg
, &lval
, i
, 1, data
)) {
1959 if (conv(&neg
, &lval
, i
, 0, data
)) {
1964 err
= proc_put_char(&buffer
, &left
, '\t');
1967 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1973 if (!write
&& !first
&& left
&& !err
)
1974 err
= proc_put_char(&buffer
, &left
, '\n');
1975 if (write
&& !err
&& left
)
1976 left
-= proc_skip_spaces(&kbuf
);
1981 return err
? : -EINVAL
;
1988 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1989 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1990 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1991 int write
, void *data
),
1994 return __do_proc_dointvec(table
->data
, table
, write
,
1995 buffer
, lenp
, ppos
, conv
, data
);
1999 * proc_dointvec - read a vector of integers
2000 * @table: the sysctl table
2001 * @write: %TRUE if this is a write to the sysctl file
2002 * @buffer: the user buffer
2003 * @lenp: the size of the user buffer
2004 * @ppos: file position
2006 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2007 * values from/to the user buffer, treated as an ASCII string.
2009 * Returns 0 on success.
2011 int proc_dointvec(struct ctl_table
*table
, int write
,
2012 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2014 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2019 * Taint values can only be increased
2020 * This means we can safely use a temporary.
2022 static int proc_taint(struct ctl_table
*table
, int write
,
2023 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2026 unsigned long tmptaint
= get_taint();
2029 if (write
&& !capable(CAP_SYS_ADMIN
))
2034 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2040 * Poor man's atomic or. Not worth adding a primitive
2041 * to everyone's atomic.h for this
2044 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2045 if ((tmptaint
>> i
) & 1)
2046 add_taint(i
, LOCKDEP_STILL_OK
);
2053 #ifdef CONFIG_PRINTK
2054 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2055 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2057 if (write
&& !capable(CAP_SYS_ADMIN
))
2060 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2064 struct do_proc_dointvec_minmax_conv_param
{
2069 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2071 int write
, void *data
)
2073 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2075 int val
= *negp
? -*lvalp
: *lvalp
;
2076 if ((param
->min
&& *param
->min
> val
) ||
2077 (param
->max
&& *param
->max
< val
))
2084 *lvalp
= (unsigned long)-val
;
2087 *lvalp
= (unsigned long)val
;
2094 * proc_dointvec_minmax - read a vector of integers with min/max values
2095 * @table: the sysctl table
2096 * @write: %TRUE if this is a write to the sysctl file
2097 * @buffer: the user buffer
2098 * @lenp: the size of the user buffer
2099 * @ppos: file position
2101 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2102 * values from/to the user buffer, treated as an ASCII string.
2104 * This routine will ensure the values are within the range specified by
2105 * table->extra1 (min) and table->extra2 (max).
2107 * Returns 0 on success.
2109 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2110 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2112 struct do_proc_dointvec_minmax_conv_param param
= {
2113 .min
= (int *) table
->extra1
,
2114 .max
= (int *) table
->extra2
,
2116 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2117 do_proc_dointvec_minmax_conv
, ¶m
);
2120 static void validate_coredump_safety(void)
2122 #ifdef CONFIG_COREDUMP
2123 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2124 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2125 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2126 "suid_dumpable=2. Pipe handler or fully qualified "\
2127 "core dump path required.\n");
2132 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2133 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2135 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2137 validate_coredump_safety();
2141 #ifdef CONFIG_COREDUMP
2142 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2143 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2145 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2147 validate_coredump_safety();
2152 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2153 void __user
*buffer
,
2154 size_t *lenp
, loff_t
*ppos
,
2155 unsigned long convmul
,
2156 unsigned long convdiv
)
2158 unsigned long *i
, *min
, *max
;
2159 int vleft
, first
= 1, err
= 0;
2160 unsigned long page
= 0;
2164 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2169 i
= (unsigned long *) data
;
2170 min
= (unsigned long *) table
->extra1
;
2171 max
= (unsigned long *) table
->extra2
;
2172 vleft
= table
->maxlen
/ sizeof(unsigned long);
2176 if (left
> PAGE_SIZE
- 1)
2177 left
= PAGE_SIZE
- 1;
2178 page
= __get_free_page(GFP_TEMPORARY
);
2179 kbuf
= (char *) page
;
2182 if (copy_from_user(kbuf
, buffer
, left
)) {
2189 for (; left
&& vleft
--; i
++, first
= 0) {
2195 left
-= proc_skip_spaces(&kbuf
);
2197 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2199 sizeof(proc_wspace_sep
), NULL
);
2204 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2208 val
= convdiv
* (*i
) / convmul
;
2210 err
= proc_put_char(&buffer
, &left
, '\t');
2211 err
= proc_put_long(&buffer
, &left
, val
, false);
2217 if (!write
&& !first
&& left
&& !err
)
2218 err
= proc_put_char(&buffer
, &left
, '\n');
2220 left
-= proc_skip_spaces(&kbuf
);
2225 return err
? : -EINVAL
;
2232 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2233 void __user
*buffer
,
2234 size_t *lenp
, loff_t
*ppos
,
2235 unsigned long convmul
,
2236 unsigned long convdiv
)
2238 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2239 buffer
, lenp
, ppos
, convmul
, convdiv
);
2243 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2244 * @table: the sysctl table
2245 * @write: %TRUE if this is a write to the sysctl file
2246 * @buffer: the user buffer
2247 * @lenp: the size of the user buffer
2248 * @ppos: file position
2250 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2251 * values from/to the user buffer, treated as an ASCII string.
2253 * This routine will ensure the values are within the range specified by
2254 * table->extra1 (min) and table->extra2 (max).
2256 * Returns 0 on success.
2258 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2259 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2261 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2265 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2266 * @table: the sysctl table
2267 * @write: %TRUE if this is a write to the sysctl file
2268 * @buffer: the user buffer
2269 * @lenp: the size of the user buffer
2270 * @ppos: file position
2272 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2273 * values from/to the user buffer, treated as an ASCII string. The values
2274 * are treated as milliseconds, and converted to jiffies when they are stored.
2276 * This routine will ensure the values are within the range specified by
2277 * table->extra1 (min) and table->extra2 (max).
2279 * Returns 0 on success.
2281 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2282 void __user
*buffer
,
2283 size_t *lenp
, loff_t
*ppos
)
2285 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2286 lenp
, ppos
, HZ
, 1000l);
2290 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2292 int write
, void *data
)
2295 if (*lvalp
> LONG_MAX
/ HZ
)
2297 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2303 lval
= (unsigned long)-val
;
2306 lval
= (unsigned long)val
;
2313 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2315 int write
, void *data
)
2318 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2320 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2326 lval
= (unsigned long)-val
;
2329 lval
= (unsigned long)val
;
2331 *lvalp
= jiffies_to_clock_t(lval
);
2336 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2338 int write
, void *data
)
2341 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2347 lval
= (unsigned long)-val
;
2350 lval
= (unsigned long)val
;
2352 *lvalp
= jiffies_to_msecs(lval
);
2358 * proc_dointvec_jiffies - read a vector of integers as seconds
2359 * @table: the sysctl table
2360 * @write: %TRUE if this is a write to the sysctl file
2361 * @buffer: the user buffer
2362 * @lenp: the size of the user buffer
2363 * @ppos: file position
2365 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2366 * values from/to the user buffer, treated as an ASCII string.
2367 * The values read are assumed to be in seconds, and are converted into
2370 * Returns 0 on success.
2372 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2373 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2375 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2376 do_proc_dointvec_jiffies_conv
,NULL
);
2380 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2381 * @table: the sysctl table
2382 * @write: %TRUE if this is a write to the sysctl file
2383 * @buffer: the user buffer
2384 * @lenp: the size of the user buffer
2385 * @ppos: pointer to the file position
2387 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2388 * values from/to the user buffer, treated as an ASCII string.
2389 * The values read are assumed to be in 1/USER_HZ seconds, and
2390 * are converted into jiffies.
2392 * Returns 0 on success.
2394 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2395 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2397 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2398 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2402 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2403 * @table: the sysctl table
2404 * @write: %TRUE if this is a write to the sysctl file
2405 * @buffer: the user buffer
2406 * @lenp: the size of the user buffer
2407 * @ppos: file position
2408 * @ppos: the current position in the file
2410 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2411 * values from/to the user buffer, treated as an ASCII string.
2412 * The values read are assumed to be in 1/1000 seconds, and
2413 * are converted into jiffies.
2415 * Returns 0 on success.
2417 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2418 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2420 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2421 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2424 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2425 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2427 struct pid
*new_pid
;
2431 tmp
= pid_vnr(cad_pid
);
2433 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2434 lenp
, ppos
, NULL
, NULL
);
2438 new_pid
= find_get_pid(tmp
);
2442 put_pid(xchg(&cad_pid
, new_pid
));
2447 * proc_do_large_bitmap - read/write from/to a large bitmap
2448 * @table: the sysctl table
2449 * @write: %TRUE if this is a write to the sysctl file
2450 * @buffer: the user buffer
2451 * @lenp: the size of the user buffer
2452 * @ppos: file position
2454 * The bitmap is stored at table->data and the bitmap length (in bits)
2457 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2458 * large bitmaps may be represented in a compact manner. Writing into
2459 * the file will clear the bitmap then update it with the given input.
2461 * Returns 0 on success.
2463 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2464 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2468 size_t left
= *lenp
;
2469 unsigned long bitmap_len
= table
->maxlen
;
2470 unsigned long *bitmap
= (unsigned long *) table
->data
;
2471 unsigned long *tmp_bitmap
= NULL
;
2472 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2474 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2480 unsigned long page
= 0;
2483 if (left
> PAGE_SIZE
- 1)
2484 left
= PAGE_SIZE
- 1;
2486 page
= __get_free_page(GFP_TEMPORARY
);
2487 kbuf
= (char *) page
;
2490 if (copy_from_user(kbuf
, buffer
, left
)) {
2496 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2502 proc_skip_char(&kbuf
, &left
, '\n');
2503 while (!err
&& left
) {
2504 unsigned long val_a
, val_b
;
2507 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2511 if (val_a
>= bitmap_len
|| neg
) {
2523 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2524 &neg
, tr_b
, sizeof(tr_b
),
2528 if (val_b
>= bitmap_len
|| neg
||
2539 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2541 proc_skip_char(&kbuf
, &left
, '\n');
2545 unsigned long bit_a
, bit_b
= 0;
2548 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2549 if (bit_a
>= bitmap_len
)
2551 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2555 err
= proc_put_char(&buffer
, &left
, ',');
2559 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2562 if (bit_a
!= bit_b
) {
2563 err
= proc_put_char(&buffer
, &left
, '-');
2566 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2574 err
= proc_put_char(&buffer
, &left
, '\n');
2580 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2582 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2594 #else /* CONFIG_PROC_SYSCTL */
2596 int proc_dostring(struct ctl_table
*table
, int write
,
2597 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2602 int proc_dointvec(struct ctl_table
*table
, int write
,
2603 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2608 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2609 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2614 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2615 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2620 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2621 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2626 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2627 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2632 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2633 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2638 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2639 void __user
*buffer
,
2640 size_t *lenp
, loff_t
*ppos
)
2646 #endif /* CONFIG_PROC_SYSCTL */
2649 * No sense putting this after each symbol definition, twice,
2650 * exception granted :-)
2652 EXPORT_SYMBOL(proc_dointvec
);
2653 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2654 EXPORT_SYMBOL(proc_dointvec_minmax
);
2655 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2656 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2657 EXPORT_SYMBOL(proc_dostring
);
2658 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2659 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);