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