Btrfs: bail out if block group has different mixed flag
[linux/fpc-iii.git] / kernel / sysctl.c
bloba13bbdaab47dc66fec2c0dd3da0b2c9898725bdf
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/kexec.h>
67 #include <linux/bpf.h>
69 #include <asm/uaccess.h>
70 #include <asm/processor.h>
72 #ifdef CONFIG_X86
73 #include <asm/nmi.h>
74 #include <asm/stacktrace.h>
75 #include <asm/io.h>
76 #endif
77 #ifdef CONFIG_SPARC
78 #include <asm/setup.h>
79 #endif
80 #ifdef CONFIG_BSD_PROCESS_ACCT
81 #include <linux/acct.h>
82 #endif
83 #ifdef CONFIG_RT_MUTEXES
84 #include <linux/rtmutex.h>
85 #endif
86 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
87 #include <linux/lockdep.h>
88 #endif
89 #ifdef CONFIG_CHR_DEV_SG
90 #include <scsi/sg.h>
91 #endif
93 #ifdef CONFIG_LOCKUP_DETECTOR
94 #include <linux/nmi.h>
95 #endif
97 #if defined(CONFIG_SYSCTL)
99 /* External variables not in a header file. */
100 extern int suid_dumpable;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid;
103 extern char core_pattern[];
104 extern unsigned int core_pipe_limit;
105 #endif
106 extern int pid_max;
107 extern int pid_max_min, pid_max_max;
108 extern int percpu_pagelist_fraction;
109 extern int compat_log;
110 extern int latencytop_enabled;
111 extern int sysctl_nr_open_min, sysctl_nr_open_max;
112 #ifndef CONFIG_MMU
113 extern int sysctl_nr_trim_pages;
114 #endif
116 /* Constants used for minimum and maximum */
117 #ifdef CONFIG_LOCKUP_DETECTOR
118 static int sixty = 60;
119 #endif
121 static int __maybe_unused neg_one = -1;
123 static int zero;
124 static int __maybe_unused one = 1;
125 static int __maybe_unused two = 2;
126 static int __maybe_unused four = 4;
127 static unsigned long one_ul = 1;
128 static int one_hundred = 100;
129 static int one_thousand = 1000;
130 #ifdef CONFIG_PRINTK
131 static int ten_thousand = 10000;
132 #endif
133 #ifdef CONFIG_PERF_EVENTS
134 static int six_hundred_forty_kb = 640 * 1024;
135 #endif
137 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141 static int maxolduid = 65535;
142 static int minolduid;
144 static int ngroups_max = NGROUPS_MAX;
145 static const int cap_last_cap = CAP_LAST_CAP;
147 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
148 #ifdef CONFIG_DETECT_HUNG_TASK
149 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
150 #endif
152 #ifdef CONFIG_INOTIFY_USER
153 #include <linux/inotify.h>
154 #endif
155 #ifdef CONFIG_SPARC
156 #endif
158 #ifdef __hppa__
159 extern int pwrsw_enabled;
160 #endif
162 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
163 extern int unaligned_enabled;
164 #endif
166 #ifdef CONFIG_IA64
167 extern int unaligned_dump_stack;
168 #endif
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
171 extern int no_unaligned_warning;
172 #endif
174 #ifdef CONFIG_PROC_SYSCTL
176 #define SYSCTL_WRITES_LEGACY -1
177 #define SYSCTL_WRITES_WARN 0
178 #define SYSCTL_WRITES_STRICT 1
180 static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
182 static int proc_do_cad_pid(struct ctl_table *table, int write,
183 void __user *buffer, size_t *lenp, loff_t *ppos);
184 static int proc_taint(struct ctl_table *table, int write,
185 void __user *buffer, size_t *lenp, loff_t *ppos);
186 #endif
188 #ifdef CONFIG_PRINTK
189 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
190 void __user *buffer, size_t *lenp, loff_t *ppos);
191 #endif
193 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
194 void __user *buffer, size_t *lenp, loff_t *ppos);
195 #ifdef CONFIG_COREDUMP
196 static int proc_dostring_coredump(struct ctl_table *table, int write,
197 void __user *buffer, size_t *lenp, loff_t *ppos);
198 #endif
200 #ifdef CONFIG_MAGIC_SYSRQ
201 /* Note: sysrq code uses it's own private copy */
202 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
204 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
205 void __user *buffer, size_t *lenp,
206 loff_t *ppos)
208 int error;
210 error = proc_dointvec(table, write, buffer, lenp, ppos);
211 if (error)
212 return error;
214 if (write)
215 sysrq_toggle_support(__sysrq_enabled);
217 return 0;
220 #endif
222 static struct ctl_table kern_table[];
223 static struct ctl_table vm_table[];
224 static struct ctl_table fs_table[];
225 static struct ctl_table debug_table[];
226 static struct ctl_table dev_table[];
227 extern struct ctl_table random_table[];
228 #ifdef CONFIG_EPOLL
229 extern struct ctl_table epoll_table[];
230 #endif
232 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
233 int sysctl_legacy_va_layout;
234 #endif
236 /* The default sysctl tables: */
238 static struct ctl_table sysctl_base_table[] = {
240 .procname = "kernel",
241 .mode = 0555,
242 .child = kern_table,
245 .procname = "vm",
246 .mode = 0555,
247 .child = vm_table,
250 .procname = "fs",
251 .mode = 0555,
252 .child = fs_table,
255 .procname = "debug",
256 .mode = 0555,
257 .child = debug_table,
260 .procname = "dev",
261 .mode = 0555,
262 .child = dev_table,
267 #ifdef CONFIG_SCHED_DEBUG
268 static int min_sched_granularity_ns = 100000; /* 100 usecs */
269 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
270 static int min_wakeup_granularity_ns; /* 0 usecs */
271 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
272 #ifdef CONFIG_SMP
273 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
274 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
275 #endif /* CONFIG_SMP */
276 #endif /* CONFIG_SCHED_DEBUG */
278 #ifdef CONFIG_COMPACTION
279 static int min_extfrag_threshold;
280 static int max_extfrag_threshold = 1000;
281 #endif
283 static struct ctl_table kern_table[] = {
285 .procname = "sched_child_runs_first",
286 .data = &sysctl_sched_child_runs_first,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
289 .proc_handler = proc_dointvec,
291 #ifdef CONFIG_SCHED_DEBUG
293 .procname = "sched_min_granularity_ns",
294 .data = &sysctl_sched_min_granularity,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
297 .proc_handler = sched_proc_update_handler,
298 .extra1 = &min_sched_granularity_ns,
299 .extra2 = &max_sched_granularity_ns,
302 .procname = "sched_latency_ns",
303 .data = &sysctl_sched_latency,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
306 .proc_handler = sched_proc_update_handler,
307 .extra1 = &min_sched_granularity_ns,
308 .extra2 = &max_sched_granularity_ns,
311 .procname = "sched_wakeup_granularity_ns",
312 .data = &sysctl_sched_wakeup_granularity,
313 .maxlen = sizeof(unsigned int),
314 .mode = 0644,
315 .proc_handler = sched_proc_update_handler,
316 .extra1 = &min_wakeup_granularity_ns,
317 .extra2 = &max_wakeup_granularity_ns,
319 #ifdef CONFIG_SMP
321 .procname = "sched_tunable_scaling",
322 .data = &sysctl_sched_tunable_scaling,
323 .maxlen = sizeof(enum sched_tunable_scaling),
324 .mode = 0644,
325 .proc_handler = sched_proc_update_handler,
326 .extra1 = &min_sched_tunable_scaling,
327 .extra2 = &max_sched_tunable_scaling,
330 .procname = "sched_migration_cost_ns",
331 .data = &sysctl_sched_migration_cost,
332 .maxlen = sizeof(unsigned int),
333 .mode = 0644,
334 .proc_handler = proc_dointvec,
337 .procname = "sched_nr_migrate",
338 .data = &sysctl_sched_nr_migrate,
339 .maxlen = sizeof(unsigned int),
340 .mode = 0644,
341 .proc_handler = proc_dointvec,
344 .procname = "sched_time_avg_ms",
345 .data = &sysctl_sched_time_avg,
346 .maxlen = sizeof(unsigned int),
347 .mode = 0644,
348 .proc_handler = proc_dointvec,
351 .procname = "sched_shares_window_ns",
352 .data = &sysctl_sched_shares_window,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
355 .proc_handler = proc_dointvec,
357 #ifdef CONFIG_SCHEDSTATS
359 .procname = "sched_schedstats",
360 .data = NULL,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
363 .proc_handler = sysctl_schedstats,
364 .extra1 = &zero,
365 .extra2 = &one,
367 #endif /* CONFIG_SCHEDSTATS */
368 #endif /* CONFIG_SMP */
369 #ifdef CONFIG_NUMA_BALANCING
371 .procname = "numa_balancing_scan_delay_ms",
372 .data = &sysctl_numa_balancing_scan_delay,
373 .maxlen = sizeof(unsigned int),
374 .mode = 0644,
375 .proc_handler = proc_dointvec,
378 .procname = "numa_balancing_scan_period_min_ms",
379 .data = &sysctl_numa_balancing_scan_period_min,
380 .maxlen = sizeof(unsigned int),
381 .mode = 0644,
382 .proc_handler = proc_dointvec,
385 .procname = "numa_balancing_scan_period_max_ms",
386 .data = &sysctl_numa_balancing_scan_period_max,
387 .maxlen = sizeof(unsigned int),
388 .mode = 0644,
389 .proc_handler = proc_dointvec,
392 .procname = "numa_balancing_scan_size_mb",
393 .data = &sysctl_numa_balancing_scan_size,
394 .maxlen = sizeof(unsigned int),
395 .mode = 0644,
396 .proc_handler = proc_dointvec_minmax,
397 .extra1 = &one,
400 .procname = "numa_balancing",
401 .data = NULL, /* filled in by handler */
402 .maxlen = sizeof(unsigned int),
403 .mode = 0644,
404 .proc_handler = sysctl_numa_balancing,
405 .extra1 = &zero,
406 .extra2 = &one,
408 #endif /* CONFIG_NUMA_BALANCING */
409 #endif /* CONFIG_SCHED_DEBUG */
411 .procname = "sched_rt_period_us",
412 .data = &sysctl_sched_rt_period,
413 .maxlen = sizeof(unsigned int),
414 .mode = 0644,
415 .proc_handler = sched_rt_handler,
418 .procname = "sched_rt_runtime_us",
419 .data = &sysctl_sched_rt_runtime,
420 .maxlen = sizeof(int),
421 .mode = 0644,
422 .proc_handler = sched_rt_handler,
425 .procname = "sched_rr_timeslice_ms",
426 .data = &sched_rr_timeslice,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = sched_rr_handler,
431 #ifdef CONFIG_SCHED_AUTOGROUP
433 .procname = "sched_autogroup_enabled",
434 .data = &sysctl_sched_autogroup_enabled,
435 .maxlen = sizeof(unsigned int),
436 .mode = 0644,
437 .proc_handler = proc_dointvec_minmax,
438 .extra1 = &zero,
439 .extra2 = &one,
441 #endif
442 #ifdef CONFIG_CFS_BANDWIDTH
444 .procname = "sched_cfs_bandwidth_slice_us",
445 .data = &sysctl_sched_cfs_bandwidth_slice,
446 .maxlen = sizeof(unsigned int),
447 .mode = 0644,
448 .proc_handler = proc_dointvec_minmax,
449 .extra1 = &one,
451 #endif
452 #ifdef CONFIG_PROVE_LOCKING
454 .procname = "prove_locking",
455 .data = &prove_locking,
456 .maxlen = sizeof(int),
457 .mode = 0644,
458 .proc_handler = proc_dointvec,
460 #endif
461 #ifdef CONFIG_LOCK_STAT
463 .procname = "lock_stat",
464 .data = &lock_stat,
465 .maxlen = sizeof(int),
466 .mode = 0644,
467 .proc_handler = proc_dointvec,
469 #endif
471 .procname = "panic",
472 .data = &panic_timeout,
473 .maxlen = sizeof(int),
474 .mode = 0644,
475 .proc_handler = proc_dointvec,
477 #ifdef CONFIG_COREDUMP
479 .procname = "core_uses_pid",
480 .data = &core_uses_pid,
481 .maxlen = sizeof(int),
482 .mode = 0644,
483 .proc_handler = proc_dointvec,
486 .procname = "core_pattern",
487 .data = core_pattern,
488 .maxlen = CORENAME_MAX_SIZE,
489 .mode = 0644,
490 .proc_handler = proc_dostring_coredump,
493 .procname = "core_pipe_limit",
494 .data = &core_pipe_limit,
495 .maxlen = sizeof(unsigned int),
496 .mode = 0644,
497 .proc_handler = proc_dointvec,
499 #endif
500 #ifdef CONFIG_PROC_SYSCTL
502 .procname = "tainted",
503 .maxlen = sizeof(long),
504 .mode = 0644,
505 .proc_handler = proc_taint,
508 .procname = "sysctl_writes_strict",
509 .data = &sysctl_writes_strict,
510 .maxlen = sizeof(int),
511 .mode = 0644,
512 .proc_handler = proc_dointvec_minmax,
513 .extra1 = &neg_one,
514 .extra2 = &one,
516 #endif
517 #ifdef CONFIG_LATENCYTOP
519 .procname = "latencytop",
520 .data = &latencytop_enabled,
521 .maxlen = sizeof(int),
522 .mode = 0644,
523 .proc_handler = sysctl_latencytop,
525 #endif
526 #ifdef CONFIG_BLK_DEV_INITRD
528 .procname = "real-root-dev",
529 .data = &real_root_dev,
530 .maxlen = sizeof(int),
531 .mode = 0644,
532 .proc_handler = proc_dointvec,
534 #endif
536 .procname = "print-fatal-signals",
537 .data = &print_fatal_signals,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 .proc_handler = proc_dointvec,
542 #ifdef CONFIG_SPARC
544 .procname = "reboot-cmd",
545 .data = reboot_command,
546 .maxlen = 256,
547 .mode = 0644,
548 .proc_handler = proc_dostring,
551 .procname = "stop-a",
552 .data = &stop_a_enabled,
553 .maxlen = sizeof (int),
554 .mode = 0644,
555 .proc_handler = proc_dointvec,
558 .procname = "scons-poweroff",
559 .data = &scons_pwroff,
560 .maxlen = sizeof (int),
561 .mode = 0644,
562 .proc_handler = proc_dointvec,
564 #endif
565 #ifdef CONFIG_SPARC64
567 .procname = "tsb-ratio",
568 .data = &sysctl_tsb_ratio,
569 .maxlen = sizeof (int),
570 .mode = 0644,
571 .proc_handler = proc_dointvec,
573 #endif
574 #ifdef __hppa__
576 .procname = "soft-power",
577 .data = &pwrsw_enabled,
578 .maxlen = sizeof (int),
579 .mode = 0644,
580 .proc_handler = proc_dointvec,
582 #endif
583 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
585 .procname = "unaligned-trap",
586 .data = &unaligned_enabled,
587 .maxlen = sizeof (int),
588 .mode = 0644,
589 .proc_handler = proc_dointvec,
591 #endif
593 .procname = "ctrl-alt-del",
594 .data = &C_A_D,
595 .maxlen = sizeof(int),
596 .mode = 0644,
597 .proc_handler = proc_dointvec,
599 #ifdef CONFIG_FUNCTION_TRACER
601 .procname = "ftrace_enabled",
602 .data = &ftrace_enabled,
603 .maxlen = sizeof(int),
604 .mode = 0644,
605 .proc_handler = ftrace_enable_sysctl,
607 #endif
608 #ifdef CONFIG_STACK_TRACER
610 .procname = "stack_tracer_enabled",
611 .data = &stack_tracer_enabled,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = stack_trace_sysctl,
616 #endif
617 #ifdef CONFIG_TRACING
619 .procname = "ftrace_dump_on_oops",
620 .data = &ftrace_dump_on_oops,
621 .maxlen = sizeof(int),
622 .mode = 0644,
623 .proc_handler = proc_dointvec,
626 .procname = "traceoff_on_warning",
627 .data = &__disable_trace_on_warning,
628 .maxlen = sizeof(__disable_trace_on_warning),
629 .mode = 0644,
630 .proc_handler = proc_dointvec,
633 .procname = "tracepoint_printk",
634 .data = &tracepoint_printk,
635 .maxlen = sizeof(tracepoint_printk),
636 .mode = 0644,
637 .proc_handler = proc_dointvec,
639 #endif
640 #ifdef CONFIG_KEXEC_CORE
642 .procname = "kexec_load_disabled",
643 .data = &kexec_load_disabled,
644 .maxlen = sizeof(int),
645 .mode = 0644,
646 /* only handle a transition from default "0" to "1" */
647 .proc_handler = proc_dointvec_minmax,
648 .extra1 = &one,
649 .extra2 = &one,
651 #endif
652 #ifdef CONFIG_MODULES
654 .procname = "modprobe",
655 .data = &modprobe_path,
656 .maxlen = KMOD_PATH_LEN,
657 .mode = 0644,
658 .proc_handler = proc_dostring,
661 .procname = "modules_disabled",
662 .data = &modules_disabled,
663 .maxlen = sizeof(int),
664 .mode = 0644,
665 /* only handle a transition from default "0" to "1" */
666 .proc_handler = proc_dointvec_minmax,
667 .extra1 = &one,
668 .extra2 = &one,
670 #endif
671 #ifdef CONFIG_UEVENT_HELPER
673 .procname = "hotplug",
674 .data = &uevent_helper,
675 .maxlen = UEVENT_HELPER_PATH_LEN,
676 .mode = 0644,
677 .proc_handler = proc_dostring,
679 #endif
680 #ifdef CONFIG_CHR_DEV_SG
682 .procname = "sg-big-buff",
683 .data = &sg_big_buff,
684 .maxlen = sizeof (int),
685 .mode = 0444,
686 .proc_handler = proc_dointvec,
688 #endif
689 #ifdef CONFIG_BSD_PROCESS_ACCT
691 .procname = "acct",
692 .data = &acct_parm,
693 .maxlen = 3*sizeof(int),
694 .mode = 0644,
695 .proc_handler = proc_dointvec,
697 #endif
698 #ifdef CONFIG_MAGIC_SYSRQ
700 .procname = "sysrq",
701 .data = &__sysrq_enabled,
702 .maxlen = sizeof (int),
703 .mode = 0644,
704 .proc_handler = sysrq_sysctl_handler,
706 #endif
707 #ifdef CONFIG_PROC_SYSCTL
709 .procname = "cad_pid",
710 .data = NULL,
711 .maxlen = sizeof (int),
712 .mode = 0600,
713 .proc_handler = proc_do_cad_pid,
715 #endif
717 .procname = "threads-max",
718 .data = NULL,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = sysctl_max_threads,
724 .procname = "random",
725 .mode = 0555,
726 .child = random_table,
729 .procname = "usermodehelper",
730 .mode = 0555,
731 .child = usermodehelper_table,
734 .procname = "overflowuid",
735 .data = &overflowuid,
736 .maxlen = sizeof(int),
737 .mode = 0644,
738 .proc_handler = proc_dointvec_minmax,
739 .extra1 = &minolduid,
740 .extra2 = &maxolduid,
743 .procname = "overflowgid",
744 .data = &overflowgid,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = proc_dointvec_minmax,
748 .extra1 = &minolduid,
749 .extra2 = &maxolduid,
751 #ifdef CONFIG_S390
752 #ifdef CONFIG_MATHEMU
754 .procname = "ieee_emulation_warnings",
755 .data = &sysctl_ieee_emulation_warnings,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = proc_dointvec,
760 #endif
762 .procname = "userprocess_debug",
763 .data = &show_unhandled_signals,
764 .maxlen = sizeof(int),
765 .mode = 0644,
766 .proc_handler = proc_dointvec,
768 #endif
770 .procname = "pid_max",
771 .data = &pid_max,
772 .maxlen = sizeof (int),
773 .mode = 0644,
774 .proc_handler = proc_dointvec_minmax,
775 .extra1 = &pid_max_min,
776 .extra2 = &pid_max_max,
779 .procname = "panic_on_oops",
780 .data = &panic_on_oops,
781 .maxlen = sizeof(int),
782 .mode = 0644,
783 .proc_handler = proc_dointvec,
785 #if defined CONFIG_PRINTK
787 .procname = "printk",
788 .data = &console_loglevel,
789 .maxlen = 4*sizeof(int),
790 .mode = 0644,
791 .proc_handler = proc_dointvec,
794 .procname = "printk_ratelimit",
795 .data = &printk_ratelimit_state.interval,
796 .maxlen = sizeof(int),
797 .mode = 0644,
798 .proc_handler = proc_dointvec_jiffies,
801 .procname = "printk_ratelimit_burst",
802 .data = &printk_ratelimit_state.burst,
803 .maxlen = sizeof(int),
804 .mode = 0644,
805 .proc_handler = proc_dointvec,
808 .procname = "printk_delay",
809 .data = &printk_delay_msec,
810 .maxlen = sizeof(int),
811 .mode = 0644,
812 .proc_handler = proc_dointvec_minmax,
813 .extra1 = &zero,
814 .extra2 = &ten_thousand,
817 .procname = "printk_devkmsg",
818 .data = devkmsg_log_str,
819 .maxlen = DEVKMSG_STR_MAX_SIZE,
820 .mode = 0644,
821 .proc_handler = devkmsg_sysctl_set_loglvl,
824 .procname = "dmesg_restrict",
825 .data = &dmesg_restrict,
826 .maxlen = sizeof(int),
827 .mode = 0644,
828 .proc_handler = proc_dointvec_minmax_sysadmin,
829 .extra1 = &zero,
830 .extra2 = &one,
833 .procname = "kptr_restrict",
834 .data = &kptr_restrict,
835 .maxlen = sizeof(int),
836 .mode = 0644,
837 .proc_handler = proc_dointvec_minmax_sysadmin,
838 .extra1 = &zero,
839 .extra2 = &two,
841 #endif
843 .procname = "ngroups_max",
844 .data = &ngroups_max,
845 .maxlen = sizeof (int),
846 .mode = 0444,
847 .proc_handler = proc_dointvec,
850 .procname = "cap_last_cap",
851 .data = (void *)&cap_last_cap,
852 .maxlen = sizeof(int),
853 .mode = 0444,
854 .proc_handler = proc_dointvec,
856 #if defined(CONFIG_LOCKUP_DETECTOR)
858 .procname = "watchdog",
859 .data = &watchdog_user_enabled,
860 .maxlen = sizeof (int),
861 .mode = 0644,
862 .proc_handler = proc_watchdog,
863 .extra1 = &zero,
864 .extra2 = &one,
867 .procname = "watchdog_thresh",
868 .data = &watchdog_thresh,
869 .maxlen = sizeof(int),
870 .mode = 0644,
871 .proc_handler = proc_watchdog_thresh,
872 .extra1 = &zero,
873 .extra2 = &sixty,
876 .procname = "nmi_watchdog",
877 .data = &nmi_watchdog_enabled,
878 .maxlen = sizeof (int),
879 .mode = 0644,
880 .proc_handler = proc_nmi_watchdog,
881 .extra1 = &zero,
882 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
883 .extra2 = &one,
884 #else
885 .extra2 = &zero,
886 #endif
889 .procname = "soft_watchdog",
890 .data = &soft_watchdog_enabled,
891 .maxlen = sizeof (int),
892 .mode = 0644,
893 .proc_handler = proc_soft_watchdog,
894 .extra1 = &zero,
895 .extra2 = &one,
898 .procname = "watchdog_cpumask",
899 .data = &watchdog_cpumask_bits,
900 .maxlen = NR_CPUS,
901 .mode = 0644,
902 .proc_handler = proc_watchdog_cpumask,
905 .procname = "softlockup_panic",
906 .data = &softlockup_panic,
907 .maxlen = sizeof(int),
908 .mode = 0644,
909 .proc_handler = proc_dointvec_minmax,
910 .extra1 = &zero,
911 .extra2 = &one,
913 #ifdef CONFIG_HARDLOCKUP_DETECTOR
915 .procname = "hardlockup_panic",
916 .data = &hardlockup_panic,
917 .maxlen = sizeof(int),
918 .mode = 0644,
919 .proc_handler = proc_dointvec_minmax,
920 .extra1 = &zero,
921 .extra2 = &one,
923 #endif
924 #ifdef CONFIG_SMP
926 .procname = "softlockup_all_cpu_backtrace",
927 .data = &sysctl_softlockup_all_cpu_backtrace,
928 .maxlen = sizeof(int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec_minmax,
931 .extra1 = &zero,
932 .extra2 = &one,
935 .procname = "hardlockup_all_cpu_backtrace",
936 .data = &sysctl_hardlockup_all_cpu_backtrace,
937 .maxlen = sizeof(int),
938 .mode = 0644,
939 .proc_handler = proc_dointvec_minmax,
940 .extra1 = &zero,
941 .extra2 = &one,
943 #endif /* CONFIG_SMP */
944 #endif
945 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
947 .procname = "unknown_nmi_panic",
948 .data = &unknown_nmi_panic,
949 .maxlen = sizeof (int),
950 .mode = 0644,
951 .proc_handler = proc_dointvec,
953 #endif
954 #if defined(CONFIG_X86)
956 .procname = "panic_on_unrecovered_nmi",
957 .data = &panic_on_unrecovered_nmi,
958 .maxlen = sizeof(int),
959 .mode = 0644,
960 .proc_handler = proc_dointvec,
963 .procname = "panic_on_io_nmi",
964 .data = &panic_on_io_nmi,
965 .maxlen = sizeof(int),
966 .mode = 0644,
967 .proc_handler = proc_dointvec,
969 #ifdef CONFIG_DEBUG_STACKOVERFLOW
971 .procname = "panic_on_stackoverflow",
972 .data = &sysctl_panic_on_stackoverflow,
973 .maxlen = sizeof(int),
974 .mode = 0644,
975 .proc_handler = proc_dointvec,
977 #endif
979 .procname = "bootloader_type",
980 .data = &bootloader_type,
981 .maxlen = sizeof (int),
982 .mode = 0444,
983 .proc_handler = proc_dointvec,
986 .procname = "bootloader_version",
987 .data = &bootloader_version,
988 .maxlen = sizeof (int),
989 .mode = 0444,
990 .proc_handler = proc_dointvec,
993 .procname = "kstack_depth_to_print",
994 .data = &kstack_depth_to_print,
995 .maxlen = sizeof(int),
996 .mode = 0644,
997 .proc_handler = proc_dointvec,
1000 .procname = "io_delay_type",
1001 .data = &io_delay_type,
1002 .maxlen = sizeof(int),
1003 .mode = 0644,
1004 .proc_handler = proc_dointvec,
1006 #endif
1007 #if defined(CONFIG_MMU)
1009 .procname = "randomize_va_space",
1010 .data = &randomize_va_space,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
1013 .proc_handler = proc_dointvec,
1015 #endif
1016 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1018 .procname = "spin_retry",
1019 .data = &spin_retry,
1020 .maxlen = sizeof (int),
1021 .mode = 0644,
1022 .proc_handler = proc_dointvec,
1024 #endif
1025 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1027 .procname = "acpi_video_flags",
1028 .data = &acpi_realmode_flags,
1029 .maxlen = sizeof (unsigned long),
1030 .mode = 0644,
1031 .proc_handler = proc_doulongvec_minmax,
1033 #endif
1034 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1036 .procname = "ignore-unaligned-usertrap",
1037 .data = &no_unaligned_warning,
1038 .maxlen = sizeof (int),
1039 .mode = 0644,
1040 .proc_handler = proc_dointvec,
1042 #endif
1043 #ifdef CONFIG_IA64
1045 .procname = "unaligned-dump-stack",
1046 .data = &unaligned_dump_stack,
1047 .maxlen = sizeof (int),
1048 .mode = 0644,
1049 .proc_handler = proc_dointvec,
1051 #endif
1052 #ifdef CONFIG_DETECT_HUNG_TASK
1054 .procname = "hung_task_panic",
1055 .data = &sysctl_hung_task_panic,
1056 .maxlen = sizeof(int),
1057 .mode = 0644,
1058 .proc_handler = proc_dointvec_minmax,
1059 .extra1 = &zero,
1060 .extra2 = &one,
1063 .procname = "hung_task_check_count",
1064 .data = &sysctl_hung_task_check_count,
1065 .maxlen = sizeof(int),
1066 .mode = 0644,
1067 .proc_handler = proc_dointvec_minmax,
1068 .extra1 = &zero,
1071 .procname = "hung_task_timeout_secs",
1072 .data = &sysctl_hung_task_timeout_secs,
1073 .maxlen = sizeof(unsigned long),
1074 .mode = 0644,
1075 .proc_handler = proc_dohung_task_timeout_secs,
1076 .extra2 = &hung_task_timeout_max,
1079 .procname = "hung_task_warnings",
1080 .data = &sysctl_hung_task_warnings,
1081 .maxlen = sizeof(int),
1082 .mode = 0644,
1083 .proc_handler = proc_dointvec_minmax,
1084 .extra1 = &neg_one,
1086 #endif
1087 #ifdef CONFIG_COMPAT
1089 .procname = "compat-log",
1090 .data = &compat_log,
1091 .maxlen = sizeof (int),
1092 .mode = 0644,
1093 .proc_handler = proc_dointvec,
1095 #endif
1096 #ifdef CONFIG_RT_MUTEXES
1098 .procname = "max_lock_depth",
1099 .data = &max_lock_depth,
1100 .maxlen = sizeof(int),
1101 .mode = 0644,
1102 .proc_handler = proc_dointvec,
1104 #endif
1106 .procname = "poweroff_cmd",
1107 .data = &poweroff_cmd,
1108 .maxlen = POWEROFF_CMD_PATH_LEN,
1109 .mode = 0644,
1110 .proc_handler = proc_dostring,
1112 #ifdef CONFIG_KEYS
1114 .procname = "keys",
1115 .mode = 0555,
1116 .child = key_sysctls,
1118 #endif
1119 #ifdef CONFIG_PERF_EVENTS
1121 * User-space scripts rely on the existence of this file
1122 * as a feature check for perf_events being enabled.
1124 * So it's an ABI, do not remove!
1127 .procname = "perf_event_paranoid",
1128 .data = &sysctl_perf_event_paranoid,
1129 .maxlen = sizeof(sysctl_perf_event_paranoid),
1130 .mode = 0644,
1131 .proc_handler = proc_dointvec,
1134 .procname = "perf_event_mlock_kb",
1135 .data = &sysctl_perf_event_mlock,
1136 .maxlen = sizeof(sysctl_perf_event_mlock),
1137 .mode = 0644,
1138 .proc_handler = proc_dointvec,
1141 .procname = "perf_event_max_sample_rate",
1142 .data = &sysctl_perf_event_sample_rate,
1143 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1144 .mode = 0644,
1145 .proc_handler = perf_proc_update_handler,
1146 .extra1 = &one,
1149 .procname = "perf_cpu_time_max_percent",
1150 .data = &sysctl_perf_cpu_time_max_percent,
1151 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1152 .mode = 0644,
1153 .proc_handler = perf_cpu_time_max_percent_handler,
1154 .extra1 = &zero,
1155 .extra2 = &one_hundred,
1158 .procname = "perf_event_max_stack",
1159 .data = &sysctl_perf_event_max_stack,
1160 .maxlen = sizeof(sysctl_perf_event_max_stack),
1161 .mode = 0644,
1162 .proc_handler = perf_event_max_stack_handler,
1163 .extra1 = &zero,
1164 .extra2 = &six_hundred_forty_kb,
1167 .procname = "perf_event_max_contexts_per_stack",
1168 .data = &sysctl_perf_event_max_contexts_per_stack,
1169 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1170 .mode = 0644,
1171 .proc_handler = perf_event_max_stack_handler,
1172 .extra1 = &zero,
1173 .extra2 = &one_thousand,
1175 #endif
1176 #ifdef CONFIG_KMEMCHECK
1178 .procname = "kmemcheck",
1179 .data = &kmemcheck_enabled,
1180 .maxlen = sizeof(int),
1181 .mode = 0644,
1182 .proc_handler = proc_dointvec,
1184 #endif
1186 .procname = "panic_on_warn",
1187 .data = &panic_on_warn,
1188 .maxlen = sizeof(int),
1189 .mode = 0644,
1190 .proc_handler = proc_dointvec_minmax,
1191 .extra1 = &zero,
1192 .extra2 = &one,
1194 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1196 .procname = "timer_migration",
1197 .data = &sysctl_timer_migration,
1198 .maxlen = sizeof(unsigned int),
1199 .mode = 0644,
1200 .proc_handler = timer_migration_handler,
1202 #endif
1203 #ifdef CONFIG_BPF_SYSCALL
1205 .procname = "unprivileged_bpf_disabled",
1206 .data = &sysctl_unprivileged_bpf_disabled,
1207 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1208 .mode = 0644,
1209 /* only handle a transition from default "0" to "1" */
1210 .proc_handler = proc_dointvec_minmax,
1211 .extra1 = &one,
1212 .extra2 = &one,
1214 #endif
1215 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1217 .procname = "panic_on_rcu_stall",
1218 .data = &sysctl_panic_on_rcu_stall,
1219 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1220 .mode = 0644,
1221 .proc_handler = proc_dointvec_minmax,
1222 .extra1 = &zero,
1223 .extra2 = &one,
1225 #endif
1229 static struct ctl_table vm_table[] = {
1231 .procname = "overcommit_memory",
1232 .data = &sysctl_overcommit_memory,
1233 .maxlen = sizeof(sysctl_overcommit_memory),
1234 .mode = 0644,
1235 .proc_handler = proc_dointvec_minmax,
1236 .extra1 = &zero,
1237 .extra2 = &two,
1240 .procname = "panic_on_oom",
1241 .data = &sysctl_panic_on_oom,
1242 .maxlen = sizeof(sysctl_panic_on_oom),
1243 .mode = 0644,
1244 .proc_handler = proc_dointvec_minmax,
1245 .extra1 = &zero,
1246 .extra2 = &two,
1249 .procname = "oom_kill_allocating_task",
1250 .data = &sysctl_oom_kill_allocating_task,
1251 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1252 .mode = 0644,
1253 .proc_handler = proc_dointvec,
1256 .procname = "oom_dump_tasks",
1257 .data = &sysctl_oom_dump_tasks,
1258 .maxlen = sizeof(sysctl_oom_dump_tasks),
1259 .mode = 0644,
1260 .proc_handler = proc_dointvec,
1263 .procname = "overcommit_ratio",
1264 .data = &sysctl_overcommit_ratio,
1265 .maxlen = sizeof(sysctl_overcommit_ratio),
1266 .mode = 0644,
1267 .proc_handler = overcommit_ratio_handler,
1270 .procname = "overcommit_kbytes",
1271 .data = &sysctl_overcommit_kbytes,
1272 .maxlen = sizeof(sysctl_overcommit_kbytes),
1273 .mode = 0644,
1274 .proc_handler = overcommit_kbytes_handler,
1277 .procname = "page-cluster",
1278 .data = &page_cluster,
1279 .maxlen = sizeof(int),
1280 .mode = 0644,
1281 .proc_handler = proc_dointvec_minmax,
1282 .extra1 = &zero,
1285 .procname = "dirty_background_ratio",
1286 .data = &dirty_background_ratio,
1287 .maxlen = sizeof(dirty_background_ratio),
1288 .mode = 0644,
1289 .proc_handler = dirty_background_ratio_handler,
1290 .extra1 = &zero,
1291 .extra2 = &one_hundred,
1294 .procname = "dirty_background_bytes",
1295 .data = &dirty_background_bytes,
1296 .maxlen = sizeof(dirty_background_bytes),
1297 .mode = 0644,
1298 .proc_handler = dirty_background_bytes_handler,
1299 .extra1 = &one_ul,
1302 .procname = "dirty_ratio",
1303 .data = &vm_dirty_ratio,
1304 .maxlen = sizeof(vm_dirty_ratio),
1305 .mode = 0644,
1306 .proc_handler = dirty_ratio_handler,
1307 .extra1 = &zero,
1308 .extra2 = &one_hundred,
1311 .procname = "dirty_bytes",
1312 .data = &vm_dirty_bytes,
1313 .maxlen = sizeof(vm_dirty_bytes),
1314 .mode = 0644,
1315 .proc_handler = dirty_bytes_handler,
1316 .extra1 = &dirty_bytes_min,
1319 .procname = "dirty_writeback_centisecs",
1320 .data = &dirty_writeback_interval,
1321 .maxlen = sizeof(dirty_writeback_interval),
1322 .mode = 0644,
1323 .proc_handler = dirty_writeback_centisecs_handler,
1326 .procname = "dirty_expire_centisecs",
1327 .data = &dirty_expire_interval,
1328 .maxlen = sizeof(dirty_expire_interval),
1329 .mode = 0644,
1330 .proc_handler = proc_dointvec_minmax,
1331 .extra1 = &zero,
1334 .procname = "dirtytime_expire_seconds",
1335 .data = &dirtytime_expire_interval,
1336 .maxlen = sizeof(dirty_expire_interval),
1337 .mode = 0644,
1338 .proc_handler = dirtytime_interval_handler,
1339 .extra1 = &zero,
1342 .procname = "nr_pdflush_threads",
1343 .mode = 0444 /* read-only */,
1344 .proc_handler = pdflush_proc_obsolete,
1347 .procname = "swappiness",
1348 .data = &vm_swappiness,
1349 .maxlen = sizeof(vm_swappiness),
1350 .mode = 0644,
1351 .proc_handler = proc_dointvec_minmax,
1352 .extra1 = &zero,
1353 .extra2 = &one_hundred,
1355 #ifdef CONFIG_HUGETLB_PAGE
1357 .procname = "nr_hugepages",
1358 .data = NULL,
1359 .maxlen = sizeof(unsigned long),
1360 .mode = 0644,
1361 .proc_handler = hugetlb_sysctl_handler,
1363 #ifdef CONFIG_NUMA
1365 .procname = "nr_hugepages_mempolicy",
1366 .data = NULL,
1367 .maxlen = sizeof(unsigned long),
1368 .mode = 0644,
1369 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1371 #endif
1373 .procname = "hugetlb_shm_group",
1374 .data = &sysctl_hugetlb_shm_group,
1375 .maxlen = sizeof(gid_t),
1376 .mode = 0644,
1377 .proc_handler = proc_dointvec,
1380 .procname = "hugepages_treat_as_movable",
1381 .data = &hugepages_treat_as_movable,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
1384 .proc_handler = proc_dointvec,
1387 .procname = "nr_overcommit_hugepages",
1388 .data = NULL,
1389 .maxlen = sizeof(unsigned long),
1390 .mode = 0644,
1391 .proc_handler = hugetlb_overcommit_handler,
1393 #endif
1395 .procname = "lowmem_reserve_ratio",
1396 .data = &sysctl_lowmem_reserve_ratio,
1397 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1398 .mode = 0644,
1399 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1402 .procname = "drop_caches",
1403 .data = &sysctl_drop_caches,
1404 .maxlen = sizeof(int),
1405 .mode = 0644,
1406 .proc_handler = drop_caches_sysctl_handler,
1407 .extra1 = &one,
1408 .extra2 = &four,
1410 #ifdef CONFIG_COMPACTION
1412 .procname = "compact_memory",
1413 .data = &sysctl_compact_memory,
1414 .maxlen = sizeof(int),
1415 .mode = 0200,
1416 .proc_handler = sysctl_compaction_handler,
1419 .procname = "extfrag_threshold",
1420 .data = &sysctl_extfrag_threshold,
1421 .maxlen = sizeof(int),
1422 .mode = 0644,
1423 .proc_handler = sysctl_extfrag_handler,
1424 .extra1 = &min_extfrag_threshold,
1425 .extra2 = &max_extfrag_threshold,
1428 .procname = "compact_unevictable_allowed",
1429 .data = &sysctl_compact_unevictable_allowed,
1430 .maxlen = sizeof(int),
1431 .mode = 0644,
1432 .proc_handler = proc_dointvec,
1433 .extra1 = &zero,
1434 .extra2 = &one,
1437 #endif /* CONFIG_COMPACTION */
1439 .procname = "min_free_kbytes",
1440 .data = &min_free_kbytes,
1441 .maxlen = sizeof(min_free_kbytes),
1442 .mode = 0644,
1443 .proc_handler = min_free_kbytes_sysctl_handler,
1444 .extra1 = &zero,
1447 .procname = "watermark_scale_factor",
1448 .data = &watermark_scale_factor,
1449 .maxlen = sizeof(watermark_scale_factor),
1450 .mode = 0644,
1451 .proc_handler = watermark_scale_factor_sysctl_handler,
1452 .extra1 = &one,
1453 .extra2 = &one_thousand,
1456 .procname = "percpu_pagelist_fraction",
1457 .data = &percpu_pagelist_fraction,
1458 .maxlen = sizeof(percpu_pagelist_fraction),
1459 .mode = 0644,
1460 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1461 .extra1 = &zero,
1463 #ifdef CONFIG_MMU
1465 .procname = "max_map_count",
1466 .data = &sysctl_max_map_count,
1467 .maxlen = sizeof(sysctl_max_map_count),
1468 .mode = 0644,
1469 .proc_handler = proc_dointvec_minmax,
1470 .extra1 = &zero,
1472 #else
1474 .procname = "nr_trim_pages",
1475 .data = &sysctl_nr_trim_pages,
1476 .maxlen = sizeof(sysctl_nr_trim_pages),
1477 .mode = 0644,
1478 .proc_handler = proc_dointvec_minmax,
1479 .extra1 = &zero,
1481 #endif
1483 .procname = "laptop_mode",
1484 .data = &laptop_mode,
1485 .maxlen = sizeof(laptop_mode),
1486 .mode = 0644,
1487 .proc_handler = proc_dointvec_jiffies,
1490 .procname = "block_dump",
1491 .data = &block_dump,
1492 .maxlen = sizeof(block_dump),
1493 .mode = 0644,
1494 .proc_handler = proc_dointvec,
1495 .extra1 = &zero,
1498 .procname = "vfs_cache_pressure",
1499 .data = &sysctl_vfs_cache_pressure,
1500 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1501 .mode = 0644,
1502 .proc_handler = proc_dointvec,
1503 .extra1 = &zero,
1505 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1507 .procname = "legacy_va_layout",
1508 .data = &sysctl_legacy_va_layout,
1509 .maxlen = sizeof(sysctl_legacy_va_layout),
1510 .mode = 0644,
1511 .proc_handler = proc_dointvec,
1512 .extra1 = &zero,
1514 #endif
1515 #ifdef CONFIG_NUMA
1517 .procname = "zone_reclaim_mode",
1518 .data = &node_reclaim_mode,
1519 .maxlen = sizeof(node_reclaim_mode),
1520 .mode = 0644,
1521 .proc_handler = proc_dointvec,
1522 .extra1 = &zero,
1525 .procname = "min_unmapped_ratio",
1526 .data = &sysctl_min_unmapped_ratio,
1527 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1528 .mode = 0644,
1529 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1530 .extra1 = &zero,
1531 .extra2 = &one_hundred,
1534 .procname = "min_slab_ratio",
1535 .data = &sysctl_min_slab_ratio,
1536 .maxlen = sizeof(sysctl_min_slab_ratio),
1537 .mode = 0644,
1538 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1539 .extra1 = &zero,
1540 .extra2 = &one_hundred,
1542 #endif
1543 #ifdef CONFIG_SMP
1545 .procname = "stat_interval",
1546 .data = &sysctl_stat_interval,
1547 .maxlen = sizeof(sysctl_stat_interval),
1548 .mode = 0644,
1549 .proc_handler = proc_dointvec_jiffies,
1552 .procname = "stat_refresh",
1553 .data = NULL,
1554 .maxlen = 0,
1555 .mode = 0600,
1556 .proc_handler = vmstat_refresh,
1558 #endif
1559 #ifdef CONFIG_MMU
1561 .procname = "mmap_min_addr",
1562 .data = &dac_mmap_min_addr,
1563 .maxlen = sizeof(unsigned long),
1564 .mode = 0644,
1565 .proc_handler = mmap_min_addr_handler,
1567 #endif
1568 #ifdef CONFIG_NUMA
1570 .procname = "numa_zonelist_order",
1571 .data = &numa_zonelist_order,
1572 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1573 .mode = 0644,
1574 .proc_handler = numa_zonelist_order_handler,
1576 #endif
1577 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1578 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1580 .procname = "vdso_enabled",
1581 #ifdef CONFIG_X86_32
1582 .data = &vdso32_enabled,
1583 .maxlen = sizeof(vdso32_enabled),
1584 #else
1585 .data = &vdso_enabled,
1586 .maxlen = sizeof(vdso_enabled),
1587 #endif
1588 .mode = 0644,
1589 .proc_handler = proc_dointvec,
1590 .extra1 = &zero,
1592 #endif
1593 #ifdef CONFIG_HIGHMEM
1595 .procname = "highmem_is_dirtyable",
1596 .data = &vm_highmem_is_dirtyable,
1597 .maxlen = sizeof(vm_highmem_is_dirtyable),
1598 .mode = 0644,
1599 .proc_handler = proc_dointvec_minmax,
1600 .extra1 = &zero,
1601 .extra2 = &one,
1603 #endif
1604 #ifdef CONFIG_MEMORY_FAILURE
1606 .procname = "memory_failure_early_kill",
1607 .data = &sysctl_memory_failure_early_kill,
1608 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1609 .mode = 0644,
1610 .proc_handler = proc_dointvec_minmax,
1611 .extra1 = &zero,
1612 .extra2 = &one,
1615 .procname = "memory_failure_recovery",
1616 .data = &sysctl_memory_failure_recovery,
1617 .maxlen = sizeof(sysctl_memory_failure_recovery),
1618 .mode = 0644,
1619 .proc_handler = proc_dointvec_minmax,
1620 .extra1 = &zero,
1621 .extra2 = &one,
1623 #endif
1625 .procname = "user_reserve_kbytes",
1626 .data = &sysctl_user_reserve_kbytes,
1627 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1628 .mode = 0644,
1629 .proc_handler = proc_doulongvec_minmax,
1632 .procname = "admin_reserve_kbytes",
1633 .data = &sysctl_admin_reserve_kbytes,
1634 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1635 .mode = 0644,
1636 .proc_handler = proc_doulongvec_minmax,
1638 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1640 .procname = "mmap_rnd_bits",
1641 .data = &mmap_rnd_bits,
1642 .maxlen = sizeof(mmap_rnd_bits),
1643 .mode = 0600,
1644 .proc_handler = proc_dointvec_minmax,
1645 .extra1 = (void *)&mmap_rnd_bits_min,
1646 .extra2 = (void *)&mmap_rnd_bits_max,
1648 #endif
1649 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1651 .procname = "mmap_rnd_compat_bits",
1652 .data = &mmap_rnd_compat_bits,
1653 .maxlen = sizeof(mmap_rnd_compat_bits),
1654 .mode = 0600,
1655 .proc_handler = proc_dointvec_minmax,
1656 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1657 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1659 #endif
1663 static struct ctl_table fs_table[] = {
1665 .procname = "inode-nr",
1666 .data = &inodes_stat,
1667 .maxlen = 2*sizeof(long),
1668 .mode = 0444,
1669 .proc_handler = proc_nr_inodes,
1672 .procname = "inode-state",
1673 .data = &inodes_stat,
1674 .maxlen = 7*sizeof(long),
1675 .mode = 0444,
1676 .proc_handler = proc_nr_inodes,
1679 .procname = "file-nr",
1680 .data = &files_stat,
1681 .maxlen = sizeof(files_stat),
1682 .mode = 0444,
1683 .proc_handler = proc_nr_files,
1686 .procname = "file-max",
1687 .data = &files_stat.max_files,
1688 .maxlen = sizeof(files_stat.max_files),
1689 .mode = 0644,
1690 .proc_handler = proc_doulongvec_minmax,
1693 .procname = "nr_open",
1694 .data = &sysctl_nr_open,
1695 .maxlen = sizeof(int),
1696 .mode = 0644,
1697 .proc_handler = proc_dointvec_minmax,
1698 .extra1 = &sysctl_nr_open_min,
1699 .extra2 = &sysctl_nr_open_max,
1702 .procname = "dentry-state",
1703 .data = &dentry_stat,
1704 .maxlen = 6*sizeof(long),
1705 .mode = 0444,
1706 .proc_handler = proc_nr_dentry,
1709 .procname = "overflowuid",
1710 .data = &fs_overflowuid,
1711 .maxlen = sizeof(int),
1712 .mode = 0644,
1713 .proc_handler = proc_dointvec_minmax,
1714 .extra1 = &minolduid,
1715 .extra2 = &maxolduid,
1718 .procname = "overflowgid",
1719 .data = &fs_overflowgid,
1720 .maxlen = sizeof(int),
1721 .mode = 0644,
1722 .proc_handler = proc_dointvec_minmax,
1723 .extra1 = &minolduid,
1724 .extra2 = &maxolduid,
1726 #ifdef CONFIG_FILE_LOCKING
1728 .procname = "leases-enable",
1729 .data = &leases_enable,
1730 .maxlen = sizeof(int),
1731 .mode = 0644,
1732 .proc_handler = proc_dointvec,
1734 #endif
1735 #ifdef CONFIG_DNOTIFY
1737 .procname = "dir-notify-enable",
1738 .data = &dir_notify_enable,
1739 .maxlen = sizeof(int),
1740 .mode = 0644,
1741 .proc_handler = proc_dointvec,
1743 #endif
1744 #ifdef CONFIG_MMU
1745 #ifdef CONFIG_FILE_LOCKING
1747 .procname = "lease-break-time",
1748 .data = &lease_break_time,
1749 .maxlen = sizeof(int),
1750 .mode = 0644,
1751 .proc_handler = proc_dointvec,
1753 #endif
1754 #ifdef CONFIG_AIO
1756 .procname = "aio-nr",
1757 .data = &aio_nr,
1758 .maxlen = sizeof(aio_nr),
1759 .mode = 0444,
1760 .proc_handler = proc_doulongvec_minmax,
1763 .procname = "aio-max-nr",
1764 .data = &aio_max_nr,
1765 .maxlen = sizeof(aio_max_nr),
1766 .mode = 0644,
1767 .proc_handler = proc_doulongvec_minmax,
1769 #endif /* CONFIG_AIO */
1770 #ifdef CONFIG_INOTIFY_USER
1772 .procname = "inotify",
1773 .mode = 0555,
1774 .child = inotify_table,
1776 #endif
1777 #ifdef CONFIG_EPOLL
1779 .procname = "epoll",
1780 .mode = 0555,
1781 .child = epoll_table,
1783 #endif
1784 #endif
1786 .procname = "protected_symlinks",
1787 .data = &sysctl_protected_symlinks,
1788 .maxlen = sizeof(int),
1789 .mode = 0600,
1790 .proc_handler = proc_dointvec_minmax,
1791 .extra1 = &zero,
1792 .extra2 = &one,
1795 .procname = "protected_hardlinks",
1796 .data = &sysctl_protected_hardlinks,
1797 .maxlen = sizeof(int),
1798 .mode = 0600,
1799 .proc_handler = proc_dointvec_minmax,
1800 .extra1 = &zero,
1801 .extra2 = &one,
1804 .procname = "suid_dumpable",
1805 .data = &suid_dumpable,
1806 .maxlen = sizeof(int),
1807 .mode = 0644,
1808 .proc_handler = proc_dointvec_minmax_coredump,
1809 .extra1 = &zero,
1810 .extra2 = &two,
1812 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1814 .procname = "binfmt_misc",
1815 .mode = 0555,
1816 .child = sysctl_mount_point,
1818 #endif
1820 .procname = "pipe-max-size",
1821 .data = &pipe_max_size,
1822 .maxlen = sizeof(int),
1823 .mode = 0644,
1824 .proc_handler = &pipe_proc_fn,
1825 .extra1 = &pipe_min_size,
1828 .procname = "pipe-user-pages-hard",
1829 .data = &pipe_user_pages_hard,
1830 .maxlen = sizeof(pipe_user_pages_hard),
1831 .mode = 0644,
1832 .proc_handler = proc_doulongvec_minmax,
1835 .procname = "pipe-user-pages-soft",
1836 .data = &pipe_user_pages_soft,
1837 .maxlen = sizeof(pipe_user_pages_soft),
1838 .mode = 0644,
1839 .proc_handler = proc_doulongvec_minmax,
1844 static struct ctl_table debug_table[] = {
1845 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1847 .procname = "exception-trace",
1848 .data = &show_unhandled_signals,
1849 .maxlen = sizeof(int),
1850 .mode = 0644,
1851 .proc_handler = proc_dointvec
1853 #endif
1854 #if defined(CONFIG_OPTPROBES)
1856 .procname = "kprobes-optimization",
1857 .data = &sysctl_kprobes_optimization,
1858 .maxlen = sizeof(int),
1859 .mode = 0644,
1860 .proc_handler = proc_kprobes_optimization_handler,
1861 .extra1 = &zero,
1862 .extra2 = &one,
1864 #endif
1868 static struct ctl_table dev_table[] = {
1872 int __init sysctl_init(void)
1874 struct ctl_table_header *hdr;
1876 hdr = register_sysctl_table(sysctl_base_table);
1877 kmemleak_not_leak(hdr);
1878 return 0;
1881 #endif /* CONFIG_SYSCTL */
1884 * /proc/sys support
1887 #ifdef CONFIG_PROC_SYSCTL
1889 static int _proc_do_string(char *data, int maxlen, int write,
1890 char __user *buffer,
1891 size_t *lenp, loff_t *ppos)
1893 size_t len;
1894 char __user *p;
1895 char c;
1897 if (!data || !maxlen || !*lenp) {
1898 *lenp = 0;
1899 return 0;
1902 if (write) {
1903 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1904 /* Only continue writes not past the end of buffer. */
1905 len = strlen(data);
1906 if (len > maxlen - 1)
1907 len = maxlen - 1;
1909 if (*ppos > len)
1910 return 0;
1911 len = *ppos;
1912 } else {
1913 /* Start writing from beginning of buffer. */
1914 len = 0;
1917 *ppos += *lenp;
1918 p = buffer;
1919 while ((p - buffer) < *lenp && len < maxlen - 1) {
1920 if (get_user(c, p++))
1921 return -EFAULT;
1922 if (c == 0 || c == '\n')
1923 break;
1924 data[len++] = c;
1926 data[len] = 0;
1927 } else {
1928 len = strlen(data);
1929 if (len > maxlen)
1930 len = maxlen;
1932 if (*ppos > len) {
1933 *lenp = 0;
1934 return 0;
1937 data += *ppos;
1938 len -= *ppos;
1940 if (len > *lenp)
1941 len = *lenp;
1942 if (len)
1943 if (copy_to_user(buffer, data, len))
1944 return -EFAULT;
1945 if (len < *lenp) {
1946 if (put_user('\n', buffer + len))
1947 return -EFAULT;
1948 len++;
1950 *lenp = len;
1951 *ppos += len;
1953 return 0;
1956 static void warn_sysctl_write(struct ctl_table *table)
1958 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1959 "This will not be supported in the future. To silence this\n"
1960 "warning, set kernel.sysctl_writes_strict = -1\n",
1961 current->comm, table->procname);
1965 * proc_dostring - read a string sysctl
1966 * @table: the sysctl table
1967 * @write: %TRUE if this is a write to the sysctl file
1968 * @buffer: the user buffer
1969 * @lenp: the size of the user buffer
1970 * @ppos: file position
1972 * Reads/writes a string from/to the user buffer. If the kernel
1973 * buffer provided is not large enough to hold the string, the
1974 * string is truncated. The copied string is %NULL-terminated.
1975 * If the string is being read by the user process, it is copied
1976 * and a newline '\n' is added. It is truncated if the buffer is
1977 * not large enough.
1979 * Returns 0 on success.
1981 int proc_dostring(struct ctl_table *table, int write,
1982 void __user *buffer, size_t *lenp, loff_t *ppos)
1984 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1985 warn_sysctl_write(table);
1987 return _proc_do_string((char *)(table->data), table->maxlen, write,
1988 (char __user *)buffer, lenp, ppos);
1991 static size_t proc_skip_spaces(char **buf)
1993 size_t ret;
1994 char *tmp = skip_spaces(*buf);
1995 ret = tmp - *buf;
1996 *buf = tmp;
1997 return ret;
2000 static void proc_skip_char(char **buf, size_t *size, const char v)
2002 while (*size) {
2003 if (**buf != v)
2004 break;
2005 (*size)--;
2006 (*buf)++;
2010 #define TMPBUFLEN 22
2012 * proc_get_long - reads an ASCII formatted integer from a user buffer
2014 * @buf: a kernel buffer
2015 * @size: size of the kernel buffer
2016 * @val: this is where the number will be stored
2017 * @neg: set to %TRUE if number is negative
2018 * @perm_tr: a vector which contains the allowed trailers
2019 * @perm_tr_len: size of the perm_tr vector
2020 * @tr: pointer to store the trailer character
2022 * In case of success %0 is returned and @buf and @size are updated with
2023 * the amount of bytes read. If @tr is non-NULL and a trailing
2024 * character exists (size is non-zero after returning from this
2025 * function), @tr is updated with the trailing character.
2027 static int proc_get_long(char **buf, size_t *size,
2028 unsigned long *val, bool *neg,
2029 const char *perm_tr, unsigned perm_tr_len, char *tr)
2031 int len;
2032 char *p, tmp[TMPBUFLEN];
2034 if (!*size)
2035 return -EINVAL;
2037 len = *size;
2038 if (len > TMPBUFLEN - 1)
2039 len = TMPBUFLEN - 1;
2041 memcpy(tmp, *buf, len);
2043 tmp[len] = 0;
2044 p = tmp;
2045 if (*p == '-' && *size > 1) {
2046 *neg = true;
2047 p++;
2048 } else
2049 *neg = false;
2050 if (!isdigit(*p))
2051 return -EINVAL;
2053 *val = simple_strtoul(p, &p, 0);
2055 len = p - tmp;
2057 /* We don't know if the next char is whitespace thus we may accept
2058 * invalid integers (e.g. 1234...a) or two integers instead of one
2059 * (e.g. 123...1). So lets not allow such large numbers. */
2060 if (len == TMPBUFLEN - 1)
2061 return -EINVAL;
2063 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2064 return -EINVAL;
2066 if (tr && (len < *size))
2067 *tr = *p;
2069 *buf += len;
2070 *size -= len;
2072 return 0;
2076 * proc_put_long - converts an integer to a decimal ASCII formatted string
2078 * @buf: the user buffer
2079 * @size: the size of the user buffer
2080 * @val: the integer to be converted
2081 * @neg: sign of the number, %TRUE for negative
2083 * In case of success %0 is returned and @buf and @size are updated with
2084 * the amount of bytes written.
2086 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2087 bool neg)
2089 int len;
2090 char tmp[TMPBUFLEN], *p = tmp;
2092 sprintf(p, "%s%lu", neg ? "-" : "", val);
2093 len = strlen(tmp);
2094 if (len > *size)
2095 len = *size;
2096 if (copy_to_user(*buf, tmp, len))
2097 return -EFAULT;
2098 *size -= len;
2099 *buf += len;
2100 return 0;
2102 #undef TMPBUFLEN
2104 static int proc_put_char(void __user **buf, size_t *size, char c)
2106 if (*size) {
2107 char __user **buffer = (char __user **)buf;
2108 if (put_user(c, *buffer))
2109 return -EFAULT;
2110 (*size)--, (*buffer)++;
2111 *buf = *buffer;
2113 return 0;
2116 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2117 int *valp,
2118 int write, void *data)
2120 if (write) {
2121 if (*negp) {
2122 if (*lvalp > (unsigned long) INT_MAX + 1)
2123 return -EINVAL;
2124 *valp = -*lvalp;
2125 } else {
2126 if (*lvalp > (unsigned long) INT_MAX)
2127 return -EINVAL;
2128 *valp = *lvalp;
2130 } else {
2131 int val = *valp;
2132 if (val < 0) {
2133 *negp = true;
2134 *lvalp = -(unsigned long)val;
2135 } else {
2136 *negp = false;
2137 *lvalp = (unsigned long)val;
2140 return 0;
2143 static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2144 int *valp,
2145 int write, void *data)
2147 if (write) {
2148 if (*negp)
2149 return -EINVAL;
2150 *valp = *lvalp;
2151 } else {
2152 unsigned int val = *valp;
2153 *lvalp = (unsigned long)val;
2155 return 0;
2158 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2160 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2161 int write, void __user *buffer,
2162 size_t *lenp, loff_t *ppos,
2163 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2164 int write, void *data),
2165 void *data)
2167 int *i, vleft, first = 1, err = 0;
2168 size_t left;
2169 char *kbuf = NULL, *p;
2171 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2172 *lenp = 0;
2173 return 0;
2176 i = (int *) tbl_data;
2177 vleft = table->maxlen / sizeof(*i);
2178 left = *lenp;
2180 if (!conv)
2181 conv = do_proc_dointvec_conv;
2183 if (write) {
2184 if (*ppos) {
2185 switch (sysctl_writes_strict) {
2186 case SYSCTL_WRITES_STRICT:
2187 goto out;
2188 case SYSCTL_WRITES_WARN:
2189 warn_sysctl_write(table);
2190 break;
2191 default:
2192 break;
2196 if (left > PAGE_SIZE - 1)
2197 left = PAGE_SIZE - 1;
2198 p = kbuf = memdup_user_nul(buffer, left);
2199 if (IS_ERR(kbuf))
2200 return PTR_ERR(kbuf);
2203 for (; left && vleft--; i++, first=0) {
2204 unsigned long lval;
2205 bool neg;
2207 if (write) {
2208 left -= proc_skip_spaces(&p);
2210 if (!left)
2211 break;
2212 err = proc_get_long(&p, &left, &lval, &neg,
2213 proc_wspace_sep,
2214 sizeof(proc_wspace_sep), NULL);
2215 if (err)
2216 break;
2217 if (conv(&neg, &lval, i, 1, data)) {
2218 err = -EINVAL;
2219 break;
2221 } else {
2222 if (conv(&neg, &lval, i, 0, data)) {
2223 err = -EINVAL;
2224 break;
2226 if (!first)
2227 err = proc_put_char(&buffer, &left, '\t');
2228 if (err)
2229 break;
2230 err = proc_put_long(&buffer, &left, lval, neg);
2231 if (err)
2232 break;
2236 if (!write && !first && left && !err)
2237 err = proc_put_char(&buffer, &left, '\n');
2238 if (write && !err && left)
2239 left -= proc_skip_spaces(&p);
2240 if (write) {
2241 kfree(kbuf);
2242 if (first)
2243 return err ? : -EINVAL;
2245 *lenp -= left;
2246 out:
2247 *ppos += *lenp;
2248 return err;
2251 static int do_proc_dointvec(struct ctl_table *table, int write,
2252 void __user *buffer, size_t *lenp, loff_t *ppos,
2253 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2254 int write, void *data),
2255 void *data)
2257 return __do_proc_dointvec(table->data, table, write,
2258 buffer, lenp, ppos, conv, data);
2262 * proc_dointvec - read a vector of integers
2263 * @table: the sysctl table
2264 * @write: %TRUE if this is a write to the sysctl file
2265 * @buffer: the user buffer
2266 * @lenp: the size of the user buffer
2267 * @ppos: file position
2269 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2270 * values from/to the user buffer, treated as an ASCII string.
2272 * Returns 0 on success.
2274 int proc_dointvec(struct ctl_table *table, int write,
2275 void __user *buffer, size_t *lenp, loff_t *ppos)
2277 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2281 * proc_douintvec - read a vector of unsigned integers
2282 * @table: the sysctl table
2283 * @write: %TRUE if this is a write to the sysctl file
2284 * @buffer: the user buffer
2285 * @lenp: the size of the user buffer
2286 * @ppos: file position
2288 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2289 * values from/to the user buffer, treated as an ASCII string.
2291 * Returns 0 on success.
2293 int proc_douintvec(struct ctl_table *table, int write,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2296 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2297 do_proc_douintvec_conv, NULL);
2301 * Taint values can only be increased
2302 * This means we can safely use a temporary.
2304 static int proc_taint(struct ctl_table *table, int write,
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2307 struct ctl_table t;
2308 unsigned long tmptaint = get_taint();
2309 int err;
2311 if (write && !capable(CAP_SYS_ADMIN))
2312 return -EPERM;
2314 t = *table;
2315 t.data = &tmptaint;
2316 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2317 if (err < 0)
2318 return err;
2320 if (write) {
2322 * Poor man's atomic or. Not worth adding a primitive
2323 * to everyone's atomic.h for this
2325 int i;
2326 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2327 if ((tmptaint >> i) & 1)
2328 add_taint(i, LOCKDEP_STILL_OK);
2332 return err;
2335 #ifdef CONFIG_PRINTK
2336 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2337 void __user *buffer, size_t *lenp, loff_t *ppos)
2339 if (write && !capable(CAP_SYS_ADMIN))
2340 return -EPERM;
2342 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2344 #endif
2346 struct do_proc_dointvec_minmax_conv_param {
2347 int *min;
2348 int *max;
2351 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2352 int *valp,
2353 int write, void *data)
2355 struct do_proc_dointvec_minmax_conv_param *param = data;
2356 if (write) {
2357 int val = *negp ? -*lvalp : *lvalp;
2358 if ((param->min && *param->min > val) ||
2359 (param->max && *param->max < val))
2360 return -EINVAL;
2361 *valp = val;
2362 } else {
2363 int val = *valp;
2364 if (val < 0) {
2365 *negp = true;
2366 *lvalp = -(unsigned long)val;
2367 } else {
2368 *negp = false;
2369 *lvalp = (unsigned long)val;
2372 return 0;
2376 * proc_dointvec_minmax - read a vector of integers with min/max values
2377 * @table: the sysctl table
2378 * @write: %TRUE if this is a write to the sysctl file
2379 * @buffer: the user buffer
2380 * @lenp: the size of the user buffer
2381 * @ppos: file position
2383 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2384 * values from/to the user buffer, treated as an ASCII string.
2386 * This routine will ensure the values are within the range specified by
2387 * table->extra1 (min) and table->extra2 (max).
2389 * Returns 0 on success.
2391 int proc_dointvec_minmax(struct ctl_table *table, int write,
2392 void __user *buffer, size_t *lenp, loff_t *ppos)
2394 struct do_proc_dointvec_minmax_conv_param param = {
2395 .min = (int *) table->extra1,
2396 .max = (int *) table->extra2,
2398 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2399 do_proc_dointvec_minmax_conv, &param);
2402 static void validate_coredump_safety(void)
2404 #ifdef CONFIG_COREDUMP
2405 if (suid_dumpable == SUID_DUMP_ROOT &&
2406 core_pattern[0] != '/' && core_pattern[0] != '|') {
2407 printk(KERN_WARNING "Unsafe core_pattern used with "\
2408 "suid_dumpable=2. Pipe handler or fully qualified "\
2409 "core dump path required.\n");
2411 #endif
2414 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2415 void __user *buffer, size_t *lenp, loff_t *ppos)
2417 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2418 if (!error)
2419 validate_coredump_safety();
2420 return error;
2423 #ifdef CONFIG_COREDUMP
2424 static int proc_dostring_coredump(struct ctl_table *table, int write,
2425 void __user *buffer, size_t *lenp, loff_t *ppos)
2427 int error = proc_dostring(table, write, buffer, lenp, ppos);
2428 if (!error)
2429 validate_coredump_safety();
2430 return error;
2432 #endif
2434 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2435 void __user *buffer,
2436 size_t *lenp, loff_t *ppos,
2437 unsigned long convmul,
2438 unsigned long convdiv)
2440 unsigned long *i, *min, *max;
2441 int vleft, first = 1, err = 0;
2442 size_t left;
2443 char *kbuf = NULL, *p;
2445 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2446 *lenp = 0;
2447 return 0;
2450 i = (unsigned long *) data;
2451 min = (unsigned long *) table->extra1;
2452 max = (unsigned long *) table->extra2;
2453 vleft = table->maxlen / sizeof(unsigned long);
2454 left = *lenp;
2456 if (write) {
2457 if (*ppos) {
2458 switch (sysctl_writes_strict) {
2459 case SYSCTL_WRITES_STRICT:
2460 goto out;
2461 case SYSCTL_WRITES_WARN:
2462 warn_sysctl_write(table);
2463 break;
2464 default:
2465 break;
2469 if (left > PAGE_SIZE - 1)
2470 left = PAGE_SIZE - 1;
2471 p = kbuf = memdup_user_nul(buffer, left);
2472 if (IS_ERR(kbuf))
2473 return PTR_ERR(kbuf);
2476 for (; left && vleft--; i++, first = 0) {
2477 unsigned long val;
2479 if (write) {
2480 bool neg;
2482 left -= proc_skip_spaces(&p);
2484 err = proc_get_long(&p, &left, &val, &neg,
2485 proc_wspace_sep,
2486 sizeof(proc_wspace_sep), NULL);
2487 if (err)
2488 break;
2489 if (neg)
2490 continue;
2491 if ((min && val < *min) || (max && val > *max))
2492 continue;
2493 *i = val;
2494 } else {
2495 val = convdiv * (*i) / convmul;
2496 if (!first) {
2497 err = proc_put_char(&buffer, &left, '\t');
2498 if (err)
2499 break;
2501 err = proc_put_long(&buffer, &left, val, false);
2502 if (err)
2503 break;
2507 if (!write && !first && left && !err)
2508 err = proc_put_char(&buffer, &left, '\n');
2509 if (write && !err)
2510 left -= proc_skip_spaces(&p);
2511 if (write) {
2512 kfree(kbuf);
2513 if (first)
2514 return err ? : -EINVAL;
2516 *lenp -= left;
2517 out:
2518 *ppos += *lenp;
2519 return err;
2522 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2523 void __user *buffer,
2524 size_t *lenp, loff_t *ppos,
2525 unsigned long convmul,
2526 unsigned long convdiv)
2528 return __do_proc_doulongvec_minmax(table->data, table, write,
2529 buffer, lenp, ppos, convmul, convdiv);
2533 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2534 * @table: the sysctl table
2535 * @write: %TRUE if this is a write to the sysctl file
2536 * @buffer: the user buffer
2537 * @lenp: the size of the user buffer
2538 * @ppos: file position
2540 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2541 * values from/to the user buffer, treated as an ASCII string.
2543 * This routine will ensure the values are within the range specified by
2544 * table->extra1 (min) and table->extra2 (max).
2546 * Returns 0 on success.
2548 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2549 void __user *buffer, size_t *lenp, loff_t *ppos)
2551 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2555 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2556 * @table: the sysctl table
2557 * @write: %TRUE if this is a write to the sysctl file
2558 * @buffer: the user buffer
2559 * @lenp: the size of the user buffer
2560 * @ppos: file position
2562 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2563 * values from/to the user buffer, treated as an ASCII string. The values
2564 * are treated as milliseconds, and converted to jiffies when they are stored.
2566 * This routine will ensure the values are within the range specified by
2567 * table->extra1 (min) and table->extra2 (max).
2569 * Returns 0 on success.
2571 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2572 void __user *buffer,
2573 size_t *lenp, loff_t *ppos)
2575 return do_proc_doulongvec_minmax(table, write, buffer,
2576 lenp, ppos, HZ, 1000l);
2580 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2581 int *valp,
2582 int write, void *data)
2584 if (write) {
2585 if (*lvalp > LONG_MAX / HZ)
2586 return 1;
2587 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2588 } else {
2589 int val = *valp;
2590 unsigned long lval;
2591 if (val < 0) {
2592 *negp = true;
2593 lval = -(unsigned long)val;
2594 } else {
2595 *negp = false;
2596 lval = (unsigned long)val;
2598 *lvalp = lval / HZ;
2600 return 0;
2603 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2604 int *valp,
2605 int write, void *data)
2607 if (write) {
2608 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2609 return 1;
2610 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2611 } else {
2612 int val = *valp;
2613 unsigned long lval;
2614 if (val < 0) {
2615 *negp = true;
2616 lval = -(unsigned long)val;
2617 } else {
2618 *negp = false;
2619 lval = (unsigned long)val;
2621 *lvalp = jiffies_to_clock_t(lval);
2623 return 0;
2626 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2627 int *valp,
2628 int write, void *data)
2630 if (write) {
2631 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2633 if (jif > INT_MAX)
2634 return 1;
2635 *valp = (int)jif;
2636 } else {
2637 int val = *valp;
2638 unsigned long lval;
2639 if (val < 0) {
2640 *negp = true;
2641 lval = -(unsigned long)val;
2642 } else {
2643 *negp = false;
2644 lval = (unsigned long)val;
2646 *lvalp = jiffies_to_msecs(lval);
2648 return 0;
2652 * proc_dointvec_jiffies - read a vector of integers as seconds
2653 * @table: the sysctl table
2654 * @write: %TRUE if this is a write to the sysctl file
2655 * @buffer: the user buffer
2656 * @lenp: the size of the user buffer
2657 * @ppos: file position
2659 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2660 * values from/to the user buffer, treated as an ASCII string.
2661 * The values read are assumed to be in seconds, and are converted into
2662 * jiffies.
2664 * Returns 0 on success.
2666 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2667 void __user *buffer, size_t *lenp, loff_t *ppos)
2669 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2670 do_proc_dointvec_jiffies_conv,NULL);
2674 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2675 * @table: the sysctl table
2676 * @write: %TRUE if this is a write to the sysctl file
2677 * @buffer: the user buffer
2678 * @lenp: the size of the user buffer
2679 * @ppos: pointer to the file position
2681 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2682 * values from/to the user buffer, treated as an ASCII string.
2683 * The values read are assumed to be in 1/USER_HZ seconds, and
2684 * are converted into jiffies.
2686 * Returns 0 on success.
2688 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2689 void __user *buffer, size_t *lenp, loff_t *ppos)
2691 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2692 do_proc_dointvec_userhz_jiffies_conv,NULL);
2696 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2697 * @table: the sysctl table
2698 * @write: %TRUE if this is a write to the sysctl file
2699 * @buffer: the user buffer
2700 * @lenp: the size of the user buffer
2701 * @ppos: file position
2702 * @ppos: the current position in the file
2704 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2705 * values from/to the user buffer, treated as an ASCII string.
2706 * The values read are assumed to be in 1/1000 seconds, and
2707 * are converted into jiffies.
2709 * Returns 0 on success.
2711 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2712 void __user *buffer, size_t *lenp, loff_t *ppos)
2714 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2715 do_proc_dointvec_ms_jiffies_conv, NULL);
2718 static int proc_do_cad_pid(struct ctl_table *table, int write,
2719 void __user *buffer, size_t *lenp, loff_t *ppos)
2721 struct pid *new_pid;
2722 pid_t tmp;
2723 int r;
2725 tmp = pid_vnr(cad_pid);
2727 r = __do_proc_dointvec(&tmp, table, write, buffer,
2728 lenp, ppos, NULL, NULL);
2729 if (r || !write)
2730 return r;
2732 new_pid = find_get_pid(tmp);
2733 if (!new_pid)
2734 return -ESRCH;
2736 put_pid(xchg(&cad_pid, new_pid));
2737 return 0;
2741 * proc_do_large_bitmap - read/write from/to a large bitmap
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
2744 * @buffer: the user buffer
2745 * @lenp: the size of the user buffer
2746 * @ppos: file position
2748 * The bitmap is stored at table->data and the bitmap length (in bits)
2749 * in table->maxlen.
2751 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2752 * large bitmaps may be represented in a compact manner. Writing into
2753 * the file will clear the bitmap then update it with the given input.
2755 * Returns 0 on success.
2757 int proc_do_large_bitmap(struct ctl_table *table, int write,
2758 void __user *buffer, size_t *lenp, loff_t *ppos)
2760 int err = 0;
2761 bool first = 1;
2762 size_t left = *lenp;
2763 unsigned long bitmap_len = table->maxlen;
2764 unsigned long *bitmap = *(unsigned long **) table->data;
2765 unsigned long *tmp_bitmap = NULL;
2766 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2768 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2769 *lenp = 0;
2770 return 0;
2773 if (write) {
2774 char *kbuf, *p;
2776 if (left > PAGE_SIZE - 1)
2777 left = PAGE_SIZE - 1;
2779 p = kbuf = memdup_user_nul(buffer, left);
2780 if (IS_ERR(kbuf))
2781 return PTR_ERR(kbuf);
2783 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2784 GFP_KERNEL);
2785 if (!tmp_bitmap) {
2786 kfree(kbuf);
2787 return -ENOMEM;
2789 proc_skip_char(&p, &left, '\n');
2790 while (!err && left) {
2791 unsigned long val_a, val_b;
2792 bool neg;
2794 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
2795 sizeof(tr_a), &c);
2796 if (err)
2797 break;
2798 if (val_a >= bitmap_len || neg) {
2799 err = -EINVAL;
2800 break;
2803 val_b = val_a;
2804 if (left) {
2805 p++;
2806 left--;
2809 if (c == '-') {
2810 err = proc_get_long(&p, &left, &val_b,
2811 &neg, tr_b, sizeof(tr_b),
2812 &c);
2813 if (err)
2814 break;
2815 if (val_b >= bitmap_len || neg ||
2816 val_a > val_b) {
2817 err = -EINVAL;
2818 break;
2820 if (left) {
2821 p++;
2822 left--;
2826 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2827 first = 0;
2828 proc_skip_char(&p, &left, '\n');
2830 kfree(kbuf);
2831 } else {
2832 unsigned long bit_a, bit_b = 0;
2834 while (left) {
2835 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2836 if (bit_a >= bitmap_len)
2837 break;
2838 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2839 bit_a + 1) - 1;
2841 if (!first) {
2842 err = proc_put_char(&buffer, &left, ',');
2843 if (err)
2844 break;
2846 err = proc_put_long(&buffer, &left, bit_a, false);
2847 if (err)
2848 break;
2849 if (bit_a != bit_b) {
2850 err = proc_put_char(&buffer, &left, '-');
2851 if (err)
2852 break;
2853 err = proc_put_long(&buffer, &left, bit_b, false);
2854 if (err)
2855 break;
2858 first = 0; bit_b++;
2860 if (!err)
2861 err = proc_put_char(&buffer, &left, '\n');
2864 if (!err) {
2865 if (write) {
2866 if (*ppos)
2867 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2868 else
2869 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2871 kfree(tmp_bitmap);
2872 *lenp -= left;
2873 *ppos += *lenp;
2874 return 0;
2875 } else {
2876 kfree(tmp_bitmap);
2877 return err;
2881 #else /* CONFIG_PROC_SYSCTL */
2883 int proc_dostring(struct ctl_table *table, int write,
2884 void __user *buffer, size_t *lenp, loff_t *ppos)
2886 return -ENOSYS;
2889 int proc_dointvec(struct ctl_table *table, int write,
2890 void __user *buffer, size_t *lenp, loff_t *ppos)
2892 return -ENOSYS;
2895 int proc_douintvec(struct ctl_table *table, int write,
2896 void __user *buffer, size_t *lenp, loff_t *ppos)
2898 return -ENOSYS;
2901 int proc_dointvec_minmax(struct ctl_table *table, int write,
2902 void __user *buffer, size_t *lenp, loff_t *ppos)
2904 return -ENOSYS;
2907 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2908 void __user *buffer, size_t *lenp, loff_t *ppos)
2910 return -ENOSYS;
2913 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2914 void __user *buffer, size_t *lenp, loff_t *ppos)
2916 return -ENOSYS;
2919 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2920 void __user *buffer, size_t *lenp, loff_t *ppos)
2922 return -ENOSYS;
2925 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2926 void __user *buffer, size_t *lenp, loff_t *ppos)
2928 return -ENOSYS;
2931 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2932 void __user *buffer,
2933 size_t *lenp, loff_t *ppos)
2935 return -ENOSYS;
2939 #endif /* CONFIG_PROC_SYSCTL */
2942 * No sense putting this after each symbol definition, twice,
2943 * exception granted :-)
2945 EXPORT_SYMBOL(proc_dointvec);
2946 EXPORT_SYMBOL(proc_douintvec);
2947 EXPORT_SYMBOL(proc_dointvec_jiffies);
2948 EXPORT_SYMBOL(proc_dointvec_minmax);
2949 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2950 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2951 EXPORT_SYMBOL(proc_dostring);
2952 EXPORT_SYMBOL(proc_doulongvec_minmax);
2953 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);