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>
65 #include <asm/uaccess.h>
66 #include <asm/processor.h>
70 #include <asm/stacktrace.h>
74 #include <asm/setup.h>
76 #ifdef CONFIG_BSD_PROCESS_ACCT
77 #include <linux/acct.h>
79 #ifdef CONFIG_RT_MUTEXES
80 #include <linux/rtmutex.h>
82 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
83 #include <linux/lockdep.h>
85 #ifdef CONFIG_CHR_DEV_SG
89 #ifdef CONFIG_LOCKUP_DETECTOR
90 #include <linux/nmi.h>
94 #if defined(CONFIG_SYSCTL)
96 /* External variables not in a header file. */
97 extern int sysctl_overcommit_memory
;
98 extern int sysctl_overcommit_ratio
;
99 extern int max_threads
;
100 extern int suid_dumpable
;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid
;
103 extern char core_pattern
[];
104 extern unsigned int core_pipe_limit
;
107 extern int min_free_kbytes
;
108 extern int pid_max_min
, pid_max_max
;
109 extern int sysctl_drop_caches
;
110 extern int percpu_pagelist_fraction
;
111 extern int compat_log
;
112 extern int latencytop_enabled
;
113 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
115 extern int sysctl_nr_trim_pages
;
118 extern int blk_iopoll_enabled
;
121 /* Constants used for minimum and maximum */
122 #ifdef CONFIG_LOCKUP_DETECTOR
123 static int sixty
= 60;
124 static int neg_one
= -1;
128 static int __maybe_unused one
= 1;
129 static int __maybe_unused two
= 2;
130 static int __maybe_unused three
= 3;
131 static unsigned long one_ul
= 1;
132 static int one_hundred
= 100;
134 static int ten_thousand
= 10000;
137 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
140 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141 static int maxolduid
= 65535;
142 static int minolduid
;
143 static int min_percpu_pagelist_fract
= 8;
145 static int ngroups_max
= NGROUPS_MAX
;
146 static const int cap_last_cap
= CAP_LAST_CAP
;
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
154 #ifdef CONFIG_SPARC64
155 extern int sysctl_tsb_ratio
;
159 extern int pwrsw_enabled
;
160 extern int unaligned_enabled
;
164 extern int no_unaligned_warning
;
165 extern int unaligned_dump_stack
;
168 #ifdef CONFIG_PROC_SYSCTL
169 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
171 static int proc_taint(struct ctl_table
*table
, int write
,
172 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
176 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
177 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
180 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
181 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
182 #ifdef CONFIG_COREDUMP
183 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
184 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
187 #ifdef CONFIG_MAGIC_SYSRQ
188 /* Note: sysrq code uses it's own private copy */
189 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
191 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
192 void __user
*buffer
, size_t *lenp
,
197 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
202 sysrq_toggle_support(__sysrq_enabled
);
209 static struct ctl_table kern_table
[];
210 static struct ctl_table vm_table
[];
211 static struct ctl_table fs_table
[];
212 static struct ctl_table debug_table
[];
213 static struct ctl_table dev_table
[];
214 extern struct ctl_table random_table
[];
216 extern struct ctl_table epoll_table
[];
219 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220 int sysctl_legacy_va_layout
;
223 /* The default sysctl tables: */
225 static struct ctl_table sysctl_base_table
[] = {
227 .procname
= "kernel",
244 .child
= debug_table
,
254 #ifdef CONFIG_SCHED_DEBUG
255 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
256 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
257 static int min_wakeup_granularity_ns
; /* 0 usecs */
258 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
260 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
261 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
262 #endif /* CONFIG_SMP */
263 #endif /* CONFIG_SCHED_DEBUG */
265 #ifdef CONFIG_COMPACTION
266 static int min_extfrag_threshold
;
267 static int max_extfrag_threshold
= 1000;
270 static struct ctl_table kern_table
[] = {
272 .procname
= "sched_child_runs_first",
273 .data
= &sysctl_sched_child_runs_first
,
274 .maxlen
= sizeof(unsigned int),
276 .proc_handler
= proc_dointvec
,
278 #ifdef CONFIG_SCHED_DEBUG
280 .procname
= "sched_min_granularity_ns",
281 .data
= &sysctl_sched_min_granularity
,
282 .maxlen
= sizeof(unsigned int),
284 .proc_handler
= sched_proc_update_handler
,
285 .extra1
= &min_sched_granularity_ns
,
286 .extra2
= &max_sched_granularity_ns
,
289 .procname
= "sched_latency_ns",
290 .data
= &sysctl_sched_latency
,
291 .maxlen
= sizeof(unsigned int),
293 .proc_handler
= sched_proc_update_handler
,
294 .extra1
= &min_sched_granularity_ns
,
295 .extra2
= &max_sched_granularity_ns
,
298 .procname
= "sched_wakeup_granularity_ns",
299 .data
= &sysctl_sched_wakeup_granularity
,
300 .maxlen
= sizeof(unsigned int),
302 .proc_handler
= sched_proc_update_handler
,
303 .extra1
= &min_wakeup_granularity_ns
,
304 .extra2
= &max_wakeup_granularity_ns
,
308 .procname
= "sched_tunable_scaling",
309 .data
= &sysctl_sched_tunable_scaling
,
310 .maxlen
= sizeof(enum sched_tunable_scaling
),
312 .proc_handler
= sched_proc_update_handler
,
313 .extra1
= &min_sched_tunable_scaling
,
314 .extra2
= &max_sched_tunable_scaling
,
317 .procname
= "sched_migration_cost_ns",
318 .data
= &sysctl_sched_migration_cost
,
319 .maxlen
= sizeof(unsigned int),
321 .proc_handler
= proc_dointvec
,
324 .procname
= "sched_nr_migrate",
325 .data
= &sysctl_sched_nr_migrate
,
326 .maxlen
= sizeof(unsigned int),
328 .proc_handler
= proc_dointvec
,
331 .procname
= "sched_time_avg_ms",
332 .data
= &sysctl_sched_time_avg
,
333 .maxlen
= sizeof(unsigned int),
335 .proc_handler
= proc_dointvec
,
338 .procname
= "sched_shares_window_ns",
339 .data
= &sysctl_sched_shares_window
,
340 .maxlen
= sizeof(unsigned int),
342 .proc_handler
= proc_dointvec
,
345 .procname
= "timer_migration",
346 .data
= &sysctl_timer_migration
,
347 .maxlen
= sizeof(unsigned int),
349 .proc_handler
= proc_dointvec_minmax
,
353 #endif /* CONFIG_SMP */
354 #ifdef CONFIG_NUMA_BALANCING
356 .procname
= "numa_balancing_scan_delay_ms",
357 .data
= &sysctl_numa_balancing_scan_delay
,
358 .maxlen
= sizeof(unsigned int),
360 .proc_handler
= proc_dointvec
,
363 .procname
= "numa_balancing_scan_period_min_ms",
364 .data
= &sysctl_numa_balancing_scan_period_min
,
365 .maxlen
= sizeof(unsigned int),
367 .proc_handler
= proc_dointvec
,
370 .procname
= "numa_balancing_scan_period_reset",
371 .data
= &sysctl_numa_balancing_scan_period_reset
,
372 .maxlen
= sizeof(unsigned int),
374 .proc_handler
= proc_dointvec
,
377 .procname
= "numa_balancing_scan_period_max_ms",
378 .data
= &sysctl_numa_balancing_scan_period_max
,
379 .maxlen
= sizeof(unsigned int),
381 .proc_handler
= proc_dointvec
,
384 .procname
= "numa_balancing_scan_size_mb",
385 .data
= &sysctl_numa_balancing_scan_size
,
386 .maxlen
= sizeof(unsigned int),
388 .proc_handler
= proc_dointvec
,
390 #endif /* CONFIG_NUMA_BALANCING */
391 #endif /* CONFIG_SCHED_DEBUG */
393 .procname
= "sched_rt_period_us",
394 .data
= &sysctl_sched_rt_period
,
395 .maxlen
= sizeof(unsigned int),
397 .proc_handler
= sched_rt_handler
,
400 .procname
= "sched_rt_runtime_us",
401 .data
= &sysctl_sched_rt_runtime
,
402 .maxlen
= sizeof(int),
404 .proc_handler
= sched_rt_handler
,
406 #ifdef CONFIG_SCHED_AUTOGROUP
408 .procname
= "sched_autogroup_enabled",
409 .data
= &sysctl_sched_autogroup_enabled
,
410 .maxlen
= sizeof(unsigned int),
412 .proc_handler
= proc_dointvec_minmax
,
417 #ifdef CONFIG_CFS_BANDWIDTH
419 .procname
= "sched_cfs_bandwidth_slice_us",
420 .data
= &sysctl_sched_cfs_bandwidth_slice
,
421 .maxlen
= sizeof(unsigned int),
423 .proc_handler
= proc_dointvec_minmax
,
427 #ifdef CONFIG_PROVE_LOCKING
429 .procname
= "prove_locking",
430 .data
= &prove_locking
,
431 .maxlen
= sizeof(int),
433 .proc_handler
= proc_dointvec
,
436 #ifdef CONFIG_LOCK_STAT
438 .procname
= "lock_stat",
440 .maxlen
= sizeof(int),
442 .proc_handler
= proc_dointvec
,
447 .data
= &panic_timeout
,
448 .maxlen
= sizeof(int),
450 .proc_handler
= proc_dointvec
,
452 #ifdef CONFIG_COREDUMP
454 .procname
= "core_uses_pid",
455 .data
= &core_uses_pid
,
456 .maxlen
= sizeof(int),
458 .proc_handler
= proc_dointvec
,
461 .procname
= "core_pattern",
462 .data
= core_pattern
,
463 .maxlen
= CORENAME_MAX_SIZE
,
465 .proc_handler
= proc_dostring_coredump
,
468 .procname
= "core_pipe_limit",
469 .data
= &core_pipe_limit
,
470 .maxlen
= sizeof(unsigned int),
472 .proc_handler
= proc_dointvec
,
475 #ifdef CONFIG_PROC_SYSCTL
477 .procname
= "tainted",
478 .maxlen
= sizeof(long),
480 .proc_handler
= proc_taint
,
483 #ifdef CONFIG_LATENCYTOP
485 .procname
= "latencytop",
486 .data
= &latencytop_enabled
,
487 .maxlen
= sizeof(int),
489 .proc_handler
= proc_dointvec
,
492 #ifdef CONFIG_BLK_DEV_INITRD
494 .procname
= "real-root-dev",
495 .data
= &real_root_dev
,
496 .maxlen
= sizeof(int),
498 .proc_handler
= proc_dointvec
,
502 .procname
= "print-fatal-signals",
503 .data
= &print_fatal_signals
,
504 .maxlen
= sizeof(int),
506 .proc_handler
= proc_dointvec
,
510 .procname
= "reboot-cmd",
511 .data
= reboot_command
,
514 .proc_handler
= proc_dostring
,
517 .procname
= "stop-a",
518 .data
= &stop_a_enabled
,
519 .maxlen
= sizeof (int),
521 .proc_handler
= proc_dointvec
,
524 .procname
= "scons-poweroff",
525 .data
= &scons_pwroff
,
526 .maxlen
= sizeof (int),
528 .proc_handler
= proc_dointvec
,
531 #ifdef CONFIG_SPARC64
533 .procname
= "tsb-ratio",
534 .data
= &sysctl_tsb_ratio
,
535 .maxlen
= sizeof (int),
537 .proc_handler
= proc_dointvec
,
542 .procname
= "soft-power",
543 .data
= &pwrsw_enabled
,
544 .maxlen
= sizeof (int),
546 .proc_handler
= proc_dointvec
,
549 .procname
= "unaligned-trap",
550 .data
= &unaligned_enabled
,
551 .maxlen
= sizeof (int),
553 .proc_handler
= proc_dointvec
,
557 .procname
= "ctrl-alt-del",
559 .maxlen
= sizeof(int),
561 .proc_handler
= proc_dointvec
,
563 #ifdef CONFIG_FUNCTION_TRACER
565 .procname
= "ftrace_enabled",
566 .data
= &ftrace_enabled
,
567 .maxlen
= sizeof(int),
569 .proc_handler
= ftrace_enable_sysctl
,
572 #ifdef CONFIG_STACK_TRACER
574 .procname
= "stack_tracer_enabled",
575 .data
= &stack_tracer_enabled
,
576 .maxlen
= sizeof(int),
578 .proc_handler
= stack_trace_sysctl
,
581 #ifdef CONFIG_TRACING
583 .procname
= "ftrace_dump_on_oops",
584 .data
= &ftrace_dump_on_oops
,
585 .maxlen
= sizeof(int),
587 .proc_handler
= proc_dointvec
,
590 #ifdef CONFIG_MODULES
592 .procname
= "modprobe",
593 .data
= &modprobe_path
,
594 .maxlen
= KMOD_PATH_LEN
,
596 .proc_handler
= proc_dostring
,
599 .procname
= "modules_disabled",
600 .data
= &modules_disabled
,
601 .maxlen
= sizeof(int),
603 /* only handle a transition from default "0" to "1" */
604 .proc_handler
= proc_dointvec_minmax
,
611 .procname
= "hotplug",
612 .data
= &uevent_helper
,
613 .maxlen
= UEVENT_HELPER_PATH_LEN
,
615 .proc_handler
= proc_dostring
,
618 #ifdef CONFIG_CHR_DEV_SG
620 .procname
= "sg-big-buff",
621 .data
= &sg_big_buff
,
622 .maxlen
= sizeof (int),
624 .proc_handler
= proc_dointvec
,
627 #ifdef CONFIG_BSD_PROCESS_ACCT
631 .maxlen
= 3*sizeof(int),
633 .proc_handler
= proc_dointvec
,
636 #ifdef CONFIG_MAGIC_SYSRQ
639 .data
= &__sysrq_enabled
,
640 .maxlen
= sizeof (int),
642 .proc_handler
= sysrq_sysctl_handler
,
645 #ifdef CONFIG_PROC_SYSCTL
647 .procname
= "cad_pid",
649 .maxlen
= sizeof (int),
651 .proc_handler
= proc_do_cad_pid
,
655 .procname
= "threads-max",
656 .data
= &max_threads
,
657 .maxlen
= sizeof(int),
659 .proc_handler
= proc_dointvec
,
662 .procname
= "random",
664 .child
= random_table
,
667 .procname
= "usermodehelper",
669 .child
= usermodehelper_table
,
672 .procname
= "overflowuid",
673 .data
= &overflowuid
,
674 .maxlen
= sizeof(int),
676 .proc_handler
= proc_dointvec_minmax
,
677 .extra1
= &minolduid
,
678 .extra2
= &maxolduid
,
681 .procname
= "overflowgid",
682 .data
= &overflowgid
,
683 .maxlen
= sizeof(int),
685 .proc_handler
= proc_dointvec_minmax
,
686 .extra1
= &minolduid
,
687 .extra2
= &maxolduid
,
690 #ifdef CONFIG_MATHEMU
692 .procname
= "ieee_emulation_warnings",
693 .data
= &sysctl_ieee_emulation_warnings
,
694 .maxlen
= sizeof(int),
696 .proc_handler
= proc_dointvec
,
700 .procname
= "userprocess_debug",
701 .data
= &show_unhandled_signals
,
702 .maxlen
= sizeof(int),
704 .proc_handler
= proc_dointvec
,
708 .procname
= "pid_max",
710 .maxlen
= sizeof (int),
712 .proc_handler
= proc_dointvec_minmax
,
713 .extra1
= &pid_max_min
,
714 .extra2
= &pid_max_max
,
717 .procname
= "panic_on_oops",
718 .data
= &panic_on_oops
,
719 .maxlen
= sizeof(int),
721 .proc_handler
= proc_dointvec
,
723 #if defined CONFIG_PRINTK
725 .procname
= "printk",
726 .data
= &console_loglevel
,
727 .maxlen
= 4*sizeof(int),
729 .proc_handler
= proc_dointvec
,
732 .procname
= "printk_ratelimit",
733 .data
= &printk_ratelimit_state
.interval
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= proc_dointvec_jiffies
,
739 .procname
= "printk_ratelimit_burst",
740 .data
= &printk_ratelimit_state
.burst
,
741 .maxlen
= sizeof(int),
743 .proc_handler
= proc_dointvec
,
746 .procname
= "printk_delay",
747 .data
= &printk_delay_msec
,
748 .maxlen
= sizeof(int),
750 .proc_handler
= proc_dointvec_minmax
,
752 .extra2
= &ten_thousand
,
755 .procname
= "dmesg_restrict",
756 .data
= &dmesg_restrict
,
757 .maxlen
= sizeof(int),
759 .proc_handler
= proc_dointvec_minmax_sysadmin
,
764 .procname
= "kptr_restrict",
765 .data
= &kptr_restrict
,
766 .maxlen
= sizeof(int),
768 .proc_handler
= proc_dointvec_minmax_sysadmin
,
774 .procname
= "ngroups_max",
775 .data
= &ngroups_max
,
776 .maxlen
= sizeof (int),
778 .proc_handler
= proc_dointvec
,
781 .procname
= "cap_last_cap",
782 .data
= (void *)&cap_last_cap
,
783 .maxlen
= sizeof(int),
785 .proc_handler
= proc_dointvec
,
787 #if defined(CONFIG_LOCKUP_DETECTOR)
789 .procname
= "watchdog",
790 .data
= &watchdog_enabled
,
791 .maxlen
= sizeof (int),
793 .proc_handler
= proc_dowatchdog
,
798 .procname
= "watchdog_thresh",
799 .data
= &watchdog_thresh
,
800 .maxlen
= sizeof(int),
802 .proc_handler
= proc_dowatchdog
,
807 .procname
= "softlockup_panic",
808 .data
= &softlockup_panic
,
809 .maxlen
= sizeof(int),
811 .proc_handler
= proc_dointvec_minmax
,
816 .procname
= "nmi_watchdog",
817 .data
= &watchdog_enabled
,
818 .maxlen
= sizeof (int),
820 .proc_handler
= proc_dowatchdog
,
825 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
827 .procname
= "unknown_nmi_panic",
828 .data
= &unknown_nmi_panic
,
829 .maxlen
= sizeof (int),
831 .proc_handler
= proc_dointvec
,
834 #if defined(CONFIG_X86)
836 .procname
= "panic_on_unrecovered_nmi",
837 .data
= &panic_on_unrecovered_nmi
,
838 .maxlen
= sizeof(int),
840 .proc_handler
= proc_dointvec
,
843 .procname
= "panic_on_io_nmi",
844 .data
= &panic_on_io_nmi
,
845 .maxlen
= sizeof(int),
847 .proc_handler
= proc_dointvec
,
849 #ifdef CONFIG_DEBUG_STACKOVERFLOW
851 .procname
= "panic_on_stackoverflow",
852 .data
= &sysctl_panic_on_stackoverflow
,
853 .maxlen
= sizeof(int),
855 .proc_handler
= proc_dointvec
,
859 .procname
= "bootloader_type",
860 .data
= &bootloader_type
,
861 .maxlen
= sizeof (int),
863 .proc_handler
= proc_dointvec
,
866 .procname
= "bootloader_version",
867 .data
= &bootloader_version
,
868 .maxlen
= sizeof (int),
870 .proc_handler
= proc_dointvec
,
873 .procname
= "kstack_depth_to_print",
874 .data
= &kstack_depth_to_print
,
875 .maxlen
= sizeof(int),
877 .proc_handler
= proc_dointvec
,
880 .procname
= "io_delay_type",
881 .data
= &io_delay_type
,
882 .maxlen
= sizeof(int),
884 .proc_handler
= proc_dointvec
,
887 #if defined(CONFIG_MMU)
889 .procname
= "randomize_va_space",
890 .data
= &randomize_va_space
,
891 .maxlen
= sizeof(int),
893 .proc_handler
= proc_dointvec
,
896 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
898 .procname
= "spin_retry",
900 .maxlen
= sizeof (int),
902 .proc_handler
= proc_dointvec
,
905 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
907 .procname
= "acpi_video_flags",
908 .data
= &acpi_realmode_flags
,
909 .maxlen
= sizeof (unsigned long),
911 .proc_handler
= proc_doulongvec_minmax
,
916 .procname
= "ignore-unaligned-usertrap",
917 .data
= &no_unaligned_warning
,
918 .maxlen
= sizeof (int),
920 .proc_handler
= proc_dointvec
,
923 .procname
= "unaligned-dump-stack",
924 .data
= &unaligned_dump_stack
,
925 .maxlen
= sizeof (int),
927 .proc_handler
= proc_dointvec
,
930 #ifdef CONFIG_DETECT_HUNG_TASK
932 .procname
= "hung_task_panic",
933 .data
= &sysctl_hung_task_panic
,
934 .maxlen
= sizeof(int),
936 .proc_handler
= proc_dointvec_minmax
,
941 .procname
= "hung_task_check_count",
942 .data
= &sysctl_hung_task_check_count
,
943 .maxlen
= sizeof(unsigned long),
945 .proc_handler
= proc_doulongvec_minmax
,
948 .procname
= "hung_task_timeout_secs",
949 .data
= &sysctl_hung_task_timeout_secs
,
950 .maxlen
= sizeof(unsigned long),
952 .proc_handler
= proc_dohung_task_timeout_secs
,
955 .procname
= "hung_task_warnings",
956 .data
= &sysctl_hung_task_warnings
,
957 .maxlen
= sizeof(unsigned long),
959 .proc_handler
= proc_doulongvec_minmax
,
964 .procname
= "compat-log",
966 .maxlen
= sizeof (int),
968 .proc_handler
= proc_dointvec
,
971 #ifdef CONFIG_RT_MUTEXES
973 .procname
= "max_lock_depth",
974 .data
= &max_lock_depth
,
975 .maxlen
= sizeof(int),
977 .proc_handler
= proc_dointvec
,
981 .procname
= "poweroff_cmd",
982 .data
= &poweroff_cmd
,
983 .maxlen
= POWEROFF_CMD_PATH_LEN
,
985 .proc_handler
= proc_dostring
,
991 .child
= key_sysctls
,
994 #ifdef CONFIG_RCU_TORTURE_TEST
996 .procname
= "rcutorture_runnable",
997 .data
= &rcutorture_runnable
,
998 .maxlen
= sizeof(int),
1000 .proc_handler
= proc_dointvec
,
1003 #ifdef CONFIG_PERF_EVENTS
1005 * User-space scripts rely on the existence of this file
1006 * as a feature check for perf_events being enabled.
1008 * So it's an ABI, do not remove!
1011 .procname
= "perf_event_paranoid",
1012 .data
= &sysctl_perf_event_paranoid
,
1013 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1015 .proc_handler
= proc_dointvec
,
1018 .procname
= "perf_event_mlock_kb",
1019 .data
= &sysctl_perf_event_mlock
,
1020 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1022 .proc_handler
= proc_dointvec
,
1025 .procname
= "perf_event_max_sample_rate",
1026 .data
= &sysctl_perf_event_sample_rate
,
1027 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1029 .proc_handler
= perf_proc_update_handler
,
1032 #ifdef CONFIG_KMEMCHECK
1034 .procname
= "kmemcheck",
1035 .data
= &kmemcheck_enabled
,
1036 .maxlen
= sizeof(int),
1038 .proc_handler
= proc_dointvec
,
1043 .procname
= "blk_iopoll",
1044 .data
= &blk_iopoll_enabled
,
1045 .maxlen
= sizeof(int),
1047 .proc_handler
= proc_dointvec
,
1053 static struct ctl_table vm_table
[] = {
1055 .procname
= "overcommit_memory",
1056 .data
= &sysctl_overcommit_memory
,
1057 .maxlen
= sizeof(sysctl_overcommit_memory
),
1059 .proc_handler
= proc_dointvec_minmax
,
1064 .procname
= "panic_on_oom",
1065 .data
= &sysctl_panic_on_oom
,
1066 .maxlen
= sizeof(sysctl_panic_on_oom
),
1068 .proc_handler
= proc_dointvec_minmax
,
1073 .procname
= "oom_kill_allocating_task",
1074 .data
= &sysctl_oom_kill_allocating_task
,
1075 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1077 .proc_handler
= proc_dointvec
,
1080 .procname
= "oom_dump_tasks",
1081 .data
= &sysctl_oom_dump_tasks
,
1082 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1084 .proc_handler
= proc_dointvec
,
1087 .procname
= "overcommit_ratio",
1088 .data
= &sysctl_overcommit_ratio
,
1089 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1091 .proc_handler
= proc_dointvec
,
1094 .procname
= "page-cluster",
1095 .data
= &page_cluster
,
1096 .maxlen
= sizeof(int),
1098 .proc_handler
= proc_dointvec_minmax
,
1102 .procname
= "dirty_background_ratio",
1103 .data
= &dirty_background_ratio
,
1104 .maxlen
= sizeof(dirty_background_ratio
),
1106 .proc_handler
= dirty_background_ratio_handler
,
1108 .extra2
= &one_hundred
,
1111 .procname
= "dirty_background_bytes",
1112 .data
= &dirty_background_bytes
,
1113 .maxlen
= sizeof(dirty_background_bytes
),
1115 .proc_handler
= dirty_background_bytes_handler
,
1119 .procname
= "dirty_ratio",
1120 .data
= &vm_dirty_ratio
,
1121 .maxlen
= sizeof(vm_dirty_ratio
),
1123 .proc_handler
= dirty_ratio_handler
,
1125 .extra2
= &one_hundred
,
1128 .procname
= "dirty_bytes",
1129 .data
= &vm_dirty_bytes
,
1130 .maxlen
= sizeof(vm_dirty_bytes
),
1132 .proc_handler
= dirty_bytes_handler
,
1133 .extra1
= &dirty_bytes_min
,
1136 .procname
= "dirty_writeback_centisecs",
1137 .data
= &dirty_writeback_interval
,
1138 .maxlen
= sizeof(dirty_writeback_interval
),
1140 .proc_handler
= dirty_writeback_centisecs_handler
,
1143 .procname
= "dirty_expire_centisecs",
1144 .data
= &dirty_expire_interval
,
1145 .maxlen
= sizeof(dirty_expire_interval
),
1147 .proc_handler
= proc_dointvec_minmax
,
1151 .procname
= "nr_pdflush_threads",
1152 .mode
= 0444 /* read-only */,
1153 .proc_handler
= pdflush_proc_obsolete
,
1156 .procname
= "swappiness",
1157 .data
= &vm_swappiness
,
1158 .maxlen
= sizeof(vm_swappiness
),
1160 .proc_handler
= proc_dointvec_minmax
,
1162 .extra2
= &one_hundred
,
1164 #ifdef CONFIG_HUGETLB_PAGE
1166 .procname
= "nr_hugepages",
1168 .maxlen
= sizeof(unsigned long),
1170 .proc_handler
= hugetlb_sysctl_handler
,
1171 .extra1
= (void *)&hugetlb_zero
,
1172 .extra2
= (void *)&hugetlb_infinity
,
1176 .procname
= "nr_hugepages_mempolicy",
1178 .maxlen
= sizeof(unsigned long),
1180 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1181 .extra1
= (void *)&hugetlb_zero
,
1182 .extra2
= (void *)&hugetlb_infinity
,
1186 .procname
= "hugetlb_shm_group",
1187 .data
= &sysctl_hugetlb_shm_group
,
1188 .maxlen
= sizeof(gid_t
),
1190 .proc_handler
= proc_dointvec
,
1193 .procname
= "hugepages_treat_as_movable",
1194 .data
= &hugepages_treat_as_movable
,
1195 .maxlen
= sizeof(int),
1197 .proc_handler
= hugetlb_treat_movable_handler
,
1200 .procname
= "nr_overcommit_hugepages",
1202 .maxlen
= sizeof(unsigned long),
1204 .proc_handler
= hugetlb_overcommit_handler
,
1205 .extra1
= (void *)&hugetlb_zero
,
1206 .extra2
= (void *)&hugetlb_infinity
,
1210 .procname
= "lowmem_reserve_ratio",
1211 .data
= &sysctl_lowmem_reserve_ratio
,
1212 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1214 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1217 .procname
= "drop_caches",
1218 .data
= &sysctl_drop_caches
,
1219 .maxlen
= sizeof(int),
1221 .proc_handler
= drop_caches_sysctl_handler
,
1225 #ifdef CONFIG_COMPACTION
1227 .procname
= "compact_memory",
1228 .data
= &sysctl_compact_memory
,
1229 .maxlen
= sizeof(int),
1231 .proc_handler
= sysctl_compaction_handler
,
1234 .procname
= "extfrag_threshold",
1235 .data
= &sysctl_extfrag_threshold
,
1236 .maxlen
= sizeof(int),
1238 .proc_handler
= sysctl_extfrag_handler
,
1239 .extra1
= &min_extfrag_threshold
,
1240 .extra2
= &max_extfrag_threshold
,
1243 #endif /* CONFIG_COMPACTION */
1245 .procname
= "min_free_kbytes",
1246 .data
= &min_free_kbytes
,
1247 .maxlen
= sizeof(min_free_kbytes
),
1249 .proc_handler
= min_free_kbytes_sysctl_handler
,
1253 .procname
= "percpu_pagelist_fraction",
1254 .data
= &percpu_pagelist_fraction
,
1255 .maxlen
= sizeof(percpu_pagelist_fraction
),
1257 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1258 .extra1
= &min_percpu_pagelist_fract
,
1262 .procname
= "max_map_count",
1263 .data
= &sysctl_max_map_count
,
1264 .maxlen
= sizeof(sysctl_max_map_count
),
1266 .proc_handler
= proc_dointvec_minmax
,
1271 .procname
= "nr_trim_pages",
1272 .data
= &sysctl_nr_trim_pages
,
1273 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1275 .proc_handler
= proc_dointvec_minmax
,
1280 .procname
= "laptop_mode",
1281 .data
= &laptop_mode
,
1282 .maxlen
= sizeof(laptop_mode
),
1284 .proc_handler
= proc_dointvec_jiffies
,
1287 .procname
= "block_dump",
1288 .data
= &block_dump
,
1289 .maxlen
= sizeof(block_dump
),
1291 .proc_handler
= proc_dointvec
,
1295 .procname
= "vfs_cache_pressure",
1296 .data
= &sysctl_vfs_cache_pressure
,
1297 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1299 .proc_handler
= proc_dointvec
,
1302 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1304 .procname
= "legacy_va_layout",
1305 .data
= &sysctl_legacy_va_layout
,
1306 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1308 .proc_handler
= proc_dointvec
,
1314 .procname
= "zone_reclaim_mode",
1315 .data
= &zone_reclaim_mode
,
1316 .maxlen
= sizeof(zone_reclaim_mode
),
1318 .proc_handler
= proc_dointvec
,
1322 .procname
= "min_unmapped_ratio",
1323 .data
= &sysctl_min_unmapped_ratio
,
1324 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1326 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1328 .extra2
= &one_hundred
,
1331 .procname
= "min_slab_ratio",
1332 .data
= &sysctl_min_slab_ratio
,
1333 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1335 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1337 .extra2
= &one_hundred
,
1342 .procname
= "stat_interval",
1343 .data
= &sysctl_stat_interval
,
1344 .maxlen
= sizeof(sysctl_stat_interval
),
1346 .proc_handler
= proc_dointvec_jiffies
,
1351 .procname
= "mmap_min_addr",
1352 .data
= &dac_mmap_min_addr
,
1353 .maxlen
= sizeof(unsigned long),
1355 .proc_handler
= mmap_min_addr_handler
,
1360 .procname
= "numa_zonelist_order",
1361 .data
= &numa_zonelist_order
,
1362 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1364 .proc_handler
= numa_zonelist_order_handler
,
1367 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1368 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1370 .procname
= "vdso_enabled",
1371 .data
= &vdso_enabled
,
1372 .maxlen
= sizeof(vdso_enabled
),
1374 .proc_handler
= proc_dointvec
,
1378 #ifdef CONFIG_HIGHMEM
1380 .procname
= "highmem_is_dirtyable",
1381 .data
= &vm_highmem_is_dirtyable
,
1382 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1384 .proc_handler
= proc_dointvec_minmax
,
1390 .procname
= "scan_unevictable_pages",
1391 .data
= &scan_unevictable_pages
,
1392 .maxlen
= sizeof(scan_unevictable_pages
),
1394 .proc_handler
= scan_unevictable_handler
,
1396 #ifdef CONFIG_MEMORY_FAILURE
1398 .procname
= "memory_failure_early_kill",
1399 .data
= &sysctl_memory_failure_early_kill
,
1400 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1402 .proc_handler
= proc_dointvec_minmax
,
1407 .procname
= "memory_failure_recovery",
1408 .data
= &sysctl_memory_failure_recovery
,
1409 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1411 .proc_handler
= proc_dointvec_minmax
,
1419 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1420 static struct ctl_table binfmt_misc_table
[] = {
1425 static struct ctl_table fs_table
[] = {
1427 .procname
= "inode-nr",
1428 .data
= &inodes_stat
,
1429 .maxlen
= 2*sizeof(int),
1431 .proc_handler
= proc_nr_inodes
,
1434 .procname
= "inode-state",
1435 .data
= &inodes_stat
,
1436 .maxlen
= 7*sizeof(int),
1438 .proc_handler
= proc_nr_inodes
,
1441 .procname
= "file-nr",
1442 .data
= &files_stat
,
1443 .maxlen
= sizeof(files_stat
),
1445 .proc_handler
= proc_nr_files
,
1448 .procname
= "file-max",
1449 .data
= &files_stat
.max_files
,
1450 .maxlen
= sizeof(files_stat
.max_files
),
1452 .proc_handler
= proc_doulongvec_minmax
,
1455 .procname
= "nr_open",
1456 .data
= &sysctl_nr_open
,
1457 .maxlen
= sizeof(int),
1459 .proc_handler
= proc_dointvec_minmax
,
1460 .extra1
= &sysctl_nr_open_min
,
1461 .extra2
= &sysctl_nr_open_max
,
1464 .procname
= "dentry-state",
1465 .data
= &dentry_stat
,
1466 .maxlen
= 6*sizeof(int),
1468 .proc_handler
= proc_nr_dentry
,
1471 .procname
= "overflowuid",
1472 .data
= &fs_overflowuid
,
1473 .maxlen
= sizeof(int),
1475 .proc_handler
= proc_dointvec_minmax
,
1476 .extra1
= &minolduid
,
1477 .extra2
= &maxolduid
,
1480 .procname
= "overflowgid",
1481 .data
= &fs_overflowgid
,
1482 .maxlen
= sizeof(int),
1484 .proc_handler
= proc_dointvec_minmax
,
1485 .extra1
= &minolduid
,
1486 .extra2
= &maxolduid
,
1488 #ifdef CONFIG_FILE_LOCKING
1490 .procname
= "leases-enable",
1491 .data
= &leases_enable
,
1492 .maxlen
= sizeof(int),
1494 .proc_handler
= proc_dointvec
,
1497 #ifdef CONFIG_DNOTIFY
1499 .procname
= "dir-notify-enable",
1500 .data
= &dir_notify_enable
,
1501 .maxlen
= sizeof(int),
1503 .proc_handler
= proc_dointvec
,
1507 #ifdef CONFIG_FILE_LOCKING
1509 .procname
= "lease-break-time",
1510 .data
= &lease_break_time
,
1511 .maxlen
= sizeof(int),
1513 .proc_handler
= proc_dointvec
,
1518 .procname
= "aio-nr",
1520 .maxlen
= sizeof(aio_nr
),
1522 .proc_handler
= proc_doulongvec_minmax
,
1525 .procname
= "aio-max-nr",
1526 .data
= &aio_max_nr
,
1527 .maxlen
= sizeof(aio_max_nr
),
1529 .proc_handler
= proc_doulongvec_minmax
,
1531 #endif /* CONFIG_AIO */
1532 #ifdef CONFIG_INOTIFY_USER
1534 .procname
= "inotify",
1536 .child
= inotify_table
,
1541 .procname
= "epoll",
1543 .child
= epoll_table
,
1548 .procname
= "protected_symlinks",
1549 .data
= &sysctl_protected_symlinks
,
1550 .maxlen
= sizeof(int),
1552 .proc_handler
= proc_dointvec_minmax
,
1557 .procname
= "protected_hardlinks",
1558 .data
= &sysctl_protected_hardlinks
,
1559 .maxlen
= sizeof(int),
1561 .proc_handler
= proc_dointvec_minmax
,
1566 .procname
= "suid_dumpable",
1567 .data
= &suid_dumpable
,
1568 .maxlen
= sizeof(int),
1570 .proc_handler
= proc_dointvec_minmax_coredump
,
1574 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1576 .procname
= "binfmt_misc",
1578 .child
= binfmt_misc_table
,
1582 .procname
= "pipe-max-size",
1583 .data
= &pipe_max_size
,
1584 .maxlen
= sizeof(int),
1586 .proc_handler
= &pipe_proc_fn
,
1587 .extra1
= &pipe_min_size
,
1592 static struct ctl_table debug_table
[] = {
1593 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1595 .procname
= "exception-trace",
1596 .data
= &show_unhandled_signals
,
1597 .maxlen
= sizeof(int),
1599 .proc_handler
= proc_dointvec
1602 #if defined(CONFIG_OPTPROBES)
1604 .procname
= "kprobes-optimization",
1605 .data
= &sysctl_kprobes_optimization
,
1606 .maxlen
= sizeof(int),
1608 .proc_handler
= proc_kprobes_optimization_handler
,
1616 static struct ctl_table dev_table
[] = {
1620 int __init
sysctl_init(void)
1622 struct ctl_table_header
*hdr
;
1624 hdr
= register_sysctl_table(sysctl_base_table
);
1625 kmemleak_not_leak(hdr
);
1629 #endif /* CONFIG_SYSCTL */
1635 #ifdef CONFIG_PROC_SYSCTL
1637 static int _proc_do_string(void* data
, int maxlen
, int write
,
1638 void __user
*buffer
,
1639 size_t *lenp
, loff_t
*ppos
)
1645 if (!data
|| !maxlen
|| !*lenp
) {
1653 while (len
< *lenp
) {
1654 if (get_user(c
, p
++))
1656 if (c
== 0 || c
== '\n')
1662 if(copy_from_user(data
, buffer
, len
))
1664 ((char *) data
)[len
] = 0;
1682 if(copy_to_user(buffer
, data
, len
))
1685 if(put_user('\n', ((char __user
*) buffer
) + len
))
1696 * proc_dostring - read a string sysctl
1697 * @table: the sysctl table
1698 * @write: %TRUE if this is a write to the sysctl file
1699 * @buffer: the user buffer
1700 * @lenp: the size of the user buffer
1701 * @ppos: file position
1703 * Reads/writes a string from/to the user buffer. If the kernel
1704 * buffer provided is not large enough to hold the string, the
1705 * string is truncated. The copied string is %NULL-terminated.
1706 * If the string is being read by the user process, it is copied
1707 * and a newline '\n' is added. It is truncated if the buffer is
1710 * Returns 0 on success.
1712 int proc_dostring(struct ctl_table
*table
, int write
,
1713 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1715 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1716 buffer
, lenp
, ppos
);
1719 static size_t proc_skip_spaces(char **buf
)
1722 char *tmp
= skip_spaces(*buf
);
1728 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1738 #define TMPBUFLEN 22
1740 * proc_get_long - reads an ASCII formatted integer from a user buffer
1742 * @buf: a kernel buffer
1743 * @size: size of the kernel buffer
1744 * @val: this is where the number will be stored
1745 * @neg: set to %TRUE if number is negative
1746 * @perm_tr: a vector which contains the allowed trailers
1747 * @perm_tr_len: size of the perm_tr vector
1748 * @tr: pointer to store the trailer character
1750 * In case of success %0 is returned and @buf and @size are updated with
1751 * the amount of bytes read. If @tr is non-NULL and a trailing
1752 * character exists (size is non-zero after returning from this
1753 * function), @tr is updated with the trailing character.
1755 static int proc_get_long(char **buf
, size_t *size
,
1756 unsigned long *val
, bool *neg
,
1757 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1760 char *p
, tmp
[TMPBUFLEN
];
1766 if (len
> TMPBUFLEN
- 1)
1767 len
= TMPBUFLEN
- 1;
1769 memcpy(tmp
, *buf
, len
);
1773 if (*p
== '-' && *size
> 1) {
1781 *val
= simple_strtoul(p
, &p
, 0);
1785 /* We don't know if the next char is whitespace thus we may accept
1786 * invalid integers (e.g. 1234...a) or two integers instead of one
1787 * (e.g. 123...1). So lets not allow such large numbers. */
1788 if (len
== TMPBUFLEN
- 1)
1791 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1794 if (tr
&& (len
< *size
))
1804 * proc_put_long - converts an integer to a decimal ASCII formatted string
1806 * @buf: the user buffer
1807 * @size: the size of the user buffer
1808 * @val: the integer to be converted
1809 * @neg: sign of the number, %TRUE for negative
1811 * In case of success %0 is returned and @buf and @size are updated with
1812 * the amount of bytes written.
1814 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1818 char tmp
[TMPBUFLEN
], *p
= tmp
;
1820 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1824 if (copy_to_user(*buf
, tmp
, len
))
1832 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1835 char __user
**buffer
= (char __user
**)buf
;
1836 if (put_user(c
, *buffer
))
1838 (*size
)--, (*buffer
)++;
1844 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1846 int write
, void *data
)
1849 *valp
= *negp
? -*lvalp
: *lvalp
;
1854 *lvalp
= (unsigned long)-val
;
1857 *lvalp
= (unsigned long)val
;
1863 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1865 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1866 int write
, void __user
*buffer
,
1867 size_t *lenp
, loff_t
*ppos
,
1868 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1869 int write
, void *data
),
1872 int *i
, vleft
, first
= 1, err
= 0;
1873 unsigned long page
= 0;
1877 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1882 i
= (int *) tbl_data
;
1883 vleft
= table
->maxlen
/ sizeof(*i
);
1887 conv
= do_proc_dointvec_conv
;
1890 if (left
> PAGE_SIZE
- 1)
1891 left
= PAGE_SIZE
- 1;
1892 page
= __get_free_page(GFP_TEMPORARY
);
1893 kbuf
= (char *) page
;
1896 if (copy_from_user(kbuf
, buffer
, left
)) {
1903 for (; left
&& vleft
--; i
++, first
=0) {
1908 left
-= proc_skip_spaces(&kbuf
);
1912 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1914 sizeof(proc_wspace_sep
), NULL
);
1917 if (conv(&neg
, &lval
, i
, 1, data
)) {
1922 if (conv(&neg
, &lval
, i
, 0, data
)) {
1927 err
= proc_put_char(&buffer
, &left
, '\t');
1930 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
1936 if (!write
&& !first
&& left
&& !err
)
1937 err
= proc_put_char(&buffer
, &left
, '\n');
1938 if (write
&& !err
&& left
)
1939 left
-= proc_skip_spaces(&kbuf
);
1944 return err
? : -EINVAL
;
1951 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
1952 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1953 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1954 int write
, void *data
),
1957 return __do_proc_dointvec(table
->data
, table
, write
,
1958 buffer
, lenp
, ppos
, conv
, data
);
1962 * proc_dointvec - read a vector of integers
1963 * @table: the sysctl table
1964 * @write: %TRUE if this is a write to the sysctl file
1965 * @buffer: the user buffer
1966 * @lenp: the size of the user buffer
1967 * @ppos: file position
1969 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1970 * values from/to the user buffer, treated as an ASCII string.
1972 * Returns 0 on success.
1974 int proc_dointvec(struct ctl_table
*table
, int write
,
1975 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1977 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
1982 * Taint values can only be increased
1983 * This means we can safely use a temporary.
1985 static int proc_taint(struct ctl_table
*table
, int write
,
1986 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1989 unsigned long tmptaint
= get_taint();
1992 if (write
&& !capable(CAP_SYS_ADMIN
))
1997 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2003 * Poor man's atomic or. Not worth adding a primitive
2004 * to everyone's atomic.h for this
2007 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2008 if ((tmptaint
>> i
) & 1)
2016 #ifdef CONFIG_PRINTK
2017 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2018 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2020 if (write
&& !capable(CAP_SYS_ADMIN
))
2023 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2027 struct do_proc_dointvec_minmax_conv_param
{
2032 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2034 int write
, void *data
)
2036 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2038 int val
= *negp
? -*lvalp
: *lvalp
;
2039 if ((param
->min
&& *param
->min
> val
) ||
2040 (param
->max
&& *param
->max
< val
))
2047 *lvalp
= (unsigned long)-val
;
2050 *lvalp
= (unsigned long)val
;
2057 * proc_dointvec_minmax - read a vector of integers with min/max values
2058 * @table: the sysctl table
2059 * @write: %TRUE if this is a write to the sysctl file
2060 * @buffer: the user buffer
2061 * @lenp: the size of the user buffer
2062 * @ppos: file position
2064 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2065 * values from/to the user buffer, treated as an ASCII string.
2067 * This routine will ensure the values are within the range specified by
2068 * table->extra1 (min) and table->extra2 (max).
2070 * Returns 0 on success.
2072 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2073 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2075 struct do_proc_dointvec_minmax_conv_param param
= {
2076 .min
= (int *) table
->extra1
,
2077 .max
= (int *) table
->extra2
,
2079 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2080 do_proc_dointvec_minmax_conv
, ¶m
);
2083 static void validate_coredump_safety(void)
2085 #ifdef CONFIG_COREDUMP
2086 if (suid_dumpable
== SUID_DUMPABLE_SAFE
&&
2087 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2088 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2089 "suid_dumpable=2. Pipe handler or fully qualified "\
2090 "core dump path required.\n");
2095 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2096 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2098 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2100 validate_coredump_safety();
2104 #ifdef CONFIG_COREDUMP
2105 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2106 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2108 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2110 validate_coredump_safety();
2115 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2116 void __user
*buffer
,
2117 size_t *lenp
, loff_t
*ppos
,
2118 unsigned long convmul
,
2119 unsigned long convdiv
)
2121 unsigned long *i
, *min
, *max
;
2122 int vleft
, first
= 1, err
= 0;
2123 unsigned long page
= 0;
2127 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2132 i
= (unsigned long *) data
;
2133 min
= (unsigned long *) table
->extra1
;
2134 max
= (unsigned long *) table
->extra2
;
2135 vleft
= table
->maxlen
/ sizeof(unsigned long);
2139 if (left
> PAGE_SIZE
- 1)
2140 left
= PAGE_SIZE
- 1;
2141 page
= __get_free_page(GFP_TEMPORARY
);
2142 kbuf
= (char *) page
;
2145 if (copy_from_user(kbuf
, buffer
, left
)) {
2152 for (; left
&& vleft
--; i
++, first
= 0) {
2158 left
-= proc_skip_spaces(&kbuf
);
2160 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2162 sizeof(proc_wspace_sep
), NULL
);
2167 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2171 val
= convdiv
* (*i
) / convmul
;
2173 err
= proc_put_char(&buffer
, &left
, '\t');
2174 err
= proc_put_long(&buffer
, &left
, val
, false);
2180 if (!write
&& !first
&& left
&& !err
)
2181 err
= proc_put_char(&buffer
, &left
, '\n');
2183 left
-= proc_skip_spaces(&kbuf
);
2188 return err
? : -EINVAL
;
2195 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2196 void __user
*buffer
,
2197 size_t *lenp
, loff_t
*ppos
,
2198 unsigned long convmul
,
2199 unsigned long convdiv
)
2201 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2202 buffer
, lenp
, ppos
, convmul
, convdiv
);
2206 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2207 * @table: the sysctl table
2208 * @write: %TRUE if this is a write to the sysctl file
2209 * @buffer: the user buffer
2210 * @lenp: the size of the user buffer
2211 * @ppos: file position
2213 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2214 * values from/to the user buffer, treated as an ASCII string.
2216 * This routine will ensure the values are within the range specified by
2217 * table->extra1 (min) and table->extra2 (max).
2219 * Returns 0 on success.
2221 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2222 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2224 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2228 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
2231 * @buffer: the user buffer
2232 * @lenp: the size of the user buffer
2233 * @ppos: file position
2235 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2236 * values from/to the user buffer, treated as an ASCII string. The values
2237 * are treated as milliseconds, and converted to jiffies when they are stored.
2239 * This routine will ensure the values are within the range specified by
2240 * table->extra1 (min) and table->extra2 (max).
2242 * Returns 0 on success.
2244 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2245 void __user
*buffer
,
2246 size_t *lenp
, loff_t
*ppos
)
2248 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2249 lenp
, ppos
, HZ
, 1000l);
2253 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2255 int write
, void *data
)
2258 if (*lvalp
> LONG_MAX
/ HZ
)
2260 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2266 lval
= (unsigned long)-val
;
2269 lval
= (unsigned long)val
;
2276 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2278 int write
, void *data
)
2281 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2283 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2289 lval
= (unsigned long)-val
;
2292 lval
= (unsigned long)val
;
2294 *lvalp
= jiffies_to_clock_t(lval
);
2299 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2301 int write
, void *data
)
2304 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2310 lval
= (unsigned long)-val
;
2313 lval
= (unsigned long)val
;
2315 *lvalp
= jiffies_to_msecs(lval
);
2321 * proc_dointvec_jiffies - read a vector of integers as seconds
2322 * @table: the sysctl table
2323 * @write: %TRUE if this is a write to the sysctl file
2324 * @buffer: the user buffer
2325 * @lenp: the size of the user buffer
2326 * @ppos: file position
2328 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2329 * values from/to the user buffer, treated as an ASCII string.
2330 * The values read are assumed to be in seconds, and are converted into
2333 * Returns 0 on success.
2335 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2336 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2338 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2339 do_proc_dointvec_jiffies_conv
,NULL
);
2343 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2344 * @table: the sysctl table
2345 * @write: %TRUE if this is a write to the sysctl file
2346 * @buffer: the user buffer
2347 * @lenp: the size of the user buffer
2348 * @ppos: pointer to the file position
2350 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2351 * values from/to the user buffer, treated as an ASCII string.
2352 * The values read are assumed to be in 1/USER_HZ seconds, and
2353 * are converted into jiffies.
2355 * Returns 0 on success.
2357 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2358 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2360 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2361 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2365 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2366 * @table: the sysctl table
2367 * @write: %TRUE if this is a write to the sysctl file
2368 * @buffer: the user buffer
2369 * @lenp: the size of the user buffer
2370 * @ppos: file position
2371 * @ppos: the current position in the file
2373 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2374 * values from/to the user buffer, treated as an ASCII string.
2375 * The values read are assumed to be in 1/1000 seconds, and
2376 * are converted into jiffies.
2378 * Returns 0 on success.
2380 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2381 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2383 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2384 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2387 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2388 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2390 struct pid
*new_pid
;
2394 tmp
= pid_vnr(cad_pid
);
2396 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2397 lenp
, ppos
, NULL
, NULL
);
2401 new_pid
= find_get_pid(tmp
);
2405 put_pid(xchg(&cad_pid
, new_pid
));
2410 * proc_do_large_bitmap - read/write from/to a large bitmap
2411 * @table: the sysctl table
2412 * @write: %TRUE if this is a write to the sysctl file
2413 * @buffer: the user buffer
2414 * @lenp: the size of the user buffer
2415 * @ppos: file position
2417 * The bitmap is stored at table->data and the bitmap length (in bits)
2420 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2421 * large bitmaps may be represented in a compact manner. Writing into
2422 * the file will clear the bitmap then update it with the given input.
2424 * Returns 0 on success.
2426 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2427 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2431 size_t left
= *lenp
;
2432 unsigned long bitmap_len
= table
->maxlen
;
2433 unsigned long *bitmap
= (unsigned long *) table
->data
;
2434 unsigned long *tmp_bitmap
= NULL
;
2435 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2437 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2443 unsigned long page
= 0;
2446 if (left
> PAGE_SIZE
- 1)
2447 left
= PAGE_SIZE
- 1;
2449 page
= __get_free_page(GFP_TEMPORARY
);
2450 kbuf
= (char *) page
;
2453 if (copy_from_user(kbuf
, buffer
, left
)) {
2459 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2465 proc_skip_char(&kbuf
, &left
, '\n');
2466 while (!err
&& left
) {
2467 unsigned long val_a
, val_b
;
2470 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2474 if (val_a
>= bitmap_len
|| neg
) {
2486 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2487 &neg
, tr_b
, sizeof(tr_b
),
2491 if (val_b
>= bitmap_len
|| neg
||
2502 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2504 proc_skip_char(&kbuf
, &left
, '\n');
2508 unsigned long bit_a
, bit_b
= 0;
2511 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2512 if (bit_a
>= bitmap_len
)
2514 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2518 err
= proc_put_char(&buffer
, &left
, ',');
2522 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2525 if (bit_a
!= bit_b
) {
2526 err
= proc_put_char(&buffer
, &left
, '-');
2529 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2537 err
= proc_put_char(&buffer
, &left
, '\n');
2543 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2545 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2557 #else /* CONFIG_PROC_SYSCTL */
2559 int proc_dostring(struct ctl_table
*table
, int write
,
2560 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2565 int proc_dointvec(struct ctl_table
*table
, int write
,
2566 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2571 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2572 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2577 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2578 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2583 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2584 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2589 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2590 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2595 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2596 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2601 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2602 void __user
*buffer
,
2603 size_t *lenp
, loff_t
*ppos
)
2609 #endif /* CONFIG_PROC_SYSCTL */
2612 * No sense putting this after each symbol definition, twice,
2613 * exception granted :-)
2615 EXPORT_SYMBOL(proc_dointvec
);
2616 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2617 EXPORT_SYMBOL(proc_dointvec_minmax
);
2618 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2619 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2620 EXPORT_SYMBOL(proc_dostring
);
2621 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2622 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);