x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / kernel / sysctl.c
blob8c8714fcb53c35a390becf14f2fa8e1bfc20142c
1 /*
2 * sysctl.c: General linux system control interface
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
21 #include <linux/module.h>
22 #include <linux/aio.h>
23 #include <linux/mm.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemcheck.h>
34 #include <linux/kmemleak.h>
35 #include <linux/fs.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/sched/coredump.h>
67 #include <linux/kexec.h>
68 #include <linux/bpf.h>
69 #include <linux/mount.h>
71 #include <linux/uaccess.h>
72 #include <asm/processor.h>
74 #ifdef CONFIG_X86
75 #include <asm/nmi.h>
76 #include <asm/stacktrace.h>
77 #include <asm/io.h>
78 #endif
79 #ifdef CONFIG_SPARC
80 #include <asm/setup.h>
81 #endif
82 #ifdef CONFIG_BSD_PROCESS_ACCT
83 #include <linux/acct.h>
84 #endif
85 #ifdef CONFIG_RT_MUTEXES
86 #include <linux/rtmutex.h>
87 #endif
88 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
89 #include <linux/lockdep.h>
90 #endif
91 #ifdef CONFIG_CHR_DEV_SG
92 #include <scsi/sg.h>
93 #endif
95 #ifdef CONFIG_LOCKUP_DETECTOR
96 #include <linux/nmi.h>
97 #endif
99 #if defined(CONFIG_SYSCTL)
101 /* External variables not in a header file. */
102 extern int suid_dumpable;
103 #ifdef CONFIG_COREDUMP
104 extern int core_uses_pid;
105 extern char core_pattern[];
106 extern unsigned int core_pipe_limit;
107 #endif
108 extern int pid_max;
109 extern int pid_max_min, pid_max_max;
110 extern int percpu_pagelist_fraction;
111 extern int latencytop_enabled;
112 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
113 #ifndef CONFIG_MMU
114 extern int sysctl_nr_trim_pages;
115 #endif
117 /* Constants used for minimum and maximum */
118 #ifdef CONFIG_LOCKUP_DETECTOR
119 static int sixty = 60;
120 #endif
122 static int __maybe_unused neg_one = -1;
124 static int zero;
125 static int __maybe_unused one = 1;
126 static int __maybe_unused two = 2;
127 static int __maybe_unused four = 4;
128 static unsigned long one_ul = 1;
129 static int one_hundred = 100;
130 static int one_thousand = 1000;
131 #ifdef CONFIG_PRINTK
132 static int ten_thousand = 10000;
133 #endif
134 #ifdef CONFIG_PERF_EVENTS
135 static int six_hundred_forty_kb = 640 * 1024;
136 #endif
138 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
141 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142 static int maxolduid = 65535;
143 static int minolduid;
145 static int ngroups_max = NGROUPS_MAX;
146 static const int cap_last_cap = CAP_LAST_CAP;
148 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
149 #ifdef CONFIG_DETECT_HUNG_TASK
150 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
151 #endif
153 #ifdef CONFIG_INOTIFY_USER
154 #include <linux/inotify.h>
155 #endif
156 #ifdef CONFIG_SPARC
157 #endif
159 #ifdef __hppa__
160 extern int pwrsw_enabled;
161 #endif
163 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
164 extern int unaligned_enabled;
165 #endif
167 #ifdef CONFIG_IA64
168 extern int unaligned_dump_stack;
169 #endif
171 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172 extern int no_unaligned_warning;
173 #endif
175 #ifdef CONFIG_PROC_SYSCTL
177 #define SYSCTL_WRITES_LEGACY -1
178 #define SYSCTL_WRITES_WARN 0
179 #define SYSCTL_WRITES_STRICT 1
181 static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
183 static int proc_do_cad_pid(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
185 static int proc_taint(struct ctl_table *table, int write,
186 void __user *buffer, size_t *lenp, loff_t *ppos);
187 #endif
189 #ifdef CONFIG_PRINTK
190 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
192 #endif
194 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
195 void __user *buffer, size_t *lenp, loff_t *ppos);
196 #ifdef CONFIG_COREDUMP
197 static int proc_dostring_coredump(struct ctl_table *table, int write,
198 void __user *buffer, size_t *lenp, loff_t *ppos);
199 #endif
201 #ifdef CONFIG_MAGIC_SYSRQ
202 /* Note: sysrq code uses it's own private copy */
203 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
205 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
206 void __user *buffer, size_t *lenp,
207 loff_t *ppos)
209 int error;
211 error = proc_dointvec(table, write, buffer, lenp, ppos);
212 if (error)
213 return error;
215 if (write)
216 sysrq_toggle_support(__sysrq_enabled);
218 return 0;
221 #endif
223 static struct ctl_table kern_table[];
224 static struct ctl_table vm_table[];
225 static struct ctl_table fs_table[];
226 static struct ctl_table debug_table[];
227 static struct ctl_table dev_table[];
228 extern struct ctl_table random_table[];
229 #ifdef CONFIG_EPOLL
230 extern struct ctl_table epoll_table[];
231 #endif
233 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
234 int sysctl_legacy_va_layout;
235 #endif
237 /* The default sysctl tables: */
239 static struct ctl_table sysctl_base_table[] = {
241 .procname = "kernel",
242 .mode = 0555,
243 .child = kern_table,
246 .procname = "vm",
247 .mode = 0555,
248 .child = vm_table,
251 .procname = "fs",
252 .mode = 0555,
253 .child = fs_table,
256 .procname = "debug",
257 .mode = 0555,
258 .child = debug_table,
261 .procname = "dev",
262 .mode = 0555,
263 .child = dev_table,
268 #ifdef CONFIG_SCHED_DEBUG
269 static int min_sched_granularity_ns = 100000; /* 100 usecs */
270 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
271 static int min_wakeup_granularity_ns; /* 0 usecs */
272 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
273 #ifdef CONFIG_SMP
274 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
275 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
276 #endif /* CONFIG_SMP */
277 #endif /* CONFIG_SCHED_DEBUG */
279 #ifdef CONFIG_COMPACTION
280 static int min_extfrag_threshold;
281 static int max_extfrag_threshold = 1000;
282 #endif
284 static struct ctl_table kern_table[] = {
286 .procname = "sched_child_runs_first",
287 .data = &sysctl_sched_child_runs_first,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = proc_dointvec,
292 #ifdef CONFIG_SCHED_DEBUG
294 .procname = "sched_min_granularity_ns",
295 .data = &sysctl_sched_min_granularity,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
298 .proc_handler = sched_proc_update_handler,
299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
303 .procname = "sched_latency_ns",
304 .data = &sysctl_sched_latency,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
307 .proc_handler = sched_proc_update_handler,
308 .extra1 = &min_sched_granularity_ns,
309 .extra2 = &max_sched_granularity_ns,
312 .procname = "sched_wakeup_granularity_ns",
313 .data = &sysctl_sched_wakeup_granularity,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_wakeup_granularity_ns,
318 .extra2 = &max_wakeup_granularity_ns,
320 #ifdef CONFIG_SMP
322 .procname = "sched_tunable_scaling",
323 .data = &sysctl_sched_tunable_scaling,
324 .maxlen = sizeof(enum sched_tunable_scaling),
325 .mode = 0644,
326 .proc_handler = sched_proc_update_handler,
327 .extra1 = &min_sched_tunable_scaling,
328 .extra2 = &max_sched_tunable_scaling,
331 .procname = "sched_migration_cost_ns",
332 .data = &sysctl_sched_migration_cost,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
335 .proc_handler = proc_dointvec,
338 .procname = "sched_nr_migrate",
339 .data = &sysctl_sched_nr_migrate,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
342 .proc_handler = proc_dointvec,
345 .procname = "sched_time_avg_ms",
346 .data = &sysctl_sched_time_avg,
347 .maxlen = sizeof(unsigned int),
348 .mode = 0644,
349 .proc_handler = proc_dointvec,
351 #ifdef CONFIG_SCHEDSTATS
353 .procname = "sched_schedstats",
354 .data = NULL,
355 .maxlen = sizeof(unsigned int),
356 .mode = 0644,
357 .proc_handler = sysctl_schedstats,
358 .extra1 = &zero,
359 .extra2 = &one,
361 #endif /* CONFIG_SCHEDSTATS */
362 #endif /* CONFIG_SMP */
363 #ifdef CONFIG_NUMA_BALANCING
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,
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,
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,
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_minmax,
391 .extra1 = &one,
394 .procname = "numa_balancing",
395 .data = NULL, /* filled in by handler */
396 .maxlen = sizeof(unsigned int),
397 .mode = 0644,
398 .proc_handler = sysctl_numa_balancing,
399 .extra1 = &zero,
400 .extra2 = &one,
402 #endif /* CONFIG_NUMA_BALANCING */
403 #endif /* CONFIG_SCHED_DEBUG */
405 .procname = "sched_rt_period_us",
406 .data = &sysctl_sched_rt_period,
407 .maxlen = sizeof(unsigned int),
408 .mode = 0644,
409 .proc_handler = sched_rt_handler,
412 .procname = "sched_rt_runtime_us",
413 .data = &sysctl_sched_rt_runtime,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = sched_rt_handler,
419 .procname = "sched_rr_timeslice_ms",
420 .data = &sysctl_sched_rr_timeslice,
421 .maxlen = sizeof(int),
422 .mode = 0644,
423 .proc_handler = sched_rr_handler,
425 #ifdef CONFIG_SCHED_AUTOGROUP
427 .procname = "sched_autogroup_enabled",
428 .data = &sysctl_sched_autogroup_enabled,
429 .maxlen = sizeof(unsigned int),
430 .mode = 0644,
431 .proc_handler = proc_dointvec_minmax,
432 .extra1 = &zero,
433 .extra2 = &one,
435 #endif
436 #ifdef CONFIG_CFS_BANDWIDTH
438 .procname = "sched_cfs_bandwidth_slice_us",
439 .data = &sysctl_sched_cfs_bandwidth_slice,
440 .maxlen = sizeof(unsigned int),
441 .mode = 0644,
442 .proc_handler = proc_dointvec_minmax,
443 .extra1 = &one,
445 #endif
446 #ifdef CONFIG_PROVE_LOCKING
448 .procname = "prove_locking",
449 .data = &prove_locking,
450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = proc_dointvec,
454 #endif
455 #ifdef CONFIG_LOCK_STAT
457 .procname = "lock_stat",
458 .data = &lock_stat,
459 .maxlen = sizeof(int),
460 .mode = 0644,
461 .proc_handler = proc_dointvec,
463 #endif
465 .procname = "panic",
466 .data = &panic_timeout,
467 .maxlen = sizeof(int),
468 .mode = 0644,
469 .proc_handler = proc_dointvec,
471 #ifdef CONFIG_COREDUMP
473 .procname = "core_uses_pid",
474 .data = &core_uses_pid,
475 .maxlen = sizeof(int),
476 .mode = 0644,
477 .proc_handler = proc_dointvec,
480 .procname = "core_pattern",
481 .data = core_pattern,
482 .maxlen = CORENAME_MAX_SIZE,
483 .mode = 0644,
484 .proc_handler = proc_dostring_coredump,
487 .procname = "core_pipe_limit",
488 .data = &core_pipe_limit,
489 .maxlen = sizeof(unsigned int),
490 .mode = 0644,
491 .proc_handler = proc_dointvec,
493 #endif
494 #ifdef CONFIG_PROC_SYSCTL
496 .procname = "tainted",
497 .maxlen = sizeof(long),
498 .mode = 0644,
499 .proc_handler = proc_taint,
502 .procname = "sysctl_writes_strict",
503 .data = &sysctl_writes_strict,
504 .maxlen = sizeof(int),
505 .mode = 0644,
506 .proc_handler = proc_dointvec_minmax,
507 .extra1 = &neg_one,
508 .extra2 = &one,
510 #endif
511 #ifdef CONFIG_LATENCYTOP
513 .procname = "latencytop",
514 .data = &latencytop_enabled,
515 .maxlen = sizeof(int),
516 .mode = 0644,
517 .proc_handler = sysctl_latencytop,
519 #endif
520 #ifdef CONFIG_BLK_DEV_INITRD
522 .procname = "real-root-dev",
523 .data = &real_root_dev,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = proc_dointvec,
528 #endif
530 .procname = "print-fatal-signals",
531 .data = &print_fatal_signals,
532 .maxlen = sizeof(int),
533 .mode = 0644,
534 .proc_handler = proc_dointvec,
536 #ifdef CONFIG_SPARC
538 .procname = "reboot-cmd",
539 .data = reboot_command,
540 .maxlen = 256,
541 .mode = 0644,
542 .proc_handler = proc_dostring,
545 .procname = "stop-a",
546 .data = &stop_a_enabled,
547 .maxlen = sizeof (int),
548 .mode = 0644,
549 .proc_handler = proc_dointvec,
552 .procname = "scons-poweroff",
553 .data = &scons_pwroff,
554 .maxlen = sizeof (int),
555 .mode = 0644,
556 .proc_handler = proc_dointvec,
558 #endif
559 #ifdef CONFIG_SPARC64
561 .procname = "tsb-ratio",
562 .data = &sysctl_tsb_ratio,
563 .maxlen = sizeof (int),
564 .mode = 0644,
565 .proc_handler = proc_dointvec,
567 #endif
568 #ifdef __hppa__
570 .procname = "soft-power",
571 .data = &pwrsw_enabled,
572 .maxlen = sizeof (int),
573 .mode = 0644,
574 .proc_handler = proc_dointvec,
576 #endif
577 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
579 .procname = "unaligned-trap",
580 .data = &unaligned_enabled,
581 .maxlen = sizeof (int),
582 .mode = 0644,
583 .proc_handler = proc_dointvec,
585 #endif
587 .procname = "ctrl-alt-del",
588 .data = &C_A_D,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = proc_dointvec,
593 #ifdef CONFIG_FUNCTION_TRACER
595 .procname = "ftrace_enabled",
596 .data = &ftrace_enabled,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = ftrace_enable_sysctl,
601 #endif
602 #ifdef CONFIG_STACK_TRACER
604 .procname = "stack_tracer_enabled",
605 .data = &stack_tracer_enabled,
606 .maxlen = sizeof(int),
607 .mode = 0644,
608 .proc_handler = stack_trace_sysctl,
610 #endif
611 #ifdef CONFIG_TRACING
613 .procname = "ftrace_dump_on_oops",
614 .data = &ftrace_dump_on_oops,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = proc_dointvec,
620 .procname = "traceoff_on_warning",
621 .data = &__disable_trace_on_warning,
622 .maxlen = sizeof(__disable_trace_on_warning),
623 .mode = 0644,
624 .proc_handler = proc_dointvec,
627 .procname = "tracepoint_printk",
628 .data = &tracepoint_printk,
629 .maxlen = sizeof(tracepoint_printk),
630 .mode = 0644,
631 .proc_handler = tracepoint_printk_sysctl,
633 #endif
634 #ifdef CONFIG_KEXEC_CORE
636 .procname = "kexec_load_disabled",
637 .data = &kexec_load_disabled,
638 .maxlen = sizeof(int),
639 .mode = 0644,
640 /* only handle a transition from default "0" to "1" */
641 .proc_handler = proc_dointvec_minmax,
642 .extra1 = &one,
643 .extra2 = &one,
645 #endif
646 #ifdef CONFIG_MODULES
648 .procname = "modprobe",
649 .data = &modprobe_path,
650 .maxlen = KMOD_PATH_LEN,
651 .mode = 0644,
652 .proc_handler = proc_dostring,
655 .procname = "modules_disabled",
656 .data = &modules_disabled,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 /* only handle a transition from default "0" to "1" */
660 .proc_handler = proc_dointvec_minmax,
661 .extra1 = &one,
662 .extra2 = &one,
664 #endif
665 #ifdef CONFIG_UEVENT_HELPER
667 .procname = "hotplug",
668 .data = &uevent_helper,
669 .maxlen = UEVENT_HELPER_PATH_LEN,
670 .mode = 0644,
671 .proc_handler = proc_dostring,
673 #endif
674 #ifdef CONFIG_CHR_DEV_SG
676 .procname = "sg-big-buff",
677 .data = &sg_big_buff,
678 .maxlen = sizeof (int),
679 .mode = 0444,
680 .proc_handler = proc_dointvec,
682 #endif
683 #ifdef CONFIG_BSD_PROCESS_ACCT
685 .procname = "acct",
686 .data = &acct_parm,
687 .maxlen = 3*sizeof(int),
688 .mode = 0644,
689 .proc_handler = proc_dointvec,
691 #endif
692 #ifdef CONFIG_MAGIC_SYSRQ
694 .procname = "sysrq",
695 .data = &__sysrq_enabled,
696 .maxlen = sizeof (int),
697 .mode = 0644,
698 .proc_handler = sysrq_sysctl_handler,
700 #endif
701 #ifdef CONFIG_PROC_SYSCTL
703 .procname = "cad_pid",
704 .data = NULL,
705 .maxlen = sizeof (int),
706 .mode = 0600,
707 .proc_handler = proc_do_cad_pid,
709 #endif
711 .procname = "threads-max",
712 .data = NULL,
713 .maxlen = sizeof(int),
714 .mode = 0644,
715 .proc_handler = sysctl_max_threads,
718 .procname = "random",
719 .mode = 0555,
720 .child = random_table,
723 .procname = "usermodehelper",
724 .mode = 0555,
725 .child = usermodehelper_table,
728 .procname = "overflowuid",
729 .data = &overflowuid,
730 .maxlen = sizeof(int),
731 .mode = 0644,
732 .proc_handler = proc_dointvec_minmax,
733 .extra1 = &minolduid,
734 .extra2 = &maxolduid,
737 .procname = "overflowgid",
738 .data = &overflowgid,
739 .maxlen = sizeof(int),
740 .mode = 0644,
741 .proc_handler = proc_dointvec_minmax,
742 .extra1 = &minolduid,
743 .extra2 = &maxolduid,
745 #ifdef CONFIG_S390
746 #ifdef CONFIG_MATHEMU
748 .procname = "ieee_emulation_warnings",
749 .data = &sysctl_ieee_emulation_warnings,
750 .maxlen = sizeof(int),
751 .mode = 0644,
752 .proc_handler = proc_dointvec,
754 #endif
756 .procname = "userprocess_debug",
757 .data = &show_unhandled_signals,
758 .maxlen = sizeof(int),
759 .mode = 0644,
760 .proc_handler = proc_dointvec,
762 #endif
764 .procname = "pid_max",
765 .data = &pid_max,
766 .maxlen = sizeof (int),
767 .mode = 0644,
768 .proc_handler = proc_dointvec_minmax,
769 .extra1 = &pid_max_min,
770 .extra2 = &pid_max_max,
773 .procname = "panic_on_oops",
774 .data = &panic_on_oops,
775 .maxlen = sizeof(int),
776 .mode = 0644,
777 .proc_handler = proc_dointvec,
779 #if defined CONFIG_PRINTK
781 .procname = "printk",
782 .data = &console_loglevel,
783 .maxlen = 4*sizeof(int),
784 .mode = 0644,
785 .proc_handler = proc_dointvec,
788 .procname = "printk_ratelimit",
789 .data = &printk_ratelimit_state.interval,
790 .maxlen = sizeof(int),
791 .mode = 0644,
792 .proc_handler = proc_dointvec_jiffies,
795 .procname = "printk_ratelimit_burst",
796 .data = &printk_ratelimit_state.burst,
797 .maxlen = sizeof(int),
798 .mode = 0644,
799 .proc_handler = proc_dointvec,
802 .procname = "printk_delay",
803 .data = &printk_delay_msec,
804 .maxlen = sizeof(int),
805 .mode = 0644,
806 .proc_handler = proc_dointvec_minmax,
807 .extra1 = &zero,
808 .extra2 = &ten_thousand,
811 .procname = "printk_devkmsg",
812 .data = devkmsg_log_str,
813 .maxlen = DEVKMSG_STR_MAX_SIZE,
814 .mode = 0644,
815 .proc_handler = devkmsg_sysctl_set_loglvl,
818 .procname = "dmesg_restrict",
819 .data = &dmesg_restrict,
820 .maxlen = sizeof(int),
821 .mode = 0644,
822 .proc_handler = proc_dointvec_minmax_sysadmin,
823 .extra1 = &zero,
824 .extra2 = &one,
827 .procname = "kptr_restrict",
828 .data = &kptr_restrict,
829 .maxlen = sizeof(int),
830 .mode = 0644,
831 .proc_handler = proc_dointvec_minmax_sysadmin,
832 .extra1 = &zero,
833 .extra2 = &two,
835 #endif
837 .procname = "ngroups_max",
838 .data = &ngroups_max,
839 .maxlen = sizeof (int),
840 .mode = 0444,
841 .proc_handler = proc_dointvec,
844 .procname = "cap_last_cap",
845 .data = (void *)&cap_last_cap,
846 .maxlen = sizeof(int),
847 .mode = 0444,
848 .proc_handler = proc_dointvec,
850 #if defined(CONFIG_LOCKUP_DETECTOR)
852 .procname = "watchdog",
853 .data = &watchdog_user_enabled,
854 .maxlen = sizeof (int),
855 .mode = 0644,
856 .proc_handler = proc_watchdog,
857 .extra1 = &zero,
858 .extra2 = &one,
861 .procname = "watchdog_thresh",
862 .data = &watchdog_thresh,
863 .maxlen = sizeof(int),
864 .mode = 0644,
865 .proc_handler = proc_watchdog_thresh,
866 .extra1 = &zero,
867 .extra2 = &sixty,
870 .procname = "nmi_watchdog",
871 .data = &nmi_watchdog_enabled,
872 .maxlen = sizeof (int),
873 .mode = 0644,
874 .proc_handler = proc_nmi_watchdog,
875 .extra1 = &zero,
876 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
877 .extra2 = &one,
878 #else
879 .extra2 = &zero,
880 #endif
883 .procname = "soft_watchdog",
884 .data = &soft_watchdog_enabled,
885 .maxlen = sizeof (int),
886 .mode = 0644,
887 .proc_handler = proc_soft_watchdog,
888 .extra1 = &zero,
889 .extra2 = &one,
892 .procname = "watchdog_cpumask",
893 .data = &watchdog_cpumask_bits,
894 .maxlen = NR_CPUS,
895 .mode = 0644,
896 .proc_handler = proc_watchdog_cpumask,
899 .procname = "softlockup_panic",
900 .data = &softlockup_panic,
901 .maxlen = sizeof(int),
902 .mode = 0644,
903 .proc_handler = proc_dointvec_minmax,
904 .extra1 = &zero,
905 .extra2 = &one,
907 #ifdef CONFIG_HARDLOCKUP_DETECTOR
909 .procname = "hardlockup_panic",
910 .data = &hardlockup_panic,
911 .maxlen = sizeof(int),
912 .mode = 0644,
913 .proc_handler = proc_dointvec_minmax,
914 .extra1 = &zero,
915 .extra2 = &one,
917 #endif
918 #ifdef CONFIG_SMP
920 .procname = "softlockup_all_cpu_backtrace",
921 .data = &sysctl_softlockup_all_cpu_backtrace,
922 .maxlen = sizeof(int),
923 .mode = 0644,
924 .proc_handler = proc_dointvec_minmax,
925 .extra1 = &zero,
926 .extra2 = &one,
929 .procname = "hardlockup_all_cpu_backtrace",
930 .data = &sysctl_hardlockup_all_cpu_backtrace,
931 .maxlen = sizeof(int),
932 .mode = 0644,
933 .proc_handler = proc_dointvec_minmax,
934 .extra1 = &zero,
935 .extra2 = &one,
937 #endif /* CONFIG_SMP */
938 #endif
939 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
941 .procname = "unknown_nmi_panic",
942 .data = &unknown_nmi_panic,
943 .maxlen = sizeof (int),
944 .mode = 0644,
945 .proc_handler = proc_dointvec,
947 #endif
948 #if defined(CONFIG_X86)
950 .procname = "panic_on_unrecovered_nmi",
951 .data = &panic_on_unrecovered_nmi,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = proc_dointvec,
957 .procname = "panic_on_io_nmi",
958 .data = &panic_on_io_nmi,
959 .maxlen = sizeof(int),
960 .mode = 0644,
961 .proc_handler = proc_dointvec,
963 #ifdef CONFIG_DEBUG_STACKOVERFLOW
965 .procname = "panic_on_stackoverflow",
966 .data = &sysctl_panic_on_stackoverflow,
967 .maxlen = sizeof(int),
968 .mode = 0644,
969 .proc_handler = proc_dointvec,
971 #endif
973 .procname = "bootloader_type",
974 .data = &bootloader_type,
975 .maxlen = sizeof (int),
976 .mode = 0444,
977 .proc_handler = proc_dointvec,
980 .procname = "bootloader_version",
981 .data = &bootloader_version,
982 .maxlen = sizeof (int),
983 .mode = 0444,
984 .proc_handler = proc_dointvec,
987 .procname = "io_delay_type",
988 .data = &io_delay_type,
989 .maxlen = sizeof(int),
990 .mode = 0644,
991 .proc_handler = proc_dointvec,
993 #endif
994 #if defined(CONFIG_MMU)
996 .procname = "randomize_va_space",
997 .data = &randomize_va_space,
998 .maxlen = sizeof(int),
999 .mode = 0644,
1000 .proc_handler = proc_dointvec,
1002 #endif
1003 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1005 .procname = "spin_retry",
1006 .data = &spin_retry,
1007 .maxlen = sizeof (int),
1008 .mode = 0644,
1009 .proc_handler = proc_dointvec,
1011 #endif
1012 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1014 .procname = "acpi_video_flags",
1015 .data = &acpi_realmode_flags,
1016 .maxlen = sizeof (unsigned long),
1017 .mode = 0644,
1018 .proc_handler = proc_doulongvec_minmax,
1020 #endif
1021 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1023 .procname = "ignore-unaligned-usertrap",
1024 .data = &no_unaligned_warning,
1025 .maxlen = sizeof (int),
1026 .mode = 0644,
1027 .proc_handler = proc_dointvec,
1029 #endif
1030 #ifdef CONFIG_IA64
1032 .procname = "unaligned-dump-stack",
1033 .data = &unaligned_dump_stack,
1034 .maxlen = sizeof (int),
1035 .mode = 0644,
1036 .proc_handler = proc_dointvec,
1038 #endif
1039 #ifdef CONFIG_DETECT_HUNG_TASK
1041 .procname = "hung_task_panic",
1042 .data = &sysctl_hung_task_panic,
1043 .maxlen = sizeof(int),
1044 .mode = 0644,
1045 .proc_handler = proc_dointvec_minmax,
1046 .extra1 = &zero,
1047 .extra2 = &one,
1050 .procname = "hung_task_check_count",
1051 .data = &sysctl_hung_task_check_count,
1052 .maxlen = sizeof(int),
1053 .mode = 0644,
1054 .proc_handler = proc_dointvec_minmax,
1055 .extra1 = &zero,
1058 .procname = "hung_task_timeout_secs",
1059 .data = &sysctl_hung_task_timeout_secs,
1060 .maxlen = sizeof(unsigned long),
1061 .mode = 0644,
1062 .proc_handler = proc_dohung_task_timeout_secs,
1063 .extra2 = &hung_task_timeout_max,
1066 .procname = "hung_task_warnings",
1067 .data = &sysctl_hung_task_warnings,
1068 .maxlen = sizeof(int),
1069 .mode = 0644,
1070 .proc_handler = proc_dointvec_minmax,
1071 .extra1 = &neg_one,
1073 #endif
1074 #ifdef CONFIG_RT_MUTEXES
1076 .procname = "max_lock_depth",
1077 .data = &max_lock_depth,
1078 .maxlen = sizeof(int),
1079 .mode = 0644,
1080 .proc_handler = proc_dointvec,
1082 #endif
1084 .procname = "poweroff_cmd",
1085 .data = &poweroff_cmd,
1086 .maxlen = POWEROFF_CMD_PATH_LEN,
1087 .mode = 0644,
1088 .proc_handler = proc_dostring,
1090 #ifdef CONFIG_KEYS
1092 .procname = "keys",
1093 .mode = 0555,
1094 .child = key_sysctls,
1096 #endif
1097 #ifdef CONFIG_PERF_EVENTS
1099 * User-space scripts rely on the existence of this file
1100 * as a feature check for perf_events being enabled.
1102 * So it's an ABI, do not remove!
1105 .procname = "perf_event_paranoid",
1106 .data = &sysctl_perf_event_paranoid,
1107 .maxlen = sizeof(sysctl_perf_event_paranoid),
1108 .mode = 0644,
1109 .proc_handler = proc_dointvec,
1112 .procname = "perf_event_mlock_kb",
1113 .data = &sysctl_perf_event_mlock,
1114 .maxlen = sizeof(sysctl_perf_event_mlock),
1115 .mode = 0644,
1116 .proc_handler = proc_dointvec,
1119 .procname = "perf_event_max_sample_rate",
1120 .data = &sysctl_perf_event_sample_rate,
1121 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1122 .mode = 0644,
1123 .proc_handler = perf_proc_update_handler,
1124 .extra1 = &one,
1127 .procname = "perf_cpu_time_max_percent",
1128 .data = &sysctl_perf_cpu_time_max_percent,
1129 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1130 .mode = 0644,
1131 .proc_handler = perf_cpu_time_max_percent_handler,
1132 .extra1 = &zero,
1133 .extra2 = &one_hundred,
1136 .procname = "perf_event_max_stack",
1137 .data = &sysctl_perf_event_max_stack,
1138 .maxlen = sizeof(sysctl_perf_event_max_stack),
1139 .mode = 0644,
1140 .proc_handler = perf_event_max_stack_handler,
1141 .extra1 = &zero,
1142 .extra2 = &six_hundred_forty_kb,
1145 .procname = "perf_event_max_contexts_per_stack",
1146 .data = &sysctl_perf_event_max_contexts_per_stack,
1147 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1148 .mode = 0644,
1149 .proc_handler = perf_event_max_stack_handler,
1150 .extra1 = &zero,
1151 .extra2 = &one_thousand,
1153 #endif
1154 #ifdef CONFIG_KMEMCHECK
1156 .procname = "kmemcheck",
1157 .data = &kmemcheck_enabled,
1158 .maxlen = sizeof(int),
1159 .mode = 0644,
1160 .proc_handler = proc_dointvec,
1162 #endif
1164 .procname = "panic_on_warn",
1165 .data = &panic_on_warn,
1166 .maxlen = sizeof(int),
1167 .mode = 0644,
1168 .proc_handler = proc_dointvec_minmax,
1169 .extra1 = &zero,
1170 .extra2 = &one,
1172 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1174 .procname = "timer_migration",
1175 .data = &sysctl_timer_migration,
1176 .maxlen = sizeof(unsigned int),
1177 .mode = 0644,
1178 .proc_handler = timer_migration_handler,
1180 #endif
1181 #ifdef CONFIG_BPF_SYSCALL
1183 .procname = "unprivileged_bpf_disabled",
1184 .data = &sysctl_unprivileged_bpf_disabled,
1185 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1186 .mode = 0644,
1187 /* only handle a transition from default "0" to "1" */
1188 .proc_handler = proc_dointvec_minmax,
1189 .extra1 = &one,
1190 .extra2 = &one,
1192 #endif
1193 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1195 .procname = "panic_on_rcu_stall",
1196 .data = &sysctl_panic_on_rcu_stall,
1197 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1198 .mode = 0644,
1199 .proc_handler = proc_dointvec_minmax,
1200 .extra1 = &zero,
1201 .extra2 = &one,
1203 #endif
1207 static struct ctl_table vm_table[] = {
1209 .procname = "overcommit_memory",
1210 .data = &sysctl_overcommit_memory,
1211 .maxlen = sizeof(sysctl_overcommit_memory),
1212 .mode = 0644,
1213 .proc_handler = proc_dointvec_minmax,
1214 .extra1 = &zero,
1215 .extra2 = &two,
1218 .procname = "panic_on_oom",
1219 .data = &sysctl_panic_on_oom,
1220 .maxlen = sizeof(sysctl_panic_on_oom),
1221 .mode = 0644,
1222 .proc_handler = proc_dointvec_minmax,
1223 .extra1 = &zero,
1224 .extra2 = &two,
1227 .procname = "oom_kill_allocating_task",
1228 .data = &sysctl_oom_kill_allocating_task,
1229 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1230 .mode = 0644,
1231 .proc_handler = proc_dointvec,
1234 .procname = "oom_dump_tasks",
1235 .data = &sysctl_oom_dump_tasks,
1236 .maxlen = sizeof(sysctl_oom_dump_tasks),
1237 .mode = 0644,
1238 .proc_handler = proc_dointvec,
1241 .procname = "overcommit_ratio",
1242 .data = &sysctl_overcommit_ratio,
1243 .maxlen = sizeof(sysctl_overcommit_ratio),
1244 .mode = 0644,
1245 .proc_handler = overcommit_ratio_handler,
1248 .procname = "overcommit_kbytes",
1249 .data = &sysctl_overcommit_kbytes,
1250 .maxlen = sizeof(sysctl_overcommit_kbytes),
1251 .mode = 0644,
1252 .proc_handler = overcommit_kbytes_handler,
1255 .procname = "page-cluster",
1256 .data = &page_cluster,
1257 .maxlen = sizeof(int),
1258 .mode = 0644,
1259 .proc_handler = proc_dointvec_minmax,
1260 .extra1 = &zero,
1263 .procname = "dirty_background_ratio",
1264 .data = &dirty_background_ratio,
1265 .maxlen = sizeof(dirty_background_ratio),
1266 .mode = 0644,
1267 .proc_handler = dirty_background_ratio_handler,
1268 .extra1 = &zero,
1269 .extra2 = &one_hundred,
1272 .procname = "dirty_background_bytes",
1273 .data = &dirty_background_bytes,
1274 .maxlen = sizeof(dirty_background_bytes),
1275 .mode = 0644,
1276 .proc_handler = dirty_background_bytes_handler,
1277 .extra1 = &one_ul,
1280 .procname = "dirty_ratio",
1281 .data = &vm_dirty_ratio,
1282 .maxlen = sizeof(vm_dirty_ratio),
1283 .mode = 0644,
1284 .proc_handler = dirty_ratio_handler,
1285 .extra1 = &zero,
1286 .extra2 = &one_hundred,
1289 .procname = "dirty_bytes",
1290 .data = &vm_dirty_bytes,
1291 .maxlen = sizeof(vm_dirty_bytes),
1292 .mode = 0644,
1293 .proc_handler = dirty_bytes_handler,
1294 .extra1 = &dirty_bytes_min,
1297 .procname = "dirty_writeback_centisecs",
1298 .data = &dirty_writeback_interval,
1299 .maxlen = sizeof(dirty_writeback_interval),
1300 .mode = 0644,
1301 .proc_handler = dirty_writeback_centisecs_handler,
1304 .procname = "dirty_expire_centisecs",
1305 .data = &dirty_expire_interval,
1306 .maxlen = sizeof(dirty_expire_interval),
1307 .mode = 0644,
1308 .proc_handler = proc_dointvec_minmax,
1309 .extra1 = &zero,
1312 .procname = "dirtytime_expire_seconds",
1313 .data = &dirtytime_expire_interval,
1314 .maxlen = sizeof(dirty_expire_interval),
1315 .mode = 0644,
1316 .proc_handler = dirtytime_interval_handler,
1317 .extra1 = &zero,
1320 .procname = "nr_pdflush_threads",
1321 .mode = 0444 /* read-only */,
1322 .proc_handler = pdflush_proc_obsolete,
1325 .procname = "swappiness",
1326 .data = &vm_swappiness,
1327 .maxlen = sizeof(vm_swappiness),
1328 .mode = 0644,
1329 .proc_handler = proc_dointvec_minmax,
1330 .extra1 = &zero,
1331 .extra2 = &one_hundred,
1333 #ifdef CONFIG_HUGETLB_PAGE
1335 .procname = "nr_hugepages",
1336 .data = NULL,
1337 .maxlen = sizeof(unsigned long),
1338 .mode = 0644,
1339 .proc_handler = hugetlb_sysctl_handler,
1341 #ifdef CONFIG_NUMA
1343 .procname = "nr_hugepages_mempolicy",
1344 .data = NULL,
1345 .maxlen = sizeof(unsigned long),
1346 .mode = 0644,
1347 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1349 #endif
1351 .procname = "hugetlb_shm_group",
1352 .data = &sysctl_hugetlb_shm_group,
1353 .maxlen = sizeof(gid_t),
1354 .mode = 0644,
1355 .proc_handler = proc_dointvec,
1358 .procname = "hugepages_treat_as_movable",
1359 .data = &hugepages_treat_as_movable,
1360 .maxlen = sizeof(int),
1361 .mode = 0644,
1362 .proc_handler = proc_dointvec,
1365 .procname = "nr_overcommit_hugepages",
1366 .data = NULL,
1367 .maxlen = sizeof(unsigned long),
1368 .mode = 0644,
1369 .proc_handler = hugetlb_overcommit_handler,
1371 #endif
1373 .procname = "lowmem_reserve_ratio",
1374 .data = &sysctl_lowmem_reserve_ratio,
1375 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1376 .mode = 0644,
1377 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1380 .procname = "drop_caches",
1381 .data = &sysctl_drop_caches,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
1384 .proc_handler = drop_caches_sysctl_handler,
1385 .extra1 = &one,
1386 .extra2 = &four,
1388 #ifdef CONFIG_COMPACTION
1390 .procname = "compact_memory",
1391 .data = &sysctl_compact_memory,
1392 .maxlen = sizeof(int),
1393 .mode = 0200,
1394 .proc_handler = sysctl_compaction_handler,
1397 .procname = "extfrag_threshold",
1398 .data = &sysctl_extfrag_threshold,
1399 .maxlen = sizeof(int),
1400 .mode = 0644,
1401 .proc_handler = sysctl_extfrag_handler,
1402 .extra1 = &min_extfrag_threshold,
1403 .extra2 = &max_extfrag_threshold,
1406 .procname = "compact_unevictable_allowed",
1407 .data = &sysctl_compact_unevictable_allowed,
1408 .maxlen = sizeof(int),
1409 .mode = 0644,
1410 .proc_handler = proc_dointvec,
1411 .extra1 = &zero,
1412 .extra2 = &one,
1415 #endif /* CONFIG_COMPACTION */
1417 .procname = "min_free_kbytes",
1418 .data = &min_free_kbytes,
1419 .maxlen = sizeof(min_free_kbytes),
1420 .mode = 0644,
1421 .proc_handler = min_free_kbytes_sysctl_handler,
1422 .extra1 = &zero,
1425 .procname = "watermark_scale_factor",
1426 .data = &watermark_scale_factor,
1427 .maxlen = sizeof(watermark_scale_factor),
1428 .mode = 0644,
1429 .proc_handler = watermark_scale_factor_sysctl_handler,
1430 .extra1 = &one,
1431 .extra2 = &one_thousand,
1434 .procname = "percpu_pagelist_fraction",
1435 .data = &percpu_pagelist_fraction,
1436 .maxlen = sizeof(percpu_pagelist_fraction),
1437 .mode = 0644,
1438 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1439 .extra1 = &zero,
1441 #ifdef CONFIG_MMU
1443 .procname = "max_map_count",
1444 .data = &sysctl_max_map_count,
1445 .maxlen = sizeof(sysctl_max_map_count),
1446 .mode = 0644,
1447 .proc_handler = proc_dointvec_minmax,
1448 .extra1 = &zero,
1450 #else
1452 .procname = "nr_trim_pages",
1453 .data = &sysctl_nr_trim_pages,
1454 .maxlen = sizeof(sysctl_nr_trim_pages),
1455 .mode = 0644,
1456 .proc_handler = proc_dointvec_minmax,
1457 .extra1 = &zero,
1459 #endif
1461 .procname = "laptop_mode",
1462 .data = &laptop_mode,
1463 .maxlen = sizeof(laptop_mode),
1464 .mode = 0644,
1465 .proc_handler = proc_dointvec_jiffies,
1468 .procname = "block_dump",
1469 .data = &block_dump,
1470 .maxlen = sizeof(block_dump),
1471 .mode = 0644,
1472 .proc_handler = proc_dointvec,
1473 .extra1 = &zero,
1476 .procname = "vfs_cache_pressure",
1477 .data = &sysctl_vfs_cache_pressure,
1478 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1479 .mode = 0644,
1480 .proc_handler = proc_dointvec,
1481 .extra1 = &zero,
1483 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1485 .procname = "legacy_va_layout",
1486 .data = &sysctl_legacy_va_layout,
1487 .maxlen = sizeof(sysctl_legacy_va_layout),
1488 .mode = 0644,
1489 .proc_handler = proc_dointvec,
1490 .extra1 = &zero,
1492 #endif
1493 #ifdef CONFIG_NUMA
1495 .procname = "zone_reclaim_mode",
1496 .data = &node_reclaim_mode,
1497 .maxlen = sizeof(node_reclaim_mode),
1498 .mode = 0644,
1499 .proc_handler = proc_dointvec,
1500 .extra1 = &zero,
1503 .procname = "min_unmapped_ratio",
1504 .data = &sysctl_min_unmapped_ratio,
1505 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1506 .mode = 0644,
1507 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1508 .extra1 = &zero,
1509 .extra2 = &one_hundred,
1512 .procname = "min_slab_ratio",
1513 .data = &sysctl_min_slab_ratio,
1514 .maxlen = sizeof(sysctl_min_slab_ratio),
1515 .mode = 0644,
1516 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1517 .extra1 = &zero,
1518 .extra2 = &one_hundred,
1520 #endif
1521 #ifdef CONFIG_SMP
1523 .procname = "stat_interval",
1524 .data = &sysctl_stat_interval,
1525 .maxlen = sizeof(sysctl_stat_interval),
1526 .mode = 0644,
1527 .proc_handler = proc_dointvec_jiffies,
1530 .procname = "stat_refresh",
1531 .data = NULL,
1532 .maxlen = 0,
1533 .mode = 0600,
1534 .proc_handler = vmstat_refresh,
1536 #endif
1537 #ifdef CONFIG_MMU
1539 .procname = "mmap_min_addr",
1540 .data = &dac_mmap_min_addr,
1541 .maxlen = sizeof(unsigned long),
1542 .mode = 0644,
1543 .proc_handler = mmap_min_addr_handler,
1545 #endif
1546 #ifdef CONFIG_NUMA
1548 .procname = "numa_zonelist_order",
1549 .data = &numa_zonelist_order,
1550 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1551 .mode = 0644,
1552 .proc_handler = numa_zonelist_order_handler,
1554 #endif
1555 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1556 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1558 .procname = "vdso_enabled",
1559 #ifdef CONFIG_X86_32
1560 .data = &vdso32_enabled,
1561 .maxlen = sizeof(vdso32_enabled),
1562 #else
1563 .data = &vdso_enabled,
1564 .maxlen = sizeof(vdso_enabled),
1565 #endif
1566 .mode = 0644,
1567 .proc_handler = proc_dointvec,
1568 .extra1 = &zero,
1570 #endif
1571 #ifdef CONFIG_HIGHMEM
1573 .procname = "highmem_is_dirtyable",
1574 .data = &vm_highmem_is_dirtyable,
1575 .maxlen = sizeof(vm_highmem_is_dirtyable),
1576 .mode = 0644,
1577 .proc_handler = proc_dointvec_minmax,
1578 .extra1 = &zero,
1579 .extra2 = &one,
1581 #endif
1582 #ifdef CONFIG_MEMORY_FAILURE
1584 .procname = "memory_failure_early_kill",
1585 .data = &sysctl_memory_failure_early_kill,
1586 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1587 .mode = 0644,
1588 .proc_handler = proc_dointvec_minmax,
1589 .extra1 = &zero,
1590 .extra2 = &one,
1593 .procname = "memory_failure_recovery",
1594 .data = &sysctl_memory_failure_recovery,
1595 .maxlen = sizeof(sysctl_memory_failure_recovery),
1596 .mode = 0644,
1597 .proc_handler = proc_dointvec_minmax,
1598 .extra1 = &zero,
1599 .extra2 = &one,
1601 #endif
1603 .procname = "user_reserve_kbytes",
1604 .data = &sysctl_user_reserve_kbytes,
1605 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1606 .mode = 0644,
1607 .proc_handler = proc_doulongvec_minmax,
1610 .procname = "admin_reserve_kbytes",
1611 .data = &sysctl_admin_reserve_kbytes,
1612 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1613 .mode = 0644,
1614 .proc_handler = proc_doulongvec_minmax,
1616 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1618 .procname = "mmap_rnd_bits",
1619 .data = &mmap_rnd_bits,
1620 .maxlen = sizeof(mmap_rnd_bits),
1621 .mode = 0600,
1622 .proc_handler = proc_dointvec_minmax,
1623 .extra1 = (void *)&mmap_rnd_bits_min,
1624 .extra2 = (void *)&mmap_rnd_bits_max,
1626 #endif
1627 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1629 .procname = "mmap_rnd_compat_bits",
1630 .data = &mmap_rnd_compat_bits,
1631 .maxlen = sizeof(mmap_rnd_compat_bits),
1632 .mode = 0600,
1633 .proc_handler = proc_dointvec_minmax,
1634 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1635 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1637 #endif
1641 static struct ctl_table fs_table[] = {
1643 .procname = "inode-nr",
1644 .data = &inodes_stat,
1645 .maxlen = 2*sizeof(long),
1646 .mode = 0444,
1647 .proc_handler = proc_nr_inodes,
1650 .procname = "inode-state",
1651 .data = &inodes_stat,
1652 .maxlen = 7*sizeof(long),
1653 .mode = 0444,
1654 .proc_handler = proc_nr_inodes,
1657 .procname = "file-nr",
1658 .data = &files_stat,
1659 .maxlen = sizeof(files_stat),
1660 .mode = 0444,
1661 .proc_handler = proc_nr_files,
1664 .procname = "file-max",
1665 .data = &files_stat.max_files,
1666 .maxlen = sizeof(files_stat.max_files),
1667 .mode = 0644,
1668 .proc_handler = proc_doulongvec_minmax,
1671 .procname = "nr_open",
1672 .data = &sysctl_nr_open,
1673 .maxlen = sizeof(unsigned int),
1674 .mode = 0644,
1675 .proc_handler = proc_dointvec_minmax,
1676 .extra1 = &sysctl_nr_open_min,
1677 .extra2 = &sysctl_nr_open_max,
1680 .procname = "dentry-state",
1681 .data = &dentry_stat,
1682 .maxlen = 6*sizeof(long),
1683 .mode = 0444,
1684 .proc_handler = proc_nr_dentry,
1687 .procname = "overflowuid",
1688 .data = &fs_overflowuid,
1689 .maxlen = sizeof(int),
1690 .mode = 0644,
1691 .proc_handler = proc_dointvec_minmax,
1692 .extra1 = &minolduid,
1693 .extra2 = &maxolduid,
1696 .procname = "overflowgid",
1697 .data = &fs_overflowgid,
1698 .maxlen = sizeof(int),
1699 .mode = 0644,
1700 .proc_handler = proc_dointvec_minmax,
1701 .extra1 = &minolduid,
1702 .extra2 = &maxolduid,
1704 #ifdef CONFIG_FILE_LOCKING
1706 .procname = "leases-enable",
1707 .data = &leases_enable,
1708 .maxlen = sizeof(int),
1709 .mode = 0644,
1710 .proc_handler = proc_dointvec,
1712 #endif
1713 #ifdef CONFIG_DNOTIFY
1715 .procname = "dir-notify-enable",
1716 .data = &dir_notify_enable,
1717 .maxlen = sizeof(int),
1718 .mode = 0644,
1719 .proc_handler = proc_dointvec,
1721 #endif
1722 #ifdef CONFIG_MMU
1723 #ifdef CONFIG_FILE_LOCKING
1725 .procname = "lease-break-time",
1726 .data = &lease_break_time,
1727 .maxlen = sizeof(int),
1728 .mode = 0644,
1729 .proc_handler = proc_dointvec,
1731 #endif
1732 #ifdef CONFIG_AIO
1734 .procname = "aio-nr",
1735 .data = &aio_nr,
1736 .maxlen = sizeof(aio_nr),
1737 .mode = 0444,
1738 .proc_handler = proc_doulongvec_minmax,
1741 .procname = "aio-max-nr",
1742 .data = &aio_max_nr,
1743 .maxlen = sizeof(aio_max_nr),
1744 .mode = 0644,
1745 .proc_handler = proc_doulongvec_minmax,
1747 #endif /* CONFIG_AIO */
1748 #ifdef CONFIG_INOTIFY_USER
1750 .procname = "inotify",
1751 .mode = 0555,
1752 .child = inotify_table,
1754 #endif
1755 #ifdef CONFIG_EPOLL
1757 .procname = "epoll",
1758 .mode = 0555,
1759 .child = epoll_table,
1761 #endif
1762 #endif
1764 .procname = "protected_symlinks",
1765 .data = &sysctl_protected_symlinks,
1766 .maxlen = sizeof(int),
1767 .mode = 0600,
1768 .proc_handler = proc_dointvec_minmax,
1769 .extra1 = &zero,
1770 .extra2 = &one,
1773 .procname = "protected_hardlinks",
1774 .data = &sysctl_protected_hardlinks,
1775 .maxlen = sizeof(int),
1776 .mode = 0600,
1777 .proc_handler = proc_dointvec_minmax,
1778 .extra1 = &zero,
1779 .extra2 = &one,
1782 .procname = "suid_dumpable",
1783 .data = &suid_dumpable,
1784 .maxlen = sizeof(int),
1785 .mode = 0644,
1786 .proc_handler = proc_dointvec_minmax_coredump,
1787 .extra1 = &zero,
1788 .extra2 = &two,
1790 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1792 .procname = "binfmt_misc",
1793 .mode = 0555,
1794 .child = sysctl_mount_point,
1796 #endif
1798 .procname = "pipe-max-size",
1799 .data = &pipe_max_size,
1800 .maxlen = sizeof(int),
1801 .mode = 0644,
1802 .proc_handler = &pipe_proc_fn,
1803 .extra1 = &pipe_min_size,
1806 .procname = "pipe-user-pages-hard",
1807 .data = &pipe_user_pages_hard,
1808 .maxlen = sizeof(pipe_user_pages_hard),
1809 .mode = 0644,
1810 .proc_handler = proc_doulongvec_minmax,
1813 .procname = "pipe-user-pages-soft",
1814 .data = &pipe_user_pages_soft,
1815 .maxlen = sizeof(pipe_user_pages_soft),
1816 .mode = 0644,
1817 .proc_handler = proc_doulongvec_minmax,
1820 .procname = "mount-max",
1821 .data = &sysctl_mount_max,
1822 .maxlen = sizeof(unsigned int),
1823 .mode = 0644,
1824 .proc_handler = proc_dointvec_minmax,
1825 .extra1 = &one,
1830 static struct ctl_table debug_table[] = {
1831 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1833 .procname = "exception-trace",
1834 .data = &show_unhandled_signals,
1835 .maxlen = sizeof(int),
1836 .mode = 0644,
1837 .proc_handler = proc_dointvec
1839 #endif
1840 #if defined(CONFIG_OPTPROBES)
1842 .procname = "kprobes-optimization",
1843 .data = &sysctl_kprobes_optimization,
1844 .maxlen = sizeof(int),
1845 .mode = 0644,
1846 .proc_handler = proc_kprobes_optimization_handler,
1847 .extra1 = &zero,
1848 .extra2 = &one,
1850 #endif
1854 static struct ctl_table dev_table[] = {
1858 int __init sysctl_init(void)
1860 struct ctl_table_header *hdr;
1862 hdr = register_sysctl_table(sysctl_base_table);
1863 kmemleak_not_leak(hdr);
1864 return 0;
1867 #endif /* CONFIG_SYSCTL */
1870 * /proc/sys support
1873 #ifdef CONFIG_PROC_SYSCTL
1875 static int _proc_do_string(char *data, int maxlen, int write,
1876 char __user *buffer,
1877 size_t *lenp, loff_t *ppos)
1879 size_t len;
1880 char __user *p;
1881 char c;
1883 if (!data || !maxlen || !*lenp) {
1884 *lenp = 0;
1885 return 0;
1888 if (write) {
1889 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1890 /* Only continue writes not past the end of buffer. */
1891 len = strlen(data);
1892 if (len > maxlen - 1)
1893 len = maxlen - 1;
1895 if (*ppos > len)
1896 return 0;
1897 len = *ppos;
1898 } else {
1899 /* Start writing from beginning of buffer. */
1900 len = 0;
1903 *ppos += *lenp;
1904 p = buffer;
1905 while ((p - buffer) < *lenp && len < maxlen - 1) {
1906 if (get_user(c, p++))
1907 return -EFAULT;
1908 if (c == 0 || c == '\n')
1909 break;
1910 data[len++] = c;
1912 data[len] = 0;
1913 } else {
1914 len = strlen(data);
1915 if (len > maxlen)
1916 len = maxlen;
1918 if (*ppos > len) {
1919 *lenp = 0;
1920 return 0;
1923 data += *ppos;
1924 len -= *ppos;
1926 if (len > *lenp)
1927 len = *lenp;
1928 if (len)
1929 if (copy_to_user(buffer, data, len))
1930 return -EFAULT;
1931 if (len < *lenp) {
1932 if (put_user('\n', buffer + len))
1933 return -EFAULT;
1934 len++;
1936 *lenp = len;
1937 *ppos += len;
1939 return 0;
1942 static void warn_sysctl_write(struct ctl_table *table)
1944 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1945 "This will not be supported in the future. To silence this\n"
1946 "warning, set kernel.sysctl_writes_strict = -1\n",
1947 current->comm, table->procname);
1951 * proc_dostring - read a string sysctl
1952 * @table: the sysctl table
1953 * @write: %TRUE if this is a write to the sysctl file
1954 * @buffer: the user buffer
1955 * @lenp: the size of the user buffer
1956 * @ppos: file position
1958 * Reads/writes a string from/to the user buffer. If the kernel
1959 * buffer provided is not large enough to hold the string, the
1960 * string is truncated. The copied string is %NULL-terminated.
1961 * If the string is being read by the user process, it is copied
1962 * and a newline '\n' is added. It is truncated if the buffer is
1963 * not large enough.
1965 * Returns 0 on success.
1967 int proc_dostring(struct ctl_table *table, int write,
1968 void __user *buffer, size_t *lenp, loff_t *ppos)
1970 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1971 warn_sysctl_write(table);
1973 return _proc_do_string((char *)(table->data), table->maxlen, write,
1974 (char __user *)buffer, lenp, ppos);
1977 static size_t proc_skip_spaces(char **buf)
1979 size_t ret;
1980 char *tmp = skip_spaces(*buf);
1981 ret = tmp - *buf;
1982 *buf = tmp;
1983 return ret;
1986 static void proc_skip_char(char **buf, size_t *size, const char v)
1988 while (*size) {
1989 if (**buf != v)
1990 break;
1991 (*size)--;
1992 (*buf)++;
1996 #define TMPBUFLEN 22
1998 * proc_get_long - reads an ASCII formatted integer from a user buffer
2000 * @buf: a kernel buffer
2001 * @size: size of the kernel buffer
2002 * @val: this is where the number will be stored
2003 * @neg: set to %TRUE if number is negative
2004 * @perm_tr: a vector which contains the allowed trailers
2005 * @perm_tr_len: size of the perm_tr vector
2006 * @tr: pointer to store the trailer character
2008 * In case of success %0 is returned and @buf and @size are updated with
2009 * the amount of bytes read. If @tr is non-NULL and a trailing
2010 * character exists (size is non-zero after returning from this
2011 * function), @tr is updated with the trailing character.
2013 static int proc_get_long(char **buf, size_t *size,
2014 unsigned long *val, bool *neg,
2015 const char *perm_tr, unsigned perm_tr_len, char *tr)
2017 int len;
2018 char *p, tmp[TMPBUFLEN];
2020 if (!*size)
2021 return -EINVAL;
2023 len = *size;
2024 if (len > TMPBUFLEN - 1)
2025 len = TMPBUFLEN - 1;
2027 memcpy(tmp, *buf, len);
2029 tmp[len] = 0;
2030 p = tmp;
2031 if (*p == '-' && *size > 1) {
2032 *neg = true;
2033 p++;
2034 } else
2035 *neg = false;
2036 if (!isdigit(*p))
2037 return -EINVAL;
2039 *val = simple_strtoul(p, &p, 0);
2041 len = p - tmp;
2043 /* We don't know if the next char is whitespace thus we may accept
2044 * invalid integers (e.g. 1234...a) or two integers instead of one
2045 * (e.g. 123...1). So lets not allow such large numbers. */
2046 if (len == TMPBUFLEN - 1)
2047 return -EINVAL;
2049 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2050 return -EINVAL;
2052 if (tr && (len < *size))
2053 *tr = *p;
2055 *buf += len;
2056 *size -= len;
2058 return 0;
2062 * proc_put_long - converts an integer to a decimal ASCII formatted string
2064 * @buf: the user buffer
2065 * @size: the size of the user buffer
2066 * @val: the integer to be converted
2067 * @neg: sign of the number, %TRUE for negative
2069 * In case of success %0 is returned and @buf and @size are updated with
2070 * the amount of bytes written.
2072 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2073 bool neg)
2075 int len;
2076 char tmp[TMPBUFLEN], *p = tmp;
2078 sprintf(p, "%s%lu", neg ? "-" : "", val);
2079 len = strlen(tmp);
2080 if (len > *size)
2081 len = *size;
2082 if (copy_to_user(*buf, tmp, len))
2083 return -EFAULT;
2084 *size -= len;
2085 *buf += len;
2086 return 0;
2088 #undef TMPBUFLEN
2090 static int proc_put_char(void __user **buf, size_t *size, char c)
2092 if (*size) {
2093 char __user **buffer = (char __user **)buf;
2094 if (put_user(c, *buffer))
2095 return -EFAULT;
2096 (*size)--, (*buffer)++;
2097 *buf = *buffer;
2099 return 0;
2102 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2103 int *valp,
2104 int write, void *data)
2106 if (write) {
2107 if (*negp) {
2108 if (*lvalp > (unsigned long) INT_MAX + 1)
2109 return -EINVAL;
2110 *valp = -*lvalp;
2111 } else {
2112 if (*lvalp > (unsigned long) INT_MAX)
2113 return -EINVAL;
2114 *valp = *lvalp;
2116 } else {
2117 int val = *valp;
2118 if (val < 0) {
2119 *negp = true;
2120 *lvalp = -(unsigned long)val;
2121 } else {
2122 *negp = false;
2123 *lvalp = (unsigned long)val;
2126 return 0;
2129 static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2130 int *valp,
2131 int write, void *data)
2133 if (write) {
2134 if (*negp)
2135 return -EINVAL;
2136 if (*lvalp > UINT_MAX)
2137 return -EINVAL;
2138 *valp = *lvalp;
2139 } else {
2140 unsigned int val = *valp;
2141 *negp = false;
2142 *lvalp = (unsigned long)val;
2144 return 0;
2147 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2149 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2150 int write, void __user *buffer,
2151 size_t *lenp, loff_t *ppos,
2152 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2153 int write, void *data),
2154 void *data)
2156 int *i, vleft, first = 1, err = 0;
2157 size_t left;
2158 char *kbuf = NULL, *p;
2160 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2161 *lenp = 0;
2162 return 0;
2165 i = (int *) tbl_data;
2166 vleft = table->maxlen / sizeof(*i);
2167 left = *lenp;
2169 if (!conv)
2170 conv = do_proc_dointvec_conv;
2172 if (write) {
2173 if (*ppos) {
2174 switch (sysctl_writes_strict) {
2175 case SYSCTL_WRITES_STRICT:
2176 goto out;
2177 case SYSCTL_WRITES_WARN:
2178 warn_sysctl_write(table);
2179 break;
2180 default:
2181 break;
2185 if (left > PAGE_SIZE - 1)
2186 left = PAGE_SIZE - 1;
2187 p = kbuf = memdup_user_nul(buffer, left);
2188 if (IS_ERR(kbuf))
2189 return PTR_ERR(kbuf);
2192 for (; left && vleft--; i++, first=0) {
2193 unsigned long lval;
2194 bool neg;
2196 if (write) {
2197 left -= proc_skip_spaces(&p);
2199 if (!left)
2200 break;
2201 err = proc_get_long(&p, &left, &lval, &neg,
2202 proc_wspace_sep,
2203 sizeof(proc_wspace_sep), NULL);
2204 if (err)
2205 break;
2206 if (conv(&neg, &lval, i, 1, data)) {
2207 err = -EINVAL;
2208 break;
2210 } else {
2211 if (conv(&neg, &lval, i, 0, data)) {
2212 err = -EINVAL;
2213 break;
2215 if (!first)
2216 err = proc_put_char(&buffer, &left, '\t');
2217 if (err)
2218 break;
2219 err = proc_put_long(&buffer, &left, lval, neg);
2220 if (err)
2221 break;
2225 if (!write && !first && left && !err)
2226 err = proc_put_char(&buffer, &left, '\n');
2227 if (write && !err && left)
2228 left -= proc_skip_spaces(&p);
2229 if (write) {
2230 kfree(kbuf);
2231 if (first)
2232 return err ? : -EINVAL;
2234 *lenp -= left;
2235 out:
2236 *ppos += *lenp;
2237 return err;
2240 static int do_proc_dointvec(struct ctl_table *table, int write,
2241 void __user *buffer, size_t *lenp, loff_t *ppos,
2242 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2243 int write, void *data),
2244 void *data)
2246 return __do_proc_dointvec(table->data, table, write,
2247 buffer, lenp, ppos, conv, data);
2251 * proc_dointvec - read a vector of integers
2252 * @table: the sysctl table
2253 * @write: %TRUE if this is a write to the sysctl file
2254 * @buffer: the user buffer
2255 * @lenp: the size of the user buffer
2256 * @ppos: file position
2258 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2259 * values from/to the user buffer, treated as an ASCII string.
2261 * Returns 0 on success.
2263 int proc_dointvec(struct ctl_table *table, int write,
2264 void __user *buffer, size_t *lenp, loff_t *ppos)
2266 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2270 * proc_douintvec - read a vector of unsigned integers
2271 * @table: the sysctl table
2272 * @write: %TRUE if this is a write to the sysctl file
2273 * @buffer: the user buffer
2274 * @lenp: the size of the user buffer
2275 * @ppos: file position
2277 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2278 * values from/to the user buffer, treated as an ASCII string.
2280 * Returns 0 on success.
2282 int proc_douintvec(struct ctl_table *table, int write,
2283 void __user *buffer, size_t *lenp, loff_t *ppos)
2285 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2286 do_proc_douintvec_conv, NULL);
2290 * Taint values can only be increased
2291 * This means we can safely use a temporary.
2293 static int proc_taint(struct ctl_table *table, int write,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2296 struct ctl_table t;
2297 unsigned long tmptaint = get_taint();
2298 int err;
2300 if (write && !capable(CAP_SYS_ADMIN))
2301 return -EPERM;
2303 t = *table;
2304 t.data = &tmptaint;
2305 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2306 if (err < 0)
2307 return err;
2309 if (write) {
2311 * Poor man's atomic or. Not worth adding a primitive
2312 * to everyone's atomic.h for this
2314 int i;
2315 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2316 if ((tmptaint >> i) & 1)
2317 add_taint(i, LOCKDEP_STILL_OK);
2321 return err;
2324 #ifdef CONFIG_PRINTK
2325 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2326 void __user *buffer, size_t *lenp, loff_t *ppos)
2328 if (write && !capable(CAP_SYS_ADMIN))
2329 return -EPERM;
2331 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2333 #endif
2335 struct do_proc_dointvec_minmax_conv_param {
2336 int *min;
2337 int *max;
2340 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2341 int *valp,
2342 int write, void *data)
2344 struct do_proc_dointvec_minmax_conv_param *param = data;
2345 if (write) {
2346 int val = *negp ? -*lvalp : *lvalp;
2347 if ((param->min && *param->min > val) ||
2348 (param->max && *param->max < val))
2349 return -EINVAL;
2350 *valp = val;
2351 } else {
2352 int val = *valp;
2353 if (val < 0) {
2354 *negp = true;
2355 *lvalp = -(unsigned long)val;
2356 } else {
2357 *negp = false;
2358 *lvalp = (unsigned long)val;
2361 return 0;
2365 * proc_dointvec_minmax - read a vector of integers with min/max values
2366 * @table: the sysctl table
2367 * @write: %TRUE if this is a write to the sysctl file
2368 * @buffer: the user buffer
2369 * @lenp: the size of the user buffer
2370 * @ppos: file position
2372 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2373 * values from/to the user buffer, treated as an ASCII string.
2375 * This routine will ensure the values are within the range specified by
2376 * table->extra1 (min) and table->extra2 (max).
2378 * Returns 0 on success.
2380 int proc_dointvec_minmax(struct ctl_table *table, int write,
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2383 struct do_proc_dointvec_minmax_conv_param param = {
2384 .min = (int *) table->extra1,
2385 .max = (int *) table->extra2,
2387 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2388 do_proc_dointvec_minmax_conv, &param);
2391 static void validate_coredump_safety(void)
2393 #ifdef CONFIG_COREDUMP
2394 if (suid_dumpable == SUID_DUMP_ROOT &&
2395 core_pattern[0] != '/' && core_pattern[0] != '|') {
2396 printk(KERN_WARNING
2397 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2398 "Pipe handler or fully qualified core dump path required.\n"
2399 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2402 #endif
2405 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2406 void __user *buffer, size_t *lenp, loff_t *ppos)
2408 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2409 if (!error)
2410 validate_coredump_safety();
2411 return error;
2414 #ifdef CONFIG_COREDUMP
2415 static int proc_dostring_coredump(struct ctl_table *table, int write,
2416 void __user *buffer, size_t *lenp, loff_t *ppos)
2418 int error = proc_dostring(table, write, buffer, lenp, ppos);
2419 if (!error)
2420 validate_coredump_safety();
2421 return error;
2423 #endif
2425 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2426 void __user *buffer,
2427 size_t *lenp, loff_t *ppos,
2428 unsigned long convmul,
2429 unsigned long convdiv)
2431 unsigned long *i, *min, *max;
2432 int vleft, first = 1, err = 0;
2433 size_t left;
2434 char *kbuf = NULL, *p;
2436 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2437 *lenp = 0;
2438 return 0;
2441 i = (unsigned long *) data;
2442 min = (unsigned long *) table->extra1;
2443 max = (unsigned long *) table->extra2;
2444 vleft = table->maxlen / sizeof(unsigned long);
2445 left = *lenp;
2447 if (write) {
2448 if (*ppos) {
2449 switch (sysctl_writes_strict) {
2450 case SYSCTL_WRITES_STRICT:
2451 goto out;
2452 case SYSCTL_WRITES_WARN:
2453 warn_sysctl_write(table);
2454 break;
2455 default:
2456 break;
2460 if (left > PAGE_SIZE - 1)
2461 left = PAGE_SIZE - 1;
2462 p = kbuf = memdup_user_nul(buffer, left);
2463 if (IS_ERR(kbuf))
2464 return PTR_ERR(kbuf);
2467 for (; left && vleft--; i++, first = 0) {
2468 unsigned long val;
2470 if (write) {
2471 bool neg;
2473 left -= proc_skip_spaces(&p);
2475 err = proc_get_long(&p, &left, &val, &neg,
2476 proc_wspace_sep,
2477 sizeof(proc_wspace_sep), NULL);
2478 if (err)
2479 break;
2480 if (neg)
2481 continue;
2482 val = convmul * val / convdiv;
2483 if ((min && val < *min) || (max && val > *max))
2484 continue;
2485 *i = val;
2486 } else {
2487 val = convdiv * (*i) / convmul;
2488 if (!first) {
2489 err = proc_put_char(&buffer, &left, '\t');
2490 if (err)
2491 break;
2493 err = proc_put_long(&buffer, &left, val, false);
2494 if (err)
2495 break;
2499 if (!write && !first && left && !err)
2500 err = proc_put_char(&buffer, &left, '\n');
2501 if (write && !err)
2502 left -= proc_skip_spaces(&p);
2503 if (write) {
2504 kfree(kbuf);
2505 if (first)
2506 return err ? : -EINVAL;
2508 *lenp -= left;
2509 out:
2510 *ppos += *lenp;
2511 return err;
2514 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2515 void __user *buffer,
2516 size_t *lenp, loff_t *ppos,
2517 unsigned long convmul,
2518 unsigned long convdiv)
2520 return __do_proc_doulongvec_minmax(table->data, table, write,
2521 buffer, lenp, ppos, convmul, convdiv);
2525 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2526 * @table: the sysctl table
2527 * @write: %TRUE if this is a write to the sysctl file
2528 * @buffer: the user buffer
2529 * @lenp: the size of the user buffer
2530 * @ppos: file position
2532 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2533 * values from/to the user buffer, treated as an ASCII string.
2535 * This routine will ensure the values are within the range specified by
2536 * table->extra1 (min) and table->extra2 (max).
2538 * Returns 0 on success.
2540 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2541 void __user *buffer, size_t *lenp, loff_t *ppos)
2543 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2547 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2548 * @table: the sysctl table
2549 * @write: %TRUE if this is a write to the sysctl file
2550 * @buffer: the user buffer
2551 * @lenp: the size of the user buffer
2552 * @ppos: file position
2554 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2555 * values from/to the user buffer, treated as an ASCII string. The values
2556 * are treated as milliseconds, and converted to jiffies when they are stored.
2558 * This routine will ensure the values are within the range specified by
2559 * table->extra1 (min) and table->extra2 (max).
2561 * Returns 0 on success.
2563 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2564 void __user *buffer,
2565 size_t *lenp, loff_t *ppos)
2567 return do_proc_doulongvec_minmax(table, write, buffer,
2568 lenp, ppos, HZ, 1000l);
2572 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2573 int *valp,
2574 int write, void *data)
2576 if (write) {
2577 if (*lvalp > LONG_MAX / HZ)
2578 return 1;
2579 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2580 } else {
2581 int val = *valp;
2582 unsigned long lval;
2583 if (val < 0) {
2584 *negp = true;
2585 lval = -(unsigned long)val;
2586 } else {
2587 *negp = false;
2588 lval = (unsigned long)val;
2590 *lvalp = lval / HZ;
2592 return 0;
2595 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2596 int *valp,
2597 int write, void *data)
2599 if (write) {
2600 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2601 return 1;
2602 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2603 } else {
2604 int val = *valp;
2605 unsigned long lval;
2606 if (val < 0) {
2607 *negp = true;
2608 lval = -(unsigned long)val;
2609 } else {
2610 *negp = false;
2611 lval = (unsigned long)val;
2613 *lvalp = jiffies_to_clock_t(lval);
2615 return 0;
2618 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2619 int *valp,
2620 int write, void *data)
2622 if (write) {
2623 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2625 if (jif > INT_MAX)
2626 return 1;
2627 *valp = (int)jif;
2628 } else {
2629 int val = *valp;
2630 unsigned long lval;
2631 if (val < 0) {
2632 *negp = true;
2633 lval = -(unsigned long)val;
2634 } else {
2635 *negp = false;
2636 lval = (unsigned long)val;
2638 *lvalp = jiffies_to_msecs(lval);
2640 return 0;
2644 * proc_dointvec_jiffies - read a vector of integers as seconds
2645 * @table: the sysctl table
2646 * @write: %TRUE if this is a write to the sysctl file
2647 * @buffer: the user buffer
2648 * @lenp: the size of the user buffer
2649 * @ppos: file position
2651 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2652 * values from/to the user buffer, treated as an ASCII string.
2653 * The values read are assumed to be in seconds, and are converted into
2654 * jiffies.
2656 * Returns 0 on success.
2658 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2659 void __user *buffer, size_t *lenp, loff_t *ppos)
2661 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2662 do_proc_dointvec_jiffies_conv,NULL);
2666 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2667 * @table: the sysctl table
2668 * @write: %TRUE if this is a write to the sysctl file
2669 * @buffer: the user buffer
2670 * @lenp: the size of the user buffer
2671 * @ppos: pointer to the file position
2673 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2674 * values from/to the user buffer, treated as an ASCII string.
2675 * The values read are assumed to be in 1/USER_HZ seconds, and
2676 * are converted into jiffies.
2678 * Returns 0 on success.
2680 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2681 void __user *buffer, size_t *lenp, loff_t *ppos)
2683 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2684 do_proc_dointvec_userhz_jiffies_conv,NULL);
2688 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2689 * @table: the sysctl table
2690 * @write: %TRUE if this is a write to the sysctl file
2691 * @buffer: the user buffer
2692 * @lenp: the size of the user buffer
2693 * @ppos: file position
2694 * @ppos: the current position in the file
2696 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2697 * values from/to the user buffer, treated as an ASCII string.
2698 * The values read are assumed to be in 1/1000 seconds, and
2699 * are converted into jiffies.
2701 * Returns 0 on success.
2703 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2704 void __user *buffer, size_t *lenp, loff_t *ppos)
2706 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2707 do_proc_dointvec_ms_jiffies_conv, NULL);
2710 static int proc_do_cad_pid(struct ctl_table *table, int write,
2711 void __user *buffer, size_t *lenp, loff_t *ppos)
2713 struct pid *new_pid;
2714 pid_t tmp;
2715 int r;
2717 tmp = pid_vnr(cad_pid);
2719 r = __do_proc_dointvec(&tmp, table, write, buffer,
2720 lenp, ppos, NULL, NULL);
2721 if (r || !write)
2722 return r;
2724 new_pid = find_get_pid(tmp);
2725 if (!new_pid)
2726 return -ESRCH;
2728 put_pid(xchg(&cad_pid, new_pid));
2729 return 0;
2733 * proc_do_large_bitmap - read/write from/to a large bitmap
2734 * @table: the sysctl table
2735 * @write: %TRUE if this is a write to the sysctl file
2736 * @buffer: the user buffer
2737 * @lenp: the size of the user buffer
2738 * @ppos: file position
2740 * The bitmap is stored at table->data and the bitmap length (in bits)
2741 * in table->maxlen.
2743 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2744 * large bitmaps may be represented in a compact manner. Writing into
2745 * the file will clear the bitmap then update it with the given input.
2747 * Returns 0 on success.
2749 int proc_do_large_bitmap(struct ctl_table *table, int write,
2750 void __user *buffer, size_t *lenp, loff_t *ppos)
2752 int err = 0;
2753 bool first = 1;
2754 size_t left = *lenp;
2755 unsigned long bitmap_len = table->maxlen;
2756 unsigned long *bitmap = *(unsigned long **) table->data;
2757 unsigned long *tmp_bitmap = NULL;
2758 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2760 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2761 *lenp = 0;
2762 return 0;
2765 if (write) {
2766 char *kbuf, *p;
2768 if (left > PAGE_SIZE - 1)
2769 left = PAGE_SIZE - 1;
2771 p = kbuf = memdup_user_nul(buffer, left);
2772 if (IS_ERR(kbuf))
2773 return PTR_ERR(kbuf);
2775 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2776 GFP_KERNEL);
2777 if (!tmp_bitmap) {
2778 kfree(kbuf);
2779 return -ENOMEM;
2781 proc_skip_char(&p, &left, '\n');
2782 while (!err && left) {
2783 unsigned long val_a, val_b;
2784 bool neg;
2786 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
2787 sizeof(tr_a), &c);
2788 if (err)
2789 break;
2790 if (val_a >= bitmap_len || neg) {
2791 err = -EINVAL;
2792 break;
2795 val_b = val_a;
2796 if (left) {
2797 p++;
2798 left--;
2801 if (c == '-') {
2802 err = proc_get_long(&p, &left, &val_b,
2803 &neg, tr_b, sizeof(tr_b),
2804 &c);
2805 if (err)
2806 break;
2807 if (val_b >= bitmap_len || neg ||
2808 val_a > val_b) {
2809 err = -EINVAL;
2810 break;
2812 if (left) {
2813 p++;
2814 left--;
2818 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2819 first = 0;
2820 proc_skip_char(&p, &left, '\n');
2822 kfree(kbuf);
2823 } else {
2824 unsigned long bit_a, bit_b = 0;
2826 while (left) {
2827 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2828 if (bit_a >= bitmap_len)
2829 break;
2830 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2831 bit_a + 1) - 1;
2833 if (!first) {
2834 err = proc_put_char(&buffer, &left, ',');
2835 if (err)
2836 break;
2838 err = proc_put_long(&buffer, &left, bit_a, false);
2839 if (err)
2840 break;
2841 if (bit_a != bit_b) {
2842 err = proc_put_char(&buffer, &left, '-');
2843 if (err)
2844 break;
2845 err = proc_put_long(&buffer, &left, bit_b, false);
2846 if (err)
2847 break;
2850 first = 0; bit_b++;
2852 if (!err)
2853 err = proc_put_char(&buffer, &left, '\n');
2856 if (!err) {
2857 if (write) {
2858 if (*ppos)
2859 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2860 else
2861 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2863 kfree(tmp_bitmap);
2864 *lenp -= left;
2865 *ppos += *lenp;
2866 return 0;
2867 } else {
2868 kfree(tmp_bitmap);
2869 return err;
2873 #else /* CONFIG_PROC_SYSCTL */
2875 int proc_dostring(struct ctl_table *table, int write,
2876 void __user *buffer, size_t *lenp, loff_t *ppos)
2878 return -ENOSYS;
2881 int proc_dointvec(struct ctl_table *table, int write,
2882 void __user *buffer, size_t *lenp, loff_t *ppos)
2884 return -ENOSYS;
2887 int proc_douintvec(struct ctl_table *table, int write,
2888 void __user *buffer, size_t *lenp, loff_t *ppos)
2890 return -ENOSYS;
2893 int proc_dointvec_minmax(struct ctl_table *table, int write,
2894 void __user *buffer, size_t *lenp, loff_t *ppos)
2896 return -ENOSYS;
2899 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2900 void __user *buffer, size_t *lenp, loff_t *ppos)
2902 return -ENOSYS;
2905 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2906 void __user *buffer, size_t *lenp, loff_t *ppos)
2908 return -ENOSYS;
2911 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2912 void __user *buffer, size_t *lenp, loff_t *ppos)
2914 return -ENOSYS;
2917 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2918 void __user *buffer, size_t *lenp, loff_t *ppos)
2920 return -ENOSYS;
2923 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2924 void __user *buffer,
2925 size_t *lenp, loff_t *ppos)
2927 return -ENOSYS;
2931 #endif /* CONFIG_PROC_SYSCTL */
2934 * No sense putting this after each symbol definition, twice,
2935 * exception granted :-)
2937 EXPORT_SYMBOL(proc_dointvec);
2938 EXPORT_SYMBOL(proc_douintvec);
2939 EXPORT_SYMBOL(proc_dointvec_jiffies);
2940 EXPORT_SYMBOL(proc_dointvec_minmax);
2941 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2942 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2943 EXPORT_SYMBOL(proc_dostring);
2944 EXPORT_SYMBOL(proc_doulongvec_minmax);
2945 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);