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/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/sched/coredump.h>
66 #include <linux/kexec.h>
67 #include <linux/bpf.h>
68 #include <linux/mount.h>
70 #include <linux/uaccess.h>
71 #include <asm/processor.h>
75 #include <asm/stacktrace.h>
79 #include <asm/setup.h>
81 #ifdef CONFIG_BSD_PROCESS_ACCT
82 #include <linux/acct.h>
84 #ifdef CONFIG_RT_MUTEXES
85 #include <linux/rtmutex.h>
87 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
88 #include <linux/lockdep.h>
90 #ifdef CONFIG_CHR_DEV_SG
94 #ifdef CONFIG_LOCKUP_DETECTOR
95 #include <linux/nmi.h>
98 #if defined(CONFIG_SYSCTL)
100 /* External variables not in a header file. */
101 extern int suid_dumpable
;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid
;
104 extern char core_pattern
[];
105 extern unsigned int core_pipe_limit
;
108 extern int extra_free_kbytes
;
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
,
1222 .procname
= "panic_on_warn",
1223 .data
= &panic_on_warn
,
1224 .maxlen
= sizeof(int),
1226 .proc_handler
= proc_dointvec_minmax
,
1230 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1232 .procname
= "timer_migration",
1233 .data
= &sysctl_timer_migration
,
1234 .maxlen
= sizeof(unsigned int),
1236 .proc_handler
= timer_migration_handler
,
1241 #ifdef CONFIG_BPF_SYSCALL
1243 .procname
= "unprivileged_bpf_disabled",
1244 .data
= &sysctl_unprivileged_bpf_disabled
,
1245 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1247 /* only handle a transition from default "0" to "1" */
1248 .proc_handler
= proc_dointvec_minmax
,
1253 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1255 .procname
= "panic_on_rcu_stall",
1256 .data
= &sysctl_panic_on_rcu_stall
,
1257 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1259 .proc_handler
= proc_dointvec_minmax
,
1267 static struct ctl_table vm_table
[] = {
1269 .procname
= "overcommit_memory",
1270 .data
= &sysctl_overcommit_memory
,
1271 .maxlen
= sizeof(sysctl_overcommit_memory
),
1273 .proc_handler
= proc_dointvec_minmax
,
1278 .procname
= "panic_on_oom",
1279 .data
= &sysctl_panic_on_oom
,
1280 .maxlen
= sizeof(sysctl_panic_on_oom
),
1282 .proc_handler
= proc_dointvec_minmax
,
1287 .procname
= "oom_kill_allocating_task",
1288 .data
= &sysctl_oom_kill_allocating_task
,
1289 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1291 .proc_handler
= proc_dointvec
,
1294 .procname
= "oom_dump_tasks",
1295 .data
= &sysctl_oom_dump_tasks
,
1296 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1298 .proc_handler
= proc_dointvec
,
1301 .procname
= "overcommit_ratio",
1302 .data
= &sysctl_overcommit_ratio
,
1303 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1305 .proc_handler
= overcommit_ratio_handler
,
1308 .procname
= "overcommit_kbytes",
1309 .data
= &sysctl_overcommit_kbytes
,
1310 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1312 .proc_handler
= overcommit_kbytes_handler
,
1315 .procname
= "page-cluster",
1316 .data
= &page_cluster
,
1317 .maxlen
= sizeof(int),
1319 .proc_handler
= proc_dointvec_minmax
,
1323 .procname
= "dirty_background_ratio",
1324 .data
= &dirty_background_ratio
,
1325 .maxlen
= sizeof(dirty_background_ratio
),
1327 .proc_handler
= dirty_background_ratio_handler
,
1329 .extra2
= &one_hundred
,
1332 .procname
= "dirty_background_bytes",
1333 .data
= &dirty_background_bytes
,
1334 .maxlen
= sizeof(dirty_background_bytes
),
1336 .proc_handler
= dirty_background_bytes_handler
,
1340 .procname
= "dirty_ratio",
1341 .data
= &vm_dirty_ratio
,
1342 .maxlen
= sizeof(vm_dirty_ratio
),
1344 .proc_handler
= dirty_ratio_handler
,
1346 .extra2
= &one_hundred
,
1349 .procname
= "dirty_bytes",
1350 .data
= &vm_dirty_bytes
,
1351 .maxlen
= sizeof(vm_dirty_bytes
),
1353 .proc_handler
= dirty_bytes_handler
,
1354 .extra1
= &dirty_bytes_min
,
1357 .procname
= "dirty_writeback_centisecs",
1358 .data
= &dirty_writeback_interval
,
1359 .maxlen
= sizeof(dirty_writeback_interval
),
1361 .proc_handler
= dirty_writeback_centisecs_handler
,
1364 .procname
= "dirty_expire_centisecs",
1365 .data
= &dirty_expire_interval
,
1366 .maxlen
= sizeof(dirty_expire_interval
),
1368 .proc_handler
= proc_dointvec_minmax
,
1372 .procname
= "dirtytime_expire_seconds",
1373 .data
= &dirtytime_expire_interval
,
1374 .maxlen
= sizeof(dirty_expire_interval
),
1376 .proc_handler
= dirtytime_interval_handler
,
1380 .procname
= "nr_pdflush_threads",
1381 .mode
= 0444 /* read-only */,
1382 .proc_handler
= pdflush_proc_obsolete
,
1385 .procname
= "swappiness",
1386 .data
= &vm_swappiness
,
1387 .maxlen
= sizeof(vm_swappiness
),
1389 .proc_handler
= proc_dointvec_minmax
,
1391 .extra2
= &one_hundred
,
1393 #ifdef CONFIG_HUGETLB_PAGE
1395 .procname
= "nr_hugepages",
1397 .maxlen
= sizeof(unsigned long),
1399 .proc_handler
= hugetlb_sysctl_handler
,
1403 .procname
= "nr_hugepages_mempolicy",
1405 .maxlen
= sizeof(unsigned long),
1407 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1411 .procname
= "hugetlb_shm_group",
1412 .data
= &sysctl_hugetlb_shm_group
,
1413 .maxlen
= sizeof(gid_t
),
1415 .proc_handler
= proc_dointvec
,
1418 .procname
= "hugepages_treat_as_movable",
1419 .data
= &hugepages_treat_as_movable
,
1420 .maxlen
= sizeof(int),
1422 .proc_handler
= proc_dointvec
,
1425 .procname
= "nr_overcommit_hugepages",
1427 .maxlen
= sizeof(unsigned long),
1429 .proc_handler
= hugetlb_overcommit_handler
,
1433 .procname
= "lowmem_reserve_ratio",
1434 .data
= &sysctl_lowmem_reserve_ratio
,
1435 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1437 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1440 .procname
= "drop_caches",
1441 .data
= &sysctl_drop_caches
,
1442 .maxlen
= sizeof(int),
1444 .proc_handler
= drop_caches_sysctl_handler
,
1448 #ifdef CONFIG_COMPACTION
1450 .procname
= "compact_memory",
1451 .data
= &sysctl_compact_memory
,
1452 .maxlen
= sizeof(int),
1454 .proc_handler
= sysctl_compaction_handler
,
1457 .procname
= "extfrag_threshold",
1458 .data
= &sysctl_extfrag_threshold
,
1459 .maxlen
= sizeof(int),
1461 .proc_handler
= sysctl_extfrag_handler
,
1462 .extra1
= &min_extfrag_threshold
,
1463 .extra2
= &max_extfrag_threshold
,
1466 .procname
= "compact_unevictable_allowed",
1467 .data
= &sysctl_compact_unevictable_allowed
,
1468 .maxlen
= sizeof(int),
1470 .proc_handler
= proc_dointvec
,
1475 #endif /* CONFIG_COMPACTION */
1477 .procname
= "min_free_kbytes",
1478 .data
= &min_free_kbytes
,
1479 .maxlen
= sizeof(min_free_kbytes
),
1481 .proc_handler
= min_free_kbytes_sysctl_handler
,
1485 .procname
= "watermark_scale_factor",
1486 .data
= &watermark_scale_factor
,
1487 .maxlen
= sizeof(watermark_scale_factor
),
1489 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1491 .extra2
= &one_thousand
,
1494 .procname
= "extra_free_kbytes",
1495 .data
= &extra_free_kbytes
,
1496 .maxlen
= sizeof(extra_free_kbytes
),
1498 .proc_handler
= min_free_kbytes_sysctl_handler
,
1502 .procname
= "percpu_pagelist_fraction",
1503 .data
= &percpu_pagelist_fraction
,
1504 .maxlen
= sizeof(percpu_pagelist_fraction
),
1506 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1511 .procname
= "max_map_count",
1512 .data
= &sysctl_max_map_count
,
1513 .maxlen
= sizeof(sysctl_max_map_count
),
1515 .proc_handler
= proc_dointvec_minmax
,
1520 .procname
= "nr_trim_pages",
1521 .data
= &sysctl_nr_trim_pages
,
1522 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1524 .proc_handler
= proc_dointvec_minmax
,
1529 .procname
= "laptop_mode",
1530 .data
= &laptop_mode
,
1531 .maxlen
= sizeof(laptop_mode
),
1533 .proc_handler
= proc_dointvec_jiffies
,
1536 .procname
= "block_dump",
1537 .data
= &block_dump
,
1538 .maxlen
= sizeof(block_dump
),
1540 .proc_handler
= proc_dointvec
,
1544 .procname
= "vfs_cache_pressure",
1545 .data
= &sysctl_vfs_cache_pressure
,
1546 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1548 .proc_handler
= proc_dointvec
,
1551 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1553 .procname
= "legacy_va_layout",
1554 .data
= &sysctl_legacy_va_layout
,
1555 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1557 .proc_handler
= proc_dointvec
,
1563 .procname
= "zone_reclaim_mode",
1564 .data
= &node_reclaim_mode
,
1565 .maxlen
= sizeof(node_reclaim_mode
),
1567 .proc_handler
= proc_dointvec
,
1571 .procname
= "min_unmapped_ratio",
1572 .data
= &sysctl_min_unmapped_ratio
,
1573 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1575 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1577 .extra2
= &one_hundred
,
1580 .procname
= "min_slab_ratio",
1581 .data
= &sysctl_min_slab_ratio
,
1582 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1584 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1586 .extra2
= &one_hundred
,
1591 .procname
= "stat_interval",
1592 .data
= &sysctl_stat_interval
,
1593 .maxlen
= sizeof(sysctl_stat_interval
),
1595 .proc_handler
= proc_dointvec_jiffies
,
1598 .procname
= "stat_refresh",
1602 .proc_handler
= vmstat_refresh
,
1607 .procname
= "mmap_min_addr",
1608 .data
= &dac_mmap_min_addr
,
1609 .maxlen
= sizeof(unsigned long),
1611 .proc_handler
= mmap_min_addr_handler
,
1616 .procname
= "numa_zonelist_order",
1617 .data
= &numa_zonelist_order
,
1618 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1620 .proc_handler
= numa_zonelist_order_handler
,
1623 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1624 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1626 .procname
= "vdso_enabled",
1627 #ifdef CONFIG_X86_32
1628 .data
= &vdso32_enabled
,
1629 .maxlen
= sizeof(vdso32_enabled
),
1631 .data
= &vdso_enabled
,
1632 .maxlen
= sizeof(vdso_enabled
),
1635 .proc_handler
= proc_dointvec
,
1639 #ifdef CONFIG_HIGHMEM
1641 .procname
= "highmem_is_dirtyable",
1642 .data
= &vm_highmem_is_dirtyable
,
1643 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1645 .proc_handler
= proc_dointvec_minmax
,
1650 #ifdef CONFIG_MEMORY_FAILURE
1652 .procname
= "memory_failure_early_kill",
1653 .data
= &sysctl_memory_failure_early_kill
,
1654 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1656 .proc_handler
= proc_dointvec_minmax
,
1661 .procname
= "memory_failure_recovery",
1662 .data
= &sysctl_memory_failure_recovery
,
1663 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1665 .proc_handler
= proc_dointvec_minmax
,
1671 .procname
= "user_reserve_kbytes",
1672 .data
= &sysctl_user_reserve_kbytes
,
1673 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1675 .proc_handler
= proc_doulongvec_minmax
,
1678 .procname
= "admin_reserve_kbytes",
1679 .data
= &sysctl_admin_reserve_kbytes
,
1680 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1682 .proc_handler
= proc_doulongvec_minmax
,
1684 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1686 .procname
= "mmap_rnd_bits",
1687 .data
= &mmap_rnd_bits
,
1688 .maxlen
= sizeof(mmap_rnd_bits
),
1690 .proc_handler
= proc_dointvec_minmax
,
1691 .extra1
= (void *)&mmap_rnd_bits_min
,
1692 .extra2
= (void *)&mmap_rnd_bits_max
,
1695 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1697 .procname
= "mmap_rnd_compat_bits",
1698 .data
= &mmap_rnd_compat_bits
,
1699 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1701 .proc_handler
= proc_dointvec_minmax
,
1702 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1703 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1709 static struct ctl_table fs_table
[] = {
1711 .procname
= "inode-nr",
1712 .data
= &inodes_stat
,
1713 .maxlen
= 2*sizeof(long),
1715 .proc_handler
= proc_nr_inodes
,
1718 .procname
= "inode-state",
1719 .data
= &inodes_stat
,
1720 .maxlen
= 7*sizeof(long),
1722 .proc_handler
= proc_nr_inodes
,
1725 .procname
= "file-nr",
1726 .data
= &files_stat
,
1727 .maxlen
= sizeof(files_stat
),
1729 .proc_handler
= proc_nr_files
,
1732 .procname
= "file-max",
1733 .data
= &files_stat
.max_files
,
1734 .maxlen
= sizeof(files_stat
.max_files
),
1736 .proc_handler
= proc_doulongvec_minmax
,
1739 .procname
= "nr_open",
1740 .data
= &sysctl_nr_open
,
1741 .maxlen
= sizeof(unsigned int),
1743 .proc_handler
= proc_dointvec_minmax
,
1744 .extra1
= &sysctl_nr_open_min
,
1745 .extra2
= &sysctl_nr_open_max
,
1748 .procname
= "dentry-state",
1749 .data
= &dentry_stat
,
1750 .maxlen
= 6*sizeof(long),
1752 .proc_handler
= proc_nr_dentry
,
1755 .procname
= "overflowuid",
1756 .data
= &fs_overflowuid
,
1757 .maxlen
= sizeof(int),
1759 .proc_handler
= proc_dointvec_minmax
,
1760 .extra1
= &minolduid
,
1761 .extra2
= &maxolduid
,
1764 .procname
= "overflowgid",
1765 .data
= &fs_overflowgid
,
1766 .maxlen
= sizeof(int),
1768 .proc_handler
= proc_dointvec_minmax
,
1769 .extra1
= &minolduid
,
1770 .extra2
= &maxolduid
,
1772 #ifdef CONFIG_FILE_LOCKING
1774 .procname
= "leases-enable",
1775 .data
= &leases_enable
,
1776 .maxlen
= sizeof(int),
1778 .proc_handler
= proc_dointvec
,
1781 #ifdef CONFIG_DNOTIFY
1783 .procname
= "dir-notify-enable",
1784 .data
= &dir_notify_enable
,
1785 .maxlen
= sizeof(int),
1787 .proc_handler
= proc_dointvec
,
1791 #ifdef CONFIG_FILE_LOCKING
1793 .procname
= "lease-break-time",
1794 .data
= &lease_break_time
,
1795 .maxlen
= sizeof(int),
1797 .proc_handler
= proc_dointvec
,
1802 .procname
= "aio-nr",
1804 .maxlen
= sizeof(aio_nr
),
1806 .proc_handler
= proc_doulongvec_minmax
,
1809 .procname
= "aio-max-nr",
1810 .data
= &aio_max_nr
,
1811 .maxlen
= sizeof(aio_max_nr
),
1813 .proc_handler
= proc_doulongvec_minmax
,
1815 #endif /* CONFIG_AIO */
1816 #ifdef CONFIG_INOTIFY_USER
1818 .procname
= "inotify",
1820 .child
= inotify_table
,
1825 .procname
= "epoll",
1827 .child
= epoll_table
,
1832 .procname
= "protected_symlinks",
1833 .data
= &sysctl_protected_symlinks
,
1834 .maxlen
= sizeof(int),
1836 .proc_handler
= proc_dointvec_minmax
,
1841 .procname
= "protected_hardlinks",
1842 .data
= &sysctl_protected_hardlinks
,
1843 .maxlen
= sizeof(int),
1845 .proc_handler
= proc_dointvec_minmax
,
1850 .procname
= "suid_dumpable",
1851 .data
= &suid_dumpable
,
1852 .maxlen
= sizeof(int),
1854 .proc_handler
= proc_dointvec_minmax_coredump
,
1858 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1860 .procname
= "binfmt_misc",
1862 .child
= sysctl_mount_point
,
1866 .procname
= "pipe-max-size",
1867 .data
= &pipe_max_size
,
1868 .maxlen
= sizeof(pipe_max_size
),
1870 .proc_handler
= &pipe_proc_fn
,
1871 .extra1
= &pipe_min_size
,
1874 .procname
= "pipe-user-pages-hard",
1875 .data
= &pipe_user_pages_hard
,
1876 .maxlen
= sizeof(pipe_user_pages_hard
),
1878 .proc_handler
= proc_doulongvec_minmax
,
1881 .procname
= "pipe-user-pages-soft",
1882 .data
= &pipe_user_pages_soft
,
1883 .maxlen
= sizeof(pipe_user_pages_soft
),
1885 .proc_handler
= proc_doulongvec_minmax
,
1888 .procname
= "mount-max",
1889 .data
= &sysctl_mount_max
,
1890 .maxlen
= sizeof(unsigned int),
1892 .proc_handler
= proc_dointvec_minmax
,
1898 static struct ctl_table debug_table
[] = {
1899 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1901 .procname
= "exception-trace",
1902 .data
= &show_unhandled_signals
,
1903 .maxlen
= sizeof(int),
1905 .proc_handler
= proc_dointvec
1908 #if defined(CONFIG_OPTPROBES)
1910 .procname
= "kprobes-optimization",
1911 .data
= &sysctl_kprobes_optimization
,
1912 .maxlen
= sizeof(int),
1914 .proc_handler
= proc_kprobes_optimization_handler
,
1922 static struct ctl_table dev_table
[] = {
1926 int __init
sysctl_init(void)
1928 struct ctl_table_header
*hdr
;
1930 hdr
= register_sysctl_table(sysctl_base_table
);
1931 kmemleak_not_leak(hdr
);
1935 #endif /* CONFIG_SYSCTL */
1941 #ifdef CONFIG_PROC_SYSCTL
1943 static int _proc_do_string(char *data
, int maxlen
, int write
,
1944 char __user
*buffer
,
1945 size_t *lenp
, loff_t
*ppos
)
1951 if (!data
|| !maxlen
|| !*lenp
) {
1957 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1958 /* Only continue writes not past the end of buffer. */
1960 if (len
> maxlen
- 1)
1967 /* Start writing from beginning of buffer. */
1973 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1974 if (get_user(c
, p
++))
1976 if (c
== 0 || c
== '\n')
1997 if (copy_to_user(buffer
, data
, len
))
2000 if (put_user('\n', buffer
+ len
))
2010 static void warn_sysctl_write(struct ctl_table
*table
)
2012 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2013 "This will not be supported in the future. To silence this\n"
2014 "warning, set kernel.sysctl_writes_strict = -1\n",
2015 current
->comm
, table
->procname
);
2019 * proc_first_pos_non_zero_ignore - check if firs position is allowed
2020 * @ppos: file position
2021 * @table: the sysctl table
2023 * Returns true if the first position is non-zero and the sysctl_writes_strict
2024 * mode indicates this is not allowed for numeric input types. String proc
2025 * hadlers can ignore the return value.
2027 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2028 struct ctl_table
*table
)
2033 switch (sysctl_writes_strict
) {
2034 case SYSCTL_WRITES_STRICT
:
2036 case SYSCTL_WRITES_WARN
:
2037 warn_sysctl_write(table
);
2045 * proc_dostring - read a string sysctl
2046 * @table: the sysctl table
2047 * @write: %TRUE if this is a write to the sysctl file
2048 * @buffer: the user buffer
2049 * @lenp: the size of the user buffer
2050 * @ppos: file position
2052 * Reads/writes a string from/to the user buffer. If the kernel
2053 * buffer provided is not large enough to hold the string, the
2054 * string is truncated. The copied string is %NULL-terminated.
2055 * If the string is being read by the user process, it is copied
2056 * and a newline '\n' is added. It is truncated if the buffer is
2059 * Returns 0 on success.
2061 int proc_dostring(struct ctl_table
*table
, int write
,
2062 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2065 proc_first_pos_non_zero_ignore(ppos
, table
);
2067 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2068 (char __user
*)buffer
, lenp
, ppos
);
2071 static size_t proc_skip_spaces(char **buf
)
2074 char *tmp
= skip_spaces(*buf
);
2080 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2090 #define TMPBUFLEN 22
2092 * proc_get_long - reads an ASCII formatted integer from a user buffer
2094 * @buf: a kernel buffer
2095 * @size: size of the kernel buffer
2096 * @val: this is where the number will be stored
2097 * @neg: set to %TRUE if number is negative
2098 * @perm_tr: a vector which contains the allowed trailers
2099 * @perm_tr_len: size of the perm_tr vector
2100 * @tr: pointer to store the trailer character
2102 * In case of success %0 is returned and @buf and @size are updated with
2103 * the amount of bytes read. If @tr is non-NULL and a trailing
2104 * character exists (size is non-zero after returning from this
2105 * function), @tr is updated with the trailing character.
2107 static int proc_get_long(char **buf
, size_t *size
,
2108 unsigned long *val
, bool *neg
,
2109 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2112 char *p
, tmp
[TMPBUFLEN
];
2118 if (len
> TMPBUFLEN
- 1)
2119 len
= TMPBUFLEN
- 1;
2121 memcpy(tmp
, *buf
, len
);
2125 if (*p
== '-' && *size
> 1) {
2133 *val
= simple_strtoul(p
, &p
, 0);
2137 /* We don't know if the next char is whitespace thus we may accept
2138 * invalid integers (e.g. 1234...a) or two integers instead of one
2139 * (e.g. 123...1). So lets not allow such large numbers. */
2140 if (len
== TMPBUFLEN
- 1)
2143 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2146 if (tr
&& (len
< *size
))
2156 * proc_put_long - converts an integer to a decimal ASCII formatted string
2158 * @buf: the user buffer
2159 * @size: the size of the user buffer
2160 * @val: the integer to be converted
2161 * @neg: sign of the number, %TRUE for negative
2163 * In case of success %0 is returned and @buf and @size are updated with
2164 * the amount of bytes written.
2166 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2170 char tmp
[TMPBUFLEN
], *p
= tmp
;
2172 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2176 if (copy_to_user(*buf
, tmp
, len
))
2184 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2187 char __user
**buffer
= (char __user
**)buf
;
2188 if (put_user(c
, *buffer
))
2190 (*size
)--, (*buffer
)++;
2196 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2198 int write
, void *data
)
2202 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2206 if (*lvalp
> (unsigned long) INT_MAX
)
2214 *lvalp
= -(unsigned long)val
;
2217 *lvalp
= (unsigned long)val
;
2223 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2225 int write
, void *data
)
2228 if (*lvalp
> UINT_MAX
)
2232 unsigned int val
= *valp
;
2233 *lvalp
= (unsigned long)val
;
2238 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2240 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2241 int write
, void __user
*buffer
,
2242 size_t *lenp
, loff_t
*ppos
,
2243 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2244 int write
, void *data
),
2247 int *i
, vleft
, first
= 1, err
= 0;
2249 char *kbuf
= NULL
, *p
;
2251 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2256 i
= (int *) tbl_data
;
2257 vleft
= table
->maxlen
/ sizeof(*i
);
2261 conv
= do_proc_dointvec_conv
;
2264 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2267 if (left
> PAGE_SIZE
- 1)
2268 left
= PAGE_SIZE
- 1;
2269 p
= kbuf
= memdup_user_nul(buffer
, left
);
2271 return PTR_ERR(kbuf
);
2274 for (; left
&& vleft
--; i
++, first
=0) {
2279 left
-= proc_skip_spaces(&p
);
2283 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2285 sizeof(proc_wspace_sep
), NULL
);
2288 if (conv(&neg
, &lval
, i
, 1, data
)) {
2293 if (conv(&neg
, &lval
, i
, 0, data
)) {
2298 err
= proc_put_char(&buffer
, &left
, '\t');
2301 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2307 if (!write
&& !first
&& left
&& !err
)
2308 err
= proc_put_char(&buffer
, &left
, '\n');
2309 if (write
&& !err
&& left
)
2310 left
-= proc_skip_spaces(&p
);
2314 return err
? : -EINVAL
;
2322 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2323 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2324 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2325 int write
, void *data
),
2328 return __do_proc_dointvec(table
->data
, table
, write
,
2329 buffer
, lenp
, ppos
, conv
, data
);
2332 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2333 struct ctl_table
*table
,
2334 void __user
*buffer
,
2335 size_t *lenp
, loff_t
*ppos
,
2336 int (*conv
)(unsigned long *lvalp
,
2338 int write
, void *data
),
2345 char *kbuf
= NULL
, *p
;
2349 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2352 if (left
> PAGE_SIZE
- 1)
2353 left
= PAGE_SIZE
- 1;
2355 p
= kbuf
= memdup_user_nul(buffer
, left
);
2359 left
-= proc_skip_spaces(&p
);
2365 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2367 sizeof(proc_wspace_sep
), NULL
);
2373 if (conv(&lval
, tbl_data
, 1, data
)) {
2379 left
-= proc_skip_spaces(&p
);
2388 /* This is in keeping with old __do_proc_dointvec() */
2394 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2395 size_t *lenp
, loff_t
*ppos
,
2396 int (*conv
)(unsigned long *lvalp
,
2398 int write
, void *data
),
2407 if (conv(&lval
, tbl_data
, 0, data
)) {
2412 err
= proc_put_long(&buffer
, &left
, lval
, false);
2416 err
= proc_put_char(&buffer
, &left
, '\n');
2425 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2426 int write
, void __user
*buffer
,
2427 size_t *lenp
, loff_t
*ppos
,
2428 int (*conv
)(unsigned long *lvalp
,
2430 int write
, void *data
),
2433 unsigned int *i
, vleft
;
2435 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2440 i
= (unsigned int *) tbl_data
;
2441 vleft
= table
->maxlen
/ sizeof(*i
);
2444 * Arrays are not supported, keep this simple. *Do not* add
2453 conv
= do_proc_douintvec_conv
;
2456 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2458 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2461 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2462 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2463 int (*conv
)(unsigned long *lvalp
,
2465 int write
, void *data
),
2468 return __do_proc_douintvec(table
->data
, table
, write
,
2469 buffer
, lenp
, ppos
, conv
, data
);
2473 * proc_dointvec - read a vector of integers
2474 * @table: the sysctl table
2475 * @write: %TRUE if this is a write to the sysctl file
2476 * @buffer: the user buffer
2477 * @lenp: the size of the user buffer
2478 * @ppos: file position
2480 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2481 * values from/to the user buffer, treated as an ASCII string.
2483 * Returns 0 on success.
2485 int proc_dointvec(struct ctl_table
*table
, int write
,
2486 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2488 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2492 * proc_douintvec - read a vector of unsigned integers
2493 * @table: the sysctl table
2494 * @write: %TRUE if this is a write to the sysctl file
2495 * @buffer: the user buffer
2496 * @lenp: the size of the user buffer
2497 * @ppos: file position
2499 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2500 * values from/to the user buffer, treated as an ASCII string.
2502 * Returns 0 on success.
2504 int proc_douintvec(struct ctl_table
*table
, int write
,
2505 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2507 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2508 do_proc_douintvec_conv
, NULL
);
2512 * Taint values can only be increased
2513 * This means we can safely use a temporary.
2515 static int proc_taint(struct ctl_table
*table
, int write
,
2516 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2519 unsigned long tmptaint
= get_taint();
2522 if (write
&& !capable(CAP_SYS_ADMIN
))
2527 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2533 * Poor man's atomic or. Not worth adding a primitive
2534 * to everyone's atomic.h for this
2537 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2538 if ((tmptaint
>> i
) & 1)
2539 add_taint(i
, LOCKDEP_STILL_OK
);
2546 #ifdef CONFIG_PRINTK
2547 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2548 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2550 if (write
&& !capable(CAP_SYS_ADMIN
))
2553 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2557 struct do_proc_dointvec_minmax_conv_param
{
2562 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2564 int write
, void *data
)
2566 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2568 int val
= *negp
? -*lvalp
: *lvalp
;
2569 if ((param
->min
&& *param
->min
> val
) ||
2570 (param
->max
&& *param
->max
< val
))
2577 *lvalp
= -(unsigned long)val
;
2580 *lvalp
= (unsigned long)val
;
2587 * proc_dointvec_minmax - read a vector of integers with min/max values
2588 * @table: the sysctl table
2589 * @write: %TRUE if this is a write to the sysctl file
2590 * @buffer: the user buffer
2591 * @lenp: the size of the user buffer
2592 * @ppos: file position
2594 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2595 * values from/to the user buffer, treated as an ASCII string.
2597 * This routine will ensure the values are within the range specified by
2598 * table->extra1 (min) and table->extra2 (max).
2600 * Returns 0 on success.
2602 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2603 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2605 struct do_proc_dointvec_minmax_conv_param param
= {
2606 .min
= (int *) table
->extra1
,
2607 .max
= (int *) table
->extra2
,
2609 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2610 do_proc_dointvec_minmax_conv
, ¶m
);
2613 struct do_proc_douintvec_minmax_conv_param
{
2618 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2620 int write
, void *data
)
2622 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2625 unsigned int val
= *lvalp
;
2627 if ((param
->min
&& *param
->min
> val
) ||
2628 (param
->max
&& *param
->max
< val
))
2631 if (*lvalp
> UINT_MAX
)
2635 unsigned int val
= *valp
;
2636 *lvalp
= (unsigned long) val
;
2643 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2644 * @table: the sysctl table
2645 * @write: %TRUE if this is a write to the sysctl file
2646 * @buffer: the user buffer
2647 * @lenp: the size of the user buffer
2648 * @ppos: file position
2650 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2651 * values from/to the user buffer, treated as an ASCII string. Negative
2652 * strings are not allowed.
2654 * This routine will ensure the values are within the range specified by
2655 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2656 * check for UINT_MAX to avoid having to support wrap around uses from
2659 * Returns 0 on success.
2661 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2662 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2664 struct do_proc_douintvec_minmax_conv_param param
= {
2665 .min
= (unsigned int *) table
->extra1
,
2666 .max
= (unsigned int *) table
->extra2
,
2668 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2669 do_proc_douintvec_minmax_conv
, ¶m
);
2672 static void validate_coredump_safety(void)
2674 #ifdef CONFIG_COREDUMP
2675 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2676 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2678 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2679 "Pipe handler or fully qualified core dump path required.\n"
2680 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2686 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2687 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2689 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2691 validate_coredump_safety();
2695 #ifdef CONFIG_COREDUMP
2696 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2697 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2699 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2701 validate_coredump_safety();
2706 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2707 void __user
*buffer
,
2708 size_t *lenp
, loff_t
*ppos
,
2709 unsigned long convmul
,
2710 unsigned long convdiv
)
2712 unsigned long *i
, *min
, *max
;
2713 int vleft
, first
= 1, err
= 0;
2715 char *kbuf
= NULL
, *p
;
2717 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2722 i
= (unsigned long *) data
;
2723 min
= (unsigned long *) table
->extra1
;
2724 max
= (unsigned long *) table
->extra2
;
2725 vleft
= table
->maxlen
/ sizeof(unsigned long);
2729 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2732 if (left
> PAGE_SIZE
- 1)
2733 left
= PAGE_SIZE
- 1;
2734 p
= kbuf
= memdup_user_nul(buffer
, left
);
2736 return PTR_ERR(kbuf
);
2739 for (; left
&& vleft
--; i
++, first
= 0) {
2745 left
-= proc_skip_spaces(&p
);
2747 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2749 sizeof(proc_wspace_sep
), NULL
);
2754 val
= convmul
* val
/ convdiv
;
2755 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2759 val
= convdiv
* (*i
) / convmul
;
2761 err
= proc_put_char(&buffer
, &left
, '\t');
2765 err
= proc_put_long(&buffer
, &left
, val
, false);
2771 if (!write
&& !first
&& left
&& !err
)
2772 err
= proc_put_char(&buffer
, &left
, '\n');
2774 left
-= proc_skip_spaces(&p
);
2778 return err
? : -EINVAL
;
2786 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2787 void __user
*buffer
,
2788 size_t *lenp
, loff_t
*ppos
,
2789 unsigned long convmul
,
2790 unsigned long convdiv
)
2792 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2793 buffer
, lenp
, ppos
, convmul
, convdiv
);
2797 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2798 * @table: the sysctl table
2799 * @write: %TRUE if this is a write to the sysctl file
2800 * @buffer: the user buffer
2801 * @lenp: the size of the user buffer
2802 * @ppos: file position
2804 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2805 * values from/to the user buffer, treated as an ASCII string.
2807 * This routine will ensure the values are within the range specified by
2808 * table->extra1 (min) and table->extra2 (max).
2810 * Returns 0 on success.
2812 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2813 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2815 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2819 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2820 * @table: the sysctl table
2821 * @write: %TRUE if this is a write to the sysctl file
2822 * @buffer: the user buffer
2823 * @lenp: the size of the user buffer
2824 * @ppos: file position
2826 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2827 * values from/to the user buffer, treated as an ASCII string. The values
2828 * are treated as milliseconds, and converted to jiffies when they are stored.
2830 * This routine will ensure the values are within the range specified by
2831 * table->extra1 (min) and table->extra2 (max).
2833 * Returns 0 on success.
2835 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2836 void __user
*buffer
,
2837 size_t *lenp
, loff_t
*ppos
)
2839 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2840 lenp
, ppos
, HZ
, 1000l);
2844 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2846 int write
, void *data
)
2849 if (*lvalp
> INT_MAX
/ HZ
)
2851 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2857 lval
= -(unsigned long)val
;
2860 lval
= (unsigned long)val
;
2867 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2869 int write
, void *data
)
2872 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2874 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2880 lval
= -(unsigned long)val
;
2883 lval
= (unsigned long)val
;
2885 *lvalp
= jiffies_to_clock_t(lval
);
2890 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2892 int write
, void *data
)
2895 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2905 lval
= -(unsigned long)val
;
2908 lval
= (unsigned long)val
;
2910 *lvalp
= jiffies_to_msecs(lval
);
2916 * proc_dointvec_jiffies - read a vector of integers as seconds
2917 * @table: the sysctl table
2918 * @write: %TRUE if this is a write to the sysctl file
2919 * @buffer: the user buffer
2920 * @lenp: the size of the user buffer
2921 * @ppos: file position
2923 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2924 * values from/to the user buffer, treated as an ASCII string.
2925 * The values read are assumed to be in seconds, and are converted into
2928 * Returns 0 on success.
2930 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2931 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2933 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2934 do_proc_dointvec_jiffies_conv
,NULL
);
2938 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2939 * @table: the sysctl table
2940 * @write: %TRUE if this is a write to the sysctl file
2941 * @buffer: the user buffer
2942 * @lenp: the size of the user buffer
2943 * @ppos: pointer to the file position
2945 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2946 * values from/to the user buffer, treated as an ASCII string.
2947 * The values read are assumed to be in 1/USER_HZ seconds, and
2948 * are converted into jiffies.
2950 * Returns 0 on success.
2952 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2953 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2955 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2956 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2960 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2961 * @table: the sysctl table
2962 * @write: %TRUE if this is a write to the sysctl file
2963 * @buffer: the user buffer
2964 * @lenp: the size of the user buffer
2965 * @ppos: file position
2966 * @ppos: the current position in the file
2968 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2969 * values from/to the user buffer, treated as an ASCII string.
2970 * The values read are assumed to be in 1/1000 seconds, and
2971 * are converted into jiffies.
2973 * Returns 0 on success.
2975 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2976 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2978 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2979 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2982 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2983 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2985 struct pid
*new_pid
;
2989 tmp
= pid_vnr(cad_pid
);
2991 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2992 lenp
, ppos
, NULL
, NULL
);
2996 new_pid
= find_get_pid(tmp
);
3000 put_pid(xchg(&cad_pid
, new_pid
));
3005 * proc_do_large_bitmap - read/write from/to a large bitmap
3006 * @table: the sysctl table
3007 * @write: %TRUE if this is a write to the sysctl file
3008 * @buffer: the user buffer
3009 * @lenp: the size of the user buffer
3010 * @ppos: file position
3012 * The bitmap is stored at table->data and the bitmap length (in bits)
3015 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3016 * large bitmaps may be represented in a compact manner. Writing into
3017 * the file will clear the bitmap then update it with the given input.
3019 * Returns 0 on success.
3021 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3022 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3026 size_t left
= *lenp
;
3027 unsigned long bitmap_len
= table
->maxlen
;
3028 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3029 unsigned long *tmp_bitmap
= NULL
;
3030 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3032 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3040 if (left
> PAGE_SIZE
- 1)
3041 left
= PAGE_SIZE
- 1;
3043 p
= kbuf
= memdup_user_nul(buffer
, left
);
3045 return PTR_ERR(kbuf
);
3047 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
3053 proc_skip_char(&p
, &left
, '\n');
3054 while (!err
&& left
) {
3055 unsigned long val_a
, val_b
;
3058 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3062 if (val_a
>= bitmap_len
|| neg
) {
3074 err
= proc_get_long(&p
, &left
, &val_b
,
3075 &neg
, tr_b
, sizeof(tr_b
),
3079 if (val_b
>= bitmap_len
|| neg
||
3090 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3092 proc_skip_char(&p
, &left
, '\n');
3096 unsigned long bit_a
, bit_b
= 0;
3099 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3100 if (bit_a
>= bitmap_len
)
3102 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3106 err
= proc_put_char(&buffer
, &left
, ',');
3110 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3113 if (bit_a
!= bit_b
) {
3114 err
= proc_put_char(&buffer
, &left
, '-');
3117 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3125 err
= proc_put_char(&buffer
, &left
, '\n');
3131 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3133 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3145 #else /* CONFIG_PROC_SYSCTL */
3147 int proc_dostring(struct ctl_table
*table
, int write
,
3148 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3153 int proc_dointvec(struct ctl_table
*table
, int write
,
3154 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3159 int proc_douintvec(struct ctl_table
*table
, int write
,
3160 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3165 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3166 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3171 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3172 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3177 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3178 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3183 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3184 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3189 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3190 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3195 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3196 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3201 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3202 void __user
*buffer
,
3203 size_t *lenp
, loff_t
*ppos
)
3209 #endif /* CONFIG_PROC_SYSCTL */
3212 * No sense putting this after each symbol definition, twice,
3213 * exception granted :-)
3215 EXPORT_SYMBOL(proc_dointvec
);
3216 EXPORT_SYMBOL(proc_douintvec
);
3217 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3218 EXPORT_SYMBOL(proc_dointvec_minmax
);
3219 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3220 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3221 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3222 EXPORT_SYMBOL(proc_dostring
);
3223 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3224 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);