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
= "protected_fifos",
1851 .data
= &sysctl_protected_fifos
,
1852 .maxlen
= sizeof(int),
1854 .proc_handler
= proc_dointvec_minmax
,
1859 .procname
= "protected_regular",
1860 .data
= &sysctl_protected_regular
,
1861 .maxlen
= sizeof(int),
1863 .proc_handler
= proc_dointvec_minmax
,
1868 .procname
= "suid_dumpable",
1869 .data
= &suid_dumpable
,
1870 .maxlen
= sizeof(int),
1872 .proc_handler
= proc_dointvec_minmax_coredump
,
1876 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1878 .procname
= "binfmt_misc",
1880 .child
= sysctl_mount_point
,
1884 .procname
= "pipe-max-size",
1885 .data
= &pipe_max_size
,
1886 .maxlen
= sizeof(pipe_max_size
),
1888 .proc_handler
= &pipe_proc_fn
,
1889 .extra1
= &pipe_min_size
,
1892 .procname
= "pipe-user-pages-hard",
1893 .data
= &pipe_user_pages_hard
,
1894 .maxlen
= sizeof(pipe_user_pages_hard
),
1896 .proc_handler
= proc_doulongvec_minmax
,
1899 .procname
= "pipe-user-pages-soft",
1900 .data
= &pipe_user_pages_soft
,
1901 .maxlen
= sizeof(pipe_user_pages_soft
),
1903 .proc_handler
= proc_doulongvec_minmax
,
1906 .procname
= "mount-max",
1907 .data
= &sysctl_mount_max
,
1908 .maxlen
= sizeof(unsigned int),
1910 .proc_handler
= proc_dointvec_minmax
,
1916 static struct ctl_table debug_table
[] = {
1917 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1919 .procname
= "exception-trace",
1920 .data
= &show_unhandled_signals
,
1921 .maxlen
= sizeof(int),
1923 .proc_handler
= proc_dointvec
1926 #if defined(CONFIG_OPTPROBES)
1928 .procname
= "kprobes-optimization",
1929 .data
= &sysctl_kprobes_optimization
,
1930 .maxlen
= sizeof(int),
1932 .proc_handler
= proc_kprobes_optimization_handler
,
1940 static struct ctl_table dev_table
[] = {
1944 int __init
sysctl_init(void)
1946 struct ctl_table_header
*hdr
;
1948 hdr
= register_sysctl_table(sysctl_base_table
);
1949 kmemleak_not_leak(hdr
);
1953 #endif /* CONFIG_SYSCTL */
1959 #ifdef CONFIG_PROC_SYSCTL
1961 static int _proc_do_string(char *data
, int maxlen
, int write
,
1962 char __user
*buffer
,
1963 size_t *lenp
, loff_t
*ppos
)
1969 if (!data
|| !maxlen
|| !*lenp
) {
1975 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1976 /* Only continue writes not past the end of buffer. */
1978 if (len
> maxlen
- 1)
1985 /* Start writing from beginning of buffer. */
1991 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1992 if (get_user(c
, p
++))
1994 if (c
== 0 || c
== '\n')
2015 if (copy_to_user(buffer
, data
, len
))
2018 if (put_user('\n', buffer
+ len
))
2028 static void warn_sysctl_write(struct ctl_table
*table
)
2030 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2031 "This will not be supported in the future. To silence this\n"
2032 "warning, set kernel.sysctl_writes_strict = -1\n",
2033 current
->comm
, table
->procname
);
2037 * proc_first_pos_non_zero_ignore - check if firs position is allowed
2038 * @ppos: file position
2039 * @table: the sysctl table
2041 * Returns true if the first position is non-zero and the sysctl_writes_strict
2042 * mode indicates this is not allowed for numeric input types. String proc
2043 * hadlers can ignore the return value.
2045 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2046 struct ctl_table
*table
)
2051 switch (sysctl_writes_strict
) {
2052 case SYSCTL_WRITES_STRICT
:
2054 case SYSCTL_WRITES_WARN
:
2055 warn_sysctl_write(table
);
2063 * proc_dostring - read a string sysctl
2064 * @table: the sysctl table
2065 * @write: %TRUE if this is a write to the sysctl file
2066 * @buffer: the user buffer
2067 * @lenp: the size of the user buffer
2068 * @ppos: file position
2070 * Reads/writes a string from/to the user buffer. If the kernel
2071 * buffer provided is not large enough to hold the string, the
2072 * string is truncated. The copied string is %NULL-terminated.
2073 * If the string is being read by the user process, it is copied
2074 * and a newline '\n' is added. It is truncated if the buffer is
2077 * Returns 0 on success.
2079 int proc_dostring(struct ctl_table
*table
, int write
,
2080 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2083 proc_first_pos_non_zero_ignore(ppos
, table
);
2085 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2086 (char __user
*)buffer
, lenp
, ppos
);
2089 static size_t proc_skip_spaces(char **buf
)
2092 char *tmp
= skip_spaces(*buf
);
2098 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2108 #define TMPBUFLEN 22
2110 * proc_get_long - reads an ASCII formatted integer from a user buffer
2112 * @buf: a kernel buffer
2113 * @size: size of the kernel buffer
2114 * @val: this is where the number will be stored
2115 * @neg: set to %TRUE if number is negative
2116 * @perm_tr: a vector which contains the allowed trailers
2117 * @perm_tr_len: size of the perm_tr vector
2118 * @tr: pointer to store the trailer character
2120 * In case of success %0 is returned and @buf and @size are updated with
2121 * the amount of bytes read. If @tr is non-NULL and a trailing
2122 * character exists (size is non-zero after returning from this
2123 * function), @tr is updated with the trailing character.
2125 static int proc_get_long(char **buf
, size_t *size
,
2126 unsigned long *val
, bool *neg
,
2127 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2130 char *p
, tmp
[TMPBUFLEN
];
2136 if (len
> TMPBUFLEN
- 1)
2137 len
= TMPBUFLEN
- 1;
2139 memcpy(tmp
, *buf
, len
);
2143 if (*p
== '-' && *size
> 1) {
2151 *val
= simple_strtoul(p
, &p
, 0);
2155 /* We don't know if the next char is whitespace thus we may accept
2156 * invalid integers (e.g. 1234...a) or two integers instead of one
2157 * (e.g. 123...1). So lets not allow such large numbers. */
2158 if (len
== TMPBUFLEN
- 1)
2161 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2164 if (tr
&& (len
< *size
))
2174 * proc_put_long - converts an integer to a decimal ASCII formatted string
2176 * @buf: the user buffer
2177 * @size: the size of the user buffer
2178 * @val: the integer to be converted
2179 * @neg: sign of the number, %TRUE for negative
2181 * In case of success %0 is returned and @buf and @size are updated with
2182 * the amount of bytes written.
2184 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2188 char tmp
[TMPBUFLEN
], *p
= tmp
;
2190 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2194 if (copy_to_user(*buf
, tmp
, len
))
2202 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2205 char __user
**buffer
= (char __user
**)buf
;
2206 if (put_user(c
, *buffer
))
2208 (*size
)--, (*buffer
)++;
2214 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2216 int write
, void *data
)
2220 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2224 if (*lvalp
> (unsigned long) INT_MAX
)
2232 *lvalp
= -(unsigned long)val
;
2235 *lvalp
= (unsigned long)val
;
2241 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2243 int write
, void *data
)
2246 if (*lvalp
> UINT_MAX
)
2250 unsigned int val
= *valp
;
2251 *lvalp
= (unsigned long)val
;
2256 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2258 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2259 int write
, void __user
*buffer
,
2260 size_t *lenp
, loff_t
*ppos
,
2261 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2262 int write
, void *data
),
2265 int *i
, vleft
, first
= 1, err
= 0;
2267 char *kbuf
= NULL
, *p
;
2269 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2274 i
= (int *) tbl_data
;
2275 vleft
= table
->maxlen
/ sizeof(*i
);
2279 conv
= do_proc_dointvec_conv
;
2282 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2285 if (left
> PAGE_SIZE
- 1)
2286 left
= PAGE_SIZE
- 1;
2287 p
= kbuf
= memdup_user_nul(buffer
, left
);
2289 return PTR_ERR(kbuf
);
2292 for (; left
&& vleft
--; i
++, first
=0) {
2297 left
-= proc_skip_spaces(&p
);
2301 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2303 sizeof(proc_wspace_sep
), NULL
);
2306 if (conv(&neg
, &lval
, i
, 1, data
)) {
2311 if (conv(&neg
, &lval
, i
, 0, data
)) {
2316 err
= proc_put_char(&buffer
, &left
, '\t');
2319 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2325 if (!write
&& !first
&& left
&& !err
)
2326 err
= proc_put_char(&buffer
, &left
, '\n');
2327 if (write
&& !err
&& left
)
2328 left
-= proc_skip_spaces(&p
);
2332 return err
? : -EINVAL
;
2340 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2341 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2342 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2343 int write
, void *data
),
2346 return __do_proc_dointvec(table
->data
, table
, write
,
2347 buffer
, lenp
, ppos
, conv
, data
);
2350 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2351 struct ctl_table
*table
,
2352 void __user
*buffer
,
2353 size_t *lenp
, loff_t
*ppos
,
2354 int (*conv
)(unsigned long *lvalp
,
2356 int write
, void *data
),
2363 char *kbuf
= NULL
, *p
;
2367 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2370 if (left
> PAGE_SIZE
- 1)
2371 left
= PAGE_SIZE
- 1;
2373 p
= kbuf
= memdup_user_nul(buffer
, left
);
2377 left
-= proc_skip_spaces(&p
);
2383 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2385 sizeof(proc_wspace_sep
), NULL
);
2391 if (conv(&lval
, tbl_data
, 1, data
)) {
2397 left
-= proc_skip_spaces(&p
);
2406 /* This is in keeping with old __do_proc_dointvec() */
2412 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2413 size_t *lenp
, loff_t
*ppos
,
2414 int (*conv
)(unsigned long *lvalp
,
2416 int write
, void *data
),
2425 if (conv(&lval
, tbl_data
, 0, data
)) {
2430 err
= proc_put_long(&buffer
, &left
, lval
, false);
2434 err
= proc_put_char(&buffer
, &left
, '\n');
2443 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2444 int write
, void __user
*buffer
,
2445 size_t *lenp
, loff_t
*ppos
,
2446 int (*conv
)(unsigned long *lvalp
,
2448 int write
, void *data
),
2451 unsigned int *i
, vleft
;
2453 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2458 i
= (unsigned int *) tbl_data
;
2459 vleft
= table
->maxlen
/ sizeof(*i
);
2462 * Arrays are not supported, keep this simple. *Do not* add
2471 conv
= do_proc_douintvec_conv
;
2474 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2476 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2479 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2480 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2481 int (*conv
)(unsigned long *lvalp
,
2483 int write
, void *data
),
2486 return __do_proc_douintvec(table
->data
, table
, write
,
2487 buffer
, lenp
, ppos
, conv
, data
);
2491 * proc_dointvec - read a vector of integers
2492 * @table: the sysctl table
2493 * @write: %TRUE if this is a write to the sysctl file
2494 * @buffer: the user buffer
2495 * @lenp: the size of the user buffer
2496 * @ppos: file position
2498 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2499 * values from/to the user buffer, treated as an ASCII string.
2501 * Returns 0 on success.
2503 int proc_dointvec(struct ctl_table
*table
, int write
,
2504 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2506 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2510 * proc_douintvec - read a vector of unsigned integers
2511 * @table: the sysctl table
2512 * @write: %TRUE if this is a write to the sysctl file
2513 * @buffer: the user buffer
2514 * @lenp: the size of the user buffer
2515 * @ppos: file position
2517 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2518 * values from/to the user buffer, treated as an ASCII string.
2520 * Returns 0 on success.
2522 int proc_douintvec(struct ctl_table
*table
, int write
,
2523 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2525 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2526 do_proc_douintvec_conv
, NULL
);
2530 * Taint values can only be increased
2531 * This means we can safely use a temporary.
2533 static int proc_taint(struct ctl_table
*table
, int write
,
2534 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2537 unsigned long tmptaint
= get_taint();
2540 if (write
&& !capable(CAP_SYS_ADMIN
))
2545 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2551 * Poor man's atomic or. Not worth adding a primitive
2552 * to everyone's atomic.h for this
2555 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2556 if ((tmptaint
>> i
) & 1)
2557 add_taint(i
, LOCKDEP_STILL_OK
);
2564 #ifdef CONFIG_PRINTK
2565 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2566 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2568 if (write
&& !capable(CAP_SYS_ADMIN
))
2571 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2575 struct do_proc_dointvec_minmax_conv_param
{
2580 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2582 int write
, void *data
)
2584 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2586 int val
= *negp
? -*lvalp
: *lvalp
;
2587 if ((param
->min
&& *param
->min
> val
) ||
2588 (param
->max
&& *param
->max
< val
))
2595 *lvalp
= -(unsigned long)val
;
2598 *lvalp
= (unsigned long)val
;
2605 * proc_dointvec_minmax - read a vector of integers with min/max values
2606 * @table: the sysctl table
2607 * @write: %TRUE if this is a write to the sysctl file
2608 * @buffer: the user buffer
2609 * @lenp: the size of the user buffer
2610 * @ppos: file position
2612 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2613 * values from/to the user buffer, treated as an ASCII string.
2615 * This routine will ensure the values are within the range specified by
2616 * table->extra1 (min) and table->extra2 (max).
2618 * Returns 0 on success.
2620 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2621 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2623 struct do_proc_dointvec_minmax_conv_param param
= {
2624 .min
= (int *) table
->extra1
,
2625 .max
= (int *) table
->extra2
,
2627 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2628 do_proc_dointvec_minmax_conv
, ¶m
);
2631 struct do_proc_douintvec_minmax_conv_param
{
2636 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2638 int write
, void *data
)
2640 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2643 unsigned int val
= *lvalp
;
2645 if ((param
->min
&& *param
->min
> val
) ||
2646 (param
->max
&& *param
->max
< val
))
2649 if (*lvalp
> UINT_MAX
)
2653 unsigned int val
= *valp
;
2654 *lvalp
= (unsigned long) val
;
2661 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2662 * @table: the sysctl table
2663 * @write: %TRUE if this is a write to the sysctl file
2664 * @buffer: the user buffer
2665 * @lenp: the size of the user buffer
2666 * @ppos: file position
2668 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2669 * values from/to the user buffer, treated as an ASCII string. Negative
2670 * strings are not allowed.
2672 * This routine will ensure the values are within the range specified by
2673 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2674 * check for UINT_MAX to avoid having to support wrap around uses from
2677 * Returns 0 on success.
2679 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2680 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2682 struct do_proc_douintvec_minmax_conv_param param
= {
2683 .min
= (unsigned int *) table
->extra1
,
2684 .max
= (unsigned int *) table
->extra2
,
2686 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2687 do_proc_douintvec_minmax_conv
, ¶m
);
2690 static void validate_coredump_safety(void)
2692 #ifdef CONFIG_COREDUMP
2693 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2694 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2696 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2697 "Pipe handler or fully qualified core dump path required.\n"
2698 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2704 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2705 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2707 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2709 validate_coredump_safety();
2713 #ifdef CONFIG_COREDUMP
2714 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2715 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2717 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2719 validate_coredump_safety();
2724 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2725 void __user
*buffer
,
2726 size_t *lenp
, loff_t
*ppos
,
2727 unsigned long convmul
,
2728 unsigned long convdiv
)
2730 unsigned long *i
, *min
, *max
;
2731 int vleft
, first
= 1, err
= 0;
2733 char *kbuf
= NULL
, *p
;
2735 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2740 i
= (unsigned long *) data
;
2741 min
= (unsigned long *) table
->extra1
;
2742 max
= (unsigned long *) table
->extra2
;
2743 vleft
= table
->maxlen
/ sizeof(unsigned long);
2747 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2750 if (left
> PAGE_SIZE
- 1)
2751 left
= PAGE_SIZE
- 1;
2752 p
= kbuf
= memdup_user_nul(buffer
, left
);
2754 return PTR_ERR(kbuf
);
2757 for (; left
&& vleft
--; i
++, first
= 0) {
2763 left
-= proc_skip_spaces(&p
);
2765 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2767 sizeof(proc_wspace_sep
), NULL
);
2772 val
= convmul
* val
/ convdiv
;
2773 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2777 val
= convdiv
* (*i
) / convmul
;
2779 err
= proc_put_char(&buffer
, &left
, '\t');
2783 err
= proc_put_long(&buffer
, &left
, val
, false);
2789 if (!write
&& !first
&& left
&& !err
)
2790 err
= proc_put_char(&buffer
, &left
, '\n');
2792 left
-= proc_skip_spaces(&p
);
2796 return err
? : -EINVAL
;
2804 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2805 void __user
*buffer
,
2806 size_t *lenp
, loff_t
*ppos
,
2807 unsigned long convmul
,
2808 unsigned long convdiv
)
2810 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2811 buffer
, lenp
, ppos
, convmul
, convdiv
);
2815 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2816 * @table: the sysctl table
2817 * @write: %TRUE if this is a write to the sysctl file
2818 * @buffer: the user buffer
2819 * @lenp: the size of the user buffer
2820 * @ppos: file position
2822 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2823 * values from/to the user buffer, treated as an ASCII string.
2825 * This routine will ensure the values are within the range specified by
2826 * table->extra1 (min) and table->extra2 (max).
2828 * Returns 0 on success.
2830 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2831 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2833 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2837 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2838 * @table: the sysctl table
2839 * @write: %TRUE if this is a write to the sysctl file
2840 * @buffer: the user buffer
2841 * @lenp: the size of the user buffer
2842 * @ppos: file position
2844 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2845 * values from/to the user buffer, treated as an ASCII string. The values
2846 * are treated as milliseconds, and converted to jiffies when they are stored.
2848 * This routine will ensure the values are within the range specified by
2849 * table->extra1 (min) and table->extra2 (max).
2851 * Returns 0 on success.
2853 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2854 void __user
*buffer
,
2855 size_t *lenp
, loff_t
*ppos
)
2857 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2858 lenp
, ppos
, HZ
, 1000l);
2862 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2864 int write
, void *data
)
2867 if (*lvalp
> INT_MAX
/ HZ
)
2869 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2875 lval
= -(unsigned long)val
;
2878 lval
= (unsigned long)val
;
2885 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2887 int write
, void *data
)
2890 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2892 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2898 lval
= -(unsigned long)val
;
2901 lval
= (unsigned long)val
;
2903 *lvalp
= jiffies_to_clock_t(lval
);
2908 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2910 int write
, void *data
)
2913 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2923 lval
= -(unsigned long)val
;
2926 lval
= (unsigned long)val
;
2928 *lvalp
= jiffies_to_msecs(lval
);
2934 * proc_dointvec_jiffies - read a vector of integers as seconds
2935 * @table: the sysctl table
2936 * @write: %TRUE if this is a write to the sysctl file
2937 * @buffer: the user buffer
2938 * @lenp: the size of the user buffer
2939 * @ppos: file position
2941 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2942 * values from/to the user buffer, treated as an ASCII string.
2943 * The values read are assumed to be in seconds, and are converted into
2946 * Returns 0 on success.
2948 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2949 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2951 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2952 do_proc_dointvec_jiffies_conv
,NULL
);
2956 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2957 * @table: the sysctl table
2958 * @write: %TRUE if this is a write to the sysctl file
2959 * @buffer: the user buffer
2960 * @lenp: the size of the user buffer
2961 * @ppos: pointer to the file position
2963 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2964 * values from/to the user buffer, treated as an ASCII string.
2965 * The values read are assumed to be in 1/USER_HZ seconds, and
2966 * are converted into jiffies.
2968 * Returns 0 on success.
2970 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2971 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2973 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2974 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2978 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2979 * @table: the sysctl table
2980 * @write: %TRUE if this is a write to the sysctl file
2981 * @buffer: the user buffer
2982 * @lenp: the size of the user buffer
2983 * @ppos: file position
2984 * @ppos: the current position in the file
2986 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2987 * values from/to the user buffer, treated as an ASCII string.
2988 * The values read are assumed to be in 1/1000 seconds, and
2989 * are converted into jiffies.
2991 * Returns 0 on success.
2993 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2994 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2996 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2997 do_proc_dointvec_ms_jiffies_conv
, NULL
);
3000 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3001 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3003 struct pid
*new_pid
;
3007 tmp
= pid_vnr(cad_pid
);
3009 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3010 lenp
, ppos
, NULL
, NULL
);
3014 new_pid
= find_get_pid(tmp
);
3018 put_pid(xchg(&cad_pid
, new_pid
));
3023 * proc_do_large_bitmap - read/write from/to a large bitmap
3024 * @table: the sysctl table
3025 * @write: %TRUE if this is a write to the sysctl file
3026 * @buffer: the user buffer
3027 * @lenp: the size of the user buffer
3028 * @ppos: file position
3030 * The bitmap is stored at table->data and the bitmap length (in bits)
3033 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3034 * large bitmaps may be represented in a compact manner. Writing into
3035 * the file will clear the bitmap then update it with the given input.
3037 * Returns 0 on success.
3039 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3040 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3044 size_t left
= *lenp
;
3045 unsigned long bitmap_len
= table
->maxlen
;
3046 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3047 unsigned long *tmp_bitmap
= NULL
;
3048 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3050 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3058 if (left
> PAGE_SIZE
- 1)
3059 left
= PAGE_SIZE
- 1;
3061 p
= kbuf
= memdup_user_nul(buffer
, left
);
3063 return PTR_ERR(kbuf
);
3065 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
3071 proc_skip_char(&p
, &left
, '\n');
3072 while (!err
&& left
) {
3073 unsigned long val_a
, val_b
;
3076 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3080 if (val_a
>= bitmap_len
|| neg
) {
3092 err
= proc_get_long(&p
, &left
, &val_b
,
3093 &neg
, tr_b
, sizeof(tr_b
),
3097 if (val_b
>= bitmap_len
|| neg
||
3108 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3110 proc_skip_char(&p
, &left
, '\n');
3114 unsigned long bit_a
, bit_b
= 0;
3117 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3118 if (bit_a
>= bitmap_len
)
3120 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3124 err
= proc_put_char(&buffer
, &left
, ',');
3128 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3131 if (bit_a
!= bit_b
) {
3132 err
= proc_put_char(&buffer
, &left
, '-');
3135 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3143 err
= proc_put_char(&buffer
, &left
, '\n');
3149 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3151 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3163 #else /* CONFIG_PROC_SYSCTL */
3165 int proc_dostring(struct ctl_table
*table
, int write
,
3166 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3171 int proc_dointvec(struct ctl_table
*table
, int write
,
3172 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3177 int proc_douintvec(struct ctl_table
*table
, int write
,
3178 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3183 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3184 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3189 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3190 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3195 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3196 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3201 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3202 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3207 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3208 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3213 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3214 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3219 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3220 void __user
*buffer
,
3221 size_t *lenp
, loff_t
*ppos
)
3227 #endif /* CONFIG_PROC_SYSCTL */
3230 * No sense putting this after each symbol definition, twice,
3231 * exception granted :-)
3233 EXPORT_SYMBOL(proc_dointvec
);
3234 EXPORT_SYMBOL(proc_douintvec
);
3235 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3236 EXPORT_SYMBOL(proc_dointvec_minmax
);
3237 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3238 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3239 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3240 EXPORT_SYMBOL(proc_dostring
);
3241 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3242 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);