Revert "tty: hvc: Fix data abort due to race in hvc_open"
[linux/fpc-iii.git] / kernel / sysctl.c
blob8a176d8727a3ab8e12c4b48fe9ff7c3afdd97465
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * sysctl.c: General linux system control interface
5 * Begun 24 March 1995, Stephen Tweedie
6 * Added /proc support, Dec 1995
7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10 * Dynamic registration fixes, Stephen Tweedie.
11 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Horn.
14 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * Wendling.
18 * The list_for_each() macro wasn't appropriate for the sysctl loop.
19 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
22 #include <linux/module.h>
23 #include <linux/aio.h>
24 #include <linux/mm.h>
25 #include <linux/swap.h>
26 #include <linux/slab.h>
27 #include <linux/sysctl.h>
28 #include <linux/bitmap.h>
29 #include <linux/signal.h>
30 #include <linux/printk.h>
31 #include <linux/proc_fs.h>
32 #include <linux/security.h>
33 #include <linux/ctype.h>
34 #include <linux/kmemleak.h>
35 #include <linux/fs.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/sched/coredump.h>
67 #include <linux/kexec.h>
68 #include <linux/bpf.h>
69 #include <linux/mount.h>
70 #include <linux/userfaultfd_k.h>
72 #include "../lib/kstrtox.h"
74 #include <linux/uaccess.h>
75 #include <asm/processor.h>
77 #ifdef CONFIG_X86
78 #include <asm/nmi.h>
79 #include <asm/stacktrace.h>
80 #include <asm/io.h>
81 #endif
82 #ifdef CONFIG_SPARC
83 #include <asm/setup.h>
84 #endif
85 #ifdef CONFIG_BSD_PROCESS_ACCT
86 #include <linux/acct.h>
87 #endif
88 #ifdef CONFIG_RT_MUTEXES
89 #include <linux/rtmutex.h>
90 #endif
91 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
92 #include <linux/lockdep.h>
93 #endif
94 #ifdef CONFIG_CHR_DEV_SG
95 #include <scsi/sg.h>
96 #endif
97 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
98 #include <linux/stackleak.h>
99 #endif
100 #ifdef CONFIG_LOCKUP_DETECTOR
101 #include <linux/nmi.h>
102 #endif
104 #if defined(CONFIG_SYSCTL)
106 /* External variables not in a header file. */
107 extern int suid_dumpable;
108 #ifdef CONFIG_COREDUMP
109 extern int core_uses_pid;
110 extern char core_pattern[];
111 extern unsigned int core_pipe_limit;
112 #endif
113 extern int pid_max;
114 extern int pid_max_min, pid_max_max;
115 extern int percpu_pagelist_fraction;
116 extern int latencytop_enabled;
117 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
118 #ifndef CONFIG_MMU
119 extern int sysctl_nr_trim_pages;
120 #endif
122 /* Constants used for minimum and maximum */
123 #ifdef CONFIG_LOCKUP_DETECTOR
124 static int sixty = 60;
125 #endif
127 static int __maybe_unused neg_one = -1;
128 static int __maybe_unused two = 2;
129 static int __maybe_unused four = 4;
130 static unsigned long zero_ul;
131 static unsigned long one_ul = 1;
132 static unsigned long long_max = LONG_MAX;
133 static int one_hundred = 100;
134 static int one_thousand = 1000;
135 #ifdef CONFIG_PRINTK
136 static int ten_thousand = 10000;
137 #endif
138 #ifdef CONFIG_PERF_EVENTS
139 static int six_hundred_forty_kb = 640 * 1024;
140 #endif
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);
158 #endif
160 #ifdef CONFIG_INOTIFY_USER
161 #include <linux/inotify.h>
162 #endif
163 #ifdef CONFIG_SPARC
164 #endif
166 #ifdef CONFIG_PARISC
167 extern int pwrsw_enabled;
168 #endif
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
171 extern int unaligned_enabled;
172 #endif
174 #ifdef CONFIG_IA64
175 extern int unaligned_dump_stack;
176 #endif
178 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179 extern int no_unaligned_warning;
180 #endif
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
192 * not 0.
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 length will be ignored. Multiple writes will append
198 * to the buffer.
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);
215 #ifdef CONFIG_COMPACTION
216 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
217 int write, void __user *buffer,
218 size_t *lenp, loff_t *ppos);
219 #endif
220 #endif
222 #ifdef CONFIG_PRINTK
223 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
224 void __user *buffer, size_t *lenp, loff_t *ppos);
225 #endif
227 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
228 void __user *buffer, size_t *lenp, loff_t *ppos);
229 #ifdef CONFIG_COREDUMP
230 static int proc_dostring_coredump(struct ctl_table *table, int write,
231 void __user *buffer, size_t *lenp, loff_t *ppos);
232 #endif
233 static int proc_dopipe_max_size(struct ctl_table *table, int write,
234 void __user *buffer, size_t *lenp, loff_t *ppos);
236 #ifdef CONFIG_MAGIC_SYSRQ
237 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
238 void __user *buffer, size_t *lenp, loff_t *ppos);
239 #endif
241 static struct ctl_table kern_table[];
242 static struct ctl_table vm_table[];
243 static struct ctl_table fs_table[];
244 static struct ctl_table debug_table[];
245 static struct ctl_table dev_table[];
246 extern struct ctl_table random_table[];
247 #ifdef CONFIG_EPOLL
248 extern struct ctl_table epoll_table[];
249 #endif
251 #ifdef CONFIG_FW_LOADER_USER_HELPER
252 extern struct ctl_table firmware_config_table[];
253 #endif
255 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
256 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
257 int sysctl_legacy_va_layout;
258 #endif
260 /* The default sysctl tables: */
262 static struct ctl_table sysctl_base_table[] = {
264 .procname = "kernel",
265 .mode = 0555,
266 .child = kern_table,
269 .procname = "vm",
270 .mode = 0555,
271 .child = vm_table,
274 .procname = "fs",
275 .mode = 0555,
276 .child = fs_table,
279 .procname = "debug",
280 .mode = 0555,
281 .child = debug_table,
284 .procname = "dev",
285 .mode = 0555,
286 .child = dev_table,
291 #ifdef CONFIG_SCHED_DEBUG
292 static int min_sched_granularity_ns = 100000; /* 100 usecs */
293 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
294 static int min_wakeup_granularity_ns; /* 0 usecs */
295 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
296 #ifdef CONFIG_SMP
297 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
298 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
299 #endif /* CONFIG_SMP */
300 #endif /* CONFIG_SCHED_DEBUG */
302 #ifdef CONFIG_COMPACTION
303 static int min_extfrag_threshold;
304 static int max_extfrag_threshold = 1000;
305 #endif
307 static struct ctl_table kern_table[] = {
309 .procname = "sched_child_runs_first",
310 .data = &sysctl_sched_child_runs_first,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
313 .proc_handler = proc_dointvec,
315 #ifdef CONFIG_SCHED_DEBUG
317 .procname = "sched_min_granularity_ns",
318 .data = &sysctl_sched_min_granularity,
319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
321 .proc_handler = sched_proc_update_handler,
322 .extra1 = &min_sched_granularity_ns,
323 .extra2 = &max_sched_granularity_ns,
326 .procname = "sched_latency_ns",
327 .data = &sysctl_sched_latency,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
330 .proc_handler = sched_proc_update_handler,
331 .extra1 = &min_sched_granularity_ns,
332 .extra2 = &max_sched_granularity_ns,
335 .procname = "sched_wakeup_granularity_ns",
336 .data = &sysctl_sched_wakeup_granularity,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = sched_proc_update_handler,
340 .extra1 = &min_wakeup_granularity_ns,
341 .extra2 = &max_wakeup_granularity_ns,
343 #ifdef CONFIG_SMP
345 .procname = "sched_tunable_scaling",
346 .data = &sysctl_sched_tunable_scaling,
347 .maxlen = sizeof(enum sched_tunable_scaling),
348 .mode = 0644,
349 .proc_handler = sched_proc_update_handler,
350 .extra1 = &min_sched_tunable_scaling,
351 .extra2 = &max_sched_tunable_scaling,
354 .procname = "sched_migration_cost_ns",
355 .data = &sysctl_sched_migration_cost,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
358 .proc_handler = proc_dointvec,
361 .procname = "sched_nr_migrate",
362 .data = &sysctl_sched_nr_migrate,
363 .maxlen = sizeof(unsigned int),
364 .mode = 0644,
365 .proc_handler = proc_dointvec,
367 #ifdef CONFIG_SCHEDSTATS
369 .procname = "sched_schedstats",
370 .data = NULL,
371 .maxlen = sizeof(unsigned int),
372 .mode = 0644,
373 .proc_handler = sysctl_schedstats,
374 .extra1 = SYSCTL_ZERO,
375 .extra2 = SYSCTL_ONE,
377 #endif /* CONFIG_SCHEDSTATS */
378 #endif /* CONFIG_SMP */
379 #ifdef CONFIG_NUMA_BALANCING
381 .procname = "numa_balancing_scan_delay_ms",
382 .data = &sysctl_numa_balancing_scan_delay,
383 .maxlen = sizeof(unsigned int),
384 .mode = 0644,
385 .proc_handler = proc_dointvec,
388 .procname = "numa_balancing_scan_period_min_ms",
389 .data = &sysctl_numa_balancing_scan_period_min,
390 .maxlen = sizeof(unsigned int),
391 .mode = 0644,
392 .proc_handler = proc_dointvec,
395 .procname = "numa_balancing_scan_period_max_ms",
396 .data = &sysctl_numa_balancing_scan_period_max,
397 .maxlen = sizeof(unsigned int),
398 .mode = 0644,
399 .proc_handler = proc_dointvec,
402 .procname = "numa_balancing_scan_size_mb",
403 .data = &sysctl_numa_balancing_scan_size,
404 .maxlen = sizeof(unsigned int),
405 .mode = 0644,
406 .proc_handler = proc_dointvec_minmax,
407 .extra1 = SYSCTL_ONE,
410 .procname = "numa_balancing",
411 .data = NULL, /* filled in by handler */
412 .maxlen = sizeof(unsigned int),
413 .mode = 0644,
414 .proc_handler = sysctl_numa_balancing,
415 .extra1 = SYSCTL_ZERO,
416 .extra2 = SYSCTL_ONE,
418 #endif /* CONFIG_NUMA_BALANCING */
419 #endif /* CONFIG_SCHED_DEBUG */
421 .procname = "sched_rt_period_us",
422 .data = &sysctl_sched_rt_period,
423 .maxlen = sizeof(unsigned int),
424 .mode = 0644,
425 .proc_handler = sched_rt_handler,
428 .procname = "sched_rt_runtime_us",
429 .data = &sysctl_sched_rt_runtime,
430 .maxlen = sizeof(int),
431 .mode = 0644,
432 .proc_handler = sched_rt_handler,
435 .procname = "sched_rr_timeslice_ms",
436 .data = &sysctl_sched_rr_timeslice,
437 .maxlen = sizeof(int),
438 .mode = 0644,
439 .proc_handler = sched_rr_handler,
441 #ifdef CONFIG_UCLAMP_TASK
443 .procname = "sched_util_clamp_min",
444 .data = &sysctl_sched_uclamp_util_min,
445 .maxlen = sizeof(unsigned int),
446 .mode = 0644,
447 .proc_handler = sysctl_sched_uclamp_handler,
450 .procname = "sched_util_clamp_max",
451 .data = &sysctl_sched_uclamp_util_max,
452 .maxlen = sizeof(unsigned int),
453 .mode = 0644,
454 .proc_handler = sysctl_sched_uclamp_handler,
456 #endif
457 #ifdef CONFIG_SCHED_AUTOGROUP
459 .procname = "sched_autogroup_enabled",
460 .data = &sysctl_sched_autogroup_enabled,
461 .maxlen = sizeof(unsigned int),
462 .mode = 0644,
463 .proc_handler = proc_dointvec_minmax,
464 .extra1 = SYSCTL_ZERO,
465 .extra2 = SYSCTL_ONE,
467 #endif
468 #ifdef CONFIG_CFS_BANDWIDTH
470 .procname = "sched_cfs_bandwidth_slice_us",
471 .data = &sysctl_sched_cfs_bandwidth_slice,
472 .maxlen = sizeof(unsigned int),
473 .mode = 0644,
474 .proc_handler = proc_dointvec_minmax,
475 .extra1 = SYSCTL_ONE,
477 #endif
478 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
480 .procname = "sched_energy_aware",
481 .data = &sysctl_sched_energy_aware,
482 .maxlen = sizeof(unsigned int),
483 .mode = 0644,
484 .proc_handler = sched_energy_aware_handler,
485 .extra1 = SYSCTL_ZERO,
486 .extra2 = SYSCTL_ONE,
488 #endif
489 #ifdef CONFIG_PROVE_LOCKING
491 .procname = "prove_locking",
492 .data = &prove_locking,
493 .maxlen = sizeof(int),
494 .mode = 0644,
495 .proc_handler = proc_dointvec,
497 #endif
498 #ifdef CONFIG_LOCK_STAT
500 .procname = "lock_stat",
501 .data = &lock_stat,
502 .maxlen = sizeof(int),
503 .mode = 0644,
504 .proc_handler = proc_dointvec,
506 #endif
508 .procname = "panic",
509 .data = &panic_timeout,
510 .maxlen = sizeof(int),
511 .mode = 0644,
512 .proc_handler = proc_dointvec,
514 #ifdef CONFIG_COREDUMP
516 .procname = "core_uses_pid",
517 .data = &core_uses_pid,
518 .maxlen = sizeof(int),
519 .mode = 0644,
520 .proc_handler = proc_dointvec,
523 .procname = "core_pattern",
524 .data = core_pattern,
525 .maxlen = CORENAME_MAX_SIZE,
526 .mode = 0644,
527 .proc_handler = proc_dostring_coredump,
530 .procname = "core_pipe_limit",
531 .data = &core_pipe_limit,
532 .maxlen = sizeof(unsigned int),
533 .mode = 0644,
534 .proc_handler = proc_dointvec,
536 #endif
537 #ifdef CONFIG_PROC_SYSCTL
539 .procname = "tainted",
540 .maxlen = sizeof(long),
541 .mode = 0644,
542 .proc_handler = proc_taint,
545 .procname = "sysctl_writes_strict",
546 .data = &sysctl_writes_strict,
547 .maxlen = sizeof(int),
548 .mode = 0644,
549 .proc_handler = proc_dointvec_minmax,
550 .extra1 = &neg_one,
551 .extra2 = SYSCTL_ONE,
553 #endif
554 #ifdef CONFIG_LATENCYTOP
556 .procname = "latencytop",
557 .data = &latencytop_enabled,
558 .maxlen = sizeof(int),
559 .mode = 0644,
560 .proc_handler = sysctl_latencytop,
562 #endif
563 #ifdef CONFIG_BLK_DEV_INITRD
565 .procname = "real-root-dev",
566 .data = &real_root_dev,
567 .maxlen = sizeof(int),
568 .mode = 0644,
569 .proc_handler = proc_dointvec,
571 #endif
573 .procname = "print-fatal-signals",
574 .data = &print_fatal_signals,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = proc_dointvec,
579 #ifdef CONFIG_SPARC
581 .procname = "reboot-cmd",
582 .data = reboot_command,
583 .maxlen = 256,
584 .mode = 0644,
585 .proc_handler = proc_dostring,
588 .procname = "stop-a",
589 .data = &stop_a_enabled,
590 .maxlen = sizeof (int),
591 .mode = 0644,
592 .proc_handler = proc_dointvec,
595 .procname = "scons-poweroff",
596 .data = &scons_pwroff,
597 .maxlen = sizeof (int),
598 .mode = 0644,
599 .proc_handler = proc_dointvec,
601 #endif
602 #ifdef CONFIG_SPARC64
604 .procname = "tsb-ratio",
605 .data = &sysctl_tsb_ratio,
606 .maxlen = sizeof (int),
607 .mode = 0644,
608 .proc_handler = proc_dointvec,
610 #endif
611 #ifdef CONFIG_PARISC
613 .procname = "soft-power",
614 .data = &pwrsw_enabled,
615 .maxlen = sizeof (int),
616 .mode = 0644,
617 .proc_handler = proc_dointvec,
619 #endif
620 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
622 .procname = "unaligned-trap",
623 .data = &unaligned_enabled,
624 .maxlen = sizeof (int),
625 .mode = 0644,
626 .proc_handler = proc_dointvec,
628 #endif
630 .procname = "ctrl-alt-del",
631 .data = &C_A_D,
632 .maxlen = sizeof(int),
633 .mode = 0644,
634 .proc_handler = proc_dointvec,
636 #ifdef CONFIG_FUNCTION_TRACER
638 .procname = "ftrace_enabled",
639 .data = &ftrace_enabled,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 .proc_handler = ftrace_enable_sysctl,
644 #endif
645 #ifdef CONFIG_STACK_TRACER
647 .procname = "stack_tracer_enabled",
648 .data = &stack_tracer_enabled,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 .proc_handler = stack_trace_sysctl,
653 #endif
654 #ifdef CONFIG_TRACING
656 .procname = "ftrace_dump_on_oops",
657 .data = &ftrace_dump_on_oops,
658 .maxlen = sizeof(int),
659 .mode = 0644,
660 .proc_handler = proc_dointvec,
663 .procname = "traceoff_on_warning",
664 .data = &__disable_trace_on_warning,
665 .maxlen = sizeof(__disable_trace_on_warning),
666 .mode = 0644,
667 .proc_handler = proc_dointvec,
670 .procname = "tracepoint_printk",
671 .data = &tracepoint_printk,
672 .maxlen = sizeof(tracepoint_printk),
673 .mode = 0644,
674 .proc_handler = tracepoint_printk_sysctl,
676 #endif
677 #ifdef CONFIG_KEXEC_CORE
679 .procname = "kexec_load_disabled",
680 .data = &kexec_load_disabled,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 /* only handle a transition from default "0" to "1" */
684 .proc_handler = proc_dointvec_minmax,
685 .extra1 = SYSCTL_ONE,
686 .extra2 = SYSCTL_ONE,
688 #endif
689 #ifdef CONFIG_MODULES
691 .procname = "modprobe",
692 .data = &modprobe_path,
693 .maxlen = KMOD_PATH_LEN,
694 .mode = 0644,
695 .proc_handler = proc_dostring,
698 .procname = "modules_disabled",
699 .data = &modules_disabled,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 /* only handle a transition from default "0" to "1" */
703 .proc_handler = proc_dointvec_minmax,
704 .extra1 = SYSCTL_ONE,
705 .extra2 = SYSCTL_ONE,
707 #endif
708 #ifdef CONFIG_UEVENT_HELPER
710 .procname = "hotplug",
711 .data = &uevent_helper,
712 .maxlen = UEVENT_HELPER_PATH_LEN,
713 .mode = 0644,
714 .proc_handler = proc_dostring,
716 #endif
717 #ifdef CONFIG_CHR_DEV_SG
719 .procname = "sg-big-buff",
720 .data = &sg_big_buff,
721 .maxlen = sizeof (int),
722 .mode = 0444,
723 .proc_handler = proc_dointvec,
725 #endif
726 #ifdef CONFIG_BSD_PROCESS_ACCT
728 .procname = "acct",
729 .data = &acct_parm,
730 .maxlen = 3*sizeof(int),
731 .mode = 0644,
732 .proc_handler = proc_dointvec,
734 #endif
735 #ifdef CONFIG_MAGIC_SYSRQ
737 .procname = "sysrq",
738 .data = NULL,
739 .maxlen = sizeof (int),
740 .mode = 0644,
741 .proc_handler = sysrq_sysctl_handler,
743 #endif
744 #ifdef CONFIG_PROC_SYSCTL
746 .procname = "cad_pid",
747 .data = NULL,
748 .maxlen = sizeof (int),
749 .mode = 0600,
750 .proc_handler = proc_do_cad_pid,
752 #endif
754 .procname = "threads-max",
755 .data = NULL,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = sysctl_max_threads,
761 .procname = "random",
762 .mode = 0555,
763 .child = random_table,
766 .procname = "usermodehelper",
767 .mode = 0555,
768 .child = usermodehelper_table,
770 #ifdef CONFIG_FW_LOADER_USER_HELPER
772 .procname = "firmware_config",
773 .mode = 0555,
774 .child = firmware_config_table,
776 #endif
778 .procname = "overflowuid",
779 .data = &overflowuid,
780 .maxlen = sizeof(int),
781 .mode = 0644,
782 .proc_handler = proc_dointvec_minmax,
783 .extra1 = &minolduid,
784 .extra2 = &maxolduid,
787 .procname = "overflowgid",
788 .data = &overflowgid,
789 .maxlen = sizeof(int),
790 .mode = 0644,
791 .proc_handler = proc_dointvec_minmax,
792 .extra1 = &minolduid,
793 .extra2 = &maxolduid,
795 #ifdef CONFIG_S390
797 .procname = "userprocess_debug",
798 .data = &show_unhandled_signals,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = proc_dointvec,
803 #endif
805 .procname = "pid_max",
806 .data = &pid_max,
807 .maxlen = sizeof (int),
808 .mode = 0644,
809 .proc_handler = proc_dointvec_minmax,
810 .extra1 = &pid_max_min,
811 .extra2 = &pid_max_max,
814 .procname = "panic_on_oops",
815 .data = &panic_on_oops,
816 .maxlen = sizeof(int),
817 .mode = 0644,
818 .proc_handler = proc_dointvec,
821 .procname = "panic_print",
822 .data = &panic_print,
823 .maxlen = sizeof(unsigned long),
824 .mode = 0644,
825 .proc_handler = proc_doulongvec_minmax,
827 #if defined CONFIG_PRINTK
829 .procname = "printk",
830 .data = &console_loglevel,
831 .maxlen = 4*sizeof(int),
832 .mode = 0644,
833 .proc_handler = proc_dointvec,
836 .procname = "printk_ratelimit",
837 .data = &printk_ratelimit_state.interval,
838 .maxlen = sizeof(int),
839 .mode = 0644,
840 .proc_handler = proc_dointvec_jiffies,
843 .procname = "printk_ratelimit_burst",
844 .data = &printk_ratelimit_state.burst,
845 .maxlen = sizeof(int),
846 .mode = 0644,
847 .proc_handler = proc_dointvec,
850 .procname = "printk_delay",
851 .data = &printk_delay_msec,
852 .maxlen = sizeof(int),
853 .mode = 0644,
854 .proc_handler = proc_dointvec_minmax,
855 .extra1 = SYSCTL_ZERO,
856 .extra2 = &ten_thousand,
859 .procname = "printk_devkmsg",
860 .data = devkmsg_log_str,
861 .maxlen = DEVKMSG_STR_MAX_SIZE,
862 .mode = 0644,
863 .proc_handler = devkmsg_sysctl_set_loglvl,
866 .procname = "dmesg_restrict",
867 .data = &dmesg_restrict,
868 .maxlen = sizeof(int),
869 .mode = 0644,
870 .proc_handler = proc_dointvec_minmax_sysadmin,
871 .extra1 = SYSCTL_ZERO,
872 .extra2 = SYSCTL_ONE,
875 .procname = "kptr_restrict",
876 .data = &kptr_restrict,
877 .maxlen = sizeof(int),
878 .mode = 0644,
879 .proc_handler = proc_dointvec_minmax_sysadmin,
880 .extra1 = SYSCTL_ZERO,
881 .extra2 = &two,
883 #endif
885 .procname = "ngroups_max",
886 .data = &ngroups_max,
887 .maxlen = sizeof (int),
888 .mode = 0444,
889 .proc_handler = proc_dointvec,
892 .procname = "cap_last_cap",
893 .data = (void *)&cap_last_cap,
894 .maxlen = sizeof(int),
895 .mode = 0444,
896 .proc_handler = proc_dointvec,
898 #if defined(CONFIG_LOCKUP_DETECTOR)
900 .procname = "watchdog",
901 .data = &watchdog_user_enabled,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = proc_watchdog,
905 .extra1 = SYSCTL_ZERO,
906 .extra2 = SYSCTL_ONE,
909 .procname = "watchdog_thresh",
910 .data = &watchdog_thresh,
911 .maxlen = sizeof(int),
912 .mode = 0644,
913 .proc_handler = proc_watchdog_thresh,
914 .extra1 = SYSCTL_ZERO,
915 .extra2 = &sixty,
918 .procname = "nmi_watchdog",
919 .data = &nmi_watchdog_user_enabled,
920 .maxlen = sizeof(int),
921 .mode = NMI_WATCHDOG_SYSCTL_PERM,
922 .proc_handler = proc_nmi_watchdog,
923 .extra1 = SYSCTL_ZERO,
924 .extra2 = SYSCTL_ONE,
927 .procname = "watchdog_cpumask",
928 .data = &watchdog_cpumask_bits,
929 .maxlen = NR_CPUS,
930 .mode = 0644,
931 .proc_handler = proc_watchdog_cpumask,
933 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
935 .procname = "soft_watchdog",
936 .data = &soft_watchdog_user_enabled,
937 .maxlen = sizeof(int),
938 .mode = 0644,
939 .proc_handler = proc_soft_watchdog,
940 .extra1 = SYSCTL_ZERO,
941 .extra2 = SYSCTL_ONE,
944 .procname = "softlockup_panic",
945 .data = &softlockup_panic,
946 .maxlen = sizeof(int),
947 .mode = 0644,
948 .proc_handler = proc_dointvec_minmax,
949 .extra1 = SYSCTL_ZERO,
950 .extra2 = SYSCTL_ONE,
952 #ifdef CONFIG_SMP
954 .procname = "softlockup_all_cpu_backtrace",
955 .data = &sysctl_softlockup_all_cpu_backtrace,
956 .maxlen = sizeof(int),
957 .mode = 0644,
958 .proc_handler = proc_dointvec_minmax,
959 .extra1 = SYSCTL_ZERO,
960 .extra2 = SYSCTL_ONE,
962 #endif /* CONFIG_SMP */
963 #endif
964 #ifdef CONFIG_HARDLOCKUP_DETECTOR
966 .procname = "hardlockup_panic",
967 .data = &hardlockup_panic,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = proc_dointvec_minmax,
971 .extra1 = SYSCTL_ZERO,
972 .extra2 = SYSCTL_ONE,
974 #ifdef CONFIG_SMP
976 .procname = "hardlockup_all_cpu_backtrace",
977 .data = &sysctl_hardlockup_all_cpu_backtrace,
978 .maxlen = sizeof(int),
979 .mode = 0644,
980 .proc_handler = proc_dointvec_minmax,
981 .extra1 = SYSCTL_ZERO,
982 .extra2 = SYSCTL_ONE,
984 #endif /* CONFIG_SMP */
985 #endif
986 #endif
988 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
990 .procname = "unknown_nmi_panic",
991 .data = &unknown_nmi_panic,
992 .maxlen = sizeof (int),
993 .mode = 0644,
994 .proc_handler = proc_dointvec,
996 #endif
997 #if defined(CONFIG_X86)
999 .procname = "panic_on_unrecovered_nmi",
1000 .data = &panic_on_unrecovered_nmi,
1001 .maxlen = sizeof(int),
1002 .mode = 0644,
1003 .proc_handler = proc_dointvec,
1006 .procname = "panic_on_io_nmi",
1007 .data = &panic_on_io_nmi,
1008 .maxlen = sizeof(int),
1009 .mode = 0644,
1010 .proc_handler = proc_dointvec,
1012 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1014 .procname = "panic_on_stackoverflow",
1015 .data = &sysctl_panic_on_stackoverflow,
1016 .maxlen = sizeof(int),
1017 .mode = 0644,
1018 .proc_handler = proc_dointvec,
1020 #endif
1022 .procname = "bootloader_type",
1023 .data = &bootloader_type,
1024 .maxlen = sizeof (int),
1025 .mode = 0444,
1026 .proc_handler = proc_dointvec,
1029 .procname = "bootloader_version",
1030 .data = &bootloader_version,
1031 .maxlen = sizeof (int),
1032 .mode = 0444,
1033 .proc_handler = proc_dointvec,
1036 .procname = "io_delay_type",
1037 .data = &io_delay_type,
1038 .maxlen = sizeof(int),
1039 .mode = 0644,
1040 .proc_handler = proc_dointvec,
1042 #endif
1043 #if defined(CONFIG_MMU)
1045 .procname = "randomize_va_space",
1046 .data = &randomize_va_space,
1047 .maxlen = sizeof(int),
1048 .mode = 0644,
1049 .proc_handler = proc_dointvec,
1051 #endif
1052 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1054 .procname = "spin_retry",
1055 .data = &spin_retry,
1056 .maxlen = sizeof (int),
1057 .mode = 0644,
1058 .proc_handler = proc_dointvec,
1060 #endif
1061 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1063 .procname = "acpi_video_flags",
1064 .data = &acpi_realmode_flags,
1065 .maxlen = sizeof (unsigned long),
1066 .mode = 0644,
1067 .proc_handler = proc_doulongvec_minmax,
1069 #endif
1070 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1072 .procname = "ignore-unaligned-usertrap",
1073 .data = &no_unaligned_warning,
1074 .maxlen = sizeof (int),
1075 .mode = 0644,
1076 .proc_handler = proc_dointvec,
1078 #endif
1079 #ifdef CONFIG_IA64
1081 .procname = "unaligned-dump-stack",
1082 .data = &unaligned_dump_stack,
1083 .maxlen = sizeof (int),
1084 .mode = 0644,
1085 .proc_handler = proc_dointvec,
1087 #endif
1088 #ifdef CONFIG_DETECT_HUNG_TASK
1090 .procname = "hung_task_panic",
1091 .data = &sysctl_hung_task_panic,
1092 .maxlen = sizeof(int),
1093 .mode = 0644,
1094 .proc_handler = proc_dointvec_minmax,
1095 .extra1 = SYSCTL_ZERO,
1096 .extra2 = SYSCTL_ONE,
1099 .procname = "hung_task_check_count",
1100 .data = &sysctl_hung_task_check_count,
1101 .maxlen = sizeof(int),
1102 .mode = 0644,
1103 .proc_handler = proc_dointvec_minmax,
1104 .extra1 = SYSCTL_ZERO,
1107 .procname = "hung_task_timeout_secs",
1108 .data = &sysctl_hung_task_timeout_secs,
1109 .maxlen = sizeof(unsigned long),
1110 .mode = 0644,
1111 .proc_handler = proc_dohung_task_timeout_secs,
1112 .extra2 = &hung_task_timeout_max,
1115 .procname = "hung_task_check_interval_secs",
1116 .data = &sysctl_hung_task_check_interval_secs,
1117 .maxlen = sizeof(unsigned long),
1118 .mode = 0644,
1119 .proc_handler = proc_dohung_task_timeout_secs,
1120 .extra2 = &hung_task_timeout_max,
1123 .procname = "hung_task_warnings",
1124 .data = &sysctl_hung_task_warnings,
1125 .maxlen = sizeof(int),
1126 .mode = 0644,
1127 .proc_handler = proc_dointvec_minmax,
1128 .extra1 = &neg_one,
1130 #endif
1131 #ifdef CONFIG_RT_MUTEXES
1133 .procname = "max_lock_depth",
1134 .data = &max_lock_depth,
1135 .maxlen = sizeof(int),
1136 .mode = 0644,
1137 .proc_handler = proc_dointvec,
1139 #endif
1141 .procname = "poweroff_cmd",
1142 .data = &poweroff_cmd,
1143 .maxlen = POWEROFF_CMD_PATH_LEN,
1144 .mode = 0644,
1145 .proc_handler = proc_dostring,
1147 #ifdef CONFIG_KEYS
1149 .procname = "keys",
1150 .mode = 0555,
1151 .child = key_sysctls,
1153 #endif
1154 #ifdef CONFIG_PERF_EVENTS
1156 * User-space scripts rely on the existence of this file
1157 * as a feature check for perf_events being enabled.
1159 * So it's an ABI, do not remove!
1162 .procname = "perf_event_paranoid",
1163 .data = &sysctl_perf_event_paranoid,
1164 .maxlen = sizeof(sysctl_perf_event_paranoid),
1165 .mode = 0644,
1166 .proc_handler = proc_dointvec,
1169 .procname = "perf_event_mlock_kb",
1170 .data = &sysctl_perf_event_mlock,
1171 .maxlen = sizeof(sysctl_perf_event_mlock),
1172 .mode = 0644,
1173 .proc_handler = proc_dointvec,
1176 .procname = "perf_event_max_sample_rate",
1177 .data = &sysctl_perf_event_sample_rate,
1178 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1179 .mode = 0644,
1180 .proc_handler = perf_proc_update_handler,
1181 .extra1 = SYSCTL_ONE,
1184 .procname = "perf_cpu_time_max_percent",
1185 .data = &sysctl_perf_cpu_time_max_percent,
1186 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1187 .mode = 0644,
1188 .proc_handler = perf_cpu_time_max_percent_handler,
1189 .extra1 = SYSCTL_ZERO,
1190 .extra2 = &one_hundred,
1193 .procname = "perf_event_max_stack",
1194 .data = &sysctl_perf_event_max_stack,
1195 .maxlen = sizeof(sysctl_perf_event_max_stack),
1196 .mode = 0644,
1197 .proc_handler = perf_event_max_stack_handler,
1198 .extra1 = SYSCTL_ZERO,
1199 .extra2 = &six_hundred_forty_kb,
1202 .procname = "perf_event_max_contexts_per_stack",
1203 .data = &sysctl_perf_event_max_contexts_per_stack,
1204 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1205 .mode = 0644,
1206 .proc_handler = perf_event_max_stack_handler,
1207 .extra1 = SYSCTL_ZERO,
1208 .extra2 = &one_thousand,
1210 #endif
1212 .procname = "panic_on_warn",
1213 .data = &panic_on_warn,
1214 .maxlen = sizeof(int),
1215 .mode = 0644,
1216 .proc_handler = proc_dointvec_minmax,
1217 .extra1 = SYSCTL_ZERO,
1218 .extra2 = SYSCTL_ONE,
1220 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1222 .procname = "timer_migration",
1223 .data = &sysctl_timer_migration,
1224 .maxlen = sizeof(unsigned int),
1225 .mode = 0644,
1226 .proc_handler = timer_migration_handler,
1227 .extra1 = SYSCTL_ZERO,
1228 .extra2 = SYSCTL_ONE,
1230 #endif
1231 #ifdef CONFIG_BPF_SYSCALL
1233 .procname = "unprivileged_bpf_disabled",
1234 .data = &sysctl_unprivileged_bpf_disabled,
1235 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1236 .mode = 0644,
1237 /* only handle a transition from default "0" to "1" */
1238 .proc_handler = proc_dointvec_minmax,
1239 .extra1 = SYSCTL_ONE,
1240 .extra2 = SYSCTL_ONE,
1243 .procname = "bpf_stats_enabled",
1244 .data = &bpf_stats_enabled_key.key,
1245 .maxlen = sizeof(bpf_stats_enabled_key),
1246 .mode = 0644,
1247 .proc_handler = proc_do_static_key,
1249 #endif
1250 #if defined(CONFIG_TREE_RCU)
1252 .procname = "panic_on_rcu_stall",
1253 .data = &sysctl_panic_on_rcu_stall,
1254 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1255 .mode = 0644,
1256 .proc_handler = proc_dointvec_minmax,
1257 .extra1 = SYSCTL_ZERO,
1258 .extra2 = SYSCTL_ONE,
1260 #endif
1261 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1263 .procname = "stack_erasing",
1264 .data = NULL,
1265 .maxlen = sizeof(int),
1266 .mode = 0600,
1267 .proc_handler = stack_erasing_sysctl,
1268 .extra1 = SYSCTL_ZERO,
1269 .extra2 = SYSCTL_ONE,
1271 #endif
1275 static struct ctl_table vm_table[] = {
1277 .procname = "overcommit_memory",
1278 .data = &sysctl_overcommit_memory,
1279 .maxlen = sizeof(sysctl_overcommit_memory),
1280 .mode = 0644,
1281 .proc_handler = proc_dointvec_minmax,
1282 .extra1 = SYSCTL_ZERO,
1283 .extra2 = &two,
1286 .procname = "panic_on_oom",
1287 .data = &sysctl_panic_on_oom,
1288 .maxlen = sizeof(sysctl_panic_on_oom),
1289 .mode = 0644,
1290 .proc_handler = proc_dointvec_minmax,
1291 .extra1 = SYSCTL_ZERO,
1292 .extra2 = &two,
1295 .procname = "oom_kill_allocating_task",
1296 .data = &sysctl_oom_kill_allocating_task,
1297 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1298 .mode = 0644,
1299 .proc_handler = proc_dointvec,
1302 .procname = "oom_dump_tasks",
1303 .data = &sysctl_oom_dump_tasks,
1304 .maxlen = sizeof(sysctl_oom_dump_tasks),
1305 .mode = 0644,
1306 .proc_handler = proc_dointvec,
1309 .procname = "overcommit_ratio",
1310 .data = &sysctl_overcommit_ratio,
1311 .maxlen = sizeof(sysctl_overcommit_ratio),
1312 .mode = 0644,
1313 .proc_handler = overcommit_ratio_handler,
1316 .procname = "overcommit_kbytes",
1317 .data = &sysctl_overcommit_kbytes,
1318 .maxlen = sizeof(sysctl_overcommit_kbytes),
1319 .mode = 0644,
1320 .proc_handler = overcommit_kbytes_handler,
1323 .procname = "page-cluster",
1324 .data = &page_cluster,
1325 .maxlen = sizeof(int),
1326 .mode = 0644,
1327 .proc_handler = proc_dointvec_minmax,
1328 .extra1 = SYSCTL_ZERO,
1331 .procname = "dirty_background_ratio",
1332 .data = &dirty_background_ratio,
1333 .maxlen = sizeof(dirty_background_ratio),
1334 .mode = 0644,
1335 .proc_handler = dirty_background_ratio_handler,
1336 .extra1 = SYSCTL_ZERO,
1337 .extra2 = &one_hundred,
1340 .procname = "dirty_background_bytes",
1341 .data = &dirty_background_bytes,
1342 .maxlen = sizeof(dirty_background_bytes),
1343 .mode = 0644,
1344 .proc_handler = dirty_background_bytes_handler,
1345 .extra1 = &one_ul,
1348 .procname = "dirty_ratio",
1349 .data = &vm_dirty_ratio,
1350 .maxlen = sizeof(vm_dirty_ratio),
1351 .mode = 0644,
1352 .proc_handler = dirty_ratio_handler,
1353 .extra1 = SYSCTL_ZERO,
1354 .extra2 = &one_hundred,
1357 .procname = "dirty_bytes",
1358 .data = &vm_dirty_bytes,
1359 .maxlen = sizeof(vm_dirty_bytes),
1360 .mode = 0644,
1361 .proc_handler = dirty_bytes_handler,
1362 .extra1 = &dirty_bytes_min,
1365 .procname = "dirty_writeback_centisecs",
1366 .data = &dirty_writeback_interval,
1367 .maxlen = sizeof(dirty_writeback_interval),
1368 .mode = 0644,
1369 .proc_handler = dirty_writeback_centisecs_handler,
1372 .procname = "dirty_expire_centisecs",
1373 .data = &dirty_expire_interval,
1374 .maxlen = sizeof(dirty_expire_interval),
1375 .mode = 0644,
1376 .proc_handler = proc_dointvec_minmax,
1377 .extra1 = SYSCTL_ZERO,
1380 .procname = "dirtytime_expire_seconds",
1381 .data = &dirtytime_expire_interval,
1382 .maxlen = sizeof(dirtytime_expire_interval),
1383 .mode = 0644,
1384 .proc_handler = dirtytime_interval_handler,
1385 .extra1 = SYSCTL_ZERO,
1388 .procname = "swappiness",
1389 .data = &vm_swappiness,
1390 .maxlen = sizeof(vm_swappiness),
1391 .mode = 0644,
1392 .proc_handler = proc_dointvec_minmax,
1393 .extra1 = SYSCTL_ZERO,
1394 .extra2 = &one_hundred,
1396 #ifdef CONFIG_HUGETLB_PAGE
1398 .procname = "nr_hugepages",
1399 .data = NULL,
1400 .maxlen = sizeof(unsigned long),
1401 .mode = 0644,
1402 .proc_handler = hugetlb_sysctl_handler,
1404 #ifdef CONFIG_NUMA
1406 .procname = "nr_hugepages_mempolicy",
1407 .data = NULL,
1408 .maxlen = sizeof(unsigned long),
1409 .mode = 0644,
1410 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1413 .procname = "numa_stat",
1414 .data = &sysctl_vm_numa_stat,
1415 .maxlen = sizeof(int),
1416 .mode = 0644,
1417 .proc_handler = sysctl_vm_numa_stat_handler,
1418 .extra1 = SYSCTL_ZERO,
1419 .extra2 = SYSCTL_ONE,
1421 #endif
1423 .procname = "hugetlb_shm_group",
1424 .data = &sysctl_hugetlb_shm_group,
1425 .maxlen = sizeof(gid_t),
1426 .mode = 0644,
1427 .proc_handler = proc_dointvec,
1430 .procname = "nr_overcommit_hugepages",
1431 .data = NULL,
1432 .maxlen = sizeof(unsigned long),
1433 .mode = 0644,
1434 .proc_handler = hugetlb_overcommit_handler,
1436 #endif
1438 .procname = "lowmem_reserve_ratio",
1439 .data = &sysctl_lowmem_reserve_ratio,
1440 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1441 .mode = 0644,
1442 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1445 .procname = "drop_caches",
1446 .data = &sysctl_drop_caches,
1447 .maxlen = sizeof(int),
1448 .mode = 0200,
1449 .proc_handler = drop_caches_sysctl_handler,
1450 .extra1 = SYSCTL_ONE,
1451 .extra2 = &four,
1453 #ifdef CONFIG_COMPACTION
1455 .procname = "compact_memory",
1456 .data = &sysctl_compact_memory,
1457 .maxlen = sizeof(int),
1458 .mode = 0200,
1459 .proc_handler = sysctl_compaction_handler,
1462 .procname = "extfrag_threshold",
1463 .data = &sysctl_extfrag_threshold,
1464 .maxlen = sizeof(int),
1465 .mode = 0644,
1466 .proc_handler = proc_dointvec_minmax,
1467 .extra1 = &min_extfrag_threshold,
1468 .extra2 = &max_extfrag_threshold,
1471 .procname = "compact_unevictable_allowed",
1472 .data = &sysctl_compact_unevictable_allowed,
1473 .maxlen = sizeof(int),
1474 .mode = 0644,
1475 .proc_handler = proc_dointvec_minmax_warn_RT_change,
1476 .extra1 = SYSCTL_ZERO,
1477 .extra2 = SYSCTL_ONE,
1480 #endif /* CONFIG_COMPACTION */
1482 .procname = "min_free_kbytes",
1483 .data = &min_free_kbytes,
1484 .maxlen = sizeof(min_free_kbytes),
1485 .mode = 0644,
1486 .proc_handler = min_free_kbytes_sysctl_handler,
1487 .extra1 = SYSCTL_ZERO,
1490 .procname = "watermark_boost_factor",
1491 .data = &watermark_boost_factor,
1492 .maxlen = sizeof(watermark_boost_factor),
1493 .mode = 0644,
1494 .proc_handler = watermark_boost_factor_sysctl_handler,
1495 .extra1 = SYSCTL_ZERO,
1498 .procname = "watermark_scale_factor",
1499 .data = &watermark_scale_factor,
1500 .maxlen = sizeof(watermark_scale_factor),
1501 .mode = 0644,
1502 .proc_handler = watermark_scale_factor_sysctl_handler,
1503 .extra1 = SYSCTL_ONE,
1504 .extra2 = &one_thousand,
1507 .procname = "percpu_pagelist_fraction",
1508 .data = &percpu_pagelist_fraction,
1509 .maxlen = sizeof(percpu_pagelist_fraction),
1510 .mode = 0644,
1511 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1512 .extra1 = SYSCTL_ZERO,
1514 #ifdef CONFIG_MMU
1516 .procname = "max_map_count",
1517 .data = &sysctl_max_map_count,
1518 .maxlen = sizeof(sysctl_max_map_count),
1519 .mode = 0644,
1520 .proc_handler = proc_dointvec_minmax,
1521 .extra1 = SYSCTL_ZERO,
1523 #else
1525 .procname = "nr_trim_pages",
1526 .data = &sysctl_nr_trim_pages,
1527 .maxlen = sizeof(sysctl_nr_trim_pages),
1528 .mode = 0644,
1529 .proc_handler = proc_dointvec_minmax,
1530 .extra1 = SYSCTL_ZERO,
1532 #endif
1534 .procname = "laptop_mode",
1535 .data = &laptop_mode,
1536 .maxlen = sizeof(laptop_mode),
1537 .mode = 0644,
1538 .proc_handler = proc_dointvec_jiffies,
1541 .procname = "block_dump",
1542 .data = &block_dump,
1543 .maxlen = sizeof(block_dump),
1544 .mode = 0644,
1545 .proc_handler = proc_dointvec,
1546 .extra1 = SYSCTL_ZERO,
1549 .procname = "vfs_cache_pressure",
1550 .data = &sysctl_vfs_cache_pressure,
1551 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1552 .mode = 0644,
1553 .proc_handler = proc_dointvec,
1554 .extra1 = SYSCTL_ZERO,
1556 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
1557 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1559 .procname = "legacy_va_layout",
1560 .data = &sysctl_legacy_va_layout,
1561 .maxlen = sizeof(sysctl_legacy_va_layout),
1562 .mode = 0644,
1563 .proc_handler = proc_dointvec,
1564 .extra1 = SYSCTL_ZERO,
1566 #endif
1567 #ifdef CONFIG_NUMA
1569 .procname = "zone_reclaim_mode",
1570 .data = &node_reclaim_mode,
1571 .maxlen = sizeof(node_reclaim_mode),
1572 .mode = 0644,
1573 .proc_handler = proc_dointvec,
1574 .extra1 = SYSCTL_ZERO,
1577 .procname = "min_unmapped_ratio",
1578 .data = &sysctl_min_unmapped_ratio,
1579 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1580 .mode = 0644,
1581 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1582 .extra1 = SYSCTL_ZERO,
1583 .extra2 = &one_hundred,
1586 .procname = "min_slab_ratio",
1587 .data = &sysctl_min_slab_ratio,
1588 .maxlen = sizeof(sysctl_min_slab_ratio),
1589 .mode = 0644,
1590 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1591 .extra1 = SYSCTL_ZERO,
1592 .extra2 = &one_hundred,
1594 #endif
1595 #ifdef CONFIG_SMP
1597 .procname = "stat_interval",
1598 .data = &sysctl_stat_interval,
1599 .maxlen = sizeof(sysctl_stat_interval),
1600 .mode = 0644,
1601 .proc_handler = proc_dointvec_jiffies,
1604 .procname = "stat_refresh",
1605 .data = NULL,
1606 .maxlen = 0,
1607 .mode = 0600,
1608 .proc_handler = vmstat_refresh,
1610 #endif
1611 #ifdef CONFIG_MMU
1613 .procname = "mmap_min_addr",
1614 .data = &dac_mmap_min_addr,
1615 .maxlen = sizeof(unsigned long),
1616 .mode = 0644,
1617 .proc_handler = mmap_min_addr_handler,
1619 #endif
1620 #ifdef CONFIG_NUMA
1622 .procname = "numa_zonelist_order",
1623 .data = &numa_zonelist_order,
1624 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1625 .mode = 0644,
1626 .proc_handler = numa_zonelist_order_handler,
1628 #endif
1629 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1630 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1632 .procname = "vdso_enabled",
1633 #ifdef CONFIG_X86_32
1634 .data = &vdso32_enabled,
1635 .maxlen = sizeof(vdso32_enabled),
1636 #else
1637 .data = &vdso_enabled,
1638 .maxlen = sizeof(vdso_enabled),
1639 #endif
1640 .mode = 0644,
1641 .proc_handler = proc_dointvec,
1642 .extra1 = SYSCTL_ZERO,
1644 #endif
1645 #ifdef CONFIG_HIGHMEM
1647 .procname = "highmem_is_dirtyable",
1648 .data = &vm_highmem_is_dirtyable,
1649 .maxlen = sizeof(vm_highmem_is_dirtyable),
1650 .mode = 0644,
1651 .proc_handler = proc_dointvec_minmax,
1652 .extra1 = SYSCTL_ZERO,
1653 .extra2 = SYSCTL_ONE,
1655 #endif
1656 #ifdef CONFIG_MEMORY_FAILURE
1658 .procname = "memory_failure_early_kill",
1659 .data = &sysctl_memory_failure_early_kill,
1660 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1661 .mode = 0644,
1662 .proc_handler = proc_dointvec_minmax,
1663 .extra1 = SYSCTL_ZERO,
1664 .extra2 = SYSCTL_ONE,
1667 .procname = "memory_failure_recovery",
1668 .data = &sysctl_memory_failure_recovery,
1669 .maxlen = sizeof(sysctl_memory_failure_recovery),
1670 .mode = 0644,
1671 .proc_handler = proc_dointvec_minmax,
1672 .extra1 = SYSCTL_ZERO,
1673 .extra2 = SYSCTL_ONE,
1675 #endif
1677 .procname = "user_reserve_kbytes",
1678 .data = &sysctl_user_reserve_kbytes,
1679 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1680 .mode = 0644,
1681 .proc_handler = proc_doulongvec_minmax,
1684 .procname = "admin_reserve_kbytes",
1685 .data = &sysctl_admin_reserve_kbytes,
1686 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1687 .mode = 0644,
1688 .proc_handler = proc_doulongvec_minmax,
1690 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1692 .procname = "mmap_rnd_bits",
1693 .data = &mmap_rnd_bits,
1694 .maxlen = sizeof(mmap_rnd_bits),
1695 .mode = 0600,
1696 .proc_handler = proc_dointvec_minmax,
1697 .extra1 = (void *)&mmap_rnd_bits_min,
1698 .extra2 = (void *)&mmap_rnd_bits_max,
1700 #endif
1701 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1703 .procname = "mmap_rnd_compat_bits",
1704 .data = &mmap_rnd_compat_bits,
1705 .maxlen = sizeof(mmap_rnd_compat_bits),
1706 .mode = 0600,
1707 .proc_handler = proc_dointvec_minmax,
1708 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1709 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1711 #endif
1712 #ifdef CONFIG_USERFAULTFD
1714 .procname = "unprivileged_userfaultfd",
1715 .data = &sysctl_unprivileged_userfaultfd,
1716 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1717 .mode = 0644,
1718 .proc_handler = proc_dointvec_minmax,
1719 .extra1 = SYSCTL_ZERO,
1720 .extra2 = SYSCTL_ONE,
1722 #endif
1726 static struct ctl_table fs_table[] = {
1728 .procname = "inode-nr",
1729 .data = &inodes_stat,
1730 .maxlen = 2*sizeof(long),
1731 .mode = 0444,
1732 .proc_handler = proc_nr_inodes,
1735 .procname = "inode-state",
1736 .data = &inodes_stat,
1737 .maxlen = 7*sizeof(long),
1738 .mode = 0444,
1739 .proc_handler = proc_nr_inodes,
1742 .procname = "file-nr",
1743 .data = &files_stat,
1744 .maxlen = sizeof(files_stat),
1745 .mode = 0444,
1746 .proc_handler = proc_nr_files,
1749 .procname = "file-max",
1750 .data = &files_stat.max_files,
1751 .maxlen = sizeof(files_stat.max_files),
1752 .mode = 0644,
1753 .proc_handler = proc_doulongvec_minmax,
1754 .extra1 = &zero_ul,
1755 .extra2 = &long_max,
1758 .procname = "nr_open",
1759 .data = &sysctl_nr_open,
1760 .maxlen = sizeof(unsigned int),
1761 .mode = 0644,
1762 .proc_handler = proc_dointvec_minmax,
1763 .extra1 = &sysctl_nr_open_min,
1764 .extra2 = &sysctl_nr_open_max,
1767 .procname = "dentry-state",
1768 .data = &dentry_stat,
1769 .maxlen = 6*sizeof(long),
1770 .mode = 0444,
1771 .proc_handler = proc_nr_dentry,
1774 .procname = "overflowuid",
1775 .data = &fs_overflowuid,
1776 .maxlen = sizeof(int),
1777 .mode = 0644,
1778 .proc_handler = proc_dointvec_minmax,
1779 .extra1 = &minolduid,
1780 .extra2 = &maxolduid,
1783 .procname = "overflowgid",
1784 .data = &fs_overflowgid,
1785 .maxlen = sizeof(int),
1786 .mode = 0644,
1787 .proc_handler = proc_dointvec_minmax,
1788 .extra1 = &minolduid,
1789 .extra2 = &maxolduid,
1791 #ifdef CONFIG_FILE_LOCKING
1793 .procname = "leases-enable",
1794 .data = &leases_enable,
1795 .maxlen = sizeof(int),
1796 .mode = 0644,
1797 .proc_handler = proc_dointvec,
1799 #endif
1800 #ifdef CONFIG_DNOTIFY
1802 .procname = "dir-notify-enable",
1803 .data = &dir_notify_enable,
1804 .maxlen = sizeof(int),
1805 .mode = 0644,
1806 .proc_handler = proc_dointvec,
1808 #endif
1809 #ifdef CONFIG_MMU
1810 #ifdef CONFIG_FILE_LOCKING
1812 .procname = "lease-break-time",
1813 .data = &lease_break_time,
1814 .maxlen = sizeof(int),
1815 .mode = 0644,
1816 .proc_handler = proc_dointvec,
1818 #endif
1819 #ifdef CONFIG_AIO
1821 .procname = "aio-nr",
1822 .data = &aio_nr,
1823 .maxlen = sizeof(aio_nr),
1824 .mode = 0444,
1825 .proc_handler = proc_doulongvec_minmax,
1828 .procname = "aio-max-nr",
1829 .data = &aio_max_nr,
1830 .maxlen = sizeof(aio_max_nr),
1831 .mode = 0644,
1832 .proc_handler = proc_doulongvec_minmax,
1834 #endif /* CONFIG_AIO */
1835 #ifdef CONFIG_INOTIFY_USER
1837 .procname = "inotify",
1838 .mode = 0555,
1839 .child = inotify_table,
1841 #endif
1842 #ifdef CONFIG_EPOLL
1844 .procname = "epoll",
1845 .mode = 0555,
1846 .child = epoll_table,
1848 #endif
1849 #endif
1851 .procname = "protected_symlinks",
1852 .data = &sysctl_protected_symlinks,
1853 .maxlen = sizeof(int),
1854 .mode = 0600,
1855 .proc_handler = proc_dointvec_minmax,
1856 .extra1 = SYSCTL_ZERO,
1857 .extra2 = SYSCTL_ONE,
1860 .procname = "protected_hardlinks",
1861 .data = &sysctl_protected_hardlinks,
1862 .maxlen = sizeof(int),
1863 .mode = 0600,
1864 .proc_handler = proc_dointvec_minmax,
1865 .extra1 = SYSCTL_ZERO,
1866 .extra2 = SYSCTL_ONE,
1869 .procname = "protected_fifos",
1870 .data = &sysctl_protected_fifos,
1871 .maxlen = sizeof(int),
1872 .mode = 0600,
1873 .proc_handler = proc_dointvec_minmax,
1874 .extra1 = SYSCTL_ZERO,
1875 .extra2 = &two,
1878 .procname = "protected_regular",
1879 .data = &sysctl_protected_regular,
1880 .maxlen = sizeof(int),
1881 .mode = 0600,
1882 .proc_handler = proc_dointvec_minmax,
1883 .extra1 = SYSCTL_ZERO,
1884 .extra2 = &two,
1887 .procname = "suid_dumpable",
1888 .data = &suid_dumpable,
1889 .maxlen = sizeof(int),
1890 .mode = 0644,
1891 .proc_handler = proc_dointvec_minmax_coredump,
1892 .extra1 = SYSCTL_ZERO,
1893 .extra2 = &two,
1895 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1897 .procname = "binfmt_misc",
1898 .mode = 0555,
1899 .child = sysctl_mount_point,
1901 #endif
1903 .procname = "pipe-max-size",
1904 .data = &pipe_max_size,
1905 .maxlen = sizeof(pipe_max_size),
1906 .mode = 0644,
1907 .proc_handler = proc_dopipe_max_size,
1910 .procname = "pipe-user-pages-hard",
1911 .data = &pipe_user_pages_hard,
1912 .maxlen = sizeof(pipe_user_pages_hard),
1913 .mode = 0644,
1914 .proc_handler = proc_doulongvec_minmax,
1917 .procname = "pipe-user-pages-soft",
1918 .data = &pipe_user_pages_soft,
1919 .maxlen = sizeof(pipe_user_pages_soft),
1920 .mode = 0644,
1921 .proc_handler = proc_doulongvec_minmax,
1924 .procname = "mount-max",
1925 .data = &sysctl_mount_max,
1926 .maxlen = sizeof(unsigned int),
1927 .mode = 0644,
1928 .proc_handler = proc_dointvec_minmax,
1929 .extra1 = SYSCTL_ONE,
1934 static struct ctl_table debug_table[] = {
1935 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1937 .procname = "exception-trace",
1938 .data = &show_unhandled_signals,
1939 .maxlen = sizeof(int),
1940 .mode = 0644,
1941 .proc_handler = proc_dointvec
1943 #endif
1944 #if defined(CONFIG_OPTPROBES)
1946 .procname = "kprobes-optimization",
1947 .data = &sysctl_kprobes_optimization,
1948 .maxlen = sizeof(int),
1949 .mode = 0644,
1950 .proc_handler = proc_kprobes_optimization_handler,
1951 .extra1 = SYSCTL_ZERO,
1952 .extra2 = SYSCTL_ONE,
1954 #endif
1958 static struct ctl_table dev_table[] = {
1962 int __init sysctl_init(void)
1964 struct ctl_table_header *hdr;
1966 hdr = register_sysctl_table(sysctl_base_table);
1967 kmemleak_not_leak(hdr);
1968 return 0;
1971 #endif /* CONFIG_SYSCTL */
1974 * /proc/sys support
1977 #ifdef CONFIG_PROC_SYSCTL
1979 static int _proc_do_string(char *data, int maxlen, int write,
1980 char __user *buffer,
1981 size_t *lenp, loff_t *ppos)
1983 size_t len;
1984 char __user *p;
1985 char c;
1987 if (!data || !maxlen || !*lenp) {
1988 *lenp = 0;
1989 return 0;
1992 if (write) {
1993 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1994 /* Only continue writes not past the end of buffer. */
1995 len = strlen(data);
1996 if (len > maxlen - 1)
1997 len = maxlen - 1;
1999 if (*ppos > len)
2000 return 0;
2001 len = *ppos;
2002 } else {
2003 /* Start writing from beginning of buffer. */
2004 len = 0;
2007 *ppos += *lenp;
2008 p = buffer;
2009 while ((p - buffer) < *lenp && len < maxlen - 1) {
2010 if (get_user(c, p++))
2011 return -EFAULT;
2012 if (c == 0 || c == '\n')
2013 break;
2014 data[len++] = c;
2016 data[len] = 0;
2017 } else {
2018 len = strlen(data);
2019 if (len > maxlen)
2020 len = maxlen;
2022 if (*ppos > len) {
2023 *lenp = 0;
2024 return 0;
2027 data += *ppos;
2028 len -= *ppos;
2030 if (len > *lenp)
2031 len = *lenp;
2032 if (len)
2033 if (copy_to_user(buffer, data, len))
2034 return -EFAULT;
2035 if (len < *lenp) {
2036 if (put_user('\n', buffer + len))
2037 return -EFAULT;
2038 len++;
2040 *lenp = len;
2041 *ppos += len;
2043 return 0;
2046 static void warn_sysctl_write(struct ctl_table *table)
2048 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2049 "This will not be supported in the future. To silence this\n"
2050 "warning, set kernel.sysctl_writes_strict = -1\n",
2051 current->comm, table->procname);
2055 * proc_first_pos_non_zero_ignore - check if first position is allowed
2056 * @ppos: file position
2057 * @table: the sysctl table
2059 * Returns true if the first position is non-zero and the sysctl_writes_strict
2060 * mode indicates this is not allowed for numeric input types. String proc
2061 * handlers can ignore the return value.
2063 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2064 struct ctl_table *table)
2066 if (!*ppos)
2067 return false;
2069 switch (sysctl_writes_strict) {
2070 case SYSCTL_WRITES_STRICT:
2071 return true;
2072 case SYSCTL_WRITES_WARN:
2073 warn_sysctl_write(table);
2074 return false;
2075 default:
2076 return false;
2081 * proc_dostring - read a string sysctl
2082 * @table: the sysctl table
2083 * @write: %TRUE if this is a write to the sysctl file
2084 * @buffer: the user buffer
2085 * @lenp: the size of the user buffer
2086 * @ppos: file position
2088 * Reads/writes a string from/to the user buffer. If the kernel
2089 * buffer provided is not large enough to hold the string, the
2090 * string is truncated. The copied string is %NULL-terminated.
2091 * If the string is being read by the user process, it is copied
2092 * and a newline '\n' is added. It is truncated if the buffer is
2093 * not large enough.
2095 * Returns 0 on success.
2097 int proc_dostring(struct ctl_table *table, int write,
2098 void __user *buffer, size_t *lenp, loff_t *ppos)
2100 if (write)
2101 proc_first_pos_non_zero_ignore(ppos, table);
2103 return _proc_do_string((char *)(table->data), table->maxlen, write,
2104 (char __user *)buffer, lenp, ppos);
2107 static size_t proc_skip_spaces(char **buf)
2109 size_t ret;
2110 char *tmp = skip_spaces(*buf);
2111 ret = tmp - *buf;
2112 *buf = tmp;
2113 return ret;
2116 static void proc_skip_char(char **buf, size_t *size, const char v)
2118 while (*size) {
2119 if (**buf != v)
2120 break;
2121 (*size)--;
2122 (*buf)++;
2127 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2128 * fail on overflow
2130 * @cp: kernel buffer containing the string to parse
2131 * @endp: pointer to store the trailing characters
2132 * @base: the base to use
2133 * @res: where the parsed integer will be stored
2135 * In case of success 0 is returned and @res will contain the parsed integer,
2136 * @endp will hold any trailing characters.
2137 * This function will fail the parse on overflow. If there wasn't an overflow
2138 * the function will defer the decision what characters count as invalid to the
2139 * caller.
2141 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2142 unsigned long *res)
2144 unsigned long long result;
2145 unsigned int rv;
2147 cp = _parse_integer_fixup_radix(cp, &base);
2148 rv = _parse_integer(cp, base, &result);
2149 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2150 return -ERANGE;
2152 cp += rv;
2154 if (endp)
2155 *endp = (char *)cp;
2157 *res = (unsigned long)result;
2158 return 0;
2161 #define TMPBUFLEN 22
2163 * proc_get_long - reads an ASCII formatted integer from a user buffer
2165 * @buf: a kernel buffer
2166 * @size: size of the kernel buffer
2167 * @val: this is where the number will be stored
2168 * @neg: set to %TRUE if number is negative
2169 * @perm_tr: a vector which contains the allowed trailers
2170 * @perm_tr_len: size of the perm_tr vector
2171 * @tr: pointer to store the trailer character
2173 * In case of success %0 is returned and @buf and @size are updated with
2174 * the amount of bytes read. If @tr is non-NULL and a trailing
2175 * character exists (size is non-zero after returning from this
2176 * function), @tr is updated with the trailing character.
2178 static int proc_get_long(char **buf, size_t *size,
2179 unsigned long *val, bool *neg,
2180 const char *perm_tr, unsigned perm_tr_len, char *tr)
2182 int len;
2183 char *p, tmp[TMPBUFLEN];
2185 if (!*size)
2186 return -EINVAL;
2188 len = *size;
2189 if (len > TMPBUFLEN - 1)
2190 len = TMPBUFLEN - 1;
2192 memcpy(tmp, *buf, len);
2194 tmp[len] = 0;
2195 p = tmp;
2196 if (*p == '-' && *size > 1) {
2197 *neg = true;
2198 p++;
2199 } else
2200 *neg = false;
2201 if (!isdigit(*p))
2202 return -EINVAL;
2204 if (strtoul_lenient(p, &p, 0, val))
2205 return -EINVAL;
2207 len = p - tmp;
2209 /* We don't know if the next char is whitespace thus we may accept
2210 * invalid integers (e.g. 1234...a) or two integers instead of one
2211 * (e.g. 123...1). So lets not allow such large numbers. */
2212 if (len == TMPBUFLEN - 1)
2213 return -EINVAL;
2215 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2216 return -EINVAL;
2218 if (tr && (len < *size))
2219 *tr = *p;
2221 *buf += len;
2222 *size -= len;
2224 return 0;
2228 * proc_put_long - converts an integer to a decimal ASCII formatted string
2230 * @buf: the user buffer
2231 * @size: the size of the user buffer
2232 * @val: the integer to be converted
2233 * @neg: sign of the number, %TRUE for negative
2235 * In case of success %0 is returned and @buf and @size are updated with
2236 * the amount of bytes written.
2238 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2239 bool neg)
2241 int len;
2242 char tmp[TMPBUFLEN], *p = tmp;
2244 sprintf(p, "%s%lu", neg ? "-" : "", val);
2245 len = strlen(tmp);
2246 if (len > *size)
2247 len = *size;
2248 if (copy_to_user(*buf, tmp, len))
2249 return -EFAULT;
2250 *size -= len;
2251 *buf += len;
2252 return 0;
2254 #undef TMPBUFLEN
2256 static int proc_put_char(void __user **buf, size_t *size, char c)
2258 if (*size) {
2259 char __user **buffer = (char __user **)buf;
2260 if (put_user(c, *buffer))
2261 return -EFAULT;
2262 (*size)--, (*buffer)++;
2263 *buf = *buffer;
2265 return 0;
2268 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2269 int *valp,
2270 int write, void *data)
2272 if (write) {
2273 if (*negp) {
2274 if (*lvalp > (unsigned long) INT_MAX + 1)
2275 return -EINVAL;
2276 *valp = -*lvalp;
2277 } else {
2278 if (*lvalp > (unsigned long) INT_MAX)
2279 return -EINVAL;
2280 *valp = *lvalp;
2282 } else {
2283 int val = *valp;
2284 if (val < 0) {
2285 *negp = true;
2286 *lvalp = -(unsigned long)val;
2287 } else {
2288 *negp = false;
2289 *lvalp = (unsigned long)val;
2292 return 0;
2295 static int do_proc_douintvec_conv(unsigned long *lvalp,
2296 unsigned int *valp,
2297 int write, void *data)
2299 if (write) {
2300 if (*lvalp > UINT_MAX)
2301 return -EINVAL;
2302 *valp = *lvalp;
2303 } else {
2304 unsigned int val = *valp;
2305 *lvalp = (unsigned long)val;
2307 return 0;
2310 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2312 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2313 int write, void __user *buffer,
2314 size_t *lenp, loff_t *ppos,
2315 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2316 int write, void *data),
2317 void *data)
2319 int *i, vleft, first = 1, err = 0;
2320 size_t left;
2321 char *kbuf = NULL, *p;
2323 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2324 *lenp = 0;
2325 return 0;
2328 i = (int *) tbl_data;
2329 vleft = table->maxlen / sizeof(*i);
2330 left = *lenp;
2332 if (!conv)
2333 conv = do_proc_dointvec_conv;
2335 if (write) {
2336 if (proc_first_pos_non_zero_ignore(ppos, table))
2337 goto out;
2339 if (left > PAGE_SIZE - 1)
2340 left = PAGE_SIZE - 1;
2341 p = kbuf = memdup_user_nul(buffer, left);
2342 if (IS_ERR(kbuf))
2343 return PTR_ERR(kbuf);
2346 for (; left && vleft--; i++, first=0) {
2347 unsigned long lval;
2348 bool neg;
2350 if (write) {
2351 left -= proc_skip_spaces(&p);
2353 if (!left)
2354 break;
2355 err = proc_get_long(&p, &left, &lval, &neg,
2356 proc_wspace_sep,
2357 sizeof(proc_wspace_sep), NULL);
2358 if (err)
2359 break;
2360 if (conv(&neg, &lval, i, 1, data)) {
2361 err = -EINVAL;
2362 break;
2364 } else {
2365 if (conv(&neg, &lval, i, 0, data)) {
2366 err = -EINVAL;
2367 break;
2369 if (!first)
2370 err = proc_put_char(&buffer, &left, '\t');
2371 if (err)
2372 break;
2373 err = proc_put_long(&buffer, &left, lval, neg);
2374 if (err)
2375 break;
2379 if (!write && !first && left && !err)
2380 err = proc_put_char(&buffer, &left, '\n');
2381 if (write && !err && left)
2382 left -= proc_skip_spaces(&p);
2383 if (write) {
2384 kfree(kbuf);
2385 if (first)
2386 return err ? : -EINVAL;
2388 *lenp -= left;
2389 out:
2390 *ppos += *lenp;
2391 return err;
2394 static int do_proc_dointvec(struct ctl_table *table, int write,
2395 void __user *buffer, size_t *lenp, loff_t *ppos,
2396 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2397 int write, void *data),
2398 void *data)
2400 return __do_proc_dointvec(table->data, table, write,
2401 buffer, lenp, ppos, conv, data);
2404 static int do_proc_douintvec_w(unsigned int *tbl_data,
2405 struct ctl_table *table,
2406 void __user *buffer,
2407 size_t *lenp, loff_t *ppos,
2408 int (*conv)(unsigned long *lvalp,
2409 unsigned int *valp,
2410 int write, void *data),
2411 void *data)
2413 unsigned long lval;
2414 int err = 0;
2415 size_t left;
2416 bool neg;
2417 char *kbuf = NULL, *p;
2419 left = *lenp;
2421 if (proc_first_pos_non_zero_ignore(ppos, table))
2422 goto bail_early;
2424 if (left > PAGE_SIZE - 1)
2425 left = PAGE_SIZE - 1;
2427 p = kbuf = memdup_user_nul(buffer, left);
2428 if (IS_ERR(kbuf))
2429 return -EINVAL;
2431 left -= proc_skip_spaces(&p);
2432 if (!left) {
2433 err = -EINVAL;
2434 goto out_free;
2437 err = proc_get_long(&p, &left, &lval, &neg,
2438 proc_wspace_sep,
2439 sizeof(proc_wspace_sep), NULL);
2440 if (err || neg) {
2441 err = -EINVAL;
2442 goto out_free;
2445 if (conv(&lval, tbl_data, 1, data)) {
2446 err = -EINVAL;
2447 goto out_free;
2450 if (!err && left)
2451 left -= proc_skip_spaces(&p);
2453 out_free:
2454 kfree(kbuf);
2455 if (err)
2456 return -EINVAL;
2458 return 0;
2460 /* This is in keeping with old __do_proc_dointvec() */
2461 bail_early:
2462 *ppos += *lenp;
2463 return err;
2466 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2467 size_t *lenp, loff_t *ppos,
2468 int (*conv)(unsigned long *lvalp,
2469 unsigned int *valp,
2470 int write, void *data),
2471 void *data)
2473 unsigned long lval;
2474 int err = 0;
2475 size_t left;
2477 left = *lenp;
2479 if (conv(&lval, tbl_data, 0, data)) {
2480 err = -EINVAL;
2481 goto out;
2484 err = proc_put_long(&buffer, &left, lval, false);
2485 if (err || !left)
2486 goto out;
2488 err = proc_put_char(&buffer, &left, '\n');
2490 out:
2491 *lenp -= left;
2492 *ppos += *lenp;
2494 return err;
2497 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2498 int write, void __user *buffer,
2499 size_t *lenp, loff_t *ppos,
2500 int (*conv)(unsigned long *lvalp,
2501 unsigned int *valp,
2502 int write, void *data),
2503 void *data)
2505 unsigned int *i, vleft;
2507 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2508 *lenp = 0;
2509 return 0;
2512 i = (unsigned int *) tbl_data;
2513 vleft = table->maxlen / sizeof(*i);
2516 * Arrays are not supported, keep this simple. *Do not* add
2517 * support for them.
2519 if (vleft != 1) {
2520 *lenp = 0;
2521 return -EINVAL;
2524 if (!conv)
2525 conv = do_proc_douintvec_conv;
2527 if (write)
2528 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2529 conv, data);
2530 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2533 static int do_proc_douintvec(struct ctl_table *table, int write,
2534 void __user *buffer, size_t *lenp, loff_t *ppos,
2535 int (*conv)(unsigned long *lvalp,
2536 unsigned int *valp,
2537 int write, void *data),
2538 void *data)
2540 return __do_proc_douintvec(table->data, table, write,
2541 buffer, lenp, ppos, conv, data);
2545 * proc_dointvec - read a vector of integers
2546 * @table: the sysctl table
2547 * @write: %TRUE if this is a write to the sysctl file
2548 * @buffer: the user buffer
2549 * @lenp: the size of the user buffer
2550 * @ppos: file position
2552 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2553 * values from/to the user buffer, treated as an ASCII string.
2555 * Returns 0 on success.
2557 int proc_dointvec(struct ctl_table *table, int write,
2558 void __user *buffer, size_t *lenp, loff_t *ppos)
2560 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2563 #ifdef CONFIG_COMPACTION
2564 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
2565 int write, void __user *buffer,
2566 size_t *lenp, loff_t *ppos)
2568 int ret, old;
2570 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
2571 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2573 old = *(int *)table->data;
2574 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2575 if (ret)
2576 return ret;
2577 if (old != *(int *)table->data)
2578 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
2579 table->procname, current->comm,
2580 task_pid_nr(current));
2581 return ret;
2583 #endif
2586 * proc_douintvec - read a vector of unsigned integers
2587 * @table: the sysctl table
2588 * @write: %TRUE if this is a write to the sysctl file
2589 * @buffer: the user buffer
2590 * @lenp: the size of the user buffer
2591 * @ppos: file position
2593 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2594 * values from/to the user buffer, treated as an ASCII string.
2596 * Returns 0 on success.
2598 int proc_douintvec(struct ctl_table *table, int write,
2599 void __user *buffer, size_t *lenp, loff_t *ppos)
2601 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2602 do_proc_douintvec_conv, NULL);
2606 * Taint values can only be increased
2607 * This means we can safely use a temporary.
2609 static int proc_taint(struct ctl_table *table, int write,
2610 void __user *buffer, size_t *lenp, loff_t *ppos)
2612 struct ctl_table t;
2613 unsigned long tmptaint = get_taint();
2614 int err;
2616 if (write && !capable(CAP_SYS_ADMIN))
2617 return -EPERM;
2619 t = *table;
2620 t.data = &tmptaint;
2621 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2622 if (err < 0)
2623 return err;
2625 if (write) {
2627 * Poor man's atomic or. Not worth adding a primitive
2628 * to everyone's atomic.h for this
2630 int i;
2631 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2632 if ((tmptaint >> i) & 1)
2633 add_taint(i, LOCKDEP_STILL_OK);
2637 return err;
2640 #ifdef CONFIG_PRINTK
2641 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2642 void __user *buffer, size_t *lenp, loff_t *ppos)
2644 if (write && !capable(CAP_SYS_ADMIN))
2645 return -EPERM;
2647 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2649 #endif
2652 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2653 * @min: pointer to minimum allowable value
2654 * @max: pointer to maximum allowable value
2656 * The do_proc_dointvec_minmax_conv_param structure provides the
2657 * minimum and maximum values for doing range checking for those sysctl
2658 * parameters that use the proc_dointvec_minmax() handler.
2660 struct do_proc_dointvec_minmax_conv_param {
2661 int *min;
2662 int *max;
2665 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2666 int *valp,
2667 int write, void *data)
2669 int tmp, ret;
2670 struct do_proc_dointvec_minmax_conv_param *param = data;
2672 * If writing, first do so via a temporary local int so we can
2673 * bounds-check it before touching *valp.
2675 int *ip = write ? &tmp : valp;
2677 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2678 if (ret)
2679 return ret;
2681 if (write) {
2682 if ((param->min && *param->min > tmp) ||
2683 (param->max && *param->max < tmp))
2684 return -EINVAL;
2685 *valp = tmp;
2688 return 0;
2692 * proc_dointvec_minmax - read a vector of integers 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) integer
2700 * values from/to the user buffer, treated as an ASCII string.
2702 * This routine will ensure the values are within the range specified by
2703 * table->extra1 (min) and table->extra2 (max).
2705 * Returns 0 on success or -EINVAL on write when the range check fails.
2707 int proc_dointvec_minmax(struct ctl_table *table, int write,
2708 void __user *buffer, size_t *lenp, loff_t *ppos)
2710 struct do_proc_dointvec_minmax_conv_param param = {
2711 .min = (int *) table->extra1,
2712 .max = (int *) table->extra2,
2714 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2715 do_proc_dointvec_minmax_conv, &param);
2719 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2720 * @min: pointer to minimum allowable value
2721 * @max: pointer to maximum allowable value
2723 * The do_proc_douintvec_minmax_conv_param structure provides the
2724 * minimum and maximum values for doing range checking for those sysctl
2725 * parameters that use the proc_douintvec_minmax() handler.
2727 struct do_proc_douintvec_minmax_conv_param {
2728 unsigned int *min;
2729 unsigned int *max;
2732 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2733 unsigned int *valp,
2734 int write, void *data)
2736 int ret;
2737 unsigned int tmp;
2738 struct do_proc_douintvec_minmax_conv_param *param = data;
2739 /* write via temporary local uint for bounds-checking */
2740 unsigned int *up = write ? &tmp : valp;
2742 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2743 if (ret)
2744 return ret;
2746 if (write) {
2747 if ((param->min && *param->min > tmp) ||
2748 (param->max && *param->max < tmp))
2749 return -ERANGE;
2751 *valp = tmp;
2754 return 0;
2758 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2759 * @table: the sysctl table
2760 * @write: %TRUE if this is a write to the sysctl file
2761 * @buffer: the user buffer
2762 * @lenp: the size of the user buffer
2763 * @ppos: file position
2765 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2766 * values from/to the user buffer, treated as an ASCII string. Negative
2767 * strings are not allowed.
2769 * This routine will ensure the values are within the range specified by
2770 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2771 * check for UINT_MAX to avoid having to support wrap around uses from
2772 * userspace.
2774 * Returns 0 on success or -ERANGE on write when the range check fails.
2776 int proc_douintvec_minmax(struct ctl_table *table, int write,
2777 void __user *buffer, size_t *lenp, loff_t *ppos)
2779 struct do_proc_douintvec_minmax_conv_param param = {
2780 .min = (unsigned int *) table->extra1,
2781 .max = (unsigned int *) table->extra2,
2783 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2784 do_proc_douintvec_minmax_conv, &param);
2787 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2788 unsigned int *valp,
2789 int write, void *data)
2791 if (write) {
2792 unsigned int val;
2794 val = round_pipe_size(*lvalp);
2795 if (val == 0)
2796 return -EINVAL;
2798 *valp = val;
2799 } else {
2800 unsigned int val = *valp;
2801 *lvalp = (unsigned long) val;
2804 return 0;
2807 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2808 void __user *buffer, size_t *lenp, loff_t *ppos)
2810 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2811 do_proc_dopipe_max_size_conv, NULL);
2814 static void validate_coredump_safety(void)
2816 #ifdef CONFIG_COREDUMP
2817 if (suid_dumpable == SUID_DUMP_ROOT &&
2818 core_pattern[0] != '/' && core_pattern[0] != '|') {
2819 printk(KERN_WARNING
2820 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2821 "Pipe handler or fully qualified core dump path required.\n"
2822 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2825 #endif
2828 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2829 void __user *buffer, size_t *lenp, loff_t *ppos)
2831 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2832 if (!error)
2833 validate_coredump_safety();
2834 return error;
2837 #ifdef CONFIG_COREDUMP
2838 static int proc_dostring_coredump(struct ctl_table *table, int write,
2839 void __user *buffer, size_t *lenp, loff_t *ppos)
2841 int error = proc_dostring(table, write, buffer, lenp, ppos);
2842 if (!error)
2843 validate_coredump_safety();
2844 return error;
2846 #endif
2848 #ifdef CONFIG_MAGIC_SYSRQ
2849 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
2850 void __user *buffer, size_t *lenp, loff_t *ppos)
2852 int tmp, ret;
2854 tmp = sysrq_mask();
2856 ret = __do_proc_dointvec(&tmp, table, write, buffer,
2857 lenp, ppos, NULL, NULL);
2858 if (ret || !write)
2859 return ret;
2861 if (write)
2862 sysrq_toggle_support(tmp);
2864 return 0;
2866 #endif
2868 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2869 void __user *buffer,
2870 size_t *lenp, loff_t *ppos,
2871 unsigned long convmul,
2872 unsigned long convdiv)
2874 unsigned long *i, *min, *max;
2875 int vleft, first = 1, err = 0;
2876 size_t left;
2877 char *kbuf = NULL, *p;
2879 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2880 *lenp = 0;
2881 return 0;
2884 i = (unsigned long *) data;
2885 min = (unsigned long *) table->extra1;
2886 max = (unsigned long *) table->extra2;
2887 vleft = table->maxlen / sizeof(unsigned long);
2888 left = *lenp;
2890 if (write) {
2891 if (proc_first_pos_non_zero_ignore(ppos, table))
2892 goto out;
2894 if (left > PAGE_SIZE - 1)
2895 left = PAGE_SIZE - 1;
2896 p = kbuf = memdup_user_nul(buffer, left);
2897 if (IS_ERR(kbuf))
2898 return PTR_ERR(kbuf);
2901 for (; left && vleft--; i++, first = 0) {
2902 unsigned long val;
2904 if (write) {
2905 bool neg;
2907 left -= proc_skip_spaces(&p);
2908 if (!left)
2909 break;
2911 err = proc_get_long(&p, &left, &val, &neg,
2912 proc_wspace_sep,
2913 sizeof(proc_wspace_sep), NULL);
2914 if (err)
2915 break;
2916 if (neg)
2917 continue;
2918 val = convmul * val / convdiv;
2919 if ((min && val < *min) || (max && val > *max)) {
2920 err = -EINVAL;
2921 break;
2923 *i = val;
2924 } else {
2925 val = convdiv * (*i) / convmul;
2926 if (!first) {
2927 err = proc_put_char(&buffer, &left, '\t');
2928 if (err)
2929 break;
2931 err = proc_put_long(&buffer, &left, val, false);
2932 if (err)
2933 break;
2937 if (!write && !first && left && !err)
2938 err = proc_put_char(&buffer, &left, '\n');
2939 if (write && !err)
2940 left -= proc_skip_spaces(&p);
2941 if (write) {
2942 kfree(kbuf);
2943 if (first)
2944 return err ? : -EINVAL;
2946 *lenp -= left;
2947 out:
2948 *ppos += *lenp;
2949 return err;
2952 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2953 void __user *buffer,
2954 size_t *lenp, loff_t *ppos,
2955 unsigned long convmul,
2956 unsigned long convdiv)
2958 return __do_proc_doulongvec_minmax(table->data, table, write,
2959 buffer, lenp, ppos, convmul, convdiv);
2963 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2964 * @table: the sysctl table
2965 * @write: %TRUE if this is a write to the sysctl file
2966 * @buffer: the user buffer
2967 * @lenp: the size of the user buffer
2968 * @ppos: file position
2970 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2971 * values from/to the user buffer, treated as an ASCII string.
2973 * This routine will ensure the values are within the range specified by
2974 * table->extra1 (min) and table->extra2 (max).
2976 * Returns 0 on success.
2978 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2979 void __user *buffer, size_t *lenp, loff_t *ppos)
2981 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2985 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2986 * @table: the sysctl table
2987 * @write: %TRUE if this is a write to the sysctl file
2988 * @buffer: the user buffer
2989 * @lenp: the size of the user buffer
2990 * @ppos: file position
2992 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2993 * values from/to the user buffer, treated as an ASCII string. The values
2994 * are treated as milliseconds, and converted to jiffies when they are stored.
2996 * This routine will ensure the values are within the range specified by
2997 * table->extra1 (min) and table->extra2 (max).
2999 * Returns 0 on success.
3001 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3002 void __user *buffer,
3003 size_t *lenp, loff_t *ppos)
3005 return do_proc_doulongvec_minmax(table, write, buffer,
3006 lenp, ppos, HZ, 1000l);
3010 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
3011 int *valp,
3012 int write, void *data)
3014 if (write) {
3015 if (*lvalp > INT_MAX / HZ)
3016 return 1;
3017 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
3018 } else {
3019 int val = *valp;
3020 unsigned long lval;
3021 if (val < 0) {
3022 *negp = true;
3023 lval = -(unsigned long)val;
3024 } else {
3025 *negp = false;
3026 lval = (unsigned long)val;
3028 *lvalp = lval / HZ;
3030 return 0;
3033 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
3034 int *valp,
3035 int write, void *data)
3037 if (write) {
3038 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3039 return 1;
3040 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3041 } else {
3042 int val = *valp;
3043 unsigned long lval;
3044 if (val < 0) {
3045 *negp = true;
3046 lval = -(unsigned long)val;
3047 } else {
3048 *negp = false;
3049 lval = (unsigned long)val;
3051 *lvalp = jiffies_to_clock_t(lval);
3053 return 0;
3056 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3057 int *valp,
3058 int write, void *data)
3060 if (write) {
3061 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3063 if (jif > INT_MAX)
3064 return 1;
3065 *valp = (int)jif;
3066 } else {
3067 int val = *valp;
3068 unsigned long lval;
3069 if (val < 0) {
3070 *negp = true;
3071 lval = -(unsigned long)val;
3072 } else {
3073 *negp = false;
3074 lval = (unsigned long)val;
3076 *lvalp = jiffies_to_msecs(lval);
3078 return 0;
3082 * proc_dointvec_jiffies - read a vector of integers as seconds
3083 * @table: the sysctl table
3084 * @write: %TRUE if this is a write to the sysctl file
3085 * @buffer: the user buffer
3086 * @lenp: the size of the user buffer
3087 * @ppos: file position
3089 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3090 * values from/to the user buffer, treated as an ASCII string.
3091 * The values read are assumed to be in seconds, and are converted into
3092 * jiffies.
3094 * Returns 0 on success.
3096 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3097 void __user *buffer, size_t *lenp, loff_t *ppos)
3099 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3100 do_proc_dointvec_jiffies_conv,NULL);
3104 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3105 * @table: the sysctl table
3106 * @write: %TRUE if this is a write to the sysctl file
3107 * @buffer: the user buffer
3108 * @lenp: the size of the user buffer
3109 * @ppos: pointer to the file position
3111 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3112 * values from/to the user buffer, treated as an ASCII string.
3113 * The values read are assumed to be in 1/USER_HZ seconds, and
3114 * are converted into jiffies.
3116 * Returns 0 on success.
3118 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3119 void __user *buffer, size_t *lenp, loff_t *ppos)
3121 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3122 do_proc_dointvec_userhz_jiffies_conv,NULL);
3126 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3127 * @table: the sysctl table
3128 * @write: %TRUE if this is a write to the sysctl file
3129 * @buffer: the user buffer
3130 * @lenp: the size of the user buffer
3131 * @ppos: file position
3132 * @ppos: the current position in the file
3134 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3135 * values from/to the user buffer, treated as an ASCII string.
3136 * The values read are assumed to be in 1/1000 seconds, and
3137 * are converted into jiffies.
3139 * Returns 0 on success.
3141 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3142 void __user *buffer, size_t *lenp, loff_t *ppos)
3144 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3145 do_proc_dointvec_ms_jiffies_conv, NULL);
3148 static int proc_do_cad_pid(struct ctl_table *table, int write,
3149 void __user *buffer, size_t *lenp, loff_t *ppos)
3151 struct pid *new_pid;
3152 pid_t tmp;
3153 int r;
3155 tmp = pid_vnr(cad_pid);
3157 r = __do_proc_dointvec(&tmp, table, write, buffer,
3158 lenp, ppos, NULL, NULL);
3159 if (r || !write)
3160 return r;
3162 new_pid = find_get_pid(tmp);
3163 if (!new_pid)
3164 return -ESRCH;
3166 put_pid(xchg(&cad_pid, new_pid));
3167 return 0;
3171 * proc_do_large_bitmap - read/write from/to a large bitmap
3172 * @table: the sysctl table
3173 * @write: %TRUE if this is a write to the sysctl file
3174 * @buffer: the user buffer
3175 * @lenp: the size of the user buffer
3176 * @ppos: file position
3178 * The bitmap is stored at table->data and the bitmap length (in bits)
3179 * in table->maxlen.
3181 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3182 * large bitmaps may be represented in a compact manner. Writing into
3183 * the file will clear the bitmap then update it with the given input.
3185 * Returns 0 on success.
3187 int proc_do_large_bitmap(struct ctl_table *table, int write,
3188 void __user *buffer, size_t *lenp, loff_t *ppos)
3190 int err = 0;
3191 bool first = 1;
3192 size_t left = *lenp;
3193 unsigned long bitmap_len = table->maxlen;
3194 unsigned long *bitmap = *(unsigned long **) table->data;
3195 unsigned long *tmp_bitmap = NULL;
3196 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3198 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3199 *lenp = 0;
3200 return 0;
3203 if (write) {
3204 char *kbuf, *p;
3205 size_t skipped = 0;
3207 if (left > PAGE_SIZE - 1) {
3208 left = PAGE_SIZE - 1;
3209 /* How much of the buffer we'll skip this pass */
3210 skipped = *lenp - left;
3213 p = kbuf = memdup_user_nul(buffer, left);
3214 if (IS_ERR(kbuf))
3215 return PTR_ERR(kbuf);
3217 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
3218 if (!tmp_bitmap) {
3219 kfree(kbuf);
3220 return -ENOMEM;
3222 proc_skip_char(&p, &left, '\n');
3223 while (!err && left) {
3224 unsigned long val_a, val_b;
3225 bool neg;
3226 size_t saved_left;
3228 /* In case we stop parsing mid-number, we can reset */
3229 saved_left = left;
3230 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3231 sizeof(tr_a), &c);
3233 * If we consumed the entirety of a truncated buffer or
3234 * only one char is left (may be a "-"), then stop here,
3235 * reset, & come back for more.
3237 if ((left <= 1) && skipped) {
3238 left = saved_left;
3239 break;
3242 if (err)
3243 break;
3244 if (val_a >= bitmap_len || neg) {
3245 err = -EINVAL;
3246 break;
3249 val_b = val_a;
3250 if (left) {
3251 p++;
3252 left--;
3255 if (c == '-') {
3256 err = proc_get_long(&p, &left, &val_b,
3257 &neg, tr_b, sizeof(tr_b),
3258 &c);
3260 * If we consumed all of a truncated buffer or
3261 * then stop here, reset, & come back for more.
3263 if (!left && skipped) {
3264 left = saved_left;
3265 break;
3268 if (err)
3269 break;
3270 if (val_b >= bitmap_len || neg ||
3271 val_a > val_b) {
3272 err = -EINVAL;
3273 break;
3275 if (left) {
3276 p++;
3277 left--;
3281 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3282 first = 0;
3283 proc_skip_char(&p, &left, '\n');
3285 kfree(kbuf);
3286 left += skipped;
3287 } else {
3288 unsigned long bit_a, bit_b = 0;
3290 while (left) {
3291 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3292 if (bit_a >= bitmap_len)
3293 break;
3294 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3295 bit_a + 1) - 1;
3297 if (!first) {
3298 err = proc_put_char(&buffer, &left, ',');
3299 if (err)
3300 break;
3302 err = proc_put_long(&buffer, &left, bit_a, false);
3303 if (err)
3304 break;
3305 if (bit_a != bit_b) {
3306 err = proc_put_char(&buffer, &left, '-');
3307 if (err)
3308 break;
3309 err = proc_put_long(&buffer, &left, bit_b, false);
3310 if (err)
3311 break;
3314 first = 0; bit_b++;
3316 if (!err)
3317 err = proc_put_char(&buffer, &left, '\n');
3320 if (!err) {
3321 if (write) {
3322 if (*ppos)
3323 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3324 else
3325 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3327 *lenp -= left;
3328 *ppos += *lenp;
3331 bitmap_free(tmp_bitmap);
3332 return err;
3335 #else /* CONFIG_PROC_SYSCTL */
3337 int proc_dostring(struct ctl_table *table, int write,
3338 void __user *buffer, size_t *lenp, loff_t *ppos)
3340 return -ENOSYS;
3343 int proc_dointvec(struct ctl_table *table, int write,
3344 void __user *buffer, size_t *lenp, loff_t *ppos)
3346 return -ENOSYS;
3349 int proc_douintvec(struct ctl_table *table, int write,
3350 void __user *buffer, size_t *lenp, loff_t *ppos)
3352 return -ENOSYS;
3355 int proc_dointvec_minmax(struct ctl_table *table, int write,
3356 void __user *buffer, size_t *lenp, loff_t *ppos)
3358 return -ENOSYS;
3361 int proc_douintvec_minmax(struct ctl_table *table, int write,
3362 void __user *buffer, size_t *lenp, loff_t *ppos)
3364 return -ENOSYS;
3367 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3368 void __user *buffer, size_t *lenp, loff_t *ppos)
3370 return -ENOSYS;
3373 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3374 void __user *buffer, size_t *lenp, loff_t *ppos)
3376 return -ENOSYS;
3379 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3380 void __user *buffer, size_t *lenp, loff_t *ppos)
3382 return -ENOSYS;
3385 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3386 void __user *buffer, size_t *lenp, loff_t *ppos)
3388 return -ENOSYS;
3391 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3392 void __user *buffer,
3393 size_t *lenp, loff_t *ppos)
3395 return -ENOSYS;
3398 int proc_do_large_bitmap(struct ctl_table *table, int write,
3399 void __user *buffer, size_t *lenp, loff_t *ppos)
3401 return -ENOSYS;
3404 #endif /* CONFIG_PROC_SYSCTL */
3406 #if defined(CONFIG_SYSCTL)
3407 int proc_do_static_key(struct ctl_table *table, int write,
3408 void __user *buffer, size_t *lenp,
3409 loff_t *ppos)
3411 struct static_key *key = (struct static_key *)table->data;
3412 static DEFINE_MUTEX(static_key_mutex);
3413 int val, ret;
3414 struct ctl_table tmp = {
3415 .data = &val,
3416 .maxlen = sizeof(val),
3417 .mode = table->mode,
3418 .extra1 = SYSCTL_ZERO,
3419 .extra2 = SYSCTL_ONE,
3422 if (write && !capable(CAP_SYS_ADMIN))
3423 return -EPERM;
3425 mutex_lock(&static_key_mutex);
3426 val = static_key_enabled(key);
3427 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3428 if (write && !ret) {
3429 if (val)
3430 static_key_enable(key);
3431 else
3432 static_key_disable(key);
3434 mutex_unlock(&static_key_mutex);
3435 return ret;
3437 #endif
3439 * No sense putting this after each symbol definition, twice,
3440 * exception granted :-)
3442 EXPORT_SYMBOL(proc_dointvec);
3443 EXPORT_SYMBOL(proc_douintvec);
3444 EXPORT_SYMBOL(proc_dointvec_jiffies);
3445 EXPORT_SYMBOL(proc_dointvec_minmax);
3446 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3447 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3448 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3449 EXPORT_SYMBOL(proc_dostring);
3450 EXPORT_SYMBOL(proc_doulongvec_minmax);
3451 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3452 EXPORT_SYMBOL(proc_do_large_bitmap);