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);
227 #ifdef CONFIG_BPF_SYSCALL
228 static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp,
233 #ifdef CONFIG_MAGIC_SYSRQ
234 /* Note: sysrq code uses its own private copy */
235 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
237 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
238 void __user *buffer, size_t *lenp,
243 error = proc_dointvec(table, write, buffer, lenp, ppos);
248 sysrq_toggle_support(__sysrq_enabled);
255 static struct ctl_table kern_table[];
256 static struct ctl_table vm_table[];
257 static struct ctl_table fs_table[];
258 static struct ctl_table debug_table[];
259 static struct ctl_table dev_table[];
260 extern struct ctl_table random_table[];
262 extern struct ctl_table epoll_table[];
265 #ifdef CONFIG_FW_LOADER_USER_HELPER
266 extern struct ctl_table firmware_config_table[];
269 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
270 int sysctl_legacy_va_layout;
273 /* The default sysctl tables: */
275 static struct ctl_table sysctl_base_table[] = {
277 .procname = "kernel",
294 .child = debug_table,
304 #ifdef CONFIG_SCHED_DEBUG
305 static int min_sched_granularity_ns = 100000; /* 100 usecs */
306 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
307 static int min_wakeup_granularity_ns; /* 0 usecs */
308 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
310 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
311 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
312 #endif /* CONFIG_SMP */
313 #endif /* CONFIG_SCHED_DEBUG */
315 #ifdef CONFIG_COMPACTION
316 static int min_extfrag_threshold;
317 static int max_extfrag_threshold = 1000;
320 static struct ctl_table kern_table[] = {
322 .procname = "sched_child_runs_first",
323 .data = &sysctl_sched_child_runs_first,
324 .maxlen = sizeof(unsigned int),
326 .proc_handler = proc_dointvec,
328 #ifdef CONFIG_SCHED_DEBUG
330 .procname = "sched_min_granularity_ns",
331 .data = &sysctl_sched_min_granularity,
332 .maxlen = sizeof(unsigned int),
334 .proc_handler = sched_proc_update_handler,
335 .extra1 = &min_sched_granularity_ns,
336 .extra2 = &max_sched_granularity_ns,
339 .procname = "sched_latency_ns",
340 .data = &sysctl_sched_latency,
341 .maxlen = sizeof(unsigned int),
343 .proc_handler = sched_proc_update_handler,
344 .extra1 = &min_sched_granularity_ns,
345 .extra2 = &max_sched_granularity_ns,
348 .procname = "sched_wakeup_granularity_ns",
349 .data = &sysctl_sched_wakeup_granularity,
350 .maxlen = sizeof(unsigned int),
352 .proc_handler = sched_proc_update_handler,
353 .extra1 = &min_wakeup_granularity_ns,
354 .extra2 = &max_wakeup_granularity_ns,
358 .procname = "sched_tunable_scaling",
359 .data = &sysctl_sched_tunable_scaling,
360 .maxlen = sizeof(enum sched_tunable_scaling),
362 .proc_handler = sched_proc_update_handler,
363 .extra1 = &min_sched_tunable_scaling,
364 .extra2 = &max_sched_tunable_scaling,
367 .procname = "sched_migration_cost_ns",
368 .data = &sysctl_sched_migration_cost,
369 .maxlen = sizeof(unsigned int),
371 .proc_handler = proc_dointvec,
374 .procname = "sched_nr_migrate",
375 .data = &sysctl_sched_nr_migrate,
376 .maxlen = sizeof(unsigned int),
378 .proc_handler = proc_dointvec,
380 #ifdef CONFIG_SCHEDSTATS
382 .procname = "sched_schedstats",
384 .maxlen = sizeof(unsigned int),
386 .proc_handler = sysctl_schedstats,
390 #endif /* CONFIG_SCHEDSTATS */
391 #endif /* CONFIG_SMP */
392 #ifdef CONFIG_NUMA_BALANCING
394 .procname = "numa_balancing_scan_delay_ms",
395 .data = &sysctl_numa_balancing_scan_delay,
396 .maxlen = sizeof(unsigned int),
398 .proc_handler = proc_dointvec,
401 .procname = "numa_balancing_scan_period_min_ms",
402 .data = &sysctl_numa_balancing_scan_period_min,
403 .maxlen = sizeof(unsigned int),
405 .proc_handler = proc_dointvec,
408 .procname = "numa_balancing_scan_period_max_ms",
409 .data = &sysctl_numa_balancing_scan_period_max,
410 .maxlen = sizeof(unsigned int),
412 .proc_handler = proc_dointvec,
415 .procname = "numa_balancing_scan_size_mb",
416 .data = &sysctl_numa_balancing_scan_size,
417 .maxlen = sizeof(unsigned int),
419 .proc_handler = proc_dointvec_minmax,
423 .procname = "numa_balancing",
424 .data = NULL, /* filled in by handler */
425 .maxlen = sizeof(unsigned int),
427 .proc_handler = sysctl_numa_balancing,
431 #endif /* CONFIG_NUMA_BALANCING */
432 #endif /* CONFIG_SCHED_DEBUG */
434 .procname = "sched_rt_period_us",
435 .data = &sysctl_sched_rt_period,
436 .maxlen = sizeof(unsigned int),
438 .proc_handler = sched_rt_handler,
441 .procname = "sched_rt_runtime_us",
442 .data = &sysctl_sched_rt_runtime,
443 .maxlen = sizeof(int),
445 .proc_handler = sched_rt_handler,
448 .procname = "sched_rr_timeslice_ms",
449 .data = &sysctl_sched_rr_timeslice,
450 .maxlen = sizeof(int),
452 .proc_handler = sched_rr_handler,
454 #ifdef CONFIG_SCHED_AUTOGROUP
456 .procname = "sched_autogroup_enabled",
457 .data = &sysctl_sched_autogroup_enabled,
458 .maxlen = sizeof(unsigned int),
460 .proc_handler = proc_dointvec_minmax,
465 #ifdef CONFIG_CFS_BANDWIDTH
467 .procname = "sched_cfs_bandwidth_slice_us",
468 .data = &sysctl_sched_cfs_bandwidth_slice,
469 .maxlen = sizeof(unsigned int),
471 .proc_handler = proc_dointvec_minmax,
475 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
477 .procname = "sched_energy_aware",
478 .data = &sysctl_sched_energy_aware,
479 .maxlen = sizeof(unsigned int),
481 .proc_handler = sched_energy_aware_handler,
486 #ifdef CONFIG_PROVE_LOCKING
488 .procname = "prove_locking",
489 .data = &prove_locking,
490 .maxlen = sizeof(int),
492 .proc_handler = proc_dointvec,
495 #ifdef CONFIG_LOCK_STAT
497 .procname = "lock_stat",
499 .maxlen = sizeof(int),
501 .proc_handler = proc_dointvec,
506 .data = &panic_timeout,
507 .maxlen = sizeof(int),
509 .proc_handler = proc_dointvec,
511 #ifdef CONFIG_COREDUMP
513 .procname = "core_uses_pid",
514 .data = &core_uses_pid,
515 .maxlen = sizeof(int),
517 .proc_handler = proc_dointvec,
520 .procname = "core_pattern",
521 .data = core_pattern,
522 .maxlen = CORENAME_MAX_SIZE,
524 .proc_handler = proc_dostring_coredump,
527 .procname = "core_pipe_limit",
528 .data = &core_pipe_limit,
529 .maxlen = sizeof(unsigned int),
531 .proc_handler = proc_dointvec,
534 #ifdef CONFIG_PROC_SYSCTL
536 .procname = "tainted",
537 .maxlen = sizeof(long),
539 .proc_handler = proc_taint,
542 .procname = "sysctl_writes_strict",
543 .data = &sysctl_writes_strict,
544 .maxlen = sizeof(int),
546 .proc_handler = proc_dointvec_minmax,
551 #ifdef CONFIG_LATENCYTOP
553 .procname = "latencytop",
554 .data = &latencytop_enabled,
555 .maxlen = sizeof(int),
557 .proc_handler = sysctl_latencytop,
560 #ifdef CONFIG_BLK_DEV_INITRD
562 .procname = "real-root-dev",
563 .data = &real_root_dev,
564 .maxlen = sizeof(int),
566 .proc_handler = proc_dointvec,
570 .procname = "print-fatal-signals",
571 .data = &print_fatal_signals,
572 .maxlen = sizeof(int),
574 .proc_handler = proc_dointvec,
578 .procname = "reboot-cmd",
579 .data = reboot_command,
582 .proc_handler = proc_dostring,
585 .procname = "stop-a",
586 .data = &stop_a_enabled,
587 .maxlen = sizeof (int),
589 .proc_handler = proc_dointvec,
592 .procname = "scons-poweroff",
593 .data = &scons_pwroff,
594 .maxlen = sizeof (int),
596 .proc_handler = proc_dointvec,
599 #ifdef CONFIG_SPARC64
601 .procname = "tsb-ratio",
602 .data = &sysctl_tsb_ratio,
603 .maxlen = sizeof (int),
605 .proc_handler = proc_dointvec,
610 .procname = "soft-power",
611 .data = &pwrsw_enabled,
612 .maxlen = sizeof (int),
614 .proc_handler = proc_dointvec,
617 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
619 .procname = "unaligned-trap",
620 .data = &unaligned_enabled,
621 .maxlen = sizeof (int),
623 .proc_handler = proc_dointvec,
627 .procname = "ctrl-alt-del",
629 .maxlen = sizeof(int),
631 .proc_handler = proc_dointvec,
633 #ifdef CONFIG_FUNCTION_TRACER
635 .procname = "ftrace_enabled",
636 .data = &ftrace_enabled,
637 .maxlen = sizeof(int),
639 .proc_handler = ftrace_enable_sysctl,
642 #ifdef CONFIG_STACK_TRACER
644 .procname = "stack_tracer_enabled",
645 .data = &stack_tracer_enabled,
646 .maxlen = sizeof(int),
648 .proc_handler = stack_trace_sysctl,
651 #ifdef CONFIG_TRACING
653 .procname = "ftrace_dump_on_oops",
654 .data = &ftrace_dump_on_oops,
655 .maxlen = sizeof(int),
657 .proc_handler = proc_dointvec,
660 .procname = "traceoff_on_warning",
661 .data = &__disable_trace_on_warning,
662 .maxlen = sizeof(__disable_trace_on_warning),
664 .proc_handler = proc_dointvec,
667 .procname = "tracepoint_printk",
668 .data = &tracepoint_printk,
669 .maxlen = sizeof(tracepoint_printk),
671 .proc_handler = tracepoint_printk_sysctl,
674 #ifdef CONFIG_KEXEC_CORE
676 .procname = "kexec_load_disabled",
677 .data = &kexec_load_disabled,
678 .maxlen = sizeof(int),
680 /* only handle a transition from default "0" to "1" */
681 .proc_handler = proc_dointvec_minmax,
686 #ifdef CONFIG_MODULES
688 .procname = "modprobe",
689 .data = &modprobe_path,
690 .maxlen = KMOD_PATH_LEN,
692 .proc_handler = proc_dostring,
695 .procname = "modules_disabled",
696 .data = &modules_disabled,
697 .maxlen = sizeof(int),
699 /* only handle a transition from default "0" to "1" */
700 .proc_handler = proc_dointvec_minmax,
705 #ifdef CONFIG_UEVENT_HELPER
707 .procname = "hotplug",
708 .data = &uevent_helper,
709 .maxlen = UEVENT_HELPER_PATH_LEN,
711 .proc_handler = proc_dostring,
714 #ifdef CONFIG_CHR_DEV_SG
716 .procname = "sg-big-buff",
717 .data = &sg_big_buff,
718 .maxlen = sizeof (int),
720 .proc_handler = proc_dointvec,
723 #ifdef CONFIG_BSD_PROCESS_ACCT
727 .maxlen = 3*sizeof(int),
729 .proc_handler = proc_dointvec,
732 #ifdef CONFIG_MAGIC_SYSRQ
735 .data = &__sysrq_enabled,
736 .maxlen = sizeof (int),
738 .proc_handler = sysrq_sysctl_handler,
741 #ifdef CONFIG_PROC_SYSCTL
743 .procname = "cad_pid",
745 .maxlen = sizeof (int),
747 .proc_handler = proc_do_cad_pid,
751 .procname = "threads-max",
753 .maxlen = sizeof(int),
755 .proc_handler = sysctl_max_threads,
758 .procname = "random",
760 .child = random_table,
763 .procname = "usermodehelper",
765 .child = usermodehelper_table,
767 #ifdef CONFIG_FW_LOADER_USER_HELPER
769 .procname = "firmware_config",
771 .child = firmware_config_table,
775 .procname = "overflowuid",
776 .data = &overflowuid,
777 .maxlen = sizeof(int),
779 .proc_handler = proc_dointvec_minmax,
780 .extra1 = &minolduid,
781 .extra2 = &maxolduid,
784 .procname = "overflowgid",
785 .data = &overflowgid,
786 .maxlen = sizeof(int),
788 .proc_handler = proc_dointvec_minmax,
789 .extra1 = &minolduid,
790 .extra2 = &maxolduid,
793 #ifdef CONFIG_MATHEMU
795 .procname = "ieee_emulation_warnings",
796 .data = &sysctl_ieee_emulation_warnings,
797 .maxlen = sizeof(int),
799 .proc_handler = proc_dointvec,
803 .procname = "userprocess_debug",
804 .data = &show_unhandled_signals,
805 .maxlen = sizeof(int),
807 .proc_handler = proc_dointvec,
811 .procname = "pid_max",
813 .maxlen = sizeof (int),
815 .proc_handler = proc_dointvec_minmax,
816 .extra1 = &pid_max_min,
817 .extra2 = &pid_max_max,
820 .procname = "panic_on_oops",
821 .data = &panic_on_oops,
822 .maxlen = sizeof(int),
824 .proc_handler = proc_dointvec,
827 .procname = "panic_print",
828 .data = &panic_print,
829 .maxlen = sizeof(unsigned long),
831 .proc_handler = proc_doulongvec_minmax,
833 #if defined CONFIG_PRINTK
835 .procname = "printk",
836 .data = &console_loglevel,
837 .maxlen = 4*sizeof(int),
839 .proc_handler = proc_dointvec,
842 .procname = "printk_ratelimit",
843 .data = &printk_ratelimit_state.interval,
844 .maxlen = sizeof(int),
846 .proc_handler = proc_dointvec_jiffies,
849 .procname = "printk_ratelimit_burst",
850 .data = &printk_ratelimit_state.burst,
851 .maxlen = sizeof(int),
853 .proc_handler = proc_dointvec,
856 .procname = "printk_delay",
857 .data = &printk_delay_msec,
858 .maxlen = sizeof(int),
860 .proc_handler = proc_dointvec_minmax,
862 .extra2 = &ten_thousand,
865 .procname = "printk_devkmsg",
866 .data = devkmsg_log_str,
867 .maxlen = DEVKMSG_STR_MAX_SIZE,
869 .proc_handler = devkmsg_sysctl_set_loglvl,
872 .procname = "dmesg_restrict",
873 .data = &dmesg_restrict,
874 .maxlen = sizeof(int),
876 .proc_handler = proc_dointvec_minmax_sysadmin,
881 .procname = "kptr_restrict",
882 .data = &kptr_restrict,
883 .maxlen = sizeof(int),
885 .proc_handler = proc_dointvec_minmax_sysadmin,
891 .procname = "ngroups_max",
892 .data = &ngroups_max,
893 .maxlen = sizeof (int),
895 .proc_handler = proc_dointvec,
898 .procname = "cap_last_cap",
899 .data = (void *)&cap_last_cap,
900 .maxlen = sizeof(int),
902 .proc_handler = proc_dointvec,
904 #if defined(CONFIG_LOCKUP_DETECTOR)
906 .procname = "watchdog",
907 .data = &watchdog_user_enabled,
908 .maxlen = sizeof(int),
910 .proc_handler = proc_watchdog,
915 .procname = "watchdog_thresh",
916 .data = &watchdog_thresh,
917 .maxlen = sizeof(int),
919 .proc_handler = proc_watchdog_thresh,
924 .procname = "nmi_watchdog",
925 .data = &nmi_watchdog_user_enabled,
926 .maxlen = sizeof(int),
927 .mode = NMI_WATCHDOG_SYSCTL_PERM,
928 .proc_handler = proc_nmi_watchdog,
933 .procname = "watchdog_cpumask",
934 .data = &watchdog_cpumask_bits,
937 .proc_handler = proc_watchdog_cpumask,
939 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
941 .procname = "soft_watchdog",
942 .data = &soft_watchdog_user_enabled,
943 .maxlen = sizeof(int),
945 .proc_handler = proc_soft_watchdog,
950 .procname = "softlockup_panic",
951 .data = &softlockup_panic,
952 .maxlen = sizeof(int),
954 .proc_handler = proc_dointvec_minmax,
960 .procname = "softlockup_all_cpu_backtrace",
961 .data = &sysctl_softlockup_all_cpu_backtrace,
962 .maxlen = sizeof(int),
964 .proc_handler = proc_dointvec_minmax,
968 #endif /* CONFIG_SMP */
970 #ifdef CONFIG_HARDLOCKUP_DETECTOR
972 .procname = "hardlockup_panic",
973 .data = &hardlockup_panic,
974 .maxlen = sizeof(int),
976 .proc_handler = proc_dointvec_minmax,
982 .procname = "hardlockup_all_cpu_backtrace",
983 .data = &sysctl_hardlockup_all_cpu_backtrace,
984 .maxlen = sizeof(int),
986 .proc_handler = proc_dointvec_minmax,
990 #endif /* CONFIG_SMP */
994 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
996 .procname = "unknown_nmi_panic",
997 .data = &unknown_nmi_panic,
998 .maxlen = sizeof (int),
1000 .proc_handler = proc_dointvec,
1003 #if defined(CONFIG_X86)
1005 .procname = "panic_on_unrecovered_nmi",
1006 .data = &panic_on_unrecovered_nmi,
1007 .maxlen = sizeof(int),
1009 .proc_handler = proc_dointvec,
1012 .procname = "panic_on_io_nmi",
1013 .data = &panic_on_io_nmi,
1014 .maxlen = sizeof(int),
1016 .proc_handler = proc_dointvec,
1018 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1020 .procname = "panic_on_stackoverflow",
1021 .data = &sysctl_panic_on_stackoverflow,
1022 .maxlen = sizeof(int),
1024 .proc_handler = proc_dointvec,
1028 .procname = "bootloader_type",
1029 .data = &bootloader_type,
1030 .maxlen = sizeof (int),
1032 .proc_handler = proc_dointvec,
1035 .procname = "bootloader_version",
1036 .data = &bootloader_version,
1037 .maxlen = sizeof (int),
1039 .proc_handler = proc_dointvec,
1042 .procname = "io_delay_type",
1043 .data = &io_delay_type,
1044 .maxlen = sizeof(int),
1046 .proc_handler = proc_dointvec,
1049 #if defined(CONFIG_MMU)
1051 .procname = "randomize_va_space",
1052 .data = &randomize_va_space,
1053 .maxlen = sizeof(int),
1055 .proc_handler = proc_dointvec,
1058 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1060 .procname = "spin_retry",
1061 .data = &spin_retry,
1062 .maxlen = sizeof (int),
1064 .proc_handler = proc_dointvec,
1067 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1069 .procname = "acpi_video_flags",
1070 .data = &acpi_realmode_flags,
1071 .maxlen = sizeof (unsigned long),
1073 .proc_handler = proc_doulongvec_minmax,
1076 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1078 .procname = "ignore-unaligned-usertrap",
1079 .data = &no_unaligned_warning,
1080 .maxlen = sizeof (int),
1082 .proc_handler = proc_dointvec,
1087 .procname = "unaligned-dump-stack",
1088 .data = &unaligned_dump_stack,
1089 .maxlen = sizeof (int),
1091 .proc_handler = proc_dointvec,
1094 #ifdef CONFIG_DETECT_HUNG_TASK
1096 .procname = "hung_task_panic",
1097 .data = &sysctl_hung_task_panic,
1098 .maxlen = sizeof(int),
1100 .proc_handler = proc_dointvec_minmax,
1105 .procname = "hung_task_check_count",
1106 .data = &sysctl_hung_task_check_count,
1107 .maxlen = sizeof(int),
1109 .proc_handler = proc_dointvec_minmax,
1113 .procname = "hung_task_timeout_secs",
1114 .data = &sysctl_hung_task_timeout_secs,
1115 .maxlen = sizeof(unsigned long),
1117 .proc_handler = proc_dohung_task_timeout_secs,
1118 .extra2 = &hung_task_timeout_max,
1121 .procname = "hung_task_check_interval_secs",
1122 .data = &sysctl_hung_task_check_interval_secs,
1123 .maxlen = sizeof(unsigned long),
1125 .proc_handler = proc_dohung_task_timeout_secs,
1126 .extra2 = &hung_task_timeout_max,
1129 .procname = "hung_task_warnings",
1130 .data = &sysctl_hung_task_warnings,
1131 .maxlen = sizeof(int),
1133 .proc_handler = proc_dointvec_minmax,
1137 #ifdef CONFIG_RT_MUTEXES
1139 .procname = "max_lock_depth",
1140 .data = &max_lock_depth,
1141 .maxlen = sizeof(int),
1143 .proc_handler = proc_dointvec,
1147 .procname = "poweroff_cmd",
1148 .data = &poweroff_cmd,
1149 .maxlen = POWEROFF_CMD_PATH_LEN,
1151 .proc_handler = proc_dostring,
1157 .child = key_sysctls,
1160 #ifdef CONFIG_PERF_EVENTS
1162 * User-space scripts rely on the existence of this file
1163 * as a feature check for perf_events being enabled.
1165 * So it's an ABI, do not remove!
1168 .procname = "perf_event_paranoid",
1169 .data = &sysctl_perf_event_paranoid,
1170 .maxlen = sizeof(sysctl_perf_event_paranoid),
1172 .proc_handler = proc_dointvec,
1175 .procname = "perf_event_mlock_kb",
1176 .data = &sysctl_perf_event_mlock,
1177 .maxlen = sizeof(sysctl_perf_event_mlock),
1179 .proc_handler = proc_dointvec,
1182 .procname = "perf_event_max_sample_rate",
1183 .data = &sysctl_perf_event_sample_rate,
1184 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1186 .proc_handler = perf_proc_update_handler,
1190 .procname = "perf_cpu_time_max_percent",
1191 .data = &sysctl_perf_cpu_time_max_percent,
1192 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1194 .proc_handler = perf_cpu_time_max_percent_handler,
1196 .extra2 = &one_hundred,
1199 .procname = "perf_event_max_stack",
1200 .data = &sysctl_perf_event_max_stack,
1201 .maxlen = sizeof(sysctl_perf_event_max_stack),
1203 .proc_handler = perf_event_max_stack_handler,
1205 .extra2 = &six_hundred_forty_kb,
1208 .procname = "perf_event_max_contexts_per_stack",
1209 .data = &sysctl_perf_event_max_contexts_per_stack,
1210 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1212 .proc_handler = perf_event_max_stack_handler,
1214 .extra2 = &one_thousand,
1218 .procname = "panic_on_warn",
1219 .data = &panic_on_warn,
1220 .maxlen = sizeof(int),
1222 .proc_handler = proc_dointvec_minmax,
1226 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1228 .procname = "timer_migration",
1229 .data = &sysctl_timer_migration,
1230 .maxlen = sizeof(unsigned int),
1232 .proc_handler = timer_migration_handler,
1237 #ifdef CONFIG_BPF_SYSCALL
1239 .procname = "unprivileged_bpf_disabled",
1240 .data = &sysctl_unprivileged_bpf_disabled,
1241 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1243 /* only handle a transition from default "0" to "1" */
1244 .proc_handler = proc_dointvec_minmax,
1249 .procname = "bpf_stats_enabled",
1250 .data = &sysctl_bpf_stats_enabled,
1251 .maxlen = sizeof(sysctl_bpf_stats_enabled),
1253 .proc_handler = proc_dointvec_minmax_bpf_stats,
1258 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1260 .procname = "panic_on_rcu_stall",
1261 .data = &sysctl_panic_on_rcu_stall,
1262 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1264 .proc_handler = proc_dointvec_minmax,
1269 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1271 .procname = "stack_erasing",
1273 .maxlen = sizeof(int),
1275 .proc_handler = stack_erasing_sysctl,
1283 static struct ctl_table vm_table[] = {
1285 .procname = "overcommit_memory",
1286 .data = &sysctl_overcommit_memory,
1287 .maxlen = sizeof(sysctl_overcommit_memory),
1289 .proc_handler = proc_dointvec_minmax,
1294 .procname = "panic_on_oom",
1295 .data = &sysctl_panic_on_oom,
1296 .maxlen = sizeof(sysctl_panic_on_oom),
1298 .proc_handler = proc_dointvec_minmax,
1303 .procname = "oom_kill_allocating_task",
1304 .data = &sysctl_oom_kill_allocating_task,
1305 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1307 .proc_handler = proc_dointvec,
1310 .procname = "oom_dump_tasks",
1311 .data = &sysctl_oom_dump_tasks,
1312 .maxlen = sizeof(sysctl_oom_dump_tasks),
1314 .proc_handler = proc_dointvec,
1317 .procname = "overcommit_ratio",
1318 .data = &sysctl_overcommit_ratio,
1319 .maxlen = sizeof(sysctl_overcommit_ratio),
1321 .proc_handler = overcommit_ratio_handler,
1324 .procname = "overcommit_kbytes",
1325 .data = &sysctl_overcommit_kbytes,
1326 .maxlen = sizeof(sysctl_overcommit_kbytes),
1328 .proc_handler = overcommit_kbytes_handler,
1331 .procname = "page-cluster",
1332 .data = &page_cluster,
1333 .maxlen = sizeof(int),
1335 .proc_handler = proc_dointvec_minmax,
1339 .procname = "dirty_background_ratio",
1340 .data = &dirty_background_ratio,
1341 .maxlen = sizeof(dirty_background_ratio),
1343 .proc_handler = dirty_background_ratio_handler,
1345 .extra2 = &one_hundred,
1348 .procname = "dirty_background_bytes",
1349 .data = &dirty_background_bytes,
1350 .maxlen = sizeof(dirty_background_bytes),
1352 .proc_handler = dirty_background_bytes_handler,
1356 .procname = "dirty_ratio",
1357 .data = &vm_dirty_ratio,
1358 .maxlen = sizeof(vm_dirty_ratio),
1360 .proc_handler = dirty_ratio_handler,
1362 .extra2 = &one_hundred,
1365 .procname = "dirty_bytes",
1366 .data = &vm_dirty_bytes,
1367 .maxlen = sizeof(vm_dirty_bytes),
1369 .proc_handler = dirty_bytes_handler,
1370 .extra1 = &dirty_bytes_min,
1373 .procname = "dirty_writeback_centisecs",
1374 .data = &dirty_writeback_interval,
1375 .maxlen = sizeof(dirty_writeback_interval),
1377 .proc_handler = dirty_writeback_centisecs_handler,
1380 .procname = "dirty_expire_centisecs",
1381 .data = &dirty_expire_interval,
1382 .maxlen = sizeof(dirty_expire_interval),
1384 .proc_handler = proc_dointvec_minmax,
1388 .procname = "dirtytime_expire_seconds",
1389 .data = &dirtytime_expire_interval,
1390 .maxlen = sizeof(dirtytime_expire_interval),
1392 .proc_handler = dirtytime_interval_handler,
1396 .procname = "swappiness",
1397 .data = &vm_swappiness,
1398 .maxlen = sizeof(vm_swappiness),
1400 .proc_handler = proc_dointvec_minmax,
1402 .extra2 = &one_hundred,
1404 #ifdef CONFIG_HUGETLB_PAGE
1406 .procname = "nr_hugepages",
1408 .maxlen = sizeof(unsigned long),
1410 .proc_handler = hugetlb_sysctl_handler,
1414 .procname = "nr_hugepages_mempolicy",
1416 .maxlen = sizeof(unsigned long),
1418 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1421 .procname = "numa_stat",
1422 .data = &sysctl_vm_numa_stat,
1423 .maxlen = sizeof(int),
1425 .proc_handler = sysctl_vm_numa_stat_handler,
1431 .procname = "hugetlb_shm_group",
1432 .data = &sysctl_hugetlb_shm_group,
1433 .maxlen = sizeof(gid_t),
1435 .proc_handler = proc_dointvec,
1438 .procname = "nr_overcommit_hugepages",
1440 .maxlen = sizeof(unsigned long),
1442 .proc_handler = hugetlb_overcommit_handler,
1446 .procname = "lowmem_reserve_ratio",
1447 .data = &sysctl_lowmem_reserve_ratio,
1448 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1450 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1453 .procname = "drop_caches",
1454 .data = &sysctl_drop_caches,
1455 .maxlen = sizeof(int),
1457 .proc_handler = drop_caches_sysctl_handler,
1461 #ifdef CONFIG_COMPACTION
1463 .procname = "compact_memory",
1464 .data = &sysctl_compact_memory,
1465 .maxlen = sizeof(int),
1467 .proc_handler = sysctl_compaction_handler,
1470 .procname = "extfrag_threshold",
1471 .data = &sysctl_extfrag_threshold,
1472 .maxlen = sizeof(int),
1474 .proc_handler = proc_dointvec_minmax,
1475 .extra1 = &min_extfrag_threshold,
1476 .extra2 = &max_extfrag_threshold,
1479 .procname = "compact_unevictable_allowed",
1480 .data = &sysctl_compact_unevictable_allowed,
1481 .maxlen = sizeof(int),
1483 .proc_handler = proc_dointvec,
1488 #endif /* CONFIG_COMPACTION */
1490 .procname = "min_free_kbytes",
1491 .data = &min_free_kbytes,
1492 .maxlen = sizeof(min_free_kbytes),
1494 .proc_handler = min_free_kbytes_sysctl_handler,
1498 .procname = "watermark_boost_factor",
1499 .data = &watermark_boost_factor,
1500 .maxlen = sizeof(watermark_boost_factor),
1502 .proc_handler = watermark_boost_factor_sysctl_handler,
1506 .procname = "watermark_scale_factor",
1507 .data = &watermark_scale_factor,
1508 .maxlen = sizeof(watermark_scale_factor),
1510 .proc_handler = watermark_scale_factor_sysctl_handler,
1512 .extra2 = &one_thousand,
1515 .procname = "percpu_pagelist_fraction",
1516 .data = &percpu_pagelist_fraction,
1517 .maxlen = sizeof(percpu_pagelist_fraction),
1519 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1524 .procname = "max_map_count",
1525 .data = &sysctl_max_map_count,
1526 .maxlen = sizeof(sysctl_max_map_count),
1528 .proc_handler = proc_dointvec_minmax,
1533 .procname = "nr_trim_pages",
1534 .data = &sysctl_nr_trim_pages,
1535 .maxlen = sizeof(sysctl_nr_trim_pages),
1537 .proc_handler = proc_dointvec_minmax,
1542 .procname = "laptop_mode",
1543 .data = &laptop_mode,
1544 .maxlen = sizeof(laptop_mode),
1546 .proc_handler = proc_dointvec_jiffies,
1549 .procname = "block_dump",
1550 .data = &block_dump,
1551 .maxlen = sizeof(block_dump),
1553 .proc_handler = proc_dointvec,
1557 .procname = "vfs_cache_pressure",
1558 .data = &sysctl_vfs_cache_pressure,
1559 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1561 .proc_handler = proc_dointvec,
1564 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1566 .procname = "legacy_va_layout",
1567 .data = &sysctl_legacy_va_layout,
1568 .maxlen = sizeof(sysctl_legacy_va_layout),
1570 .proc_handler = proc_dointvec,
1576 .procname = "zone_reclaim_mode",
1577 .data = &node_reclaim_mode,
1578 .maxlen = sizeof(node_reclaim_mode),
1580 .proc_handler = proc_dointvec,
1584 .procname = "min_unmapped_ratio",
1585 .data = &sysctl_min_unmapped_ratio,
1586 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1588 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1590 .extra2 = &one_hundred,
1593 .procname = "min_slab_ratio",
1594 .data = &sysctl_min_slab_ratio,
1595 .maxlen = sizeof(sysctl_min_slab_ratio),
1597 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1599 .extra2 = &one_hundred,
1604 .procname = "stat_interval",
1605 .data = &sysctl_stat_interval,
1606 .maxlen = sizeof(sysctl_stat_interval),
1608 .proc_handler = proc_dointvec_jiffies,
1611 .procname = "stat_refresh",
1615 .proc_handler = vmstat_refresh,
1620 .procname = "mmap_min_addr",
1621 .data = &dac_mmap_min_addr,
1622 .maxlen = sizeof(unsigned long),
1624 .proc_handler = mmap_min_addr_handler,
1629 .procname = "numa_zonelist_order",
1630 .data = &numa_zonelist_order,
1631 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1633 .proc_handler = numa_zonelist_order_handler,
1636 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1637 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1639 .procname = "vdso_enabled",
1640 #ifdef CONFIG_X86_32
1641 .data = &vdso32_enabled,
1642 .maxlen = sizeof(vdso32_enabled),
1644 .data = &vdso_enabled,
1645 .maxlen = sizeof(vdso_enabled),
1648 .proc_handler = proc_dointvec,
1652 #ifdef CONFIG_HIGHMEM
1654 .procname = "highmem_is_dirtyable",
1655 .data = &vm_highmem_is_dirtyable,
1656 .maxlen = sizeof(vm_highmem_is_dirtyable),
1658 .proc_handler = proc_dointvec_minmax,
1663 #ifdef CONFIG_MEMORY_FAILURE
1665 .procname = "memory_failure_early_kill",
1666 .data = &sysctl_memory_failure_early_kill,
1667 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1669 .proc_handler = proc_dointvec_minmax,
1674 .procname = "memory_failure_recovery",
1675 .data = &sysctl_memory_failure_recovery,
1676 .maxlen = sizeof(sysctl_memory_failure_recovery),
1678 .proc_handler = proc_dointvec_minmax,
1684 .procname = "user_reserve_kbytes",
1685 .data = &sysctl_user_reserve_kbytes,
1686 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1688 .proc_handler = proc_doulongvec_minmax,
1691 .procname = "admin_reserve_kbytes",
1692 .data = &sysctl_admin_reserve_kbytes,
1693 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1695 .proc_handler = proc_doulongvec_minmax,
1697 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1699 .procname = "mmap_rnd_bits",
1700 .data = &mmap_rnd_bits,
1701 .maxlen = sizeof(mmap_rnd_bits),
1703 .proc_handler = proc_dointvec_minmax,
1704 .extra1 = (void *)&mmap_rnd_bits_min,
1705 .extra2 = (void *)&mmap_rnd_bits_max,
1708 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1710 .procname = "mmap_rnd_compat_bits",
1711 .data = &mmap_rnd_compat_bits,
1712 .maxlen = sizeof(mmap_rnd_compat_bits),
1714 .proc_handler = proc_dointvec_minmax,
1715 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1716 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1722 static struct ctl_table fs_table[] = {
1724 .procname = "inode-nr",
1725 .data = &inodes_stat,
1726 .maxlen = 2*sizeof(long),
1728 .proc_handler = proc_nr_inodes,
1731 .procname = "inode-state",
1732 .data = &inodes_stat,
1733 .maxlen = 7*sizeof(long),
1735 .proc_handler = proc_nr_inodes,
1738 .procname = "file-nr",
1739 .data = &files_stat,
1740 .maxlen = sizeof(files_stat),
1742 .proc_handler = proc_nr_files,
1745 .procname = "file-max",
1746 .data = &files_stat.max_files,
1747 .maxlen = sizeof(files_stat.max_files),
1749 .proc_handler = proc_doulongvec_minmax,
1752 .procname = "nr_open",
1753 .data = &sysctl_nr_open,
1754 .maxlen = sizeof(unsigned int),
1756 .proc_handler = proc_dointvec_minmax,
1757 .extra1 = &sysctl_nr_open_min,
1758 .extra2 = &sysctl_nr_open_max,
1761 .procname = "dentry-state",
1762 .data = &dentry_stat,
1763 .maxlen = 6*sizeof(long),
1765 .proc_handler = proc_nr_dentry,
1768 .procname = "overflowuid",
1769 .data = &fs_overflowuid,
1770 .maxlen = sizeof(int),
1772 .proc_handler = proc_dointvec_minmax,
1773 .extra1 = &minolduid,
1774 .extra2 = &maxolduid,
1777 .procname = "overflowgid",
1778 .data = &fs_overflowgid,
1779 .maxlen = sizeof(int),
1781 .proc_handler = proc_dointvec_minmax,
1782 .extra1 = &minolduid,
1783 .extra2 = &maxolduid,
1785 #ifdef CONFIG_FILE_LOCKING
1787 .procname = "leases-enable",
1788 .data = &leases_enable,
1789 .maxlen = sizeof(int),
1791 .proc_handler = proc_dointvec,
1794 #ifdef CONFIG_DNOTIFY
1796 .procname = "dir-notify-enable",
1797 .data = &dir_notify_enable,
1798 .maxlen = sizeof(int),
1800 .proc_handler = proc_dointvec,
1804 #ifdef CONFIG_FILE_LOCKING
1806 .procname = "lease-break-time",
1807 .data = &lease_break_time,
1808 .maxlen = sizeof(int),
1810 .proc_handler = proc_dointvec,
1815 .procname = "aio-nr",
1817 .maxlen = sizeof(aio_nr),
1819 .proc_handler = proc_doulongvec_minmax,
1822 .procname = "aio-max-nr",
1823 .data = &aio_max_nr,
1824 .maxlen = sizeof(aio_max_nr),
1826 .proc_handler = proc_doulongvec_minmax,
1828 #endif /* CONFIG_AIO */
1829 #ifdef CONFIG_INOTIFY_USER
1831 .procname = "inotify",
1833 .child = inotify_table,
1838 .procname = "epoll",
1840 .child = epoll_table,
1845 .procname = "protected_symlinks",
1846 .data = &sysctl_protected_symlinks,
1847 .maxlen = sizeof(int),
1849 .proc_handler = proc_dointvec_minmax,
1854 .procname = "protected_hardlinks",
1855 .data = &sysctl_protected_hardlinks,
1856 .maxlen = sizeof(int),
1858 .proc_handler = proc_dointvec_minmax,
1863 .procname = "protected_fifos",
1864 .data = &sysctl_protected_fifos,
1865 .maxlen = sizeof(int),
1867 .proc_handler = proc_dointvec_minmax,
1872 .procname = "protected_regular",
1873 .data = &sysctl_protected_regular,
1874 .maxlen = sizeof(int),
1876 .proc_handler = proc_dointvec_minmax,
1881 .procname = "suid_dumpable",
1882 .data = &suid_dumpable,
1883 .maxlen = sizeof(int),
1885 .proc_handler = proc_dointvec_minmax_coredump,
1889 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1891 .procname = "binfmt_misc",
1893 .child = sysctl_mount_point,
1897 .procname = "pipe-max-size",
1898 .data = &pipe_max_size,
1899 .maxlen = sizeof(pipe_max_size),
1901 .proc_handler = proc_dopipe_max_size,
1904 .procname = "pipe-user-pages-hard",
1905 .data = &pipe_user_pages_hard,
1906 .maxlen = sizeof(pipe_user_pages_hard),
1908 .proc_handler = proc_doulongvec_minmax,
1911 .procname = "pipe-user-pages-soft",
1912 .data = &pipe_user_pages_soft,
1913 .maxlen = sizeof(pipe_user_pages_soft),
1915 .proc_handler = proc_doulongvec_minmax,
1918 .procname = "mount-max",
1919 .data = &sysctl_mount_max,
1920 .maxlen = sizeof(unsigned int),
1922 .proc_handler = proc_dointvec_minmax,
1928 static struct ctl_table debug_table[] = {
1929 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1931 .procname = "exception-trace",
1932 .data = &show_unhandled_signals,
1933 .maxlen = sizeof(int),
1935 .proc_handler = proc_dointvec
1938 #if defined(CONFIG_OPTPROBES)
1940 .procname = "kprobes-optimization",
1941 .data = &sysctl_kprobes_optimization,
1942 .maxlen = sizeof(int),
1944 .proc_handler = proc_kprobes_optimization_handler,
1952 static struct ctl_table dev_table[] = {
1956 int __init sysctl_init(void)
1958 struct ctl_table_header *hdr;
1960 hdr = register_sysctl_table(sysctl_base_table);
1961 kmemleak_not_leak(hdr);
1965 #endif /* CONFIG_SYSCTL */
1971 #ifdef CONFIG_PROC_SYSCTL
1973 static int _proc_do_string(char *data, int maxlen, int write,
1974 char __user *buffer,
1975 size_t *lenp, loff_t *ppos)
1981 if (!data || !maxlen || !*lenp) {
1987 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1988 /* Only continue writes not past the end of buffer. */
1990 if (len > maxlen - 1)
1997 /* Start writing from beginning of buffer. */
2003 while ((p - buffer) < *lenp && len < maxlen - 1) {
2004 if (get_user(c, p++))
2006 if (c == 0 || c == '\n')
2027 if (copy_to_user(buffer, data, len))
2030 if (put_user('\n', buffer + len))
2040 static void warn_sysctl_write(struct ctl_table *table)
2042 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2043 "This will not be supported in the future. To silence this\n"
2044 "warning, set kernel.sysctl_writes_strict = -1\n",
2045 current->comm, table->procname);
2049 * proc_first_pos_non_zero_ignore - check if first position is allowed
2050 * @ppos: file position
2051 * @table: the sysctl table
2053 * Returns true if the first position is non-zero and the sysctl_writes_strict
2054 * mode indicates this is not allowed for numeric input types. String proc
2055 * handlers can ignore the return value.
2057 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2058 struct ctl_table *table)
2063 switch (sysctl_writes_strict) {
2064 case SYSCTL_WRITES_STRICT:
2066 case SYSCTL_WRITES_WARN:
2067 warn_sysctl_write(table);
2075 * proc_dostring - read a string sysctl
2076 * @table: the sysctl table
2077 * @write: %TRUE if this is a write to the sysctl file
2078 * @buffer: the user buffer
2079 * @lenp: the size of the user buffer
2080 * @ppos: file position
2082 * Reads/writes a string from/to the user buffer. If the kernel
2083 * buffer provided is not large enough to hold the string, the
2084 * string is truncated. The copied string is %NULL-terminated.
2085 * If the string is being read by the user process, it is copied
2086 * and a newline '\n' is added. It is truncated if the buffer is
2089 * Returns 0 on success.
2091 int proc_dostring(struct ctl_table *table, int write,
2092 void __user *buffer, size_t *lenp, loff_t *ppos)
2095 proc_first_pos_non_zero_ignore(ppos, table);
2097 return _proc_do_string((char *)(table->data), table->maxlen, write,
2098 (char __user *)buffer, lenp, ppos);
2101 static size_t proc_skip_spaces(char **buf)
2104 char *tmp = skip_spaces(*buf);
2110 static void proc_skip_char(char **buf, size_t *size, const char v)
2120 #define TMPBUFLEN 22
2122 * proc_get_long - reads an ASCII formatted integer from a user buffer
2124 * @buf: a kernel buffer
2125 * @size: size of the kernel buffer
2126 * @val: this is where the number will be stored
2127 * @neg: set to %TRUE if number is negative
2128 * @perm_tr: a vector which contains the allowed trailers
2129 * @perm_tr_len: size of the perm_tr vector
2130 * @tr: pointer to store the trailer character
2132 * In case of success %0 is returned and @buf and @size are updated with
2133 * the amount of bytes read. If @tr is non-NULL and a trailing
2134 * character exists (size is non-zero after returning from this
2135 * function), @tr is updated with the trailing character.
2137 static int proc_get_long(char **buf, size_t *size,
2138 unsigned long *val, bool *neg,
2139 const char *perm_tr, unsigned perm_tr_len, char *tr)
2142 char *p, tmp[TMPBUFLEN];
2148 if (len > TMPBUFLEN - 1)
2149 len = TMPBUFLEN - 1;
2151 memcpy(tmp, *buf, len);
2155 if (*p == '-' && *size > 1) {
2163 *val = simple_strtoul(p, &p, 0);
2167 /* We don't know if the next char is whitespace thus we may accept
2168 * invalid integers (e.g. 1234...a) or two integers instead of one
2169 * (e.g. 123...1). So lets not allow such large numbers. */
2170 if (len == TMPBUFLEN - 1)
2173 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2176 if (tr && (len < *size))
2186 * proc_put_long - converts an integer to a decimal ASCII formatted string
2188 * @buf: the user buffer
2189 * @size: the size of the user buffer
2190 * @val: the integer to be converted
2191 * @neg: sign of the number, %TRUE for negative
2193 * In case of success %0 is returned and @buf and @size are updated with
2194 * the amount of bytes written.
2196 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2200 char tmp[TMPBUFLEN], *p = tmp;
2202 sprintf(p, "%s%lu", neg ? "-" : "", val);
2206 if (copy_to_user(*buf, tmp, len))
2214 static int proc_put_char(void __user **buf, size_t *size, char c)
2217 char __user **buffer = (char __user **)buf;
2218 if (put_user(c, *buffer))
2220 (*size)--, (*buffer)++;
2226 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2228 int write, void *data)
2232 if (*lvalp > (unsigned long) INT_MAX + 1)
2236 if (*lvalp > (unsigned long) INT_MAX)
2244 *lvalp = -(unsigned long)val;
2247 *lvalp = (unsigned long)val;
2253 static int do_proc_douintvec_conv(unsigned long *lvalp,
2255 int write, void *data)
2258 if (*lvalp > UINT_MAX)
2262 unsigned int val = *valp;
2263 *lvalp = (unsigned long)val;
2268 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2270 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2271 int write, void __user *buffer,
2272 size_t *lenp, loff_t *ppos,
2273 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2274 int write, void *data),
2277 int *i, vleft, first = 1, err = 0;
2279 char *kbuf = NULL, *p;
2281 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2286 i = (int *) tbl_data;
2287 vleft = table->maxlen / sizeof(*i);
2291 conv = do_proc_dointvec_conv;
2294 if (proc_first_pos_non_zero_ignore(ppos, table))
2297 if (left > PAGE_SIZE - 1)
2298 left = PAGE_SIZE - 1;
2299 p = kbuf = memdup_user_nul(buffer, left);
2301 return PTR_ERR(kbuf);
2304 for (; left && vleft--; i++, first=0) {
2309 left -= proc_skip_spaces(&p);
2313 err = proc_get_long(&p, &left, &lval, &neg,
2315 sizeof(proc_wspace_sep), NULL);
2318 if (conv(&neg, &lval, i, 1, data)) {
2323 if (conv(&neg, &lval, i, 0, data)) {
2328 err = proc_put_char(&buffer, &left, '\t');
2331 err = proc_put_long(&buffer, &left, lval, neg);
2337 if (!write && !first && left && !err)
2338 err = proc_put_char(&buffer, &left, '\n');
2339 if (write && !err && left)
2340 left -= proc_skip_spaces(&p);
2344 return err ? : -EINVAL;
2352 static int do_proc_dointvec(struct ctl_table *table, int write,
2353 void __user *buffer, size_t *lenp, loff_t *ppos,
2354 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2355 int write, void *data),
2358 return __do_proc_dointvec(table->data, table, write,
2359 buffer, lenp, ppos, conv, data);
2362 static int do_proc_douintvec_w(unsigned int *tbl_data,
2363 struct ctl_table *table,
2364 void __user *buffer,
2365 size_t *lenp, loff_t *ppos,
2366 int (*conv)(unsigned long *lvalp,
2368 int write, void *data),
2375 char *kbuf = NULL, *p;
2379 if (proc_first_pos_non_zero_ignore(ppos, table))
2382 if (left > PAGE_SIZE - 1)
2383 left = PAGE_SIZE - 1;
2385 p = kbuf = memdup_user_nul(buffer, left);
2389 left -= proc_skip_spaces(&p);
2395 err = proc_get_long(&p, &left, &lval, &neg,
2397 sizeof(proc_wspace_sep), NULL);
2403 if (conv(&lval, tbl_data, 1, data)) {
2409 left -= proc_skip_spaces(&p);
2418 /* This is in keeping with old __do_proc_dointvec() */
2424 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2425 size_t *lenp, loff_t *ppos,
2426 int (*conv)(unsigned long *lvalp,
2428 int write, void *data),
2437 if (conv(&lval, tbl_data, 0, data)) {
2442 err = proc_put_long(&buffer, &left, lval, false);
2446 err = proc_put_char(&buffer, &left, '\n');
2455 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2456 int write, void __user *buffer,
2457 size_t *lenp, loff_t *ppos,
2458 int (*conv)(unsigned long *lvalp,
2460 int write, void *data),
2463 unsigned int *i, vleft;
2465 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2470 i = (unsigned int *) tbl_data;
2471 vleft = table->maxlen / sizeof(*i);
2474 * Arrays are not supported, keep this simple. *Do not* add
2483 conv = do_proc_douintvec_conv;
2486 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2488 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2491 static int do_proc_douintvec(struct ctl_table *table, int write,
2492 void __user *buffer, size_t *lenp, loff_t *ppos,
2493 int (*conv)(unsigned long *lvalp,
2495 int write, void *data),
2498 return __do_proc_douintvec(table->data, table, write,
2499 buffer, lenp, ppos, conv, data);
2503 * proc_dointvec - read a vector of integers
2504 * @table: the sysctl table
2505 * @write: %TRUE if this is a write to the sysctl file
2506 * @buffer: the user buffer
2507 * @lenp: the size of the user buffer
2508 * @ppos: file position
2510 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2511 * values from/to the user buffer, treated as an ASCII string.
2513 * Returns 0 on success.
2515 int proc_dointvec(struct ctl_table *table, int write,
2516 void __user *buffer, size_t *lenp, loff_t *ppos)
2518 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2522 * proc_douintvec - read a vector of unsigned integers
2523 * @table: the sysctl table
2524 * @write: %TRUE if this is a write to the sysctl file
2525 * @buffer: the user buffer
2526 * @lenp: the size of the user buffer
2527 * @ppos: file position
2529 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2530 * values from/to the user buffer, treated as an ASCII string.
2532 * Returns 0 on success.
2534 int proc_douintvec(struct ctl_table *table, int write,
2535 void __user *buffer, size_t *lenp, loff_t *ppos)
2537 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2538 do_proc_douintvec_conv, NULL);
2542 * Taint values can only be increased
2543 * This means we can safely use a temporary.
2545 static int proc_taint(struct ctl_table *table, int write,
2546 void __user *buffer, size_t *lenp, loff_t *ppos)
2549 unsigned long tmptaint = get_taint();
2552 if (write && !capable(CAP_SYS_ADMIN))
2557 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2563 * Poor man's atomic or. Not worth adding a primitive
2564 * to everyone's atomic.h for this
2567 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2568 if ((tmptaint >> i) & 1)
2569 add_taint(i, LOCKDEP_STILL_OK);
2576 #ifdef CONFIG_PRINTK
2577 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2578 void __user *buffer, size_t *lenp, loff_t *ppos)
2580 if (write && !capable(CAP_SYS_ADMIN))
2583 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2588 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2589 * @min: pointer to minimum allowable value
2590 * @max: pointer to maximum allowable value
2592 * The do_proc_dointvec_minmax_conv_param structure provides the
2593 * minimum and maximum values for doing range checking for those sysctl
2594 * parameters that use the proc_dointvec_minmax() handler.
2596 struct do_proc_dointvec_minmax_conv_param {
2601 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2603 int write, void *data)
2605 struct do_proc_dointvec_minmax_conv_param *param = data;
2607 int val = *negp ? -*lvalp : *lvalp;
2608 if ((param->min && *param->min > val) ||
2609 (param->max && *param->max < val))
2616 *lvalp = -(unsigned long)val;
2619 *lvalp = (unsigned long)val;
2626 * proc_dointvec_minmax - read a vector of integers with min/max values
2627 * @table: the sysctl table
2628 * @write: %TRUE if this is a write to the sysctl file
2629 * @buffer: the user buffer
2630 * @lenp: the size of the user buffer
2631 * @ppos: file position
2633 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2634 * values from/to the user buffer, treated as an ASCII string.
2636 * This routine will ensure the values are within the range specified by
2637 * table->extra1 (min) and table->extra2 (max).
2639 * Returns 0 on success or -EINVAL on write when the range check fails.
2641 int proc_dointvec_minmax(struct ctl_table *table, int write,
2642 void __user *buffer, size_t *lenp, loff_t *ppos)
2644 struct do_proc_dointvec_minmax_conv_param param = {
2645 .min = (int *) table->extra1,
2646 .max = (int *) table->extra2,
2648 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2649 do_proc_dointvec_minmax_conv, ¶m);
2653 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2654 * @min: pointer to minimum allowable value
2655 * @max: pointer to maximum allowable value
2657 * The do_proc_douintvec_minmax_conv_param structure provides the
2658 * minimum and maximum values for doing range checking for those sysctl
2659 * parameters that use the proc_douintvec_minmax() handler.
2661 struct do_proc_douintvec_minmax_conv_param {
2666 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2668 int write, void *data)
2670 struct do_proc_douintvec_minmax_conv_param *param = data;
2673 unsigned int val = *lvalp;
2675 if (*lvalp > UINT_MAX)
2678 if ((param->min && *param->min > val) ||
2679 (param->max && *param->max < val))
2684 unsigned int val = *valp;
2685 *lvalp = (unsigned long) val;
2692 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2693 * @table: the sysctl table
2694 * @write: %TRUE if this is a write to the sysctl file
2695 * @buffer: the user buffer
2696 * @lenp: the size of the user buffer
2697 * @ppos: file position
2699 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2700 * values from/to the user buffer, treated as an ASCII string. Negative
2701 * strings are not allowed.
2703 * This routine will ensure the values are within the range specified by
2704 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2705 * check for UINT_MAX to avoid having to support wrap around uses from
2708 * Returns 0 on success or -ERANGE on write when the range check fails.
2710 int proc_douintvec_minmax(struct ctl_table *table, int write,
2711 void __user *buffer, size_t *lenp, loff_t *ppos)
2713 struct do_proc_douintvec_minmax_conv_param param = {
2714 .min = (unsigned int *) table->extra1,
2715 .max = (unsigned int *) table->extra2,
2717 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2718 do_proc_douintvec_minmax_conv, ¶m);
2721 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2723 int write, void *data)
2728 val = round_pipe_size(*lvalp);
2734 unsigned int val = *valp;
2735 *lvalp = (unsigned long) val;
2741 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2742 void __user *buffer, size_t *lenp, loff_t *ppos)
2744 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2745 do_proc_dopipe_max_size_conv, NULL);
2748 static void validate_coredump_safety(void)
2750 #ifdef CONFIG_COREDUMP
2751 if (suid_dumpable == SUID_DUMP_ROOT &&
2752 core_pattern[0] != '/' && core_pattern[0] != '|') {
2754 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2755 "Pipe handler or fully qualified core dump path required.\n"
2756 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2762 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2763 void __user *buffer, size_t *lenp, loff_t *ppos)
2765 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2767 validate_coredump_safety();
2771 #ifdef CONFIG_COREDUMP
2772 static int proc_dostring_coredump(struct ctl_table *table, int write,
2773 void __user *buffer, size_t *lenp, loff_t *ppos)
2775 int error = proc_dostring(table, write, buffer, lenp, ppos);
2777 validate_coredump_safety();
2782 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2783 void __user *buffer,
2784 size_t *lenp, loff_t *ppos,
2785 unsigned long convmul,
2786 unsigned long convdiv)
2788 unsigned long *i, *min, *max;
2789 int vleft, first = 1, err = 0;
2791 char *kbuf = NULL, *p;
2793 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2798 i = (unsigned long *) data;
2799 min = (unsigned long *) table->extra1;
2800 max = (unsigned long *) table->extra2;
2801 vleft = table->maxlen / sizeof(unsigned long);
2805 if (proc_first_pos_non_zero_ignore(ppos, table))
2808 if (left > PAGE_SIZE - 1)
2809 left = PAGE_SIZE - 1;
2810 p = kbuf = memdup_user_nul(buffer, left);
2812 return PTR_ERR(kbuf);
2815 for (; left && vleft--; i++, first = 0) {
2821 left -= proc_skip_spaces(&p);
2825 err = proc_get_long(&p, &left, &val, &neg,
2827 sizeof(proc_wspace_sep), NULL);
2832 val = convmul * val / convdiv;
2833 if ((min && val < *min) || (max && val > *max))
2837 val = convdiv * (*i) / convmul;
2839 err = proc_put_char(&buffer, &left, '\t');
2843 err = proc_put_long(&buffer, &left, val, false);
2849 if (!write && !first && left && !err)
2850 err = proc_put_char(&buffer, &left, '\n');
2852 left -= proc_skip_spaces(&p);
2856 return err ? : -EINVAL;
2864 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2865 void __user *buffer,
2866 size_t *lenp, loff_t *ppos,
2867 unsigned long convmul,
2868 unsigned long convdiv)
2870 return __do_proc_doulongvec_minmax(table->data, table, write,
2871 buffer, lenp, ppos, convmul, convdiv);
2875 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2876 * @table: the sysctl table
2877 * @write: %TRUE if this is a write to the sysctl file
2878 * @buffer: the user buffer
2879 * @lenp: the size of the user buffer
2880 * @ppos: file position
2882 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2883 * values from/to the user buffer, treated as an ASCII string.
2885 * This routine will ensure the values are within the range specified by
2886 * table->extra1 (min) and table->extra2 (max).
2888 * Returns 0 on success.
2890 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2891 void __user *buffer, size_t *lenp, loff_t *ppos)
2893 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2897 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2898 * @table: the sysctl table
2899 * @write: %TRUE if this is a write to the sysctl file
2900 * @buffer: the user buffer
2901 * @lenp: the size of the user buffer
2902 * @ppos: file position
2904 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2905 * values from/to the user buffer, treated as an ASCII string. The values
2906 * are treated as milliseconds, and converted to jiffies when they are stored.
2908 * This routine will ensure the values are within the range specified by
2909 * table->extra1 (min) and table->extra2 (max).
2911 * Returns 0 on success.
2913 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2914 void __user *buffer,
2915 size_t *lenp, loff_t *ppos)
2917 return do_proc_doulongvec_minmax(table, write, buffer,
2918 lenp, ppos, HZ, 1000l);
2922 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2924 int write, void *data)
2927 if (*lvalp > INT_MAX / HZ)
2929 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2935 lval = -(unsigned long)val;
2938 lval = (unsigned long)val;
2945 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2947 int write, void *data)
2950 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2952 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2958 lval = -(unsigned long)val;
2961 lval = (unsigned long)val;
2963 *lvalp = jiffies_to_clock_t(lval);
2968 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2970 int write, void *data)
2973 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2983 lval = -(unsigned long)val;
2986 lval = (unsigned long)val;
2988 *lvalp = jiffies_to_msecs(lval);
2994 * proc_dointvec_jiffies - read a vector of integers as seconds
2995 * @table: the sysctl table
2996 * @write: %TRUE if this is a write to the sysctl file
2997 * @buffer: the user buffer
2998 * @lenp: the size of the user buffer
2999 * @ppos: file position
3001 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3002 * values from/to the user buffer, treated as an ASCII string.
3003 * The values read are assumed to be in seconds, and are converted into
3006 * Returns 0 on success.
3008 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3009 void __user *buffer, size_t *lenp, loff_t *ppos)
3011 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3012 do_proc_dointvec_jiffies_conv,NULL);
3016 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3017 * @table: the sysctl table
3018 * @write: %TRUE if this is a write to the sysctl file
3019 * @buffer: the user buffer
3020 * @lenp: the size of the user buffer
3021 * @ppos: pointer to the file position
3023 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3024 * values from/to the user buffer, treated as an ASCII string.
3025 * The values read are assumed to be in 1/USER_HZ seconds, and
3026 * are converted into jiffies.
3028 * Returns 0 on success.
3030 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3031 void __user *buffer, size_t *lenp, loff_t *ppos)
3033 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3034 do_proc_dointvec_userhz_jiffies_conv,NULL);
3038 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3039 * @table: the sysctl table
3040 * @write: %TRUE if this is a write to the sysctl file
3041 * @buffer: the user buffer
3042 * @lenp: the size of the user buffer
3043 * @ppos: file position
3044 * @ppos: the current position in the file
3046 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3047 * values from/to the user buffer, treated as an ASCII string.
3048 * The values read are assumed to be in 1/1000 seconds, and
3049 * are converted into jiffies.
3051 * Returns 0 on success.
3053 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3054 void __user *buffer, size_t *lenp, loff_t *ppos)
3056 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3057 do_proc_dointvec_ms_jiffies_conv, NULL);
3060 static int proc_do_cad_pid(struct ctl_table *table, int write,
3061 void __user *buffer, size_t *lenp, loff_t *ppos)
3063 struct pid *new_pid;
3067 tmp = pid_vnr(cad_pid);
3069 r = __do_proc_dointvec(&tmp, table, write, buffer,
3070 lenp, ppos, NULL, NULL);
3074 new_pid = find_get_pid(tmp);
3078 put_pid(xchg(&cad_pid, new_pid));
3083 * proc_do_large_bitmap - read/write from/to a large bitmap
3084 * @table: the sysctl table
3085 * @write: %TRUE if this is a write to the sysctl file
3086 * @buffer: the user buffer
3087 * @lenp: the size of the user buffer
3088 * @ppos: file position
3090 * The bitmap is stored at table->data and the bitmap length (in bits)
3093 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3094 * large bitmaps may be represented in a compact manner. Writing into
3095 * the file will clear the bitmap then update it with the given input.
3097 * Returns 0 on success.
3099 int proc_do_large_bitmap(struct ctl_table *table, int write,
3100 void __user *buffer, size_t *lenp, loff_t *ppos)
3104 size_t left = *lenp;
3105 unsigned long bitmap_len = table->maxlen;
3106 unsigned long *bitmap = *(unsigned long **) table->data;
3107 unsigned long *tmp_bitmap = NULL;
3108 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3110 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3118 if (left > PAGE_SIZE - 1)
3119 left = PAGE_SIZE - 1;
3121 p = kbuf = memdup_user_nul(buffer, left);
3123 return PTR_ERR(kbuf);
3125 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3126 sizeof(unsigned long),
3132 proc_skip_char(&p, &left, '\n');
3133 while (!err && left) {
3134 unsigned long val_a, val_b;
3137 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3141 if (val_a >= bitmap_len || neg) {
3153 err = proc_get_long(&p, &left, &val_b,
3154 &neg, tr_b, sizeof(tr_b),
3158 if (val_b >= bitmap_len || neg ||
3169 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3171 proc_skip_char(&p, &left, '\n');
3175 unsigned long bit_a, bit_b = 0;
3178 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3179 if (bit_a >= bitmap_len)
3181 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3185 err = proc_put_char(&buffer, &left, ',');
3189 err = proc_put_long(&buffer, &left, bit_a, false);
3192 if (bit_a != bit_b) {
3193 err = proc_put_char(&buffer, &left, '-');
3196 err = proc_put_long(&buffer, &left, bit_b, false);
3204 err = proc_put_char(&buffer, &left, '\n');
3210 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3212 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3222 #else /* CONFIG_PROC_SYSCTL */
3224 int proc_dostring(struct ctl_table *table, int write,
3225 void __user *buffer, size_t *lenp, loff_t *ppos)
3230 int proc_dointvec(struct ctl_table *table, int write,
3231 void __user *buffer, size_t *lenp, loff_t *ppos)
3236 int proc_douintvec(struct ctl_table *table, int write,
3237 void __user *buffer, size_t *lenp, loff_t *ppos)
3242 int proc_dointvec_minmax(struct ctl_table *table, int write,
3243 void __user *buffer, size_t *lenp, loff_t *ppos)
3248 int proc_douintvec_minmax(struct ctl_table *table, int write,
3249 void __user *buffer, size_t *lenp, loff_t *ppos)
3254 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3255 void __user *buffer, size_t *lenp, loff_t *ppos)
3260 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3261 void __user *buffer, size_t *lenp, loff_t *ppos)
3266 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3267 void __user *buffer, size_t *lenp, loff_t *ppos)
3272 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3273 void __user *buffer, size_t *lenp, loff_t *ppos)
3278 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3279 void __user *buffer,
3280 size_t *lenp, loff_t *ppos)
3286 #endif /* CONFIG_PROC_SYSCTL */
3288 #ifdef CONFIG_BPF_SYSCALL
3289 static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
3290 void __user *buffer, size_t *lenp,
3293 int ret, bpf_stats = *(int *)table->data;
3294 struct ctl_table tmp = *table;
3296 if (write && !capable(CAP_SYS_ADMIN))
3299 tmp.data = &bpf_stats;
3300 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3301 if (write && !ret) {
3302 *(int *)table->data = bpf_stats;