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>
65 #include <linux/kexec.h>
67 #include <asm/uaccess.h>
68 #include <asm/processor.h>
72 #include <asm/stacktrace.h>
76 #include <asm/setup.h>
78 #ifdef CONFIG_BSD_PROCESS_ACCT
79 #include <linux/acct.h>
81 #ifdef CONFIG_RT_MUTEXES
82 #include <linux/rtmutex.h>
84 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85 #include <linux/lockdep.h>
87 #ifdef CONFIG_CHR_DEV_SG
91 #ifdef CONFIG_LOCKUP_DETECTOR
92 #include <linux/nmi.h>
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
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 pid_max_min
, pid_max_max
;
108 extern int percpu_pagelist_fraction
;
109 extern int compat_log
;
110 extern int latencytop_enabled
;
111 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
113 extern int sysctl_nr_trim_pages
;
116 extern int blk_iopoll_enabled
;
119 /* Constants used for minimum and maximum */
120 #ifdef CONFIG_LOCKUP_DETECTOR
121 static int sixty
= 60;
124 static int __maybe_unused neg_one
= -1;
127 static int __maybe_unused one
= 1;
128 static int __maybe_unused two
= 2;
129 static int __maybe_unused three
= 3;
130 static unsigned long one_ul
= 1;
131 static int one_hundred
= 100;
133 static int ten_thousand
= 10000;
136 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
137 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
139 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
140 static int maxolduid
= 65535;
141 static int minolduid
;
143 static int ngroups_max
= NGROUPS_MAX
;
144 static const int cap_last_cap
= CAP_LAST_CAP
;
146 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
147 #ifdef CONFIG_DETECT_HUNG_TASK
148 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
151 #ifdef CONFIG_INOTIFY_USER
152 #include <linux/inotify.h>
157 #ifdef CONFIG_SPARC64
158 extern int sysctl_tsb_ratio
;
162 extern int pwrsw_enabled
;
165 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
166 extern int unaligned_enabled
;
170 extern int unaligned_dump_stack
;
173 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
174 extern int no_unaligned_warning
;
177 #ifdef CONFIG_PROC_SYSCTL
178 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
179 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
180 static int proc_taint(struct ctl_table
*table
, int write
,
181 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
185 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
186 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
189 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
190 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
191 #ifdef CONFIG_COREDUMP
192 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
193 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
196 #ifdef CONFIG_MAGIC_SYSRQ
197 /* Note: sysrq code uses it's own private copy */
198 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
200 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
201 void __user
*buffer
, size_t *lenp
,
206 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
211 sysrq_toggle_support(__sysrq_enabled
);
218 static struct ctl_table kern_table
[];
219 static struct ctl_table vm_table
[];
220 static struct ctl_table fs_table
[];
221 static struct ctl_table debug_table
[];
222 static struct ctl_table dev_table
[];
223 extern struct ctl_table random_table
[];
225 extern struct ctl_table epoll_table
[];
228 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
229 int sysctl_legacy_va_layout
;
232 /* The default sysctl tables: */
234 static struct ctl_table sysctl_base_table
[] = {
236 .procname
= "kernel",
253 .child
= debug_table
,
263 #ifdef CONFIG_SCHED_DEBUG
264 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
265 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
266 static int min_wakeup_granularity_ns
; /* 0 usecs */
267 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
269 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
270 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
271 #endif /* CONFIG_SMP */
272 #endif /* CONFIG_SCHED_DEBUG */
274 #ifdef CONFIG_COMPACTION
275 static int min_extfrag_threshold
;
276 static int max_extfrag_threshold
= 1000;
279 static struct ctl_table kern_table
[] = {
281 .procname
= "sched_child_runs_first",
282 .data
= &sysctl_sched_child_runs_first
,
283 .maxlen
= sizeof(unsigned int),
285 .proc_handler
= proc_dointvec
,
287 #ifdef CONFIG_SCHED_DEBUG
289 .procname
= "sched_min_granularity_ns",
290 .data
= &sysctl_sched_min_granularity
,
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_latency_ns",
299 .data
= &sysctl_sched_latency
,
300 .maxlen
= sizeof(unsigned int),
302 .proc_handler
= sched_proc_update_handler
,
303 .extra1
= &min_sched_granularity_ns
,
304 .extra2
= &max_sched_granularity_ns
,
307 .procname
= "sched_wakeup_granularity_ns",
308 .data
= &sysctl_sched_wakeup_granularity
,
309 .maxlen
= sizeof(unsigned int),
311 .proc_handler
= sched_proc_update_handler
,
312 .extra1
= &min_wakeup_granularity_ns
,
313 .extra2
= &max_wakeup_granularity_ns
,
317 .procname
= "sched_tunable_scaling",
318 .data
= &sysctl_sched_tunable_scaling
,
319 .maxlen
= sizeof(enum sched_tunable_scaling
),
321 .proc_handler
= sched_proc_update_handler
,
322 .extra1
= &min_sched_tunable_scaling
,
323 .extra2
= &max_sched_tunable_scaling
,
326 .procname
= "sched_migration_cost_ns",
327 .data
= &sysctl_sched_migration_cost
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= proc_dointvec
,
333 .procname
= "sched_nr_migrate",
334 .data
= &sysctl_sched_nr_migrate
,
335 .maxlen
= sizeof(unsigned int),
337 .proc_handler
= proc_dointvec
,
340 .procname
= "sched_time_avg_ms",
341 .data
= &sysctl_sched_time_avg
,
342 .maxlen
= sizeof(unsigned int),
344 .proc_handler
= proc_dointvec
,
347 .procname
= "sched_shares_window_ns",
348 .data
= &sysctl_sched_shares_window
,
349 .maxlen
= sizeof(unsigned int),
351 .proc_handler
= proc_dointvec
,
354 .procname
= "timer_migration",
355 .data
= &sysctl_timer_migration
,
356 .maxlen
= sizeof(unsigned int),
358 .proc_handler
= proc_dointvec_minmax
,
362 #endif /* CONFIG_SMP */
363 #ifdef CONFIG_NUMA_BALANCING
365 .procname
= "numa_balancing_scan_delay_ms",
366 .data
= &sysctl_numa_balancing_scan_delay
,
367 .maxlen
= sizeof(unsigned int),
369 .proc_handler
= proc_dointvec
,
372 .procname
= "numa_balancing_scan_period_min_ms",
373 .data
= &sysctl_numa_balancing_scan_period_min
,
374 .maxlen
= sizeof(unsigned int),
376 .proc_handler
= proc_dointvec
,
379 .procname
= "numa_balancing_scan_period_max_ms",
380 .data
= &sysctl_numa_balancing_scan_period_max
,
381 .maxlen
= sizeof(unsigned int),
383 .proc_handler
= proc_dointvec
,
386 .procname
= "numa_balancing_scan_size_mb",
387 .data
= &sysctl_numa_balancing_scan_size
,
388 .maxlen
= sizeof(unsigned int),
390 .proc_handler
= proc_dointvec
,
393 .procname
= "numa_balancing_migrate_deferred",
394 .data
= &sysctl_numa_balancing_migrate_deferred
,
395 .maxlen
= sizeof(unsigned int),
397 .proc_handler
= proc_dointvec
,
400 .procname
= "numa_balancing",
401 .data
= NULL
, /* filled in by handler */
402 .maxlen
= sizeof(unsigned int),
404 .proc_handler
= sysctl_numa_balancing
,
408 #endif /* CONFIG_NUMA_BALANCING */
409 #endif /* CONFIG_SCHED_DEBUG */
411 .procname
= "sched_rt_period_us",
412 .data
= &sysctl_sched_rt_period
,
413 .maxlen
= sizeof(unsigned int),
415 .proc_handler
= sched_rt_handler
,
418 .procname
= "sched_rt_runtime_us",
419 .data
= &sysctl_sched_rt_runtime
,
420 .maxlen
= sizeof(int),
422 .proc_handler
= sched_rt_handler
,
425 .procname
= "sched_rr_timeslice_ms",
426 .data
= &sched_rr_timeslice
,
427 .maxlen
= sizeof(int),
429 .proc_handler
= sched_rr_handler
,
431 #ifdef CONFIG_SCHED_AUTOGROUP
433 .procname
= "sched_autogroup_enabled",
434 .data
= &sysctl_sched_autogroup_enabled
,
435 .maxlen
= sizeof(unsigned int),
437 .proc_handler
= proc_dointvec_minmax
,
442 #ifdef CONFIG_CFS_BANDWIDTH
444 .procname
= "sched_cfs_bandwidth_slice_us",
445 .data
= &sysctl_sched_cfs_bandwidth_slice
,
446 .maxlen
= sizeof(unsigned int),
448 .proc_handler
= proc_dointvec_minmax
,
452 #ifdef CONFIG_PROVE_LOCKING
454 .procname
= "prove_locking",
455 .data
= &prove_locking
,
456 .maxlen
= sizeof(int),
458 .proc_handler
= proc_dointvec
,
461 #ifdef CONFIG_LOCK_STAT
463 .procname
= "lock_stat",
465 .maxlen
= sizeof(int),
467 .proc_handler
= proc_dointvec
,
472 .data
= &panic_timeout
,
473 .maxlen
= sizeof(int),
475 .proc_handler
= proc_dointvec
,
477 #ifdef CONFIG_COREDUMP
479 .procname
= "core_uses_pid",
480 .data
= &core_uses_pid
,
481 .maxlen
= sizeof(int),
483 .proc_handler
= proc_dointvec
,
486 .procname
= "core_pattern",
487 .data
= core_pattern
,
488 .maxlen
= CORENAME_MAX_SIZE
,
490 .proc_handler
= proc_dostring_coredump
,
493 .procname
= "core_pipe_limit",
494 .data
= &core_pipe_limit
,
495 .maxlen
= sizeof(unsigned int),
497 .proc_handler
= proc_dointvec
,
500 #ifdef CONFIG_PROC_SYSCTL
502 .procname
= "tainted",
503 .maxlen
= sizeof(long),
505 .proc_handler
= proc_taint
,
508 #ifdef CONFIG_LATENCYTOP
510 .procname
= "latencytop",
511 .data
= &latencytop_enabled
,
512 .maxlen
= sizeof(int),
514 .proc_handler
= proc_dointvec
,
517 #ifdef CONFIG_BLK_DEV_INITRD
519 .procname
= "real-root-dev",
520 .data
= &real_root_dev
,
521 .maxlen
= sizeof(int),
523 .proc_handler
= proc_dointvec
,
527 .procname
= "print-fatal-signals",
528 .data
= &print_fatal_signals
,
529 .maxlen
= sizeof(int),
531 .proc_handler
= proc_dointvec
,
535 .procname
= "reboot-cmd",
536 .data
= reboot_command
,
539 .proc_handler
= proc_dostring
,
542 .procname
= "stop-a",
543 .data
= &stop_a_enabled
,
544 .maxlen
= sizeof (int),
546 .proc_handler
= proc_dointvec
,
549 .procname
= "scons-poweroff",
550 .data
= &scons_pwroff
,
551 .maxlen
= sizeof (int),
553 .proc_handler
= proc_dointvec
,
556 #ifdef CONFIG_SPARC64
558 .procname
= "tsb-ratio",
559 .data
= &sysctl_tsb_ratio
,
560 .maxlen
= sizeof (int),
562 .proc_handler
= proc_dointvec
,
567 .procname
= "soft-power",
568 .data
= &pwrsw_enabled
,
569 .maxlen
= sizeof (int),
571 .proc_handler
= proc_dointvec
,
574 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
576 .procname
= "unaligned-trap",
577 .data
= &unaligned_enabled
,
578 .maxlen
= sizeof (int),
580 .proc_handler
= proc_dointvec
,
584 .procname
= "ctrl-alt-del",
586 .maxlen
= sizeof(int),
588 .proc_handler
= proc_dointvec
,
590 #ifdef CONFIG_FUNCTION_TRACER
592 .procname
= "ftrace_enabled",
593 .data
= &ftrace_enabled
,
594 .maxlen
= sizeof(int),
596 .proc_handler
= ftrace_enable_sysctl
,
599 #ifdef CONFIG_STACK_TRACER
601 .procname
= "stack_tracer_enabled",
602 .data
= &stack_tracer_enabled
,
603 .maxlen
= sizeof(int),
605 .proc_handler
= stack_trace_sysctl
,
608 #ifdef CONFIG_TRACING
610 .procname
= "ftrace_dump_on_oops",
611 .data
= &ftrace_dump_on_oops
,
612 .maxlen
= sizeof(int),
614 .proc_handler
= proc_dointvec
,
617 .procname
= "traceoff_on_warning",
618 .data
= &__disable_trace_on_warning
,
619 .maxlen
= sizeof(__disable_trace_on_warning
),
621 .proc_handler
= proc_dointvec
,
626 .procname
= "kexec_load_disabled",
627 .data
= &kexec_load_disabled
,
628 .maxlen
= sizeof(int),
630 /* only handle a transition from default "0" to "1" */
631 .proc_handler
= proc_dointvec_minmax
,
636 #ifdef CONFIG_MODULES
638 .procname
= "modprobe",
639 .data
= &modprobe_path
,
640 .maxlen
= KMOD_PATH_LEN
,
642 .proc_handler
= proc_dostring
,
645 .procname
= "modules_disabled",
646 .data
= &modules_disabled
,
647 .maxlen
= sizeof(int),
649 /* only handle a transition from default "0" to "1" */
650 .proc_handler
= proc_dointvec_minmax
,
657 .procname
= "hotplug",
658 .data
= &uevent_helper
,
659 .maxlen
= UEVENT_HELPER_PATH_LEN
,
661 .proc_handler
= proc_dostring
,
664 #ifdef CONFIG_CHR_DEV_SG
666 .procname
= "sg-big-buff",
667 .data
= &sg_big_buff
,
668 .maxlen
= sizeof (int),
670 .proc_handler
= proc_dointvec
,
673 #ifdef CONFIG_BSD_PROCESS_ACCT
677 .maxlen
= 3*sizeof(int),
679 .proc_handler
= proc_dointvec
,
682 #ifdef CONFIG_MAGIC_SYSRQ
685 .data
= &__sysrq_enabled
,
686 .maxlen
= sizeof (int),
688 .proc_handler
= sysrq_sysctl_handler
,
691 #ifdef CONFIG_PROC_SYSCTL
693 .procname
= "cad_pid",
695 .maxlen
= sizeof (int),
697 .proc_handler
= proc_do_cad_pid
,
701 .procname
= "threads-max",
702 .data
= &max_threads
,
703 .maxlen
= sizeof(int),
705 .proc_handler
= proc_dointvec
,
708 .procname
= "random",
710 .child
= random_table
,
713 .procname
= "usermodehelper",
715 .child
= usermodehelper_table
,
718 .procname
= "overflowuid",
719 .data
= &overflowuid
,
720 .maxlen
= sizeof(int),
722 .proc_handler
= proc_dointvec_minmax
,
723 .extra1
= &minolduid
,
724 .extra2
= &maxolduid
,
727 .procname
= "overflowgid",
728 .data
= &overflowgid
,
729 .maxlen
= sizeof(int),
731 .proc_handler
= proc_dointvec_minmax
,
732 .extra1
= &minolduid
,
733 .extra2
= &maxolduid
,
736 #ifdef CONFIG_MATHEMU
738 .procname
= "ieee_emulation_warnings",
739 .data
= &sysctl_ieee_emulation_warnings
,
740 .maxlen
= sizeof(int),
742 .proc_handler
= proc_dointvec
,
746 .procname
= "userprocess_debug",
747 .data
= &show_unhandled_signals
,
748 .maxlen
= sizeof(int),
750 .proc_handler
= proc_dointvec
,
754 .procname
= "pid_max",
756 .maxlen
= sizeof (int),
758 .proc_handler
= proc_dointvec_minmax
,
759 .extra1
= &pid_max_min
,
760 .extra2
= &pid_max_max
,
763 .procname
= "panic_on_oops",
764 .data
= &panic_on_oops
,
765 .maxlen
= sizeof(int),
767 .proc_handler
= proc_dointvec
,
769 #if defined CONFIG_PRINTK
771 .procname
= "printk",
772 .data
= &console_loglevel
,
773 .maxlen
= 4*sizeof(int),
775 .proc_handler
= proc_dointvec
,
778 .procname
= "printk_ratelimit",
779 .data
= &printk_ratelimit_state
.interval
,
780 .maxlen
= sizeof(int),
782 .proc_handler
= proc_dointvec_jiffies
,
785 .procname
= "printk_ratelimit_burst",
786 .data
= &printk_ratelimit_state
.burst
,
787 .maxlen
= sizeof(int),
789 .proc_handler
= proc_dointvec
,
792 .procname
= "printk_delay",
793 .data
= &printk_delay_msec
,
794 .maxlen
= sizeof(int),
796 .proc_handler
= proc_dointvec_minmax
,
798 .extra2
= &ten_thousand
,
801 .procname
= "dmesg_restrict",
802 .data
= &dmesg_restrict
,
803 .maxlen
= sizeof(int),
805 .proc_handler
= proc_dointvec_minmax_sysadmin
,
810 .procname
= "kptr_restrict",
811 .data
= &kptr_restrict
,
812 .maxlen
= sizeof(int),
814 .proc_handler
= proc_dointvec_minmax_sysadmin
,
820 .procname
= "ngroups_max",
821 .data
= &ngroups_max
,
822 .maxlen
= sizeof (int),
824 .proc_handler
= proc_dointvec
,
827 .procname
= "cap_last_cap",
828 .data
= (void *)&cap_last_cap
,
829 .maxlen
= sizeof(int),
831 .proc_handler
= proc_dointvec
,
833 #if defined(CONFIG_LOCKUP_DETECTOR)
835 .procname
= "watchdog",
836 .data
= &watchdog_user_enabled
,
837 .maxlen
= sizeof (int),
839 .proc_handler
= proc_dowatchdog
,
844 .procname
= "watchdog_thresh",
845 .data
= &watchdog_thresh
,
846 .maxlen
= sizeof(int),
848 .proc_handler
= proc_dowatchdog
,
853 .procname
= "softlockup_panic",
854 .data
= &softlockup_panic
,
855 .maxlen
= sizeof(int),
857 .proc_handler
= proc_dointvec_minmax
,
862 .procname
= "nmi_watchdog",
863 .data
= &watchdog_user_enabled
,
864 .maxlen
= sizeof (int),
866 .proc_handler
= proc_dowatchdog
,
871 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
873 .procname
= "unknown_nmi_panic",
874 .data
= &unknown_nmi_panic
,
875 .maxlen
= sizeof (int),
877 .proc_handler
= proc_dointvec
,
880 #if defined(CONFIG_X86)
882 .procname
= "panic_on_unrecovered_nmi",
883 .data
= &panic_on_unrecovered_nmi
,
884 .maxlen
= sizeof(int),
886 .proc_handler
= proc_dointvec
,
889 .procname
= "panic_on_io_nmi",
890 .data
= &panic_on_io_nmi
,
891 .maxlen
= sizeof(int),
893 .proc_handler
= proc_dointvec
,
895 #ifdef CONFIG_DEBUG_STACKOVERFLOW
897 .procname
= "panic_on_stackoverflow",
898 .data
= &sysctl_panic_on_stackoverflow
,
899 .maxlen
= sizeof(int),
901 .proc_handler
= proc_dointvec
,
905 .procname
= "bootloader_type",
906 .data
= &bootloader_type
,
907 .maxlen
= sizeof (int),
909 .proc_handler
= proc_dointvec
,
912 .procname
= "bootloader_version",
913 .data
= &bootloader_version
,
914 .maxlen
= sizeof (int),
916 .proc_handler
= proc_dointvec
,
919 .procname
= "kstack_depth_to_print",
920 .data
= &kstack_depth_to_print
,
921 .maxlen
= sizeof(int),
923 .proc_handler
= proc_dointvec
,
926 .procname
= "io_delay_type",
927 .data
= &io_delay_type
,
928 .maxlen
= sizeof(int),
930 .proc_handler
= proc_dointvec
,
933 #if defined(CONFIG_MMU)
935 .procname
= "randomize_va_space",
936 .data
= &randomize_va_space
,
937 .maxlen
= sizeof(int),
939 .proc_handler
= proc_dointvec
,
942 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
944 .procname
= "spin_retry",
946 .maxlen
= sizeof (int),
948 .proc_handler
= proc_dointvec
,
951 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
953 .procname
= "acpi_video_flags",
954 .data
= &acpi_realmode_flags
,
955 .maxlen
= sizeof (unsigned long),
957 .proc_handler
= proc_doulongvec_minmax
,
960 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
962 .procname
= "ignore-unaligned-usertrap",
963 .data
= &no_unaligned_warning
,
964 .maxlen
= sizeof (int),
966 .proc_handler
= proc_dointvec
,
971 .procname
= "unaligned-dump-stack",
972 .data
= &unaligned_dump_stack
,
973 .maxlen
= sizeof (int),
975 .proc_handler
= proc_dointvec
,
978 #ifdef CONFIG_DETECT_HUNG_TASK
980 .procname
= "hung_task_panic",
981 .data
= &sysctl_hung_task_panic
,
982 .maxlen
= sizeof(int),
984 .proc_handler
= proc_dointvec_minmax
,
989 .procname
= "hung_task_check_count",
990 .data
= &sysctl_hung_task_check_count
,
991 .maxlen
= sizeof(int),
993 .proc_handler
= proc_dointvec_minmax
,
997 .procname
= "hung_task_timeout_secs",
998 .data
= &sysctl_hung_task_timeout_secs
,
999 .maxlen
= sizeof(unsigned long),
1001 .proc_handler
= proc_dohung_task_timeout_secs
,
1002 .extra2
= &hung_task_timeout_max
,
1005 .procname
= "hung_task_warnings",
1006 .data
= &sysctl_hung_task_warnings
,
1007 .maxlen
= sizeof(int),
1009 .proc_handler
= proc_dointvec_minmax
,
1013 #ifdef CONFIG_COMPAT
1015 .procname
= "compat-log",
1016 .data
= &compat_log
,
1017 .maxlen
= sizeof (int),
1019 .proc_handler
= proc_dointvec
,
1022 #ifdef CONFIG_RT_MUTEXES
1024 .procname
= "max_lock_depth",
1025 .data
= &max_lock_depth
,
1026 .maxlen
= sizeof(int),
1028 .proc_handler
= proc_dointvec
,
1032 .procname
= "poweroff_cmd",
1033 .data
= &poweroff_cmd
,
1034 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1036 .proc_handler
= proc_dostring
,
1042 .child
= key_sysctls
,
1045 #ifdef CONFIG_RCU_TORTURE_TEST
1047 .procname
= "rcutorture_runnable",
1048 .data
= &rcutorture_runnable
,
1049 .maxlen
= sizeof(int),
1051 .proc_handler
= proc_dointvec
,
1054 #ifdef CONFIG_PERF_EVENTS
1056 * User-space scripts rely on the existence of this file
1057 * as a feature check for perf_events being enabled.
1059 * So it's an ABI, do not remove!
1062 .procname
= "perf_event_paranoid",
1063 .data
= &sysctl_perf_event_paranoid
,
1064 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1066 .proc_handler
= proc_dointvec
,
1069 .procname
= "perf_event_mlock_kb",
1070 .data
= &sysctl_perf_event_mlock
,
1071 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1073 .proc_handler
= proc_dointvec
,
1076 .procname
= "perf_event_max_sample_rate",
1077 .data
= &sysctl_perf_event_sample_rate
,
1078 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1080 .proc_handler
= perf_proc_update_handler
,
1084 .procname
= "perf_cpu_time_max_percent",
1085 .data
= &sysctl_perf_cpu_time_max_percent
,
1086 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1088 .proc_handler
= perf_cpu_time_max_percent_handler
,
1090 .extra2
= &one_hundred
,
1093 #ifdef CONFIG_KMEMCHECK
1095 .procname
= "kmemcheck",
1096 .data
= &kmemcheck_enabled
,
1097 .maxlen
= sizeof(int),
1099 .proc_handler
= proc_dointvec
,
1104 .procname
= "blk_iopoll",
1105 .data
= &blk_iopoll_enabled
,
1106 .maxlen
= sizeof(int),
1108 .proc_handler
= proc_dointvec
,
1114 static struct ctl_table vm_table
[] = {
1116 .procname
= "overcommit_memory",
1117 .data
= &sysctl_overcommit_memory
,
1118 .maxlen
= sizeof(sysctl_overcommit_memory
),
1120 .proc_handler
= proc_dointvec_minmax
,
1125 .procname
= "panic_on_oom",
1126 .data
= &sysctl_panic_on_oom
,
1127 .maxlen
= sizeof(sysctl_panic_on_oom
),
1129 .proc_handler
= proc_dointvec_minmax
,
1134 .procname
= "oom_kill_allocating_task",
1135 .data
= &sysctl_oom_kill_allocating_task
,
1136 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1138 .proc_handler
= proc_dointvec
,
1141 .procname
= "oom_dump_tasks",
1142 .data
= &sysctl_oom_dump_tasks
,
1143 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1145 .proc_handler
= proc_dointvec
,
1148 .procname
= "overcommit_ratio",
1149 .data
= &sysctl_overcommit_ratio
,
1150 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1152 .proc_handler
= overcommit_ratio_handler
,
1155 .procname
= "overcommit_kbytes",
1156 .data
= &sysctl_overcommit_kbytes
,
1157 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1159 .proc_handler
= overcommit_kbytes_handler
,
1162 .procname
= "page-cluster",
1163 .data
= &page_cluster
,
1164 .maxlen
= sizeof(int),
1166 .proc_handler
= proc_dointvec_minmax
,
1170 .procname
= "dirty_background_ratio",
1171 .data
= &dirty_background_ratio
,
1172 .maxlen
= sizeof(dirty_background_ratio
),
1174 .proc_handler
= dirty_background_ratio_handler
,
1176 .extra2
= &one_hundred
,
1179 .procname
= "dirty_background_bytes",
1180 .data
= &dirty_background_bytes
,
1181 .maxlen
= sizeof(dirty_background_bytes
),
1183 .proc_handler
= dirty_background_bytes_handler
,
1187 .procname
= "dirty_ratio",
1188 .data
= &vm_dirty_ratio
,
1189 .maxlen
= sizeof(vm_dirty_ratio
),
1191 .proc_handler
= dirty_ratio_handler
,
1193 .extra2
= &one_hundred
,
1196 .procname
= "dirty_bytes",
1197 .data
= &vm_dirty_bytes
,
1198 .maxlen
= sizeof(vm_dirty_bytes
),
1200 .proc_handler
= dirty_bytes_handler
,
1201 .extra1
= &dirty_bytes_min
,
1204 .procname
= "dirty_writeback_centisecs",
1205 .data
= &dirty_writeback_interval
,
1206 .maxlen
= sizeof(dirty_writeback_interval
),
1208 .proc_handler
= dirty_writeback_centisecs_handler
,
1211 .procname
= "dirty_expire_centisecs",
1212 .data
= &dirty_expire_interval
,
1213 .maxlen
= sizeof(dirty_expire_interval
),
1215 .proc_handler
= proc_dointvec_minmax
,
1219 .procname
= "nr_pdflush_threads",
1220 .mode
= 0444 /* read-only */,
1221 .proc_handler
= pdflush_proc_obsolete
,
1224 .procname
= "swappiness",
1225 .data
= &vm_swappiness
,
1226 .maxlen
= sizeof(vm_swappiness
),
1228 .proc_handler
= proc_dointvec_minmax
,
1230 .extra2
= &one_hundred
,
1232 #ifdef CONFIG_HUGETLB_PAGE
1234 .procname
= "nr_hugepages",
1236 .maxlen
= sizeof(unsigned long),
1238 .proc_handler
= hugetlb_sysctl_handler
,
1239 .extra1
= (void *)&hugetlb_zero
,
1240 .extra2
= (void *)&hugetlb_infinity
,
1244 .procname
= "nr_hugepages_mempolicy",
1246 .maxlen
= sizeof(unsigned long),
1248 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1249 .extra1
= (void *)&hugetlb_zero
,
1250 .extra2
= (void *)&hugetlb_infinity
,
1254 .procname
= "hugetlb_shm_group",
1255 .data
= &sysctl_hugetlb_shm_group
,
1256 .maxlen
= sizeof(gid_t
),
1258 .proc_handler
= proc_dointvec
,
1261 .procname
= "hugepages_treat_as_movable",
1262 .data
= &hugepages_treat_as_movable
,
1263 .maxlen
= sizeof(int),
1265 .proc_handler
= proc_dointvec
,
1268 .procname
= "nr_overcommit_hugepages",
1270 .maxlen
= sizeof(unsigned long),
1272 .proc_handler
= hugetlb_overcommit_handler
,
1273 .extra1
= (void *)&hugetlb_zero
,
1274 .extra2
= (void *)&hugetlb_infinity
,
1278 .procname
= "lowmem_reserve_ratio",
1279 .data
= &sysctl_lowmem_reserve_ratio
,
1280 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1282 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1285 .procname
= "drop_caches",
1286 .data
= &sysctl_drop_caches
,
1287 .maxlen
= sizeof(int),
1289 .proc_handler
= drop_caches_sysctl_handler
,
1293 #ifdef CONFIG_COMPACTION
1295 .procname
= "compact_memory",
1296 .data
= &sysctl_compact_memory
,
1297 .maxlen
= sizeof(int),
1299 .proc_handler
= sysctl_compaction_handler
,
1302 .procname
= "extfrag_threshold",
1303 .data
= &sysctl_extfrag_threshold
,
1304 .maxlen
= sizeof(int),
1306 .proc_handler
= sysctl_extfrag_handler
,
1307 .extra1
= &min_extfrag_threshold
,
1308 .extra2
= &max_extfrag_threshold
,
1311 #endif /* CONFIG_COMPACTION */
1313 .procname
= "min_free_kbytes",
1314 .data
= &min_free_kbytes
,
1315 .maxlen
= sizeof(min_free_kbytes
),
1317 .proc_handler
= min_free_kbytes_sysctl_handler
,
1321 .procname
= "percpu_pagelist_fraction",
1322 .data
= &percpu_pagelist_fraction
,
1323 .maxlen
= sizeof(percpu_pagelist_fraction
),
1325 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1330 .procname
= "max_map_count",
1331 .data
= &sysctl_max_map_count
,
1332 .maxlen
= sizeof(sysctl_max_map_count
),
1334 .proc_handler
= proc_dointvec_minmax
,
1339 .procname
= "nr_trim_pages",
1340 .data
= &sysctl_nr_trim_pages
,
1341 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1343 .proc_handler
= proc_dointvec_minmax
,
1348 .procname
= "laptop_mode",
1349 .data
= &laptop_mode
,
1350 .maxlen
= sizeof(laptop_mode
),
1352 .proc_handler
= proc_dointvec_jiffies
,
1355 .procname
= "block_dump",
1356 .data
= &block_dump
,
1357 .maxlen
= sizeof(block_dump
),
1359 .proc_handler
= proc_dointvec
,
1363 .procname
= "vfs_cache_pressure",
1364 .data
= &sysctl_vfs_cache_pressure
,
1365 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1367 .proc_handler
= proc_dointvec
,
1370 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1372 .procname
= "legacy_va_layout",
1373 .data
= &sysctl_legacy_va_layout
,
1374 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1376 .proc_handler
= proc_dointvec
,
1382 .procname
= "zone_reclaim_mode",
1383 .data
= &zone_reclaim_mode
,
1384 .maxlen
= sizeof(zone_reclaim_mode
),
1386 .proc_handler
= proc_dointvec
,
1390 .procname
= "min_unmapped_ratio",
1391 .data
= &sysctl_min_unmapped_ratio
,
1392 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1394 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1396 .extra2
= &one_hundred
,
1399 .procname
= "min_slab_ratio",
1400 .data
= &sysctl_min_slab_ratio
,
1401 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1403 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1405 .extra2
= &one_hundred
,
1410 .procname
= "stat_interval",
1411 .data
= &sysctl_stat_interval
,
1412 .maxlen
= sizeof(sysctl_stat_interval
),
1414 .proc_handler
= proc_dointvec_jiffies
,
1419 .procname
= "mmap_min_addr",
1420 .data
= &dac_mmap_min_addr
,
1421 .maxlen
= sizeof(unsigned long),
1423 .proc_handler
= mmap_min_addr_handler
,
1428 .procname
= "numa_zonelist_order",
1429 .data
= &numa_zonelist_order
,
1430 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1432 .proc_handler
= numa_zonelist_order_handler
,
1435 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1436 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1438 .procname
= "vdso_enabled",
1439 .data
= &vdso_enabled
,
1440 .maxlen
= sizeof(vdso_enabled
),
1442 .proc_handler
= proc_dointvec
,
1446 #ifdef CONFIG_HIGHMEM
1448 .procname
= "highmem_is_dirtyable",
1449 .data
= &vm_highmem_is_dirtyable
,
1450 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1452 .proc_handler
= proc_dointvec_minmax
,
1458 .procname
= "scan_unevictable_pages",
1459 .data
= &scan_unevictable_pages
,
1460 .maxlen
= sizeof(scan_unevictable_pages
),
1462 .proc_handler
= scan_unevictable_handler
,
1464 #ifdef CONFIG_MEMORY_FAILURE
1466 .procname
= "memory_failure_early_kill",
1467 .data
= &sysctl_memory_failure_early_kill
,
1468 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1470 .proc_handler
= proc_dointvec_minmax
,
1475 .procname
= "memory_failure_recovery",
1476 .data
= &sysctl_memory_failure_recovery
,
1477 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1479 .proc_handler
= proc_dointvec_minmax
,
1485 .procname
= "user_reserve_kbytes",
1486 .data
= &sysctl_user_reserve_kbytes
,
1487 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1489 .proc_handler
= proc_doulongvec_minmax
,
1492 .procname
= "admin_reserve_kbytes",
1493 .data
= &sysctl_admin_reserve_kbytes
,
1494 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1496 .proc_handler
= proc_doulongvec_minmax
,
1501 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1502 static struct ctl_table binfmt_misc_table
[] = {
1507 static struct ctl_table fs_table
[] = {
1509 .procname
= "inode-nr",
1510 .data
= &inodes_stat
,
1511 .maxlen
= 2*sizeof(long),
1513 .proc_handler
= proc_nr_inodes
,
1516 .procname
= "inode-state",
1517 .data
= &inodes_stat
,
1518 .maxlen
= 7*sizeof(long),
1520 .proc_handler
= proc_nr_inodes
,
1523 .procname
= "file-nr",
1524 .data
= &files_stat
,
1525 .maxlen
= sizeof(files_stat
),
1527 .proc_handler
= proc_nr_files
,
1530 .procname
= "file-max",
1531 .data
= &files_stat
.max_files
,
1532 .maxlen
= sizeof(files_stat
.max_files
),
1534 .proc_handler
= proc_doulongvec_minmax
,
1537 .procname
= "nr_open",
1538 .data
= &sysctl_nr_open
,
1539 .maxlen
= sizeof(int),
1541 .proc_handler
= proc_dointvec_minmax
,
1542 .extra1
= &sysctl_nr_open_min
,
1543 .extra2
= &sysctl_nr_open_max
,
1546 .procname
= "dentry-state",
1547 .data
= &dentry_stat
,
1548 .maxlen
= 6*sizeof(long),
1550 .proc_handler
= proc_nr_dentry
,
1553 .procname
= "overflowuid",
1554 .data
= &fs_overflowuid
,
1555 .maxlen
= sizeof(int),
1557 .proc_handler
= proc_dointvec_minmax
,
1558 .extra1
= &minolduid
,
1559 .extra2
= &maxolduid
,
1562 .procname
= "overflowgid",
1563 .data
= &fs_overflowgid
,
1564 .maxlen
= sizeof(int),
1566 .proc_handler
= proc_dointvec_minmax
,
1567 .extra1
= &minolduid
,
1568 .extra2
= &maxolduid
,
1570 #ifdef CONFIG_FILE_LOCKING
1572 .procname
= "leases-enable",
1573 .data
= &leases_enable
,
1574 .maxlen
= sizeof(int),
1576 .proc_handler
= proc_dointvec
,
1579 #ifdef CONFIG_DNOTIFY
1581 .procname
= "dir-notify-enable",
1582 .data
= &dir_notify_enable
,
1583 .maxlen
= sizeof(int),
1585 .proc_handler
= proc_dointvec
,
1589 #ifdef CONFIG_FILE_LOCKING
1591 .procname
= "lease-break-time",
1592 .data
= &lease_break_time
,
1593 .maxlen
= sizeof(int),
1595 .proc_handler
= proc_dointvec
,
1600 .procname
= "aio-nr",
1602 .maxlen
= sizeof(aio_nr
),
1604 .proc_handler
= proc_doulongvec_minmax
,
1607 .procname
= "aio-max-nr",
1608 .data
= &aio_max_nr
,
1609 .maxlen
= sizeof(aio_max_nr
),
1611 .proc_handler
= proc_doulongvec_minmax
,
1613 #endif /* CONFIG_AIO */
1614 #ifdef CONFIG_INOTIFY_USER
1616 .procname
= "inotify",
1618 .child
= inotify_table
,
1623 .procname
= "epoll",
1625 .child
= epoll_table
,
1630 .procname
= "protected_symlinks",
1631 .data
= &sysctl_protected_symlinks
,
1632 .maxlen
= sizeof(int),
1634 .proc_handler
= proc_dointvec_minmax
,
1639 .procname
= "protected_hardlinks",
1640 .data
= &sysctl_protected_hardlinks
,
1641 .maxlen
= sizeof(int),
1643 .proc_handler
= proc_dointvec_minmax
,
1648 .procname
= "suid_dumpable",
1649 .data
= &suid_dumpable
,
1650 .maxlen
= sizeof(int),
1652 .proc_handler
= proc_dointvec_minmax_coredump
,
1656 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1658 .procname
= "binfmt_misc",
1660 .child
= binfmt_misc_table
,
1664 .procname
= "pipe-max-size",
1665 .data
= &pipe_max_size
,
1666 .maxlen
= sizeof(int),
1668 .proc_handler
= &pipe_proc_fn
,
1669 .extra1
= &pipe_min_size
,
1674 static struct ctl_table debug_table
[] = {
1675 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1677 .procname
= "exception-trace",
1678 .data
= &show_unhandled_signals
,
1679 .maxlen
= sizeof(int),
1681 .proc_handler
= proc_dointvec
1684 #if defined(CONFIG_OPTPROBES)
1686 .procname
= "kprobes-optimization",
1687 .data
= &sysctl_kprobes_optimization
,
1688 .maxlen
= sizeof(int),
1690 .proc_handler
= proc_kprobes_optimization_handler
,
1698 static struct ctl_table dev_table
[] = {
1702 int __init
sysctl_init(void)
1704 struct ctl_table_header
*hdr
;
1706 hdr
= register_sysctl_table(sysctl_base_table
);
1707 kmemleak_not_leak(hdr
);
1711 #endif /* CONFIG_SYSCTL */
1717 #ifdef CONFIG_PROC_SYSCTL
1719 static int _proc_do_string(void* data
, int maxlen
, int write
,
1720 void __user
*buffer
,
1721 size_t *lenp
, loff_t
*ppos
)
1727 if (!data
|| !maxlen
|| !*lenp
) {
1735 while (len
< *lenp
) {
1736 if (get_user(c
, p
++))
1738 if (c
== 0 || c
== '\n')
1744 if(copy_from_user(data
, buffer
, len
))
1746 ((char *) data
)[len
] = 0;
1764 if(copy_to_user(buffer
, data
, len
))
1767 if(put_user('\n', ((char __user
*) buffer
) + len
))
1778 * proc_dostring - read a string sysctl
1779 * @table: the sysctl table
1780 * @write: %TRUE if this is a write to the sysctl file
1781 * @buffer: the user buffer
1782 * @lenp: the size of the user buffer
1783 * @ppos: file position
1785 * Reads/writes a string from/to the user buffer. If the kernel
1786 * buffer provided is not large enough to hold the string, the
1787 * string is truncated. The copied string is %NULL-terminated.
1788 * If the string is being read by the user process, it is copied
1789 * and a newline '\n' is added. It is truncated if the buffer is
1792 * Returns 0 on success.
1794 int proc_dostring(struct ctl_table
*table
, int write
,
1795 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1797 return _proc_do_string(table
->data
, table
->maxlen
, write
,
1798 buffer
, lenp
, ppos
);
1801 static size_t proc_skip_spaces(char **buf
)
1804 char *tmp
= skip_spaces(*buf
);
1810 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
1820 #define TMPBUFLEN 22
1822 * proc_get_long - reads an ASCII formatted integer from a user buffer
1824 * @buf: a kernel buffer
1825 * @size: size of the kernel buffer
1826 * @val: this is where the number will be stored
1827 * @neg: set to %TRUE if number is negative
1828 * @perm_tr: a vector which contains the allowed trailers
1829 * @perm_tr_len: size of the perm_tr vector
1830 * @tr: pointer to store the trailer character
1832 * In case of success %0 is returned and @buf and @size are updated with
1833 * the amount of bytes read. If @tr is non-NULL and a trailing
1834 * character exists (size is non-zero after returning from this
1835 * function), @tr is updated with the trailing character.
1837 static int proc_get_long(char **buf
, size_t *size
,
1838 unsigned long *val
, bool *neg
,
1839 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
1842 char *p
, tmp
[TMPBUFLEN
];
1848 if (len
> TMPBUFLEN
- 1)
1849 len
= TMPBUFLEN
- 1;
1851 memcpy(tmp
, *buf
, len
);
1855 if (*p
== '-' && *size
> 1) {
1863 *val
= simple_strtoul(p
, &p
, 0);
1867 /* We don't know if the next char is whitespace thus we may accept
1868 * invalid integers (e.g. 1234...a) or two integers instead of one
1869 * (e.g. 123...1). So lets not allow such large numbers. */
1870 if (len
== TMPBUFLEN
- 1)
1873 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
1876 if (tr
&& (len
< *size
))
1886 * proc_put_long - converts an integer to a decimal ASCII formatted string
1888 * @buf: the user buffer
1889 * @size: the size of the user buffer
1890 * @val: the integer to be converted
1891 * @neg: sign of the number, %TRUE for negative
1893 * In case of success %0 is returned and @buf and @size are updated with
1894 * the amount of bytes written.
1896 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
1900 char tmp
[TMPBUFLEN
], *p
= tmp
;
1902 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
1906 if (copy_to_user(*buf
, tmp
, len
))
1914 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
1917 char __user
**buffer
= (char __user
**)buf
;
1918 if (put_user(c
, *buffer
))
1920 (*size
)--, (*buffer
)++;
1926 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
1928 int write
, void *data
)
1931 *valp
= *negp
? -*lvalp
: *lvalp
;
1936 *lvalp
= (unsigned long)-val
;
1939 *lvalp
= (unsigned long)val
;
1945 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
1947 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1948 int write
, void __user
*buffer
,
1949 size_t *lenp
, loff_t
*ppos
,
1950 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
1951 int write
, void *data
),
1954 int *i
, vleft
, first
= 1, err
= 0;
1955 unsigned long page
= 0;
1959 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
1964 i
= (int *) tbl_data
;
1965 vleft
= table
->maxlen
/ sizeof(*i
);
1969 conv
= do_proc_dointvec_conv
;
1972 if (left
> PAGE_SIZE
- 1)
1973 left
= PAGE_SIZE
- 1;
1974 page
= __get_free_page(GFP_TEMPORARY
);
1975 kbuf
= (char *) page
;
1978 if (copy_from_user(kbuf
, buffer
, left
)) {
1985 for (; left
&& vleft
--; i
++, first
=0) {
1990 left
-= proc_skip_spaces(&kbuf
);
1994 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
1996 sizeof(proc_wspace_sep
), NULL
);
1999 if (conv(&neg
, &lval
, i
, 1, data
)) {
2004 if (conv(&neg
, &lval
, i
, 0, data
)) {
2009 err
= proc_put_char(&buffer
, &left
, '\t');
2012 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2018 if (!write
&& !first
&& left
&& !err
)
2019 err
= proc_put_char(&buffer
, &left
, '\n');
2020 if (write
&& !err
&& left
)
2021 left
-= proc_skip_spaces(&kbuf
);
2026 return err
? : -EINVAL
;
2033 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2034 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2035 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2036 int write
, void *data
),
2039 return __do_proc_dointvec(table
->data
, table
, write
,
2040 buffer
, lenp
, ppos
, conv
, data
);
2044 * proc_dointvec - read a vector of integers
2045 * @table: the sysctl table
2046 * @write: %TRUE if this is a write to the sysctl file
2047 * @buffer: the user buffer
2048 * @lenp: the size of the user buffer
2049 * @ppos: file position
2051 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2052 * values from/to the user buffer, treated as an ASCII string.
2054 * Returns 0 on success.
2056 int proc_dointvec(struct ctl_table
*table
, int write
,
2057 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2059 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2064 * Taint values can only be increased
2065 * This means we can safely use a temporary.
2067 static int proc_taint(struct ctl_table
*table
, int write
,
2068 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2071 unsigned long tmptaint
= get_taint();
2074 if (write
&& !capable(CAP_SYS_ADMIN
))
2079 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2085 * Poor man's atomic or. Not worth adding a primitive
2086 * to everyone's atomic.h for this
2089 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2090 if ((tmptaint
>> i
) & 1)
2091 add_taint(i
, LOCKDEP_STILL_OK
);
2098 #ifdef CONFIG_PRINTK
2099 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2100 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2102 if (write
&& !capable(CAP_SYS_ADMIN
))
2105 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2109 struct do_proc_dointvec_minmax_conv_param
{
2114 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2116 int write
, void *data
)
2118 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2120 int val
= *negp
? -*lvalp
: *lvalp
;
2121 if ((param
->min
&& *param
->min
> val
) ||
2122 (param
->max
&& *param
->max
< val
))
2129 *lvalp
= (unsigned long)-val
;
2132 *lvalp
= (unsigned long)val
;
2139 * proc_dointvec_minmax - read a vector of integers with min/max values
2140 * @table: the sysctl table
2141 * @write: %TRUE if this is a write to the sysctl file
2142 * @buffer: the user buffer
2143 * @lenp: the size of the user buffer
2144 * @ppos: file position
2146 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2147 * values from/to the user buffer, treated as an ASCII string.
2149 * This routine will ensure the values are within the range specified by
2150 * table->extra1 (min) and table->extra2 (max).
2152 * Returns 0 on success.
2154 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2155 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2157 struct do_proc_dointvec_minmax_conv_param param
= {
2158 .min
= (int *) table
->extra1
,
2159 .max
= (int *) table
->extra2
,
2161 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2162 do_proc_dointvec_minmax_conv
, ¶m
);
2165 static void validate_coredump_safety(void)
2167 #ifdef CONFIG_COREDUMP
2168 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2169 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2170 printk(KERN_WARNING
"Unsafe core_pattern used with "\
2171 "suid_dumpable=2. Pipe handler or fully qualified "\
2172 "core dump path required.\n");
2177 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2178 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2180 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2182 validate_coredump_safety();
2186 #ifdef CONFIG_COREDUMP
2187 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2188 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2190 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2192 validate_coredump_safety();
2197 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2198 void __user
*buffer
,
2199 size_t *lenp
, loff_t
*ppos
,
2200 unsigned long convmul
,
2201 unsigned long convdiv
)
2203 unsigned long *i
, *min
, *max
;
2204 int vleft
, first
= 1, err
= 0;
2205 unsigned long page
= 0;
2209 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2214 i
= (unsigned long *) data
;
2215 min
= (unsigned long *) table
->extra1
;
2216 max
= (unsigned long *) table
->extra2
;
2217 vleft
= table
->maxlen
/ sizeof(unsigned long);
2221 if (left
> PAGE_SIZE
- 1)
2222 left
= PAGE_SIZE
- 1;
2223 page
= __get_free_page(GFP_TEMPORARY
);
2224 kbuf
= (char *) page
;
2227 if (copy_from_user(kbuf
, buffer
, left
)) {
2234 for (; left
&& vleft
--; i
++, first
= 0) {
2240 left
-= proc_skip_spaces(&kbuf
);
2242 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2244 sizeof(proc_wspace_sep
), NULL
);
2249 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2253 val
= convdiv
* (*i
) / convmul
;
2255 err
= proc_put_char(&buffer
, &left
, '\t');
2259 err
= proc_put_long(&buffer
, &left
, val
, false);
2265 if (!write
&& !first
&& left
&& !err
)
2266 err
= proc_put_char(&buffer
, &left
, '\n');
2268 left
-= proc_skip_spaces(&kbuf
);
2273 return err
? : -EINVAL
;
2280 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2281 void __user
*buffer
,
2282 size_t *lenp
, loff_t
*ppos
,
2283 unsigned long convmul
,
2284 unsigned long convdiv
)
2286 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2287 buffer
, lenp
, ppos
, convmul
, convdiv
);
2291 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2292 * @table: the sysctl table
2293 * @write: %TRUE if this is a write to the sysctl file
2294 * @buffer: the user buffer
2295 * @lenp: the size of the user buffer
2296 * @ppos: file position
2298 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2299 * values from/to the user buffer, treated as an ASCII string.
2301 * This routine will ensure the values are within the range specified by
2302 * table->extra1 (min) and table->extra2 (max).
2304 * Returns 0 on success.
2306 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2307 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2309 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2313 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2314 * @table: the sysctl table
2315 * @write: %TRUE if this is a write to the sysctl file
2316 * @buffer: the user buffer
2317 * @lenp: the size of the user buffer
2318 * @ppos: file position
2320 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2321 * values from/to the user buffer, treated as an ASCII string. The values
2322 * are treated as milliseconds, and converted to jiffies when they are stored.
2324 * This routine will ensure the values are within the range specified by
2325 * table->extra1 (min) and table->extra2 (max).
2327 * Returns 0 on success.
2329 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2330 void __user
*buffer
,
2331 size_t *lenp
, loff_t
*ppos
)
2333 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2334 lenp
, ppos
, HZ
, 1000l);
2338 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2340 int write
, void *data
)
2343 if (*lvalp
> LONG_MAX
/ HZ
)
2345 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2351 lval
= (unsigned long)-val
;
2354 lval
= (unsigned long)val
;
2361 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2363 int write
, void *data
)
2366 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2368 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2374 lval
= (unsigned long)-val
;
2377 lval
= (unsigned long)val
;
2379 *lvalp
= jiffies_to_clock_t(lval
);
2384 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2386 int write
, void *data
)
2389 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2399 lval
= (unsigned long)-val
;
2402 lval
= (unsigned long)val
;
2404 *lvalp
= jiffies_to_msecs(lval
);
2410 * proc_dointvec_jiffies - read a vector of integers as seconds
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 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2418 * values from/to the user buffer, treated as an ASCII string.
2419 * The values read are assumed to be in seconds, and are converted into
2422 * Returns 0 on success.
2424 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2425 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2427 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2428 do_proc_dointvec_jiffies_conv
,NULL
);
2432 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2433 * @table: the sysctl table
2434 * @write: %TRUE if this is a write to the sysctl file
2435 * @buffer: the user buffer
2436 * @lenp: the size of the user buffer
2437 * @ppos: pointer to the file position
2439 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2440 * values from/to the user buffer, treated as an ASCII string.
2441 * The values read are assumed to be in 1/USER_HZ seconds, and
2442 * are converted into jiffies.
2444 * Returns 0 on success.
2446 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2447 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2449 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2450 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2454 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2455 * @table: the sysctl table
2456 * @write: %TRUE if this is a write to the sysctl file
2457 * @buffer: the user buffer
2458 * @lenp: the size of the user buffer
2459 * @ppos: file position
2460 * @ppos: the current position in the file
2462 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2463 * values from/to the user buffer, treated as an ASCII string.
2464 * The values read are assumed to be in 1/1000 seconds, and
2465 * are converted into jiffies.
2467 * Returns 0 on success.
2469 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2470 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2472 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2473 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2476 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2477 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2479 struct pid
*new_pid
;
2483 tmp
= pid_vnr(cad_pid
);
2485 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2486 lenp
, ppos
, NULL
, NULL
);
2490 new_pid
= find_get_pid(tmp
);
2494 put_pid(xchg(&cad_pid
, new_pid
));
2499 * proc_do_large_bitmap - read/write from/to a large bitmap
2500 * @table: the sysctl table
2501 * @write: %TRUE if this is a write to the sysctl file
2502 * @buffer: the user buffer
2503 * @lenp: the size of the user buffer
2504 * @ppos: file position
2506 * The bitmap is stored at table->data and the bitmap length (in bits)
2509 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2510 * large bitmaps may be represented in a compact manner. Writing into
2511 * the file will clear the bitmap then update it with the given input.
2513 * Returns 0 on success.
2515 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2516 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2520 size_t left
= *lenp
;
2521 unsigned long bitmap_len
= table
->maxlen
;
2522 unsigned long *bitmap
= (unsigned long *) table
->data
;
2523 unsigned long *tmp_bitmap
= NULL
;
2524 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2526 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2532 unsigned long page
= 0;
2535 if (left
> PAGE_SIZE
- 1)
2536 left
= PAGE_SIZE
- 1;
2538 page
= __get_free_page(GFP_TEMPORARY
);
2539 kbuf
= (char *) page
;
2542 if (copy_from_user(kbuf
, buffer
, left
)) {
2548 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2554 proc_skip_char(&kbuf
, &left
, '\n');
2555 while (!err
&& left
) {
2556 unsigned long val_a
, val_b
;
2559 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2563 if (val_a
>= bitmap_len
|| neg
) {
2575 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2576 &neg
, tr_b
, sizeof(tr_b
),
2580 if (val_b
>= bitmap_len
|| neg
||
2591 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
2593 proc_skip_char(&kbuf
, &left
, '\n');
2597 unsigned long bit_a
, bit_b
= 0;
2600 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2601 if (bit_a
>= bitmap_len
)
2603 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2607 err
= proc_put_char(&buffer
, &left
, ',');
2611 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2614 if (bit_a
!= bit_b
) {
2615 err
= proc_put_char(&buffer
, &left
, '-');
2618 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2626 err
= proc_put_char(&buffer
, &left
, '\n');
2632 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2634 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
2646 #else /* CONFIG_PROC_SYSCTL */
2648 int proc_dostring(struct ctl_table
*table
, int write
,
2649 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2654 int proc_dointvec(struct ctl_table
*table
, int write
,
2655 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2660 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2661 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2666 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2667 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2672 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2673 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2678 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2679 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2684 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2685 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2690 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2691 void __user
*buffer
,
2692 size_t *lenp
, loff_t
*ppos
)
2698 #endif /* CONFIG_PROC_SYSCTL */
2701 * No sense putting this after each symbol definition, twice,
2702 * exception granted :-)
2704 EXPORT_SYMBOL(proc_dointvec
);
2705 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2706 EXPORT_SYMBOL(proc_dointvec_minmax
);
2707 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2708 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2709 EXPORT_SYMBOL(proc_dostring
);
2710 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2711 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);