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