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>
22 #include <linux/aio.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemcheck.h>
34 #include <linux/kmemleak.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/sched/coredump.h>
67 #include <linux/kexec.h>
68 #include <linux/bpf.h>
69 #include <linux/mount.h>
71 #include <linux/uaccess.h>
72 #include <asm/processor.h>
76 #include <asm/stacktrace.h>
80 #include <asm/setup.h>
82 #ifdef CONFIG_BSD_PROCESS_ACCT
83 #include <linux/acct.h>
85 #ifdef CONFIG_RT_MUTEXES
86 #include <linux/rtmutex.h>
88 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
89 #include <linux/lockdep.h>
91 #ifdef CONFIG_CHR_DEV_SG
95 #ifdef CONFIG_LOCKUP_DETECTOR
96 #include <linux/nmi.h>
99 #if defined(CONFIG_SYSCTL)
101 /* External variables not in a header file. */
102 extern int suid_dumpable
;
103 #ifdef CONFIG_COREDUMP
104 extern int core_uses_pid
;
105 extern char core_pattern
[];
106 extern unsigned int core_pipe_limit
;
109 extern int pid_max_min
, pid_max_max
;
110 extern int percpu_pagelist_fraction
;
111 extern int latencytop_enabled
;
112 extern unsigned int sysctl_nr_open_min
, sysctl_nr_open_max
;
114 extern int sysctl_nr_trim_pages
;
117 /* Constants used for minimum and maximum */
118 #ifdef CONFIG_LOCKUP_DETECTOR
119 static int sixty
= 60;
122 static int __maybe_unused neg_one
= -1;
125 static int __maybe_unused one
= 1;
126 static int __maybe_unused two
= 2;
127 static int __maybe_unused four
= 4;
128 static unsigned long one_ul
= 1;
129 static int one_hundred
= 100;
130 static int one_thousand
= 1000;
132 static int ten_thousand
= 10000;
134 #ifdef CONFIG_PERF_EVENTS
135 static int six_hundred_forty_kb
= 640 * 1024;
138 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
141 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142 static int maxolduid
= 65535;
143 static int minolduid
;
145 static int ngroups_max
= NGROUPS_MAX
;
146 static const int cap_last_cap
= CAP_LAST_CAP
;
148 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
149 #ifdef CONFIG_DETECT_HUNG_TASK
150 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
153 #ifdef CONFIG_INOTIFY_USER
154 #include <linux/inotify.h>
160 extern int pwrsw_enabled
;
163 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
164 extern int unaligned_enabled
;
168 extern int unaligned_dump_stack
;
171 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172 extern int no_unaligned_warning
;
175 #ifdef CONFIG_PROC_SYSCTL
178 * enum sysctl_writes_mode - supported sysctl write modes
180 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
181 * to be written, and multiple writes on the same sysctl file descriptor
182 * will rewrite the sysctl value, regardless of file position. No warning
183 * is issued when the initial position is not 0.
184 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
186 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
187 * file position 0 and the value must be fully contained in the buffer
188 * sent to the write syscall. If dealing with strings respect the file
189 * position, but restrict this to the max length of the buffer, anything
190 * passed the max lenght will be ignored. Multiple writes will append
193 * These write modes control how current file position affects the behavior of
194 * updating sysctl values through the proc interface on each write.
196 enum sysctl_writes_mode
{
197 SYSCTL_WRITES_LEGACY
= -1,
198 SYSCTL_WRITES_WARN
= 0,
199 SYSCTL_WRITES_STRICT
= 1,
202 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
204 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
205 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
206 static int proc_taint(struct ctl_table
*table
, int write
,
207 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
211 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
212 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
215 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
216 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
217 #ifdef CONFIG_COREDUMP
218 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
219 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
222 #ifdef CONFIG_MAGIC_SYSRQ
223 /* Note: sysrq code uses it's own private copy */
224 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
226 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
227 void __user
*buffer
, size_t *lenp
,
232 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
237 sysrq_toggle_support(__sysrq_enabled
);
244 static struct ctl_table kern_table
[];
245 static struct ctl_table vm_table
[];
246 static struct ctl_table fs_table
[];
247 static struct ctl_table debug_table
[];
248 static struct ctl_table dev_table
[];
249 extern struct ctl_table random_table
[];
251 extern struct ctl_table epoll_table
[];
254 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
255 int sysctl_legacy_va_layout
;
258 /* The default sysctl tables: */
260 static struct ctl_table sysctl_base_table
[] = {
262 .procname
= "kernel",
279 .child
= debug_table
,
289 #ifdef CONFIG_SCHED_DEBUG
290 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
291 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
292 static int min_wakeup_granularity_ns
; /* 0 usecs */
293 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
295 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
296 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
297 #endif /* CONFIG_SMP */
298 #endif /* CONFIG_SCHED_DEBUG */
300 #ifdef CONFIG_COMPACTION
301 static int min_extfrag_threshold
;
302 static int max_extfrag_threshold
= 1000;
305 static struct ctl_table kern_table
[] = {
307 .procname
= "sched_child_runs_first",
308 .data
= &sysctl_sched_child_runs_first
,
309 .maxlen
= sizeof(unsigned int),
311 .proc_handler
= proc_dointvec
,
313 #ifdef CONFIG_SCHED_DEBUG
315 .procname
= "sched_min_granularity_ns",
316 .data
= &sysctl_sched_min_granularity
,
317 .maxlen
= sizeof(unsigned int),
319 .proc_handler
= sched_proc_update_handler
,
320 .extra1
= &min_sched_granularity_ns
,
321 .extra2
= &max_sched_granularity_ns
,
324 .procname
= "sched_latency_ns",
325 .data
= &sysctl_sched_latency
,
326 .maxlen
= sizeof(unsigned int),
328 .proc_handler
= sched_proc_update_handler
,
329 .extra1
= &min_sched_granularity_ns
,
330 .extra2
= &max_sched_granularity_ns
,
333 .procname
= "sched_wakeup_granularity_ns",
334 .data
= &sysctl_sched_wakeup_granularity
,
335 .maxlen
= sizeof(unsigned int),
337 .proc_handler
= sched_proc_update_handler
,
338 .extra1
= &min_wakeup_granularity_ns
,
339 .extra2
= &max_wakeup_granularity_ns
,
343 .procname
= "sched_tunable_scaling",
344 .data
= &sysctl_sched_tunable_scaling
,
345 .maxlen
= sizeof(enum sched_tunable_scaling
),
347 .proc_handler
= sched_proc_update_handler
,
348 .extra1
= &min_sched_tunable_scaling
,
349 .extra2
= &max_sched_tunable_scaling
,
352 .procname
= "sched_migration_cost_ns",
353 .data
= &sysctl_sched_migration_cost
,
354 .maxlen
= sizeof(unsigned int),
356 .proc_handler
= proc_dointvec
,
359 .procname
= "sched_nr_migrate",
360 .data
= &sysctl_sched_nr_migrate
,
361 .maxlen
= sizeof(unsigned int),
363 .proc_handler
= proc_dointvec
,
366 .procname
= "sched_time_avg_ms",
367 .data
= &sysctl_sched_time_avg
,
368 .maxlen
= sizeof(unsigned int),
370 .proc_handler
= proc_dointvec
,
372 #ifdef CONFIG_SCHEDSTATS
374 .procname
= "sched_schedstats",
376 .maxlen
= sizeof(unsigned int),
378 .proc_handler
= sysctl_schedstats
,
382 #endif /* CONFIG_SCHEDSTATS */
383 #endif /* CONFIG_SMP */
384 #ifdef CONFIG_NUMA_BALANCING
386 .procname
= "numa_balancing_scan_delay_ms",
387 .data
= &sysctl_numa_balancing_scan_delay
,
388 .maxlen
= sizeof(unsigned int),
390 .proc_handler
= proc_dointvec
,
393 .procname
= "numa_balancing_scan_period_min_ms",
394 .data
= &sysctl_numa_balancing_scan_period_min
,
395 .maxlen
= sizeof(unsigned int),
397 .proc_handler
= proc_dointvec
,
400 .procname
= "numa_balancing_scan_period_max_ms",
401 .data
= &sysctl_numa_balancing_scan_period_max
,
402 .maxlen
= sizeof(unsigned int),
404 .proc_handler
= proc_dointvec
,
407 .procname
= "numa_balancing_scan_size_mb",
408 .data
= &sysctl_numa_balancing_scan_size
,
409 .maxlen
= sizeof(unsigned int),
411 .proc_handler
= proc_dointvec_minmax
,
415 .procname
= "numa_balancing",
416 .data
= NULL
, /* filled in by handler */
417 .maxlen
= sizeof(unsigned int),
419 .proc_handler
= sysctl_numa_balancing
,
423 #endif /* CONFIG_NUMA_BALANCING */
424 #endif /* CONFIG_SCHED_DEBUG */
426 .procname
= "sched_rt_period_us",
427 .data
= &sysctl_sched_rt_period
,
428 .maxlen
= sizeof(unsigned int),
430 .proc_handler
= sched_rt_handler
,
433 .procname
= "sched_rt_runtime_us",
434 .data
= &sysctl_sched_rt_runtime
,
435 .maxlen
= sizeof(int),
437 .proc_handler
= sched_rt_handler
,
440 .procname
= "sched_rr_timeslice_ms",
441 .data
= &sysctl_sched_rr_timeslice
,
442 .maxlen
= sizeof(int),
444 .proc_handler
= sched_rr_handler
,
446 #ifdef CONFIG_SCHED_AUTOGROUP
448 .procname
= "sched_autogroup_enabled",
449 .data
= &sysctl_sched_autogroup_enabled
,
450 .maxlen
= sizeof(unsigned int),
452 .proc_handler
= proc_dointvec_minmax
,
457 #ifdef CONFIG_CFS_BANDWIDTH
459 .procname
= "sched_cfs_bandwidth_slice_us",
460 .data
= &sysctl_sched_cfs_bandwidth_slice
,
461 .maxlen
= sizeof(unsigned int),
463 .proc_handler
= proc_dointvec_minmax
,
467 #ifdef CONFIG_PROVE_LOCKING
469 .procname
= "prove_locking",
470 .data
= &prove_locking
,
471 .maxlen
= sizeof(int),
473 .proc_handler
= proc_dointvec
,
476 #ifdef CONFIG_LOCK_STAT
478 .procname
= "lock_stat",
480 .maxlen
= sizeof(int),
482 .proc_handler
= proc_dointvec
,
487 .data
= &panic_timeout
,
488 .maxlen
= sizeof(int),
490 .proc_handler
= proc_dointvec
,
492 #ifdef CONFIG_COREDUMP
494 .procname
= "core_uses_pid",
495 .data
= &core_uses_pid
,
496 .maxlen
= sizeof(int),
498 .proc_handler
= proc_dointvec
,
501 .procname
= "core_pattern",
502 .data
= core_pattern
,
503 .maxlen
= CORENAME_MAX_SIZE
,
505 .proc_handler
= proc_dostring_coredump
,
508 .procname
= "core_pipe_limit",
509 .data
= &core_pipe_limit
,
510 .maxlen
= sizeof(unsigned int),
512 .proc_handler
= proc_dointvec
,
515 #ifdef CONFIG_PROC_SYSCTL
517 .procname
= "tainted",
518 .maxlen
= sizeof(long),
520 .proc_handler
= proc_taint
,
523 .procname
= "sysctl_writes_strict",
524 .data
= &sysctl_writes_strict
,
525 .maxlen
= sizeof(int),
527 .proc_handler
= proc_dointvec_minmax
,
532 #ifdef CONFIG_LATENCYTOP
534 .procname
= "latencytop",
535 .data
= &latencytop_enabled
,
536 .maxlen
= sizeof(int),
538 .proc_handler
= sysctl_latencytop
,
541 #ifdef CONFIG_BLK_DEV_INITRD
543 .procname
= "real-root-dev",
544 .data
= &real_root_dev
,
545 .maxlen
= sizeof(int),
547 .proc_handler
= proc_dointvec
,
551 .procname
= "print-fatal-signals",
552 .data
= &print_fatal_signals
,
553 .maxlen
= sizeof(int),
555 .proc_handler
= proc_dointvec
,
559 .procname
= "reboot-cmd",
560 .data
= reboot_command
,
563 .proc_handler
= proc_dostring
,
566 .procname
= "stop-a",
567 .data
= &stop_a_enabled
,
568 .maxlen
= sizeof (int),
570 .proc_handler
= proc_dointvec
,
573 .procname
= "scons-poweroff",
574 .data
= &scons_pwroff
,
575 .maxlen
= sizeof (int),
577 .proc_handler
= proc_dointvec
,
580 #ifdef CONFIG_SPARC64
582 .procname
= "tsb-ratio",
583 .data
= &sysctl_tsb_ratio
,
584 .maxlen
= sizeof (int),
586 .proc_handler
= proc_dointvec
,
591 .procname
= "soft-power",
592 .data
= &pwrsw_enabled
,
593 .maxlen
= sizeof (int),
595 .proc_handler
= proc_dointvec
,
598 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
600 .procname
= "unaligned-trap",
601 .data
= &unaligned_enabled
,
602 .maxlen
= sizeof (int),
604 .proc_handler
= proc_dointvec
,
608 .procname
= "ctrl-alt-del",
610 .maxlen
= sizeof(int),
612 .proc_handler
= proc_dointvec
,
614 #ifdef CONFIG_FUNCTION_TRACER
616 .procname
= "ftrace_enabled",
617 .data
= &ftrace_enabled
,
618 .maxlen
= sizeof(int),
620 .proc_handler
= ftrace_enable_sysctl
,
623 #ifdef CONFIG_STACK_TRACER
625 .procname
= "stack_tracer_enabled",
626 .data
= &stack_tracer_enabled
,
627 .maxlen
= sizeof(int),
629 .proc_handler
= stack_trace_sysctl
,
632 #ifdef CONFIG_TRACING
634 .procname
= "ftrace_dump_on_oops",
635 .data
= &ftrace_dump_on_oops
,
636 .maxlen
= sizeof(int),
638 .proc_handler
= proc_dointvec
,
641 .procname
= "traceoff_on_warning",
642 .data
= &__disable_trace_on_warning
,
643 .maxlen
= sizeof(__disable_trace_on_warning
),
645 .proc_handler
= proc_dointvec
,
648 .procname
= "tracepoint_printk",
649 .data
= &tracepoint_printk
,
650 .maxlen
= sizeof(tracepoint_printk
),
652 .proc_handler
= tracepoint_printk_sysctl
,
655 #ifdef CONFIG_KEXEC_CORE
657 .procname
= "kexec_load_disabled",
658 .data
= &kexec_load_disabled
,
659 .maxlen
= sizeof(int),
661 /* only handle a transition from default "0" to "1" */
662 .proc_handler
= proc_dointvec_minmax
,
667 #ifdef CONFIG_MODULES
669 .procname
= "modprobe",
670 .data
= &modprobe_path
,
671 .maxlen
= KMOD_PATH_LEN
,
673 .proc_handler
= proc_dostring
,
676 .procname
= "modules_disabled",
677 .data
= &modules_disabled
,
678 .maxlen
= sizeof(int),
680 /* only handle a transition from default "0" to "1" */
681 .proc_handler
= proc_dointvec_minmax
,
686 #ifdef CONFIG_UEVENT_HELPER
688 .procname
= "hotplug",
689 .data
= &uevent_helper
,
690 .maxlen
= UEVENT_HELPER_PATH_LEN
,
692 .proc_handler
= proc_dostring
,
695 #ifdef CONFIG_CHR_DEV_SG
697 .procname
= "sg-big-buff",
698 .data
= &sg_big_buff
,
699 .maxlen
= sizeof (int),
701 .proc_handler
= proc_dointvec
,
704 #ifdef CONFIG_BSD_PROCESS_ACCT
708 .maxlen
= 3*sizeof(int),
710 .proc_handler
= proc_dointvec
,
713 #ifdef CONFIG_MAGIC_SYSRQ
716 .data
= &__sysrq_enabled
,
717 .maxlen
= sizeof (int),
719 .proc_handler
= sysrq_sysctl_handler
,
722 #ifdef CONFIG_PROC_SYSCTL
724 .procname
= "cad_pid",
726 .maxlen
= sizeof (int),
728 .proc_handler
= proc_do_cad_pid
,
732 .procname
= "threads-max",
734 .maxlen
= sizeof(int),
736 .proc_handler
= sysctl_max_threads
,
739 .procname
= "random",
741 .child
= random_table
,
744 .procname
= "usermodehelper",
746 .child
= usermodehelper_table
,
749 .procname
= "overflowuid",
750 .data
= &overflowuid
,
751 .maxlen
= sizeof(int),
753 .proc_handler
= proc_dointvec_minmax
,
754 .extra1
= &minolduid
,
755 .extra2
= &maxolduid
,
758 .procname
= "overflowgid",
759 .data
= &overflowgid
,
760 .maxlen
= sizeof(int),
762 .proc_handler
= proc_dointvec_minmax
,
763 .extra1
= &minolduid
,
764 .extra2
= &maxolduid
,
767 #ifdef CONFIG_MATHEMU
769 .procname
= "ieee_emulation_warnings",
770 .data
= &sysctl_ieee_emulation_warnings
,
771 .maxlen
= sizeof(int),
773 .proc_handler
= proc_dointvec
,
777 .procname
= "userprocess_debug",
778 .data
= &show_unhandled_signals
,
779 .maxlen
= sizeof(int),
781 .proc_handler
= proc_dointvec
,
785 .procname
= "pid_max",
787 .maxlen
= sizeof (int),
789 .proc_handler
= proc_dointvec_minmax
,
790 .extra1
= &pid_max_min
,
791 .extra2
= &pid_max_max
,
794 .procname
= "panic_on_oops",
795 .data
= &panic_on_oops
,
796 .maxlen
= sizeof(int),
798 .proc_handler
= proc_dointvec
,
800 #if defined CONFIG_PRINTK
802 .procname
= "printk",
803 .data
= &console_loglevel
,
804 .maxlen
= 4*sizeof(int),
806 .proc_handler
= proc_dointvec
,
809 .procname
= "printk_ratelimit",
810 .data
= &printk_ratelimit_state
.interval
,
811 .maxlen
= sizeof(int),
813 .proc_handler
= proc_dointvec_jiffies
,
816 .procname
= "printk_ratelimit_burst",
817 .data
= &printk_ratelimit_state
.burst
,
818 .maxlen
= sizeof(int),
820 .proc_handler
= proc_dointvec
,
823 .procname
= "printk_delay",
824 .data
= &printk_delay_msec
,
825 .maxlen
= sizeof(int),
827 .proc_handler
= proc_dointvec_minmax
,
829 .extra2
= &ten_thousand
,
832 .procname
= "printk_devkmsg",
833 .data
= devkmsg_log_str
,
834 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
836 .proc_handler
= devkmsg_sysctl_set_loglvl
,
839 .procname
= "dmesg_restrict",
840 .data
= &dmesg_restrict
,
841 .maxlen
= sizeof(int),
843 .proc_handler
= proc_dointvec_minmax_sysadmin
,
848 .procname
= "kptr_restrict",
849 .data
= &kptr_restrict
,
850 .maxlen
= sizeof(int),
852 .proc_handler
= proc_dointvec_minmax_sysadmin
,
858 .procname
= "ngroups_max",
859 .data
= &ngroups_max
,
860 .maxlen
= sizeof (int),
862 .proc_handler
= proc_dointvec
,
865 .procname
= "cap_last_cap",
866 .data
= (void *)&cap_last_cap
,
867 .maxlen
= sizeof(int),
869 .proc_handler
= proc_dointvec
,
871 #if defined(CONFIG_LOCKUP_DETECTOR)
873 .procname
= "watchdog",
874 .data
= &watchdog_user_enabled
,
875 .maxlen
= sizeof (int),
877 .proc_handler
= proc_watchdog
,
882 .procname
= "watchdog_thresh",
883 .data
= &watchdog_thresh
,
884 .maxlen
= sizeof(int),
886 .proc_handler
= proc_watchdog_thresh
,
891 .procname
= "nmi_watchdog",
892 .data
= &nmi_watchdog_enabled
,
893 .maxlen
= sizeof (int),
895 .proc_handler
= proc_nmi_watchdog
,
897 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
904 .procname
= "watchdog_cpumask",
905 .data
= &watchdog_cpumask_bits
,
908 .proc_handler
= proc_watchdog_cpumask
,
910 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
912 .procname
= "soft_watchdog",
913 .data
= &soft_watchdog_enabled
,
914 .maxlen
= sizeof (int),
916 .proc_handler
= proc_soft_watchdog
,
921 .procname
= "softlockup_panic",
922 .data
= &softlockup_panic
,
923 .maxlen
= sizeof(int),
925 .proc_handler
= proc_dointvec_minmax
,
931 .procname
= "softlockup_all_cpu_backtrace",
932 .data
= &sysctl_softlockup_all_cpu_backtrace
,
933 .maxlen
= sizeof(int),
935 .proc_handler
= proc_dointvec_minmax
,
939 #endif /* CONFIG_SMP */
941 #ifdef CONFIG_HARDLOCKUP_DETECTOR
943 .procname
= "hardlockup_panic",
944 .data
= &hardlockup_panic
,
945 .maxlen
= sizeof(int),
947 .proc_handler
= proc_dointvec_minmax
,
953 .procname
= "hardlockup_all_cpu_backtrace",
954 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
955 .maxlen
= sizeof(int),
957 .proc_handler
= proc_dointvec_minmax
,
961 #endif /* CONFIG_SMP */
965 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
967 .procname
= "unknown_nmi_panic",
968 .data
= &unknown_nmi_panic
,
969 .maxlen
= sizeof (int),
971 .proc_handler
= proc_dointvec
,
974 #if defined(CONFIG_X86)
976 .procname
= "panic_on_unrecovered_nmi",
977 .data
= &panic_on_unrecovered_nmi
,
978 .maxlen
= sizeof(int),
980 .proc_handler
= proc_dointvec
,
983 .procname
= "panic_on_io_nmi",
984 .data
= &panic_on_io_nmi
,
985 .maxlen
= sizeof(int),
987 .proc_handler
= proc_dointvec
,
989 #ifdef CONFIG_DEBUG_STACKOVERFLOW
991 .procname
= "panic_on_stackoverflow",
992 .data
= &sysctl_panic_on_stackoverflow
,
993 .maxlen
= sizeof(int),
995 .proc_handler
= proc_dointvec
,
999 .procname
= "bootloader_type",
1000 .data
= &bootloader_type
,
1001 .maxlen
= sizeof (int),
1003 .proc_handler
= proc_dointvec
,
1006 .procname
= "bootloader_version",
1007 .data
= &bootloader_version
,
1008 .maxlen
= sizeof (int),
1010 .proc_handler
= proc_dointvec
,
1013 .procname
= "io_delay_type",
1014 .data
= &io_delay_type
,
1015 .maxlen
= sizeof(int),
1017 .proc_handler
= proc_dointvec
,
1020 #if defined(CONFIG_MMU)
1022 .procname
= "randomize_va_space",
1023 .data
= &randomize_va_space
,
1024 .maxlen
= sizeof(int),
1026 .proc_handler
= proc_dointvec
,
1029 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1031 .procname
= "spin_retry",
1032 .data
= &spin_retry
,
1033 .maxlen
= sizeof (int),
1035 .proc_handler
= proc_dointvec
,
1038 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1040 .procname
= "acpi_video_flags",
1041 .data
= &acpi_realmode_flags
,
1042 .maxlen
= sizeof (unsigned long),
1044 .proc_handler
= proc_doulongvec_minmax
,
1047 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1049 .procname
= "ignore-unaligned-usertrap",
1050 .data
= &no_unaligned_warning
,
1051 .maxlen
= sizeof (int),
1053 .proc_handler
= proc_dointvec
,
1058 .procname
= "unaligned-dump-stack",
1059 .data
= &unaligned_dump_stack
,
1060 .maxlen
= sizeof (int),
1062 .proc_handler
= proc_dointvec
,
1065 #ifdef CONFIG_DETECT_HUNG_TASK
1067 .procname
= "hung_task_panic",
1068 .data
= &sysctl_hung_task_panic
,
1069 .maxlen
= sizeof(int),
1071 .proc_handler
= proc_dointvec_minmax
,
1076 .procname
= "hung_task_check_count",
1077 .data
= &sysctl_hung_task_check_count
,
1078 .maxlen
= sizeof(int),
1080 .proc_handler
= proc_dointvec_minmax
,
1084 .procname
= "hung_task_timeout_secs",
1085 .data
= &sysctl_hung_task_timeout_secs
,
1086 .maxlen
= sizeof(unsigned long),
1088 .proc_handler
= proc_dohung_task_timeout_secs
,
1089 .extra2
= &hung_task_timeout_max
,
1092 .procname
= "hung_task_warnings",
1093 .data
= &sysctl_hung_task_warnings
,
1094 .maxlen
= sizeof(int),
1096 .proc_handler
= proc_dointvec_minmax
,
1100 #ifdef CONFIG_RT_MUTEXES
1102 .procname
= "max_lock_depth",
1103 .data
= &max_lock_depth
,
1104 .maxlen
= sizeof(int),
1106 .proc_handler
= proc_dointvec
,
1110 .procname
= "poweroff_cmd",
1111 .data
= &poweroff_cmd
,
1112 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1114 .proc_handler
= proc_dostring
,
1120 .child
= key_sysctls
,
1123 #ifdef CONFIG_PERF_EVENTS
1125 * User-space scripts rely on the existence of this file
1126 * as a feature check for perf_events being enabled.
1128 * So it's an ABI, do not remove!
1131 .procname
= "perf_event_paranoid",
1132 .data
= &sysctl_perf_event_paranoid
,
1133 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1135 .proc_handler
= proc_dointvec
,
1138 .procname
= "perf_event_mlock_kb",
1139 .data
= &sysctl_perf_event_mlock
,
1140 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1142 .proc_handler
= proc_dointvec
,
1145 .procname
= "perf_event_max_sample_rate",
1146 .data
= &sysctl_perf_event_sample_rate
,
1147 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1149 .proc_handler
= perf_proc_update_handler
,
1153 .procname
= "perf_cpu_time_max_percent",
1154 .data
= &sysctl_perf_cpu_time_max_percent
,
1155 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1157 .proc_handler
= perf_cpu_time_max_percent_handler
,
1159 .extra2
= &one_hundred
,
1162 .procname
= "perf_event_max_stack",
1163 .data
= &sysctl_perf_event_max_stack
,
1164 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1166 .proc_handler
= perf_event_max_stack_handler
,
1168 .extra2
= &six_hundred_forty_kb
,
1171 .procname
= "perf_event_max_contexts_per_stack",
1172 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1173 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1175 .proc_handler
= perf_event_max_stack_handler
,
1177 .extra2
= &one_thousand
,
1180 #ifdef CONFIG_KMEMCHECK
1182 .procname
= "kmemcheck",
1183 .data
= &kmemcheck_enabled
,
1184 .maxlen
= sizeof(int),
1186 .proc_handler
= proc_dointvec
,
1190 .procname
= "panic_on_warn",
1191 .data
= &panic_on_warn
,
1192 .maxlen
= sizeof(int),
1194 .proc_handler
= proc_dointvec_minmax
,
1198 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1200 .procname
= "timer_migration",
1201 .data
= &sysctl_timer_migration
,
1202 .maxlen
= sizeof(unsigned int),
1204 .proc_handler
= timer_migration_handler
,
1209 #ifdef CONFIG_BPF_SYSCALL
1211 .procname
= "unprivileged_bpf_disabled",
1212 .data
= &sysctl_unprivileged_bpf_disabled
,
1213 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1215 /* only handle a transition from default "0" to "1" */
1216 .proc_handler
= proc_dointvec_minmax
,
1221 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1223 .procname
= "panic_on_rcu_stall",
1224 .data
= &sysctl_panic_on_rcu_stall
,
1225 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1227 .proc_handler
= proc_dointvec_minmax
,
1235 static struct ctl_table vm_table
[] = {
1237 .procname
= "overcommit_memory",
1238 .data
= &sysctl_overcommit_memory
,
1239 .maxlen
= sizeof(sysctl_overcommit_memory
),
1241 .proc_handler
= proc_dointvec_minmax
,
1246 .procname
= "panic_on_oom",
1247 .data
= &sysctl_panic_on_oom
,
1248 .maxlen
= sizeof(sysctl_panic_on_oom
),
1250 .proc_handler
= proc_dointvec_minmax
,
1255 .procname
= "oom_kill_allocating_task",
1256 .data
= &sysctl_oom_kill_allocating_task
,
1257 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1259 .proc_handler
= proc_dointvec
,
1262 .procname
= "oom_dump_tasks",
1263 .data
= &sysctl_oom_dump_tasks
,
1264 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1266 .proc_handler
= proc_dointvec
,
1269 .procname
= "overcommit_ratio",
1270 .data
= &sysctl_overcommit_ratio
,
1271 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1273 .proc_handler
= overcommit_ratio_handler
,
1276 .procname
= "overcommit_kbytes",
1277 .data
= &sysctl_overcommit_kbytes
,
1278 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1280 .proc_handler
= overcommit_kbytes_handler
,
1283 .procname
= "page-cluster",
1284 .data
= &page_cluster
,
1285 .maxlen
= sizeof(int),
1287 .proc_handler
= proc_dointvec_minmax
,
1291 .procname
= "dirty_background_ratio",
1292 .data
= &dirty_background_ratio
,
1293 .maxlen
= sizeof(dirty_background_ratio
),
1295 .proc_handler
= dirty_background_ratio_handler
,
1297 .extra2
= &one_hundred
,
1300 .procname
= "dirty_background_bytes",
1301 .data
= &dirty_background_bytes
,
1302 .maxlen
= sizeof(dirty_background_bytes
),
1304 .proc_handler
= dirty_background_bytes_handler
,
1308 .procname
= "dirty_ratio",
1309 .data
= &vm_dirty_ratio
,
1310 .maxlen
= sizeof(vm_dirty_ratio
),
1312 .proc_handler
= dirty_ratio_handler
,
1314 .extra2
= &one_hundred
,
1317 .procname
= "dirty_bytes",
1318 .data
= &vm_dirty_bytes
,
1319 .maxlen
= sizeof(vm_dirty_bytes
),
1321 .proc_handler
= dirty_bytes_handler
,
1322 .extra1
= &dirty_bytes_min
,
1325 .procname
= "dirty_writeback_centisecs",
1326 .data
= &dirty_writeback_interval
,
1327 .maxlen
= sizeof(dirty_writeback_interval
),
1329 .proc_handler
= dirty_writeback_centisecs_handler
,
1332 .procname
= "dirty_expire_centisecs",
1333 .data
= &dirty_expire_interval
,
1334 .maxlen
= sizeof(dirty_expire_interval
),
1336 .proc_handler
= proc_dointvec_minmax
,
1340 .procname
= "dirtytime_expire_seconds",
1341 .data
= &dirtytime_expire_interval
,
1342 .maxlen
= sizeof(dirty_expire_interval
),
1344 .proc_handler
= dirtytime_interval_handler
,
1348 .procname
= "nr_pdflush_threads",
1349 .mode
= 0444 /* read-only */,
1350 .proc_handler
= pdflush_proc_obsolete
,
1353 .procname
= "swappiness",
1354 .data
= &vm_swappiness
,
1355 .maxlen
= sizeof(vm_swappiness
),
1357 .proc_handler
= proc_dointvec_minmax
,
1359 .extra2
= &one_hundred
,
1361 #ifdef CONFIG_HUGETLB_PAGE
1363 .procname
= "nr_hugepages",
1365 .maxlen
= sizeof(unsigned long),
1367 .proc_handler
= hugetlb_sysctl_handler
,
1371 .procname
= "nr_hugepages_mempolicy",
1373 .maxlen
= sizeof(unsigned long),
1375 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1379 .procname
= "hugetlb_shm_group",
1380 .data
= &sysctl_hugetlb_shm_group
,
1381 .maxlen
= sizeof(gid_t
),
1383 .proc_handler
= proc_dointvec
,
1386 .procname
= "hugepages_treat_as_movable",
1387 .data
= &hugepages_treat_as_movable
,
1388 .maxlen
= sizeof(int),
1390 .proc_handler
= proc_dointvec
,
1393 .procname
= "nr_overcommit_hugepages",
1395 .maxlen
= sizeof(unsigned long),
1397 .proc_handler
= hugetlb_overcommit_handler
,
1401 .procname
= "lowmem_reserve_ratio",
1402 .data
= &sysctl_lowmem_reserve_ratio
,
1403 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1405 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1408 .procname
= "drop_caches",
1409 .data
= &sysctl_drop_caches
,
1410 .maxlen
= sizeof(int),
1412 .proc_handler
= drop_caches_sysctl_handler
,
1416 #ifdef CONFIG_COMPACTION
1418 .procname
= "compact_memory",
1419 .data
= &sysctl_compact_memory
,
1420 .maxlen
= sizeof(int),
1422 .proc_handler
= sysctl_compaction_handler
,
1425 .procname
= "extfrag_threshold",
1426 .data
= &sysctl_extfrag_threshold
,
1427 .maxlen
= sizeof(int),
1429 .proc_handler
= sysctl_extfrag_handler
,
1430 .extra1
= &min_extfrag_threshold
,
1431 .extra2
= &max_extfrag_threshold
,
1434 .procname
= "compact_unevictable_allowed",
1435 .data
= &sysctl_compact_unevictable_allowed
,
1436 .maxlen
= sizeof(int),
1438 .proc_handler
= proc_dointvec
,
1443 #endif /* CONFIG_COMPACTION */
1445 .procname
= "min_free_kbytes",
1446 .data
= &min_free_kbytes
,
1447 .maxlen
= sizeof(min_free_kbytes
),
1449 .proc_handler
= min_free_kbytes_sysctl_handler
,
1453 .procname
= "watermark_scale_factor",
1454 .data
= &watermark_scale_factor
,
1455 .maxlen
= sizeof(watermark_scale_factor
),
1457 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1459 .extra2
= &one_thousand
,
1462 .procname
= "percpu_pagelist_fraction",
1463 .data
= &percpu_pagelist_fraction
,
1464 .maxlen
= sizeof(percpu_pagelist_fraction
),
1466 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1471 .procname
= "max_map_count",
1472 .data
= &sysctl_max_map_count
,
1473 .maxlen
= sizeof(sysctl_max_map_count
),
1475 .proc_handler
= proc_dointvec_minmax
,
1480 .procname
= "nr_trim_pages",
1481 .data
= &sysctl_nr_trim_pages
,
1482 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1484 .proc_handler
= proc_dointvec_minmax
,
1489 .procname
= "laptop_mode",
1490 .data
= &laptop_mode
,
1491 .maxlen
= sizeof(laptop_mode
),
1493 .proc_handler
= proc_dointvec_jiffies
,
1496 .procname
= "block_dump",
1497 .data
= &block_dump
,
1498 .maxlen
= sizeof(block_dump
),
1500 .proc_handler
= proc_dointvec
,
1504 .procname
= "vfs_cache_pressure",
1505 .data
= &sysctl_vfs_cache_pressure
,
1506 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1508 .proc_handler
= proc_dointvec
,
1511 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1513 .procname
= "legacy_va_layout",
1514 .data
= &sysctl_legacy_va_layout
,
1515 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1517 .proc_handler
= proc_dointvec
,
1523 .procname
= "zone_reclaim_mode",
1524 .data
= &node_reclaim_mode
,
1525 .maxlen
= sizeof(node_reclaim_mode
),
1527 .proc_handler
= proc_dointvec
,
1531 .procname
= "min_unmapped_ratio",
1532 .data
= &sysctl_min_unmapped_ratio
,
1533 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1535 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1537 .extra2
= &one_hundred
,
1540 .procname
= "min_slab_ratio",
1541 .data
= &sysctl_min_slab_ratio
,
1542 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1544 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1546 .extra2
= &one_hundred
,
1551 .procname
= "stat_interval",
1552 .data
= &sysctl_stat_interval
,
1553 .maxlen
= sizeof(sysctl_stat_interval
),
1555 .proc_handler
= proc_dointvec_jiffies
,
1558 .procname
= "stat_refresh",
1562 .proc_handler
= vmstat_refresh
,
1567 .procname
= "mmap_min_addr",
1568 .data
= &dac_mmap_min_addr
,
1569 .maxlen
= sizeof(unsigned long),
1571 .proc_handler
= mmap_min_addr_handler
,
1576 .procname
= "numa_zonelist_order",
1577 .data
= &numa_zonelist_order
,
1578 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1580 .proc_handler
= numa_zonelist_order_handler
,
1583 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1584 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1586 .procname
= "vdso_enabled",
1587 #ifdef CONFIG_X86_32
1588 .data
= &vdso32_enabled
,
1589 .maxlen
= sizeof(vdso32_enabled
),
1591 .data
= &vdso_enabled
,
1592 .maxlen
= sizeof(vdso_enabled
),
1595 .proc_handler
= proc_dointvec
,
1599 #ifdef CONFIG_HIGHMEM
1601 .procname
= "highmem_is_dirtyable",
1602 .data
= &vm_highmem_is_dirtyable
,
1603 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1605 .proc_handler
= proc_dointvec_minmax
,
1610 #ifdef CONFIG_MEMORY_FAILURE
1612 .procname
= "memory_failure_early_kill",
1613 .data
= &sysctl_memory_failure_early_kill
,
1614 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1616 .proc_handler
= proc_dointvec_minmax
,
1621 .procname
= "memory_failure_recovery",
1622 .data
= &sysctl_memory_failure_recovery
,
1623 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1625 .proc_handler
= proc_dointvec_minmax
,
1631 .procname
= "user_reserve_kbytes",
1632 .data
= &sysctl_user_reserve_kbytes
,
1633 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1635 .proc_handler
= proc_doulongvec_minmax
,
1638 .procname
= "admin_reserve_kbytes",
1639 .data
= &sysctl_admin_reserve_kbytes
,
1640 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1642 .proc_handler
= proc_doulongvec_minmax
,
1644 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1646 .procname
= "mmap_rnd_bits",
1647 .data
= &mmap_rnd_bits
,
1648 .maxlen
= sizeof(mmap_rnd_bits
),
1650 .proc_handler
= proc_dointvec_minmax
,
1651 .extra1
= (void *)&mmap_rnd_bits_min
,
1652 .extra2
= (void *)&mmap_rnd_bits_max
,
1655 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1657 .procname
= "mmap_rnd_compat_bits",
1658 .data
= &mmap_rnd_compat_bits
,
1659 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1661 .proc_handler
= proc_dointvec_minmax
,
1662 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1663 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1669 static struct ctl_table fs_table
[] = {
1671 .procname
= "inode-nr",
1672 .data
= &inodes_stat
,
1673 .maxlen
= 2*sizeof(long),
1675 .proc_handler
= proc_nr_inodes
,
1678 .procname
= "inode-state",
1679 .data
= &inodes_stat
,
1680 .maxlen
= 7*sizeof(long),
1682 .proc_handler
= proc_nr_inodes
,
1685 .procname
= "file-nr",
1686 .data
= &files_stat
,
1687 .maxlen
= sizeof(files_stat
),
1689 .proc_handler
= proc_nr_files
,
1692 .procname
= "file-max",
1693 .data
= &files_stat
.max_files
,
1694 .maxlen
= sizeof(files_stat
.max_files
),
1696 .proc_handler
= proc_doulongvec_minmax
,
1699 .procname
= "nr_open",
1700 .data
= &sysctl_nr_open
,
1701 .maxlen
= sizeof(unsigned int),
1703 .proc_handler
= proc_dointvec_minmax
,
1704 .extra1
= &sysctl_nr_open_min
,
1705 .extra2
= &sysctl_nr_open_max
,
1708 .procname
= "dentry-state",
1709 .data
= &dentry_stat
,
1710 .maxlen
= 6*sizeof(long),
1712 .proc_handler
= proc_nr_dentry
,
1715 .procname
= "overflowuid",
1716 .data
= &fs_overflowuid
,
1717 .maxlen
= sizeof(int),
1719 .proc_handler
= proc_dointvec_minmax
,
1720 .extra1
= &minolduid
,
1721 .extra2
= &maxolduid
,
1724 .procname
= "overflowgid",
1725 .data
= &fs_overflowgid
,
1726 .maxlen
= sizeof(int),
1728 .proc_handler
= proc_dointvec_minmax
,
1729 .extra1
= &minolduid
,
1730 .extra2
= &maxolduid
,
1732 #ifdef CONFIG_FILE_LOCKING
1734 .procname
= "leases-enable",
1735 .data
= &leases_enable
,
1736 .maxlen
= sizeof(int),
1738 .proc_handler
= proc_dointvec
,
1741 #ifdef CONFIG_DNOTIFY
1743 .procname
= "dir-notify-enable",
1744 .data
= &dir_notify_enable
,
1745 .maxlen
= sizeof(int),
1747 .proc_handler
= proc_dointvec
,
1751 #ifdef CONFIG_FILE_LOCKING
1753 .procname
= "lease-break-time",
1754 .data
= &lease_break_time
,
1755 .maxlen
= sizeof(int),
1757 .proc_handler
= proc_dointvec
,
1762 .procname
= "aio-nr",
1764 .maxlen
= sizeof(aio_nr
),
1766 .proc_handler
= proc_doulongvec_minmax
,
1769 .procname
= "aio-max-nr",
1770 .data
= &aio_max_nr
,
1771 .maxlen
= sizeof(aio_max_nr
),
1773 .proc_handler
= proc_doulongvec_minmax
,
1775 #endif /* CONFIG_AIO */
1776 #ifdef CONFIG_INOTIFY_USER
1778 .procname
= "inotify",
1780 .child
= inotify_table
,
1785 .procname
= "epoll",
1787 .child
= epoll_table
,
1792 .procname
= "protected_symlinks",
1793 .data
= &sysctl_protected_symlinks
,
1794 .maxlen
= sizeof(int),
1796 .proc_handler
= proc_dointvec_minmax
,
1801 .procname
= "protected_hardlinks",
1802 .data
= &sysctl_protected_hardlinks
,
1803 .maxlen
= sizeof(int),
1805 .proc_handler
= proc_dointvec_minmax
,
1810 .procname
= "suid_dumpable",
1811 .data
= &suid_dumpable
,
1812 .maxlen
= sizeof(int),
1814 .proc_handler
= proc_dointvec_minmax_coredump
,
1818 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1820 .procname
= "binfmt_misc",
1822 .child
= sysctl_mount_point
,
1826 .procname
= "pipe-max-size",
1827 .data
= &pipe_max_size
,
1828 .maxlen
= sizeof(int),
1830 .proc_handler
= &pipe_proc_fn
,
1831 .extra1
= &pipe_min_size
,
1834 .procname
= "pipe-user-pages-hard",
1835 .data
= &pipe_user_pages_hard
,
1836 .maxlen
= sizeof(pipe_user_pages_hard
),
1838 .proc_handler
= proc_doulongvec_minmax
,
1841 .procname
= "pipe-user-pages-soft",
1842 .data
= &pipe_user_pages_soft
,
1843 .maxlen
= sizeof(pipe_user_pages_soft
),
1845 .proc_handler
= proc_doulongvec_minmax
,
1848 .procname
= "mount-max",
1849 .data
= &sysctl_mount_max
,
1850 .maxlen
= sizeof(unsigned int),
1852 .proc_handler
= proc_dointvec_minmax
,
1858 static struct ctl_table debug_table
[] = {
1859 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1861 .procname
= "exception-trace",
1862 .data
= &show_unhandled_signals
,
1863 .maxlen
= sizeof(int),
1865 .proc_handler
= proc_dointvec
1868 #if defined(CONFIG_OPTPROBES)
1870 .procname
= "kprobes-optimization",
1871 .data
= &sysctl_kprobes_optimization
,
1872 .maxlen
= sizeof(int),
1874 .proc_handler
= proc_kprobes_optimization_handler
,
1882 static struct ctl_table dev_table
[] = {
1886 int __init
sysctl_init(void)
1888 struct ctl_table_header
*hdr
;
1890 hdr
= register_sysctl_table(sysctl_base_table
);
1891 kmemleak_not_leak(hdr
);
1895 #endif /* CONFIG_SYSCTL */
1901 #ifdef CONFIG_PROC_SYSCTL
1903 static int _proc_do_string(char *data
, int maxlen
, int write
,
1904 char __user
*buffer
,
1905 size_t *lenp
, loff_t
*ppos
)
1911 if (!data
|| !maxlen
|| !*lenp
) {
1917 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1918 /* Only continue writes not past the end of buffer. */
1920 if (len
> maxlen
- 1)
1927 /* Start writing from beginning of buffer. */
1933 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1934 if (get_user(c
, p
++))
1936 if (c
== 0 || c
== '\n')
1957 if (copy_to_user(buffer
, data
, len
))
1960 if (put_user('\n', buffer
+ len
))
1970 static void warn_sysctl_write(struct ctl_table
*table
)
1972 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1973 "This will not be supported in the future. To silence this\n"
1974 "warning, set kernel.sysctl_writes_strict = -1\n",
1975 current
->comm
, table
->procname
);
1979 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1980 * @ppos: file position
1981 * @table: the sysctl table
1983 * Returns true if the first position is non-zero and the sysctl_writes_strict
1984 * mode indicates this is not allowed for numeric input types. String proc
1985 * hadlers can ignore the return value.
1987 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
1988 struct ctl_table
*table
)
1993 switch (sysctl_writes_strict
) {
1994 case SYSCTL_WRITES_STRICT
:
1996 case SYSCTL_WRITES_WARN
:
1997 warn_sysctl_write(table
);
2005 * proc_dostring - read a string sysctl
2006 * @table: the sysctl table
2007 * @write: %TRUE if this is a write to the sysctl file
2008 * @buffer: the user buffer
2009 * @lenp: the size of the user buffer
2010 * @ppos: file position
2012 * Reads/writes a string from/to the user buffer. If the kernel
2013 * buffer provided is not large enough to hold the string, the
2014 * string is truncated. The copied string is %NULL-terminated.
2015 * If the string is being read by the user process, it is copied
2016 * and a newline '\n' is added. It is truncated if the buffer is
2019 * Returns 0 on success.
2021 int proc_dostring(struct ctl_table
*table
, int write
,
2022 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2025 proc_first_pos_non_zero_ignore(ppos
, table
);
2027 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2028 (char __user
*)buffer
, lenp
, ppos
);
2031 static size_t proc_skip_spaces(char **buf
)
2034 char *tmp
= skip_spaces(*buf
);
2040 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2050 #define TMPBUFLEN 22
2052 * proc_get_long - reads an ASCII formatted integer from a user buffer
2054 * @buf: a kernel buffer
2055 * @size: size of the kernel buffer
2056 * @val: this is where the number will be stored
2057 * @neg: set to %TRUE if number is negative
2058 * @perm_tr: a vector which contains the allowed trailers
2059 * @perm_tr_len: size of the perm_tr vector
2060 * @tr: pointer to store the trailer character
2062 * In case of success %0 is returned and @buf and @size are updated with
2063 * the amount of bytes read. If @tr is non-NULL and a trailing
2064 * character exists (size is non-zero after returning from this
2065 * function), @tr is updated with the trailing character.
2067 static int proc_get_long(char **buf
, size_t *size
,
2068 unsigned long *val
, bool *neg
,
2069 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2072 char *p
, tmp
[TMPBUFLEN
];
2078 if (len
> TMPBUFLEN
- 1)
2079 len
= TMPBUFLEN
- 1;
2081 memcpy(tmp
, *buf
, len
);
2085 if (*p
== '-' && *size
> 1) {
2093 *val
= simple_strtoul(p
, &p
, 0);
2097 /* We don't know if the next char is whitespace thus we may accept
2098 * invalid integers (e.g. 1234...a) or two integers instead of one
2099 * (e.g. 123...1). So lets not allow such large numbers. */
2100 if (len
== TMPBUFLEN
- 1)
2103 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2106 if (tr
&& (len
< *size
))
2116 * proc_put_long - converts an integer to a decimal ASCII formatted string
2118 * @buf: the user buffer
2119 * @size: the size of the user buffer
2120 * @val: the integer to be converted
2121 * @neg: sign of the number, %TRUE for negative
2123 * In case of success %0 is returned and @buf and @size are updated with
2124 * the amount of bytes written.
2126 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2130 char tmp
[TMPBUFLEN
], *p
= tmp
;
2132 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2136 if (copy_to_user(*buf
, tmp
, len
))
2144 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2147 char __user
**buffer
= (char __user
**)buf
;
2148 if (put_user(c
, *buffer
))
2150 (*size
)--, (*buffer
)++;
2156 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2158 int write
, void *data
)
2162 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2166 if (*lvalp
> (unsigned long) INT_MAX
)
2174 *lvalp
= -(unsigned long)val
;
2177 *lvalp
= (unsigned long)val
;
2183 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2185 int write
, void *data
)
2188 if (*lvalp
> UINT_MAX
)
2190 if (*lvalp
> UINT_MAX
)
2194 unsigned int val
= *valp
;
2195 *lvalp
= (unsigned long)val
;
2200 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2202 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2203 int write
, void __user
*buffer
,
2204 size_t *lenp
, loff_t
*ppos
,
2205 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2206 int write
, void *data
),
2209 int *i
, vleft
, first
= 1, err
= 0;
2211 char *kbuf
= NULL
, *p
;
2213 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2218 i
= (int *) tbl_data
;
2219 vleft
= table
->maxlen
/ sizeof(*i
);
2223 conv
= do_proc_dointvec_conv
;
2226 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2229 if (left
> PAGE_SIZE
- 1)
2230 left
= PAGE_SIZE
- 1;
2231 p
= kbuf
= memdup_user_nul(buffer
, left
);
2233 return PTR_ERR(kbuf
);
2236 for (; left
&& vleft
--; i
++, first
=0) {
2241 left
-= proc_skip_spaces(&p
);
2245 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2247 sizeof(proc_wspace_sep
), NULL
);
2250 if (conv(&neg
, &lval
, i
, 1, data
)) {
2255 if (conv(&neg
, &lval
, i
, 0, data
)) {
2260 err
= proc_put_char(&buffer
, &left
, '\t');
2263 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2269 if (!write
&& !first
&& left
&& !err
)
2270 err
= proc_put_char(&buffer
, &left
, '\n');
2271 if (write
&& !err
&& left
)
2272 left
-= proc_skip_spaces(&p
);
2276 return err
? : -EINVAL
;
2284 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2285 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2286 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2287 int write
, void *data
),
2290 return __do_proc_dointvec(table
->data
, table
, write
,
2291 buffer
, lenp
, ppos
, conv
, data
);
2294 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2295 struct ctl_table
*table
,
2296 void __user
*buffer
,
2297 size_t *lenp
, loff_t
*ppos
,
2298 int (*conv
)(unsigned long *lvalp
,
2300 int write
, void *data
),
2307 char *kbuf
= NULL
, *p
;
2311 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2314 if (left
> PAGE_SIZE
- 1)
2315 left
= PAGE_SIZE
- 1;
2317 p
= kbuf
= memdup_user_nul(buffer
, left
);
2321 left
-= proc_skip_spaces(&p
);
2327 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2329 sizeof(proc_wspace_sep
), NULL
);
2335 if (conv(&lval
, tbl_data
, 1, data
)) {
2341 left
-= proc_skip_spaces(&p
);
2350 /* This is in keeping with old __do_proc_dointvec() */
2356 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2357 size_t *lenp
, loff_t
*ppos
,
2358 int (*conv
)(unsigned long *lvalp
,
2360 int write
, void *data
),
2369 if (conv(&lval
, tbl_data
, 0, data
)) {
2374 err
= proc_put_long(&buffer
, &left
, lval
, false);
2378 err
= proc_put_char(&buffer
, &left
, '\n');
2387 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2388 int write
, void __user
*buffer
,
2389 size_t *lenp
, loff_t
*ppos
,
2390 int (*conv
)(unsigned long *lvalp
,
2392 int write
, void *data
),
2395 unsigned int *i
, vleft
;
2397 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2402 i
= (unsigned int *) tbl_data
;
2403 vleft
= table
->maxlen
/ sizeof(*i
);
2406 * Arrays are not supported, keep this simple. *Do not* add
2415 conv
= do_proc_douintvec_conv
;
2418 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2420 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2423 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2424 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2425 int (*conv
)(unsigned long *lvalp
,
2427 int write
, void *data
),
2430 return __do_proc_douintvec(table
->data
, table
, write
,
2431 buffer
, lenp
, ppos
, conv
, data
);
2435 * proc_dointvec - read a vector of integers
2436 * @table: the sysctl table
2437 * @write: %TRUE if this is a write to the sysctl file
2438 * @buffer: the user buffer
2439 * @lenp: the size of the user buffer
2440 * @ppos: file position
2442 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2443 * values from/to the user buffer, treated as an ASCII string.
2445 * Returns 0 on success.
2447 int proc_dointvec(struct ctl_table
*table
, int write
,
2448 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2450 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2454 * proc_douintvec - read a vector of unsigned integers
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
2461 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2462 * values from/to the user buffer, treated as an ASCII string.
2464 * Returns 0 on success.
2466 int proc_douintvec(struct ctl_table
*table
, int write
,
2467 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2469 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2470 do_proc_douintvec_conv
, NULL
);
2474 * Taint values can only be increased
2475 * This means we can safely use a temporary.
2477 static int proc_taint(struct ctl_table
*table
, int write
,
2478 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2481 unsigned long tmptaint
= get_taint();
2484 if (write
&& !capable(CAP_SYS_ADMIN
))
2489 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2495 * Poor man's atomic or. Not worth adding a primitive
2496 * to everyone's atomic.h for this
2499 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2500 if ((tmptaint
>> i
) & 1)
2501 add_taint(i
, LOCKDEP_STILL_OK
);
2508 #ifdef CONFIG_PRINTK
2509 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2510 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2512 if (write
&& !capable(CAP_SYS_ADMIN
))
2515 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2519 struct do_proc_dointvec_minmax_conv_param
{
2524 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2526 int write
, void *data
)
2528 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2530 int val
= *negp
? -*lvalp
: *lvalp
;
2531 if ((param
->min
&& *param
->min
> val
) ||
2532 (param
->max
&& *param
->max
< val
))
2539 *lvalp
= -(unsigned long)val
;
2542 *lvalp
= (unsigned long)val
;
2549 * proc_dointvec_minmax - read a vector of integers with min/max values
2550 * @table: the sysctl table
2551 * @write: %TRUE if this is a write to the sysctl file
2552 * @buffer: the user buffer
2553 * @lenp: the size of the user buffer
2554 * @ppos: file position
2556 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2557 * values from/to the user buffer, treated as an ASCII string.
2559 * This routine will ensure the values are within the range specified by
2560 * table->extra1 (min) and table->extra2 (max).
2562 * Returns 0 on success.
2564 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2565 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2567 struct do_proc_dointvec_minmax_conv_param param
= {
2568 .min
= (int *) table
->extra1
,
2569 .max
= (int *) table
->extra2
,
2571 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2572 do_proc_dointvec_minmax_conv
, ¶m
);
2575 struct do_proc_douintvec_minmax_conv_param
{
2580 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2582 int write
, void *data
)
2584 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2587 unsigned int val
= *lvalp
;
2589 if ((param
->min
&& *param
->min
> val
) ||
2590 (param
->max
&& *param
->max
< val
))
2593 if (*lvalp
> UINT_MAX
)
2597 unsigned int val
= *valp
;
2598 *lvalp
= (unsigned long) val
;
2605 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2606 * @table: the sysctl table
2607 * @write: %TRUE if this is a write to the sysctl file
2608 * @buffer: the user buffer
2609 * @lenp: the size of the user buffer
2610 * @ppos: file position
2612 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2613 * values from/to the user buffer, treated as an ASCII string. Negative
2614 * strings are not allowed.
2616 * This routine will ensure the values are within the range specified by
2617 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2618 * check for UINT_MAX to avoid having to support wrap around uses from
2621 * Returns 0 on success.
2623 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2624 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2626 struct do_proc_douintvec_minmax_conv_param param
= {
2627 .min
= (unsigned int *) table
->extra1
,
2628 .max
= (unsigned int *) table
->extra2
,
2630 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2631 do_proc_douintvec_minmax_conv
, ¶m
);
2634 static void validate_coredump_safety(void)
2636 #ifdef CONFIG_COREDUMP
2637 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2638 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2640 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2641 "Pipe handler or fully qualified core dump path required.\n"
2642 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2648 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2649 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2651 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2653 validate_coredump_safety();
2657 #ifdef CONFIG_COREDUMP
2658 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2659 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2661 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2663 validate_coredump_safety();
2668 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2669 void __user
*buffer
,
2670 size_t *lenp
, loff_t
*ppos
,
2671 unsigned long convmul
,
2672 unsigned long convdiv
)
2674 unsigned long *i
, *min
, *max
;
2675 int vleft
, first
= 1, err
= 0;
2677 char *kbuf
= NULL
, *p
;
2679 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2684 i
= (unsigned long *) data
;
2685 min
= (unsigned long *) table
->extra1
;
2686 max
= (unsigned long *) table
->extra2
;
2687 vleft
= table
->maxlen
/ sizeof(unsigned long);
2691 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2694 if (left
> PAGE_SIZE
- 1)
2695 left
= PAGE_SIZE
- 1;
2696 p
= kbuf
= memdup_user_nul(buffer
, left
);
2698 return PTR_ERR(kbuf
);
2701 for (; left
&& vleft
--; i
++, first
= 0) {
2707 left
-= proc_skip_spaces(&p
);
2709 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2711 sizeof(proc_wspace_sep
), NULL
);
2716 val
= convmul
* val
/ convdiv
;
2717 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2721 val
= convdiv
* (*i
) / convmul
;
2723 err
= proc_put_char(&buffer
, &left
, '\t');
2727 err
= proc_put_long(&buffer
, &left
, val
, false);
2733 if (!write
&& !first
&& left
&& !err
)
2734 err
= proc_put_char(&buffer
, &left
, '\n');
2736 left
-= proc_skip_spaces(&p
);
2740 return err
? : -EINVAL
;
2748 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2749 void __user
*buffer
,
2750 size_t *lenp
, loff_t
*ppos
,
2751 unsigned long convmul
,
2752 unsigned long convdiv
)
2754 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2755 buffer
, lenp
, ppos
, convmul
, convdiv
);
2759 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2760 * @table: the sysctl table
2761 * @write: %TRUE if this is a write to the sysctl file
2762 * @buffer: the user buffer
2763 * @lenp: the size of the user buffer
2764 * @ppos: file position
2766 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2767 * values from/to the user buffer, treated as an ASCII string.
2769 * This routine will ensure the values are within the range specified by
2770 * table->extra1 (min) and table->extra2 (max).
2772 * Returns 0 on success.
2774 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2775 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2777 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2781 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2782 * @table: the sysctl table
2783 * @write: %TRUE if this is a write to the sysctl file
2784 * @buffer: the user buffer
2785 * @lenp: the size of the user buffer
2786 * @ppos: file position
2788 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2789 * values from/to the user buffer, treated as an ASCII string. The values
2790 * are treated as milliseconds, and converted to jiffies when they are stored.
2792 * This routine will ensure the values are within the range specified by
2793 * table->extra1 (min) and table->extra2 (max).
2795 * Returns 0 on success.
2797 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2798 void __user
*buffer
,
2799 size_t *lenp
, loff_t
*ppos
)
2801 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2802 lenp
, ppos
, HZ
, 1000l);
2806 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2808 int write
, void *data
)
2811 if (*lvalp
> INT_MAX
/ HZ
)
2813 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2819 lval
= -(unsigned long)val
;
2822 lval
= (unsigned long)val
;
2829 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2831 int write
, void *data
)
2834 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2836 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2842 lval
= -(unsigned long)val
;
2845 lval
= (unsigned long)val
;
2847 *lvalp
= jiffies_to_clock_t(lval
);
2852 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2854 int write
, void *data
)
2857 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2867 lval
= -(unsigned long)val
;
2870 lval
= (unsigned long)val
;
2872 *lvalp
= jiffies_to_msecs(lval
);
2878 * proc_dointvec_jiffies - read a vector of integers as seconds
2879 * @table: the sysctl table
2880 * @write: %TRUE if this is a write to the sysctl file
2881 * @buffer: the user buffer
2882 * @lenp: the size of the user buffer
2883 * @ppos: file position
2885 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2886 * values from/to the user buffer, treated as an ASCII string.
2887 * The values read are assumed to be in seconds, and are converted into
2890 * Returns 0 on success.
2892 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2893 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2895 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2896 do_proc_dointvec_jiffies_conv
,NULL
);
2900 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2901 * @table: the sysctl table
2902 * @write: %TRUE if this is a write to the sysctl file
2903 * @buffer: the user buffer
2904 * @lenp: the size of the user buffer
2905 * @ppos: pointer to the file position
2907 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2908 * values from/to the user buffer, treated as an ASCII string.
2909 * The values read are assumed to be in 1/USER_HZ seconds, and
2910 * are converted into jiffies.
2912 * Returns 0 on success.
2914 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2915 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2917 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2918 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2922 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2923 * @table: the sysctl table
2924 * @write: %TRUE if this is a write to the sysctl file
2925 * @buffer: the user buffer
2926 * @lenp: the size of the user buffer
2927 * @ppos: file position
2928 * @ppos: the current position in the file
2930 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2931 * values from/to the user buffer, treated as an ASCII string.
2932 * The values read are assumed to be in 1/1000 seconds, and
2933 * are converted into jiffies.
2935 * Returns 0 on success.
2937 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2938 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2940 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2941 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2944 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2945 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2947 struct pid
*new_pid
;
2951 tmp
= pid_vnr(cad_pid
);
2953 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2954 lenp
, ppos
, NULL
, NULL
);
2958 new_pid
= find_get_pid(tmp
);
2962 put_pid(xchg(&cad_pid
, new_pid
));
2967 * proc_do_large_bitmap - read/write from/to a large bitmap
2968 * @table: the sysctl table
2969 * @write: %TRUE if this is a write to the sysctl file
2970 * @buffer: the user buffer
2971 * @lenp: the size of the user buffer
2972 * @ppos: file position
2974 * The bitmap is stored at table->data and the bitmap length (in bits)
2977 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2978 * large bitmaps may be represented in a compact manner. Writing into
2979 * the file will clear the bitmap then update it with the given input.
2981 * Returns 0 on success.
2983 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2984 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2988 size_t left
= *lenp
;
2989 unsigned long bitmap_len
= table
->maxlen
;
2990 unsigned long *bitmap
= *(unsigned long **) table
->data
;
2991 unsigned long *tmp_bitmap
= NULL
;
2992 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2994 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3002 if (left
> PAGE_SIZE
- 1)
3003 left
= PAGE_SIZE
- 1;
3005 p
= kbuf
= memdup_user_nul(buffer
, left
);
3007 return PTR_ERR(kbuf
);
3009 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
3015 proc_skip_char(&p
, &left
, '\n');
3016 while (!err
&& left
) {
3017 unsigned long val_a
, val_b
;
3020 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3024 if (val_a
>= bitmap_len
|| neg
) {
3036 err
= proc_get_long(&p
, &left
, &val_b
,
3037 &neg
, tr_b
, sizeof(tr_b
),
3041 if (val_b
>= bitmap_len
|| neg
||
3052 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3054 proc_skip_char(&p
, &left
, '\n');
3058 unsigned long bit_a
, bit_b
= 0;
3061 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3062 if (bit_a
>= bitmap_len
)
3064 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3068 err
= proc_put_char(&buffer
, &left
, ',');
3072 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3075 if (bit_a
!= bit_b
) {
3076 err
= proc_put_char(&buffer
, &left
, '-');
3079 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3087 err
= proc_put_char(&buffer
, &left
, '\n');
3093 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3095 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3107 #else /* CONFIG_PROC_SYSCTL */
3109 int proc_dostring(struct ctl_table
*table
, int write
,
3110 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3115 int proc_dointvec(struct ctl_table
*table
, int write
,
3116 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3121 int proc_douintvec(struct ctl_table
*table
, int write
,
3122 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3127 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3128 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3133 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3134 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3139 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3140 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3145 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3146 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3151 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3152 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3157 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3158 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3163 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3164 void __user
*buffer
,
3165 size_t *lenp
, loff_t
*ppos
)
3171 #endif /* CONFIG_PROC_SYSCTL */
3174 * No sense putting this after each symbol definition, twice,
3175 * exception granted :-)
3177 EXPORT_SYMBOL(proc_dointvec
);
3178 EXPORT_SYMBOL(proc_douintvec
);
3179 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3180 EXPORT_SYMBOL(proc_dointvec_minmax
);
3181 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3182 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3183 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3184 EXPORT_SYMBOL(proc_dostring
);
3185 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3186 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);