sparc: Fix parport build warnings.
[linux/fpc-iii.git] / kernel / sysctl.c
blob24c7fe8608d0280df1d3d030f91ee336b00e4fe4
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 zero_ul;
129 static unsigned long one_ul = 1;
130 static unsigned long long_max = LONG_MAX;
131 static int one_hundred = 100;
132 #ifdef CONFIG_PRINTK
133 static int ten_thousand = 10000;
134 #endif
136 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
137 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
139 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
140 static int maxolduid = 65535;
141 static int minolduid;
143 static int ngroups_max = NGROUPS_MAX;
144 static const int cap_last_cap = CAP_LAST_CAP;
146 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
147 #ifdef CONFIG_DETECT_HUNG_TASK
148 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
149 #endif
151 #ifdef CONFIG_INOTIFY_USER
152 #include <linux/inotify.h>
153 #endif
154 #ifdef CONFIG_SPARC
155 #endif
157 #ifdef __hppa__
158 extern int pwrsw_enabled;
159 #endif
161 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
162 extern int unaligned_enabled;
163 #endif
165 #ifdef CONFIG_IA64
166 extern int unaligned_dump_stack;
167 #endif
169 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
170 extern int no_unaligned_warning;
171 #endif
173 #ifdef CONFIG_PROC_SYSCTL
175 #define SYSCTL_WRITES_LEGACY -1
176 #define SYSCTL_WRITES_WARN 0
177 #define SYSCTL_WRITES_STRICT 1
179 static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
181 static int proc_do_cad_pid(struct ctl_table *table, int write,
182 void __user *buffer, size_t *lenp, loff_t *ppos);
183 static int proc_taint(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
185 #endif
187 #ifdef CONFIG_PRINTK
188 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
189 void __user *buffer, size_t *lenp, loff_t *ppos);
190 #endif
192 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
193 void __user *buffer, size_t *lenp, loff_t *ppos);
194 #ifdef CONFIG_COREDUMP
195 static int proc_dostring_coredump(struct ctl_table *table, int write,
196 void __user *buffer, size_t *lenp, loff_t *ppos);
197 #endif
199 #ifdef CONFIG_MAGIC_SYSRQ
200 /* Note: sysrq code uses it's own private copy */
201 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
203 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
204 void __user *buffer, size_t *lenp,
205 loff_t *ppos)
207 int error;
209 error = proc_dointvec(table, write, buffer, lenp, ppos);
210 if (error)
211 return error;
213 if (write)
214 sysrq_toggle_support(__sysrq_enabled);
216 return 0;
219 #endif
221 static struct ctl_table kern_table[];
222 static struct ctl_table vm_table[];
223 static struct ctl_table fs_table[];
224 static struct ctl_table debug_table[];
225 static struct ctl_table dev_table[];
226 extern struct ctl_table random_table[];
227 #ifdef CONFIG_EPOLL
228 extern struct ctl_table epoll_table[];
229 #endif
231 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
232 int sysctl_legacy_va_layout;
233 #endif
235 /* The default sysctl tables: */
237 static struct ctl_table sysctl_base_table[] = {
239 .procname = "kernel",
240 .mode = 0555,
241 .child = kern_table,
244 .procname = "vm",
245 .mode = 0555,
246 .child = vm_table,
249 .procname = "fs",
250 .mode = 0555,
251 .child = fs_table,
254 .procname = "debug",
255 .mode = 0555,
256 .child = debug_table,
259 .procname = "dev",
260 .mode = 0555,
261 .child = dev_table,
266 #ifdef CONFIG_SCHED_DEBUG
267 static int min_sched_granularity_ns = 100000; /* 100 usecs */
268 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
269 static int min_wakeup_granularity_ns; /* 0 usecs */
270 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
271 #ifdef CONFIG_SMP
272 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
273 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
274 #endif /* CONFIG_SMP */
275 #endif /* CONFIG_SCHED_DEBUG */
277 #ifdef CONFIG_COMPACTION
278 static int min_extfrag_threshold;
279 static int max_extfrag_threshold = 1000;
280 #endif
282 static struct ctl_table kern_table[] = {
284 .procname = "sched_child_runs_first",
285 .data = &sysctl_sched_child_runs_first,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
288 .proc_handler = proc_dointvec,
290 #ifdef CONFIG_SCHED_DEBUG
292 .procname = "sched_min_granularity_ns",
293 .data = &sysctl_sched_min_granularity,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = sched_proc_update_handler,
297 .extra1 = &min_sched_granularity_ns,
298 .extra2 = &max_sched_granularity_ns,
301 .procname = "sched_latency_ns",
302 .data = &sysctl_sched_latency,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = sched_proc_update_handler,
306 .extra1 = &min_sched_granularity_ns,
307 .extra2 = &max_sched_granularity_ns,
310 .procname = "sched_wakeup_granularity_ns",
311 .data = &sysctl_sched_wakeup_granularity,
312 .maxlen = sizeof(unsigned int),
313 .mode = 0644,
314 .proc_handler = sched_proc_update_handler,
315 .extra1 = &min_wakeup_granularity_ns,
316 .extra2 = &max_wakeup_granularity_ns,
318 #ifdef CONFIG_SMP
320 .procname = "sched_tunable_scaling",
321 .data = &sysctl_sched_tunable_scaling,
322 .maxlen = sizeof(enum sched_tunable_scaling),
323 .mode = 0644,
324 .proc_handler = sched_proc_update_handler,
325 .extra1 = &min_sched_tunable_scaling,
326 .extra2 = &max_sched_tunable_scaling,
329 .procname = "sched_migration_cost_ns",
330 .data = &sysctl_sched_migration_cost,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
333 .proc_handler = proc_dointvec,
336 .procname = "sched_nr_migrate",
337 .data = &sysctl_sched_nr_migrate,
338 .maxlen = sizeof(unsigned int),
339 .mode = 0644,
340 .proc_handler = proc_dointvec,
343 .procname = "sched_time_avg_ms",
344 .data = &sysctl_sched_time_avg,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
347 .proc_handler = proc_dointvec_minmax,
348 .extra1 = &one,
351 .procname = "sched_shares_window_ns",
352 .data = &sysctl_sched_shares_window,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
355 .proc_handler = proc_dointvec,
357 #endif /* CONFIG_SMP */
358 #ifdef CONFIG_NUMA_BALANCING
360 .procname = "numa_balancing_scan_delay_ms",
361 .data = &sysctl_numa_balancing_scan_delay,
362 .maxlen = sizeof(unsigned int),
363 .mode = 0644,
364 .proc_handler = proc_dointvec,
367 .procname = "numa_balancing_scan_period_min_ms",
368 .data = &sysctl_numa_balancing_scan_period_min,
369 .maxlen = sizeof(unsigned int),
370 .mode = 0644,
371 .proc_handler = proc_dointvec,
374 .procname = "numa_balancing_scan_period_max_ms",
375 .data = &sysctl_numa_balancing_scan_period_max,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
378 .proc_handler = proc_dointvec,
381 .procname = "numa_balancing_scan_size_mb",
382 .data = &sysctl_numa_balancing_scan_size,
383 .maxlen = sizeof(unsigned int),
384 .mode = 0644,
385 .proc_handler = proc_dointvec_minmax,
386 .extra1 = &one,
389 .procname = "numa_balancing",
390 .data = NULL, /* filled in by handler */
391 .maxlen = sizeof(unsigned int),
392 .mode = 0644,
393 .proc_handler = sysctl_numa_balancing,
394 .extra1 = &zero,
395 .extra2 = &one,
397 #endif /* CONFIG_NUMA_BALANCING */
398 #endif /* CONFIG_SCHED_DEBUG */
400 .procname = "sched_rt_period_us",
401 .data = &sysctl_sched_rt_period,
402 .maxlen = sizeof(unsigned int),
403 .mode = 0644,
404 .proc_handler = sched_rt_handler,
407 .procname = "sched_rt_runtime_us",
408 .data = &sysctl_sched_rt_runtime,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = sched_rt_handler,
414 .procname = "sched_rr_timeslice_ms",
415 .data = &sched_rr_timeslice,
416 .maxlen = sizeof(int),
417 .mode = 0644,
418 .proc_handler = sched_rr_handler,
420 #ifdef CONFIG_SCHED_AUTOGROUP
422 .procname = "sched_autogroup_enabled",
423 .data = &sysctl_sched_autogroup_enabled,
424 .maxlen = sizeof(unsigned int),
425 .mode = 0644,
426 .proc_handler = proc_dointvec_minmax,
427 .extra1 = &zero,
428 .extra2 = &one,
430 #endif
431 #ifdef CONFIG_CFS_BANDWIDTH
433 .procname = "sched_cfs_bandwidth_slice_us",
434 .data = &sysctl_sched_cfs_bandwidth_slice,
435 .maxlen = sizeof(unsigned int),
436 .mode = 0644,
437 .proc_handler = proc_dointvec_minmax,
438 .extra1 = &one,
440 #endif
441 #ifdef CONFIG_PROVE_LOCKING
443 .procname = "prove_locking",
444 .data = &prove_locking,
445 .maxlen = sizeof(int),
446 .mode = 0644,
447 .proc_handler = proc_dointvec,
449 #endif
450 #ifdef CONFIG_LOCK_STAT
452 .procname = "lock_stat",
453 .data = &lock_stat,
454 .maxlen = sizeof(int),
455 .mode = 0644,
456 .proc_handler = proc_dointvec,
458 #endif
460 .procname = "panic",
461 .data = &panic_timeout,
462 .maxlen = sizeof(int),
463 .mode = 0644,
464 .proc_handler = proc_dointvec,
466 #ifdef CONFIG_COREDUMP
468 .procname = "core_uses_pid",
469 .data = &core_uses_pid,
470 .maxlen = sizeof(int),
471 .mode = 0644,
472 .proc_handler = proc_dointvec,
475 .procname = "core_pattern",
476 .data = core_pattern,
477 .maxlen = CORENAME_MAX_SIZE,
478 .mode = 0644,
479 .proc_handler = proc_dostring_coredump,
482 .procname = "core_pipe_limit",
483 .data = &core_pipe_limit,
484 .maxlen = sizeof(unsigned int),
485 .mode = 0644,
486 .proc_handler = proc_dointvec,
488 #endif
489 #ifdef CONFIG_PROC_SYSCTL
491 .procname = "tainted",
492 .maxlen = sizeof(long),
493 .mode = 0644,
494 .proc_handler = proc_taint,
497 .procname = "sysctl_writes_strict",
498 .data = &sysctl_writes_strict,
499 .maxlen = sizeof(int),
500 .mode = 0644,
501 .proc_handler = proc_dointvec_minmax,
502 .extra1 = &neg_one,
503 .extra2 = &one,
505 #endif
506 #ifdef CONFIG_LATENCYTOP
508 .procname = "latencytop",
509 .data = &latencytop_enabled,
510 .maxlen = sizeof(int),
511 .mode = 0644,
512 .proc_handler = proc_dointvec,
514 #endif
515 #ifdef CONFIG_BLK_DEV_INITRD
517 .procname = "real-root-dev",
518 .data = &real_root_dev,
519 .maxlen = sizeof(int),
520 .mode = 0644,
521 .proc_handler = proc_dointvec,
523 #endif
525 .procname = "print-fatal-signals",
526 .data = &print_fatal_signals,
527 .maxlen = sizeof(int),
528 .mode = 0644,
529 .proc_handler = proc_dointvec,
531 #ifdef CONFIG_SPARC
533 .procname = "reboot-cmd",
534 .data = reboot_command,
535 .maxlen = 256,
536 .mode = 0644,
537 .proc_handler = proc_dostring,
540 .procname = "stop-a",
541 .data = &stop_a_enabled,
542 .maxlen = sizeof (int),
543 .mode = 0644,
544 .proc_handler = proc_dointvec,
547 .procname = "scons-poweroff",
548 .data = &scons_pwroff,
549 .maxlen = sizeof (int),
550 .mode = 0644,
551 .proc_handler = proc_dointvec,
553 #endif
554 #ifdef CONFIG_SPARC64
556 .procname = "tsb-ratio",
557 .data = &sysctl_tsb_ratio,
558 .maxlen = sizeof (int),
559 .mode = 0644,
560 .proc_handler = proc_dointvec,
562 #endif
563 #ifdef __hppa__
565 .procname = "soft-power",
566 .data = &pwrsw_enabled,
567 .maxlen = sizeof (int),
568 .mode = 0644,
569 .proc_handler = proc_dointvec,
571 #endif
572 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
574 .procname = "unaligned-trap",
575 .data = &unaligned_enabled,
576 .maxlen = sizeof (int),
577 .mode = 0644,
578 .proc_handler = proc_dointvec,
580 #endif
582 .procname = "ctrl-alt-del",
583 .data = &C_A_D,
584 .maxlen = sizeof(int),
585 .mode = 0644,
586 .proc_handler = proc_dointvec,
588 #ifdef CONFIG_FUNCTION_TRACER
590 .procname = "ftrace_enabled",
591 .data = &ftrace_enabled,
592 .maxlen = sizeof(int),
593 .mode = 0644,
594 .proc_handler = ftrace_enable_sysctl,
596 #endif
597 #ifdef CONFIG_STACK_TRACER
599 .procname = "stack_tracer_enabled",
600 .data = &stack_tracer_enabled,
601 .maxlen = sizeof(int),
602 .mode = 0644,
603 .proc_handler = stack_trace_sysctl,
605 #endif
606 #ifdef CONFIG_TRACING
608 .procname = "ftrace_dump_on_oops",
609 .data = &ftrace_dump_on_oops,
610 .maxlen = sizeof(int),
611 .mode = 0644,
612 .proc_handler = proc_dointvec,
615 .procname = "traceoff_on_warning",
616 .data = &__disable_trace_on_warning,
617 .maxlen = sizeof(__disable_trace_on_warning),
618 .mode = 0644,
619 .proc_handler = proc_dointvec,
622 .procname = "tracepoint_printk",
623 .data = &tracepoint_printk,
624 .maxlen = sizeof(tracepoint_printk),
625 .mode = 0644,
626 .proc_handler = proc_dointvec,
628 #endif
629 #ifdef CONFIG_KEXEC_CORE
631 .procname = "kexec_load_disabled",
632 .data = &kexec_load_disabled,
633 .maxlen = sizeof(int),
634 .mode = 0644,
635 /* only handle a transition from default "0" to "1" */
636 .proc_handler = proc_dointvec_minmax,
637 .extra1 = &one,
638 .extra2 = &one,
640 #endif
641 #ifdef CONFIG_MODULES
643 .procname = "modprobe",
644 .data = &modprobe_path,
645 .maxlen = KMOD_PATH_LEN,
646 .mode = 0644,
647 .proc_handler = proc_dostring,
650 .procname = "modules_disabled",
651 .data = &modules_disabled,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 /* only handle a transition from default "0" to "1" */
655 .proc_handler = proc_dointvec_minmax,
656 .extra1 = &one,
657 .extra2 = &one,
659 #endif
660 #ifdef CONFIG_UEVENT_HELPER
662 .procname = "hotplug",
663 .data = &uevent_helper,
664 .maxlen = UEVENT_HELPER_PATH_LEN,
665 .mode = 0644,
666 .proc_handler = proc_dostring,
668 #endif
669 #ifdef CONFIG_CHR_DEV_SG
671 .procname = "sg-big-buff",
672 .data = &sg_big_buff,
673 .maxlen = sizeof (int),
674 .mode = 0444,
675 .proc_handler = proc_dointvec,
677 #endif
678 #ifdef CONFIG_BSD_PROCESS_ACCT
680 .procname = "acct",
681 .data = &acct_parm,
682 .maxlen = 3*sizeof(int),
683 .mode = 0644,
684 .proc_handler = proc_dointvec,
686 #endif
687 #ifdef CONFIG_MAGIC_SYSRQ
689 .procname = "sysrq",
690 .data = &__sysrq_enabled,
691 .maxlen = sizeof (int),
692 .mode = 0644,
693 .proc_handler = sysrq_sysctl_handler,
695 #endif
696 #ifdef CONFIG_PROC_SYSCTL
698 .procname = "cad_pid",
699 .data = NULL,
700 .maxlen = sizeof (int),
701 .mode = 0600,
702 .proc_handler = proc_do_cad_pid,
704 #endif
706 .procname = "threads-max",
707 .data = NULL,
708 .maxlen = sizeof(int),
709 .mode = 0644,
710 .proc_handler = sysctl_max_threads,
713 .procname = "random",
714 .mode = 0555,
715 .child = random_table,
718 .procname = "usermodehelper",
719 .mode = 0555,
720 .child = usermodehelper_table,
723 .procname = "overflowuid",
724 .data = &overflowuid,
725 .maxlen = sizeof(int),
726 .mode = 0644,
727 .proc_handler = proc_dointvec_minmax,
728 .extra1 = &minolduid,
729 .extra2 = &maxolduid,
732 .procname = "overflowgid",
733 .data = &overflowgid,
734 .maxlen = sizeof(int),
735 .mode = 0644,
736 .proc_handler = proc_dointvec_minmax,
737 .extra1 = &minolduid,
738 .extra2 = &maxolduid,
740 #ifdef CONFIG_S390
741 #ifdef CONFIG_MATHEMU
743 .procname = "ieee_emulation_warnings",
744 .data = &sysctl_ieee_emulation_warnings,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = proc_dointvec,
749 #endif
751 .procname = "userprocess_debug",
752 .data = &show_unhandled_signals,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = proc_dointvec,
757 #endif
759 .procname = "pid_max",
760 .data = &pid_max,
761 .maxlen = sizeof (int),
762 .mode = 0644,
763 .proc_handler = proc_dointvec_minmax,
764 .extra1 = &pid_max_min,
765 .extra2 = &pid_max_max,
768 .procname = "panic_on_oops",
769 .data = &panic_on_oops,
770 .maxlen = sizeof(int),
771 .mode = 0644,
772 .proc_handler = proc_dointvec,
774 #if defined CONFIG_PRINTK
776 .procname = "printk",
777 .data = &console_loglevel,
778 .maxlen = 4*sizeof(int),
779 .mode = 0644,
780 .proc_handler = proc_dointvec,
783 .procname = "printk_ratelimit",
784 .data = &printk_ratelimit_state.interval,
785 .maxlen = sizeof(int),
786 .mode = 0644,
787 .proc_handler = proc_dointvec_jiffies,
790 .procname = "printk_ratelimit_burst",
791 .data = &printk_ratelimit_state.burst,
792 .maxlen = sizeof(int),
793 .mode = 0644,
794 .proc_handler = proc_dointvec,
797 .procname = "printk_delay",
798 .data = &printk_delay_msec,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = proc_dointvec_minmax,
802 .extra1 = &zero,
803 .extra2 = &ten_thousand,
806 .procname = "dmesg_restrict",
807 .data = &dmesg_restrict,
808 .maxlen = sizeof(int),
809 .mode = 0644,
810 .proc_handler = proc_dointvec_minmax_sysadmin,
811 .extra1 = &zero,
812 .extra2 = &one,
815 .procname = "kptr_restrict",
816 .data = &kptr_restrict,
817 .maxlen = sizeof(int),
818 .mode = 0644,
819 .proc_handler = proc_dointvec_minmax_sysadmin,
820 .extra1 = &zero,
821 .extra2 = &two,
823 #endif
825 .procname = "ngroups_max",
826 .data = &ngroups_max,
827 .maxlen = sizeof (int),
828 .mode = 0444,
829 .proc_handler = proc_dointvec,
832 .procname = "cap_last_cap",
833 .data = (void *)&cap_last_cap,
834 .maxlen = sizeof(int),
835 .mode = 0444,
836 .proc_handler = proc_dointvec,
838 #if defined(CONFIG_LOCKUP_DETECTOR)
840 .procname = "watchdog",
841 .data = &watchdog_user_enabled,
842 .maxlen = sizeof (int),
843 .mode = 0644,
844 .proc_handler = proc_watchdog,
845 .extra1 = &zero,
846 .extra2 = &one,
849 .procname = "watchdog_thresh",
850 .data = &watchdog_thresh,
851 .maxlen = sizeof(int),
852 .mode = 0644,
853 .proc_handler = proc_watchdog_thresh,
854 .extra1 = &zero,
855 .extra2 = &sixty,
858 .procname = "nmi_watchdog",
859 .data = &nmi_watchdog_enabled,
860 .maxlen = sizeof (int),
861 .mode = 0644,
862 .proc_handler = proc_nmi_watchdog,
863 .extra1 = &zero,
864 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
865 .extra2 = &one,
866 #else
867 .extra2 = &zero,
868 #endif
871 .procname = "soft_watchdog",
872 .data = &soft_watchdog_enabled,
873 .maxlen = sizeof (int),
874 .mode = 0644,
875 .proc_handler = proc_soft_watchdog,
876 .extra1 = &zero,
877 .extra2 = &one,
880 .procname = "watchdog_cpumask",
881 .data = &watchdog_cpumask_bits,
882 .maxlen = NR_CPUS,
883 .mode = 0644,
884 .proc_handler = proc_watchdog_cpumask,
887 .procname = "softlockup_panic",
888 .data = &softlockup_panic,
889 .maxlen = sizeof(int),
890 .mode = 0644,
891 .proc_handler = proc_dointvec_minmax,
892 .extra1 = &zero,
893 .extra2 = &one,
895 #ifdef CONFIG_HARDLOCKUP_DETECTOR
897 .procname = "hardlockup_panic",
898 .data = &hardlockup_panic,
899 .maxlen = sizeof(int),
900 .mode = 0644,
901 .proc_handler = proc_dointvec_minmax,
902 .extra1 = &zero,
903 .extra2 = &one,
905 #endif
906 #ifdef CONFIG_SMP
908 .procname = "softlockup_all_cpu_backtrace",
909 .data = &sysctl_softlockup_all_cpu_backtrace,
910 .maxlen = sizeof(int),
911 .mode = 0644,
912 .proc_handler = proc_dointvec_minmax,
913 .extra1 = &zero,
914 .extra2 = &one,
917 .procname = "hardlockup_all_cpu_backtrace",
918 .data = &sysctl_hardlockup_all_cpu_backtrace,
919 .maxlen = sizeof(int),
920 .mode = 0644,
921 .proc_handler = proc_dointvec_minmax,
922 .extra1 = &zero,
923 .extra2 = &one,
925 #endif /* CONFIG_SMP */
926 #endif
927 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
929 .procname = "unknown_nmi_panic",
930 .data = &unknown_nmi_panic,
931 .maxlen = sizeof (int),
932 .mode = 0644,
933 .proc_handler = proc_dointvec,
935 #endif
936 #if defined(CONFIG_X86)
938 .procname = "panic_on_unrecovered_nmi",
939 .data = &panic_on_unrecovered_nmi,
940 .maxlen = sizeof(int),
941 .mode = 0644,
942 .proc_handler = proc_dointvec,
945 .procname = "panic_on_io_nmi",
946 .data = &panic_on_io_nmi,
947 .maxlen = sizeof(int),
948 .mode = 0644,
949 .proc_handler = proc_dointvec,
951 #ifdef CONFIG_DEBUG_STACKOVERFLOW
953 .procname = "panic_on_stackoverflow",
954 .data = &sysctl_panic_on_stackoverflow,
955 .maxlen = sizeof(int),
956 .mode = 0644,
957 .proc_handler = proc_dointvec,
959 #endif
961 .procname = "bootloader_type",
962 .data = &bootloader_type,
963 .maxlen = sizeof (int),
964 .mode = 0444,
965 .proc_handler = proc_dointvec,
968 .procname = "bootloader_version",
969 .data = &bootloader_version,
970 .maxlen = sizeof (int),
971 .mode = 0444,
972 .proc_handler = proc_dointvec,
975 .procname = "kstack_depth_to_print",
976 .data = &kstack_depth_to_print,
977 .maxlen = sizeof(int),
978 .mode = 0644,
979 .proc_handler = proc_dointvec,
982 .procname = "io_delay_type",
983 .data = &io_delay_type,
984 .maxlen = sizeof(int),
985 .mode = 0644,
986 .proc_handler = proc_dointvec,
988 #endif
989 #if defined(CONFIG_MMU)
991 .procname = "randomize_va_space",
992 .data = &randomize_va_space,
993 .maxlen = sizeof(int),
994 .mode = 0644,
995 .proc_handler = proc_dointvec,
997 #endif
998 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1000 .procname = "spin_retry",
1001 .data = &spin_retry,
1002 .maxlen = sizeof (int),
1003 .mode = 0644,
1004 .proc_handler = proc_dointvec,
1006 #endif
1007 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1009 .procname = "acpi_video_flags",
1010 .data = &acpi_realmode_flags,
1011 .maxlen = sizeof (unsigned long),
1012 .mode = 0644,
1013 .proc_handler = proc_doulongvec_minmax,
1015 #endif
1016 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1018 .procname = "ignore-unaligned-usertrap",
1019 .data = &no_unaligned_warning,
1020 .maxlen = sizeof (int),
1021 .mode = 0644,
1022 .proc_handler = proc_dointvec,
1024 #endif
1025 #ifdef CONFIG_IA64
1027 .procname = "unaligned-dump-stack",
1028 .data = &unaligned_dump_stack,
1029 .maxlen = sizeof (int),
1030 .mode = 0644,
1031 .proc_handler = proc_dointvec,
1033 #endif
1034 #ifdef CONFIG_DETECT_HUNG_TASK
1036 .procname = "hung_task_panic",
1037 .data = &sysctl_hung_task_panic,
1038 .maxlen = sizeof(int),
1039 .mode = 0644,
1040 .proc_handler = proc_dointvec_minmax,
1041 .extra1 = &zero,
1042 .extra2 = &one,
1045 .procname = "hung_task_check_count",
1046 .data = &sysctl_hung_task_check_count,
1047 .maxlen = sizeof(int),
1048 .mode = 0644,
1049 .proc_handler = proc_dointvec_minmax,
1050 .extra1 = &zero,
1053 .procname = "hung_task_timeout_secs",
1054 .data = &sysctl_hung_task_timeout_secs,
1055 .maxlen = sizeof(unsigned long),
1056 .mode = 0644,
1057 .proc_handler = proc_dohung_task_timeout_secs,
1058 .extra2 = &hung_task_timeout_max,
1061 .procname = "hung_task_warnings",
1062 .data = &sysctl_hung_task_warnings,
1063 .maxlen = sizeof(int),
1064 .mode = 0644,
1065 .proc_handler = proc_dointvec_minmax,
1066 .extra1 = &neg_one,
1068 #endif
1069 #ifdef CONFIG_COMPAT
1071 .procname = "compat-log",
1072 .data = &compat_log,
1073 .maxlen = sizeof (int),
1074 .mode = 0644,
1075 .proc_handler = proc_dointvec,
1077 #endif
1078 #ifdef CONFIG_RT_MUTEXES
1080 .procname = "max_lock_depth",
1081 .data = &max_lock_depth,
1082 .maxlen = sizeof(int),
1083 .mode = 0644,
1084 .proc_handler = proc_dointvec,
1086 #endif
1088 .procname = "poweroff_cmd",
1089 .data = &poweroff_cmd,
1090 .maxlen = POWEROFF_CMD_PATH_LEN,
1091 .mode = 0644,
1092 .proc_handler = proc_dostring,
1094 #ifdef CONFIG_KEYS
1096 .procname = "keys",
1097 .mode = 0555,
1098 .child = key_sysctls,
1100 #endif
1101 #ifdef CONFIG_PERF_EVENTS
1103 * User-space scripts rely on the existence of this file
1104 * as a feature check for perf_events being enabled.
1106 * So it's an ABI, do not remove!
1109 .procname = "perf_event_paranoid",
1110 .data = &sysctl_perf_event_paranoid,
1111 .maxlen = sizeof(sysctl_perf_event_paranoid),
1112 .mode = 0644,
1113 .proc_handler = proc_dointvec,
1116 .procname = "perf_event_mlock_kb",
1117 .data = &sysctl_perf_event_mlock,
1118 .maxlen = sizeof(sysctl_perf_event_mlock),
1119 .mode = 0644,
1120 .proc_handler = proc_dointvec,
1123 .procname = "perf_event_max_sample_rate",
1124 .data = &sysctl_perf_event_sample_rate,
1125 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1126 .mode = 0644,
1127 .proc_handler = perf_proc_update_handler,
1128 .extra1 = &one,
1131 .procname = "perf_cpu_time_max_percent",
1132 .data = &sysctl_perf_cpu_time_max_percent,
1133 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1134 .mode = 0644,
1135 .proc_handler = perf_cpu_time_max_percent_handler,
1136 .extra1 = &zero,
1137 .extra2 = &one_hundred,
1139 #endif
1140 #ifdef CONFIG_KMEMCHECK
1142 .procname = "kmemcheck",
1143 .data = &kmemcheck_enabled,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = proc_dointvec,
1148 #endif
1150 .procname = "panic_on_warn",
1151 .data = &panic_on_warn,
1152 .maxlen = sizeof(int),
1153 .mode = 0644,
1154 .proc_handler = proc_dointvec_minmax,
1155 .extra1 = &zero,
1156 .extra2 = &one,
1158 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1160 .procname = "timer_migration",
1161 .data = &sysctl_timer_migration,
1162 .maxlen = sizeof(unsigned int),
1163 .mode = 0644,
1164 .proc_handler = timer_migration_handler,
1165 .extra1 = &zero,
1166 .extra2 = &one,
1168 #endif
1169 #ifdef CONFIG_BPF_SYSCALL
1171 .procname = "unprivileged_bpf_disabled",
1172 .data = &sysctl_unprivileged_bpf_disabled,
1173 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1174 .mode = 0644,
1175 /* only handle a transition from default "0" to "1" */
1176 .proc_handler = proc_dointvec_minmax,
1177 .extra1 = &one,
1178 .extra2 = &one,
1180 #endif
1184 static struct ctl_table vm_table[] = {
1186 .procname = "overcommit_memory",
1187 .data = &sysctl_overcommit_memory,
1188 .maxlen = sizeof(sysctl_overcommit_memory),
1189 .mode = 0644,
1190 .proc_handler = proc_dointvec_minmax,
1191 .extra1 = &zero,
1192 .extra2 = &two,
1195 .procname = "panic_on_oom",
1196 .data = &sysctl_panic_on_oom,
1197 .maxlen = sizeof(sysctl_panic_on_oom),
1198 .mode = 0644,
1199 .proc_handler = proc_dointvec_minmax,
1200 .extra1 = &zero,
1201 .extra2 = &two,
1204 .procname = "oom_kill_allocating_task",
1205 .data = &sysctl_oom_kill_allocating_task,
1206 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1207 .mode = 0644,
1208 .proc_handler = proc_dointvec,
1211 .procname = "oom_dump_tasks",
1212 .data = &sysctl_oom_dump_tasks,
1213 .maxlen = sizeof(sysctl_oom_dump_tasks),
1214 .mode = 0644,
1215 .proc_handler = proc_dointvec,
1218 .procname = "overcommit_ratio",
1219 .data = &sysctl_overcommit_ratio,
1220 .maxlen = sizeof(sysctl_overcommit_ratio),
1221 .mode = 0644,
1222 .proc_handler = overcommit_ratio_handler,
1225 .procname = "overcommit_kbytes",
1226 .data = &sysctl_overcommit_kbytes,
1227 .maxlen = sizeof(sysctl_overcommit_kbytes),
1228 .mode = 0644,
1229 .proc_handler = overcommit_kbytes_handler,
1232 .procname = "page-cluster",
1233 .data = &page_cluster,
1234 .maxlen = sizeof(int),
1235 .mode = 0644,
1236 .proc_handler = proc_dointvec_minmax,
1237 .extra1 = &zero,
1240 .procname = "dirty_background_ratio",
1241 .data = &dirty_background_ratio,
1242 .maxlen = sizeof(dirty_background_ratio),
1243 .mode = 0644,
1244 .proc_handler = dirty_background_ratio_handler,
1245 .extra1 = &zero,
1246 .extra2 = &one_hundred,
1249 .procname = "dirty_background_bytes",
1250 .data = &dirty_background_bytes,
1251 .maxlen = sizeof(dirty_background_bytes),
1252 .mode = 0644,
1253 .proc_handler = dirty_background_bytes_handler,
1254 .extra1 = &one_ul,
1257 .procname = "dirty_ratio",
1258 .data = &vm_dirty_ratio,
1259 .maxlen = sizeof(vm_dirty_ratio),
1260 .mode = 0644,
1261 .proc_handler = dirty_ratio_handler,
1262 .extra1 = &zero,
1263 .extra2 = &one_hundred,
1266 .procname = "dirty_bytes",
1267 .data = &vm_dirty_bytes,
1268 .maxlen = sizeof(vm_dirty_bytes),
1269 .mode = 0644,
1270 .proc_handler = dirty_bytes_handler,
1271 .extra1 = &dirty_bytes_min,
1274 .procname = "dirty_writeback_centisecs",
1275 .data = &dirty_writeback_interval,
1276 .maxlen = sizeof(dirty_writeback_interval),
1277 .mode = 0644,
1278 .proc_handler = dirty_writeback_centisecs_handler,
1281 .procname = "dirty_expire_centisecs",
1282 .data = &dirty_expire_interval,
1283 .maxlen = sizeof(dirty_expire_interval),
1284 .mode = 0644,
1285 .proc_handler = proc_dointvec_minmax,
1286 .extra1 = &zero,
1289 .procname = "dirtytime_expire_seconds",
1290 .data = &dirtytime_expire_interval,
1291 .maxlen = sizeof(dirty_expire_interval),
1292 .mode = 0644,
1293 .proc_handler = dirtytime_interval_handler,
1294 .extra1 = &zero,
1297 .procname = "nr_pdflush_threads",
1298 .mode = 0444 /* read-only */,
1299 .proc_handler = pdflush_proc_obsolete,
1302 .procname = "swappiness",
1303 .data = &vm_swappiness,
1304 .maxlen = sizeof(vm_swappiness),
1305 .mode = 0644,
1306 .proc_handler = proc_dointvec_minmax,
1307 .extra1 = &zero,
1308 .extra2 = &one_hundred,
1310 #ifdef CONFIG_HUGETLB_PAGE
1312 .procname = "nr_hugepages",
1313 .data = NULL,
1314 .maxlen = sizeof(unsigned long),
1315 .mode = 0644,
1316 .proc_handler = hugetlb_sysctl_handler,
1318 #ifdef CONFIG_NUMA
1320 .procname = "nr_hugepages_mempolicy",
1321 .data = NULL,
1322 .maxlen = sizeof(unsigned long),
1323 .mode = 0644,
1324 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1326 #endif
1328 .procname = "hugetlb_shm_group",
1329 .data = &sysctl_hugetlb_shm_group,
1330 .maxlen = sizeof(gid_t),
1331 .mode = 0644,
1332 .proc_handler = proc_dointvec,
1335 .procname = "hugepages_treat_as_movable",
1336 .data = &hugepages_treat_as_movable,
1337 .maxlen = sizeof(int),
1338 .mode = 0644,
1339 .proc_handler = proc_dointvec,
1342 .procname = "nr_overcommit_hugepages",
1343 .data = NULL,
1344 .maxlen = sizeof(unsigned long),
1345 .mode = 0644,
1346 .proc_handler = hugetlb_overcommit_handler,
1348 #endif
1350 .procname = "lowmem_reserve_ratio",
1351 .data = &sysctl_lowmem_reserve_ratio,
1352 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1353 .mode = 0644,
1354 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1357 .procname = "drop_caches",
1358 .data = &sysctl_drop_caches,
1359 .maxlen = sizeof(int),
1360 .mode = 0644,
1361 .proc_handler = drop_caches_sysctl_handler,
1362 .extra1 = &one,
1363 .extra2 = &four,
1365 #ifdef CONFIG_COMPACTION
1367 .procname = "compact_memory",
1368 .data = &sysctl_compact_memory,
1369 .maxlen = sizeof(int),
1370 .mode = 0200,
1371 .proc_handler = sysctl_compaction_handler,
1374 .procname = "extfrag_threshold",
1375 .data = &sysctl_extfrag_threshold,
1376 .maxlen = sizeof(int),
1377 .mode = 0644,
1378 .proc_handler = sysctl_extfrag_handler,
1379 .extra1 = &min_extfrag_threshold,
1380 .extra2 = &max_extfrag_threshold,
1383 .procname = "compact_unevictable_allowed",
1384 .data = &sysctl_compact_unevictable_allowed,
1385 .maxlen = sizeof(int),
1386 .mode = 0644,
1387 .proc_handler = proc_dointvec,
1388 .extra1 = &zero,
1389 .extra2 = &one,
1392 #endif /* CONFIG_COMPACTION */
1394 .procname = "min_free_kbytes",
1395 .data = &min_free_kbytes,
1396 .maxlen = sizeof(min_free_kbytes),
1397 .mode = 0644,
1398 .proc_handler = min_free_kbytes_sysctl_handler,
1399 .extra1 = &zero,
1402 .procname = "percpu_pagelist_fraction",
1403 .data = &percpu_pagelist_fraction,
1404 .maxlen = sizeof(percpu_pagelist_fraction),
1405 .mode = 0644,
1406 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1407 .extra1 = &zero,
1409 #ifdef CONFIG_MMU
1411 .procname = "max_map_count",
1412 .data = &sysctl_max_map_count,
1413 .maxlen = sizeof(sysctl_max_map_count),
1414 .mode = 0644,
1415 .proc_handler = proc_dointvec_minmax,
1416 .extra1 = &zero,
1418 #else
1420 .procname = "nr_trim_pages",
1421 .data = &sysctl_nr_trim_pages,
1422 .maxlen = sizeof(sysctl_nr_trim_pages),
1423 .mode = 0644,
1424 .proc_handler = proc_dointvec_minmax,
1425 .extra1 = &zero,
1427 #endif
1429 .procname = "laptop_mode",
1430 .data = &laptop_mode,
1431 .maxlen = sizeof(laptop_mode),
1432 .mode = 0644,
1433 .proc_handler = proc_dointvec_jiffies,
1436 .procname = "block_dump",
1437 .data = &block_dump,
1438 .maxlen = sizeof(block_dump),
1439 .mode = 0644,
1440 .proc_handler = proc_dointvec,
1441 .extra1 = &zero,
1444 .procname = "vfs_cache_pressure",
1445 .data = &sysctl_vfs_cache_pressure,
1446 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1447 .mode = 0644,
1448 .proc_handler = proc_dointvec,
1449 .extra1 = &zero,
1451 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1453 .procname = "legacy_va_layout",
1454 .data = &sysctl_legacy_va_layout,
1455 .maxlen = sizeof(sysctl_legacy_va_layout),
1456 .mode = 0644,
1457 .proc_handler = proc_dointvec,
1458 .extra1 = &zero,
1460 #endif
1461 #ifdef CONFIG_NUMA
1463 .procname = "zone_reclaim_mode",
1464 .data = &zone_reclaim_mode,
1465 .maxlen = sizeof(zone_reclaim_mode),
1466 .mode = 0644,
1467 .proc_handler = proc_dointvec,
1468 .extra1 = &zero,
1471 .procname = "min_unmapped_ratio",
1472 .data = &sysctl_min_unmapped_ratio,
1473 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1474 .mode = 0644,
1475 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1476 .extra1 = &zero,
1477 .extra2 = &one_hundred,
1480 .procname = "min_slab_ratio",
1481 .data = &sysctl_min_slab_ratio,
1482 .maxlen = sizeof(sysctl_min_slab_ratio),
1483 .mode = 0644,
1484 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1485 .extra1 = &zero,
1486 .extra2 = &one_hundred,
1488 #endif
1489 #ifdef CONFIG_SMP
1491 .procname = "stat_interval",
1492 .data = &sysctl_stat_interval,
1493 .maxlen = sizeof(sysctl_stat_interval),
1494 .mode = 0644,
1495 .proc_handler = proc_dointvec_jiffies,
1497 #endif
1498 #ifdef CONFIG_MMU
1500 .procname = "mmap_min_addr",
1501 .data = &dac_mmap_min_addr,
1502 .maxlen = sizeof(unsigned long),
1503 .mode = 0644,
1504 .proc_handler = mmap_min_addr_handler,
1506 #endif
1507 #ifdef CONFIG_NUMA
1509 .procname = "numa_zonelist_order",
1510 .data = &numa_zonelist_order,
1511 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1512 .mode = 0644,
1513 .proc_handler = numa_zonelist_order_handler,
1515 #endif
1516 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1517 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1519 .procname = "vdso_enabled",
1520 #ifdef CONFIG_X86_32
1521 .data = &vdso32_enabled,
1522 .maxlen = sizeof(vdso32_enabled),
1523 #else
1524 .data = &vdso_enabled,
1525 .maxlen = sizeof(vdso_enabled),
1526 #endif
1527 .mode = 0644,
1528 .proc_handler = proc_dointvec,
1529 .extra1 = &zero,
1531 #endif
1532 #ifdef CONFIG_HIGHMEM
1534 .procname = "highmem_is_dirtyable",
1535 .data = &vm_highmem_is_dirtyable,
1536 .maxlen = sizeof(vm_highmem_is_dirtyable),
1537 .mode = 0644,
1538 .proc_handler = proc_dointvec_minmax,
1539 .extra1 = &zero,
1540 .extra2 = &one,
1542 #endif
1543 #ifdef CONFIG_MEMORY_FAILURE
1545 .procname = "memory_failure_early_kill",
1546 .data = &sysctl_memory_failure_early_kill,
1547 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1548 .mode = 0644,
1549 .proc_handler = proc_dointvec_minmax,
1550 .extra1 = &zero,
1551 .extra2 = &one,
1554 .procname = "memory_failure_recovery",
1555 .data = &sysctl_memory_failure_recovery,
1556 .maxlen = sizeof(sysctl_memory_failure_recovery),
1557 .mode = 0644,
1558 .proc_handler = proc_dointvec_minmax,
1559 .extra1 = &zero,
1560 .extra2 = &one,
1562 #endif
1564 .procname = "user_reserve_kbytes",
1565 .data = &sysctl_user_reserve_kbytes,
1566 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1567 .mode = 0644,
1568 .proc_handler = proc_doulongvec_minmax,
1571 .procname = "admin_reserve_kbytes",
1572 .data = &sysctl_admin_reserve_kbytes,
1573 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1574 .mode = 0644,
1575 .proc_handler = proc_doulongvec_minmax,
1580 static struct ctl_table fs_table[] = {
1582 .procname = "inode-nr",
1583 .data = &inodes_stat,
1584 .maxlen = 2*sizeof(long),
1585 .mode = 0444,
1586 .proc_handler = proc_nr_inodes,
1589 .procname = "inode-state",
1590 .data = &inodes_stat,
1591 .maxlen = 7*sizeof(long),
1592 .mode = 0444,
1593 .proc_handler = proc_nr_inodes,
1596 .procname = "file-nr",
1597 .data = &files_stat,
1598 .maxlen = sizeof(files_stat),
1599 .mode = 0444,
1600 .proc_handler = proc_nr_files,
1603 .procname = "file-max",
1604 .data = &files_stat.max_files,
1605 .maxlen = sizeof(files_stat.max_files),
1606 .mode = 0644,
1607 .proc_handler = proc_doulongvec_minmax,
1608 .extra1 = &zero_ul,
1609 .extra2 = &long_max,
1612 .procname = "nr_open",
1613 .data = &sysctl_nr_open,
1614 .maxlen = sizeof(int),
1615 .mode = 0644,
1616 .proc_handler = proc_dointvec_minmax,
1617 .extra1 = &sysctl_nr_open_min,
1618 .extra2 = &sysctl_nr_open_max,
1621 .procname = "dentry-state",
1622 .data = &dentry_stat,
1623 .maxlen = 6*sizeof(long),
1624 .mode = 0444,
1625 .proc_handler = proc_nr_dentry,
1628 .procname = "overflowuid",
1629 .data = &fs_overflowuid,
1630 .maxlen = sizeof(int),
1631 .mode = 0644,
1632 .proc_handler = proc_dointvec_minmax,
1633 .extra1 = &minolduid,
1634 .extra2 = &maxolduid,
1637 .procname = "overflowgid",
1638 .data = &fs_overflowgid,
1639 .maxlen = sizeof(int),
1640 .mode = 0644,
1641 .proc_handler = proc_dointvec_minmax,
1642 .extra1 = &minolduid,
1643 .extra2 = &maxolduid,
1645 #ifdef CONFIG_FILE_LOCKING
1647 .procname = "leases-enable",
1648 .data = &leases_enable,
1649 .maxlen = sizeof(int),
1650 .mode = 0644,
1651 .proc_handler = proc_dointvec,
1653 #endif
1654 #ifdef CONFIG_DNOTIFY
1656 .procname = "dir-notify-enable",
1657 .data = &dir_notify_enable,
1658 .maxlen = sizeof(int),
1659 .mode = 0644,
1660 .proc_handler = proc_dointvec,
1662 #endif
1663 #ifdef CONFIG_MMU
1664 #ifdef CONFIG_FILE_LOCKING
1666 .procname = "lease-break-time",
1667 .data = &lease_break_time,
1668 .maxlen = sizeof(int),
1669 .mode = 0644,
1670 .proc_handler = proc_dointvec,
1672 #endif
1673 #ifdef CONFIG_AIO
1675 .procname = "aio-nr",
1676 .data = &aio_nr,
1677 .maxlen = sizeof(aio_nr),
1678 .mode = 0444,
1679 .proc_handler = proc_doulongvec_minmax,
1682 .procname = "aio-max-nr",
1683 .data = &aio_max_nr,
1684 .maxlen = sizeof(aio_max_nr),
1685 .mode = 0644,
1686 .proc_handler = proc_doulongvec_minmax,
1688 #endif /* CONFIG_AIO */
1689 #ifdef CONFIG_INOTIFY_USER
1691 .procname = "inotify",
1692 .mode = 0555,
1693 .child = inotify_table,
1695 #endif
1696 #ifdef CONFIG_EPOLL
1698 .procname = "epoll",
1699 .mode = 0555,
1700 .child = epoll_table,
1702 #endif
1703 #endif
1705 .procname = "protected_symlinks",
1706 .data = &sysctl_protected_symlinks,
1707 .maxlen = sizeof(int),
1708 .mode = 0600,
1709 .proc_handler = proc_dointvec_minmax,
1710 .extra1 = &zero,
1711 .extra2 = &one,
1714 .procname = "protected_hardlinks",
1715 .data = &sysctl_protected_hardlinks,
1716 .maxlen = sizeof(int),
1717 .mode = 0600,
1718 .proc_handler = proc_dointvec_minmax,
1719 .extra1 = &zero,
1720 .extra2 = &one,
1723 .procname = "protected_fifos",
1724 .data = &sysctl_protected_fifos,
1725 .maxlen = sizeof(int),
1726 .mode = 0600,
1727 .proc_handler = proc_dointvec_minmax,
1728 .extra1 = &zero,
1729 .extra2 = &two,
1732 .procname = "protected_regular",
1733 .data = &sysctl_protected_regular,
1734 .maxlen = sizeof(int),
1735 .mode = 0600,
1736 .proc_handler = proc_dointvec_minmax,
1737 .extra1 = &zero,
1738 .extra2 = &two,
1741 .procname = "suid_dumpable",
1742 .data = &suid_dumpable,
1743 .maxlen = sizeof(int),
1744 .mode = 0644,
1745 .proc_handler = proc_dointvec_minmax_coredump,
1746 .extra1 = &zero,
1747 .extra2 = &two,
1749 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1751 .procname = "binfmt_misc",
1752 .mode = 0555,
1753 .child = sysctl_mount_point,
1755 #endif
1757 .procname = "pipe-max-size",
1758 .data = &pipe_max_size,
1759 .maxlen = sizeof(int),
1760 .mode = 0644,
1761 .proc_handler = &pipe_proc_fn,
1762 .extra1 = &pipe_min_size,
1765 .procname = "pipe-user-pages-hard",
1766 .data = &pipe_user_pages_hard,
1767 .maxlen = sizeof(pipe_user_pages_hard),
1768 .mode = 0644,
1769 .proc_handler = proc_doulongvec_minmax,
1772 .procname = "pipe-user-pages-soft",
1773 .data = &pipe_user_pages_soft,
1774 .maxlen = sizeof(pipe_user_pages_soft),
1775 .mode = 0644,
1776 .proc_handler = proc_doulongvec_minmax,
1779 .procname = "mount-max",
1780 .data = &sysctl_mount_max,
1781 .maxlen = sizeof(unsigned int),
1782 .mode = 0644,
1783 .proc_handler = proc_dointvec_minmax,
1784 .extra1 = &one,
1789 static struct ctl_table debug_table[] = {
1790 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1792 .procname = "exception-trace",
1793 .data = &show_unhandled_signals,
1794 .maxlen = sizeof(int),
1795 .mode = 0644,
1796 .proc_handler = proc_dointvec
1798 #endif
1799 #if defined(CONFIG_OPTPROBES)
1801 .procname = "kprobes-optimization",
1802 .data = &sysctl_kprobes_optimization,
1803 .maxlen = sizeof(int),
1804 .mode = 0644,
1805 .proc_handler = proc_kprobes_optimization_handler,
1806 .extra1 = &zero,
1807 .extra2 = &one,
1809 #endif
1813 static struct ctl_table dev_table[] = {
1817 int __init sysctl_init(void)
1819 struct ctl_table_header *hdr;
1821 hdr = register_sysctl_table(sysctl_base_table);
1822 kmemleak_not_leak(hdr);
1823 return 0;
1826 #endif /* CONFIG_SYSCTL */
1829 * /proc/sys support
1832 #ifdef CONFIG_PROC_SYSCTL
1834 static int _proc_do_string(char *data, int maxlen, int write,
1835 char __user *buffer,
1836 size_t *lenp, loff_t *ppos)
1838 size_t len;
1839 char __user *p;
1840 char c;
1842 if (!data || !maxlen || !*lenp) {
1843 *lenp = 0;
1844 return 0;
1847 if (write) {
1848 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1849 /* Only continue writes not past the end of buffer. */
1850 len = strlen(data);
1851 if (len > maxlen - 1)
1852 len = maxlen - 1;
1854 if (*ppos > len)
1855 return 0;
1856 len = *ppos;
1857 } else {
1858 /* Start writing from beginning of buffer. */
1859 len = 0;
1862 *ppos += *lenp;
1863 p = buffer;
1864 while ((p - buffer) < *lenp && len < maxlen - 1) {
1865 if (get_user(c, p++))
1866 return -EFAULT;
1867 if (c == 0 || c == '\n')
1868 break;
1869 data[len++] = c;
1871 data[len] = 0;
1872 } else {
1873 len = strlen(data);
1874 if (len > maxlen)
1875 len = maxlen;
1877 if (*ppos > len) {
1878 *lenp = 0;
1879 return 0;
1882 data += *ppos;
1883 len -= *ppos;
1885 if (len > *lenp)
1886 len = *lenp;
1887 if (len)
1888 if (copy_to_user(buffer, data, len))
1889 return -EFAULT;
1890 if (len < *lenp) {
1891 if (put_user('\n', buffer + len))
1892 return -EFAULT;
1893 len++;
1895 *lenp = len;
1896 *ppos += len;
1898 return 0;
1901 static void warn_sysctl_write(struct ctl_table *table)
1903 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1904 "This will not be supported in the future. To silence this\n"
1905 "warning, set kernel.sysctl_writes_strict = -1\n",
1906 current->comm, table->procname);
1910 * proc_dostring - read a string sysctl
1911 * @table: the sysctl table
1912 * @write: %TRUE if this is a write to the sysctl file
1913 * @buffer: the user buffer
1914 * @lenp: the size of the user buffer
1915 * @ppos: file position
1917 * Reads/writes a string from/to the user buffer. If the kernel
1918 * buffer provided is not large enough to hold the string, the
1919 * string is truncated. The copied string is %NULL-terminated.
1920 * If the string is being read by the user process, it is copied
1921 * and a newline '\n' is added. It is truncated if the buffer is
1922 * not large enough.
1924 * Returns 0 on success.
1926 int proc_dostring(struct ctl_table *table, int write,
1927 void __user *buffer, size_t *lenp, loff_t *ppos)
1929 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1930 warn_sysctl_write(table);
1932 return _proc_do_string((char *)(table->data), table->maxlen, write,
1933 (char __user *)buffer, lenp, ppos);
1936 static size_t proc_skip_spaces(char **buf)
1938 size_t ret;
1939 char *tmp = skip_spaces(*buf);
1940 ret = tmp - *buf;
1941 *buf = tmp;
1942 return ret;
1945 static void proc_skip_char(char **buf, size_t *size, const char v)
1947 while (*size) {
1948 if (**buf != v)
1949 break;
1950 (*size)--;
1951 (*buf)++;
1955 #define TMPBUFLEN 22
1957 * proc_get_long - reads an ASCII formatted integer from a user buffer
1959 * @buf: a kernel buffer
1960 * @size: size of the kernel buffer
1961 * @val: this is where the number will be stored
1962 * @neg: set to %TRUE if number is negative
1963 * @perm_tr: a vector which contains the allowed trailers
1964 * @perm_tr_len: size of the perm_tr vector
1965 * @tr: pointer to store the trailer character
1967 * In case of success %0 is returned and @buf and @size are updated with
1968 * the amount of bytes read. If @tr is non-NULL and a trailing
1969 * character exists (size is non-zero after returning from this
1970 * function), @tr is updated with the trailing character.
1972 static int proc_get_long(char **buf, size_t *size,
1973 unsigned long *val, bool *neg,
1974 const char *perm_tr, unsigned perm_tr_len, char *tr)
1976 int len;
1977 char *p, tmp[TMPBUFLEN];
1979 if (!*size)
1980 return -EINVAL;
1982 len = *size;
1983 if (len > TMPBUFLEN - 1)
1984 len = TMPBUFLEN - 1;
1986 memcpy(tmp, *buf, len);
1988 tmp[len] = 0;
1989 p = tmp;
1990 if (*p == '-' && *size > 1) {
1991 *neg = true;
1992 p++;
1993 } else
1994 *neg = false;
1995 if (!isdigit(*p))
1996 return -EINVAL;
1998 *val = simple_strtoul(p, &p, 0);
2000 len = p - tmp;
2002 /* We don't know if the next char is whitespace thus we may accept
2003 * invalid integers (e.g. 1234...a) or two integers instead of one
2004 * (e.g. 123...1). So lets not allow such large numbers. */
2005 if (len == TMPBUFLEN - 1)
2006 return -EINVAL;
2008 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2009 return -EINVAL;
2011 if (tr && (len < *size))
2012 *tr = *p;
2014 *buf += len;
2015 *size -= len;
2017 return 0;
2021 * proc_put_long - converts an integer to a decimal ASCII formatted string
2023 * @buf: the user buffer
2024 * @size: the size of the user buffer
2025 * @val: the integer to be converted
2026 * @neg: sign of the number, %TRUE for negative
2028 * In case of success %0 is returned and @buf and @size are updated with
2029 * the amount of bytes written.
2031 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2032 bool neg)
2034 int len;
2035 char tmp[TMPBUFLEN], *p = tmp;
2037 sprintf(p, "%s%lu", neg ? "-" : "", val);
2038 len = strlen(tmp);
2039 if (len > *size)
2040 len = *size;
2041 if (copy_to_user(*buf, tmp, len))
2042 return -EFAULT;
2043 *size -= len;
2044 *buf += len;
2045 return 0;
2047 #undef TMPBUFLEN
2049 static int proc_put_char(void __user **buf, size_t *size, char c)
2051 if (*size) {
2052 char __user **buffer = (char __user **)buf;
2053 if (put_user(c, *buffer))
2054 return -EFAULT;
2055 (*size)--, (*buffer)++;
2056 *buf = *buffer;
2058 return 0;
2061 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2062 int *valp,
2063 int write, void *data)
2065 if (write) {
2066 if (*negp) {
2067 if (*lvalp > (unsigned long) INT_MAX + 1)
2068 return -EINVAL;
2069 *valp = -*lvalp;
2070 } else {
2071 if (*lvalp > (unsigned long) INT_MAX)
2072 return -EINVAL;
2073 *valp = *lvalp;
2075 } else {
2076 int val = *valp;
2077 if (val < 0) {
2078 *negp = true;
2079 *lvalp = -(unsigned long)val;
2080 } else {
2081 *negp = false;
2082 *lvalp = (unsigned long)val;
2085 return 0;
2088 static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2089 int *valp,
2090 int write, void *data)
2092 if (write) {
2093 if (*negp)
2094 return -EINVAL;
2095 if (*lvalp > UINT_MAX)
2096 return -EINVAL;
2097 *valp = *lvalp;
2098 } else {
2099 unsigned int val = *valp;
2100 *negp = false;
2101 *lvalp = (unsigned long)val;
2103 return 0;
2106 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2108 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2109 int write, void __user *buffer,
2110 size_t *lenp, loff_t *ppos,
2111 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2112 int write, void *data),
2113 void *data)
2115 int *i, vleft, first = 1, err = 0;
2116 unsigned long page = 0;
2117 size_t left;
2118 char *kbuf;
2120 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2121 *lenp = 0;
2122 return 0;
2125 i = (int *) tbl_data;
2126 vleft = table->maxlen / sizeof(*i);
2127 left = *lenp;
2129 if (!conv)
2130 conv = do_proc_dointvec_conv;
2132 if (write) {
2133 if (*ppos) {
2134 switch (sysctl_writes_strict) {
2135 case SYSCTL_WRITES_STRICT:
2136 goto out;
2137 case SYSCTL_WRITES_WARN:
2138 warn_sysctl_write(table);
2139 break;
2140 default:
2141 break;
2145 if (left > PAGE_SIZE - 1)
2146 left = PAGE_SIZE - 1;
2147 page = __get_free_page(GFP_TEMPORARY);
2148 kbuf = (char *) page;
2149 if (!kbuf)
2150 return -ENOMEM;
2151 if (copy_from_user(kbuf, buffer, left)) {
2152 err = -EFAULT;
2153 goto free;
2155 kbuf[left] = 0;
2158 for (; left && vleft--; i++, first=0) {
2159 unsigned long lval;
2160 bool neg;
2162 if (write) {
2163 left -= proc_skip_spaces(&kbuf);
2165 if (!left)
2166 break;
2167 err = proc_get_long(&kbuf, &left, &lval, &neg,
2168 proc_wspace_sep,
2169 sizeof(proc_wspace_sep), NULL);
2170 if (err)
2171 break;
2172 if (conv(&neg, &lval, i, 1, data)) {
2173 err = -EINVAL;
2174 break;
2176 } else {
2177 if (conv(&neg, &lval, i, 0, data)) {
2178 err = -EINVAL;
2179 break;
2181 if (!first)
2182 err = proc_put_char(&buffer, &left, '\t');
2183 if (err)
2184 break;
2185 err = proc_put_long(&buffer, &left, lval, neg);
2186 if (err)
2187 break;
2191 if (!write && !first && left && !err)
2192 err = proc_put_char(&buffer, &left, '\n');
2193 if (write && !err && left)
2194 left -= proc_skip_spaces(&kbuf);
2195 free:
2196 if (write) {
2197 free_page(page);
2198 if (first)
2199 return err ? : -EINVAL;
2201 *lenp -= left;
2202 out:
2203 *ppos += *lenp;
2204 return err;
2207 static int do_proc_dointvec(struct ctl_table *table, int write,
2208 void __user *buffer, size_t *lenp, loff_t *ppos,
2209 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2210 int write, void *data),
2211 void *data)
2213 return __do_proc_dointvec(table->data, table, write,
2214 buffer, lenp, ppos, conv, data);
2218 * proc_dointvec - read a vector of integers
2219 * @table: the sysctl table
2220 * @write: %TRUE if this is a write to the sysctl file
2221 * @buffer: the user buffer
2222 * @lenp: the size of the user buffer
2223 * @ppos: file position
2225 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2226 * values from/to the user buffer, treated as an ASCII string.
2228 * Returns 0 on success.
2230 int proc_dointvec(struct ctl_table *table, int write,
2231 void __user *buffer, size_t *lenp, loff_t *ppos)
2233 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2237 * proc_douintvec - read a vector of unsigned integers
2238 * @table: the sysctl table
2239 * @write: %TRUE if this is a write to the sysctl file
2240 * @buffer: the user buffer
2241 * @lenp: the size of the user buffer
2242 * @ppos: file position
2244 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2245 * values from/to the user buffer, treated as an ASCII string.
2247 * Returns 0 on success.
2249 int proc_douintvec(struct ctl_table *table, int write,
2250 void __user *buffer, size_t *lenp, loff_t *ppos)
2252 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2253 do_proc_douintvec_conv, NULL);
2257 * Taint values can only be increased
2258 * This means we can safely use a temporary.
2260 static int proc_taint(struct ctl_table *table, int write,
2261 void __user *buffer, size_t *lenp, loff_t *ppos)
2263 struct ctl_table t;
2264 unsigned long tmptaint = get_taint();
2265 int err;
2267 if (write && !capable(CAP_SYS_ADMIN))
2268 return -EPERM;
2270 t = *table;
2271 t.data = &tmptaint;
2272 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2273 if (err < 0)
2274 return err;
2276 if (write) {
2278 * Poor man's atomic or. Not worth adding a primitive
2279 * to everyone's atomic.h for this
2281 int i;
2282 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2283 if ((tmptaint >> i) & 1)
2284 add_taint(i, LOCKDEP_STILL_OK);
2288 return err;
2291 #ifdef CONFIG_PRINTK
2292 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2293 void __user *buffer, size_t *lenp, loff_t *ppos)
2295 if (write && !capable(CAP_SYS_ADMIN))
2296 return -EPERM;
2298 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2300 #endif
2302 struct do_proc_dointvec_minmax_conv_param {
2303 int *min;
2304 int *max;
2307 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2308 int *valp,
2309 int write, void *data)
2311 struct do_proc_dointvec_minmax_conv_param *param = data;
2312 if (write) {
2313 int val;
2314 if (*negp) {
2315 if (*lvalp > (unsigned long) INT_MAX + 1)
2316 return -EINVAL;
2317 val = -*lvalp;
2318 } else {
2319 if (*lvalp > (unsigned long) INT_MAX)
2320 return -EINVAL;
2321 val = *lvalp;
2323 if ((param->min && *param->min > val) ||
2324 (param->max && *param->max < val))
2325 return -EINVAL;
2326 *valp = val;
2327 } else {
2328 int val = *valp;
2329 if (val < 0) {
2330 *negp = true;
2331 *lvalp = -(unsigned long)val;
2332 } else {
2333 *negp = false;
2334 *lvalp = (unsigned long)val;
2337 return 0;
2341 * proc_dointvec_minmax - read a vector of integers with min/max values
2342 * @table: the sysctl table
2343 * @write: %TRUE if this is a write to the sysctl file
2344 * @buffer: the user buffer
2345 * @lenp: the size of the user buffer
2346 * @ppos: file position
2348 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2349 * values from/to the user buffer, treated as an ASCII string.
2351 * This routine will ensure the values are within the range specified by
2352 * table->extra1 (min) and table->extra2 (max).
2354 * Returns 0 on success.
2356 int proc_dointvec_minmax(struct ctl_table *table, int write,
2357 void __user *buffer, size_t *lenp, loff_t *ppos)
2359 struct do_proc_dointvec_minmax_conv_param param = {
2360 .min = (int *) table->extra1,
2361 .max = (int *) table->extra2,
2363 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2364 do_proc_dointvec_minmax_conv, &param);
2367 static void validate_coredump_safety(void)
2369 #ifdef CONFIG_COREDUMP
2370 if (suid_dumpable == SUID_DUMP_ROOT &&
2371 core_pattern[0] != '/' && core_pattern[0] != '|') {
2372 printk(KERN_WARNING "Unsafe core_pattern used with "\
2373 "suid_dumpable=2. Pipe handler or fully qualified "\
2374 "core dump path required.\n");
2376 #endif
2379 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2380 void __user *buffer, size_t *lenp, loff_t *ppos)
2382 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2383 if (!error)
2384 validate_coredump_safety();
2385 return error;
2388 #ifdef CONFIG_COREDUMP
2389 static int proc_dostring_coredump(struct ctl_table *table, int write,
2390 void __user *buffer, size_t *lenp, loff_t *ppos)
2392 int error = proc_dostring(table, write, buffer, lenp, ppos);
2393 if (!error)
2394 validate_coredump_safety();
2395 return error;
2397 #endif
2399 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2400 void __user *buffer,
2401 size_t *lenp, loff_t *ppos,
2402 unsigned long convmul,
2403 unsigned long convdiv)
2405 unsigned long *i, *min, *max;
2406 int vleft, first = 1, err = 0;
2407 unsigned long page = 0;
2408 size_t left;
2409 char *kbuf;
2411 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2412 *lenp = 0;
2413 return 0;
2416 i = (unsigned long *) data;
2417 min = (unsigned long *) table->extra1;
2418 max = (unsigned long *) table->extra2;
2419 vleft = table->maxlen / sizeof(unsigned long);
2420 left = *lenp;
2422 if (write) {
2423 if (*ppos) {
2424 switch (sysctl_writes_strict) {
2425 case SYSCTL_WRITES_STRICT:
2426 goto out;
2427 case SYSCTL_WRITES_WARN:
2428 warn_sysctl_write(table);
2429 break;
2430 default:
2431 break;
2435 if (left > PAGE_SIZE - 1)
2436 left = PAGE_SIZE - 1;
2437 page = __get_free_page(GFP_TEMPORARY);
2438 kbuf = (char *) page;
2439 if (!kbuf)
2440 return -ENOMEM;
2441 if (copy_from_user(kbuf, buffer, left)) {
2442 err = -EFAULT;
2443 goto free;
2445 kbuf[left] = 0;
2448 for (; left && vleft--; i++, first = 0) {
2449 unsigned long val;
2451 if (write) {
2452 bool neg;
2454 left -= proc_skip_spaces(&kbuf);
2456 err = proc_get_long(&kbuf, &left, &val, &neg,
2457 proc_wspace_sep,
2458 sizeof(proc_wspace_sep), NULL);
2459 if (err)
2460 break;
2461 if (neg)
2462 continue;
2463 val = convmul * val / convdiv;
2464 if ((min && val < *min) || (max && val > *max)) {
2465 err = -EINVAL;
2466 break;
2468 *i = val;
2469 } else {
2470 val = convdiv * (*i) / convmul;
2471 if (!first) {
2472 err = proc_put_char(&buffer, &left, '\t');
2473 if (err)
2474 break;
2476 err = proc_put_long(&buffer, &left, val, false);
2477 if (err)
2478 break;
2482 if (!write && !first && left && !err)
2483 err = proc_put_char(&buffer, &left, '\n');
2484 if (write && !err)
2485 left -= proc_skip_spaces(&kbuf);
2486 free:
2487 if (write) {
2488 free_page(page);
2489 if (first)
2490 return err ? : -EINVAL;
2492 *lenp -= left;
2493 out:
2494 *ppos += *lenp;
2495 return err;
2498 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2499 void __user *buffer,
2500 size_t *lenp, loff_t *ppos,
2501 unsigned long convmul,
2502 unsigned long convdiv)
2504 return __do_proc_doulongvec_minmax(table->data, table, write,
2505 buffer, lenp, ppos, convmul, convdiv);
2509 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2510 * @table: the sysctl table
2511 * @write: %TRUE if this is a write to the sysctl file
2512 * @buffer: the user buffer
2513 * @lenp: the size of the user buffer
2514 * @ppos: file position
2516 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2517 * values from/to the user buffer, treated as an ASCII string.
2519 * This routine will ensure the values are within the range specified by
2520 * table->extra1 (min) and table->extra2 (max).
2522 * Returns 0 on success.
2524 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2525 void __user *buffer, size_t *lenp, loff_t *ppos)
2527 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2531 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2532 * @table: the sysctl table
2533 * @write: %TRUE if this is a write to the sysctl file
2534 * @buffer: the user buffer
2535 * @lenp: the size of the user buffer
2536 * @ppos: file position
2538 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2539 * values from/to the user buffer, treated as an ASCII string. The values
2540 * are treated as milliseconds, and converted to jiffies when they are stored.
2542 * This routine will ensure the values are within the range specified by
2543 * table->extra1 (min) and table->extra2 (max).
2545 * Returns 0 on success.
2547 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2548 void __user *buffer,
2549 size_t *lenp, loff_t *ppos)
2551 return do_proc_doulongvec_minmax(table, write, buffer,
2552 lenp, ppos, HZ, 1000l);
2556 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2557 int *valp,
2558 int write, void *data)
2560 if (write) {
2561 if (*lvalp > LONG_MAX / HZ)
2562 return 1;
2563 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2564 } else {
2565 int val = *valp;
2566 unsigned long lval;
2567 if (val < 0) {
2568 *negp = true;
2569 lval = -(unsigned long)val;
2570 } else {
2571 *negp = false;
2572 lval = (unsigned long)val;
2574 *lvalp = lval / HZ;
2576 return 0;
2579 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2580 int *valp,
2581 int write, void *data)
2583 if (write) {
2584 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2585 return 1;
2586 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2587 } else {
2588 int val = *valp;
2589 unsigned long lval;
2590 if (val < 0) {
2591 *negp = true;
2592 lval = -(unsigned long)val;
2593 } else {
2594 *negp = false;
2595 lval = (unsigned long)val;
2597 *lvalp = jiffies_to_clock_t(lval);
2599 return 0;
2602 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2603 int *valp,
2604 int write, void *data)
2606 if (write) {
2607 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2609 if (jif > INT_MAX)
2610 return 1;
2611 *valp = (int)jif;
2612 } else {
2613 int val = *valp;
2614 unsigned long lval;
2615 if (val < 0) {
2616 *negp = true;
2617 lval = -(unsigned long)val;
2618 } else {
2619 *negp = false;
2620 lval = (unsigned long)val;
2622 *lvalp = jiffies_to_msecs(lval);
2624 return 0;
2628 * proc_dointvec_jiffies - read a vector of integers as seconds
2629 * @table: the sysctl table
2630 * @write: %TRUE if this is a write to the sysctl file
2631 * @buffer: the user buffer
2632 * @lenp: the size of the user buffer
2633 * @ppos: file position
2635 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2636 * values from/to the user buffer, treated as an ASCII string.
2637 * The values read are assumed to be in seconds, and are converted into
2638 * jiffies.
2640 * Returns 0 on success.
2642 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2643 void __user *buffer, size_t *lenp, loff_t *ppos)
2645 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2646 do_proc_dointvec_jiffies_conv,NULL);
2650 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2651 * @table: the sysctl table
2652 * @write: %TRUE if this is a write to the sysctl file
2653 * @buffer: the user buffer
2654 * @lenp: the size of the user buffer
2655 * @ppos: pointer to the file position
2657 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2658 * values from/to the user buffer, treated as an ASCII string.
2659 * The values read are assumed to be in 1/USER_HZ seconds, and
2660 * are converted into jiffies.
2662 * Returns 0 on success.
2664 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2665 void __user *buffer, size_t *lenp, loff_t *ppos)
2667 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2668 do_proc_dointvec_userhz_jiffies_conv,NULL);
2672 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2673 * @table: the sysctl table
2674 * @write: %TRUE if this is a write to the sysctl file
2675 * @buffer: the user buffer
2676 * @lenp: the size of the user buffer
2677 * @ppos: file position
2678 * @ppos: the current position in the file
2680 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2681 * values from/to the user buffer, treated as an ASCII string.
2682 * The values read are assumed to be in 1/1000 seconds, and
2683 * are converted into jiffies.
2685 * Returns 0 on success.
2687 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2688 void __user *buffer, size_t *lenp, loff_t *ppos)
2690 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2691 do_proc_dointvec_ms_jiffies_conv, NULL);
2694 static int proc_do_cad_pid(struct ctl_table *table, int write,
2695 void __user *buffer, size_t *lenp, loff_t *ppos)
2697 struct pid *new_pid;
2698 pid_t tmp;
2699 int r;
2701 tmp = pid_vnr(cad_pid);
2703 r = __do_proc_dointvec(&tmp, table, write, buffer,
2704 lenp, ppos, NULL, NULL);
2705 if (r || !write)
2706 return r;
2708 new_pid = find_get_pid(tmp);
2709 if (!new_pid)
2710 return -ESRCH;
2712 put_pid(xchg(&cad_pid, new_pid));
2713 return 0;
2717 * proc_do_large_bitmap - read/write from/to a large bitmap
2718 * @table: the sysctl table
2719 * @write: %TRUE if this is a write to the sysctl file
2720 * @buffer: the user buffer
2721 * @lenp: the size of the user buffer
2722 * @ppos: file position
2724 * The bitmap is stored at table->data and the bitmap length (in bits)
2725 * in table->maxlen.
2727 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2728 * large bitmaps may be represented in a compact manner. Writing into
2729 * the file will clear the bitmap then update it with the given input.
2731 * Returns 0 on success.
2733 int proc_do_large_bitmap(struct ctl_table *table, int write,
2734 void __user *buffer, size_t *lenp, loff_t *ppos)
2736 int err = 0;
2737 bool first = 1;
2738 size_t left = *lenp;
2739 unsigned long bitmap_len = table->maxlen;
2740 unsigned long *bitmap = *(unsigned long **) table->data;
2741 unsigned long *tmp_bitmap = NULL;
2742 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2744 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2745 *lenp = 0;
2746 return 0;
2749 if (write) {
2750 unsigned long page = 0;
2751 char *kbuf;
2753 if (left > PAGE_SIZE - 1)
2754 left = PAGE_SIZE - 1;
2756 page = __get_free_page(GFP_TEMPORARY);
2757 kbuf = (char *) page;
2758 if (!kbuf)
2759 return -ENOMEM;
2760 if (copy_from_user(kbuf, buffer, left)) {
2761 free_page(page);
2762 return -EFAULT;
2764 kbuf[left] = 0;
2766 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2767 GFP_KERNEL);
2768 if (!tmp_bitmap) {
2769 free_page(page);
2770 return -ENOMEM;
2772 proc_skip_char(&kbuf, &left, '\n');
2773 while (!err && left) {
2774 unsigned long val_a, val_b;
2775 bool neg;
2777 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2778 sizeof(tr_a), &c);
2779 if (err)
2780 break;
2781 if (val_a >= bitmap_len || neg) {
2782 err = -EINVAL;
2783 break;
2786 val_b = val_a;
2787 if (left) {
2788 kbuf++;
2789 left--;
2792 if (c == '-') {
2793 err = proc_get_long(&kbuf, &left, &val_b,
2794 &neg, tr_b, sizeof(tr_b),
2795 &c);
2796 if (err)
2797 break;
2798 if (val_b >= bitmap_len || neg ||
2799 val_a > val_b) {
2800 err = -EINVAL;
2801 break;
2803 if (left) {
2804 kbuf++;
2805 left--;
2809 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2810 first = 0;
2811 proc_skip_char(&kbuf, &left, '\n');
2813 free_page(page);
2814 } else {
2815 unsigned long bit_a, bit_b = 0;
2817 while (left) {
2818 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2819 if (bit_a >= bitmap_len)
2820 break;
2821 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2822 bit_a + 1) - 1;
2824 if (!first) {
2825 err = proc_put_char(&buffer, &left, ',');
2826 if (err)
2827 break;
2829 err = proc_put_long(&buffer, &left, bit_a, false);
2830 if (err)
2831 break;
2832 if (bit_a != bit_b) {
2833 err = proc_put_char(&buffer, &left, '-');
2834 if (err)
2835 break;
2836 err = proc_put_long(&buffer, &left, bit_b, false);
2837 if (err)
2838 break;
2841 first = 0; bit_b++;
2843 if (!err)
2844 err = proc_put_char(&buffer, &left, '\n');
2847 if (!err) {
2848 if (write) {
2849 if (*ppos)
2850 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2851 else
2852 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2854 kfree(tmp_bitmap);
2855 *lenp -= left;
2856 *ppos += *lenp;
2857 return 0;
2858 } else {
2859 kfree(tmp_bitmap);
2860 return err;
2864 #else /* CONFIG_PROC_SYSCTL */
2866 int proc_dostring(struct ctl_table *table, int write,
2867 void __user *buffer, size_t *lenp, loff_t *ppos)
2869 return -ENOSYS;
2872 int proc_dointvec(struct ctl_table *table, int write,
2873 void __user *buffer, size_t *lenp, loff_t *ppos)
2875 return -ENOSYS;
2878 int proc_douintvec(struct ctl_table *table, int write,
2879 void __user *buffer, size_t *lenp, loff_t *ppos)
2881 return -ENOSYS;
2884 int proc_dointvec_minmax(struct ctl_table *table, int write,
2885 void __user *buffer, size_t *lenp, loff_t *ppos)
2887 return -ENOSYS;
2890 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2891 void __user *buffer, size_t *lenp, loff_t *ppos)
2893 return -ENOSYS;
2896 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2897 void __user *buffer, size_t *lenp, loff_t *ppos)
2899 return -ENOSYS;
2902 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2903 void __user *buffer, size_t *lenp, loff_t *ppos)
2905 return -ENOSYS;
2908 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2909 void __user *buffer, size_t *lenp, loff_t *ppos)
2911 return -ENOSYS;
2914 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2915 void __user *buffer,
2916 size_t *lenp, loff_t *ppos)
2918 return -ENOSYS;
2922 #endif /* CONFIG_PROC_SYSCTL */
2925 * No sense putting this after each symbol definition, twice,
2926 * exception granted :-)
2928 EXPORT_SYMBOL(proc_dointvec);
2929 EXPORT_SYMBOL(proc_douintvec);
2930 EXPORT_SYMBOL(proc_dointvec_jiffies);
2931 EXPORT_SYMBOL(proc_dointvec_minmax);
2932 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2933 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2934 EXPORT_SYMBOL(proc_dostring);
2935 EXPORT_SYMBOL(proc_doulongvec_minmax);
2936 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);