2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/aio.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/sched/coredump.h>
66 #include <linux/kexec.h>
67 #include <linux/bpf.h>
68 #include <linux/mount.h>
69 #include <linux/pipe_fs_i.h>
71 #include <linux/uaccess.h>
72 #include <asm/processor.h>
76 #include <asm/stacktrace.h>
80 #include <asm/setup.h>
82 #ifdef CONFIG_BSD_PROCESS_ACCT
83 #include <linux/acct.h>
85 #ifdef CONFIG_RT_MUTEXES
86 #include <linux/rtmutex.h>
88 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
89 #include <linux/lockdep.h>
91 #ifdef CONFIG_CHR_DEV_SG
95 #ifdef CONFIG_LOCKUP_DETECTOR
96 #include <linux/nmi.h>
99 #if defined(CONFIG_SYSCTL)
101 /* External variables not in a header file. */
102 extern int suid_dumpable
;
103 #ifdef CONFIG_COREDUMP
104 extern int core_uses_pid
;
105 extern char core_pattern
[];
106 extern unsigned int core_pipe_limit
;
109 extern int pid_max_min
, pid_max_max
;
110 extern int percpu_pagelist_fraction
;
111 extern int latencytop_enabled
;
112 extern unsigned int sysctl_nr_open_min
, sysctl_nr_open_max
;
114 extern int sysctl_nr_trim_pages
;
117 /* Constants used for minimum and maximum */
118 #ifdef CONFIG_LOCKUP_DETECTOR
119 static int sixty
= 60;
122 static int __maybe_unused neg_one
= -1;
125 static int __maybe_unused one
= 1;
126 static int __maybe_unused two
= 2;
127 static int __maybe_unused four
= 4;
128 static unsigned long one_ul
= 1;
129 static int one_hundred
= 100;
130 static int one_thousand
= 1000;
132 static int ten_thousand
= 10000;
134 #ifdef CONFIG_PERF_EVENTS
135 static int six_hundred_forty_kb
= 640 * 1024;
138 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
141 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142 static int maxolduid
= 65535;
143 static int minolduid
;
145 static int ngroups_max
= NGROUPS_MAX
;
146 static const int cap_last_cap
= CAP_LAST_CAP
;
148 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
149 #ifdef CONFIG_DETECT_HUNG_TASK
150 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
153 #ifdef CONFIG_INOTIFY_USER
154 #include <linux/inotify.h>
160 extern int pwrsw_enabled
;
163 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
164 extern int unaligned_enabled
;
168 extern int unaligned_dump_stack
;
171 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172 extern int no_unaligned_warning
;
175 #ifdef CONFIG_PROC_SYSCTL
178 * enum sysctl_writes_mode - supported sysctl write modes
180 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
181 * to be written, and multiple writes on the same sysctl file descriptor
182 * will rewrite the sysctl value, regardless of file position. No warning
183 * is issued when the initial position is not 0.
184 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
186 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
187 * file position 0 and the value must be fully contained in the buffer
188 * sent to the write syscall. If dealing with strings respect the file
189 * position, but restrict this to the max length of the buffer, anything
190 * passed the max lenght will be ignored. Multiple writes will append
193 * These write modes control how current file position affects the behavior of
194 * updating sysctl values through the proc interface on each write.
196 enum sysctl_writes_mode
{
197 SYSCTL_WRITES_LEGACY
= -1,
198 SYSCTL_WRITES_WARN
= 0,
199 SYSCTL_WRITES_STRICT
= 1,
202 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
204 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
205 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
206 static int proc_taint(struct ctl_table
*table
, int write
,
207 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
211 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
212 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
215 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
216 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
217 #ifdef CONFIG_COREDUMP
218 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
219 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
222 #ifdef CONFIG_MAGIC_SYSRQ
223 /* Note: sysrq code uses it's own private copy */
224 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
226 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
227 void __user
*buffer
, size_t *lenp
,
232 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
237 sysrq_toggle_support(__sysrq_enabled
);
244 static struct ctl_table kern_table
[];
245 static struct ctl_table vm_table
[];
246 static struct ctl_table fs_table
[];
247 static struct ctl_table debug_table
[];
248 static struct ctl_table dev_table
[];
249 extern struct ctl_table random_table
[];
251 extern struct ctl_table epoll_table
[];
254 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
255 int sysctl_legacy_va_layout
;
258 /* The default sysctl tables: */
260 static struct ctl_table sysctl_base_table
[] = {
262 .procname
= "kernel",
279 .child
= debug_table
,
289 #ifdef CONFIG_SCHED_DEBUG
290 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
291 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
292 static int min_wakeup_granularity_ns
; /* 0 usecs */
293 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
295 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
296 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
297 #endif /* CONFIG_SMP */
298 #endif /* CONFIG_SCHED_DEBUG */
300 #ifdef CONFIG_COMPACTION
301 static int min_extfrag_threshold
;
302 static int max_extfrag_threshold
= 1000;
305 static struct ctl_table kern_table
[] = {
307 .procname
= "sched_child_runs_first",
308 .data
= &sysctl_sched_child_runs_first
,
309 .maxlen
= sizeof(unsigned int),
311 .proc_handler
= proc_dointvec
,
313 #ifdef CONFIG_SCHED_DEBUG
315 .procname
= "sched_min_granularity_ns",
316 .data
= &sysctl_sched_min_granularity
,
317 .maxlen
= sizeof(unsigned int),
319 .proc_handler
= sched_proc_update_handler
,
320 .extra1
= &min_sched_granularity_ns
,
321 .extra2
= &max_sched_granularity_ns
,
324 .procname
= "sched_latency_ns",
325 .data
= &sysctl_sched_latency
,
326 .maxlen
= sizeof(unsigned int),
328 .proc_handler
= sched_proc_update_handler
,
329 .extra1
= &min_sched_granularity_ns
,
330 .extra2
= &max_sched_granularity_ns
,
333 .procname
= "sched_wakeup_granularity_ns",
334 .data
= &sysctl_sched_wakeup_granularity
,
335 .maxlen
= sizeof(unsigned int),
337 .proc_handler
= sched_proc_update_handler
,
338 .extra1
= &min_wakeup_granularity_ns
,
339 .extra2
= &max_wakeup_granularity_ns
,
343 .procname
= "sched_tunable_scaling",
344 .data
= &sysctl_sched_tunable_scaling
,
345 .maxlen
= sizeof(enum sched_tunable_scaling
),
347 .proc_handler
= sched_proc_update_handler
,
348 .extra1
= &min_sched_tunable_scaling
,
349 .extra2
= &max_sched_tunable_scaling
,
352 .procname
= "sched_migration_cost_ns",
353 .data
= &sysctl_sched_migration_cost
,
354 .maxlen
= sizeof(unsigned int),
356 .proc_handler
= proc_dointvec
,
359 .procname
= "sched_nr_migrate",
360 .data
= &sysctl_sched_nr_migrate
,
361 .maxlen
= sizeof(unsigned int),
363 .proc_handler
= proc_dointvec
,
366 .procname
= "sched_time_avg_ms",
367 .data
= &sysctl_sched_time_avg
,
368 .maxlen
= sizeof(unsigned int),
370 .proc_handler
= proc_dointvec_minmax
,
373 #ifdef CONFIG_SCHEDSTATS
375 .procname
= "sched_schedstats",
377 .maxlen
= sizeof(unsigned int),
379 .proc_handler
= sysctl_schedstats
,
383 #endif /* CONFIG_SCHEDSTATS */
384 #endif /* CONFIG_SMP */
385 #ifdef CONFIG_NUMA_BALANCING
387 .procname
= "numa_balancing_scan_delay_ms",
388 .data
= &sysctl_numa_balancing_scan_delay
,
389 .maxlen
= sizeof(unsigned int),
391 .proc_handler
= proc_dointvec
,
394 .procname
= "numa_balancing_scan_period_min_ms",
395 .data
= &sysctl_numa_balancing_scan_period_min
,
396 .maxlen
= sizeof(unsigned int),
398 .proc_handler
= proc_dointvec
,
401 .procname
= "numa_balancing_scan_period_max_ms",
402 .data
= &sysctl_numa_balancing_scan_period_max
,
403 .maxlen
= sizeof(unsigned int),
405 .proc_handler
= proc_dointvec
,
408 .procname
= "numa_balancing_scan_size_mb",
409 .data
= &sysctl_numa_balancing_scan_size
,
410 .maxlen
= sizeof(unsigned int),
412 .proc_handler
= proc_dointvec_minmax
,
416 .procname
= "numa_balancing",
417 .data
= NULL
, /* filled in by handler */
418 .maxlen
= sizeof(unsigned int),
420 .proc_handler
= sysctl_numa_balancing
,
424 #endif /* CONFIG_NUMA_BALANCING */
425 #endif /* CONFIG_SCHED_DEBUG */
427 .procname
= "sched_rt_period_us",
428 .data
= &sysctl_sched_rt_period
,
429 .maxlen
= sizeof(unsigned int),
431 .proc_handler
= sched_rt_handler
,
434 .procname
= "sched_rt_runtime_us",
435 .data
= &sysctl_sched_rt_runtime
,
436 .maxlen
= sizeof(int),
438 .proc_handler
= sched_rt_handler
,
441 .procname
= "sched_rr_timeslice_ms",
442 .data
= &sysctl_sched_rr_timeslice
,
443 .maxlen
= sizeof(int),
445 .proc_handler
= sched_rr_handler
,
447 #ifdef CONFIG_SCHED_AUTOGROUP
449 .procname
= "sched_autogroup_enabled",
450 .data
= &sysctl_sched_autogroup_enabled
,
451 .maxlen
= sizeof(unsigned int),
453 .proc_handler
= proc_dointvec_minmax
,
458 #ifdef CONFIG_CFS_BANDWIDTH
460 .procname
= "sched_cfs_bandwidth_slice_us",
461 .data
= &sysctl_sched_cfs_bandwidth_slice
,
462 .maxlen
= sizeof(unsigned int),
464 .proc_handler
= proc_dointvec_minmax
,
468 #ifdef CONFIG_PROVE_LOCKING
470 .procname
= "prove_locking",
471 .data
= &prove_locking
,
472 .maxlen
= sizeof(int),
474 .proc_handler
= proc_dointvec
,
477 #ifdef CONFIG_LOCK_STAT
479 .procname
= "lock_stat",
481 .maxlen
= sizeof(int),
483 .proc_handler
= proc_dointvec
,
488 .data
= &panic_timeout
,
489 .maxlen
= sizeof(int),
491 .proc_handler
= proc_dointvec
,
493 #ifdef CONFIG_COREDUMP
495 .procname
= "core_uses_pid",
496 .data
= &core_uses_pid
,
497 .maxlen
= sizeof(int),
499 .proc_handler
= proc_dointvec
,
502 .procname
= "core_pattern",
503 .data
= core_pattern
,
504 .maxlen
= CORENAME_MAX_SIZE
,
506 .proc_handler
= proc_dostring_coredump
,
509 .procname
= "core_pipe_limit",
510 .data
= &core_pipe_limit
,
511 .maxlen
= sizeof(unsigned int),
513 .proc_handler
= proc_dointvec
,
516 #ifdef CONFIG_PROC_SYSCTL
518 .procname
= "tainted",
519 .maxlen
= sizeof(long),
521 .proc_handler
= proc_taint
,
524 .procname
= "sysctl_writes_strict",
525 .data
= &sysctl_writes_strict
,
526 .maxlen
= sizeof(int),
528 .proc_handler
= proc_dointvec_minmax
,
533 #ifdef CONFIG_LATENCYTOP
535 .procname
= "latencytop",
536 .data
= &latencytop_enabled
,
537 .maxlen
= sizeof(int),
539 .proc_handler
= sysctl_latencytop
,
542 #ifdef CONFIG_BLK_DEV_INITRD
544 .procname
= "real-root-dev",
545 .data
= &real_root_dev
,
546 .maxlen
= sizeof(int),
548 .proc_handler
= proc_dointvec
,
552 .procname
= "print-fatal-signals",
553 .data
= &print_fatal_signals
,
554 .maxlen
= sizeof(int),
556 .proc_handler
= proc_dointvec
,
560 .procname
= "reboot-cmd",
561 .data
= reboot_command
,
564 .proc_handler
= proc_dostring
,
567 .procname
= "stop-a",
568 .data
= &stop_a_enabled
,
569 .maxlen
= sizeof (int),
571 .proc_handler
= proc_dointvec
,
574 .procname
= "scons-poweroff",
575 .data
= &scons_pwroff
,
576 .maxlen
= sizeof (int),
578 .proc_handler
= proc_dointvec
,
581 #ifdef CONFIG_SPARC64
583 .procname
= "tsb-ratio",
584 .data
= &sysctl_tsb_ratio
,
585 .maxlen
= sizeof (int),
587 .proc_handler
= proc_dointvec
,
592 .procname
= "soft-power",
593 .data
= &pwrsw_enabled
,
594 .maxlen
= sizeof (int),
596 .proc_handler
= proc_dointvec
,
599 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
601 .procname
= "unaligned-trap",
602 .data
= &unaligned_enabled
,
603 .maxlen
= sizeof (int),
605 .proc_handler
= proc_dointvec
,
609 .procname
= "ctrl-alt-del",
611 .maxlen
= sizeof(int),
613 .proc_handler
= proc_dointvec
,
615 #ifdef CONFIG_FUNCTION_TRACER
617 .procname
= "ftrace_enabled",
618 .data
= &ftrace_enabled
,
619 .maxlen
= sizeof(int),
621 .proc_handler
= ftrace_enable_sysctl
,
624 #ifdef CONFIG_STACK_TRACER
626 .procname
= "stack_tracer_enabled",
627 .data
= &stack_tracer_enabled
,
628 .maxlen
= sizeof(int),
630 .proc_handler
= stack_trace_sysctl
,
633 #ifdef CONFIG_TRACING
635 .procname
= "ftrace_dump_on_oops",
636 .data
= &ftrace_dump_on_oops
,
637 .maxlen
= sizeof(int),
639 .proc_handler
= proc_dointvec
,
642 .procname
= "traceoff_on_warning",
643 .data
= &__disable_trace_on_warning
,
644 .maxlen
= sizeof(__disable_trace_on_warning
),
646 .proc_handler
= proc_dointvec
,
649 .procname
= "tracepoint_printk",
650 .data
= &tracepoint_printk
,
651 .maxlen
= sizeof(tracepoint_printk
),
653 .proc_handler
= tracepoint_printk_sysctl
,
656 #ifdef CONFIG_KEXEC_CORE
658 .procname
= "kexec_load_disabled",
659 .data
= &kexec_load_disabled
,
660 .maxlen
= sizeof(int),
662 /* only handle a transition from default "0" to "1" */
663 .proc_handler
= proc_dointvec_minmax
,
668 #ifdef CONFIG_MODULES
670 .procname
= "modprobe",
671 .data
= &modprobe_path
,
672 .maxlen
= KMOD_PATH_LEN
,
674 .proc_handler
= proc_dostring
,
677 .procname
= "modules_disabled",
678 .data
= &modules_disabled
,
679 .maxlen
= sizeof(int),
681 /* only handle a transition from default "0" to "1" */
682 .proc_handler
= proc_dointvec_minmax
,
687 #ifdef CONFIG_UEVENT_HELPER
689 .procname
= "hotplug",
690 .data
= &uevent_helper
,
691 .maxlen
= UEVENT_HELPER_PATH_LEN
,
693 .proc_handler
= proc_dostring
,
696 #ifdef CONFIG_CHR_DEV_SG
698 .procname
= "sg-big-buff",
699 .data
= &sg_big_buff
,
700 .maxlen
= sizeof (int),
702 .proc_handler
= proc_dointvec
,
705 #ifdef CONFIG_BSD_PROCESS_ACCT
709 .maxlen
= 3*sizeof(int),
711 .proc_handler
= proc_dointvec
,
714 #ifdef CONFIG_MAGIC_SYSRQ
717 .data
= &__sysrq_enabled
,
718 .maxlen
= sizeof (int),
720 .proc_handler
= sysrq_sysctl_handler
,
723 #ifdef CONFIG_PROC_SYSCTL
725 .procname
= "cad_pid",
727 .maxlen
= sizeof (int),
729 .proc_handler
= proc_do_cad_pid
,
733 .procname
= "threads-max",
735 .maxlen
= sizeof(int),
737 .proc_handler
= sysctl_max_threads
,
740 .procname
= "random",
742 .child
= random_table
,
745 .procname
= "usermodehelper",
747 .child
= usermodehelper_table
,
750 .procname
= "overflowuid",
751 .data
= &overflowuid
,
752 .maxlen
= sizeof(int),
754 .proc_handler
= proc_dointvec_minmax
,
755 .extra1
= &minolduid
,
756 .extra2
= &maxolduid
,
759 .procname
= "overflowgid",
760 .data
= &overflowgid
,
761 .maxlen
= sizeof(int),
763 .proc_handler
= proc_dointvec_minmax
,
764 .extra1
= &minolduid
,
765 .extra2
= &maxolduid
,
768 #ifdef CONFIG_MATHEMU
770 .procname
= "ieee_emulation_warnings",
771 .data
= &sysctl_ieee_emulation_warnings
,
772 .maxlen
= sizeof(int),
774 .proc_handler
= proc_dointvec
,
778 .procname
= "userprocess_debug",
779 .data
= &show_unhandled_signals
,
780 .maxlen
= sizeof(int),
782 .proc_handler
= proc_dointvec
,
786 .procname
= "pid_max",
788 .maxlen
= sizeof (int),
790 .proc_handler
= proc_dointvec_minmax
,
791 .extra1
= &pid_max_min
,
792 .extra2
= &pid_max_max
,
795 .procname
= "panic_on_oops",
796 .data
= &panic_on_oops
,
797 .maxlen
= sizeof(int),
799 .proc_handler
= proc_dointvec
,
801 #if defined CONFIG_PRINTK
803 .procname
= "printk",
804 .data
= &console_loglevel
,
805 .maxlen
= 4*sizeof(int),
807 .proc_handler
= proc_dointvec
,
810 .procname
= "printk_ratelimit",
811 .data
= &printk_ratelimit_state
.interval
,
812 .maxlen
= sizeof(int),
814 .proc_handler
= proc_dointvec_jiffies
,
817 .procname
= "printk_ratelimit_burst",
818 .data
= &printk_ratelimit_state
.burst
,
819 .maxlen
= sizeof(int),
821 .proc_handler
= proc_dointvec
,
824 .procname
= "printk_delay",
825 .data
= &printk_delay_msec
,
826 .maxlen
= sizeof(int),
828 .proc_handler
= proc_dointvec_minmax
,
830 .extra2
= &ten_thousand
,
833 .procname
= "printk_devkmsg",
834 .data
= devkmsg_log_str
,
835 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
837 .proc_handler
= devkmsg_sysctl_set_loglvl
,
840 .procname
= "dmesg_restrict",
841 .data
= &dmesg_restrict
,
842 .maxlen
= sizeof(int),
844 .proc_handler
= proc_dointvec_minmax_sysadmin
,
849 .procname
= "kptr_restrict",
850 .data
= &kptr_restrict
,
851 .maxlen
= sizeof(int),
853 .proc_handler
= proc_dointvec_minmax_sysadmin
,
859 .procname
= "ngroups_max",
860 .data
= &ngroups_max
,
861 .maxlen
= sizeof (int),
863 .proc_handler
= proc_dointvec
,
866 .procname
= "cap_last_cap",
867 .data
= (void *)&cap_last_cap
,
868 .maxlen
= sizeof(int),
870 .proc_handler
= proc_dointvec
,
872 #if defined(CONFIG_LOCKUP_DETECTOR)
874 .procname
= "watchdog",
875 .data
= &watchdog_user_enabled
,
876 .maxlen
= sizeof(int),
878 .proc_handler
= proc_watchdog
,
883 .procname
= "watchdog_thresh",
884 .data
= &watchdog_thresh
,
885 .maxlen
= sizeof(int),
887 .proc_handler
= proc_watchdog_thresh
,
892 .procname
= "nmi_watchdog",
893 .data
= &nmi_watchdog_user_enabled
,
894 .maxlen
= sizeof(int),
895 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
896 .proc_handler
= proc_nmi_watchdog
,
901 .procname
= "watchdog_cpumask",
902 .data
= &watchdog_cpumask_bits
,
905 .proc_handler
= proc_watchdog_cpumask
,
907 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
909 .procname
= "soft_watchdog",
910 .data
= &soft_watchdog_user_enabled
,
911 .maxlen
= sizeof(int),
913 .proc_handler
= proc_soft_watchdog
,
918 .procname
= "softlockup_panic",
919 .data
= &softlockup_panic
,
920 .maxlen
= sizeof(int),
922 .proc_handler
= proc_dointvec_minmax
,
928 .procname
= "softlockup_all_cpu_backtrace",
929 .data
= &sysctl_softlockup_all_cpu_backtrace
,
930 .maxlen
= sizeof(int),
932 .proc_handler
= proc_dointvec_minmax
,
936 #endif /* CONFIG_SMP */
938 #ifdef CONFIG_HARDLOCKUP_DETECTOR
940 .procname
= "hardlockup_panic",
941 .data
= &hardlockup_panic
,
942 .maxlen
= sizeof(int),
944 .proc_handler
= proc_dointvec_minmax
,
950 .procname
= "hardlockup_all_cpu_backtrace",
951 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
952 .maxlen
= sizeof(int),
954 .proc_handler
= proc_dointvec_minmax
,
958 #endif /* CONFIG_SMP */
962 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
964 .procname
= "unknown_nmi_panic",
965 .data
= &unknown_nmi_panic
,
966 .maxlen
= sizeof (int),
968 .proc_handler
= proc_dointvec
,
971 #if defined(CONFIG_X86)
973 .procname
= "panic_on_unrecovered_nmi",
974 .data
= &panic_on_unrecovered_nmi
,
975 .maxlen
= sizeof(int),
977 .proc_handler
= proc_dointvec
,
980 .procname
= "panic_on_io_nmi",
981 .data
= &panic_on_io_nmi
,
982 .maxlen
= sizeof(int),
984 .proc_handler
= proc_dointvec
,
986 #ifdef CONFIG_DEBUG_STACKOVERFLOW
988 .procname
= "panic_on_stackoverflow",
989 .data
= &sysctl_panic_on_stackoverflow
,
990 .maxlen
= sizeof(int),
992 .proc_handler
= proc_dointvec
,
996 .procname
= "bootloader_type",
997 .data
= &bootloader_type
,
998 .maxlen
= sizeof (int),
1000 .proc_handler
= proc_dointvec
,
1003 .procname
= "bootloader_version",
1004 .data
= &bootloader_version
,
1005 .maxlen
= sizeof (int),
1007 .proc_handler
= proc_dointvec
,
1010 .procname
= "io_delay_type",
1011 .data
= &io_delay_type
,
1012 .maxlen
= sizeof(int),
1014 .proc_handler
= proc_dointvec
,
1017 #if defined(CONFIG_MMU)
1019 .procname
= "randomize_va_space",
1020 .data
= &randomize_va_space
,
1021 .maxlen
= sizeof(int),
1023 .proc_handler
= proc_dointvec
,
1026 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1028 .procname
= "spin_retry",
1029 .data
= &spin_retry
,
1030 .maxlen
= sizeof (int),
1032 .proc_handler
= proc_dointvec
,
1035 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1037 .procname
= "acpi_video_flags",
1038 .data
= &acpi_realmode_flags
,
1039 .maxlen
= sizeof (unsigned long),
1041 .proc_handler
= proc_doulongvec_minmax
,
1044 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1046 .procname
= "ignore-unaligned-usertrap",
1047 .data
= &no_unaligned_warning
,
1048 .maxlen
= sizeof (int),
1050 .proc_handler
= proc_dointvec
,
1055 .procname
= "unaligned-dump-stack",
1056 .data
= &unaligned_dump_stack
,
1057 .maxlen
= sizeof (int),
1059 .proc_handler
= proc_dointvec
,
1062 #ifdef CONFIG_DETECT_HUNG_TASK
1064 .procname
= "hung_task_panic",
1065 .data
= &sysctl_hung_task_panic
,
1066 .maxlen
= sizeof(int),
1068 .proc_handler
= proc_dointvec_minmax
,
1073 .procname
= "hung_task_check_count",
1074 .data
= &sysctl_hung_task_check_count
,
1075 .maxlen
= sizeof(int),
1077 .proc_handler
= proc_dointvec_minmax
,
1081 .procname
= "hung_task_timeout_secs",
1082 .data
= &sysctl_hung_task_timeout_secs
,
1083 .maxlen
= sizeof(unsigned long),
1085 .proc_handler
= proc_dohung_task_timeout_secs
,
1086 .extra2
= &hung_task_timeout_max
,
1089 .procname
= "hung_task_warnings",
1090 .data
= &sysctl_hung_task_warnings
,
1091 .maxlen
= sizeof(int),
1093 .proc_handler
= proc_dointvec_minmax
,
1097 #ifdef CONFIG_RT_MUTEXES
1099 .procname
= "max_lock_depth",
1100 .data
= &max_lock_depth
,
1101 .maxlen
= sizeof(int),
1103 .proc_handler
= proc_dointvec
,
1107 .procname
= "poweroff_cmd",
1108 .data
= &poweroff_cmd
,
1109 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1111 .proc_handler
= proc_dostring
,
1117 .child
= key_sysctls
,
1120 #ifdef CONFIG_PERF_EVENTS
1122 * User-space scripts rely on the existence of this file
1123 * as a feature check for perf_events being enabled.
1125 * So it's an ABI, do not remove!
1128 .procname
= "perf_event_paranoid",
1129 .data
= &sysctl_perf_event_paranoid
,
1130 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1132 .proc_handler
= proc_dointvec
,
1135 .procname
= "perf_event_mlock_kb",
1136 .data
= &sysctl_perf_event_mlock
,
1137 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1139 .proc_handler
= proc_dointvec
,
1142 .procname
= "perf_event_max_sample_rate",
1143 .data
= &sysctl_perf_event_sample_rate
,
1144 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1146 .proc_handler
= perf_proc_update_handler
,
1150 .procname
= "perf_cpu_time_max_percent",
1151 .data
= &sysctl_perf_cpu_time_max_percent
,
1152 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1154 .proc_handler
= perf_cpu_time_max_percent_handler
,
1156 .extra2
= &one_hundred
,
1159 .procname
= "perf_event_max_stack",
1160 .data
= &sysctl_perf_event_max_stack
,
1161 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1163 .proc_handler
= perf_event_max_stack_handler
,
1165 .extra2
= &six_hundred_forty_kb
,
1168 .procname
= "perf_event_max_contexts_per_stack",
1169 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1170 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1172 .proc_handler
= perf_event_max_stack_handler
,
1174 .extra2
= &one_thousand
,
1178 .procname
= "panic_on_warn",
1179 .data
= &panic_on_warn
,
1180 .maxlen
= sizeof(int),
1182 .proc_handler
= proc_dointvec_minmax
,
1186 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1188 .procname
= "timer_migration",
1189 .data
= &sysctl_timer_migration
,
1190 .maxlen
= sizeof(unsigned int),
1192 .proc_handler
= timer_migration_handler
,
1197 #ifdef CONFIG_BPF_SYSCALL
1199 .procname
= "unprivileged_bpf_disabled",
1200 .data
= &sysctl_unprivileged_bpf_disabled
,
1201 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1203 /* only handle a transition from default "0" to "1" */
1204 .proc_handler
= proc_dointvec_minmax
,
1209 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1211 .procname
= "panic_on_rcu_stall",
1212 .data
= &sysctl_panic_on_rcu_stall
,
1213 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1215 .proc_handler
= proc_dointvec_minmax
,
1223 static struct ctl_table vm_table
[] = {
1225 .procname
= "overcommit_memory",
1226 .data
= &sysctl_overcommit_memory
,
1227 .maxlen
= sizeof(sysctl_overcommit_memory
),
1229 .proc_handler
= proc_dointvec_minmax
,
1234 .procname
= "panic_on_oom",
1235 .data
= &sysctl_panic_on_oom
,
1236 .maxlen
= sizeof(sysctl_panic_on_oom
),
1238 .proc_handler
= proc_dointvec_minmax
,
1243 .procname
= "oom_kill_allocating_task",
1244 .data
= &sysctl_oom_kill_allocating_task
,
1245 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1247 .proc_handler
= proc_dointvec
,
1250 .procname
= "oom_dump_tasks",
1251 .data
= &sysctl_oom_dump_tasks
,
1252 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1254 .proc_handler
= proc_dointvec
,
1257 .procname
= "overcommit_ratio",
1258 .data
= &sysctl_overcommit_ratio
,
1259 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1261 .proc_handler
= overcommit_ratio_handler
,
1264 .procname
= "overcommit_kbytes",
1265 .data
= &sysctl_overcommit_kbytes
,
1266 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1268 .proc_handler
= overcommit_kbytes_handler
,
1271 .procname
= "page-cluster",
1272 .data
= &page_cluster
,
1273 .maxlen
= sizeof(int),
1275 .proc_handler
= proc_dointvec_minmax
,
1279 .procname
= "dirty_background_ratio",
1280 .data
= &dirty_background_ratio
,
1281 .maxlen
= sizeof(dirty_background_ratio
),
1283 .proc_handler
= dirty_background_ratio_handler
,
1285 .extra2
= &one_hundred
,
1288 .procname
= "dirty_background_bytes",
1289 .data
= &dirty_background_bytes
,
1290 .maxlen
= sizeof(dirty_background_bytes
),
1292 .proc_handler
= dirty_background_bytes_handler
,
1296 .procname
= "dirty_ratio",
1297 .data
= &vm_dirty_ratio
,
1298 .maxlen
= sizeof(vm_dirty_ratio
),
1300 .proc_handler
= dirty_ratio_handler
,
1302 .extra2
= &one_hundred
,
1305 .procname
= "dirty_bytes",
1306 .data
= &vm_dirty_bytes
,
1307 .maxlen
= sizeof(vm_dirty_bytes
),
1309 .proc_handler
= dirty_bytes_handler
,
1310 .extra1
= &dirty_bytes_min
,
1313 .procname
= "dirty_writeback_centisecs",
1314 .data
= &dirty_writeback_interval
,
1315 .maxlen
= sizeof(dirty_writeback_interval
),
1317 .proc_handler
= dirty_writeback_centisecs_handler
,
1320 .procname
= "dirty_expire_centisecs",
1321 .data
= &dirty_expire_interval
,
1322 .maxlen
= sizeof(dirty_expire_interval
),
1324 .proc_handler
= proc_dointvec_minmax
,
1328 .procname
= "dirtytime_expire_seconds",
1329 .data
= &dirtytime_expire_interval
,
1330 .maxlen
= sizeof(dirty_expire_interval
),
1332 .proc_handler
= dirtytime_interval_handler
,
1336 .procname
= "swappiness",
1337 .data
= &vm_swappiness
,
1338 .maxlen
= sizeof(vm_swappiness
),
1340 .proc_handler
= proc_dointvec_minmax
,
1342 .extra2
= &one_hundred
,
1344 #ifdef CONFIG_HUGETLB_PAGE
1346 .procname
= "nr_hugepages",
1348 .maxlen
= sizeof(unsigned long),
1350 .proc_handler
= hugetlb_sysctl_handler
,
1354 .procname
= "nr_hugepages_mempolicy",
1356 .maxlen
= sizeof(unsigned long),
1358 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1361 .procname
= "numa_stat",
1362 .data
= &sysctl_vm_numa_stat
,
1363 .maxlen
= sizeof(int),
1365 .proc_handler
= sysctl_vm_numa_stat_handler
,
1371 .procname
= "hugetlb_shm_group",
1372 .data
= &sysctl_hugetlb_shm_group
,
1373 .maxlen
= sizeof(gid_t
),
1375 .proc_handler
= proc_dointvec
,
1378 .procname
= "hugepages_treat_as_movable",
1379 .data
= &hugepages_treat_as_movable
,
1380 .maxlen
= sizeof(int),
1382 .proc_handler
= proc_dointvec
,
1385 .procname
= "nr_overcommit_hugepages",
1387 .maxlen
= sizeof(unsigned long),
1389 .proc_handler
= hugetlb_overcommit_handler
,
1393 .procname
= "lowmem_reserve_ratio",
1394 .data
= &sysctl_lowmem_reserve_ratio
,
1395 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1397 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1400 .procname
= "drop_caches",
1401 .data
= &sysctl_drop_caches
,
1402 .maxlen
= sizeof(int),
1404 .proc_handler
= drop_caches_sysctl_handler
,
1408 #ifdef CONFIG_COMPACTION
1410 .procname
= "compact_memory",
1411 .data
= &sysctl_compact_memory
,
1412 .maxlen
= sizeof(int),
1414 .proc_handler
= sysctl_compaction_handler
,
1417 .procname
= "extfrag_threshold",
1418 .data
= &sysctl_extfrag_threshold
,
1419 .maxlen
= sizeof(int),
1421 .proc_handler
= sysctl_extfrag_handler
,
1422 .extra1
= &min_extfrag_threshold
,
1423 .extra2
= &max_extfrag_threshold
,
1426 .procname
= "compact_unevictable_allowed",
1427 .data
= &sysctl_compact_unevictable_allowed
,
1428 .maxlen
= sizeof(int),
1430 .proc_handler
= proc_dointvec
,
1435 #endif /* CONFIG_COMPACTION */
1437 .procname
= "min_free_kbytes",
1438 .data
= &min_free_kbytes
,
1439 .maxlen
= sizeof(min_free_kbytes
),
1441 .proc_handler
= min_free_kbytes_sysctl_handler
,
1445 .procname
= "watermark_scale_factor",
1446 .data
= &watermark_scale_factor
,
1447 .maxlen
= sizeof(watermark_scale_factor
),
1449 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1451 .extra2
= &one_thousand
,
1454 .procname
= "percpu_pagelist_fraction",
1455 .data
= &percpu_pagelist_fraction
,
1456 .maxlen
= sizeof(percpu_pagelist_fraction
),
1458 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1463 .procname
= "max_map_count",
1464 .data
= &sysctl_max_map_count
,
1465 .maxlen
= sizeof(sysctl_max_map_count
),
1467 .proc_handler
= proc_dointvec_minmax
,
1472 .procname
= "nr_trim_pages",
1473 .data
= &sysctl_nr_trim_pages
,
1474 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1476 .proc_handler
= proc_dointvec_minmax
,
1481 .procname
= "laptop_mode",
1482 .data
= &laptop_mode
,
1483 .maxlen
= sizeof(laptop_mode
),
1485 .proc_handler
= proc_dointvec_jiffies
,
1488 .procname
= "block_dump",
1489 .data
= &block_dump
,
1490 .maxlen
= sizeof(block_dump
),
1492 .proc_handler
= proc_dointvec
,
1496 .procname
= "vfs_cache_pressure",
1497 .data
= &sysctl_vfs_cache_pressure
,
1498 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1500 .proc_handler
= proc_dointvec
,
1503 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1505 .procname
= "legacy_va_layout",
1506 .data
= &sysctl_legacy_va_layout
,
1507 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1509 .proc_handler
= proc_dointvec
,
1515 .procname
= "zone_reclaim_mode",
1516 .data
= &node_reclaim_mode
,
1517 .maxlen
= sizeof(node_reclaim_mode
),
1519 .proc_handler
= proc_dointvec
,
1523 .procname
= "min_unmapped_ratio",
1524 .data
= &sysctl_min_unmapped_ratio
,
1525 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1527 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1529 .extra2
= &one_hundred
,
1532 .procname
= "min_slab_ratio",
1533 .data
= &sysctl_min_slab_ratio
,
1534 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1536 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1538 .extra2
= &one_hundred
,
1543 .procname
= "stat_interval",
1544 .data
= &sysctl_stat_interval
,
1545 .maxlen
= sizeof(sysctl_stat_interval
),
1547 .proc_handler
= proc_dointvec_jiffies
,
1550 .procname
= "stat_refresh",
1554 .proc_handler
= vmstat_refresh
,
1559 .procname
= "mmap_min_addr",
1560 .data
= &dac_mmap_min_addr
,
1561 .maxlen
= sizeof(unsigned long),
1563 .proc_handler
= mmap_min_addr_handler
,
1568 .procname
= "numa_zonelist_order",
1569 .data
= &numa_zonelist_order
,
1570 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1572 .proc_handler
= numa_zonelist_order_handler
,
1575 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1576 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1578 .procname
= "vdso_enabled",
1579 #ifdef CONFIG_X86_32
1580 .data
= &vdso32_enabled
,
1581 .maxlen
= sizeof(vdso32_enabled
),
1583 .data
= &vdso_enabled
,
1584 .maxlen
= sizeof(vdso_enabled
),
1587 .proc_handler
= proc_dointvec
,
1591 #ifdef CONFIG_HIGHMEM
1593 .procname
= "highmem_is_dirtyable",
1594 .data
= &vm_highmem_is_dirtyable
,
1595 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1597 .proc_handler
= proc_dointvec_minmax
,
1602 #ifdef CONFIG_MEMORY_FAILURE
1604 .procname
= "memory_failure_early_kill",
1605 .data
= &sysctl_memory_failure_early_kill
,
1606 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1608 .proc_handler
= proc_dointvec_minmax
,
1613 .procname
= "memory_failure_recovery",
1614 .data
= &sysctl_memory_failure_recovery
,
1615 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1617 .proc_handler
= proc_dointvec_minmax
,
1623 .procname
= "user_reserve_kbytes",
1624 .data
= &sysctl_user_reserve_kbytes
,
1625 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1627 .proc_handler
= proc_doulongvec_minmax
,
1630 .procname
= "admin_reserve_kbytes",
1631 .data
= &sysctl_admin_reserve_kbytes
,
1632 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1634 .proc_handler
= proc_doulongvec_minmax
,
1636 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1638 .procname
= "mmap_rnd_bits",
1639 .data
= &mmap_rnd_bits
,
1640 .maxlen
= sizeof(mmap_rnd_bits
),
1642 .proc_handler
= proc_dointvec_minmax
,
1643 .extra1
= (void *)&mmap_rnd_bits_min
,
1644 .extra2
= (void *)&mmap_rnd_bits_max
,
1647 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1649 .procname
= "mmap_rnd_compat_bits",
1650 .data
= &mmap_rnd_compat_bits
,
1651 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1653 .proc_handler
= proc_dointvec_minmax
,
1654 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1655 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1661 static struct ctl_table fs_table
[] = {
1663 .procname
= "inode-nr",
1664 .data
= &inodes_stat
,
1665 .maxlen
= 2*sizeof(long),
1667 .proc_handler
= proc_nr_inodes
,
1670 .procname
= "inode-state",
1671 .data
= &inodes_stat
,
1672 .maxlen
= 7*sizeof(long),
1674 .proc_handler
= proc_nr_inodes
,
1677 .procname
= "file-nr",
1678 .data
= &files_stat
,
1679 .maxlen
= sizeof(files_stat
),
1681 .proc_handler
= proc_nr_files
,
1684 .procname
= "file-max",
1685 .data
= &files_stat
.max_files
,
1686 .maxlen
= sizeof(files_stat
.max_files
),
1688 .proc_handler
= proc_doulongvec_minmax
,
1691 .procname
= "nr_open",
1692 .data
= &sysctl_nr_open
,
1693 .maxlen
= sizeof(unsigned int),
1695 .proc_handler
= proc_dointvec_minmax
,
1696 .extra1
= &sysctl_nr_open_min
,
1697 .extra2
= &sysctl_nr_open_max
,
1700 .procname
= "dentry-state",
1701 .data
= &dentry_stat
,
1702 .maxlen
= 6*sizeof(long),
1704 .proc_handler
= proc_nr_dentry
,
1707 .procname
= "overflowuid",
1708 .data
= &fs_overflowuid
,
1709 .maxlen
= sizeof(int),
1711 .proc_handler
= proc_dointvec_minmax
,
1712 .extra1
= &minolduid
,
1713 .extra2
= &maxolduid
,
1716 .procname
= "overflowgid",
1717 .data
= &fs_overflowgid
,
1718 .maxlen
= sizeof(int),
1720 .proc_handler
= proc_dointvec_minmax
,
1721 .extra1
= &minolduid
,
1722 .extra2
= &maxolduid
,
1724 #ifdef CONFIG_FILE_LOCKING
1726 .procname
= "leases-enable",
1727 .data
= &leases_enable
,
1728 .maxlen
= sizeof(int),
1730 .proc_handler
= proc_dointvec
,
1733 #ifdef CONFIG_DNOTIFY
1735 .procname
= "dir-notify-enable",
1736 .data
= &dir_notify_enable
,
1737 .maxlen
= sizeof(int),
1739 .proc_handler
= proc_dointvec
,
1743 #ifdef CONFIG_FILE_LOCKING
1745 .procname
= "lease-break-time",
1746 .data
= &lease_break_time
,
1747 .maxlen
= sizeof(int),
1749 .proc_handler
= proc_dointvec
,
1754 .procname
= "aio-nr",
1756 .maxlen
= sizeof(aio_nr
),
1758 .proc_handler
= proc_doulongvec_minmax
,
1761 .procname
= "aio-max-nr",
1762 .data
= &aio_max_nr
,
1763 .maxlen
= sizeof(aio_max_nr
),
1765 .proc_handler
= proc_doulongvec_minmax
,
1767 #endif /* CONFIG_AIO */
1768 #ifdef CONFIG_INOTIFY_USER
1770 .procname
= "inotify",
1772 .child
= inotify_table
,
1777 .procname
= "epoll",
1779 .child
= epoll_table
,
1784 .procname
= "protected_symlinks",
1785 .data
= &sysctl_protected_symlinks
,
1786 .maxlen
= sizeof(int),
1788 .proc_handler
= proc_dointvec_minmax
,
1793 .procname
= "protected_hardlinks",
1794 .data
= &sysctl_protected_hardlinks
,
1795 .maxlen
= sizeof(int),
1797 .proc_handler
= proc_dointvec_minmax
,
1802 .procname
= "suid_dumpable",
1803 .data
= &suid_dumpable
,
1804 .maxlen
= sizeof(int),
1806 .proc_handler
= proc_dointvec_minmax_coredump
,
1810 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1812 .procname
= "binfmt_misc",
1814 .child
= sysctl_mount_point
,
1818 .procname
= "pipe-max-size",
1819 .data
= &pipe_max_size
,
1820 .maxlen
= sizeof(pipe_max_size
),
1822 .proc_handler
= &pipe_proc_fn
,
1823 .extra1
= &pipe_min_size
,
1826 .procname
= "pipe-user-pages-hard",
1827 .data
= &pipe_user_pages_hard
,
1828 .maxlen
= sizeof(pipe_user_pages_hard
),
1830 .proc_handler
= proc_doulongvec_minmax
,
1833 .procname
= "pipe-user-pages-soft",
1834 .data
= &pipe_user_pages_soft
,
1835 .maxlen
= sizeof(pipe_user_pages_soft
),
1837 .proc_handler
= proc_doulongvec_minmax
,
1840 .procname
= "mount-max",
1841 .data
= &sysctl_mount_max
,
1842 .maxlen
= sizeof(unsigned int),
1844 .proc_handler
= proc_dointvec_minmax
,
1850 static struct ctl_table debug_table
[] = {
1851 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1853 .procname
= "exception-trace",
1854 .data
= &show_unhandled_signals
,
1855 .maxlen
= sizeof(int),
1857 .proc_handler
= proc_dointvec
1860 #if defined(CONFIG_OPTPROBES)
1862 .procname
= "kprobes-optimization",
1863 .data
= &sysctl_kprobes_optimization
,
1864 .maxlen
= sizeof(int),
1866 .proc_handler
= proc_kprobes_optimization_handler
,
1874 static struct ctl_table dev_table
[] = {
1878 int __init
sysctl_init(void)
1880 struct ctl_table_header
*hdr
;
1882 hdr
= register_sysctl_table(sysctl_base_table
);
1883 kmemleak_not_leak(hdr
);
1887 #endif /* CONFIG_SYSCTL */
1893 #ifdef CONFIG_PROC_SYSCTL
1895 static int _proc_do_string(char *data
, int maxlen
, int write
,
1896 char __user
*buffer
,
1897 size_t *lenp
, loff_t
*ppos
)
1903 if (!data
|| !maxlen
|| !*lenp
) {
1909 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1910 /* Only continue writes not past the end of buffer. */
1912 if (len
> maxlen
- 1)
1919 /* Start writing from beginning of buffer. */
1925 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1926 if (get_user(c
, p
++))
1928 if (c
== 0 || c
== '\n')
1949 if (copy_to_user(buffer
, data
, len
))
1952 if (put_user('\n', buffer
+ len
))
1962 static void warn_sysctl_write(struct ctl_table
*table
)
1964 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1965 "This will not be supported in the future. To silence this\n"
1966 "warning, set kernel.sysctl_writes_strict = -1\n",
1967 current
->comm
, table
->procname
);
1971 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1972 * @ppos: file position
1973 * @table: the sysctl table
1975 * Returns true if the first position is non-zero and the sysctl_writes_strict
1976 * mode indicates this is not allowed for numeric input types. String proc
1977 * hadlers can ignore the return value.
1979 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
1980 struct ctl_table
*table
)
1985 switch (sysctl_writes_strict
) {
1986 case SYSCTL_WRITES_STRICT
:
1988 case SYSCTL_WRITES_WARN
:
1989 warn_sysctl_write(table
);
1997 * proc_dostring - read a string sysctl
1998 * @table: the sysctl table
1999 * @write: %TRUE if this is a write to the sysctl file
2000 * @buffer: the user buffer
2001 * @lenp: the size of the user buffer
2002 * @ppos: file position
2004 * Reads/writes a string from/to the user buffer. If the kernel
2005 * buffer provided is not large enough to hold the string, the
2006 * string is truncated. The copied string is %NULL-terminated.
2007 * If the string is being read by the user process, it is copied
2008 * and a newline '\n' is added. It is truncated if the buffer is
2011 * Returns 0 on success.
2013 int proc_dostring(struct ctl_table
*table
, int write
,
2014 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2017 proc_first_pos_non_zero_ignore(ppos
, table
);
2019 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2020 (char __user
*)buffer
, lenp
, ppos
);
2023 static size_t proc_skip_spaces(char **buf
)
2026 char *tmp
= skip_spaces(*buf
);
2032 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2042 #define TMPBUFLEN 22
2044 * proc_get_long - reads an ASCII formatted integer from a user buffer
2046 * @buf: a kernel buffer
2047 * @size: size of the kernel buffer
2048 * @val: this is where the number will be stored
2049 * @neg: set to %TRUE if number is negative
2050 * @perm_tr: a vector which contains the allowed trailers
2051 * @perm_tr_len: size of the perm_tr vector
2052 * @tr: pointer to store the trailer character
2054 * In case of success %0 is returned and @buf and @size are updated with
2055 * the amount of bytes read. If @tr is non-NULL and a trailing
2056 * character exists (size is non-zero after returning from this
2057 * function), @tr is updated with the trailing character.
2059 static int proc_get_long(char **buf
, size_t *size
,
2060 unsigned long *val
, bool *neg
,
2061 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2064 char *p
, tmp
[TMPBUFLEN
];
2070 if (len
> TMPBUFLEN
- 1)
2071 len
= TMPBUFLEN
- 1;
2073 memcpy(tmp
, *buf
, len
);
2077 if (*p
== '-' && *size
> 1) {
2085 *val
= simple_strtoul(p
, &p
, 0);
2089 /* We don't know if the next char is whitespace thus we may accept
2090 * invalid integers (e.g. 1234...a) or two integers instead of one
2091 * (e.g. 123...1). So lets not allow such large numbers. */
2092 if (len
== TMPBUFLEN
- 1)
2095 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2098 if (tr
&& (len
< *size
))
2108 * proc_put_long - converts an integer to a decimal ASCII formatted string
2110 * @buf: the user buffer
2111 * @size: the size of the user buffer
2112 * @val: the integer to be converted
2113 * @neg: sign of the number, %TRUE for negative
2115 * In case of success %0 is returned and @buf and @size are updated with
2116 * the amount of bytes written.
2118 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2122 char tmp
[TMPBUFLEN
], *p
= tmp
;
2124 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2128 if (copy_to_user(*buf
, tmp
, len
))
2136 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2139 char __user
**buffer
= (char __user
**)buf
;
2140 if (put_user(c
, *buffer
))
2142 (*size
)--, (*buffer
)++;
2148 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2150 int write
, void *data
)
2154 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2158 if (*lvalp
> (unsigned long) INT_MAX
)
2166 *lvalp
= -(unsigned long)val
;
2169 *lvalp
= (unsigned long)val
;
2175 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2177 int write
, void *data
)
2180 if (*lvalp
> UINT_MAX
)
2184 unsigned int val
= *valp
;
2185 *lvalp
= (unsigned long)val
;
2190 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2192 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2193 int write
, void __user
*buffer
,
2194 size_t *lenp
, loff_t
*ppos
,
2195 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2196 int write
, void *data
),
2199 int *i
, vleft
, first
= 1, err
= 0;
2201 char *kbuf
= NULL
, *p
;
2203 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2208 i
= (int *) tbl_data
;
2209 vleft
= table
->maxlen
/ sizeof(*i
);
2213 conv
= do_proc_dointvec_conv
;
2216 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2219 if (left
> PAGE_SIZE
- 1)
2220 left
= PAGE_SIZE
- 1;
2221 p
= kbuf
= memdup_user_nul(buffer
, left
);
2223 return PTR_ERR(kbuf
);
2226 for (; left
&& vleft
--; i
++, first
=0) {
2231 left
-= proc_skip_spaces(&p
);
2235 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2237 sizeof(proc_wspace_sep
), NULL
);
2240 if (conv(&neg
, &lval
, i
, 1, data
)) {
2245 if (conv(&neg
, &lval
, i
, 0, data
)) {
2250 err
= proc_put_char(&buffer
, &left
, '\t');
2253 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2259 if (!write
&& !first
&& left
&& !err
)
2260 err
= proc_put_char(&buffer
, &left
, '\n');
2261 if (write
&& !err
&& left
)
2262 left
-= proc_skip_spaces(&p
);
2266 return err
? : -EINVAL
;
2274 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2275 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2276 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2277 int write
, void *data
),
2280 return __do_proc_dointvec(table
->data
, table
, write
,
2281 buffer
, lenp
, ppos
, conv
, data
);
2284 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2285 struct ctl_table
*table
,
2286 void __user
*buffer
,
2287 size_t *lenp
, loff_t
*ppos
,
2288 int (*conv
)(unsigned long *lvalp
,
2290 int write
, void *data
),
2297 char *kbuf
= NULL
, *p
;
2301 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2304 if (left
> PAGE_SIZE
- 1)
2305 left
= PAGE_SIZE
- 1;
2307 p
= kbuf
= memdup_user_nul(buffer
, left
);
2311 left
-= proc_skip_spaces(&p
);
2317 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2319 sizeof(proc_wspace_sep
), NULL
);
2325 if (conv(&lval
, tbl_data
, 1, data
)) {
2331 left
-= proc_skip_spaces(&p
);
2340 /* This is in keeping with old __do_proc_dointvec() */
2346 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2347 size_t *lenp
, loff_t
*ppos
,
2348 int (*conv
)(unsigned long *lvalp
,
2350 int write
, void *data
),
2359 if (conv(&lval
, tbl_data
, 0, data
)) {
2364 err
= proc_put_long(&buffer
, &left
, lval
, false);
2368 err
= proc_put_char(&buffer
, &left
, '\n');
2377 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2378 int write
, void __user
*buffer
,
2379 size_t *lenp
, loff_t
*ppos
,
2380 int (*conv
)(unsigned long *lvalp
,
2382 int write
, void *data
),
2385 unsigned int *i
, vleft
;
2387 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2392 i
= (unsigned int *) tbl_data
;
2393 vleft
= table
->maxlen
/ sizeof(*i
);
2396 * Arrays are not supported, keep this simple. *Do not* add
2405 conv
= do_proc_douintvec_conv
;
2408 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2410 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2413 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2414 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2415 int (*conv
)(unsigned long *lvalp
,
2417 int write
, void *data
),
2420 return __do_proc_douintvec(table
->data
, table
, write
,
2421 buffer
, lenp
, ppos
, conv
, data
);
2425 * proc_dointvec - read a vector of integers
2426 * @table: the sysctl table
2427 * @write: %TRUE if this is a write to the sysctl file
2428 * @buffer: the user buffer
2429 * @lenp: the size of the user buffer
2430 * @ppos: file position
2432 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2433 * values from/to the user buffer, treated as an ASCII string.
2435 * Returns 0 on success.
2437 int proc_dointvec(struct ctl_table
*table
, int write
,
2438 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2440 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2444 * proc_douintvec - read a vector of unsigned integers
2445 * @table: the sysctl table
2446 * @write: %TRUE if this is a write to the sysctl file
2447 * @buffer: the user buffer
2448 * @lenp: the size of the user buffer
2449 * @ppos: file position
2451 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2452 * values from/to the user buffer, treated as an ASCII string.
2454 * Returns 0 on success.
2456 int proc_douintvec(struct ctl_table
*table
, int write
,
2457 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2459 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2460 do_proc_douintvec_conv
, NULL
);
2464 * Taint values can only be increased
2465 * This means we can safely use a temporary.
2467 static int proc_taint(struct ctl_table
*table
, int write
,
2468 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2471 unsigned long tmptaint
= get_taint();
2474 if (write
&& !capable(CAP_SYS_ADMIN
))
2479 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2485 * Poor man's atomic or. Not worth adding a primitive
2486 * to everyone's atomic.h for this
2489 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2490 if ((tmptaint
>> i
) & 1)
2491 add_taint(i
, LOCKDEP_STILL_OK
);
2498 #ifdef CONFIG_PRINTK
2499 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2500 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2502 if (write
&& !capable(CAP_SYS_ADMIN
))
2505 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2509 struct do_proc_dointvec_minmax_conv_param
{
2514 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2516 int write
, void *data
)
2518 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2520 int val
= *negp
? -*lvalp
: *lvalp
;
2521 if ((param
->min
&& *param
->min
> val
) ||
2522 (param
->max
&& *param
->max
< val
))
2529 *lvalp
= -(unsigned long)val
;
2532 *lvalp
= (unsigned long)val
;
2539 * proc_dointvec_minmax - read a vector of integers with min/max values
2540 * @table: the sysctl table
2541 * @write: %TRUE if this is a write to the sysctl file
2542 * @buffer: the user buffer
2543 * @lenp: the size of the user buffer
2544 * @ppos: file position
2546 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2547 * values from/to the user buffer, treated as an ASCII string.
2549 * This routine will ensure the values are within the range specified by
2550 * table->extra1 (min) and table->extra2 (max).
2552 * Returns 0 on success.
2554 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2555 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2557 struct do_proc_dointvec_minmax_conv_param param
= {
2558 .min
= (int *) table
->extra1
,
2559 .max
= (int *) table
->extra2
,
2561 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2562 do_proc_dointvec_minmax_conv
, ¶m
);
2565 struct do_proc_douintvec_minmax_conv_param
{
2570 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2572 int write
, void *data
)
2574 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2577 unsigned int val
= *lvalp
;
2579 if (*lvalp
> UINT_MAX
)
2582 if ((param
->min
&& *param
->min
> val
) ||
2583 (param
->max
&& *param
->max
< val
))
2588 unsigned int val
= *valp
;
2589 *lvalp
= (unsigned long) val
;
2596 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2597 * @table: the sysctl table
2598 * @write: %TRUE if this is a write to the sysctl file
2599 * @buffer: the user buffer
2600 * @lenp: the size of the user buffer
2601 * @ppos: file position
2603 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2604 * values from/to the user buffer, treated as an ASCII string. Negative
2605 * strings are not allowed.
2607 * This routine will ensure the values are within the range specified by
2608 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2609 * check for UINT_MAX to avoid having to support wrap around uses from
2612 * Returns 0 on success.
2614 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2615 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2617 struct do_proc_douintvec_minmax_conv_param param
= {
2618 .min
= (unsigned int *) table
->extra1
,
2619 .max
= (unsigned int *) table
->extra2
,
2621 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2622 do_proc_douintvec_minmax_conv
, ¶m
);
2625 struct do_proc_dopipe_max_size_conv_param
{
2629 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp
,
2631 int write
, void *data
)
2633 struct do_proc_dopipe_max_size_conv_param
*param
= data
;
2638 if (*lvalp
> UINT_MAX
)
2641 val
= round_pipe_size(*lvalp
);
2645 if (param
->min
&& *param
->min
> val
)
2650 unsigned int val
= *valp
;
2651 *lvalp
= (unsigned long) val
;
2657 int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
2658 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2660 struct do_proc_dopipe_max_size_conv_param param
= {
2661 .min
= (unsigned int *) table
->extra1
,
2663 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2664 do_proc_dopipe_max_size_conv
, ¶m
);
2667 static void validate_coredump_safety(void)
2669 #ifdef CONFIG_COREDUMP
2670 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2671 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2673 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2674 "Pipe handler or fully qualified core dump path required.\n"
2675 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2681 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2682 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2684 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2686 validate_coredump_safety();
2690 #ifdef CONFIG_COREDUMP
2691 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2692 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2694 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2696 validate_coredump_safety();
2701 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2702 void __user
*buffer
,
2703 size_t *lenp
, loff_t
*ppos
,
2704 unsigned long convmul
,
2705 unsigned long convdiv
)
2707 unsigned long *i
, *min
, *max
;
2708 int vleft
, first
= 1, err
= 0;
2710 char *kbuf
= NULL
, *p
;
2712 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2717 i
= (unsigned long *) data
;
2718 min
= (unsigned long *) table
->extra1
;
2719 max
= (unsigned long *) table
->extra2
;
2720 vleft
= table
->maxlen
/ sizeof(unsigned long);
2724 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2727 if (left
> PAGE_SIZE
- 1)
2728 left
= PAGE_SIZE
- 1;
2729 p
= kbuf
= memdup_user_nul(buffer
, left
);
2731 return PTR_ERR(kbuf
);
2734 for (; left
&& vleft
--; i
++, first
= 0) {
2740 left
-= proc_skip_spaces(&p
);
2742 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2744 sizeof(proc_wspace_sep
), NULL
);
2749 val
= convmul
* val
/ convdiv
;
2750 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2754 val
= convdiv
* (*i
) / convmul
;
2756 err
= proc_put_char(&buffer
, &left
, '\t');
2760 err
= proc_put_long(&buffer
, &left
, val
, false);
2766 if (!write
&& !first
&& left
&& !err
)
2767 err
= proc_put_char(&buffer
, &left
, '\n');
2769 left
-= proc_skip_spaces(&p
);
2773 return err
? : -EINVAL
;
2781 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2782 void __user
*buffer
,
2783 size_t *lenp
, loff_t
*ppos
,
2784 unsigned long convmul
,
2785 unsigned long convdiv
)
2787 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2788 buffer
, lenp
, ppos
, convmul
, convdiv
);
2792 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2793 * @table: the sysctl table
2794 * @write: %TRUE if this is a write to the sysctl file
2795 * @buffer: the user buffer
2796 * @lenp: the size of the user buffer
2797 * @ppos: file position
2799 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2800 * values from/to the user buffer, treated as an ASCII string.
2802 * This routine will ensure the values are within the range specified by
2803 * table->extra1 (min) and table->extra2 (max).
2805 * Returns 0 on success.
2807 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2808 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2810 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2814 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2815 * @table: the sysctl table
2816 * @write: %TRUE if this is a write to the sysctl file
2817 * @buffer: the user buffer
2818 * @lenp: the size of the user buffer
2819 * @ppos: file position
2821 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2822 * values from/to the user buffer, treated as an ASCII string. The values
2823 * are treated as milliseconds, and converted to jiffies when they are stored.
2825 * This routine will ensure the values are within the range specified by
2826 * table->extra1 (min) and table->extra2 (max).
2828 * Returns 0 on success.
2830 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2831 void __user
*buffer
,
2832 size_t *lenp
, loff_t
*ppos
)
2834 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2835 lenp
, ppos
, HZ
, 1000l);
2839 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2841 int write
, void *data
)
2844 if (*lvalp
> INT_MAX
/ HZ
)
2846 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2852 lval
= -(unsigned long)val
;
2855 lval
= (unsigned long)val
;
2862 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2864 int write
, void *data
)
2867 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2869 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2875 lval
= -(unsigned long)val
;
2878 lval
= (unsigned long)val
;
2880 *lvalp
= jiffies_to_clock_t(lval
);
2885 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2887 int write
, void *data
)
2890 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2900 lval
= -(unsigned long)val
;
2903 lval
= (unsigned long)val
;
2905 *lvalp
= jiffies_to_msecs(lval
);
2911 * proc_dointvec_jiffies - read a vector of integers as seconds
2912 * @table: the sysctl table
2913 * @write: %TRUE if this is a write to the sysctl file
2914 * @buffer: the user buffer
2915 * @lenp: the size of the user buffer
2916 * @ppos: file position
2918 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2919 * values from/to the user buffer, treated as an ASCII string.
2920 * The values read are assumed to be in seconds, and are converted into
2923 * Returns 0 on success.
2925 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2926 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2928 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2929 do_proc_dointvec_jiffies_conv
,NULL
);
2933 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2934 * @table: the sysctl table
2935 * @write: %TRUE if this is a write to the sysctl file
2936 * @buffer: the user buffer
2937 * @lenp: the size of the user buffer
2938 * @ppos: pointer to the file position
2940 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2941 * values from/to the user buffer, treated as an ASCII string.
2942 * The values read are assumed to be in 1/USER_HZ seconds, and
2943 * are converted into jiffies.
2945 * Returns 0 on success.
2947 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2948 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2950 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2951 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2955 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
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
2961 * @ppos: the current position in the file
2963 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2964 * values from/to the user buffer, treated as an ASCII string.
2965 * The values read are assumed to be in 1/1000 seconds, and
2966 * are converted into jiffies.
2968 * Returns 0 on success.
2970 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2971 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2973 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2974 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2977 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2978 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2980 struct pid
*new_pid
;
2984 tmp
= pid_vnr(cad_pid
);
2986 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2987 lenp
, ppos
, NULL
, NULL
);
2991 new_pid
= find_get_pid(tmp
);
2995 put_pid(xchg(&cad_pid
, new_pid
));
3000 * proc_do_large_bitmap - read/write from/to a large bitmap
3001 * @table: the sysctl table
3002 * @write: %TRUE if this is a write to the sysctl file
3003 * @buffer: the user buffer
3004 * @lenp: the size of the user buffer
3005 * @ppos: file position
3007 * The bitmap is stored at table->data and the bitmap length (in bits)
3010 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3011 * large bitmaps may be represented in a compact manner. Writing into
3012 * the file will clear the bitmap then update it with the given input.
3014 * Returns 0 on success.
3016 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3017 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3021 size_t left
= *lenp
;
3022 unsigned long bitmap_len
= table
->maxlen
;
3023 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3024 unsigned long *tmp_bitmap
= NULL
;
3025 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3027 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3035 if (left
> PAGE_SIZE
- 1)
3036 left
= PAGE_SIZE
- 1;
3038 p
= kbuf
= memdup_user_nul(buffer
, left
);
3040 return PTR_ERR(kbuf
);
3042 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
3048 proc_skip_char(&p
, &left
, '\n');
3049 while (!err
&& left
) {
3050 unsigned long val_a
, val_b
;
3053 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3057 if (val_a
>= bitmap_len
|| neg
) {
3069 err
= proc_get_long(&p
, &left
, &val_b
,
3070 &neg
, tr_b
, sizeof(tr_b
),
3074 if (val_b
>= bitmap_len
|| neg
||
3085 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3087 proc_skip_char(&p
, &left
, '\n');
3091 unsigned long bit_a
, bit_b
= 0;
3094 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3095 if (bit_a
>= bitmap_len
)
3097 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3101 err
= proc_put_char(&buffer
, &left
, ',');
3105 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3108 if (bit_a
!= bit_b
) {
3109 err
= proc_put_char(&buffer
, &left
, '-');
3112 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3120 err
= proc_put_char(&buffer
, &left
, '\n');
3126 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3128 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3138 #else /* CONFIG_PROC_SYSCTL */
3140 int proc_dostring(struct ctl_table
*table
, int write
,
3141 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3146 int proc_dointvec(struct ctl_table
*table
, int write
,
3147 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3152 int proc_douintvec(struct ctl_table
*table
, int write
,
3153 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3158 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3159 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3164 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3165 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3170 int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
3171 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3176 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3177 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3182 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3183 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3188 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3189 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3194 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3195 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3200 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3201 void __user
*buffer
,
3202 size_t *lenp
, loff_t
*ppos
)
3208 #endif /* CONFIG_PROC_SYSCTL */
3211 * No sense putting this after each symbol definition, twice,
3212 * exception granted :-)
3214 EXPORT_SYMBOL(proc_dointvec
);
3215 EXPORT_SYMBOL(proc_douintvec
);
3216 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3217 EXPORT_SYMBOL(proc_dointvec_minmax
);
3218 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3219 EXPORT_SYMBOL_GPL(proc_dopipe_max_size
);
3220 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3221 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3222 EXPORT_SYMBOL(proc_dostring
);
3223 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3224 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);