projects/linux·blob v5.6 · refs

3422 lines · 80.2 KiB

1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * sysctl.c: General linux system control interface
4 *
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
20 */
21
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>
71
72#include "../lib/kstrtox.h"
73
74#include <linux/uaccess.h>
75#include <asm/processor.h>
76
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
103
104#if defined(CONFIG_SYSCTL)
105
106/* External variables not in a header file. */
107extern int suid_dumpable;
108#ifdef CONFIG_COREDUMP
109extern int core_uses_pid;
110extern char core_pattern[];
111extern unsigned int core_pipe_limit;
112#endif
113extern int pid_max;
114extern int pid_max_min, pid_max_max;
115extern int percpu_pagelist_fraction;
116extern int latencytop_enabled;
117extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
118#ifndef CONFIG_MMU
119extern int sysctl_nr_trim_pages;
120#endif
121
122/* Constants used for minimum and maximum */
123#ifdef CONFIG_LOCKUP_DETECTOR
124static int sixty = 60;
125#endif
126
127static int __maybe_unused neg_one = -1;
128static int __maybe_unused two = 2;
129static int __maybe_unused four = 4;
130static unsigned long zero_ul;
131static unsigned long one_ul = 1;
132static unsigned long long_max = LONG_MAX;
133static int one_hundred = 100;
134static int one_thousand = 1000;
135#ifdef CONFIG_PRINTK
136static int ten_thousand = 10000;
137#endif
138#ifdef CONFIG_PERF_EVENTS
139static int six_hundred_forty_kb = 640 * 1024;
140#endif
141
142/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
143static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
144
145/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
146static int maxolduid = 65535;
147static int minolduid;
148
149static int ngroups_max = NGROUPS_MAX;
150static const int cap_last_cap = CAP_LAST_CAP;
151
152/*
153 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
154 * and hung_task_check_interval_secs
155 */
156#ifdef CONFIG_DETECT_HUNG_TASK
157static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
158#endif
159
160#ifdef CONFIG_INOTIFY_USER
161#include <linux/inotify.h>
162#endif
163#ifdef CONFIG_SPARC
164#endif
165
166#ifdef CONFIG_PARISC
167extern int pwrsw_enabled;
168#endif
169
170#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
171extern int unaligned_enabled;
172#endif
173
174#ifdef CONFIG_IA64
175extern int unaligned_dump_stack;
176#endif
177
178#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179extern int no_unaligned_warning;
180#endif
181
182#ifdef CONFIG_PROC_SYSCTL
183
184/**
185 * enum sysctl_writes_mode - supported sysctl write modes
186 *
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.
199 *
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
202 */
203enum sysctl_writes_mode {
204 SYSCTL_WRITES_LEGACY = -1,
205 SYSCTL_WRITES_WARN = 0,
206 SYSCTL_WRITES_STRICT = 1,
207};
208
209static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
210
211static int proc_do_cad_pid(struct ctl_table *table, int write,
212 void __user *buffer, size_t *lenp, loff_t *ppos);
213static int proc_taint(struct ctl_table *table, int write,
214 void __user *buffer, size_t *lenp, loff_t *ppos);
215#endif
216
217#ifdef CONFIG_PRINTK
218static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
219 void __user *buffer, size_t *lenp, loff_t *ppos);
220#endif
221
222static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
223 void __user *buffer, size_t *lenp, loff_t *ppos);
224#ifdef CONFIG_COREDUMP
225static int proc_dostring_coredump(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
227#endif
228static int proc_dopipe_max_size(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp, loff_t *ppos);
230
231#ifdef CONFIG_MAGIC_SYSRQ
232/* Note: sysrq code uses its own private copy */
233static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
234
235static int sysrq_sysctl_handler(struct ctl_table *table, int write,
236 void __user *buffer, size_t *lenp,
237 loff_t *ppos)
238{
239 int error;
240
241 error = proc_dointvec(table, write, buffer, lenp, ppos);
242 if (error)
243 return error;
244
245 if (write)
246 sysrq_toggle_support(__sysrq_enabled);
247
248 return 0;
249}
250
251#endif
252
253static struct ctl_table kern_table[];
254static struct ctl_table vm_table[];
255static struct ctl_table fs_table[];
256static struct ctl_table debug_table[];
257static struct ctl_table dev_table[];
258extern struct ctl_table random_table[];
259#ifdef CONFIG_EPOLL
260extern struct ctl_table epoll_table[];
261#endif
262
263#ifdef CONFIG_FW_LOADER_USER_HELPER
264extern struct ctl_table firmware_config_table[];
265#endif
266
267#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
268 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
269int sysctl_legacy_va_layout;
270#endif
271
272/* The default sysctl tables: */
273
274static struct ctl_table sysctl_base_table[] = {
275 {
276 .procname = "kernel",
277 .mode = 0555,
278 .child = kern_table,
279 },
280 {
281 .procname = "vm",
282 .mode = 0555,
283 .child = vm_table,
284 },
285 {
286 .procname = "fs",
287 .mode = 0555,
288 .child = fs_table,
289 },
290 {
291 .procname = "debug",
292 .mode = 0555,
293 .child = debug_table,
294 },
295 {
296 .procname = "dev",
297 .mode = 0555,
298 .child = dev_table,
299 },
300 { }
301};
302
303#ifdef CONFIG_SCHED_DEBUG
304static int min_sched_granularity_ns = 100000; /* 100 usecs */
305static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
306static int min_wakeup_granularity_ns; /* 0 usecs */
307static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
308#ifdef CONFIG_SMP
309static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
310static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
311#endif /* CONFIG_SMP */
312#endif /* CONFIG_SCHED_DEBUG */
313
314#ifdef CONFIG_COMPACTION
315static int min_extfrag_threshold;
316static int max_extfrag_threshold = 1000;
317#endif
318
319static struct ctl_table kern_table[] = {
320 {
321 .procname = "sched_child_runs_first",
322 .data = &sysctl_sched_child_runs_first,
323 .maxlen = sizeof(unsigned int),
324 .mode = 0644,
325 .proc_handler = proc_dointvec,
326 },
327#ifdef CONFIG_SCHED_DEBUG
328 {
329 .procname = "sched_min_granularity_ns",
330 .data = &sysctl_sched_min_granularity,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
333 .proc_handler = sched_proc_update_handler,
334 .extra1 = &min_sched_granularity_ns,
335 .extra2 = &max_sched_granularity_ns,
336 },
337 {
338 .procname = "sched_latency_ns",
339 .data = &sysctl_sched_latency,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
342 .proc_handler = sched_proc_update_handler,
343 .extra1 = &min_sched_granularity_ns,
344 .extra2 = &max_sched_granularity_ns,
345 },
346 {
347 .procname = "sched_wakeup_granularity_ns",
348 .data = &sysctl_sched_wakeup_granularity,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
351 .proc_handler = sched_proc_update_handler,
352 .extra1 = &min_wakeup_granularity_ns,
353 .extra2 = &max_wakeup_granularity_ns,
354 },
355#ifdef CONFIG_SMP
356 {
357 .procname = "sched_tunable_scaling",
358 .data = &sysctl_sched_tunable_scaling,
359 .maxlen = sizeof(enum sched_tunable_scaling),
360 .mode = 0644,
361 .proc_handler = sched_proc_update_handler,
362 .extra1 = &min_sched_tunable_scaling,
363 .extra2 = &max_sched_tunable_scaling,
364 },
365 {
366 .procname = "sched_migration_cost_ns",
367 .data = &sysctl_sched_migration_cost,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
370 .proc_handler = proc_dointvec,
371 },
372 {
373 .procname = "sched_nr_migrate",
374 .data = &sysctl_sched_nr_migrate,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
377 .proc_handler = proc_dointvec,
378 },
379#ifdef CONFIG_SCHEDSTATS
380 {
381 .procname = "sched_schedstats",
382 .data = NULL,
383 .maxlen = sizeof(unsigned int),
384 .mode = 0644,
385 .proc_handler = sysctl_schedstats,
386 .extra1 = SYSCTL_ZERO,
387 .extra2 = SYSCTL_ONE,
388 },
389#endif /* CONFIG_SCHEDSTATS */
390#endif /* CONFIG_SMP */
391#ifdef CONFIG_NUMA_BALANCING
392 {
393 .procname = "numa_balancing_scan_delay_ms",
394 .data = &sysctl_numa_balancing_scan_delay,
395 .maxlen = sizeof(unsigned int),
396 .mode = 0644,
397 .proc_handler = proc_dointvec,
398 },
399 {
400 .procname = "numa_balancing_scan_period_min_ms",
401 .data = &sysctl_numa_balancing_scan_period_min,
402 .maxlen = sizeof(unsigned int),
403 .mode = 0644,
404 .proc_handler = proc_dointvec,
405 },
406 {
407 .procname = "numa_balancing_scan_period_max_ms",
408 .data = &sysctl_numa_balancing_scan_period_max,
409 .maxlen = sizeof(unsigned int),
410 .mode = 0644,
411 .proc_handler = proc_dointvec,
412 },
413 {
414 .procname = "numa_balancing_scan_size_mb",
415 .data = &sysctl_numa_balancing_scan_size,
416 .maxlen = sizeof(unsigned int),
417 .mode = 0644,
418 .proc_handler = proc_dointvec_minmax,
419 .extra1 = SYSCTL_ONE,
420 },
421 {
422 .procname = "numa_balancing",
423 .data = NULL, /* filled in by handler */
424 .maxlen = sizeof(unsigned int),
425 .mode = 0644,
426 .proc_handler = sysctl_numa_balancing,
427 .extra1 = SYSCTL_ZERO,
428 .extra2 = SYSCTL_ONE,
429 },
430#endif /* CONFIG_NUMA_BALANCING */
431#endif /* CONFIG_SCHED_DEBUG */
432 {
433 .procname = "sched_rt_period_us",
434 .data = &sysctl_sched_rt_period,
435 .maxlen = sizeof(unsigned int),
436 .mode = 0644,
437 .proc_handler = sched_rt_handler,
438 },
439 {
440 .procname = "sched_rt_runtime_us",
441 .data = &sysctl_sched_rt_runtime,
442 .maxlen = sizeof(int),
443 .mode = 0644,
444 .proc_handler = sched_rt_handler,
445 },
446 {
447 .procname = "sched_rr_timeslice_ms",
448 .data = &sysctl_sched_rr_timeslice,
449 .maxlen = sizeof(int),
450 .mode = 0644,
451 .proc_handler = sched_rr_handler,
452 },
453#ifdef CONFIG_UCLAMP_TASK
454 {
455 .procname = "sched_util_clamp_min",
456 .data = &sysctl_sched_uclamp_util_min,
457 .maxlen = sizeof(unsigned int),
458 .mode = 0644,
459 .proc_handler = sysctl_sched_uclamp_handler,
460 },
461 {
462 .procname = "sched_util_clamp_max",
463 .data = &sysctl_sched_uclamp_util_max,
464 .maxlen = sizeof(unsigned int),
465 .mode = 0644,
466 .proc_handler = sysctl_sched_uclamp_handler,
467 },
468#endif
469#ifdef CONFIG_SCHED_AUTOGROUP
470 {
471 .procname = "sched_autogroup_enabled",
472 .data = &sysctl_sched_autogroup_enabled,
473 .maxlen = sizeof(unsigned int),
474 .mode = 0644,
475 .proc_handler = proc_dointvec_minmax,
476 .extra1 = SYSCTL_ZERO,
477 .extra2 = SYSCTL_ONE,
478 },
479#endif
480#ifdef CONFIG_CFS_BANDWIDTH
481 {
482 .procname = "sched_cfs_bandwidth_slice_us",
483 .data = &sysctl_sched_cfs_bandwidth_slice,
484 .maxlen = sizeof(unsigned int),
485 .mode = 0644,
486 .proc_handler = proc_dointvec_minmax,
487 .extra1 = SYSCTL_ONE,
488 },
489#endif
490#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
491 {
492 .procname = "sched_energy_aware",
493 .data = &sysctl_sched_energy_aware,
494 .maxlen = sizeof(unsigned int),
495 .mode = 0644,
496 .proc_handler = sched_energy_aware_handler,
497 .extra1 = SYSCTL_ZERO,
498 .extra2 = SYSCTL_ONE,
499 },
500#endif
501#ifdef CONFIG_PROVE_LOCKING
502 {
503 .procname = "prove_locking",
504 .data = &prove_locking,
505 .maxlen = sizeof(int),
506 .mode = 0644,
507 .proc_handler = proc_dointvec,
508 },
509#endif
510#ifdef CONFIG_LOCK_STAT
511 {
512 .procname = "lock_stat",
513 .data = &lock_stat,
514 .maxlen = sizeof(int),
515 .mode = 0644,
516 .proc_handler = proc_dointvec,
517 },
518#endif
519 {
520 .procname = "panic",
521 .data = &panic_timeout,
522 .maxlen = sizeof(int),
523 .mode = 0644,
524 .proc_handler = proc_dointvec,
525 },
526#ifdef CONFIG_COREDUMP
527 {
528 .procname = "core_uses_pid",
529 .data = &core_uses_pid,
530 .maxlen = sizeof(int),
531 .mode = 0644,
532 .proc_handler = proc_dointvec,
533 },
534 {
535 .procname = "core_pattern",
536 .data = core_pattern,
537 .maxlen = CORENAME_MAX_SIZE,
538 .mode = 0644,
539 .proc_handler = proc_dostring_coredump,
540 },
541 {
542 .procname = "core_pipe_limit",
543 .data = &core_pipe_limit,
544 .maxlen = sizeof(unsigned int),
545 .mode = 0644,
546 .proc_handler = proc_dointvec,
547 },
548#endif
549#ifdef CONFIG_PROC_SYSCTL
550 {
551 .procname = "tainted",
552 .maxlen = sizeof(long),
553 .mode = 0644,
554 .proc_handler = proc_taint,
555 },
556 {
557 .procname = "sysctl_writes_strict",
558 .data = &sysctl_writes_strict,
559 .maxlen = sizeof(int),
560 .mode = 0644,
561 .proc_handler = proc_dointvec_minmax,
562 .extra1 = &neg_one,
563 .extra2 = SYSCTL_ONE,
564 },
565#endif
566#ifdef CONFIG_LATENCYTOP
567 {
568 .procname = "latencytop",
569 .data = &latencytop_enabled,
570 .maxlen = sizeof(int),
571 .mode = 0644,
572 .proc_handler = sysctl_latencytop,
573 },
574#endif
575#ifdef CONFIG_BLK_DEV_INITRD
576 {
577 .procname = "real-root-dev",
578 .data = &real_root_dev,
579 .maxlen = sizeof(int),
580 .mode = 0644,
581 .proc_handler = proc_dointvec,
582 },
583#endif
584 {
585 .procname = "print-fatal-signals",
586 .data = &print_fatal_signals,
587 .maxlen = sizeof(int),
588 .mode = 0644,
589 .proc_handler = proc_dointvec,
590 },
591#ifdef CONFIG_SPARC
592 {
593 .procname = "reboot-cmd",
594 .data = reboot_command,
595 .maxlen = 256,
596 .mode = 0644,
597 .proc_handler = proc_dostring,
598 },
599 {
600 .procname = "stop-a",
601 .data = &stop_a_enabled,
602 .maxlen = sizeof (int),
603 .mode = 0644,
604 .proc_handler = proc_dointvec,
605 },
606 {
607 .procname = "scons-poweroff",
608 .data = &scons_pwroff,
609 .maxlen = sizeof (int),
610 .mode = 0644,
611 .proc_handler = proc_dointvec,
612 },
613#endif
614#ifdef CONFIG_SPARC64
615 {
616 .procname = "tsb-ratio",
617 .data = &sysctl_tsb_ratio,
618 .maxlen = sizeof (int),
619 .mode = 0644,
620 .proc_handler = proc_dointvec,
621 },
622#endif
623#ifdef CONFIG_PARISC
624 {
625 .procname = "soft-power",
626 .data = &pwrsw_enabled,
627 .maxlen = sizeof (int),
628 .mode = 0644,
629 .proc_handler = proc_dointvec,
630 },
631#endif
632#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
633 {
634 .procname = "unaligned-trap",
635 .data = &unaligned_enabled,
636 .maxlen = sizeof (int),
637 .mode = 0644,
638 .proc_handler = proc_dointvec,
639 },
640#endif
641 {
642 .procname = "ctrl-alt-del",
643 .data = &C_A_D,
644 .maxlen = sizeof(int),
645 .mode = 0644,
646 .proc_handler = proc_dointvec,
647 },
648#ifdef CONFIG_FUNCTION_TRACER
649 {
650 .procname = "ftrace_enabled",
651 .data = &ftrace_enabled,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 .proc_handler = ftrace_enable_sysctl,
655 },
656#endif
657#ifdef CONFIG_STACK_TRACER
658 {
659 .procname = "stack_tracer_enabled",
660 .data = &stack_tracer_enabled,
661 .maxlen = sizeof(int),
662 .mode = 0644,
663 .proc_handler = stack_trace_sysctl,
664 },
665#endif
666#ifdef CONFIG_TRACING
667 {
668 .procname = "ftrace_dump_on_oops",
669 .data = &ftrace_dump_on_oops,
670 .maxlen = sizeof(int),
671 .mode = 0644,
672 .proc_handler = proc_dointvec,
673 },
674 {
675 .procname = "traceoff_on_warning",
676 .data = &__disable_trace_on_warning,
677 .maxlen = sizeof(__disable_trace_on_warning),
678 .mode = 0644,
679 .proc_handler = proc_dointvec,
680 },
681 {
682 .procname = "tracepoint_printk",
683 .data = &tracepoint_printk,
684 .maxlen = sizeof(tracepoint_printk),
685 .mode = 0644,
686 .proc_handler = tracepoint_printk_sysctl,
687 },
688#endif
689#ifdef CONFIG_KEXEC_CORE
690 {
691 .procname = "kexec_load_disabled",
692 .data = &kexec_load_disabled,
693 .maxlen = sizeof(int),
694 .mode = 0644,
695 /* only handle a transition from default "0" to "1" */
696 .proc_handler = proc_dointvec_minmax,
697 .extra1 = SYSCTL_ONE,
698 .extra2 = SYSCTL_ONE,
699 },
700#endif
701#ifdef CONFIG_MODULES
702 {
703 .procname = "modprobe",
704 .data = &modprobe_path,
705 .maxlen = KMOD_PATH_LEN,
706 .mode = 0644,
707 .proc_handler = proc_dostring,
708 },
709 {
710 .procname = "modules_disabled",
711 .data = &modules_disabled,
712 .maxlen = sizeof(int),
713 .mode = 0644,
714 /* only handle a transition from default "0" to "1" */
715 .proc_handler = proc_dointvec_minmax,
716 .extra1 = SYSCTL_ONE,
717 .extra2 = SYSCTL_ONE,
718 },
719#endif
720#ifdef CONFIG_UEVENT_HELPER
721 {
722 .procname = "hotplug",
723 .data = &uevent_helper,
724 .maxlen = UEVENT_HELPER_PATH_LEN,
725 .mode = 0644,
726 .proc_handler = proc_dostring,
727 },
728#endif
729#ifdef CONFIG_CHR_DEV_SG
730 {
731 .procname = "sg-big-buff",
732 .data = &sg_big_buff,
733 .maxlen = sizeof (int),
734 .mode = 0444,
735 .proc_handler = proc_dointvec,
736 },
737#endif
738#ifdef CONFIG_BSD_PROCESS_ACCT
739 {
740 .procname = "acct",
741 .data = &acct_parm,
742 .maxlen = 3*sizeof(int),
743 .mode = 0644,
744 .proc_handler = proc_dointvec,
745 },
746#endif
747#ifdef CONFIG_MAGIC_SYSRQ
748 {
749 .procname = "sysrq",
750 .data = &__sysrq_enabled,
751 .maxlen = sizeof (int),
752 .mode = 0644,
753 .proc_handler = sysrq_sysctl_handler,
754 },
755#endif
756#ifdef CONFIG_PROC_SYSCTL
757 {
758 .procname = "cad_pid",
759 .data = NULL,
760 .maxlen = sizeof (int),
761 .mode = 0600,
762 .proc_handler = proc_do_cad_pid,
763 },
764#endif
765 {
766 .procname = "threads-max",
767 .data = NULL,
768 .maxlen = sizeof(int),
769 .mode = 0644,
770 .proc_handler = sysctl_max_threads,
771 },
772 {
773 .procname = "random",
774 .mode = 0555,
775 .child = random_table,
776 },
777 {
778 .procname = "usermodehelper",
779 .mode = 0555,
780 .child = usermodehelper_table,
781 },
782#ifdef CONFIG_FW_LOADER_USER_HELPER
783 {
784 .procname = "firmware_config",
785 .mode = 0555,
786 .child = firmware_config_table,
787 },
788#endif
789 {
790 .procname = "overflowuid",
791 .data = &overflowuid,
792 .maxlen = sizeof(int),
793 .mode = 0644,
794 .proc_handler = proc_dointvec_minmax,
795 .extra1 = &minolduid,
796 .extra2 = &maxolduid,
797 },
798 {
799 .procname = "overflowgid",
800 .data = &overflowgid,
801 .maxlen = sizeof(int),
802 .mode = 0644,
803 .proc_handler = proc_dointvec_minmax,
804 .extra1 = &minolduid,
805 .extra2 = &maxolduid,
806 },
807#ifdef CONFIG_S390
808 {
809 .procname = "userprocess_debug",
810 .data = &show_unhandled_signals,
811 .maxlen = sizeof(int),
812 .mode = 0644,
813 .proc_handler = proc_dointvec,
814 },
815#endif
816 {
817 .procname = "pid_max",
818 .data = &pid_max,
819 .maxlen = sizeof (int),
820 .mode = 0644,
821 .proc_handler = proc_dointvec_minmax,
822 .extra1 = &pid_max_min,
823 .extra2 = &pid_max_max,
824 },
825 {
826 .procname = "panic_on_oops",
827 .data = &panic_on_oops,
828 .maxlen = sizeof(int),
829 .mode = 0644,
830 .proc_handler = proc_dointvec,
831 },
832 {
833 .procname = "panic_print",
834 .data = &panic_print,
835 .maxlen = sizeof(unsigned long),
836 .mode = 0644,
837 .proc_handler = proc_doulongvec_minmax,
838 },
839#if defined CONFIG_PRINTK
840 {
841 .procname = "printk",
842 .data = &console_loglevel,
843 .maxlen = 4*sizeof(int),
844 .mode = 0644,
845 .proc_handler = proc_dointvec,
846 },
847 {
848 .procname = "printk_ratelimit",
849 .data = &printk_ratelimit_state.interval,
850 .maxlen = sizeof(int),
851 .mode = 0644,
852 .proc_handler = proc_dointvec_jiffies,
853 },
854 {
855 .procname = "printk_ratelimit_burst",
856 .data = &printk_ratelimit_state.burst,
857 .maxlen = sizeof(int),
858 .mode = 0644,
859 .proc_handler = proc_dointvec,
860 },
861 {
862 .procname = "printk_delay",
863 .data = &printk_delay_msec,
864 .maxlen = sizeof(int),
865 .mode = 0644,
866 .proc_handler = proc_dointvec_minmax,
867 .extra1 = SYSCTL_ZERO,
868 .extra2 = &ten_thousand,
869 },
870 {
871 .procname = "printk_devkmsg",
872 .data = devkmsg_log_str,
873 .maxlen = DEVKMSG_STR_MAX_SIZE,
874 .mode = 0644,
875 .proc_handler = devkmsg_sysctl_set_loglvl,
876 },
877 {
878 .procname = "dmesg_restrict",
879 .data = &dmesg_restrict,
880 .maxlen = sizeof(int),
881 .mode = 0644,
882 .proc_handler = proc_dointvec_minmax_sysadmin,
883 .extra1 = SYSCTL_ZERO,
884 .extra2 = SYSCTL_ONE,
885 },
886 {
887 .procname = "kptr_restrict",
888 .data = &kptr_restrict,
889 .maxlen = sizeof(int),
890 .mode = 0644,
891 .proc_handler = proc_dointvec_minmax_sysadmin,
892 .extra1 = SYSCTL_ZERO,
893 .extra2 = &two,
894 },
895#endif
896 {
897 .procname = "ngroups_max",
898 .data = &ngroups_max,
899 .maxlen = sizeof (int),
900 .mode = 0444,
901 .proc_handler = proc_dointvec,
902 },
903 {
904 .procname = "cap_last_cap",
905 .data = (void *)&cap_last_cap,
906 .maxlen = sizeof(int),
907 .mode = 0444,
908 .proc_handler = proc_dointvec,
909 },
910#if defined(CONFIG_LOCKUP_DETECTOR)
911 {
912 .procname = "watchdog",
913 .data = &watchdog_user_enabled,
914 .maxlen = sizeof(int),
915 .mode = 0644,
916 .proc_handler = proc_watchdog,
917 .extra1 = SYSCTL_ZERO,
918 .extra2 = SYSCTL_ONE,
919 },
920 {
921 .procname = "watchdog_thresh",
922 .data = &watchdog_thresh,
923 .maxlen = sizeof(int),
924 .mode = 0644,
925 .proc_handler = proc_watchdog_thresh,
926 .extra1 = SYSCTL_ZERO,
927 .extra2 = &sixty,
928 },
929 {
930 .procname = "nmi_watchdog",
931 .data = &nmi_watchdog_user_enabled,
932 .maxlen = sizeof(int),
933 .mode = NMI_WATCHDOG_SYSCTL_PERM,
934 .proc_handler = proc_nmi_watchdog,
935 .extra1 = SYSCTL_ZERO,
936 .extra2 = SYSCTL_ONE,
937 },
938 {
939 .procname = "watchdog_cpumask",
940 .data = &watchdog_cpumask_bits,
941 .maxlen = NR_CPUS,
942 .mode = 0644,
943 .proc_handler = proc_watchdog_cpumask,
944 },
945#ifdef CONFIG_SOFTLOCKUP_DETECTOR
946 {
947 .procname = "soft_watchdog",
948 .data = &soft_watchdog_user_enabled,
949 .maxlen = sizeof(int),
950 .mode = 0644,
951 .proc_handler = proc_soft_watchdog,
952 .extra1 = SYSCTL_ZERO,
953 .extra2 = SYSCTL_ONE,
954 },
955 {
956 .procname = "softlockup_panic",
957 .data = &softlockup_panic,
958 .maxlen = sizeof(int),
959 .mode = 0644,
960 .proc_handler = proc_dointvec_minmax,
961 .extra1 = SYSCTL_ZERO,
962 .extra2 = SYSCTL_ONE,
963 },
964#ifdef CONFIG_SMP
965 {
966 .procname = "softlockup_all_cpu_backtrace",
967 .data = &sysctl_softlockup_all_cpu_backtrace,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = proc_dointvec_minmax,
971 .extra1 = SYSCTL_ZERO,
972 .extra2 = SYSCTL_ONE,
973 },
974#endif /* CONFIG_SMP */
975#endif
976#ifdef CONFIG_HARDLOCKUP_DETECTOR
977 {
978 .procname = "hardlockup_panic",
979 .data = &hardlockup_panic,
980 .maxlen = sizeof(int),
981 .mode = 0644,
982 .proc_handler = proc_dointvec_minmax,
983 .extra1 = SYSCTL_ZERO,
984 .extra2 = SYSCTL_ONE,
985 },
986#ifdef CONFIG_SMP
987 {
988 .procname = "hardlockup_all_cpu_backtrace",
989 .data = &sysctl_hardlockup_all_cpu_backtrace,
990 .maxlen = sizeof(int),
991 .mode = 0644,
992 .proc_handler = proc_dointvec_minmax,
993 .extra1 = SYSCTL_ZERO,
994 .extra2 = SYSCTL_ONE,
995 },
996#endif /* CONFIG_SMP */
997#endif
998#endif
999
1000#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1001 {
1002 .procname = "unknown_nmi_panic",
1003 .data = &unknown_nmi_panic,
1004 .maxlen = sizeof (int),
1005 .mode = 0644,
1006 .proc_handler = proc_dointvec,
1007 },
1008#endif
1009#if defined(CONFIG_X86)
1010 {
1011 .procname = "panic_on_unrecovered_nmi",
1012 .data = &panic_on_unrecovered_nmi,
1013 .maxlen = sizeof(int),
1014 .mode = 0644,
1015 .proc_handler = proc_dointvec,
1016 },
1017 {
1018 .procname = "panic_on_io_nmi",
1019 .data = &panic_on_io_nmi,
1020 .maxlen = sizeof(int),
1021 .mode = 0644,
1022 .proc_handler = proc_dointvec,
1023 },
1024#ifdef CONFIG_DEBUG_STACKOVERFLOW
1025 {
1026 .procname = "panic_on_stackoverflow",
1027 .data = &sysctl_panic_on_stackoverflow,
1028 .maxlen = sizeof(int),
1029 .mode = 0644,
1030 .proc_handler = proc_dointvec,
1031 },
1032#endif
1033 {
1034 .procname = "bootloader_type",
1035 .data = &bootloader_type,
1036 .maxlen = sizeof (int),
1037 .mode = 0444,
1038 .proc_handler = proc_dointvec,
1039 },
1040 {
1041 .procname = "bootloader_version",
1042 .data = &bootloader_version,
1043 .maxlen = sizeof (int),
1044 .mode = 0444,
1045 .proc_handler = proc_dointvec,
1046 },
1047 {
1048 .procname = "io_delay_type",
1049 .data = &io_delay_type,
1050 .maxlen = sizeof(int),
1051 .mode = 0644,
1052 .proc_handler = proc_dointvec,
1053 },
1054#endif
1055#if defined(CONFIG_MMU)
1056 {
1057 .procname = "randomize_va_space",
1058 .data = &randomize_va_space,
1059 .maxlen = sizeof(int),
1060 .mode = 0644,
1061 .proc_handler = proc_dointvec,
1062 },
1063#endif
1064#if defined(CONFIG_S390) && defined(CONFIG_SMP)
1065 {
1066 .procname = "spin_retry",
1067 .data = &spin_retry,
1068 .maxlen = sizeof (int),
1069 .mode = 0644,
1070 .proc_handler = proc_dointvec,
1071 },
1072#endif
1073#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1074 {
1075 .procname = "acpi_video_flags",
1076 .data = &acpi_realmode_flags,
1077 .maxlen = sizeof (unsigned long),
1078 .mode = 0644,
1079 .proc_handler = proc_doulongvec_minmax,
1080 },
1081#endif
1082#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1083 {
1084 .procname = "ignore-unaligned-usertrap",
1085 .data = &no_unaligned_warning,
1086 .maxlen = sizeof (int),
1087 .mode = 0644,
1088 .proc_handler = proc_dointvec,
1089 },
1090#endif
1091#ifdef CONFIG_IA64
1092 {
1093 .procname = "unaligned-dump-stack",
1094 .data = &unaligned_dump_stack,
1095 .maxlen = sizeof (int),
1096 .mode = 0644,
1097 .proc_handler = proc_dointvec,
1098 },
1099#endif
1100#ifdef CONFIG_DETECT_HUNG_TASK
1101 {
1102 .procname = "hung_task_panic",
1103 .data = &sysctl_hung_task_panic,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
1106 .proc_handler = proc_dointvec_minmax,
1107 .extra1 = SYSCTL_ZERO,
1108 .extra2 = SYSCTL_ONE,
1109 },
1110 {
1111 .procname = "hung_task_check_count",
1112 .data = &sysctl_hung_task_check_count,
1113 .maxlen = sizeof(int),
1114 .mode = 0644,
1115 .proc_handler = proc_dointvec_minmax,
1116 .extra1 = SYSCTL_ZERO,
1117 },
1118 {
1119 .procname = "hung_task_timeout_secs",
1120 .data = &sysctl_hung_task_timeout_secs,
1121 .maxlen = sizeof(unsigned long),
1122 .mode = 0644,
1123 .proc_handler = proc_dohung_task_timeout_secs,
1124 .extra2 = &hung_task_timeout_max,
1125 },
1126 {
1127 .procname = "hung_task_check_interval_secs",
1128 .data = &sysctl_hung_task_check_interval_secs,
1129 .maxlen = sizeof(unsigned long),
1130 .mode = 0644,
1131 .proc_handler = proc_dohung_task_timeout_secs,
1132 .extra2 = &hung_task_timeout_max,
1133 },
1134 {
1135 .procname = "hung_task_warnings",
1136 .data = &sysctl_hung_task_warnings,
1137 .maxlen = sizeof(int),
1138 .mode = 0644,
1139 .proc_handler = proc_dointvec_minmax,
1140 .extra1 = &neg_one,
1141 },
1142#endif
1143#ifdef CONFIG_RT_MUTEXES
1144 {
1145 .procname = "max_lock_depth",
1146 .data = &max_lock_depth,
1147 .maxlen = sizeof(int),
1148 .mode = 0644,
1149 .proc_handler = proc_dointvec,
1150 },
1151#endif
1152 {
1153 .procname = "poweroff_cmd",
1154 .data = &poweroff_cmd,
1155 .maxlen = POWEROFF_CMD_PATH_LEN,
1156 .mode = 0644,
1157 .proc_handler = proc_dostring,
1158 },
1159#ifdef CONFIG_KEYS
1160 {
1161 .procname = "keys",
1162 .mode = 0555,
1163 .child = key_sysctls,
1164 },
1165#endif
1166#ifdef CONFIG_PERF_EVENTS
1167 /*
1168 * User-space scripts rely on the existence of this file
1169 * as a feature check for perf_events being enabled.
1170 *
1171 * So it's an ABI, do not remove!
1172 */
1173 {
1174 .procname = "perf_event_paranoid",
1175 .data = &sysctl_perf_event_paranoid,
1176 .maxlen = sizeof(sysctl_perf_event_paranoid),
1177 .mode = 0644,
1178 .proc_handler = proc_dointvec,
1179 },
1180 {
1181 .procname = "perf_event_mlock_kb",
1182 .data = &sysctl_perf_event_mlock,
1183 .maxlen = sizeof(sysctl_perf_event_mlock),
1184 .mode = 0644,
1185 .proc_handler = proc_dointvec,
1186 },
1187 {
1188 .procname = "perf_event_max_sample_rate",
1189 .data = &sysctl_perf_event_sample_rate,
1190 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1191 .mode = 0644,
1192 .proc_handler = perf_proc_update_handler,
1193 .extra1 = SYSCTL_ONE,
1194 },
1195 {
1196 .procname = "perf_cpu_time_max_percent",
1197 .data = &sysctl_perf_cpu_time_max_percent,
1198 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1199 .mode = 0644,
1200 .proc_handler = perf_cpu_time_max_percent_handler,
1201 .extra1 = SYSCTL_ZERO,
1202 .extra2 = &one_hundred,
1203 },
1204 {
1205 .procname = "perf_event_max_stack",
1206 .data = &sysctl_perf_event_max_stack,
1207 .maxlen = sizeof(sysctl_perf_event_max_stack),
1208 .mode = 0644,
1209 .proc_handler = perf_event_max_stack_handler,
1210 .extra1 = SYSCTL_ZERO,
1211 .extra2 = &six_hundred_forty_kb,
1212 },
1213 {
1214 .procname = "perf_event_max_contexts_per_stack",
1215 .data = &sysctl_perf_event_max_contexts_per_stack,
1216 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1217 .mode = 0644,
1218 .proc_handler = perf_event_max_stack_handler,
1219 .extra1 = SYSCTL_ZERO,
1220 .extra2 = &one_thousand,
1221 },
1222#endif
1223 {
1224 .procname = "panic_on_warn",
1225 .data = &panic_on_warn,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
1228 .proc_handler = proc_dointvec_minmax,
1229 .extra1 = SYSCTL_ZERO,
1230 .extra2 = SYSCTL_ONE,
1231 },
1232#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1233 {
1234 .procname = "timer_migration",
1235 .data = &sysctl_timer_migration,
1236 .maxlen = sizeof(unsigned int),
1237 .mode = 0644,
1238 .proc_handler = timer_migration_handler,
1239 .extra1 = SYSCTL_ZERO,
1240 .extra2 = SYSCTL_ONE,
1241 },
1242#endif
1243#ifdef CONFIG_BPF_SYSCALL
1244 {
1245 .procname = "unprivileged_bpf_disabled",
1246 .data = &sysctl_unprivileged_bpf_disabled,
1247 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1248 .mode = 0644,
1249 /* only handle a transition from default "0" to "1" */
1250 .proc_handler = proc_dointvec_minmax,
1251 .extra1 = SYSCTL_ONE,
1252 .extra2 = SYSCTL_ONE,
1253 },
1254 {
1255 .procname = "bpf_stats_enabled",
1256 .data = &bpf_stats_enabled_key.key,
1257 .maxlen = sizeof(bpf_stats_enabled_key),
1258 .mode = 0644,
1259 .proc_handler = proc_do_static_key,
1260 },
1261#endif
1262#if defined(CONFIG_TREE_RCU)
1263 {
1264 .procname = "panic_on_rcu_stall",
1265 .data = &sysctl_panic_on_rcu_stall,
1266 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1267 .mode = 0644,
1268 .proc_handler = proc_dointvec_minmax,
1269 .extra1 = SYSCTL_ZERO,
1270 .extra2 = SYSCTL_ONE,
1271 },
1272#endif
1273#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1274 {
1275 .procname = "stack_erasing",
1276 .data = NULL,
1277 .maxlen = sizeof(int),
1278 .mode = 0600,
1279 .proc_handler = stack_erasing_sysctl,
1280 .extra1 = SYSCTL_ZERO,
1281 .extra2 = SYSCTL_ONE,
1282 },
1283#endif
1284 { }
1285};
1286
1287static struct ctl_table vm_table[] = {
1288 {
1289 .procname = "overcommit_memory",
1290 .data = &sysctl_overcommit_memory,
1291 .maxlen = sizeof(sysctl_overcommit_memory),
1292 .mode = 0644,
1293 .proc_handler = proc_dointvec_minmax,
1294 .extra1 = SYSCTL_ZERO,
1295 .extra2 = &two,
1296 },
1297 {
1298 .procname = "panic_on_oom",
1299 .data = &sysctl_panic_on_oom,
1300 .maxlen = sizeof(sysctl_panic_on_oom),
1301 .mode = 0644,
1302 .proc_handler = proc_dointvec_minmax,
1303 .extra1 = SYSCTL_ZERO,
1304 .extra2 = &two,
1305 },
1306 {
1307 .procname = "oom_kill_allocating_task",
1308 .data = &sysctl_oom_kill_allocating_task,
1309 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1310 .mode = 0644,
1311 .proc_handler = proc_dointvec,
1312 },
1313 {
1314 .procname = "oom_dump_tasks",
1315 .data = &sysctl_oom_dump_tasks,
1316 .maxlen = sizeof(sysctl_oom_dump_tasks),
1317 .mode = 0644,
1318 .proc_handler = proc_dointvec,
1319 },
1320 {
1321 .procname = "overcommit_ratio",
1322 .data = &sysctl_overcommit_ratio,
1323 .maxlen = sizeof(sysctl_overcommit_ratio),
1324 .mode = 0644,
1325 .proc_handler = overcommit_ratio_handler,
1326 },
1327 {
1328 .procname = "overcommit_kbytes",
1329 .data = &sysctl_overcommit_kbytes,
1330 .maxlen = sizeof(sysctl_overcommit_kbytes),
1331 .mode = 0644,
1332 .proc_handler = overcommit_kbytes_handler,
1333 },
1334 {
1335 .procname = "page-cluster",
1336 .data = &page_cluster,
1337 .maxlen = sizeof(int),
1338 .mode = 0644,
1339 .proc_handler = proc_dointvec_minmax,
1340 .extra1 = SYSCTL_ZERO,
1341 },
1342 {
1343 .procname = "dirty_background_ratio",
1344 .data = &dirty_background_ratio,
1345 .maxlen = sizeof(dirty_background_ratio),
1346 .mode = 0644,
1347 .proc_handler = dirty_background_ratio_handler,
1348 .extra1 = SYSCTL_ZERO,
1349 .extra2 = &one_hundred,
1350 },
1351 {
1352 .procname = "dirty_background_bytes",
1353 .data = &dirty_background_bytes,
1354 .maxlen = sizeof(dirty_background_bytes),
1355 .mode = 0644,
1356 .proc_handler = dirty_background_bytes_handler,
1357 .extra1 = &one_ul,
1358 },
1359 {
1360 .procname = "dirty_ratio",
1361 .data = &vm_dirty_ratio,
1362 .maxlen = sizeof(vm_dirty_ratio),
1363 .mode = 0644,
1364 .proc_handler = dirty_ratio_handler,
1365 .extra1 = SYSCTL_ZERO,
1366 .extra2 = &one_hundred,
1367 },
1368 {
1369 .procname = "dirty_bytes",
1370 .data = &vm_dirty_bytes,
1371 .maxlen = sizeof(vm_dirty_bytes),
1372 .mode = 0644,
1373 .proc_handler = dirty_bytes_handler,
1374 .extra1 = &dirty_bytes_min,
1375 },
1376 {
1377 .procname = "dirty_writeback_centisecs",
1378 .data = &dirty_writeback_interval,
1379 .maxlen = sizeof(dirty_writeback_interval),
1380 .mode = 0644,
1381 .proc_handler = dirty_writeback_centisecs_handler,
1382 },
1383 {
1384 .procname = "dirty_expire_centisecs",
1385 .data = &dirty_expire_interval,
1386 .maxlen = sizeof(dirty_expire_interval),
1387 .mode = 0644,
1388 .proc_handler = proc_dointvec_minmax,
1389 .extra1 = SYSCTL_ZERO,
1390 },
1391 {
1392 .procname = "dirtytime_expire_seconds",
1393 .data = &dirtytime_expire_interval,
1394 .maxlen = sizeof(dirtytime_expire_interval),
1395 .mode = 0644,
1396 .proc_handler = dirtytime_interval_handler,
1397 .extra1 = SYSCTL_ZERO,
1398 },
1399 {
1400 .procname = "swappiness",
1401 .data = &vm_swappiness,
1402 .maxlen = sizeof(vm_swappiness),
1403 .mode = 0644,
1404 .proc_handler = proc_dointvec_minmax,
1405 .extra1 = SYSCTL_ZERO,
1406 .extra2 = &one_hundred,
1407 },
1408#ifdef CONFIG_HUGETLB_PAGE
1409 {
1410 .procname = "nr_hugepages",
1411 .data = NULL,
1412 .maxlen = sizeof(unsigned long),
1413 .mode = 0644,
1414 .proc_handler = hugetlb_sysctl_handler,
1415 },
1416#ifdef CONFIG_NUMA
1417 {
1418 .procname = "nr_hugepages_mempolicy",
1419 .data = NULL,
1420 .maxlen = sizeof(unsigned long),
1421 .mode = 0644,
1422 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1423 },
1424 {
1425 .procname = "numa_stat",
1426 .data = &sysctl_vm_numa_stat,
1427 .maxlen = sizeof(int),
1428 .mode = 0644,
1429 .proc_handler = sysctl_vm_numa_stat_handler,
1430 .extra1 = SYSCTL_ZERO,
1431 .extra2 = SYSCTL_ONE,
1432 },
1433#endif
1434 {
1435 .procname = "hugetlb_shm_group",
1436 .data = &sysctl_hugetlb_shm_group,
1437 .maxlen = sizeof(gid_t),
1438 .mode = 0644,
1439 .proc_handler = proc_dointvec,
1440 },
1441 {
1442 .procname = "nr_overcommit_hugepages",
1443 .data = NULL,
1444 .maxlen = sizeof(unsigned long),
1445 .mode = 0644,
1446 .proc_handler = hugetlb_overcommit_handler,
1447 },
1448#endif
1449 {
1450 .procname = "lowmem_reserve_ratio",
1451 .data = &sysctl_lowmem_reserve_ratio,
1452 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1453 .mode = 0644,
1454 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1455 },
1456 {
1457 .procname = "drop_caches",
1458 .data = &sysctl_drop_caches,
1459 .maxlen = sizeof(int),
1460 .mode = 0200,
1461 .proc_handler = drop_caches_sysctl_handler,
1462 .extra1 = SYSCTL_ONE,
1463 .extra2 = &four,
1464 },
1465#ifdef CONFIG_COMPACTION
1466 {
1467 .procname = "compact_memory",
1468 .data = &sysctl_compact_memory,
1469 .maxlen = sizeof(int),
1470 .mode = 0200,
1471 .proc_handler = sysctl_compaction_handler,
1472 },
1473 {
1474 .procname = "extfrag_threshold",
1475 .data = &sysctl_extfrag_threshold,
1476 .maxlen = sizeof(int),
1477 .mode = 0644,
1478 .proc_handler = proc_dointvec_minmax,
1479 .extra1 = &min_extfrag_threshold,
1480 .extra2 = &max_extfrag_threshold,
1481 },
1482 {
1483 .procname = "compact_unevictable_allowed",
1484 .data = &sysctl_compact_unevictable_allowed,
1485 .maxlen = sizeof(int),
1486 .mode = 0644,
1487 .proc_handler = proc_dointvec,
1488 .extra1 = SYSCTL_ZERO,
1489 .extra2 = SYSCTL_ONE,
1490 },
1491
1492#endif /* CONFIG_COMPACTION */
1493 {
1494 .procname = "min_free_kbytes",
1495 .data = &min_free_kbytes,
1496 .maxlen = sizeof(min_free_kbytes),
1497 .mode = 0644,
1498 .proc_handler = min_free_kbytes_sysctl_handler,
1499 .extra1 = SYSCTL_ZERO,
1500 },
1501 {
1502 .procname = "watermark_boost_factor",
1503 .data = &watermark_boost_factor,
1504 .maxlen = sizeof(watermark_boost_factor),
1505 .mode = 0644,
1506 .proc_handler = watermark_boost_factor_sysctl_handler,
1507 .extra1 = SYSCTL_ZERO,
1508 },
1509 {
1510 .procname = "watermark_scale_factor",
1511 .data = &watermark_scale_factor,
1512 .maxlen = sizeof(watermark_scale_factor),
1513 .mode = 0644,
1514 .proc_handler = watermark_scale_factor_sysctl_handler,
1515 .extra1 = SYSCTL_ONE,
1516 .extra2 = &one_thousand,
1517 },
1518 {
1519 .procname = "percpu_pagelist_fraction",
1520 .data = &percpu_pagelist_fraction,
1521 .maxlen = sizeof(percpu_pagelist_fraction),
1522 .mode = 0644,
1523 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1524 .extra1 = SYSCTL_ZERO,
1525 },
1526#ifdef CONFIG_MMU
1527 {
1528 .procname = "max_map_count",
1529 .data = &sysctl_max_map_count,
1530 .maxlen = sizeof(sysctl_max_map_count),
1531 .mode = 0644,
1532 .proc_handler = proc_dointvec_minmax,
1533 .extra1 = SYSCTL_ZERO,
1534 },
1535#else
1536 {
1537 .procname = "nr_trim_pages",
1538 .data = &sysctl_nr_trim_pages,
1539 .maxlen = sizeof(sysctl_nr_trim_pages),
1540 .mode = 0644,
1541 .proc_handler = proc_dointvec_minmax,
1542 .extra1 = SYSCTL_ZERO,
1543 },
1544#endif
1545 {
1546 .procname = "laptop_mode",
1547 .data = &laptop_mode,
1548 .maxlen = sizeof(laptop_mode),
1549 .mode = 0644,
1550 .proc_handler = proc_dointvec_jiffies,
1551 },
1552 {
1553 .procname = "block_dump",
1554 .data = &block_dump,
1555 .maxlen = sizeof(block_dump),
1556 .mode = 0644,
1557 .proc_handler = proc_dointvec,
1558 .extra1 = SYSCTL_ZERO,
1559 },
1560 {
1561 .procname = "vfs_cache_pressure",
1562 .data = &sysctl_vfs_cache_pressure,
1563 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1564 .mode = 0644,
1565 .proc_handler = proc_dointvec,
1566 .extra1 = SYSCTL_ZERO,
1567 },
1568#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
1569 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1570 {
1571 .procname = "legacy_va_layout",
1572 .data = &sysctl_legacy_va_layout,
1573 .maxlen = sizeof(sysctl_legacy_va_layout),
1574 .mode = 0644,
1575 .proc_handler = proc_dointvec,
1576 .extra1 = SYSCTL_ZERO,
1577 },
1578#endif
1579#ifdef CONFIG_NUMA
1580 {
1581 .procname = "zone_reclaim_mode",
1582 .data = &node_reclaim_mode,
1583 .maxlen = sizeof(node_reclaim_mode),
1584 .mode = 0644,
1585 .proc_handler = proc_dointvec,
1586 .extra1 = SYSCTL_ZERO,
1587 },
1588 {
1589 .procname = "min_unmapped_ratio",
1590 .data = &sysctl_min_unmapped_ratio,
1591 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1592 .mode = 0644,
1593 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1594 .extra1 = SYSCTL_ZERO,
1595 .extra2 = &one_hundred,
1596 },
1597 {
1598 .procname = "min_slab_ratio",
1599 .data = &sysctl_min_slab_ratio,
1600 .maxlen = sizeof(sysctl_min_slab_ratio),
1601 .mode = 0644,
1602 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1603 .extra1 = SYSCTL_ZERO,
1604 .extra2 = &one_hundred,
1605 },
1606#endif
1607#ifdef CONFIG_SMP
1608 {
1609 .procname = "stat_interval",
1610 .data = &sysctl_stat_interval,
1611 .maxlen = sizeof(sysctl_stat_interval),
1612 .mode = 0644,
1613 .proc_handler = proc_dointvec_jiffies,
1614 },
1615 {
1616 .procname = "stat_refresh",
1617 .data = NULL,
1618 .maxlen = 0,
1619 .mode = 0600,
1620 .proc_handler = vmstat_refresh,
1621 },
1622#endif
1623#ifdef CONFIG_MMU
1624 {
1625 .procname = "mmap_min_addr",
1626 .data = &dac_mmap_min_addr,
1627 .maxlen = sizeof(unsigned long),
1628 .mode = 0644,
1629 .proc_handler = mmap_min_addr_handler,
1630 },
1631#endif
1632#ifdef CONFIG_NUMA
1633 {
1634 .procname = "numa_zonelist_order",
1635 .data = &numa_zonelist_order,
1636 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1637 .mode = 0644,
1638 .proc_handler = numa_zonelist_order_handler,
1639 },
1640#endif
1641#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1642 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1643 {
1644 .procname = "vdso_enabled",
1645#ifdef CONFIG_X86_32
1646 .data = &vdso32_enabled,
1647 .maxlen = sizeof(vdso32_enabled),
1648#else
1649 .data = &vdso_enabled,
1650 .maxlen = sizeof(vdso_enabled),
1651#endif
1652 .mode = 0644,
1653 .proc_handler = proc_dointvec,
1654 .extra1 = SYSCTL_ZERO,
1655 },
1656#endif
1657#ifdef CONFIG_HIGHMEM
1658 {
1659 .procname = "highmem_is_dirtyable",
1660 .data = &vm_highmem_is_dirtyable,
1661 .maxlen = sizeof(vm_highmem_is_dirtyable),
1662 .mode = 0644,
1663 .proc_handler = proc_dointvec_minmax,
1664 .extra1 = SYSCTL_ZERO,
1665 .extra2 = SYSCTL_ONE,
1666 },
1667#endif
1668#ifdef CONFIG_MEMORY_FAILURE
1669 {
1670 .procname = "memory_failure_early_kill",
1671 .data = &sysctl_memory_failure_early_kill,
1672 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1673 .mode = 0644,
1674 .proc_handler = proc_dointvec_minmax,
1675 .extra1 = SYSCTL_ZERO,
1676 .extra2 = SYSCTL_ONE,
1677 },
1678 {
1679 .procname = "memory_failure_recovery",
1680 .data = &sysctl_memory_failure_recovery,
1681 .maxlen = sizeof(sysctl_memory_failure_recovery),
1682 .mode = 0644,
1683 .proc_handler = proc_dointvec_minmax,
1684 .extra1 = SYSCTL_ZERO,
1685 .extra2 = SYSCTL_ONE,
1686 },
1687#endif
1688 {
1689 .procname = "user_reserve_kbytes",
1690 .data = &sysctl_user_reserve_kbytes,
1691 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1692 .mode = 0644,
1693 .proc_handler = proc_doulongvec_minmax,
1694 },
1695 {
1696 .procname = "admin_reserve_kbytes",
1697 .data = &sysctl_admin_reserve_kbytes,
1698 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1699 .mode = 0644,
1700 .proc_handler = proc_doulongvec_minmax,
1701 },
1702#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1703 {
1704 .procname = "mmap_rnd_bits",
1705 .data = &mmap_rnd_bits,
1706 .maxlen = sizeof(mmap_rnd_bits),
1707 .mode = 0600,
1708 .proc_handler = proc_dointvec_minmax,
1709 .extra1 = (void *)&mmap_rnd_bits_min,
1710 .extra2 = (void *)&mmap_rnd_bits_max,
1711 },
1712#endif
1713#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1714 {
1715 .procname = "mmap_rnd_compat_bits",
1716 .data = &mmap_rnd_compat_bits,
1717 .maxlen = sizeof(mmap_rnd_compat_bits),
1718 .mode = 0600,
1719 .proc_handler = proc_dointvec_minmax,
1720 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1721 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1722 },
1723#endif
1724#ifdef CONFIG_USERFAULTFD
1725 {
1726 .procname = "unprivileged_userfaultfd",
1727 .data = &sysctl_unprivileged_userfaultfd,
1728 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1729 .mode = 0644,
1730 .proc_handler = proc_dointvec_minmax,
1731 .extra1 = SYSCTL_ZERO,
1732 .extra2 = SYSCTL_ONE,
1733 },
1734#endif
1735 { }
1736};
1737
1738static struct ctl_table fs_table[] = {
1739 {
1740 .procname = "inode-nr",
1741 .data = &inodes_stat,
1742 .maxlen = 2*sizeof(long),
1743 .mode = 0444,
1744 .proc_handler = proc_nr_inodes,
1745 },
1746 {
1747 .procname = "inode-state",
1748 .data = &inodes_stat,
1749 .maxlen = 7*sizeof(long),
1750 .mode = 0444,
1751 .proc_handler = proc_nr_inodes,
1752 },
1753 {
1754 .procname = "file-nr",
1755 .data = &files_stat,
1756 .maxlen = sizeof(files_stat),
1757 .mode = 0444,
1758 .proc_handler = proc_nr_files,
1759 },
1760 {
1761 .procname = "file-max",
1762 .data = &files_stat.max_files,
1763 .maxlen = sizeof(files_stat.max_files),
1764 .mode = 0644,
1765 .proc_handler = proc_doulongvec_minmax,
1766 .extra1 = &zero_ul,
1767 .extra2 = &long_max,
1768 },
1769 {
1770 .procname = "nr_open",
1771 .data = &sysctl_nr_open,
1772 .maxlen = sizeof(unsigned int),
1773 .mode = 0644,
1774 .proc_handler = proc_dointvec_minmax,
1775 .extra1 = &sysctl_nr_open_min,
1776 .extra2 = &sysctl_nr_open_max,
1777 },
1778 {
1779 .procname = "dentry-state",
1780 .data = &dentry_stat,
1781 .maxlen = 6*sizeof(long),
1782 .mode = 0444,
1783 .proc_handler = proc_nr_dentry,
1784 },
1785 {
1786 .procname = "overflowuid",
1787 .data = &fs_overflowuid,
1788 .maxlen = sizeof(int),
1789 .mode = 0644,
1790 .proc_handler = proc_dointvec_minmax,
1791 .extra1 = &minolduid,
1792 .extra2 = &maxolduid,
1793 },
1794 {
1795 .procname = "overflowgid",
1796 .data = &fs_overflowgid,
1797 .maxlen = sizeof(int),
1798 .mode = 0644,
1799 .proc_handler = proc_dointvec_minmax,
1800 .extra1 = &minolduid,
1801 .extra2 = &maxolduid,
1802 },
1803#ifdef CONFIG_FILE_LOCKING
1804 {
1805 .procname = "leases-enable",
1806 .data = &leases_enable,
1807 .maxlen = sizeof(int),
1808 .mode = 0644,
1809 .proc_handler = proc_dointvec,
1810 },
1811#endif
1812#ifdef CONFIG_DNOTIFY
1813 {
1814 .procname = "dir-notify-enable",
1815 .data = &dir_notify_enable,
1816 .maxlen = sizeof(int),
1817 .mode = 0644,
1818 .proc_handler = proc_dointvec,
1819 },
1820#endif
1821#ifdef CONFIG_MMU
1822#ifdef CONFIG_FILE_LOCKING
1823 {
1824 .procname = "lease-break-time",
1825 .data = &lease_break_time,
1826 .maxlen = sizeof(int),
1827 .mode = 0644,
1828 .proc_handler = proc_dointvec,
1829 },
1830#endif
1831#ifdef CONFIG_AIO
1832 {
1833 .procname = "aio-nr",
1834 .data = &aio_nr,
1835 .maxlen = sizeof(aio_nr),
1836 .mode = 0444,
1837 .proc_handler = proc_doulongvec_minmax,
1838 },
1839 {
1840 .procname = "aio-max-nr",
1841 .data = &aio_max_nr,
1842 .maxlen = sizeof(aio_max_nr),
1843 .mode = 0644,
1844 .proc_handler = proc_doulongvec_minmax,
1845 },
1846#endif /* CONFIG_AIO */
1847#ifdef CONFIG_INOTIFY_USER
1848 {
1849 .procname = "inotify",
1850 .mode = 0555,
1851 .child = inotify_table,
1852 },
1853#endif
1854#ifdef CONFIG_EPOLL
1855 {
1856 .procname = "epoll",
1857 .mode = 0555,
1858 .child = epoll_table,
1859 },
1860#endif
1861#endif
1862 {
1863 .procname = "protected_symlinks",
1864 .data = &sysctl_protected_symlinks,
1865 .maxlen = sizeof(int),
1866 .mode = 0600,
1867 .proc_handler = proc_dointvec_minmax,
1868 .extra1 = SYSCTL_ZERO,
1869 .extra2 = SYSCTL_ONE,
1870 },
1871 {
1872 .procname = "protected_hardlinks",
1873 .data = &sysctl_protected_hardlinks,
1874 .maxlen = sizeof(int),
1875 .mode = 0600,
1876 .proc_handler = proc_dointvec_minmax,
1877 .extra1 = SYSCTL_ZERO,
1878 .extra2 = SYSCTL_ONE,
1879 },
1880 {
1881 .procname = "protected_fifos",
1882 .data = &sysctl_protected_fifos,
1883 .maxlen = sizeof(int),
1884 .mode = 0600,
1885 .proc_handler = proc_dointvec_minmax,
1886 .extra1 = SYSCTL_ZERO,
1887 .extra2 = &two,
1888 },
1889 {
1890 .procname = "protected_regular",
1891 .data = &sysctl_protected_regular,
1892 .maxlen = sizeof(int),
1893 .mode = 0600,
1894 .proc_handler = proc_dointvec_minmax,
1895 .extra1 = SYSCTL_ZERO,
1896 .extra2 = &two,
1897 },
1898 {
1899 .procname = "suid_dumpable",
1900 .data = &suid_dumpable,
1901 .maxlen = sizeof(int),
1902 .mode = 0644,
1903 .proc_handler = proc_dointvec_minmax_coredump,
1904 .extra1 = SYSCTL_ZERO,
1905 .extra2 = &two,
1906 },
1907#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1908 {
1909 .procname = "binfmt_misc",
1910 .mode = 0555,
1911 .child = sysctl_mount_point,
1912 },
1913#endif
1914 {
1915 .procname = "pipe-max-size",
1916 .data = &pipe_max_size,
1917 .maxlen = sizeof(pipe_max_size),
1918 .mode = 0644,
1919 .proc_handler = proc_dopipe_max_size,
1920 },
1921 {
1922 .procname = "pipe-user-pages-hard",
1923 .data = &pipe_user_pages_hard,
1924 .maxlen = sizeof(pipe_user_pages_hard),
1925 .mode = 0644,
1926 .proc_handler = proc_doulongvec_minmax,
1927 },
1928 {
1929 .procname = "pipe-user-pages-soft",
1930 .data = &pipe_user_pages_soft,
1931 .maxlen = sizeof(pipe_user_pages_soft),
1932 .mode = 0644,
1933 .proc_handler = proc_doulongvec_minmax,
1934 },
1935 {
1936 .procname = "mount-max",
1937 .data = &sysctl_mount_max,
1938 .maxlen = sizeof(unsigned int),
1939 .mode = 0644,
1940 .proc_handler = proc_dointvec_minmax,
1941 .extra1 = SYSCTL_ONE,
1942 },
1943 { }
1944};
1945
1946static struct ctl_table debug_table[] = {
1947#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1948 {
1949 .procname = "exception-trace",
1950 .data = &show_unhandled_signals,
1951 .maxlen = sizeof(int),
1952 .mode = 0644,
1953 .proc_handler = proc_dointvec
1954 },
1955#endif
1956#if defined(CONFIG_OPTPROBES)
1957 {
1958 .procname = "kprobes-optimization",
1959 .data = &sysctl_kprobes_optimization,
1960 .maxlen = sizeof(int),
1961 .mode = 0644,
1962 .proc_handler = proc_kprobes_optimization_handler,
1963 .extra1 = SYSCTL_ZERO,
1964 .extra2 = SYSCTL_ONE,
1965 },
1966#endif
1967 { }
1968};
1969
1970static struct ctl_table dev_table[] = {
1971 { }
1972};
1973
1974int __init sysctl_init(void)
1975{
1976 struct ctl_table_header *hdr;
1977
1978 hdr = register_sysctl_table(sysctl_base_table);
1979 kmemleak_not_leak(hdr);
1980 return 0;
1981}
1982
1983#endif /* CONFIG_SYSCTL */
1984
1985/*
1986 * /proc/sys support
1987 */
1988
1989#ifdef CONFIG_PROC_SYSCTL
1990
1991static int _proc_do_string(char *data, int maxlen, int write,
1992 char __user *buffer,
1993 size_t *lenp, loff_t *ppos)
1994{
1995 size_t len;
1996 char __user *p;
1997 char c;
1998
1999 if (!data || !maxlen || !*lenp) {
2000 *lenp = 0;
2001 return 0;
2002 }
2003
2004 if (write) {
2005 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
2006 /* Only continue writes not past the end of buffer. */
2007 len = strlen(data);
2008 if (len > maxlen - 1)
2009 len = maxlen - 1;
2010
2011 if (*ppos > len)
2012 return 0;
2013 len = *ppos;
2014 } else {
2015 /* Start writing from beginning of buffer. */
2016 len = 0;
2017 }
2018
2019 *ppos += *lenp;
2020 p = buffer;
2021 while ((p - buffer) < *lenp && len < maxlen - 1) {
2022 if (get_user(c, p++))
2023 return -EFAULT;
2024 if (c == 0 || c == '\n')
2025 break;
2026 data[len++] = c;
2027 }
2028 data[len] = 0;
2029 } else {
2030 len = strlen(data);
2031 if (len > maxlen)
2032 len = maxlen;
2033
2034 if (*ppos > len) {
2035 *lenp = 0;
2036 return 0;
2037 }
2038
2039 data += *ppos;
2040 len -= *ppos;
2041
2042 if (len > *lenp)
2043 len = *lenp;
2044 if (len)
2045 if (copy_to_user(buffer, data, len))
2046 return -EFAULT;
2047 if (len < *lenp) {
2048 if (put_user('\n', buffer + len))
2049 return -EFAULT;
2050 len++;
2051 }
2052 *lenp = len;
2053 *ppos += len;
2054 }
2055 return 0;
2056}
2057
2058static void warn_sysctl_write(struct ctl_table *table)
2059{
2060 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2061 "This will not be supported in the future. To silence this\n"
2062 "warning, set kernel.sysctl_writes_strict = -1\n",
2063 current->comm, table->procname);
2064}
2065
2066/**
2067 * proc_first_pos_non_zero_ignore - check if first position is allowed
2068 * @ppos: file position
2069 * @table: the sysctl table
2070 *
2071 * Returns true if the first position is non-zero and the sysctl_writes_strict
2072 * mode indicates this is not allowed for numeric input types. String proc
2073 * handlers can ignore the return value.
2074 */
2075static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2076 struct ctl_table *table)
2077{
2078 if (!*ppos)
2079 return false;
2080
2081 switch (sysctl_writes_strict) {
2082 case SYSCTL_WRITES_STRICT:
2083 return true;
2084 case SYSCTL_WRITES_WARN:
2085 warn_sysctl_write(table);
2086 return false;
2087 default:
2088 return false;
2089 }
2090}
2091
2092/**
2093 * proc_dostring - read a string sysctl
2094 * @table: the sysctl table
2095 * @write: %TRUE if this is a write to the sysctl file
2096 * @buffer: the user buffer
2097 * @lenp: the size of the user buffer
2098 * @ppos: file position
2099 *
2100 * Reads/writes a string from/to the user buffer. If the kernel
2101 * buffer provided is not large enough to hold the string, the
2102 * string is truncated. The copied string is %NULL-terminated.
2103 * If the string is being read by the user process, it is copied
2104 * and a newline '\n' is added. It is truncated if the buffer is
2105 * not large enough.
2106 *
2107 * Returns 0 on success.
2108 */
2109int proc_dostring(struct ctl_table *table, int write,
2110 void __user *buffer, size_t *lenp, loff_t *ppos)
2111{
2112 if (write)
2113 proc_first_pos_non_zero_ignore(ppos, table);
2114
2115 return _proc_do_string((char *)(table->data), table->maxlen, write,
2116 (char __user *)buffer, lenp, ppos);
2117}
2118
2119static size_t proc_skip_spaces(char **buf)
2120{
2121 size_t ret;
2122 char *tmp = skip_spaces(*buf);
2123 ret = tmp - *buf;
2124 *buf = tmp;
2125 return ret;
2126}
2127
2128static void proc_skip_char(char **buf, size_t *size, const char v)
2129{
2130 while (*size) {
2131 if (**buf != v)
2132 break;
2133 (*size)--;
2134 (*buf)++;
2135 }
2136}
2137
2138/**
2139 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2140 * fail on overflow
2141 *
2142 * @cp: kernel buffer containing the string to parse
2143 * @endp: pointer to store the trailing characters
2144 * @base: the base to use
2145 * @res: where the parsed integer will be stored
2146 *
2147 * In case of success 0 is returned and @res will contain the parsed integer,
2148 * @endp will hold any trailing characters.
2149 * This function will fail the parse on overflow. If there wasn't an overflow
2150 * the function will defer the decision what characters count as invalid to the
2151 * caller.
2152 */
2153static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2154 unsigned long *res)
2155{
2156 unsigned long long result;
2157 unsigned int rv;
2158
2159 cp = _parse_integer_fixup_radix(cp, &base);
2160 rv = _parse_integer(cp, base, &result);
2161 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2162 return -ERANGE;
2163
2164 cp += rv;
2165
2166 if (endp)
2167 *endp = (char *)cp;
2168
2169 *res = (unsigned long)result;
2170 return 0;
2171}
2172
2173#define TMPBUFLEN 22
2174/**
2175 * proc_get_long - reads an ASCII formatted integer from a user buffer
2176 *
2177 * @buf: a kernel buffer
2178 * @size: size of the kernel buffer
2179 * @val: this is where the number will be stored
2180 * @neg: set to %TRUE if number is negative
2181 * @perm_tr: a vector which contains the allowed trailers
2182 * @perm_tr_len: size of the perm_tr vector
2183 * @tr: pointer to store the trailer character
2184 *
2185 * In case of success %0 is returned and @buf and @size are updated with
2186 * the amount of bytes read. If @tr is non-NULL and a trailing
2187 * character exists (size is non-zero after returning from this
2188 * function), @tr is updated with the trailing character.
2189 */
2190static int proc_get_long(char **buf, size_t *size,
2191 unsigned long *val, bool *neg,
2192 const char *perm_tr, unsigned perm_tr_len, char *tr)
2193{
2194 int len;
2195 char *p, tmp[TMPBUFLEN];
2196
2197 if (!*size)
2198 return -EINVAL;
2199
2200 len = *size;
2201 if (len > TMPBUFLEN - 1)
2202 len = TMPBUFLEN - 1;
2203
2204 memcpy(tmp, *buf, len);
2205
2206 tmp[len] = 0;
2207 p = tmp;
2208 if (*p == '-' && *size > 1) {
2209 *neg = true;
2210 p++;
2211 } else
2212 *neg = false;
2213 if (!isdigit(*p))
2214 return -EINVAL;
2215
2216 if (strtoul_lenient(p, &p, 0, val))
2217 return -EINVAL;
2218
2219 len = p - tmp;
2220
2221 /* We don't know if the next char is whitespace thus we may accept
2222 * invalid integers (e.g. 1234...a) or two integers instead of one
2223 * (e.g. 123...1). So lets not allow such large numbers. */
2224 if (len == TMPBUFLEN - 1)
2225 return -EINVAL;
2226
2227 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2228 return -EINVAL;
2229
2230 if (tr && (len < *size))
2231 *tr = *p;
2232
2233 *buf += len;
2234 *size -= len;
2235
2236 return 0;
2237}
2238
2239/**
2240 * proc_put_long - converts an integer to a decimal ASCII formatted string
2241 *
2242 * @buf: the user buffer
2243 * @size: the size of the user buffer
2244 * @val: the integer to be converted
2245 * @neg: sign of the number, %TRUE for negative
2246 *
2247 * In case of success %0 is returned and @buf and @size are updated with
2248 * the amount of bytes written.
2249 */
2250static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2251 bool neg)
2252{
2253 int len;
2254 char tmp[TMPBUFLEN], *p = tmp;
2255
2256 sprintf(p, "%s%lu", neg ? "-" : "", val);
2257 len = strlen(tmp);
2258 if (len > *size)
2259 len = *size;
2260 if (copy_to_user(*buf, tmp, len))
2261 return -EFAULT;
2262 *size -= len;
2263 *buf += len;
2264 return 0;
2265}
2266#undef TMPBUFLEN
2267
2268static int proc_put_char(void __user **buf, size_t *size, char c)
2269{
2270 if (*size) {
2271 char __user **buffer = (char __user **)buf;
2272 if (put_user(c, *buffer))
2273 return -EFAULT;
2274 (*size)--, (*buffer)++;
2275 *buf = *buffer;
2276 }
2277 return 0;
2278}
2279
2280static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2281 int *valp,
2282 int write, void *data)
2283{
2284 if (write) {
2285 if (*negp) {
2286 if (*lvalp > (unsigned long) INT_MAX + 1)
2287 return -EINVAL;
2288 *valp = -*lvalp;
2289 } else {
2290 if (*lvalp > (unsigned long) INT_MAX)
2291 return -EINVAL;
2292 *valp = *lvalp;
2293 }
2294 } else {
2295 int val = *valp;
2296 if (val < 0) {
2297 *negp = true;
2298 *lvalp = -(unsigned long)val;
2299 } else {
2300 *negp = false;
2301 *lvalp = (unsigned long)val;
2302 }
2303 }
2304 return 0;
2305}
2306
2307static int do_proc_douintvec_conv(unsigned long *lvalp,
2308 unsigned int *valp,
2309 int write, void *data)
2310{
2311 if (write) {
2312 if (*lvalp > UINT_MAX)
2313 return -EINVAL;
2314 *valp = *lvalp;
2315 } else {
2316 unsigned int val = *valp;
2317 *lvalp = (unsigned long)val;
2318 }
2319 return 0;
2320}
2321
2322static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2323
2324static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2325 int write, void __user *buffer,
2326 size_t *lenp, loff_t *ppos,
2327 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2328 int write, void *data),
2329 void *data)
2330{
2331 int *i, vleft, first = 1, err = 0;
2332 size_t left;
2333 char *kbuf = NULL, *p;
2334
2335 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2336 *lenp = 0;
2337 return 0;
2338 }
2339
2340 i = (int *) tbl_data;
2341 vleft = table->maxlen / sizeof(*i);
2342 left = *lenp;
2343
2344 if (!conv)
2345 conv = do_proc_dointvec_conv;
2346
2347 if (write) {
2348 if (proc_first_pos_non_zero_ignore(ppos, table))
2349 goto out;
2350
2351 if (left > PAGE_SIZE - 1)
2352 left = PAGE_SIZE - 1;
2353 p = kbuf = memdup_user_nul(buffer, left);
2354 if (IS_ERR(kbuf))
2355 return PTR_ERR(kbuf);
2356 }
2357
2358 for (; left && vleft--; i++, first=0) {
2359 unsigned long lval;
2360 bool neg;
2361
2362 if (write) {
2363 left -= proc_skip_spaces(&p);
2364
2365 if (!left)
2366 break;
2367 err = proc_get_long(&p, &left, &lval, &neg,
2368 proc_wspace_sep,
2369 sizeof(proc_wspace_sep), NULL);
2370 if (err)
2371 break;
2372 if (conv(&neg, &lval, i, 1, data)) {
2373 err = -EINVAL;
2374 break;
2375 }
2376 } else {
2377 if (conv(&neg, &lval, i, 0, data)) {
2378 err = -EINVAL;
2379 break;
2380 }
2381 if (!first)
2382 err = proc_put_char(&buffer, &left, '\t');
2383 if (err)
2384 break;
2385 err = proc_put_long(&buffer, &left, lval, neg);
2386 if (err)
2387 break;
2388 }
2389 }
2390
2391 if (!write && !first && left && !err)
2392 err = proc_put_char(&buffer, &left, '\n');
2393 if (write && !err && left)
2394 left -= proc_skip_spaces(&p);
2395 if (write) {
2396 kfree(kbuf);
2397 if (first)
2398 return err ? : -EINVAL;
2399 }
2400 *lenp -= left;
2401out:
2402 *ppos += *lenp;
2403 return err;
2404}
2405
2406static int do_proc_dointvec(struct ctl_table *table, int write,
2407 void __user *buffer, size_t *lenp, loff_t *ppos,
2408 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2409 int write, void *data),
2410 void *data)
2411{
2412 return __do_proc_dointvec(table->data, table, write,
2413 buffer, lenp, ppos, conv, data);
2414}
2415
2416static int do_proc_douintvec_w(unsigned int *tbl_data,
2417 struct ctl_table *table,
2418 void __user *buffer,
2419 size_t *lenp, loff_t *ppos,
2420 int (*conv)(unsigned long *lvalp,
2421 unsigned int *valp,
2422 int write, void *data),
2423 void *data)
2424{
2425 unsigned long lval;
2426 int err = 0;
2427 size_t left;
2428 bool neg;
2429 char *kbuf = NULL, *p;
2430
2431 left = *lenp;
2432
2433 if (proc_first_pos_non_zero_ignore(ppos, table))
2434 goto bail_early;
2435
2436 if (left > PAGE_SIZE - 1)
2437 left = PAGE_SIZE - 1;
2438
2439 p = kbuf = memdup_user_nul(buffer, left);
2440 if (IS_ERR(kbuf))
2441 return -EINVAL;
2442
2443 left -= proc_skip_spaces(&p);
2444 if (!left) {
2445 err = -EINVAL;
2446 goto out_free;
2447 }
2448
2449 err = proc_get_long(&p, &left, &lval, &neg,
2450 proc_wspace_sep,
2451 sizeof(proc_wspace_sep), NULL);
2452 if (err || neg) {
2453 err = -EINVAL;
2454 goto out_free;
2455 }
2456
2457 if (conv(&lval, tbl_data, 1, data)) {
2458 err = -EINVAL;
2459 goto out_free;
2460 }
2461
2462 if (!err && left)
2463 left -= proc_skip_spaces(&p);
2464
2465out_free:
2466 kfree(kbuf);
2467 if (err)
2468 return -EINVAL;
2469
2470 return 0;
2471
2472 /* This is in keeping with old __do_proc_dointvec() */
2473bail_early:
2474 *ppos += *lenp;
2475 return err;
2476}
2477
2478static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2479 size_t *lenp, loff_t *ppos,
2480 int (*conv)(unsigned long *lvalp,
2481 unsigned int *valp,
2482 int write, void *data),
2483 void *data)
2484{
2485 unsigned long lval;
2486 int err = 0;
2487 size_t left;
2488
2489 left = *lenp;
2490
2491 if (conv(&lval, tbl_data, 0, data)) {
2492 err = -EINVAL;
2493 goto out;
2494 }
2495
2496 err = proc_put_long(&buffer, &left, lval, false);
2497 if (err || !left)
2498 goto out;
2499
2500 err = proc_put_char(&buffer, &left, '\n');
2501
2502out:
2503 *lenp -= left;
2504 *ppos += *lenp;
2505
2506 return err;
2507}
2508
2509static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2510 int write, void __user *buffer,
2511 size_t *lenp, loff_t *ppos,
2512 int (*conv)(unsigned long *lvalp,
2513 unsigned int *valp,
2514 int write, void *data),
2515 void *data)
2516{
2517 unsigned int *i, vleft;
2518
2519 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2520 *lenp = 0;
2521 return 0;
2522 }
2523
2524 i = (unsigned int *) tbl_data;
2525 vleft = table->maxlen / sizeof(*i);
2526
2527 /*
2528 * Arrays are not supported, keep this simple. *Do not* add
2529 * support for them.
2530 */
2531 if (vleft != 1) {
2532 *lenp = 0;
2533 return -EINVAL;
2534 }
2535
2536 if (!conv)
2537 conv = do_proc_douintvec_conv;
2538
2539 if (write)
2540 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2541 conv, data);
2542 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2543}
2544
2545static int do_proc_douintvec(struct ctl_table *table, int write,
2546 void __user *buffer, size_t *lenp, loff_t *ppos,
2547 int (*conv)(unsigned long *lvalp,
2548 unsigned int *valp,
2549 int write, void *data),
2550 void *data)
2551{
2552 return __do_proc_douintvec(table->data, table, write,
2553 buffer, lenp, ppos, conv, data);
2554}
2555
2556/**
2557 * proc_dointvec - read a vector of integers
2558 * @table: the sysctl table
2559 * @write: %TRUE if this is a write to the sysctl file
2560 * @buffer: the user buffer
2561 * @lenp: the size of the user buffer
2562 * @ppos: file position
2563 *
2564 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2565 * values from/to the user buffer, treated as an ASCII string.
2566 *
2567 * Returns 0 on success.
2568 */
2569int proc_dointvec(struct ctl_table *table, int write,
2570 void __user *buffer, size_t *lenp, loff_t *ppos)
2571{
2572 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2573}
2574
2575/**
2576 * proc_douintvec - read a vector of unsigned integers
2577 * @table: the sysctl table
2578 * @write: %TRUE if this is a write to the sysctl file
2579 * @buffer: the user buffer
2580 * @lenp: the size of the user buffer
2581 * @ppos: file position
2582 *
2583 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2584 * values from/to the user buffer, treated as an ASCII string.
2585 *
2586 * Returns 0 on success.
2587 */
2588int proc_douintvec(struct ctl_table *table, int write,
2589 void __user *buffer, size_t *lenp, loff_t *ppos)
2590{
2591 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2592 do_proc_douintvec_conv, NULL);
2593}
2594
2595/*
2596 * Taint values can only be increased
2597 * This means we can safely use a temporary.
2598 */
2599static int proc_taint(struct ctl_table *table, int write,
2600 void __user *buffer, size_t *lenp, loff_t *ppos)
2601{
2602 struct ctl_table t;
2603 unsigned long tmptaint = get_taint();
2604 int err;
2605
2606 if (write && !capable(CAP_SYS_ADMIN))
2607 return -EPERM;
2608
2609 t = *table;
2610 t.data = &tmptaint;
2611 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2612 if (err < 0)
2613 return err;
2614
2615 if (write) {
2616 /*
2617 * Poor man's atomic or. Not worth adding a primitive
2618 * to everyone's atomic.h for this
2619 */
2620 int i;
2621 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2622 if ((tmptaint >> i) & 1)
2623 add_taint(i, LOCKDEP_STILL_OK);
2624 }
2625 }
2626
2627 return err;
2628}
2629
2630#ifdef CONFIG_PRINTK
2631static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2632 void __user *buffer, size_t *lenp, loff_t *ppos)
2633{
2634 if (write && !capable(CAP_SYS_ADMIN))
2635 return -EPERM;
2636
2637 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2638}
2639#endif
2640
2641/**
2642 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2643 * @min: pointer to minimum allowable value
2644 * @max: pointer to maximum allowable value
2645 *
2646 * The do_proc_dointvec_minmax_conv_param structure provides the
2647 * minimum and maximum values for doing range checking for those sysctl
2648 * parameters that use the proc_dointvec_minmax() handler.
2649 */
2650struct do_proc_dointvec_minmax_conv_param {
2651 int *min;
2652 int *max;
2653};
2654
2655static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2656 int *valp,
2657 int write, void *data)
2658{
2659 int tmp, ret;
2660 struct do_proc_dointvec_minmax_conv_param *param = data;
2661 /*
2662 * If writing, first do so via a temporary local int so we can
2663 * bounds-check it before touching *valp.
2664 */
2665 int *ip = write ? &tmp : valp;
2666
2667 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2668 if (ret)
2669 return ret;
2670
2671 if (write) {
2672 if ((param->min && *param->min > tmp) ||
2673 (param->max && *param->max < tmp))
2674 return -EINVAL;
2675 *valp = tmp;
2676 }
2677
2678 return 0;
2679}
2680
2681/**
2682 * proc_dointvec_minmax - read a vector of integers with min/max values
2683 * @table: the sysctl table
2684 * @write: %TRUE if this is a write to the sysctl file
2685 * @buffer: the user buffer
2686 * @lenp: the size of the user buffer
2687 * @ppos: file position
2688 *
2689 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2690 * values from/to the user buffer, treated as an ASCII string.
2691 *
2692 * This routine will ensure the values are within the range specified by
2693 * table->extra1 (min) and table->extra2 (max).
2694 *
2695 * Returns 0 on success or -EINVAL on write when the range check fails.
2696 */
2697int proc_dointvec_minmax(struct ctl_table *table, int write,
2698 void __user *buffer, size_t *lenp, loff_t *ppos)
2699{
2700 struct do_proc_dointvec_minmax_conv_param param = {
2701 .min = (int *) table->extra1,
2702 .max = (int *) table->extra2,
2703 };
2704 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2705 do_proc_dointvec_minmax_conv, &param);
2706}
2707
2708/**
2709 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2710 * @min: pointer to minimum allowable value
2711 * @max: pointer to maximum allowable value
2712 *
2713 * The do_proc_douintvec_minmax_conv_param structure provides the
2714 * minimum and maximum values for doing range checking for those sysctl
2715 * parameters that use the proc_douintvec_minmax() handler.
2716 */
2717struct do_proc_douintvec_minmax_conv_param {
2718 unsigned int *min;
2719 unsigned int *max;
2720};
2721
2722static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2723 unsigned int *valp,
2724 int write, void *data)
2725{
2726 int ret;
2727 unsigned int tmp;
2728 struct do_proc_douintvec_minmax_conv_param *param = data;
2729 /* write via temporary local uint for bounds-checking */
2730 unsigned int *up = write ? &tmp : valp;
2731
2732 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2733 if (ret)
2734 return ret;
2735
2736 if (write) {
2737 if ((param->min && *param->min > tmp) ||
2738 (param->max && *param->max < tmp))
2739 return -ERANGE;
2740
2741 *valp = tmp;
2742 }
2743
2744 return 0;
2745}
2746
2747/**
2748 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2749 * @table: the sysctl table
2750 * @write: %TRUE if this is a write to the sysctl file
2751 * @buffer: the user buffer
2752 * @lenp: the size of the user buffer
2753 * @ppos: file position
2754 *
2755 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2756 * values from/to the user buffer, treated as an ASCII string. Negative
2757 * strings are not allowed.
2758 *
2759 * This routine will ensure the values are within the range specified by
2760 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2761 * check for UINT_MAX to avoid having to support wrap around uses from
2762 * userspace.
2763 *
2764 * Returns 0 on success or -ERANGE on write when the range check fails.
2765 */
2766int proc_douintvec_minmax(struct ctl_table *table, int write,
2767 void __user *buffer, size_t *lenp, loff_t *ppos)
2768{
2769 struct do_proc_douintvec_minmax_conv_param param = {
2770 .min = (unsigned int *) table->extra1,
2771 .max = (unsigned int *) table->extra2,
2772 };
2773 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2774 do_proc_douintvec_minmax_conv, &param);
2775}
2776
2777static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2778 unsigned int *valp,
2779 int write, void *data)
2780{
2781 if (write) {
2782 unsigned int val;
2783
2784 val = round_pipe_size(*lvalp);
2785 if (val == 0)
2786 return -EINVAL;
2787
2788 *valp = val;
2789 } else {
2790 unsigned int val = *valp;
2791 *lvalp = (unsigned long) val;
2792 }
2793
2794 return 0;
2795}
2796
2797static int proc_dopipe_max_size(struct ctl_table *table, int write,
2798 void __user *buffer, size_t *lenp, loff_t *ppos)
2799{
2800 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2801 do_proc_dopipe_max_size_conv, NULL);
2802}
2803
2804static void validate_coredump_safety(void)
2805{
2806#ifdef CONFIG_COREDUMP
2807 if (suid_dumpable == SUID_DUMP_ROOT &&
2808 core_pattern[0] != '/' && core_pattern[0] != '|') {
2809 printk(KERN_WARNING
2810"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2811"Pipe handler or fully qualified core dump path required.\n"
2812"Set kernel.core_pattern before fs.suid_dumpable.\n"
2813 );
2814 }
2815#endif
2816}
2817
2818static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2819 void __user *buffer, size_t *lenp, loff_t *ppos)
2820{
2821 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2822 if (!error)
2823 validate_coredump_safety();
2824 return error;
2825}
2826
2827#ifdef CONFIG_COREDUMP
2828static int proc_dostring_coredump(struct ctl_table *table, int write,
2829 void __user *buffer, size_t *lenp, loff_t *ppos)
2830{
2831 int error = proc_dostring(table, write, buffer, lenp, ppos);
2832 if (!error)
2833 validate_coredump_safety();
2834 return error;
2835}
2836#endif
2837
2838static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2839 void __user *buffer,
2840 size_t *lenp, loff_t *ppos,
2841 unsigned long convmul,
2842 unsigned long convdiv)
2843{
2844 unsigned long *i, *min, *max;
2845 int vleft, first = 1, err = 0;
2846 size_t left;
2847 char *kbuf = NULL, *p;
2848
2849 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2850 *lenp = 0;
2851 return 0;
2852 }
2853
2854 i = (unsigned long *) data;
2855 min = (unsigned long *) table->extra1;
2856 max = (unsigned long *) table->extra2;
2857 vleft = table->maxlen / sizeof(unsigned long);
2858 left = *lenp;
2859
2860 if (write) {
2861 if (proc_first_pos_non_zero_ignore(ppos, table))
2862 goto out;
2863
2864 if (left > PAGE_SIZE - 1)
2865 left = PAGE_SIZE - 1;
2866 p = kbuf = memdup_user_nul(buffer, left);
2867 if (IS_ERR(kbuf))
2868 return PTR_ERR(kbuf);
2869 }
2870
2871 for (; left && vleft--; i++, first = 0) {
2872 unsigned long val;
2873
2874 if (write) {
2875 bool neg;
2876
2877 left -= proc_skip_spaces(&p);
2878 if (!left)
2879 break;
2880
2881 err = proc_get_long(&p, &left, &val, &neg,
2882 proc_wspace_sep,
2883 sizeof(proc_wspace_sep), NULL);
2884 if (err)
2885 break;
2886 if (neg)
2887 continue;
2888 val = convmul * val / convdiv;
2889 if ((min && val < *min) || (max && val > *max)) {
2890 err = -EINVAL;
2891 break;
2892 }
2893 *i = val;
2894 } else {
2895 val = convdiv * (*i) / convmul;
2896 if (!first) {
2897 err = proc_put_char(&buffer, &left, '\t');
2898 if (err)
2899 break;
2900 }
2901 err = proc_put_long(&buffer, &left, val, false);
2902 if (err)
2903 break;
2904 }
2905 }
2906
2907 if (!write && !first && left && !err)
2908 err = proc_put_char(&buffer, &left, '\n');
2909 if (write && !err)
2910 left -= proc_skip_spaces(&p);
2911 if (write) {
2912 kfree(kbuf);
2913 if (first)
2914 return err ? : -EINVAL;
2915 }
2916 *lenp -= left;
2917out:
2918 *ppos += *lenp;
2919 return err;
2920}
2921
2922static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2923 void __user *buffer,
2924 size_t *lenp, loff_t *ppos,
2925 unsigned long convmul,
2926 unsigned long convdiv)
2927{
2928 return __do_proc_doulongvec_minmax(table->data, table, write,
2929 buffer, lenp, ppos, convmul, convdiv);
2930}
2931
2932/**
2933 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2934 * @table: the sysctl table
2935 * @write: %TRUE if this is a write to the sysctl file
2936 * @buffer: the user buffer
2937 * @lenp: the size of the user buffer
2938 * @ppos: file position
2939 *
2940 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2941 * values from/to the user buffer, treated as an ASCII string.
2942 *
2943 * This routine will ensure the values are within the range specified by
2944 * table->extra1 (min) and table->extra2 (max).
2945 *
2946 * Returns 0 on success.
2947 */
2948int proc_doulongvec_minmax(struct ctl_table *table, int write,
2949 void __user *buffer, size_t *lenp, loff_t *ppos)
2950{
2951 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2952}
2953
2954/**
2955 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2956 * @table: the sysctl table
2957 * @write: %TRUE if this is a write to the sysctl file
2958 * @buffer: the user buffer
2959 * @lenp: the size of the user buffer
2960 * @ppos: file position
2961 *
2962 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2963 * values from/to the user buffer, treated as an ASCII string. The values
2964 * are treated as milliseconds, and converted to jiffies when they are stored.
2965 *
2966 * This routine will ensure the values are within the range specified by
2967 * table->extra1 (min) and table->extra2 (max).
2968 *
2969 * Returns 0 on success.
2970 */
2971int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2972 void __user *buffer,
2973 size_t *lenp, loff_t *ppos)
2974{
2975 return do_proc_doulongvec_minmax(table, write, buffer,
2976 lenp, ppos, HZ, 1000l);
2977}
2978
2979
2980static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2981 int *valp,
2982 int write, void *data)
2983{
2984 if (write) {
2985 if (*lvalp > INT_MAX / HZ)
2986 return 1;
2987 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2988 } else {
2989 int val = *valp;
2990 unsigned long lval;
2991 if (val < 0) {
2992 *negp = true;
2993 lval = -(unsigned long)val;
2994 } else {
2995 *negp = false;
2996 lval = (unsigned long)val;
2997 }
2998 *lvalp = lval / HZ;
2999 }
3000 return 0;
3001}
3002
3003static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
3004 int *valp,
3005 int write, void *data)
3006{
3007 if (write) {
3008 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3009 return 1;
3010 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3011 } else {
3012 int val = *valp;
3013 unsigned long lval;
3014 if (val < 0) {
3015 *negp = true;
3016 lval = -(unsigned long)val;
3017 } else {
3018 *negp = false;
3019 lval = (unsigned long)val;
3020 }
3021 *lvalp = jiffies_to_clock_t(lval);
3022 }
3023 return 0;
3024}
3025
3026static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3027 int *valp,
3028 int write, void *data)
3029{
3030 if (write) {
3031 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3032
3033 if (jif > INT_MAX)
3034 return 1;
3035 *valp = (int)jif;
3036 } else {
3037 int val = *valp;
3038 unsigned long lval;
3039 if (val < 0) {
3040 *negp = true;
3041 lval = -(unsigned long)val;
3042 } else {
3043 *negp = false;
3044 lval = (unsigned long)val;
3045 }
3046 *lvalp = jiffies_to_msecs(lval);
3047 }
3048 return 0;
3049}
3050
3051/**
3052 * proc_dointvec_jiffies - read a vector of integers as seconds
3053 * @table: the sysctl table
3054 * @write: %TRUE if this is a write to the sysctl file
3055 * @buffer: the user buffer
3056 * @lenp: the size of the user buffer
3057 * @ppos: file position
3058 *
3059 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3060 * values from/to the user buffer, treated as an ASCII string.
3061 * The values read are assumed to be in seconds, and are converted into
3062 * jiffies.
3063 *
3064 * Returns 0 on success.
3065 */
3066int proc_dointvec_jiffies(struct ctl_table *table, int write,
3067 void __user *buffer, size_t *lenp, loff_t *ppos)
3068{
3069 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3070 do_proc_dointvec_jiffies_conv,NULL);
3071}
3072
3073/**
3074 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3075 * @table: the sysctl table
3076 * @write: %TRUE if this is a write to the sysctl file
3077 * @buffer: the user buffer
3078 * @lenp: the size of the user buffer
3079 * @ppos: pointer to the file position
3080 *
3081 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3082 * values from/to the user buffer, treated as an ASCII string.
3083 * The values read are assumed to be in 1/USER_HZ seconds, and
3084 * are converted into jiffies.
3085 *
3086 * Returns 0 on success.
3087 */
3088int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3089 void __user *buffer, size_t *lenp, loff_t *ppos)
3090{
3091 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3092 do_proc_dointvec_userhz_jiffies_conv,NULL);
3093}
3094
3095/**
3096 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3097 * @table: the sysctl table
3098 * @write: %TRUE if this is a write to the sysctl file
3099 * @buffer: the user buffer
3100 * @lenp: the size of the user buffer
3101 * @ppos: file position
3102 * @ppos: the current position in the file
3103 *
3104 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3105 * values from/to the user buffer, treated as an ASCII string.
3106 * The values read are assumed to be in 1/1000 seconds, and
3107 * are converted into jiffies.
3108 *
3109 * Returns 0 on success.
3110 */
3111int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3112 void __user *buffer, size_t *lenp, loff_t *ppos)
3113{
3114 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3115 do_proc_dointvec_ms_jiffies_conv, NULL);
3116}
3117
3118static int proc_do_cad_pid(struct ctl_table *table, int write,
3119 void __user *buffer, size_t *lenp, loff_t *ppos)
3120{
3121 struct pid *new_pid;
3122 pid_t tmp;
3123 int r;
3124
3125 tmp = pid_vnr(cad_pid);
3126
3127 r = __do_proc_dointvec(&tmp, table, write, buffer,
3128 lenp, ppos, NULL, NULL);
3129 if (r || !write)
3130 return r;
3131
3132 new_pid = find_get_pid(tmp);
3133 if (!new_pid)
3134 return -ESRCH;
3135
3136 put_pid(xchg(&cad_pid, new_pid));
3137 return 0;
3138}
3139
3140/**
3141 * proc_do_large_bitmap - read/write from/to a large bitmap
3142 * @table: the sysctl table
3143 * @write: %TRUE if this is a write to the sysctl file
3144 * @buffer: the user buffer
3145 * @lenp: the size of the user buffer
3146 * @ppos: file position
3147 *
3148 * The bitmap is stored at table->data and the bitmap length (in bits)
3149 * in table->maxlen.
3150 *
3151 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3152 * large bitmaps may be represented in a compact manner. Writing into
3153 * the file will clear the bitmap then update it with the given input.
3154 *
3155 * Returns 0 on success.
3156 */
3157int proc_do_large_bitmap(struct ctl_table *table, int write,
3158 void __user *buffer, size_t *lenp, loff_t *ppos)
3159{
3160 int err = 0;
3161 bool first = 1;
3162 size_t left = *lenp;
3163 unsigned long bitmap_len = table->maxlen;
3164 unsigned long *bitmap = *(unsigned long **) table->data;
3165 unsigned long *tmp_bitmap = NULL;
3166 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3167
3168 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3169 *lenp = 0;
3170 return 0;
3171 }
3172
3173 if (write) {
3174 char *kbuf, *p;
3175 size_t skipped = 0;
3176
3177 if (left > PAGE_SIZE - 1) {
3178 left = PAGE_SIZE - 1;
3179 /* How much of the buffer we'll skip this pass */
3180 skipped = *lenp - left;
3181 }
3182
3183 p = kbuf = memdup_user_nul(buffer, left);
3184 if (IS_ERR(kbuf))
3185 return PTR_ERR(kbuf);
3186
3187 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
3188 if (!tmp_bitmap) {
3189 kfree(kbuf);
3190 return -ENOMEM;
3191 }
3192 proc_skip_char(&p, &left, '\n');
3193 while (!err && left) {
3194 unsigned long val_a, val_b;
3195 bool neg;
3196 size_t saved_left;
3197
3198 /* In case we stop parsing mid-number, we can reset */
3199 saved_left = left;
3200 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3201 sizeof(tr_a), &c);
3202 /*
3203 * If we consumed the entirety of a truncated buffer or
3204 * only one char is left (may be a "-"), then stop here,
3205 * reset, & come back for more.
3206 */
3207 if ((left <= 1) && skipped) {
3208 left = saved_left;
3209 break;
3210 }
3211
3212 if (err)
3213 break;
3214 if (val_a >= bitmap_len || neg) {
3215 err = -EINVAL;
3216 break;
3217 }
3218
3219 val_b = val_a;
3220 if (left) {
3221 p++;
3222 left--;
3223 }
3224
3225 if (c == '-') {
3226 err = proc_get_long(&p, &left, &val_b,
3227 &neg, tr_b, sizeof(tr_b),
3228 &c);
3229 /*
3230 * If we consumed all of a truncated buffer or
3231 * then stop here, reset, & come back for more.
3232 */
3233 if (!left && skipped) {
3234 left = saved_left;
3235 break;
3236 }
3237
3238 if (err)
3239 break;
3240 if (val_b >= bitmap_len || neg ||
3241 val_a > val_b) {
3242 err = -EINVAL;
3243 break;
3244 }
3245 if (left) {
3246 p++;
3247 left--;
3248 }
3249 }
3250
3251 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3252 first = 0;
3253 proc_skip_char(&p, &left, '\n');
3254 }
3255 kfree(kbuf);
3256 left += skipped;
3257 } else {
3258 unsigned long bit_a, bit_b = 0;
3259
3260 while (left) {
3261 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3262 if (bit_a >= bitmap_len)
3263 break;
3264 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3265 bit_a + 1) - 1;
3266
3267 if (!first) {
3268 err = proc_put_char(&buffer, &left, ',');
3269 if (err)
3270 break;
3271 }
3272 err = proc_put_long(&buffer, &left, bit_a, false);
3273 if (err)
3274 break;
3275 if (bit_a != bit_b) {
3276 err = proc_put_char(&buffer, &left, '-');
3277 if (err)
3278 break;
3279 err = proc_put_long(&buffer, &left, bit_b, false);
3280 if (err)
3281 break;
3282 }
3283
3284 first = 0; bit_b++;
3285 }
3286 if (!err)
3287 err = proc_put_char(&buffer, &left, '\n');
3288 }
3289
3290 if (!err) {
3291 if (write) {
3292 if (*ppos)
3293 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3294 else
3295 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3296 }
3297 *lenp -= left;
3298 *ppos += *lenp;
3299 }
3300
3301 bitmap_free(tmp_bitmap);
3302 return err;
3303}
3304
3305#else /* CONFIG_PROC_SYSCTL */
3306
3307int proc_dostring(struct ctl_table *table, int write,
3308 void __user *buffer, size_t *lenp, loff_t *ppos)
3309{
3310 return -ENOSYS;
3311}
3312
3313int proc_dointvec(struct ctl_table *table, int write,
3314 void __user *buffer, size_t *lenp, loff_t *ppos)
3315{
3316 return -ENOSYS;
3317}
3318
3319int proc_douintvec(struct ctl_table *table, int write,
3320 void __user *buffer, size_t *lenp, loff_t *ppos)
3321{
3322 return -ENOSYS;
3323}
3324
3325int proc_dointvec_minmax(struct ctl_table *table, int write,
3326 void __user *buffer, size_t *lenp, loff_t *ppos)
3327{
3328 return -ENOSYS;
3329}
3330
3331int proc_douintvec_minmax(struct ctl_table *table, int write,
3332 void __user *buffer, size_t *lenp, loff_t *ppos)
3333{
3334 return -ENOSYS;
3335}
3336
3337int proc_dointvec_jiffies(struct ctl_table *table, int write,
3338 void __user *buffer, size_t *lenp, loff_t *ppos)
3339{
3340 return -ENOSYS;
3341}
3342
3343int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3344 void __user *buffer, size_t *lenp, loff_t *ppos)
3345{
3346 return -ENOSYS;
3347}
3348
3349int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3350 void __user *buffer, size_t *lenp, loff_t *ppos)
3351{
3352 return -ENOSYS;
3353}
3354
3355int proc_doulongvec_minmax(struct ctl_table *table, int write,
3356 void __user *buffer, size_t *lenp, loff_t *ppos)
3357{
3358 return -ENOSYS;
3359}
3360
3361int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3362 void __user *buffer,
3363 size_t *lenp, loff_t *ppos)
3364{
3365 return -ENOSYS;
3366}
3367
3368int proc_do_large_bitmap(struct ctl_table *table, int write,
3369 void __user *buffer, size_t *lenp, loff_t *ppos)
3370{
3371 return -ENOSYS;
3372}
3373
3374#endif /* CONFIG_PROC_SYSCTL */
3375
3376#if defined(CONFIG_SYSCTL)
3377int proc_do_static_key(struct ctl_table *table, int write,
3378 void __user *buffer, size_t *lenp,
3379 loff_t *ppos)
3380{
3381 struct static_key *key = (struct static_key *)table->data;
3382 static DEFINE_MUTEX(static_key_mutex);
3383 int val, ret;
3384 struct ctl_table tmp = {
3385 .data = &val,
3386 .maxlen = sizeof(val),
3387 .mode = table->mode,
3388 .extra1 = SYSCTL_ZERO,
3389 .extra2 = SYSCTL_ONE,
3390 };
3391
3392 if (write && !capable(CAP_SYS_ADMIN))
3393 return -EPERM;
3394
3395 mutex_lock(&static_key_mutex);
3396 val = static_key_enabled(key);
3397 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3398 if (write && !ret) {
3399 if (val)
3400 static_key_enable(key);
3401 else
3402 static_key_disable(key);
3403 }
3404 mutex_unlock(&static_key_mutex);
3405 return ret;
3406}
3407#endif
3408/*
3409 * No sense putting this after each symbol definition, twice,
3410 * exception granted :-)
3411 */
3412EXPORT_SYMBOL(proc_dointvec);
3413EXPORT_SYMBOL(proc_douintvec);
3414EXPORT_SYMBOL(proc_dointvec_jiffies);
3415EXPORT_SYMBOL(proc_dointvec_minmax);
3416EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3417EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3418EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3419EXPORT_SYMBOL(proc_dostring);
3420EXPORT_SYMBOL(proc_doulongvec_minmax);
3421EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3422EXPORT_SYMBOL(proc_do_large_bitmap);