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