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>
69 #include <linux/pipe_fs_i.h>
71 #include "../lib/kstrtox.h"
73 #include <linux/uaccess.h>
74 #include <asm/processor.h>
78 #include <asm/stacktrace.h>
82 #include <asm/setup.h>
84 #ifdef CONFIG_BSD_PROCESS_ACCT
85 #include <linux/acct.h>
87 #ifdef CONFIG_RT_MUTEXES
88 #include <linux/rtmutex.h>
90 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
91 #include <linux/lockdep.h>
93 #ifdef CONFIG_CHR_DEV_SG
97 #ifdef CONFIG_LOCKUP_DETECTOR
98 #include <linux/nmi.h>
101 #if defined(CONFIG_SYSCTL)
103 /* External variables not in a header file. */
104 extern int suid_dumpable
;
105 #ifdef CONFIG_COREDUMP
106 extern int core_uses_pid
;
107 extern char core_pattern
[];
108 extern unsigned int core_pipe_limit
;
110 #ifdef CONFIG_USER_NS
111 extern int unprivileged_userns_clone
;
114 extern int pid_max_min
, pid_max_max
;
115 extern int percpu_pagelist_fraction
;
116 extern int latencytop_enabled
;
117 extern unsigned int sysctl_nr_open_min
, sysctl_nr_open_max
;
119 extern int sysctl_nr_trim_pages
;
122 /* Constants used for minimum and maximum */
123 #ifdef CONFIG_LOCKUP_DETECTOR
124 static int sixty
= 60;
127 static int __maybe_unused neg_one
= -1;
130 static int __maybe_unused one
= 1;
131 static int __maybe_unused two
= 2;
132 static int __maybe_unused four
= 4;
133 static unsigned long zero_ul
;
134 static unsigned long one_ul
= 1;
135 static unsigned long long_max
= LONG_MAX
;
136 static int one_hundred
= 100;
137 static int one_thousand
= 1000;
139 static int ten_thousand
= 10000;
141 #ifdef CONFIG_PERF_EVENTS
142 static int six_hundred_forty_kb
= 640 * 1024;
145 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
146 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
148 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
149 static int maxolduid
= 65535;
150 static int minolduid
;
152 static int ngroups_max
= NGROUPS_MAX
;
153 static const int cap_last_cap
= CAP_LAST_CAP
;
155 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
156 #ifdef CONFIG_DETECT_HUNG_TASK
157 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
160 #ifdef CONFIG_INOTIFY_USER
161 #include <linux/inotify.h>
167 extern int pwrsw_enabled
;
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
171 extern int unaligned_enabled
;
175 extern int unaligned_dump_stack
;
178 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179 extern int no_unaligned_warning
;
182 #ifdef CONFIG_PROC_SYSCTL
185 * enum sysctl_writes_mode - supported sysctl write modes
187 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
188 * to be written, and multiple writes on the same sysctl file descriptor
189 * will rewrite the sysctl value, regardless of file position. No warning
190 * is issued when the initial position is not 0.
191 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
193 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
194 * file position 0 and the value must be fully contained in the buffer
195 * sent to the write syscall. If dealing with strings respect the file
196 * position, but restrict this to the max length of the buffer, anything
197 * passed the max lenght will be ignored. Multiple writes will append
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
203 enum sysctl_writes_mode
{
204 SYSCTL_WRITES_LEGACY
= -1,
205 SYSCTL_WRITES_WARN
= 0,
206 SYSCTL_WRITES_STRICT
= 1,
209 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
211 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
212 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
213 static int proc_taint(struct ctl_table
*table
, int write
,
214 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
218 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
219 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
222 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
223 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
224 #ifdef CONFIG_COREDUMP
225 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
226 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
229 #ifdef CONFIG_MAGIC_SYSRQ
230 /* Note: sysrq code uses it's own private copy */
231 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
233 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
234 void __user
*buffer
, size_t *lenp
,
239 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
244 sysrq_toggle_support(__sysrq_enabled
);
251 static struct ctl_table kern_table
[];
252 static struct ctl_table vm_table
[];
253 static struct ctl_table fs_table
[];
254 static struct ctl_table debug_table
[];
255 static struct ctl_table dev_table
[];
256 extern struct ctl_table random_table
[];
258 extern struct ctl_table epoll_table
[];
261 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
262 int sysctl_legacy_va_layout
;
265 /* The default sysctl tables: */
267 static struct ctl_table sysctl_base_table
[] = {
269 .procname
= "kernel",
286 .child
= debug_table
,
296 #ifdef CONFIG_SCHED_DEBUG
297 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
298 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
299 static int min_wakeup_granularity_ns
; /* 0 usecs */
300 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
302 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
303 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
304 #endif /* CONFIG_SMP */
305 #endif /* CONFIG_SCHED_DEBUG */
307 #ifdef CONFIG_COMPACTION
308 static int min_extfrag_threshold
;
309 static int max_extfrag_threshold
= 1000;
312 static struct ctl_table kern_table
[] = {
314 .procname
= "sched_child_runs_first",
315 .data
= &sysctl_sched_child_runs_first
,
316 .maxlen
= sizeof(unsigned int),
318 .proc_handler
= proc_dointvec
,
320 #ifdef CONFIG_SCHED_DEBUG
322 .procname
= "sched_min_granularity_ns",
323 .data
= &sysctl_sched_min_granularity
,
324 .maxlen
= sizeof(unsigned int),
326 .proc_handler
= sched_proc_update_handler
,
327 .extra1
= &min_sched_granularity_ns
,
328 .extra2
= &max_sched_granularity_ns
,
331 .procname
= "sched_latency_ns",
332 .data
= &sysctl_sched_latency
,
333 .maxlen
= sizeof(unsigned int),
335 .proc_handler
= sched_proc_update_handler
,
336 .extra1
= &min_sched_granularity_ns
,
337 .extra2
= &max_sched_granularity_ns
,
340 .procname
= "sched_wakeup_granularity_ns",
341 .data
= &sysctl_sched_wakeup_granularity
,
342 .maxlen
= sizeof(unsigned int),
344 .proc_handler
= sched_proc_update_handler
,
345 .extra1
= &min_wakeup_granularity_ns
,
346 .extra2
= &max_wakeup_granularity_ns
,
350 .procname
= "sched_tunable_scaling",
351 .data
= &sysctl_sched_tunable_scaling
,
352 .maxlen
= sizeof(enum sched_tunable_scaling
),
354 .proc_handler
= sched_proc_update_handler
,
355 .extra1
= &min_sched_tunable_scaling
,
356 .extra2
= &max_sched_tunable_scaling
,
359 .procname
= "sched_migration_cost_ns",
360 .data
= &sysctl_sched_migration_cost
,
361 .maxlen
= sizeof(unsigned int),
363 .proc_handler
= proc_dointvec
,
366 .procname
= "sched_nr_migrate",
367 .data
= &sysctl_sched_nr_migrate
,
368 .maxlen
= sizeof(unsigned int),
370 .proc_handler
= proc_dointvec
,
373 .procname
= "sched_time_avg_ms",
374 .data
= &sysctl_sched_time_avg
,
375 .maxlen
= sizeof(unsigned int),
377 .proc_handler
= proc_dointvec_minmax
,
380 #ifdef CONFIG_SCHEDSTATS
382 .procname
= "sched_schedstats",
384 .maxlen
= sizeof(unsigned int),
386 .proc_handler
= sysctl_schedstats
,
390 #endif /* CONFIG_SCHEDSTATS */
391 #endif /* CONFIG_SMP */
392 #ifdef CONFIG_NUMA_BALANCING
394 .procname
= "numa_balancing_scan_delay_ms",
395 .data
= &sysctl_numa_balancing_scan_delay
,
396 .maxlen
= sizeof(unsigned int),
398 .proc_handler
= proc_dointvec
,
401 .procname
= "numa_balancing_scan_period_min_ms",
402 .data
= &sysctl_numa_balancing_scan_period_min
,
403 .maxlen
= sizeof(unsigned int),
405 .proc_handler
= proc_dointvec
,
408 .procname
= "numa_balancing_scan_period_max_ms",
409 .data
= &sysctl_numa_balancing_scan_period_max
,
410 .maxlen
= sizeof(unsigned int),
412 .proc_handler
= proc_dointvec
,
415 .procname
= "numa_balancing_scan_size_mb",
416 .data
= &sysctl_numa_balancing_scan_size
,
417 .maxlen
= sizeof(unsigned int),
419 .proc_handler
= proc_dointvec_minmax
,
423 .procname
= "numa_balancing",
424 .data
= NULL
, /* filled in by handler */
425 .maxlen
= sizeof(unsigned int),
427 .proc_handler
= sysctl_numa_balancing
,
431 #endif /* CONFIG_NUMA_BALANCING */
432 #endif /* CONFIG_SCHED_DEBUG */
434 .procname
= "sched_rt_period_us",
435 .data
= &sysctl_sched_rt_period
,
436 .maxlen
= sizeof(unsigned int),
438 .proc_handler
= sched_rt_handler
,
441 .procname
= "sched_rt_runtime_us",
442 .data
= &sysctl_sched_rt_runtime
,
443 .maxlen
= sizeof(int),
445 .proc_handler
= sched_rt_handler
,
448 .procname
= "sched_rr_timeslice_ms",
449 .data
= &sysctl_sched_rr_timeslice
,
450 .maxlen
= sizeof(int),
452 .proc_handler
= sched_rr_handler
,
454 #ifdef CONFIG_SCHED_AUTOGROUP
456 .procname
= "sched_autogroup_enabled",
457 .data
= &sysctl_sched_autogroup_enabled
,
458 .maxlen
= sizeof(unsigned int),
460 .proc_handler
= proc_dointvec_minmax
,
465 #ifdef CONFIG_CFS_BANDWIDTH
467 .procname
= "sched_cfs_bandwidth_slice_us",
468 .data
= &sysctl_sched_cfs_bandwidth_slice
,
469 .maxlen
= sizeof(unsigned int),
471 .proc_handler
= proc_dointvec_minmax
,
475 #ifdef CONFIG_PROVE_LOCKING
477 .procname
= "prove_locking",
478 .data
= &prove_locking
,
479 .maxlen
= sizeof(int),
481 .proc_handler
= proc_dointvec
,
484 #ifdef CONFIG_LOCK_STAT
486 .procname
= "lock_stat",
488 .maxlen
= sizeof(int),
490 .proc_handler
= proc_dointvec
,
495 .data
= &panic_timeout
,
496 .maxlen
= sizeof(int),
498 .proc_handler
= proc_dointvec
,
500 #ifdef CONFIG_COREDUMP
502 .procname
= "core_uses_pid",
503 .data
= &core_uses_pid
,
504 .maxlen
= sizeof(int),
506 .proc_handler
= proc_dointvec
,
509 .procname
= "core_pattern",
510 .data
= core_pattern
,
511 .maxlen
= CORENAME_MAX_SIZE
,
513 .proc_handler
= proc_dostring_coredump
,
516 .procname
= "core_pipe_limit",
517 .data
= &core_pipe_limit
,
518 .maxlen
= sizeof(unsigned int),
520 .proc_handler
= proc_dointvec
,
523 #ifdef CONFIG_USER_NS
525 .procname
= "unprivileged_userns_clone",
526 .data
= &unprivileged_userns_clone
,
527 .maxlen
= sizeof(int),
529 .proc_handler
= proc_dointvec
,
532 #ifdef CONFIG_PROC_SYSCTL
534 .procname
= "tainted",
535 .maxlen
= sizeof(long),
537 .proc_handler
= proc_taint
,
540 .procname
= "sysctl_writes_strict",
541 .data
= &sysctl_writes_strict
,
542 .maxlen
= sizeof(int),
544 .proc_handler
= proc_dointvec_minmax
,
549 #ifdef CONFIG_LATENCYTOP
551 .procname
= "latencytop",
552 .data
= &latencytop_enabled
,
553 .maxlen
= sizeof(int),
555 .proc_handler
= sysctl_latencytop
,
558 #ifdef CONFIG_BLK_DEV_INITRD
560 .procname
= "real-root-dev",
561 .data
= &real_root_dev
,
562 .maxlen
= sizeof(int),
564 .proc_handler
= proc_dointvec
,
568 .procname
= "print-fatal-signals",
569 .data
= &print_fatal_signals
,
570 .maxlen
= sizeof(int),
572 .proc_handler
= proc_dointvec
,
576 .procname
= "reboot-cmd",
577 .data
= reboot_command
,
580 .proc_handler
= proc_dostring
,
583 .procname
= "stop-a",
584 .data
= &stop_a_enabled
,
585 .maxlen
= sizeof (int),
587 .proc_handler
= proc_dointvec
,
590 .procname
= "scons-poweroff",
591 .data
= &scons_pwroff
,
592 .maxlen
= sizeof (int),
594 .proc_handler
= proc_dointvec
,
597 #ifdef CONFIG_SPARC64
599 .procname
= "tsb-ratio",
600 .data
= &sysctl_tsb_ratio
,
601 .maxlen
= sizeof (int),
603 .proc_handler
= proc_dointvec
,
608 .procname
= "soft-power",
609 .data
= &pwrsw_enabled
,
610 .maxlen
= sizeof (int),
612 .proc_handler
= proc_dointvec
,
615 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
617 .procname
= "unaligned-trap",
618 .data
= &unaligned_enabled
,
619 .maxlen
= sizeof (int),
621 .proc_handler
= proc_dointvec
,
625 .procname
= "ctrl-alt-del",
627 .maxlen
= sizeof(int),
629 .proc_handler
= proc_dointvec
,
631 #ifdef CONFIG_FUNCTION_TRACER
633 .procname
= "ftrace_enabled",
634 .data
= &ftrace_enabled
,
635 .maxlen
= sizeof(int),
637 .proc_handler
= ftrace_enable_sysctl
,
640 #ifdef CONFIG_STACK_TRACER
642 .procname
= "stack_tracer_enabled",
643 .data
= &stack_tracer_enabled
,
644 .maxlen
= sizeof(int),
646 .proc_handler
= stack_trace_sysctl
,
649 #ifdef CONFIG_TRACING
651 .procname
= "ftrace_dump_on_oops",
652 .data
= &ftrace_dump_on_oops
,
653 .maxlen
= sizeof(int),
655 .proc_handler
= proc_dointvec
,
658 .procname
= "traceoff_on_warning",
659 .data
= &__disable_trace_on_warning
,
660 .maxlen
= sizeof(__disable_trace_on_warning
),
662 .proc_handler
= proc_dointvec
,
665 .procname
= "tracepoint_printk",
666 .data
= &tracepoint_printk
,
667 .maxlen
= sizeof(tracepoint_printk
),
669 .proc_handler
= tracepoint_printk_sysctl
,
672 #ifdef CONFIG_KEXEC_CORE
674 .procname
= "kexec_load_disabled",
675 .data
= &kexec_load_disabled
,
676 .maxlen
= sizeof(int),
678 /* only handle a transition from default "0" to "1" */
679 .proc_handler
= proc_dointvec_minmax
,
684 #ifdef CONFIG_MODULES
686 .procname
= "modprobe",
687 .data
= &modprobe_path
,
688 .maxlen
= KMOD_PATH_LEN
,
690 .proc_handler
= proc_dostring
,
693 .procname
= "modules_disabled",
694 .data
= &modules_disabled
,
695 .maxlen
= sizeof(int),
697 /* only handle a transition from default "0" to "1" */
698 .proc_handler
= proc_dointvec_minmax
,
703 #ifdef CONFIG_UEVENT_HELPER
705 .procname
= "hotplug",
706 .data
= &uevent_helper
,
707 .maxlen
= UEVENT_HELPER_PATH_LEN
,
709 .proc_handler
= proc_dostring
,
712 #ifdef CONFIG_CHR_DEV_SG
714 .procname
= "sg-big-buff",
715 .data
= &sg_big_buff
,
716 .maxlen
= sizeof (int),
718 .proc_handler
= proc_dointvec
,
721 #ifdef CONFIG_BSD_PROCESS_ACCT
725 .maxlen
= 3*sizeof(int),
727 .proc_handler
= proc_dointvec
,
730 #ifdef CONFIG_MAGIC_SYSRQ
733 .data
= &__sysrq_enabled
,
734 .maxlen
= sizeof (int),
736 .proc_handler
= sysrq_sysctl_handler
,
739 #ifdef CONFIG_PROC_SYSCTL
741 .procname
= "cad_pid",
743 .maxlen
= sizeof (int),
745 .proc_handler
= proc_do_cad_pid
,
749 .procname
= "threads-max",
751 .maxlen
= sizeof(int),
753 .proc_handler
= sysctl_max_threads
,
756 .procname
= "random",
758 .child
= random_table
,
761 .procname
= "usermodehelper",
763 .child
= usermodehelper_table
,
766 .procname
= "overflowuid",
767 .data
= &overflowuid
,
768 .maxlen
= sizeof(int),
770 .proc_handler
= proc_dointvec_minmax
,
771 .extra1
= &minolduid
,
772 .extra2
= &maxolduid
,
775 .procname
= "overflowgid",
776 .data
= &overflowgid
,
777 .maxlen
= sizeof(int),
779 .proc_handler
= proc_dointvec_minmax
,
780 .extra1
= &minolduid
,
781 .extra2
= &maxolduid
,
784 #ifdef CONFIG_MATHEMU
786 .procname
= "ieee_emulation_warnings",
787 .data
= &sysctl_ieee_emulation_warnings
,
788 .maxlen
= sizeof(int),
790 .proc_handler
= proc_dointvec
,
794 .procname
= "userprocess_debug",
795 .data
= &show_unhandled_signals
,
796 .maxlen
= sizeof(int),
798 .proc_handler
= proc_dointvec
,
802 .procname
= "pid_max",
804 .maxlen
= sizeof (int),
806 .proc_handler
= proc_dointvec_minmax
,
807 .extra1
= &pid_max_min
,
808 .extra2
= &pid_max_max
,
811 .procname
= "panic_on_oops",
812 .data
= &panic_on_oops
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= proc_dointvec
,
817 #if defined CONFIG_PRINTK
819 .procname
= "printk",
820 .data
= &console_loglevel
,
821 .maxlen
= 4*sizeof(int),
823 .proc_handler
= proc_dointvec
,
826 .procname
= "printk_ratelimit",
827 .data
= &printk_ratelimit_state
.interval
,
828 .maxlen
= sizeof(int),
830 .proc_handler
= proc_dointvec_jiffies
,
833 .procname
= "printk_ratelimit_burst",
834 .data
= &printk_ratelimit_state
.burst
,
835 .maxlen
= sizeof(int),
837 .proc_handler
= proc_dointvec
,
840 .procname
= "printk_delay",
841 .data
= &printk_delay_msec
,
842 .maxlen
= sizeof(int),
844 .proc_handler
= proc_dointvec_minmax
,
846 .extra2
= &ten_thousand
,
849 .procname
= "printk_devkmsg",
850 .data
= devkmsg_log_str
,
851 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
853 .proc_handler
= devkmsg_sysctl_set_loglvl
,
856 .procname
= "dmesg_restrict",
857 .data
= &dmesg_restrict
,
858 .maxlen
= sizeof(int),
860 .proc_handler
= proc_dointvec_minmax_sysadmin
,
865 .procname
= "kptr_restrict",
866 .data
= &kptr_restrict
,
867 .maxlen
= sizeof(int),
869 .proc_handler
= proc_dointvec_minmax_sysadmin
,
875 .procname
= "ngroups_max",
876 .data
= &ngroups_max
,
877 .maxlen
= sizeof (int),
879 .proc_handler
= proc_dointvec
,
882 .procname
= "cap_last_cap",
883 .data
= (void *)&cap_last_cap
,
884 .maxlen
= sizeof(int),
886 .proc_handler
= proc_dointvec
,
888 #if defined(CONFIG_LOCKUP_DETECTOR)
890 .procname
= "watchdog",
891 .data
= &watchdog_user_enabled
,
892 .maxlen
= sizeof(int),
894 .proc_handler
= proc_watchdog
,
899 .procname
= "watchdog_thresh",
900 .data
= &watchdog_thresh
,
901 .maxlen
= sizeof(int),
903 .proc_handler
= proc_watchdog_thresh
,
908 .procname
= "nmi_watchdog",
909 .data
= &nmi_watchdog_user_enabled
,
910 .maxlen
= sizeof(int),
911 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
912 .proc_handler
= proc_nmi_watchdog
,
917 .procname
= "watchdog_cpumask",
918 .data
= &watchdog_cpumask_bits
,
921 .proc_handler
= proc_watchdog_cpumask
,
923 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
925 .procname
= "soft_watchdog",
926 .data
= &soft_watchdog_user_enabled
,
927 .maxlen
= sizeof(int),
929 .proc_handler
= proc_soft_watchdog
,
934 .procname
= "softlockup_panic",
935 .data
= &softlockup_panic
,
936 .maxlen
= sizeof(int),
938 .proc_handler
= proc_dointvec_minmax
,
944 .procname
= "softlockup_all_cpu_backtrace",
945 .data
= &sysctl_softlockup_all_cpu_backtrace
,
946 .maxlen
= sizeof(int),
948 .proc_handler
= proc_dointvec_minmax
,
952 #endif /* CONFIG_SMP */
954 #ifdef CONFIG_HARDLOCKUP_DETECTOR
956 .procname
= "hardlockup_panic",
957 .data
= &hardlockup_panic
,
958 .maxlen
= sizeof(int),
960 .proc_handler
= proc_dointvec_minmax
,
966 .procname
= "hardlockup_all_cpu_backtrace",
967 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
968 .maxlen
= sizeof(int),
970 .proc_handler
= proc_dointvec_minmax
,
974 #endif /* CONFIG_SMP */
978 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
980 .procname
= "unknown_nmi_panic",
981 .data
= &unknown_nmi_panic
,
982 .maxlen
= sizeof (int),
984 .proc_handler
= proc_dointvec
,
987 #if defined(CONFIG_X86)
989 .procname
= "panic_on_unrecovered_nmi",
990 .data
= &panic_on_unrecovered_nmi
,
991 .maxlen
= sizeof(int),
993 .proc_handler
= proc_dointvec
,
996 .procname
= "panic_on_io_nmi",
997 .data
= &panic_on_io_nmi
,
998 .maxlen
= sizeof(int),
1000 .proc_handler
= proc_dointvec
,
1002 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1004 .procname
= "panic_on_stackoverflow",
1005 .data
= &sysctl_panic_on_stackoverflow
,
1006 .maxlen
= sizeof(int),
1008 .proc_handler
= proc_dointvec
,
1012 .procname
= "bootloader_type",
1013 .data
= &bootloader_type
,
1014 .maxlen
= sizeof (int),
1016 .proc_handler
= proc_dointvec
,
1019 .procname
= "bootloader_version",
1020 .data
= &bootloader_version
,
1021 .maxlen
= sizeof (int),
1023 .proc_handler
= proc_dointvec
,
1026 .procname
= "io_delay_type",
1027 .data
= &io_delay_type
,
1028 .maxlen
= sizeof(int),
1030 .proc_handler
= proc_dointvec
,
1033 #if defined(CONFIG_MMU)
1035 .procname
= "randomize_va_space",
1036 .data
= &randomize_va_space
,
1037 .maxlen
= sizeof(int),
1039 .proc_handler
= proc_dointvec
,
1042 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1044 .procname
= "spin_retry",
1045 .data
= &spin_retry
,
1046 .maxlen
= sizeof (int),
1048 .proc_handler
= proc_dointvec
,
1051 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1053 .procname
= "acpi_video_flags",
1054 .data
= &acpi_realmode_flags
,
1055 .maxlen
= sizeof (unsigned long),
1057 .proc_handler
= proc_doulongvec_minmax
,
1060 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1062 .procname
= "ignore-unaligned-usertrap",
1063 .data
= &no_unaligned_warning
,
1064 .maxlen
= sizeof (int),
1066 .proc_handler
= proc_dointvec
,
1071 .procname
= "unaligned-dump-stack",
1072 .data
= &unaligned_dump_stack
,
1073 .maxlen
= sizeof (int),
1075 .proc_handler
= proc_dointvec
,
1078 #ifdef CONFIG_DETECT_HUNG_TASK
1080 .procname
= "hung_task_panic",
1081 .data
= &sysctl_hung_task_panic
,
1082 .maxlen
= sizeof(int),
1084 .proc_handler
= proc_dointvec_minmax
,
1089 .procname
= "hung_task_check_count",
1090 .data
= &sysctl_hung_task_check_count
,
1091 .maxlen
= sizeof(int),
1093 .proc_handler
= proc_dointvec_minmax
,
1097 .procname
= "hung_task_timeout_secs",
1098 .data
= &sysctl_hung_task_timeout_secs
,
1099 .maxlen
= sizeof(unsigned long),
1101 .proc_handler
= proc_dohung_task_timeout_secs
,
1102 .extra2
= &hung_task_timeout_max
,
1105 .procname
= "hung_task_warnings",
1106 .data
= &sysctl_hung_task_warnings
,
1107 .maxlen
= sizeof(int),
1109 .proc_handler
= proc_dointvec_minmax
,
1113 #ifdef CONFIG_RT_MUTEXES
1115 .procname
= "max_lock_depth",
1116 .data
= &max_lock_depth
,
1117 .maxlen
= sizeof(int),
1119 .proc_handler
= proc_dointvec
,
1123 .procname
= "poweroff_cmd",
1124 .data
= &poweroff_cmd
,
1125 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1127 .proc_handler
= proc_dostring
,
1133 .child
= key_sysctls
,
1136 #ifdef CONFIG_PERF_EVENTS
1138 * User-space scripts rely on the existence of this file
1139 * as a feature check for perf_events being enabled.
1141 * So it's an ABI, do not remove!
1144 .procname
= "perf_event_paranoid",
1145 .data
= &sysctl_perf_event_paranoid
,
1146 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1148 .proc_handler
= proc_dointvec
,
1151 .procname
= "perf_event_mlock_kb",
1152 .data
= &sysctl_perf_event_mlock
,
1153 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1155 .proc_handler
= proc_dointvec
,
1158 .procname
= "perf_event_max_sample_rate",
1159 .data
= &sysctl_perf_event_sample_rate
,
1160 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1162 .proc_handler
= perf_proc_update_handler
,
1166 .procname
= "perf_cpu_time_max_percent",
1167 .data
= &sysctl_perf_cpu_time_max_percent
,
1168 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1170 .proc_handler
= perf_cpu_time_max_percent_handler
,
1172 .extra2
= &one_hundred
,
1175 .procname
= "perf_event_max_stack",
1176 .data
= &sysctl_perf_event_max_stack
,
1177 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1179 .proc_handler
= perf_event_max_stack_handler
,
1181 .extra2
= &six_hundred_forty_kb
,
1184 .procname
= "perf_event_max_contexts_per_stack",
1185 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1186 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1188 .proc_handler
= perf_event_max_stack_handler
,
1190 .extra2
= &one_thousand
,
1194 .procname
= "panic_on_warn",
1195 .data
= &panic_on_warn
,
1196 .maxlen
= sizeof(int),
1198 .proc_handler
= proc_dointvec_minmax
,
1202 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1204 .procname
= "timer_migration",
1205 .data
= &sysctl_timer_migration
,
1206 .maxlen
= sizeof(unsigned int),
1208 .proc_handler
= timer_migration_handler
,
1213 #ifdef CONFIG_BPF_SYSCALL
1215 .procname
= "unprivileged_bpf_disabled",
1216 .data
= &sysctl_unprivileged_bpf_disabled
,
1217 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1219 /* only handle a transition from default "0" to "1" */
1220 .proc_handler
= proc_dointvec_minmax
,
1225 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1227 .procname
= "panic_on_rcu_stall",
1228 .data
= &sysctl_panic_on_rcu_stall
,
1229 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1231 .proc_handler
= proc_dointvec_minmax
,
1239 static struct ctl_table vm_table
[] = {
1241 .procname
= "overcommit_memory",
1242 .data
= &sysctl_overcommit_memory
,
1243 .maxlen
= sizeof(sysctl_overcommit_memory
),
1245 .proc_handler
= proc_dointvec_minmax
,
1250 .procname
= "panic_on_oom",
1251 .data
= &sysctl_panic_on_oom
,
1252 .maxlen
= sizeof(sysctl_panic_on_oom
),
1254 .proc_handler
= proc_dointvec_minmax
,
1259 .procname
= "oom_kill_allocating_task",
1260 .data
= &sysctl_oom_kill_allocating_task
,
1261 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1263 .proc_handler
= proc_dointvec
,
1266 .procname
= "oom_dump_tasks",
1267 .data
= &sysctl_oom_dump_tasks
,
1268 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1270 .proc_handler
= proc_dointvec
,
1273 .procname
= "overcommit_ratio",
1274 .data
= &sysctl_overcommit_ratio
,
1275 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1277 .proc_handler
= overcommit_ratio_handler
,
1280 .procname
= "overcommit_kbytes",
1281 .data
= &sysctl_overcommit_kbytes
,
1282 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1284 .proc_handler
= overcommit_kbytes_handler
,
1287 .procname
= "page-cluster",
1288 .data
= &page_cluster
,
1289 .maxlen
= sizeof(int),
1291 .proc_handler
= proc_dointvec_minmax
,
1295 .procname
= "dirty_background_ratio",
1296 .data
= &dirty_background_ratio
,
1297 .maxlen
= sizeof(dirty_background_ratio
),
1299 .proc_handler
= dirty_background_ratio_handler
,
1301 .extra2
= &one_hundred
,
1304 .procname
= "dirty_background_bytes",
1305 .data
= &dirty_background_bytes
,
1306 .maxlen
= sizeof(dirty_background_bytes
),
1308 .proc_handler
= dirty_background_bytes_handler
,
1312 .procname
= "dirty_ratio",
1313 .data
= &vm_dirty_ratio
,
1314 .maxlen
= sizeof(vm_dirty_ratio
),
1316 .proc_handler
= dirty_ratio_handler
,
1318 .extra2
= &one_hundred
,
1321 .procname
= "dirty_bytes",
1322 .data
= &vm_dirty_bytes
,
1323 .maxlen
= sizeof(vm_dirty_bytes
),
1325 .proc_handler
= dirty_bytes_handler
,
1326 .extra1
= &dirty_bytes_min
,
1329 .procname
= "dirty_writeback_centisecs",
1330 .data
= &dirty_writeback_interval
,
1331 .maxlen
= sizeof(dirty_writeback_interval
),
1333 .proc_handler
= dirty_writeback_centisecs_handler
,
1336 .procname
= "dirty_expire_centisecs",
1337 .data
= &dirty_expire_interval
,
1338 .maxlen
= sizeof(dirty_expire_interval
),
1340 .proc_handler
= proc_dointvec_minmax
,
1344 .procname
= "dirtytime_expire_seconds",
1345 .data
= &dirtytime_expire_interval
,
1346 .maxlen
= sizeof(dirty_expire_interval
),
1348 .proc_handler
= dirtytime_interval_handler
,
1352 .procname
= "swappiness",
1353 .data
= &vm_swappiness
,
1354 .maxlen
= sizeof(vm_swappiness
),
1356 .proc_handler
= proc_dointvec_minmax
,
1358 .extra2
= &one_hundred
,
1360 #ifdef CONFIG_HUGETLB_PAGE
1362 .procname
= "nr_hugepages",
1364 .maxlen
= sizeof(unsigned long),
1366 .proc_handler
= hugetlb_sysctl_handler
,
1370 .procname
= "nr_hugepages_mempolicy",
1372 .maxlen
= sizeof(unsigned long),
1374 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1377 .procname
= "numa_stat",
1378 .data
= &sysctl_vm_numa_stat
,
1379 .maxlen
= sizeof(int),
1381 .proc_handler
= sysctl_vm_numa_stat_handler
,
1387 .procname
= "hugetlb_shm_group",
1388 .data
= &sysctl_hugetlb_shm_group
,
1389 .maxlen
= sizeof(gid_t
),
1391 .proc_handler
= proc_dointvec
,
1394 .procname
= "hugepages_treat_as_movable",
1395 .data
= &hugepages_treat_as_movable
,
1396 .maxlen
= sizeof(int),
1398 .proc_handler
= proc_dointvec
,
1401 .procname
= "nr_overcommit_hugepages",
1403 .maxlen
= sizeof(unsigned long),
1405 .proc_handler
= hugetlb_overcommit_handler
,
1409 .procname
= "lowmem_reserve_ratio",
1410 .data
= &sysctl_lowmem_reserve_ratio
,
1411 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1413 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1416 .procname
= "drop_caches",
1417 .data
= &sysctl_drop_caches
,
1418 .maxlen
= sizeof(int),
1420 .proc_handler
= drop_caches_sysctl_handler
,
1424 #ifdef CONFIG_COMPACTION
1426 .procname
= "compact_memory",
1427 .data
= &sysctl_compact_memory
,
1428 .maxlen
= sizeof(int),
1430 .proc_handler
= sysctl_compaction_handler
,
1433 .procname
= "extfrag_threshold",
1434 .data
= &sysctl_extfrag_threshold
,
1435 .maxlen
= sizeof(int),
1437 .proc_handler
= sysctl_extfrag_handler
,
1438 .extra1
= &min_extfrag_threshold
,
1439 .extra2
= &max_extfrag_threshold
,
1442 .procname
= "compact_unevictable_allowed",
1443 .data
= &sysctl_compact_unevictable_allowed
,
1444 .maxlen
= sizeof(int),
1446 .proc_handler
= proc_dointvec
,
1451 #endif /* CONFIG_COMPACTION */
1453 .procname
= "min_free_kbytes",
1454 .data
= &min_free_kbytes
,
1455 .maxlen
= sizeof(min_free_kbytes
),
1457 .proc_handler
= min_free_kbytes_sysctl_handler
,
1461 .procname
= "watermark_scale_factor",
1462 .data
= &watermark_scale_factor
,
1463 .maxlen
= sizeof(watermark_scale_factor
),
1465 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1467 .extra2
= &one_thousand
,
1470 .procname
= "percpu_pagelist_fraction",
1471 .data
= &percpu_pagelist_fraction
,
1472 .maxlen
= sizeof(percpu_pagelist_fraction
),
1474 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1479 .procname
= "max_map_count",
1480 .data
= &sysctl_max_map_count
,
1481 .maxlen
= sizeof(sysctl_max_map_count
),
1483 .proc_handler
= proc_dointvec_minmax
,
1488 .procname
= "nr_trim_pages",
1489 .data
= &sysctl_nr_trim_pages
,
1490 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1492 .proc_handler
= proc_dointvec_minmax
,
1497 .procname
= "laptop_mode",
1498 .data
= &laptop_mode
,
1499 .maxlen
= sizeof(laptop_mode
),
1501 .proc_handler
= proc_dointvec_jiffies
,
1504 .procname
= "block_dump",
1505 .data
= &block_dump
,
1506 .maxlen
= sizeof(block_dump
),
1508 .proc_handler
= proc_dointvec
,
1512 .procname
= "vfs_cache_pressure",
1513 .data
= &sysctl_vfs_cache_pressure
,
1514 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1516 .proc_handler
= proc_dointvec
,
1519 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1521 .procname
= "legacy_va_layout",
1522 .data
= &sysctl_legacy_va_layout
,
1523 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1525 .proc_handler
= proc_dointvec
,
1531 .procname
= "zone_reclaim_mode",
1532 .data
= &node_reclaim_mode
,
1533 .maxlen
= sizeof(node_reclaim_mode
),
1535 .proc_handler
= proc_dointvec
,
1539 .procname
= "min_unmapped_ratio",
1540 .data
= &sysctl_min_unmapped_ratio
,
1541 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1543 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1545 .extra2
= &one_hundred
,
1548 .procname
= "min_slab_ratio",
1549 .data
= &sysctl_min_slab_ratio
,
1550 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1552 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1554 .extra2
= &one_hundred
,
1559 .procname
= "stat_interval",
1560 .data
= &sysctl_stat_interval
,
1561 .maxlen
= sizeof(sysctl_stat_interval
),
1563 .proc_handler
= proc_dointvec_jiffies
,
1566 .procname
= "stat_refresh",
1570 .proc_handler
= vmstat_refresh
,
1575 .procname
= "mmap_min_addr",
1576 .data
= &dac_mmap_min_addr
,
1577 .maxlen
= sizeof(unsigned long),
1579 .proc_handler
= mmap_min_addr_handler
,
1584 .procname
= "numa_zonelist_order",
1585 .data
= &numa_zonelist_order
,
1586 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1588 .proc_handler
= numa_zonelist_order_handler
,
1591 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1592 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1594 .procname
= "vdso_enabled",
1595 #ifdef CONFIG_X86_32
1596 .data
= &vdso32_enabled
,
1597 .maxlen
= sizeof(vdso32_enabled
),
1599 .data
= &vdso_enabled
,
1600 .maxlen
= sizeof(vdso_enabled
),
1603 .proc_handler
= proc_dointvec
,
1607 #ifdef CONFIG_HIGHMEM
1609 .procname
= "highmem_is_dirtyable",
1610 .data
= &vm_highmem_is_dirtyable
,
1611 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1613 .proc_handler
= proc_dointvec_minmax
,
1618 #ifdef CONFIG_MEMORY_FAILURE
1620 .procname
= "memory_failure_early_kill",
1621 .data
= &sysctl_memory_failure_early_kill
,
1622 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1624 .proc_handler
= proc_dointvec_minmax
,
1629 .procname
= "memory_failure_recovery",
1630 .data
= &sysctl_memory_failure_recovery
,
1631 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1633 .proc_handler
= proc_dointvec_minmax
,
1639 .procname
= "user_reserve_kbytes",
1640 .data
= &sysctl_user_reserve_kbytes
,
1641 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1643 .proc_handler
= proc_doulongvec_minmax
,
1646 .procname
= "admin_reserve_kbytes",
1647 .data
= &sysctl_admin_reserve_kbytes
,
1648 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1650 .proc_handler
= proc_doulongvec_minmax
,
1652 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1654 .procname
= "mmap_rnd_bits",
1655 .data
= &mmap_rnd_bits
,
1656 .maxlen
= sizeof(mmap_rnd_bits
),
1658 .proc_handler
= proc_dointvec_minmax
,
1659 .extra1
= (void *)&mmap_rnd_bits_min
,
1660 .extra2
= (void *)&mmap_rnd_bits_max
,
1663 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1665 .procname
= "mmap_rnd_compat_bits",
1666 .data
= &mmap_rnd_compat_bits
,
1667 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1669 .proc_handler
= proc_dointvec_minmax
,
1670 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1671 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1677 static struct ctl_table fs_table
[] = {
1679 .procname
= "inode-nr",
1680 .data
= &inodes_stat
,
1681 .maxlen
= 2*sizeof(long),
1683 .proc_handler
= proc_nr_inodes
,
1686 .procname
= "inode-state",
1687 .data
= &inodes_stat
,
1688 .maxlen
= 7*sizeof(long),
1690 .proc_handler
= proc_nr_inodes
,
1693 .procname
= "file-nr",
1694 .data
= &files_stat
,
1695 .maxlen
= sizeof(files_stat
),
1697 .proc_handler
= proc_nr_files
,
1700 .procname
= "file-max",
1701 .data
= &files_stat
.max_files
,
1702 .maxlen
= sizeof(files_stat
.max_files
),
1704 .proc_handler
= proc_doulongvec_minmax
,
1706 .extra2
= &long_max
,
1709 .procname
= "nr_open",
1710 .data
= &sysctl_nr_open
,
1711 .maxlen
= sizeof(unsigned int),
1713 .proc_handler
= proc_dointvec_minmax
,
1714 .extra1
= &sysctl_nr_open_min
,
1715 .extra2
= &sysctl_nr_open_max
,
1718 .procname
= "dentry-state",
1719 .data
= &dentry_stat
,
1720 .maxlen
= 6*sizeof(long),
1722 .proc_handler
= proc_nr_dentry
,
1725 .procname
= "overflowuid",
1726 .data
= &fs_overflowuid
,
1727 .maxlen
= sizeof(int),
1729 .proc_handler
= proc_dointvec_minmax
,
1730 .extra1
= &minolduid
,
1731 .extra2
= &maxolduid
,
1734 .procname
= "overflowgid",
1735 .data
= &fs_overflowgid
,
1736 .maxlen
= sizeof(int),
1738 .proc_handler
= proc_dointvec_minmax
,
1739 .extra1
= &minolduid
,
1740 .extra2
= &maxolduid
,
1742 #ifdef CONFIG_FILE_LOCKING
1744 .procname
= "leases-enable",
1745 .data
= &leases_enable
,
1746 .maxlen
= sizeof(int),
1748 .proc_handler
= proc_dointvec
,
1751 #ifdef CONFIG_DNOTIFY
1753 .procname
= "dir-notify-enable",
1754 .data
= &dir_notify_enable
,
1755 .maxlen
= sizeof(int),
1757 .proc_handler
= proc_dointvec
,
1761 #ifdef CONFIG_FILE_LOCKING
1763 .procname
= "lease-break-time",
1764 .data
= &lease_break_time
,
1765 .maxlen
= sizeof(int),
1767 .proc_handler
= proc_dointvec
,
1772 .procname
= "aio-nr",
1774 .maxlen
= sizeof(aio_nr
),
1776 .proc_handler
= proc_doulongvec_minmax
,
1779 .procname
= "aio-max-nr",
1780 .data
= &aio_max_nr
,
1781 .maxlen
= sizeof(aio_max_nr
),
1783 .proc_handler
= proc_doulongvec_minmax
,
1785 #endif /* CONFIG_AIO */
1786 #ifdef CONFIG_INOTIFY_USER
1788 .procname
= "inotify",
1790 .child
= inotify_table
,
1795 .procname
= "epoll",
1797 .child
= epoll_table
,
1802 .procname
= "protected_symlinks",
1803 .data
= &sysctl_protected_symlinks
,
1804 .maxlen
= sizeof(int),
1806 .proc_handler
= proc_dointvec_minmax
,
1811 .procname
= "protected_hardlinks",
1812 .data
= &sysctl_protected_hardlinks
,
1813 .maxlen
= sizeof(int),
1815 .proc_handler
= proc_dointvec_minmax
,
1820 .procname
= "suid_dumpable",
1821 .data
= &suid_dumpable
,
1822 .maxlen
= sizeof(int),
1824 .proc_handler
= proc_dointvec_minmax_coredump
,
1828 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1830 .procname
= "binfmt_misc",
1832 .child
= sysctl_mount_point
,
1836 .procname
= "pipe-max-size",
1837 .data
= &pipe_max_size
,
1838 .maxlen
= sizeof(pipe_max_size
),
1840 .proc_handler
= &pipe_proc_fn
,
1841 .extra1
= &pipe_min_size
,
1844 .procname
= "pipe-user-pages-hard",
1845 .data
= &pipe_user_pages_hard
,
1846 .maxlen
= sizeof(pipe_user_pages_hard
),
1848 .proc_handler
= proc_doulongvec_minmax
,
1851 .procname
= "pipe-user-pages-soft",
1852 .data
= &pipe_user_pages_soft
,
1853 .maxlen
= sizeof(pipe_user_pages_soft
),
1855 .proc_handler
= proc_doulongvec_minmax
,
1858 .procname
= "mount-max",
1859 .data
= &sysctl_mount_max
,
1860 .maxlen
= sizeof(unsigned int),
1862 .proc_handler
= proc_dointvec_minmax
,
1868 static struct ctl_table debug_table
[] = {
1869 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1871 .procname
= "exception-trace",
1872 .data
= &show_unhandled_signals
,
1873 .maxlen
= sizeof(int),
1875 .proc_handler
= proc_dointvec
1878 #if defined(CONFIG_OPTPROBES)
1880 .procname
= "kprobes-optimization",
1881 .data
= &sysctl_kprobes_optimization
,
1882 .maxlen
= sizeof(int),
1884 .proc_handler
= proc_kprobes_optimization_handler
,
1892 static struct ctl_table dev_table
[] = {
1896 int __init
sysctl_init(void)
1898 struct ctl_table_header
*hdr
;
1900 hdr
= register_sysctl_table(sysctl_base_table
);
1901 kmemleak_not_leak(hdr
);
1905 #endif /* CONFIG_SYSCTL */
1911 #ifdef CONFIG_PROC_SYSCTL
1913 static int _proc_do_string(char *data
, int maxlen
, int write
,
1914 char __user
*buffer
,
1915 size_t *lenp
, loff_t
*ppos
)
1921 if (!data
|| !maxlen
|| !*lenp
) {
1927 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1928 /* Only continue writes not past the end of buffer. */
1930 if (len
> maxlen
- 1)
1937 /* Start writing from beginning of buffer. */
1943 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1944 if (get_user(c
, p
++))
1946 if (c
== 0 || c
== '\n')
1967 if (copy_to_user(buffer
, data
, len
))
1970 if (put_user('\n', buffer
+ len
))
1980 static void warn_sysctl_write(struct ctl_table
*table
)
1982 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1983 "This will not be supported in the future. To silence this\n"
1984 "warning, set kernel.sysctl_writes_strict = -1\n",
1985 current
->comm
, table
->procname
);
1989 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1990 * @ppos: file position
1991 * @table: the sysctl table
1993 * Returns true if the first position is non-zero and the sysctl_writes_strict
1994 * mode indicates this is not allowed for numeric input types. String proc
1995 * hadlers can ignore the return value.
1997 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
1998 struct ctl_table
*table
)
2003 switch (sysctl_writes_strict
) {
2004 case SYSCTL_WRITES_STRICT
:
2006 case SYSCTL_WRITES_WARN
:
2007 warn_sysctl_write(table
);
2015 * proc_dostring - read a string sysctl
2016 * @table: the sysctl table
2017 * @write: %TRUE if this is a write to the sysctl file
2018 * @buffer: the user buffer
2019 * @lenp: the size of the user buffer
2020 * @ppos: file position
2022 * Reads/writes a string from/to the user buffer. If the kernel
2023 * buffer provided is not large enough to hold the string, the
2024 * string is truncated. The copied string is %NULL-terminated.
2025 * If the string is being read by the user process, it is copied
2026 * and a newline '\n' is added. It is truncated if the buffer is
2029 * Returns 0 on success.
2031 int proc_dostring(struct ctl_table
*table
, int write
,
2032 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2035 proc_first_pos_non_zero_ignore(ppos
, table
);
2037 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2038 (char __user
*)buffer
, lenp
, ppos
);
2041 static size_t proc_skip_spaces(char **buf
)
2044 char *tmp
= skip_spaces(*buf
);
2050 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2061 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2064 * @cp: kernel buffer containing the string to parse
2065 * @endp: pointer to store the trailing characters
2066 * @base: the base to use
2067 * @res: where the parsed integer will be stored
2069 * In case of success 0 is returned and @res will contain the parsed integer,
2070 * @endp will hold any trailing characters.
2071 * This function will fail the parse on overflow. If there wasn't an overflow
2072 * the function will defer the decision what characters count as invalid to the
2075 static int strtoul_lenient(const char *cp
, char **endp
, unsigned int base
,
2078 unsigned long long result
;
2081 cp
= _parse_integer_fixup_radix(cp
, &base
);
2082 rv
= _parse_integer(cp
, base
, &result
);
2083 if ((rv
& KSTRTOX_OVERFLOW
) || (result
!= (unsigned long)result
))
2091 *res
= (unsigned long)result
;
2095 #define TMPBUFLEN 22
2097 * proc_get_long - reads an ASCII formatted integer from a user buffer
2099 * @buf: a kernel buffer
2100 * @size: size of the kernel buffer
2101 * @val: this is where the number will be stored
2102 * @neg: set to %TRUE if number is negative
2103 * @perm_tr: a vector which contains the allowed trailers
2104 * @perm_tr_len: size of the perm_tr vector
2105 * @tr: pointer to store the trailer character
2107 * In case of success %0 is returned and @buf and @size are updated with
2108 * the amount of bytes read. If @tr is non-NULL and a trailing
2109 * character exists (size is non-zero after returning from this
2110 * function), @tr is updated with the trailing character.
2112 static int proc_get_long(char **buf
, size_t *size
,
2113 unsigned long *val
, bool *neg
,
2114 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2117 char *p
, tmp
[TMPBUFLEN
];
2123 if (len
> TMPBUFLEN
- 1)
2124 len
= TMPBUFLEN
- 1;
2126 memcpy(tmp
, *buf
, len
);
2130 if (*p
== '-' && *size
> 1) {
2138 if (strtoul_lenient(p
, &p
, 0, val
))
2143 /* We don't know if the next char is whitespace thus we may accept
2144 * invalid integers (e.g. 1234...a) or two integers instead of one
2145 * (e.g. 123...1). So lets not allow such large numbers. */
2146 if (len
== TMPBUFLEN
- 1)
2149 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2152 if (tr
&& (len
< *size
))
2162 * proc_put_long - converts an integer to a decimal ASCII formatted string
2164 * @buf: the user buffer
2165 * @size: the size of the user buffer
2166 * @val: the integer to be converted
2167 * @neg: sign of the number, %TRUE for negative
2169 * In case of success %0 is returned and @buf and @size are updated with
2170 * the amount of bytes written.
2172 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2176 char tmp
[TMPBUFLEN
], *p
= tmp
;
2178 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2182 if (copy_to_user(*buf
, tmp
, len
))
2190 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2193 char __user
**buffer
= (char __user
**)buf
;
2194 if (put_user(c
, *buffer
))
2196 (*size
)--, (*buffer
)++;
2202 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2204 int write
, void *data
)
2208 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2212 if (*lvalp
> (unsigned long) INT_MAX
)
2220 *lvalp
= -(unsigned long)val
;
2223 *lvalp
= (unsigned long)val
;
2229 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2231 int write
, void *data
)
2234 if (*lvalp
> UINT_MAX
)
2238 unsigned int val
= *valp
;
2239 *lvalp
= (unsigned long)val
;
2244 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2246 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2247 int write
, void __user
*buffer
,
2248 size_t *lenp
, loff_t
*ppos
,
2249 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2250 int write
, void *data
),
2253 int *i
, vleft
, first
= 1, err
= 0;
2255 char *kbuf
= NULL
, *p
;
2257 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2262 i
= (int *) tbl_data
;
2263 vleft
= table
->maxlen
/ sizeof(*i
);
2267 conv
= do_proc_dointvec_conv
;
2270 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2273 if (left
> PAGE_SIZE
- 1)
2274 left
= PAGE_SIZE
- 1;
2275 p
= kbuf
= memdup_user_nul(buffer
, left
);
2277 return PTR_ERR(kbuf
);
2280 for (; left
&& vleft
--; i
++, first
=0) {
2285 left
-= proc_skip_spaces(&p
);
2289 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2291 sizeof(proc_wspace_sep
), NULL
);
2294 if (conv(&neg
, &lval
, i
, 1, data
)) {
2299 if (conv(&neg
, &lval
, i
, 0, data
)) {
2304 err
= proc_put_char(&buffer
, &left
, '\t');
2307 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2313 if (!write
&& !first
&& left
&& !err
)
2314 err
= proc_put_char(&buffer
, &left
, '\n');
2315 if (write
&& !err
&& left
)
2316 left
-= proc_skip_spaces(&p
);
2320 return err
? : -EINVAL
;
2328 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2329 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2330 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2331 int write
, void *data
),
2334 return __do_proc_dointvec(table
->data
, table
, write
,
2335 buffer
, lenp
, ppos
, conv
, data
);
2338 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2339 struct ctl_table
*table
,
2340 void __user
*buffer
,
2341 size_t *lenp
, loff_t
*ppos
,
2342 int (*conv
)(unsigned long *lvalp
,
2344 int write
, void *data
),
2351 char *kbuf
= NULL
, *p
;
2355 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2358 if (left
> PAGE_SIZE
- 1)
2359 left
= PAGE_SIZE
- 1;
2361 p
= kbuf
= memdup_user_nul(buffer
, left
);
2365 left
-= proc_skip_spaces(&p
);
2371 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2373 sizeof(proc_wspace_sep
), NULL
);
2379 if (conv(&lval
, tbl_data
, 1, data
)) {
2385 left
-= proc_skip_spaces(&p
);
2394 /* This is in keeping with old __do_proc_dointvec() */
2400 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2401 size_t *lenp
, loff_t
*ppos
,
2402 int (*conv
)(unsigned long *lvalp
,
2404 int write
, void *data
),
2413 if (conv(&lval
, tbl_data
, 0, data
)) {
2418 err
= proc_put_long(&buffer
, &left
, lval
, false);
2422 err
= proc_put_char(&buffer
, &left
, '\n');
2431 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2432 int write
, void __user
*buffer
,
2433 size_t *lenp
, loff_t
*ppos
,
2434 int (*conv
)(unsigned long *lvalp
,
2436 int write
, void *data
),
2439 unsigned int *i
, vleft
;
2441 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2446 i
= (unsigned int *) tbl_data
;
2447 vleft
= table
->maxlen
/ sizeof(*i
);
2450 * Arrays are not supported, keep this simple. *Do not* add
2459 conv
= do_proc_douintvec_conv
;
2462 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2464 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2467 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2468 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2469 int (*conv
)(unsigned long *lvalp
,
2471 int write
, void *data
),
2474 return __do_proc_douintvec(table
->data
, table
, write
,
2475 buffer
, lenp
, ppos
, conv
, data
);
2479 * proc_dointvec - read a vector of integers
2480 * @table: the sysctl table
2481 * @write: %TRUE if this is a write to the sysctl file
2482 * @buffer: the user buffer
2483 * @lenp: the size of the user buffer
2484 * @ppos: file position
2486 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2487 * values from/to the user buffer, treated as an ASCII string.
2489 * Returns 0 on success.
2491 int proc_dointvec(struct ctl_table
*table
, int write
,
2492 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2494 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2498 * proc_douintvec - read a vector of unsigned integers
2499 * @table: the sysctl table
2500 * @write: %TRUE if this is a write to the sysctl file
2501 * @buffer: the user buffer
2502 * @lenp: the size of the user buffer
2503 * @ppos: file position
2505 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2506 * values from/to the user buffer, treated as an ASCII string.
2508 * Returns 0 on success.
2510 int proc_douintvec(struct ctl_table
*table
, int write
,
2511 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2513 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2514 do_proc_douintvec_conv
, NULL
);
2518 * Taint values can only be increased
2519 * This means we can safely use a temporary.
2521 static int proc_taint(struct ctl_table
*table
, int write
,
2522 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2525 unsigned long tmptaint
= get_taint();
2528 if (write
&& !capable(CAP_SYS_ADMIN
))
2533 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2539 * Poor man's atomic or. Not worth adding a primitive
2540 * to everyone's atomic.h for this
2543 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2544 if ((tmptaint
>> i
) & 1)
2545 add_taint(i
, LOCKDEP_STILL_OK
);
2552 #ifdef CONFIG_PRINTK
2553 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2554 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2556 if (write
&& !capable(CAP_SYS_ADMIN
))
2559 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2563 struct do_proc_dointvec_minmax_conv_param
{
2568 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2570 int write
, void *data
)
2572 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2574 int val
= *negp
? -*lvalp
: *lvalp
;
2575 if ((param
->min
&& *param
->min
> val
) ||
2576 (param
->max
&& *param
->max
< val
))
2583 *lvalp
= -(unsigned long)val
;
2586 *lvalp
= (unsigned long)val
;
2593 * proc_dointvec_minmax - read a vector of integers with min/max values
2594 * @table: the sysctl table
2595 * @write: %TRUE if this is a write to the sysctl file
2596 * @buffer: the user buffer
2597 * @lenp: the size of the user buffer
2598 * @ppos: file position
2600 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2601 * values from/to the user buffer, treated as an ASCII string.
2603 * This routine will ensure the values are within the range specified by
2604 * table->extra1 (min) and table->extra2 (max).
2606 * Returns 0 on success.
2608 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2609 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2611 struct do_proc_dointvec_minmax_conv_param param
= {
2612 .min
= (int *) table
->extra1
,
2613 .max
= (int *) table
->extra2
,
2615 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2616 do_proc_dointvec_minmax_conv
, ¶m
);
2619 struct do_proc_douintvec_minmax_conv_param
{
2624 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2626 int write
, void *data
)
2628 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2631 unsigned int val
= *lvalp
;
2633 if (*lvalp
> UINT_MAX
)
2636 if ((param
->min
&& *param
->min
> val
) ||
2637 (param
->max
&& *param
->max
< val
))
2642 unsigned int val
= *valp
;
2643 *lvalp
= (unsigned long) val
;
2650 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2651 * @table: the sysctl table
2652 * @write: %TRUE if this is a write to the sysctl file
2653 * @buffer: the user buffer
2654 * @lenp: the size of the user buffer
2655 * @ppos: file position
2657 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2658 * values from/to the user buffer, treated as an ASCII string. Negative
2659 * strings are not allowed.
2661 * This routine will ensure the values are within the range specified by
2662 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2663 * check for UINT_MAX to avoid having to support wrap around uses from
2666 * Returns 0 on success.
2668 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2669 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2671 struct do_proc_douintvec_minmax_conv_param param
= {
2672 .min
= (unsigned int *) table
->extra1
,
2673 .max
= (unsigned int *) table
->extra2
,
2675 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2676 do_proc_douintvec_minmax_conv
, ¶m
);
2679 struct do_proc_dopipe_max_size_conv_param
{
2683 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp
,
2685 int write
, void *data
)
2687 struct do_proc_dopipe_max_size_conv_param
*param
= data
;
2692 if (*lvalp
> UINT_MAX
)
2695 val
= round_pipe_size(*lvalp
);
2699 if (param
->min
&& *param
->min
> val
)
2704 unsigned int val
= *valp
;
2705 *lvalp
= (unsigned long) val
;
2711 int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
2712 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2714 struct do_proc_dopipe_max_size_conv_param param
= {
2715 .min
= (unsigned int *) table
->extra1
,
2717 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2718 do_proc_dopipe_max_size_conv
, ¶m
);
2721 static void validate_coredump_safety(void)
2723 #ifdef CONFIG_COREDUMP
2724 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2725 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2727 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2728 "Pipe handler or fully qualified core dump path required.\n"
2729 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2735 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2736 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2738 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2740 validate_coredump_safety();
2744 #ifdef CONFIG_COREDUMP
2745 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2746 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2748 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2750 validate_coredump_safety();
2755 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2756 void __user
*buffer
,
2757 size_t *lenp
, loff_t
*ppos
,
2758 unsigned long convmul
,
2759 unsigned long convdiv
)
2761 unsigned long *i
, *min
, *max
;
2762 int vleft
, first
= 1, err
= 0;
2764 char *kbuf
= NULL
, *p
;
2766 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2771 i
= (unsigned long *) data
;
2772 min
= (unsigned long *) table
->extra1
;
2773 max
= (unsigned long *) table
->extra2
;
2774 vleft
= table
->maxlen
/ sizeof(unsigned long);
2778 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2781 if (left
> PAGE_SIZE
- 1)
2782 left
= PAGE_SIZE
- 1;
2783 p
= kbuf
= memdup_user_nul(buffer
, left
);
2785 return PTR_ERR(kbuf
);
2788 for (; left
&& vleft
--; i
++, first
= 0) {
2794 left
-= proc_skip_spaces(&p
);
2796 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2798 sizeof(proc_wspace_sep
), NULL
);
2803 val
= convmul
* val
/ convdiv
;
2804 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2808 val
= convdiv
* (*i
) / convmul
;
2810 err
= proc_put_char(&buffer
, &left
, '\t');
2814 err
= proc_put_long(&buffer
, &left
, val
, false);
2820 if (!write
&& !first
&& left
&& !err
)
2821 err
= proc_put_char(&buffer
, &left
, '\n');
2823 left
-= proc_skip_spaces(&p
);
2827 return err
? : -EINVAL
;
2835 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2836 void __user
*buffer
,
2837 size_t *lenp
, loff_t
*ppos
,
2838 unsigned long convmul
,
2839 unsigned long convdiv
)
2841 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2842 buffer
, lenp
, ppos
, convmul
, convdiv
);
2846 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2847 * @table: the sysctl table
2848 * @write: %TRUE if this is a write to the sysctl file
2849 * @buffer: the user buffer
2850 * @lenp: the size of the user buffer
2851 * @ppos: file position
2853 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2854 * values from/to the user buffer, treated as an ASCII string.
2856 * This routine will ensure the values are within the range specified by
2857 * table->extra1 (min) and table->extra2 (max).
2859 * Returns 0 on success.
2861 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2862 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2864 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2868 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2869 * @table: the sysctl table
2870 * @write: %TRUE if this is a write to the sysctl file
2871 * @buffer: the user buffer
2872 * @lenp: the size of the user buffer
2873 * @ppos: file position
2875 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2876 * values from/to the user buffer, treated as an ASCII string. The values
2877 * are treated as milliseconds, and converted to jiffies when they are stored.
2879 * This routine will ensure the values are within the range specified by
2880 * table->extra1 (min) and table->extra2 (max).
2882 * Returns 0 on success.
2884 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2885 void __user
*buffer
,
2886 size_t *lenp
, loff_t
*ppos
)
2888 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2889 lenp
, ppos
, HZ
, 1000l);
2893 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2895 int write
, void *data
)
2898 if (*lvalp
> INT_MAX
/ HZ
)
2900 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2906 lval
= -(unsigned long)val
;
2909 lval
= (unsigned long)val
;
2916 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2918 int write
, void *data
)
2921 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2923 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2929 lval
= -(unsigned long)val
;
2932 lval
= (unsigned long)val
;
2934 *lvalp
= jiffies_to_clock_t(lval
);
2939 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2941 int write
, void *data
)
2944 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2954 lval
= -(unsigned long)val
;
2957 lval
= (unsigned long)val
;
2959 *lvalp
= jiffies_to_msecs(lval
);
2965 * proc_dointvec_jiffies - read a vector of integers as seconds
2966 * @table: the sysctl table
2967 * @write: %TRUE if this is a write to the sysctl file
2968 * @buffer: the user buffer
2969 * @lenp: the size of the user buffer
2970 * @ppos: file position
2972 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2973 * values from/to the user buffer, treated as an ASCII string.
2974 * The values read are assumed to be in seconds, and are converted into
2977 * Returns 0 on success.
2979 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2980 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2982 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2983 do_proc_dointvec_jiffies_conv
,NULL
);
2987 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2988 * @table: the sysctl table
2989 * @write: %TRUE if this is a write to the sysctl file
2990 * @buffer: the user buffer
2991 * @lenp: the size of the user buffer
2992 * @ppos: pointer to the file position
2994 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2995 * values from/to the user buffer, treated as an ASCII string.
2996 * The values read are assumed to be in 1/USER_HZ seconds, and
2997 * are converted into jiffies.
2999 * Returns 0 on success.
3001 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3002 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3004 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3005 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
3009 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3010 * @table: the sysctl table
3011 * @write: %TRUE if this is a write to the sysctl file
3012 * @buffer: the user buffer
3013 * @lenp: the size of the user buffer
3014 * @ppos: file position
3015 * @ppos: the current position in the file
3017 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3018 * values from/to the user buffer, treated as an ASCII string.
3019 * The values read are assumed to be in 1/1000 seconds, and
3020 * are converted into jiffies.
3022 * Returns 0 on success.
3024 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3025 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3027 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
3028 do_proc_dointvec_ms_jiffies_conv
, NULL
);
3031 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3032 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3034 struct pid
*new_pid
;
3038 tmp
= pid_vnr(cad_pid
);
3040 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3041 lenp
, ppos
, NULL
, NULL
);
3045 new_pid
= find_get_pid(tmp
);
3049 put_pid(xchg(&cad_pid
, new_pid
));
3054 * proc_do_large_bitmap - read/write from/to a large bitmap
3055 * @table: the sysctl table
3056 * @write: %TRUE if this is a write to the sysctl file
3057 * @buffer: the user buffer
3058 * @lenp: the size of the user buffer
3059 * @ppos: file position
3061 * The bitmap is stored at table->data and the bitmap length (in bits)
3064 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3065 * large bitmaps may be represented in a compact manner. Writing into
3066 * the file will clear the bitmap then update it with the given input.
3068 * Returns 0 on success.
3070 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3071 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3075 size_t left
= *lenp
;
3076 unsigned long bitmap_len
= table
->maxlen
;
3077 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3078 unsigned long *tmp_bitmap
= NULL
;
3079 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3081 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3089 if (left
> PAGE_SIZE
- 1)
3090 left
= PAGE_SIZE
- 1;
3092 p
= kbuf
= memdup_user_nul(buffer
, left
);
3094 return PTR_ERR(kbuf
);
3096 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
3102 proc_skip_char(&p
, &left
, '\n');
3103 while (!err
&& left
) {
3104 unsigned long val_a
, val_b
;
3107 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3111 if (val_a
>= bitmap_len
|| neg
) {
3123 err
= proc_get_long(&p
, &left
, &val_b
,
3124 &neg
, tr_b
, sizeof(tr_b
),
3128 if (val_b
>= bitmap_len
|| neg
||
3139 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3141 proc_skip_char(&p
, &left
, '\n');
3145 unsigned long bit_a
, bit_b
= 0;
3148 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3149 if (bit_a
>= bitmap_len
)
3151 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3155 err
= proc_put_char(&buffer
, &left
, ',');
3159 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3162 if (bit_a
!= bit_b
) {
3163 err
= proc_put_char(&buffer
, &left
, '-');
3166 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3174 err
= proc_put_char(&buffer
, &left
, '\n');
3180 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3182 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3192 #else /* CONFIG_PROC_SYSCTL */
3194 int proc_dostring(struct ctl_table
*table
, int write
,
3195 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3200 int proc_dointvec(struct ctl_table
*table
, int write
,
3201 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3206 int proc_douintvec(struct ctl_table
*table
, int write
,
3207 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3212 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3213 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3218 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3219 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3224 int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
3225 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3230 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3231 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3236 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3237 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3242 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3243 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3248 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3249 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3254 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3255 void __user
*buffer
,
3256 size_t *lenp
, loff_t
*ppos
)
3262 #endif /* CONFIG_PROC_SYSCTL */
3265 * No sense putting this after each symbol definition, twice,
3266 * exception granted :-)
3268 EXPORT_SYMBOL(proc_dointvec
);
3269 EXPORT_SYMBOL(proc_douintvec
);
3270 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3271 EXPORT_SYMBOL(proc_dointvec_minmax
);
3272 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3273 EXPORT_SYMBOL_GPL(proc_dopipe_max_size
);
3274 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3275 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3276 EXPORT_SYMBOL(proc_dostring
);
3277 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3278 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);