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 unsigned long long_max
= LONG_MAX
;
130 static int one_hundred
= 100;
131 static int one_thousand
= 1000;
133 static int ten_thousand
= 10000;
135 #ifdef CONFIG_PERF_EVENTS
136 static int six_hundred_forty_kb
= 640 * 1024;
139 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
140 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
142 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
143 static int maxolduid
= 65535;
144 static int minolduid
;
146 static int ngroups_max
= NGROUPS_MAX
;
147 static const int cap_last_cap
= CAP_LAST_CAP
;
149 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
150 #ifdef CONFIG_DETECT_HUNG_TASK
151 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
154 #ifdef CONFIG_INOTIFY_USER
155 #include <linux/inotify.h>
161 extern int pwrsw_enabled
;
164 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
165 extern int unaligned_enabled
;
169 extern int unaligned_dump_stack
;
172 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
173 extern int no_unaligned_warning
;
176 #ifdef CONFIG_PROC_SYSCTL
179 * enum sysctl_writes_mode - supported sysctl write modes
181 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
182 * to be written, and multiple writes on the same sysctl file descriptor
183 * will rewrite the sysctl value, regardless of file position. No warning
184 * is issued when the initial position is not 0.
185 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
187 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
188 * file position 0 and the value must be fully contained in the buffer
189 * sent to the write syscall. If dealing with strings respect the file
190 * position, but restrict this to the max length of the buffer, anything
191 * passed the max lenght will be ignored. Multiple writes will append
194 * These write modes control how current file position affects the behavior of
195 * updating sysctl values through the proc interface on each write.
197 enum sysctl_writes_mode
{
198 SYSCTL_WRITES_LEGACY
= -1,
199 SYSCTL_WRITES_WARN
= 0,
200 SYSCTL_WRITES_STRICT
= 1,
203 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
205 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
206 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
207 static int proc_taint(struct ctl_table
*table
, int write
,
208 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
212 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
213 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
216 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
217 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
218 #ifdef CONFIG_COREDUMP
219 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
220 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
223 #ifdef CONFIG_MAGIC_SYSRQ
224 /* Note: sysrq code uses it's own private copy */
225 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
227 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
228 void __user
*buffer
, size_t *lenp
,
233 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
238 sysrq_toggle_support(__sysrq_enabled
);
245 static struct ctl_table kern_table
[];
246 static struct ctl_table vm_table
[];
247 static struct ctl_table fs_table
[];
248 static struct ctl_table debug_table
[];
249 static struct ctl_table dev_table
[];
250 extern struct ctl_table random_table
[];
252 extern struct ctl_table epoll_table
[];
255 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
256 int sysctl_legacy_va_layout
;
259 /* The default sysctl tables: */
261 static struct ctl_table sysctl_base_table
[] = {
263 .procname
= "kernel",
280 .child
= debug_table
,
290 #ifdef CONFIG_SCHED_DEBUG
291 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
292 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
293 static int min_wakeup_granularity_ns
; /* 0 usecs */
294 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
296 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
297 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
298 #endif /* CONFIG_SMP */
299 #endif /* CONFIG_SCHED_DEBUG */
301 #ifdef CONFIG_COMPACTION
302 static int min_extfrag_threshold
;
303 static int max_extfrag_threshold
= 1000;
306 static struct ctl_table kern_table
[] = {
308 .procname
= "sched_child_runs_first",
309 .data
= &sysctl_sched_child_runs_first
,
310 .maxlen
= sizeof(unsigned int),
312 .proc_handler
= proc_dointvec
,
314 #ifdef CONFIG_SCHED_DEBUG
316 .procname
= "sched_min_granularity_ns",
317 .data
= &sysctl_sched_min_granularity
,
318 .maxlen
= sizeof(unsigned int),
320 .proc_handler
= sched_proc_update_handler
,
321 .extra1
= &min_sched_granularity_ns
,
322 .extra2
= &max_sched_granularity_ns
,
325 .procname
= "sched_latency_ns",
326 .data
= &sysctl_sched_latency
,
327 .maxlen
= sizeof(unsigned int),
329 .proc_handler
= sched_proc_update_handler
,
330 .extra1
= &min_sched_granularity_ns
,
331 .extra2
= &max_sched_granularity_ns
,
333 #ifdef CONFIG_SCHED_WALT
335 .procname
= "sched_use_walt_cpu_util",
336 .data
= &sysctl_sched_use_walt_cpu_util
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= proc_dointvec
,
342 .procname
= "sched_use_walt_task_util",
343 .data
= &sysctl_sched_use_walt_task_util
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= proc_dointvec
,
349 .procname
= "sched_walt_init_task_load_pct",
350 .data
= &sysctl_sched_walt_init_task_load_pct
,
351 .maxlen
= sizeof(unsigned int),
353 .proc_handler
= proc_dointvec
,
356 .procname
= "sched_walt_cpu_high_irqload",
357 .data
= &sysctl_sched_walt_cpu_high_irqload
,
358 .maxlen
= sizeof(unsigned int),
360 .proc_handler
= proc_dointvec
,
364 .procname
= "sched_sync_hint_enable",
365 .data
= &sysctl_sched_sync_hint_enable
,
366 .maxlen
= sizeof(unsigned int),
368 .proc_handler
= proc_dointvec
,
371 .procname
= "sched_cstate_aware",
372 .data
= &sysctl_sched_cstate_aware
,
373 .maxlen
= sizeof(unsigned int),
375 .proc_handler
= proc_dointvec
,
378 .procname
= "sched_wakeup_granularity_ns",
379 .data
= &sysctl_sched_wakeup_granularity
,
380 .maxlen
= sizeof(unsigned int),
382 .proc_handler
= sched_proc_update_handler
,
383 .extra1
= &min_wakeup_granularity_ns
,
384 .extra2
= &max_wakeup_granularity_ns
,
388 .procname
= "sched_tunable_scaling",
389 .data
= &sysctl_sched_tunable_scaling
,
390 .maxlen
= sizeof(enum sched_tunable_scaling
),
392 .proc_handler
= sched_proc_update_handler
,
393 .extra1
= &min_sched_tunable_scaling
,
394 .extra2
= &max_sched_tunable_scaling
,
397 .procname
= "sched_migration_cost_ns",
398 .data
= &sysctl_sched_migration_cost
,
399 .maxlen
= sizeof(unsigned int),
401 .proc_handler
= proc_dointvec
,
404 .procname
= "sched_nr_migrate",
405 .data
= &sysctl_sched_nr_migrate
,
406 .maxlen
= sizeof(unsigned int),
408 .proc_handler
= proc_dointvec
,
411 .procname
= "sched_time_avg_ms",
412 .data
= &sysctl_sched_time_avg
,
413 .maxlen
= sizeof(unsigned int),
415 .proc_handler
= proc_dointvec_minmax
,
418 #ifdef CONFIG_SCHEDSTATS
420 .procname
= "sched_schedstats",
422 .maxlen
= sizeof(unsigned int),
424 .proc_handler
= sysctl_schedstats
,
428 #endif /* CONFIG_SCHEDSTATS */
429 #endif /* CONFIG_SMP */
430 #ifdef CONFIG_NUMA_BALANCING
432 .procname
= "numa_balancing_scan_delay_ms",
433 .data
= &sysctl_numa_balancing_scan_delay
,
434 .maxlen
= sizeof(unsigned int),
436 .proc_handler
= proc_dointvec
,
439 .procname
= "numa_balancing_scan_period_min_ms",
440 .data
= &sysctl_numa_balancing_scan_period_min
,
441 .maxlen
= sizeof(unsigned int),
443 .proc_handler
= proc_dointvec
,
446 .procname
= "numa_balancing_scan_period_max_ms",
447 .data
= &sysctl_numa_balancing_scan_period_max
,
448 .maxlen
= sizeof(unsigned int),
450 .proc_handler
= proc_dointvec
,
453 .procname
= "numa_balancing_scan_size_mb",
454 .data
= &sysctl_numa_balancing_scan_size
,
455 .maxlen
= sizeof(unsigned int),
457 .proc_handler
= proc_dointvec_minmax
,
461 .procname
= "numa_balancing",
462 .data
= NULL
, /* filled in by handler */
463 .maxlen
= sizeof(unsigned int),
465 .proc_handler
= sysctl_numa_balancing
,
469 #endif /* CONFIG_NUMA_BALANCING */
470 #endif /* CONFIG_SCHED_DEBUG */
472 .procname
= "sched_rt_period_us",
473 .data
= &sysctl_sched_rt_period
,
474 .maxlen
= sizeof(unsigned int),
476 .proc_handler
= sched_rt_handler
,
479 .procname
= "sched_rt_runtime_us",
480 .data
= &sysctl_sched_rt_runtime
,
481 .maxlen
= sizeof(int),
483 .proc_handler
= sched_rt_handler
,
486 .procname
= "sched_rr_timeslice_ms",
487 .data
= &sysctl_sched_rr_timeslice
,
488 .maxlen
= sizeof(int),
490 .proc_handler
= sched_rr_handler
,
492 #ifdef CONFIG_SCHED_AUTOGROUP
494 .procname
= "sched_autogroup_enabled",
495 .data
= &sysctl_sched_autogroup_enabled
,
496 .maxlen
= sizeof(unsigned int),
498 .proc_handler
= proc_dointvec_minmax
,
503 #ifdef CONFIG_CFS_BANDWIDTH
505 .procname
= "sched_cfs_bandwidth_slice_us",
506 .data
= &sysctl_sched_cfs_bandwidth_slice
,
507 .maxlen
= sizeof(unsigned int),
509 .proc_handler
= proc_dointvec_minmax
,
513 #ifdef CONFIG_PROVE_LOCKING
515 .procname
= "prove_locking",
516 .data
= &prove_locking
,
517 .maxlen
= sizeof(int),
519 .proc_handler
= proc_dointvec
,
522 #ifdef CONFIG_LOCK_STAT
524 .procname
= "lock_stat",
526 .maxlen
= sizeof(int),
528 .proc_handler
= proc_dointvec
,
533 .data
= &panic_timeout
,
534 .maxlen
= sizeof(int),
536 .proc_handler
= proc_dointvec
,
538 #ifdef CONFIG_COREDUMP
540 .procname
= "core_uses_pid",
541 .data
= &core_uses_pid
,
542 .maxlen
= sizeof(int),
544 .proc_handler
= proc_dointvec
,
547 .procname
= "core_pattern",
548 .data
= core_pattern
,
549 .maxlen
= CORENAME_MAX_SIZE
,
551 .proc_handler
= proc_dostring_coredump
,
554 .procname
= "core_pipe_limit",
555 .data
= &core_pipe_limit
,
556 .maxlen
= sizeof(unsigned int),
558 .proc_handler
= proc_dointvec
,
561 #ifdef CONFIG_PROC_SYSCTL
563 .procname
= "tainted",
564 .maxlen
= sizeof(long),
566 .proc_handler
= proc_taint
,
569 .procname
= "sysctl_writes_strict",
570 .data
= &sysctl_writes_strict
,
571 .maxlen
= sizeof(int),
573 .proc_handler
= proc_dointvec_minmax
,
578 #ifdef CONFIG_LATENCYTOP
580 .procname
= "latencytop",
581 .data
= &latencytop_enabled
,
582 .maxlen
= sizeof(int),
584 .proc_handler
= sysctl_latencytop
,
587 #ifdef CONFIG_BLK_DEV_INITRD
589 .procname
= "real-root-dev",
590 .data
= &real_root_dev
,
591 .maxlen
= sizeof(int),
593 .proc_handler
= proc_dointvec
,
597 .procname
= "print-fatal-signals",
598 .data
= &print_fatal_signals
,
599 .maxlen
= sizeof(int),
601 .proc_handler
= proc_dointvec
,
605 .procname
= "reboot-cmd",
606 .data
= reboot_command
,
609 .proc_handler
= proc_dostring
,
612 .procname
= "stop-a",
613 .data
= &stop_a_enabled
,
614 .maxlen
= sizeof (int),
616 .proc_handler
= proc_dointvec
,
619 .procname
= "scons-poweroff",
620 .data
= &scons_pwroff
,
621 .maxlen
= sizeof (int),
623 .proc_handler
= proc_dointvec
,
626 #ifdef CONFIG_SPARC64
628 .procname
= "tsb-ratio",
629 .data
= &sysctl_tsb_ratio
,
630 .maxlen
= sizeof (int),
632 .proc_handler
= proc_dointvec
,
637 .procname
= "soft-power",
638 .data
= &pwrsw_enabled
,
639 .maxlen
= sizeof (int),
641 .proc_handler
= proc_dointvec
,
644 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
646 .procname
= "unaligned-trap",
647 .data
= &unaligned_enabled
,
648 .maxlen
= sizeof (int),
650 .proc_handler
= proc_dointvec
,
654 .procname
= "ctrl-alt-del",
656 .maxlen
= sizeof(int),
658 .proc_handler
= proc_dointvec
,
660 #ifdef CONFIG_FUNCTION_TRACER
662 .procname
= "ftrace_enabled",
663 .data
= &ftrace_enabled
,
664 .maxlen
= sizeof(int),
666 .proc_handler
= ftrace_enable_sysctl
,
669 #ifdef CONFIG_STACK_TRACER
671 .procname
= "stack_tracer_enabled",
672 .data
= &stack_tracer_enabled
,
673 .maxlen
= sizeof(int),
675 .proc_handler
= stack_trace_sysctl
,
678 #ifdef CONFIG_TRACING
680 .procname
= "ftrace_dump_on_oops",
681 .data
= &ftrace_dump_on_oops
,
682 .maxlen
= sizeof(int),
684 .proc_handler
= proc_dointvec
,
687 .procname
= "traceoff_on_warning",
688 .data
= &__disable_trace_on_warning
,
689 .maxlen
= sizeof(__disable_trace_on_warning
),
691 .proc_handler
= proc_dointvec
,
694 .procname
= "tracepoint_printk",
695 .data
= &tracepoint_printk
,
696 .maxlen
= sizeof(tracepoint_printk
),
698 .proc_handler
= tracepoint_printk_sysctl
,
701 #ifdef CONFIG_KEXEC_CORE
703 .procname
= "kexec_load_disabled",
704 .data
= &kexec_load_disabled
,
705 .maxlen
= sizeof(int),
707 /* only handle a transition from default "0" to "1" */
708 .proc_handler
= proc_dointvec_minmax
,
713 #ifdef CONFIG_MODULES
715 .procname
= "modprobe",
716 .data
= &modprobe_path
,
717 .maxlen
= KMOD_PATH_LEN
,
719 .proc_handler
= proc_dostring
,
722 .procname
= "modules_disabled",
723 .data
= &modules_disabled
,
724 .maxlen
= sizeof(int),
726 /* only handle a transition from default "0" to "1" */
727 .proc_handler
= proc_dointvec_minmax
,
732 #ifdef CONFIG_UEVENT_HELPER
734 .procname
= "hotplug",
735 .data
= &uevent_helper
,
736 .maxlen
= UEVENT_HELPER_PATH_LEN
,
738 .proc_handler
= proc_dostring
,
741 #ifdef CONFIG_CHR_DEV_SG
743 .procname
= "sg-big-buff",
744 .data
= &sg_big_buff
,
745 .maxlen
= sizeof (int),
747 .proc_handler
= proc_dointvec
,
750 #ifdef CONFIG_BSD_PROCESS_ACCT
754 .maxlen
= 3*sizeof(int),
756 .proc_handler
= proc_dointvec
,
759 #ifdef CONFIG_MAGIC_SYSRQ
762 .data
= &__sysrq_enabled
,
763 .maxlen
= sizeof (int),
765 .proc_handler
= sysrq_sysctl_handler
,
768 #ifdef CONFIG_PROC_SYSCTL
770 .procname
= "cad_pid",
772 .maxlen
= sizeof (int),
774 .proc_handler
= proc_do_cad_pid
,
778 .procname
= "threads-max",
780 .maxlen
= sizeof(int),
782 .proc_handler
= sysctl_max_threads
,
785 .procname
= "random",
787 .child
= random_table
,
790 .procname
= "usermodehelper",
792 .child
= usermodehelper_table
,
795 .procname
= "overflowuid",
796 .data
= &overflowuid
,
797 .maxlen
= sizeof(int),
799 .proc_handler
= proc_dointvec_minmax
,
800 .extra1
= &minolduid
,
801 .extra2
= &maxolduid
,
804 .procname
= "overflowgid",
805 .data
= &overflowgid
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= proc_dointvec_minmax
,
809 .extra1
= &minolduid
,
810 .extra2
= &maxolduid
,
813 #ifdef CONFIG_MATHEMU
815 .procname
= "ieee_emulation_warnings",
816 .data
= &sysctl_ieee_emulation_warnings
,
817 .maxlen
= sizeof(int),
819 .proc_handler
= proc_dointvec
,
823 .procname
= "userprocess_debug",
824 .data
= &show_unhandled_signals
,
825 .maxlen
= sizeof(int),
827 .proc_handler
= proc_dointvec
,
831 .procname
= "pid_max",
833 .maxlen
= sizeof (int),
835 .proc_handler
= proc_dointvec_minmax
,
836 .extra1
= &pid_max_min
,
837 .extra2
= &pid_max_max
,
840 .procname
= "panic_on_oops",
841 .data
= &panic_on_oops
,
842 .maxlen
= sizeof(int),
844 .proc_handler
= proc_dointvec
,
846 #if defined CONFIG_PRINTK
848 .procname
= "printk",
849 .data
= &console_loglevel
,
850 .maxlen
= 4*sizeof(int),
852 .proc_handler
= proc_dointvec
,
855 .procname
= "printk_ratelimit",
856 .data
= &printk_ratelimit_state
.interval
,
857 .maxlen
= sizeof(int),
859 .proc_handler
= proc_dointvec_jiffies
,
862 .procname
= "printk_ratelimit_burst",
863 .data
= &printk_ratelimit_state
.burst
,
864 .maxlen
= sizeof(int),
866 .proc_handler
= proc_dointvec
,
869 .procname
= "printk_delay",
870 .data
= &printk_delay_msec
,
871 .maxlen
= sizeof(int),
873 .proc_handler
= proc_dointvec_minmax
,
875 .extra2
= &ten_thousand
,
878 .procname
= "printk_devkmsg",
879 .data
= devkmsg_log_str
,
880 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
882 .proc_handler
= devkmsg_sysctl_set_loglvl
,
885 .procname
= "dmesg_restrict",
886 .data
= &dmesg_restrict
,
887 .maxlen
= sizeof(int),
889 .proc_handler
= proc_dointvec_minmax_sysadmin
,
894 .procname
= "kptr_restrict",
895 .data
= &kptr_restrict
,
896 .maxlen
= sizeof(int),
898 .proc_handler
= proc_dointvec_minmax_sysadmin
,
904 .procname
= "ngroups_max",
905 .data
= &ngroups_max
,
906 .maxlen
= sizeof (int),
908 .proc_handler
= proc_dointvec
,
911 .procname
= "cap_last_cap",
912 .data
= (void *)&cap_last_cap
,
913 .maxlen
= sizeof(int),
915 .proc_handler
= proc_dointvec
,
917 #if defined(CONFIG_LOCKUP_DETECTOR)
919 .procname
= "watchdog",
920 .data
= &watchdog_user_enabled
,
921 .maxlen
= sizeof(int),
923 .proc_handler
= proc_watchdog
,
928 .procname
= "watchdog_thresh",
929 .data
= &watchdog_thresh
,
930 .maxlen
= sizeof(int),
932 .proc_handler
= proc_watchdog_thresh
,
937 .procname
= "nmi_watchdog",
938 .data
= &nmi_watchdog_user_enabled
,
939 .maxlen
= sizeof(int),
940 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
941 .proc_handler
= proc_nmi_watchdog
,
946 .procname
= "watchdog_cpumask",
947 .data
= &watchdog_cpumask_bits
,
950 .proc_handler
= proc_watchdog_cpumask
,
952 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
954 .procname
= "soft_watchdog",
955 .data
= &soft_watchdog_user_enabled
,
956 .maxlen
= sizeof(int),
958 .proc_handler
= proc_soft_watchdog
,
963 .procname
= "softlockup_panic",
964 .data
= &softlockup_panic
,
965 .maxlen
= sizeof(int),
967 .proc_handler
= proc_dointvec_minmax
,
973 .procname
= "softlockup_all_cpu_backtrace",
974 .data
= &sysctl_softlockup_all_cpu_backtrace
,
975 .maxlen
= sizeof(int),
977 .proc_handler
= proc_dointvec_minmax
,
981 #endif /* CONFIG_SMP */
983 #ifdef CONFIG_HARDLOCKUP_DETECTOR
985 .procname
= "hardlockup_panic",
986 .data
= &hardlockup_panic
,
987 .maxlen
= sizeof(int),
989 .proc_handler
= proc_dointvec_minmax
,
995 .procname
= "hardlockup_all_cpu_backtrace",
996 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
997 .maxlen
= sizeof(int),
999 .proc_handler
= proc_dointvec_minmax
,
1003 #endif /* CONFIG_SMP */
1007 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1009 .procname
= "unknown_nmi_panic",
1010 .data
= &unknown_nmi_panic
,
1011 .maxlen
= sizeof (int),
1013 .proc_handler
= proc_dointvec
,
1016 #if defined(CONFIG_X86)
1018 .procname
= "panic_on_unrecovered_nmi",
1019 .data
= &panic_on_unrecovered_nmi
,
1020 .maxlen
= sizeof(int),
1022 .proc_handler
= proc_dointvec
,
1025 .procname
= "panic_on_io_nmi",
1026 .data
= &panic_on_io_nmi
,
1027 .maxlen
= sizeof(int),
1029 .proc_handler
= proc_dointvec
,
1031 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1033 .procname
= "panic_on_stackoverflow",
1034 .data
= &sysctl_panic_on_stackoverflow
,
1035 .maxlen
= sizeof(int),
1037 .proc_handler
= proc_dointvec
,
1041 .procname
= "bootloader_type",
1042 .data
= &bootloader_type
,
1043 .maxlen
= sizeof (int),
1045 .proc_handler
= proc_dointvec
,
1048 .procname
= "bootloader_version",
1049 .data
= &bootloader_version
,
1050 .maxlen
= sizeof (int),
1052 .proc_handler
= proc_dointvec
,
1055 .procname
= "io_delay_type",
1056 .data
= &io_delay_type
,
1057 .maxlen
= sizeof(int),
1059 .proc_handler
= proc_dointvec
,
1062 #if defined(CONFIG_MMU)
1064 .procname
= "randomize_va_space",
1065 .data
= &randomize_va_space
,
1066 .maxlen
= sizeof(int),
1068 .proc_handler
= proc_dointvec
,
1071 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1073 .procname
= "spin_retry",
1074 .data
= &spin_retry
,
1075 .maxlen
= sizeof (int),
1077 .proc_handler
= proc_dointvec
,
1080 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1082 .procname
= "acpi_video_flags",
1083 .data
= &acpi_realmode_flags
,
1084 .maxlen
= sizeof (unsigned long),
1086 .proc_handler
= proc_doulongvec_minmax
,
1089 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1091 .procname
= "ignore-unaligned-usertrap",
1092 .data
= &no_unaligned_warning
,
1093 .maxlen
= sizeof (int),
1095 .proc_handler
= proc_dointvec
,
1100 .procname
= "unaligned-dump-stack",
1101 .data
= &unaligned_dump_stack
,
1102 .maxlen
= sizeof (int),
1104 .proc_handler
= proc_dointvec
,
1107 #ifdef CONFIG_DETECT_HUNG_TASK
1109 .procname
= "hung_task_panic",
1110 .data
= &sysctl_hung_task_panic
,
1111 .maxlen
= sizeof(int),
1113 .proc_handler
= proc_dointvec_minmax
,
1118 .procname
= "hung_task_check_count",
1119 .data
= &sysctl_hung_task_check_count
,
1120 .maxlen
= sizeof(int),
1122 .proc_handler
= proc_dointvec_minmax
,
1126 .procname
= "hung_task_timeout_secs",
1127 .data
= &sysctl_hung_task_timeout_secs
,
1128 .maxlen
= sizeof(unsigned long),
1130 .proc_handler
= proc_dohung_task_timeout_secs
,
1131 .extra2
= &hung_task_timeout_max
,
1134 .procname
= "hung_task_warnings",
1135 .data
= &sysctl_hung_task_warnings
,
1136 .maxlen
= sizeof(int),
1138 .proc_handler
= proc_dointvec_minmax
,
1142 #ifdef CONFIG_RT_MUTEXES
1144 .procname
= "max_lock_depth",
1145 .data
= &max_lock_depth
,
1146 .maxlen
= sizeof(int),
1148 .proc_handler
= proc_dointvec
,
1152 .procname
= "poweroff_cmd",
1153 .data
= &poweroff_cmd
,
1154 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1156 .proc_handler
= proc_dostring
,
1162 .child
= key_sysctls
,
1165 #ifdef CONFIG_PERF_EVENTS
1167 * User-space scripts rely on the existence of this file
1168 * as a feature check for perf_events being enabled.
1170 * So it's an ABI, do not remove!
1173 .procname
= "perf_event_paranoid",
1174 .data
= &sysctl_perf_event_paranoid
,
1175 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1177 .proc_handler
= proc_dointvec
,
1180 .procname
= "perf_event_mlock_kb",
1181 .data
= &sysctl_perf_event_mlock
,
1182 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1184 .proc_handler
= proc_dointvec
,
1187 .procname
= "perf_event_max_sample_rate",
1188 .data
= &sysctl_perf_event_sample_rate
,
1189 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1191 .proc_handler
= perf_proc_update_handler
,
1195 .procname
= "perf_cpu_time_max_percent",
1196 .data
= &sysctl_perf_cpu_time_max_percent
,
1197 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1199 .proc_handler
= perf_cpu_time_max_percent_handler
,
1201 .extra2
= &one_hundred
,
1204 .procname
= "perf_event_max_stack",
1205 .data
= &sysctl_perf_event_max_stack
,
1206 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1208 .proc_handler
= perf_event_max_stack_handler
,
1210 .extra2
= &six_hundred_forty_kb
,
1213 .procname
= "perf_event_max_contexts_per_stack",
1214 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1215 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1217 .proc_handler
= perf_event_max_stack_handler
,
1219 .extra2
= &one_thousand
,
1223 .procname
= "panic_on_warn",
1224 .data
= &panic_on_warn
,
1225 .maxlen
= sizeof(int),
1227 .proc_handler
= proc_dointvec_minmax
,
1231 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1233 .procname
= "timer_migration",
1234 .data
= &sysctl_timer_migration
,
1235 .maxlen
= sizeof(unsigned int),
1237 .proc_handler
= timer_migration_handler
,
1242 #ifdef CONFIG_BPF_SYSCALL
1244 .procname
= "unprivileged_bpf_disabled",
1245 .data
= &sysctl_unprivileged_bpf_disabled
,
1246 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1248 /* only handle a transition from default "0" to "1" */
1249 .proc_handler
= proc_dointvec_minmax
,
1254 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1256 .procname
= "panic_on_rcu_stall",
1257 .data
= &sysctl_panic_on_rcu_stall
,
1258 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1260 .proc_handler
= proc_dointvec_minmax
,
1268 static struct ctl_table vm_table
[] = {
1270 .procname
= "overcommit_memory",
1271 .data
= &sysctl_overcommit_memory
,
1272 .maxlen
= sizeof(sysctl_overcommit_memory
),
1274 .proc_handler
= proc_dointvec_minmax
,
1279 .procname
= "panic_on_oom",
1280 .data
= &sysctl_panic_on_oom
,
1281 .maxlen
= sizeof(sysctl_panic_on_oom
),
1283 .proc_handler
= proc_dointvec_minmax
,
1288 .procname
= "oom_kill_allocating_task",
1289 .data
= &sysctl_oom_kill_allocating_task
,
1290 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1292 .proc_handler
= proc_dointvec
,
1295 .procname
= "oom_dump_tasks",
1296 .data
= &sysctl_oom_dump_tasks
,
1297 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1299 .proc_handler
= proc_dointvec
,
1302 .procname
= "overcommit_ratio",
1303 .data
= &sysctl_overcommit_ratio
,
1304 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1306 .proc_handler
= overcommit_ratio_handler
,
1309 .procname
= "overcommit_kbytes",
1310 .data
= &sysctl_overcommit_kbytes
,
1311 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1313 .proc_handler
= overcommit_kbytes_handler
,
1316 .procname
= "page-cluster",
1317 .data
= &page_cluster
,
1318 .maxlen
= sizeof(int),
1320 .proc_handler
= proc_dointvec_minmax
,
1324 .procname
= "dirty_background_ratio",
1325 .data
= &dirty_background_ratio
,
1326 .maxlen
= sizeof(dirty_background_ratio
),
1328 .proc_handler
= dirty_background_ratio_handler
,
1330 .extra2
= &one_hundred
,
1333 .procname
= "dirty_background_bytes",
1334 .data
= &dirty_background_bytes
,
1335 .maxlen
= sizeof(dirty_background_bytes
),
1337 .proc_handler
= dirty_background_bytes_handler
,
1341 .procname
= "dirty_ratio",
1342 .data
= &vm_dirty_ratio
,
1343 .maxlen
= sizeof(vm_dirty_ratio
),
1345 .proc_handler
= dirty_ratio_handler
,
1347 .extra2
= &one_hundred
,
1350 .procname
= "dirty_bytes",
1351 .data
= &vm_dirty_bytes
,
1352 .maxlen
= sizeof(vm_dirty_bytes
),
1354 .proc_handler
= dirty_bytes_handler
,
1355 .extra1
= &dirty_bytes_min
,
1358 .procname
= "dirty_writeback_centisecs",
1359 .data
= &dirty_writeback_interval
,
1360 .maxlen
= sizeof(dirty_writeback_interval
),
1362 .proc_handler
= dirty_writeback_centisecs_handler
,
1365 .procname
= "dirty_expire_centisecs",
1366 .data
= &dirty_expire_interval
,
1367 .maxlen
= sizeof(dirty_expire_interval
),
1369 .proc_handler
= proc_dointvec_minmax
,
1373 .procname
= "dirtytime_expire_seconds",
1374 .data
= &dirtytime_expire_interval
,
1375 .maxlen
= sizeof(dirty_expire_interval
),
1377 .proc_handler
= dirtytime_interval_handler
,
1381 .procname
= "nr_pdflush_threads",
1382 .mode
= 0444 /* read-only */,
1383 .proc_handler
= pdflush_proc_obsolete
,
1386 .procname
= "swappiness",
1387 .data
= &vm_swappiness
,
1388 .maxlen
= sizeof(vm_swappiness
),
1390 .proc_handler
= proc_dointvec_minmax
,
1392 .extra2
= &one_hundred
,
1394 #ifdef CONFIG_HUGETLB_PAGE
1396 .procname
= "nr_hugepages",
1398 .maxlen
= sizeof(unsigned long),
1400 .proc_handler
= hugetlb_sysctl_handler
,
1404 .procname
= "nr_hugepages_mempolicy",
1406 .maxlen
= sizeof(unsigned long),
1408 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1412 .procname
= "hugetlb_shm_group",
1413 .data
= &sysctl_hugetlb_shm_group
,
1414 .maxlen
= sizeof(gid_t
),
1416 .proc_handler
= proc_dointvec
,
1419 .procname
= "hugepages_treat_as_movable",
1420 .data
= &hugepages_treat_as_movable
,
1421 .maxlen
= sizeof(int),
1423 .proc_handler
= proc_dointvec
,
1426 .procname
= "nr_overcommit_hugepages",
1428 .maxlen
= sizeof(unsigned long),
1430 .proc_handler
= hugetlb_overcommit_handler
,
1434 .procname
= "lowmem_reserve_ratio",
1435 .data
= &sysctl_lowmem_reserve_ratio
,
1436 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1438 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1441 .procname
= "drop_caches",
1442 .data
= &sysctl_drop_caches
,
1443 .maxlen
= sizeof(int),
1445 .proc_handler
= drop_caches_sysctl_handler
,
1449 #ifdef CONFIG_COMPACTION
1451 .procname
= "compact_memory",
1452 .data
= &sysctl_compact_memory
,
1453 .maxlen
= sizeof(int),
1455 .proc_handler
= sysctl_compaction_handler
,
1458 .procname
= "extfrag_threshold",
1459 .data
= &sysctl_extfrag_threshold
,
1460 .maxlen
= sizeof(int),
1462 .proc_handler
= sysctl_extfrag_handler
,
1463 .extra1
= &min_extfrag_threshold
,
1464 .extra2
= &max_extfrag_threshold
,
1467 .procname
= "compact_unevictable_allowed",
1468 .data
= &sysctl_compact_unevictable_allowed
,
1469 .maxlen
= sizeof(int),
1471 .proc_handler
= proc_dointvec
,
1476 #endif /* CONFIG_COMPACTION */
1478 .procname
= "min_free_kbytes",
1479 .data
= &min_free_kbytes
,
1480 .maxlen
= sizeof(min_free_kbytes
),
1482 .proc_handler
= min_free_kbytes_sysctl_handler
,
1486 .procname
= "watermark_scale_factor",
1487 .data
= &watermark_scale_factor
,
1488 .maxlen
= sizeof(watermark_scale_factor
),
1490 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1492 .extra2
= &one_thousand
,
1495 .procname
= "extra_free_kbytes",
1496 .data
= &extra_free_kbytes
,
1497 .maxlen
= sizeof(extra_free_kbytes
),
1499 .proc_handler
= min_free_kbytes_sysctl_handler
,
1503 .procname
= "percpu_pagelist_fraction",
1504 .data
= &percpu_pagelist_fraction
,
1505 .maxlen
= sizeof(percpu_pagelist_fraction
),
1507 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1512 .procname
= "max_map_count",
1513 .data
= &sysctl_max_map_count
,
1514 .maxlen
= sizeof(sysctl_max_map_count
),
1516 .proc_handler
= proc_dointvec_minmax
,
1521 .procname
= "nr_trim_pages",
1522 .data
= &sysctl_nr_trim_pages
,
1523 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1525 .proc_handler
= proc_dointvec_minmax
,
1530 .procname
= "laptop_mode",
1531 .data
= &laptop_mode
,
1532 .maxlen
= sizeof(laptop_mode
),
1534 .proc_handler
= proc_dointvec_jiffies
,
1537 .procname
= "block_dump",
1538 .data
= &block_dump
,
1539 .maxlen
= sizeof(block_dump
),
1541 .proc_handler
= proc_dointvec
,
1545 .procname
= "vfs_cache_pressure",
1546 .data
= &sysctl_vfs_cache_pressure
,
1547 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1549 .proc_handler
= proc_dointvec
,
1552 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1554 .procname
= "legacy_va_layout",
1555 .data
= &sysctl_legacy_va_layout
,
1556 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1558 .proc_handler
= proc_dointvec
,
1564 .procname
= "zone_reclaim_mode",
1565 .data
= &node_reclaim_mode
,
1566 .maxlen
= sizeof(node_reclaim_mode
),
1568 .proc_handler
= proc_dointvec
,
1572 .procname
= "min_unmapped_ratio",
1573 .data
= &sysctl_min_unmapped_ratio
,
1574 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1576 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1578 .extra2
= &one_hundred
,
1581 .procname
= "min_slab_ratio",
1582 .data
= &sysctl_min_slab_ratio
,
1583 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1585 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1587 .extra2
= &one_hundred
,
1592 .procname
= "stat_interval",
1593 .data
= &sysctl_stat_interval
,
1594 .maxlen
= sizeof(sysctl_stat_interval
),
1596 .proc_handler
= proc_dointvec_jiffies
,
1599 .procname
= "stat_refresh",
1603 .proc_handler
= vmstat_refresh
,
1608 .procname
= "mmap_min_addr",
1609 .data
= &dac_mmap_min_addr
,
1610 .maxlen
= sizeof(unsigned long),
1612 .proc_handler
= mmap_min_addr_handler
,
1617 .procname
= "numa_zonelist_order",
1618 .data
= &numa_zonelist_order
,
1619 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1621 .proc_handler
= numa_zonelist_order_handler
,
1624 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1625 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1627 .procname
= "vdso_enabled",
1628 #ifdef CONFIG_X86_32
1629 .data
= &vdso32_enabled
,
1630 .maxlen
= sizeof(vdso32_enabled
),
1632 .data
= &vdso_enabled
,
1633 .maxlen
= sizeof(vdso_enabled
),
1636 .proc_handler
= proc_dointvec
,
1640 #ifdef CONFIG_HIGHMEM
1642 .procname
= "highmem_is_dirtyable",
1643 .data
= &vm_highmem_is_dirtyable
,
1644 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1646 .proc_handler
= proc_dointvec_minmax
,
1651 #ifdef CONFIG_MEMORY_FAILURE
1653 .procname
= "memory_failure_early_kill",
1654 .data
= &sysctl_memory_failure_early_kill
,
1655 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1657 .proc_handler
= proc_dointvec_minmax
,
1662 .procname
= "memory_failure_recovery",
1663 .data
= &sysctl_memory_failure_recovery
,
1664 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1666 .proc_handler
= proc_dointvec_minmax
,
1672 .procname
= "user_reserve_kbytes",
1673 .data
= &sysctl_user_reserve_kbytes
,
1674 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1676 .proc_handler
= proc_doulongvec_minmax
,
1679 .procname
= "admin_reserve_kbytes",
1680 .data
= &sysctl_admin_reserve_kbytes
,
1681 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1683 .proc_handler
= proc_doulongvec_minmax
,
1685 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1687 .procname
= "mmap_rnd_bits",
1688 .data
= &mmap_rnd_bits
,
1689 .maxlen
= sizeof(mmap_rnd_bits
),
1691 .proc_handler
= proc_dointvec_minmax
,
1692 .extra1
= (void *)&mmap_rnd_bits_min
,
1693 .extra2
= (void *)&mmap_rnd_bits_max
,
1696 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1698 .procname
= "mmap_rnd_compat_bits",
1699 .data
= &mmap_rnd_compat_bits
,
1700 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1702 .proc_handler
= proc_dointvec_minmax
,
1703 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1704 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1710 static struct ctl_table fs_table
[] = {
1712 .procname
= "inode-nr",
1713 .data
= &inodes_stat
,
1714 .maxlen
= 2*sizeof(long),
1716 .proc_handler
= proc_nr_inodes
,
1719 .procname
= "inode-state",
1720 .data
= &inodes_stat
,
1721 .maxlen
= 7*sizeof(long),
1723 .proc_handler
= proc_nr_inodes
,
1726 .procname
= "file-nr",
1727 .data
= &files_stat
,
1728 .maxlen
= sizeof(files_stat
),
1730 .proc_handler
= proc_nr_files
,
1733 .procname
= "file-max",
1734 .data
= &files_stat
.max_files
,
1735 .maxlen
= sizeof(files_stat
.max_files
),
1737 .proc_handler
= proc_doulongvec_minmax
,
1739 .extra2
= &long_max
,
1742 .procname
= "nr_open",
1743 .data
= &sysctl_nr_open
,
1744 .maxlen
= sizeof(unsigned int),
1746 .proc_handler
= proc_dointvec_minmax
,
1747 .extra1
= &sysctl_nr_open_min
,
1748 .extra2
= &sysctl_nr_open_max
,
1751 .procname
= "dentry-state",
1752 .data
= &dentry_stat
,
1753 .maxlen
= 6*sizeof(long),
1755 .proc_handler
= proc_nr_dentry
,
1758 .procname
= "overflowuid",
1759 .data
= &fs_overflowuid
,
1760 .maxlen
= sizeof(int),
1762 .proc_handler
= proc_dointvec_minmax
,
1763 .extra1
= &minolduid
,
1764 .extra2
= &maxolduid
,
1767 .procname
= "overflowgid",
1768 .data
= &fs_overflowgid
,
1769 .maxlen
= sizeof(int),
1771 .proc_handler
= proc_dointvec_minmax
,
1772 .extra1
= &minolduid
,
1773 .extra2
= &maxolduid
,
1775 #ifdef CONFIG_FILE_LOCKING
1777 .procname
= "leases-enable",
1778 .data
= &leases_enable
,
1779 .maxlen
= sizeof(int),
1781 .proc_handler
= proc_dointvec
,
1784 #ifdef CONFIG_DNOTIFY
1786 .procname
= "dir-notify-enable",
1787 .data
= &dir_notify_enable
,
1788 .maxlen
= sizeof(int),
1790 .proc_handler
= proc_dointvec
,
1794 #ifdef CONFIG_FILE_LOCKING
1796 .procname
= "lease-break-time",
1797 .data
= &lease_break_time
,
1798 .maxlen
= sizeof(int),
1800 .proc_handler
= proc_dointvec
,
1805 .procname
= "aio-nr",
1807 .maxlen
= sizeof(aio_nr
),
1809 .proc_handler
= proc_doulongvec_minmax
,
1812 .procname
= "aio-max-nr",
1813 .data
= &aio_max_nr
,
1814 .maxlen
= sizeof(aio_max_nr
),
1816 .proc_handler
= proc_doulongvec_minmax
,
1818 #endif /* CONFIG_AIO */
1819 #ifdef CONFIG_INOTIFY_USER
1821 .procname
= "inotify",
1823 .child
= inotify_table
,
1828 .procname
= "epoll",
1830 .child
= epoll_table
,
1835 .procname
= "protected_symlinks",
1836 .data
= &sysctl_protected_symlinks
,
1837 .maxlen
= sizeof(int),
1839 .proc_handler
= proc_dointvec_minmax
,
1844 .procname
= "protected_hardlinks",
1845 .data
= &sysctl_protected_hardlinks
,
1846 .maxlen
= sizeof(int),
1848 .proc_handler
= proc_dointvec_minmax
,
1853 .procname
= "protected_fifos",
1854 .data
= &sysctl_protected_fifos
,
1855 .maxlen
= sizeof(int),
1857 .proc_handler
= proc_dointvec_minmax
,
1862 .procname
= "protected_regular",
1863 .data
= &sysctl_protected_regular
,
1864 .maxlen
= sizeof(int),
1866 .proc_handler
= proc_dointvec_minmax
,
1871 .procname
= "suid_dumpable",
1872 .data
= &suid_dumpable
,
1873 .maxlen
= sizeof(int),
1875 .proc_handler
= proc_dointvec_minmax_coredump
,
1879 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1881 .procname
= "binfmt_misc",
1883 .child
= sysctl_mount_point
,
1887 .procname
= "pipe-max-size",
1888 .data
= &pipe_max_size
,
1889 .maxlen
= sizeof(pipe_max_size
),
1891 .proc_handler
= &pipe_proc_fn
,
1892 .extra1
= &pipe_min_size
,
1895 .procname
= "pipe-user-pages-hard",
1896 .data
= &pipe_user_pages_hard
,
1897 .maxlen
= sizeof(pipe_user_pages_hard
),
1899 .proc_handler
= proc_doulongvec_minmax
,
1902 .procname
= "pipe-user-pages-soft",
1903 .data
= &pipe_user_pages_soft
,
1904 .maxlen
= sizeof(pipe_user_pages_soft
),
1906 .proc_handler
= proc_doulongvec_minmax
,
1909 .procname
= "mount-max",
1910 .data
= &sysctl_mount_max
,
1911 .maxlen
= sizeof(unsigned int),
1913 .proc_handler
= proc_dointvec_minmax
,
1919 static struct ctl_table debug_table
[] = {
1920 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1922 .procname
= "exception-trace",
1923 .data
= &show_unhandled_signals
,
1924 .maxlen
= sizeof(int),
1926 .proc_handler
= proc_dointvec
1929 #if defined(CONFIG_OPTPROBES)
1931 .procname
= "kprobes-optimization",
1932 .data
= &sysctl_kprobes_optimization
,
1933 .maxlen
= sizeof(int),
1935 .proc_handler
= proc_kprobes_optimization_handler
,
1943 static struct ctl_table dev_table
[] = {
1947 int __init
sysctl_init(void)
1949 struct ctl_table_header
*hdr
;
1951 hdr
= register_sysctl_table(sysctl_base_table
);
1952 kmemleak_not_leak(hdr
);
1956 #endif /* CONFIG_SYSCTL */
1962 #ifdef CONFIG_PROC_SYSCTL
1964 static int _proc_do_string(char *data
, int maxlen
, int write
,
1965 char __user
*buffer
,
1966 size_t *lenp
, loff_t
*ppos
)
1972 if (!data
|| !maxlen
|| !*lenp
) {
1978 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1979 /* Only continue writes not past the end of buffer. */
1981 if (len
> maxlen
- 1)
1988 /* Start writing from beginning of buffer. */
1994 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1995 if (get_user(c
, p
++))
1997 if (c
== 0 || c
== '\n')
2018 if (copy_to_user(buffer
, data
, len
))
2021 if (put_user('\n', buffer
+ len
))
2031 static void warn_sysctl_write(struct ctl_table
*table
)
2033 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2034 "This will not be supported in the future. To silence this\n"
2035 "warning, set kernel.sysctl_writes_strict = -1\n",
2036 current
->comm
, table
->procname
);
2040 * proc_first_pos_non_zero_ignore - check if firs position is allowed
2041 * @ppos: file position
2042 * @table: the sysctl table
2044 * Returns true if the first position is non-zero and the sysctl_writes_strict
2045 * mode indicates this is not allowed for numeric input types. String proc
2046 * hadlers can ignore the return value.
2048 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2049 struct ctl_table
*table
)
2054 switch (sysctl_writes_strict
) {
2055 case SYSCTL_WRITES_STRICT
:
2057 case SYSCTL_WRITES_WARN
:
2058 warn_sysctl_write(table
);
2066 * proc_dostring - read a string sysctl
2067 * @table: the sysctl table
2068 * @write: %TRUE if this is a write to the sysctl file
2069 * @buffer: the user buffer
2070 * @lenp: the size of the user buffer
2071 * @ppos: file position
2073 * Reads/writes a string from/to the user buffer. If the kernel
2074 * buffer provided is not large enough to hold the string, the
2075 * string is truncated. The copied string is %NULL-terminated.
2076 * If the string is being read by the user process, it is copied
2077 * and a newline '\n' is added. It is truncated if the buffer is
2080 * Returns 0 on success.
2082 int proc_dostring(struct ctl_table
*table
, int write
,
2083 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2086 proc_first_pos_non_zero_ignore(ppos
, table
);
2088 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2089 (char __user
*)buffer
, lenp
, ppos
);
2092 static size_t proc_skip_spaces(char **buf
)
2095 char *tmp
= skip_spaces(*buf
);
2101 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2111 #define TMPBUFLEN 22
2113 * proc_get_long - reads an ASCII formatted integer from a user buffer
2115 * @buf: a kernel buffer
2116 * @size: size of the kernel buffer
2117 * @val: this is where the number will be stored
2118 * @neg: set to %TRUE if number is negative
2119 * @perm_tr: a vector which contains the allowed trailers
2120 * @perm_tr_len: size of the perm_tr vector
2121 * @tr: pointer to store the trailer character
2123 * In case of success %0 is returned and @buf and @size are updated with
2124 * the amount of bytes read. If @tr is non-NULL and a trailing
2125 * character exists (size is non-zero after returning from this
2126 * function), @tr is updated with the trailing character.
2128 static int proc_get_long(char **buf
, size_t *size
,
2129 unsigned long *val
, bool *neg
,
2130 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2133 char *p
, tmp
[TMPBUFLEN
];
2139 if (len
> TMPBUFLEN
- 1)
2140 len
= TMPBUFLEN
- 1;
2142 memcpy(tmp
, *buf
, len
);
2146 if (*p
== '-' && *size
> 1) {
2154 *val
= simple_strtoul(p
, &p
, 0);
2158 /* We don't know if the next char is whitespace thus we may accept
2159 * invalid integers (e.g. 1234...a) or two integers instead of one
2160 * (e.g. 123...1). So lets not allow such large numbers. */
2161 if (len
== TMPBUFLEN
- 1)
2164 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2167 if (tr
&& (len
< *size
))
2177 * proc_put_long - converts an integer to a decimal ASCII formatted string
2179 * @buf: the user buffer
2180 * @size: the size of the user buffer
2181 * @val: the integer to be converted
2182 * @neg: sign of the number, %TRUE for negative
2184 * In case of success %0 is returned and @buf and @size are updated with
2185 * the amount of bytes written.
2187 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2191 char tmp
[TMPBUFLEN
], *p
= tmp
;
2193 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2197 if (copy_to_user(*buf
, tmp
, len
))
2205 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2208 char __user
**buffer
= (char __user
**)buf
;
2209 if (put_user(c
, *buffer
))
2211 (*size
)--, (*buffer
)++;
2217 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2219 int write
, void *data
)
2223 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2227 if (*lvalp
> (unsigned long) INT_MAX
)
2235 *lvalp
= -(unsigned long)val
;
2238 *lvalp
= (unsigned long)val
;
2244 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2246 int write
, void *data
)
2249 if (*lvalp
> UINT_MAX
)
2253 unsigned int val
= *valp
;
2254 *lvalp
= (unsigned long)val
;
2259 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2261 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2262 int write
, void __user
*buffer
,
2263 size_t *lenp
, loff_t
*ppos
,
2264 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2265 int write
, void *data
),
2268 int *i
, vleft
, first
= 1, err
= 0;
2270 char *kbuf
= NULL
, *p
;
2272 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2277 i
= (int *) tbl_data
;
2278 vleft
= table
->maxlen
/ sizeof(*i
);
2282 conv
= do_proc_dointvec_conv
;
2285 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2288 if (left
> PAGE_SIZE
- 1)
2289 left
= PAGE_SIZE
- 1;
2290 p
= kbuf
= memdup_user_nul(buffer
, left
);
2292 return PTR_ERR(kbuf
);
2295 for (; left
&& vleft
--; i
++, first
=0) {
2300 left
-= proc_skip_spaces(&p
);
2304 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2306 sizeof(proc_wspace_sep
), NULL
);
2309 if (conv(&neg
, &lval
, i
, 1, data
)) {
2314 if (conv(&neg
, &lval
, i
, 0, data
)) {
2319 err
= proc_put_char(&buffer
, &left
, '\t');
2322 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2328 if (!write
&& !first
&& left
&& !err
)
2329 err
= proc_put_char(&buffer
, &left
, '\n');
2330 if (write
&& !err
&& left
)
2331 left
-= proc_skip_spaces(&p
);
2335 return err
? : -EINVAL
;
2343 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2344 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2345 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2346 int write
, void *data
),
2349 return __do_proc_dointvec(table
->data
, table
, write
,
2350 buffer
, lenp
, ppos
, conv
, data
);
2353 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2354 struct ctl_table
*table
,
2355 void __user
*buffer
,
2356 size_t *lenp
, loff_t
*ppos
,
2357 int (*conv
)(unsigned long *lvalp
,
2359 int write
, void *data
),
2366 char *kbuf
= NULL
, *p
;
2370 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2373 if (left
> PAGE_SIZE
- 1)
2374 left
= PAGE_SIZE
- 1;
2376 p
= kbuf
= memdup_user_nul(buffer
, left
);
2380 left
-= proc_skip_spaces(&p
);
2386 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2388 sizeof(proc_wspace_sep
), NULL
);
2394 if (conv(&lval
, tbl_data
, 1, data
)) {
2400 left
-= proc_skip_spaces(&p
);
2409 /* This is in keeping with old __do_proc_dointvec() */
2415 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2416 size_t *lenp
, loff_t
*ppos
,
2417 int (*conv
)(unsigned long *lvalp
,
2419 int write
, void *data
),
2428 if (conv(&lval
, tbl_data
, 0, data
)) {
2433 err
= proc_put_long(&buffer
, &left
, lval
, false);
2437 err
= proc_put_char(&buffer
, &left
, '\n');
2446 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2447 int write
, void __user
*buffer
,
2448 size_t *lenp
, loff_t
*ppos
,
2449 int (*conv
)(unsigned long *lvalp
,
2451 int write
, void *data
),
2454 unsigned int *i
, vleft
;
2456 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2461 i
= (unsigned int *) tbl_data
;
2462 vleft
= table
->maxlen
/ sizeof(*i
);
2465 * Arrays are not supported, keep this simple. *Do not* add
2474 conv
= do_proc_douintvec_conv
;
2477 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2479 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2482 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2483 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2484 int (*conv
)(unsigned long *lvalp
,
2486 int write
, void *data
),
2489 return __do_proc_douintvec(table
->data
, table
, write
,
2490 buffer
, lenp
, ppos
, conv
, data
);
2494 * proc_dointvec - read a vector of integers
2495 * @table: the sysctl table
2496 * @write: %TRUE if this is a write to the sysctl file
2497 * @buffer: the user buffer
2498 * @lenp: the size of the user buffer
2499 * @ppos: file position
2501 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2502 * values from/to the user buffer, treated as an ASCII string.
2504 * Returns 0 on success.
2506 int proc_dointvec(struct ctl_table
*table
, int write
,
2507 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2509 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2513 * proc_douintvec - read a vector of unsigned integers
2514 * @table: the sysctl table
2515 * @write: %TRUE if this is a write to the sysctl file
2516 * @buffer: the user buffer
2517 * @lenp: the size of the user buffer
2518 * @ppos: file position
2520 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2521 * values from/to the user buffer, treated as an ASCII string.
2523 * Returns 0 on success.
2525 int proc_douintvec(struct ctl_table
*table
, int write
,
2526 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2528 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2529 do_proc_douintvec_conv
, NULL
);
2533 * Taint values can only be increased
2534 * This means we can safely use a temporary.
2536 static int proc_taint(struct ctl_table
*table
, int write
,
2537 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2540 unsigned long tmptaint
= get_taint();
2543 if (write
&& !capable(CAP_SYS_ADMIN
))
2548 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2554 * Poor man's atomic or. Not worth adding a primitive
2555 * to everyone's atomic.h for this
2558 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2559 if ((tmptaint
>> i
) & 1)
2560 add_taint(i
, LOCKDEP_STILL_OK
);
2567 #ifdef CONFIG_PRINTK
2568 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2569 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2571 if (write
&& !capable(CAP_SYS_ADMIN
))
2574 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2578 struct do_proc_dointvec_minmax_conv_param
{
2583 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2585 int write
, void *data
)
2587 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2591 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2595 if (*lvalp
> (unsigned long) INT_MAX
)
2599 if ((param
->min
&& *param
->min
> val
) ||
2600 (param
->max
&& *param
->max
< val
))
2607 *lvalp
= -(unsigned long)val
;
2610 *lvalp
= (unsigned long)val
;
2617 * proc_dointvec_minmax - read a vector of integers with min/max values
2618 * @table: the sysctl table
2619 * @write: %TRUE if this is a write to the sysctl file
2620 * @buffer: the user buffer
2621 * @lenp: the size of the user buffer
2622 * @ppos: file position
2624 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2625 * values from/to the user buffer, treated as an ASCII string.
2627 * This routine will ensure the values are within the range specified by
2628 * table->extra1 (min) and table->extra2 (max).
2630 * Returns 0 on success.
2632 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2633 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2635 struct do_proc_dointvec_minmax_conv_param param
= {
2636 .min
= (int *) table
->extra1
,
2637 .max
= (int *) table
->extra2
,
2639 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2640 do_proc_dointvec_minmax_conv
, ¶m
);
2643 struct do_proc_douintvec_minmax_conv_param
{
2648 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2650 int write
, void *data
)
2652 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2655 unsigned int val
= *lvalp
;
2657 if ((param
->min
&& *param
->min
> val
) ||
2658 (param
->max
&& *param
->max
< val
))
2661 if (*lvalp
> UINT_MAX
)
2665 unsigned int val
= *valp
;
2666 *lvalp
= (unsigned long) val
;
2673 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2674 * @table: the sysctl table
2675 * @write: %TRUE if this is a write to the sysctl file
2676 * @buffer: the user buffer
2677 * @lenp: the size of the user buffer
2678 * @ppos: file position
2680 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2681 * values from/to the user buffer, treated as an ASCII string. Negative
2682 * strings are not allowed.
2684 * This routine will ensure the values are within the range specified by
2685 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2686 * check for UINT_MAX to avoid having to support wrap around uses from
2689 * Returns 0 on success.
2691 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2692 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2694 struct do_proc_douintvec_minmax_conv_param param
= {
2695 .min
= (unsigned int *) table
->extra1
,
2696 .max
= (unsigned int *) table
->extra2
,
2698 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2699 do_proc_douintvec_minmax_conv
, ¶m
);
2702 static void validate_coredump_safety(void)
2704 #ifdef CONFIG_COREDUMP
2705 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2706 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2708 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2709 "Pipe handler or fully qualified core dump path required.\n"
2710 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2716 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2717 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2719 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2721 validate_coredump_safety();
2725 #ifdef CONFIG_COREDUMP
2726 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2727 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2729 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2731 validate_coredump_safety();
2736 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2737 void __user
*buffer
,
2738 size_t *lenp
, loff_t
*ppos
,
2739 unsigned long convmul
,
2740 unsigned long convdiv
)
2742 unsigned long *i
, *min
, *max
;
2743 int vleft
, first
= 1, err
= 0;
2745 char *kbuf
= NULL
, *p
;
2747 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2752 i
= (unsigned long *) data
;
2753 min
= (unsigned long *) table
->extra1
;
2754 max
= (unsigned long *) table
->extra2
;
2755 vleft
= table
->maxlen
/ sizeof(unsigned long);
2759 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2762 if (left
> PAGE_SIZE
- 1)
2763 left
= PAGE_SIZE
- 1;
2764 p
= kbuf
= memdup_user_nul(buffer
, left
);
2766 return PTR_ERR(kbuf
);
2769 for (; left
&& vleft
--; i
++, first
= 0) {
2775 left
-= proc_skip_spaces(&p
);
2779 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2781 sizeof(proc_wspace_sep
), NULL
);
2786 val
= convmul
* val
/ convdiv
;
2787 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2791 val
= convdiv
* (*i
) / convmul
;
2793 err
= proc_put_char(&buffer
, &left
, '\t');
2797 err
= proc_put_long(&buffer
, &left
, val
, false);
2803 if (!write
&& !first
&& left
&& !err
)
2804 err
= proc_put_char(&buffer
, &left
, '\n');
2806 left
-= proc_skip_spaces(&p
);
2810 return err
? : -EINVAL
;
2818 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2819 void __user
*buffer
,
2820 size_t *lenp
, loff_t
*ppos
,
2821 unsigned long convmul
,
2822 unsigned long convdiv
)
2824 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2825 buffer
, lenp
, ppos
, convmul
, convdiv
);
2829 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2830 * @table: the sysctl table
2831 * @write: %TRUE if this is a write to the sysctl file
2832 * @buffer: the user buffer
2833 * @lenp: the size of the user buffer
2834 * @ppos: file position
2836 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2837 * values from/to the user buffer, treated as an ASCII string.
2839 * This routine will ensure the values are within the range specified by
2840 * table->extra1 (min) and table->extra2 (max).
2842 * Returns 0 on success.
2844 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2845 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2847 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2851 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2852 * @table: the sysctl table
2853 * @write: %TRUE if this is a write to the sysctl file
2854 * @buffer: the user buffer
2855 * @lenp: the size of the user buffer
2856 * @ppos: file position
2858 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2859 * values from/to the user buffer, treated as an ASCII string. The values
2860 * are treated as milliseconds, and converted to jiffies when they are stored.
2862 * This routine will ensure the values are within the range specified by
2863 * table->extra1 (min) and table->extra2 (max).
2865 * Returns 0 on success.
2867 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2868 void __user
*buffer
,
2869 size_t *lenp
, loff_t
*ppos
)
2871 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2872 lenp
, ppos
, HZ
, 1000l);
2876 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2878 int write
, void *data
)
2881 if (*lvalp
> INT_MAX
/ HZ
)
2883 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2889 lval
= -(unsigned long)val
;
2892 lval
= (unsigned long)val
;
2899 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2901 int write
, void *data
)
2904 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2906 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2912 lval
= -(unsigned long)val
;
2915 lval
= (unsigned long)val
;
2917 *lvalp
= jiffies_to_clock_t(lval
);
2922 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2924 int write
, void *data
)
2927 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2937 lval
= -(unsigned long)val
;
2940 lval
= (unsigned long)val
;
2942 *lvalp
= jiffies_to_msecs(lval
);
2948 * proc_dointvec_jiffies - read a vector of integers as seconds
2949 * @table: the sysctl table
2950 * @write: %TRUE if this is a write to the sysctl file
2951 * @buffer: the user buffer
2952 * @lenp: the size of the user buffer
2953 * @ppos: file position
2955 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2956 * values from/to the user buffer, treated as an ASCII string.
2957 * The values read are assumed to be in seconds, and are converted into
2960 * Returns 0 on success.
2962 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2963 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2965 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2966 do_proc_dointvec_jiffies_conv
,NULL
);
2970 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2971 * @table: the sysctl table
2972 * @write: %TRUE if this is a write to the sysctl file
2973 * @buffer: the user buffer
2974 * @lenp: the size of the user buffer
2975 * @ppos: pointer to the file position
2977 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2978 * values from/to the user buffer, treated as an ASCII string.
2979 * The values read are assumed to be in 1/USER_HZ seconds, and
2980 * are converted into jiffies.
2982 * Returns 0 on success.
2984 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2985 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2987 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2988 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2992 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2993 * @table: the sysctl table
2994 * @write: %TRUE if this is a write to the sysctl file
2995 * @buffer: the user buffer
2996 * @lenp: the size of the user buffer
2997 * @ppos: file position
2998 * @ppos: the current position in the file
3000 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3001 * values from/to the user buffer, treated as an ASCII string.
3002 * The values read are assumed to be in 1/1000 seconds, and
3003 * are converted into jiffies.
3005 * Returns 0 on success.
3007 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3008 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3010 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
3011 do_proc_dointvec_ms_jiffies_conv
, NULL
);
3014 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3015 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3017 struct pid
*new_pid
;
3021 tmp
= pid_vnr(cad_pid
);
3023 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3024 lenp
, ppos
, NULL
, NULL
);
3028 new_pid
= find_get_pid(tmp
);
3032 put_pid(xchg(&cad_pid
, new_pid
));
3037 * proc_do_large_bitmap - read/write from/to a large bitmap
3038 * @table: the sysctl table
3039 * @write: %TRUE if this is a write to the sysctl file
3040 * @buffer: the user buffer
3041 * @lenp: the size of the user buffer
3042 * @ppos: file position
3044 * The bitmap is stored at table->data and the bitmap length (in bits)
3047 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3048 * large bitmaps may be represented in a compact manner. Writing into
3049 * the file will clear the bitmap then update it with the given input.
3051 * Returns 0 on success.
3053 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3054 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3058 size_t left
= *lenp
;
3059 unsigned long bitmap_len
= table
->maxlen
;
3060 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3061 unsigned long *tmp_bitmap
= NULL
;
3062 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3064 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3072 if (left
> PAGE_SIZE
- 1)
3073 left
= PAGE_SIZE
- 1;
3075 p
= kbuf
= memdup_user_nul(buffer
, left
);
3077 return PTR_ERR(kbuf
);
3079 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
3085 proc_skip_char(&p
, &left
, '\n');
3086 while (!err
&& left
) {
3087 unsigned long val_a
, val_b
;
3090 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3094 if (val_a
>= bitmap_len
|| neg
) {
3106 err
= proc_get_long(&p
, &left
, &val_b
,
3107 &neg
, tr_b
, sizeof(tr_b
),
3111 if (val_b
>= bitmap_len
|| neg
||
3122 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3124 proc_skip_char(&p
, &left
, '\n');
3128 unsigned long bit_a
, bit_b
= 0;
3131 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3132 if (bit_a
>= bitmap_len
)
3134 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3138 err
= proc_put_char(&buffer
, &left
, ',');
3142 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3145 if (bit_a
!= bit_b
) {
3146 err
= proc_put_char(&buffer
, &left
, '-');
3149 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3157 err
= proc_put_char(&buffer
, &left
, '\n');
3163 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3165 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3177 #else /* CONFIG_PROC_SYSCTL */
3179 int proc_dostring(struct ctl_table
*table
, int write
,
3180 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3185 int proc_dointvec(struct ctl_table
*table
, int write
,
3186 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3191 int proc_douintvec(struct ctl_table
*table
, int write
,
3192 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3197 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3198 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3203 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3204 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3209 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3210 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3215 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3216 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3221 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3222 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3227 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3228 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3233 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3234 void __user
*buffer
,
3235 size_t *lenp
, loff_t
*ppos
)
3241 #endif /* CONFIG_PROC_SYSCTL */
3244 * No sense putting this after each symbol definition, twice,
3245 * exception granted :-)
3247 EXPORT_SYMBOL(proc_dointvec
);
3248 EXPORT_SYMBOL(proc_douintvec
);
3249 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3250 EXPORT_SYMBOL(proc_dointvec_minmax
);
3251 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3252 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3253 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3254 EXPORT_SYMBOL(proc_dostring
);
3255 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3256 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);