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 "../lib/kstrtox.h"
72 #include <linux/uaccess.h>
73 #include <asm/processor.h>
77 #include <asm/stacktrace.h>
81 #include <asm/setup.h>
83 #ifdef CONFIG_BSD_PROCESS_ACCT
84 #include <linux/acct.h>
86 #ifdef CONFIG_RT_MUTEXES
87 #include <linux/rtmutex.h>
89 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
90 #include <linux/lockdep.h>
92 #ifdef CONFIG_CHR_DEV_SG
95 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
96 #include <linux/stackleak.h>
98 #ifdef CONFIG_LOCKUP_DETECTOR
99 #include <linux/nmi.h>
102 #if defined(CONFIG_SYSCTL)
104 /* External variables not in a header file. */
105 extern int suid_dumpable;
106 #ifdef CONFIG_COREDUMP
107 extern int core_uses_pid;
108 extern char core_pattern[];
109 extern unsigned int core_pipe_limit;
112 extern int pid_max_min, pid_max_max;
113 extern int percpu_pagelist_fraction;
114 extern int latencytop_enabled;
115 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
117 extern int sysctl_nr_trim_pages;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty = 60;
125 static int __maybe_unused neg_one = -1;
128 static int __maybe_unused one = 1;
129 static int __maybe_unused two = 2;
130 static int __maybe_unused four = 4;
131 static unsigned long one_ul = 1;
132 static unsigned long long_max = LONG_MAX;
133 static int one_hundred = 100;
134 static int one_thousand = 1000;
136 static int ten_thousand = 10000;
138 #ifdef CONFIG_PERF_EVENTS
139 static int six_hundred_forty_kb = 640 * 1024;
142 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
143 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
145 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
146 static int maxolduid = 65535;
147 static int minolduid;
149 static int ngroups_max = NGROUPS_MAX;
150 static const int cap_last_cap = CAP_LAST_CAP;
153 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
154 * and hung_task_check_interval_secs
156 #ifdef CONFIG_DETECT_HUNG_TASK
157 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
160 #ifdef CONFIG_INOTIFY_USER
161 #include <linux/inotify.h>
167 extern int pwrsw_enabled;
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
171 extern int unaligned_enabled;
175 extern int unaligned_dump_stack;
178 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179 extern int no_unaligned_warning;
182 #ifdef CONFIG_PROC_SYSCTL
185 * enum sysctl_writes_mode - supported sysctl write modes
187 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
188 * to be written, and multiple writes on the same sysctl file descriptor
189 * will rewrite the sysctl value, regardless of file position. No warning
190 * is issued when the initial position is not 0.
191 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
193 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
194 * file position 0 and the value must be fully contained in the buffer
195 * sent to the write syscall. If dealing with strings respect the file
196 * position, but restrict this to the max length of the buffer, anything
197 * passed the max lenght will be ignored. Multiple writes will append
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
203 enum sysctl_writes_mode {
204 SYSCTL_WRITES_LEGACY = -1,
205 SYSCTL_WRITES_WARN = 0,
206 SYSCTL_WRITES_STRICT = 1,
209 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
211 static int proc_do_cad_pid(struct ctl_table *table, int write,
212 void __user *buffer, size_t *lenp, loff_t *ppos);
213 static int proc_taint(struct ctl_table *table, int write,
214 void __user *buffer, size_t *lenp, loff_t *ppos);
218 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
219 void __user *buffer, size_t *lenp, loff_t *ppos);
222 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
223 void __user *buffer, size_t *lenp, loff_t *ppos);
224 #ifdef CONFIG_COREDUMP
225 static int proc_dostring_coredump(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
228 static int proc_dopipe_max_size(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp, loff_t *ppos);
231 #ifdef CONFIG_MAGIC_SYSRQ
232 /* Note: sysrq code uses its own private copy */
233 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
235 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
236 void __user *buffer, size_t *lenp,
241 error = proc_dointvec(table, write, buffer, lenp, ppos);
246 sysrq_toggle_support(__sysrq_enabled);
253 static struct ctl_table kern_table[];
254 static struct ctl_table vm_table[];
255 static struct ctl_table fs_table[];
256 static struct ctl_table debug_table[];
257 static struct ctl_table dev_table[];
258 extern struct ctl_table random_table[];
260 extern struct ctl_table epoll_table[];
263 #ifdef CONFIG_FW_LOADER_USER_HELPER
264 extern struct ctl_table firmware_config_table[];
267 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
268 int sysctl_legacy_va_layout;
271 /* The default sysctl tables: */
273 static struct ctl_table sysctl_base_table[] = {
275 .procname = "kernel",
292 .child = debug_table,
302 #ifdef CONFIG_SCHED_DEBUG
303 static int min_sched_granularity_ns = 100000; /* 100 usecs */
304 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
305 static int min_wakeup_granularity_ns; /* 0 usecs */
306 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
308 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
309 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
310 #endif /* CONFIG_SMP */
311 #endif /* CONFIG_SCHED_DEBUG */
313 #ifdef CONFIG_COMPACTION
314 static int min_extfrag_threshold;
315 static int max_extfrag_threshold = 1000;
318 static struct ctl_table kern_table[] = {
320 .procname = "sched_child_runs_first",
321 .data = &sysctl_sched_child_runs_first,
322 .maxlen = sizeof(unsigned int),
324 .proc_handler = proc_dointvec,
326 #ifdef CONFIG_SCHED_DEBUG
328 .procname = "sched_min_granularity_ns",
329 .data = &sysctl_sched_min_granularity,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = sched_proc_update_handler,
333 .extra1 = &min_sched_granularity_ns,
334 .extra2 = &max_sched_granularity_ns,
337 .procname = "sched_latency_ns",
338 .data = &sysctl_sched_latency,
339 .maxlen = sizeof(unsigned int),
341 .proc_handler = sched_proc_update_handler,
342 .extra1 = &min_sched_granularity_ns,
343 .extra2 = &max_sched_granularity_ns,
346 .procname = "sched_wakeup_granularity_ns",
347 .data = &sysctl_sched_wakeup_granularity,
348 .maxlen = sizeof(unsigned int),
350 .proc_handler = sched_proc_update_handler,
351 .extra1 = &min_wakeup_granularity_ns,
352 .extra2 = &max_wakeup_granularity_ns,
356 .procname = "sched_tunable_scaling",
357 .data = &sysctl_sched_tunable_scaling,
358 .maxlen = sizeof(enum sched_tunable_scaling),
360 .proc_handler = sched_proc_update_handler,
361 .extra1 = &min_sched_tunable_scaling,
362 .extra2 = &max_sched_tunable_scaling,
365 .procname = "sched_migration_cost_ns",
366 .data = &sysctl_sched_migration_cost,
367 .maxlen = sizeof(unsigned int),
369 .proc_handler = proc_dointvec,
372 .procname = "sched_nr_migrate",
373 .data = &sysctl_sched_nr_migrate,
374 .maxlen = sizeof(unsigned int),
376 .proc_handler = proc_dointvec,
378 #ifdef CONFIG_SCHEDSTATS
380 .procname = "sched_schedstats",
382 .maxlen = sizeof(unsigned int),
384 .proc_handler = sysctl_schedstats,
388 #endif /* CONFIG_SCHEDSTATS */
389 #endif /* CONFIG_SMP */
390 #ifdef CONFIG_NUMA_BALANCING
392 .procname = "numa_balancing_scan_delay_ms",
393 .data = &sysctl_numa_balancing_scan_delay,
394 .maxlen = sizeof(unsigned int),
396 .proc_handler = proc_dointvec,
399 .procname = "numa_balancing_scan_period_min_ms",
400 .data = &sysctl_numa_balancing_scan_period_min,
401 .maxlen = sizeof(unsigned int),
403 .proc_handler = proc_dointvec,
406 .procname = "numa_balancing_scan_period_max_ms",
407 .data = &sysctl_numa_balancing_scan_period_max,
408 .maxlen = sizeof(unsigned int),
410 .proc_handler = proc_dointvec,
413 .procname = "numa_balancing_scan_size_mb",
414 .data = &sysctl_numa_balancing_scan_size,
415 .maxlen = sizeof(unsigned int),
417 .proc_handler = proc_dointvec_minmax,
421 .procname = "numa_balancing",
422 .data = NULL, /* filled in by handler */
423 .maxlen = sizeof(unsigned int),
425 .proc_handler = sysctl_numa_balancing,
429 #endif /* CONFIG_NUMA_BALANCING */
430 #endif /* CONFIG_SCHED_DEBUG */
432 .procname = "sched_rt_period_us",
433 .data = &sysctl_sched_rt_period,
434 .maxlen = sizeof(unsigned int),
436 .proc_handler = sched_rt_handler,
439 .procname = "sched_rt_runtime_us",
440 .data = &sysctl_sched_rt_runtime,
441 .maxlen = sizeof(int),
443 .proc_handler = sched_rt_handler,
446 .procname = "sched_rr_timeslice_ms",
447 .data = &sysctl_sched_rr_timeslice,
448 .maxlen = sizeof(int),
450 .proc_handler = sched_rr_handler,
452 #ifdef CONFIG_SCHED_AUTOGROUP
454 .procname = "sched_autogroup_enabled",
455 .data = &sysctl_sched_autogroup_enabled,
456 .maxlen = sizeof(unsigned int),
458 .proc_handler = proc_dointvec_minmax,
463 #ifdef CONFIG_CFS_BANDWIDTH
465 .procname = "sched_cfs_bandwidth_slice_us",
466 .data = &sysctl_sched_cfs_bandwidth_slice,
467 .maxlen = sizeof(unsigned int),
469 .proc_handler = proc_dointvec_minmax,
473 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
475 .procname = "sched_energy_aware",
476 .data = &sysctl_sched_energy_aware,
477 .maxlen = sizeof(unsigned int),
479 .proc_handler = sched_energy_aware_handler,
484 #ifdef CONFIG_PROVE_LOCKING
486 .procname = "prove_locking",
487 .data = &prove_locking,
488 .maxlen = sizeof(int),
490 .proc_handler = proc_dointvec,
493 #ifdef CONFIG_LOCK_STAT
495 .procname = "lock_stat",
497 .maxlen = sizeof(int),
499 .proc_handler = proc_dointvec,
504 .data = &panic_timeout,
505 .maxlen = sizeof(int),
507 .proc_handler = proc_dointvec,
509 #ifdef CONFIG_COREDUMP
511 .procname = "core_uses_pid",
512 .data = &core_uses_pid,
513 .maxlen = sizeof(int),
515 .proc_handler = proc_dointvec,
518 .procname = "core_pattern",
519 .data = core_pattern,
520 .maxlen = CORENAME_MAX_SIZE,
522 .proc_handler = proc_dostring_coredump,
525 .procname = "core_pipe_limit",
526 .data = &core_pipe_limit,
527 .maxlen = sizeof(unsigned int),
529 .proc_handler = proc_dointvec,
532 #ifdef CONFIG_PROC_SYSCTL
534 .procname = "tainted",
535 .maxlen = sizeof(long),
537 .proc_handler = proc_taint,
540 .procname = "sysctl_writes_strict",
541 .data = &sysctl_writes_strict,
542 .maxlen = sizeof(int),
544 .proc_handler = proc_dointvec_minmax,
549 #ifdef CONFIG_LATENCYTOP
551 .procname = "latencytop",
552 .data = &latencytop_enabled,
553 .maxlen = sizeof(int),
555 .proc_handler = sysctl_latencytop,
558 #ifdef CONFIG_BLK_DEV_INITRD
560 .procname = "real-root-dev",
561 .data = &real_root_dev,
562 .maxlen = sizeof(int),
564 .proc_handler = proc_dointvec,
568 .procname = "print-fatal-signals",
569 .data = &print_fatal_signals,
570 .maxlen = sizeof(int),
572 .proc_handler = proc_dointvec,
576 .procname = "reboot-cmd",
577 .data = reboot_command,
580 .proc_handler = proc_dostring,
583 .procname = "stop-a",
584 .data = &stop_a_enabled,
585 .maxlen = sizeof (int),
587 .proc_handler = proc_dointvec,
590 .procname = "scons-poweroff",
591 .data = &scons_pwroff,
592 .maxlen = sizeof (int),
594 .proc_handler = proc_dointvec,
597 #ifdef CONFIG_SPARC64
599 .procname = "tsb-ratio",
600 .data = &sysctl_tsb_ratio,
601 .maxlen = sizeof (int),
603 .proc_handler = proc_dointvec,
608 .procname = "soft-power",
609 .data = &pwrsw_enabled,
610 .maxlen = sizeof (int),
612 .proc_handler = proc_dointvec,
615 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
617 .procname = "unaligned-trap",
618 .data = &unaligned_enabled,
619 .maxlen = sizeof (int),
621 .proc_handler = proc_dointvec,
625 .procname = "ctrl-alt-del",
627 .maxlen = sizeof(int),
629 .proc_handler = proc_dointvec,
631 #ifdef CONFIG_FUNCTION_TRACER
633 .procname = "ftrace_enabled",
634 .data = &ftrace_enabled,
635 .maxlen = sizeof(int),
637 .proc_handler = ftrace_enable_sysctl,
640 #ifdef CONFIG_STACK_TRACER
642 .procname = "stack_tracer_enabled",
643 .data = &stack_tracer_enabled,
644 .maxlen = sizeof(int),
646 .proc_handler = stack_trace_sysctl,
649 #ifdef CONFIG_TRACING
651 .procname = "ftrace_dump_on_oops",
652 .data = &ftrace_dump_on_oops,
653 .maxlen = sizeof(int),
655 .proc_handler = proc_dointvec,
658 .procname = "traceoff_on_warning",
659 .data = &__disable_trace_on_warning,
660 .maxlen = sizeof(__disable_trace_on_warning),
662 .proc_handler = proc_dointvec,
665 .procname = "tracepoint_printk",
666 .data = &tracepoint_printk,
667 .maxlen = sizeof(tracepoint_printk),
669 .proc_handler = tracepoint_printk_sysctl,
672 #ifdef CONFIG_KEXEC_CORE
674 .procname = "kexec_load_disabled",
675 .data = &kexec_load_disabled,
676 .maxlen = sizeof(int),
678 /* only handle a transition from default "0" to "1" */
679 .proc_handler = proc_dointvec_minmax,
684 #ifdef CONFIG_MODULES
686 .procname = "modprobe",
687 .data = &modprobe_path,
688 .maxlen = KMOD_PATH_LEN,
690 .proc_handler = proc_dostring,
693 .procname = "modules_disabled",
694 .data = &modules_disabled,
695 .maxlen = sizeof(int),
697 /* only handle a transition from default "0" to "1" */
698 .proc_handler = proc_dointvec_minmax,
703 #ifdef CONFIG_UEVENT_HELPER
705 .procname = "hotplug",
706 .data = &uevent_helper,
707 .maxlen = UEVENT_HELPER_PATH_LEN,
709 .proc_handler = proc_dostring,
712 #ifdef CONFIG_CHR_DEV_SG
714 .procname = "sg-big-buff",
715 .data = &sg_big_buff,
716 .maxlen = sizeof (int),
718 .proc_handler = proc_dointvec,
721 #ifdef CONFIG_BSD_PROCESS_ACCT
725 .maxlen = 3*sizeof(int),
727 .proc_handler = proc_dointvec,
730 #ifdef CONFIG_MAGIC_SYSRQ
733 .data = &__sysrq_enabled,
734 .maxlen = sizeof (int),
736 .proc_handler = sysrq_sysctl_handler,
739 #ifdef CONFIG_PROC_SYSCTL
741 .procname = "cad_pid",
743 .maxlen = sizeof (int),
745 .proc_handler = proc_do_cad_pid,
749 .procname = "threads-max",
751 .maxlen = sizeof(int),
753 .proc_handler = sysctl_max_threads,
756 .procname = "random",
758 .child = random_table,
761 .procname = "usermodehelper",
763 .child = usermodehelper_table,
765 #ifdef CONFIG_FW_LOADER_USER_HELPER
767 .procname = "firmware_config",
769 .child = firmware_config_table,
773 .procname = "overflowuid",
774 .data = &overflowuid,
775 .maxlen = sizeof(int),
777 .proc_handler = proc_dointvec_minmax,
778 .extra1 = &minolduid,
779 .extra2 = &maxolduid,
782 .procname = "overflowgid",
783 .data = &overflowgid,
784 .maxlen = sizeof(int),
786 .proc_handler = proc_dointvec_minmax,
787 .extra1 = &minolduid,
788 .extra2 = &maxolduid,
791 #ifdef CONFIG_MATHEMU
793 .procname = "ieee_emulation_warnings",
794 .data = &sysctl_ieee_emulation_warnings,
795 .maxlen = sizeof(int),
797 .proc_handler = proc_dointvec,
801 .procname = "userprocess_debug",
802 .data = &show_unhandled_signals,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dointvec,
809 .procname = "pid_max",
811 .maxlen = sizeof (int),
813 .proc_handler = proc_dointvec_minmax,
814 .extra1 = &pid_max_min,
815 .extra2 = &pid_max_max,
818 .procname = "panic_on_oops",
819 .data = &panic_on_oops,
820 .maxlen = sizeof(int),
822 .proc_handler = proc_dointvec,
825 .procname = "panic_print",
826 .data = &panic_print,
827 .maxlen = sizeof(unsigned long),
829 .proc_handler = proc_doulongvec_minmax,
831 #if defined CONFIG_PRINTK
833 .procname = "printk",
834 .data = &console_loglevel,
835 .maxlen = 4*sizeof(int),
837 .proc_handler = proc_dointvec,
840 .procname = "printk_ratelimit",
841 .data = &printk_ratelimit_state.interval,
842 .maxlen = sizeof(int),
844 .proc_handler = proc_dointvec_jiffies,
847 .procname = "printk_ratelimit_burst",
848 .data = &printk_ratelimit_state.burst,
849 .maxlen = sizeof(int),
851 .proc_handler = proc_dointvec,
854 .procname = "printk_delay",
855 .data = &printk_delay_msec,
856 .maxlen = sizeof(int),
858 .proc_handler = proc_dointvec_minmax,
860 .extra2 = &ten_thousand,
863 .procname = "printk_devkmsg",
864 .data = devkmsg_log_str,
865 .maxlen = DEVKMSG_STR_MAX_SIZE,
867 .proc_handler = devkmsg_sysctl_set_loglvl,
870 .procname = "dmesg_restrict",
871 .data = &dmesg_restrict,
872 .maxlen = sizeof(int),
874 .proc_handler = proc_dointvec_minmax_sysadmin,
879 .procname = "kptr_restrict",
880 .data = &kptr_restrict,
881 .maxlen = sizeof(int),
883 .proc_handler = proc_dointvec_minmax_sysadmin,
889 .procname = "ngroups_max",
890 .data = &ngroups_max,
891 .maxlen = sizeof (int),
893 .proc_handler = proc_dointvec,
896 .procname = "cap_last_cap",
897 .data = (void *)&cap_last_cap,
898 .maxlen = sizeof(int),
900 .proc_handler = proc_dointvec,
902 #if defined(CONFIG_LOCKUP_DETECTOR)
904 .procname = "watchdog",
905 .data = &watchdog_user_enabled,
906 .maxlen = sizeof(int),
908 .proc_handler = proc_watchdog,
913 .procname = "watchdog_thresh",
914 .data = &watchdog_thresh,
915 .maxlen = sizeof(int),
917 .proc_handler = proc_watchdog_thresh,
922 .procname = "nmi_watchdog",
923 .data = &nmi_watchdog_user_enabled,
924 .maxlen = sizeof(int),
925 .mode = NMI_WATCHDOG_SYSCTL_PERM,
926 .proc_handler = proc_nmi_watchdog,
931 .procname = "watchdog_cpumask",
932 .data = &watchdog_cpumask_bits,
935 .proc_handler = proc_watchdog_cpumask,
937 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
939 .procname = "soft_watchdog",
940 .data = &soft_watchdog_user_enabled,
941 .maxlen = sizeof(int),
943 .proc_handler = proc_soft_watchdog,
948 .procname = "softlockup_panic",
949 .data = &softlockup_panic,
950 .maxlen = sizeof(int),
952 .proc_handler = proc_dointvec_minmax,
958 .procname = "softlockup_all_cpu_backtrace",
959 .data = &sysctl_softlockup_all_cpu_backtrace,
960 .maxlen = sizeof(int),
962 .proc_handler = proc_dointvec_minmax,
966 #endif /* CONFIG_SMP */
968 #ifdef CONFIG_HARDLOCKUP_DETECTOR
970 .procname = "hardlockup_panic",
971 .data = &hardlockup_panic,
972 .maxlen = sizeof(int),
974 .proc_handler = proc_dointvec_minmax,
980 .procname = "hardlockup_all_cpu_backtrace",
981 .data = &sysctl_hardlockup_all_cpu_backtrace,
982 .maxlen = sizeof(int),
984 .proc_handler = proc_dointvec_minmax,
988 #endif /* CONFIG_SMP */
992 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
994 .procname = "unknown_nmi_panic",
995 .data = &unknown_nmi_panic,
996 .maxlen = sizeof (int),
998 .proc_handler = proc_dointvec,
1001 #if defined(CONFIG_X86)
1003 .procname = "panic_on_unrecovered_nmi",
1004 .data = &panic_on_unrecovered_nmi,
1005 .maxlen = sizeof(int),
1007 .proc_handler = proc_dointvec,
1010 .procname = "panic_on_io_nmi",
1011 .data = &panic_on_io_nmi,
1012 .maxlen = sizeof(int),
1014 .proc_handler = proc_dointvec,
1016 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1018 .procname = "panic_on_stackoverflow",
1019 .data = &sysctl_panic_on_stackoverflow,
1020 .maxlen = sizeof(int),
1022 .proc_handler = proc_dointvec,
1026 .procname = "bootloader_type",
1027 .data = &bootloader_type,
1028 .maxlen = sizeof (int),
1030 .proc_handler = proc_dointvec,
1033 .procname = "bootloader_version",
1034 .data = &bootloader_version,
1035 .maxlen = sizeof (int),
1037 .proc_handler = proc_dointvec,
1040 .procname = "io_delay_type",
1041 .data = &io_delay_type,
1042 .maxlen = sizeof(int),
1044 .proc_handler = proc_dointvec,
1047 #if defined(CONFIG_MMU)
1049 .procname = "randomize_va_space",
1050 .data = &randomize_va_space,
1051 .maxlen = sizeof(int),
1053 .proc_handler = proc_dointvec,
1056 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1058 .procname = "spin_retry",
1059 .data = &spin_retry,
1060 .maxlen = sizeof (int),
1062 .proc_handler = proc_dointvec,
1065 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1067 .procname = "acpi_video_flags",
1068 .data = &acpi_realmode_flags,
1069 .maxlen = sizeof (unsigned long),
1071 .proc_handler = proc_doulongvec_minmax,
1074 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1076 .procname = "ignore-unaligned-usertrap",
1077 .data = &no_unaligned_warning,
1078 .maxlen = sizeof (int),
1080 .proc_handler = proc_dointvec,
1085 .procname = "unaligned-dump-stack",
1086 .data = &unaligned_dump_stack,
1087 .maxlen = sizeof (int),
1089 .proc_handler = proc_dointvec,
1092 #ifdef CONFIG_DETECT_HUNG_TASK
1094 .procname = "hung_task_panic",
1095 .data = &sysctl_hung_task_panic,
1096 .maxlen = sizeof(int),
1098 .proc_handler = proc_dointvec_minmax,
1103 .procname = "hung_task_check_count",
1104 .data = &sysctl_hung_task_check_count,
1105 .maxlen = sizeof(int),
1107 .proc_handler = proc_dointvec_minmax,
1111 .procname = "hung_task_timeout_secs",
1112 .data = &sysctl_hung_task_timeout_secs,
1113 .maxlen = sizeof(unsigned long),
1115 .proc_handler = proc_dohung_task_timeout_secs,
1116 .extra2 = &hung_task_timeout_max,
1119 .procname = "hung_task_check_interval_secs",
1120 .data = &sysctl_hung_task_check_interval_secs,
1121 .maxlen = sizeof(unsigned long),
1123 .proc_handler = proc_dohung_task_timeout_secs,
1124 .extra2 = &hung_task_timeout_max,
1127 .procname = "hung_task_warnings",
1128 .data = &sysctl_hung_task_warnings,
1129 .maxlen = sizeof(int),
1131 .proc_handler = proc_dointvec_minmax,
1135 #ifdef CONFIG_RT_MUTEXES
1137 .procname = "max_lock_depth",
1138 .data = &max_lock_depth,
1139 .maxlen = sizeof(int),
1141 .proc_handler = proc_dointvec,
1145 .procname = "poweroff_cmd",
1146 .data = &poweroff_cmd,
1147 .maxlen = POWEROFF_CMD_PATH_LEN,
1149 .proc_handler = proc_dostring,
1155 .child = key_sysctls,
1158 #ifdef CONFIG_PERF_EVENTS
1160 * User-space scripts rely on the existence of this file
1161 * as a feature check for perf_events being enabled.
1163 * So it's an ABI, do not remove!
1166 .procname = "perf_event_paranoid",
1167 .data = &sysctl_perf_event_paranoid,
1168 .maxlen = sizeof(sysctl_perf_event_paranoid),
1170 .proc_handler = proc_dointvec,
1173 .procname = "perf_event_mlock_kb",
1174 .data = &sysctl_perf_event_mlock,
1175 .maxlen = sizeof(sysctl_perf_event_mlock),
1177 .proc_handler = proc_dointvec,
1180 .procname = "perf_event_max_sample_rate",
1181 .data = &sysctl_perf_event_sample_rate,
1182 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1184 .proc_handler = perf_proc_update_handler,
1188 .procname = "perf_cpu_time_max_percent",
1189 .data = &sysctl_perf_cpu_time_max_percent,
1190 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1192 .proc_handler = perf_cpu_time_max_percent_handler,
1194 .extra2 = &one_hundred,
1197 .procname = "perf_event_max_stack",
1198 .data = &sysctl_perf_event_max_stack,
1199 .maxlen = sizeof(sysctl_perf_event_max_stack),
1201 .proc_handler = perf_event_max_stack_handler,
1203 .extra2 = &six_hundred_forty_kb,
1206 .procname = "perf_event_max_contexts_per_stack",
1207 .data = &sysctl_perf_event_max_contexts_per_stack,
1208 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1210 .proc_handler = perf_event_max_stack_handler,
1212 .extra2 = &one_thousand,
1216 .procname = "panic_on_warn",
1217 .data = &panic_on_warn,
1218 .maxlen = sizeof(int),
1220 .proc_handler = proc_dointvec_minmax,
1224 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1226 .procname = "timer_migration",
1227 .data = &sysctl_timer_migration,
1228 .maxlen = sizeof(unsigned int),
1230 .proc_handler = timer_migration_handler,
1235 #ifdef CONFIG_BPF_SYSCALL
1237 .procname = "unprivileged_bpf_disabled",
1238 .data = &sysctl_unprivileged_bpf_disabled,
1239 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1241 /* only handle a transition from default "0" to "1" */
1242 .proc_handler = proc_dointvec_minmax,
1247 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1249 .procname = "panic_on_rcu_stall",
1250 .data = &sysctl_panic_on_rcu_stall,
1251 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1253 .proc_handler = proc_dointvec_minmax,
1258 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1260 .procname = "stack_erasing",
1262 .maxlen = sizeof(int),
1264 .proc_handler = stack_erasing_sysctl,
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 = proc_dointvec_minmax,
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_boost_factor",
1488 .data = &watermark_boost_factor,
1489 .maxlen = sizeof(watermark_boost_factor),
1491 .proc_handler = watermark_boost_factor_sysctl_handler,
1495 .procname = "watermark_scale_factor",
1496 .data = &watermark_scale_factor,
1497 .maxlen = sizeof(watermark_scale_factor),
1499 .proc_handler = watermark_scale_factor_sysctl_handler,
1501 .extra2 = &one_thousand,
1504 .procname = "percpu_pagelist_fraction",
1505 .data = &percpu_pagelist_fraction,
1506 .maxlen = sizeof(percpu_pagelist_fraction),
1508 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1513 .procname = "max_map_count",
1514 .data = &sysctl_max_map_count,
1515 .maxlen = sizeof(sysctl_max_map_count),
1517 .proc_handler = proc_dointvec_minmax,
1522 .procname = "nr_trim_pages",
1523 .data = &sysctl_nr_trim_pages,
1524 .maxlen = sizeof(sysctl_nr_trim_pages),
1526 .proc_handler = proc_dointvec_minmax,
1531 .procname = "laptop_mode",
1532 .data = &laptop_mode,
1533 .maxlen = sizeof(laptop_mode),
1535 .proc_handler = proc_dointvec_jiffies,
1538 .procname = "block_dump",
1539 .data = &block_dump,
1540 .maxlen = sizeof(block_dump),
1542 .proc_handler = proc_dointvec,
1546 .procname = "vfs_cache_pressure",
1547 .data = &sysctl_vfs_cache_pressure,
1548 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1550 .proc_handler = proc_dointvec,
1553 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1555 .procname = "legacy_va_layout",
1556 .data = &sysctl_legacy_va_layout,
1557 .maxlen = sizeof(sysctl_legacy_va_layout),
1559 .proc_handler = proc_dointvec,
1565 .procname = "zone_reclaim_mode",
1566 .data = &node_reclaim_mode,
1567 .maxlen = sizeof(node_reclaim_mode),
1569 .proc_handler = proc_dointvec,
1573 .procname = "min_unmapped_ratio",
1574 .data = &sysctl_min_unmapped_ratio,
1575 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1577 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1579 .extra2 = &one_hundred,
1582 .procname = "min_slab_ratio",
1583 .data = &sysctl_min_slab_ratio,
1584 .maxlen = sizeof(sysctl_min_slab_ratio),
1586 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1588 .extra2 = &one_hundred,
1593 .procname = "stat_interval",
1594 .data = &sysctl_stat_interval,
1595 .maxlen = sizeof(sysctl_stat_interval),
1597 .proc_handler = proc_dointvec_jiffies,
1600 .procname = "stat_refresh",
1604 .proc_handler = vmstat_refresh,
1609 .procname = "mmap_min_addr",
1610 .data = &dac_mmap_min_addr,
1611 .maxlen = sizeof(unsigned long),
1613 .proc_handler = mmap_min_addr_handler,
1618 .procname = "numa_zonelist_order",
1619 .data = &numa_zonelist_order,
1620 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1622 .proc_handler = numa_zonelist_order_handler,
1625 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1626 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1628 .procname = "vdso_enabled",
1629 #ifdef CONFIG_X86_32
1630 .data = &vdso32_enabled,
1631 .maxlen = sizeof(vdso32_enabled),
1633 .data = &vdso_enabled,
1634 .maxlen = sizeof(vdso_enabled),
1637 .proc_handler = proc_dointvec,
1641 #ifdef CONFIG_HIGHMEM
1643 .procname = "highmem_is_dirtyable",
1644 .data = &vm_highmem_is_dirtyable,
1645 .maxlen = sizeof(vm_highmem_is_dirtyable),
1647 .proc_handler = proc_dointvec_minmax,
1652 #ifdef CONFIG_MEMORY_FAILURE
1654 .procname = "memory_failure_early_kill",
1655 .data = &sysctl_memory_failure_early_kill,
1656 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1658 .proc_handler = proc_dointvec_minmax,
1663 .procname = "memory_failure_recovery",
1664 .data = &sysctl_memory_failure_recovery,
1665 .maxlen = sizeof(sysctl_memory_failure_recovery),
1667 .proc_handler = proc_dointvec_minmax,
1673 .procname = "user_reserve_kbytes",
1674 .data = &sysctl_user_reserve_kbytes,
1675 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1677 .proc_handler = proc_doulongvec_minmax,
1680 .procname = "admin_reserve_kbytes",
1681 .data = &sysctl_admin_reserve_kbytes,
1682 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1684 .proc_handler = proc_doulongvec_minmax,
1686 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1688 .procname = "mmap_rnd_bits",
1689 .data = &mmap_rnd_bits,
1690 .maxlen = sizeof(mmap_rnd_bits),
1692 .proc_handler = proc_dointvec_minmax,
1693 .extra1 = (void *)&mmap_rnd_bits_min,
1694 .extra2 = (void *)&mmap_rnd_bits_max,
1697 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1699 .procname = "mmap_rnd_compat_bits",
1700 .data = &mmap_rnd_compat_bits,
1701 .maxlen = sizeof(mmap_rnd_compat_bits),
1703 .proc_handler = proc_dointvec_minmax,
1704 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1705 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1711 static struct ctl_table fs_table[] = {
1713 .procname = "inode-nr",
1714 .data = &inodes_stat,
1715 .maxlen = 2*sizeof(long),
1717 .proc_handler = proc_nr_inodes,
1720 .procname = "inode-state",
1721 .data = &inodes_stat,
1722 .maxlen = 7*sizeof(long),
1724 .proc_handler = proc_nr_inodes,
1727 .procname = "file-nr",
1728 .data = &files_stat,
1729 .maxlen = sizeof(files_stat),
1731 .proc_handler = proc_nr_files,
1734 .procname = "file-max",
1735 .data = &files_stat.max_files,
1736 .maxlen = sizeof(files_stat.max_files),
1738 .proc_handler = proc_doulongvec_minmax,
1740 .extra2 = &long_max,
1743 .procname = "nr_open",
1744 .data = &sysctl_nr_open,
1745 .maxlen = sizeof(unsigned int),
1747 .proc_handler = proc_dointvec_minmax,
1748 .extra1 = &sysctl_nr_open_min,
1749 .extra2 = &sysctl_nr_open_max,
1752 .procname = "dentry-state",
1753 .data = &dentry_stat,
1754 .maxlen = 6*sizeof(long),
1756 .proc_handler = proc_nr_dentry,
1759 .procname = "overflowuid",
1760 .data = &fs_overflowuid,
1761 .maxlen = sizeof(int),
1763 .proc_handler = proc_dointvec_minmax,
1764 .extra1 = &minolduid,
1765 .extra2 = &maxolduid,
1768 .procname = "overflowgid",
1769 .data = &fs_overflowgid,
1770 .maxlen = sizeof(int),
1772 .proc_handler = proc_dointvec_minmax,
1773 .extra1 = &minolduid,
1774 .extra2 = &maxolduid,
1776 #ifdef CONFIG_FILE_LOCKING
1778 .procname = "leases-enable",
1779 .data = &leases_enable,
1780 .maxlen = sizeof(int),
1782 .proc_handler = proc_dointvec,
1785 #ifdef CONFIG_DNOTIFY
1787 .procname = "dir-notify-enable",
1788 .data = &dir_notify_enable,
1789 .maxlen = sizeof(int),
1791 .proc_handler = proc_dointvec,
1795 #ifdef CONFIG_FILE_LOCKING
1797 .procname = "lease-break-time",
1798 .data = &lease_break_time,
1799 .maxlen = sizeof(int),
1801 .proc_handler = proc_dointvec,
1806 .procname = "aio-nr",
1808 .maxlen = sizeof(aio_nr),
1810 .proc_handler = proc_doulongvec_minmax,
1813 .procname = "aio-max-nr",
1814 .data = &aio_max_nr,
1815 .maxlen = sizeof(aio_max_nr),
1817 .proc_handler = proc_doulongvec_minmax,
1819 #endif /* CONFIG_AIO */
1820 #ifdef CONFIG_INOTIFY_USER
1822 .procname = "inotify",
1824 .child = inotify_table,
1829 .procname = "epoll",
1831 .child = epoll_table,
1836 .procname = "protected_symlinks",
1837 .data = &sysctl_protected_symlinks,
1838 .maxlen = sizeof(int),
1840 .proc_handler = proc_dointvec_minmax,
1845 .procname = "protected_hardlinks",
1846 .data = &sysctl_protected_hardlinks,
1847 .maxlen = sizeof(int),
1849 .proc_handler = proc_dointvec_minmax,
1854 .procname = "protected_fifos",
1855 .data = &sysctl_protected_fifos,
1856 .maxlen = sizeof(int),
1858 .proc_handler = proc_dointvec_minmax,
1863 .procname = "protected_regular",
1864 .data = &sysctl_protected_regular,
1865 .maxlen = sizeof(int),
1867 .proc_handler = proc_dointvec_minmax,
1872 .procname = "suid_dumpable",
1873 .data = &suid_dumpable,
1874 .maxlen = sizeof(int),
1876 .proc_handler = proc_dointvec_minmax_coredump,
1880 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1882 .procname = "binfmt_misc",
1884 .child = sysctl_mount_point,
1888 .procname = "pipe-max-size",
1889 .data = &pipe_max_size,
1890 .maxlen = sizeof(pipe_max_size),
1892 .proc_handler = proc_dopipe_max_size,
1895 .procname = "pipe-user-pages-hard",
1896 .data = &pipe_user_pages_hard,
1897 .maxlen = sizeof(pipe_user_pages_hard),
1899 .proc_handler = proc_doulongvec_minmax,
1902 .procname = "pipe-user-pages-soft",
1903 .data = &pipe_user_pages_soft,
1904 .maxlen = sizeof(pipe_user_pages_soft),
1906 .proc_handler = proc_doulongvec_minmax,
1909 .procname = "mount-max",
1910 .data = &sysctl_mount_max,
1911 .maxlen = sizeof(unsigned int),
1913 .proc_handler = proc_dointvec_minmax,
1919 static struct ctl_table debug_table[] = {
1920 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1922 .procname = "exception-trace",
1923 .data = &show_unhandled_signals,
1924 .maxlen = sizeof(int),
1926 .proc_handler = proc_dointvec
1929 #if defined(CONFIG_OPTPROBES)
1931 .procname = "kprobes-optimization",
1932 .data = &sysctl_kprobes_optimization,
1933 .maxlen = sizeof(int),
1935 .proc_handler = proc_kprobes_optimization_handler,
1943 static struct ctl_table dev_table[] = {
1947 int __init sysctl_init(void)
1949 struct ctl_table_header *hdr;
1951 hdr = register_sysctl_table(sysctl_base_table);
1952 kmemleak_not_leak(hdr);
1956 #endif /* CONFIG_SYSCTL */
1962 #ifdef CONFIG_PROC_SYSCTL
1964 static int _proc_do_string(char *data, int maxlen, int write,
1965 char __user *buffer,
1966 size_t *lenp, loff_t *ppos)
1972 if (!data || !maxlen || !*lenp) {
1978 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1979 /* Only continue writes not past the end of buffer. */
1981 if (len > maxlen - 1)
1988 /* Start writing from beginning of buffer. */
1994 while ((p - buffer) < *lenp && len < maxlen - 1) {
1995 if (get_user(c, p++))
1997 if (c == 0 || c == '\n')
2018 if (copy_to_user(buffer, data, len))
2021 if (put_user('\n', buffer + len))
2031 static void warn_sysctl_write(struct ctl_table *table)
2033 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2034 "This will not be supported in the future. To silence this\n"
2035 "warning, set kernel.sysctl_writes_strict = -1\n",
2036 current->comm, table->procname);
2040 * proc_first_pos_non_zero_ignore - check if first position is allowed
2041 * @ppos: file position
2042 * @table: the sysctl table
2044 * Returns true if the first position is non-zero and the sysctl_writes_strict
2045 * mode indicates this is not allowed for numeric input types. String proc
2046 * handlers can ignore the return value.
2048 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2049 struct ctl_table *table)
2054 switch (sysctl_writes_strict) {
2055 case SYSCTL_WRITES_STRICT:
2057 case SYSCTL_WRITES_WARN:
2058 warn_sysctl_write(table);
2066 * proc_dostring - read a string sysctl
2067 * @table: the sysctl table
2068 * @write: %TRUE if this is a write to the sysctl file
2069 * @buffer: the user buffer
2070 * @lenp: the size of the user buffer
2071 * @ppos: file position
2073 * Reads/writes a string from/to the user buffer. If the kernel
2074 * buffer provided is not large enough to hold the string, the
2075 * string is truncated. The copied string is %NULL-terminated.
2076 * If the string is being read by the user process, it is copied
2077 * and a newline '\n' is added. It is truncated if the buffer is
2080 * Returns 0 on success.
2082 int proc_dostring(struct ctl_table *table, int write,
2083 void __user *buffer, size_t *lenp, loff_t *ppos)
2086 proc_first_pos_non_zero_ignore(ppos, table);
2088 return _proc_do_string((char *)(table->data), table->maxlen, write,
2089 (char __user *)buffer, lenp, ppos);
2092 static size_t proc_skip_spaces(char **buf)
2095 char *tmp = skip_spaces(*buf);
2101 static void proc_skip_char(char **buf, size_t *size, const char v)
2112 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2115 * @cp: kernel buffer containing the string to parse
2116 * @endp: pointer to store the trailing characters
2117 * @base: the base to use
2118 * @res: where the parsed integer will be stored
2120 * In case of success 0 is returned and @res will contain the parsed integer,
2121 * @endp will hold any trailing characters.
2122 * This function will fail the parse on overflow. If there wasn't an overflow
2123 * the function will defer the decision what characters count as invalid to the
2126 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2129 unsigned long long result;
2132 cp = _parse_integer_fixup_radix(cp, &base);
2133 rv = _parse_integer(cp, base, &result);
2134 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2142 *res = (unsigned long)result;
2146 #define TMPBUFLEN 22
2148 * proc_get_long - reads an ASCII formatted integer from a user buffer
2150 * @buf: a kernel buffer
2151 * @size: size of the kernel buffer
2152 * @val: this is where the number will be stored
2153 * @neg: set to %TRUE if number is negative
2154 * @perm_tr: a vector which contains the allowed trailers
2155 * @perm_tr_len: size of the perm_tr vector
2156 * @tr: pointer to store the trailer character
2158 * In case of success %0 is returned and @buf and @size are updated with
2159 * the amount of bytes read. If @tr is non-NULL and a trailing
2160 * character exists (size is non-zero after returning from this
2161 * function), @tr is updated with the trailing character.
2163 static int proc_get_long(char **buf, size_t *size,
2164 unsigned long *val, bool *neg,
2165 const char *perm_tr, unsigned perm_tr_len, char *tr)
2168 char *p, tmp[TMPBUFLEN];
2174 if (len > TMPBUFLEN - 1)
2175 len = TMPBUFLEN - 1;
2177 memcpy(tmp, *buf, len);
2181 if (*p == '-' && *size > 1) {
2189 if (strtoul_lenient(p, &p, 0, val))
2194 /* We don't know if the next char is whitespace thus we may accept
2195 * invalid integers (e.g. 1234...a) or two integers instead of one
2196 * (e.g. 123...1). So lets not allow such large numbers. */
2197 if (len == TMPBUFLEN - 1)
2200 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2203 if (tr && (len < *size))
2213 * proc_put_long - converts an integer to a decimal ASCII formatted string
2215 * @buf: the user buffer
2216 * @size: the size of the user buffer
2217 * @val: the integer to be converted
2218 * @neg: sign of the number, %TRUE for negative
2220 * In case of success %0 is returned and @buf and @size are updated with
2221 * the amount of bytes written.
2223 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2227 char tmp[TMPBUFLEN], *p = tmp;
2229 sprintf(p, "%s%lu", neg ? "-" : "", val);
2233 if (copy_to_user(*buf, tmp, len))
2241 static int proc_put_char(void __user **buf, size_t *size, char c)
2244 char __user **buffer = (char __user **)buf;
2245 if (put_user(c, *buffer))
2247 (*size)--, (*buffer)++;
2253 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2255 int write, void *data)
2259 if (*lvalp > (unsigned long) INT_MAX + 1)
2263 if (*lvalp > (unsigned long) INT_MAX)
2271 *lvalp = -(unsigned long)val;
2274 *lvalp = (unsigned long)val;
2280 static int do_proc_douintvec_conv(unsigned long *lvalp,
2282 int write, void *data)
2285 if (*lvalp > UINT_MAX)
2289 unsigned int val = *valp;
2290 *lvalp = (unsigned long)val;
2295 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2297 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2298 int write, void __user *buffer,
2299 size_t *lenp, loff_t *ppos,
2300 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2301 int write, void *data),
2304 int *i, vleft, first = 1, err = 0;
2306 char *kbuf = NULL, *p;
2308 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2313 i = (int *) tbl_data;
2314 vleft = table->maxlen / sizeof(*i);
2318 conv = do_proc_dointvec_conv;
2321 if (proc_first_pos_non_zero_ignore(ppos, table))
2324 if (left > PAGE_SIZE - 1)
2325 left = PAGE_SIZE - 1;
2326 p = kbuf = memdup_user_nul(buffer, left);
2328 return PTR_ERR(kbuf);
2331 for (; left && vleft--; i++, first=0) {
2336 left -= proc_skip_spaces(&p);
2340 err = proc_get_long(&p, &left, &lval, &neg,
2342 sizeof(proc_wspace_sep), NULL);
2345 if (conv(&neg, &lval, i, 1, data)) {
2350 if (conv(&neg, &lval, i, 0, data)) {
2355 err = proc_put_char(&buffer, &left, '\t');
2358 err = proc_put_long(&buffer, &left, lval, neg);
2364 if (!write && !first && left && !err)
2365 err = proc_put_char(&buffer, &left, '\n');
2366 if (write && !err && left)
2367 left -= proc_skip_spaces(&p);
2371 return err ? : -EINVAL;
2379 static int do_proc_dointvec(struct ctl_table *table, int write,
2380 void __user *buffer, size_t *lenp, loff_t *ppos,
2381 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2382 int write, void *data),
2385 return __do_proc_dointvec(table->data, table, write,
2386 buffer, lenp, ppos, conv, data);
2389 static int do_proc_douintvec_w(unsigned int *tbl_data,
2390 struct ctl_table *table,
2391 void __user *buffer,
2392 size_t *lenp, loff_t *ppos,
2393 int (*conv)(unsigned long *lvalp,
2395 int write, void *data),
2402 char *kbuf = NULL, *p;
2406 if (proc_first_pos_non_zero_ignore(ppos, table))
2409 if (left > PAGE_SIZE - 1)
2410 left = PAGE_SIZE - 1;
2412 p = kbuf = memdup_user_nul(buffer, left);
2416 left -= proc_skip_spaces(&p);
2422 err = proc_get_long(&p, &left, &lval, &neg,
2424 sizeof(proc_wspace_sep), NULL);
2430 if (conv(&lval, tbl_data, 1, data)) {
2436 left -= proc_skip_spaces(&p);
2445 /* This is in keeping with old __do_proc_dointvec() */
2451 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2452 size_t *lenp, loff_t *ppos,
2453 int (*conv)(unsigned long *lvalp,
2455 int write, void *data),
2464 if (conv(&lval, tbl_data, 0, data)) {
2469 err = proc_put_long(&buffer, &left, lval, false);
2473 err = proc_put_char(&buffer, &left, '\n');
2482 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2483 int write, void __user *buffer,
2484 size_t *lenp, loff_t *ppos,
2485 int (*conv)(unsigned long *lvalp,
2487 int write, void *data),
2490 unsigned int *i, vleft;
2492 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2497 i = (unsigned int *) tbl_data;
2498 vleft = table->maxlen / sizeof(*i);
2501 * Arrays are not supported, keep this simple. *Do not* add
2510 conv = do_proc_douintvec_conv;
2513 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2515 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2518 static int do_proc_douintvec(struct ctl_table *table, int write,
2519 void __user *buffer, size_t *lenp, loff_t *ppos,
2520 int (*conv)(unsigned long *lvalp,
2522 int write, void *data),
2525 return __do_proc_douintvec(table->data, table, write,
2526 buffer, lenp, ppos, conv, data);
2530 * proc_dointvec - read a vector of integers
2531 * @table: the sysctl table
2532 * @write: %TRUE if this is a write to the sysctl file
2533 * @buffer: the user buffer
2534 * @lenp: the size of the user buffer
2535 * @ppos: file position
2537 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2538 * values from/to the user buffer, treated as an ASCII string.
2540 * Returns 0 on success.
2542 int proc_dointvec(struct ctl_table *table, int write,
2543 void __user *buffer, size_t *lenp, loff_t *ppos)
2545 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2549 * proc_douintvec - read a vector of unsigned integers
2550 * @table: the sysctl table
2551 * @write: %TRUE if this is a write to the sysctl file
2552 * @buffer: the user buffer
2553 * @lenp: the size of the user buffer
2554 * @ppos: file position
2556 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2557 * values from/to the user buffer, treated as an ASCII string.
2559 * Returns 0 on success.
2561 int proc_douintvec(struct ctl_table *table, int write,
2562 void __user *buffer, size_t *lenp, loff_t *ppos)
2564 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2565 do_proc_douintvec_conv, NULL);
2569 * Taint values can only be increased
2570 * This means we can safely use a temporary.
2572 static int proc_taint(struct ctl_table *table, int write,
2573 void __user *buffer, size_t *lenp, loff_t *ppos)
2576 unsigned long tmptaint = get_taint();
2579 if (write && !capable(CAP_SYS_ADMIN))
2584 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2590 * Poor man's atomic or. Not worth adding a primitive
2591 * to everyone's atomic.h for this
2594 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2595 if ((tmptaint >> i) & 1)
2596 add_taint(i, LOCKDEP_STILL_OK);
2603 #ifdef CONFIG_PRINTK
2604 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2605 void __user *buffer, size_t *lenp, loff_t *ppos)
2607 if (write && !capable(CAP_SYS_ADMIN))
2610 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2615 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2616 * @min: pointer to minimum allowable value
2617 * @max: pointer to maximum allowable value
2619 * The do_proc_dointvec_minmax_conv_param structure provides the
2620 * minimum and maximum values for doing range checking for those sysctl
2621 * parameters that use the proc_dointvec_minmax() handler.
2623 struct do_proc_dointvec_minmax_conv_param {
2628 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2630 int write, void *data)
2632 struct do_proc_dointvec_minmax_conv_param *param = data;
2634 int val = *negp ? -*lvalp : *lvalp;
2635 if ((param->min && *param->min > val) ||
2636 (param->max && *param->max < val))
2643 *lvalp = -(unsigned long)val;
2646 *lvalp = (unsigned long)val;
2653 * proc_dointvec_minmax - read a vector of integers with min/max values
2654 * @table: the sysctl table
2655 * @write: %TRUE if this is a write to the sysctl file
2656 * @buffer: the user buffer
2657 * @lenp: the size of the user buffer
2658 * @ppos: file position
2660 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2661 * values from/to the user buffer, treated as an ASCII string.
2663 * This routine will ensure the values are within the range specified by
2664 * table->extra1 (min) and table->extra2 (max).
2666 * Returns 0 on success or -EINVAL on write when the range check fails.
2668 int proc_dointvec_minmax(struct ctl_table *table, int write,
2669 void __user *buffer, size_t *lenp, loff_t *ppos)
2671 struct do_proc_dointvec_minmax_conv_param param = {
2672 .min = (int *) table->extra1,
2673 .max = (int *) table->extra2,
2675 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2676 do_proc_dointvec_minmax_conv, ¶m);
2680 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2681 * @min: pointer to minimum allowable value
2682 * @max: pointer to maximum allowable value
2684 * The do_proc_douintvec_minmax_conv_param structure provides the
2685 * minimum and maximum values for doing range checking for those sysctl
2686 * parameters that use the proc_douintvec_minmax() handler.
2688 struct do_proc_douintvec_minmax_conv_param {
2693 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2695 int write, void *data)
2697 struct do_proc_douintvec_minmax_conv_param *param = data;
2700 unsigned int val = *lvalp;
2702 if (*lvalp > UINT_MAX)
2705 if ((param->min && *param->min > val) ||
2706 (param->max && *param->max < val))
2711 unsigned int val = *valp;
2712 *lvalp = (unsigned long) val;
2719 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2720 * @table: the sysctl table
2721 * @write: %TRUE if this is a write to the sysctl file
2722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
2724 * @ppos: file position
2726 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2727 * values from/to the user buffer, treated as an ASCII string. Negative
2728 * strings are not allowed.
2730 * This routine will ensure the values are within the range specified by
2731 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2732 * check for UINT_MAX to avoid having to support wrap around uses from
2735 * Returns 0 on success or -ERANGE on write when the range check fails.
2737 int proc_douintvec_minmax(struct ctl_table *table, int write,
2738 void __user *buffer, size_t *lenp, loff_t *ppos)
2740 struct do_proc_douintvec_minmax_conv_param param = {
2741 .min = (unsigned int *) table->extra1,
2742 .max = (unsigned int *) table->extra2,
2744 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2745 do_proc_douintvec_minmax_conv, ¶m);
2748 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2750 int write, void *data)
2755 val = round_pipe_size(*lvalp);
2761 unsigned int val = *valp;
2762 *lvalp = (unsigned long) val;
2768 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2769 void __user *buffer, size_t *lenp, loff_t *ppos)
2771 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2772 do_proc_dopipe_max_size_conv, NULL);
2775 static void validate_coredump_safety(void)
2777 #ifdef CONFIG_COREDUMP
2778 if (suid_dumpable == SUID_DUMP_ROOT &&
2779 core_pattern[0] != '/' && core_pattern[0] != '|') {
2781 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2782 "Pipe handler or fully qualified core dump path required.\n"
2783 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2789 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2790 void __user *buffer, size_t *lenp, loff_t *ppos)
2792 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2794 validate_coredump_safety();
2798 #ifdef CONFIG_COREDUMP
2799 static int proc_dostring_coredump(struct ctl_table *table, int write,
2800 void __user *buffer, size_t *lenp, loff_t *ppos)
2802 int error = proc_dostring(table, write, buffer, lenp, ppos);
2804 validate_coredump_safety();
2809 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2810 void __user *buffer,
2811 size_t *lenp, loff_t *ppos,
2812 unsigned long convmul,
2813 unsigned long convdiv)
2815 unsigned long *i, *min, *max;
2816 int vleft, first = 1, err = 0;
2818 char *kbuf = NULL, *p;
2820 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2825 i = (unsigned long *) data;
2826 min = (unsigned long *) table->extra1;
2827 max = (unsigned long *) table->extra2;
2828 vleft = table->maxlen / sizeof(unsigned long);
2832 if (proc_first_pos_non_zero_ignore(ppos, table))
2835 if (left > PAGE_SIZE - 1)
2836 left = PAGE_SIZE - 1;
2837 p = kbuf = memdup_user_nul(buffer, left);
2839 return PTR_ERR(kbuf);
2842 for (; left && vleft--; i++, first = 0) {
2848 left -= proc_skip_spaces(&p);
2852 err = proc_get_long(&p, &left, &val, &neg,
2854 sizeof(proc_wspace_sep), NULL);
2859 if ((max && val > *max) || (min && val < *min)) {
2863 val = convmul * val / convdiv;
2864 if ((min && val < *min) || (max && val > *max))
2868 val = convdiv * (*i) / convmul;
2870 err = proc_put_char(&buffer, &left, '\t');
2874 err = proc_put_long(&buffer, &left, val, false);
2880 if (!write && !first && left && !err)
2881 err = proc_put_char(&buffer, &left, '\n');
2883 left -= proc_skip_spaces(&p);
2887 return err ? : -EINVAL;
2895 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2896 void __user *buffer,
2897 size_t *lenp, loff_t *ppos,
2898 unsigned long convmul,
2899 unsigned long convdiv)
2901 return __do_proc_doulongvec_minmax(table->data, table, write,
2902 buffer, lenp, ppos, convmul, convdiv);
2906 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2907 * @table: the sysctl table
2908 * @write: %TRUE if this is a write to the sysctl file
2909 * @buffer: the user buffer
2910 * @lenp: the size of the user buffer
2911 * @ppos: file position
2913 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2914 * values from/to the user buffer, treated as an ASCII string.
2916 * This routine will ensure the values are within the range specified by
2917 * table->extra1 (min) and table->extra2 (max).
2919 * Returns 0 on success.
2921 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2922 void __user *buffer, size_t *lenp, loff_t *ppos)
2924 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2928 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2929 * @table: the sysctl table
2930 * @write: %TRUE if this is a write to the sysctl file
2931 * @buffer: the user buffer
2932 * @lenp: the size of the user buffer
2933 * @ppos: file position
2935 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2936 * values from/to the user buffer, treated as an ASCII string. The values
2937 * are treated as milliseconds, and converted to jiffies when they are stored.
2939 * This routine will ensure the values are within the range specified by
2940 * table->extra1 (min) and table->extra2 (max).
2942 * Returns 0 on success.
2944 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2945 void __user *buffer,
2946 size_t *lenp, loff_t *ppos)
2948 return do_proc_doulongvec_minmax(table, write, buffer,
2949 lenp, ppos, HZ, 1000l);
2953 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2955 int write, void *data)
2958 if (*lvalp > INT_MAX / HZ)
2960 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2966 lval = -(unsigned long)val;
2969 lval = (unsigned long)val;
2976 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2978 int write, void *data)
2981 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2983 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2989 lval = -(unsigned long)val;
2992 lval = (unsigned long)val;
2994 *lvalp = jiffies_to_clock_t(lval);
2999 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3001 int write, void *data)
3004 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3014 lval = -(unsigned long)val;
3017 lval = (unsigned long)val;
3019 *lvalp = jiffies_to_msecs(lval);
3025 * proc_dointvec_jiffies - read a vector of integers as seconds
3026 * @table: the sysctl table
3027 * @write: %TRUE if this is a write to the sysctl file
3028 * @buffer: the user buffer
3029 * @lenp: the size of the user buffer
3030 * @ppos: file position
3032 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3033 * values from/to the user buffer, treated as an ASCII string.
3034 * The values read are assumed to be in seconds, and are converted into
3037 * Returns 0 on success.
3039 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3040 void __user *buffer, size_t *lenp, loff_t *ppos)
3042 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3043 do_proc_dointvec_jiffies_conv,NULL);
3047 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3048 * @table: the sysctl table
3049 * @write: %TRUE if this is a write to the sysctl file
3050 * @buffer: the user buffer
3051 * @lenp: the size of the user buffer
3052 * @ppos: pointer to the file position
3054 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3055 * values from/to the user buffer, treated as an ASCII string.
3056 * The values read are assumed to be in 1/USER_HZ seconds, and
3057 * are converted into jiffies.
3059 * Returns 0 on success.
3061 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3062 void __user *buffer, size_t *lenp, loff_t *ppos)
3064 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3065 do_proc_dointvec_userhz_jiffies_conv,NULL);
3069 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3070 * @table: the sysctl table
3071 * @write: %TRUE if this is a write to the sysctl file
3072 * @buffer: the user buffer
3073 * @lenp: the size of the user buffer
3074 * @ppos: file position
3075 * @ppos: the current position in the file
3077 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3078 * values from/to the user buffer, treated as an ASCII string.
3079 * The values read are assumed to be in 1/1000 seconds, and
3080 * are converted into jiffies.
3082 * Returns 0 on success.
3084 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3085 void __user *buffer, size_t *lenp, loff_t *ppos)
3087 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3088 do_proc_dointvec_ms_jiffies_conv, NULL);
3091 static int proc_do_cad_pid(struct ctl_table *table, int write,
3092 void __user *buffer, size_t *lenp, loff_t *ppos)
3094 struct pid *new_pid;
3098 tmp = pid_vnr(cad_pid);
3100 r = __do_proc_dointvec(&tmp, table, write, buffer,
3101 lenp, ppos, NULL, NULL);
3105 new_pid = find_get_pid(tmp);
3109 put_pid(xchg(&cad_pid, new_pid));
3114 * proc_do_large_bitmap - read/write from/to a large bitmap
3115 * @table: the sysctl table
3116 * @write: %TRUE if this is a write to the sysctl file
3117 * @buffer: the user buffer
3118 * @lenp: the size of the user buffer
3119 * @ppos: file position
3121 * The bitmap is stored at table->data and the bitmap length (in bits)
3124 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3125 * large bitmaps may be represented in a compact manner. Writing into
3126 * the file will clear the bitmap then update it with the given input.
3128 * Returns 0 on success.
3130 int proc_do_large_bitmap(struct ctl_table *table, int write,
3131 void __user *buffer, size_t *lenp, loff_t *ppos)
3135 size_t left = *lenp;
3136 unsigned long bitmap_len = table->maxlen;
3137 unsigned long *bitmap = *(unsigned long **) table->data;
3138 unsigned long *tmp_bitmap = NULL;
3139 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3141 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3149 if (left > PAGE_SIZE - 1)
3150 left = PAGE_SIZE - 1;
3152 p = kbuf = memdup_user_nul(buffer, left);
3154 return PTR_ERR(kbuf);
3156 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3157 sizeof(unsigned long),
3163 proc_skip_char(&p, &left, '\n');
3164 while (!err && left) {
3165 unsigned long val_a, val_b;
3168 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3172 if (val_a >= bitmap_len || neg) {
3184 err = proc_get_long(&p, &left, &val_b,
3185 &neg, tr_b, sizeof(tr_b),
3189 if (val_b >= bitmap_len || neg ||
3200 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3202 proc_skip_char(&p, &left, '\n');
3206 unsigned long bit_a, bit_b = 0;
3209 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3210 if (bit_a >= bitmap_len)
3212 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3216 err = proc_put_char(&buffer, &left, ',');
3220 err = proc_put_long(&buffer, &left, bit_a, false);
3223 if (bit_a != bit_b) {
3224 err = proc_put_char(&buffer, &left, '-');
3227 err = proc_put_long(&buffer, &left, bit_b, false);
3235 err = proc_put_char(&buffer, &left, '\n');
3241 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3243 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3253 #else /* CONFIG_PROC_SYSCTL */
3255 int proc_dostring(struct ctl_table *table, int write,
3256 void __user *buffer, size_t *lenp, loff_t *ppos)
3261 int proc_dointvec(struct ctl_table *table, int write,
3262 void __user *buffer, size_t *lenp, loff_t *ppos)
3267 int proc_douintvec(struct ctl_table *table, int write,
3268 void __user *buffer, size_t *lenp, loff_t *ppos)
3273 int proc_dointvec_minmax(struct ctl_table *table, int write,
3274 void __user *buffer, size_t *lenp, loff_t *ppos)
3279 int proc_douintvec_minmax(struct ctl_table *table, int write,
3280 void __user *buffer, size_t *lenp, loff_t *ppos)
3285 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3286 void __user *buffer, size_t *lenp, loff_t *ppos)
3291 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3292 void __user *buffer, size_t *lenp, loff_t *ppos)
3297 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3298 void __user *buffer, size_t *lenp, loff_t *ppos)
3303 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3304 void __user *buffer, size_t *lenp, loff_t *ppos)
3309 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3310 void __user *buffer,
3311 size_t *lenp, loff_t *ppos)
3317 #endif /* CONFIG_PROC_SYSCTL */
3320 * No sense putting this after each symbol definition, twice,
3321 * exception granted :-)
3323 EXPORT_SYMBOL(proc_dointvec);
3324 EXPORT_SYMBOL(proc_douintvec);
3325 EXPORT_SYMBOL(proc_dointvec_jiffies);
3326 EXPORT_SYMBOL(proc_dointvec_minmax);
3327 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3328 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3329 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3330 EXPORT_SYMBOL(proc_dostring);
3331 EXPORT_SYMBOL(proc_doulongvec_minmax);
3332 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);