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;
126 static int __maybe_unused one
= 1;
127 static int __maybe_unused two
= 2;
128 static int __maybe_unused three
= 3;
129 static unsigned long one_ul
= 1;
130 static int one_hundred
= 100;
132 static int ten_thousand
= 10000;
135 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
136 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
138 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
139 static int maxolduid
= 65535;
140 static int minolduid
;
141 static int min_percpu_pagelist_fract
= 8;
143 static int ngroups_max
= NGROUPS_MAX
;
144 static const int cap_last_cap
= CAP_LAST_CAP
;
146 #ifdef CONFIG_INOTIFY_USER
147 #include <linux/inotify.h>
152 #ifdef CONFIG_SPARC64
153 extern int sysctl_tsb_ratio
;
157 extern int pwrsw_enabled
;
160 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
161 extern int unaligned_enabled
;
165 extern int unaligned_dump_stack
;
168 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
169 extern int no_unaligned_warning
;
172 #ifdef CONFIG_PROC_SYSCTL
173 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
174 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
175 static int proc_taint(struct ctl_table
*table
, int write
,
176 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
180 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
181 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
184 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
185 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
186 #ifdef CONFIG_COREDUMP
187 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
188 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
191 #ifdef CONFIG_MAGIC_SYSRQ
192 /* Note: sysrq code uses it's own private copy */
193 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
195 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
196 void __user
*buffer
, size_t *lenp
,
201 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
206 sysrq_toggle_support(__sysrq_enabled
);
213 static struct ctl_table kern_table
[];
214 static struct ctl_table vm_table
[];
215 static struct ctl_table fs_table
[];
216 static struct ctl_table debug_table
[];
217 static struct ctl_table dev_table
[];
218 extern struct ctl_table random_table
[];
220 extern struct ctl_table epoll_table
[];
223 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
224 int sysctl_legacy_va_layout
;
227 /* The default sysctl tables: */
229 static struct ctl_table sysctl_base_table
[] = {
231 .procname
= "kernel",
248 .child
= debug_table
,
258 #ifdef CONFIG_SCHED_DEBUG
259 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
260 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
261 static int min_wakeup_granularity_ns
; /* 0 usecs */
262 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
264 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
265 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
266 #endif /* CONFIG_SMP */
267 #endif /* CONFIG_SCHED_DEBUG */
269 #ifdef CONFIG_COMPACTION
270 static int min_extfrag_threshold
;
271 static int max_extfrag_threshold
= 1000;
274 static struct ctl_table kern_table
[] = {
276 .procname
= "sched_child_runs_first",
277 .data
= &sysctl_sched_child_runs_first
,
278 .maxlen
= sizeof(unsigned int),
280 .proc_handler
= proc_dointvec
,
282 #ifdef CONFIG_SCHED_DEBUG
284 .procname
= "sched_min_granularity_ns",
285 .data
= &sysctl_sched_min_granularity
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= sched_proc_update_handler
,
289 .extra1
= &min_sched_granularity_ns
,
290 .extra2
= &max_sched_granularity_ns
,
293 .procname
= "sched_latency_ns",
294 .data
= &sysctl_sched_latency
,
295 .maxlen
= sizeof(unsigned int),
297 .proc_handler
= sched_proc_update_handler
,
298 .extra1
= &min_sched_granularity_ns
,
299 .extra2
= &max_sched_granularity_ns
,
302 .procname
= "sched_wakeup_granularity_ns",
303 .data
= &sysctl_sched_wakeup_granularity
,
304 .maxlen
= sizeof(unsigned int),
306 .proc_handler
= sched_proc_update_handler
,
307 .extra1
= &min_wakeup_granularity_ns
,
308 .extra2
= &max_wakeup_granularity_ns
,
312 .procname
= "sched_tunable_scaling",
313 .data
= &sysctl_sched_tunable_scaling
,
314 .maxlen
= sizeof(enum sched_tunable_scaling
),
316 .proc_handler
= sched_proc_update_handler
,
317 .extra1
= &min_sched_tunable_scaling
,
318 .extra2
= &max_sched_tunable_scaling
,
321 .procname
= "sched_migration_cost_ns",
322 .data
= &sysctl_sched_migration_cost
,
323 .maxlen
= sizeof(unsigned int),
325 .proc_handler
= proc_dointvec
,
328 .procname
= "sched_nr_migrate",
329 .data
= &sysctl_sched_nr_migrate
,
330 .maxlen
= sizeof(unsigned int),
332 .proc_handler
= proc_dointvec
,
335 .procname
= "sched_time_avg_ms",
336 .data
= &sysctl_sched_time_avg
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= proc_dointvec
,
342 .procname
= "sched_shares_window_ns",
343 .data
= &sysctl_sched_shares_window
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= proc_dointvec
,
349 .procname
= "timer_migration",
350 .data
= &sysctl_timer_migration
,
351 .maxlen
= sizeof(unsigned int),
353 .proc_handler
= proc_dointvec_minmax
,
357 #endif /* CONFIG_SMP */
358 #ifdef CONFIG_NUMA_BALANCING
360 .procname
= "numa_balancing_scan_delay_ms",
361 .data
= &sysctl_numa_balancing_scan_delay
,
362 .maxlen
= sizeof(unsigned int),
364 .proc_handler
= proc_dointvec
,
367 .procname
= "numa_balancing_scan_period_min_ms",
368 .data
= &sysctl_numa_balancing_scan_period_min
,
369 .maxlen
= sizeof(unsigned int),
371 .proc_handler
= proc_dointvec
,
374 .procname
= "numa_balancing_scan_period_reset",
375 .data
= &sysctl_numa_balancing_scan_period_reset
,
376 .maxlen
= sizeof(unsigned int),
378 .proc_handler
= proc_dointvec
,
381 .procname
= "numa_balancing_scan_period_max_ms",
382 .data
= &sysctl_numa_balancing_scan_period_max
,
383 .maxlen
= sizeof(unsigned int),
385 .proc_handler
= proc_dointvec
,
388 .procname
= "numa_balancing_scan_size_mb",
389 .data
= &sysctl_numa_balancing_scan_size
,
390 .maxlen
= sizeof(unsigned int),
392 .proc_handler
= proc_dointvec
,
394 #endif /* CONFIG_NUMA_BALANCING */
395 #endif /* CONFIG_SCHED_DEBUG */
397 .procname
= "sched_rt_period_us",
398 .data
= &sysctl_sched_rt_period
,
399 .maxlen
= sizeof(unsigned int),
401 .proc_handler
= sched_rt_handler
,
404 .procname
= "sched_rt_runtime_us",
405 .data
= &sysctl_sched_rt_runtime
,
406 .maxlen
= sizeof(int),
408 .proc_handler
= sched_rt_handler
,
411 .procname
= "sched_rr_timeslice_ms",
412 .data
= &sched_rr_timeslice
,
413 .maxlen
= sizeof(int),
415 .proc_handler
= sched_rr_handler
,
417 #ifdef CONFIG_SCHED_AUTOGROUP
419 .procname
= "sched_autogroup_enabled",
420 .data
= &sysctl_sched_autogroup_enabled
,
421 .maxlen
= sizeof(unsigned int),
423 .proc_handler
= proc_dointvec_minmax
,
428 #ifdef CONFIG_CFS_BANDWIDTH
430 .procname
= "sched_cfs_bandwidth_slice_us",
431 .data
= &sysctl_sched_cfs_bandwidth_slice
,
432 .maxlen
= sizeof(unsigned int),
434 .proc_handler
= proc_dointvec_minmax
,
438 #ifdef CONFIG_PROVE_LOCKING
440 .procname
= "prove_locking",
441 .data
= &prove_locking
,
442 .maxlen
= sizeof(int),
444 .proc_handler
= proc_dointvec
,
447 #ifdef CONFIG_LOCK_STAT
449 .procname
= "lock_stat",
451 .maxlen
= sizeof(int),
453 .proc_handler
= proc_dointvec
,
458 .data
= &panic_timeout
,
459 .maxlen
= sizeof(int),
461 .proc_handler
= proc_dointvec
,
463 #ifdef CONFIG_COREDUMP
465 .procname
= "core_uses_pid",
466 .data
= &core_uses_pid
,
467 .maxlen
= sizeof(int),
469 .proc_handler
= proc_dointvec
,
472 .procname
= "core_pattern",
473 .data
= core_pattern
,
474 .maxlen
= CORENAME_MAX_SIZE
,
476 .proc_handler
= proc_dostring_coredump
,
479 .procname
= "core_pipe_limit",
480 .data
= &core_pipe_limit
,
481 .maxlen
= sizeof(unsigned int),
483 .proc_handler
= proc_dointvec
,
486 #ifdef CONFIG_PROC_SYSCTL
488 .procname
= "tainted",
489 .maxlen
= sizeof(long),
491 .proc_handler
= proc_taint
,
494 #ifdef CONFIG_LATENCYTOP
496 .procname
= "latencytop",
497 .data
= &latencytop_enabled
,
498 .maxlen
= sizeof(int),
500 .proc_handler
= proc_dointvec
,
503 #ifdef CONFIG_BLK_DEV_INITRD
505 .procname
= "real-root-dev",
506 .data
= &real_root_dev
,
507 .maxlen
= sizeof(int),
509 .proc_handler
= proc_dointvec
,
513 .procname
= "print-fatal-signals",
514 .data
= &print_fatal_signals
,
515 .maxlen
= sizeof(int),
517 .proc_handler
= proc_dointvec
,
521 .procname
= "reboot-cmd",
522 .data
= reboot_command
,
525 .proc_handler
= proc_dostring
,
528 .procname
= "stop-a",
529 .data
= &stop_a_enabled
,
530 .maxlen
= sizeof (int),
532 .proc_handler
= proc_dointvec
,
535 .procname
= "scons-poweroff",
536 .data
= &scons_pwroff
,
537 .maxlen
= sizeof (int),
539 .proc_handler
= proc_dointvec
,
542 #ifdef CONFIG_SPARC64
544 .procname
= "tsb-ratio",
545 .data
= &sysctl_tsb_ratio
,
546 .maxlen
= sizeof (int),
548 .proc_handler
= proc_dointvec
,
553 .procname
= "soft-power",
554 .data
= &pwrsw_enabled
,
555 .maxlen
= sizeof (int),
557 .proc_handler
= proc_dointvec
,
560 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
562 .procname
= "unaligned-trap",
563 .data
= &unaligned_enabled
,
564 .maxlen
= sizeof (int),
566 .proc_handler
= proc_dointvec
,
570 .procname
= "ctrl-alt-del",
572 .maxlen
= sizeof(int),
574 .proc_handler
= proc_dointvec
,
576 #ifdef CONFIG_FUNCTION_TRACER
578 .procname
= "ftrace_enabled",
579 .data
= &ftrace_enabled
,
580 .maxlen
= sizeof(int),
582 .proc_handler
= ftrace_enable_sysctl
,
585 #ifdef CONFIG_STACK_TRACER
587 .procname
= "stack_tracer_enabled",
588 .data
= &stack_tracer_enabled
,
589 .maxlen
= sizeof(int),
591 .proc_handler
= stack_trace_sysctl
,
594 #ifdef CONFIG_TRACING
596 .procname
= "ftrace_dump_on_oops",
597 .data
= &ftrace_dump_on_oops
,
598 .maxlen
= sizeof(int),
600 .proc_handler
= proc_dointvec
,
603 #ifdef CONFIG_MODULES
605 .procname
= "modprobe",
606 .data
= &modprobe_path
,
607 .maxlen
= KMOD_PATH_LEN
,
609 .proc_handler
= proc_dostring
,
612 .procname
= "modules_disabled",
613 .data
= &modules_disabled
,
614 .maxlen
= sizeof(int),
616 /* only handle a transition from default "0" to "1" */
617 .proc_handler
= proc_dointvec_minmax
,
624 .procname
= "hotplug",
625 .data
= &uevent_helper
,
626 .maxlen
= UEVENT_HELPER_PATH_LEN
,
628 .proc_handler
= proc_dostring
,
631 #ifdef CONFIG_CHR_DEV_SG
633 .procname
= "sg-big-buff",
634 .data
= &sg_big_buff
,
635 .maxlen
= sizeof (int),
637 .proc_handler
= proc_dointvec
,
640 #ifdef CONFIG_BSD_PROCESS_ACCT
644 .maxlen
= 3*sizeof(int),
646 .proc_handler
= proc_dointvec
,
649 #ifdef CONFIG_MAGIC_SYSRQ
652 .data
= &__sysrq_enabled
,
653 .maxlen
= sizeof (int),
655 .proc_handler
= sysrq_sysctl_handler
,
658 #ifdef CONFIG_PROC_SYSCTL
660 .procname
= "cad_pid",
662 .maxlen
= sizeof (int),
664 .proc_handler
= proc_do_cad_pid
,
668 .procname
= "threads-max",
669 .data
= &max_threads
,
670 .maxlen
= sizeof(int),
672 .proc_handler
= proc_dointvec
,
675 .procname
= "random",
677 .child
= random_table
,
680 .procname
= "usermodehelper",
682 .child
= usermodehelper_table
,
685 .procname
= "overflowuid",
686 .data
= &overflowuid
,
687 .maxlen
= sizeof(int),
689 .proc_handler
= proc_dointvec_minmax
,
690 .extra1
= &minolduid
,
691 .extra2
= &maxolduid
,
694 .procname
= "overflowgid",
695 .data
= &overflowgid
,
696 .maxlen
= sizeof(int),
698 .proc_handler
= proc_dointvec_minmax
,
699 .extra1
= &minolduid
,
700 .extra2
= &maxolduid
,
703 #ifdef CONFIG_MATHEMU
705 .procname
= "ieee_emulation_warnings",
706 .data
= &sysctl_ieee_emulation_warnings
,
707 .maxlen
= sizeof(int),
709 .proc_handler
= proc_dointvec
,
713 .procname
= "userprocess_debug",
714 .data
= &show_unhandled_signals
,
715 .maxlen
= sizeof(int),
717 .proc_handler
= proc_dointvec
,
721 .procname
= "pid_max",
723 .maxlen
= sizeof (int),
725 .proc_handler
= proc_dointvec_minmax
,
726 .extra1
= &pid_max_min
,
727 .extra2
= &pid_max_max
,
730 .procname
= "panic_on_oops",
731 .data
= &panic_on_oops
,
732 .maxlen
= sizeof(int),
734 .proc_handler
= proc_dointvec
,
736 #if defined CONFIG_PRINTK
738 .procname
= "printk",
739 .data
= &console_loglevel
,
740 .maxlen
= 4*sizeof(int),
742 .proc_handler
= proc_dointvec
,
745 .procname
= "printk_ratelimit",
746 .data
= &printk_ratelimit_state
.interval
,
747 .maxlen
= sizeof(int),
749 .proc_handler
= proc_dointvec_jiffies
,
752 .procname
= "printk_ratelimit_burst",
753 .data
= &printk_ratelimit_state
.burst
,
754 .maxlen
= sizeof(int),
756 .proc_handler
= proc_dointvec
,
759 .procname
= "printk_delay",
760 .data
= &printk_delay_msec
,
761 .maxlen
= sizeof(int),
763 .proc_handler
= proc_dointvec_minmax
,
765 .extra2
= &ten_thousand
,
768 .procname
= "dmesg_restrict",
769 .data
= &dmesg_restrict
,
770 .maxlen
= sizeof(int),
772 .proc_handler
= proc_dointvec_minmax_sysadmin
,
777 .procname
= "kptr_restrict",
778 .data
= &kptr_restrict
,
779 .maxlen
= sizeof(int),
781 .proc_handler
= proc_dointvec_minmax_sysadmin
,
787 .procname
= "ngroups_max",
788 .data
= &ngroups_max
,
789 .maxlen
= sizeof (int),
791 .proc_handler
= proc_dointvec
,
794 .procname
= "cap_last_cap",
795 .data
= (void *)&cap_last_cap
,
796 .maxlen
= sizeof(int),
798 .proc_handler
= proc_dointvec
,
800 #if defined(CONFIG_LOCKUP_DETECTOR)
802 .procname
= "watchdog",
803 .data
= &watchdog_enabled
,
804 .maxlen
= sizeof (int),
806 .proc_handler
= proc_dowatchdog
,
811 .procname
= "watchdog_thresh",
812 .data
= &watchdog_thresh
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= proc_dowatchdog
,
820 .procname
= "softlockup_panic",
821 .data
= &softlockup_panic
,
822 .maxlen
= sizeof(int),
824 .proc_handler
= proc_dointvec_minmax
,
829 .procname
= "nmi_watchdog",
830 .data
= &watchdog_enabled
,
831 .maxlen
= sizeof (int),
833 .proc_handler
= proc_dowatchdog
,
838 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
840 .procname
= "unknown_nmi_panic",
841 .data
= &unknown_nmi_panic
,
842 .maxlen
= sizeof (int),
844 .proc_handler
= proc_dointvec
,
847 #if defined(CONFIG_X86)
849 .procname
= "panic_on_unrecovered_nmi",
850 .data
= &panic_on_unrecovered_nmi
,
851 .maxlen
= sizeof(int),
853 .proc_handler
= proc_dointvec
,
856 .procname
= "panic_on_io_nmi",
857 .data
= &panic_on_io_nmi
,
858 .maxlen
= sizeof(int),
860 .proc_handler
= proc_dointvec
,
862 #ifdef CONFIG_DEBUG_STACKOVERFLOW
864 .procname
= "panic_on_stackoverflow",
865 .data
= &sysctl_panic_on_stackoverflow
,
866 .maxlen
= sizeof(int),
868 .proc_handler
= proc_dointvec
,
872 .procname
= "bootloader_type",
873 .data
= &bootloader_type
,
874 .maxlen
= sizeof (int),
876 .proc_handler
= proc_dointvec
,
879 .procname
= "bootloader_version",
880 .data
= &bootloader_version
,
881 .maxlen
= sizeof (int),
883 .proc_handler
= proc_dointvec
,
886 .procname
= "kstack_depth_to_print",
887 .data
= &kstack_depth_to_print
,
888 .maxlen
= sizeof(int),
890 .proc_handler
= proc_dointvec
,
893 .procname
= "io_delay_type",
894 .data
= &io_delay_type
,
895 .maxlen
= sizeof(int),
897 .proc_handler
= proc_dointvec
,
900 #if defined(CONFIG_MMU)
902 .procname
= "randomize_va_space",
903 .data
= &randomize_va_space
,
904 .maxlen
= sizeof(int),
906 .proc_handler
= proc_dointvec
,
909 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
911 .procname
= "spin_retry",
913 .maxlen
= sizeof (int),
915 .proc_handler
= proc_dointvec
,
918 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
920 .procname
= "acpi_video_flags",
921 .data
= &acpi_realmode_flags
,
922 .maxlen
= sizeof (unsigned long),
924 .proc_handler
= proc_doulongvec_minmax
,
927 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
929 .procname
= "ignore-unaligned-usertrap",
930 .data
= &no_unaligned_warning
,
931 .maxlen
= sizeof (int),
933 .proc_handler
= proc_dointvec
,
938 .procname
= "unaligned-dump-stack",
939 .data
= &unaligned_dump_stack
,
940 .maxlen
= sizeof (int),
942 .proc_handler
= proc_dointvec
,
945 #ifdef CONFIG_DETECT_HUNG_TASK
947 .procname
= "hung_task_panic",
948 .data
= &sysctl_hung_task_panic
,
949 .maxlen
= sizeof(int),
951 .proc_handler
= proc_dointvec_minmax
,
956 .procname
= "hung_task_check_count",
957 .data
= &sysctl_hung_task_check_count
,
958 .maxlen
= sizeof(unsigned long),
960 .proc_handler
= proc_doulongvec_minmax
,
963 .procname
= "hung_task_timeout_secs",
964 .data
= &sysctl_hung_task_timeout_secs
,
965 .maxlen
= sizeof(unsigned long),
967 .proc_handler
= proc_dohung_task_timeout_secs
,
970 .procname
= "hung_task_warnings",
971 .data
= &sysctl_hung_task_warnings
,
972 .maxlen
= sizeof(unsigned long),
974 .proc_handler
= proc_doulongvec_minmax
,
979 .procname
= "compat-log",
981 .maxlen
= sizeof (int),
983 .proc_handler
= proc_dointvec
,
986 #ifdef CONFIG_RT_MUTEXES
988 .procname
= "max_lock_depth",
989 .data
= &max_lock_depth
,
990 .maxlen
= sizeof(int),
992 .proc_handler
= proc_dointvec
,
996 .procname
= "poweroff_cmd",
997 .data
= &poweroff_cmd
,
998 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1000 .proc_handler
= proc_dostring
,
1006 .child
= key_sysctls
,
1009 #ifdef CONFIG_RCU_TORTURE_TEST
1011 .procname
= "rcutorture_runnable",
1012 .data
= &rcutorture_runnable
,
1013 .maxlen
= sizeof(int),
1015 .proc_handler
= proc_dointvec
,
1018 #ifdef CONFIG_PERF_EVENTS
1020 * User-space scripts rely on the existence of this file
1021 * as a feature check for perf_events being enabled.
1023 * So it's an ABI, do not remove!
1026 .procname
= "perf_event_paranoid",
1027 .data
= &sysctl_perf_event_paranoid
,
1028 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1030 .proc_handler
= proc_dointvec
,
1033 .procname
= "perf_event_mlock_kb",
1034 .data
= &sysctl_perf_event_mlock
,
1035 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1037 .proc_handler
= proc_dointvec
,
1040 .procname
= "perf_event_max_sample_rate",
1041 .data
= &sysctl_perf_event_sample_rate
,
1042 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1044 .proc_handler
= perf_proc_update_handler
,
1047 #ifdef CONFIG_KMEMCHECK
1049 .procname
= "kmemcheck",
1050 .data
= &kmemcheck_enabled
,
1051 .maxlen
= sizeof(int),
1053 .proc_handler
= proc_dointvec
,
1058 .procname
= "blk_iopoll",
1059 .data
= &blk_iopoll_enabled
,
1060 .maxlen
= sizeof(int),
1062 .proc_handler
= proc_dointvec
,
1068 static struct ctl_table vm_table
[] = {
1070 .procname
= "overcommit_memory",
1071 .data
= &sysctl_overcommit_memory
,
1072 .maxlen
= sizeof(sysctl_overcommit_memory
),
1074 .proc_handler
= proc_dointvec_minmax
,
1079 .procname
= "panic_on_oom",
1080 .data
= &sysctl_panic_on_oom
,
1081 .maxlen
= sizeof(sysctl_panic_on_oom
),
1083 .proc_handler
= proc_dointvec_minmax
,
1088 .procname
= "oom_kill_allocating_task",
1089 .data
= &sysctl_oom_kill_allocating_task
,
1090 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1092 .proc_handler
= proc_dointvec
,
1095 .procname
= "oom_dump_tasks",
1096 .data
= &sysctl_oom_dump_tasks
,
1097 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1099 .proc_handler
= proc_dointvec
,
1102 .procname
= "overcommit_ratio",
1103 .data
= &sysctl_overcommit_ratio
,
1104 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1106 .proc_handler
= proc_dointvec
,
1109 .procname
= "page-cluster",
1110 .data
= &page_cluster
,
1111 .maxlen
= sizeof(int),
1113 .proc_handler
= proc_dointvec_minmax
,
1117 .procname
= "dirty_background_ratio",
1118 .data
= &dirty_background_ratio
,
1119 .maxlen
= sizeof(dirty_background_ratio
),
1121 .proc_handler
= dirty_background_ratio_handler
,
1123 .extra2
= &one_hundred
,
1126 .procname
= "dirty_background_bytes",
1127 .data
= &dirty_background_bytes
,
1128 .maxlen
= sizeof(dirty_background_bytes
),
1130 .proc_handler
= dirty_background_bytes_handler
,
1134 .procname
= "dirty_ratio",
1135 .data
= &vm_dirty_ratio
,
1136 .maxlen
= sizeof(vm_dirty_ratio
),
1138 .proc_handler
= dirty_ratio_handler
,
1140 .extra2
= &one_hundred
,
1143 .procname
= "dirty_bytes",
1144 .data
= &vm_dirty_bytes
,
1145 .maxlen
= sizeof(vm_dirty_bytes
),
1147 .proc_handler
= dirty_bytes_handler
,
1148 .extra1
= &dirty_bytes_min
,
1151 .procname
= "dirty_writeback_centisecs",
1152 .data
= &dirty_writeback_interval
,
1153 .maxlen
= sizeof(dirty_writeback_interval
),
1155 .proc_handler
= dirty_writeback_centisecs_handler
,
1158 .procname
= "dirty_expire_centisecs",
1159 .data
= &dirty_expire_interval
,
1160 .maxlen
= sizeof(dirty_expire_interval
),
1162 .proc_handler
= proc_dointvec_minmax
,
1166 .procname
= "nr_pdflush_threads",
1167 .mode
= 0444 /* read-only */,
1168 .proc_handler
= pdflush_proc_obsolete
,
1171 .procname
= "swappiness",
1172 .data
= &vm_swappiness
,
1173 .maxlen
= sizeof(vm_swappiness
),
1175 .proc_handler
= proc_dointvec_minmax
,
1177 .extra2
= &one_hundred
,
1179 #ifdef CONFIG_HUGETLB_PAGE
1181 .procname
= "nr_hugepages",
1183 .maxlen
= sizeof(unsigned long),
1185 .proc_handler
= hugetlb_sysctl_handler
,
1186 .extra1
= (void *)&hugetlb_zero
,
1187 .extra2
= (void *)&hugetlb_infinity
,
1191 .procname
= "nr_hugepages_mempolicy",
1193 .maxlen
= sizeof(unsigned long),
1195 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1196 .extra1
= (void *)&hugetlb_zero
,
1197 .extra2
= (void *)&hugetlb_infinity
,
1201 .procname
= "hugetlb_shm_group",
1202 .data
= &sysctl_hugetlb_shm_group
,
1203 .maxlen
= sizeof(gid_t
),
1205 .proc_handler
= proc_dointvec
,
1208 .procname
= "hugepages_treat_as_movable",
1209 .data
= &hugepages_treat_as_movable
,
1210 .maxlen
= sizeof(int),
1212 .proc_handler
= hugetlb_treat_movable_handler
,
1215 .procname
= "nr_overcommit_hugepages",
1217 .maxlen
= sizeof(unsigned long),
1219 .proc_handler
= hugetlb_overcommit_handler
,
1220 .extra1
= (void *)&hugetlb_zero
,
1221 .extra2
= (void *)&hugetlb_infinity
,
1225 .procname
= "lowmem_reserve_ratio",
1226 .data
= &sysctl_lowmem_reserve_ratio
,
1227 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1229 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1232 .procname
= "drop_caches",
1233 .data
= &sysctl_drop_caches
,
1234 .maxlen
= sizeof(int),
1236 .proc_handler
= drop_caches_sysctl_handler
,
1240 #ifdef CONFIG_COMPACTION
1242 .procname
= "compact_memory",
1243 .data
= &sysctl_compact_memory
,
1244 .maxlen
= sizeof(int),
1246 .proc_handler
= sysctl_compaction_handler
,
1249 .procname
= "extfrag_threshold",
1250 .data
= &sysctl_extfrag_threshold
,
1251 .maxlen
= sizeof(int),
1253 .proc_handler
= sysctl_extfrag_handler
,
1254 .extra1
= &min_extfrag_threshold
,
1255 .extra2
= &max_extfrag_threshold
,
1258 #endif /* CONFIG_COMPACTION */
1260 .procname
= "min_free_kbytes",
1261 .data
= &min_free_kbytes
,
1262 .maxlen
= sizeof(min_free_kbytes
),
1264 .proc_handler
= min_free_kbytes_sysctl_handler
,
1268 .procname
= "percpu_pagelist_fraction",
1269 .data
= &percpu_pagelist_fraction
,
1270 .maxlen
= sizeof(percpu_pagelist_fraction
),
1272 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1273 .extra1
= &min_percpu_pagelist_fract
,
1277 .procname
= "max_map_count",
1278 .data
= &sysctl_max_map_count
,
1279 .maxlen
= sizeof(sysctl_max_map_count
),
1281 .proc_handler
= proc_dointvec_minmax
,
1286 .procname
= "nr_trim_pages",
1287 .data
= &sysctl_nr_trim_pages
,
1288 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1290 .proc_handler
= proc_dointvec_minmax
,
1295 .procname
= "laptop_mode",
1296 .data
= &laptop_mode
,
1297 .maxlen
= sizeof(laptop_mode
),
1299 .proc_handler
= proc_dointvec_jiffies
,
1302 .procname
= "block_dump",
1303 .data
= &block_dump
,
1304 .maxlen
= sizeof(block_dump
),
1306 .proc_handler
= proc_dointvec
,
1310 .procname
= "vfs_cache_pressure",
1311 .data
= &sysctl_vfs_cache_pressure
,
1312 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1314 .proc_handler
= proc_dointvec
,
1317 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1319 .procname
= "legacy_va_layout",
1320 .data
= &sysctl_legacy_va_layout
,
1321 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1323 .proc_handler
= proc_dointvec
,
1329 .procname
= "zone_reclaim_mode",
1330 .data
= &zone_reclaim_mode
,
1331 .maxlen
= sizeof(zone_reclaim_mode
),
1333 .proc_handler
= proc_dointvec
,
1337 .procname
= "min_unmapped_ratio",
1338 .data
= &sysctl_min_unmapped_ratio
,
1339 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1341 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1343 .extra2
= &one_hundred
,
1346 .procname
= "min_slab_ratio",
1347 .data
= &sysctl_min_slab_ratio
,
1348 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1350 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1352 .extra2
= &one_hundred
,
1357 .procname
= "stat_interval",
1358 .data
= &sysctl_stat_interval
,
1359 .maxlen
= sizeof(sysctl_stat_interval
),
1361 .proc_handler
= proc_dointvec_jiffies
,
1366 .procname
= "mmap_min_addr",
1367 .data
= &dac_mmap_min_addr
,
1368 .maxlen
= sizeof(unsigned long),
1370 .proc_handler
= mmap_min_addr_handler
,
1375 .procname
= "numa_zonelist_order",
1376 .data
= &numa_zonelist_order
,
1377 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1379 .proc_handler
= numa_zonelist_order_handler
,
1382 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1383 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1385 .procname
= "vdso_enabled",
1386 .data
= &vdso_enabled
,
1387 .maxlen
= sizeof(vdso_enabled
),
1389 .proc_handler
= proc_dointvec
,
1393 #ifdef CONFIG_HIGHMEM
1395 .procname
= "highmem_is_dirtyable",
1396 .data
= &vm_highmem_is_dirtyable
,
1397 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1399 .proc_handler
= proc_dointvec_minmax
,
1405 .procname
= "scan_unevictable_pages",
1406 .data
= &scan_unevictable_pages
,
1407 .maxlen
= sizeof(scan_unevictable_pages
),
1409 .proc_handler
= scan_unevictable_handler
,
1411 #ifdef CONFIG_MEMORY_FAILURE
1413 .procname
= "memory_failure_early_kill",
1414 .data
= &sysctl_memory_failure_early_kill
,
1415 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1417 .proc_handler
= proc_dointvec_minmax
,
1422 .procname
= "memory_failure_recovery",
1423 .data
= &sysctl_memory_failure_recovery
,
1424 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1426 .proc_handler
= proc_dointvec_minmax
,
1432 .procname
= "user_reserve_kbytes",
1433 .data
= &sysctl_user_reserve_kbytes
,
1434 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1436 .proc_handler
= proc_doulongvec_minmax
,
1439 .procname
= "admin_reserve_kbytes",
1440 .data
= &sysctl_admin_reserve_kbytes
,
1441 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1443 .proc_handler
= proc_doulongvec_minmax
,
1448 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1449 static struct ctl_table binfmt_misc_table
[] = {
1454 static struct ctl_table fs_table
[] = {
1456 .procname
= "inode-nr",
1457 .data
= &inodes_stat
,
1458 .maxlen
= 2*sizeof(int),
1460 .proc_handler
= proc_nr_inodes
,
1463 .procname
= "inode-state",
1464 .data
= &inodes_stat
,
1465 .maxlen
= 7*sizeof(int),
1467 .proc_handler
= proc_nr_inodes
,
1470 .procname
= "file-nr",
1471 .data
= &files_stat
,
1472 .maxlen
= sizeof(files_stat
),
1474 .proc_handler
= proc_nr_files
,
1477 .procname
= "file-max",
1478 .data
= &files_stat
.max_files
,
1479 .maxlen
= sizeof(files_stat
.max_files
),
1481 .proc_handler
= proc_doulongvec_minmax
,
1484 .procname
= "nr_open",
1485 .data
= &sysctl_nr_open
,
1486 .maxlen
= sizeof(int),
1488 .proc_handler
= proc_dointvec_minmax
,
1489 .extra1
= &sysctl_nr_open_min
,
1490 .extra2
= &sysctl_nr_open_max
,
1493 .procname
= "dentry-state",
1494 .data
= &dentry_stat
,
1495 .maxlen
= 6*sizeof(int),
1497 .proc_handler
= proc_nr_dentry
,
1500 .procname
= "overflowuid",
1501 .data
= &fs_overflowuid
,
1502 .maxlen
= sizeof(int),
1504 .proc_handler
= proc_dointvec_minmax
,
1505 .extra1
= &minolduid
,
1506 .extra2
= &maxolduid
,
1509 .procname
= "overflowgid",
1510 .data
= &fs_overflowgid
,
1511 .maxlen
= sizeof(int),
1513 .proc_handler
= proc_dointvec_minmax
,
1514 .extra1
= &minolduid
,
1515 .extra2
= &maxolduid
,
1517 #ifdef CONFIG_FILE_LOCKING
1519 .procname
= "leases-enable",
1520 .data
= &leases_enable
,
1521 .maxlen
= sizeof(int),
1523 .proc_handler
= proc_dointvec
,
1526 #ifdef CONFIG_DNOTIFY
1528 .procname
= "dir-notify-enable",
1529 .data
= &dir_notify_enable
,
1530 .maxlen
= sizeof(int),
1532 .proc_handler
= proc_dointvec
,
1536 #ifdef CONFIG_FILE_LOCKING
1538 .procname
= "lease-break-time",
1539 .data
= &lease_break_time
,
1540 .maxlen
= sizeof(int),
1542 .proc_handler
= proc_dointvec
,
1547 .procname
= "aio-nr",
1549 .maxlen
= sizeof(aio_nr
),
1551 .proc_handler
= proc_doulongvec_minmax
,
1554 .procname
= "aio-max-nr",
1555 .data
= &aio_max_nr
,
1556 .maxlen
= sizeof(aio_max_nr
),
1558 .proc_handler
= proc_doulongvec_minmax
,
1560 #endif /* CONFIG_AIO */
1561 #ifdef CONFIG_INOTIFY_USER
1563 .procname
= "inotify",
1565 .child
= inotify_table
,
1570 .procname
= "epoll",
1572 .child
= epoll_table
,
1577 .procname
= "protected_symlinks",
1578 .data
= &sysctl_protected_symlinks
,
1579 .maxlen
= sizeof(int),
1581 .proc_handler
= proc_dointvec_minmax
,
1586 .procname
= "protected_hardlinks",
1587 .data
= &sysctl_protected_hardlinks
,
1588 .maxlen
= sizeof(int),
1590 .proc_handler
= proc_dointvec_minmax
,
1595 .procname
= "suid_dumpable",
1596 .data
= &suid_dumpable
,
1597 .maxlen
= sizeof(int),
1599 .proc_handler
= proc_dointvec_minmax_coredump
,
1603 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1605 .procname
= "binfmt_misc",
1607 .child
= binfmt_misc_table
,
1611 .procname
= "pipe-max-size",
1612 .data
= &pipe_max_size
,
1613 .maxlen
= sizeof(int),
1615 .proc_handler
= &pipe_proc_fn
,
1616 .extra1
= &pipe_min_size
,
1621 static struct ctl_table debug_table
[] = {
1622 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1624 .procname
= "exception-trace",
1625 .data
= &show_unhandled_signals
,
1626 .maxlen
= sizeof(int),
1628 .proc_handler
= proc_dointvec
1631 #if defined(CONFIG_OPTPROBES)
1633 .procname
= "kprobes-optimization",
1634 .data
= &sysctl_kprobes_optimization
,
1635 .maxlen
= sizeof(int),
1637 .proc_handler
= proc_kprobes_optimization_handler
,
1645 static struct ctl_table dev_table
[] = {
1649 int __init
sysctl_init(void)
1651 struct ctl_table_header
*hdr
;
1653 hdr
= register_sysctl_table(sysctl_base_table
);
1654 kmemleak_not_leak(hdr
);
1658 #endif /* CONFIG_SYSCTL */
1664 #ifdef CONFIG_PROC_SYSCTL
1666 static int _proc_do_string(void* data
, int maxlen
, int write
,
1667 void __user
*buffer
,
1668 size_t *lenp
, loff_t
*ppos
)
1674 if (!data
|| !maxlen
|| !*lenp
) {
1682 while (len
< *lenp
) {
1683 if (get_user(c
, p
++))
1685 if (c
== 0 || c
== '\n')
1691 if(copy_from_user(data
, buffer
, len
))
1693 ((char *) data
)[len
] = 0;
1711 if(copy_to_user(buffer
, data
, len
))
1714 if(put_user('\n', ((char __user
*) buffer
) + len
))
1725 * proc_dostring - read a string sysctl
1726 * @table: the sysctl table
1727 * @write: %TRUE if this is a write to the sysctl file
1728 * @buffer: the user buffer
1729 * @lenp: the size of the user buffer
1730 * @ppos: file position
1732 * Reads/writes a string from/to the user buffer. If the kernel
1733 * buffer provided is not large enough to hold the string, the
1734 * string is truncated. The copied string is %NULL-terminated.
1735 * If the string is being read by the user process, it is copied
1736 * and a newline '\n' is added. It is truncated if the buffer is
1739 * Returns 0 on success.
1741 int proc_dostring(struct ctl_table
*table
, int write
,
1742 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1744 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1745 buffer
, lenp
, ppos
);
1748 static size_t proc_skip_spaces(char **buf
)
1751 char *tmp
= skip_spaces(*buf
);
1757 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1767 #define TMPBUFLEN 22
1769 * proc_get_long - reads an ASCII formatted integer from a user buffer
1771 * @buf: a kernel buffer
1772 * @size: size of the kernel buffer
1773 * @val: this is where the number will be stored
1774 * @neg: set to %TRUE if number is negative
1775 * @perm_tr: a vector which contains the allowed trailers
1776 * @perm_tr_len: size of the perm_tr vector
1777 * @tr: pointer to store the trailer character
1779 * In case of success %0 is returned and @buf and @size are updated with
1780 * the amount of bytes read. If @tr is non-NULL and a trailing
1781 * character exists (size is non-zero after returning from this
1782 * function), @tr is updated with the trailing character.
1784 static int proc_get_long(char **buf
, size_t *size
,
1785 unsigned long *val
, bool *neg
,
1786 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1789 char *p
, tmp
[TMPBUFLEN
];
1795 if (len
> TMPBUFLEN
- 1)
1796 len
= TMPBUFLEN
- 1;
1798 memcpy(tmp
, *buf
, len
);
1802 if (*p
== '-' && *size
> 1) {
1810 *val
= simple_strtoul(p
, &p
, 0);
1814 /* We don't know if the next char is whitespace thus we may accept
1815 * invalid integers (e.g. 1234...a) or two integers instead of one
1816 * (e.g. 123...1). So lets not allow such large numbers. */
1817 if (len
== TMPBUFLEN
- 1)
1820 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1823 if (tr
&& (len
< *size
))
1833 * proc_put_long - converts an integer to a decimal ASCII formatted string
1835 * @buf: the user buffer
1836 * @size: the size of the user buffer
1837 * @val: the integer to be converted
1838 * @neg: sign of the number, %TRUE for negative
1840 * In case of success %0 is returned and @buf and @size are updated with
1841 * the amount of bytes written.
1843 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1847 char tmp
[TMPBUFLEN
], *p
= tmp
;
1849 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1853 if (copy_to_user(*buf
, tmp
, len
))
1861 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1864 char __user
**buffer
= (char __user
**)buf
;
1865 if (put_user(c
, *buffer
))
1867 (*size
)--, (*buffer
)++;
1873 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1875 int write
, void *data
)
1878 *valp
= *negp
? -*lvalp
: *lvalp
;
1883 *lvalp
= (unsigned long)-val
;
1886 *lvalp
= (unsigned long)val
;
1892 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1894 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1895 int write
, void __user
*buffer
,
1896 size_t *lenp
, loff_t
*ppos
,
1897 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1898 int write
, void *data
),
1901 int *i
, vleft
, first
= 1, err
= 0;
1902 unsigned long page
= 0;
1906 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1911 i
= (int *) tbl_data
;
1912 vleft
= table
->maxlen
/ sizeof(*i
);
1916 conv
= do_proc_dointvec_conv
;
1919 if (left
> PAGE_SIZE
- 1)
1920 left
= PAGE_SIZE
- 1;
1921 page
= __get_free_page(GFP_TEMPORARY
);
1922 kbuf
= (char *) page
;
1925 if (copy_from_user(kbuf
, buffer
, left
)) {
1932 for (; left
&& vleft
--; i
++, first
=0) {
1937 left
-= proc_skip_spaces(&kbuf
);
1941 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1943 sizeof(proc_wspace_sep
), NULL
);
1946 if (conv(&neg
, &lval
, i
, 1, data
)) {
1951 if (conv(&neg
, &lval
, i
, 0, data
)) {
1956 err
= proc_put_char(&buffer
, &left
, '\t');
1959 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1965 if (!write
&& !first
&& left
&& !err
)
1966 err
= proc_put_char(&buffer
, &left
, '\n');
1967 if (write
&& !err
&& left
)
1968 left
-= proc_skip_spaces(&kbuf
);
1973 return err
? : -EINVAL
;
1980 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1981 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1982 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1983 int write
, void *data
),
1986 return __do_proc_dointvec(table
->data
, table
, write
,
1987 buffer
, lenp
, ppos
, conv
, data
);
1991 * proc_dointvec - read a vector of integers
1992 * @table: the sysctl table
1993 * @write: %TRUE if this is a write to the sysctl file
1994 * @buffer: the user buffer
1995 * @lenp: the size of the user buffer
1996 * @ppos: file position
1998 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1999 * values from/to the user buffer, treated as an ASCII string.
2001 * Returns 0 on success.
2003 int proc_dointvec(struct ctl_table
*table
, int write
,
2004 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2006 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2011 * Taint values can only be increased
2012 * This means we can safely use a temporary.
2014 static int proc_taint(struct ctl_table
*table
, int write
,
2015 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2018 unsigned long tmptaint
= get_taint();
2021 if (write
&& !capable(CAP_SYS_ADMIN
))
2026 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2032 * Poor man's atomic or. Not worth adding a primitive
2033 * to everyone's atomic.h for this
2036 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2037 if ((tmptaint
>> i
) & 1)
2038 add_taint(i
, LOCKDEP_STILL_OK
);
2045 #ifdef CONFIG_PRINTK
2046 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2047 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2049 if (write
&& !capable(CAP_SYS_ADMIN
))
2052 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2056 struct do_proc_dointvec_minmax_conv_param
{
2061 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2063 int write
, void *data
)
2065 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2067 int val
= *negp
? -*lvalp
: *lvalp
;
2068 if ((param
->min
&& *param
->min
> val
) ||
2069 (param
->max
&& *param
->max
< val
))
2076 *lvalp
= (unsigned long)-val
;
2079 *lvalp
= (unsigned long)val
;
2086 * proc_dointvec_minmax - read a vector of integers with min/max values
2087 * @table: the sysctl table
2088 * @write: %TRUE if this is a write to the sysctl file
2089 * @buffer: the user buffer
2090 * @lenp: the size of the user buffer
2091 * @ppos: file position
2093 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2094 * values from/to the user buffer, treated as an ASCII string.
2096 * This routine will ensure the values are within the range specified by
2097 * table->extra1 (min) and table->extra2 (max).
2099 * Returns 0 on success.
2101 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2102 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2104 struct do_proc_dointvec_minmax_conv_param param
= {
2105 .min
= (int *) table
->extra1
,
2106 .max
= (int *) table
->extra2
,
2108 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2109 do_proc_dointvec_minmax_conv
, ¶m
);
2112 static void validate_coredump_safety(void)
2114 #ifdef CONFIG_COREDUMP
2115 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2116 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2117 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2118 "suid_dumpable=2. Pipe handler or fully qualified "\
2119 "core dump path required.\n");
2124 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2125 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2127 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2129 validate_coredump_safety();
2133 #ifdef CONFIG_COREDUMP
2134 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2135 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2137 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2139 validate_coredump_safety();
2144 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2145 void __user
*buffer
,
2146 size_t *lenp
, loff_t
*ppos
,
2147 unsigned long convmul
,
2148 unsigned long convdiv
)
2150 unsigned long *i
, *min
, *max
;
2151 int vleft
, first
= 1, err
= 0;
2152 unsigned long page
= 0;
2156 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2161 i
= (unsigned long *) data
;
2162 min
= (unsigned long *) table
->extra1
;
2163 max
= (unsigned long *) table
->extra2
;
2164 vleft
= table
->maxlen
/ sizeof(unsigned long);
2168 if (left
> PAGE_SIZE
- 1)
2169 left
= PAGE_SIZE
- 1;
2170 page
= __get_free_page(GFP_TEMPORARY
);
2171 kbuf
= (char *) page
;
2174 if (copy_from_user(kbuf
, buffer
, left
)) {
2181 for (; left
&& vleft
--; i
++, first
= 0) {
2187 left
-= proc_skip_spaces(&kbuf
);
2189 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2191 sizeof(proc_wspace_sep
), NULL
);
2196 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2200 val
= convdiv
* (*i
) / convmul
;
2202 err
= proc_put_char(&buffer
, &left
, '\t');
2203 err
= proc_put_long(&buffer
, &left
, val
, false);
2209 if (!write
&& !first
&& left
&& !err
)
2210 err
= proc_put_char(&buffer
, &left
, '\n');
2212 left
-= proc_skip_spaces(&kbuf
);
2217 return err
? : -EINVAL
;
2224 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2225 void __user
*buffer
,
2226 size_t *lenp
, loff_t
*ppos
,
2227 unsigned long convmul
,
2228 unsigned long convdiv
)
2230 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2231 buffer
, lenp
, ppos
, convmul
, convdiv
);
2235 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2236 * @table: the sysctl table
2237 * @write: %TRUE if this is a write to the sysctl file
2238 * @buffer: the user buffer
2239 * @lenp: the size of the user buffer
2240 * @ppos: file position
2242 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2243 * values from/to the user buffer, treated as an ASCII string.
2245 * This routine will ensure the values are within the range specified by
2246 * table->extra1 (min) and table->extra2 (max).
2248 * Returns 0 on success.
2250 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2251 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2253 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2257 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2258 * @table: the sysctl table
2259 * @write: %TRUE if this is a write to the sysctl file
2260 * @buffer: the user buffer
2261 * @lenp: the size of the user buffer
2262 * @ppos: file position
2264 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2265 * values from/to the user buffer, treated as an ASCII string. The values
2266 * are treated as milliseconds, and converted to jiffies when they are stored.
2268 * This routine will ensure the values are within the range specified by
2269 * table->extra1 (min) and table->extra2 (max).
2271 * Returns 0 on success.
2273 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2274 void __user
*buffer
,
2275 size_t *lenp
, loff_t
*ppos
)
2277 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2278 lenp
, ppos
, HZ
, 1000l);
2282 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2284 int write
, void *data
)
2287 if (*lvalp
> LONG_MAX
/ HZ
)
2289 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2295 lval
= (unsigned long)-val
;
2298 lval
= (unsigned long)val
;
2305 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2307 int write
, void *data
)
2310 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2312 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2318 lval
= (unsigned long)-val
;
2321 lval
= (unsigned long)val
;
2323 *lvalp
= jiffies_to_clock_t(lval
);
2328 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2330 int write
, void *data
)
2333 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2339 lval
= (unsigned long)-val
;
2342 lval
= (unsigned long)val
;
2344 *lvalp
= jiffies_to_msecs(lval
);
2350 * proc_dointvec_jiffies - read a vector of integers as seconds
2351 * @table: the sysctl table
2352 * @write: %TRUE if this is a write to the sysctl file
2353 * @buffer: the user buffer
2354 * @lenp: the size of the user buffer
2355 * @ppos: file position
2357 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2358 * values from/to the user buffer, treated as an ASCII string.
2359 * The values read are assumed to be in seconds, and are converted into
2362 * Returns 0 on success.
2364 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2365 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2367 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2368 do_proc_dointvec_jiffies_conv
,NULL
);
2372 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2373 * @table: the sysctl table
2374 * @write: %TRUE if this is a write to the sysctl file
2375 * @buffer: the user buffer
2376 * @lenp: the size of the user buffer
2377 * @ppos: pointer to the file position
2379 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2380 * values from/to the user buffer, treated as an ASCII string.
2381 * The values read are assumed to be in 1/USER_HZ seconds, and
2382 * are converted into jiffies.
2384 * Returns 0 on success.
2386 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2387 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2389 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2390 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2394 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2395 * @table: the sysctl table
2396 * @write: %TRUE if this is a write to the sysctl file
2397 * @buffer: the user buffer
2398 * @lenp: the size of the user buffer
2399 * @ppos: file position
2400 * @ppos: the current position in the file
2402 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2403 * values from/to the user buffer, treated as an ASCII string.
2404 * The values read are assumed to be in 1/1000 seconds, and
2405 * are converted into jiffies.
2407 * Returns 0 on success.
2409 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2410 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2412 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2413 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2416 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2417 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2419 struct pid
*new_pid
;
2423 tmp
= pid_vnr(cad_pid
);
2425 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2426 lenp
, ppos
, NULL
, NULL
);
2430 new_pid
= find_get_pid(tmp
);
2434 put_pid(xchg(&cad_pid
, new_pid
));
2439 * proc_do_large_bitmap - read/write from/to a large bitmap
2440 * @table: the sysctl table
2441 * @write: %TRUE if this is a write to the sysctl file
2442 * @buffer: the user buffer
2443 * @lenp: the size of the user buffer
2444 * @ppos: file position
2446 * The bitmap is stored at table->data and the bitmap length (in bits)
2449 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2450 * large bitmaps may be represented in a compact manner. Writing into
2451 * the file will clear the bitmap then update it with the given input.
2453 * Returns 0 on success.
2455 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2456 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2460 size_t left
= *lenp
;
2461 unsigned long bitmap_len
= table
->maxlen
;
2462 unsigned long *bitmap
= (unsigned long *) table
->data
;
2463 unsigned long *tmp_bitmap
= NULL
;
2464 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2466 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2472 unsigned long page
= 0;
2475 if (left
> PAGE_SIZE
- 1)
2476 left
= PAGE_SIZE
- 1;
2478 page
= __get_free_page(GFP_TEMPORARY
);
2479 kbuf
= (char *) page
;
2482 if (copy_from_user(kbuf
, buffer
, left
)) {
2488 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2494 proc_skip_char(&kbuf
, &left
, '\n');
2495 while (!err
&& left
) {
2496 unsigned long val_a
, val_b
;
2499 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2503 if (val_a
>= bitmap_len
|| neg
) {
2515 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2516 &neg
, tr_b
, sizeof(tr_b
),
2520 if (val_b
>= bitmap_len
|| neg
||
2531 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2533 proc_skip_char(&kbuf
, &left
, '\n');
2537 unsigned long bit_a
, bit_b
= 0;
2540 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2541 if (bit_a
>= bitmap_len
)
2543 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2547 err
= proc_put_char(&buffer
, &left
, ',');
2551 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2554 if (bit_a
!= bit_b
) {
2555 err
= proc_put_char(&buffer
, &left
, '-');
2558 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2566 err
= proc_put_char(&buffer
, &left
, '\n');
2572 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2574 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2586 #else /* CONFIG_PROC_SYSCTL */
2588 int proc_dostring(struct ctl_table
*table
, int write
,
2589 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2594 int proc_dointvec(struct ctl_table
*table
, int write
,
2595 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2600 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2601 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2606 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2607 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2612 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2613 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2618 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2619 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2624 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2625 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2630 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2631 void __user
*buffer
,
2632 size_t *lenp
, loff_t
*ppos
)
2638 #endif /* CONFIG_PROC_SYSCTL */
2641 * No sense putting this after each symbol definition, twice,
2642 * exception granted :-)
2644 EXPORT_SYMBOL(proc_dointvec
);
2645 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2646 EXPORT_SYMBOL(proc_dointvec_minmax
);
2647 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2648 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2649 EXPORT_SYMBOL(proc_dostring
);
2650 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2651 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);