2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/aio.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/sched/coredump.h>
66 #include <linux/kexec.h>
67 #include <linux/bpf.h>
68 #include <linux/mount.h>
70 #include <linux/uaccess.h>
71 #include <asm/processor.h>
75 #include <asm/stacktrace.h>
79 #include <asm/setup.h>
81 #ifdef CONFIG_BSD_PROCESS_ACCT
82 #include <linux/acct.h>
84 #ifdef CONFIG_RT_MUTEXES
85 #include <linux/rtmutex.h>
87 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
88 #include <linux/lockdep.h>
90 #ifdef CONFIG_CHR_DEV_SG
93 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
94 #include <linux/stackleak.h>
96 #ifdef CONFIG_LOCKUP_DETECTOR
97 #include <linux/nmi.h>
100 #if defined(CONFIG_SYSCTL)
102 /* External variables not in a header file. */
103 extern int suid_dumpable;
104 #ifdef CONFIG_COREDUMP
105 extern int core_uses_pid;
106 extern char core_pattern[];
107 extern unsigned int core_pipe_limit;
110 extern int pid_max_min, pid_max_max;
111 extern int percpu_pagelist_fraction;
112 extern int latencytop_enabled;
113 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
115 extern int sysctl_nr_trim_pages;
118 /* Constants used for minimum and maximum */
119 #ifdef CONFIG_LOCKUP_DETECTOR
120 static int sixty = 60;
123 static int __maybe_unused neg_one = -1;
126 static int __maybe_unused one = 1;
127 static int __maybe_unused two = 2;
128 static int __maybe_unused four = 4;
129 static unsigned long one_ul = 1;
130 static int one_hundred = 100;
131 static int one_thousand = 1000;
133 static int ten_thousand = 10000;
135 #ifdef CONFIG_PERF_EVENTS
136 static int six_hundred_forty_kb = 640 * 1024;
139 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
140 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
142 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
143 static int maxolduid = 65535;
144 static int minolduid;
146 static int ngroups_max = NGROUPS_MAX;
147 static const int cap_last_cap = CAP_LAST_CAP;
150 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
151 * and hung_task_check_interval_secs
153 #ifdef CONFIG_DETECT_HUNG_TASK
154 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
157 #ifdef CONFIG_INOTIFY_USER
158 #include <linux/inotify.h>
164 extern int pwrsw_enabled;
167 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
168 extern int unaligned_enabled;
172 extern int unaligned_dump_stack;
175 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
176 extern int no_unaligned_warning;
179 #ifdef CONFIG_PROC_SYSCTL
182 * enum sysctl_writes_mode - supported sysctl write modes
184 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
185 * to be written, and multiple writes on the same sysctl file descriptor
186 * will rewrite the sysctl value, regardless of file position. No warning
187 * is issued when the initial position is not 0.
188 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
190 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
191 * file position 0 and the value must be fully contained in the buffer
192 * sent to the write syscall. If dealing with strings respect the file
193 * position, but restrict this to the max length of the buffer, anything
194 * passed the max lenght will be ignored. Multiple writes will append
197 * These write modes control how current file position affects the behavior of
198 * updating sysctl values through the proc interface on each write.
200 enum sysctl_writes_mode {
201 SYSCTL_WRITES_LEGACY = -1,
202 SYSCTL_WRITES_WARN = 0,
203 SYSCTL_WRITES_STRICT = 1,
206 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
208 static int proc_do_cad_pid(struct ctl_table *table, int write,
209 void __user *buffer, size_t *lenp, loff_t *ppos);
210 static int proc_taint(struct ctl_table *table, int write,
211 void __user *buffer, size_t *lenp, loff_t *ppos);
215 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
216 void __user *buffer, size_t *lenp, loff_t *ppos);
219 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
220 void __user *buffer, size_t *lenp, loff_t *ppos);
221 #ifdef CONFIG_COREDUMP
222 static int proc_dostring_coredump(struct ctl_table *table, int write,
223 void __user *buffer, size_t *lenp, loff_t *ppos);
225 static int proc_dopipe_max_size(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
228 #ifdef CONFIG_MAGIC_SYSRQ
229 /* Note: sysrq code uses its own private copy */
230 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
232 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
233 void __user *buffer, size_t *lenp,
238 error = proc_dointvec(table, write, buffer, lenp, ppos);
243 sysrq_toggle_support(__sysrq_enabled);
250 static struct ctl_table kern_table[];
251 static struct ctl_table vm_table[];
252 static struct ctl_table fs_table[];
253 static struct ctl_table debug_table[];
254 static struct ctl_table dev_table[];
255 extern struct ctl_table random_table[];
257 extern struct ctl_table epoll_table[];
260 #ifdef CONFIG_FW_LOADER_USER_HELPER
261 extern struct ctl_table firmware_config_table[];
264 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
265 int sysctl_legacy_va_layout;
268 /* The default sysctl tables: */
270 static struct ctl_table sysctl_base_table[] = {
272 .procname = "kernel",
289 .child = debug_table,
299 #ifdef CONFIG_SCHED_DEBUG
300 static int min_sched_granularity_ns = 100000; /* 100 usecs */
301 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
302 static int min_wakeup_granularity_ns; /* 0 usecs */
303 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
305 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
306 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
307 #endif /* CONFIG_SMP */
308 #endif /* CONFIG_SCHED_DEBUG */
310 #ifdef CONFIG_COMPACTION
311 static int min_extfrag_threshold;
312 static int max_extfrag_threshold = 1000;
315 static struct ctl_table kern_table[] = {
317 .procname = "sched_child_runs_first",
318 .data = &sysctl_sched_child_runs_first,
319 .maxlen = sizeof(unsigned int),
321 .proc_handler = proc_dointvec,
323 #ifdef CONFIG_SCHED_DEBUG
325 .procname = "sched_min_granularity_ns",
326 .data = &sysctl_sched_min_granularity,
327 .maxlen = sizeof(unsigned int),
329 .proc_handler = sched_proc_update_handler,
330 .extra1 = &min_sched_granularity_ns,
331 .extra2 = &max_sched_granularity_ns,
334 .procname = "sched_latency_ns",
335 .data = &sysctl_sched_latency,
336 .maxlen = sizeof(unsigned int),
338 .proc_handler = sched_proc_update_handler,
339 .extra1 = &min_sched_granularity_ns,
340 .extra2 = &max_sched_granularity_ns,
343 .procname = "sched_wakeup_granularity_ns",
344 .data = &sysctl_sched_wakeup_granularity,
345 .maxlen = sizeof(unsigned int),
347 .proc_handler = sched_proc_update_handler,
348 .extra1 = &min_wakeup_granularity_ns,
349 .extra2 = &max_wakeup_granularity_ns,
353 .procname = "sched_tunable_scaling",
354 .data = &sysctl_sched_tunable_scaling,
355 .maxlen = sizeof(enum sched_tunable_scaling),
357 .proc_handler = sched_proc_update_handler,
358 .extra1 = &min_sched_tunable_scaling,
359 .extra2 = &max_sched_tunable_scaling,
362 .procname = "sched_migration_cost_ns",
363 .data = &sysctl_sched_migration_cost,
364 .maxlen = sizeof(unsigned int),
366 .proc_handler = proc_dointvec,
369 .procname = "sched_nr_migrate",
370 .data = &sysctl_sched_nr_migrate,
371 .maxlen = sizeof(unsigned int),
373 .proc_handler = proc_dointvec,
375 #ifdef CONFIG_SCHEDSTATS
377 .procname = "sched_schedstats",
379 .maxlen = sizeof(unsigned int),
381 .proc_handler = sysctl_schedstats,
385 #endif /* CONFIG_SCHEDSTATS */
386 #endif /* CONFIG_SMP */
387 #ifdef CONFIG_NUMA_BALANCING
389 .procname = "numa_balancing_scan_delay_ms",
390 .data = &sysctl_numa_balancing_scan_delay,
391 .maxlen = sizeof(unsigned int),
393 .proc_handler = proc_dointvec,
396 .procname = "numa_balancing_scan_period_min_ms",
397 .data = &sysctl_numa_balancing_scan_period_min,
398 .maxlen = sizeof(unsigned int),
400 .proc_handler = proc_dointvec,
403 .procname = "numa_balancing_scan_period_max_ms",
404 .data = &sysctl_numa_balancing_scan_period_max,
405 .maxlen = sizeof(unsigned int),
407 .proc_handler = proc_dointvec,
410 .procname = "numa_balancing_scan_size_mb",
411 .data = &sysctl_numa_balancing_scan_size,
412 .maxlen = sizeof(unsigned int),
414 .proc_handler = proc_dointvec_minmax,
418 .procname = "numa_balancing",
419 .data = NULL, /* filled in by handler */
420 .maxlen = sizeof(unsigned int),
422 .proc_handler = sysctl_numa_balancing,
426 #endif /* CONFIG_NUMA_BALANCING */
427 #endif /* CONFIG_SCHED_DEBUG */
429 .procname = "sched_rt_period_us",
430 .data = &sysctl_sched_rt_period,
431 .maxlen = sizeof(unsigned int),
433 .proc_handler = sched_rt_handler,
436 .procname = "sched_rt_runtime_us",
437 .data = &sysctl_sched_rt_runtime,
438 .maxlen = sizeof(int),
440 .proc_handler = sched_rt_handler,
443 .procname = "sched_rr_timeslice_ms",
444 .data = &sysctl_sched_rr_timeslice,
445 .maxlen = sizeof(int),
447 .proc_handler = sched_rr_handler,
449 #ifdef CONFIG_SCHED_AUTOGROUP
451 .procname = "sched_autogroup_enabled",
452 .data = &sysctl_sched_autogroup_enabled,
453 .maxlen = sizeof(unsigned int),
455 .proc_handler = proc_dointvec_minmax,
460 #ifdef CONFIG_CFS_BANDWIDTH
462 .procname = "sched_cfs_bandwidth_slice_us",
463 .data = &sysctl_sched_cfs_bandwidth_slice,
464 .maxlen = sizeof(unsigned int),
466 .proc_handler = proc_dointvec_minmax,
470 #ifdef CONFIG_PROVE_LOCKING
472 .procname = "prove_locking",
473 .data = &prove_locking,
474 .maxlen = sizeof(int),
476 .proc_handler = proc_dointvec,
479 #ifdef CONFIG_LOCK_STAT
481 .procname = "lock_stat",
483 .maxlen = sizeof(int),
485 .proc_handler = proc_dointvec,
490 .data = &panic_timeout,
491 .maxlen = sizeof(int),
493 .proc_handler = proc_dointvec,
495 #ifdef CONFIG_COREDUMP
497 .procname = "core_uses_pid",
498 .data = &core_uses_pid,
499 .maxlen = sizeof(int),
501 .proc_handler = proc_dointvec,
504 .procname = "core_pattern",
505 .data = core_pattern,
506 .maxlen = CORENAME_MAX_SIZE,
508 .proc_handler = proc_dostring_coredump,
511 .procname = "core_pipe_limit",
512 .data = &core_pipe_limit,
513 .maxlen = sizeof(unsigned int),
515 .proc_handler = proc_dointvec,
518 #ifdef CONFIG_PROC_SYSCTL
520 .procname = "tainted",
521 .maxlen = sizeof(long),
523 .proc_handler = proc_taint,
526 .procname = "sysctl_writes_strict",
527 .data = &sysctl_writes_strict,
528 .maxlen = sizeof(int),
530 .proc_handler = proc_dointvec_minmax,
535 #ifdef CONFIG_LATENCYTOP
537 .procname = "latencytop",
538 .data = &latencytop_enabled,
539 .maxlen = sizeof(int),
541 .proc_handler = sysctl_latencytop,
544 #ifdef CONFIG_BLK_DEV_INITRD
546 .procname = "real-root-dev",
547 .data = &real_root_dev,
548 .maxlen = sizeof(int),
550 .proc_handler = proc_dointvec,
554 .procname = "print-fatal-signals",
555 .data = &print_fatal_signals,
556 .maxlen = sizeof(int),
558 .proc_handler = proc_dointvec,
562 .procname = "reboot-cmd",
563 .data = reboot_command,
566 .proc_handler = proc_dostring,
569 .procname = "stop-a",
570 .data = &stop_a_enabled,
571 .maxlen = sizeof (int),
573 .proc_handler = proc_dointvec,
576 .procname = "scons-poweroff",
577 .data = &scons_pwroff,
578 .maxlen = sizeof (int),
580 .proc_handler = proc_dointvec,
583 #ifdef CONFIG_SPARC64
585 .procname = "tsb-ratio",
586 .data = &sysctl_tsb_ratio,
587 .maxlen = sizeof (int),
589 .proc_handler = proc_dointvec,
594 .procname = "soft-power",
595 .data = &pwrsw_enabled,
596 .maxlen = sizeof (int),
598 .proc_handler = proc_dointvec,
601 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
603 .procname = "unaligned-trap",
604 .data = &unaligned_enabled,
605 .maxlen = sizeof (int),
607 .proc_handler = proc_dointvec,
611 .procname = "ctrl-alt-del",
613 .maxlen = sizeof(int),
615 .proc_handler = proc_dointvec,
617 #ifdef CONFIG_FUNCTION_TRACER
619 .procname = "ftrace_enabled",
620 .data = &ftrace_enabled,
621 .maxlen = sizeof(int),
623 .proc_handler = ftrace_enable_sysctl,
626 #ifdef CONFIG_STACK_TRACER
628 .procname = "stack_tracer_enabled",
629 .data = &stack_tracer_enabled,
630 .maxlen = sizeof(int),
632 .proc_handler = stack_trace_sysctl,
635 #ifdef CONFIG_TRACING
637 .procname = "ftrace_dump_on_oops",
638 .data = &ftrace_dump_on_oops,
639 .maxlen = sizeof(int),
641 .proc_handler = proc_dointvec,
644 .procname = "traceoff_on_warning",
645 .data = &__disable_trace_on_warning,
646 .maxlen = sizeof(__disable_trace_on_warning),
648 .proc_handler = proc_dointvec,
651 .procname = "tracepoint_printk",
652 .data = &tracepoint_printk,
653 .maxlen = sizeof(tracepoint_printk),
655 .proc_handler = tracepoint_printk_sysctl,
658 #ifdef CONFIG_KEXEC_CORE
660 .procname = "kexec_load_disabled",
661 .data = &kexec_load_disabled,
662 .maxlen = sizeof(int),
664 /* only handle a transition from default "0" to "1" */
665 .proc_handler = proc_dointvec_minmax,
670 #ifdef CONFIG_MODULES
672 .procname = "modprobe",
673 .data = &modprobe_path,
674 .maxlen = KMOD_PATH_LEN,
676 .proc_handler = proc_dostring,
679 .procname = "modules_disabled",
680 .data = &modules_disabled,
681 .maxlen = sizeof(int),
683 /* only handle a transition from default "0" to "1" */
684 .proc_handler = proc_dointvec_minmax,
689 #ifdef CONFIG_UEVENT_HELPER
691 .procname = "hotplug",
692 .data = &uevent_helper,
693 .maxlen = UEVENT_HELPER_PATH_LEN,
695 .proc_handler = proc_dostring,
698 #ifdef CONFIG_CHR_DEV_SG
700 .procname = "sg-big-buff",
701 .data = &sg_big_buff,
702 .maxlen = sizeof (int),
704 .proc_handler = proc_dointvec,
707 #ifdef CONFIG_BSD_PROCESS_ACCT
711 .maxlen = 3*sizeof(int),
713 .proc_handler = proc_dointvec,
716 #ifdef CONFIG_MAGIC_SYSRQ
719 .data = &__sysrq_enabled,
720 .maxlen = sizeof (int),
722 .proc_handler = sysrq_sysctl_handler,
725 #ifdef CONFIG_PROC_SYSCTL
727 .procname = "cad_pid",
729 .maxlen = sizeof (int),
731 .proc_handler = proc_do_cad_pid,
735 .procname = "threads-max",
737 .maxlen = sizeof(int),
739 .proc_handler = sysctl_max_threads,
742 .procname = "random",
744 .child = random_table,
747 .procname = "usermodehelper",
749 .child = usermodehelper_table,
751 #ifdef CONFIG_FW_LOADER_USER_HELPER
753 .procname = "firmware_config",
755 .child = firmware_config_table,
759 .procname = "overflowuid",
760 .data = &overflowuid,
761 .maxlen = sizeof(int),
763 .proc_handler = proc_dointvec_minmax,
764 .extra1 = &minolduid,
765 .extra2 = &maxolduid,
768 .procname = "overflowgid",
769 .data = &overflowgid,
770 .maxlen = sizeof(int),
772 .proc_handler = proc_dointvec_minmax,
773 .extra1 = &minolduid,
774 .extra2 = &maxolduid,
777 #ifdef CONFIG_MATHEMU
779 .procname = "ieee_emulation_warnings",
780 .data = &sysctl_ieee_emulation_warnings,
781 .maxlen = sizeof(int),
783 .proc_handler = proc_dointvec,
787 .procname = "userprocess_debug",
788 .data = &show_unhandled_signals,
789 .maxlen = sizeof(int),
791 .proc_handler = proc_dointvec,
795 .procname = "pid_max",
797 .maxlen = sizeof (int),
799 .proc_handler = proc_dointvec_minmax,
800 .extra1 = &pid_max_min,
801 .extra2 = &pid_max_max,
804 .procname = "panic_on_oops",
805 .data = &panic_on_oops,
806 .maxlen = sizeof(int),
808 .proc_handler = proc_dointvec,
811 .procname = "panic_print",
812 .data = &panic_print,
813 .maxlen = sizeof(unsigned long),
815 .proc_handler = proc_doulongvec_minmax,
817 #if defined CONFIG_PRINTK
819 .procname = "printk",
820 .data = &console_loglevel,
821 .maxlen = 4*sizeof(int),
823 .proc_handler = proc_dointvec,
826 .procname = "printk_ratelimit",
827 .data = &printk_ratelimit_state.interval,
828 .maxlen = sizeof(int),
830 .proc_handler = proc_dointvec_jiffies,
833 .procname = "printk_ratelimit_burst",
834 .data = &printk_ratelimit_state.burst,
835 .maxlen = sizeof(int),
837 .proc_handler = proc_dointvec,
840 .procname = "printk_delay",
841 .data = &printk_delay_msec,
842 .maxlen = sizeof(int),
844 .proc_handler = proc_dointvec_minmax,
846 .extra2 = &ten_thousand,
849 .procname = "printk_devkmsg",
850 .data = devkmsg_log_str,
851 .maxlen = DEVKMSG_STR_MAX_SIZE,
853 .proc_handler = devkmsg_sysctl_set_loglvl,
856 .procname = "dmesg_restrict",
857 .data = &dmesg_restrict,
858 .maxlen = sizeof(int),
860 .proc_handler = proc_dointvec_minmax_sysadmin,
865 .procname = "kptr_restrict",
866 .data = &kptr_restrict,
867 .maxlen = sizeof(int),
869 .proc_handler = proc_dointvec_minmax_sysadmin,
875 .procname = "ngroups_max",
876 .data = &ngroups_max,
877 .maxlen = sizeof (int),
879 .proc_handler = proc_dointvec,
882 .procname = "cap_last_cap",
883 .data = (void *)&cap_last_cap,
884 .maxlen = sizeof(int),
886 .proc_handler = proc_dointvec,
888 #if defined(CONFIG_LOCKUP_DETECTOR)
890 .procname = "watchdog",
891 .data = &watchdog_user_enabled,
892 .maxlen = sizeof(int),
894 .proc_handler = proc_watchdog,
899 .procname = "watchdog_thresh",
900 .data = &watchdog_thresh,
901 .maxlen = sizeof(int),
903 .proc_handler = proc_watchdog_thresh,
908 .procname = "nmi_watchdog",
909 .data = &nmi_watchdog_user_enabled,
910 .maxlen = sizeof(int),
911 .mode = NMI_WATCHDOG_SYSCTL_PERM,
912 .proc_handler = proc_nmi_watchdog,
917 .procname = "watchdog_cpumask",
918 .data = &watchdog_cpumask_bits,
921 .proc_handler = proc_watchdog_cpumask,
923 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
925 .procname = "soft_watchdog",
926 .data = &soft_watchdog_user_enabled,
927 .maxlen = sizeof(int),
929 .proc_handler = proc_soft_watchdog,
934 .procname = "softlockup_panic",
935 .data = &softlockup_panic,
936 .maxlen = sizeof(int),
938 .proc_handler = proc_dointvec_minmax,
944 .procname = "softlockup_all_cpu_backtrace",
945 .data = &sysctl_softlockup_all_cpu_backtrace,
946 .maxlen = sizeof(int),
948 .proc_handler = proc_dointvec_minmax,
952 #endif /* CONFIG_SMP */
954 #ifdef CONFIG_HARDLOCKUP_DETECTOR
956 .procname = "hardlockup_panic",
957 .data = &hardlockup_panic,
958 .maxlen = sizeof(int),
960 .proc_handler = proc_dointvec_minmax,
966 .procname = "hardlockup_all_cpu_backtrace",
967 .data = &sysctl_hardlockup_all_cpu_backtrace,
968 .maxlen = sizeof(int),
970 .proc_handler = proc_dointvec_minmax,
974 #endif /* CONFIG_SMP */
978 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
980 .procname = "unknown_nmi_panic",
981 .data = &unknown_nmi_panic,
982 .maxlen = sizeof (int),
984 .proc_handler = proc_dointvec,
987 #if defined(CONFIG_X86)
989 .procname = "panic_on_unrecovered_nmi",
990 .data = &panic_on_unrecovered_nmi,
991 .maxlen = sizeof(int),
993 .proc_handler = proc_dointvec,
996 .procname = "panic_on_io_nmi",
997 .data = &panic_on_io_nmi,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec,
1002 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1004 .procname = "panic_on_stackoverflow",
1005 .data = &sysctl_panic_on_stackoverflow,
1006 .maxlen = sizeof(int),
1008 .proc_handler = proc_dointvec,
1012 .procname = "bootloader_type",
1013 .data = &bootloader_type,
1014 .maxlen = sizeof (int),
1016 .proc_handler = proc_dointvec,
1019 .procname = "bootloader_version",
1020 .data = &bootloader_version,
1021 .maxlen = sizeof (int),
1023 .proc_handler = proc_dointvec,
1026 .procname = "io_delay_type",
1027 .data = &io_delay_type,
1028 .maxlen = sizeof(int),
1030 .proc_handler = proc_dointvec,
1033 #if defined(CONFIG_MMU)
1035 .procname = "randomize_va_space",
1036 .data = &randomize_va_space,
1037 .maxlen = sizeof(int),
1039 .proc_handler = proc_dointvec,
1042 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1044 .procname = "spin_retry",
1045 .data = &spin_retry,
1046 .maxlen = sizeof (int),
1048 .proc_handler = proc_dointvec,
1051 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1053 .procname = "acpi_video_flags",
1054 .data = &acpi_realmode_flags,
1055 .maxlen = sizeof (unsigned long),
1057 .proc_handler = proc_doulongvec_minmax,
1060 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1062 .procname = "ignore-unaligned-usertrap",
1063 .data = &no_unaligned_warning,
1064 .maxlen = sizeof (int),
1066 .proc_handler = proc_dointvec,
1071 .procname = "unaligned-dump-stack",
1072 .data = &unaligned_dump_stack,
1073 .maxlen = sizeof (int),
1075 .proc_handler = proc_dointvec,
1078 #ifdef CONFIG_DETECT_HUNG_TASK
1080 .procname = "hung_task_panic",
1081 .data = &sysctl_hung_task_panic,
1082 .maxlen = sizeof(int),
1084 .proc_handler = proc_dointvec_minmax,
1089 .procname = "hung_task_check_count",
1090 .data = &sysctl_hung_task_check_count,
1091 .maxlen = sizeof(int),
1093 .proc_handler = proc_dointvec_minmax,
1097 .procname = "hung_task_timeout_secs",
1098 .data = &sysctl_hung_task_timeout_secs,
1099 .maxlen = sizeof(unsigned long),
1101 .proc_handler = proc_dohung_task_timeout_secs,
1102 .extra2 = &hung_task_timeout_max,
1105 .procname = "hung_task_check_interval_secs",
1106 .data = &sysctl_hung_task_check_interval_secs,
1107 .maxlen = sizeof(unsigned long),
1109 .proc_handler = proc_dohung_task_timeout_secs,
1110 .extra2 = &hung_task_timeout_max,
1113 .procname = "hung_task_warnings",
1114 .data = &sysctl_hung_task_warnings,
1115 .maxlen = sizeof(int),
1117 .proc_handler = proc_dointvec_minmax,
1121 #ifdef CONFIG_RT_MUTEXES
1123 .procname = "max_lock_depth",
1124 .data = &max_lock_depth,
1125 .maxlen = sizeof(int),
1127 .proc_handler = proc_dointvec,
1131 .procname = "poweroff_cmd",
1132 .data = &poweroff_cmd,
1133 .maxlen = POWEROFF_CMD_PATH_LEN,
1135 .proc_handler = proc_dostring,
1141 .child = key_sysctls,
1144 #ifdef CONFIG_PERF_EVENTS
1146 * User-space scripts rely on the existence of this file
1147 * as a feature check for perf_events being enabled.
1149 * So it's an ABI, do not remove!
1152 .procname = "perf_event_paranoid",
1153 .data = &sysctl_perf_event_paranoid,
1154 .maxlen = sizeof(sysctl_perf_event_paranoid),
1156 .proc_handler = proc_dointvec,
1159 .procname = "perf_event_mlock_kb",
1160 .data = &sysctl_perf_event_mlock,
1161 .maxlen = sizeof(sysctl_perf_event_mlock),
1163 .proc_handler = proc_dointvec,
1166 .procname = "perf_event_max_sample_rate",
1167 .data = &sysctl_perf_event_sample_rate,
1168 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1170 .proc_handler = perf_proc_update_handler,
1174 .procname = "perf_cpu_time_max_percent",
1175 .data = &sysctl_perf_cpu_time_max_percent,
1176 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1178 .proc_handler = perf_cpu_time_max_percent_handler,
1180 .extra2 = &one_hundred,
1183 .procname = "perf_event_max_stack",
1184 .data = &sysctl_perf_event_max_stack,
1185 .maxlen = sizeof(sysctl_perf_event_max_stack),
1187 .proc_handler = perf_event_max_stack_handler,
1189 .extra2 = &six_hundred_forty_kb,
1192 .procname = "perf_event_max_contexts_per_stack",
1193 .data = &sysctl_perf_event_max_contexts_per_stack,
1194 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1196 .proc_handler = perf_event_max_stack_handler,
1198 .extra2 = &one_thousand,
1202 .procname = "panic_on_warn",
1203 .data = &panic_on_warn,
1204 .maxlen = sizeof(int),
1206 .proc_handler = proc_dointvec_minmax,
1210 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1212 .procname = "timer_migration",
1213 .data = &sysctl_timer_migration,
1214 .maxlen = sizeof(unsigned int),
1216 .proc_handler = timer_migration_handler,
1221 #ifdef CONFIG_BPF_SYSCALL
1223 .procname = "unprivileged_bpf_disabled",
1224 .data = &sysctl_unprivileged_bpf_disabled,
1225 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1227 /* only handle a transition from default "0" to "1" */
1228 .proc_handler = proc_dointvec_minmax,
1233 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1235 .procname = "panic_on_rcu_stall",
1236 .data = &sysctl_panic_on_rcu_stall,
1237 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1239 .proc_handler = proc_dointvec_minmax,
1244 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1246 .procname = "stack_erasing",
1248 .maxlen = sizeof(int),
1250 .proc_handler = stack_erasing_sysctl,
1258 static struct ctl_table vm_table[] = {
1260 .procname = "overcommit_memory",
1261 .data = &sysctl_overcommit_memory,
1262 .maxlen = sizeof(sysctl_overcommit_memory),
1264 .proc_handler = proc_dointvec_minmax,
1269 .procname = "panic_on_oom",
1270 .data = &sysctl_panic_on_oom,
1271 .maxlen = sizeof(sysctl_panic_on_oom),
1273 .proc_handler = proc_dointvec_minmax,
1278 .procname = "oom_kill_allocating_task",
1279 .data = &sysctl_oom_kill_allocating_task,
1280 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1282 .proc_handler = proc_dointvec,
1285 .procname = "oom_dump_tasks",
1286 .data = &sysctl_oom_dump_tasks,
1287 .maxlen = sizeof(sysctl_oom_dump_tasks),
1289 .proc_handler = proc_dointvec,
1292 .procname = "overcommit_ratio",
1293 .data = &sysctl_overcommit_ratio,
1294 .maxlen = sizeof(sysctl_overcommit_ratio),
1296 .proc_handler = overcommit_ratio_handler,
1299 .procname = "overcommit_kbytes",
1300 .data = &sysctl_overcommit_kbytes,
1301 .maxlen = sizeof(sysctl_overcommit_kbytes),
1303 .proc_handler = overcommit_kbytes_handler,
1306 .procname = "page-cluster",
1307 .data = &page_cluster,
1308 .maxlen = sizeof(int),
1310 .proc_handler = proc_dointvec_minmax,
1314 .procname = "dirty_background_ratio",
1315 .data = &dirty_background_ratio,
1316 .maxlen = sizeof(dirty_background_ratio),
1318 .proc_handler = dirty_background_ratio_handler,
1320 .extra2 = &one_hundred,
1323 .procname = "dirty_background_bytes",
1324 .data = &dirty_background_bytes,
1325 .maxlen = sizeof(dirty_background_bytes),
1327 .proc_handler = dirty_background_bytes_handler,
1331 .procname = "dirty_ratio",
1332 .data = &vm_dirty_ratio,
1333 .maxlen = sizeof(vm_dirty_ratio),
1335 .proc_handler = dirty_ratio_handler,
1337 .extra2 = &one_hundred,
1340 .procname = "dirty_bytes",
1341 .data = &vm_dirty_bytes,
1342 .maxlen = sizeof(vm_dirty_bytes),
1344 .proc_handler = dirty_bytes_handler,
1345 .extra1 = &dirty_bytes_min,
1348 .procname = "dirty_writeback_centisecs",
1349 .data = &dirty_writeback_interval,
1350 .maxlen = sizeof(dirty_writeback_interval),
1352 .proc_handler = dirty_writeback_centisecs_handler,
1355 .procname = "dirty_expire_centisecs",
1356 .data = &dirty_expire_interval,
1357 .maxlen = sizeof(dirty_expire_interval),
1359 .proc_handler = proc_dointvec_minmax,
1363 .procname = "dirtytime_expire_seconds",
1364 .data = &dirtytime_expire_interval,
1365 .maxlen = sizeof(dirtytime_expire_interval),
1367 .proc_handler = dirtytime_interval_handler,
1371 .procname = "swappiness",
1372 .data = &vm_swappiness,
1373 .maxlen = sizeof(vm_swappiness),
1375 .proc_handler = proc_dointvec_minmax,
1377 .extra2 = &one_hundred,
1379 #ifdef CONFIG_HUGETLB_PAGE
1381 .procname = "nr_hugepages",
1383 .maxlen = sizeof(unsigned long),
1385 .proc_handler = hugetlb_sysctl_handler,
1389 .procname = "nr_hugepages_mempolicy",
1391 .maxlen = sizeof(unsigned long),
1393 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1396 .procname = "numa_stat",
1397 .data = &sysctl_vm_numa_stat,
1398 .maxlen = sizeof(int),
1400 .proc_handler = sysctl_vm_numa_stat_handler,
1406 .procname = "hugetlb_shm_group",
1407 .data = &sysctl_hugetlb_shm_group,
1408 .maxlen = sizeof(gid_t),
1410 .proc_handler = proc_dointvec,
1413 .procname = "nr_overcommit_hugepages",
1415 .maxlen = sizeof(unsigned long),
1417 .proc_handler = hugetlb_overcommit_handler,
1421 .procname = "lowmem_reserve_ratio",
1422 .data = &sysctl_lowmem_reserve_ratio,
1423 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1425 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1428 .procname = "drop_caches",
1429 .data = &sysctl_drop_caches,
1430 .maxlen = sizeof(int),
1432 .proc_handler = drop_caches_sysctl_handler,
1436 #ifdef CONFIG_COMPACTION
1438 .procname = "compact_memory",
1439 .data = &sysctl_compact_memory,
1440 .maxlen = sizeof(int),
1442 .proc_handler = sysctl_compaction_handler,
1445 .procname = "extfrag_threshold",
1446 .data = &sysctl_extfrag_threshold,
1447 .maxlen = sizeof(int),
1449 .proc_handler = sysctl_extfrag_handler,
1450 .extra1 = &min_extfrag_threshold,
1451 .extra2 = &max_extfrag_threshold,
1454 .procname = "compact_unevictable_allowed",
1455 .data = &sysctl_compact_unevictable_allowed,
1456 .maxlen = sizeof(int),
1458 .proc_handler = proc_dointvec,
1463 #endif /* CONFIG_COMPACTION */
1465 .procname = "min_free_kbytes",
1466 .data = &min_free_kbytes,
1467 .maxlen = sizeof(min_free_kbytes),
1469 .proc_handler = min_free_kbytes_sysctl_handler,
1473 .procname = "watermark_boost_factor",
1474 .data = &watermark_boost_factor,
1475 .maxlen = sizeof(watermark_boost_factor),
1477 .proc_handler = watermark_boost_factor_sysctl_handler,
1481 .procname = "watermark_scale_factor",
1482 .data = &watermark_scale_factor,
1483 .maxlen = sizeof(watermark_scale_factor),
1485 .proc_handler = watermark_scale_factor_sysctl_handler,
1487 .extra2 = &one_thousand,
1490 .procname = "percpu_pagelist_fraction",
1491 .data = &percpu_pagelist_fraction,
1492 .maxlen = sizeof(percpu_pagelist_fraction),
1494 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1499 .procname = "max_map_count",
1500 .data = &sysctl_max_map_count,
1501 .maxlen = sizeof(sysctl_max_map_count),
1503 .proc_handler = proc_dointvec_minmax,
1508 .procname = "nr_trim_pages",
1509 .data = &sysctl_nr_trim_pages,
1510 .maxlen = sizeof(sysctl_nr_trim_pages),
1512 .proc_handler = proc_dointvec_minmax,
1517 .procname = "laptop_mode",
1518 .data = &laptop_mode,
1519 .maxlen = sizeof(laptop_mode),
1521 .proc_handler = proc_dointvec_jiffies,
1524 .procname = "block_dump",
1525 .data = &block_dump,
1526 .maxlen = sizeof(block_dump),
1528 .proc_handler = proc_dointvec,
1532 .procname = "vfs_cache_pressure",
1533 .data = &sysctl_vfs_cache_pressure,
1534 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1536 .proc_handler = proc_dointvec,
1539 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1541 .procname = "legacy_va_layout",
1542 .data = &sysctl_legacy_va_layout,
1543 .maxlen = sizeof(sysctl_legacy_va_layout),
1545 .proc_handler = proc_dointvec,
1551 .procname = "zone_reclaim_mode",
1552 .data = &node_reclaim_mode,
1553 .maxlen = sizeof(node_reclaim_mode),
1555 .proc_handler = proc_dointvec,
1559 .procname = "min_unmapped_ratio",
1560 .data = &sysctl_min_unmapped_ratio,
1561 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1563 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1565 .extra2 = &one_hundred,
1568 .procname = "min_slab_ratio",
1569 .data = &sysctl_min_slab_ratio,
1570 .maxlen = sizeof(sysctl_min_slab_ratio),
1572 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1574 .extra2 = &one_hundred,
1579 .procname = "stat_interval",
1580 .data = &sysctl_stat_interval,
1581 .maxlen = sizeof(sysctl_stat_interval),
1583 .proc_handler = proc_dointvec_jiffies,
1586 .procname = "stat_refresh",
1590 .proc_handler = vmstat_refresh,
1595 .procname = "mmap_min_addr",
1596 .data = &dac_mmap_min_addr,
1597 .maxlen = sizeof(unsigned long),
1599 .proc_handler = mmap_min_addr_handler,
1604 .procname = "numa_zonelist_order",
1605 .data = &numa_zonelist_order,
1606 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1608 .proc_handler = numa_zonelist_order_handler,
1611 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1612 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1614 .procname = "vdso_enabled",
1615 #ifdef CONFIG_X86_32
1616 .data = &vdso32_enabled,
1617 .maxlen = sizeof(vdso32_enabled),
1619 .data = &vdso_enabled,
1620 .maxlen = sizeof(vdso_enabled),
1623 .proc_handler = proc_dointvec,
1627 #ifdef CONFIG_HIGHMEM
1629 .procname = "highmem_is_dirtyable",
1630 .data = &vm_highmem_is_dirtyable,
1631 .maxlen = sizeof(vm_highmem_is_dirtyable),
1633 .proc_handler = proc_dointvec_minmax,
1638 #ifdef CONFIG_MEMORY_FAILURE
1640 .procname = "memory_failure_early_kill",
1641 .data = &sysctl_memory_failure_early_kill,
1642 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1644 .proc_handler = proc_dointvec_minmax,
1649 .procname = "memory_failure_recovery",
1650 .data = &sysctl_memory_failure_recovery,
1651 .maxlen = sizeof(sysctl_memory_failure_recovery),
1653 .proc_handler = proc_dointvec_minmax,
1659 .procname = "user_reserve_kbytes",
1660 .data = &sysctl_user_reserve_kbytes,
1661 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1663 .proc_handler = proc_doulongvec_minmax,
1666 .procname = "admin_reserve_kbytes",
1667 .data = &sysctl_admin_reserve_kbytes,
1668 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1670 .proc_handler = proc_doulongvec_minmax,
1672 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1674 .procname = "mmap_rnd_bits",
1675 .data = &mmap_rnd_bits,
1676 .maxlen = sizeof(mmap_rnd_bits),
1678 .proc_handler = proc_dointvec_minmax,
1679 .extra1 = (void *)&mmap_rnd_bits_min,
1680 .extra2 = (void *)&mmap_rnd_bits_max,
1683 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1685 .procname = "mmap_rnd_compat_bits",
1686 .data = &mmap_rnd_compat_bits,
1687 .maxlen = sizeof(mmap_rnd_compat_bits),
1689 .proc_handler = proc_dointvec_minmax,
1690 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1691 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1697 static struct ctl_table fs_table[] = {
1699 .procname = "inode-nr",
1700 .data = &inodes_stat,
1701 .maxlen = 2*sizeof(long),
1703 .proc_handler = proc_nr_inodes,
1706 .procname = "inode-state",
1707 .data = &inodes_stat,
1708 .maxlen = 7*sizeof(long),
1710 .proc_handler = proc_nr_inodes,
1713 .procname = "file-nr",
1714 .data = &files_stat,
1715 .maxlen = sizeof(files_stat),
1717 .proc_handler = proc_nr_files,
1720 .procname = "file-max",
1721 .data = &files_stat.max_files,
1722 .maxlen = sizeof(files_stat.max_files),
1724 .proc_handler = proc_doulongvec_minmax,
1727 .procname = "nr_open",
1728 .data = &sysctl_nr_open,
1729 .maxlen = sizeof(unsigned int),
1731 .proc_handler = proc_dointvec_minmax,
1732 .extra1 = &sysctl_nr_open_min,
1733 .extra2 = &sysctl_nr_open_max,
1736 .procname = "dentry-state",
1737 .data = &dentry_stat,
1738 .maxlen = 6*sizeof(long),
1740 .proc_handler = proc_nr_dentry,
1743 .procname = "overflowuid",
1744 .data = &fs_overflowuid,
1745 .maxlen = sizeof(int),
1747 .proc_handler = proc_dointvec_minmax,
1748 .extra1 = &minolduid,
1749 .extra2 = &maxolduid,
1752 .procname = "overflowgid",
1753 .data = &fs_overflowgid,
1754 .maxlen = sizeof(int),
1756 .proc_handler = proc_dointvec_minmax,
1757 .extra1 = &minolduid,
1758 .extra2 = &maxolduid,
1760 #ifdef CONFIG_FILE_LOCKING
1762 .procname = "leases-enable",
1763 .data = &leases_enable,
1764 .maxlen = sizeof(int),
1766 .proc_handler = proc_dointvec,
1769 #ifdef CONFIG_DNOTIFY
1771 .procname = "dir-notify-enable",
1772 .data = &dir_notify_enable,
1773 .maxlen = sizeof(int),
1775 .proc_handler = proc_dointvec,
1779 #ifdef CONFIG_FILE_LOCKING
1781 .procname = "lease-break-time",
1782 .data = &lease_break_time,
1783 .maxlen = sizeof(int),
1785 .proc_handler = proc_dointvec,
1790 .procname = "aio-nr",
1792 .maxlen = sizeof(aio_nr),
1794 .proc_handler = proc_doulongvec_minmax,
1797 .procname = "aio-max-nr",
1798 .data = &aio_max_nr,
1799 .maxlen = sizeof(aio_max_nr),
1801 .proc_handler = proc_doulongvec_minmax,
1803 #endif /* CONFIG_AIO */
1804 #ifdef CONFIG_INOTIFY_USER
1806 .procname = "inotify",
1808 .child = inotify_table,
1813 .procname = "epoll",
1815 .child = epoll_table,
1820 .procname = "protected_symlinks",
1821 .data = &sysctl_protected_symlinks,
1822 .maxlen = sizeof(int),
1824 .proc_handler = proc_dointvec_minmax,
1829 .procname = "protected_hardlinks",
1830 .data = &sysctl_protected_hardlinks,
1831 .maxlen = sizeof(int),
1833 .proc_handler = proc_dointvec_minmax,
1838 .procname = "protected_fifos",
1839 .data = &sysctl_protected_fifos,
1840 .maxlen = sizeof(int),
1842 .proc_handler = proc_dointvec_minmax,
1847 .procname = "protected_regular",
1848 .data = &sysctl_protected_regular,
1849 .maxlen = sizeof(int),
1851 .proc_handler = proc_dointvec_minmax,
1856 .procname = "suid_dumpable",
1857 .data = &suid_dumpable,
1858 .maxlen = sizeof(int),
1860 .proc_handler = proc_dointvec_minmax_coredump,
1864 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1866 .procname = "binfmt_misc",
1868 .child = sysctl_mount_point,
1872 .procname = "pipe-max-size",
1873 .data = &pipe_max_size,
1874 .maxlen = sizeof(pipe_max_size),
1876 .proc_handler = proc_dopipe_max_size,
1879 .procname = "pipe-user-pages-hard",
1880 .data = &pipe_user_pages_hard,
1881 .maxlen = sizeof(pipe_user_pages_hard),
1883 .proc_handler = proc_doulongvec_minmax,
1886 .procname = "pipe-user-pages-soft",
1887 .data = &pipe_user_pages_soft,
1888 .maxlen = sizeof(pipe_user_pages_soft),
1890 .proc_handler = proc_doulongvec_minmax,
1893 .procname = "mount-max",
1894 .data = &sysctl_mount_max,
1895 .maxlen = sizeof(unsigned int),
1897 .proc_handler = proc_dointvec_minmax,
1903 static struct ctl_table debug_table[] = {
1904 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1906 .procname = "exception-trace",
1907 .data = &show_unhandled_signals,
1908 .maxlen = sizeof(int),
1910 .proc_handler = proc_dointvec
1913 #if defined(CONFIG_OPTPROBES)
1915 .procname = "kprobes-optimization",
1916 .data = &sysctl_kprobes_optimization,
1917 .maxlen = sizeof(int),
1919 .proc_handler = proc_kprobes_optimization_handler,
1927 static struct ctl_table dev_table[] = {
1931 int __init sysctl_init(void)
1933 struct ctl_table_header *hdr;
1935 hdr = register_sysctl_table(sysctl_base_table);
1936 kmemleak_not_leak(hdr);
1940 #endif /* CONFIG_SYSCTL */
1946 #ifdef CONFIG_PROC_SYSCTL
1948 static int _proc_do_string(char *data, int maxlen, int write,
1949 char __user *buffer,
1950 size_t *lenp, loff_t *ppos)
1956 if (!data || !maxlen || !*lenp) {
1962 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1963 /* Only continue writes not past the end of buffer. */
1965 if (len > maxlen - 1)
1972 /* Start writing from beginning of buffer. */
1978 while ((p - buffer) < *lenp && len < maxlen - 1) {
1979 if (get_user(c, p++))
1981 if (c == 0 || c == '\n')
2002 if (copy_to_user(buffer, data, len))
2005 if (put_user('\n', buffer + len))
2015 static void warn_sysctl_write(struct ctl_table *table)
2017 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2018 "This will not be supported in the future. To silence this\n"
2019 "warning, set kernel.sysctl_writes_strict = -1\n",
2020 current->comm, table->procname);
2024 * proc_first_pos_non_zero_ignore - check if first position is allowed
2025 * @ppos: file position
2026 * @table: the sysctl table
2028 * Returns true if the first position is non-zero and the sysctl_writes_strict
2029 * mode indicates this is not allowed for numeric input types. String proc
2030 * handlers can ignore the return value.
2032 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2033 struct ctl_table *table)
2038 switch (sysctl_writes_strict) {
2039 case SYSCTL_WRITES_STRICT:
2041 case SYSCTL_WRITES_WARN:
2042 warn_sysctl_write(table);
2050 * proc_dostring - read a string sysctl
2051 * @table: the sysctl table
2052 * @write: %TRUE if this is a write to the sysctl file
2053 * @buffer: the user buffer
2054 * @lenp: the size of the user buffer
2055 * @ppos: file position
2057 * Reads/writes a string from/to the user buffer. If the kernel
2058 * buffer provided is not large enough to hold the string, the
2059 * string is truncated. The copied string is %NULL-terminated.
2060 * If the string is being read by the user process, it is copied
2061 * and a newline '\n' is added. It is truncated if the buffer is
2064 * Returns 0 on success.
2066 int proc_dostring(struct ctl_table *table, int write,
2067 void __user *buffer, size_t *lenp, loff_t *ppos)
2070 proc_first_pos_non_zero_ignore(ppos, table);
2072 return _proc_do_string((char *)(table->data), table->maxlen, write,
2073 (char __user *)buffer, lenp, ppos);
2076 static size_t proc_skip_spaces(char **buf)
2079 char *tmp = skip_spaces(*buf);
2085 static void proc_skip_char(char **buf, size_t *size, const char v)
2095 #define TMPBUFLEN 22
2097 * proc_get_long - reads an ASCII formatted integer from a user buffer
2099 * @buf: a kernel buffer
2100 * @size: size of the kernel buffer
2101 * @val: this is where the number will be stored
2102 * @neg: set to %TRUE if number is negative
2103 * @perm_tr: a vector which contains the allowed trailers
2104 * @perm_tr_len: size of the perm_tr vector
2105 * @tr: pointer to store the trailer character
2107 * In case of success %0 is returned and @buf and @size are updated with
2108 * the amount of bytes read. If @tr is non-NULL and a trailing
2109 * character exists (size is non-zero after returning from this
2110 * function), @tr is updated with the trailing character.
2112 static int proc_get_long(char **buf, size_t *size,
2113 unsigned long *val, bool *neg,
2114 const char *perm_tr, unsigned perm_tr_len, char *tr)
2117 char *p, tmp[TMPBUFLEN];
2123 if (len > TMPBUFLEN - 1)
2124 len = TMPBUFLEN - 1;
2126 memcpy(tmp, *buf, len);
2130 if (*p == '-' && *size > 1) {
2138 *val = simple_strtoul(p, &p, 0);
2142 /* We don't know if the next char is whitespace thus we may accept
2143 * invalid integers (e.g. 1234...a) or two integers instead of one
2144 * (e.g. 123...1). So lets not allow such large numbers. */
2145 if (len == TMPBUFLEN - 1)
2148 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2151 if (tr && (len < *size))
2161 * proc_put_long - converts an integer to a decimal ASCII formatted string
2163 * @buf: the user buffer
2164 * @size: the size of the user buffer
2165 * @val: the integer to be converted
2166 * @neg: sign of the number, %TRUE for negative
2168 * In case of success %0 is returned and @buf and @size are updated with
2169 * the amount of bytes written.
2171 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2175 char tmp[TMPBUFLEN], *p = tmp;
2177 sprintf(p, "%s%lu", neg ? "-" : "", val);
2181 if (copy_to_user(*buf, tmp, len))
2189 static int proc_put_char(void __user **buf, size_t *size, char c)
2192 char __user **buffer = (char __user **)buf;
2193 if (put_user(c, *buffer))
2195 (*size)--, (*buffer)++;
2201 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2203 int write, void *data)
2207 if (*lvalp > (unsigned long) INT_MAX + 1)
2211 if (*lvalp > (unsigned long) INT_MAX)
2219 *lvalp = -(unsigned long)val;
2222 *lvalp = (unsigned long)val;
2228 static int do_proc_douintvec_conv(unsigned long *lvalp,
2230 int write, void *data)
2233 if (*lvalp > UINT_MAX)
2237 unsigned int val = *valp;
2238 *lvalp = (unsigned long)val;
2243 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2245 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2246 int write, void __user *buffer,
2247 size_t *lenp, loff_t *ppos,
2248 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2249 int write, void *data),
2252 int *i, vleft, first = 1, err = 0;
2254 char *kbuf = NULL, *p;
2256 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2261 i = (int *) tbl_data;
2262 vleft = table->maxlen / sizeof(*i);
2266 conv = do_proc_dointvec_conv;
2269 if (proc_first_pos_non_zero_ignore(ppos, table))
2272 if (left > PAGE_SIZE - 1)
2273 left = PAGE_SIZE - 1;
2274 p = kbuf = memdup_user_nul(buffer, left);
2276 return PTR_ERR(kbuf);
2279 for (; left && vleft--; i++, first=0) {
2284 left -= proc_skip_spaces(&p);
2288 err = proc_get_long(&p, &left, &lval, &neg,
2290 sizeof(proc_wspace_sep), NULL);
2293 if (conv(&neg, &lval, i, 1, data)) {
2298 if (conv(&neg, &lval, i, 0, data)) {
2303 err = proc_put_char(&buffer, &left, '\t');
2306 err = proc_put_long(&buffer, &left, lval, neg);
2312 if (!write && !first && left && !err)
2313 err = proc_put_char(&buffer, &left, '\n');
2314 if (write && !err && left)
2315 left -= proc_skip_spaces(&p);
2319 return err ? : -EINVAL;
2327 static int do_proc_dointvec(struct ctl_table *table, int write,
2328 void __user *buffer, size_t *lenp, loff_t *ppos,
2329 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2330 int write, void *data),
2333 return __do_proc_dointvec(table->data, table, write,
2334 buffer, lenp, ppos, conv, data);
2337 static int do_proc_douintvec_w(unsigned int *tbl_data,
2338 struct ctl_table *table,
2339 void __user *buffer,
2340 size_t *lenp, loff_t *ppos,
2341 int (*conv)(unsigned long *lvalp,
2343 int write, void *data),
2350 char *kbuf = NULL, *p;
2354 if (proc_first_pos_non_zero_ignore(ppos, table))
2357 if (left > PAGE_SIZE - 1)
2358 left = PAGE_SIZE - 1;
2360 p = kbuf = memdup_user_nul(buffer, left);
2364 left -= proc_skip_spaces(&p);
2370 err = proc_get_long(&p, &left, &lval, &neg,
2372 sizeof(proc_wspace_sep), NULL);
2378 if (conv(&lval, tbl_data, 1, data)) {
2384 left -= proc_skip_spaces(&p);
2393 /* This is in keeping with old __do_proc_dointvec() */
2399 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2400 size_t *lenp, loff_t *ppos,
2401 int (*conv)(unsigned long *lvalp,
2403 int write, void *data),
2412 if (conv(&lval, tbl_data, 0, data)) {
2417 err = proc_put_long(&buffer, &left, lval, false);
2421 err = proc_put_char(&buffer, &left, '\n');
2430 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2431 int write, void __user *buffer,
2432 size_t *lenp, loff_t *ppos,
2433 int (*conv)(unsigned long *lvalp,
2435 int write, void *data),
2438 unsigned int *i, vleft;
2440 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2445 i = (unsigned int *) tbl_data;
2446 vleft = table->maxlen / sizeof(*i);
2449 * Arrays are not supported, keep this simple. *Do not* add
2458 conv = do_proc_douintvec_conv;
2461 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2463 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2466 static int do_proc_douintvec(struct ctl_table *table, int write,
2467 void __user *buffer, size_t *lenp, loff_t *ppos,
2468 int (*conv)(unsigned long *lvalp,
2470 int write, void *data),
2473 return __do_proc_douintvec(table->data, table, write,
2474 buffer, lenp, ppos, conv, data);
2478 * proc_dointvec - read a vector of integers
2479 * @table: the sysctl table
2480 * @write: %TRUE if this is a write to the sysctl file
2481 * @buffer: the user buffer
2482 * @lenp: the size of the user buffer
2483 * @ppos: file position
2485 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2486 * values from/to the user buffer, treated as an ASCII string.
2488 * Returns 0 on success.
2490 int proc_dointvec(struct ctl_table *table, int write,
2491 void __user *buffer, size_t *lenp, loff_t *ppos)
2493 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2497 * proc_douintvec - read a vector of unsigned integers
2498 * @table: the sysctl table
2499 * @write: %TRUE if this is a write to the sysctl file
2500 * @buffer: the user buffer
2501 * @lenp: the size of the user buffer
2502 * @ppos: file position
2504 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2505 * values from/to the user buffer, treated as an ASCII string.
2507 * Returns 0 on success.
2509 int proc_douintvec(struct ctl_table *table, int write,
2510 void __user *buffer, size_t *lenp, loff_t *ppos)
2512 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2513 do_proc_douintvec_conv, NULL);
2517 * Taint values can only be increased
2518 * This means we can safely use a temporary.
2520 static int proc_taint(struct ctl_table *table, int write,
2521 void __user *buffer, size_t *lenp, loff_t *ppos)
2524 unsigned long tmptaint = get_taint();
2527 if (write && !capable(CAP_SYS_ADMIN))
2532 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2538 * Poor man's atomic or. Not worth adding a primitive
2539 * to everyone's atomic.h for this
2542 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2543 if ((tmptaint >> i) & 1)
2544 add_taint(i, LOCKDEP_STILL_OK);
2551 #ifdef CONFIG_PRINTK
2552 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2553 void __user *buffer, size_t *lenp, loff_t *ppos)
2555 if (write && !capable(CAP_SYS_ADMIN))
2558 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2563 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2564 * @min: pointer to minimum allowable value
2565 * @max: pointer to maximum allowable value
2567 * The do_proc_dointvec_minmax_conv_param structure provides the
2568 * minimum and maximum values for doing range checking for those sysctl
2569 * parameters that use the proc_dointvec_minmax() handler.
2571 struct do_proc_dointvec_minmax_conv_param {
2576 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2578 int write, void *data)
2580 struct do_proc_dointvec_minmax_conv_param *param = data;
2582 int val = *negp ? -*lvalp : *lvalp;
2583 if ((param->min && *param->min > val) ||
2584 (param->max && *param->max < val))
2591 *lvalp = -(unsigned long)val;
2594 *lvalp = (unsigned long)val;
2601 * proc_dointvec_minmax - read a vector of integers with min/max values
2602 * @table: the sysctl table
2603 * @write: %TRUE if this is a write to the sysctl file
2604 * @buffer: the user buffer
2605 * @lenp: the size of the user buffer
2606 * @ppos: file position
2608 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2609 * values from/to the user buffer, treated as an ASCII string.
2611 * This routine will ensure the values are within the range specified by
2612 * table->extra1 (min) and table->extra2 (max).
2614 * Returns 0 on success or -EINVAL on write when the range check fails.
2616 int proc_dointvec_minmax(struct ctl_table *table, int write,
2617 void __user *buffer, size_t *lenp, loff_t *ppos)
2619 struct do_proc_dointvec_minmax_conv_param param = {
2620 .min = (int *) table->extra1,
2621 .max = (int *) table->extra2,
2623 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2624 do_proc_dointvec_minmax_conv, ¶m);
2628 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2629 * @min: pointer to minimum allowable value
2630 * @max: pointer to maximum allowable value
2632 * The do_proc_douintvec_minmax_conv_param structure provides the
2633 * minimum and maximum values for doing range checking for those sysctl
2634 * parameters that use the proc_douintvec_minmax() handler.
2636 struct do_proc_douintvec_minmax_conv_param {
2641 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2643 int write, void *data)
2645 struct do_proc_douintvec_minmax_conv_param *param = data;
2648 unsigned int val = *lvalp;
2650 if (*lvalp > UINT_MAX)
2653 if ((param->min && *param->min > val) ||
2654 (param->max && *param->max < val))
2659 unsigned int val = *valp;
2660 *lvalp = (unsigned long) val;
2667 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2668 * @table: the sysctl table
2669 * @write: %TRUE if this is a write to the sysctl file
2670 * @buffer: the user buffer
2671 * @lenp: the size of the user buffer
2672 * @ppos: file position
2674 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2675 * values from/to the user buffer, treated as an ASCII string. Negative
2676 * strings are not allowed.
2678 * This routine will ensure the values are within the range specified by
2679 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2680 * check for UINT_MAX to avoid having to support wrap around uses from
2683 * Returns 0 on success or -ERANGE on write when the range check fails.
2685 int proc_douintvec_minmax(struct ctl_table *table, int write,
2686 void __user *buffer, size_t *lenp, loff_t *ppos)
2688 struct do_proc_douintvec_minmax_conv_param param = {
2689 .min = (unsigned int *) table->extra1,
2690 .max = (unsigned int *) table->extra2,
2692 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2693 do_proc_douintvec_minmax_conv, ¶m);
2696 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2698 int write, void *data)
2703 val = round_pipe_size(*lvalp);
2709 unsigned int val = *valp;
2710 *lvalp = (unsigned long) val;
2716 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2717 void __user *buffer, size_t *lenp, loff_t *ppos)
2719 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2720 do_proc_dopipe_max_size_conv, NULL);
2723 static void validate_coredump_safety(void)
2725 #ifdef CONFIG_COREDUMP
2726 if (suid_dumpable == SUID_DUMP_ROOT &&
2727 core_pattern[0] != '/' && core_pattern[0] != '|') {
2729 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2730 "Pipe handler or fully qualified core dump path required.\n"
2731 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2737 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2738 void __user *buffer, size_t *lenp, loff_t *ppos)
2740 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2742 validate_coredump_safety();
2746 #ifdef CONFIG_COREDUMP
2747 static int proc_dostring_coredump(struct ctl_table *table, int write,
2748 void __user *buffer, size_t *lenp, loff_t *ppos)
2750 int error = proc_dostring(table, write, buffer, lenp, ppos);
2752 validate_coredump_safety();
2757 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2758 void __user *buffer,
2759 size_t *lenp, loff_t *ppos,
2760 unsigned long convmul,
2761 unsigned long convdiv)
2763 unsigned long *i, *min, *max;
2764 int vleft, first = 1, err = 0;
2766 char *kbuf = NULL, *p;
2768 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2773 i = (unsigned long *) data;
2774 min = (unsigned long *) table->extra1;
2775 max = (unsigned long *) table->extra2;
2776 vleft = table->maxlen / sizeof(unsigned long);
2780 if (proc_first_pos_non_zero_ignore(ppos, table))
2783 if (left > PAGE_SIZE - 1)
2784 left = PAGE_SIZE - 1;
2785 p = kbuf = memdup_user_nul(buffer, left);
2787 return PTR_ERR(kbuf);
2790 for (; left && vleft--; i++, first = 0) {
2796 left -= proc_skip_spaces(&p);
2800 err = proc_get_long(&p, &left, &val, &neg,
2802 sizeof(proc_wspace_sep), NULL);
2807 val = convmul * val / convdiv;
2808 if ((min && val < *min) || (max && val > *max))
2812 val = convdiv * (*i) / convmul;
2814 err = proc_put_char(&buffer, &left, '\t');
2818 err = proc_put_long(&buffer, &left, val, false);
2824 if (!write && !first && left && !err)
2825 err = proc_put_char(&buffer, &left, '\n');
2827 left -= proc_skip_spaces(&p);
2831 return err ? : -EINVAL;
2839 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2840 void __user *buffer,
2841 size_t *lenp, loff_t *ppos,
2842 unsigned long convmul,
2843 unsigned long convdiv)
2845 return __do_proc_doulongvec_minmax(table->data, table, write,
2846 buffer, lenp, ppos, convmul, convdiv);
2850 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2851 * @table: the sysctl table
2852 * @write: %TRUE if this is a write to the sysctl file
2853 * @buffer: the user buffer
2854 * @lenp: the size of the user buffer
2855 * @ppos: file position
2857 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2858 * values from/to the user buffer, treated as an ASCII string.
2860 * This routine will ensure the values are within the range specified by
2861 * table->extra1 (min) and table->extra2 (max).
2863 * Returns 0 on success.
2865 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2866 void __user *buffer, size_t *lenp, loff_t *ppos)
2868 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2872 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2873 * @table: the sysctl table
2874 * @write: %TRUE if this is a write to the sysctl file
2875 * @buffer: the user buffer
2876 * @lenp: the size of the user buffer
2877 * @ppos: file position
2879 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2880 * values from/to the user buffer, treated as an ASCII string. The values
2881 * are treated as milliseconds, and converted to jiffies when they are stored.
2883 * This routine will ensure the values are within the range specified by
2884 * table->extra1 (min) and table->extra2 (max).
2886 * Returns 0 on success.
2888 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2889 void __user *buffer,
2890 size_t *lenp, loff_t *ppos)
2892 return do_proc_doulongvec_minmax(table, write, buffer,
2893 lenp, ppos, HZ, 1000l);
2897 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2899 int write, void *data)
2902 if (*lvalp > INT_MAX / HZ)
2904 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2910 lval = -(unsigned long)val;
2913 lval = (unsigned long)val;
2920 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2922 int write, void *data)
2925 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2927 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2933 lval = -(unsigned long)val;
2936 lval = (unsigned long)val;
2938 *lvalp = jiffies_to_clock_t(lval);
2943 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2945 int write, void *data)
2948 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2958 lval = -(unsigned long)val;
2961 lval = (unsigned long)val;
2963 *lvalp = jiffies_to_msecs(lval);
2969 * proc_dointvec_jiffies - read a vector of integers as seconds
2970 * @table: the sysctl table
2971 * @write: %TRUE if this is a write to the sysctl file
2972 * @buffer: the user buffer
2973 * @lenp: the size of the user buffer
2974 * @ppos: file position
2976 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2977 * values from/to the user buffer, treated as an ASCII string.
2978 * The values read are assumed to be in seconds, and are converted into
2981 * Returns 0 on success.
2983 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2984 void __user *buffer, size_t *lenp, loff_t *ppos)
2986 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2987 do_proc_dointvec_jiffies_conv,NULL);
2991 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2992 * @table: the sysctl table
2993 * @write: %TRUE if this is a write to the sysctl file
2994 * @buffer: the user buffer
2995 * @lenp: the size of the user buffer
2996 * @ppos: pointer to the file position
2998 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2999 * values from/to the user buffer, treated as an ASCII string.
3000 * The values read are assumed to be in 1/USER_HZ seconds, and
3001 * are converted into jiffies.
3003 * Returns 0 on success.
3005 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3006 void __user *buffer, size_t *lenp, loff_t *ppos)
3008 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3009 do_proc_dointvec_userhz_jiffies_conv,NULL);
3013 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3014 * @table: the sysctl table
3015 * @write: %TRUE if this is a write to the sysctl file
3016 * @buffer: the user buffer
3017 * @lenp: the size of the user buffer
3018 * @ppos: file position
3019 * @ppos: the current position in the file
3021 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3022 * values from/to the user buffer, treated as an ASCII string.
3023 * The values read are assumed to be in 1/1000 seconds, and
3024 * are converted into jiffies.
3026 * Returns 0 on success.
3028 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3029 void __user *buffer, size_t *lenp, loff_t *ppos)
3031 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3032 do_proc_dointvec_ms_jiffies_conv, NULL);
3035 static int proc_do_cad_pid(struct ctl_table *table, int write,
3036 void __user *buffer, size_t *lenp, loff_t *ppos)
3038 struct pid *new_pid;
3042 tmp = pid_vnr(cad_pid);
3044 r = __do_proc_dointvec(&tmp, table, write, buffer,
3045 lenp, ppos, NULL, NULL);
3049 new_pid = find_get_pid(tmp);
3053 put_pid(xchg(&cad_pid, new_pid));
3058 * proc_do_large_bitmap - read/write from/to a large bitmap
3059 * @table: the sysctl table
3060 * @write: %TRUE if this is a write to the sysctl file
3061 * @buffer: the user buffer
3062 * @lenp: the size of the user buffer
3063 * @ppos: file position
3065 * The bitmap is stored at table->data and the bitmap length (in bits)
3068 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3069 * large bitmaps may be represented in a compact manner. Writing into
3070 * the file will clear the bitmap then update it with the given input.
3072 * Returns 0 on success.
3074 int proc_do_large_bitmap(struct ctl_table *table, int write,
3075 void __user *buffer, size_t *lenp, loff_t *ppos)
3079 size_t left = *lenp;
3080 unsigned long bitmap_len = table->maxlen;
3081 unsigned long *bitmap = *(unsigned long **) table->data;
3082 unsigned long *tmp_bitmap = NULL;
3083 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3085 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3093 if (left > PAGE_SIZE - 1)
3094 left = PAGE_SIZE - 1;
3096 p = kbuf = memdup_user_nul(buffer, left);
3098 return PTR_ERR(kbuf);
3100 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3101 sizeof(unsigned long),
3107 proc_skip_char(&p, &left, '\n');
3108 while (!err && left) {
3109 unsigned long val_a, val_b;
3112 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3116 if (val_a >= bitmap_len || neg) {
3128 err = proc_get_long(&p, &left, &val_b,
3129 &neg, tr_b, sizeof(tr_b),
3133 if (val_b >= bitmap_len || neg ||
3144 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3146 proc_skip_char(&p, &left, '\n');
3150 unsigned long bit_a, bit_b = 0;
3153 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3154 if (bit_a >= bitmap_len)
3156 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3160 err = proc_put_char(&buffer, &left, ',');
3164 err = proc_put_long(&buffer, &left, bit_a, false);
3167 if (bit_a != bit_b) {
3168 err = proc_put_char(&buffer, &left, '-');
3171 err = proc_put_long(&buffer, &left, bit_b, false);
3179 err = proc_put_char(&buffer, &left, '\n');
3185 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3187 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3197 #else /* CONFIG_PROC_SYSCTL */
3199 int proc_dostring(struct ctl_table *table, int write,
3200 void __user *buffer, size_t *lenp, loff_t *ppos)
3205 int proc_dointvec(struct ctl_table *table, int write,
3206 void __user *buffer, size_t *lenp, loff_t *ppos)
3211 int proc_douintvec(struct ctl_table *table, int write,
3212 void __user *buffer, size_t *lenp, loff_t *ppos)
3217 int proc_dointvec_minmax(struct ctl_table *table, int write,
3218 void __user *buffer, size_t *lenp, loff_t *ppos)
3223 int proc_douintvec_minmax(struct ctl_table *table, int write,
3224 void __user *buffer, size_t *lenp, loff_t *ppos)
3229 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3230 void __user *buffer, size_t *lenp, loff_t *ppos)
3235 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3236 void __user *buffer, size_t *lenp, loff_t *ppos)
3241 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3242 void __user *buffer, size_t *lenp, loff_t *ppos)
3247 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3248 void __user *buffer, size_t *lenp, loff_t *ppos)
3253 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3254 void __user *buffer,
3255 size_t *lenp, loff_t *ppos)
3261 #endif /* CONFIG_PROC_SYSCTL */
3264 * No sense putting this after each symbol definition, twice,
3265 * exception granted :-)
3267 EXPORT_SYMBOL(proc_dointvec);
3268 EXPORT_SYMBOL(proc_douintvec);
3269 EXPORT_SYMBOL(proc_dointvec_jiffies);
3270 EXPORT_SYMBOL(proc_dointvec_minmax);
3271 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3272 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3273 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3274 EXPORT_SYMBOL(proc_dostring);
3275 EXPORT_SYMBOL(proc_doulongvec_minmax);
3276 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);