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