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 #ifdef CONFIG_BPF_SYSCALL
255 void __weak unpriv_ebpf_notify(int new_state)
259 static int bpf_unpriv_handler(struct ctl_table *table, int write,
260 void *buffer, size_t *lenp, loff_t *ppos)
262 int ret, unpriv_enable = *(int *)table->data;
263 bool locked_state = unpriv_enable == 1;
264 struct ctl_table tmp = *table;
266 if (write && !capable(CAP_SYS_ADMIN))
269 tmp.data = &unpriv_enable;
270 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
272 if (locked_state && unpriv_enable != 1)
274 *(int *)table->data = unpriv_enable;
277 unpriv_ebpf_notify(unpriv_enable);
283 static struct ctl_table kern_table[];
284 static struct ctl_table vm_table[];
285 static struct ctl_table fs_table[];
286 static struct ctl_table debug_table[];
287 static struct ctl_table dev_table[];
288 extern struct ctl_table random_table[];
290 extern struct ctl_table epoll_table[];
293 #ifdef CONFIG_FW_LOADER_USER_HELPER
294 extern struct ctl_table firmware_config_table[];
297 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
298 int sysctl_legacy_va_layout;
301 /* The default sysctl tables: */
303 static struct ctl_table sysctl_base_table[] = {
305 .procname = "kernel",
322 .child = debug_table,
332 #ifdef CONFIG_SCHED_DEBUG
333 static int min_sched_granularity_ns = 100000; /* 100 usecs */
334 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
335 static int min_wakeup_granularity_ns; /* 0 usecs */
336 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
338 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
339 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
340 #endif /* CONFIG_SMP */
341 #endif /* CONFIG_SCHED_DEBUG */
343 #ifdef CONFIG_COMPACTION
344 static int min_extfrag_threshold;
345 static int max_extfrag_threshold = 1000;
348 static struct ctl_table kern_table[] = {
350 .procname = "sched_child_runs_first",
351 .data = &sysctl_sched_child_runs_first,
352 .maxlen = sizeof(unsigned int),
354 .proc_handler = proc_dointvec,
356 #ifdef CONFIG_SCHED_DEBUG
358 .procname = "sched_min_granularity_ns",
359 .data = &sysctl_sched_min_granularity,
360 .maxlen = sizeof(unsigned int),
362 .proc_handler = sched_proc_update_handler,
363 .extra1 = &min_sched_granularity_ns,
364 .extra2 = &max_sched_granularity_ns,
367 .procname = "sched_latency_ns",
368 .data = &sysctl_sched_latency,
369 .maxlen = sizeof(unsigned int),
371 .proc_handler = sched_proc_update_handler,
372 .extra1 = &min_sched_granularity_ns,
373 .extra2 = &max_sched_granularity_ns,
376 .procname = "sched_wakeup_granularity_ns",
377 .data = &sysctl_sched_wakeup_granularity,
378 .maxlen = sizeof(unsigned int),
380 .proc_handler = sched_proc_update_handler,
381 .extra1 = &min_wakeup_granularity_ns,
382 .extra2 = &max_wakeup_granularity_ns,
386 .procname = "sched_tunable_scaling",
387 .data = &sysctl_sched_tunable_scaling,
388 .maxlen = sizeof(enum sched_tunable_scaling),
390 .proc_handler = sched_proc_update_handler,
391 .extra1 = &min_sched_tunable_scaling,
392 .extra2 = &max_sched_tunable_scaling,
395 .procname = "sched_migration_cost_ns",
396 .data = &sysctl_sched_migration_cost,
397 .maxlen = sizeof(unsigned int),
399 .proc_handler = proc_dointvec,
402 .procname = "sched_nr_migrate",
403 .data = &sysctl_sched_nr_migrate,
404 .maxlen = sizeof(unsigned int),
406 .proc_handler = proc_dointvec,
408 #ifdef CONFIG_SCHEDSTATS
410 .procname = "sched_schedstats",
412 .maxlen = sizeof(unsigned int),
414 .proc_handler = sysctl_schedstats,
418 #endif /* CONFIG_SCHEDSTATS */
419 #endif /* CONFIG_SMP */
420 #ifdef CONFIG_NUMA_BALANCING
422 .procname = "numa_balancing_scan_delay_ms",
423 .data = &sysctl_numa_balancing_scan_delay,
424 .maxlen = sizeof(unsigned int),
426 .proc_handler = proc_dointvec,
429 .procname = "numa_balancing_scan_period_min_ms",
430 .data = &sysctl_numa_balancing_scan_period_min,
431 .maxlen = sizeof(unsigned int),
433 .proc_handler = proc_dointvec,
436 .procname = "numa_balancing_scan_period_max_ms",
437 .data = &sysctl_numa_balancing_scan_period_max,
438 .maxlen = sizeof(unsigned int),
440 .proc_handler = proc_dointvec,
443 .procname = "numa_balancing_scan_size_mb",
444 .data = &sysctl_numa_balancing_scan_size,
445 .maxlen = sizeof(unsigned int),
447 .proc_handler = proc_dointvec_minmax,
451 .procname = "numa_balancing",
452 .data = NULL, /* filled in by handler */
453 .maxlen = sizeof(unsigned int),
455 .proc_handler = sysctl_numa_balancing,
459 #endif /* CONFIG_NUMA_BALANCING */
460 #endif /* CONFIG_SCHED_DEBUG */
462 .procname = "sched_rt_period_us",
463 .data = &sysctl_sched_rt_period,
464 .maxlen = sizeof(unsigned int),
466 .proc_handler = sched_rt_handler,
469 .procname = "sched_rt_runtime_us",
470 .data = &sysctl_sched_rt_runtime,
471 .maxlen = sizeof(int),
473 .proc_handler = sched_rt_handler,
476 .procname = "sched_rr_timeslice_ms",
477 .data = &sysctl_sched_rr_timeslice,
478 .maxlen = sizeof(int),
480 .proc_handler = sched_rr_handler,
482 #ifdef CONFIG_SCHED_AUTOGROUP
484 .procname = "sched_autogroup_enabled",
485 .data = &sysctl_sched_autogroup_enabled,
486 .maxlen = sizeof(unsigned int),
488 .proc_handler = proc_dointvec_minmax,
493 #ifdef CONFIG_CFS_BANDWIDTH
495 .procname = "sched_cfs_bandwidth_slice_us",
496 .data = &sysctl_sched_cfs_bandwidth_slice,
497 .maxlen = sizeof(unsigned int),
499 .proc_handler = proc_dointvec_minmax,
503 #ifdef CONFIG_PROVE_LOCKING
505 .procname = "prove_locking",
506 .data = &prove_locking,
507 .maxlen = sizeof(int),
509 .proc_handler = proc_dointvec,
512 #ifdef CONFIG_LOCK_STAT
514 .procname = "lock_stat",
516 .maxlen = sizeof(int),
518 .proc_handler = proc_dointvec,
523 .data = &panic_timeout,
524 .maxlen = sizeof(int),
526 .proc_handler = proc_dointvec,
528 #ifdef CONFIG_COREDUMP
530 .procname = "core_uses_pid",
531 .data = &core_uses_pid,
532 .maxlen = sizeof(int),
534 .proc_handler = proc_dointvec,
537 .procname = "core_pattern",
538 .data = core_pattern,
539 .maxlen = CORENAME_MAX_SIZE,
541 .proc_handler = proc_dostring_coredump,
544 .procname = "core_pipe_limit",
545 .data = &core_pipe_limit,
546 .maxlen = sizeof(unsigned int),
548 .proc_handler = proc_dointvec,
551 #ifdef CONFIG_PROC_SYSCTL
553 .procname = "tainted",
554 .maxlen = sizeof(long),
556 .proc_handler = proc_taint,
559 .procname = "sysctl_writes_strict",
560 .data = &sysctl_writes_strict,
561 .maxlen = sizeof(int),
563 .proc_handler = proc_dointvec_minmax,
568 #ifdef CONFIG_LATENCYTOP
570 .procname = "latencytop",
571 .data = &latencytop_enabled,
572 .maxlen = sizeof(int),
574 .proc_handler = sysctl_latencytop,
577 #ifdef CONFIG_BLK_DEV_INITRD
579 .procname = "real-root-dev",
580 .data = &real_root_dev,
581 .maxlen = sizeof(int),
583 .proc_handler = proc_dointvec,
587 .procname = "print-fatal-signals",
588 .data = &print_fatal_signals,
589 .maxlen = sizeof(int),
591 .proc_handler = proc_dointvec,
595 .procname = "reboot-cmd",
596 .data = reboot_command,
599 .proc_handler = proc_dostring,
602 .procname = "stop-a",
603 .data = &stop_a_enabled,
604 .maxlen = sizeof (int),
606 .proc_handler = proc_dointvec,
609 .procname = "scons-poweroff",
610 .data = &scons_pwroff,
611 .maxlen = sizeof (int),
613 .proc_handler = proc_dointvec,
616 #ifdef CONFIG_SPARC64
618 .procname = "tsb-ratio",
619 .data = &sysctl_tsb_ratio,
620 .maxlen = sizeof (int),
622 .proc_handler = proc_dointvec,
627 .procname = "soft-power",
628 .data = &pwrsw_enabled,
629 .maxlen = sizeof (int),
631 .proc_handler = proc_dointvec,
634 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
636 .procname = "unaligned-trap",
637 .data = &unaligned_enabled,
638 .maxlen = sizeof (int),
640 .proc_handler = proc_dointvec,
644 .procname = "ctrl-alt-del",
646 .maxlen = sizeof(int),
648 .proc_handler = proc_dointvec,
650 #ifdef CONFIG_FUNCTION_TRACER
652 .procname = "ftrace_enabled",
653 .data = &ftrace_enabled,
654 .maxlen = sizeof(int),
656 .proc_handler = ftrace_enable_sysctl,
659 #ifdef CONFIG_STACK_TRACER
661 .procname = "stack_tracer_enabled",
662 .data = &stack_tracer_enabled,
663 .maxlen = sizeof(int),
665 .proc_handler = stack_trace_sysctl,
668 #ifdef CONFIG_TRACING
670 .procname = "ftrace_dump_on_oops",
671 .data = &ftrace_dump_on_oops,
672 .maxlen = sizeof(int),
674 .proc_handler = proc_dointvec,
677 .procname = "traceoff_on_warning",
678 .data = &__disable_trace_on_warning,
679 .maxlen = sizeof(__disable_trace_on_warning),
681 .proc_handler = proc_dointvec,
684 .procname = "tracepoint_printk",
685 .data = &tracepoint_printk,
686 .maxlen = sizeof(tracepoint_printk),
688 .proc_handler = tracepoint_printk_sysctl,
691 #ifdef CONFIG_KEXEC_CORE
693 .procname = "kexec_load_disabled",
694 .data = &kexec_load_disabled,
695 .maxlen = sizeof(int),
697 /* only handle a transition from default "0" to "1" */
698 .proc_handler = proc_dointvec_minmax,
703 #ifdef CONFIG_MODULES
705 .procname = "modprobe",
706 .data = &modprobe_path,
707 .maxlen = KMOD_PATH_LEN,
709 .proc_handler = proc_dostring,
712 .procname = "modules_disabled",
713 .data = &modules_disabled,
714 .maxlen = sizeof(int),
716 /* only handle a transition from default "0" to "1" */
717 .proc_handler = proc_dointvec_minmax,
722 #ifdef CONFIG_UEVENT_HELPER
724 .procname = "hotplug",
725 .data = &uevent_helper,
726 .maxlen = UEVENT_HELPER_PATH_LEN,
728 .proc_handler = proc_dostring,
731 #ifdef CONFIG_CHR_DEV_SG
733 .procname = "sg-big-buff",
734 .data = &sg_big_buff,
735 .maxlen = sizeof (int),
737 .proc_handler = proc_dointvec,
740 #ifdef CONFIG_BSD_PROCESS_ACCT
744 .maxlen = 3*sizeof(int),
746 .proc_handler = proc_dointvec,
749 #ifdef CONFIG_MAGIC_SYSRQ
752 .data = &__sysrq_enabled,
753 .maxlen = sizeof (int),
755 .proc_handler = sysrq_sysctl_handler,
758 #ifdef CONFIG_PROC_SYSCTL
760 .procname = "cad_pid",
762 .maxlen = sizeof (int),
764 .proc_handler = proc_do_cad_pid,
768 .procname = "threads-max",
770 .maxlen = sizeof(int),
772 .proc_handler = sysctl_max_threads,
775 .procname = "random",
777 .child = random_table,
780 .procname = "usermodehelper",
782 .child = usermodehelper_table,
784 #ifdef CONFIG_FW_LOADER_USER_HELPER
786 .procname = "firmware_config",
788 .child = firmware_config_table,
792 .procname = "overflowuid",
793 .data = &overflowuid,
794 .maxlen = sizeof(int),
796 .proc_handler = proc_dointvec_minmax,
797 .extra1 = &minolduid,
798 .extra2 = &maxolduid,
801 .procname = "overflowgid",
802 .data = &overflowgid,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dointvec_minmax,
806 .extra1 = &minolduid,
807 .extra2 = &maxolduid,
810 #ifdef CONFIG_MATHEMU
812 .procname = "ieee_emulation_warnings",
813 .data = &sysctl_ieee_emulation_warnings,
814 .maxlen = sizeof(int),
816 .proc_handler = proc_dointvec,
820 .procname = "userprocess_debug",
821 .data = &show_unhandled_signals,
822 .maxlen = sizeof(int),
824 .proc_handler = proc_dointvec,
828 .procname = "pid_max",
830 .maxlen = sizeof (int),
832 .proc_handler = proc_dointvec_minmax,
833 .extra1 = &pid_max_min,
834 .extra2 = &pid_max_max,
837 .procname = "panic_on_oops",
838 .data = &panic_on_oops,
839 .maxlen = sizeof(int),
841 .proc_handler = proc_dointvec,
843 #if defined CONFIG_PRINTK
845 .procname = "printk",
846 .data = &console_loglevel,
847 .maxlen = 4*sizeof(int),
849 .proc_handler = proc_dointvec,
852 .procname = "printk_ratelimit",
853 .data = &printk_ratelimit_state.interval,
854 .maxlen = sizeof(int),
856 .proc_handler = proc_dointvec_jiffies,
859 .procname = "printk_ratelimit_burst",
860 .data = &printk_ratelimit_state.burst,
861 .maxlen = sizeof(int),
863 .proc_handler = proc_dointvec,
866 .procname = "printk_delay",
867 .data = &printk_delay_msec,
868 .maxlen = sizeof(int),
870 .proc_handler = proc_dointvec_minmax,
872 .extra2 = &ten_thousand,
875 .procname = "printk_devkmsg",
876 .data = devkmsg_log_str,
877 .maxlen = DEVKMSG_STR_MAX_SIZE,
879 .proc_handler = devkmsg_sysctl_set_loglvl,
882 .procname = "dmesg_restrict",
883 .data = &dmesg_restrict,
884 .maxlen = sizeof(int),
886 .proc_handler = proc_dointvec_minmax_sysadmin,
891 .procname = "kptr_restrict",
892 .data = &kptr_restrict,
893 .maxlen = sizeof(int),
895 .proc_handler = proc_dointvec_minmax_sysadmin,
901 .procname = "ngroups_max",
902 .data = &ngroups_max,
903 .maxlen = sizeof (int),
905 .proc_handler = proc_dointvec,
908 .procname = "cap_last_cap",
909 .data = (void *)&cap_last_cap,
910 .maxlen = sizeof(int),
912 .proc_handler = proc_dointvec,
914 #if defined(CONFIG_LOCKUP_DETECTOR)
916 .procname = "watchdog",
917 .data = &watchdog_user_enabled,
918 .maxlen = sizeof(int),
920 .proc_handler = proc_watchdog,
925 .procname = "watchdog_thresh",
926 .data = &watchdog_thresh,
927 .maxlen = sizeof(int),
929 .proc_handler = proc_watchdog_thresh,
934 .procname = "nmi_watchdog",
935 .data = &nmi_watchdog_user_enabled,
936 .maxlen = sizeof(int),
937 .mode = NMI_WATCHDOG_SYSCTL_PERM,
938 .proc_handler = proc_nmi_watchdog,
943 .procname = "watchdog_cpumask",
944 .data = &watchdog_cpumask_bits,
947 .proc_handler = proc_watchdog_cpumask,
949 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
951 .procname = "soft_watchdog",
952 .data = &soft_watchdog_user_enabled,
953 .maxlen = sizeof(int),
955 .proc_handler = proc_soft_watchdog,
960 .procname = "softlockup_panic",
961 .data = &softlockup_panic,
962 .maxlen = sizeof(int),
964 .proc_handler = proc_dointvec_minmax,
970 .procname = "softlockup_all_cpu_backtrace",
971 .data = &sysctl_softlockup_all_cpu_backtrace,
972 .maxlen = sizeof(int),
974 .proc_handler = proc_dointvec_minmax,
978 #endif /* CONFIG_SMP */
980 #ifdef CONFIG_HARDLOCKUP_DETECTOR
982 .procname = "hardlockup_panic",
983 .data = &hardlockup_panic,
984 .maxlen = sizeof(int),
986 .proc_handler = proc_dointvec_minmax,
992 .procname = "hardlockup_all_cpu_backtrace",
993 .data = &sysctl_hardlockup_all_cpu_backtrace,
994 .maxlen = sizeof(int),
996 .proc_handler = proc_dointvec_minmax,
1000 #endif /* CONFIG_SMP */
1004 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1006 .procname = "unknown_nmi_panic",
1007 .data = &unknown_nmi_panic,
1008 .maxlen = sizeof (int),
1010 .proc_handler = proc_dointvec,
1013 #if defined(CONFIG_X86)
1015 .procname = "panic_on_unrecovered_nmi",
1016 .data = &panic_on_unrecovered_nmi,
1017 .maxlen = sizeof(int),
1019 .proc_handler = proc_dointvec,
1022 .procname = "panic_on_io_nmi",
1023 .data = &panic_on_io_nmi,
1024 .maxlen = sizeof(int),
1026 .proc_handler = proc_dointvec,
1028 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1030 .procname = "panic_on_stackoverflow",
1031 .data = &sysctl_panic_on_stackoverflow,
1032 .maxlen = sizeof(int),
1034 .proc_handler = proc_dointvec,
1038 .procname = "bootloader_type",
1039 .data = &bootloader_type,
1040 .maxlen = sizeof (int),
1042 .proc_handler = proc_dointvec,
1045 .procname = "bootloader_version",
1046 .data = &bootloader_version,
1047 .maxlen = sizeof (int),
1049 .proc_handler = proc_dointvec,
1052 .procname = "io_delay_type",
1053 .data = &io_delay_type,
1054 .maxlen = sizeof(int),
1056 .proc_handler = proc_dointvec,
1059 #if defined(CONFIG_MMU)
1061 .procname = "randomize_va_space",
1062 .data = &randomize_va_space,
1063 .maxlen = sizeof(int),
1065 .proc_handler = proc_dointvec,
1068 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1070 .procname = "spin_retry",
1071 .data = &spin_retry,
1072 .maxlen = sizeof (int),
1074 .proc_handler = proc_dointvec,
1077 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1079 .procname = "acpi_video_flags",
1080 .data = &acpi_realmode_flags,
1081 .maxlen = sizeof (unsigned long),
1083 .proc_handler = proc_doulongvec_minmax,
1086 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1088 .procname = "ignore-unaligned-usertrap",
1089 .data = &no_unaligned_warning,
1090 .maxlen = sizeof (int),
1092 .proc_handler = proc_dointvec,
1097 .procname = "unaligned-dump-stack",
1098 .data = &unaligned_dump_stack,
1099 .maxlen = sizeof (int),
1101 .proc_handler = proc_dointvec,
1104 #ifdef CONFIG_DETECT_HUNG_TASK
1106 .procname = "hung_task_panic",
1107 .data = &sysctl_hung_task_panic,
1108 .maxlen = sizeof(int),
1110 .proc_handler = proc_dointvec_minmax,
1115 .procname = "hung_task_check_count",
1116 .data = &sysctl_hung_task_check_count,
1117 .maxlen = sizeof(int),
1119 .proc_handler = proc_dointvec_minmax,
1123 .procname = "hung_task_timeout_secs",
1124 .data = &sysctl_hung_task_timeout_secs,
1125 .maxlen = sizeof(unsigned long),
1127 .proc_handler = proc_dohung_task_timeout_secs,
1128 .extra2 = &hung_task_timeout_max,
1131 .procname = "hung_task_check_interval_secs",
1132 .data = &sysctl_hung_task_check_interval_secs,
1133 .maxlen = sizeof(unsigned long),
1135 .proc_handler = proc_dohung_task_timeout_secs,
1136 .extra2 = &hung_task_timeout_max,
1139 .procname = "hung_task_warnings",
1140 .data = &sysctl_hung_task_warnings,
1141 .maxlen = sizeof(int),
1143 .proc_handler = proc_dointvec_minmax,
1147 #ifdef CONFIG_RT_MUTEXES
1149 .procname = "max_lock_depth",
1150 .data = &max_lock_depth,
1151 .maxlen = sizeof(int),
1153 .proc_handler = proc_dointvec,
1157 .procname = "poweroff_cmd",
1158 .data = &poweroff_cmd,
1159 .maxlen = POWEROFF_CMD_PATH_LEN,
1161 .proc_handler = proc_dostring,
1167 .child = key_sysctls,
1170 #ifdef CONFIG_PERF_EVENTS
1172 * User-space scripts rely on the existence of this file
1173 * as a feature check for perf_events being enabled.
1175 * So it's an ABI, do not remove!
1178 .procname = "perf_event_paranoid",
1179 .data = &sysctl_perf_event_paranoid,
1180 .maxlen = sizeof(sysctl_perf_event_paranoid),
1182 .proc_handler = proc_dointvec,
1185 .procname = "perf_event_mlock_kb",
1186 .data = &sysctl_perf_event_mlock,
1187 .maxlen = sizeof(sysctl_perf_event_mlock),
1189 .proc_handler = proc_dointvec,
1192 .procname = "perf_event_max_sample_rate",
1193 .data = &sysctl_perf_event_sample_rate,
1194 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1196 .proc_handler = perf_proc_update_handler,
1200 .procname = "perf_cpu_time_max_percent",
1201 .data = &sysctl_perf_cpu_time_max_percent,
1202 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1204 .proc_handler = perf_cpu_time_max_percent_handler,
1206 .extra2 = &one_hundred,
1209 .procname = "perf_event_max_stack",
1210 .data = &sysctl_perf_event_max_stack,
1211 .maxlen = sizeof(sysctl_perf_event_max_stack),
1213 .proc_handler = perf_event_max_stack_handler,
1215 .extra2 = &six_hundred_forty_kb,
1218 .procname = "perf_event_max_contexts_per_stack",
1219 .data = &sysctl_perf_event_max_contexts_per_stack,
1220 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1222 .proc_handler = perf_event_max_stack_handler,
1224 .extra2 = &one_thousand,
1228 .procname = "panic_on_warn",
1229 .data = &panic_on_warn,
1230 .maxlen = sizeof(int),
1232 .proc_handler = proc_dointvec_minmax,
1236 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1238 .procname = "timer_migration",
1239 .data = &sysctl_timer_migration,
1240 .maxlen = sizeof(unsigned int),
1242 .proc_handler = timer_migration_handler,
1247 #ifdef CONFIG_BPF_SYSCALL
1249 .procname = "unprivileged_bpf_disabled",
1250 .data = &sysctl_unprivileged_bpf_disabled,
1251 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1253 .proc_handler = bpf_unpriv_handler,
1258 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1260 .procname = "panic_on_rcu_stall",
1261 .data = &sysctl_panic_on_rcu_stall,
1262 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1264 .proc_handler = proc_dointvec_minmax,
1272 static struct ctl_table vm_table[] = {
1274 .procname = "overcommit_memory",
1275 .data = &sysctl_overcommit_memory,
1276 .maxlen = sizeof(sysctl_overcommit_memory),
1278 .proc_handler = proc_dointvec_minmax,
1283 .procname = "panic_on_oom",
1284 .data = &sysctl_panic_on_oom,
1285 .maxlen = sizeof(sysctl_panic_on_oom),
1287 .proc_handler = proc_dointvec_minmax,
1292 .procname = "oom_kill_allocating_task",
1293 .data = &sysctl_oom_kill_allocating_task,
1294 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1296 .proc_handler = proc_dointvec,
1299 .procname = "oom_dump_tasks",
1300 .data = &sysctl_oom_dump_tasks,
1301 .maxlen = sizeof(sysctl_oom_dump_tasks),
1303 .proc_handler = proc_dointvec,
1306 .procname = "overcommit_ratio",
1307 .data = &sysctl_overcommit_ratio,
1308 .maxlen = sizeof(sysctl_overcommit_ratio),
1310 .proc_handler = overcommit_ratio_handler,
1313 .procname = "overcommit_kbytes",
1314 .data = &sysctl_overcommit_kbytes,
1315 .maxlen = sizeof(sysctl_overcommit_kbytes),
1317 .proc_handler = overcommit_kbytes_handler,
1320 .procname = "page-cluster",
1321 .data = &page_cluster,
1322 .maxlen = sizeof(int),
1324 .proc_handler = proc_dointvec_minmax,
1328 .procname = "dirty_background_ratio",
1329 .data = &dirty_background_ratio,
1330 .maxlen = sizeof(dirty_background_ratio),
1332 .proc_handler = dirty_background_ratio_handler,
1334 .extra2 = &one_hundred,
1337 .procname = "dirty_background_bytes",
1338 .data = &dirty_background_bytes,
1339 .maxlen = sizeof(dirty_background_bytes),
1341 .proc_handler = dirty_background_bytes_handler,
1345 .procname = "dirty_ratio",
1346 .data = &vm_dirty_ratio,
1347 .maxlen = sizeof(vm_dirty_ratio),
1349 .proc_handler = dirty_ratio_handler,
1351 .extra2 = &one_hundred,
1354 .procname = "dirty_bytes",
1355 .data = &vm_dirty_bytes,
1356 .maxlen = sizeof(vm_dirty_bytes),
1358 .proc_handler = dirty_bytes_handler,
1359 .extra1 = &dirty_bytes_min,
1362 .procname = "dirty_writeback_centisecs",
1363 .data = &dirty_writeback_interval,
1364 .maxlen = sizeof(dirty_writeback_interval),
1366 .proc_handler = dirty_writeback_centisecs_handler,
1369 .procname = "dirty_expire_centisecs",
1370 .data = &dirty_expire_interval,
1371 .maxlen = sizeof(dirty_expire_interval),
1373 .proc_handler = proc_dointvec_minmax,
1377 .procname = "dirtytime_expire_seconds",
1378 .data = &dirtytime_expire_interval,
1379 .maxlen = sizeof(dirtytime_expire_interval),
1381 .proc_handler = dirtytime_interval_handler,
1385 .procname = "swappiness",
1386 .data = &vm_swappiness,
1387 .maxlen = sizeof(vm_swappiness),
1389 .proc_handler = proc_dointvec_minmax,
1391 .extra2 = &one_hundred,
1393 #ifdef CONFIG_HUGETLB_PAGE
1395 .procname = "nr_hugepages",
1397 .maxlen = sizeof(unsigned long),
1399 .proc_handler = hugetlb_sysctl_handler,
1403 .procname = "nr_hugepages_mempolicy",
1405 .maxlen = sizeof(unsigned long),
1407 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1410 .procname = "numa_stat",
1411 .data = &sysctl_vm_numa_stat,
1412 .maxlen = sizeof(int),
1414 .proc_handler = sysctl_vm_numa_stat_handler,
1420 .procname = "hugetlb_shm_group",
1421 .data = &sysctl_hugetlb_shm_group,
1422 .maxlen = sizeof(gid_t),
1424 .proc_handler = proc_dointvec,
1427 .procname = "nr_overcommit_hugepages",
1429 .maxlen = sizeof(unsigned long),
1431 .proc_handler = hugetlb_overcommit_handler,
1435 .procname = "lowmem_reserve_ratio",
1436 .data = &sysctl_lowmem_reserve_ratio,
1437 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1439 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1442 .procname = "drop_caches",
1443 .data = &sysctl_drop_caches,
1444 .maxlen = sizeof(int),
1446 .proc_handler = drop_caches_sysctl_handler,
1450 #ifdef CONFIG_COMPACTION
1452 .procname = "compact_memory",
1453 .data = &sysctl_compact_memory,
1454 .maxlen = sizeof(int),
1456 .proc_handler = sysctl_compaction_handler,
1459 .procname = "extfrag_threshold",
1460 .data = &sysctl_extfrag_threshold,
1461 .maxlen = sizeof(int),
1463 .proc_handler = sysctl_extfrag_handler,
1464 .extra1 = &min_extfrag_threshold,
1465 .extra2 = &max_extfrag_threshold,
1468 .procname = "compact_unevictable_allowed",
1469 .data = &sysctl_compact_unevictable_allowed,
1470 .maxlen = sizeof(int),
1472 .proc_handler = proc_dointvec,
1477 #endif /* CONFIG_COMPACTION */
1479 .procname = "min_free_kbytes",
1480 .data = &min_free_kbytes,
1481 .maxlen = sizeof(min_free_kbytes),
1483 .proc_handler = min_free_kbytes_sysctl_handler,
1487 .procname = "watermark_scale_factor",
1488 .data = &watermark_scale_factor,
1489 .maxlen = sizeof(watermark_scale_factor),
1491 .proc_handler = watermark_scale_factor_sysctl_handler,
1493 .extra2 = &one_thousand,
1496 .procname = "percpu_pagelist_fraction",
1497 .data = &percpu_pagelist_fraction,
1498 .maxlen = sizeof(percpu_pagelist_fraction),
1500 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1505 .procname = "max_map_count",
1506 .data = &sysctl_max_map_count,
1507 .maxlen = sizeof(sysctl_max_map_count),
1509 .proc_handler = proc_dointvec_minmax,
1514 .procname = "nr_trim_pages",
1515 .data = &sysctl_nr_trim_pages,
1516 .maxlen = sizeof(sysctl_nr_trim_pages),
1518 .proc_handler = proc_dointvec_minmax,
1523 .procname = "laptop_mode",
1524 .data = &laptop_mode,
1525 .maxlen = sizeof(laptop_mode),
1527 .proc_handler = proc_dointvec_jiffies,
1530 .procname = "block_dump",
1531 .data = &block_dump,
1532 .maxlen = sizeof(block_dump),
1534 .proc_handler = proc_dointvec,
1538 .procname = "vfs_cache_pressure",
1539 .data = &sysctl_vfs_cache_pressure,
1540 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1542 .proc_handler = proc_dointvec,
1545 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1547 .procname = "legacy_va_layout",
1548 .data = &sysctl_legacy_va_layout,
1549 .maxlen = sizeof(sysctl_legacy_va_layout),
1551 .proc_handler = proc_dointvec,
1557 .procname = "zone_reclaim_mode",
1558 .data = &node_reclaim_mode,
1559 .maxlen = sizeof(node_reclaim_mode),
1561 .proc_handler = proc_dointvec,
1565 .procname = "min_unmapped_ratio",
1566 .data = &sysctl_min_unmapped_ratio,
1567 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1569 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1571 .extra2 = &one_hundred,
1574 .procname = "min_slab_ratio",
1575 .data = &sysctl_min_slab_ratio,
1576 .maxlen = sizeof(sysctl_min_slab_ratio),
1578 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1580 .extra2 = &one_hundred,
1585 .procname = "stat_interval",
1586 .data = &sysctl_stat_interval,
1587 .maxlen = sizeof(sysctl_stat_interval),
1589 .proc_handler = proc_dointvec_jiffies,
1592 .procname = "stat_refresh",
1596 .proc_handler = vmstat_refresh,
1601 .procname = "mmap_min_addr",
1602 .data = &dac_mmap_min_addr,
1603 .maxlen = sizeof(unsigned long),
1605 .proc_handler = mmap_min_addr_handler,
1610 .procname = "numa_zonelist_order",
1611 .data = &numa_zonelist_order,
1612 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1614 .proc_handler = numa_zonelist_order_handler,
1617 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1618 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1620 .procname = "vdso_enabled",
1621 #ifdef CONFIG_X86_32
1622 .data = &vdso32_enabled,
1623 .maxlen = sizeof(vdso32_enabled),
1625 .data = &vdso_enabled,
1626 .maxlen = sizeof(vdso_enabled),
1629 .proc_handler = proc_dointvec,
1633 #ifdef CONFIG_HIGHMEM
1635 .procname = "highmem_is_dirtyable",
1636 .data = &vm_highmem_is_dirtyable,
1637 .maxlen = sizeof(vm_highmem_is_dirtyable),
1639 .proc_handler = proc_dointvec_minmax,
1644 #ifdef CONFIG_MEMORY_FAILURE
1646 .procname = "memory_failure_early_kill",
1647 .data = &sysctl_memory_failure_early_kill,
1648 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1650 .proc_handler = proc_dointvec_minmax,
1655 .procname = "memory_failure_recovery",
1656 .data = &sysctl_memory_failure_recovery,
1657 .maxlen = sizeof(sysctl_memory_failure_recovery),
1659 .proc_handler = proc_dointvec_minmax,
1665 .procname = "user_reserve_kbytes",
1666 .data = &sysctl_user_reserve_kbytes,
1667 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1669 .proc_handler = proc_doulongvec_minmax,
1672 .procname = "admin_reserve_kbytes",
1673 .data = &sysctl_admin_reserve_kbytes,
1674 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1676 .proc_handler = proc_doulongvec_minmax,
1678 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1680 .procname = "mmap_rnd_bits",
1681 .data = &mmap_rnd_bits,
1682 .maxlen = sizeof(mmap_rnd_bits),
1684 .proc_handler = proc_dointvec_minmax,
1685 .extra1 = (void *)&mmap_rnd_bits_min,
1686 .extra2 = (void *)&mmap_rnd_bits_max,
1689 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1691 .procname = "mmap_rnd_compat_bits",
1692 .data = &mmap_rnd_compat_bits,
1693 .maxlen = sizeof(mmap_rnd_compat_bits),
1695 .proc_handler = proc_dointvec_minmax,
1696 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1697 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1703 static struct ctl_table fs_table[] = {
1705 .procname = "inode-nr",
1706 .data = &inodes_stat,
1707 .maxlen = 2*sizeof(long),
1709 .proc_handler = proc_nr_inodes,
1712 .procname = "inode-state",
1713 .data = &inodes_stat,
1714 .maxlen = 7*sizeof(long),
1716 .proc_handler = proc_nr_inodes,
1719 .procname = "file-nr",
1720 .data = &files_stat,
1721 .maxlen = sizeof(files_stat),
1723 .proc_handler = proc_nr_files,
1726 .procname = "file-max",
1727 .data = &files_stat.max_files,
1728 .maxlen = sizeof(files_stat.max_files),
1730 .proc_handler = proc_doulongvec_minmax,
1732 .extra2 = &long_max,
1735 .procname = "nr_open",
1736 .data = &sysctl_nr_open,
1737 .maxlen = sizeof(unsigned int),
1739 .proc_handler = proc_dointvec_minmax,
1740 .extra1 = &sysctl_nr_open_min,
1741 .extra2 = &sysctl_nr_open_max,
1744 .procname = "dentry-state",
1745 .data = &dentry_stat,
1746 .maxlen = 6*sizeof(long),
1748 .proc_handler = proc_nr_dentry,
1751 .procname = "overflowuid",
1752 .data = &fs_overflowuid,
1753 .maxlen = sizeof(int),
1755 .proc_handler = proc_dointvec_minmax,
1756 .extra1 = &minolduid,
1757 .extra2 = &maxolduid,
1760 .procname = "overflowgid",
1761 .data = &fs_overflowgid,
1762 .maxlen = sizeof(int),
1764 .proc_handler = proc_dointvec_minmax,
1765 .extra1 = &minolduid,
1766 .extra2 = &maxolduid,
1768 #ifdef CONFIG_FILE_LOCKING
1770 .procname = "leases-enable",
1771 .data = &leases_enable,
1772 .maxlen = sizeof(int),
1774 .proc_handler = proc_dointvec,
1777 #ifdef CONFIG_DNOTIFY
1779 .procname = "dir-notify-enable",
1780 .data = &dir_notify_enable,
1781 .maxlen = sizeof(int),
1783 .proc_handler = proc_dointvec,
1787 #ifdef CONFIG_FILE_LOCKING
1789 .procname = "lease-break-time",
1790 .data = &lease_break_time,
1791 .maxlen = sizeof(int),
1793 .proc_handler = proc_dointvec,
1798 .procname = "aio-nr",
1800 .maxlen = sizeof(aio_nr),
1802 .proc_handler = proc_doulongvec_minmax,
1805 .procname = "aio-max-nr",
1806 .data = &aio_max_nr,
1807 .maxlen = sizeof(aio_max_nr),
1809 .proc_handler = proc_doulongvec_minmax,
1811 #endif /* CONFIG_AIO */
1812 #ifdef CONFIG_INOTIFY_USER
1814 .procname = "inotify",
1816 .child = inotify_table,
1821 .procname = "epoll",
1823 .child = epoll_table,
1828 .procname = "protected_symlinks",
1829 .data = &sysctl_protected_symlinks,
1830 .maxlen = sizeof(int),
1832 .proc_handler = proc_dointvec_minmax,
1837 .procname = "protected_hardlinks",
1838 .data = &sysctl_protected_hardlinks,
1839 .maxlen = sizeof(int),
1841 .proc_handler = proc_dointvec_minmax,
1846 .procname = "protected_fifos",
1847 .data = &sysctl_protected_fifos,
1848 .maxlen = sizeof(int),
1850 .proc_handler = proc_dointvec_minmax,
1855 .procname = "protected_regular",
1856 .data = &sysctl_protected_regular,
1857 .maxlen = sizeof(int),
1859 .proc_handler = proc_dointvec_minmax,
1864 .procname = "suid_dumpable",
1865 .data = &suid_dumpable,
1866 .maxlen = sizeof(int),
1868 .proc_handler = proc_dointvec_minmax_coredump,
1872 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1874 .procname = "binfmt_misc",
1876 .child = sysctl_mount_point,
1880 .procname = "pipe-max-size",
1881 .data = &pipe_max_size,
1882 .maxlen = sizeof(pipe_max_size),
1884 .proc_handler = proc_dopipe_max_size,
1887 .procname = "pipe-user-pages-hard",
1888 .data = &pipe_user_pages_hard,
1889 .maxlen = sizeof(pipe_user_pages_hard),
1891 .proc_handler = proc_doulongvec_minmax,
1894 .procname = "pipe-user-pages-soft",
1895 .data = &pipe_user_pages_soft,
1896 .maxlen = sizeof(pipe_user_pages_soft),
1898 .proc_handler = proc_doulongvec_minmax,
1901 .procname = "mount-max",
1902 .data = &sysctl_mount_max,
1903 .maxlen = sizeof(unsigned int),
1905 .proc_handler = proc_dointvec_minmax,
1911 static struct ctl_table debug_table[] = {
1912 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1914 .procname = "exception-trace",
1915 .data = &show_unhandled_signals,
1916 .maxlen = sizeof(int),
1918 .proc_handler = proc_dointvec
1921 #if defined(CONFIG_OPTPROBES)
1923 .procname = "kprobes-optimization",
1924 .data = &sysctl_kprobes_optimization,
1925 .maxlen = sizeof(int),
1927 .proc_handler = proc_kprobes_optimization_handler,
1935 static struct ctl_table dev_table[] = {
1939 int __init sysctl_init(void)
1941 struct ctl_table_header *hdr;
1943 hdr = register_sysctl_table(sysctl_base_table);
1944 kmemleak_not_leak(hdr);
1948 #endif /* CONFIG_SYSCTL */
1954 #ifdef CONFIG_PROC_SYSCTL
1956 static int _proc_do_string(char *data, int maxlen, int write,
1957 char __user *buffer,
1958 size_t *lenp, loff_t *ppos)
1964 if (!data || !maxlen || !*lenp) {
1970 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1971 /* Only continue writes not past the end of buffer. */
1973 if (len > maxlen - 1)
1980 /* Start writing from beginning of buffer. */
1986 while ((p - buffer) < *lenp && len < maxlen - 1) {
1987 if (get_user(c, p++))
1989 if (c == 0 || c == '\n')
2010 if (copy_to_user(buffer, data, len))
2013 if (put_user('\n', buffer + len))
2023 static void warn_sysctl_write(struct ctl_table *table)
2025 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2026 "This will not be supported in the future. To silence this\n"
2027 "warning, set kernel.sysctl_writes_strict = -1\n",
2028 current->comm, table->procname);
2032 * proc_first_pos_non_zero_ignore - check if first position is allowed
2033 * @ppos: file position
2034 * @table: the sysctl table
2036 * Returns true if the first position is non-zero and the sysctl_writes_strict
2037 * mode indicates this is not allowed for numeric input types. String proc
2038 * handlers can ignore the return value.
2040 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2041 struct ctl_table *table)
2046 switch (sysctl_writes_strict) {
2047 case SYSCTL_WRITES_STRICT:
2049 case SYSCTL_WRITES_WARN:
2050 warn_sysctl_write(table);
2058 * proc_dostring - read a string sysctl
2059 * @table: the sysctl table
2060 * @write: %TRUE if this is a write to the sysctl file
2061 * @buffer: the user buffer
2062 * @lenp: the size of the user buffer
2063 * @ppos: file position
2065 * Reads/writes a string from/to the user buffer. If the kernel
2066 * buffer provided is not large enough to hold the string, the
2067 * string is truncated. The copied string is %NULL-terminated.
2068 * If the string is being read by the user process, it is copied
2069 * and a newline '\n' is added. It is truncated if the buffer is
2072 * Returns 0 on success.
2074 int proc_dostring(struct ctl_table *table, int write,
2075 void __user *buffer, size_t *lenp, loff_t *ppos)
2078 proc_first_pos_non_zero_ignore(ppos, table);
2080 return _proc_do_string((char *)(table->data), table->maxlen, write,
2081 (char __user *)buffer, lenp, ppos);
2084 static size_t proc_skip_spaces(char **buf)
2087 char *tmp = skip_spaces(*buf);
2093 static void proc_skip_char(char **buf, size_t *size, const char v)
2104 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2107 * @cp: kernel buffer containing the string to parse
2108 * @endp: pointer to store the trailing characters
2109 * @base: the base to use
2110 * @res: where the parsed integer will be stored
2112 * In case of success 0 is returned and @res will contain the parsed integer,
2113 * @endp will hold any trailing characters.
2114 * This function will fail the parse on overflow. If there wasn't an overflow
2115 * the function will defer the decision what characters count as invalid to the
2118 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2121 unsigned long long result;
2124 cp = _parse_integer_fixup_radix(cp, &base);
2125 rv = _parse_integer(cp, base, &result);
2126 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2134 *res = (unsigned long)result;
2138 #define TMPBUFLEN 22
2140 * proc_get_long - reads an ASCII formatted integer from a user buffer
2142 * @buf: a kernel buffer
2143 * @size: size of the kernel buffer
2144 * @val: this is where the number will be stored
2145 * @neg: set to %TRUE if number is negative
2146 * @perm_tr: a vector which contains the allowed trailers
2147 * @perm_tr_len: size of the perm_tr vector
2148 * @tr: pointer to store the trailer character
2150 * In case of success %0 is returned and @buf and @size are updated with
2151 * the amount of bytes read. If @tr is non-NULL and a trailing
2152 * character exists (size is non-zero after returning from this
2153 * function), @tr is updated with the trailing character.
2155 static int proc_get_long(char **buf, size_t *size,
2156 unsigned long *val, bool *neg,
2157 const char *perm_tr, unsigned perm_tr_len, char *tr)
2160 char *p, tmp[TMPBUFLEN];
2166 if (len > TMPBUFLEN - 1)
2167 len = TMPBUFLEN - 1;
2169 memcpy(tmp, *buf, len);
2173 if (*p == '-' && *size > 1) {
2181 if (strtoul_lenient(p, &p, 0, val))
2186 /* We don't know if the next char is whitespace thus we may accept
2187 * invalid integers (e.g. 1234...a) or two integers instead of one
2188 * (e.g. 123...1). So lets not allow such large numbers. */
2189 if (len == TMPBUFLEN - 1)
2192 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2195 if (tr && (len < *size))
2205 * proc_put_long - converts an integer to a decimal ASCII formatted string
2207 * @buf: the user buffer
2208 * @size: the size of the user buffer
2209 * @val: the integer to be converted
2210 * @neg: sign of the number, %TRUE for negative
2212 * In case of success %0 is returned and @buf and @size are updated with
2213 * the amount of bytes written.
2215 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2219 char tmp[TMPBUFLEN], *p = tmp;
2221 sprintf(p, "%s%lu", neg ? "-" : "", val);
2225 if (copy_to_user(*buf, tmp, len))
2233 static int proc_put_char(void __user **buf, size_t *size, char c)
2236 char __user **buffer = (char __user **)buf;
2237 if (put_user(c, *buffer))
2239 (*size)--, (*buffer)++;
2245 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2247 int write, void *data)
2251 if (*lvalp > (unsigned long) INT_MAX + 1)
2255 if (*lvalp > (unsigned long) INT_MAX)
2263 *lvalp = -(unsigned long)val;
2266 *lvalp = (unsigned long)val;
2272 static int do_proc_douintvec_conv(unsigned long *lvalp,
2274 int write, void *data)
2277 if (*lvalp > UINT_MAX)
2281 unsigned int val = *valp;
2282 *lvalp = (unsigned long)val;
2287 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2289 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2290 int write, void __user *buffer,
2291 size_t *lenp, loff_t *ppos,
2292 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2293 int write, void *data),
2296 int *i, vleft, first = 1, err = 0;
2298 char *kbuf = NULL, *p;
2300 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2305 i = (int *) tbl_data;
2306 vleft = table->maxlen / sizeof(*i);
2310 conv = do_proc_dointvec_conv;
2313 if (proc_first_pos_non_zero_ignore(ppos, table))
2316 if (left > PAGE_SIZE - 1)
2317 left = PAGE_SIZE - 1;
2318 p = kbuf = memdup_user_nul(buffer, left);
2320 return PTR_ERR(kbuf);
2323 for (; left && vleft--; i++, first=0) {
2328 left -= proc_skip_spaces(&p);
2332 err = proc_get_long(&p, &left, &lval, &neg,
2334 sizeof(proc_wspace_sep), NULL);
2337 if (conv(&neg, &lval, i, 1, data)) {
2342 if (conv(&neg, &lval, i, 0, data)) {
2347 err = proc_put_char(&buffer, &left, '\t');
2350 err = proc_put_long(&buffer, &left, lval, neg);
2356 if (!write && !first && left && !err)
2357 err = proc_put_char(&buffer, &left, '\n');
2358 if (write && !err && left)
2359 left -= proc_skip_spaces(&p);
2363 return err ? : -EINVAL;
2371 static int do_proc_dointvec(struct ctl_table *table, int write,
2372 void __user *buffer, size_t *lenp, loff_t *ppos,
2373 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2374 int write, void *data),
2377 return __do_proc_dointvec(table->data, table, write,
2378 buffer, lenp, ppos, conv, data);
2381 static int do_proc_douintvec_w(unsigned int *tbl_data,
2382 struct ctl_table *table,
2383 void __user *buffer,
2384 size_t *lenp, loff_t *ppos,
2385 int (*conv)(unsigned long *lvalp,
2387 int write, void *data),
2394 char *kbuf = NULL, *p;
2398 if (proc_first_pos_non_zero_ignore(ppos, table))
2401 if (left > PAGE_SIZE - 1)
2402 left = PAGE_SIZE - 1;
2404 p = kbuf = memdup_user_nul(buffer, left);
2408 left -= proc_skip_spaces(&p);
2414 err = proc_get_long(&p, &left, &lval, &neg,
2416 sizeof(proc_wspace_sep), NULL);
2422 if (conv(&lval, tbl_data, 1, data)) {
2428 left -= proc_skip_spaces(&p);
2437 /* This is in keeping with old __do_proc_dointvec() */
2443 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2444 size_t *lenp, loff_t *ppos,
2445 int (*conv)(unsigned long *lvalp,
2447 int write, void *data),
2456 if (conv(&lval, tbl_data, 0, data)) {
2461 err = proc_put_long(&buffer, &left, lval, false);
2465 err = proc_put_char(&buffer, &left, '\n');
2474 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2475 int write, void __user *buffer,
2476 size_t *lenp, loff_t *ppos,
2477 int (*conv)(unsigned long *lvalp,
2479 int write, void *data),
2482 unsigned int *i, vleft;
2484 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2489 i = (unsigned int *) tbl_data;
2490 vleft = table->maxlen / sizeof(*i);
2493 * Arrays are not supported, keep this simple. *Do not* add
2502 conv = do_proc_douintvec_conv;
2505 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2507 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2510 static int do_proc_douintvec(struct ctl_table *table, int write,
2511 void __user *buffer, size_t *lenp, loff_t *ppos,
2512 int (*conv)(unsigned long *lvalp,
2514 int write, void *data),
2517 return __do_proc_douintvec(table->data, table, write,
2518 buffer, lenp, ppos, conv, data);
2522 * proc_dointvec - read a vector of integers
2523 * @table: the sysctl table
2524 * @write: %TRUE if this is a write to the sysctl file
2525 * @buffer: the user buffer
2526 * @lenp: the size of the user buffer
2527 * @ppos: file position
2529 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2530 * values from/to the user buffer, treated as an ASCII string.
2532 * Returns 0 on success.
2534 int proc_dointvec(struct ctl_table *table, int write,
2535 void __user *buffer, size_t *lenp, loff_t *ppos)
2537 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2541 * proc_douintvec - read a vector of unsigned integers
2542 * @table: the sysctl table
2543 * @write: %TRUE if this is a write to the sysctl file
2544 * @buffer: the user buffer
2545 * @lenp: the size of the user buffer
2546 * @ppos: file position
2548 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2549 * values from/to the user buffer, treated as an ASCII string.
2551 * Returns 0 on success.
2553 int proc_douintvec(struct ctl_table *table, int write,
2554 void __user *buffer, size_t *lenp, loff_t *ppos)
2556 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2557 do_proc_douintvec_conv, NULL);
2561 * Taint values can only be increased
2562 * This means we can safely use a temporary.
2564 static int proc_taint(struct ctl_table *table, int write,
2565 void __user *buffer, size_t *lenp, loff_t *ppos)
2568 unsigned long tmptaint = get_taint();
2571 if (write && !capable(CAP_SYS_ADMIN))
2576 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2582 * Poor man's atomic or. Not worth adding a primitive
2583 * to everyone's atomic.h for this
2586 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2587 if ((tmptaint >> i) & 1)
2588 add_taint(i, LOCKDEP_STILL_OK);
2595 #ifdef CONFIG_PRINTK
2596 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2597 void __user *buffer, size_t *lenp, loff_t *ppos)
2599 if (write && !capable(CAP_SYS_ADMIN))
2602 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2607 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2608 * @min: pointer to minimum allowable value
2609 * @max: pointer to maximum allowable value
2611 * The do_proc_dointvec_minmax_conv_param structure provides the
2612 * minimum and maximum values for doing range checking for those sysctl
2613 * parameters that use the proc_dointvec_minmax() handler.
2615 struct do_proc_dointvec_minmax_conv_param {
2620 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2622 int write, void *data)
2624 struct do_proc_dointvec_minmax_conv_param *param = data;
2628 if (*lvalp > (unsigned long) INT_MAX + 1)
2632 if (*lvalp > (unsigned long) INT_MAX)
2636 if ((param->min && *param->min > val) ||
2637 (param->max && *param->max < val))
2644 *lvalp = -(unsigned long)val;
2647 *lvalp = (unsigned long)val;
2654 * proc_dointvec_minmax - read a vector of integers with min/max values
2655 * @table: the sysctl table
2656 * @write: %TRUE if this is a write to the sysctl file
2657 * @buffer: the user buffer
2658 * @lenp: the size of the user buffer
2659 * @ppos: file position
2661 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2662 * values from/to the user buffer, treated as an ASCII string.
2664 * This routine will ensure the values are within the range specified by
2665 * table->extra1 (min) and table->extra2 (max).
2667 * Returns 0 on success or -EINVAL on write when the range check fails.
2669 int proc_dointvec_minmax(struct ctl_table *table, int write,
2670 void __user *buffer, size_t *lenp, loff_t *ppos)
2672 struct do_proc_dointvec_minmax_conv_param param = {
2673 .min = (int *) table->extra1,
2674 .max = (int *) table->extra2,
2676 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2677 do_proc_dointvec_minmax_conv, ¶m);
2681 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2682 * @min: pointer to minimum allowable value
2683 * @max: pointer to maximum allowable value
2685 * The do_proc_douintvec_minmax_conv_param structure provides the
2686 * minimum and maximum values for doing range checking for those sysctl
2687 * parameters that use the proc_douintvec_minmax() handler.
2689 struct do_proc_douintvec_minmax_conv_param {
2694 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2696 int write, void *data)
2698 struct do_proc_douintvec_minmax_conv_param *param = data;
2701 unsigned int val = *lvalp;
2703 if (*lvalp > UINT_MAX)
2706 if ((param->min && *param->min > val) ||
2707 (param->max && *param->max < val))
2712 unsigned int val = *valp;
2713 *lvalp = (unsigned long) val;
2720 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2721 * @table: the sysctl table
2722 * @write: %TRUE if this is a write to the sysctl file
2723 * @buffer: the user buffer
2724 * @lenp: the size of the user buffer
2725 * @ppos: file position
2727 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2728 * values from/to the user buffer, treated as an ASCII string. Negative
2729 * strings are not allowed.
2731 * This routine will ensure the values are within the range specified by
2732 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2733 * check for UINT_MAX to avoid having to support wrap around uses from
2736 * Returns 0 on success or -ERANGE on write when the range check fails.
2738 int proc_douintvec_minmax(struct ctl_table *table, int write,
2739 void __user *buffer, size_t *lenp, loff_t *ppos)
2741 struct do_proc_douintvec_minmax_conv_param param = {
2742 .min = (unsigned int *) table->extra1,
2743 .max = (unsigned int *) table->extra2,
2745 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2746 do_proc_douintvec_minmax_conv, ¶m);
2749 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2751 int write, void *data)
2756 val = round_pipe_size(*lvalp);
2762 unsigned int val = *valp;
2763 *lvalp = (unsigned long) val;
2769 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2770 void __user *buffer, size_t *lenp, loff_t *ppos)
2772 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2773 do_proc_dopipe_max_size_conv, NULL);
2776 static void validate_coredump_safety(void)
2778 #ifdef CONFIG_COREDUMP
2779 if (suid_dumpable == SUID_DUMP_ROOT &&
2780 core_pattern[0] != '/' && core_pattern[0] != '|') {
2782 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2783 "Pipe handler or fully qualified core dump path required.\n"
2784 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2790 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2791 void __user *buffer, size_t *lenp, loff_t *ppos)
2793 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2795 validate_coredump_safety();
2799 #ifdef CONFIG_COREDUMP
2800 static int proc_dostring_coredump(struct ctl_table *table, int write,
2801 void __user *buffer, size_t *lenp, loff_t *ppos)
2803 int error = proc_dostring(table, write, buffer, lenp, ppos);
2805 validate_coredump_safety();
2810 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2811 void __user *buffer,
2812 size_t *lenp, loff_t *ppos,
2813 unsigned long convmul,
2814 unsigned long convdiv)
2816 unsigned long *i, *min, *max;
2817 int vleft, first = 1, err = 0;
2819 char *kbuf = NULL, *p;
2821 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2826 i = (unsigned long *) data;
2827 min = (unsigned long *) table->extra1;
2828 max = (unsigned long *) table->extra2;
2829 vleft = table->maxlen / sizeof(unsigned long);
2833 if (proc_first_pos_non_zero_ignore(ppos, table))
2836 if (left > PAGE_SIZE - 1)
2837 left = PAGE_SIZE - 1;
2838 p = kbuf = memdup_user_nul(buffer, left);
2840 return PTR_ERR(kbuf);
2843 for (; left && vleft--; i++, first = 0) {
2849 left -= proc_skip_spaces(&p);
2853 err = proc_get_long(&p, &left, &val, &neg,
2855 sizeof(proc_wspace_sep), NULL);
2860 val = convmul * val / convdiv;
2861 if ((min && val < *min) || (max && val > *max)) {
2867 val = convdiv * (*i) / convmul;
2869 err = proc_put_char(&buffer, &left, '\t');
2873 err = proc_put_long(&buffer, &left, val, false);
2879 if (!write && !first && left && !err)
2880 err = proc_put_char(&buffer, &left, '\n');
2882 left -= proc_skip_spaces(&p);
2886 return err ? : -EINVAL;
2894 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2895 void __user *buffer,
2896 size_t *lenp, loff_t *ppos,
2897 unsigned long convmul,
2898 unsigned long convdiv)
2900 return __do_proc_doulongvec_minmax(table->data, table, write,
2901 buffer, lenp, ppos, convmul, convdiv);
2905 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2906 * @table: the sysctl table
2907 * @write: %TRUE if this is a write to the sysctl file
2908 * @buffer: the user buffer
2909 * @lenp: the size of the user buffer
2910 * @ppos: file position
2912 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2913 * values from/to the user buffer, treated as an ASCII string.
2915 * This routine will ensure the values are within the range specified by
2916 * table->extra1 (min) and table->extra2 (max).
2918 * Returns 0 on success.
2920 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2921 void __user *buffer, size_t *lenp, loff_t *ppos)
2923 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2927 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2928 * @table: the sysctl table
2929 * @write: %TRUE if this is a write to the sysctl file
2930 * @buffer: the user buffer
2931 * @lenp: the size of the user buffer
2932 * @ppos: file position
2934 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2935 * values from/to the user buffer, treated as an ASCII string. The values
2936 * are treated as milliseconds, and converted to jiffies when they are stored.
2938 * This routine will ensure the values are within the range specified by
2939 * table->extra1 (min) and table->extra2 (max).
2941 * Returns 0 on success.
2943 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2944 void __user *buffer,
2945 size_t *lenp, loff_t *ppos)
2947 return do_proc_doulongvec_minmax(table, write, buffer,
2948 lenp, ppos, HZ, 1000l);
2952 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2954 int write, void *data)
2957 if (*lvalp > INT_MAX / HZ)
2959 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2965 lval = -(unsigned long)val;
2968 lval = (unsigned long)val;
2975 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2977 int write, void *data)
2980 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2982 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2988 lval = -(unsigned long)val;
2991 lval = (unsigned long)val;
2993 *lvalp = jiffies_to_clock_t(lval);
2998 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3000 int write, void *data)
3003 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3013 lval = -(unsigned long)val;
3016 lval = (unsigned long)val;
3018 *lvalp = jiffies_to_msecs(lval);
3024 * proc_dointvec_jiffies - read a vector of integers as seconds
3025 * @table: the sysctl table
3026 * @write: %TRUE if this is a write to the sysctl file
3027 * @buffer: the user buffer
3028 * @lenp: the size of the user buffer
3029 * @ppos: file position
3031 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3032 * values from/to the user buffer, treated as an ASCII string.
3033 * The values read are assumed to be in seconds, and are converted into
3036 * Returns 0 on success.
3038 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3039 void __user *buffer, size_t *lenp, loff_t *ppos)
3041 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3042 do_proc_dointvec_jiffies_conv,NULL);
3046 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3047 * @table: the sysctl table
3048 * @write: %TRUE if this is a write to the sysctl file
3049 * @buffer: the user buffer
3050 * @lenp: the size of the user buffer
3051 * @ppos: pointer to the file position
3053 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3054 * values from/to the user buffer, treated as an ASCII string.
3055 * The values read are assumed to be in 1/USER_HZ seconds, and
3056 * are converted into jiffies.
3058 * Returns 0 on success.
3060 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3061 void __user *buffer, size_t *lenp, loff_t *ppos)
3063 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3064 do_proc_dointvec_userhz_jiffies_conv,NULL);
3068 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3069 * @table: the sysctl table
3070 * @write: %TRUE if this is a write to the sysctl file
3071 * @buffer: the user buffer
3072 * @lenp: the size of the user buffer
3073 * @ppos: file position
3074 * @ppos: the current position in the file
3076 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3077 * values from/to the user buffer, treated as an ASCII string.
3078 * The values read are assumed to be in 1/1000 seconds, and
3079 * are converted into jiffies.
3081 * Returns 0 on success.
3083 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3084 void __user *buffer, size_t *lenp, loff_t *ppos)
3086 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3087 do_proc_dointvec_ms_jiffies_conv, NULL);
3090 static int proc_do_cad_pid(struct ctl_table *table, int write,
3091 void __user *buffer, size_t *lenp, loff_t *ppos)
3093 struct pid *new_pid;
3097 tmp = pid_vnr(cad_pid);
3099 r = __do_proc_dointvec(&tmp, table, write, buffer,
3100 lenp, ppos, NULL, NULL);
3104 new_pid = find_get_pid(tmp);
3108 put_pid(xchg(&cad_pid, new_pid));
3113 * proc_do_large_bitmap - read/write from/to a large bitmap
3114 * @table: the sysctl table
3115 * @write: %TRUE if this is a write to the sysctl file
3116 * @buffer: the user buffer
3117 * @lenp: the size of the user buffer
3118 * @ppos: file position
3120 * The bitmap is stored at table->data and the bitmap length (in bits)
3123 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3124 * large bitmaps may be represented in a compact manner. Writing into
3125 * the file will clear the bitmap then update it with the given input.
3127 * Returns 0 on success.
3129 int proc_do_large_bitmap(struct ctl_table *table, int write,
3130 void __user *buffer, size_t *lenp, loff_t *ppos)
3134 size_t left = *lenp;
3135 unsigned long bitmap_len = table->maxlen;
3136 unsigned long *bitmap = *(unsigned long **) table->data;
3137 unsigned long *tmp_bitmap = NULL;
3138 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3140 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3148 if (left > PAGE_SIZE - 1)
3149 left = PAGE_SIZE - 1;
3151 p = kbuf = memdup_user_nul(buffer, left);
3153 return PTR_ERR(kbuf);
3155 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3156 sizeof(unsigned long),
3162 proc_skip_char(&p, &left, '\n');
3163 while (!err && left) {
3164 unsigned long val_a, val_b;
3167 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3171 if (val_a >= bitmap_len || neg) {
3183 err = proc_get_long(&p, &left, &val_b,
3184 &neg, tr_b, sizeof(tr_b),
3188 if (val_b >= bitmap_len || neg ||
3199 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3201 proc_skip_char(&p, &left, '\n');
3205 unsigned long bit_a, bit_b = 0;
3208 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3209 if (bit_a >= bitmap_len)
3211 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3215 err = proc_put_char(&buffer, &left, ',');
3219 err = proc_put_long(&buffer, &left, bit_a, false);
3222 if (bit_a != bit_b) {
3223 err = proc_put_char(&buffer, &left, '-');
3226 err = proc_put_long(&buffer, &left, bit_b, false);
3234 err = proc_put_char(&buffer, &left, '\n');
3240 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3242 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3252 #else /* CONFIG_PROC_SYSCTL */
3254 int proc_dostring(struct ctl_table *table, int write,
3255 void __user *buffer, size_t *lenp, loff_t *ppos)
3260 int proc_dointvec(struct ctl_table *table, int write,
3261 void __user *buffer, size_t *lenp, loff_t *ppos)
3266 int proc_douintvec(struct ctl_table *table, int write,
3267 void __user *buffer, size_t *lenp, loff_t *ppos)
3272 int proc_dointvec_minmax(struct ctl_table *table, int write,
3273 void __user *buffer, size_t *lenp, loff_t *ppos)
3278 int proc_douintvec_minmax(struct ctl_table *table, int write,
3279 void __user *buffer, size_t *lenp, loff_t *ppos)
3284 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3285 void __user *buffer, size_t *lenp, loff_t *ppos)
3290 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3291 void __user *buffer, size_t *lenp, loff_t *ppos)
3296 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3297 void __user *buffer, size_t *lenp, loff_t *ppos)
3302 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3303 void __user *buffer, size_t *lenp, loff_t *ppos)
3308 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3309 void __user *buffer,
3310 size_t *lenp, loff_t *ppos)
3316 #endif /* CONFIG_PROC_SYSCTL */
3319 * No sense putting this after each symbol definition, twice,
3320 * exception granted :-)
3322 EXPORT_SYMBOL(proc_dointvec);
3323 EXPORT_SYMBOL(proc_douintvec);
3324 EXPORT_SYMBOL(proc_dointvec_jiffies);
3325 EXPORT_SYMBOL(proc_dointvec_minmax);
3326 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3327 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3328 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3329 EXPORT_SYMBOL(proc_dostring);
3330 EXPORT_SYMBOL(proc_doulongvec_minmax);
3331 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);