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
= "reap_mem_on_sigkill",
1303 .data
= &sysctl_reap_mem_on_sigkill
,
1304 .maxlen
= sizeof(sysctl_reap_mem_on_sigkill
),
1306 .proc_handler
= proc_dointvec
,
1309 .procname
= "overcommit_ratio",
1310 .data
= &sysctl_overcommit_ratio
,
1311 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1313 .proc_handler
= overcommit_ratio_handler
,
1316 .procname
= "overcommit_kbytes",
1317 .data
= &sysctl_overcommit_kbytes
,
1318 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1320 .proc_handler
= overcommit_kbytes_handler
,
1323 .procname
= "page-cluster",
1324 .data
= &page_cluster
,
1325 .maxlen
= sizeof(int),
1327 .proc_handler
= proc_dointvec_minmax
,
1331 .procname
= "dirty_background_ratio",
1332 .data
= &dirty_background_ratio
,
1333 .maxlen
= sizeof(dirty_background_ratio
),
1335 .proc_handler
= dirty_background_ratio_handler
,
1337 .extra2
= &one_hundred
,
1340 .procname
= "dirty_background_bytes",
1341 .data
= &dirty_background_bytes
,
1342 .maxlen
= sizeof(dirty_background_bytes
),
1344 .proc_handler
= dirty_background_bytes_handler
,
1348 .procname
= "dirty_ratio",
1349 .data
= &vm_dirty_ratio
,
1350 .maxlen
= sizeof(vm_dirty_ratio
),
1352 .proc_handler
= dirty_ratio_handler
,
1354 .extra2
= &one_hundred
,
1357 .procname
= "dirty_bytes",
1358 .data
= &vm_dirty_bytes
,
1359 .maxlen
= sizeof(vm_dirty_bytes
),
1361 .proc_handler
= dirty_bytes_handler
,
1362 .extra1
= &dirty_bytes_min
,
1365 .procname
= "dirty_writeback_centisecs",
1366 .data
= &dirty_writeback_interval
,
1367 .maxlen
= sizeof(dirty_writeback_interval
),
1369 .proc_handler
= dirty_writeback_centisecs_handler
,
1372 .procname
= "dirty_expire_centisecs",
1373 .data
= &dirty_expire_interval
,
1374 .maxlen
= sizeof(dirty_expire_interval
),
1376 .proc_handler
= proc_dointvec_minmax
,
1380 .procname
= "dirtytime_expire_seconds",
1381 .data
= &dirtytime_expire_interval
,
1382 .maxlen
= sizeof(dirty_expire_interval
),
1384 .proc_handler
= dirtytime_interval_handler
,
1388 .procname
= "nr_pdflush_threads",
1389 .mode
= 0444 /* read-only */,
1390 .proc_handler
= pdflush_proc_obsolete
,
1393 .procname
= "swappiness",
1394 .data
= &vm_swappiness
,
1395 .maxlen
= sizeof(vm_swappiness
),
1397 .proc_handler
= proc_dointvec_minmax
,
1399 .extra2
= &one_hundred
,
1401 #ifdef CONFIG_HUGETLB_PAGE
1403 .procname
= "nr_hugepages",
1405 .maxlen
= sizeof(unsigned long),
1407 .proc_handler
= hugetlb_sysctl_handler
,
1411 .procname
= "nr_hugepages_mempolicy",
1413 .maxlen
= sizeof(unsigned long),
1415 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1419 .procname
= "hugetlb_shm_group",
1420 .data
= &sysctl_hugetlb_shm_group
,
1421 .maxlen
= sizeof(gid_t
),
1423 .proc_handler
= proc_dointvec
,
1426 .procname
= "hugepages_treat_as_movable",
1427 .data
= &hugepages_treat_as_movable
,
1428 .maxlen
= sizeof(int),
1430 .proc_handler
= proc_dointvec
,
1433 .procname
= "nr_overcommit_hugepages",
1435 .maxlen
= sizeof(unsigned long),
1437 .proc_handler
= hugetlb_overcommit_handler
,
1441 .procname
= "lowmem_reserve_ratio",
1442 .data
= &sysctl_lowmem_reserve_ratio
,
1443 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1445 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1448 .procname
= "drop_caches",
1449 .data
= &sysctl_drop_caches
,
1450 .maxlen
= sizeof(int),
1452 .proc_handler
= drop_caches_sysctl_handler
,
1456 #ifdef CONFIG_COMPACTION
1458 .procname
= "compact_memory",
1459 .data
= &sysctl_compact_memory
,
1460 .maxlen
= sizeof(int),
1462 .proc_handler
= sysctl_compaction_handler
,
1465 .procname
= "extfrag_threshold",
1466 .data
= &sysctl_extfrag_threshold
,
1467 .maxlen
= sizeof(int),
1469 .proc_handler
= sysctl_extfrag_handler
,
1470 .extra1
= &min_extfrag_threshold
,
1471 .extra2
= &max_extfrag_threshold
,
1474 .procname
= "compact_unevictable_allowed",
1475 .data
= &sysctl_compact_unevictable_allowed
,
1476 .maxlen
= sizeof(int),
1478 .proc_handler
= proc_dointvec
,
1483 #endif /* CONFIG_COMPACTION */
1485 .procname
= "min_free_kbytes",
1486 .data
= &min_free_kbytes
,
1487 .maxlen
= sizeof(min_free_kbytes
),
1489 .proc_handler
= min_free_kbytes_sysctl_handler
,
1493 .procname
= "watermark_scale_factor",
1494 .data
= &watermark_scale_factor
,
1495 .maxlen
= sizeof(watermark_scale_factor
),
1497 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1499 .extra2
= &one_thousand
,
1502 .procname
= "extra_free_kbytes",
1503 .data
= &extra_free_kbytes
,
1504 .maxlen
= sizeof(extra_free_kbytes
),
1506 .proc_handler
= min_free_kbytes_sysctl_handler
,
1510 .procname
= "percpu_pagelist_fraction",
1511 .data
= &percpu_pagelist_fraction
,
1512 .maxlen
= sizeof(percpu_pagelist_fraction
),
1514 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1519 .procname
= "max_map_count",
1520 .data
= &sysctl_max_map_count
,
1521 .maxlen
= sizeof(sysctl_max_map_count
),
1523 .proc_handler
= proc_dointvec_minmax
,
1528 .procname
= "nr_trim_pages",
1529 .data
= &sysctl_nr_trim_pages
,
1530 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1532 .proc_handler
= proc_dointvec_minmax
,
1537 .procname
= "laptop_mode",
1538 .data
= &laptop_mode
,
1539 .maxlen
= sizeof(laptop_mode
),
1541 .proc_handler
= proc_dointvec_jiffies
,
1544 .procname
= "block_dump",
1545 .data
= &block_dump
,
1546 .maxlen
= sizeof(block_dump
),
1548 .proc_handler
= proc_dointvec
,
1552 .procname
= "vfs_cache_pressure",
1553 .data
= &sysctl_vfs_cache_pressure
,
1554 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1556 .proc_handler
= proc_dointvec
,
1559 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1561 .procname
= "legacy_va_layout",
1562 .data
= &sysctl_legacy_va_layout
,
1563 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1565 .proc_handler
= proc_dointvec
,
1571 .procname
= "zone_reclaim_mode",
1572 .data
= &node_reclaim_mode
,
1573 .maxlen
= sizeof(node_reclaim_mode
),
1575 .proc_handler
= proc_dointvec
,
1579 .procname
= "min_unmapped_ratio",
1580 .data
= &sysctl_min_unmapped_ratio
,
1581 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1583 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1585 .extra2
= &one_hundred
,
1588 .procname
= "min_slab_ratio",
1589 .data
= &sysctl_min_slab_ratio
,
1590 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1592 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1594 .extra2
= &one_hundred
,
1599 .procname
= "stat_interval",
1600 .data
= &sysctl_stat_interval
,
1601 .maxlen
= sizeof(sysctl_stat_interval
),
1603 .proc_handler
= proc_dointvec_jiffies
,
1606 .procname
= "stat_refresh",
1610 .proc_handler
= vmstat_refresh
,
1615 .procname
= "mmap_min_addr",
1616 .data
= &dac_mmap_min_addr
,
1617 .maxlen
= sizeof(unsigned long),
1619 .proc_handler
= mmap_min_addr_handler
,
1624 .procname
= "numa_zonelist_order",
1625 .data
= &numa_zonelist_order
,
1626 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1628 .proc_handler
= numa_zonelist_order_handler
,
1631 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1632 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1634 .procname
= "vdso_enabled",
1635 #ifdef CONFIG_X86_32
1636 .data
= &vdso32_enabled
,
1637 .maxlen
= sizeof(vdso32_enabled
),
1639 .data
= &vdso_enabled
,
1640 .maxlen
= sizeof(vdso_enabled
),
1643 .proc_handler
= proc_dointvec
,
1647 #ifdef CONFIG_HIGHMEM
1649 .procname
= "highmem_is_dirtyable",
1650 .data
= &vm_highmem_is_dirtyable
,
1651 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1653 .proc_handler
= proc_dointvec_minmax
,
1658 #ifdef CONFIG_MEMORY_FAILURE
1660 .procname
= "memory_failure_early_kill",
1661 .data
= &sysctl_memory_failure_early_kill
,
1662 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1664 .proc_handler
= proc_dointvec_minmax
,
1669 .procname
= "memory_failure_recovery",
1670 .data
= &sysctl_memory_failure_recovery
,
1671 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1673 .proc_handler
= proc_dointvec_minmax
,
1679 .procname
= "user_reserve_kbytes",
1680 .data
= &sysctl_user_reserve_kbytes
,
1681 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1683 .proc_handler
= proc_doulongvec_minmax
,
1686 .procname
= "admin_reserve_kbytes",
1687 .data
= &sysctl_admin_reserve_kbytes
,
1688 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1690 .proc_handler
= proc_doulongvec_minmax
,
1692 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1694 .procname
= "mmap_rnd_bits",
1695 .data
= &mmap_rnd_bits
,
1696 .maxlen
= sizeof(mmap_rnd_bits
),
1698 .proc_handler
= proc_dointvec_minmax
,
1699 .extra1
= (void *)&mmap_rnd_bits_min
,
1700 .extra2
= (void *)&mmap_rnd_bits_max
,
1703 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1705 .procname
= "mmap_rnd_compat_bits",
1706 .data
= &mmap_rnd_compat_bits
,
1707 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1709 .proc_handler
= proc_dointvec_minmax
,
1710 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1711 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1717 static struct ctl_table fs_table
[] = {
1719 .procname
= "inode-nr",
1720 .data
= &inodes_stat
,
1721 .maxlen
= 2*sizeof(long),
1723 .proc_handler
= proc_nr_inodes
,
1726 .procname
= "inode-state",
1727 .data
= &inodes_stat
,
1728 .maxlen
= 7*sizeof(long),
1730 .proc_handler
= proc_nr_inodes
,
1733 .procname
= "file-nr",
1734 .data
= &files_stat
,
1735 .maxlen
= sizeof(files_stat
),
1737 .proc_handler
= proc_nr_files
,
1740 .procname
= "file-max",
1741 .data
= &files_stat
.max_files
,
1742 .maxlen
= sizeof(files_stat
.max_files
),
1744 .proc_handler
= proc_doulongvec_minmax
,
1746 .extra2
= &long_max
,
1749 .procname
= "nr_open",
1750 .data
= &sysctl_nr_open
,
1751 .maxlen
= sizeof(unsigned int),
1753 .proc_handler
= proc_dointvec_minmax
,
1754 .extra1
= &sysctl_nr_open_min
,
1755 .extra2
= &sysctl_nr_open_max
,
1758 .procname
= "dentry-state",
1759 .data
= &dentry_stat
,
1760 .maxlen
= 6*sizeof(long),
1762 .proc_handler
= proc_nr_dentry
,
1765 .procname
= "overflowuid",
1766 .data
= &fs_overflowuid
,
1767 .maxlen
= sizeof(int),
1769 .proc_handler
= proc_dointvec_minmax
,
1770 .extra1
= &minolduid
,
1771 .extra2
= &maxolduid
,
1774 .procname
= "overflowgid",
1775 .data
= &fs_overflowgid
,
1776 .maxlen
= sizeof(int),
1778 .proc_handler
= proc_dointvec_minmax
,
1779 .extra1
= &minolduid
,
1780 .extra2
= &maxolduid
,
1782 #ifdef CONFIG_FILE_LOCKING
1784 .procname
= "leases-enable",
1785 .data
= &leases_enable
,
1786 .maxlen
= sizeof(int),
1788 .proc_handler
= proc_dointvec
,
1791 #ifdef CONFIG_DNOTIFY
1793 .procname
= "dir-notify-enable",
1794 .data
= &dir_notify_enable
,
1795 .maxlen
= sizeof(int),
1797 .proc_handler
= proc_dointvec
,
1801 #ifdef CONFIG_FILE_LOCKING
1803 .procname
= "lease-break-time",
1804 .data
= &lease_break_time
,
1805 .maxlen
= sizeof(int),
1807 .proc_handler
= proc_dointvec
,
1812 .procname
= "aio-nr",
1814 .maxlen
= sizeof(aio_nr
),
1816 .proc_handler
= proc_doulongvec_minmax
,
1819 .procname
= "aio-max-nr",
1820 .data
= &aio_max_nr
,
1821 .maxlen
= sizeof(aio_max_nr
),
1823 .proc_handler
= proc_doulongvec_minmax
,
1825 #endif /* CONFIG_AIO */
1826 #ifdef CONFIG_INOTIFY_USER
1828 .procname
= "inotify",
1830 .child
= inotify_table
,
1835 .procname
= "epoll",
1837 .child
= epoll_table
,
1842 .procname
= "protected_symlinks",
1843 .data
= &sysctl_protected_symlinks
,
1844 .maxlen
= sizeof(int),
1846 .proc_handler
= proc_dointvec_minmax
,
1851 .procname
= "protected_hardlinks",
1852 .data
= &sysctl_protected_hardlinks
,
1853 .maxlen
= sizeof(int),
1855 .proc_handler
= proc_dointvec_minmax
,
1860 .procname
= "protected_fifos",
1861 .data
= &sysctl_protected_fifos
,
1862 .maxlen
= sizeof(int),
1864 .proc_handler
= proc_dointvec_minmax
,
1869 .procname
= "protected_regular",
1870 .data
= &sysctl_protected_regular
,
1871 .maxlen
= sizeof(int),
1873 .proc_handler
= proc_dointvec_minmax
,
1878 .procname
= "suid_dumpable",
1879 .data
= &suid_dumpable
,
1880 .maxlen
= sizeof(int),
1882 .proc_handler
= proc_dointvec_minmax_coredump
,
1886 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1888 .procname
= "binfmt_misc",
1890 .child
= sysctl_mount_point
,
1894 .procname
= "pipe-max-size",
1895 .data
= &pipe_max_size
,
1896 .maxlen
= sizeof(pipe_max_size
),
1898 .proc_handler
= &pipe_proc_fn
,
1899 .extra1
= &pipe_min_size
,
1902 .procname
= "pipe-user-pages-hard",
1903 .data
= &pipe_user_pages_hard
,
1904 .maxlen
= sizeof(pipe_user_pages_hard
),
1906 .proc_handler
= proc_doulongvec_minmax
,
1909 .procname
= "pipe-user-pages-soft",
1910 .data
= &pipe_user_pages_soft
,
1911 .maxlen
= sizeof(pipe_user_pages_soft
),
1913 .proc_handler
= proc_doulongvec_minmax
,
1916 .procname
= "mount-max",
1917 .data
= &sysctl_mount_max
,
1918 .maxlen
= sizeof(unsigned int),
1920 .proc_handler
= proc_dointvec_minmax
,
1926 static struct ctl_table debug_table
[] = {
1927 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1929 .procname
= "exception-trace",
1930 .data
= &show_unhandled_signals
,
1931 .maxlen
= sizeof(int),
1933 .proc_handler
= proc_dointvec
1936 #if defined(CONFIG_OPTPROBES)
1938 .procname
= "kprobes-optimization",
1939 .data
= &sysctl_kprobes_optimization
,
1940 .maxlen
= sizeof(int),
1942 .proc_handler
= proc_kprobes_optimization_handler
,
1950 static struct ctl_table dev_table
[] = {
1954 int __init
sysctl_init(void)
1956 struct ctl_table_header
*hdr
;
1958 hdr
= register_sysctl_table(sysctl_base_table
);
1959 kmemleak_not_leak(hdr
);
1963 #endif /* CONFIG_SYSCTL */
1969 #ifdef CONFIG_PROC_SYSCTL
1971 static int _proc_do_string(char *data
, int maxlen
, int write
,
1972 char __user
*buffer
,
1973 size_t *lenp
, loff_t
*ppos
)
1979 if (!data
|| !maxlen
|| !*lenp
) {
1985 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1986 /* Only continue writes not past the end of buffer. */
1988 if (len
> maxlen
- 1)
1995 /* Start writing from beginning of buffer. */
2001 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
2002 if (get_user(c
, p
++))
2004 if (c
== 0 || c
== '\n')
2025 if (copy_to_user(buffer
, data
, len
))
2028 if (put_user('\n', buffer
+ len
))
2038 static void warn_sysctl_write(struct ctl_table
*table
)
2040 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2041 "This will not be supported in the future. To silence this\n"
2042 "warning, set kernel.sysctl_writes_strict = -1\n",
2043 current
->comm
, table
->procname
);
2047 * proc_first_pos_non_zero_ignore - check if firs position is allowed
2048 * @ppos: file position
2049 * @table: the sysctl table
2051 * Returns true if the first position is non-zero and the sysctl_writes_strict
2052 * mode indicates this is not allowed for numeric input types. String proc
2053 * hadlers can ignore the return value.
2055 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2056 struct ctl_table
*table
)
2061 switch (sysctl_writes_strict
) {
2062 case SYSCTL_WRITES_STRICT
:
2064 case SYSCTL_WRITES_WARN
:
2065 warn_sysctl_write(table
);
2073 * proc_dostring - read a string sysctl
2074 * @table: the sysctl table
2075 * @write: %TRUE if this is a write to the sysctl file
2076 * @buffer: the user buffer
2077 * @lenp: the size of the user buffer
2078 * @ppos: file position
2080 * Reads/writes a string from/to the user buffer. If the kernel
2081 * buffer provided is not large enough to hold the string, the
2082 * string is truncated. The copied string is %NULL-terminated.
2083 * If the string is being read by the user process, it is copied
2084 * and a newline '\n' is added. It is truncated if the buffer is
2087 * Returns 0 on success.
2089 int proc_dostring(struct ctl_table
*table
, int write
,
2090 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2093 proc_first_pos_non_zero_ignore(ppos
, table
);
2095 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2096 (char __user
*)buffer
, lenp
, ppos
);
2099 static size_t proc_skip_spaces(char **buf
)
2102 char *tmp
= skip_spaces(*buf
);
2108 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2118 #define TMPBUFLEN 22
2120 * proc_get_long - reads an ASCII formatted integer from a user buffer
2122 * @buf: a kernel buffer
2123 * @size: size of the kernel buffer
2124 * @val: this is where the number will be stored
2125 * @neg: set to %TRUE if number is negative
2126 * @perm_tr: a vector which contains the allowed trailers
2127 * @perm_tr_len: size of the perm_tr vector
2128 * @tr: pointer to store the trailer character
2130 * In case of success %0 is returned and @buf and @size are updated with
2131 * the amount of bytes read. If @tr is non-NULL and a trailing
2132 * character exists (size is non-zero after returning from this
2133 * function), @tr is updated with the trailing character.
2135 static int proc_get_long(char **buf
, size_t *size
,
2136 unsigned long *val
, bool *neg
,
2137 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2140 char *p
, tmp
[TMPBUFLEN
];
2146 if (len
> TMPBUFLEN
- 1)
2147 len
= TMPBUFLEN
- 1;
2149 memcpy(tmp
, *buf
, len
);
2153 if (*p
== '-' && *size
> 1) {
2161 *val
= simple_strtoul(p
, &p
, 0);
2165 /* We don't know if the next char is whitespace thus we may accept
2166 * invalid integers (e.g. 1234...a) or two integers instead of one
2167 * (e.g. 123...1). So lets not allow such large numbers. */
2168 if (len
== TMPBUFLEN
- 1)
2171 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2174 if (tr
&& (len
< *size
))
2184 * proc_put_long - converts an integer to a decimal ASCII formatted string
2186 * @buf: the user buffer
2187 * @size: the size of the user buffer
2188 * @val: the integer to be converted
2189 * @neg: sign of the number, %TRUE for negative
2191 * In case of success %0 is returned and @buf and @size are updated with
2192 * the amount of bytes written.
2194 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2198 char tmp
[TMPBUFLEN
], *p
= tmp
;
2200 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2204 if (copy_to_user(*buf
, tmp
, len
))
2212 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2215 char __user
**buffer
= (char __user
**)buf
;
2216 if (put_user(c
, *buffer
))
2218 (*size
)--, (*buffer
)++;
2224 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2226 int write
, void *data
)
2230 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2234 if (*lvalp
> (unsigned long) INT_MAX
)
2242 *lvalp
= -(unsigned long)val
;
2245 *lvalp
= (unsigned long)val
;
2251 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2253 int write
, void *data
)
2256 if (*lvalp
> UINT_MAX
)
2260 unsigned int val
= *valp
;
2261 *lvalp
= (unsigned long)val
;
2266 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2268 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2269 int write
, void __user
*buffer
,
2270 size_t *lenp
, loff_t
*ppos
,
2271 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2272 int write
, void *data
),
2275 int *i
, vleft
, first
= 1, err
= 0;
2277 char *kbuf
= NULL
, *p
;
2279 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2284 i
= (int *) tbl_data
;
2285 vleft
= table
->maxlen
/ sizeof(*i
);
2289 conv
= do_proc_dointvec_conv
;
2292 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2295 if (left
> PAGE_SIZE
- 1)
2296 left
= PAGE_SIZE
- 1;
2297 p
= kbuf
= memdup_user_nul(buffer
, left
);
2299 return PTR_ERR(kbuf
);
2302 for (; left
&& vleft
--; i
++, first
=0) {
2307 left
-= proc_skip_spaces(&p
);
2311 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2313 sizeof(proc_wspace_sep
), NULL
);
2316 if (conv(&neg
, &lval
, i
, 1, data
)) {
2321 if (conv(&neg
, &lval
, i
, 0, data
)) {
2326 err
= proc_put_char(&buffer
, &left
, '\t');
2329 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2335 if (!write
&& !first
&& left
&& !err
)
2336 err
= proc_put_char(&buffer
, &left
, '\n');
2337 if (write
&& !err
&& left
)
2338 left
-= proc_skip_spaces(&p
);
2342 return err
? : -EINVAL
;
2350 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2351 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2352 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2353 int write
, void *data
),
2356 return __do_proc_dointvec(table
->data
, table
, write
,
2357 buffer
, lenp
, ppos
, conv
, data
);
2360 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2361 struct ctl_table
*table
,
2362 void __user
*buffer
,
2363 size_t *lenp
, loff_t
*ppos
,
2364 int (*conv
)(unsigned long *lvalp
,
2366 int write
, void *data
),
2373 char *kbuf
= NULL
, *p
;
2377 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2380 if (left
> PAGE_SIZE
- 1)
2381 left
= PAGE_SIZE
- 1;
2383 p
= kbuf
= memdup_user_nul(buffer
, left
);
2387 left
-= proc_skip_spaces(&p
);
2393 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2395 sizeof(proc_wspace_sep
), NULL
);
2401 if (conv(&lval
, tbl_data
, 1, data
)) {
2407 left
-= proc_skip_spaces(&p
);
2416 /* This is in keeping with old __do_proc_dointvec() */
2422 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2423 size_t *lenp
, loff_t
*ppos
,
2424 int (*conv
)(unsigned long *lvalp
,
2426 int write
, void *data
),
2435 if (conv(&lval
, tbl_data
, 0, data
)) {
2440 err
= proc_put_long(&buffer
, &left
, lval
, false);
2444 err
= proc_put_char(&buffer
, &left
, '\n');
2453 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2454 int write
, void __user
*buffer
,
2455 size_t *lenp
, loff_t
*ppos
,
2456 int (*conv
)(unsigned long *lvalp
,
2458 int write
, void *data
),
2461 unsigned int *i
, vleft
;
2463 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2468 i
= (unsigned int *) tbl_data
;
2469 vleft
= table
->maxlen
/ sizeof(*i
);
2472 * Arrays are not supported, keep this simple. *Do not* add
2481 conv
= do_proc_douintvec_conv
;
2484 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2486 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2489 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2490 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2491 int (*conv
)(unsigned long *lvalp
,
2493 int write
, void *data
),
2496 return __do_proc_douintvec(table
->data
, table
, write
,
2497 buffer
, lenp
, ppos
, conv
, data
);
2501 * proc_dointvec - read a vector of integers
2502 * @table: the sysctl table
2503 * @write: %TRUE if this is a write to the sysctl file
2504 * @buffer: the user buffer
2505 * @lenp: the size of the user buffer
2506 * @ppos: file position
2508 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2509 * values from/to the user buffer, treated as an ASCII string.
2511 * Returns 0 on success.
2513 int proc_dointvec(struct ctl_table
*table
, int write
,
2514 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2516 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2520 * proc_douintvec - read a vector of unsigned integers
2521 * @table: the sysctl table
2522 * @write: %TRUE if this is a write to the sysctl file
2523 * @buffer: the user buffer
2524 * @lenp: the size of the user buffer
2525 * @ppos: file position
2527 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2528 * values from/to the user buffer, treated as an ASCII string.
2530 * Returns 0 on success.
2532 int proc_douintvec(struct ctl_table
*table
, int write
,
2533 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2535 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2536 do_proc_douintvec_conv
, NULL
);
2540 * Taint values can only be increased
2541 * This means we can safely use a temporary.
2543 static int proc_taint(struct ctl_table
*table
, int write
,
2544 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2547 unsigned long tmptaint
= get_taint();
2550 if (write
&& !capable(CAP_SYS_ADMIN
))
2555 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2561 * Poor man's atomic or. Not worth adding a primitive
2562 * to everyone's atomic.h for this
2565 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2566 if ((tmptaint
>> i
) & 1)
2567 add_taint(i
, LOCKDEP_STILL_OK
);
2574 #ifdef CONFIG_PRINTK
2575 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2576 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2578 if (write
&& !capable(CAP_SYS_ADMIN
))
2581 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2585 struct do_proc_dointvec_minmax_conv_param
{
2590 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2592 int write
, void *data
)
2594 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2598 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2602 if (*lvalp
> (unsigned long) INT_MAX
)
2606 if ((param
->min
&& *param
->min
> val
) ||
2607 (param
->max
&& *param
->max
< val
))
2614 *lvalp
= -(unsigned long)val
;
2617 *lvalp
= (unsigned long)val
;
2624 * proc_dointvec_minmax - read a vector of integers with min/max values
2625 * @table: the sysctl table
2626 * @write: %TRUE if this is a write to the sysctl file
2627 * @buffer: the user buffer
2628 * @lenp: the size of the user buffer
2629 * @ppos: file position
2631 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2632 * values from/to the user buffer, treated as an ASCII string.
2634 * This routine will ensure the values are within the range specified by
2635 * table->extra1 (min) and table->extra2 (max).
2637 * Returns 0 on success.
2639 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2640 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2642 struct do_proc_dointvec_minmax_conv_param param
= {
2643 .min
= (int *) table
->extra1
,
2644 .max
= (int *) table
->extra2
,
2646 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2647 do_proc_dointvec_minmax_conv
, ¶m
);
2650 struct do_proc_douintvec_minmax_conv_param
{
2655 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2657 int write
, void *data
)
2659 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2662 unsigned int val
= *lvalp
;
2664 if ((param
->min
&& *param
->min
> val
) ||
2665 (param
->max
&& *param
->max
< val
))
2668 if (*lvalp
> UINT_MAX
)
2672 unsigned int val
= *valp
;
2673 *lvalp
= (unsigned long) val
;
2680 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2681 * @table: the sysctl table
2682 * @write: %TRUE if this is a write to the sysctl file
2683 * @buffer: the user buffer
2684 * @lenp: the size of the user buffer
2685 * @ppos: file position
2687 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2688 * values from/to the user buffer, treated as an ASCII string. Negative
2689 * strings are not allowed.
2691 * This routine will ensure the values are within the range specified by
2692 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2693 * check for UINT_MAX to avoid having to support wrap around uses from
2696 * Returns 0 on success.
2698 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2699 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2701 struct do_proc_douintvec_minmax_conv_param param
= {
2702 .min
= (unsigned int *) table
->extra1
,
2703 .max
= (unsigned int *) table
->extra2
,
2705 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2706 do_proc_douintvec_minmax_conv
, ¶m
);
2709 static void validate_coredump_safety(void)
2711 #ifdef CONFIG_COREDUMP
2712 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2713 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2715 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2716 "Pipe handler or fully qualified core dump path required.\n"
2717 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2723 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2724 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2726 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2728 validate_coredump_safety();
2732 #ifdef CONFIG_COREDUMP
2733 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2734 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2736 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2738 validate_coredump_safety();
2743 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2744 void __user
*buffer
,
2745 size_t *lenp
, loff_t
*ppos
,
2746 unsigned long convmul
,
2747 unsigned long convdiv
)
2749 unsigned long *i
, *min
, *max
;
2750 int vleft
, first
= 1, err
= 0;
2752 char *kbuf
= NULL
, *p
;
2754 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2759 i
= (unsigned long *) data
;
2760 min
= (unsigned long *) table
->extra1
;
2761 max
= (unsigned long *) table
->extra2
;
2762 vleft
= table
->maxlen
/ sizeof(unsigned long);
2766 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2769 if (left
> PAGE_SIZE
- 1)
2770 left
= PAGE_SIZE
- 1;
2771 p
= kbuf
= memdup_user_nul(buffer
, left
);
2773 return PTR_ERR(kbuf
);
2776 for (; left
&& vleft
--; i
++, first
= 0) {
2782 left
-= proc_skip_spaces(&p
);
2786 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2788 sizeof(proc_wspace_sep
), NULL
);
2793 val
= convmul
* val
/ convdiv
;
2794 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2798 val
= convdiv
* (*i
) / convmul
;
2800 err
= proc_put_char(&buffer
, &left
, '\t');
2804 err
= proc_put_long(&buffer
, &left
, val
, false);
2810 if (!write
&& !first
&& left
&& !err
)
2811 err
= proc_put_char(&buffer
, &left
, '\n');
2813 left
-= proc_skip_spaces(&p
);
2817 return err
? : -EINVAL
;
2825 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2826 void __user
*buffer
,
2827 size_t *lenp
, loff_t
*ppos
,
2828 unsigned long convmul
,
2829 unsigned long convdiv
)
2831 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2832 buffer
, lenp
, ppos
, convmul
, convdiv
);
2836 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2837 * @table: the sysctl table
2838 * @write: %TRUE if this is a write to the sysctl file
2839 * @buffer: the user buffer
2840 * @lenp: the size of the user buffer
2841 * @ppos: file position
2843 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2844 * values from/to the user buffer, treated as an ASCII string.
2846 * This routine will ensure the values are within the range specified by
2847 * table->extra1 (min) and table->extra2 (max).
2849 * Returns 0 on success.
2851 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2852 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2854 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2858 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2859 * @table: the sysctl table
2860 * @write: %TRUE if this is a write to the sysctl file
2861 * @buffer: the user buffer
2862 * @lenp: the size of the user buffer
2863 * @ppos: file position
2865 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2866 * values from/to the user buffer, treated as an ASCII string. The values
2867 * are treated as milliseconds, and converted to jiffies when they are stored.
2869 * This routine will ensure the values are within the range specified by
2870 * table->extra1 (min) and table->extra2 (max).
2872 * Returns 0 on success.
2874 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2875 void __user
*buffer
,
2876 size_t *lenp
, loff_t
*ppos
)
2878 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2879 lenp
, ppos
, HZ
, 1000l);
2883 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2885 int write
, void *data
)
2888 if (*lvalp
> INT_MAX
/ HZ
)
2890 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2896 lval
= -(unsigned long)val
;
2899 lval
= (unsigned long)val
;
2906 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2908 int write
, void *data
)
2911 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2913 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2919 lval
= -(unsigned long)val
;
2922 lval
= (unsigned long)val
;
2924 *lvalp
= jiffies_to_clock_t(lval
);
2929 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2931 int write
, void *data
)
2934 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2944 lval
= -(unsigned long)val
;
2947 lval
= (unsigned long)val
;
2949 *lvalp
= jiffies_to_msecs(lval
);
2955 * proc_dointvec_jiffies - read a vector of integers as seconds
2956 * @table: the sysctl table
2957 * @write: %TRUE if this is a write to the sysctl file
2958 * @buffer: the user buffer
2959 * @lenp: the size of the user buffer
2960 * @ppos: file position
2962 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2963 * values from/to the user buffer, treated as an ASCII string.
2964 * The values read are assumed to be in seconds, and are converted into
2967 * Returns 0 on success.
2969 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2970 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2972 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2973 do_proc_dointvec_jiffies_conv
,NULL
);
2977 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2978 * @table: the sysctl table
2979 * @write: %TRUE if this is a write to the sysctl file
2980 * @buffer: the user buffer
2981 * @lenp: the size of the user buffer
2982 * @ppos: pointer to the file position
2984 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2985 * values from/to the user buffer, treated as an ASCII string.
2986 * The values read are assumed to be in 1/USER_HZ seconds, and
2987 * are converted into jiffies.
2989 * Returns 0 on success.
2991 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2992 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2994 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2995 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2999 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3000 * @table: the sysctl table
3001 * @write: %TRUE if this is a write to the sysctl file
3002 * @buffer: the user buffer
3003 * @lenp: the size of the user buffer
3004 * @ppos: file position
3005 * @ppos: the current position in the file
3007 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3008 * values from/to the user buffer, treated as an ASCII string.
3009 * The values read are assumed to be in 1/1000 seconds, and
3010 * are converted into jiffies.
3012 * Returns 0 on success.
3014 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3015 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3017 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
3018 do_proc_dointvec_ms_jiffies_conv
, NULL
);
3021 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3022 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3024 struct pid
*new_pid
;
3028 tmp
= pid_vnr(cad_pid
);
3030 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3031 lenp
, ppos
, NULL
, NULL
);
3035 new_pid
= find_get_pid(tmp
);
3039 put_pid(xchg(&cad_pid
, new_pid
));
3044 * proc_do_large_bitmap - read/write from/to a large bitmap
3045 * @table: the sysctl table
3046 * @write: %TRUE if this is a write to the sysctl file
3047 * @buffer: the user buffer
3048 * @lenp: the size of the user buffer
3049 * @ppos: file position
3051 * The bitmap is stored at table->data and the bitmap length (in bits)
3054 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3055 * large bitmaps may be represented in a compact manner. Writing into
3056 * the file will clear the bitmap then update it with the given input.
3058 * Returns 0 on success.
3060 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3061 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3065 size_t left
= *lenp
;
3066 unsigned long bitmap_len
= table
->maxlen
;
3067 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3068 unsigned long *tmp_bitmap
= NULL
;
3069 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3071 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3079 if (left
> PAGE_SIZE
- 1)
3080 left
= PAGE_SIZE
- 1;
3082 p
= kbuf
= memdup_user_nul(buffer
, left
);
3084 return PTR_ERR(kbuf
);
3086 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
3092 proc_skip_char(&p
, &left
, '\n');
3093 while (!err
&& left
) {
3094 unsigned long val_a
, val_b
;
3097 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3101 if (val_a
>= bitmap_len
|| neg
) {
3113 err
= proc_get_long(&p
, &left
, &val_b
,
3114 &neg
, tr_b
, sizeof(tr_b
),
3118 if (val_b
>= bitmap_len
|| neg
||
3129 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3131 proc_skip_char(&p
, &left
, '\n');
3135 unsigned long bit_a
, bit_b
= 0;
3138 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3139 if (bit_a
>= bitmap_len
)
3141 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3145 err
= proc_put_char(&buffer
, &left
, ',');
3149 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3152 if (bit_a
!= bit_b
) {
3153 err
= proc_put_char(&buffer
, &left
, '-');
3156 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3164 err
= proc_put_char(&buffer
, &left
, '\n');
3170 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3172 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3184 #else /* CONFIG_PROC_SYSCTL */
3186 int proc_dostring(struct ctl_table
*table
, int write
,
3187 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3192 int proc_dointvec(struct ctl_table
*table
, int write
,
3193 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3198 int proc_douintvec(struct ctl_table
*table
, int write
,
3199 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3204 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3205 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3210 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3211 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3216 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3217 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3222 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3223 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3228 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3229 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3234 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3235 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3240 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3241 void __user
*buffer
,
3242 size_t *lenp
, loff_t
*ppos
)
3248 #endif /* CONFIG_PROC_SYSCTL */
3251 * No sense putting this after each symbol definition, twice,
3252 * exception granted :-)
3254 EXPORT_SYMBOL(proc_dointvec
);
3255 EXPORT_SYMBOL(proc_douintvec
);
3256 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3257 EXPORT_SYMBOL(proc_dointvec_minmax
);
3258 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3259 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3260 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3261 EXPORT_SYMBOL(proc_dostring
);
3262 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3263 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);