MIPS: Disallow outsized PTRACE_SETREGSET NT_PRFPREG regset accesses
[linux/fpc-iii.git] / kernel / sysctl.c
blob17c59e78661b4baf1ddd87fde045809f81c81955
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,
348 .procname = "sched_shares_window_ns",
349 .data = &sysctl_sched_shares_window,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = proc_dointvec,
354 #endif /* CONFIG_SMP */
355 #ifdef CONFIG_NUMA_BALANCING
357 .procname = "numa_balancing_scan_delay_ms",
358 .data = &sysctl_numa_balancing_scan_delay,
359 .maxlen = sizeof(unsigned int),
360 .mode = 0644,
361 .proc_handler = proc_dointvec,
364 .procname = "numa_balancing_scan_period_min_ms",
365 .data = &sysctl_numa_balancing_scan_period_min,
366 .maxlen = sizeof(unsigned int),
367 .mode = 0644,
368 .proc_handler = proc_dointvec,
371 .procname = "numa_balancing_scan_period_max_ms",
372 .data = &sysctl_numa_balancing_scan_period_max,
373 .maxlen = sizeof(unsigned int),
374 .mode = 0644,
375 .proc_handler = proc_dointvec,
378 .procname = "numa_balancing_scan_size_mb",
379 .data = &sysctl_numa_balancing_scan_size,
380 .maxlen = sizeof(unsigned int),
381 .mode = 0644,
382 .proc_handler = proc_dointvec_minmax,
383 .extra1 = &one,
386 .procname = "numa_balancing",
387 .data = NULL, /* filled in by handler */
388 .maxlen = sizeof(unsigned int),
389 .mode = 0644,
390 .proc_handler = sysctl_numa_balancing,
391 .extra1 = &zero,
392 .extra2 = &one,
394 #endif /* CONFIG_NUMA_BALANCING */
395 #endif /* CONFIG_SCHED_DEBUG */
397 .procname = "sched_rt_period_us",
398 .data = &sysctl_sched_rt_period,
399 .maxlen = sizeof(unsigned int),
400 .mode = 0644,
401 .proc_handler = sched_rt_handler,
404 .procname = "sched_rt_runtime_us",
405 .data = &sysctl_sched_rt_runtime,
406 .maxlen = sizeof(int),
407 .mode = 0644,
408 .proc_handler = sched_rt_handler,
411 .procname = "sched_rr_timeslice_ms",
412 .data = &sched_rr_timeslice,
413 .maxlen = sizeof(int),
414 .mode = 0644,
415 .proc_handler = sched_rr_handler,
417 #ifdef CONFIG_SCHED_AUTOGROUP
419 .procname = "sched_autogroup_enabled",
420 .data = &sysctl_sched_autogroup_enabled,
421 .maxlen = sizeof(unsigned int),
422 .mode = 0644,
423 .proc_handler = proc_dointvec_minmax,
424 .extra1 = &zero,
425 .extra2 = &one,
427 #endif
428 #ifdef CONFIG_CFS_BANDWIDTH
430 .procname = "sched_cfs_bandwidth_slice_us",
431 .data = &sysctl_sched_cfs_bandwidth_slice,
432 .maxlen = sizeof(unsigned int),
433 .mode = 0644,
434 .proc_handler = proc_dointvec_minmax,
435 .extra1 = &one,
437 #endif
438 #ifdef CONFIG_PROVE_LOCKING
440 .procname = "prove_locking",
441 .data = &prove_locking,
442 .maxlen = sizeof(int),
443 .mode = 0644,
444 .proc_handler = proc_dointvec,
446 #endif
447 #ifdef CONFIG_LOCK_STAT
449 .procname = "lock_stat",
450 .data = &lock_stat,
451 .maxlen = sizeof(int),
452 .mode = 0644,
453 .proc_handler = proc_dointvec,
455 #endif
457 .procname = "panic",
458 .data = &panic_timeout,
459 .maxlen = sizeof(int),
460 .mode = 0644,
461 .proc_handler = proc_dointvec,
463 #ifdef CONFIG_COREDUMP
465 .procname = "core_uses_pid",
466 .data = &core_uses_pid,
467 .maxlen = sizeof(int),
468 .mode = 0644,
469 .proc_handler = proc_dointvec,
472 .procname = "core_pattern",
473 .data = core_pattern,
474 .maxlen = CORENAME_MAX_SIZE,
475 .mode = 0644,
476 .proc_handler = proc_dostring_coredump,
479 .procname = "core_pipe_limit",
480 .data = &core_pipe_limit,
481 .maxlen = sizeof(unsigned int),
482 .mode = 0644,
483 .proc_handler = proc_dointvec,
485 #endif
486 #ifdef CONFIG_PROC_SYSCTL
488 .procname = "tainted",
489 .maxlen = sizeof(long),
490 .mode = 0644,
491 .proc_handler = proc_taint,
494 .procname = "sysctl_writes_strict",
495 .data = &sysctl_writes_strict,
496 .maxlen = sizeof(int),
497 .mode = 0644,
498 .proc_handler = proc_dointvec_minmax,
499 .extra1 = &neg_one,
500 .extra2 = &one,
502 #endif
503 #ifdef CONFIG_LATENCYTOP
505 .procname = "latencytop",
506 .data = &latencytop_enabled,
507 .maxlen = sizeof(int),
508 .mode = 0644,
509 .proc_handler = proc_dointvec,
511 #endif
512 #ifdef CONFIG_BLK_DEV_INITRD
514 .procname = "real-root-dev",
515 .data = &real_root_dev,
516 .maxlen = sizeof(int),
517 .mode = 0644,
518 .proc_handler = proc_dointvec,
520 #endif
522 .procname = "print-fatal-signals",
523 .data = &print_fatal_signals,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = proc_dointvec,
528 #ifdef CONFIG_SPARC
530 .procname = "reboot-cmd",
531 .data = reboot_command,
532 .maxlen = 256,
533 .mode = 0644,
534 .proc_handler = proc_dostring,
537 .procname = "stop-a",
538 .data = &stop_a_enabled,
539 .maxlen = sizeof (int),
540 .mode = 0644,
541 .proc_handler = proc_dointvec,
544 .procname = "scons-poweroff",
545 .data = &scons_pwroff,
546 .maxlen = sizeof (int),
547 .mode = 0644,
548 .proc_handler = proc_dointvec,
550 #endif
551 #ifdef CONFIG_SPARC64
553 .procname = "tsb-ratio",
554 .data = &sysctl_tsb_ratio,
555 .maxlen = sizeof (int),
556 .mode = 0644,
557 .proc_handler = proc_dointvec,
559 #endif
560 #ifdef __hppa__
562 .procname = "soft-power",
563 .data = &pwrsw_enabled,
564 .maxlen = sizeof (int),
565 .mode = 0644,
566 .proc_handler = proc_dointvec,
568 #endif
569 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
571 .procname = "unaligned-trap",
572 .data = &unaligned_enabled,
573 .maxlen = sizeof (int),
574 .mode = 0644,
575 .proc_handler = proc_dointvec,
577 #endif
579 .procname = "ctrl-alt-del",
580 .data = &C_A_D,
581 .maxlen = sizeof(int),
582 .mode = 0644,
583 .proc_handler = proc_dointvec,
585 #ifdef CONFIG_FUNCTION_TRACER
587 .procname = "ftrace_enabled",
588 .data = &ftrace_enabled,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = ftrace_enable_sysctl,
593 #endif
594 #ifdef CONFIG_STACK_TRACER
596 .procname = "stack_tracer_enabled",
597 .data = &stack_tracer_enabled,
598 .maxlen = sizeof(int),
599 .mode = 0644,
600 .proc_handler = stack_trace_sysctl,
602 #endif
603 #ifdef CONFIG_TRACING
605 .procname = "ftrace_dump_on_oops",
606 .data = &ftrace_dump_on_oops,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = proc_dointvec,
612 .procname = "traceoff_on_warning",
613 .data = &__disable_trace_on_warning,
614 .maxlen = sizeof(__disable_trace_on_warning),
615 .mode = 0644,
616 .proc_handler = proc_dointvec,
619 .procname = "tracepoint_printk",
620 .data = &tracepoint_printk,
621 .maxlen = sizeof(tracepoint_printk),
622 .mode = 0644,
623 .proc_handler = proc_dointvec,
625 #endif
626 #ifdef CONFIG_KEXEC_CORE
628 .procname = "kexec_load_disabled",
629 .data = &kexec_load_disabled,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 /* only handle a transition from default "0" to "1" */
633 .proc_handler = proc_dointvec_minmax,
634 .extra1 = &one,
635 .extra2 = &one,
637 #endif
638 #ifdef CONFIG_MODULES
640 .procname = "modprobe",
641 .data = &modprobe_path,
642 .maxlen = KMOD_PATH_LEN,
643 .mode = 0644,
644 .proc_handler = proc_dostring,
647 .procname = "modules_disabled",
648 .data = &modules_disabled,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 /* only handle a transition from default "0" to "1" */
652 .proc_handler = proc_dointvec_minmax,
653 .extra1 = &one,
654 .extra2 = &one,
656 #endif
657 #ifdef CONFIG_UEVENT_HELPER
659 .procname = "hotplug",
660 .data = &uevent_helper,
661 .maxlen = UEVENT_HELPER_PATH_LEN,
662 .mode = 0644,
663 .proc_handler = proc_dostring,
665 #endif
666 #ifdef CONFIG_CHR_DEV_SG
668 .procname = "sg-big-buff",
669 .data = &sg_big_buff,
670 .maxlen = sizeof (int),
671 .mode = 0444,
672 .proc_handler = proc_dointvec,
674 #endif
675 #ifdef CONFIG_BSD_PROCESS_ACCT
677 .procname = "acct",
678 .data = &acct_parm,
679 .maxlen = 3*sizeof(int),
680 .mode = 0644,
681 .proc_handler = proc_dointvec,
683 #endif
684 #ifdef CONFIG_MAGIC_SYSRQ
686 .procname = "sysrq",
687 .data = &__sysrq_enabled,
688 .maxlen = sizeof (int),
689 .mode = 0644,
690 .proc_handler = sysrq_sysctl_handler,
692 #endif
693 #ifdef CONFIG_PROC_SYSCTL
695 .procname = "cad_pid",
696 .data = NULL,
697 .maxlen = sizeof (int),
698 .mode = 0600,
699 .proc_handler = proc_do_cad_pid,
701 #endif
703 .procname = "threads-max",
704 .data = NULL,
705 .maxlen = sizeof(int),
706 .mode = 0644,
707 .proc_handler = sysctl_max_threads,
710 .procname = "random",
711 .mode = 0555,
712 .child = random_table,
715 .procname = "usermodehelper",
716 .mode = 0555,
717 .child = usermodehelper_table,
720 .procname = "overflowuid",
721 .data = &overflowuid,
722 .maxlen = sizeof(int),
723 .mode = 0644,
724 .proc_handler = proc_dointvec_minmax,
725 .extra1 = &minolduid,
726 .extra2 = &maxolduid,
729 .procname = "overflowgid",
730 .data = &overflowgid,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = proc_dointvec_minmax,
734 .extra1 = &minolduid,
735 .extra2 = &maxolduid,
737 #ifdef CONFIG_S390
738 #ifdef CONFIG_MATHEMU
740 .procname = "ieee_emulation_warnings",
741 .data = &sysctl_ieee_emulation_warnings,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = proc_dointvec,
746 #endif
748 .procname = "userprocess_debug",
749 .data = &show_unhandled_signals,
750 .maxlen = sizeof(int),
751 .mode = 0644,
752 .proc_handler = proc_dointvec,
754 #endif
756 .procname = "pid_max",
757 .data = &pid_max,
758 .maxlen = sizeof (int),
759 .mode = 0644,
760 .proc_handler = proc_dointvec_minmax,
761 .extra1 = &pid_max_min,
762 .extra2 = &pid_max_max,
765 .procname = "panic_on_oops",
766 .data = &panic_on_oops,
767 .maxlen = sizeof(int),
768 .mode = 0644,
769 .proc_handler = proc_dointvec,
771 #if defined CONFIG_PRINTK
773 .procname = "printk",
774 .data = &console_loglevel,
775 .maxlen = 4*sizeof(int),
776 .mode = 0644,
777 .proc_handler = proc_dointvec,
780 .procname = "printk_ratelimit",
781 .data = &printk_ratelimit_state.interval,
782 .maxlen = sizeof(int),
783 .mode = 0644,
784 .proc_handler = proc_dointvec_jiffies,
787 .procname = "printk_ratelimit_burst",
788 .data = &printk_ratelimit_state.burst,
789 .maxlen = sizeof(int),
790 .mode = 0644,
791 .proc_handler = proc_dointvec,
794 .procname = "printk_delay",
795 .data = &printk_delay_msec,
796 .maxlen = sizeof(int),
797 .mode = 0644,
798 .proc_handler = proc_dointvec_minmax,
799 .extra1 = &zero,
800 .extra2 = &ten_thousand,
803 .procname = "dmesg_restrict",
804 .data = &dmesg_restrict,
805 .maxlen = sizeof(int),
806 .mode = 0644,
807 .proc_handler = proc_dointvec_minmax_sysadmin,
808 .extra1 = &zero,
809 .extra2 = &one,
812 .procname = "kptr_restrict",
813 .data = &kptr_restrict,
814 .maxlen = sizeof(int),
815 .mode = 0644,
816 .proc_handler = proc_dointvec_minmax_sysadmin,
817 .extra1 = &zero,
818 .extra2 = &two,
820 #endif
822 .procname = "ngroups_max",
823 .data = &ngroups_max,
824 .maxlen = sizeof (int),
825 .mode = 0444,
826 .proc_handler = proc_dointvec,
829 .procname = "cap_last_cap",
830 .data = (void *)&cap_last_cap,
831 .maxlen = sizeof(int),
832 .mode = 0444,
833 .proc_handler = proc_dointvec,
835 #if defined(CONFIG_LOCKUP_DETECTOR)
837 .procname = "watchdog",
838 .data = &watchdog_user_enabled,
839 .maxlen = sizeof (int),
840 .mode = 0644,
841 .proc_handler = proc_watchdog,
842 .extra1 = &zero,
843 .extra2 = &one,
846 .procname = "watchdog_thresh",
847 .data = &watchdog_thresh,
848 .maxlen = sizeof(int),
849 .mode = 0644,
850 .proc_handler = proc_watchdog_thresh,
851 .extra1 = &zero,
852 .extra2 = &sixty,
855 .procname = "nmi_watchdog",
856 .data = &nmi_watchdog_enabled,
857 .maxlen = sizeof (int),
858 .mode = 0644,
859 .proc_handler = proc_nmi_watchdog,
860 .extra1 = &zero,
861 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
862 .extra2 = &one,
863 #else
864 .extra2 = &zero,
865 #endif
868 .procname = "soft_watchdog",
869 .data = &soft_watchdog_enabled,
870 .maxlen = sizeof (int),
871 .mode = 0644,
872 .proc_handler = proc_soft_watchdog,
873 .extra1 = &zero,
874 .extra2 = &one,
877 .procname = "watchdog_cpumask",
878 .data = &watchdog_cpumask_bits,
879 .maxlen = NR_CPUS,
880 .mode = 0644,
881 .proc_handler = proc_watchdog_cpumask,
884 .procname = "softlockup_panic",
885 .data = &softlockup_panic,
886 .maxlen = sizeof(int),
887 .mode = 0644,
888 .proc_handler = proc_dointvec_minmax,
889 .extra1 = &zero,
890 .extra2 = &one,
892 #ifdef CONFIG_HARDLOCKUP_DETECTOR
894 .procname = "hardlockup_panic",
895 .data = &hardlockup_panic,
896 .maxlen = sizeof(int),
897 .mode = 0644,
898 .proc_handler = proc_dointvec_minmax,
899 .extra1 = &zero,
900 .extra2 = &one,
902 #endif
903 #ifdef CONFIG_SMP
905 .procname = "softlockup_all_cpu_backtrace",
906 .data = &sysctl_softlockup_all_cpu_backtrace,
907 .maxlen = sizeof(int),
908 .mode = 0644,
909 .proc_handler = proc_dointvec_minmax,
910 .extra1 = &zero,
911 .extra2 = &one,
914 .procname = "hardlockup_all_cpu_backtrace",
915 .data = &sysctl_hardlockup_all_cpu_backtrace,
916 .maxlen = sizeof(int),
917 .mode = 0644,
918 .proc_handler = proc_dointvec_minmax,
919 .extra1 = &zero,
920 .extra2 = &one,
922 #endif /* CONFIG_SMP */
923 #endif
924 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
926 .procname = "unknown_nmi_panic",
927 .data = &unknown_nmi_panic,
928 .maxlen = sizeof (int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec,
932 #endif
933 #if defined(CONFIG_X86)
935 .procname = "panic_on_unrecovered_nmi",
936 .data = &panic_on_unrecovered_nmi,
937 .maxlen = sizeof(int),
938 .mode = 0644,
939 .proc_handler = proc_dointvec,
942 .procname = "panic_on_io_nmi",
943 .data = &panic_on_io_nmi,
944 .maxlen = sizeof(int),
945 .mode = 0644,
946 .proc_handler = proc_dointvec,
948 #ifdef CONFIG_DEBUG_STACKOVERFLOW
950 .procname = "panic_on_stackoverflow",
951 .data = &sysctl_panic_on_stackoverflow,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = proc_dointvec,
956 #endif
958 .procname = "bootloader_type",
959 .data = &bootloader_type,
960 .maxlen = sizeof (int),
961 .mode = 0444,
962 .proc_handler = proc_dointvec,
965 .procname = "bootloader_version",
966 .data = &bootloader_version,
967 .maxlen = sizeof (int),
968 .mode = 0444,
969 .proc_handler = proc_dointvec,
972 .procname = "kstack_depth_to_print",
973 .data = &kstack_depth_to_print,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = proc_dointvec,
979 .procname = "io_delay_type",
980 .data = &io_delay_type,
981 .maxlen = sizeof(int),
982 .mode = 0644,
983 .proc_handler = proc_dointvec,
985 #endif
986 #if defined(CONFIG_MMU)
988 .procname = "randomize_va_space",
989 .data = &randomize_va_space,
990 .maxlen = sizeof(int),
991 .mode = 0644,
992 .proc_handler = proc_dointvec,
994 #endif
995 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
997 .procname = "spin_retry",
998 .data = &spin_retry,
999 .maxlen = sizeof (int),
1000 .mode = 0644,
1001 .proc_handler = proc_dointvec,
1003 #endif
1004 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1006 .procname = "acpi_video_flags",
1007 .data = &acpi_realmode_flags,
1008 .maxlen = sizeof (unsigned long),
1009 .mode = 0644,
1010 .proc_handler = proc_doulongvec_minmax,
1012 #endif
1013 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1015 .procname = "ignore-unaligned-usertrap",
1016 .data = &no_unaligned_warning,
1017 .maxlen = sizeof (int),
1018 .mode = 0644,
1019 .proc_handler = proc_dointvec,
1021 #endif
1022 #ifdef CONFIG_IA64
1024 .procname = "unaligned-dump-stack",
1025 .data = &unaligned_dump_stack,
1026 .maxlen = sizeof (int),
1027 .mode = 0644,
1028 .proc_handler = proc_dointvec,
1030 #endif
1031 #ifdef CONFIG_DETECT_HUNG_TASK
1033 .procname = "hung_task_panic",
1034 .data = &sysctl_hung_task_panic,
1035 .maxlen = sizeof(int),
1036 .mode = 0644,
1037 .proc_handler = proc_dointvec_minmax,
1038 .extra1 = &zero,
1039 .extra2 = &one,
1042 .procname = "hung_task_check_count",
1043 .data = &sysctl_hung_task_check_count,
1044 .maxlen = sizeof(int),
1045 .mode = 0644,
1046 .proc_handler = proc_dointvec_minmax,
1047 .extra1 = &zero,
1050 .procname = "hung_task_timeout_secs",
1051 .data = &sysctl_hung_task_timeout_secs,
1052 .maxlen = sizeof(unsigned long),
1053 .mode = 0644,
1054 .proc_handler = proc_dohung_task_timeout_secs,
1055 .extra2 = &hung_task_timeout_max,
1058 .procname = "hung_task_warnings",
1059 .data = &sysctl_hung_task_warnings,
1060 .maxlen = sizeof(int),
1061 .mode = 0644,
1062 .proc_handler = proc_dointvec_minmax,
1063 .extra1 = &neg_one,
1065 #endif
1066 #ifdef CONFIG_COMPAT
1068 .procname = "compat-log",
1069 .data = &compat_log,
1070 .maxlen = sizeof (int),
1071 .mode = 0644,
1072 .proc_handler = proc_dointvec,
1074 #endif
1075 #ifdef CONFIG_RT_MUTEXES
1077 .procname = "max_lock_depth",
1078 .data = &max_lock_depth,
1079 .maxlen = sizeof(int),
1080 .mode = 0644,
1081 .proc_handler = proc_dointvec,
1083 #endif
1085 .procname = "poweroff_cmd",
1086 .data = &poweroff_cmd,
1087 .maxlen = POWEROFF_CMD_PATH_LEN,
1088 .mode = 0644,
1089 .proc_handler = proc_dostring,
1091 #ifdef CONFIG_KEYS
1093 .procname = "keys",
1094 .mode = 0555,
1095 .child = key_sysctls,
1097 #endif
1098 #ifdef CONFIG_PERF_EVENTS
1100 * User-space scripts rely on the existence of this file
1101 * as a feature check for perf_events being enabled.
1103 * So it's an ABI, do not remove!
1106 .procname = "perf_event_paranoid",
1107 .data = &sysctl_perf_event_paranoid,
1108 .maxlen = sizeof(sysctl_perf_event_paranoid),
1109 .mode = 0644,
1110 .proc_handler = proc_dointvec,
1113 .procname = "perf_event_mlock_kb",
1114 .data = &sysctl_perf_event_mlock,
1115 .maxlen = sizeof(sysctl_perf_event_mlock),
1116 .mode = 0644,
1117 .proc_handler = proc_dointvec,
1120 .procname = "perf_event_max_sample_rate",
1121 .data = &sysctl_perf_event_sample_rate,
1122 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1123 .mode = 0644,
1124 .proc_handler = perf_proc_update_handler,
1125 .extra1 = &one,
1128 .procname = "perf_cpu_time_max_percent",
1129 .data = &sysctl_perf_cpu_time_max_percent,
1130 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1131 .mode = 0644,
1132 .proc_handler = perf_cpu_time_max_percent_handler,
1133 .extra1 = &zero,
1134 .extra2 = &one_hundred,
1136 #endif
1137 #ifdef CONFIG_KMEMCHECK
1139 .procname = "kmemcheck",
1140 .data = &kmemcheck_enabled,
1141 .maxlen = sizeof(int),
1142 .mode = 0644,
1143 .proc_handler = proc_dointvec,
1145 #endif
1147 .procname = "panic_on_warn",
1148 .data = &panic_on_warn,
1149 .maxlen = sizeof(int),
1150 .mode = 0644,
1151 .proc_handler = proc_dointvec_minmax,
1152 .extra1 = &zero,
1153 .extra2 = &one,
1155 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1157 .procname = "timer_migration",
1158 .data = &sysctl_timer_migration,
1159 .maxlen = sizeof(unsigned int),
1160 .mode = 0644,
1161 .proc_handler = timer_migration_handler,
1162 .extra1 = &zero,
1163 .extra2 = &one,
1165 #endif
1166 #ifdef CONFIG_BPF_SYSCALL
1168 .procname = "unprivileged_bpf_disabled",
1169 .data = &sysctl_unprivileged_bpf_disabled,
1170 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1171 .mode = 0644,
1172 /* only handle a transition from default "0" to "1" */
1173 .proc_handler = proc_dointvec_minmax,
1174 .extra1 = &one,
1175 .extra2 = &one,
1177 #endif
1181 static struct ctl_table vm_table[] = {
1183 .procname = "overcommit_memory",
1184 .data = &sysctl_overcommit_memory,
1185 .maxlen = sizeof(sysctl_overcommit_memory),
1186 .mode = 0644,
1187 .proc_handler = proc_dointvec_minmax,
1188 .extra1 = &zero,
1189 .extra2 = &two,
1192 .procname = "panic_on_oom",
1193 .data = &sysctl_panic_on_oom,
1194 .maxlen = sizeof(sysctl_panic_on_oom),
1195 .mode = 0644,
1196 .proc_handler = proc_dointvec_minmax,
1197 .extra1 = &zero,
1198 .extra2 = &two,
1201 .procname = "oom_kill_allocating_task",
1202 .data = &sysctl_oom_kill_allocating_task,
1203 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1204 .mode = 0644,
1205 .proc_handler = proc_dointvec,
1208 .procname = "oom_dump_tasks",
1209 .data = &sysctl_oom_dump_tasks,
1210 .maxlen = sizeof(sysctl_oom_dump_tasks),
1211 .mode = 0644,
1212 .proc_handler = proc_dointvec,
1215 .procname = "overcommit_ratio",
1216 .data = &sysctl_overcommit_ratio,
1217 .maxlen = sizeof(sysctl_overcommit_ratio),
1218 .mode = 0644,
1219 .proc_handler = overcommit_ratio_handler,
1222 .procname = "overcommit_kbytes",
1223 .data = &sysctl_overcommit_kbytes,
1224 .maxlen = sizeof(sysctl_overcommit_kbytes),
1225 .mode = 0644,
1226 .proc_handler = overcommit_kbytes_handler,
1229 .procname = "page-cluster",
1230 .data = &page_cluster,
1231 .maxlen = sizeof(int),
1232 .mode = 0644,
1233 .proc_handler = proc_dointvec_minmax,
1234 .extra1 = &zero,
1237 .procname = "dirty_background_ratio",
1238 .data = &dirty_background_ratio,
1239 .maxlen = sizeof(dirty_background_ratio),
1240 .mode = 0644,
1241 .proc_handler = dirty_background_ratio_handler,
1242 .extra1 = &zero,
1243 .extra2 = &one_hundred,
1246 .procname = "dirty_background_bytes",
1247 .data = &dirty_background_bytes,
1248 .maxlen = sizeof(dirty_background_bytes),
1249 .mode = 0644,
1250 .proc_handler = dirty_background_bytes_handler,
1251 .extra1 = &one_ul,
1254 .procname = "dirty_ratio",
1255 .data = &vm_dirty_ratio,
1256 .maxlen = sizeof(vm_dirty_ratio),
1257 .mode = 0644,
1258 .proc_handler = dirty_ratio_handler,
1259 .extra1 = &zero,
1260 .extra2 = &one_hundred,
1263 .procname = "dirty_bytes",
1264 .data = &vm_dirty_bytes,
1265 .maxlen = sizeof(vm_dirty_bytes),
1266 .mode = 0644,
1267 .proc_handler = dirty_bytes_handler,
1268 .extra1 = &dirty_bytes_min,
1271 .procname = "dirty_writeback_centisecs",
1272 .data = &dirty_writeback_interval,
1273 .maxlen = sizeof(dirty_writeback_interval),
1274 .mode = 0644,
1275 .proc_handler = dirty_writeback_centisecs_handler,
1278 .procname = "dirty_expire_centisecs",
1279 .data = &dirty_expire_interval,
1280 .maxlen = sizeof(dirty_expire_interval),
1281 .mode = 0644,
1282 .proc_handler = proc_dointvec_minmax,
1283 .extra1 = &zero,
1286 .procname = "dirtytime_expire_seconds",
1287 .data = &dirtytime_expire_interval,
1288 .maxlen = sizeof(dirty_expire_interval),
1289 .mode = 0644,
1290 .proc_handler = dirtytime_interval_handler,
1291 .extra1 = &zero,
1294 .procname = "nr_pdflush_threads",
1295 .mode = 0444 /* read-only */,
1296 .proc_handler = pdflush_proc_obsolete,
1299 .procname = "swappiness",
1300 .data = &vm_swappiness,
1301 .maxlen = sizeof(vm_swappiness),
1302 .mode = 0644,
1303 .proc_handler = proc_dointvec_minmax,
1304 .extra1 = &zero,
1305 .extra2 = &one_hundred,
1307 #ifdef CONFIG_HUGETLB_PAGE
1309 .procname = "nr_hugepages",
1310 .data = NULL,
1311 .maxlen = sizeof(unsigned long),
1312 .mode = 0644,
1313 .proc_handler = hugetlb_sysctl_handler,
1315 #ifdef CONFIG_NUMA
1317 .procname = "nr_hugepages_mempolicy",
1318 .data = NULL,
1319 .maxlen = sizeof(unsigned long),
1320 .mode = 0644,
1321 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1323 #endif
1325 .procname = "hugetlb_shm_group",
1326 .data = &sysctl_hugetlb_shm_group,
1327 .maxlen = sizeof(gid_t),
1328 .mode = 0644,
1329 .proc_handler = proc_dointvec,
1332 .procname = "hugepages_treat_as_movable",
1333 .data = &hugepages_treat_as_movable,
1334 .maxlen = sizeof(int),
1335 .mode = 0644,
1336 .proc_handler = proc_dointvec,
1339 .procname = "nr_overcommit_hugepages",
1340 .data = NULL,
1341 .maxlen = sizeof(unsigned long),
1342 .mode = 0644,
1343 .proc_handler = hugetlb_overcommit_handler,
1345 #endif
1347 .procname = "lowmem_reserve_ratio",
1348 .data = &sysctl_lowmem_reserve_ratio,
1349 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1350 .mode = 0644,
1351 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1354 .procname = "drop_caches",
1355 .data = &sysctl_drop_caches,
1356 .maxlen = sizeof(int),
1357 .mode = 0644,
1358 .proc_handler = drop_caches_sysctl_handler,
1359 .extra1 = &one,
1360 .extra2 = &four,
1362 #ifdef CONFIG_COMPACTION
1364 .procname = "compact_memory",
1365 .data = &sysctl_compact_memory,
1366 .maxlen = sizeof(int),
1367 .mode = 0200,
1368 .proc_handler = sysctl_compaction_handler,
1371 .procname = "extfrag_threshold",
1372 .data = &sysctl_extfrag_threshold,
1373 .maxlen = sizeof(int),
1374 .mode = 0644,
1375 .proc_handler = sysctl_extfrag_handler,
1376 .extra1 = &min_extfrag_threshold,
1377 .extra2 = &max_extfrag_threshold,
1380 .procname = "compact_unevictable_allowed",
1381 .data = &sysctl_compact_unevictable_allowed,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
1384 .proc_handler = proc_dointvec,
1385 .extra1 = &zero,
1386 .extra2 = &one,
1389 #endif /* CONFIG_COMPACTION */
1391 .procname = "min_free_kbytes",
1392 .data = &min_free_kbytes,
1393 .maxlen = sizeof(min_free_kbytes),
1394 .mode = 0644,
1395 .proc_handler = min_free_kbytes_sysctl_handler,
1396 .extra1 = &zero,
1399 .procname = "percpu_pagelist_fraction",
1400 .data = &percpu_pagelist_fraction,
1401 .maxlen = sizeof(percpu_pagelist_fraction),
1402 .mode = 0644,
1403 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1404 .extra1 = &zero,
1406 #ifdef CONFIG_MMU
1408 .procname = "max_map_count",
1409 .data = &sysctl_max_map_count,
1410 .maxlen = sizeof(sysctl_max_map_count),
1411 .mode = 0644,
1412 .proc_handler = proc_dointvec_minmax,
1413 .extra1 = &zero,
1415 #else
1417 .procname = "nr_trim_pages",
1418 .data = &sysctl_nr_trim_pages,
1419 .maxlen = sizeof(sysctl_nr_trim_pages),
1420 .mode = 0644,
1421 .proc_handler = proc_dointvec_minmax,
1422 .extra1 = &zero,
1424 #endif
1426 .procname = "laptop_mode",
1427 .data = &laptop_mode,
1428 .maxlen = sizeof(laptop_mode),
1429 .mode = 0644,
1430 .proc_handler = proc_dointvec_jiffies,
1433 .procname = "block_dump",
1434 .data = &block_dump,
1435 .maxlen = sizeof(block_dump),
1436 .mode = 0644,
1437 .proc_handler = proc_dointvec,
1438 .extra1 = &zero,
1441 .procname = "vfs_cache_pressure",
1442 .data = &sysctl_vfs_cache_pressure,
1443 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1444 .mode = 0644,
1445 .proc_handler = proc_dointvec,
1446 .extra1 = &zero,
1448 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1450 .procname = "legacy_va_layout",
1451 .data = &sysctl_legacy_va_layout,
1452 .maxlen = sizeof(sysctl_legacy_va_layout),
1453 .mode = 0644,
1454 .proc_handler = proc_dointvec,
1455 .extra1 = &zero,
1457 #endif
1458 #ifdef CONFIG_NUMA
1460 .procname = "zone_reclaim_mode",
1461 .data = &zone_reclaim_mode,
1462 .maxlen = sizeof(zone_reclaim_mode),
1463 .mode = 0644,
1464 .proc_handler = proc_dointvec,
1465 .extra1 = &zero,
1468 .procname = "min_unmapped_ratio",
1469 .data = &sysctl_min_unmapped_ratio,
1470 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1471 .mode = 0644,
1472 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1473 .extra1 = &zero,
1474 .extra2 = &one_hundred,
1477 .procname = "min_slab_ratio",
1478 .data = &sysctl_min_slab_ratio,
1479 .maxlen = sizeof(sysctl_min_slab_ratio),
1480 .mode = 0644,
1481 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1482 .extra1 = &zero,
1483 .extra2 = &one_hundred,
1485 #endif
1486 #ifdef CONFIG_SMP
1488 .procname = "stat_interval",
1489 .data = &sysctl_stat_interval,
1490 .maxlen = sizeof(sysctl_stat_interval),
1491 .mode = 0644,
1492 .proc_handler = proc_dointvec_jiffies,
1494 #endif
1495 #ifdef CONFIG_MMU
1497 .procname = "mmap_min_addr",
1498 .data = &dac_mmap_min_addr,
1499 .maxlen = sizeof(unsigned long),
1500 .mode = 0644,
1501 .proc_handler = mmap_min_addr_handler,
1503 #endif
1504 #ifdef CONFIG_NUMA
1506 .procname = "numa_zonelist_order",
1507 .data = &numa_zonelist_order,
1508 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1509 .mode = 0644,
1510 .proc_handler = numa_zonelist_order_handler,
1512 #endif
1513 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1514 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1516 .procname = "vdso_enabled",
1517 #ifdef CONFIG_X86_32
1518 .data = &vdso32_enabled,
1519 .maxlen = sizeof(vdso32_enabled),
1520 #else
1521 .data = &vdso_enabled,
1522 .maxlen = sizeof(vdso_enabled),
1523 #endif
1524 .mode = 0644,
1525 .proc_handler = proc_dointvec,
1526 .extra1 = &zero,
1528 #endif
1529 #ifdef CONFIG_HIGHMEM
1531 .procname = "highmem_is_dirtyable",
1532 .data = &vm_highmem_is_dirtyable,
1533 .maxlen = sizeof(vm_highmem_is_dirtyable),
1534 .mode = 0644,
1535 .proc_handler = proc_dointvec_minmax,
1536 .extra1 = &zero,
1537 .extra2 = &one,
1539 #endif
1540 #ifdef CONFIG_MEMORY_FAILURE
1542 .procname = "memory_failure_early_kill",
1543 .data = &sysctl_memory_failure_early_kill,
1544 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1545 .mode = 0644,
1546 .proc_handler = proc_dointvec_minmax,
1547 .extra1 = &zero,
1548 .extra2 = &one,
1551 .procname = "memory_failure_recovery",
1552 .data = &sysctl_memory_failure_recovery,
1553 .maxlen = sizeof(sysctl_memory_failure_recovery),
1554 .mode = 0644,
1555 .proc_handler = proc_dointvec_minmax,
1556 .extra1 = &zero,
1557 .extra2 = &one,
1559 #endif
1561 .procname = "user_reserve_kbytes",
1562 .data = &sysctl_user_reserve_kbytes,
1563 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1564 .mode = 0644,
1565 .proc_handler = proc_doulongvec_minmax,
1568 .procname = "admin_reserve_kbytes",
1569 .data = &sysctl_admin_reserve_kbytes,
1570 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1571 .mode = 0644,
1572 .proc_handler = proc_doulongvec_minmax,
1577 static struct ctl_table fs_table[] = {
1579 .procname = "inode-nr",
1580 .data = &inodes_stat,
1581 .maxlen = 2*sizeof(long),
1582 .mode = 0444,
1583 .proc_handler = proc_nr_inodes,
1586 .procname = "inode-state",
1587 .data = &inodes_stat,
1588 .maxlen = 7*sizeof(long),
1589 .mode = 0444,
1590 .proc_handler = proc_nr_inodes,
1593 .procname = "file-nr",
1594 .data = &files_stat,
1595 .maxlen = sizeof(files_stat),
1596 .mode = 0444,
1597 .proc_handler = proc_nr_files,
1600 .procname = "file-max",
1601 .data = &files_stat.max_files,
1602 .maxlen = sizeof(files_stat.max_files),
1603 .mode = 0644,
1604 .proc_handler = proc_doulongvec_minmax,
1607 .procname = "nr_open",
1608 .data = &sysctl_nr_open,
1609 .maxlen = sizeof(int),
1610 .mode = 0644,
1611 .proc_handler = proc_dointvec_minmax,
1612 .extra1 = &sysctl_nr_open_min,
1613 .extra2 = &sysctl_nr_open_max,
1616 .procname = "dentry-state",
1617 .data = &dentry_stat,
1618 .maxlen = 6*sizeof(long),
1619 .mode = 0444,
1620 .proc_handler = proc_nr_dentry,
1623 .procname = "overflowuid",
1624 .data = &fs_overflowuid,
1625 .maxlen = sizeof(int),
1626 .mode = 0644,
1627 .proc_handler = proc_dointvec_minmax,
1628 .extra1 = &minolduid,
1629 .extra2 = &maxolduid,
1632 .procname = "overflowgid",
1633 .data = &fs_overflowgid,
1634 .maxlen = sizeof(int),
1635 .mode = 0644,
1636 .proc_handler = proc_dointvec_minmax,
1637 .extra1 = &minolduid,
1638 .extra2 = &maxolduid,
1640 #ifdef CONFIG_FILE_LOCKING
1642 .procname = "leases-enable",
1643 .data = &leases_enable,
1644 .maxlen = sizeof(int),
1645 .mode = 0644,
1646 .proc_handler = proc_dointvec,
1648 #endif
1649 #ifdef CONFIG_DNOTIFY
1651 .procname = "dir-notify-enable",
1652 .data = &dir_notify_enable,
1653 .maxlen = sizeof(int),
1654 .mode = 0644,
1655 .proc_handler = proc_dointvec,
1657 #endif
1658 #ifdef CONFIG_MMU
1659 #ifdef CONFIG_FILE_LOCKING
1661 .procname = "lease-break-time",
1662 .data = &lease_break_time,
1663 .maxlen = sizeof(int),
1664 .mode = 0644,
1665 .proc_handler = proc_dointvec,
1667 #endif
1668 #ifdef CONFIG_AIO
1670 .procname = "aio-nr",
1671 .data = &aio_nr,
1672 .maxlen = sizeof(aio_nr),
1673 .mode = 0444,
1674 .proc_handler = proc_doulongvec_minmax,
1677 .procname = "aio-max-nr",
1678 .data = &aio_max_nr,
1679 .maxlen = sizeof(aio_max_nr),
1680 .mode = 0644,
1681 .proc_handler = proc_doulongvec_minmax,
1683 #endif /* CONFIG_AIO */
1684 #ifdef CONFIG_INOTIFY_USER
1686 .procname = "inotify",
1687 .mode = 0555,
1688 .child = inotify_table,
1690 #endif
1691 #ifdef CONFIG_EPOLL
1693 .procname = "epoll",
1694 .mode = 0555,
1695 .child = epoll_table,
1697 #endif
1698 #endif
1700 .procname = "protected_symlinks",
1701 .data = &sysctl_protected_symlinks,
1702 .maxlen = sizeof(int),
1703 .mode = 0600,
1704 .proc_handler = proc_dointvec_minmax,
1705 .extra1 = &zero,
1706 .extra2 = &one,
1709 .procname = "protected_hardlinks",
1710 .data = &sysctl_protected_hardlinks,
1711 .maxlen = sizeof(int),
1712 .mode = 0600,
1713 .proc_handler = proc_dointvec_minmax,
1714 .extra1 = &zero,
1715 .extra2 = &one,
1718 .procname = "suid_dumpable",
1719 .data = &suid_dumpable,
1720 .maxlen = sizeof(int),
1721 .mode = 0644,
1722 .proc_handler = proc_dointvec_minmax_coredump,
1723 .extra1 = &zero,
1724 .extra2 = &two,
1726 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1728 .procname = "binfmt_misc",
1729 .mode = 0555,
1730 .child = sysctl_mount_point,
1732 #endif
1734 .procname = "pipe-max-size",
1735 .data = &pipe_max_size,
1736 .maxlen = sizeof(int),
1737 .mode = 0644,
1738 .proc_handler = &pipe_proc_fn,
1739 .extra1 = &pipe_min_size,
1742 .procname = "pipe-user-pages-hard",
1743 .data = &pipe_user_pages_hard,
1744 .maxlen = sizeof(pipe_user_pages_hard),
1745 .mode = 0644,
1746 .proc_handler = proc_doulongvec_minmax,
1749 .procname = "pipe-user-pages-soft",
1750 .data = &pipe_user_pages_soft,
1751 .maxlen = sizeof(pipe_user_pages_soft),
1752 .mode = 0644,
1753 .proc_handler = proc_doulongvec_minmax,
1756 .procname = "mount-max",
1757 .data = &sysctl_mount_max,
1758 .maxlen = sizeof(unsigned int),
1759 .mode = 0644,
1760 .proc_handler = proc_dointvec_minmax,
1761 .extra1 = &one,
1766 static struct ctl_table debug_table[] = {
1767 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1769 .procname = "exception-trace",
1770 .data = &show_unhandled_signals,
1771 .maxlen = sizeof(int),
1772 .mode = 0644,
1773 .proc_handler = proc_dointvec
1775 #endif
1776 #if defined(CONFIG_OPTPROBES)
1778 .procname = "kprobes-optimization",
1779 .data = &sysctl_kprobes_optimization,
1780 .maxlen = sizeof(int),
1781 .mode = 0644,
1782 .proc_handler = proc_kprobes_optimization_handler,
1783 .extra1 = &zero,
1784 .extra2 = &one,
1786 #endif
1790 static struct ctl_table dev_table[] = {
1794 int __init sysctl_init(void)
1796 struct ctl_table_header *hdr;
1798 hdr = register_sysctl_table(sysctl_base_table);
1799 kmemleak_not_leak(hdr);
1800 return 0;
1803 #endif /* CONFIG_SYSCTL */
1806 * /proc/sys support
1809 #ifdef CONFIG_PROC_SYSCTL
1811 static int _proc_do_string(char *data, int maxlen, int write,
1812 char __user *buffer,
1813 size_t *lenp, loff_t *ppos)
1815 size_t len;
1816 char __user *p;
1817 char c;
1819 if (!data || !maxlen || !*lenp) {
1820 *lenp = 0;
1821 return 0;
1824 if (write) {
1825 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1826 /* Only continue writes not past the end of buffer. */
1827 len = strlen(data);
1828 if (len > maxlen - 1)
1829 len = maxlen - 1;
1831 if (*ppos > len)
1832 return 0;
1833 len = *ppos;
1834 } else {
1835 /* Start writing from beginning of buffer. */
1836 len = 0;
1839 *ppos += *lenp;
1840 p = buffer;
1841 while ((p - buffer) < *lenp && len < maxlen - 1) {
1842 if (get_user(c, p++))
1843 return -EFAULT;
1844 if (c == 0 || c == '\n')
1845 break;
1846 data[len++] = c;
1848 data[len] = 0;
1849 } else {
1850 len = strlen(data);
1851 if (len > maxlen)
1852 len = maxlen;
1854 if (*ppos > len) {
1855 *lenp = 0;
1856 return 0;
1859 data += *ppos;
1860 len -= *ppos;
1862 if (len > *lenp)
1863 len = *lenp;
1864 if (len)
1865 if (copy_to_user(buffer, data, len))
1866 return -EFAULT;
1867 if (len < *lenp) {
1868 if (put_user('\n', buffer + len))
1869 return -EFAULT;
1870 len++;
1872 *lenp = len;
1873 *ppos += len;
1875 return 0;
1878 static void warn_sysctl_write(struct ctl_table *table)
1880 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1881 "This will not be supported in the future. To silence this\n"
1882 "warning, set kernel.sysctl_writes_strict = -1\n",
1883 current->comm, table->procname);
1887 * proc_dostring - read a string sysctl
1888 * @table: the sysctl table
1889 * @write: %TRUE if this is a write to the sysctl file
1890 * @buffer: the user buffer
1891 * @lenp: the size of the user buffer
1892 * @ppos: file position
1894 * Reads/writes a string from/to the user buffer. If the kernel
1895 * buffer provided is not large enough to hold the string, the
1896 * string is truncated. The copied string is %NULL-terminated.
1897 * If the string is being read by the user process, it is copied
1898 * and a newline '\n' is added. It is truncated if the buffer is
1899 * not large enough.
1901 * Returns 0 on success.
1903 int proc_dostring(struct ctl_table *table, int write,
1904 void __user *buffer, size_t *lenp, loff_t *ppos)
1906 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1907 warn_sysctl_write(table);
1909 return _proc_do_string((char *)(table->data), table->maxlen, write,
1910 (char __user *)buffer, lenp, ppos);
1913 static size_t proc_skip_spaces(char **buf)
1915 size_t ret;
1916 char *tmp = skip_spaces(*buf);
1917 ret = tmp - *buf;
1918 *buf = tmp;
1919 return ret;
1922 static void proc_skip_char(char **buf, size_t *size, const char v)
1924 while (*size) {
1925 if (**buf != v)
1926 break;
1927 (*size)--;
1928 (*buf)++;
1932 #define TMPBUFLEN 22
1934 * proc_get_long - reads an ASCII formatted integer from a user buffer
1936 * @buf: a kernel buffer
1937 * @size: size of the kernel buffer
1938 * @val: this is where the number will be stored
1939 * @neg: set to %TRUE if number is negative
1940 * @perm_tr: a vector which contains the allowed trailers
1941 * @perm_tr_len: size of the perm_tr vector
1942 * @tr: pointer to store the trailer character
1944 * In case of success %0 is returned and @buf and @size are updated with
1945 * the amount of bytes read. If @tr is non-NULL and a trailing
1946 * character exists (size is non-zero after returning from this
1947 * function), @tr is updated with the trailing character.
1949 static int proc_get_long(char **buf, size_t *size,
1950 unsigned long *val, bool *neg,
1951 const char *perm_tr, unsigned perm_tr_len, char *tr)
1953 int len;
1954 char *p, tmp[TMPBUFLEN];
1956 if (!*size)
1957 return -EINVAL;
1959 len = *size;
1960 if (len > TMPBUFLEN - 1)
1961 len = TMPBUFLEN - 1;
1963 memcpy(tmp, *buf, len);
1965 tmp[len] = 0;
1966 p = tmp;
1967 if (*p == '-' && *size > 1) {
1968 *neg = true;
1969 p++;
1970 } else
1971 *neg = false;
1972 if (!isdigit(*p))
1973 return -EINVAL;
1975 *val = simple_strtoul(p, &p, 0);
1977 len = p - tmp;
1979 /* We don't know if the next char is whitespace thus we may accept
1980 * invalid integers (e.g. 1234...a) or two integers instead of one
1981 * (e.g. 123...1). So lets not allow such large numbers. */
1982 if (len == TMPBUFLEN - 1)
1983 return -EINVAL;
1985 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1986 return -EINVAL;
1988 if (tr && (len < *size))
1989 *tr = *p;
1991 *buf += len;
1992 *size -= len;
1994 return 0;
1998 * proc_put_long - converts an integer to a decimal ASCII formatted string
2000 * @buf: the user buffer
2001 * @size: the size of the user buffer
2002 * @val: the integer to be converted
2003 * @neg: sign of the number, %TRUE for negative
2005 * In case of success %0 is returned and @buf and @size are updated with
2006 * the amount of bytes written.
2008 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2009 bool neg)
2011 int len;
2012 char tmp[TMPBUFLEN], *p = tmp;
2014 sprintf(p, "%s%lu", neg ? "-" : "", val);
2015 len = strlen(tmp);
2016 if (len > *size)
2017 len = *size;
2018 if (copy_to_user(*buf, tmp, len))
2019 return -EFAULT;
2020 *size -= len;
2021 *buf += len;
2022 return 0;
2024 #undef TMPBUFLEN
2026 static int proc_put_char(void __user **buf, size_t *size, char c)
2028 if (*size) {
2029 char __user **buffer = (char __user **)buf;
2030 if (put_user(c, *buffer))
2031 return -EFAULT;
2032 (*size)--, (*buffer)++;
2033 *buf = *buffer;
2035 return 0;
2038 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2039 int *valp,
2040 int write, void *data)
2042 if (write) {
2043 if (*negp) {
2044 if (*lvalp > (unsigned long) INT_MAX + 1)
2045 return -EINVAL;
2046 *valp = -*lvalp;
2047 } else {
2048 if (*lvalp > (unsigned long) INT_MAX)
2049 return -EINVAL;
2050 *valp = *lvalp;
2052 } else {
2053 int val = *valp;
2054 if (val < 0) {
2055 *negp = true;
2056 *lvalp = -(unsigned long)val;
2057 } else {
2058 *negp = false;
2059 *lvalp = (unsigned long)val;
2062 return 0;
2065 static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2066 int *valp,
2067 int write, void *data)
2069 if (write) {
2070 if (*negp)
2071 return -EINVAL;
2072 if (*lvalp > UINT_MAX)
2073 return -EINVAL;
2074 *valp = *lvalp;
2075 } else {
2076 unsigned int val = *valp;
2077 *negp = false;
2078 *lvalp = (unsigned long)val;
2080 return 0;
2083 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2085 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2086 int write, void __user *buffer,
2087 size_t *lenp, loff_t *ppos,
2088 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2089 int write, void *data),
2090 void *data)
2092 int *i, vleft, first = 1, err = 0;
2093 unsigned long page = 0;
2094 size_t left;
2095 char *kbuf;
2097 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2098 *lenp = 0;
2099 return 0;
2102 i = (int *) tbl_data;
2103 vleft = table->maxlen / sizeof(*i);
2104 left = *lenp;
2106 if (!conv)
2107 conv = do_proc_dointvec_conv;
2109 if (write) {
2110 if (*ppos) {
2111 switch (sysctl_writes_strict) {
2112 case SYSCTL_WRITES_STRICT:
2113 goto out;
2114 case SYSCTL_WRITES_WARN:
2115 warn_sysctl_write(table);
2116 break;
2117 default:
2118 break;
2122 if (left > PAGE_SIZE - 1)
2123 left = PAGE_SIZE - 1;
2124 page = __get_free_page(GFP_TEMPORARY);
2125 kbuf = (char *) page;
2126 if (!kbuf)
2127 return -ENOMEM;
2128 if (copy_from_user(kbuf, buffer, left)) {
2129 err = -EFAULT;
2130 goto free;
2132 kbuf[left] = 0;
2135 for (; left && vleft--; i++, first=0) {
2136 unsigned long lval;
2137 bool neg;
2139 if (write) {
2140 left -= proc_skip_spaces(&kbuf);
2142 if (!left)
2143 break;
2144 err = proc_get_long(&kbuf, &left, &lval, &neg,
2145 proc_wspace_sep,
2146 sizeof(proc_wspace_sep), NULL);
2147 if (err)
2148 break;
2149 if (conv(&neg, &lval, i, 1, data)) {
2150 err = -EINVAL;
2151 break;
2153 } else {
2154 if (conv(&neg, &lval, i, 0, data)) {
2155 err = -EINVAL;
2156 break;
2158 if (!first)
2159 err = proc_put_char(&buffer, &left, '\t');
2160 if (err)
2161 break;
2162 err = proc_put_long(&buffer, &left, lval, neg);
2163 if (err)
2164 break;
2168 if (!write && !first && left && !err)
2169 err = proc_put_char(&buffer, &left, '\n');
2170 if (write && !err && left)
2171 left -= proc_skip_spaces(&kbuf);
2172 free:
2173 if (write) {
2174 free_page(page);
2175 if (first)
2176 return err ? : -EINVAL;
2178 *lenp -= left;
2179 out:
2180 *ppos += *lenp;
2181 return err;
2184 static int do_proc_dointvec(struct ctl_table *table, int write,
2185 void __user *buffer, size_t *lenp, loff_t *ppos,
2186 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2187 int write, void *data),
2188 void *data)
2190 return __do_proc_dointvec(table->data, table, write,
2191 buffer, lenp, ppos, conv, data);
2195 * proc_dointvec - read a vector of integers
2196 * @table: the sysctl table
2197 * @write: %TRUE if this is a write to the sysctl file
2198 * @buffer: the user buffer
2199 * @lenp: the size of the user buffer
2200 * @ppos: file position
2202 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2203 * values from/to the user buffer, treated as an ASCII string.
2205 * Returns 0 on success.
2207 int proc_dointvec(struct ctl_table *table, int write,
2208 void __user *buffer, size_t *lenp, loff_t *ppos)
2210 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2214 * proc_douintvec - read a vector of unsigned integers
2215 * @table: the sysctl table
2216 * @write: %TRUE if this is a write to the sysctl file
2217 * @buffer: the user buffer
2218 * @lenp: the size of the user buffer
2219 * @ppos: file position
2221 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2222 * values from/to the user buffer, treated as an ASCII string.
2224 * Returns 0 on success.
2226 int proc_douintvec(struct ctl_table *table, int write,
2227 void __user *buffer, size_t *lenp, loff_t *ppos)
2229 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2230 do_proc_douintvec_conv, NULL);
2234 * Taint values can only be increased
2235 * This means we can safely use a temporary.
2237 static int proc_taint(struct ctl_table *table, int write,
2238 void __user *buffer, size_t *lenp, loff_t *ppos)
2240 struct ctl_table t;
2241 unsigned long tmptaint = get_taint();
2242 int err;
2244 if (write && !capable(CAP_SYS_ADMIN))
2245 return -EPERM;
2247 t = *table;
2248 t.data = &tmptaint;
2249 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2250 if (err < 0)
2251 return err;
2253 if (write) {
2255 * Poor man's atomic or. Not worth adding a primitive
2256 * to everyone's atomic.h for this
2258 int i;
2259 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2260 if ((tmptaint >> i) & 1)
2261 add_taint(i, LOCKDEP_STILL_OK);
2265 return err;
2268 #ifdef CONFIG_PRINTK
2269 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2270 void __user *buffer, size_t *lenp, loff_t *ppos)
2272 if (write && !capable(CAP_SYS_ADMIN))
2273 return -EPERM;
2275 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2277 #endif
2279 struct do_proc_dointvec_minmax_conv_param {
2280 int *min;
2281 int *max;
2284 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2285 int *valp,
2286 int write, void *data)
2288 struct do_proc_dointvec_minmax_conv_param *param = data;
2289 if (write) {
2290 int val = *negp ? -*lvalp : *lvalp;
2291 if ((param->min && *param->min > val) ||
2292 (param->max && *param->max < val))
2293 return -EINVAL;
2294 *valp = val;
2295 } else {
2296 int val = *valp;
2297 if (val < 0) {
2298 *negp = true;
2299 *lvalp = -(unsigned long)val;
2300 } else {
2301 *negp = false;
2302 *lvalp = (unsigned long)val;
2305 return 0;
2309 * proc_dointvec_minmax - read a vector of integers with min/max values
2310 * @table: the sysctl table
2311 * @write: %TRUE if this is a write to the sysctl file
2312 * @buffer: the user buffer
2313 * @lenp: the size of the user buffer
2314 * @ppos: file position
2316 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2317 * values from/to the user buffer, treated as an ASCII string.
2319 * This routine will ensure the values are within the range specified by
2320 * table->extra1 (min) and table->extra2 (max).
2322 * Returns 0 on success.
2324 int proc_dointvec_minmax(struct ctl_table *table, int write,
2325 void __user *buffer, size_t *lenp, loff_t *ppos)
2327 struct do_proc_dointvec_minmax_conv_param param = {
2328 .min = (int *) table->extra1,
2329 .max = (int *) table->extra2,
2331 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2332 do_proc_dointvec_minmax_conv, &param);
2335 static void validate_coredump_safety(void)
2337 #ifdef CONFIG_COREDUMP
2338 if (suid_dumpable == SUID_DUMP_ROOT &&
2339 core_pattern[0] != '/' && core_pattern[0] != '|') {
2340 printk(KERN_WARNING "Unsafe core_pattern used with "\
2341 "suid_dumpable=2. Pipe handler or fully qualified "\
2342 "core dump path required.\n");
2344 #endif
2347 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2348 void __user *buffer, size_t *lenp, loff_t *ppos)
2350 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2351 if (!error)
2352 validate_coredump_safety();
2353 return error;
2356 #ifdef CONFIG_COREDUMP
2357 static int proc_dostring_coredump(struct ctl_table *table, int write,
2358 void __user *buffer, size_t *lenp, loff_t *ppos)
2360 int error = proc_dostring(table, write, buffer, lenp, ppos);
2361 if (!error)
2362 validate_coredump_safety();
2363 return error;
2365 #endif
2367 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2368 void __user *buffer,
2369 size_t *lenp, loff_t *ppos,
2370 unsigned long convmul,
2371 unsigned long convdiv)
2373 unsigned long *i, *min, *max;
2374 int vleft, first = 1, err = 0;
2375 unsigned long page = 0;
2376 size_t left;
2377 char *kbuf;
2379 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2380 *lenp = 0;
2381 return 0;
2384 i = (unsigned long *) data;
2385 min = (unsigned long *) table->extra1;
2386 max = (unsigned long *) table->extra2;
2387 vleft = table->maxlen / sizeof(unsigned long);
2388 left = *lenp;
2390 if (write) {
2391 if (*ppos) {
2392 switch (sysctl_writes_strict) {
2393 case SYSCTL_WRITES_STRICT:
2394 goto out;
2395 case SYSCTL_WRITES_WARN:
2396 warn_sysctl_write(table);
2397 break;
2398 default:
2399 break;
2403 if (left > PAGE_SIZE - 1)
2404 left = PAGE_SIZE - 1;
2405 page = __get_free_page(GFP_TEMPORARY);
2406 kbuf = (char *) page;
2407 if (!kbuf)
2408 return -ENOMEM;
2409 if (copy_from_user(kbuf, buffer, left)) {
2410 err = -EFAULT;
2411 goto free;
2413 kbuf[left] = 0;
2416 for (; left && vleft--; i++, first = 0) {
2417 unsigned long val;
2419 if (write) {
2420 bool neg;
2422 left -= proc_skip_spaces(&kbuf);
2424 err = proc_get_long(&kbuf, &left, &val, &neg,
2425 proc_wspace_sep,
2426 sizeof(proc_wspace_sep), NULL);
2427 if (err)
2428 break;
2429 if (neg)
2430 continue;
2431 val = convmul * val / convdiv;
2432 if ((min && val < *min) || (max && val > *max))
2433 continue;
2434 *i = val;
2435 } else {
2436 val = convdiv * (*i) / convmul;
2437 if (!first) {
2438 err = proc_put_char(&buffer, &left, '\t');
2439 if (err)
2440 break;
2442 err = proc_put_long(&buffer, &left, val, false);
2443 if (err)
2444 break;
2448 if (!write && !first && left && !err)
2449 err = proc_put_char(&buffer, &left, '\n');
2450 if (write && !err)
2451 left -= proc_skip_spaces(&kbuf);
2452 free:
2453 if (write) {
2454 free_page(page);
2455 if (first)
2456 return err ? : -EINVAL;
2458 *lenp -= left;
2459 out:
2460 *ppos += *lenp;
2461 return err;
2464 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2465 void __user *buffer,
2466 size_t *lenp, loff_t *ppos,
2467 unsigned long convmul,
2468 unsigned long convdiv)
2470 return __do_proc_doulongvec_minmax(table->data, table, write,
2471 buffer, lenp, ppos, convmul, convdiv);
2475 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2476 * @table: the sysctl table
2477 * @write: %TRUE if this is a write to the sysctl file
2478 * @buffer: the user buffer
2479 * @lenp: the size of the user buffer
2480 * @ppos: file position
2482 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2483 * values from/to the user buffer, treated as an ASCII string.
2485 * This routine will ensure the values are within the range specified by
2486 * table->extra1 (min) and table->extra2 (max).
2488 * Returns 0 on success.
2490 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2491 void __user *buffer, size_t *lenp, loff_t *ppos)
2493 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2497 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2498 * @table: the sysctl table
2499 * @write: %TRUE if this is a write to the sysctl file
2500 * @buffer: the user buffer
2501 * @lenp: the size of the user buffer
2502 * @ppos: file position
2504 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2505 * values from/to the user buffer, treated as an ASCII string. The values
2506 * are treated as milliseconds, and converted to jiffies when they are stored.
2508 * This routine will ensure the values are within the range specified by
2509 * table->extra1 (min) and table->extra2 (max).
2511 * Returns 0 on success.
2513 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2514 void __user *buffer,
2515 size_t *lenp, loff_t *ppos)
2517 return do_proc_doulongvec_minmax(table, write, buffer,
2518 lenp, ppos, HZ, 1000l);
2522 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2523 int *valp,
2524 int write, void *data)
2526 if (write) {
2527 if (*lvalp > LONG_MAX / HZ)
2528 return 1;
2529 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2530 } else {
2531 int val = *valp;
2532 unsigned long lval;
2533 if (val < 0) {
2534 *negp = true;
2535 lval = -(unsigned long)val;
2536 } else {
2537 *negp = false;
2538 lval = (unsigned long)val;
2540 *lvalp = lval / HZ;
2542 return 0;
2545 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2546 int *valp,
2547 int write, void *data)
2549 if (write) {
2550 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2551 return 1;
2552 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2553 } else {
2554 int val = *valp;
2555 unsigned long lval;
2556 if (val < 0) {
2557 *negp = true;
2558 lval = -(unsigned long)val;
2559 } else {
2560 *negp = false;
2561 lval = (unsigned long)val;
2563 *lvalp = jiffies_to_clock_t(lval);
2565 return 0;
2568 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2569 int *valp,
2570 int write, void *data)
2572 if (write) {
2573 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2575 if (jif > INT_MAX)
2576 return 1;
2577 *valp = (int)jif;
2578 } else {
2579 int val = *valp;
2580 unsigned long lval;
2581 if (val < 0) {
2582 *negp = true;
2583 lval = -(unsigned long)val;
2584 } else {
2585 *negp = false;
2586 lval = (unsigned long)val;
2588 *lvalp = jiffies_to_msecs(lval);
2590 return 0;
2594 * proc_dointvec_jiffies - read a vector of integers as seconds
2595 * @table: the sysctl table
2596 * @write: %TRUE if this is a write to the sysctl file
2597 * @buffer: the user buffer
2598 * @lenp: the size of the user buffer
2599 * @ppos: file position
2601 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2602 * values from/to the user buffer, treated as an ASCII string.
2603 * The values read are assumed to be in seconds, and are converted into
2604 * jiffies.
2606 * Returns 0 on success.
2608 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2609 void __user *buffer, size_t *lenp, loff_t *ppos)
2611 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2612 do_proc_dointvec_jiffies_conv,NULL);
2616 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2617 * @table: the sysctl table
2618 * @write: %TRUE if this is a write to the sysctl file
2619 * @buffer: the user buffer
2620 * @lenp: the size of the user buffer
2621 * @ppos: pointer to the file position
2623 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2624 * values from/to the user buffer, treated as an ASCII string.
2625 * The values read are assumed to be in 1/USER_HZ seconds, and
2626 * are converted into jiffies.
2628 * Returns 0 on success.
2630 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2631 void __user *buffer, size_t *lenp, loff_t *ppos)
2633 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2634 do_proc_dointvec_userhz_jiffies_conv,NULL);
2638 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2639 * @table: the sysctl table
2640 * @write: %TRUE if this is a write to the sysctl file
2641 * @buffer: the user buffer
2642 * @lenp: the size of the user buffer
2643 * @ppos: file position
2644 * @ppos: the current position in the file
2646 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2647 * values from/to the user buffer, treated as an ASCII string.
2648 * The values read are assumed to be in 1/1000 seconds, and
2649 * are converted into jiffies.
2651 * Returns 0 on success.
2653 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2654 void __user *buffer, size_t *lenp, loff_t *ppos)
2656 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2657 do_proc_dointvec_ms_jiffies_conv, NULL);
2660 static int proc_do_cad_pid(struct ctl_table *table, int write,
2661 void __user *buffer, size_t *lenp, loff_t *ppos)
2663 struct pid *new_pid;
2664 pid_t tmp;
2665 int r;
2667 tmp = pid_vnr(cad_pid);
2669 r = __do_proc_dointvec(&tmp, table, write, buffer,
2670 lenp, ppos, NULL, NULL);
2671 if (r || !write)
2672 return r;
2674 new_pid = find_get_pid(tmp);
2675 if (!new_pid)
2676 return -ESRCH;
2678 put_pid(xchg(&cad_pid, new_pid));
2679 return 0;
2683 * proc_do_large_bitmap - read/write from/to a large bitmap
2684 * @table: the sysctl table
2685 * @write: %TRUE if this is a write to the sysctl file
2686 * @buffer: the user buffer
2687 * @lenp: the size of the user buffer
2688 * @ppos: file position
2690 * The bitmap is stored at table->data and the bitmap length (in bits)
2691 * in table->maxlen.
2693 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2694 * large bitmaps may be represented in a compact manner. Writing into
2695 * the file will clear the bitmap then update it with the given input.
2697 * Returns 0 on success.
2699 int proc_do_large_bitmap(struct ctl_table *table, int write,
2700 void __user *buffer, size_t *lenp, loff_t *ppos)
2702 int err = 0;
2703 bool first = 1;
2704 size_t left = *lenp;
2705 unsigned long bitmap_len = table->maxlen;
2706 unsigned long *bitmap = *(unsigned long **) table->data;
2707 unsigned long *tmp_bitmap = NULL;
2708 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2710 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2711 *lenp = 0;
2712 return 0;
2715 if (write) {
2716 unsigned long page = 0;
2717 char *kbuf;
2719 if (left > PAGE_SIZE - 1)
2720 left = PAGE_SIZE - 1;
2722 page = __get_free_page(GFP_TEMPORARY);
2723 kbuf = (char *) page;
2724 if (!kbuf)
2725 return -ENOMEM;
2726 if (copy_from_user(kbuf, buffer, left)) {
2727 free_page(page);
2728 return -EFAULT;
2730 kbuf[left] = 0;
2732 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2733 GFP_KERNEL);
2734 if (!tmp_bitmap) {
2735 free_page(page);
2736 return -ENOMEM;
2738 proc_skip_char(&kbuf, &left, '\n');
2739 while (!err && left) {
2740 unsigned long val_a, val_b;
2741 bool neg;
2743 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2744 sizeof(tr_a), &c);
2745 if (err)
2746 break;
2747 if (val_a >= bitmap_len || neg) {
2748 err = -EINVAL;
2749 break;
2752 val_b = val_a;
2753 if (left) {
2754 kbuf++;
2755 left--;
2758 if (c == '-') {
2759 err = proc_get_long(&kbuf, &left, &val_b,
2760 &neg, tr_b, sizeof(tr_b),
2761 &c);
2762 if (err)
2763 break;
2764 if (val_b >= bitmap_len || neg ||
2765 val_a > val_b) {
2766 err = -EINVAL;
2767 break;
2769 if (left) {
2770 kbuf++;
2771 left--;
2775 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2776 first = 0;
2777 proc_skip_char(&kbuf, &left, '\n');
2779 free_page(page);
2780 } else {
2781 unsigned long bit_a, bit_b = 0;
2783 while (left) {
2784 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2785 if (bit_a >= bitmap_len)
2786 break;
2787 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2788 bit_a + 1) - 1;
2790 if (!first) {
2791 err = proc_put_char(&buffer, &left, ',');
2792 if (err)
2793 break;
2795 err = proc_put_long(&buffer, &left, bit_a, false);
2796 if (err)
2797 break;
2798 if (bit_a != bit_b) {
2799 err = proc_put_char(&buffer, &left, '-');
2800 if (err)
2801 break;
2802 err = proc_put_long(&buffer, &left, bit_b, false);
2803 if (err)
2804 break;
2807 first = 0; bit_b++;
2809 if (!err)
2810 err = proc_put_char(&buffer, &left, '\n');
2813 if (!err) {
2814 if (write) {
2815 if (*ppos)
2816 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2817 else
2818 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2820 kfree(tmp_bitmap);
2821 *lenp -= left;
2822 *ppos += *lenp;
2823 return 0;
2824 } else {
2825 kfree(tmp_bitmap);
2826 return err;
2830 #else /* CONFIG_PROC_SYSCTL */
2832 int proc_dostring(struct ctl_table *table, int write,
2833 void __user *buffer, size_t *lenp, loff_t *ppos)
2835 return -ENOSYS;
2838 int proc_dointvec(struct ctl_table *table, int write,
2839 void __user *buffer, size_t *lenp, loff_t *ppos)
2841 return -ENOSYS;
2844 int proc_douintvec(struct ctl_table *table, int write,
2845 void __user *buffer, size_t *lenp, loff_t *ppos)
2847 return -ENOSYS;
2850 int proc_dointvec_minmax(struct ctl_table *table, int write,
2851 void __user *buffer, size_t *lenp, loff_t *ppos)
2853 return -ENOSYS;
2856 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2857 void __user *buffer, size_t *lenp, loff_t *ppos)
2859 return -ENOSYS;
2862 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2863 void __user *buffer, size_t *lenp, loff_t *ppos)
2865 return -ENOSYS;
2868 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2869 void __user *buffer, size_t *lenp, loff_t *ppos)
2871 return -ENOSYS;
2874 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2875 void __user *buffer, size_t *lenp, loff_t *ppos)
2877 return -ENOSYS;
2880 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2881 void __user *buffer,
2882 size_t *lenp, loff_t *ppos)
2884 return -ENOSYS;
2888 #endif /* CONFIG_PROC_SYSCTL */
2891 * No sense putting this after each symbol definition, twice,
2892 * exception granted :-)
2894 EXPORT_SYMBOL(proc_dointvec);
2895 EXPORT_SYMBOL(proc_douintvec);
2896 EXPORT_SYMBOL(proc_dointvec_jiffies);
2897 EXPORT_SYMBOL(proc_dointvec_minmax);
2898 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2899 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2900 EXPORT_SYMBOL(proc_dostring);
2901 EXPORT_SYMBOL(proc_doulongvec_minmax);
2902 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);