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
,
332 #ifdef CONFIG_SCHED_WALT
334 .procname
= "sched_use_walt_cpu_util",
335 .data
= &sysctl_sched_use_walt_cpu_util
,
336 .maxlen
= sizeof(unsigned int),
338 .proc_handler
= proc_dointvec
,
341 .procname
= "sched_use_walt_task_util",
342 .data
= &sysctl_sched_use_walt_task_util
,
343 .maxlen
= sizeof(unsigned int),
345 .proc_handler
= proc_dointvec
,
348 .procname
= "sched_walt_init_task_load_pct",
349 .data
= &sysctl_sched_walt_init_task_load_pct
,
350 .maxlen
= sizeof(unsigned int),
352 .proc_handler
= proc_dointvec
,
355 .procname
= "sched_walt_cpu_high_irqload",
356 .data
= &sysctl_sched_walt_cpu_high_irqload
,
357 .maxlen
= sizeof(unsigned int),
359 .proc_handler
= proc_dointvec
,
363 .procname
= "sched_sync_hint_enable",
364 .data
= &sysctl_sched_sync_hint_enable
,
365 .maxlen
= sizeof(unsigned int),
367 .proc_handler
= proc_dointvec
,
370 .procname
= "sched_cstate_aware",
371 .data
= &sysctl_sched_cstate_aware
,
372 .maxlen
= sizeof(unsigned int),
374 .proc_handler
= proc_dointvec
,
377 .procname
= "sched_wakeup_granularity_ns",
378 .data
= &sysctl_sched_wakeup_granularity
,
379 .maxlen
= sizeof(unsigned int),
381 .proc_handler
= sched_proc_update_handler
,
382 .extra1
= &min_wakeup_granularity_ns
,
383 .extra2
= &max_wakeup_granularity_ns
,
387 .procname
= "sched_tunable_scaling",
388 .data
= &sysctl_sched_tunable_scaling
,
389 .maxlen
= sizeof(enum sched_tunable_scaling
),
391 .proc_handler
= sched_proc_update_handler
,
392 .extra1
= &min_sched_tunable_scaling
,
393 .extra2
= &max_sched_tunable_scaling
,
396 .procname
= "sched_migration_cost_ns",
397 .data
= &sysctl_sched_migration_cost
,
398 .maxlen
= sizeof(unsigned int),
400 .proc_handler
= proc_dointvec
,
403 .procname
= "sched_nr_migrate",
404 .data
= &sysctl_sched_nr_migrate
,
405 .maxlen
= sizeof(unsigned int),
407 .proc_handler
= proc_dointvec
,
410 .procname
= "sched_time_avg_ms",
411 .data
= &sysctl_sched_time_avg
,
412 .maxlen
= sizeof(unsigned int),
414 .proc_handler
= proc_dointvec_minmax
,
417 #ifdef CONFIG_SCHEDSTATS
419 .procname
= "sched_schedstats",
421 .maxlen
= sizeof(unsigned int),
423 .proc_handler
= sysctl_schedstats
,
427 #endif /* CONFIG_SCHEDSTATS */
428 #endif /* CONFIG_SMP */
429 #ifdef CONFIG_NUMA_BALANCING
431 .procname
= "numa_balancing_scan_delay_ms",
432 .data
= &sysctl_numa_balancing_scan_delay
,
433 .maxlen
= sizeof(unsigned int),
435 .proc_handler
= proc_dointvec
,
438 .procname
= "numa_balancing_scan_period_min_ms",
439 .data
= &sysctl_numa_balancing_scan_period_min
,
440 .maxlen
= sizeof(unsigned int),
442 .proc_handler
= proc_dointvec
,
445 .procname
= "numa_balancing_scan_period_max_ms",
446 .data
= &sysctl_numa_balancing_scan_period_max
,
447 .maxlen
= sizeof(unsigned int),
449 .proc_handler
= proc_dointvec
,
452 .procname
= "numa_balancing_scan_size_mb",
453 .data
= &sysctl_numa_balancing_scan_size
,
454 .maxlen
= sizeof(unsigned int),
456 .proc_handler
= proc_dointvec_minmax
,
460 .procname
= "numa_balancing",
461 .data
= NULL
, /* filled in by handler */
462 .maxlen
= sizeof(unsigned int),
464 .proc_handler
= sysctl_numa_balancing
,
468 #endif /* CONFIG_NUMA_BALANCING */
469 #endif /* CONFIG_SCHED_DEBUG */
471 .procname
= "sched_rt_period_us",
472 .data
= &sysctl_sched_rt_period
,
473 .maxlen
= sizeof(unsigned int),
475 .proc_handler
= sched_rt_handler
,
478 .procname
= "sched_rt_runtime_us",
479 .data
= &sysctl_sched_rt_runtime
,
480 .maxlen
= sizeof(int),
482 .proc_handler
= sched_rt_handler
,
485 .procname
= "sched_rr_timeslice_ms",
486 .data
= &sysctl_sched_rr_timeslice
,
487 .maxlen
= sizeof(int),
489 .proc_handler
= sched_rr_handler
,
491 #ifdef CONFIG_SCHED_AUTOGROUP
493 .procname
= "sched_autogroup_enabled",
494 .data
= &sysctl_sched_autogroup_enabled
,
495 .maxlen
= sizeof(unsigned int),
497 .proc_handler
= proc_dointvec_minmax
,
502 #ifdef CONFIG_CFS_BANDWIDTH
504 .procname
= "sched_cfs_bandwidth_slice_us",
505 .data
= &sysctl_sched_cfs_bandwidth_slice
,
506 .maxlen
= sizeof(unsigned int),
508 .proc_handler
= proc_dointvec_minmax
,
512 #ifdef CONFIG_PROVE_LOCKING
514 .procname
= "prove_locking",
515 .data
= &prove_locking
,
516 .maxlen
= sizeof(int),
518 .proc_handler
= proc_dointvec
,
521 #ifdef CONFIG_LOCK_STAT
523 .procname
= "lock_stat",
525 .maxlen
= sizeof(int),
527 .proc_handler
= proc_dointvec
,
532 .data
= &panic_timeout
,
533 .maxlen
= sizeof(int),
535 .proc_handler
= proc_dointvec
,
537 #ifdef CONFIG_COREDUMP
539 .procname
= "core_uses_pid",
540 .data
= &core_uses_pid
,
541 .maxlen
= sizeof(int),
543 .proc_handler
= proc_dointvec
,
546 .procname
= "core_pattern",
547 .data
= core_pattern
,
548 .maxlen
= CORENAME_MAX_SIZE
,
550 .proc_handler
= proc_dostring_coredump
,
553 .procname
= "core_pipe_limit",
554 .data
= &core_pipe_limit
,
555 .maxlen
= sizeof(unsigned int),
557 .proc_handler
= proc_dointvec
,
560 #ifdef CONFIG_PROC_SYSCTL
562 .procname
= "tainted",
563 .maxlen
= sizeof(long),
565 .proc_handler
= proc_taint
,
568 .procname
= "sysctl_writes_strict",
569 .data
= &sysctl_writes_strict
,
570 .maxlen
= sizeof(int),
572 .proc_handler
= proc_dointvec_minmax
,
577 #ifdef CONFIG_LATENCYTOP
579 .procname
= "latencytop",
580 .data
= &latencytop_enabled
,
581 .maxlen
= sizeof(int),
583 .proc_handler
= sysctl_latencytop
,
586 #ifdef CONFIG_BLK_DEV_INITRD
588 .procname
= "real-root-dev",
589 .data
= &real_root_dev
,
590 .maxlen
= sizeof(int),
592 .proc_handler
= proc_dointvec
,
596 .procname
= "print-fatal-signals",
597 .data
= &print_fatal_signals
,
598 .maxlen
= sizeof(int),
600 .proc_handler
= proc_dointvec
,
604 .procname
= "reboot-cmd",
605 .data
= reboot_command
,
608 .proc_handler
= proc_dostring
,
611 .procname
= "stop-a",
612 .data
= &stop_a_enabled
,
613 .maxlen
= sizeof (int),
615 .proc_handler
= proc_dointvec
,
618 .procname
= "scons-poweroff",
619 .data
= &scons_pwroff
,
620 .maxlen
= sizeof (int),
622 .proc_handler
= proc_dointvec
,
625 #ifdef CONFIG_SPARC64
627 .procname
= "tsb-ratio",
628 .data
= &sysctl_tsb_ratio
,
629 .maxlen
= sizeof (int),
631 .proc_handler
= proc_dointvec
,
636 .procname
= "soft-power",
637 .data
= &pwrsw_enabled
,
638 .maxlen
= sizeof (int),
640 .proc_handler
= proc_dointvec
,
643 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
645 .procname
= "unaligned-trap",
646 .data
= &unaligned_enabled
,
647 .maxlen
= sizeof (int),
649 .proc_handler
= proc_dointvec
,
653 .procname
= "ctrl-alt-del",
655 .maxlen
= sizeof(int),
657 .proc_handler
= proc_dointvec
,
659 #ifdef CONFIG_FUNCTION_TRACER
661 .procname
= "ftrace_enabled",
662 .data
= &ftrace_enabled
,
663 .maxlen
= sizeof(int),
665 .proc_handler
= ftrace_enable_sysctl
,
668 #ifdef CONFIG_STACK_TRACER
670 .procname
= "stack_tracer_enabled",
671 .data
= &stack_tracer_enabled
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= stack_trace_sysctl
,
677 #ifdef CONFIG_TRACING
679 .procname
= "ftrace_dump_on_oops",
680 .data
= &ftrace_dump_on_oops
,
681 .maxlen
= sizeof(int),
683 .proc_handler
= proc_dointvec
,
686 .procname
= "traceoff_on_warning",
687 .data
= &__disable_trace_on_warning
,
688 .maxlen
= sizeof(__disable_trace_on_warning
),
690 .proc_handler
= proc_dointvec
,
693 .procname
= "tracepoint_printk",
694 .data
= &tracepoint_printk
,
695 .maxlen
= sizeof(tracepoint_printk
),
697 .proc_handler
= tracepoint_printk_sysctl
,
700 #ifdef CONFIG_KEXEC_CORE
702 .procname
= "kexec_load_disabled",
703 .data
= &kexec_load_disabled
,
704 .maxlen
= sizeof(int),
706 /* only handle a transition from default "0" to "1" */
707 .proc_handler
= proc_dointvec_minmax
,
712 #ifdef CONFIG_MODULES
714 .procname
= "modprobe",
715 .data
= &modprobe_path
,
716 .maxlen
= KMOD_PATH_LEN
,
718 .proc_handler
= proc_dostring
,
721 .procname
= "modules_disabled",
722 .data
= &modules_disabled
,
723 .maxlen
= sizeof(int),
725 /* only handle a transition from default "0" to "1" */
726 .proc_handler
= proc_dointvec_minmax
,
731 #ifdef CONFIG_UEVENT_HELPER
733 .procname
= "hotplug",
734 .data
= &uevent_helper
,
735 .maxlen
= UEVENT_HELPER_PATH_LEN
,
737 .proc_handler
= proc_dostring
,
740 #ifdef CONFIG_CHR_DEV_SG
742 .procname
= "sg-big-buff",
743 .data
= &sg_big_buff
,
744 .maxlen
= sizeof (int),
746 .proc_handler
= proc_dointvec
,
749 #ifdef CONFIG_BSD_PROCESS_ACCT
753 .maxlen
= 3*sizeof(int),
755 .proc_handler
= proc_dointvec
,
758 #ifdef CONFIG_MAGIC_SYSRQ
761 .data
= &__sysrq_enabled
,
762 .maxlen
= sizeof (int),
764 .proc_handler
= sysrq_sysctl_handler
,
767 #ifdef CONFIG_PROC_SYSCTL
769 .procname
= "cad_pid",
771 .maxlen
= sizeof (int),
773 .proc_handler
= proc_do_cad_pid
,
777 .procname
= "threads-max",
779 .maxlen
= sizeof(int),
781 .proc_handler
= sysctl_max_threads
,
784 .procname
= "random",
786 .child
= random_table
,
789 .procname
= "usermodehelper",
791 .child
= usermodehelper_table
,
794 .procname
= "overflowuid",
795 .data
= &overflowuid
,
796 .maxlen
= sizeof(int),
798 .proc_handler
= proc_dointvec_minmax
,
799 .extra1
= &minolduid
,
800 .extra2
= &maxolduid
,
803 .procname
= "overflowgid",
804 .data
= &overflowgid
,
805 .maxlen
= sizeof(int),
807 .proc_handler
= proc_dointvec_minmax
,
808 .extra1
= &minolduid
,
809 .extra2
= &maxolduid
,
812 #ifdef CONFIG_MATHEMU
814 .procname
= "ieee_emulation_warnings",
815 .data
= &sysctl_ieee_emulation_warnings
,
816 .maxlen
= sizeof(int),
818 .proc_handler
= proc_dointvec
,
822 .procname
= "userprocess_debug",
823 .data
= &show_unhandled_signals
,
824 .maxlen
= sizeof(int),
826 .proc_handler
= proc_dointvec
,
830 .procname
= "pid_max",
832 .maxlen
= sizeof (int),
834 .proc_handler
= proc_dointvec_minmax
,
835 .extra1
= &pid_max_min
,
836 .extra2
= &pid_max_max
,
839 .procname
= "panic_on_oops",
840 .data
= &panic_on_oops
,
841 .maxlen
= sizeof(int),
843 .proc_handler
= proc_dointvec
,
845 #if defined CONFIG_PRINTK
847 .procname
= "printk",
848 .data
= &console_loglevel
,
849 .maxlen
= 4*sizeof(int),
851 .proc_handler
= proc_dointvec
,
854 .procname
= "printk_ratelimit",
855 .data
= &printk_ratelimit_state
.interval
,
856 .maxlen
= sizeof(int),
858 .proc_handler
= proc_dointvec_jiffies
,
861 .procname
= "printk_ratelimit_burst",
862 .data
= &printk_ratelimit_state
.burst
,
863 .maxlen
= sizeof(int),
865 .proc_handler
= proc_dointvec
,
868 .procname
= "printk_delay",
869 .data
= &printk_delay_msec
,
870 .maxlen
= sizeof(int),
872 .proc_handler
= proc_dointvec_minmax
,
874 .extra2
= &ten_thousand
,
877 .procname
= "printk_devkmsg",
878 .data
= devkmsg_log_str
,
879 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
881 .proc_handler
= devkmsg_sysctl_set_loglvl
,
884 .procname
= "dmesg_restrict",
885 .data
= &dmesg_restrict
,
886 .maxlen
= sizeof(int),
888 .proc_handler
= proc_dointvec_minmax_sysadmin
,
893 .procname
= "kptr_restrict",
894 .data
= &kptr_restrict
,
895 .maxlen
= sizeof(int),
897 .proc_handler
= proc_dointvec_minmax_sysadmin
,
903 .procname
= "ngroups_max",
904 .data
= &ngroups_max
,
905 .maxlen
= sizeof (int),
907 .proc_handler
= proc_dointvec
,
910 .procname
= "cap_last_cap",
911 .data
= (void *)&cap_last_cap
,
912 .maxlen
= sizeof(int),
914 .proc_handler
= proc_dointvec
,
916 #if defined(CONFIG_LOCKUP_DETECTOR)
918 .procname
= "watchdog",
919 .data
= &watchdog_user_enabled
,
920 .maxlen
= sizeof(int),
922 .proc_handler
= proc_watchdog
,
927 .procname
= "watchdog_thresh",
928 .data
= &watchdog_thresh
,
929 .maxlen
= sizeof(int),
931 .proc_handler
= proc_watchdog_thresh
,
936 .procname
= "nmi_watchdog",
937 .data
= &nmi_watchdog_user_enabled
,
938 .maxlen
= sizeof(int),
939 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
940 .proc_handler
= proc_nmi_watchdog
,
945 .procname
= "watchdog_cpumask",
946 .data
= &watchdog_cpumask_bits
,
949 .proc_handler
= proc_watchdog_cpumask
,
951 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
953 .procname
= "soft_watchdog",
954 .data
= &soft_watchdog_user_enabled
,
955 .maxlen
= sizeof(int),
957 .proc_handler
= proc_soft_watchdog
,
962 .procname
= "softlockup_panic",
963 .data
= &softlockup_panic
,
964 .maxlen
= sizeof(int),
966 .proc_handler
= proc_dointvec_minmax
,
972 .procname
= "softlockup_all_cpu_backtrace",
973 .data
= &sysctl_softlockup_all_cpu_backtrace
,
974 .maxlen
= sizeof(int),
976 .proc_handler
= proc_dointvec_minmax
,
980 #endif /* CONFIG_SMP */
982 #ifdef CONFIG_HARDLOCKUP_DETECTOR
984 .procname
= "hardlockup_panic",
985 .data
= &hardlockup_panic
,
986 .maxlen
= sizeof(int),
988 .proc_handler
= proc_dointvec_minmax
,
994 .procname
= "hardlockup_all_cpu_backtrace",
995 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
996 .maxlen
= sizeof(int),
998 .proc_handler
= proc_dointvec_minmax
,
1002 #endif /* CONFIG_SMP */
1006 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1008 .procname
= "unknown_nmi_panic",
1009 .data
= &unknown_nmi_panic
,
1010 .maxlen
= sizeof (int),
1012 .proc_handler
= proc_dointvec
,
1015 #if defined(CONFIG_X86)
1017 .procname
= "panic_on_unrecovered_nmi",
1018 .data
= &panic_on_unrecovered_nmi
,
1019 .maxlen
= sizeof(int),
1021 .proc_handler
= proc_dointvec
,
1024 .procname
= "panic_on_io_nmi",
1025 .data
= &panic_on_io_nmi
,
1026 .maxlen
= sizeof(int),
1028 .proc_handler
= proc_dointvec
,
1030 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1032 .procname
= "panic_on_stackoverflow",
1033 .data
= &sysctl_panic_on_stackoverflow
,
1034 .maxlen
= sizeof(int),
1036 .proc_handler
= proc_dointvec
,
1040 .procname
= "bootloader_type",
1041 .data
= &bootloader_type
,
1042 .maxlen
= sizeof (int),
1044 .proc_handler
= proc_dointvec
,
1047 .procname
= "bootloader_version",
1048 .data
= &bootloader_version
,
1049 .maxlen
= sizeof (int),
1051 .proc_handler
= proc_dointvec
,
1054 .procname
= "io_delay_type",
1055 .data
= &io_delay_type
,
1056 .maxlen
= sizeof(int),
1058 .proc_handler
= proc_dointvec
,
1061 #if defined(CONFIG_MMU)
1063 .procname
= "randomize_va_space",
1064 .data
= &randomize_va_space
,
1065 .maxlen
= sizeof(int),
1067 .proc_handler
= proc_dointvec
,
1070 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1072 .procname
= "spin_retry",
1073 .data
= &spin_retry
,
1074 .maxlen
= sizeof (int),
1076 .proc_handler
= proc_dointvec
,
1079 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1081 .procname
= "acpi_video_flags",
1082 .data
= &acpi_realmode_flags
,
1083 .maxlen
= sizeof (unsigned long),
1085 .proc_handler
= proc_doulongvec_minmax
,
1088 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1090 .procname
= "ignore-unaligned-usertrap",
1091 .data
= &no_unaligned_warning
,
1092 .maxlen
= sizeof (int),
1094 .proc_handler
= proc_dointvec
,
1099 .procname
= "unaligned-dump-stack",
1100 .data
= &unaligned_dump_stack
,
1101 .maxlen
= sizeof (int),
1103 .proc_handler
= proc_dointvec
,
1106 #ifdef CONFIG_DETECT_HUNG_TASK
1108 .procname
= "hung_task_panic",
1109 .data
= &sysctl_hung_task_panic
,
1110 .maxlen
= sizeof(int),
1112 .proc_handler
= proc_dointvec_minmax
,
1117 .procname
= "hung_task_check_count",
1118 .data
= &sysctl_hung_task_check_count
,
1119 .maxlen
= sizeof(int),
1121 .proc_handler
= proc_dointvec_minmax
,
1125 .procname
= "hung_task_timeout_secs",
1126 .data
= &sysctl_hung_task_timeout_secs
,
1127 .maxlen
= sizeof(unsigned long),
1129 .proc_handler
= proc_dohung_task_timeout_secs
,
1130 .extra2
= &hung_task_timeout_max
,
1133 .procname
= "hung_task_warnings",
1134 .data
= &sysctl_hung_task_warnings
,
1135 .maxlen
= sizeof(int),
1137 .proc_handler
= proc_dointvec_minmax
,
1141 #ifdef CONFIG_RT_MUTEXES
1143 .procname
= "max_lock_depth",
1144 .data
= &max_lock_depth
,
1145 .maxlen
= sizeof(int),
1147 .proc_handler
= proc_dointvec
,
1151 .procname
= "poweroff_cmd",
1152 .data
= &poweroff_cmd
,
1153 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1155 .proc_handler
= proc_dostring
,
1161 .child
= key_sysctls
,
1164 #ifdef CONFIG_PERF_EVENTS
1166 * User-space scripts rely on the existence of this file
1167 * as a feature check for perf_events being enabled.
1169 * So it's an ABI, do not remove!
1172 .procname
= "perf_event_paranoid",
1173 .data
= &sysctl_perf_event_paranoid
,
1174 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1176 .proc_handler
= proc_dointvec
,
1179 .procname
= "perf_event_mlock_kb",
1180 .data
= &sysctl_perf_event_mlock
,
1181 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1183 .proc_handler
= proc_dointvec
,
1186 .procname
= "perf_event_max_sample_rate",
1187 .data
= &sysctl_perf_event_sample_rate
,
1188 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1190 .proc_handler
= perf_proc_update_handler
,
1194 .procname
= "perf_cpu_time_max_percent",
1195 .data
= &sysctl_perf_cpu_time_max_percent
,
1196 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1198 .proc_handler
= perf_cpu_time_max_percent_handler
,
1200 .extra2
= &one_hundred
,
1203 .procname
= "perf_event_max_stack",
1204 .data
= &sysctl_perf_event_max_stack
,
1205 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1207 .proc_handler
= perf_event_max_stack_handler
,
1209 .extra2
= &six_hundred_forty_kb
,
1212 .procname
= "perf_event_max_contexts_per_stack",
1213 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1214 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1216 .proc_handler
= perf_event_max_stack_handler
,
1218 .extra2
= &one_thousand
,
1221 #ifdef CONFIG_KMEMCHECK
1223 .procname
= "kmemcheck",
1224 .data
= &kmemcheck_enabled
,
1225 .maxlen
= sizeof(int),
1227 .proc_handler
= proc_dointvec
,
1231 .procname
= "panic_on_warn",
1232 .data
= &panic_on_warn
,
1233 .maxlen
= sizeof(int),
1235 .proc_handler
= proc_dointvec_minmax
,
1239 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1241 .procname
= "timer_migration",
1242 .data
= &sysctl_timer_migration
,
1243 .maxlen
= sizeof(unsigned int),
1245 .proc_handler
= timer_migration_handler
,
1250 #ifdef CONFIG_BPF_SYSCALL
1252 .procname
= "unprivileged_bpf_disabled",
1253 .data
= &sysctl_unprivileged_bpf_disabled
,
1254 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1256 /* only handle a transition from default "0" to "1" */
1257 .proc_handler
= proc_dointvec_minmax
,
1262 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1264 .procname
= "panic_on_rcu_stall",
1265 .data
= &sysctl_panic_on_rcu_stall
,
1266 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1268 .proc_handler
= proc_dointvec_minmax
,
1276 static struct ctl_table vm_table
[] = {
1278 .procname
= "overcommit_memory",
1279 .data
= &sysctl_overcommit_memory
,
1280 .maxlen
= sizeof(sysctl_overcommit_memory
),
1282 .proc_handler
= proc_dointvec_minmax
,
1287 .procname
= "panic_on_oom",
1288 .data
= &sysctl_panic_on_oom
,
1289 .maxlen
= sizeof(sysctl_panic_on_oom
),
1291 .proc_handler
= proc_dointvec_minmax
,
1296 .procname
= "oom_kill_allocating_task",
1297 .data
= &sysctl_oom_kill_allocating_task
,
1298 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1300 .proc_handler
= proc_dointvec
,
1303 .procname
= "oom_dump_tasks",
1304 .data
= &sysctl_oom_dump_tasks
,
1305 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1307 .proc_handler
= proc_dointvec
,
1310 .procname
= "overcommit_ratio",
1311 .data
= &sysctl_overcommit_ratio
,
1312 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1314 .proc_handler
= overcommit_ratio_handler
,
1317 .procname
= "overcommit_kbytes",
1318 .data
= &sysctl_overcommit_kbytes
,
1319 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1321 .proc_handler
= overcommit_kbytes_handler
,
1324 .procname
= "page-cluster",
1325 .data
= &page_cluster
,
1326 .maxlen
= sizeof(int),
1328 .proc_handler
= proc_dointvec_minmax
,
1332 .procname
= "dirty_background_ratio",
1333 .data
= &dirty_background_ratio
,
1334 .maxlen
= sizeof(dirty_background_ratio
),
1336 .proc_handler
= dirty_background_ratio_handler
,
1338 .extra2
= &one_hundred
,
1341 .procname
= "dirty_background_bytes",
1342 .data
= &dirty_background_bytes
,
1343 .maxlen
= sizeof(dirty_background_bytes
),
1345 .proc_handler
= dirty_background_bytes_handler
,
1349 .procname
= "dirty_ratio",
1350 .data
= &vm_dirty_ratio
,
1351 .maxlen
= sizeof(vm_dirty_ratio
),
1353 .proc_handler
= dirty_ratio_handler
,
1355 .extra2
= &one_hundred
,
1358 .procname
= "dirty_bytes",
1359 .data
= &vm_dirty_bytes
,
1360 .maxlen
= sizeof(vm_dirty_bytes
),
1362 .proc_handler
= dirty_bytes_handler
,
1363 .extra1
= &dirty_bytes_min
,
1366 .procname
= "dirty_writeback_centisecs",
1367 .data
= &dirty_writeback_interval
,
1368 .maxlen
= sizeof(dirty_writeback_interval
),
1370 .proc_handler
= dirty_writeback_centisecs_handler
,
1373 .procname
= "dirty_expire_centisecs",
1374 .data
= &dirty_expire_interval
,
1375 .maxlen
= sizeof(dirty_expire_interval
),
1377 .proc_handler
= proc_dointvec_minmax
,
1381 .procname
= "dirtytime_expire_seconds",
1382 .data
= &dirtytime_expire_interval
,
1383 .maxlen
= sizeof(dirty_expire_interval
),
1385 .proc_handler
= dirtytime_interval_handler
,
1389 .procname
= "nr_pdflush_threads",
1390 .mode
= 0444 /* read-only */,
1391 .proc_handler
= pdflush_proc_obsolete
,
1394 .procname
= "swappiness",
1395 .data
= &vm_swappiness
,
1396 .maxlen
= sizeof(vm_swappiness
),
1398 .proc_handler
= proc_dointvec_minmax
,
1400 .extra2
= &one_hundred
,
1402 #ifdef CONFIG_HUGETLB_PAGE
1404 .procname
= "nr_hugepages",
1406 .maxlen
= sizeof(unsigned long),
1408 .proc_handler
= hugetlb_sysctl_handler
,
1412 .procname
= "nr_hugepages_mempolicy",
1414 .maxlen
= sizeof(unsigned long),
1416 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1420 .procname
= "hugetlb_shm_group",
1421 .data
= &sysctl_hugetlb_shm_group
,
1422 .maxlen
= sizeof(gid_t
),
1424 .proc_handler
= proc_dointvec
,
1427 .procname
= "hugepages_treat_as_movable",
1428 .data
= &hugepages_treat_as_movable
,
1429 .maxlen
= sizeof(int),
1431 .proc_handler
= proc_dointvec
,
1434 .procname
= "nr_overcommit_hugepages",
1436 .maxlen
= sizeof(unsigned long),
1438 .proc_handler
= hugetlb_overcommit_handler
,
1442 .procname
= "lowmem_reserve_ratio",
1443 .data
= &sysctl_lowmem_reserve_ratio
,
1444 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1446 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1449 .procname
= "drop_caches",
1450 .data
= &sysctl_drop_caches
,
1451 .maxlen
= sizeof(int),
1453 .proc_handler
= drop_caches_sysctl_handler
,
1457 #ifdef CONFIG_COMPACTION
1459 .procname
= "compact_memory",
1460 .data
= &sysctl_compact_memory
,
1461 .maxlen
= sizeof(int),
1463 .proc_handler
= sysctl_compaction_handler
,
1466 .procname
= "extfrag_threshold",
1467 .data
= &sysctl_extfrag_threshold
,
1468 .maxlen
= sizeof(int),
1470 .proc_handler
= sysctl_extfrag_handler
,
1471 .extra1
= &min_extfrag_threshold
,
1472 .extra2
= &max_extfrag_threshold
,
1475 .procname
= "compact_unevictable_allowed",
1476 .data
= &sysctl_compact_unevictable_allowed
,
1477 .maxlen
= sizeof(int),
1479 .proc_handler
= proc_dointvec
,
1484 #endif /* CONFIG_COMPACTION */
1486 .procname
= "min_free_kbytes",
1487 .data
= &min_free_kbytes
,
1488 .maxlen
= sizeof(min_free_kbytes
),
1490 .proc_handler
= min_free_kbytes_sysctl_handler
,
1494 .procname
= "watermark_scale_factor",
1495 .data
= &watermark_scale_factor
,
1496 .maxlen
= sizeof(watermark_scale_factor
),
1498 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1500 .extra2
= &one_thousand
,
1503 .procname
= "percpu_pagelist_fraction",
1504 .data
= &percpu_pagelist_fraction
,
1505 .maxlen
= sizeof(percpu_pagelist_fraction
),
1507 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1512 .procname
= "max_map_count",
1513 .data
= &sysctl_max_map_count
,
1514 .maxlen
= sizeof(sysctl_max_map_count
),
1516 .proc_handler
= proc_dointvec_minmax
,
1521 .procname
= "nr_trim_pages",
1522 .data
= &sysctl_nr_trim_pages
,
1523 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1525 .proc_handler
= proc_dointvec_minmax
,
1530 .procname
= "laptop_mode",
1531 .data
= &laptop_mode
,
1532 .maxlen
= sizeof(laptop_mode
),
1534 .proc_handler
= proc_dointvec_jiffies
,
1537 .procname
= "block_dump",
1538 .data
= &block_dump
,
1539 .maxlen
= sizeof(block_dump
),
1541 .proc_handler
= proc_dointvec
,
1545 .procname
= "vfs_cache_pressure",
1546 .data
= &sysctl_vfs_cache_pressure
,
1547 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1549 .proc_handler
= proc_dointvec
,
1552 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1554 .procname
= "legacy_va_layout",
1555 .data
= &sysctl_legacy_va_layout
,
1556 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1558 .proc_handler
= proc_dointvec
,
1564 .procname
= "zone_reclaim_mode",
1565 .data
= &node_reclaim_mode
,
1566 .maxlen
= sizeof(node_reclaim_mode
),
1568 .proc_handler
= proc_dointvec
,
1572 .procname
= "min_unmapped_ratio",
1573 .data
= &sysctl_min_unmapped_ratio
,
1574 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1576 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1578 .extra2
= &one_hundred
,
1581 .procname
= "min_slab_ratio",
1582 .data
= &sysctl_min_slab_ratio
,
1583 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1585 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1587 .extra2
= &one_hundred
,
1592 .procname
= "stat_interval",
1593 .data
= &sysctl_stat_interval
,
1594 .maxlen
= sizeof(sysctl_stat_interval
),
1596 .proc_handler
= proc_dointvec_jiffies
,
1599 .procname
= "stat_refresh",
1603 .proc_handler
= vmstat_refresh
,
1608 .procname
= "mmap_min_addr",
1609 .data
= &dac_mmap_min_addr
,
1610 .maxlen
= sizeof(unsigned long),
1612 .proc_handler
= mmap_min_addr_handler
,
1617 .procname
= "numa_zonelist_order",
1618 .data
= &numa_zonelist_order
,
1619 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1621 .proc_handler
= numa_zonelist_order_handler
,
1624 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1625 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1627 .procname
= "vdso_enabled",
1628 #ifdef CONFIG_X86_32
1629 .data
= &vdso32_enabled
,
1630 .maxlen
= sizeof(vdso32_enabled
),
1632 .data
= &vdso_enabled
,
1633 .maxlen
= sizeof(vdso_enabled
),
1636 .proc_handler
= proc_dointvec
,
1640 #ifdef CONFIG_HIGHMEM
1642 .procname
= "highmem_is_dirtyable",
1643 .data
= &vm_highmem_is_dirtyable
,
1644 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1646 .proc_handler
= proc_dointvec_minmax
,
1651 #ifdef CONFIG_MEMORY_FAILURE
1653 .procname
= "memory_failure_early_kill",
1654 .data
= &sysctl_memory_failure_early_kill
,
1655 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1657 .proc_handler
= proc_dointvec_minmax
,
1662 .procname
= "memory_failure_recovery",
1663 .data
= &sysctl_memory_failure_recovery
,
1664 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1666 .proc_handler
= proc_dointvec_minmax
,
1672 .procname
= "user_reserve_kbytes",
1673 .data
= &sysctl_user_reserve_kbytes
,
1674 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1676 .proc_handler
= proc_doulongvec_minmax
,
1679 .procname
= "admin_reserve_kbytes",
1680 .data
= &sysctl_admin_reserve_kbytes
,
1681 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1683 .proc_handler
= proc_doulongvec_minmax
,
1685 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1687 .procname
= "mmap_rnd_bits",
1688 .data
= &mmap_rnd_bits
,
1689 .maxlen
= sizeof(mmap_rnd_bits
),
1691 .proc_handler
= proc_dointvec_minmax
,
1692 .extra1
= (void *)&mmap_rnd_bits_min
,
1693 .extra2
= (void *)&mmap_rnd_bits_max
,
1696 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1698 .procname
= "mmap_rnd_compat_bits",
1699 .data
= &mmap_rnd_compat_bits
,
1700 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1702 .proc_handler
= proc_dointvec_minmax
,
1703 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1704 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1710 static struct ctl_table fs_table
[] = {
1712 .procname
= "inode-nr",
1713 .data
= &inodes_stat
,
1714 .maxlen
= 2*sizeof(long),
1716 .proc_handler
= proc_nr_inodes
,
1719 .procname
= "inode-state",
1720 .data
= &inodes_stat
,
1721 .maxlen
= 7*sizeof(long),
1723 .proc_handler
= proc_nr_inodes
,
1726 .procname
= "file-nr",
1727 .data
= &files_stat
,
1728 .maxlen
= sizeof(files_stat
),
1730 .proc_handler
= proc_nr_files
,
1733 .procname
= "file-max",
1734 .data
= &files_stat
.max_files
,
1735 .maxlen
= sizeof(files_stat
.max_files
),
1737 .proc_handler
= proc_doulongvec_minmax
,
1740 .procname
= "nr_open",
1741 .data
= &sysctl_nr_open
,
1742 .maxlen
= sizeof(unsigned int),
1744 .proc_handler
= proc_dointvec_minmax
,
1745 .extra1
= &sysctl_nr_open_min
,
1746 .extra2
= &sysctl_nr_open_max
,
1749 .procname
= "dentry-state",
1750 .data
= &dentry_stat
,
1751 .maxlen
= 6*sizeof(long),
1753 .proc_handler
= proc_nr_dentry
,
1756 .procname
= "overflowuid",
1757 .data
= &fs_overflowuid
,
1758 .maxlen
= sizeof(int),
1760 .proc_handler
= proc_dointvec_minmax
,
1761 .extra1
= &minolduid
,
1762 .extra2
= &maxolduid
,
1765 .procname
= "overflowgid",
1766 .data
= &fs_overflowgid
,
1767 .maxlen
= sizeof(int),
1769 .proc_handler
= proc_dointvec_minmax
,
1770 .extra1
= &minolduid
,
1771 .extra2
= &maxolduid
,
1773 #ifdef CONFIG_FILE_LOCKING
1775 .procname
= "leases-enable",
1776 .data
= &leases_enable
,
1777 .maxlen
= sizeof(int),
1779 .proc_handler
= proc_dointvec
,
1782 #ifdef CONFIG_DNOTIFY
1784 .procname
= "dir-notify-enable",
1785 .data
= &dir_notify_enable
,
1786 .maxlen
= sizeof(int),
1788 .proc_handler
= proc_dointvec
,
1792 #ifdef CONFIG_FILE_LOCKING
1794 .procname
= "lease-break-time",
1795 .data
= &lease_break_time
,
1796 .maxlen
= sizeof(int),
1798 .proc_handler
= proc_dointvec
,
1803 .procname
= "aio-nr",
1805 .maxlen
= sizeof(aio_nr
),
1807 .proc_handler
= proc_doulongvec_minmax
,
1810 .procname
= "aio-max-nr",
1811 .data
= &aio_max_nr
,
1812 .maxlen
= sizeof(aio_max_nr
),
1814 .proc_handler
= proc_doulongvec_minmax
,
1816 #endif /* CONFIG_AIO */
1817 #ifdef CONFIG_INOTIFY_USER
1819 .procname
= "inotify",
1821 .child
= inotify_table
,
1826 .procname
= "epoll",
1828 .child
= epoll_table
,
1833 .procname
= "protected_symlinks",
1834 .data
= &sysctl_protected_symlinks
,
1835 .maxlen
= sizeof(int),
1837 .proc_handler
= proc_dointvec_minmax
,
1842 .procname
= "protected_hardlinks",
1843 .data
= &sysctl_protected_hardlinks
,
1844 .maxlen
= sizeof(int),
1846 .proc_handler
= proc_dointvec_minmax
,
1851 .procname
= "suid_dumpable",
1852 .data
= &suid_dumpable
,
1853 .maxlen
= sizeof(int),
1855 .proc_handler
= proc_dointvec_minmax_coredump
,
1859 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1861 .procname
= "binfmt_misc",
1863 .child
= sysctl_mount_point
,
1867 .procname
= "pipe-max-size",
1868 .data
= &pipe_max_size
,
1869 .maxlen
= sizeof(pipe_max_size
),
1871 .proc_handler
= &pipe_proc_fn
,
1872 .extra1
= &pipe_min_size
,
1875 .procname
= "pipe-user-pages-hard",
1876 .data
= &pipe_user_pages_hard
,
1877 .maxlen
= sizeof(pipe_user_pages_hard
),
1879 .proc_handler
= proc_doulongvec_minmax
,
1882 .procname
= "pipe-user-pages-soft",
1883 .data
= &pipe_user_pages_soft
,
1884 .maxlen
= sizeof(pipe_user_pages_soft
),
1886 .proc_handler
= proc_doulongvec_minmax
,
1889 .procname
= "mount-max",
1890 .data
= &sysctl_mount_max
,
1891 .maxlen
= sizeof(unsigned int),
1893 .proc_handler
= proc_dointvec_minmax
,
1899 static struct ctl_table debug_table
[] = {
1900 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1902 .procname
= "exception-trace",
1903 .data
= &show_unhandled_signals
,
1904 .maxlen
= sizeof(int),
1906 .proc_handler
= proc_dointvec
1909 #if defined(CONFIG_OPTPROBES)
1911 .procname
= "kprobes-optimization",
1912 .data
= &sysctl_kprobes_optimization
,
1913 .maxlen
= sizeof(int),
1915 .proc_handler
= proc_kprobes_optimization_handler
,
1923 static struct ctl_table dev_table
[] = {
1927 int __init
sysctl_init(void)
1929 struct ctl_table_header
*hdr
;
1931 hdr
= register_sysctl_table(sysctl_base_table
);
1932 kmemleak_not_leak(hdr
);
1936 #endif /* CONFIG_SYSCTL */
1942 #ifdef CONFIG_PROC_SYSCTL
1944 static int _proc_do_string(char *data
, int maxlen
, int write
,
1945 char __user
*buffer
,
1946 size_t *lenp
, loff_t
*ppos
)
1952 if (!data
|| !maxlen
|| !*lenp
) {
1958 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1959 /* Only continue writes not past the end of buffer. */
1961 if (len
> maxlen
- 1)
1968 /* Start writing from beginning of buffer. */
1974 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1975 if (get_user(c
, p
++))
1977 if (c
== 0 || c
== '\n')
1998 if (copy_to_user(buffer
, data
, len
))
2001 if (put_user('\n', buffer
+ len
))
2011 static void warn_sysctl_write(struct ctl_table
*table
)
2013 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2014 "This will not be supported in the future. To silence this\n"
2015 "warning, set kernel.sysctl_writes_strict = -1\n",
2016 current
->comm
, table
->procname
);
2020 * proc_first_pos_non_zero_ignore - check if firs position is allowed
2021 * @ppos: file position
2022 * @table: the sysctl table
2024 * Returns true if the first position is non-zero and the sysctl_writes_strict
2025 * mode indicates this is not allowed for numeric input types. String proc
2026 * hadlers can ignore the return value.
2028 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2029 struct ctl_table
*table
)
2034 switch (sysctl_writes_strict
) {
2035 case SYSCTL_WRITES_STRICT
:
2037 case SYSCTL_WRITES_WARN
:
2038 warn_sysctl_write(table
);
2046 * proc_dostring - read a string sysctl
2047 * @table: the sysctl table
2048 * @write: %TRUE if this is a write to the sysctl file
2049 * @buffer: the user buffer
2050 * @lenp: the size of the user buffer
2051 * @ppos: file position
2053 * Reads/writes a string from/to the user buffer. If the kernel
2054 * buffer provided is not large enough to hold the string, the
2055 * string is truncated. The copied string is %NULL-terminated.
2056 * If the string is being read by the user process, it is copied
2057 * and a newline '\n' is added. It is truncated if the buffer is
2060 * Returns 0 on success.
2062 int proc_dostring(struct ctl_table
*table
, int write
,
2063 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2066 proc_first_pos_non_zero_ignore(ppos
, table
);
2068 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2069 (char __user
*)buffer
, lenp
, ppos
);
2072 static size_t proc_skip_spaces(char **buf
)
2075 char *tmp
= skip_spaces(*buf
);
2081 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2091 #define TMPBUFLEN 22
2093 * proc_get_long - reads an ASCII formatted integer from a user buffer
2095 * @buf: a kernel buffer
2096 * @size: size of the kernel buffer
2097 * @val: this is where the number will be stored
2098 * @neg: set to %TRUE if number is negative
2099 * @perm_tr: a vector which contains the allowed trailers
2100 * @perm_tr_len: size of the perm_tr vector
2101 * @tr: pointer to store the trailer character
2103 * In case of success %0 is returned and @buf and @size are updated with
2104 * the amount of bytes read. If @tr is non-NULL and a trailing
2105 * character exists (size is non-zero after returning from this
2106 * function), @tr is updated with the trailing character.
2108 static int proc_get_long(char **buf
, size_t *size
,
2109 unsigned long *val
, bool *neg
,
2110 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2113 char *p
, tmp
[TMPBUFLEN
];
2119 if (len
> TMPBUFLEN
- 1)
2120 len
= TMPBUFLEN
- 1;
2122 memcpy(tmp
, *buf
, len
);
2126 if (*p
== '-' && *size
> 1) {
2134 *val
= simple_strtoul(p
, &p
, 0);
2138 /* We don't know if the next char is whitespace thus we may accept
2139 * invalid integers (e.g. 1234...a) or two integers instead of one
2140 * (e.g. 123...1). So lets not allow such large numbers. */
2141 if (len
== TMPBUFLEN
- 1)
2144 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2147 if (tr
&& (len
< *size
))
2157 * proc_put_long - converts an integer to a decimal ASCII formatted string
2159 * @buf: the user buffer
2160 * @size: the size of the user buffer
2161 * @val: the integer to be converted
2162 * @neg: sign of the number, %TRUE for negative
2164 * In case of success %0 is returned and @buf and @size are updated with
2165 * the amount of bytes written.
2167 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2171 char tmp
[TMPBUFLEN
], *p
= tmp
;
2173 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2177 if (copy_to_user(*buf
, tmp
, len
))
2185 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2188 char __user
**buffer
= (char __user
**)buf
;
2189 if (put_user(c
, *buffer
))
2191 (*size
)--, (*buffer
)++;
2197 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2199 int write
, void *data
)
2203 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2207 if (*lvalp
> (unsigned long) INT_MAX
)
2215 *lvalp
= -(unsigned long)val
;
2218 *lvalp
= (unsigned long)val
;
2224 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2226 int write
, void *data
)
2229 if (*lvalp
> UINT_MAX
)
2233 unsigned int val
= *valp
;
2234 *lvalp
= (unsigned long)val
;
2239 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2241 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2242 int write
, void __user
*buffer
,
2243 size_t *lenp
, loff_t
*ppos
,
2244 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2245 int write
, void *data
),
2248 int *i
, vleft
, first
= 1, err
= 0;
2250 char *kbuf
= NULL
, *p
;
2252 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2257 i
= (int *) tbl_data
;
2258 vleft
= table
->maxlen
/ sizeof(*i
);
2262 conv
= do_proc_dointvec_conv
;
2265 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2268 if (left
> PAGE_SIZE
- 1)
2269 left
= PAGE_SIZE
- 1;
2270 p
= kbuf
= memdup_user_nul(buffer
, left
);
2272 return PTR_ERR(kbuf
);
2275 for (; left
&& vleft
--; i
++, first
=0) {
2280 left
-= proc_skip_spaces(&p
);
2284 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2286 sizeof(proc_wspace_sep
), NULL
);
2289 if (conv(&neg
, &lval
, i
, 1, data
)) {
2294 if (conv(&neg
, &lval
, i
, 0, data
)) {
2299 err
= proc_put_char(&buffer
, &left
, '\t');
2302 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2308 if (!write
&& !first
&& left
&& !err
)
2309 err
= proc_put_char(&buffer
, &left
, '\n');
2310 if (write
&& !err
&& left
)
2311 left
-= proc_skip_spaces(&p
);
2315 return err
? : -EINVAL
;
2323 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2324 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2325 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2326 int write
, void *data
),
2329 return __do_proc_dointvec(table
->data
, table
, write
,
2330 buffer
, lenp
, ppos
, conv
, data
);
2333 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2334 struct ctl_table
*table
,
2335 void __user
*buffer
,
2336 size_t *lenp
, loff_t
*ppos
,
2337 int (*conv
)(unsigned long *lvalp
,
2339 int write
, void *data
),
2346 char *kbuf
= NULL
, *p
;
2350 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2353 if (left
> PAGE_SIZE
- 1)
2354 left
= PAGE_SIZE
- 1;
2356 p
= kbuf
= memdup_user_nul(buffer
, left
);
2360 left
-= proc_skip_spaces(&p
);
2366 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2368 sizeof(proc_wspace_sep
), NULL
);
2374 if (conv(&lval
, tbl_data
, 1, data
)) {
2380 left
-= proc_skip_spaces(&p
);
2389 /* This is in keeping with old __do_proc_dointvec() */
2395 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2396 size_t *lenp
, loff_t
*ppos
,
2397 int (*conv
)(unsigned long *lvalp
,
2399 int write
, void *data
),
2408 if (conv(&lval
, tbl_data
, 0, data
)) {
2413 err
= proc_put_long(&buffer
, &left
, lval
, false);
2417 err
= proc_put_char(&buffer
, &left
, '\n');
2426 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2427 int write
, void __user
*buffer
,
2428 size_t *lenp
, loff_t
*ppos
,
2429 int (*conv
)(unsigned long *lvalp
,
2431 int write
, void *data
),
2434 unsigned int *i
, vleft
;
2436 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2441 i
= (unsigned int *) tbl_data
;
2442 vleft
= table
->maxlen
/ sizeof(*i
);
2445 * Arrays are not supported, keep this simple. *Do not* add
2454 conv
= do_proc_douintvec_conv
;
2457 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2459 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2462 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2463 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2464 int (*conv
)(unsigned long *lvalp
,
2466 int write
, void *data
),
2469 return __do_proc_douintvec(table
->data
, table
, write
,
2470 buffer
, lenp
, ppos
, conv
, data
);
2474 * proc_dointvec - read a vector of integers
2475 * @table: the sysctl table
2476 * @write: %TRUE if this is a write to the sysctl file
2477 * @buffer: the user buffer
2478 * @lenp: the size of the user buffer
2479 * @ppos: file position
2481 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2482 * values from/to the user buffer, treated as an ASCII string.
2484 * Returns 0 on success.
2486 int proc_dointvec(struct ctl_table
*table
, int write
,
2487 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2489 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2493 * proc_douintvec - read a vector of unsigned integers
2494 * @table: the sysctl table
2495 * @write: %TRUE if this is a write to the sysctl file
2496 * @buffer: the user buffer
2497 * @lenp: the size of the user buffer
2498 * @ppos: file position
2500 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2501 * values from/to the user buffer, treated as an ASCII string.
2503 * Returns 0 on success.
2505 int proc_douintvec(struct ctl_table
*table
, int write
,
2506 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2508 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2509 do_proc_douintvec_conv
, NULL
);
2513 * Taint values can only be increased
2514 * This means we can safely use a temporary.
2516 static int proc_taint(struct ctl_table
*table
, int write
,
2517 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2520 unsigned long tmptaint
= get_taint();
2523 if (write
&& !capable(CAP_SYS_ADMIN
))
2528 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2534 * Poor man's atomic or. Not worth adding a primitive
2535 * to everyone's atomic.h for this
2538 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2539 if ((tmptaint
>> i
) & 1)
2540 add_taint(i
, LOCKDEP_STILL_OK
);
2547 #ifdef CONFIG_PRINTK
2548 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2549 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2551 if (write
&& !capable(CAP_SYS_ADMIN
))
2554 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2558 struct do_proc_dointvec_minmax_conv_param
{
2563 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2565 int write
, void *data
)
2567 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2569 int val
= *negp
? -*lvalp
: *lvalp
;
2570 if ((param
->min
&& *param
->min
> val
) ||
2571 (param
->max
&& *param
->max
< val
))
2578 *lvalp
= -(unsigned long)val
;
2581 *lvalp
= (unsigned long)val
;
2588 * proc_dointvec_minmax - read a vector of integers with min/max values
2589 * @table: the sysctl table
2590 * @write: %TRUE if this is a write to the sysctl file
2591 * @buffer: the user buffer
2592 * @lenp: the size of the user buffer
2593 * @ppos: file position
2595 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2596 * values from/to the user buffer, treated as an ASCII string.
2598 * This routine will ensure the values are within the range specified by
2599 * table->extra1 (min) and table->extra2 (max).
2601 * Returns 0 on success.
2603 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2604 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2606 struct do_proc_dointvec_minmax_conv_param param
= {
2607 .min
= (int *) table
->extra1
,
2608 .max
= (int *) table
->extra2
,
2610 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2611 do_proc_dointvec_minmax_conv
, ¶m
);
2614 struct do_proc_douintvec_minmax_conv_param
{
2619 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2621 int write
, void *data
)
2623 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2626 unsigned int val
= *lvalp
;
2628 if ((param
->min
&& *param
->min
> val
) ||
2629 (param
->max
&& *param
->max
< val
))
2632 if (*lvalp
> UINT_MAX
)
2636 unsigned int val
= *valp
;
2637 *lvalp
= (unsigned long) val
;
2644 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2645 * @table: the sysctl table
2646 * @write: %TRUE if this is a write to the sysctl file
2647 * @buffer: the user buffer
2648 * @lenp: the size of the user buffer
2649 * @ppos: file position
2651 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2652 * values from/to the user buffer, treated as an ASCII string. Negative
2653 * strings are not allowed.
2655 * This routine will ensure the values are within the range specified by
2656 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2657 * check for UINT_MAX to avoid having to support wrap around uses from
2660 * Returns 0 on success.
2662 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2663 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2665 struct do_proc_douintvec_minmax_conv_param param
= {
2666 .min
= (unsigned int *) table
->extra1
,
2667 .max
= (unsigned int *) table
->extra2
,
2669 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2670 do_proc_douintvec_minmax_conv
, ¶m
);
2673 static void validate_coredump_safety(void)
2675 #ifdef CONFIG_COREDUMP
2676 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2677 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2679 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2680 "Pipe handler or fully qualified core dump path required.\n"
2681 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2687 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2688 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2690 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2692 validate_coredump_safety();
2696 #ifdef CONFIG_COREDUMP
2697 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2698 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2700 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2702 validate_coredump_safety();
2707 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2708 void __user
*buffer
,
2709 size_t *lenp
, loff_t
*ppos
,
2710 unsigned long convmul
,
2711 unsigned long convdiv
)
2713 unsigned long *i
, *min
, *max
;
2714 int vleft
, first
= 1, err
= 0;
2716 char *kbuf
= NULL
, *p
;
2718 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2723 i
= (unsigned long *) data
;
2724 min
= (unsigned long *) table
->extra1
;
2725 max
= (unsigned long *) table
->extra2
;
2726 vleft
= table
->maxlen
/ sizeof(unsigned long);
2730 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2733 if (left
> PAGE_SIZE
- 1)
2734 left
= PAGE_SIZE
- 1;
2735 p
= kbuf
= memdup_user_nul(buffer
, left
);
2737 return PTR_ERR(kbuf
);
2740 for (; left
&& vleft
--; i
++, first
= 0) {
2746 left
-= proc_skip_spaces(&p
);
2748 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2750 sizeof(proc_wspace_sep
), NULL
);
2755 val
= convmul
* val
/ convdiv
;
2756 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2760 val
= convdiv
* (*i
) / convmul
;
2762 err
= proc_put_char(&buffer
, &left
, '\t');
2766 err
= proc_put_long(&buffer
, &left
, val
, false);
2772 if (!write
&& !first
&& left
&& !err
)
2773 err
= proc_put_char(&buffer
, &left
, '\n');
2775 left
-= proc_skip_spaces(&p
);
2779 return err
? : -EINVAL
;
2787 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2788 void __user
*buffer
,
2789 size_t *lenp
, loff_t
*ppos
,
2790 unsigned long convmul
,
2791 unsigned long convdiv
)
2793 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2794 buffer
, lenp
, ppos
, convmul
, convdiv
);
2798 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2799 * @table: the sysctl table
2800 * @write: %TRUE if this is a write to the sysctl file
2801 * @buffer: the user buffer
2802 * @lenp: the size of the user buffer
2803 * @ppos: file position
2805 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2806 * values from/to the user buffer, treated as an ASCII string.
2808 * This routine will ensure the values are within the range specified by
2809 * table->extra1 (min) and table->extra2 (max).
2811 * Returns 0 on success.
2813 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2814 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2816 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2820 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2821 * @table: the sysctl table
2822 * @write: %TRUE if this is a write to the sysctl file
2823 * @buffer: the user buffer
2824 * @lenp: the size of the user buffer
2825 * @ppos: file position
2827 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2828 * values from/to the user buffer, treated as an ASCII string. The values
2829 * are treated as milliseconds, and converted to jiffies when they are stored.
2831 * This routine will ensure the values are within the range specified by
2832 * table->extra1 (min) and table->extra2 (max).
2834 * Returns 0 on success.
2836 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2837 void __user
*buffer
,
2838 size_t *lenp
, loff_t
*ppos
)
2840 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2841 lenp
, ppos
, HZ
, 1000l);
2845 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2847 int write
, void *data
)
2850 if (*lvalp
> INT_MAX
/ HZ
)
2852 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2858 lval
= -(unsigned long)val
;
2861 lval
= (unsigned long)val
;
2868 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2870 int write
, void *data
)
2873 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2875 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2881 lval
= -(unsigned long)val
;
2884 lval
= (unsigned long)val
;
2886 *lvalp
= jiffies_to_clock_t(lval
);
2891 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2893 int write
, void *data
)
2896 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2906 lval
= -(unsigned long)val
;
2909 lval
= (unsigned long)val
;
2911 *lvalp
= jiffies_to_msecs(lval
);
2917 * proc_dointvec_jiffies - read a vector of integers as seconds
2918 * @table: the sysctl table
2919 * @write: %TRUE if this is a write to the sysctl file
2920 * @buffer: the user buffer
2921 * @lenp: the size of the user buffer
2922 * @ppos: file position
2924 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2925 * values from/to the user buffer, treated as an ASCII string.
2926 * The values read are assumed to be in seconds, and are converted into
2929 * Returns 0 on success.
2931 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2932 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2934 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2935 do_proc_dointvec_jiffies_conv
,NULL
);
2939 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2940 * @table: the sysctl table
2941 * @write: %TRUE if this is a write to the sysctl file
2942 * @buffer: the user buffer
2943 * @lenp: the size of the user buffer
2944 * @ppos: pointer to the file position
2946 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2947 * values from/to the user buffer, treated as an ASCII string.
2948 * The values read are assumed to be in 1/USER_HZ seconds, and
2949 * are converted into jiffies.
2951 * Returns 0 on success.
2953 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2954 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2956 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2957 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2961 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2962 * @table: the sysctl table
2963 * @write: %TRUE if this is a write to the sysctl file
2964 * @buffer: the user buffer
2965 * @lenp: the size of the user buffer
2966 * @ppos: file position
2967 * @ppos: the current position in the file
2969 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2970 * values from/to the user buffer, treated as an ASCII string.
2971 * The values read are assumed to be in 1/1000 seconds, and
2972 * are converted into jiffies.
2974 * Returns 0 on success.
2976 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2977 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2979 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2980 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2983 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2984 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2986 struct pid
*new_pid
;
2990 tmp
= pid_vnr(cad_pid
);
2992 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2993 lenp
, ppos
, NULL
, NULL
);
2997 new_pid
= find_get_pid(tmp
);
3001 put_pid(xchg(&cad_pid
, new_pid
));
3006 * proc_do_large_bitmap - read/write from/to a large bitmap
3007 * @table: the sysctl table
3008 * @write: %TRUE if this is a write to the sysctl file
3009 * @buffer: the user buffer
3010 * @lenp: the size of the user buffer
3011 * @ppos: file position
3013 * The bitmap is stored at table->data and the bitmap length (in bits)
3016 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3017 * large bitmaps may be represented in a compact manner. Writing into
3018 * the file will clear the bitmap then update it with the given input.
3020 * Returns 0 on success.
3022 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3023 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3027 size_t left
= *lenp
;
3028 unsigned long bitmap_len
= table
->maxlen
;
3029 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3030 unsigned long *tmp_bitmap
= NULL
;
3031 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3033 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3041 if (left
> PAGE_SIZE
- 1)
3042 left
= PAGE_SIZE
- 1;
3044 p
= kbuf
= memdup_user_nul(buffer
, left
);
3046 return PTR_ERR(kbuf
);
3048 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
3054 proc_skip_char(&p
, &left
, '\n');
3055 while (!err
&& left
) {
3056 unsigned long val_a
, val_b
;
3059 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3063 if (val_a
>= bitmap_len
|| neg
) {
3075 err
= proc_get_long(&p
, &left
, &val_b
,
3076 &neg
, tr_b
, sizeof(tr_b
),
3080 if (val_b
>= bitmap_len
|| neg
||
3091 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3093 proc_skip_char(&p
, &left
, '\n');
3097 unsigned long bit_a
, bit_b
= 0;
3100 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3101 if (bit_a
>= bitmap_len
)
3103 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3107 err
= proc_put_char(&buffer
, &left
, ',');
3111 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3114 if (bit_a
!= bit_b
) {
3115 err
= proc_put_char(&buffer
, &left
, '-');
3118 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3126 err
= proc_put_char(&buffer
, &left
, '\n');
3132 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3134 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3146 #else /* CONFIG_PROC_SYSCTL */
3148 int proc_dostring(struct ctl_table
*table
, int write
,
3149 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3154 int proc_dointvec(struct ctl_table
*table
, int write
,
3155 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3160 int proc_douintvec(struct ctl_table
*table
, int write
,
3161 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3166 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3167 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3172 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3173 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3178 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3179 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3184 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3185 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3190 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3191 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3196 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3197 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3202 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3203 void __user
*buffer
,
3204 size_t *lenp
, loff_t
*ppos
)
3210 #endif /* CONFIG_PROC_SYSCTL */
3213 * No sense putting this after each symbol definition, twice,
3214 * exception granted :-)
3216 EXPORT_SYMBOL(proc_dointvec
);
3217 EXPORT_SYMBOL(proc_douintvec
);
3218 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3219 EXPORT_SYMBOL(proc_dointvec_minmax
);
3220 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3221 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3222 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3223 EXPORT_SYMBOL(proc_dostring
);
3224 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3225 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);