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