2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/aio.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/sched/coredump.h>
66 #include <linux/kexec.h>
67 #include <linux/bpf.h>
68 #include <linux/mount.h>
69 #include <linux/pipe_fs_i.h>
71 #include "../lib/kstrtox.h"
73 #include <linux/uaccess.h>
74 #include <asm/processor.h>
78 #include <asm/stacktrace.h>
82 #include <asm/setup.h>
84 #ifdef CONFIG_BSD_PROCESS_ACCT
85 #include <linux/acct.h>
87 #ifdef CONFIG_RT_MUTEXES
88 #include <linux/rtmutex.h>
90 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
91 #include <linux/lockdep.h>
93 #ifdef CONFIG_CHR_DEV_SG
97 #ifdef CONFIG_LOCKUP_DETECTOR
98 #include <linux/nmi.h>
101 #if defined(CONFIG_SYSCTL)
103 /* External variables not in a header file. */
104 extern int suid_dumpable;
105 #ifdef CONFIG_COREDUMP
106 extern int core_uses_pid;
107 extern char core_pattern[];
108 extern unsigned int core_pipe_limit;
111 extern int pid_max_min, pid_max_max;
112 extern int percpu_pagelist_fraction;
113 extern int latencytop_enabled;
114 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
116 extern int sysctl_nr_trim_pages;
119 /* Constants used for minimum and maximum */
120 #ifdef CONFIG_LOCKUP_DETECTOR
121 static int sixty = 60;
124 static int __maybe_unused neg_one = -1;
127 static int __maybe_unused one = 1;
128 static int __maybe_unused two = 2;
129 static int __maybe_unused four = 4;
130 static unsigned long zero_ul;
131 static unsigned long one_ul = 1;
132 static unsigned long long_max = LONG_MAX;
133 static int one_hundred = 100;
134 static int one_thousand = 1000;
136 static int ten_thousand = 10000;
138 #ifdef CONFIG_PERF_EVENTS
139 static int six_hundred_forty_kb = 640 * 1024;
142 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
143 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
145 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
146 static int maxolduid = 65535;
147 static int minolduid;
149 static int ngroups_max = NGROUPS_MAX;
150 static const int cap_last_cap = CAP_LAST_CAP;
153 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
154 * and hung_task_check_interval_secs
156 #ifdef CONFIG_DETECT_HUNG_TASK
157 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
160 #ifdef CONFIG_INOTIFY_USER
161 #include <linux/inotify.h>
167 extern int pwrsw_enabled;
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
171 extern int unaligned_enabled;
175 extern int unaligned_dump_stack;
178 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179 extern int no_unaligned_warning;
182 #ifdef CONFIG_PROC_SYSCTL
185 * enum sysctl_writes_mode - supported sysctl write modes
187 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
188 * to be written, and multiple writes on the same sysctl file descriptor
189 * will rewrite the sysctl value, regardless of file position. No warning
190 * is issued when the initial position is not 0.
191 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
193 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
194 * file position 0 and the value must be fully contained in the buffer
195 * sent to the write syscall. If dealing with strings respect the file
196 * position, but restrict this to the max length of the buffer, anything
197 * passed the max lenght will be ignored. Multiple writes will append
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
203 enum sysctl_writes_mode {
204 SYSCTL_WRITES_LEGACY = -1,
205 SYSCTL_WRITES_WARN = 0,
206 SYSCTL_WRITES_STRICT = 1,
209 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
211 static int proc_do_cad_pid(struct ctl_table *table, int write,
212 void __user *buffer, size_t *lenp, loff_t *ppos);
213 static int proc_taint(struct ctl_table *table, int write,
214 void __user *buffer, size_t *lenp, loff_t *ppos);
218 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
219 void __user *buffer, size_t *lenp, loff_t *ppos);
222 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
223 void __user *buffer, size_t *lenp, loff_t *ppos);
224 #ifdef CONFIG_COREDUMP
225 static int proc_dostring_coredump(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
228 static int proc_dopipe_max_size(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp, loff_t *ppos);
231 #ifdef CONFIG_MAGIC_SYSRQ
232 /* Note: sysrq code uses its own private copy */
233 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
235 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
236 void __user *buffer, size_t *lenp,
241 error = proc_dointvec(table, write, buffer, lenp, ppos);
246 sysrq_toggle_support(__sysrq_enabled);
253 static struct ctl_table kern_table[];
254 static struct ctl_table vm_table[];
255 static struct ctl_table fs_table[];
256 static struct ctl_table debug_table[];
257 static struct ctl_table dev_table[];
258 extern struct ctl_table random_table[];
260 extern struct ctl_table epoll_table[];
263 #ifdef CONFIG_FW_LOADER_USER_HELPER
264 extern struct ctl_table firmware_config_table[];
267 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
268 int sysctl_legacy_va_layout;
271 /* The default sysctl tables: */
273 static struct ctl_table sysctl_base_table[] = {
275 .procname = "kernel",
292 .child = debug_table,
302 #ifdef CONFIG_SCHED_DEBUG
303 static int min_sched_granularity_ns = 100000; /* 100 usecs */
304 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
305 static int min_wakeup_granularity_ns; /* 0 usecs */
306 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
308 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
309 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
310 #endif /* CONFIG_SMP */
311 #endif /* CONFIG_SCHED_DEBUG */
313 #ifdef CONFIG_COMPACTION
314 static int min_extfrag_threshold;
315 static int max_extfrag_threshold = 1000;
318 static struct ctl_table kern_table[] = {
320 .procname = "sched_child_runs_first",
321 .data = &sysctl_sched_child_runs_first,
322 .maxlen = sizeof(unsigned int),
324 .proc_handler = proc_dointvec,
326 #ifdef CONFIG_SCHED_DEBUG
328 .procname = "sched_min_granularity_ns",
329 .data = &sysctl_sched_min_granularity,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = sched_proc_update_handler,
333 .extra1 = &min_sched_granularity_ns,
334 .extra2 = &max_sched_granularity_ns,
337 .procname = "sched_latency_ns",
338 .data = &sysctl_sched_latency,
339 .maxlen = sizeof(unsigned int),
341 .proc_handler = sched_proc_update_handler,
342 .extra1 = &min_sched_granularity_ns,
343 .extra2 = &max_sched_granularity_ns,
346 .procname = "sched_wakeup_granularity_ns",
347 .data = &sysctl_sched_wakeup_granularity,
348 .maxlen = sizeof(unsigned int),
350 .proc_handler = sched_proc_update_handler,
351 .extra1 = &min_wakeup_granularity_ns,
352 .extra2 = &max_wakeup_granularity_ns,
356 .procname = "sched_tunable_scaling",
357 .data = &sysctl_sched_tunable_scaling,
358 .maxlen = sizeof(enum sched_tunable_scaling),
360 .proc_handler = sched_proc_update_handler,
361 .extra1 = &min_sched_tunable_scaling,
362 .extra2 = &max_sched_tunable_scaling,
365 .procname = "sched_migration_cost_ns",
366 .data = &sysctl_sched_migration_cost,
367 .maxlen = sizeof(unsigned int),
369 .proc_handler = proc_dointvec,
372 .procname = "sched_nr_migrate",
373 .data = &sysctl_sched_nr_migrate,
374 .maxlen = sizeof(unsigned int),
376 .proc_handler = proc_dointvec,
378 #ifdef CONFIG_SCHEDSTATS
380 .procname = "sched_schedstats",
382 .maxlen = sizeof(unsigned int),
384 .proc_handler = sysctl_schedstats,
388 #endif /* CONFIG_SCHEDSTATS */
389 #endif /* CONFIG_SMP */
390 #ifdef CONFIG_NUMA_BALANCING
392 .procname = "numa_balancing_scan_delay_ms",
393 .data = &sysctl_numa_balancing_scan_delay,
394 .maxlen = sizeof(unsigned int),
396 .proc_handler = proc_dointvec,
399 .procname = "numa_balancing_scan_period_min_ms",
400 .data = &sysctl_numa_balancing_scan_period_min,
401 .maxlen = sizeof(unsigned int),
403 .proc_handler = proc_dointvec,
406 .procname = "numa_balancing_scan_period_max_ms",
407 .data = &sysctl_numa_balancing_scan_period_max,
408 .maxlen = sizeof(unsigned int),
410 .proc_handler = proc_dointvec,
413 .procname = "numa_balancing_scan_size_mb",
414 .data = &sysctl_numa_balancing_scan_size,
415 .maxlen = sizeof(unsigned int),
417 .proc_handler = proc_dointvec_minmax,
421 .procname = "numa_balancing",
422 .data = NULL, /* filled in by handler */
423 .maxlen = sizeof(unsigned int),
425 .proc_handler = sysctl_numa_balancing,
429 #endif /* CONFIG_NUMA_BALANCING */
430 #endif /* CONFIG_SCHED_DEBUG */
432 .procname = "sched_rt_period_us",
433 .data = &sysctl_sched_rt_period,
434 .maxlen = sizeof(unsigned int),
436 .proc_handler = sched_rt_handler,
439 .procname = "sched_rt_runtime_us",
440 .data = &sysctl_sched_rt_runtime,
441 .maxlen = sizeof(int),
443 .proc_handler = sched_rt_handler,
446 .procname = "sched_rr_timeslice_ms",
447 .data = &sysctl_sched_rr_timeslice,
448 .maxlen = sizeof(int),
450 .proc_handler = sched_rr_handler,
452 #ifdef CONFIG_SCHED_AUTOGROUP
454 .procname = "sched_autogroup_enabled",
455 .data = &sysctl_sched_autogroup_enabled,
456 .maxlen = sizeof(unsigned int),
458 .proc_handler = proc_dointvec_minmax,
463 #ifdef CONFIG_CFS_BANDWIDTH
465 .procname = "sched_cfs_bandwidth_slice_us",
466 .data = &sysctl_sched_cfs_bandwidth_slice,
467 .maxlen = sizeof(unsigned int),
469 .proc_handler = proc_dointvec_minmax,
473 #ifdef CONFIG_PROVE_LOCKING
475 .procname = "prove_locking",
476 .data = &prove_locking,
477 .maxlen = sizeof(int),
479 .proc_handler = proc_dointvec,
482 #ifdef CONFIG_LOCK_STAT
484 .procname = "lock_stat",
486 .maxlen = sizeof(int),
488 .proc_handler = proc_dointvec,
493 .data = &panic_timeout,
494 .maxlen = sizeof(int),
496 .proc_handler = proc_dointvec,
498 #ifdef CONFIG_COREDUMP
500 .procname = "core_uses_pid",
501 .data = &core_uses_pid,
502 .maxlen = sizeof(int),
504 .proc_handler = proc_dointvec,
507 .procname = "core_pattern",
508 .data = core_pattern,
509 .maxlen = CORENAME_MAX_SIZE,
511 .proc_handler = proc_dostring_coredump,
514 .procname = "core_pipe_limit",
515 .data = &core_pipe_limit,
516 .maxlen = sizeof(unsigned int),
518 .proc_handler = proc_dointvec,
521 #ifdef CONFIG_PROC_SYSCTL
523 .procname = "tainted",
524 .maxlen = sizeof(long),
526 .proc_handler = proc_taint,
529 .procname = "sysctl_writes_strict",
530 .data = &sysctl_writes_strict,
531 .maxlen = sizeof(int),
533 .proc_handler = proc_dointvec_minmax,
538 #ifdef CONFIG_LATENCYTOP
540 .procname = "latencytop",
541 .data = &latencytop_enabled,
542 .maxlen = sizeof(int),
544 .proc_handler = sysctl_latencytop,
547 #ifdef CONFIG_BLK_DEV_INITRD
549 .procname = "real-root-dev",
550 .data = &real_root_dev,
551 .maxlen = sizeof(int),
553 .proc_handler = proc_dointvec,
557 .procname = "print-fatal-signals",
558 .data = &print_fatal_signals,
559 .maxlen = sizeof(int),
561 .proc_handler = proc_dointvec,
565 .procname = "reboot-cmd",
566 .data = reboot_command,
569 .proc_handler = proc_dostring,
572 .procname = "stop-a",
573 .data = &stop_a_enabled,
574 .maxlen = sizeof (int),
576 .proc_handler = proc_dointvec,
579 .procname = "scons-poweroff",
580 .data = &scons_pwroff,
581 .maxlen = sizeof (int),
583 .proc_handler = proc_dointvec,
586 #ifdef CONFIG_SPARC64
588 .procname = "tsb-ratio",
589 .data = &sysctl_tsb_ratio,
590 .maxlen = sizeof (int),
592 .proc_handler = proc_dointvec,
597 .procname = "soft-power",
598 .data = &pwrsw_enabled,
599 .maxlen = sizeof (int),
601 .proc_handler = proc_dointvec,
604 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
606 .procname = "unaligned-trap",
607 .data = &unaligned_enabled,
608 .maxlen = sizeof (int),
610 .proc_handler = proc_dointvec,
614 .procname = "ctrl-alt-del",
616 .maxlen = sizeof(int),
618 .proc_handler = proc_dointvec,
620 #ifdef CONFIG_FUNCTION_TRACER
622 .procname = "ftrace_enabled",
623 .data = &ftrace_enabled,
624 .maxlen = sizeof(int),
626 .proc_handler = ftrace_enable_sysctl,
629 #ifdef CONFIG_STACK_TRACER
631 .procname = "stack_tracer_enabled",
632 .data = &stack_tracer_enabled,
633 .maxlen = sizeof(int),
635 .proc_handler = stack_trace_sysctl,
638 #ifdef CONFIG_TRACING
640 .procname = "ftrace_dump_on_oops",
641 .data = &ftrace_dump_on_oops,
642 .maxlen = sizeof(int),
644 .proc_handler = proc_dointvec,
647 .procname = "traceoff_on_warning",
648 .data = &__disable_trace_on_warning,
649 .maxlen = sizeof(__disable_trace_on_warning),
651 .proc_handler = proc_dointvec,
654 .procname = "tracepoint_printk",
655 .data = &tracepoint_printk,
656 .maxlen = sizeof(tracepoint_printk),
658 .proc_handler = tracepoint_printk_sysctl,
661 #ifdef CONFIG_KEXEC_CORE
663 .procname = "kexec_load_disabled",
664 .data = &kexec_load_disabled,
665 .maxlen = sizeof(int),
667 /* only handle a transition from default "0" to "1" */
668 .proc_handler = proc_dointvec_minmax,
673 #ifdef CONFIG_MODULES
675 .procname = "modprobe",
676 .data = &modprobe_path,
677 .maxlen = KMOD_PATH_LEN,
679 .proc_handler = proc_dostring,
682 .procname = "modules_disabled",
683 .data = &modules_disabled,
684 .maxlen = sizeof(int),
686 /* only handle a transition from default "0" to "1" */
687 .proc_handler = proc_dointvec_minmax,
692 #ifdef CONFIG_UEVENT_HELPER
694 .procname = "hotplug",
695 .data = &uevent_helper,
696 .maxlen = UEVENT_HELPER_PATH_LEN,
698 .proc_handler = proc_dostring,
701 #ifdef CONFIG_CHR_DEV_SG
703 .procname = "sg-big-buff",
704 .data = &sg_big_buff,
705 .maxlen = sizeof (int),
707 .proc_handler = proc_dointvec,
710 #ifdef CONFIG_BSD_PROCESS_ACCT
714 .maxlen = 3*sizeof(int),
716 .proc_handler = proc_dointvec,
719 #ifdef CONFIG_MAGIC_SYSRQ
722 .data = &__sysrq_enabled,
723 .maxlen = sizeof (int),
725 .proc_handler = sysrq_sysctl_handler,
728 #ifdef CONFIG_PROC_SYSCTL
730 .procname = "cad_pid",
732 .maxlen = sizeof (int),
734 .proc_handler = proc_do_cad_pid,
738 .procname = "threads-max",
740 .maxlen = sizeof(int),
742 .proc_handler = sysctl_max_threads,
745 .procname = "random",
747 .child = random_table,
750 .procname = "usermodehelper",
752 .child = usermodehelper_table,
754 #ifdef CONFIG_FW_LOADER_USER_HELPER
756 .procname = "firmware_config",
758 .child = firmware_config_table,
762 .procname = "overflowuid",
763 .data = &overflowuid,
764 .maxlen = sizeof(int),
766 .proc_handler = proc_dointvec_minmax,
767 .extra1 = &minolduid,
768 .extra2 = &maxolduid,
771 .procname = "overflowgid",
772 .data = &overflowgid,
773 .maxlen = sizeof(int),
775 .proc_handler = proc_dointvec_minmax,
776 .extra1 = &minolduid,
777 .extra2 = &maxolduid,
780 #ifdef CONFIG_MATHEMU
782 .procname = "ieee_emulation_warnings",
783 .data = &sysctl_ieee_emulation_warnings,
784 .maxlen = sizeof(int),
786 .proc_handler = proc_dointvec,
790 .procname = "userprocess_debug",
791 .data = &show_unhandled_signals,
792 .maxlen = sizeof(int),
794 .proc_handler = proc_dointvec,
798 .procname = "pid_max",
800 .maxlen = sizeof (int),
802 .proc_handler = proc_dointvec_minmax,
803 .extra1 = &pid_max_min,
804 .extra2 = &pid_max_max,
807 .procname = "panic_on_oops",
808 .data = &panic_on_oops,
809 .maxlen = sizeof(int),
811 .proc_handler = proc_dointvec,
813 #if defined CONFIG_PRINTK
815 .procname = "printk",
816 .data = &console_loglevel,
817 .maxlen = 4*sizeof(int),
819 .proc_handler = proc_dointvec,
822 .procname = "printk_ratelimit",
823 .data = &printk_ratelimit_state.interval,
824 .maxlen = sizeof(int),
826 .proc_handler = proc_dointvec_jiffies,
829 .procname = "printk_ratelimit_burst",
830 .data = &printk_ratelimit_state.burst,
831 .maxlen = sizeof(int),
833 .proc_handler = proc_dointvec,
836 .procname = "printk_delay",
837 .data = &printk_delay_msec,
838 .maxlen = sizeof(int),
840 .proc_handler = proc_dointvec_minmax,
842 .extra2 = &ten_thousand,
845 .procname = "printk_devkmsg",
846 .data = devkmsg_log_str,
847 .maxlen = DEVKMSG_STR_MAX_SIZE,
849 .proc_handler = devkmsg_sysctl_set_loglvl,
852 .procname = "dmesg_restrict",
853 .data = &dmesg_restrict,
854 .maxlen = sizeof(int),
856 .proc_handler = proc_dointvec_minmax_sysadmin,
861 .procname = "kptr_restrict",
862 .data = &kptr_restrict,
863 .maxlen = sizeof(int),
865 .proc_handler = proc_dointvec_minmax_sysadmin,
871 .procname = "ngroups_max",
872 .data = &ngroups_max,
873 .maxlen = sizeof (int),
875 .proc_handler = proc_dointvec,
878 .procname = "cap_last_cap",
879 .data = (void *)&cap_last_cap,
880 .maxlen = sizeof(int),
882 .proc_handler = proc_dointvec,
884 #if defined(CONFIG_LOCKUP_DETECTOR)
886 .procname = "watchdog",
887 .data = &watchdog_user_enabled,
888 .maxlen = sizeof(int),
890 .proc_handler = proc_watchdog,
895 .procname = "watchdog_thresh",
896 .data = &watchdog_thresh,
897 .maxlen = sizeof(int),
899 .proc_handler = proc_watchdog_thresh,
904 .procname = "nmi_watchdog",
905 .data = &nmi_watchdog_user_enabled,
906 .maxlen = sizeof(int),
907 .mode = NMI_WATCHDOG_SYSCTL_PERM,
908 .proc_handler = proc_nmi_watchdog,
913 .procname = "watchdog_cpumask",
914 .data = &watchdog_cpumask_bits,
917 .proc_handler = proc_watchdog_cpumask,
919 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
921 .procname = "soft_watchdog",
922 .data = &soft_watchdog_user_enabled,
923 .maxlen = sizeof(int),
925 .proc_handler = proc_soft_watchdog,
930 .procname = "softlockup_panic",
931 .data = &softlockup_panic,
932 .maxlen = sizeof(int),
934 .proc_handler = proc_dointvec_minmax,
940 .procname = "softlockup_all_cpu_backtrace",
941 .data = &sysctl_softlockup_all_cpu_backtrace,
942 .maxlen = sizeof(int),
944 .proc_handler = proc_dointvec_minmax,
948 #endif /* CONFIG_SMP */
950 #ifdef CONFIG_HARDLOCKUP_DETECTOR
952 .procname = "hardlockup_panic",
953 .data = &hardlockup_panic,
954 .maxlen = sizeof(int),
956 .proc_handler = proc_dointvec_minmax,
962 .procname = "hardlockup_all_cpu_backtrace",
963 .data = &sysctl_hardlockup_all_cpu_backtrace,
964 .maxlen = sizeof(int),
966 .proc_handler = proc_dointvec_minmax,
970 #endif /* CONFIG_SMP */
974 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
976 .procname = "unknown_nmi_panic",
977 .data = &unknown_nmi_panic,
978 .maxlen = sizeof (int),
980 .proc_handler = proc_dointvec,
983 #if defined(CONFIG_X86)
985 .procname = "panic_on_unrecovered_nmi",
986 .data = &panic_on_unrecovered_nmi,
987 .maxlen = sizeof(int),
989 .proc_handler = proc_dointvec,
992 .procname = "panic_on_io_nmi",
993 .data = &panic_on_io_nmi,
994 .maxlen = sizeof(int),
996 .proc_handler = proc_dointvec,
998 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1000 .procname = "panic_on_stackoverflow",
1001 .data = &sysctl_panic_on_stackoverflow,
1002 .maxlen = sizeof(int),
1004 .proc_handler = proc_dointvec,
1008 .procname = "bootloader_type",
1009 .data = &bootloader_type,
1010 .maxlen = sizeof (int),
1012 .proc_handler = proc_dointvec,
1015 .procname = "bootloader_version",
1016 .data = &bootloader_version,
1017 .maxlen = sizeof (int),
1019 .proc_handler = proc_dointvec,
1022 .procname = "io_delay_type",
1023 .data = &io_delay_type,
1024 .maxlen = sizeof(int),
1026 .proc_handler = proc_dointvec,
1029 #if defined(CONFIG_MMU)
1031 .procname = "randomize_va_space",
1032 .data = &randomize_va_space,
1033 .maxlen = sizeof(int),
1035 .proc_handler = proc_dointvec,
1038 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1040 .procname = "spin_retry",
1041 .data = &spin_retry,
1042 .maxlen = sizeof (int),
1044 .proc_handler = proc_dointvec,
1047 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1049 .procname = "acpi_video_flags",
1050 .data = &acpi_realmode_flags,
1051 .maxlen = sizeof (unsigned long),
1053 .proc_handler = proc_doulongvec_minmax,
1056 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1058 .procname = "ignore-unaligned-usertrap",
1059 .data = &no_unaligned_warning,
1060 .maxlen = sizeof (int),
1062 .proc_handler = proc_dointvec,
1067 .procname = "unaligned-dump-stack",
1068 .data = &unaligned_dump_stack,
1069 .maxlen = sizeof (int),
1071 .proc_handler = proc_dointvec,
1074 #ifdef CONFIG_DETECT_HUNG_TASK
1076 .procname = "hung_task_panic",
1077 .data = &sysctl_hung_task_panic,
1078 .maxlen = sizeof(int),
1080 .proc_handler = proc_dointvec_minmax,
1085 .procname = "hung_task_check_count",
1086 .data = &sysctl_hung_task_check_count,
1087 .maxlen = sizeof(int),
1089 .proc_handler = proc_dointvec_minmax,
1093 .procname = "hung_task_timeout_secs",
1094 .data = &sysctl_hung_task_timeout_secs,
1095 .maxlen = sizeof(unsigned long),
1097 .proc_handler = proc_dohung_task_timeout_secs,
1098 .extra2 = &hung_task_timeout_max,
1101 .procname = "hung_task_check_interval_secs",
1102 .data = &sysctl_hung_task_check_interval_secs,
1103 .maxlen = sizeof(unsigned long),
1105 .proc_handler = proc_dohung_task_timeout_secs,
1106 .extra2 = &hung_task_timeout_max,
1109 .procname = "hung_task_warnings",
1110 .data = &sysctl_hung_task_warnings,
1111 .maxlen = sizeof(int),
1113 .proc_handler = proc_dointvec_minmax,
1117 #ifdef CONFIG_RT_MUTEXES
1119 .procname = "max_lock_depth",
1120 .data = &max_lock_depth,
1121 .maxlen = sizeof(int),
1123 .proc_handler = proc_dointvec,
1127 .procname = "poweroff_cmd",
1128 .data = &poweroff_cmd,
1129 .maxlen = POWEROFF_CMD_PATH_LEN,
1131 .proc_handler = proc_dostring,
1137 .child = key_sysctls,
1140 #ifdef CONFIG_PERF_EVENTS
1142 * User-space scripts rely on the existence of this file
1143 * as a feature check for perf_events being enabled.
1145 * So it's an ABI, do not remove!
1148 .procname = "perf_event_paranoid",
1149 .data = &sysctl_perf_event_paranoid,
1150 .maxlen = sizeof(sysctl_perf_event_paranoid),
1152 .proc_handler = proc_dointvec,
1155 .procname = "perf_event_mlock_kb",
1156 .data = &sysctl_perf_event_mlock,
1157 .maxlen = sizeof(sysctl_perf_event_mlock),
1159 .proc_handler = proc_dointvec,
1162 .procname = "perf_event_max_sample_rate",
1163 .data = &sysctl_perf_event_sample_rate,
1164 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1166 .proc_handler = perf_proc_update_handler,
1170 .procname = "perf_cpu_time_max_percent",
1171 .data = &sysctl_perf_cpu_time_max_percent,
1172 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1174 .proc_handler = perf_cpu_time_max_percent_handler,
1176 .extra2 = &one_hundred,
1179 .procname = "perf_event_max_stack",
1180 .data = &sysctl_perf_event_max_stack,
1181 .maxlen = sizeof(sysctl_perf_event_max_stack),
1183 .proc_handler = perf_event_max_stack_handler,
1185 .extra2 = &six_hundred_forty_kb,
1188 .procname = "perf_event_max_contexts_per_stack",
1189 .data = &sysctl_perf_event_max_contexts_per_stack,
1190 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1192 .proc_handler = perf_event_max_stack_handler,
1194 .extra2 = &one_thousand,
1198 .procname = "panic_on_warn",
1199 .data = &panic_on_warn,
1200 .maxlen = sizeof(int),
1202 .proc_handler = proc_dointvec_minmax,
1206 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1208 .procname = "timer_migration",
1209 .data = &sysctl_timer_migration,
1210 .maxlen = sizeof(unsigned int),
1212 .proc_handler = timer_migration_handler,
1217 #ifdef CONFIG_BPF_SYSCALL
1219 .procname = "unprivileged_bpf_disabled",
1220 .data = &sysctl_unprivileged_bpf_disabled,
1221 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1223 /* only handle a transition from default "0" to "1" */
1224 .proc_handler = proc_dointvec_minmax,
1229 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1231 .procname = "panic_on_rcu_stall",
1232 .data = &sysctl_panic_on_rcu_stall,
1233 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1235 .proc_handler = proc_dointvec_minmax,
1243 static struct ctl_table vm_table[] = {
1245 .procname = "overcommit_memory",
1246 .data = &sysctl_overcommit_memory,
1247 .maxlen = sizeof(sysctl_overcommit_memory),
1249 .proc_handler = proc_dointvec_minmax,
1254 .procname = "panic_on_oom",
1255 .data = &sysctl_panic_on_oom,
1256 .maxlen = sizeof(sysctl_panic_on_oom),
1258 .proc_handler = proc_dointvec_minmax,
1263 .procname = "oom_kill_allocating_task",
1264 .data = &sysctl_oom_kill_allocating_task,
1265 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1267 .proc_handler = proc_dointvec,
1270 .procname = "oom_dump_tasks",
1271 .data = &sysctl_oom_dump_tasks,
1272 .maxlen = sizeof(sysctl_oom_dump_tasks),
1274 .proc_handler = proc_dointvec,
1277 .procname = "overcommit_ratio",
1278 .data = &sysctl_overcommit_ratio,
1279 .maxlen = sizeof(sysctl_overcommit_ratio),
1281 .proc_handler = overcommit_ratio_handler,
1284 .procname = "overcommit_kbytes",
1285 .data = &sysctl_overcommit_kbytes,
1286 .maxlen = sizeof(sysctl_overcommit_kbytes),
1288 .proc_handler = overcommit_kbytes_handler,
1291 .procname = "page-cluster",
1292 .data = &page_cluster,
1293 .maxlen = sizeof(int),
1295 .proc_handler = proc_dointvec_minmax,
1299 .procname = "dirty_background_ratio",
1300 .data = &dirty_background_ratio,
1301 .maxlen = sizeof(dirty_background_ratio),
1303 .proc_handler = dirty_background_ratio_handler,
1305 .extra2 = &one_hundred,
1308 .procname = "dirty_background_bytes",
1309 .data = &dirty_background_bytes,
1310 .maxlen = sizeof(dirty_background_bytes),
1312 .proc_handler = dirty_background_bytes_handler,
1316 .procname = "dirty_ratio",
1317 .data = &vm_dirty_ratio,
1318 .maxlen = sizeof(vm_dirty_ratio),
1320 .proc_handler = dirty_ratio_handler,
1322 .extra2 = &one_hundred,
1325 .procname = "dirty_bytes",
1326 .data = &vm_dirty_bytes,
1327 .maxlen = sizeof(vm_dirty_bytes),
1329 .proc_handler = dirty_bytes_handler,
1330 .extra1 = &dirty_bytes_min,
1333 .procname = "dirty_writeback_centisecs",
1334 .data = &dirty_writeback_interval,
1335 .maxlen = sizeof(dirty_writeback_interval),
1337 .proc_handler = dirty_writeback_centisecs_handler,
1340 .procname = "dirty_expire_centisecs",
1341 .data = &dirty_expire_interval,
1342 .maxlen = sizeof(dirty_expire_interval),
1344 .proc_handler = proc_dointvec_minmax,
1348 .procname = "dirtytime_expire_seconds",
1349 .data = &dirtytime_expire_interval,
1350 .maxlen = sizeof(dirtytime_expire_interval),
1352 .proc_handler = dirtytime_interval_handler,
1356 .procname = "swappiness",
1357 .data = &vm_swappiness,
1358 .maxlen = sizeof(vm_swappiness),
1360 .proc_handler = proc_dointvec_minmax,
1362 .extra2 = &one_hundred,
1364 #ifdef CONFIG_HUGETLB_PAGE
1366 .procname = "nr_hugepages",
1368 .maxlen = sizeof(unsigned long),
1370 .proc_handler = hugetlb_sysctl_handler,
1374 .procname = "nr_hugepages_mempolicy",
1376 .maxlen = sizeof(unsigned long),
1378 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1381 .procname = "numa_stat",
1382 .data = &sysctl_vm_numa_stat,
1383 .maxlen = sizeof(int),
1385 .proc_handler = sysctl_vm_numa_stat_handler,
1391 .procname = "hugetlb_shm_group",
1392 .data = &sysctl_hugetlb_shm_group,
1393 .maxlen = sizeof(gid_t),
1395 .proc_handler = proc_dointvec,
1398 .procname = "nr_overcommit_hugepages",
1400 .maxlen = sizeof(unsigned long),
1402 .proc_handler = hugetlb_overcommit_handler,
1406 .procname = "lowmem_reserve_ratio",
1407 .data = &sysctl_lowmem_reserve_ratio,
1408 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1410 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1413 .procname = "drop_caches",
1414 .data = &sysctl_drop_caches,
1415 .maxlen = sizeof(int),
1417 .proc_handler = drop_caches_sysctl_handler,
1421 #ifdef CONFIG_COMPACTION
1423 .procname = "compact_memory",
1424 .data = &sysctl_compact_memory,
1425 .maxlen = sizeof(int),
1427 .proc_handler = sysctl_compaction_handler,
1430 .procname = "extfrag_threshold",
1431 .data = &sysctl_extfrag_threshold,
1432 .maxlen = sizeof(int),
1434 .proc_handler = sysctl_extfrag_handler,
1435 .extra1 = &min_extfrag_threshold,
1436 .extra2 = &max_extfrag_threshold,
1439 .procname = "compact_unevictable_allowed",
1440 .data = &sysctl_compact_unevictable_allowed,
1441 .maxlen = sizeof(int),
1443 .proc_handler = proc_dointvec,
1448 #endif /* CONFIG_COMPACTION */
1450 .procname = "min_free_kbytes",
1451 .data = &min_free_kbytes,
1452 .maxlen = sizeof(min_free_kbytes),
1454 .proc_handler = min_free_kbytes_sysctl_handler,
1458 .procname = "watermark_scale_factor",
1459 .data = &watermark_scale_factor,
1460 .maxlen = sizeof(watermark_scale_factor),
1462 .proc_handler = watermark_scale_factor_sysctl_handler,
1464 .extra2 = &one_thousand,
1467 .procname = "percpu_pagelist_fraction",
1468 .data = &percpu_pagelist_fraction,
1469 .maxlen = sizeof(percpu_pagelist_fraction),
1471 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1476 .procname = "max_map_count",
1477 .data = &sysctl_max_map_count,
1478 .maxlen = sizeof(sysctl_max_map_count),
1480 .proc_handler = proc_dointvec_minmax,
1485 .procname = "nr_trim_pages",
1486 .data = &sysctl_nr_trim_pages,
1487 .maxlen = sizeof(sysctl_nr_trim_pages),
1489 .proc_handler = proc_dointvec_minmax,
1494 .procname = "laptop_mode",
1495 .data = &laptop_mode,
1496 .maxlen = sizeof(laptop_mode),
1498 .proc_handler = proc_dointvec_jiffies,
1501 .procname = "block_dump",
1502 .data = &block_dump,
1503 .maxlen = sizeof(block_dump),
1505 .proc_handler = proc_dointvec,
1509 .procname = "vfs_cache_pressure",
1510 .data = &sysctl_vfs_cache_pressure,
1511 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1513 .proc_handler = proc_dointvec,
1516 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1518 .procname = "legacy_va_layout",
1519 .data = &sysctl_legacy_va_layout,
1520 .maxlen = sizeof(sysctl_legacy_va_layout),
1522 .proc_handler = proc_dointvec,
1528 .procname = "zone_reclaim_mode",
1529 .data = &node_reclaim_mode,
1530 .maxlen = sizeof(node_reclaim_mode),
1532 .proc_handler = proc_dointvec,
1536 .procname = "min_unmapped_ratio",
1537 .data = &sysctl_min_unmapped_ratio,
1538 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1540 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1542 .extra2 = &one_hundred,
1545 .procname = "min_slab_ratio",
1546 .data = &sysctl_min_slab_ratio,
1547 .maxlen = sizeof(sysctl_min_slab_ratio),
1549 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1551 .extra2 = &one_hundred,
1556 .procname = "stat_interval",
1557 .data = &sysctl_stat_interval,
1558 .maxlen = sizeof(sysctl_stat_interval),
1560 .proc_handler = proc_dointvec_jiffies,
1563 .procname = "stat_refresh",
1567 .proc_handler = vmstat_refresh,
1572 .procname = "mmap_min_addr",
1573 .data = &dac_mmap_min_addr,
1574 .maxlen = sizeof(unsigned long),
1576 .proc_handler = mmap_min_addr_handler,
1581 .procname = "numa_zonelist_order",
1582 .data = &numa_zonelist_order,
1583 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1585 .proc_handler = numa_zonelist_order_handler,
1588 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1589 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1591 .procname = "vdso_enabled",
1592 #ifdef CONFIG_X86_32
1593 .data = &vdso32_enabled,
1594 .maxlen = sizeof(vdso32_enabled),
1596 .data = &vdso_enabled,
1597 .maxlen = sizeof(vdso_enabled),
1600 .proc_handler = proc_dointvec,
1604 #ifdef CONFIG_HIGHMEM
1606 .procname = "highmem_is_dirtyable",
1607 .data = &vm_highmem_is_dirtyable,
1608 .maxlen = sizeof(vm_highmem_is_dirtyable),
1610 .proc_handler = proc_dointvec_minmax,
1615 #ifdef CONFIG_MEMORY_FAILURE
1617 .procname = "memory_failure_early_kill",
1618 .data = &sysctl_memory_failure_early_kill,
1619 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1621 .proc_handler = proc_dointvec_minmax,
1626 .procname = "memory_failure_recovery",
1627 .data = &sysctl_memory_failure_recovery,
1628 .maxlen = sizeof(sysctl_memory_failure_recovery),
1630 .proc_handler = proc_dointvec_minmax,
1636 .procname = "user_reserve_kbytes",
1637 .data = &sysctl_user_reserve_kbytes,
1638 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1640 .proc_handler = proc_doulongvec_minmax,
1643 .procname = "admin_reserve_kbytes",
1644 .data = &sysctl_admin_reserve_kbytes,
1645 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1647 .proc_handler = proc_doulongvec_minmax,
1649 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1651 .procname = "mmap_rnd_bits",
1652 .data = &mmap_rnd_bits,
1653 .maxlen = sizeof(mmap_rnd_bits),
1655 .proc_handler = proc_dointvec_minmax,
1656 .extra1 = (void *)&mmap_rnd_bits_min,
1657 .extra2 = (void *)&mmap_rnd_bits_max,
1660 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1662 .procname = "mmap_rnd_compat_bits",
1663 .data = &mmap_rnd_compat_bits,
1664 .maxlen = sizeof(mmap_rnd_compat_bits),
1666 .proc_handler = proc_dointvec_minmax,
1667 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1668 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1674 static struct ctl_table fs_table[] = {
1676 .procname = "inode-nr",
1677 .data = &inodes_stat,
1678 .maxlen = 2*sizeof(long),
1680 .proc_handler = proc_nr_inodes,
1683 .procname = "inode-state",
1684 .data = &inodes_stat,
1685 .maxlen = 7*sizeof(long),
1687 .proc_handler = proc_nr_inodes,
1690 .procname = "file-nr",
1691 .data = &files_stat,
1692 .maxlen = sizeof(files_stat),
1694 .proc_handler = proc_nr_files,
1697 .procname = "file-max",
1698 .data = &files_stat.max_files,
1699 .maxlen = sizeof(files_stat.max_files),
1701 .proc_handler = proc_doulongvec_minmax,
1703 .extra2 = &long_max,
1706 .procname = "nr_open",
1707 .data = &sysctl_nr_open,
1708 .maxlen = sizeof(unsigned int),
1710 .proc_handler = proc_dointvec_minmax,
1711 .extra1 = &sysctl_nr_open_min,
1712 .extra2 = &sysctl_nr_open_max,
1715 .procname = "dentry-state",
1716 .data = &dentry_stat,
1717 .maxlen = 6*sizeof(long),
1719 .proc_handler = proc_nr_dentry,
1722 .procname = "overflowuid",
1723 .data = &fs_overflowuid,
1724 .maxlen = sizeof(int),
1726 .proc_handler = proc_dointvec_minmax,
1727 .extra1 = &minolduid,
1728 .extra2 = &maxolduid,
1731 .procname = "overflowgid",
1732 .data = &fs_overflowgid,
1733 .maxlen = sizeof(int),
1735 .proc_handler = proc_dointvec_minmax,
1736 .extra1 = &minolduid,
1737 .extra2 = &maxolduid,
1739 #ifdef CONFIG_FILE_LOCKING
1741 .procname = "leases-enable",
1742 .data = &leases_enable,
1743 .maxlen = sizeof(int),
1745 .proc_handler = proc_dointvec,
1748 #ifdef CONFIG_DNOTIFY
1750 .procname = "dir-notify-enable",
1751 .data = &dir_notify_enable,
1752 .maxlen = sizeof(int),
1754 .proc_handler = proc_dointvec,
1758 #ifdef CONFIG_FILE_LOCKING
1760 .procname = "lease-break-time",
1761 .data = &lease_break_time,
1762 .maxlen = sizeof(int),
1764 .proc_handler = proc_dointvec,
1769 .procname = "aio-nr",
1771 .maxlen = sizeof(aio_nr),
1773 .proc_handler = proc_doulongvec_minmax,
1776 .procname = "aio-max-nr",
1777 .data = &aio_max_nr,
1778 .maxlen = sizeof(aio_max_nr),
1780 .proc_handler = proc_doulongvec_minmax,
1782 #endif /* CONFIG_AIO */
1783 #ifdef CONFIG_INOTIFY_USER
1785 .procname = "inotify",
1787 .child = inotify_table,
1792 .procname = "epoll",
1794 .child = epoll_table,
1799 .procname = "protected_symlinks",
1800 .data = &sysctl_protected_symlinks,
1801 .maxlen = sizeof(int),
1803 .proc_handler = proc_dointvec_minmax,
1808 .procname = "protected_hardlinks",
1809 .data = &sysctl_protected_hardlinks,
1810 .maxlen = sizeof(int),
1812 .proc_handler = proc_dointvec_minmax,
1817 .procname = "protected_fifos",
1818 .data = &sysctl_protected_fifos,
1819 .maxlen = sizeof(int),
1821 .proc_handler = proc_dointvec_minmax,
1826 .procname = "protected_regular",
1827 .data = &sysctl_protected_regular,
1828 .maxlen = sizeof(int),
1830 .proc_handler = proc_dointvec_minmax,
1835 .procname = "suid_dumpable",
1836 .data = &suid_dumpable,
1837 .maxlen = sizeof(int),
1839 .proc_handler = proc_dointvec_minmax_coredump,
1843 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1845 .procname = "binfmt_misc",
1847 .child = sysctl_mount_point,
1851 .procname = "pipe-max-size",
1852 .data = &pipe_max_size,
1853 .maxlen = sizeof(pipe_max_size),
1855 .proc_handler = proc_dopipe_max_size,
1858 .procname = "pipe-user-pages-hard",
1859 .data = &pipe_user_pages_hard,
1860 .maxlen = sizeof(pipe_user_pages_hard),
1862 .proc_handler = proc_doulongvec_minmax,
1865 .procname = "pipe-user-pages-soft",
1866 .data = &pipe_user_pages_soft,
1867 .maxlen = sizeof(pipe_user_pages_soft),
1869 .proc_handler = proc_doulongvec_minmax,
1872 .procname = "mount-max",
1873 .data = &sysctl_mount_max,
1874 .maxlen = sizeof(unsigned int),
1876 .proc_handler = proc_dointvec_minmax,
1882 static struct ctl_table debug_table[] = {
1883 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1885 .procname = "exception-trace",
1886 .data = &show_unhandled_signals,
1887 .maxlen = sizeof(int),
1889 .proc_handler = proc_dointvec
1892 #if defined(CONFIG_OPTPROBES)
1894 .procname = "kprobes-optimization",
1895 .data = &sysctl_kprobes_optimization,
1896 .maxlen = sizeof(int),
1898 .proc_handler = proc_kprobes_optimization_handler,
1906 static struct ctl_table dev_table[] = {
1910 int __init sysctl_init(void)
1912 struct ctl_table_header *hdr;
1914 hdr = register_sysctl_table(sysctl_base_table);
1915 kmemleak_not_leak(hdr);
1919 #endif /* CONFIG_SYSCTL */
1925 #ifdef CONFIG_PROC_SYSCTL
1927 static int _proc_do_string(char *data, int maxlen, int write,
1928 char __user *buffer,
1929 size_t *lenp, loff_t *ppos)
1935 if (!data || !maxlen || !*lenp) {
1941 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1942 /* Only continue writes not past the end of buffer. */
1944 if (len > maxlen - 1)
1951 /* Start writing from beginning of buffer. */
1957 while ((p - buffer) < *lenp && len < maxlen - 1) {
1958 if (get_user(c, p++))
1960 if (c == 0 || c == '\n')
1981 if (copy_to_user(buffer, data, len))
1984 if (put_user('\n', buffer + len))
1994 static void warn_sysctl_write(struct ctl_table *table)
1996 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1997 "This will not be supported in the future. To silence this\n"
1998 "warning, set kernel.sysctl_writes_strict = -1\n",
1999 current->comm, table->procname);
2003 * proc_first_pos_non_zero_ignore - check if first position is allowed
2004 * @ppos: file position
2005 * @table: the sysctl table
2007 * Returns true if the first position is non-zero and the sysctl_writes_strict
2008 * mode indicates this is not allowed for numeric input types. String proc
2009 * handlers can ignore the return value.
2011 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2012 struct ctl_table *table)
2017 switch (sysctl_writes_strict) {
2018 case SYSCTL_WRITES_STRICT:
2020 case SYSCTL_WRITES_WARN:
2021 warn_sysctl_write(table);
2029 * proc_dostring - read a string sysctl
2030 * @table: the sysctl table
2031 * @write: %TRUE if this is a write to the sysctl file
2032 * @buffer: the user buffer
2033 * @lenp: the size of the user buffer
2034 * @ppos: file position
2036 * Reads/writes a string from/to the user buffer. If the kernel
2037 * buffer provided is not large enough to hold the string, the
2038 * string is truncated. The copied string is %NULL-terminated.
2039 * If the string is being read by the user process, it is copied
2040 * and a newline '\n' is added. It is truncated if the buffer is
2043 * Returns 0 on success.
2045 int proc_dostring(struct ctl_table *table, int write,
2046 void __user *buffer, size_t *lenp, loff_t *ppos)
2049 proc_first_pos_non_zero_ignore(ppos, table);
2051 return _proc_do_string((char *)(table->data), table->maxlen, write,
2052 (char __user *)buffer, lenp, ppos);
2055 static size_t proc_skip_spaces(char **buf)
2058 char *tmp = skip_spaces(*buf);
2064 static void proc_skip_char(char **buf, size_t *size, const char v)
2075 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2078 * @cp: kernel buffer containing the string to parse
2079 * @endp: pointer to store the trailing characters
2080 * @base: the base to use
2081 * @res: where the parsed integer will be stored
2083 * In case of success 0 is returned and @res will contain the parsed integer,
2084 * @endp will hold any trailing characters.
2085 * This function will fail the parse on overflow. If there wasn't an overflow
2086 * the function will defer the decision what characters count as invalid to the
2089 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2092 unsigned long long result;
2095 cp = _parse_integer_fixup_radix(cp, &base);
2096 rv = _parse_integer(cp, base, &result);
2097 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2105 *res = (unsigned long)result;
2109 #define TMPBUFLEN 22
2111 * proc_get_long - reads an ASCII formatted integer from a user buffer
2113 * @buf: a kernel buffer
2114 * @size: size of the kernel buffer
2115 * @val: this is where the number will be stored
2116 * @neg: set to %TRUE if number is negative
2117 * @perm_tr: a vector which contains the allowed trailers
2118 * @perm_tr_len: size of the perm_tr vector
2119 * @tr: pointer to store the trailer character
2121 * In case of success %0 is returned and @buf and @size are updated with
2122 * the amount of bytes read. If @tr is non-NULL and a trailing
2123 * character exists (size is non-zero after returning from this
2124 * function), @tr is updated with the trailing character.
2126 static int proc_get_long(char **buf, size_t *size,
2127 unsigned long *val, bool *neg,
2128 const char *perm_tr, unsigned perm_tr_len, char *tr)
2131 char *p, tmp[TMPBUFLEN];
2137 if (len > TMPBUFLEN - 1)
2138 len = TMPBUFLEN - 1;
2140 memcpy(tmp, *buf, len);
2144 if (*p == '-' && *size > 1) {
2152 if (strtoul_lenient(p, &p, 0, val))
2157 /* We don't know if the next char is whitespace thus we may accept
2158 * invalid integers (e.g. 1234...a) or two integers instead of one
2159 * (e.g. 123...1). So lets not allow such large numbers. */
2160 if (len == TMPBUFLEN - 1)
2163 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2166 if (tr && (len < *size))
2176 * proc_put_long - converts an integer to a decimal ASCII formatted string
2178 * @buf: the user buffer
2179 * @size: the size of the user buffer
2180 * @val: the integer to be converted
2181 * @neg: sign of the number, %TRUE for negative
2183 * In case of success %0 is returned and @buf and @size are updated with
2184 * the amount of bytes written.
2186 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2190 char tmp[TMPBUFLEN], *p = tmp;
2192 sprintf(p, "%s%lu", neg ? "-" : "", val);
2196 if (copy_to_user(*buf, tmp, len))
2204 static int proc_put_char(void __user **buf, size_t *size, char c)
2207 char __user **buffer = (char __user **)buf;
2208 if (put_user(c, *buffer))
2210 (*size)--, (*buffer)++;
2216 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2218 int write, void *data)
2222 if (*lvalp > (unsigned long) INT_MAX + 1)
2226 if (*lvalp > (unsigned long) INT_MAX)
2234 *lvalp = -(unsigned long)val;
2237 *lvalp = (unsigned long)val;
2243 static int do_proc_douintvec_conv(unsigned long *lvalp,
2245 int write, void *data)
2248 if (*lvalp > UINT_MAX)
2252 unsigned int val = *valp;
2253 *lvalp = (unsigned long)val;
2258 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2260 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2261 int write, void __user *buffer,
2262 size_t *lenp, loff_t *ppos,
2263 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2264 int write, void *data),
2267 int *i, vleft, first = 1, err = 0;
2269 char *kbuf = NULL, *p;
2271 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2276 i = (int *) tbl_data;
2277 vleft = table->maxlen / sizeof(*i);
2281 conv = do_proc_dointvec_conv;
2284 if (proc_first_pos_non_zero_ignore(ppos, table))
2287 if (left > PAGE_SIZE - 1)
2288 left = PAGE_SIZE - 1;
2289 p = kbuf = memdup_user_nul(buffer, left);
2291 return PTR_ERR(kbuf);
2294 for (; left && vleft--; i++, first=0) {
2299 left -= proc_skip_spaces(&p);
2303 err = proc_get_long(&p, &left, &lval, &neg,
2305 sizeof(proc_wspace_sep), NULL);
2308 if (conv(&neg, &lval, i, 1, data)) {
2313 if (conv(&neg, &lval, i, 0, data)) {
2318 err = proc_put_char(&buffer, &left, '\t');
2321 err = proc_put_long(&buffer, &left, lval, neg);
2327 if (!write && !first && left && !err)
2328 err = proc_put_char(&buffer, &left, '\n');
2329 if (write && !err && left)
2330 left -= proc_skip_spaces(&p);
2334 return err ? : -EINVAL;
2342 static int do_proc_dointvec(struct ctl_table *table, int write,
2343 void __user *buffer, size_t *lenp, loff_t *ppos,
2344 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2345 int write, void *data),
2348 return __do_proc_dointvec(table->data, table, write,
2349 buffer, lenp, ppos, conv, data);
2352 static int do_proc_douintvec_w(unsigned int *tbl_data,
2353 struct ctl_table *table,
2354 void __user *buffer,
2355 size_t *lenp, loff_t *ppos,
2356 int (*conv)(unsigned long *lvalp,
2358 int write, void *data),
2365 char *kbuf = NULL, *p;
2369 if (proc_first_pos_non_zero_ignore(ppos, table))
2372 if (left > PAGE_SIZE - 1)
2373 left = PAGE_SIZE - 1;
2375 p = kbuf = memdup_user_nul(buffer, left);
2379 left -= proc_skip_spaces(&p);
2385 err = proc_get_long(&p, &left, &lval, &neg,
2387 sizeof(proc_wspace_sep), NULL);
2393 if (conv(&lval, tbl_data, 1, data)) {
2399 left -= proc_skip_spaces(&p);
2408 /* This is in keeping with old __do_proc_dointvec() */
2414 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2415 size_t *lenp, loff_t *ppos,
2416 int (*conv)(unsigned long *lvalp,
2418 int write, void *data),
2427 if (conv(&lval, tbl_data, 0, data)) {
2432 err = proc_put_long(&buffer, &left, lval, false);
2436 err = proc_put_char(&buffer, &left, '\n');
2445 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2446 int write, void __user *buffer,
2447 size_t *lenp, loff_t *ppos,
2448 int (*conv)(unsigned long *lvalp,
2450 int write, void *data),
2453 unsigned int *i, vleft;
2455 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2460 i = (unsigned int *) tbl_data;
2461 vleft = table->maxlen / sizeof(*i);
2464 * Arrays are not supported, keep this simple. *Do not* add
2473 conv = do_proc_douintvec_conv;
2476 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2478 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2481 static int do_proc_douintvec(struct ctl_table *table, int write,
2482 void __user *buffer, size_t *lenp, loff_t *ppos,
2483 int (*conv)(unsigned long *lvalp,
2485 int write, void *data),
2488 return __do_proc_douintvec(table->data, table, write,
2489 buffer, lenp, ppos, conv, data);
2493 * proc_dointvec - read a vector of integers
2494 * @table: the sysctl table
2495 * @write: %TRUE if this is a write to the sysctl file
2496 * @buffer: the user buffer
2497 * @lenp: the size of the user buffer
2498 * @ppos: file position
2500 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2501 * values from/to the user buffer, treated as an ASCII string.
2503 * Returns 0 on success.
2505 int proc_dointvec(struct ctl_table *table, int write,
2506 void __user *buffer, size_t *lenp, loff_t *ppos)
2508 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2512 * proc_douintvec - read a vector of unsigned integers
2513 * @table: the sysctl table
2514 * @write: %TRUE if this is a write to the sysctl file
2515 * @buffer: the user buffer
2516 * @lenp: the size of the user buffer
2517 * @ppos: file position
2519 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2520 * values from/to the user buffer, treated as an ASCII string.
2522 * Returns 0 on success.
2524 int proc_douintvec(struct ctl_table *table, int write,
2525 void __user *buffer, size_t *lenp, loff_t *ppos)
2527 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2528 do_proc_douintvec_conv, NULL);
2532 * Taint values can only be increased
2533 * This means we can safely use a temporary.
2535 static int proc_taint(struct ctl_table *table, int write,
2536 void __user *buffer, size_t *lenp, loff_t *ppos)
2539 unsigned long tmptaint = get_taint();
2542 if (write && !capable(CAP_SYS_ADMIN))
2547 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2553 * Poor man's atomic or. Not worth adding a primitive
2554 * to everyone's atomic.h for this
2557 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2558 if ((tmptaint >> i) & 1)
2559 add_taint(i, LOCKDEP_STILL_OK);
2566 #ifdef CONFIG_PRINTK
2567 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2568 void __user *buffer, size_t *lenp, loff_t *ppos)
2570 if (write && !capable(CAP_SYS_ADMIN))
2573 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2578 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2579 * @min: pointer to minimum allowable value
2580 * @max: pointer to maximum allowable value
2582 * The do_proc_dointvec_minmax_conv_param structure provides the
2583 * minimum and maximum values for doing range checking for those sysctl
2584 * parameters that use the proc_dointvec_minmax() handler.
2586 struct do_proc_dointvec_minmax_conv_param {
2591 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2593 int write, void *data)
2595 struct do_proc_dointvec_minmax_conv_param *param = data;
2599 if (*lvalp > (unsigned long) INT_MAX + 1)
2603 if (*lvalp > (unsigned long) INT_MAX)
2607 if ((param->min && *param->min > val) ||
2608 (param->max && *param->max < val))
2615 *lvalp = -(unsigned long)val;
2618 *lvalp = (unsigned long)val;
2625 * proc_dointvec_minmax - read a vector of integers with min/max values
2626 * @table: the sysctl table
2627 * @write: %TRUE if this is a write to the sysctl file
2628 * @buffer: the user buffer
2629 * @lenp: the size of the user buffer
2630 * @ppos: file position
2632 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2633 * values from/to the user buffer, treated as an ASCII string.
2635 * This routine will ensure the values are within the range specified by
2636 * table->extra1 (min) and table->extra2 (max).
2638 * Returns 0 on success or -EINVAL on write when the range check fails.
2640 int proc_dointvec_minmax(struct ctl_table *table, int write,
2641 void __user *buffer, size_t *lenp, loff_t *ppos)
2643 struct do_proc_dointvec_minmax_conv_param param = {
2644 .min = (int *) table->extra1,
2645 .max = (int *) table->extra2,
2647 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2648 do_proc_dointvec_minmax_conv, ¶m);
2652 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2653 * @min: pointer to minimum allowable value
2654 * @max: pointer to maximum allowable value
2656 * The do_proc_douintvec_minmax_conv_param structure provides the
2657 * minimum and maximum values for doing range checking for those sysctl
2658 * parameters that use the proc_douintvec_minmax() handler.
2660 struct do_proc_douintvec_minmax_conv_param {
2665 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2667 int write, void *data)
2669 struct do_proc_douintvec_minmax_conv_param *param = data;
2672 unsigned int val = *lvalp;
2674 if (*lvalp > UINT_MAX)
2677 if ((param->min && *param->min > val) ||
2678 (param->max && *param->max < val))
2683 unsigned int val = *valp;
2684 *lvalp = (unsigned long) val;
2691 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2692 * @table: the sysctl table
2693 * @write: %TRUE if this is a write to the sysctl file
2694 * @buffer: the user buffer
2695 * @lenp: the size of the user buffer
2696 * @ppos: file position
2698 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2699 * values from/to the user buffer, treated as an ASCII string. Negative
2700 * strings are not allowed.
2702 * This routine will ensure the values are within the range specified by
2703 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2704 * check for UINT_MAX to avoid having to support wrap around uses from
2707 * Returns 0 on success or -ERANGE on write when the range check fails.
2709 int proc_douintvec_minmax(struct ctl_table *table, int write,
2710 void __user *buffer, size_t *lenp, loff_t *ppos)
2712 struct do_proc_douintvec_minmax_conv_param param = {
2713 .min = (unsigned int *) table->extra1,
2714 .max = (unsigned int *) table->extra2,
2716 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2717 do_proc_douintvec_minmax_conv, ¶m);
2720 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2722 int write, void *data)
2727 val = round_pipe_size(*lvalp);
2733 unsigned int val = *valp;
2734 *lvalp = (unsigned long) val;
2740 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2741 void __user *buffer, size_t *lenp, loff_t *ppos)
2743 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2744 do_proc_dopipe_max_size_conv, NULL);
2747 static void validate_coredump_safety(void)
2749 #ifdef CONFIG_COREDUMP
2750 if (suid_dumpable == SUID_DUMP_ROOT &&
2751 core_pattern[0] != '/' && core_pattern[0] != '|') {
2753 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2754 "Pipe handler or fully qualified core dump path required.\n"
2755 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2761 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2762 void __user *buffer, size_t *lenp, loff_t *ppos)
2764 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2766 validate_coredump_safety();
2770 #ifdef CONFIG_COREDUMP
2771 static int proc_dostring_coredump(struct ctl_table *table, int write,
2772 void __user *buffer, size_t *lenp, loff_t *ppos)
2774 int error = proc_dostring(table, write, buffer, lenp, ppos);
2776 validate_coredump_safety();
2781 static int __do_proc_doulongvec_minmax(void *data, 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 unsigned long *i, *min, *max;
2788 int vleft, first = 1, err = 0;
2790 char *kbuf = NULL, *p;
2792 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2797 i = (unsigned long *) data;
2798 min = (unsigned long *) table->extra1;
2799 max = (unsigned long *) table->extra2;
2800 vleft = table->maxlen / sizeof(unsigned long);
2804 if (proc_first_pos_non_zero_ignore(ppos, table))
2807 if (left > PAGE_SIZE - 1)
2808 left = PAGE_SIZE - 1;
2809 p = kbuf = memdup_user_nul(buffer, left);
2811 return PTR_ERR(kbuf);
2814 for (; left && vleft--; i++, first = 0) {
2820 left -= proc_skip_spaces(&p);
2824 err = proc_get_long(&p, &left, &val, &neg,
2826 sizeof(proc_wspace_sep), NULL);
2831 val = convmul * val / convdiv;
2832 if ((min && val < *min) || (max && val > *max)) {
2838 val = convdiv * (*i) / convmul;
2840 err = proc_put_char(&buffer, &left, '\t');
2844 err = proc_put_long(&buffer, &left, val, false);
2850 if (!write && !first && left && !err)
2851 err = proc_put_char(&buffer, &left, '\n');
2853 left -= proc_skip_spaces(&p);
2857 return err ? : -EINVAL;
2865 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2866 void __user *buffer,
2867 size_t *lenp, loff_t *ppos,
2868 unsigned long convmul,
2869 unsigned long convdiv)
2871 return __do_proc_doulongvec_minmax(table->data, table, write,
2872 buffer, lenp, ppos, convmul, convdiv);
2876 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2877 * @table: the sysctl table
2878 * @write: %TRUE if this is a write to the sysctl file
2879 * @buffer: the user buffer
2880 * @lenp: the size of the user buffer
2881 * @ppos: file position
2883 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2884 * values from/to the user buffer, treated as an ASCII string.
2886 * This routine will ensure the values are within the range specified by
2887 * table->extra1 (min) and table->extra2 (max).
2889 * Returns 0 on success.
2891 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2892 void __user *buffer, size_t *lenp, loff_t *ppos)
2894 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2898 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2899 * @table: the sysctl table
2900 * @write: %TRUE if this is a write to the sysctl file
2901 * @buffer: the user buffer
2902 * @lenp: the size of the user buffer
2903 * @ppos: file position
2905 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2906 * values from/to the user buffer, treated as an ASCII string. The values
2907 * are treated as milliseconds, and converted to jiffies when they are stored.
2909 * This routine will ensure the values are within the range specified by
2910 * table->extra1 (min) and table->extra2 (max).
2912 * Returns 0 on success.
2914 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2915 void __user *buffer,
2916 size_t *lenp, loff_t *ppos)
2918 return do_proc_doulongvec_minmax(table, write, buffer,
2919 lenp, ppos, HZ, 1000l);
2923 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2925 int write, void *data)
2928 if (*lvalp > INT_MAX / HZ)
2930 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2936 lval = -(unsigned long)val;
2939 lval = (unsigned long)val;
2946 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2948 int write, void *data)
2951 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2953 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2959 lval = -(unsigned long)val;
2962 lval = (unsigned long)val;
2964 *lvalp = jiffies_to_clock_t(lval);
2969 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2971 int write, void *data)
2974 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2984 lval = -(unsigned long)val;
2987 lval = (unsigned long)val;
2989 *lvalp = jiffies_to_msecs(lval);
2995 * proc_dointvec_jiffies - read a vector of integers as seconds
2996 * @table: the sysctl table
2997 * @write: %TRUE if this is a write to the sysctl file
2998 * @buffer: the user buffer
2999 * @lenp: the size of the user buffer
3000 * @ppos: file position
3002 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3003 * values from/to the user buffer, treated as an ASCII string.
3004 * The values read are assumed to be in seconds, and are converted into
3007 * Returns 0 on success.
3009 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3010 void __user *buffer, size_t *lenp, loff_t *ppos)
3012 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3013 do_proc_dointvec_jiffies_conv,NULL);
3017 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3018 * @table: the sysctl table
3019 * @write: %TRUE if this is a write to the sysctl file
3020 * @buffer: the user buffer
3021 * @lenp: the size of the user buffer
3022 * @ppos: pointer to the file position
3024 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3025 * values from/to the user buffer, treated as an ASCII string.
3026 * The values read are assumed to be in 1/USER_HZ seconds, and
3027 * are converted into jiffies.
3029 * Returns 0 on success.
3031 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3032 void __user *buffer, size_t *lenp, loff_t *ppos)
3034 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3035 do_proc_dointvec_userhz_jiffies_conv,NULL);
3039 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3040 * @table: the sysctl table
3041 * @write: %TRUE if this is a write to the sysctl file
3042 * @buffer: the user buffer
3043 * @lenp: the size of the user buffer
3044 * @ppos: file position
3045 * @ppos: the current position in the file
3047 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3048 * values from/to the user buffer, treated as an ASCII string.
3049 * The values read are assumed to be in 1/1000 seconds, and
3050 * are converted into jiffies.
3052 * Returns 0 on success.
3054 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3055 void __user *buffer, size_t *lenp, loff_t *ppos)
3057 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3058 do_proc_dointvec_ms_jiffies_conv, NULL);
3061 static int proc_do_cad_pid(struct ctl_table *table, int write,
3062 void __user *buffer, size_t *lenp, loff_t *ppos)
3064 struct pid *new_pid;
3068 tmp = pid_vnr(cad_pid);
3070 r = __do_proc_dointvec(&tmp, table, write, buffer,
3071 lenp, ppos, NULL, NULL);
3075 new_pid = find_get_pid(tmp);
3079 put_pid(xchg(&cad_pid, new_pid));
3084 * proc_do_large_bitmap - read/write from/to a large bitmap
3085 * @table: the sysctl table
3086 * @write: %TRUE if this is a write to the sysctl file
3087 * @buffer: the user buffer
3088 * @lenp: the size of the user buffer
3089 * @ppos: file position
3091 * The bitmap is stored at table->data and the bitmap length (in bits)
3094 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3095 * large bitmaps may be represented in a compact manner. Writing into
3096 * the file will clear the bitmap then update it with the given input.
3098 * Returns 0 on success.
3100 int proc_do_large_bitmap(struct ctl_table *table, int write,
3101 void __user *buffer, size_t *lenp, loff_t *ppos)
3105 size_t left = *lenp;
3106 unsigned long bitmap_len = table->maxlen;
3107 unsigned long *bitmap = *(unsigned long **) table->data;
3108 unsigned long *tmp_bitmap = NULL;
3109 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3111 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3119 if (left > PAGE_SIZE - 1)
3120 left = PAGE_SIZE - 1;
3122 p = kbuf = memdup_user_nul(buffer, left);
3124 return PTR_ERR(kbuf);
3126 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3127 sizeof(unsigned long),
3133 proc_skip_char(&p, &left, '\n');
3134 while (!err && left) {
3135 unsigned long val_a, val_b;
3138 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3142 if (val_a >= bitmap_len || neg) {
3154 err = proc_get_long(&p, &left, &val_b,
3155 &neg, tr_b, sizeof(tr_b),
3159 if (val_b >= bitmap_len || neg ||
3170 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3172 proc_skip_char(&p, &left, '\n');
3176 unsigned long bit_a, bit_b = 0;
3179 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3180 if (bit_a >= bitmap_len)
3182 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3186 err = proc_put_char(&buffer, &left, ',');
3190 err = proc_put_long(&buffer, &left, bit_a, false);
3193 if (bit_a != bit_b) {
3194 err = proc_put_char(&buffer, &left, '-');
3197 err = proc_put_long(&buffer, &left, bit_b, false);
3205 err = proc_put_char(&buffer, &left, '\n');
3211 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3213 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3223 #else /* CONFIG_PROC_SYSCTL */
3225 int proc_dostring(struct ctl_table *table, int write,
3226 void __user *buffer, size_t *lenp, loff_t *ppos)
3231 int proc_dointvec(struct ctl_table *table, int write,
3232 void __user *buffer, size_t *lenp, loff_t *ppos)
3237 int proc_douintvec(struct ctl_table *table, int write,
3238 void __user *buffer, size_t *lenp, loff_t *ppos)
3243 int proc_dointvec_minmax(struct ctl_table *table, int write,
3244 void __user *buffer, size_t *lenp, loff_t *ppos)
3249 int proc_douintvec_minmax(struct ctl_table *table, int write,
3250 void __user *buffer, size_t *lenp, loff_t *ppos)
3255 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3256 void __user *buffer, size_t *lenp, loff_t *ppos)
3261 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3262 void __user *buffer, size_t *lenp, loff_t *ppos)
3267 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3268 void __user *buffer, size_t *lenp, loff_t *ppos)
3273 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3274 void __user *buffer, size_t *lenp, loff_t *ppos)
3279 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3280 void __user *buffer,
3281 size_t *lenp, loff_t *ppos)
3287 #endif /* CONFIG_PROC_SYSCTL */
3290 * No sense putting this after each symbol definition, twice,
3291 * exception granted :-)
3293 EXPORT_SYMBOL(proc_dointvec);
3294 EXPORT_SYMBOL(proc_douintvec);
3295 EXPORT_SYMBOL(proc_dointvec_jiffies);
3296 EXPORT_SYMBOL(proc_dointvec_minmax);
3297 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3298 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3299 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3300 EXPORT_SYMBOL(proc_dostring);
3301 EXPORT_SYMBOL(proc_doulongvec_minmax);
3302 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);