dm thin metadata: fix __udivdi3 undefined on 32-bit
[linux/fpc-iii.git] / kernel / sysctl.c
blob66100d1bc3f7dfef86d0a97d630f593dc2f29c78
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>
68 #include <linux/mount.h>
70 #include <asm/uaccess.h>
71 #include <asm/processor.h>
73 #ifdef CONFIG_X86
74 #include <asm/nmi.h>
75 #include <asm/stacktrace.h>
76 #include <asm/io.h>
77 #endif
78 #ifdef CONFIG_SPARC
79 #include <asm/setup.h>
80 #endif
81 #ifdef CONFIG_BSD_PROCESS_ACCT
82 #include <linux/acct.h>
83 #endif
84 #ifdef CONFIG_RT_MUTEXES
85 #include <linux/rtmutex.h>
86 #endif
87 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
88 #include <linux/lockdep.h>
89 #endif
90 #ifdef CONFIG_CHR_DEV_SG
91 #include <scsi/sg.h>
92 #endif
94 #ifdef CONFIG_LOCKUP_DETECTOR
95 #include <linux/nmi.h>
96 #endif
98 #if defined(CONFIG_SYSCTL)
100 /* External variables not in a header file. */
101 extern int suid_dumpable;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid;
104 extern char core_pattern[];
105 extern unsigned int core_pipe_limit;
106 #endif
107 extern int pid_max;
108 extern int pid_max_min, pid_max_max;
109 extern int percpu_pagelist_fraction;
110 extern int compat_log;
111 extern int latencytop_enabled;
112 extern 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 #ifdef CONFIG_PRINTK
131 static int ten_thousand = 10000;
132 #endif
134 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
135 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
137 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
138 static int maxolduid = 65535;
139 static int minolduid;
141 static int ngroups_max = NGROUPS_MAX;
142 static const int cap_last_cap = CAP_LAST_CAP;
144 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
145 #ifdef CONFIG_DETECT_HUNG_TASK
146 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
147 #endif
149 #ifdef CONFIG_INOTIFY_USER
150 #include <linux/inotify.h>
151 #endif
152 #ifdef CONFIG_SPARC
153 #endif
155 #ifdef __hppa__
156 extern int pwrsw_enabled;
157 #endif
159 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
160 extern int unaligned_enabled;
161 #endif
163 #ifdef CONFIG_IA64
164 extern int unaligned_dump_stack;
165 #endif
167 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168 extern int no_unaligned_warning;
169 #endif
171 #ifdef CONFIG_PROC_SYSCTL
173 #define SYSCTL_WRITES_LEGACY -1
174 #define SYSCTL_WRITES_WARN 0
175 #define SYSCTL_WRITES_STRICT 1
177 static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
179 static int proc_do_cad_pid(struct ctl_table *table, int write,
180 void __user *buffer, size_t *lenp, loff_t *ppos);
181 static int proc_taint(struct ctl_table *table, int write,
182 void __user *buffer, size_t *lenp, loff_t *ppos);
183 #endif
185 #ifdef CONFIG_PRINTK
186 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
187 void __user *buffer, size_t *lenp, loff_t *ppos);
188 #endif
190 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
192 #ifdef CONFIG_COREDUMP
193 static int proc_dostring_coredump(struct ctl_table *table, int write,
194 void __user *buffer, size_t *lenp, loff_t *ppos);
195 #endif
197 #ifdef CONFIG_MAGIC_SYSRQ
198 /* Note: sysrq code uses it's own private copy */
199 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
201 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
202 void __user *buffer, size_t *lenp,
203 loff_t *ppos)
205 int error;
207 error = proc_dointvec(table, write, buffer, lenp, ppos);
208 if (error)
209 return error;
211 if (write)
212 sysrq_toggle_support(__sysrq_enabled);
214 return 0;
217 #endif
219 static struct ctl_table kern_table[];
220 static struct ctl_table vm_table[];
221 static struct ctl_table fs_table[];
222 static struct ctl_table debug_table[];
223 static struct ctl_table dev_table[];
224 extern struct ctl_table random_table[];
225 #ifdef CONFIG_EPOLL
226 extern struct ctl_table epoll_table[];
227 #endif
229 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
230 int sysctl_legacy_va_layout;
231 #endif
233 /* The default sysctl tables: */
235 static struct ctl_table sysctl_base_table[] = {
237 .procname = "kernel",
238 .mode = 0555,
239 .child = kern_table,
242 .procname = "vm",
243 .mode = 0555,
244 .child = vm_table,
247 .procname = "fs",
248 .mode = 0555,
249 .child = fs_table,
252 .procname = "debug",
253 .mode = 0555,
254 .child = debug_table,
257 .procname = "dev",
258 .mode = 0555,
259 .child = dev_table,
264 #ifdef CONFIG_SCHED_DEBUG
265 static int min_sched_granularity_ns = 100000; /* 100 usecs */
266 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
267 static int min_wakeup_granularity_ns; /* 0 usecs */
268 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
269 #ifdef CONFIG_SMP
270 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
271 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
272 #endif /* CONFIG_SMP */
273 #endif /* CONFIG_SCHED_DEBUG */
275 #ifdef CONFIG_COMPACTION
276 static int min_extfrag_threshold;
277 static int max_extfrag_threshold = 1000;
278 #endif
280 static struct ctl_table kern_table[] = {
282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = proc_dointvec,
288 #ifdef CONFIG_SCHED_DEBUG
290 .procname = "sched_min_granularity_ns",
291 .data = &sysctl_sched_min_granularity,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = sched_proc_update_handler,
295 .extra1 = &min_sched_granularity_ns,
296 .extra2 = &max_sched_granularity_ns,
299 .procname = "sched_latency_ns",
300 .data = &sysctl_sched_latency,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
303 .proc_handler = sched_proc_update_handler,
304 .extra1 = &min_sched_granularity_ns,
305 .extra2 = &max_sched_granularity_ns,
308 .procname = "sched_wakeup_granularity_ns",
309 .data = &sysctl_sched_wakeup_granularity,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = sched_proc_update_handler,
313 .extra1 = &min_wakeup_granularity_ns,
314 .extra2 = &max_wakeup_granularity_ns,
316 #ifdef CONFIG_SMP
318 .procname = "sched_tunable_scaling",
319 .data = &sysctl_sched_tunable_scaling,
320 .maxlen = sizeof(enum sched_tunable_scaling),
321 .mode = 0644,
322 .proc_handler = sched_proc_update_handler,
323 .extra1 = &min_sched_tunable_scaling,
324 .extra2 = &max_sched_tunable_scaling,
327 .procname = "sched_migration_cost_ns",
328 .data = &sysctl_sched_migration_cost,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec,
334 .procname = "sched_nr_migrate",
335 .data = &sysctl_sched_nr_migrate,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec,
341 .procname = "sched_time_avg_ms",
342 .data = &sysctl_sched_time_avg,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = proc_dointvec_minmax,
346 .extra1 = &one,
349 .procname = "sched_shares_window_ns",
350 .data = &sysctl_sched_shares_window,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = proc_dointvec,
355 #endif /* CONFIG_SMP */
356 #ifdef CONFIG_NUMA_BALANCING
358 .procname = "numa_balancing_scan_delay_ms",
359 .data = &sysctl_numa_balancing_scan_delay,
360 .maxlen = sizeof(unsigned int),
361 .mode = 0644,
362 .proc_handler = proc_dointvec,
365 .procname = "numa_balancing_scan_period_min_ms",
366 .data = &sysctl_numa_balancing_scan_period_min,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
369 .proc_handler = proc_dointvec,
372 .procname = "numa_balancing_scan_period_max_ms",
373 .data = &sysctl_numa_balancing_scan_period_max,
374 .maxlen = sizeof(unsigned int),
375 .mode = 0644,
376 .proc_handler = proc_dointvec,
379 .procname = "numa_balancing_scan_size_mb",
380 .data = &sysctl_numa_balancing_scan_size,
381 .maxlen = sizeof(unsigned int),
382 .mode = 0644,
383 .proc_handler = proc_dointvec_minmax,
384 .extra1 = &one,
387 .procname = "numa_balancing",
388 .data = NULL, /* filled in by handler */
389 .maxlen = sizeof(unsigned int),
390 .mode = 0644,
391 .proc_handler = sysctl_numa_balancing,
392 .extra1 = &zero,
393 .extra2 = &one,
395 #endif /* CONFIG_NUMA_BALANCING */
396 #endif /* CONFIG_SCHED_DEBUG */
398 .procname = "sched_rt_period_us",
399 .data = &sysctl_sched_rt_period,
400 .maxlen = sizeof(unsigned int),
401 .mode = 0644,
402 .proc_handler = sched_rt_handler,
405 .procname = "sched_rt_runtime_us",
406 .data = &sysctl_sched_rt_runtime,
407 .maxlen = sizeof(int),
408 .mode = 0644,
409 .proc_handler = sched_rt_handler,
412 .procname = "sched_rr_timeslice_ms",
413 .data = &sched_rr_timeslice,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = sched_rr_handler,
418 #ifdef CONFIG_SCHED_AUTOGROUP
420 .procname = "sched_autogroup_enabled",
421 .data = &sysctl_sched_autogroup_enabled,
422 .maxlen = sizeof(unsigned int),
423 .mode = 0644,
424 .proc_handler = proc_dointvec_minmax,
425 .extra1 = &zero,
426 .extra2 = &one,
428 #endif
429 #ifdef CONFIG_CFS_BANDWIDTH
431 .procname = "sched_cfs_bandwidth_slice_us",
432 .data = &sysctl_sched_cfs_bandwidth_slice,
433 .maxlen = sizeof(unsigned int),
434 .mode = 0644,
435 .proc_handler = proc_dointvec_minmax,
436 .extra1 = &one,
438 #endif
439 #ifdef CONFIG_PROVE_LOCKING
441 .procname = "prove_locking",
442 .data = &prove_locking,
443 .maxlen = sizeof(int),
444 .mode = 0644,
445 .proc_handler = proc_dointvec,
447 #endif
448 #ifdef CONFIG_LOCK_STAT
450 .procname = "lock_stat",
451 .data = &lock_stat,
452 .maxlen = sizeof(int),
453 .mode = 0644,
454 .proc_handler = proc_dointvec,
456 #endif
458 .procname = "panic",
459 .data = &panic_timeout,
460 .maxlen = sizeof(int),
461 .mode = 0644,
462 .proc_handler = proc_dointvec,
464 #ifdef CONFIG_COREDUMP
466 .procname = "core_uses_pid",
467 .data = &core_uses_pid,
468 .maxlen = sizeof(int),
469 .mode = 0644,
470 .proc_handler = proc_dointvec,
473 .procname = "core_pattern",
474 .data = core_pattern,
475 .maxlen = CORENAME_MAX_SIZE,
476 .mode = 0644,
477 .proc_handler = proc_dostring_coredump,
480 .procname = "core_pipe_limit",
481 .data = &core_pipe_limit,
482 .maxlen = sizeof(unsigned int),
483 .mode = 0644,
484 .proc_handler = proc_dointvec,
486 #endif
487 #ifdef CONFIG_PROC_SYSCTL
489 .procname = "tainted",
490 .maxlen = sizeof(long),
491 .mode = 0644,
492 .proc_handler = proc_taint,
495 .procname = "sysctl_writes_strict",
496 .data = &sysctl_writes_strict,
497 .maxlen = sizeof(int),
498 .mode = 0644,
499 .proc_handler = proc_dointvec_minmax,
500 .extra1 = &neg_one,
501 .extra2 = &one,
503 #endif
504 #ifdef CONFIG_LATENCYTOP
506 .procname = "latencytop",
507 .data = &latencytop_enabled,
508 .maxlen = sizeof(int),
509 .mode = 0644,
510 .proc_handler = proc_dointvec,
512 #endif
513 #ifdef CONFIG_BLK_DEV_INITRD
515 .procname = "real-root-dev",
516 .data = &real_root_dev,
517 .maxlen = sizeof(int),
518 .mode = 0644,
519 .proc_handler = proc_dointvec,
521 #endif
523 .procname = "print-fatal-signals",
524 .data = &print_fatal_signals,
525 .maxlen = sizeof(int),
526 .mode = 0644,
527 .proc_handler = proc_dointvec,
529 #ifdef CONFIG_SPARC
531 .procname = "reboot-cmd",
532 .data = reboot_command,
533 .maxlen = 256,
534 .mode = 0644,
535 .proc_handler = proc_dostring,
538 .procname = "stop-a",
539 .data = &stop_a_enabled,
540 .maxlen = sizeof (int),
541 .mode = 0644,
542 .proc_handler = proc_dointvec,
545 .procname = "scons-poweroff",
546 .data = &scons_pwroff,
547 .maxlen = sizeof (int),
548 .mode = 0644,
549 .proc_handler = proc_dointvec,
551 #endif
552 #ifdef CONFIG_SPARC64
554 .procname = "tsb-ratio",
555 .data = &sysctl_tsb_ratio,
556 .maxlen = sizeof (int),
557 .mode = 0644,
558 .proc_handler = proc_dointvec,
560 #endif
561 #ifdef __hppa__
563 .procname = "soft-power",
564 .data = &pwrsw_enabled,
565 .maxlen = sizeof (int),
566 .mode = 0644,
567 .proc_handler = proc_dointvec,
569 #endif
570 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
572 .procname = "unaligned-trap",
573 .data = &unaligned_enabled,
574 .maxlen = sizeof (int),
575 .mode = 0644,
576 .proc_handler = proc_dointvec,
578 #endif
580 .procname = "ctrl-alt-del",
581 .data = &C_A_D,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = proc_dointvec,
586 #ifdef CONFIG_FUNCTION_TRACER
588 .procname = "ftrace_enabled",
589 .data = &ftrace_enabled,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 .proc_handler = ftrace_enable_sysctl,
594 #endif
595 #ifdef CONFIG_STACK_TRACER
597 .procname = "stack_tracer_enabled",
598 .data = &stack_tracer_enabled,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = stack_trace_sysctl,
603 #endif
604 #ifdef CONFIG_TRACING
606 .procname = "ftrace_dump_on_oops",
607 .data = &ftrace_dump_on_oops,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = proc_dointvec,
613 .procname = "traceoff_on_warning",
614 .data = &__disable_trace_on_warning,
615 .maxlen = sizeof(__disable_trace_on_warning),
616 .mode = 0644,
617 .proc_handler = proc_dointvec,
620 .procname = "tracepoint_printk",
621 .data = &tracepoint_printk,
622 .maxlen = sizeof(tracepoint_printk),
623 .mode = 0644,
624 .proc_handler = proc_dointvec,
626 #endif
627 #ifdef CONFIG_KEXEC_CORE
629 .procname = "kexec_load_disabled",
630 .data = &kexec_load_disabled,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 /* only handle a transition from default "0" to "1" */
634 .proc_handler = proc_dointvec_minmax,
635 .extra1 = &one,
636 .extra2 = &one,
638 #endif
639 #ifdef CONFIG_MODULES
641 .procname = "modprobe",
642 .data = &modprobe_path,
643 .maxlen = KMOD_PATH_LEN,
644 .mode = 0644,
645 .proc_handler = proc_dostring,
648 .procname = "modules_disabled",
649 .data = &modules_disabled,
650 .maxlen = sizeof(int),
651 .mode = 0644,
652 /* only handle a transition from default "0" to "1" */
653 .proc_handler = proc_dointvec_minmax,
654 .extra1 = &one,
655 .extra2 = &one,
657 #endif
658 #ifdef CONFIG_UEVENT_HELPER
660 .procname = "hotplug",
661 .data = &uevent_helper,
662 .maxlen = UEVENT_HELPER_PATH_LEN,
663 .mode = 0644,
664 .proc_handler = proc_dostring,
666 #endif
667 #ifdef CONFIG_CHR_DEV_SG
669 .procname = "sg-big-buff",
670 .data = &sg_big_buff,
671 .maxlen = sizeof (int),
672 .mode = 0444,
673 .proc_handler = proc_dointvec,
675 #endif
676 #ifdef CONFIG_BSD_PROCESS_ACCT
678 .procname = "acct",
679 .data = &acct_parm,
680 .maxlen = 3*sizeof(int),
681 .mode = 0644,
682 .proc_handler = proc_dointvec,
684 #endif
685 #ifdef CONFIG_MAGIC_SYSRQ
687 .procname = "sysrq",
688 .data = &__sysrq_enabled,
689 .maxlen = sizeof (int),
690 .mode = 0644,
691 .proc_handler = sysrq_sysctl_handler,
693 #endif
694 #ifdef CONFIG_PROC_SYSCTL
696 .procname = "cad_pid",
697 .data = NULL,
698 .maxlen = sizeof (int),
699 .mode = 0600,
700 .proc_handler = proc_do_cad_pid,
702 #endif
704 .procname = "threads-max",
705 .data = NULL,
706 .maxlen = sizeof(int),
707 .mode = 0644,
708 .proc_handler = sysctl_max_threads,
711 .procname = "random",
712 .mode = 0555,
713 .child = random_table,
716 .procname = "usermodehelper",
717 .mode = 0555,
718 .child = usermodehelper_table,
721 .procname = "overflowuid",
722 .data = &overflowuid,
723 .maxlen = sizeof(int),
724 .mode = 0644,
725 .proc_handler = proc_dointvec_minmax,
726 .extra1 = &minolduid,
727 .extra2 = &maxolduid,
730 .procname = "overflowgid",
731 .data = &overflowgid,
732 .maxlen = sizeof(int),
733 .mode = 0644,
734 .proc_handler = proc_dointvec_minmax,
735 .extra1 = &minolduid,
736 .extra2 = &maxolduid,
738 #ifdef CONFIG_S390
739 #ifdef CONFIG_MATHEMU
741 .procname = "ieee_emulation_warnings",
742 .data = &sysctl_ieee_emulation_warnings,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = proc_dointvec,
747 #endif
749 .procname = "userprocess_debug",
750 .data = &show_unhandled_signals,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = proc_dointvec,
755 #endif
757 .procname = "pid_max",
758 .data = &pid_max,
759 .maxlen = sizeof (int),
760 .mode = 0644,
761 .proc_handler = proc_dointvec_minmax,
762 .extra1 = &pid_max_min,
763 .extra2 = &pid_max_max,
766 .procname = "panic_on_oops",
767 .data = &panic_on_oops,
768 .maxlen = sizeof(int),
769 .mode = 0644,
770 .proc_handler = proc_dointvec,
772 #if defined CONFIG_PRINTK
774 .procname = "printk",
775 .data = &console_loglevel,
776 .maxlen = 4*sizeof(int),
777 .mode = 0644,
778 .proc_handler = proc_dointvec,
781 .procname = "printk_ratelimit",
782 .data = &printk_ratelimit_state.interval,
783 .maxlen = sizeof(int),
784 .mode = 0644,
785 .proc_handler = proc_dointvec_jiffies,
788 .procname = "printk_ratelimit_burst",
789 .data = &printk_ratelimit_state.burst,
790 .maxlen = sizeof(int),
791 .mode = 0644,
792 .proc_handler = proc_dointvec,
795 .procname = "printk_delay",
796 .data = &printk_delay_msec,
797 .maxlen = sizeof(int),
798 .mode = 0644,
799 .proc_handler = proc_dointvec_minmax,
800 .extra1 = &zero,
801 .extra2 = &ten_thousand,
804 .procname = "dmesg_restrict",
805 .data = &dmesg_restrict,
806 .maxlen = sizeof(int),
807 .mode = 0644,
808 .proc_handler = proc_dointvec_minmax_sysadmin,
809 .extra1 = &zero,
810 .extra2 = &one,
813 .procname = "kptr_restrict",
814 .data = &kptr_restrict,
815 .maxlen = sizeof(int),
816 .mode = 0644,
817 .proc_handler = proc_dointvec_minmax_sysadmin,
818 .extra1 = &zero,
819 .extra2 = &two,
821 #endif
823 .procname = "ngroups_max",
824 .data = &ngroups_max,
825 .maxlen = sizeof (int),
826 .mode = 0444,
827 .proc_handler = proc_dointvec,
830 .procname = "cap_last_cap",
831 .data = (void *)&cap_last_cap,
832 .maxlen = sizeof(int),
833 .mode = 0444,
834 .proc_handler = proc_dointvec,
836 #if defined(CONFIG_LOCKUP_DETECTOR)
838 .procname = "watchdog",
839 .data = &watchdog_user_enabled,
840 .maxlen = sizeof (int),
841 .mode = 0644,
842 .proc_handler = proc_watchdog,
843 .extra1 = &zero,
844 .extra2 = &one,
847 .procname = "watchdog_thresh",
848 .data = &watchdog_thresh,
849 .maxlen = sizeof(int),
850 .mode = 0644,
851 .proc_handler = proc_watchdog_thresh,
852 .extra1 = &zero,
853 .extra2 = &sixty,
856 .procname = "nmi_watchdog",
857 .data = &nmi_watchdog_enabled,
858 .maxlen = sizeof (int),
859 .mode = 0644,
860 .proc_handler = proc_nmi_watchdog,
861 .extra1 = &zero,
862 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
863 .extra2 = &one,
864 #else
865 .extra2 = &zero,
866 #endif
869 .procname = "soft_watchdog",
870 .data = &soft_watchdog_enabled,
871 .maxlen = sizeof (int),
872 .mode = 0644,
873 .proc_handler = proc_soft_watchdog,
874 .extra1 = &zero,
875 .extra2 = &one,
878 .procname = "watchdog_cpumask",
879 .data = &watchdog_cpumask_bits,
880 .maxlen = NR_CPUS,
881 .mode = 0644,
882 .proc_handler = proc_watchdog_cpumask,
885 .procname = "softlockup_panic",
886 .data = &softlockup_panic,
887 .maxlen = sizeof(int),
888 .mode = 0644,
889 .proc_handler = proc_dointvec_minmax,
890 .extra1 = &zero,
891 .extra2 = &one,
893 #ifdef CONFIG_HARDLOCKUP_DETECTOR
895 .procname = "hardlockup_panic",
896 .data = &hardlockup_panic,
897 .maxlen = sizeof(int),
898 .mode = 0644,
899 .proc_handler = proc_dointvec_minmax,
900 .extra1 = &zero,
901 .extra2 = &one,
903 #endif
904 #ifdef CONFIG_SMP
906 .procname = "softlockup_all_cpu_backtrace",
907 .data = &sysctl_softlockup_all_cpu_backtrace,
908 .maxlen = sizeof(int),
909 .mode = 0644,
910 .proc_handler = proc_dointvec_minmax,
911 .extra1 = &zero,
912 .extra2 = &one,
915 .procname = "hardlockup_all_cpu_backtrace",
916 .data = &sysctl_hardlockup_all_cpu_backtrace,
917 .maxlen = sizeof(int),
918 .mode = 0644,
919 .proc_handler = proc_dointvec_minmax,
920 .extra1 = &zero,
921 .extra2 = &one,
923 #endif /* CONFIG_SMP */
924 #endif
925 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
927 .procname = "unknown_nmi_panic",
928 .data = &unknown_nmi_panic,
929 .maxlen = sizeof (int),
930 .mode = 0644,
931 .proc_handler = proc_dointvec,
933 #endif
934 #if defined(CONFIG_X86)
936 .procname = "panic_on_unrecovered_nmi",
937 .data = &panic_on_unrecovered_nmi,
938 .maxlen = sizeof(int),
939 .mode = 0644,
940 .proc_handler = proc_dointvec,
943 .procname = "panic_on_io_nmi",
944 .data = &panic_on_io_nmi,
945 .maxlen = sizeof(int),
946 .mode = 0644,
947 .proc_handler = proc_dointvec,
949 #ifdef CONFIG_DEBUG_STACKOVERFLOW
951 .procname = "panic_on_stackoverflow",
952 .data = &sysctl_panic_on_stackoverflow,
953 .maxlen = sizeof(int),
954 .mode = 0644,
955 .proc_handler = proc_dointvec,
957 #endif
959 .procname = "bootloader_type",
960 .data = &bootloader_type,
961 .maxlen = sizeof (int),
962 .mode = 0444,
963 .proc_handler = proc_dointvec,
966 .procname = "bootloader_version",
967 .data = &bootloader_version,
968 .maxlen = sizeof (int),
969 .mode = 0444,
970 .proc_handler = proc_dointvec,
973 .procname = "kstack_depth_to_print",
974 .data = &kstack_depth_to_print,
975 .maxlen = sizeof(int),
976 .mode = 0644,
977 .proc_handler = proc_dointvec,
980 .procname = "io_delay_type",
981 .data = &io_delay_type,
982 .maxlen = sizeof(int),
983 .mode = 0644,
984 .proc_handler = proc_dointvec,
986 #endif
987 #if defined(CONFIG_MMU)
989 .procname = "randomize_va_space",
990 .data = &randomize_va_space,
991 .maxlen = sizeof(int),
992 .mode = 0644,
993 .proc_handler = proc_dointvec,
995 #endif
996 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
998 .procname = "spin_retry",
999 .data = &spin_retry,
1000 .maxlen = sizeof (int),
1001 .mode = 0644,
1002 .proc_handler = proc_dointvec,
1004 #endif
1005 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1007 .procname = "acpi_video_flags",
1008 .data = &acpi_realmode_flags,
1009 .maxlen = sizeof (unsigned long),
1010 .mode = 0644,
1011 .proc_handler = proc_doulongvec_minmax,
1013 #endif
1014 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1016 .procname = "ignore-unaligned-usertrap",
1017 .data = &no_unaligned_warning,
1018 .maxlen = sizeof (int),
1019 .mode = 0644,
1020 .proc_handler = proc_dointvec,
1022 #endif
1023 #ifdef CONFIG_IA64
1025 .procname = "unaligned-dump-stack",
1026 .data = &unaligned_dump_stack,
1027 .maxlen = sizeof (int),
1028 .mode = 0644,
1029 .proc_handler = proc_dointvec,
1031 #endif
1032 #ifdef CONFIG_DETECT_HUNG_TASK
1034 .procname = "hung_task_panic",
1035 .data = &sysctl_hung_task_panic,
1036 .maxlen = sizeof(int),
1037 .mode = 0644,
1038 .proc_handler = proc_dointvec_minmax,
1039 .extra1 = &zero,
1040 .extra2 = &one,
1043 .procname = "hung_task_check_count",
1044 .data = &sysctl_hung_task_check_count,
1045 .maxlen = sizeof(int),
1046 .mode = 0644,
1047 .proc_handler = proc_dointvec_minmax,
1048 .extra1 = &zero,
1051 .procname = "hung_task_timeout_secs",
1052 .data = &sysctl_hung_task_timeout_secs,
1053 .maxlen = sizeof(unsigned long),
1054 .mode = 0644,
1055 .proc_handler = proc_dohung_task_timeout_secs,
1056 .extra2 = &hung_task_timeout_max,
1059 .procname = "hung_task_warnings",
1060 .data = &sysctl_hung_task_warnings,
1061 .maxlen = sizeof(int),
1062 .mode = 0644,
1063 .proc_handler = proc_dointvec_minmax,
1064 .extra1 = &neg_one,
1066 #endif
1067 #ifdef CONFIG_COMPAT
1069 .procname = "compat-log",
1070 .data = &compat_log,
1071 .maxlen = sizeof (int),
1072 .mode = 0644,
1073 .proc_handler = proc_dointvec,
1075 #endif
1076 #ifdef CONFIG_RT_MUTEXES
1078 .procname = "max_lock_depth",
1079 .data = &max_lock_depth,
1080 .maxlen = sizeof(int),
1081 .mode = 0644,
1082 .proc_handler = proc_dointvec,
1084 #endif
1086 .procname = "poweroff_cmd",
1087 .data = &poweroff_cmd,
1088 .maxlen = POWEROFF_CMD_PATH_LEN,
1089 .mode = 0644,
1090 .proc_handler = proc_dostring,
1092 #ifdef CONFIG_KEYS
1094 .procname = "keys",
1095 .mode = 0555,
1096 .child = key_sysctls,
1098 #endif
1099 #ifdef CONFIG_PERF_EVENTS
1101 * User-space scripts rely on the existence of this file
1102 * as a feature check for perf_events being enabled.
1104 * So it's an ABI, do not remove!
1107 .procname = "perf_event_paranoid",
1108 .data = &sysctl_perf_event_paranoid,
1109 .maxlen = sizeof(sysctl_perf_event_paranoid),
1110 .mode = 0644,
1111 .proc_handler = proc_dointvec,
1114 .procname = "perf_event_mlock_kb",
1115 .data = &sysctl_perf_event_mlock,
1116 .maxlen = sizeof(sysctl_perf_event_mlock),
1117 .mode = 0644,
1118 .proc_handler = proc_dointvec,
1121 .procname = "perf_event_max_sample_rate",
1122 .data = &sysctl_perf_event_sample_rate,
1123 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1124 .mode = 0644,
1125 .proc_handler = perf_proc_update_handler,
1126 .extra1 = &one,
1129 .procname = "perf_cpu_time_max_percent",
1130 .data = &sysctl_perf_cpu_time_max_percent,
1131 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1132 .mode = 0644,
1133 .proc_handler = perf_cpu_time_max_percent_handler,
1134 .extra1 = &zero,
1135 .extra2 = &one_hundred,
1137 #endif
1138 #ifdef CONFIG_KMEMCHECK
1140 .procname = "kmemcheck",
1141 .data = &kmemcheck_enabled,
1142 .maxlen = sizeof(int),
1143 .mode = 0644,
1144 .proc_handler = proc_dointvec,
1146 #endif
1148 .procname = "panic_on_warn",
1149 .data = &panic_on_warn,
1150 .maxlen = sizeof(int),
1151 .mode = 0644,
1152 .proc_handler = proc_dointvec_minmax,
1153 .extra1 = &zero,
1154 .extra2 = &one,
1156 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1158 .procname = "timer_migration",
1159 .data = &sysctl_timer_migration,
1160 .maxlen = sizeof(unsigned int),
1161 .mode = 0644,
1162 .proc_handler = timer_migration_handler,
1163 .extra1 = &zero,
1164 .extra2 = &one,
1166 #endif
1167 #ifdef CONFIG_BPF_SYSCALL
1169 .procname = "unprivileged_bpf_disabled",
1170 .data = &sysctl_unprivileged_bpf_disabled,
1171 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1172 .mode = 0644,
1173 /* only handle a transition from default "0" to "1" */
1174 .proc_handler = proc_dointvec_minmax,
1175 .extra1 = &one,
1176 .extra2 = &one,
1178 #endif
1182 static struct ctl_table vm_table[] = {
1184 .procname = "overcommit_memory",
1185 .data = &sysctl_overcommit_memory,
1186 .maxlen = sizeof(sysctl_overcommit_memory),
1187 .mode = 0644,
1188 .proc_handler = proc_dointvec_minmax,
1189 .extra1 = &zero,
1190 .extra2 = &two,
1193 .procname = "panic_on_oom",
1194 .data = &sysctl_panic_on_oom,
1195 .maxlen = sizeof(sysctl_panic_on_oom),
1196 .mode = 0644,
1197 .proc_handler = proc_dointvec_minmax,
1198 .extra1 = &zero,
1199 .extra2 = &two,
1202 .procname = "oom_kill_allocating_task",
1203 .data = &sysctl_oom_kill_allocating_task,
1204 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1205 .mode = 0644,
1206 .proc_handler = proc_dointvec,
1209 .procname = "oom_dump_tasks",
1210 .data = &sysctl_oom_dump_tasks,
1211 .maxlen = sizeof(sysctl_oom_dump_tasks),
1212 .mode = 0644,
1213 .proc_handler = proc_dointvec,
1216 .procname = "overcommit_ratio",
1217 .data = &sysctl_overcommit_ratio,
1218 .maxlen = sizeof(sysctl_overcommit_ratio),
1219 .mode = 0644,
1220 .proc_handler = overcommit_ratio_handler,
1223 .procname = "overcommit_kbytes",
1224 .data = &sysctl_overcommit_kbytes,
1225 .maxlen = sizeof(sysctl_overcommit_kbytes),
1226 .mode = 0644,
1227 .proc_handler = overcommit_kbytes_handler,
1230 .procname = "page-cluster",
1231 .data = &page_cluster,
1232 .maxlen = sizeof(int),
1233 .mode = 0644,
1234 .proc_handler = proc_dointvec_minmax,
1235 .extra1 = &zero,
1238 .procname = "dirty_background_ratio",
1239 .data = &dirty_background_ratio,
1240 .maxlen = sizeof(dirty_background_ratio),
1241 .mode = 0644,
1242 .proc_handler = dirty_background_ratio_handler,
1243 .extra1 = &zero,
1244 .extra2 = &one_hundred,
1247 .procname = "dirty_background_bytes",
1248 .data = &dirty_background_bytes,
1249 .maxlen = sizeof(dirty_background_bytes),
1250 .mode = 0644,
1251 .proc_handler = dirty_background_bytes_handler,
1252 .extra1 = &one_ul,
1255 .procname = "dirty_ratio",
1256 .data = &vm_dirty_ratio,
1257 .maxlen = sizeof(vm_dirty_ratio),
1258 .mode = 0644,
1259 .proc_handler = dirty_ratio_handler,
1260 .extra1 = &zero,
1261 .extra2 = &one_hundred,
1264 .procname = "dirty_bytes",
1265 .data = &vm_dirty_bytes,
1266 .maxlen = sizeof(vm_dirty_bytes),
1267 .mode = 0644,
1268 .proc_handler = dirty_bytes_handler,
1269 .extra1 = &dirty_bytes_min,
1272 .procname = "dirty_writeback_centisecs",
1273 .data = &dirty_writeback_interval,
1274 .maxlen = sizeof(dirty_writeback_interval),
1275 .mode = 0644,
1276 .proc_handler = dirty_writeback_centisecs_handler,
1279 .procname = "dirty_expire_centisecs",
1280 .data = &dirty_expire_interval,
1281 .maxlen = sizeof(dirty_expire_interval),
1282 .mode = 0644,
1283 .proc_handler = proc_dointvec_minmax,
1284 .extra1 = &zero,
1287 .procname = "dirtytime_expire_seconds",
1288 .data = &dirtytime_expire_interval,
1289 .maxlen = sizeof(dirty_expire_interval),
1290 .mode = 0644,
1291 .proc_handler = dirtytime_interval_handler,
1292 .extra1 = &zero,
1295 .procname = "nr_pdflush_threads",
1296 .mode = 0444 /* read-only */,
1297 .proc_handler = pdflush_proc_obsolete,
1300 .procname = "swappiness",
1301 .data = &vm_swappiness,
1302 .maxlen = sizeof(vm_swappiness),
1303 .mode = 0644,
1304 .proc_handler = proc_dointvec_minmax,
1305 .extra1 = &zero,
1306 .extra2 = &one_hundred,
1308 #ifdef CONFIG_HUGETLB_PAGE
1310 .procname = "nr_hugepages",
1311 .data = NULL,
1312 .maxlen = sizeof(unsigned long),
1313 .mode = 0644,
1314 .proc_handler = hugetlb_sysctl_handler,
1316 #ifdef CONFIG_NUMA
1318 .procname = "nr_hugepages_mempolicy",
1319 .data = NULL,
1320 .maxlen = sizeof(unsigned long),
1321 .mode = 0644,
1322 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1324 #endif
1326 .procname = "hugetlb_shm_group",
1327 .data = &sysctl_hugetlb_shm_group,
1328 .maxlen = sizeof(gid_t),
1329 .mode = 0644,
1330 .proc_handler = proc_dointvec,
1333 .procname = "hugepages_treat_as_movable",
1334 .data = &hugepages_treat_as_movable,
1335 .maxlen = sizeof(int),
1336 .mode = 0644,
1337 .proc_handler = proc_dointvec,
1340 .procname = "nr_overcommit_hugepages",
1341 .data = NULL,
1342 .maxlen = sizeof(unsigned long),
1343 .mode = 0644,
1344 .proc_handler = hugetlb_overcommit_handler,
1346 #endif
1348 .procname = "lowmem_reserve_ratio",
1349 .data = &sysctl_lowmem_reserve_ratio,
1350 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1351 .mode = 0644,
1352 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1355 .procname = "drop_caches",
1356 .data = &sysctl_drop_caches,
1357 .maxlen = sizeof(int),
1358 .mode = 0644,
1359 .proc_handler = drop_caches_sysctl_handler,
1360 .extra1 = &one,
1361 .extra2 = &four,
1363 #ifdef CONFIG_COMPACTION
1365 .procname = "compact_memory",
1366 .data = &sysctl_compact_memory,
1367 .maxlen = sizeof(int),
1368 .mode = 0200,
1369 .proc_handler = sysctl_compaction_handler,
1372 .procname = "extfrag_threshold",
1373 .data = &sysctl_extfrag_threshold,
1374 .maxlen = sizeof(int),
1375 .mode = 0644,
1376 .proc_handler = sysctl_extfrag_handler,
1377 .extra1 = &min_extfrag_threshold,
1378 .extra2 = &max_extfrag_threshold,
1381 .procname = "compact_unevictable_allowed",
1382 .data = &sysctl_compact_unevictable_allowed,
1383 .maxlen = sizeof(int),
1384 .mode = 0644,
1385 .proc_handler = proc_dointvec,
1386 .extra1 = &zero,
1387 .extra2 = &one,
1390 #endif /* CONFIG_COMPACTION */
1392 .procname = "min_free_kbytes",
1393 .data = &min_free_kbytes,
1394 .maxlen = sizeof(min_free_kbytes),
1395 .mode = 0644,
1396 .proc_handler = min_free_kbytes_sysctl_handler,
1397 .extra1 = &zero,
1400 .procname = "percpu_pagelist_fraction",
1401 .data = &percpu_pagelist_fraction,
1402 .maxlen = sizeof(percpu_pagelist_fraction),
1403 .mode = 0644,
1404 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1405 .extra1 = &zero,
1407 #ifdef CONFIG_MMU
1409 .procname = "max_map_count",
1410 .data = &sysctl_max_map_count,
1411 .maxlen = sizeof(sysctl_max_map_count),
1412 .mode = 0644,
1413 .proc_handler = proc_dointvec_minmax,
1414 .extra1 = &zero,
1416 #else
1418 .procname = "nr_trim_pages",
1419 .data = &sysctl_nr_trim_pages,
1420 .maxlen = sizeof(sysctl_nr_trim_pages),
1421 .mode = 0644,
1422 .proc_handler = proc_dointvec_minmax,
1423 .extra1 = &zero,
1425 #endif
1427 .procname = "laptop_mode",
1428 .data = &laptop_mode,
1429 .maxlen = sizeof(laptop_mode),
1430 .mode = 0644,
1431 .proc_handler = proc_dointvec_jiffies,
1434 .procname = "block_dump",
1435 .data = &block_dump,
1436 .maxlen = sizeof(block_dump),
1437 .mode = 0644,
1438 .proc_handler = proc_dointvec,
1439 .extra1 = &zero,
1442 .procname = "vfs_cache_pressure",
1443 .data = &sysctl_vfs_cache_pressure,
1444 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1445 .mode = 0644,
1446 .proc_handler = proc_dointvec,
1447 .extra1 = &zero,
1449 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1451 .procname = "legacy_va_layout",
1452 .data = &sysctl_legacy_va_layout,
1453 .maxlen = sizeof(sysctl_legacy_va_layout),
1454 .mode = 0644,
1455 .proc_handler = proc_dointvec,
1456 .extra1 = &zero,
1458 #endif
1459 #ifdef CONFIG_NUMA
1461 .procname = "zone_reclaim_mode",
1462 .data = &zone_reclaim_mode,
1463 .maxlen = sizeof(zone_reclaim_mode),
1464 .mode = 0644,
1465 .proc_handler = proc_dointvec,
1466 .extra1 = &zero,
1469 .procname = "min_unmapped_ratio",
1470 .data = &sysctl_min_unmapped_ratio,
1471 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1472 .mode = 0644,
1473 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1474 .extra1 = &zero,
1475 .extra2 = &one_hundred,
1478 .procname = "min_slab_ratio",
1479 .data = &sysctl_min_slab_ratio,
1480 .maxlen = sizeof(sysctl_min_slab_ratio),
1481 .mode = 0644,
1482 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1483 .extra1 = &zero,
1484 .extra2 = &one_hundred,
1486 #endif
1487 #ifdef CONFIG_SMP
1489 .procname = "stat_interval",
1490 .data = &sysctl_stat_interval,
1491 .maxlen = sizeof(sysctl_stat_interval),
1492 .mode = 0644,
1493 .proc_handler = proc_dointvec_jiffies,
1495 #endif
1496 #ifdef CONFIG_MMU
1498 .procname = "mmap_min_addr",
1499 .data = &dac_mmap_min_addr,
1500 .maxlen = sizeof(unsigned long),
1501 .mode = 0644,
1502 .proc_handler = mmap_min_addr_handler,
1504 #endif
1505 #ifdef CONFIG_NUMA
1507 .procname = "numa_zonelist_order",
1508 .data = &numa_zonelist_order,
1509 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1510 .mode = 0644,
1511 .proc_handler = numa_zonelist_order_handler,
1513 #endif
1514 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1515 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1517 .procname = "vdso_enabled",
1518 #ifdef CONFIG_X86_32
1519 .data = &vdso32_enabled,
1520 .maxlen = sizeof(vdso32_enabled),
1521 #else
1522 .data = &vdso_enabled,
1523 .maxlen = sizeof(vdso_enabled),
1524 #endif
1525 .mode = 0644,
1526 .proc_handler = proc_dointvec,
1527 .extra1 = &zero,
1529 #endif
1530 #ifdef CONFIG_HIGHMEM
1532 .procname = "highmem_is_dirtyable",
1533 .data = &vm_highmem_is_dirtyable,
1534 .maxlen = sizeof(vm_highmem_is_dirtyable),
1535 .mode = 0644,
1536 .proc_handler = proc_dointvec_minmax,
1537 .extra1 = &zero,
1538 .extra2 = &one,
1540 #endif
1541 #ifdef CONFIG_MEMORY_FAILURE
1543 .procname = "memory_failure_early_kill",
1544 .data = &sysctl_memory_failure_early_kill,
1545 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1546 .mode = 0644,
1547 .proc_handler = proc_dointvec_minmax,
1548 .extra1 = &zero,
1549 .extra2 = &one,
1552 .procname = "memory_failure_recovery",
1553 .data = &sysctl_memory_failure_recovery,
1554 .maxlen = sizeof(sysctl_memory_failure_recovery),
1555 .mode = 0644,
1556 .proc_handler = proc_dointvec_minmax,
1557 .extra1 = &zero,
1558 .extra2 = &one,
1560 #endif
1562 .procname = "user_reserve_kbytes",
1563 .data = &sysctl_user_reserve_kbytes,
1564 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1565 .mode = 0644,
1566 .proc_handler = proc_doulongvec_minmax,
1569 .procname = "admin_reserve_kbytes",
1570 .data = &sysctl_admin_reserve_kbytes,
1571 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1572 .mode = 0644,
1573 .proc_handler = proc_doulongvec_minmax,
1578 static struct ctl_table fs_table[] = {
1580 .procname = "inode-nr",
1581 .data = &inodes_stat,
1582 .maxlen = 2*sizeof(long),
1583 .mode = 0444,
1584 .proc_handler = proc_nr_inodes,
1587 .procname = "inode-state",
1588 .data = &inodes_stat,
1589 .maxlen = 7*sizeof(long),
1590 .mode = 0444,
1591 .proc_handler = proc_nr_inodes,
1594 .procname = "file-nr",
1595 .data = &files_stat,
1596 .maxlen = sizeof(files_stat),
1597 .mode = 0444,
1598 .proc_handler = proc_nr_files,
1601 .procname = "file-max",
1602 .data = &files_stat.max_files,
1603 .maxlen = sizeof(files_stat.max_files),
1604 .mode = 0644,
1605 .proc_handler = proc_doulongvec_minmax,
1608 .procname = "nr_open",
1609 .data = &sysctl_nr_open,
1610 .maxlen = sizeof(int),
1611 .mode = 0644,
1612 .proc_handler = proc_dointvec_minmax,
1613 .extra1 = &sysctl_nr_open_min,
1614 .extra2 = &sysctl_nr_open_max,
1617 .procname = "dentry-state",
1618 .data = &dentry_stat,
1619 .maxlen = 6*sizeof(long),
1620 .mode = 0444,
1621 .proc_handler = proc_nr_dentry,
1624 .procname = "overflowuid",
1625 .data = &fs_overflowuid,
1626 .maxlen = sizeof(int),
1627 .mode = 0644,
1628 .proc_handler = proc_dointvec_minmax,
1629 .extra1 = &minolduid,
1630 .extra2 = &maxolduid,
1633 .procname = "overflowgid",
1634 .data = &fs_overflowgid,
1635 .maxlen = sizeof(int),
1636 .mode = 0644,
1637 .proc_handler = proc_dointvec_minmax,
1638 .extra1 = &minolduid,
1639 .extra2 = &maxolduid,
1641 #ifdef CONFIG_FILE_LOCKING
1643 .procname = "leases-enable",
1644 .data = &leases_enable,
1645 .maxlen = sizeof(int),
1646 .mode = 0644,
1647 .proc_handler = proc_dointvec,
1649 #endif
1650 #ifdef CONFIG_DNOTIFY
1652 .procname = "dir-notify-enable",
1653 .data = &dir_notify_enable,
1654 .maxlen = sizeof(int),
1655 .mode = 0644,
1656 .proc_handler = proc_dointvec,
1658 #endif
1659 #ifdef CONFIG_MMU
1660 #ifdef CONFIG_FILE_LOCKING
1662 .procname = "lease-break-time",
1663 .data = &lease_break_time,
1664 .maxlen = sizeof(int),
1665 .mode = 0644,
1666 .proc_handler = proc_dointvec,
1668 #endif
1669 #ifdef CONFIG_AIO
1671 .procname = "aio-nr",
1672 .data = &aio_nr,
1673 .maxlen = sizeof(aio_nr),
1674 .mode = 0444,
1675 .proc_handler = proc_doulongvec_minmax,
1678 .procname = "aio-max-nr",
1679 .data = &aio_max_nr,
1680 .maxlen = sizeof(aio_max_nr),
1681 .mode = 0644,
1682 .proc_handler = proc_doulongvec_minmax,
1684 #endif /* CONFIG_AIO */
1685 #ifdef CONFIG_INOTIFY_USER
1687 .procname = "inotify",
1688 .mode = 0555,
1689 .child = inotify_table,
1691 #endif
1692 #ifdef CONFIG_EPOLL
1694 .procname = "epoll",
1695 .mode = 0555,
1696 .child = epoll_table,
1698 #endif
1699 #endif
1701 .procname = "protected_symlinks",
1702 .data = &sysctl_protected_symlinks,
1703 .maxlen = sizeof(int),
1704 .mode = 0600,
1705 .proc_handler = proc_dointvec_minmax,
1706 .extra1 = &zero,
1707 .extra2 = &one,
1710 .procname = "protected_hardlinks",
1711 .data = &sysctl_protected_hardlinks,
1712 .maxlen = sizeof(int),
1713 .mode = 0600,
1714 .proc_handler = proc_dointvec_minmax,
1715 .extra1 = &zero,
1716 .extra2 = &one,
1719 .procname = "suid_dumpable",
1720 .data = &suid_dumpable,
1721 .maxlen = sizeof(int),
1722 .mode = 0644,
1723 .proc_handler = proc_dointvec_minmax_coredump,
1724 .extra1 = &zero,
1725 .extra2 = &two,
1727 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1729 .procname = "binfmt_misc",
1730 .mode = 0555,
1731 .child = sysctl_mount_point,
1733 #endif
1735 .procname = "pipe-max-size",
1736 .data = &pipe_max_size,
1737 .maxlen = sizeof(int),
1738 .mode = 0644,
1739 .proc_handler = &pipe_proc_fn,
1740 .extra1 = &pipe_min_size,
1743 .procname = "pipe-user-pages-hard",
1744 .data = &pipe_user_pages_hard,
1745 .maxlen = sizeof(pipe_user_pages_hard),
1746 .mode = 0644,
1747 .proc_handler = proc_doulongvec_minmax,
1750 .procname = "pipe-user-pages-soft",
1751 .data = &pipe_user_pages_soft,
1752 .maxlen = sizeof(pipe_user_pages_soft),
1753 .mode = 0644,
1754 .proc_handler = proc_doulongvec_minmax,
1757 .procname = "mount-max",
1758 .data = &sysctl_mount_max,
1759 .maxlen = sizeof(unsigned int),
1760 .mode = 0644,
1761 .proc_handler = proc_dointvec_minmax,
1762 .extra1 = &one,
1767 static struct ctl_table debug_table[] = {
1768 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1770 .procname = "exception-trace",
1771 .data = &show_unhandled_signals,
1772 .maxlen = sizeof(int),
1773 .mode = 0644,
1774 .proc_handler = proc_dointvec
1776 #endif
1777 #if defined(CONFIG_OPTPROBES)
1779 .procname = "kprobes-optimization",
1780 .data = &sysctl_kprobes_optimization,
1781 .maxlen = sizeof(int),
1782 .mode = 0644,
1783 .proc_handler = proc_kprobes_optimization_handler,
1784 .extra1 = &zero,
1785 .extra2 = &one,
1787 #endif
1791 static struct ctl_table dev_table[] = {
1795 int __init sysctl_init(void)
1797 struct ctl_table_header *hdr;
1799 hdr = register_sysctl_table(sysctl_base_table);
1800 kmemleak_not_leak(hdr);
1801 return 0;
1804 #endif /* CONFIG_SYSCTL */
1807 * /proc/sys support
1810 #ifdef CONFIG_PROC_SYSCTL
1812 static int _proc_do_string(char *data, int maxlen, int write,
1813 char __user *buffer,
1814 size_t *lenp, loff_t *ppos)
1816 size_t len;
1817 char __user *p;
1818 char c;
1820 if (!data || !maxlen || !*lenp) {
1821 *lenp = 0;
1822 return 0;
1825 if (write) {
1826 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1827 /* Only continue writes not past the end of buffer. */
1828 len = strlen(data);
1829 if (len > maxlen - 1)
1830 len = maxlen - 1;
1832 if (*ppos > len)
1833 return 0;
1834 len = *ppos;
1835 } else {
1836 /* Start writing from beginning of buffer. */
1837 len = 0;
1840 *ppos += *lenp;
1841 p = buffer;
1842 while ((p - buffer) < *lenp && len < maxlen - 1) {
1843 if (get_user(c, p++))
1844 return -EFAULT;
1845 if (c == 0 || c == '\n')
1846 break;
1847 data[len++] = c;
1849 data[len] = 0;
1850 } else {
1851 len = strlen(data);
1852 if (len > maxlen)
1853 len = maxlen;
1855 if (*ppos > len) {
1856 *lenp = 0;
1857 return 0;
1860 data += *ppos;
1861 len -= *ppos;
1863 if (len > *lenp)
1864 len = *lenp;
1865 if (len)
1866 if (copy_to_user(buffer, data, len))
1867 return -EFAULT;
1868 if (len < *lenp) {
1869 if (put_user('\n', buffer + len))
1870 return -EFAULT;
1871 len++;
1873 *lenp = len;
1874 *ppos += len;
1876 return 0;
1879 static void warn_sysctl_write(struct ctl_table *table)
1881 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1882 "This will not be supported in the future. To silence this\n"
1883 "warning, set kernel.sysctl_writes_strict = -1\n",
1884 current->comm, table->procname);
1888 * proc_dostring - read a string sysctl
1889 * @table: the sysctl table
1890 * @write: %TRUE if this is a write to the sysctl file
1891 * @buffer: the user buffer
1892 * @lenp: the size of the user buffer
1893 * @ppos: file position
1895 * Reads/writes a string from/to the user buffer. If the kernel
1896 * buffer provided is not large enough to hold the string, the
1897 * string is truncated. The copied string is %NULL-terminated.
1898 * If the string is being read by the user process, it is copied
1899 * and a newline '\n' is added. It is truncated if the buffer is
1900 * not large enough.
1902 * Returns 0 on success.
1904 int proc_dostring(struct ctl_table *table, int write,
1905 void __user *buffer, size_t *lenp, loff_t *ppos)
1907 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1908 warn_sysctl_write(table);
1910 return _proc_do_string((char *)(table->data), table->maxlen, write,
1911 (char __user *)buffer, lenp, ppos);
1914 static size_t proc_skip_spaces(char **buf)
1916 size_t ret;
1917 char *tmp = skip_spaces(*buf);
1918 ret = tmp - *buf;
1919 *buf = tmp;
1920 return ret;
1923 static void proc_skip_char(char **buf, size_t *size, const char v)
1925 while (*size) {
1926 if (**buf != v)
1927 break;
1928 (*size)--;
1929 (*buf)++;
1933 #define TMPBUFLEN 22
1935 * proc_get_long - reads an ASCII formatted integer from a user buffer
1937 * @buf: a kernel buffer
1938 * @size: size of the kernel buffer
1939 * @val: this is where the number will be stored
1940 * @neg: set to %TRUE if number is negative
1941 * @perm_tr: a vector which contains the allowed trailers
1942 * @perm_tr_len: size of the perm_tr vector
1943 * @tr: pointer to store the trailer character
1945 * In case of success %0 is returned and @buf and @size are updated with
1946 * the amount of bytes read. If @tr is non-NULL and a trailing
1947 * character exists (size is non-zero after returning from this
1948 * function), @tr is updated with the trailing character.
1950 static int proc_get_long(char **buf, size_t *size,
1951 unsigned long *val, bool *neg,
1952 const char *perm_tr, unsigned perm_tr_len, char *tr)
1954 int len;
1955 char *p, tmp[TMPBUFLEN];
1957 if (!*size)
1958 return -EINVAL;
1960 len = *size;
1961 if (len > TMPBUFLEN - 1)
1962 len = TMPBUFLEN - 1;
1964 memcpy(tmp, *buf, len);
1966 tmp[len] = 0;
1967 p = tmp;
1968 if (*p == '-' && *size > 1) {
1969 *neg = true;
1970 p++;
1971 } else
1972 *neg = false;
1973 if (!isdigit(*p))
1974 return -EINVAL;
1976 *val = simple_strtoul(p, &p, 0);
1978 len = p - tmp;
1980 /* We don't know if the next char is whitespace thus we may accept
1981 * invalid integers (e.g. 1234...a) or two integers instead of one
1982 * (e.g. 123...1). So lets not allow such large numbers. */
1983 if (len == TMPBUFLEN - 1)
1984 return -EINVAL;
1986 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1987 return -EINVAL;
1989 if (tr && (len < *size))
1990 *tr = *p;
1992 *buf += len;
1993 *size -= len;
1995 return 0;
1999 * proc_put_long - converts an integer to a decimal ASCII formatted string
2001 * @buf: the user buffer
2002 * @size: the size of the user buffer
2003 * @val: the integer to be converted
2004 * @neg: sign of the number, %TRUE for negative
2006 * In case of success %0 is returned and @buf and @size are updated with
2007 * the amount of bytes written.
2009 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2010 bool neg)
2012 int len;
2013 char tmp[TMPBUFLEN], *p = tmp;
2015 sprintf(p, "%s%lu", neg ? "-" : "", val);
2016 len = strlen(tmp);
2017 if (len > *size)
2018 len = *size;
2019 if (copy_to_user(*buf, tmp, len))
2020 return -EFAULT;
2021 *size -= len;
2022 *buf += len;
2023 return 0;
2025 #undef TMPBUFLEN
2027 static int proc_put_char(void __user **buf, size_t *size, char c)
2029 if (*size) {
2030 char __user **buffer = (char __user **)buf;
2031 if (put_user(c, *buffer))
2032 return -EFAULT;
2033 (*size)--, (*buffer)++;
2034 *buf = *buffer;
2036 return 0;
2039 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2040 int *valp,
2041 int write, void *data)
2043 if (write) {
2044 if (*negp) {
2045 if (*lvalp > (unsigned long) INT_MAX + 1)
2046 return -EINVAL;
2047 *valp = -*lvalp;
2048 } else {
2049 if (*lvalp > (unsigned long) INT_MAX)
2050 return -EINVAL;
2051 *valp = *lvalp;
2053 } else {
2054 int val = *valp;
2055 if (val < 0) {
2056 *negp = true;
2057 *lvalp = -(unsigned long)val;
2058 } else {
2059 *negp = false;
2060 *lvalp = (unsigned long)val;
2063 return 0;
2066 static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2067 int *valp,
2068 int write, void *data)
2070 if (write) {
2071 if (*negp)
2072 return -EINVAL;
2073 if (*lvalp > UINT_MAX)
2074 return -EINVAL;
2075 *valp = *lvalp;
2076 } else {
2077 unsigned int val = *valp;
2078 *negp = false;
2079 *lvalp = (unsigned long)val;
2081 return 0;
2084 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2086 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2087 int write, void __user *buffer,
2088 size_t *lenp, loff_t *ppos,
2089 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2090 int write, void *data),
2091 void *data)
2093 int *i, vleft, first = 1, err = 0;
2094 unsigned long page = 0;
2095 size_t left;
2096 char *kbuf;
2098 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2099 *lenp = 0;
2100 return 0;
2103 i = (int *) tbl_data;
2104 vleft = table->maxlen / sizeof(*i);
2105 left = *lenp;
2107 if (!conv)
2108 conv = do_proc_dointvec_conv;
2110 if (write) {
2111 if (*ppos) {
2112 switch (sysctl_writes_strict) {
2113 case SYSCTL_WRITES_STRICT:
2114 goto out;
2115 case SYSCTL_WRITES_WARN:
2116 warn_sysctl_write(table);
2117 break;
2118 default:
2119 break;
2123 if (left > PAGE_SIZE - 1)
2124 left = PAGE_SIZE - 1;
2125 page = __get_free_page(GFP_TEMPORARY);
2126 kbuf = (char *) page;
2127 if (!kbuf)
2128 return -ENOMEM;
2129 if (copy_from_user(kbuf, buffer, left)) {
2130 err = -EFAULT;
2131 goto free;
2133 kbuf[left] = 0;
2136 for (; left && vleft--; i++, first=0) {
2137 unsigned long lval;
2138 bool neg;
2140 if (write) {
2141 left -= proc_skip_spaces(&kbuf);
2143 if (!left)
2144 break;
2145 err = proc_get_long(&kbuf, &left, &lval, &neg,
2146 proc_wspace_sep,
2147 sizeof(proc_wspace_sep), NULL);
2148 if (err)
2149 break;
2150 if (conv(&neg, &lval, i, 1, data)) {
2151 err = -EINVAL;
2152 break;
2154 } else {
2155 if (conv(&neg, &lval, i, 0, data)) {
2156 err = -EINVAL;
2157 break;
2159 if (!first)
2160 err = proc_put_char(&buffer, &left, '\t');
2161 if (err)
2162 break;
2163 err = proc_put_long(&buffer, &left, lval, neg);
2164 if (err)
2165 break;
2169 if (!write && !first && left && !err)
2170 err = proc_put_char(&buffer, &left, '\n');
2171 if (write && !err && left)
2172 left -= proc_skip_spaces(&kbuf);
2173 free:
2174 if (write) {
2175 free_page(page);
2176 if (first)
2177 return err ? : -EINVAL;
2179 *lenp -= left;
2180 out:
2181 *ppos += *lenp;
2182 return err;
2185 static int do_proc_dointvec(struct ctl_table *table, int write,
2186 void __user *buffer, size_t *lenp, loff_t *ppos,
2187 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2188 int write, void *data),
2189 void *data)
2191 return __do_proc_dointvec(table->data, table, write,
2192 buffer, lenp, ppos, conv, data);
2196 * proc_dointvec - read a vector of integers
2197 * @table: the sysctl table
2198 * @write: %TRUE if this is a write to the sysctl file
2199 * @buffer: the user buffer
2200 * @lenp: the size of the user buffer
2201 * @ppos: file position
2203 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2204 * values from/to the user buffer, treated as an ASCII string.
2206 * Returns 0 on success.
2208 int proc_dointvec(struct ctl_table *table, int write,
2209 void __user *buffer, size_t *lenp, loff_t *ppos)
2211 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2215 * proc_douintvec - read a vector of unsigned integers
2216 * @table: the sysctl table
2217 * @write: %TRUE if this is a write to the sysctl file
2218 * @buffer: the user buffer
2219 * @lenp: the size of the user buffer
2220 * @ppos: file position
2222 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2223 * values from/to the user buffer, treated as an ASCII string.
2225 * Returns 0 on success.
2227 int proc_douintvec(struct ctl_table *table, int write,
2228 void __user *buffer, size_t *lenp, loff_t *ppos)
2230 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2231 do_proc_douintvec_conv, NULL);
2235 * Taint values can only be increased
2236 * This means we can safely use a temporary.
2238 static int proc_taint(struct ctl_table *table, int write,
2239 void __user *buffer, size_t *lenp, loff_t *ppos)
2241 struct ctl_table t;
2242 unsigned long tmptaint = get_taint();
2243 int err;
2245 if (write && !capable(CAP_SYS_ADMIN))
2246 return -EPERM;
2248 t = *table;
2249 t.data = &tmptaint;
2250 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2251 if (err < 0)
2252 return err;
2254 if (write) {
2256 * Poor man's atomic or. Not worth adding a primitive
2257 * to everyone's atomic.h for this
2259 int i;
2260 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2261 if ((tmptaint >> i) & 1)
2262 add_taint(i, LOCKDEP_STILL_OK);
2266 return err;
2269 #ifdef CONFIG_PRINTK
2270 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2271 void __user *buffer, size_t *lenp, loff_t *ppos)
2273 if (write && !capable(CAP_SYS_ADMIN))
2274 return -EPERM;
2276 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2278 #endif
2280 struct do_proc_dointvec_minmax_conv_param {
2281 int *min;
2282 int *max;
2285 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2286 int *valp,
2287 int write, void *data)
2289 struct do_proc_dointvec_minmax_conv_param *param = data;
2290 if (write) {
2291 int val = *negp ? -*lvalp : *lvalp;
2292 if ((param->min && *param->min > val) ||
2293 (param->max && *param->max < val))
2294 return -EINVAL;
2295 *valp = val;
2296 } else {
2297 int val = *valp;
2298 if (val < 0) {
2299 *negp = true;
2300 *lvalp = -(unsigned long)val;
2301 } else {
2302 *negp = false;
2303 *lvalp = (unsigned long)val;
2306 return 0;
2310 * proc_dointvec_minmax - read a vector of integers with min/max values
2311 * @table: the sysctl table
2312 * @write: %TRUE if this is a write to the sysctl file
2313 * @buffer: the user buffer
2314 * @lenp: the size of the user buffer
2315 * @ppos: file position
2317 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2318 * values from/to the user buffer, treated as an ASCII string.
2320 * This routine will ensure the values are within the range specified by
2321 * table->extra1 (min) and table->extra2 (max).
2323 * Returns 0 on success.
2325 int proc_dointvec_minmax(struct ctl_table *table, int write,
2326 void __user *buffer, size_t *lenp, loff_t *ppos)
2328 struct do_proc_dointvec_minmax_conv_param param = {
2329 .min = (int *) table->extra1,
2330 .max = (int *) table->extra2,
2332 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2333 do_proc_dointvec_minmax_conv, &param);
2336 static void validate_coredump_safety(void)
2338 #ifdef CONFIG_COREDUMP
2339 if (suid_dumpable == SUID_DUMP_ROOT &&
2340 core_pattern[0] != '/' && core_pattern[0] != '|') {
2341 printk(KERN_WARNING "Unsafe core_pattern used with "\
2342 "suid_dumpable=2. Pipe handler or fully qualified "\
2343 "core dump path required.\n");
2345 #endif
2348 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2349 void __user *buffer, size_t *lenp, loff_t *ppos)
2351 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2352 if (!error)
2353 validate_coredump_safety();
2354 return error;
2357 #ifdef CONFIG_COREDUMP
2358 static int proc_dostring_coredump(struct ctl_table *table, int write,
2359 void __user *buffer, size_t *lenp, loff_t *ppos)
2361 int error = proc_dostring(table, write, buffer, lenp, ppos);
2362 if (!error)
2363 validate_coredump_safety();
2364 return error;
2366 #endif
2368 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2369 void __user *buffer,
2370 size_t *lenp, loff_t *ppos,
2371 unsigned long convmul,
2372 unsigned long convdiv)
2374 unsigned long *i, *min, *max;
2375 int vleft, first = 1, err = 0;
2376 unsigned long page = 0;
2377 size_t left;
2378 char *kbuf;
2380 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2381 *lenp = 0;
2382 return 0;
2385 i = (unsigned long *) data;
2386 min = (unsigned long *) table->extra1;
2387 max = (unsigned long *) table->extra2;
2388 vleft = table->maxlen / sizeof(unsigned long);
2389 left = *lenp;
2391 if (write) {
2392 if (*ppos) {
2393 switch (sysctl_writes_strict) {
2394 case SYSCTL_WRITES_STRICT:
2395 goto out;
2396 case SYSCTL_WRITES_WARN:
2397 warn_sysctl_write(table);
2398 break;
2399 default:
2400 break;
2404 if (left > PAGE_SIZE - 1)
2405 left = PAGE_SIZE - 1;
2406 page = __get_free_page(GFP_TEMPORARY);
2407 kbuf = (char *) page;
2408 if (!kbuf)
2409 return -ENOMEM;
2410 if (copy_from_user(kbuf, buffer, left)) {
2411 err = -EFAULT;
2412 goto free;
2414 kbuf[left] = 0;
2417 for (; left && vleft--; i++, first = 0) {
2418 unsigned long val;
2420 if (write) {
2421 bool neg;
2423 left -= proc_skip_spaces(&kbuf);
2425 err = proc_get_long(&kbuf, &left, &val, &neg,
2426 proc_wspace_sep,
2427 sizeof(proc_wspace_sep), NULL);
2428 if (err)
2429 break;
2430 if (neg)
2431 continue;
2432 val = convmul * val / convdiv;
2433 if ((min && val < *min) || (max && val > *max))
2434 continue;
2435 *i = val;
2436 } else {
2437 val = convdiv * (*i) / convmul;
2438 if (!first) {
2439 err = proc_put_char(&buffer, &left, '\t');
2440 if (err)
2441 break;
2443 err = proc_put_long(&buffer, &left, val, false);
2444 if (err)
2445 break;
2449 if (!write && !first && left && !err)
2450 err = proc_put_char(&buffer, &left, '\n');
2451 if (write && !err)
2452 left -= proc_skip_spaces(&kbuf);
2453 free:
2454 if (write) {
2455 free_page(page);
2456 if (first)
2457 return err ? : -EINVAL;
2459 *lenp -= left;
2460 out:
2461 *ppos += *lenp;
2462 return err;
2465 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2466 void __user *buffer,
2467 size_t *lenp, loff_t *ppos,
2468 unsigned long convmul,
2469 unsigned long convdiv)
2471 return __do_proc_doulongvec_minmax(table->data, table, write,
2472 buffer, lenp, ppos, convmul, convdiv);
2476 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2477 * @table: the sysctl table
2478 * @write: %TRUE if this is a write to the sysctl file
2479 * @buffer: the user buffer
2480 * @lenp: the size of the user buffer
2481 * @ppos: file position
2483 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2484 * values from/to the user buffer, treated as an ASCII string.
2486 * This routine will ensure the values are within the range specified by
2487 * table->extra1 (min) and table->extra2 (max).
2489 * Returns 0 on success.
2491 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2492 void __user *buffer, size_t *lenp, loff_t *ppos)
2494 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2498 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2499 * @table: the sysctl table
2500 * @write: %TRUE if this is a write to the sysctl file
2501 * @buffer: the user buffer
2502 * @lenp: the size of the user buffer
2503 * @ppos: file position
2505 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2506 * values from/to the user buffer, treated as an ASCII string. The values
2507 * are treated as milliseconds, and converted to jiffies when they are stored.
2509 * This routine will ensure the values are within the range specified by
2510 * table->extra1 (min) and table->extra2 (max).
2512 * Returns 0 on success.
2514 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2515 void __user *buffer,
2516 size_t *lenp, loff_t *ppos)
2518 return do_proc_doulongvec_minmax(table, write, buffer,
2519 lenp, ppos, HZ, 1000l);
2523 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2524 int *valp,
2525 int write, void *data)
2527 if (write) {
2528 if (*lvalp > LONG_MAX / HZ)
2529 return 1;
2530 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2531 } else {
2532 int val = *valp;
2533 unsigned long lval;
2534 if (val < 0) {
2535 *negp = true;
2536 lval = -(unsigned long)val;
2537 } else {
2538 *negp = false;
2539 lval = (unsigned long)val;
2541 *lvalp = lval / HZ;
2543 return 0;
2546 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2547 int *valp,
2548 int write, void *data)
2550 if (write) {
2551 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2552 return 1;
2553 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2554 } else {
2555 int val = *valp;
2556 unsigned long lval;
2557 if (val < 0) {
2558 *negp = true;
2559 lval = -(unsigned long)val;
2560 } else {
2561 *negp = false;
2562 lval = (unsigned long)val;
2564 *lvalp = jiffies_to_clock_t(lval);
2566 return 0;
2569 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2570 int *valp,
2571 int write, void *data)
2573 if (write) {
2574 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2576 if (jif > INT_MAX)
2577 return 1;
2578 *valp = (int)jif;
2579 } else {
2580 int val = *valp;
2581 unsigned long lval;
2582 if (val < 0) {
2583 *negp = true;
2584 lval = -(unsigned long)val;
2585 } else {
2586 *negp = false;
2587 lval = (unsigned long)val;
2589 *lvalp = jiffies_to_msecs(lval);
2591 return 0;
2595 * proc_dointvec_jiffies - read a vector of integers as seconds
2596 * @table: the sysctl table
2597 * @write: %TRUE if this is a write to the sysctl file
2598 * @buffer: the user buffer
2599 * @lenp: the size of the user buffer
2600 * @ppos: file position
2602 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2603 * values from/to the user buffer, treated as an ASCII string.
2604 * The values read are assumed to be in seconds, and are converted into
2605 * jiffies.
2607 * Returns 0 on success.
2609 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2610 void __user *buffer, size_t *lenp, loff_t *ppos)
2612 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2613 do_proc_dointvec_jiffies_conv,NULL);
2617 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2618 * @table: the sysctl table
2619 * @write: %TRUE if this is a write to the sysctl file
2620 * @buffer: the user buffer
2621 * @lenp: the size of the user buffer
2622 * @ppos: pointer to the file position
2624 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2625 * values from/to the user buffer, treated as an ASCII string.
2626 * The values read are assumed to be in 1/USER_HZ seconds, and
2627 * are converted into jiffies.
2629 * Returns 0 on success.
2631 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2632 void __user *buffer, size_t *lenp, loff_t *ppos)
2634 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2635 do_proc_dointvec_userhz_jiffies_conv,NULL);
2639 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2640 * @table: the sysctl table
2641 * @write: %TRUE if this is a write to the sysctl file
2642 * @buffer: the user buffer
2643 * @lenp: the size of the user buffer
2644 * @ppos: file position
2645 * @ppos: the current position in the file
2647 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2648 * values from/to the user buffer, treated as an ASCII string.
2649 * The values read are assumed to be in 1/1000 seconds, and
2650 * are converted into jiffies.
2652 * Returns 0 on success.
2654 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2655 void __user *buffer, size_t *lenp, loff_t *ppos)
2657 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2658 do_proc_dointvec_ms_jiffies_conv, NULL);
2661 static int proc_do_cad_pid(struct ctl_table *table, int write,
2662 void __user *buffer, size_t *lenp, loff_t *ppos)
2664 struct pid *new_pid;
2665 pid_t tmp;
2666 int r;
2668 tmp = pid_vnr(cad_pid);
2670 r = __do_proc_dointvec(&tmp, table, write, buffer,
2671 lenp, ppos, NULL, NULL);
2672 if (r || !write)
2673 return r;
2675 new_pid = find_get_pid(tmp);
2676 if (!new_pid)
2677 return -ESRCH;
2679 put_pid(xchg(&cad_pid, new_pid));
2680 return 0;
2684 * proc_do_large_bitmap - read/write from/to a large bitmap
2685 * @table: the sysctl table
2686 * @write: %TRUE if this is a write to the sysctl file
2687 * @buffer: the user buffer
2688 * @lenp: the size of the user buffer
2689 * @ppos: file position
2691 * The bitmap is stored at table->data and the bitmap length (in bits)
2692 * in table->maxlen.
2694 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2695 * large bitmaps may be represented in a compact manner. Writing into
2696 * the file will clear the bitmap then update it with the given input.
2698 * Returns 0 on success.
2700 int proc_do_large_bitmap(struct ctl_table *table, int write,
2701 void __user *buffer, size_t *lenp, loff_t *ppos)
2703 int err = 0;
2704 bool first = 1;
2705 size_t left = *lenp;
2706 unsigned long bitmap_len = table->maxlen;
2707 unsigned long *bitmap = *(unsigned long **) table->data;
2708 unsigned long *tmp_bitmap = NULL;
2709 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2711 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2712 *lenp = 0;
2713 return 0;
2716 if (write) {
2717 unsigned long page = 0;
2718 char *kbuf;
2720 if (left > PAGE_SIZE - 1)
2721 left = PAGE_SIZE - 1;
2723 page = __get_free_page(GFP_TEMPORARY);
2724 kbuf = (char *) page;
2725 if (!kbuf)
2726 return -ENOMEM;
2727 if (copy_from_user(kbuf, buffer, left)) {
2728 free_page(page);
2729 return -EFAULT;
2731 kbuf[left] = 0;
2733 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2734 GFP_KERNEL);
2735 if (!tmp_bitmap) {
2736 free_page(page);
2737 return -ENOMEM;
2739 proc_skip_char(&kbuf, &left, '\n');
2740 while (!err && left) {
2741 unsigned long val_a, val_b;
2742 bool neg;
2744 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2745 sizeof(tr_a), &c);
2746 if (err)
2747 break;
2748 if (val_a >= bitmap_len || neg) {
2749 err = -EINVAL;
2750 break;
2753 val_b = val_a;
2754 if (left) {
2755 kbuf++;
2756 left--;
2759 if (c == '-') {
2760 err = proc_get_long(&kbuf, &left, &val_b,
2761 &neg, tr_b, sizeof(tr_b),
2762 &c);
2763 if (err)
2764 break;
2765 if (val_b >= bitmap_len || neg ||
2766 val_a > val_b) {
2767 err = -EINVAL;
2768 break;
2770 if (left) {
2771 kbuf++;
2772 left--;
2776 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2777 first = 0;
2778 proc_skip_char(&kbuf, &left, '\n');
2780 free_page(page);
2781 } else {
2782 unsigned long bit_a, bit_b = 0;
2784 while (left) {
2785 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2786 if (bit_a >= bitmap_len)
2787 break;
2788 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2789 bit_a + 1) - 1;
2791 if (!first) {
2792 err = proc_put_char(&buffer, &left, ',');
2793 if (err)
2794 break;
2796 err = proc_put_long(&buffer, &left, bit_a, false);
2797 if (err)
2798 break;
2799 if (bit_a != bit_b) {
2800 err = proc_put_char(&buffer, &left, '-');
2801 if (err)
2802 break;
2803 err = proc_put_long(&buffer, &left, bit_b, false);
2804 if (err)
2805 break;
2808 first = 0; bit_b++;
2810 if (!err)
2811 err = proc_put_char(&buffer, &left, '\n');
2814 if (!err) {
2815 if (write) {
2816 if (*ppos)
2817 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2818 else
2819 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2821 kfree(tmp_bitmap);
2822 *lenp -= left;
2823 *ppos += *lenp;
2824 return 0;
2825 } else {
2826 kfree(tmp_bitmap);
2827 return err;
2831 #else /* CONFIG_PROC_SYSCTL */
2833 int proc_dostring(struct ctl_table *table, int write,
2834 void __user *buffer, size_t *lenp, loff_t *ppos)
2836 return -ENOSYS;
2839 int proc_dointvec(struct ctl_table *table, int write,
2840 void __user *buffer, size_t *lenp, loff_t *ppos)
2842 return -ENOSYS;
2845 int proc_douintvec(struct ctl_table *table, int write,
2846 void __user *buffer, size_t *lenp, loff_t *ppos)
2848 return -ENOSYS;
2851 int proc_dointvec_minmax(struct ctl_table *table, int write,
2852 void __user *buffer, size_t *lenp, loff_t *ppos)
2854 return -ENOSYS;
2857 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2858 void __user *buffer, size_t *lenp, loff_t *ppos)
2860 return -ENOSYS;
2863 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2864 void __user *buffer, size_t *lenp, loff_t *ppos)
2866 return -ENOSYS;
2869 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2870 void __user *buffer, size_t *lenp, loff_t *ppos)
2872 return -ENOSYS;
2875 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2876 void __user *buffer, size_t *lenp, loff_t *ppos)
2878 return -ENOSYS;
2881 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2882 void __user *buffer,
2883 size_t *lenp, loff_t *ppos)
2885 return -ENOSYS;
2889 #endif /* CONFIG_PROC_SYSCTL */
2892 * No sense putting this after each symbol definition, twice,
2893 * exception granted :-)
2895 EXPORT_SYMBOL(proc_dointvec);
2896 EXPORT_SYMBOL(proc_douintvec);
2897 EXPORT_SYMBOL(proc_dointvec_jiffies);
2898 EXPORT_SYMBOL(proc_dointvec_minmax);
2899 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2900 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2901 EXPORT_SYMBOL(proc_dostring);
2902 EXPORT_SYMBOL(proc_doulongvec_minmax);
2903 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);