watchdog: xilinx: Make of_device_id array const
[linux/fpc-iii.git] / kernel / sysctl.c
blobdb19e3e2aa4bd000d96af8d3380af60148a01b10
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/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
34 #include <linux/fs.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/kexec.h>
67 #include <asm/uaccess.h>
68 #include <asm/processor.h>
70 #ifdef CONFIG_X86
71 #include <asm/nmi.h>
72 #include <asm/stacktrace.h>
73 #include <asm/io.h>
74 #endif
75 #ifdef CONFIG_SPARC
76 #include <asm/setup.h>
77 #endif
78 #ifdef CONFIG_BSD_PROCESS_ACCT
79 #include <linux/acct.h>
80 #endif
81 #ifdef CONFIG_RT_MUTEXES
82 #include <linux/rtmutex.h>
83 #endif
84 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85 #include <linux/lockdep.h>
86 #endif
87 #ifdef CONFIG_CHR_DEV_SG
88 #include <scsi/sg.h>
89 #endif
91 #ifdef CONFIG_LOCKUP_DETECTOR
92 #include <linux/nmi.h>
93 #endif
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
99 extern int max_threads;
100 extern int suid_dumpable;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid;
103 extern char core_pattern[];
104 extern unsigned int core_pipe_limit;
105 #endif
106 extern int pid_max;
107 extern int pid_max_min, pid_max_max;
108 extern int percpu_pagelist_fraction;
109 extern int compat_log;
110 extern int latencytop_enabled;
111 extern int sysctl_nr_open_min, sysctl_nr_open_max;
112 #ifndef CONFIG_MMU
113 extern int sysctl_nr_trim_pages;
114 #endif
116 /* Constants used for minimum and maximum */
117 #ifdef CONFIG_LOCKUP_DETECTOR
118 static int sixty = 60;
119 #endif
121 static int __maybe_unused neg_one = -1;
123 static int zero;
124 static int __maybe_unused one = 1;
125 static int __maybe_unused two = 2;
126 static int __maybe_unused four = 4;
127 static unsigned long one_ul = 1;
128 static int one_hundred = 100;
129 #ifdef CONFIG_PRINTK
130 static int ten_thousand = 10000;
131 #endif
133 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
134 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
136 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
137 static int maxolduid = 65535;
138 static int minolduid;
139 static int min_percpu_pagelist_fract = 8;
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 CONFIG_SPARC64
156 extern int sysctl_tsb_ratio;
157 #endif
159 #ifdef __hppa__
160 extern int pwrsw_enabled;
161 #endif
163 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
164 extern int unaligned_enabled;
165 #endif
167 #ifdef CONFIG_IA64
168 extern int unaligned_dump_stack;
169 #endif
171 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172 extern int no_unaligned_warning;
173 #endif
175 #ifdef CONFIG_PROC_SYSCTL
177 #define SYSCTL_WRITES_LEGACY -1
178 #define SYSCTL_WRITES_WARN 0
179 #define SYSCTL_WRITES_STRICT 1
181 static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
183 static int proc_do_cad_pid(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
185 static int proc_taint(struct ctl_table *table, int write,
186 void __user *buffer, size_t *lenp, loff_t *ppos);
187 #endif
189 #ifdef CONFIG_PRINTK
190 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
192 #endif
194 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
195 void __user *buffer, size_t *lenp, loff_t *ppos);
196 #ifdef CONFIG_COREDUMP
197 static int proc_dostring_coredump(struct ctl_table *table, int write,
198 void __user *buffer, size_t *lenp, loff_t *ppos);
199 #endif
201 #ifdef CONFIG_MAGIC_SYSRQ
202 /* Note: sysrq code uses it's own private copy */
203 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
205 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
206 void __user *buffer, size_t *lenp,
207 loff_t *ppos)
209 int error;
211 error = proc_dointvec(table, write, buffer, lenp, ppos);
212 if (error)
213 return error;
215 if (write)
216 sysrq_toggle_support(__sysrq_enabled);
218 return 0;
221 #endif
223 static struct ctl_table kern_table[];
224 static struct ctl_table vm_table[];
225 static struct ctl_table fs_table[];
226 static struct ctl_table debug_table[];
227 static struct ctl_table dev_table[];
228 extern struct ctl_table random_table[];
229 #ifdef CONFIG_EPOLL
230 extern struct ctl_table epoll_table[];
231 #endif
233 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
234 int sysctl_legacy_va_layout;
235 #endif
237 /* The default sysctl tables: */
239 static struct ctl_table sysctl_base_table[] = {
241 .procname = "kernel",
242 .mode = 0555,
243 .child = kern_table,
246 .procname = "vm",
247 .mode = 0555,
248 .child = vm_table,
251 .procname = "fs",
252 .mode = 0555,
253 .child = fs_table,
256 .procname = "debug",
257 .mode = 0555,
258 .child = debug_table,
261 .procname = "dev",
262 .mode = 0555,
263 .child = dev_table,
268 #ifdef CONFIG_SCHED_DEBUG
269 static int min_sched_granularity_ns = 100000; /* 100 usecs */
270 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
271 static int min_wakeup_granularity_ns; /* 0 usecs */
272 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
273 #ifdef CONFIG_SMP
274 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
275 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
276 #endif /* CONFIG_SMP */
277 #endif /* CONFIG_SCHED_DEBUG */
279 #ifdef CONFIG_COMPACTION
280 static int min_extfrag_threshold;
281 static int max_extfrag_threshold = 1000;
282 #endif
284 static struct ctl_table kern_table[] = {
286 .procname = "sched_child_runs_first",
287 .data = &sysctl_sched_child_runs_first,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = proc_dointvec,
292 #ifdef CONFIG_SCHED_DEBUG
294 .procname = "sched_min_granularity_ns",
295 .data = &sysctl_sched_min_granularity,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
298 .proc_handler = sched_proc_update_handler,
299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
303 .procname = "sched_latency_ns",
304 .data = &sysctl_sched_latency,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
307 .proc_handler = sched_proc_update_handler,
308 .extra1 = &min_sched_granularity_ns,
309 .extra2 = &max_sched_granularity_ns,
312 .procname = "sched_wakeup_granularity_ns",
313 .data = &sysctl_sched_wakeup_granularity,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_wakeup_granularity_ns,
318 .extra2 = &max_wakeup_granularity_ns,
320 #ifdef CONFIG_SMP
322 .procname = "sched_tunable_scaling",
323 .data = &sysctl_sched_tunable_scaling,
324 .maxlen = sizeof(enum sched_tunable_scaling),
325 .mode = 0644,
326 .proc_handler = sched_proc_update_handler,
327 .extra1 = &min_sched_tunable_scaling,
328 .extra2 = &max_sched_tunable_scaling,
331 .procname = "sched_migration_cost_ns",
332 .data = &sysctl_sched_migration_cost,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
335 .proc_handler = proc_dointvec,
338 .procname = "sched_nr_migrate",
339 .data = &sysctl_sched_nr_migrate,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
342 .proc_handler = proc_dointvec,
345 .procname = "sched_time_avg_ms",
346 .data = &sysctl_sched_time_avg,
347 .maxlen = sizeof(unsigned int),
348 .mode = 0644,
349 .proc_handler = proc_dointvec,
352 .procname = "sched_shares_window_ns",
353 .data = &sysctl_sched_shares_window,
354 .maxlen = sizeof(unsigned int),
355 .mode = 0644,
356 .proc_handler = proc_dointvec,
359 .procname = "timer_migration",
360 .data = &sysctl_timer_migration,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
363 .proc_handler = proc_dointvec_minmax,
364 .extra1 = &zero,
365 .extra2 = &one,
367 #endif /* CONFIG_SMP */
368 #ifdef CONFIG_NUMA_BALANCING
370 .procname = "numa_balancing_scan_delay_ms",
371 .data = &sysctl_numa_balancing_scan_delay,
372 .maxlen = sizeof(unsigned int),
373 .mode = 0644,
374 .proc_handler = proc_dointvec,
377 .procname = "numa_balancing_scan_period_min_ms",
378 .data = &sysctl_numa_balancing_scan_period_min,
379 .maxlen = sizeof(unsigned int),
380 .mode = 0644,
381 .proc_handler = proc_dointvec,
384 .procname = "numa_balancing_scan_period_max_ms",
385 .data = &sysctl_numa_balancing_scan_period_max,
386 .maxlen = sizeof(unsigned int),
387 .mode = 0644,
388 .proc_handler = proc_dointvec,
391 .procname = "numa_balancing_scan_size_mb",
392 .data = &sysctl_numa_balancing_scan_size,
393 .maxlen = sizeof(unsigned int),
394 .mode = 0644,
395 .proc_handler = proc_dointvec,
398 .procname = "numa_balancing",
399 .data = NULL, /* filled in by handler */
400 .maxlen = sizeof(unsigned int),
401 .mode = 0644,
402 .proc_handler = sysctl_numa_balancing,
403 .extra1 = &zero,
404 .extra2 = &one,
406 #endif /* CONFIG_NUMA_BALANCING */
407 #endif /* CONFIG_SCHED_DEBUG */
409 .procname = "sched_rt_period_us",
410 .data = &sysctl_sched_rt_period,
411 .maxlen = sizeof(unsigned int),
412 .mode = 0644,
413 .proc_handler = sched_rt_handler,
416 .procname = "sched_rt_runtime_us",
417 .data = &sysctl_sched_rt_runtime,
418 .maxlen = sizeof(int),
419 .mode = 0644,
420 .proc_handler = sched_rt_handler,
423 .procname = "sched_rr_timeslice_ms",
424 .data = &sched_rr_timeslice,
425 .maxlen = sizeof(int),
426 .mode = 0644,
427 .proc_handler = sched_rr_handler,
429 #ifdef CONFIG_SCHED_AUTOGROUP
431 .procname = "sched_autogroup_enabled",
432 .data = &sysctl_sched_autogroup_enabled,
433 .maxlen = sizeof(unsigned int),
434 .mode = 0644,
435 .proc_handler = proc_dointvec_minmax,
436 .extra1 = &zero,
437 .extra2 = &one,
439 #endif
440 #ifdef CONFIG_CFS_BANDWIDTH
442 .procname = "sched_cfs_bandwidth_slice_us",
443 .data = &sysctl_sched_cfs_bandwidth_slice,
444 .maxlen = sizeof(unsigned int),
445 .mode = 0644,
446 .proc_handler = proc_dointvec_minmax,
447 .extra1 = &one,
449 #endif
450 #ifdef CONFIG_PROVE_LOCKING
452 .procname = "prove_locking",
453 .data = &prove_locking,
454 .maxlen = sizeof(int),
455 .mode = 0644,
456 .proc_handler = proc_dointvec,
458 #endif
459 #ifdef CONFIG_LOCK_STAT
461 .procname = "lock_stat",
462 .data = &lock_stat,
463 .maxlen = sizeof(int),
464 .mode = 0644,
465 .proc_handler = proc_dointvec,
467 #endif
469 .procname = "panic",
470 .data = &panic_timeout,
471 .maxlen = sizeof(int),
472 .mode = 0644,
473 .proc_handler = proc_dointvec,
475 #ifdef CONFIG_COREDUMP
477 .procname = "core_uses_pid",
478 .data = &core_uses_pid,
479 .maxlen = sizeof(int),
480 .mode = 0644,
481 .proc_handler = proc_dointvec,
484 .procname = "core_pattern",
485 .data = core_pattern,
486 .maxlen = CORENAME_MAX_SIZE,
487 .mode = 0644,
488 .proc_handler = proc_dostring_coredump,
491 .procname = "core_pipe_limit",
492 .data = &core_pipe_limit,
493 .maxlen = sizeof(unsigned int),
494 .mode = 0644,
495 .proc_handler = proc_dointvec,
497 #endif
498 #ifdef CONFIG_PROC_SYSCTL
500 .procname = "tainted",
501 .maxlen = sizeof(long),
502 .mode = 0644,
503 .proc_handler = proc_taint,
506 .procname = "sysctl_writes_strict",
507 .data = &sysctl_writes_strict,
508 .maxlen = sizeof(int),
509 .mode = 0644,
510 .proc_handler = proc_dointvec_minmax,
511 .extra1 = &neg_one,
512 .extra2 = &one,
514 #endif
515 #ifdef CONFIG_LATENCYTOP
517 .procname = "latencytop",
518 .data = &latencytop_enabled,
519 .maxlen = sizeof(int),
520 .mode = 0644,
521 .proc_handler = proc_dointvec,
523 #endif
524 #ifdef CONFIG_BLK_DEV_INITRD
526 .procname = "real-root-dev",
527 .data = &real_root_dev,
528 .maxlen = sizeof(int),
529 .mode = 0644,
530 .proc_handler = proc_dointvec,
532 #endif
534 .procname = "print-fatal-signals",
535 .data = &print_fatal_signals,
536 .maxlen = sizeof(int),
537 .mode = 0644,
538 .proc_handler = proc_dointvec,
540 #ifdef CONFIG_SPARC
542 .procname = "reboot-cmd",
543 .data = reboot_command,
544 .maxlen = 256,
545 .mode = 0644,
546 .proc_handler = proc_dostring,
549 .procname = "stop-a",
550 .data = &stop_a_enabled,
551 .maxlen = sizeof (int),
552 .mode = 0644,
553 .proc_handler = proc_dointvec,
556 .procname = "scons-poweroff",
557 .data = &scons_pwroff,
558 .maxlen = sizeof (int),
559 .mode = 0644,
560 .proc_handler = proc_dointvec,
562 #endif
563 #ifdef CONFIG_SPARC64
565 .procname = "tsb-ratio",
566 .data = &sysctl_tsb_ratio,
567 .maxlen = sizeof (int),
568 .mode = 0644,
569 .proc_handler = proc_dointvec,
571 #endif
572 #ifdef __hppa__
574 .procname = "soft-power",
575 .data = &pwrsw_enabled,
576 .maxlen = sizeof (int),
577 .mode = 0644,
578 .proc_handler = proc_dointvec,
580 #endif
581 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
583 .procname = "unaligned-trap",
584 .data = &unaligned_enabled,
585 .maxlen = sizeof (int),
586 .mode = 0644,
587 .proc_handler = proc_dointvec,
589 #endif
591 .procname = "ctrl-alt-del",
592 .data = &C_A_D,
593 .maxlen = sizeof(int),
594 .mode = 0644,
595 .proc_handler = proc_dointvec,
597 #ifdef CONFIG_FUNCTION_TRACER
599 .procname = "ftrace_enabled",
600 .data = &ftrace_enabled,
601 .maxlen = sizeof(int),
602 .mode = 0644,
603 .proc_handler = ftrace_enable_sysctl,
605 #endif
606 #ifdef CONFIG_STACK_TRACER
608 .procname = "stack_tracer_enabled",
609 .data = &stack_tracer_enabled,
610 .maxlen = sizeof(int),
611 .mode = 0644,
612 .proc_handler = stack_trace_sysctl,
614 #endif
615 #ifdef CONFIG_TRACING
617 .procname = "ftrace_dump_on_oops",
618 .data = &ftrace_dump_on_oops,
619 .maxlen = sizeof(int),
620 .mode = 0644,
621 .proc_handler = proc_dointvec,
624 .procname = "traceoff_on_warning",
625 .data = &__disable_trace_on_warning,
626 .maxlen = sizeof(__disable_trace_on_warning),
627 .mode = 0644,
628 .proc_handler = proc_dointvec,
630 #endif
631 #ifdef CONFIG_KEXEC
633 .procname = "kexec_load_disabled",
634 .data = &kexec_load_disabled,
635 .maxlen = sizeof(int),
636 .mode = 0644,
637 /* only handle a transition from default "0" to "1" */
638 .proc_handler = proc_dointvec_minmax,
639 .extra1 = &one,
640 .extra2 = &one,
642 #endif
643 #ifdef CONFIG_MODULES
645 .procname = "modprobe",
646 .data = &modprobe_path,
647 .maxlen = KMOD_PATH_LEN,
648 .mode = 0644,
649 .proc_handler = proc_dostring,
652 .procname = "modules_disabled",
653 .data = &modules_disabled,
654 .maxlen = sizeof(int),
655 .mode = 0644,
656 /* only handle a transition from default "0" to "1" */
657 .proc_handler = proc_dointvec_minmax,
658 .extra1 = &one,
659 .extra2 = &one,
661 #endif
662 #ifdef CONFIG_UEVENT_HELPER
664 .procname = "hotplug",
665 .data = &uevent_helper,
666 .maxlen = UEVENT_HELPER_PATH_LEN,
667 .mode = 0644,
668 .proc_handler = proc_dostring,
670 #endif
671 #ifdef CONFIG_CHR_DEV_SG
673 .procname = "sg-big-buff",
674 .data = &sg_big_buff,
675 .maxlen = sizeof (int),
676 .mode = 0444,
677 .proc_handler = proc_dointvec,
679 #endif
680 #ifdef CONFIG_BSD_PROCESS_ACCT
682 .procname = "acct",
683 .data = &acct_parm,
684 .maxlen = 3*sizeof(int),
685 .mode = 0644,
686 .proc_handler = proc_dointvec,
688 #endif
689 #ifdef CONFIG_MAGIC_SYSRQ
691 .procname = "sysrq",
692 .data = &__sysrq_enabled,
693 .maxlen = sizeof (int),
694 .mode = 0644,
695 .proc_handler = sysrq_sysctl_handler,
697 #endif
698 #ifdef CONFIG_PROC_SYSCTL
700 .procname = "cad_pid",
701 .data = NULL,
702 .maxlen = sizeof (int),
703 .mode = 0600,
704 .proc_handler = proc_do_cad_pid,
706 #endif
708 .procname = "threads-max",
709 .data = &max_threads,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = proc_dointvec,
715 .procname = "random",
716 .mode = 0555,
717 .child = random_table,
720 .procname = "usermodehelper",
721 .mode = 0555,
722 .child = usermodehelper_table,
725 .procname = "overflowuid",
726 .data = &overflowuid,
727 .maxlen = sizeof(int),
728 .mode = 0644,
729 .proc_handler = proc_dointvec_minmax,
730 .extra1 = &minolduid,
731 .extra2 = &maxolduid,
734 .procname = "overflowgid",
735 .data = &overflowgid,
736 .maxlen = sizeof(int),
737 .mode = 0644,
738 .proc_handler = proc_dointvec_minmax,
739 .extra1 = &minolduid,
740 .extra2 = &maxolduid,
742 #ifdef CONFIG_S390
743 #ifdef CONFIG_MATHEMU
745 .procname = "ieee_emulation_warnings",
746 .data = &sysctl_ieee_emulation_warnings,
747 .maxlen = sizeof(int),
748 .mode = 0644,
749 .proc_handler = proc_dointvec,
751 #endif
753 .procname = "userprocess_debug",
754 .data = &show_unhandled_signals,
755 .maxlen = sizeof(int),
756 .mode = 0644,
757 .proc_handler = proc_dointvec,
759 #endif
761 .procname = "pid_max",
762 .data = &pid_max,
763 .maxlen = sizeof (int),
764 .mode = 0644,
765 .proc_handler = proc_dointvec_minmax,
766 .extra1 = &pid_max_min,
767 .extra2 = &pid_max_max,
770 .procname = "panic_on_oops",
771 .data = &panic_on_oops,
772 .maxlen = sizeof(int),
773 .mode = 0644,
774 .proc_handler = proc_dointvec,
776 #if defined CONFIG_PRINTK
778 .procname = "printk",
779 .data = &console_loglevel,
780 .maxlen = 4*sizeof(int),
781 .mode = 0644,
782 .proc_handler = proc_dointvec,
785 .procname = "printk_ratelimit",
786 .data = &printk_ratelimit_state.interval,
787 .maxlen = sizeof(int),
788 .mode = 0644,
789 .proc_handler = proc_dointvec_jiffies,
792 .procname = "printk_ratelimit_burst",
793 .data = &printk_ratelimit_state.burst,
794 .maxlen = sizeof(int),
795 .mode = 0644,
796 .proc_handler = proc_dointvec,
799 .procname = "printk_delay",
800 .data = &printk_delay_msec,
801 .maxlen = sizeof(int),
802 .mode = 0644,
803 .proc_handler = proc_dointvec_minmax,
804 .extra1 = &zero,
805 .extra2 = &ten_thousand,
808 .procname = "dmesg_restrict",
809 .data = &dmesg_restrict,
810 .maxlen = sizeof(int),
811 .mode = 0644,
812 .proc_handler = proc_dointvec_minmax_sysadmin,
813 .extra1 = &zero,
814 .extra2 = &one,
817 .procname = "kptr_restrict",
818 .data = &kptr_restrict,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = proc_dointvec_minmax_sysadmin,
822 .extra1 = &zero,
823 .extra2 = &two,
825 #endif
827 .procname = "ngroups_max",
828 .data = &ngroups_max,
829 .maxlen = sizeof (int),
830 .mode = 0444,
831 .proc_handler = proc_dointvec,
834 .procname = "cap_last_cap",
835 .data = (void *)&cap_last_cap,
836 .maxlen = sizeof(int),
837 .mode = 0444,
838 .proc_handler = proc_dointvec,
840 #if defined(CONFIG_LOCKUP_DETECTOR)
842 .procname = "watchdog",
843 .data = &watchdog_user_enabled,
844 .maxlen = sizeof (int),
845 .mode = 0644,
846 .proc_handler = proc_dowatchdog,
847 .extra1 = &zero,
848 .extra2 = &one,
851 .procname = "watchdog_thresh",
852 .data = &watchdog_thresh,
853 .maxlen = sizeof(int),
854 .mode = 0644,
855 .proc_handler = proc_dowatchdog,
856 .extra1 = &zero,
857 .extra2 = &sixty,
860 .procname = "softlockup_panic",
861 .data = &softlockup_panic,
862 .maxlen = sizeof(int),
863 .mode = 0644,
864 .proc_handler = proc_dointvec_minmax,
865 .extra1 = &zero,
866 .extra2 = &one,
869 .procname = "nmi_watchdog",
870 .data = &watchdog_user_enabled,
871 .maxlen = sizeof (int),
872 .mode = 0644,
873 .proc_handler = proc_dowatchdog,
874 .extra1 = &zero,
875 .extra2 = &one,
877 #endif
878 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
880 .procname = "unknown_nmi_panic",
881 .data = &unknown_nmi_panic,
882 .maxlen = sizeof (int),
883 .mode = 0644,
884 .proc_handler = proc_dointvec,
886 #endif
887 #if defined(CONFIG_X86)
889 .procname = "panic_on_unrecovered_nmi",
890 .data = &panic_on_unrecovered_nmi,
891 .maxlen = sizeof(int),
892 .mode = 0644,
893 .proc_handler = proc_dointvec,
896 .procname = "panic_on_io_nmi",
897 .data = &panic_on_io_nmi,
898 .maxlen = sizeof(int),
899 .mode = 0644,
900 .proc_handler = proc_dointvec,
902 #ifdef CONFIG_DEBUG_STACKOVERFLOW
904 .procname = "panic_on_stackoverflow",
905 .data = &sysctl_panic_on_stackoverflow,
906 .maxlen = sizeof(int),
907 .mode = 0644,
908 .proc_handler = proc_dointvec,
910 #endif
912 .procname = "bootloader_type",
913 .data = &bootloader_type,
914 .maxlen = sizeof (int),
915 .mode = 0444,
916 .proc_handler = proc_dointvec,
919 .procname = "bootloader_version",
920 .data = &bootloader_version,
921 .maxlen = sizeof (int),
922 .mode = 0444,
923 .proc_handler = proc_dointvec,
926 .procname = "kstack_depth_to_print",
927 .data = &kstack_depth_to_print,
928 .maxlen = sizeof(int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec,
933 .procname = "io_delay_type",
934 .data = &io_delay_type,
935 .maxlen = sizeof(int),
936 .mode = 0644,
937 .proc_handler = proc_dointvec,
939 #endif
940 #if defined(CONFIG_MMU)
942 .procname = "randomize_va_space",
943 .data = &randomize_va_space,
944 .maxlen = sizeof(int),
945 .mode = 0644,
946 .proc_handler = proc_dointvec,
948 #endif
949 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
951 .procname = "spin_retry",
952 .data = &spin_retry,
953 .maxlen = sizeof (int),
954 .mode = 0644,
955 .proc_handler = proc_dointvec,
957 #endif
958 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
960 .procname = "acpi_video_flags",
961 .data = &acpi_realmode_flags,
962 .maxlen = sizeof (unsigned long),
963 .mode = 0644,
964 .proc_handler = proc_doulongvec_minmax,
966 #endif
967 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
969 .procname = "ignore-unaligned-usertrap",
970 .data = &no_unaligned_warning,
971 .maxlen = sizeof (int),
972 .mode = 0644,
973 .proc_handler = proc_dointvec,
975 #endif
976 #ifdef CONFIG_IA64
978 .procname = "unaligned-dump-stack",
979 .data = &unaligned_dump_stack,
980 .maxlen = sizeof (int),
981 .mode = 0644,
982 .proc_handler = proc_dointvec,
984 #endif
985 #ifdef CONFIG_DETECT_HUNG_TASK
987 .procname = "hung_task_panic",
988 .data = &sysctl_hung_task_panic,
989 .maxlen = sizeof(int),
990 .mode = 0644,
991 .proc_handler = proc_dointvec_minmax,
992 .extra1 = &zero,
993 .extra2 = &one,
996 .procname = "hung_task_check_count",
997 .data = &sysctl_hung_task_check_count,
998 .maxlen = sizeof(int),
999 .mode = 0644,
1000 .proc_handler = proc_dointvec_minmax,
1001 .extra1 = &zero,
1004 .procname = "hung_task_timeout_secs",
1005 .data = &sysctl_hung_task_timeout_secs,
1006 .maxlen = sizeof(unsigned long),
1007 .mode = 0644,
1008 .proc_handler = proc_dohung_task_timeout_secs,
1009 .extra2 = &hung_task_timeout_max,
1012 .procname = "hung_task_warnings",
1013 .data = &sysctl_hung_task_warnings,
1014 .maxlen = sizeof(int),
1015 .mode = 0644,
1016 .proc_handler = proc_dointvec_minmax,
1017 .extra1 = &neg_one,
1019 #endif
1020 #ifdef CONFIG_COMPAT
1022 .procname = "compat-log",
1023 .data = &compat_log,
1024 .maxlen = sizeof (int),
1025 .mode = 0644,
1026 .proc_handler = proc_dointvec,
1028 #endif
1029 #ifdef CONFIG_RT_MUTEXES
1031 .procname = "max_lock_depth",
1032 .data = &max_lock_depth,
1033 .maxlen = sizeof(int),
1034 .mode = 0644,
1035 .proc_handler = proc_dointvec,
1037 #endif
1039 .procname = "poweroff_cmd",
1040 .data = &poweroff_cmd,
1041 .maxlen = POWEROFF_CMD_PATH_LEN,
1042 .mode = 0644,
1043 .proc_handler = proc_dostring,
1045 #ifdef CONFIG_KEYS
1047 .procname = "keys",
1048 .mode = 0555,
1049 .child = key_sysctls,
1051 #endif
1052 #ifdef CONFIG_RCU_TORTURE_TEST
1054 .procname = "rcutorture_runnable",
1055 .data = &rcutorture_runnable,
1056 .maxlen = sizeof(int),
1057 .mode = 0644,
1058 .proc_handler = proc_dointvec,
1060 #endif
1061 #ifdef CONFIG_PERF_EVENTS
1063 * User-space scripts rely on the existence of this file
1064 * as a feature check for perf_events being enabled.
1066 * So it's an ABI, do not remove!
1069 .procname = "perf_event_paranoid",
1070 .data = &sysctl_perf_event_paranoid,
1071 .maxlen = sizeof(sysctl_perf_event_paranoid),
1072 .mode = 0644,
1073 .proc_handler = proc_dointvec,
1076 .procname = "perf_event_mlock_kb",
1077 .data = &sysctl_perf_event_mlock,
1078 .maxlen = sizeof(sysctl_perf_event_mlock),
1079 .mode = 0644,
1080 .proc_handler = proc_dointvec,
1083 .procname = "perf_event_max_sample_rate",
1084 .data = &sysctl_perf_event_sample_rate,
1085 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1086 .mode = 0644,
1087 .proc_handler = perf_proc_update_handler,
1088 .extra1 = &one,
1091 .procname = "perf_cpu_time_max_percent",
1092 .data = &sysctl_perf_cpu_time_max_percent,
1093 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1094 .mode = 0644,
1095 .proc_handler = perf_cpu_time_max_percent_handler,
1096 .extra1 = &zero,
1097 .extra2 = &one_hundred,
1099 #endif
1100 #ifdef CONFIG_KMEMCHECK
1102 .procname = "kmemcheck",
1103 .data = &kmemcheck_enabled,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
1106 .proc_handler = proc_dointvec,
1108 #endif
1112 static struct ctl_table vm_table[] = {
1114 .procname = "overcommit_memory",
1115 .data = &sysctl_overcommit_memory,
1116 .maxlen = sizeof(sysctl_overcommit_memory),
1117 .mode = 0644,
1118 .proc_handler = proc_dointvec_minmax,
1119 .extra1 = &zero,
1120 .extra2 = &two,
1123 .procname = "panic_on_oom",
1124 .data = &sysctl_panic_on_oom,
1125 .maxlen = sizeof(sysctl_panic_on_oom),
1126 .mode = 0644,
1127 .proc_handler = proc_dointvec_minmax,
1128 .extra1 = &zero,
1129 .extra2 = &two,
1132 .procname = "oom_kill_allocating_task",
1133 .data = &sysctl_oom_kill_allocating_task,
1134 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1135 .mode = 0644,
1136 .proc_handler = proc_dointvec,
1139 .procname = "oom_dump_tasks",
1140 .data = &sysctl_oom_dump_tasks,
1141 .maxlen = sizeof(sysctl_oom_dump_tasks),
1142 .mode = 0644,
1143 .proc_handler = proc_dointvec,
1146 .procname = "overcommit_ratio",
1147 .data = &sysctl_overcommit_ratio,
1148 .maxlen = sizeof(sysctl_overcommit_ratio),
1149 .mode = 0644,
1150 .proc_handler = overcommit_ratio_handler,
1153 .procname = "overcommit_kbytes",
1154 .data = &sysctl_overcommit_kbytes,
1155 .maxlen = sizeof(sysctl_overcommit_kbytes),
1156 .mode = 0644,
1157 .proc_handler = overcommit_kbytes_handler,
1160 .procname = "page-cluster",
1161 .data = &page_cluster,
1162 .maxlen = sizeof(int),
1163 .mode = 0644,
1164 .proc_handler = proc_dointvec_minmax,
1165 .extra1 = &zero,
1168 .procname = "dirty_background_ratio",
1169 .data = &dirty_background_ratio,
1170 .maxlen = sizeof(dirty_background_ratio),
1171 .mode = 0644,
1172 .proc_handler = dirty_background_ratio_handler,
1173 .extra1 = &zero,
1174 .extra2 = &one_hundred,
1177 .procname = "dirty_background_bytes",
1178 .data = &dirty_background_bytes,
1179 .maxlen = sizeof(dirty_background_bytes),
1180 .mode = 0644,
1181 .proc_handler = dirty_background_bytes_handler,
1182 .extra1 = &one_ul,
1185 .procname = "dirty_ratio",
1186 .data = &vm_dirty_ratio,
1187 .maxlen = sizeof(vm_dirty_ratio),
1188 .mode = 0644,
1189 .proc_handler = dirty_ratio_handler,
1190 .extra1 = &zero,
1191 .extra2 = &one_hundred,
1194 .procname = "dirty_bytes",
1195 .data = &vm_dirty_bytes,
1196 .maxlen = sizeof(vm_dirty_bytes),
1197 .mode = 0644,
1198 .proc_handler = dirty_bytes_handler,
1199 .extra1 = &dirty_bytes_min,
1202 .procname = "dirty_writeback_centisecs",
1203 .data = &dirty_writeback_interval,
1204 .maxlen = sizeof(dirty_writeback_interval),
1205 .mode = 0644,
1206 .proc_handler = dirty_writeback_centisecs_handler,
1209 .procname = "dirty_expire_centisecs",
1210 .data = &dirty_expire_interval,
1211 .maxlen = sizeof(dirty_expire_interval),
1212 .mode = 0644,
1213 .proc_handler = proc_dointvec_minmax,
1214 .extra1 = &zero,
1217 .procname = "nr_pdflush_threads",
1218 .mode = 0444 /* read-only */,
1219 .proc_handler = pdflush_proc_obsolete,
1222 .procname = "swappiness",
1223 .data = &vm_swappiness,
1224 .maxlen = sizeof(vm_swappiness),
1225 .mode = 0644,
1226 .proc_handler = proc_dointvec_minmax,
1227 .extra1 = &zero,
1228 .extra2 = &one_hundred,
1230 #ifdef CONFIG_HUGETLB_PAGE
1232 .procname = "nr_hugepages",
1233 .data = NULL,
1234 .maxlen = sizeof(unsigned long),
1235 .mode = 0644,
1236 .proc_handler = hugetlb_sysctl_handler,
1237 .extra1 = (void *)&hugetlb_zero,
1238 .extra2 = (void *)&hugetlb_infinity,
1240 #ifdef CONFIG_NUMA
1242 .procname = "nr_hugepages_mempolicy",
1243 .data = NULL,
1244 .maxlen = sizeof(unsigned long),
1245 .mode = 0644,
1246 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1247 .extra1 = (void *)&hugetlb_zero,
1248 .extra2 = (void *)&hugetlb_infinity,
1250 #endif
1252 .procname = "hugetlb_shm_group",
1253 .data = &sysctl_hugetlb_shm_group,
1254 .maxlen = sizeof(gid_t),
1255 .mode = 0644,
1256 .proc_handler = proc_dointvec,
1259 .procname = "hugepages_treat_as_movable",
1260 .data = &hugepages_treat_as_movable,
1261 .maxlen = sizeof(int),
1262 .mode = 0644,
1263 .proc_handler = proc_dointvec,
1266 .procname = "nr_overcommit_hugepages",
1267 .data = NULL,
1268 .maxlen = sizeof(unsigned long),
1269 .mode = 0644,
1270 .proc_handler = hugetlb_overcommit_handler,
1271 .extra1 = (void *)&hugetlb_zero,
1272 .extra2 = (void *)&hugetlb_infinity,
1274 #endif
1276 .procname = "lowmem_reserve_ratio",
1277 .data = &sysctl_lowmem_reserve_ratio,
1278 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1279 .mode = 0644,
1280 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1283 .procname = "drop_caches",
1284 .data = &sysctl_drop_caches,
1285 .maxlen = sizeof(int),
1286 .mode = 0644,
1287 .proc_handler = drop_caches_sysctl_handler,
1288 .extra1 = &one,
1289 .extra2 = &four,
1291 #ifdef CONFIG_COMPACTION
1293 .procname = "compact_memory",
1294 .data = &sysctl_compact_memory,
1295 .maxlen = sizeof(int),
1296 .mode = 0200,
1297 .proc_handler = sysctl_compaction_handler,
1300 .procname = "extfrag_threshold",
1301 .data = &sysctl_extfrag_threshold,
1302 .maxlen = sizeof(int),
1303 .mode = 0644,
1304 .proc_handler = sysctl_extfrag_handler,
1305 .extra1 = &min_extfrag_threshold,
1306 .extra2 = &max_extfrag_threshold,
1309 #endif /* CONFIG_COMPACTION */
1311 .procname = "min_free_kbytes",
1312 .data = &min_free_kbytes,
1313 .maxlen = sizeof(min_free_kbytes),
1314 .mode = 0644,
1315 .proc_handler = min_free_kbytes_sysctl_handler,
1316 .extra1 = &zero,
1319 .procname = "percpu_pagelist_fraction",
1320 .data = &percpu_pagelist_fraction,
1321 .maxlen = sizeof(percpu_pagelist_fraction),
1322 .mode = 0644,
1323 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1324 .extra1 = &min_percpu_pagelist_fract,
1326 #ifdef CONFIG_MMU
1328 .procname = "max_map_count",
1329 .data = &sysctl_max_map_count,
1330 .maxlen = sizeof(sysctl_max_map_count),
1331 .mode = 0644,
1332 .proc_handler = proc_dointvec_minmax,
1333 .extra1 = &zero,
1335 #else
1337 .procname = "nr_trim_pages",
1338 .data = &sysctl_nr_trim_pages,
1339 .maxlen = sizeof(sysctl_nr_trim_pages),
1340 .mode = 0644,
1341 .proc_handler = proc_dointvec_minmax,
1342 .extra1 = &zero,
1344 #endif
1346 .procname = "laptop_mode",
1347 .data = &laptop_mode,
1348 .maxlen = sizeof(laptop_mode),
1349 .mode = 0644,
1350 .proc_handler = proc_dointvec_jiffies,
1353 .procname = "block_dump",
1354 .data = &block_dump,
1355 .maxlen = sizeof(block_dump),
1356 .mode = 0644,
1357 .proc_handler = proc_dointvec,
1358 .extra1 = &zero,
1361 .procname = "vfs_cache_pressure",
1362 .data = &sysctl_vfs_cache_pressure,
1363 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1364 .mode = 0644,
1365 .proc_handler = proc_dointvec,
1366 .extra1 = &zero,
1368 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1370 .procname = "legacy_va_layout",
1371 .data = &sysctl_legacy_va_layout,
1372 .maxlen = sizeof(sysctl_legacy_va_layout),
1373 .mode = 0644,
1374 .proc_handler = proc_dointvec,
1375 .extra1 = &zero,
1377 #endif
1378 #ifdef CONFIG_NUMA
1380 .procname = "zone_reclaim_mode",
1381 .data = &zone_reclaim_mode,
1382 .maxlen = sizeof(zone_reclaim_mode),
1383 .mode = 0644,
1384 .proc_handler = proc_dointvec,
1385 .extra1 = &zero,
1388 .procname = "min_unmapped_ratio",
1389 .data = &sysctl_min_unmapped_ratio,
1390 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1391 .mode = 0644,
1392 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1393 .extra1 = &zero,
1394 .extra2 = &one_hundred,
1397 .procname = "min_slab_ratio",
1398 .data = &sysctl_min_slab_ratio,
1399 .maxlen = sizeof(sysctl_min_slab_ratio),
1400 .mode = 0644,
1401 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1402 .extra1 = &zero,
1403 .extra2 = &one_hundred,
1405 #endif
1406 #ifdef CONFIG_SMP
1408 .procname = "stat_interval",
1409 .data = &sysctl_stat_interval,
1410 .maxlen = sizeof(sysctl_stat_interval),
1411 .mode = 0644,
1412 .proc_handler = proc_dointvec_jiffies,
1414 #endif
1415 #ifdef CONFIG_MMU
1417 .procname = "mmap_min_addr",
1418 .data = &dac_mmap_min_addr,
1419 .maxlen = sizeof(unsigned long),
1420 .mode = 0644,
1421 .proc_handler = mmap_min_addr_handler,
1423 #endif
1424 #ifdef CONFIG_NUMA
1426 .procname = "numa_zonelist_order",
1427 .data = &numa_zonelist_order,
1428 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1429 .mode = 0644,
1430 .proc_handler = numa_zonelist_order_handler,
1432 #endif
1433 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1434 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1436 .procname = "vdso_enabled",
1437 #ifdef CONFIG_X86_32
1438 .data = &vdso32_enabled,
1439 .maxlen = sizeof(vdso32_enabled),
1440 #else
1441 .data = &vdso_enabled,
1442 .maxlen = sizeof(vdso_enabled),
1443 #endif
1444 .mode = 0644,
1445 .proc_handler = proc_dointvec,
1446 .extra1 = &zero,
1448 #endif
1449 #ifdef CONFIG_HIGHMEM
1451 .procname = "highmem_is_dirtyable",
1452 .data = &vm_highmem_is_dirtyable,
1453 .maxlen = sizeof(vm_highmem_is_dirtyable),
1454 .mode = 0644,
1455 .proc_handler = proc_dointvec_minmax,
1456 .extra1 = &zero,
1457 .extra2 = &one,
1459 #endif
1461 .procname = "scan_unevictable_pages",
1462 .data = &scan_unevictable_pages,
1463 .maxlen = sizeof(scan_unevictable_pages),
1464 .mode = 0644,
1465 .proc_handler = scan_unevictable_handler,
1467 #ifdef CONFIG_MEMORY_FAILURE
1469 .procname = "memory_failure_early_kill",
1470 .data = &sysctl_memory_failure_early_kill,
1471 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1472 .mode = 0644,
1473 .proc_handler = proc_dointvec_minmax,
1474 .extra1 = &zero,
1475 .extra2 = &one,
1478 .procname = "memory_failure_recovery",
1479 .data = &sysctl_memory_failure_recovery,
1480 .maxlen = sizeof(sysctl_memory_failure_recovery),
1481 .mode = 0644,
1482 .proc_handler = proc_dointvec_minmax,
1483 .extra1 = &zero,
1484 .extra2 = &one,
1486 #endif
1488 .procname = "user_reserve_kbytes",
1489 .data = &sysctl_user_reserve_kbytes,
1490 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1491 .mode = 0644,
1492 .proc_handler = proc_doulongvec_minmax,
1495 .procname = "admin_reserve_kbytes",
1496 .data = &sysctl_admin_reserve_kbytes,
1497 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1498 .mode = 0644,
1499 .proc_handler = proc_doulongvec_minmax,
1504 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1505 static struct ctl_table binfmt_misc_table[] = {
1508 #endif
1510 static struct ctl_table fs_table[] = {
1512 .procname = "inode-nr",
1513 .data = &inodes_stat,
1514 .maxlen = 2*sizeof(long),
1515 .mode = 0444,
1516 .proc_handler = proc_nr_inodes,
1519 .procname = "inode-state",
1520 .data = &inodes_stat,
1521 .maxlen = 7*sizeof(long),
1522 .mode = 0444,
1523 .proc_handler = proc_nr_inodes,
1526 .procname = "file-nr",
1527 .data = &files_stat,
1528 .maxlen = sizeof(files_stat),
1529 .mode = 0444,
1530 .proc_handler = proc_nr_files,
1533 .procname = "file-max",
1534 .data = &files_stat.max_files,
1535 .maxlen = sizeof(files_stat.max_files),
1536 .mode = 0644,
1537 .proc_handler = proc_doulongvec_minmax,
1540 .procname = "nr_open",
1541 .data = &sysctl_nr_open,
1542 .maxlen = sizeof(int),
1543 .mode = 0644,
1544 .proc_handler = proc_dointvec_minmax,
1545 .extra1 = &sysctl_nr_open_min,
1546 .extra2 = &sysctl_nr_open_max,
1549 .procname = "dentry-state",
1550 .data = &dentry_stat,
1551 .maxlen = 6*sizeof(long),
1552 .mode = 0444,
1553 .proc_handler = proc_nr_dentry,
1556 .procname = "overflowuid",
1557 .data = &fs_overflowuid,
1558 .maxlen = sizeof(int),
1559 .mode = 0644,
1560 .proc_handler = proc_dointvec_minmax,
1561 .extra1 = &minolduid,
1562 .extra2 = &maxolduid,
1565 .procname = "overflowgid",
1566 .data = &fs_overflowgid,
1567 .maxlen = sizeof(int),
1568 .mode = 0644,
1569 .proc_handler = proc_dointvec_minmax,
1570 .extra1 = &minolduid,
1571 .extra2 = &maxolduid,
1573 #ifdef CONFIG_FILE_LOCKING
1575 .procname = "leases-enable",
1576 .data = &leases_enable,
1577 .maxlen = sizeof(int),
1578 .mode = 0644,
1579 .proc_handler = proc_dointvec,
1581 #endif
1582 #ifdef CONFIG_DNOTIFY
1584 .procname = "dir-notify-enable",
1585 .data = &dir_notify_enable,
1586 .maxlen = sizeof(int),
1587 .mode = 0644,
1588 .proc_handler = proc_dointvec,
1590 #endif
1591 #ifdef CONFIG_MMU
1592 #ifdef CONFIG_FILE_LOCKING
1594 .procname = "lease-break-time",
1595 .data = &lease_break_time,
1596 .maxlen = sizeof(int),
1597 .mode = 0644,
1598 .proc_handler = proc_dointvec,
1600 #endif
1601 #ifdef CONFIG_AIO
1603 .procname = "aio-nr",
1604 .data = &aio_nr,
1605 .maxlen = sizeof(aio_nr),
1606 .mode = 0444,
1607 .proc_handler = proc_doulongvec_minmax,
1610 .procname = "aio-max-nr",
1611 .data = &aio_max_nr,
1612 .maxlen = sizeof(aio_max_nr),
1613 .mode = 0644,
1614 .proc_handler = proc_doulongvec_minmax,
1616 #endif /* CONFIG_AIO */
1617 #ifdef CONFIG_INOTIFY_USER
1619 .procname = "inotify",
1620 .mode = 0555,
1621 .child = inotify_table,
1623 #endif
1624 #ifdef CONFIG_EPOLL
1626 .procname = "epoll",
1627 .mode = 0555,
1628 .child = epoll_table,
1630 #endif
1631 #endif
1633 .procname = "protected_symlinks",
1634 .data = &sysctl_protected_symlinks,
1635 .maxlen = sizeof(int),
1636 .mode = 0600,
1637 .proc_handler = proc_dointvec_minmax,
1638 .extra1 = &zero,
1639 .extra2 = &one,
1642 .procname = "protected_hardlinks",
1643 .data = &sysctl_protected_hardlinks,
1644 .maxlen = sizeof(int),
1645 .mode = 0600,
1646 .proc_handler = proc_dointvec_minmax,
1647 .extra1 = &zero,
1648 .extra2 = &one,
1651 .procname = "suid_dumpable",
1652 .data = &suid_dumpable,
1653 .maxlen = sizeof(int),
1654 .mode = 0644,
1655 .proc_handler = proc_dointvec_minmax_coredump,
1656 .extra1 = &zero,
1657 .extra2 = &two,
1659 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1661 .procname = "binfmt_misc",
1662 .mode = 0555,
1663 .child = binfmt_misc_table,
1665 #endif
1667 .procname = "pipe-max-size",
1668 .data = &pipe_max_size,
1669 .maxlen = sizeof(int),
1670 .mode = 0644,
1671 .proc_handler = &pipe_proc_fn,
1672 .extra1 = &pipe_min_size,
1677 static struct ctl_table debug_table[] = {
1678 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1680 .procname = "exception-trace",
1681 .data = &show_unhandled_signals,
1682 .maxlen = sizeof(int),
1683 .mode = 0644,
1684 .proc_handler = proc_dointvec
1686 #endif
1687 #if defined(CONFIG_OPTPROBES)
1689 .procname = "kprobes-optimization",
1690 .data = &sysctl_kprobes_optimization,
1691 .maxlen = sizeof(int),
1692 .mode = 0644,
1693 .proc_handler = proc_kprobes_optimization_handler,
1694 .extra1 = &zero,
1695 .extra2 = &one,
1697 #endif
1701 static struct ctl_table dev_table[] = {
1705 int __init sysctl_init(void)
1707 struct ctl_table_header *hdr;
1709 hdr = register_sysctl_table(sysctl_base_table);
1710 kmemleak_not_leak(hdr);
1711 return 0;
1714 #endif /* CONFIG_SYSCTL */
1717 * /proc/sys support
1720 #ifdef CONFIG_PROC_SYSCTL
1722 static int _proc_do_string(char *data, int maxlen, int write,
1723 char __user *buffer,
1724 size_t *lenp, loff_t *ppos)
1726 size_t len;
1727 char __user *p;
1728 char c;
1730 if (!data || !maxlen || !*lenp) {
1731 *lenp = 0;
1732 return 0;
1735 if (write) {
1736 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1737 /* Only continue writes not past the end of buffer. */
1738 len = strlen(data);
1739 if (len > maxlen - 1)
1740 len = maxlen - 1;
1742 if (*ppos > len)
1743 return 0;
1744 len = *ppos;
1745 } else {
1746 /* Start writing from beginning of buffer. */
1747 len = 0;
1750 *ppos += *lenp;
1751 p = buffer;
1752 while ((p - buffer) < *lenp && len < maxlen - 1) {
1753 if (get_user(c, p++))
1754 return -EFAULT;
1755 if (c == 0 || c == '\n')
1756 break;
1757 data[len++] = c;
1759 data[len] = 0;
1760 } else {
1761 len = strlen(data);
1762 if (len > maxlen)
1763 len = maxlen;
1765 if (*ppos > len) {
1766 *lenp = 0;
1767 return 0;
1770 data += *ppos;
1771 len -= *ppos;
1773 if (len > *lenp)
1774 len = *lenp;
1775 if (len)
1776 if (copy_to_user(buffer, data, len))
1777 return -EFAULT;
1778 if (len < *lenp) {
1779 if (put_user('\n', buffer + len))
1780 return -EFAULT;
1781 len++;
1783 *lenp = len;
1784 *ppos += len;
1786 return 0;
1789 static void warn_sysctl_write(struct ctl_table *table)
1791 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1792 "This will not be supported in the future. To silence this\n"
1793 "warning, set kernel.sysctl_writes_strict = -1\n",
1794 current->comm, table->procname);
1798 * proc_dostring - read a string sysctl
1799 * @table: the sysctl table
1800 * @write: %TRUE if this is a write to the sysctl file
1801 * @buffer: the user buffer
1802 * @lenp: the size of the user buffer
1803 * @ppos: file position
1805 * Reads/writes a string from/to the user buffer. If the kernel
1806 * buffer provided is not large enough to hold the string, the
1807 * string is truncated. The copied string is %NULL-terminated.
1808 * If the string is being read by the user process, it is copied
1809 * and a newline '\n' is added. It is truncated if the buffer is
1810 * not large enough.
1812 * Returns 0 on success.
1814 int proc_dostring(struct ctl_table *table, int write,
1815 void __user *buffer, size_t *lenp, loff_t *ppos)
1817 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1818 warn_sysctl_write(table);
1820 return _proc_do_string((char *)(table->data), table->maxlen, write,
1821 (char __user *)buffer, lenp, ppos);
1824 static size_t proc_skip_spaces(char **buf)
1826 size_t ret;
1827 char *tmp = skip_spaces(*buf);
1828 ret = tmp - *buf;
1829 *buf = tmp;
1830 return ret;
1833 static void proc_skip_char(char **buf, size_t *size, const char v)
1835 while (*size) {
1836 if (**buf != v)
1837 break;
1838 (*size)--;
1839 (*buf)++;
1843 #define TMPBUFLEN 22
1845 * proc_get_long - reads an ASCII formatted integer from a user buffer
1847 * @buf: a kernel buffer
1848 * @size: size of the kernel buffer
1849 * @val: this is where the number will be stored
1850 * @neg: set to %TRUE if number is negative
1851 * @perm_tr: a vector which contains the allowed trailers
1852 * @perm_tr_len: size of the perm_tr vector
1853 * @tr: pointer to store the trailer character
1855 * In case of success %0 is returned and @buf and @size are updated with
1856 * the amount of bytes read. If @tr is non-NULL and a trailing
1857 * character exists (size is non-zero after returning from this
1858 * function), @tr is updated with the trailing character.
1860 static int proc_get_long(char **buf, size_t *size,
1861 unsigned long *val, bool *neg,
1862 const char *perm_tr, unsigned perm_tr_len, char *tr)
1864 int len;
1865 char *p, tmp[TMPBUFLEN];
1867 if (!*size)
1868 return -EINVAL;
1870 len = *size;
1871 if (len > TMPBUFLEN - 1)
1872 len = TMPBUFLEN - 1;
1874 memcpy(tmp, *buf, len);
1876 tmp[len] = 0;
1877 p = tmp;
1878 if (*p == '-' && *size > 1) {
1879 *neg = true;
1880 p++;
1881 } else
1882 *neg = false;
1883 if (!isdigit(*p))
1884 return -EINVAL;
1886 *val = simple_strtoul(p, &p, 0);
1888 len = p - tmp;
1890 /* We don't know if the next char is whitespace thus we may accept
1891 * invalid integers (e.g. 1234...a) or two integers instead of one
1892 * (e.g. 123...1). So lets not allow such large numbers. */
1893 if (len == TMPBUFLEN - 1)
1894 return -EINVAL;
1896 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1897 return -EINVAL;
1899 if (tr && (len < *size))
1900 *tr = *p;
1902 *buf += len;
1903 *size -= len;
1905 return 0;
1909 * proc_put_long - converts an integer to a decimal ASCII formatted string
1911 * @buf: the user buffer
1912 * @size: the size of the user buffer
1913 * @val: the integer to be converted
1914 * @neg: sign of the number, %TRUE for negative
1916 * In case of success %0 is returned and @buf and @size are updated with
1917 * the amount of bytes written.
1919 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1920 bool neg)
1922 int len;
1923 char tmp[TMPBUFLEN], *p = tmp;
1925 sprintf(p, "%s%lu", neg ? "-" : "", val);
1926 len = strlen(tmp);
1927 if (len > *size)
1928 len = *size;
1929 if (copy_to_user(*buf, tmp, len))
1930 return -EFAULT;
1931 *size -= len;
1932 *buf += len;
1933 return 0;
1935 #undef TMPBUFLEN
1937 static int proc_put_char(void __user **buf, size_t *size, char c)
1939 if (*size) {
1940 char __user **buffer = (char __user **)buf;
1941 if (put_user(c, *buffer))
1942 return -EFAULT;
1943 (*size)--, (*buffer)++;
1944 *buf = *buffer;
1946 return 0;
1949 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1950 int *valp,
1951 int write, void *data)
1953 if (write) {
1954 *valp = *negp ? -*lvalp : *lvalp;
1955 } else {
1956 int val = *valp;
1957 if (val < 0) {
1958 *negp = true;
1959 *lvalp = (unsigned long)-val;
1960 } else {
1961 *negp = false;
1962 *lvalp = (unsigned long)val;
1965 return 0;
1968 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1970 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1971 int write, void __user *buffer,
1972 size_t *lenp, loff_t *ppos,
1973 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1974 int write, void *data),
1975 void *data)
1977 int *i, vleft, first = 1, err = 0;
1978 unsigned long page = 0;
1979 size_t left;
1980 char *kbuf;
1982 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1983 *lenp = 0;
1984 return 0;
1987 i = (int *) tbl_data;
1988 vleft = table->maxlen / sizeof(*i);
1989 left = *lenp;
1991 if (!conv)
1992 conv = do_proc_dointvec_conv;
1994 if (write) {
1995 if (*ppos) {
1996 switch (sysctl_writes_strict) {
1997 case SYSCTL_WRITES_STRICT:
1998 goto out;
1999 case SYSCTL_WRITES_WARN:
2000 warn_sysctl_write(table);
2001 break;
2002 default:
2003 break;
2007 if (left > PAGE_SIZE - 1)
2008 left = PAGE_SIZE - 1;
2009 page = __get_free_page(GFP_TEMPORARY);
2010 kbuf = (char *) page;
2011 if (!kbuf)
2012 return -ENOMEM;
2013 if (copy_from_user(kbuf, buffer, left)) {
2014 err = -EFAULT;
2015 goto free;
2017 kbuf[left] = 0;
2020 for (; left && vleft--; i++, first=0) {
2021 unsigned long lval;
2022 bool neg;
2024 if (write) {
2025 left -= proc_skip_spaces(&kbuf);
2027 if (!left)
2028 break;
2029 err = proc_get_long(&kbuf, &left, &lval, &neg,
2030 proc_wspace_sep,
2031 sizeof(proc_wspace_sep), NULL);
2032 if (err)
2033 break;
2034 if (conv(&neg, &lval, i, 1, data)) {
2035 err = -EINVAL;
2036 break;
2038 } else {
2039 if (conv(&neg, &lval, i, 0, data)) {
2040 err = -EINVAL;
2041 break;
2043 if (!first)
2044 err = proc_put_char(&buffer, &left, '\t');
2045 if (err)
2046 break;
2047 err = proc_put_long(&buffer, &left, lval, neg);
2048 if (err)
2049 break;
2053 if (!write && !first && left && !err)
2054 err = proc_put_char(&buffer, &left, '\n');
2055 if (write && !err && left)
2056 left -= proc_skip_spaces(&kbuf);
2057 free:
2058 if (write) {
2059 free_page(page);
2060 if (first)
2061 return err ? : -EINVAL;
2063 *lenp -= left;
2064 out:
2065 *ppos += *lenp;
2066 return err;
2069 static int do_proc_dointvec(struct ctl_table *table, int write,
2070 void __user *buffer, size_t *lenp, loff_t *ppos,
2071 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2072 int write, void *data),
2073 void *data)
2075 return __do_proc_dointvec(table->data, table, write,
2076 buffer, lenp, ppos, conv, data);
2080 * proc_dointvec - read a vector of integers
2081 * @table: the sysctl table
2082 * @write: %TRUE if this is a write to the sysctl file
2083 * @buffer: the user buffer
2084 * @lenp: the size of the user buffer
2085 * @ppos: file position
2087 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2088 * values from/to the user buffer, treated as an ASCII string.
2090 * Returns 0 on success.
2092 int proc_dointvec(struct ctl_table *table, int write,
2093 void __user *buffer, size_t *lenp, loff_t *ppos)
2095 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2096 NULL,NULL);
2100 * Taint values can only be increased
2101 * This means we can safely use a temporary.
2103 static int proc_taint(struct ctl_table *table, int write,
2104 void __user *buffer, size_t *lenp, loff_t *ppos)
2106 struct ctl_table t;
2107 unsigned long tmptaint = get_taint();
2108 int err;
2110 if (write && !capable(CAP_SYS_ADMIN))
2111 return -EPERM;
2113 t = *table;
2114 t.data = &tmptaint;
2115 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2116 if (err < 0)
2117 return err;
2119 if (write) {
2121 * Poor man's atomic or. Not worth adding a primitive
2122 * to everyone's atomic.h for this
2124 int i;
2125 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2126 if ((tmptaint >> i) & 1)
2127 add_taint(i, LOCKDEP_STILL_OK);
2131 return err;
2134 #ifdef CONFIG_PRINTK
2135 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2136 void __user *buffer, size_t *lenp, loff_t *ppos)
2138 if (write && !capable(CAP_SYS_ADMIN))
2139 return -EPERM;
2141 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2143 #endif
2145 struct do_proc_dointvec_minmax_conv_param {
2146 int *min;
2147 int *max;
2150 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2151 int *valp,
2152 int write, void *data)
2154 struct do_proc_dointvec_minmax_conv_param *param = data;
2155 if (write) {
2156 int val = *negp ? -*lvalp : *lvalp;
2157 if ((param->min && *param->min > val) ||
2158 (param->max && *param->max < val))
2159 return -EINVAL;
2160 *valp = val;
2161 } else {
2162 int val = *valp;
2163 if (val < 0) {
2164 *negp = true;
2165 *lvalp = (unsigned long)-val;
2166 } else {
2167 *negp = false;
2168 *lvalp = (unsigned long)val;
2171 return 0;
2175 * proc_dointvec_minmax - read a vector of integers with min/max values
2176 * @table: the sysctl table
2177 * @write: %TRUE if this is a write to the sysctl file
2178 * @buffer: the user buffer
2179 * @lenp: the size of the user buffer
2180 * @ppos: file position
2182 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2183 * values from/to the user buffer, treated as an ASCII string.
2185 * This routine will ensure the values are within the range specified by
2186 * table->extra1 (min) and table->extra2 (max).
2188 * Returns 0 on success.
2190 int proc_dointvec_minmax(struct ctl_table *table, int write,
2191 void __user *buffer, size_t *lenp, loff_t *ppos)
2193 struct do_proc_dointvec_minmax_conv_param param = {
2194 .min = (int *) table->extra1,
2195 .max = (int *) table->extra2,
2197 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2198 do_proc_dointvec_minmax_conv, &param);
2201 static void validate_coredump_safety(void)
2203 #ifdef CONFIG_COREDUMP
2204 if (suid_dumpable == SUID_DUMP_ROOT &&
2205 core_pattern[0] != '/' && core_pattern[0] != '|') {
2206 printk(KERN_WARNING "Unsafe core_pattern used with "\
2207 "suid_dumpable=2. Pipe handler or fully qualified "\
2208 "core dump path required.\n");
2210 #endif
2213 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2214 void __user *buffer, size_t *lenp, loff_t *ppos)
2216 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2217 if (!error)
2218 validate_coredump_safety();
2219 return error;
2222 #ifdef CONFIG_COREDUMP
2223 static int proc_dostring_coredump(struct ctl_table *table, int write,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2226 int error = proc_dostring(table, write, buffer, lenp, ppos);
2227 if (!error)
2228 validate_coredump_safety();
2229 return error;
2231 #endif
2233 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2234 void __user *buffer,
2235 size_t *lenp, loff_t *ppos,
2236 unsigned long convmul,
2237 unsigned long convdiv)
2239 unsigned long *i, *min, *max;
2240 int vleft, first = 1, err = 0;
2241 unsigned long page = 0;
2242 size_t left;
2243 char *kbuf;
2245 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2246 *lenp = 0;
2247 return 0;
2250 i = (unsigned long *) data;
2251 min = (unsigned long *) table->extra1;
2252 max = (unsigned long *) table->extra2;
2253 vleft = table->maxlen / sizeof(unsigned long);
2254 left = *lenp;
2256 if (write) {
2257 if (*ppos) {
2258 switch (sysctl_writes_strict) {
2259 case SYSCTL_WRITES_STRICT:
2260 goto out;
2261 case SYSCTL_WRITES_WARN:
2262 warn_sysctl_write(table);
2263 break;
2264 default:
2265 break;
2269 if (left > PAGE_SIZE - 1)
2270 left = PAGE_SIZE - 1;
2271 page = __get_free_page(GFP_TEMPORARY);
2272 kbuf = (char *) page;
2273 if (!kbuf)
2274 return -ENOMEM;
2275 if (copy_from_user(kbuf, buffer, left)) {
2276 err = -EFAULT;
2277 goto free;
2279 kbuf[left] = 0;
2282 for (; left && vleft--; i++, first = 0) {
2283 unsigned long val;
2285 if (write) {
2286 bool neg;
2288 left -= proc_skip_spaces(&kbuf);
2290 err = proc_get_long(&kbuf, &left, &val, &neg,
2291 proc_wspace_sep,
2292 sizeof(proc_wspace_sep), NULL);
2293 if (err)
2294 break;
2295 if (neg)
2296 continue;
2297 if ((min && val < *min) || (max && val > *max))
2298 continue;
2299 *i = val;
2300 } else {
2301 val = convdiv * (*i) / convmul;
2302 if (!first) {
2303 err = proc_put_char(&buffer, &left, '\t');
2304 if (err)
2305 break;
2307 err = proc_put_long(&buffer, &left, val, false);
2308 if (err)
2309 break;
2313 if (!write && !first && left && !err)
2314 err = proc_put_char(&buffer, &left, '\n');
2315 if (write && !err)
2316 left -= proc_skip_spaces(&kbuf);
2317 free:
2318 if (write) {
2319 free_page(page);
2320 if (first)
2321 return err ? : -EINVAL;
2323 *lenp -= left;
2324 out:
2325 *ppos += *lenp;
2326 return err;
2329 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2330 void __user *buffer,
2331 size_t *lenp, loff_t *ppos,
2332 unsigned long convmul,
2333 unsigned long convdiv)
2335 return __do_proc_doulongvec_minmax(table->data, table, write,
2336 buffer, lenp, ppos, convmul, convdiv);
2340 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2341 * @table: the sysctl table
2342 * @write: %TRUE if this is a write to the sysctl file
2343 * @buffer: the user buffer
2344 * @lenp: the size of the user buffer
2345 * @ppos: file position
2347 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2348 * values from/to the user buffer, treated as an ASCII string.
2350 * This routine will ensure the values are within the range specified by
2351 * table->extra1 (min) and table->extra2 (max).
2353 * Returns 0 on success.
2355 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2356 void __user *buffer, size_t *lenp, loff_t *ppos)
2358 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2362 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2363 * @table: the sysctl table
2364 * @write: %TRUE if this is a write to the sysctl file
2365 * @buffer: the user buffer
2366 * @lenp: the size of the user buffer
2367 * @ppos: file position
2369 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2370 * values from/to the user buffer, treated as an ASCII string. The values
2371 * are treated as milliseconds, and converted to jiffies when they are stored.
2373 * This routine will ensure the values are within the range specified by
2374 * table->extra1 (min) and table->extra2 (max).
2376 * Returns 0 on success.
2378 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2379 void __user *buffer,
2380 size_t *lenp, loff_t *ppos)
2382 return do_proc_doulongvec_minmax(table, write, buffer,
2383 lenp, ppos, HZ, 1000l);
2387 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2388 int *valp,
2389 int write, void *data)
2391 if (write) {
2392 if (*lvalp > LONG_MAX / HZ)
2393 return 1;
2394 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2395 } else {
2396 int val = *valp;
2397 unsigned long lval;
2398 if (val < 0) {
2399 *negp = true;
2400 lval = (unsigned long)-val;
2401 } else {
2402 *negp = false;
2403 lval = (unsigned long)val;
2405 *lvalp = lval / HZ;
2407 return 0;
2410 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2411 int *valp,
2412 int write, void *data)
2414 if (write) {
2415 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2416 return 1;
2417 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2418 } else {
2419 int val = *valp;
2420 unsigned long lval;
2421 if (val < 0) {
2422 *negp = true;
2423 lval = (unsigned long)-val;
2424 } else {
2425 *negp = false;
2426 lval = (unsigned long)val;
2428 *lvalp = jiffies_to_clock_t(lval);
2430 return 0;
2433 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2434 int *valp,
2435 int write, void *data)
2437 if (write) {
2438 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2440 if (jif > INT_MAX)
2441 return 1;
2442 *valp = (int)jif;
2443 } else {
2444 int val = *valp;
2445 unsigned long lval;
2446 if (val < 0) {
2447 *negp = true;
2448 lval = (unsigned long)-val;
2449 } else {
2450 *negp = false;
2451 lval = (unsigned long)val;
2453 *lvalp = jiffies_to_msecs(lval);
2455 return 0;
2459 * proc_dointvec_jiffies - read a vector of integers as seconds
2460 * @table: the sysctl table
2461 * @write: %TRUE if this is a write to the sysctl file
2462 * @buffer: the user buffer
2463 * @lenp: the size of the user buffer
2464 * @ppos: file position
2466 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2467 * values from/to the user buffer, treated as an ASCII string.
2468 * The values read are assumed to be in seconds, and are converted into
2469 * jiffies.
2471 * Returns 0 on success.
2473 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2474 void __user *buffer, size_t *lenp, loff_t *ppos)
2476 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2477 do_proc_dointvec_jiffies_conv,NULL);
2481 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
2484 * @buffer: the user buffer
2485 * @lenp: the size of the user buffer
2486 * @ppos: pointer to the file position
2488 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2489 * values from/to the user buffer, treated as an ASCII string.
2490 * The values read are assumed to be in 1/USER_HZ seconds, and
2491 * are converted into jiffies.
2493 * Returns 0 on success.
2495 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2496 void __user *buffer, size_t *lenp, loff_t *ppos)
2498 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2499 do_proc_dointvec_userhz_jiffies_conv,NULL);
2503 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2504 * @table: the sysctl table
2505 * @write: %TRUE if this is a write to the sysctl file
2506 * @buffer: the user buffer
2507 * @lenp: the size of the user buffer
2508 * @ppos: file position
2509 * @ppos: the current position in the file
2511 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2512 * values from/to the user buffer, treated as an ASCII string.
2513 * The values read are assumed to be in 1/1000 seconds, and
2514 * are converted into jiffies.
2516 * Returns 0 on success.
2518 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2519 void __user *buffer, size_t *lenp, loff_t *ppos)
2521 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2522 do_proc_dointvec_ms_jiffies_conv, NULL);
2525 static int proc_do_cad_pid(struct ctl_table *table, int write,
2526 void __user *buffer, size_t *lenp, loff_t *ppos)
2528 struct pid *new_pid;
2529 pid_t tmp;
2530 int r;
2532 tmp = pid_vnr(cad_pid);
2534 r = __do_proc_dointvec(&tmp, table, write, buffer,
2535 lenp, ppos, NULL, NULL);
2536 if (r || !write)
2537 return r;
2539 new_pid = find_get_pid(tmp);
2540 if (!new_pid)
2541 return -ESRCH;
2543 put_pid(xchg(&cad_pid, new_pid));
2544 return 0;
2548 * proc_do_large_bitmap - read/write from/to a large bitmap
2549 * @table: the sysctl table
2550 * @write: %TRUE if this is a write to the sysctl file
2551 * @buffer: the user buffer
2552 * @lenp: the size of the user buffer
2553 * @ppos: file position
2555 * The bitmap is stored at table->data and the bitmap length (in bits)
2556 * in table->maxlen.
2558 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2559 * large bitmaps may be represented in a compact manner. Writing into
2560 * the file will clear the bitmap then update it with the given input.
2562 * Returns 0 on success.
2564 int proc_do_large_bitmap(struct ctl_table *table, int write,
2565 void __user *buffer, size_t *lenp, loff_t *ppos)
2567 int err = 0;
2568 bool first = 1;
2569 size_t left = *lenp;
2570 unsigned long bitmap_len = table->maxlen;
2571 unsigned long *bitmap = (unsigned long *) table->data;
2572 unsigned long *tmp_bitmap = NULL;
2573 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2575 if (!bitmap_len || !left || (*ppos && !write)) {
2576 *lenp = 0;
2577 return 0;
2580 if (write) {
2581 unsigned long page = 0;
2582 char *kbuf;
2584 if (left > PAGE_SIZE - 1)
2585 left = PAGE_SIZE - 1;
2587 page = __get_free_page(GFP_TEMPORARY);
2588 kbuf = (char *) page;
2589 if (!kbuf)
2590 return -ENOMEM;
2591 if (copy_from_user(kbuf, buffer, left)) {
2592 free_page(page);
2593 return -EFAULT;
2595 kbuf[left] = 0;
2597 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2598 GFP_KERNEL);
2599 if (!tmp_bitmap) {
2600 free_page(page);
2601 return -ENOMEM;
2603 proc_skip_char(&kbuf, &left, '\n');
2604 while (!err && left) {
2605 unsigned long val_a, val_b;
2606 bool neg;
2608 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2609 sizeof(tr_a), &c);
2610 if (err)
2611 break;
2612 if (val_a >= bitmap_len || neg) {
2613 err = -EINVAL;
2614 break;
2617 val_b = val_a;
2618 if (left) {
2619 kbuf++;
2620 left--;
2623 if (c == '-') {
2624 err = proc_get_long(&kbuf, &left, &val_b,
2625 &neg, tr_b, sizeof(tr_b),
2626 &c);
2627 if (err)
2628 break;
2629 if (val_b >= bitmap_len || neg ||
2630 val_a > val_b) {
2631 err = -EINVAL;
2632 break;
2634 if (left) {
2635 kbuf++;
2636 left--;
2640 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2641 first = 0;
2642 proc_skip_char(&kbuf, &left, '\n');
2644 free_page(page);
2645 } else {
2646 unsigned long bit_a, bit_b = 0;
2648 while (left) {
2649 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2650 if (bit_a >= bitmap_len)
2651 break;
2652 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2653 bit_a + 1) - 1;
2655 if (!first) {
2656 err = proc_put_char(&buffer, &left, ',');
2657 if (err)
2658 break;
2660 err = proc_put_long(&buffer, &left, bit_a, false);
2661 if (err)
2662 break;
2663 if (bit_a != bit_b) {
2664 err = proc_put_char(&buffer, &left, '-');
2665 if (err)
2666 break;
2667 err = proc_put_long(&buffer, &left, bit_b, false);
2668 if (err)
2669 break;
2672 first = 0; bit_b++;
2674 if (!err)
2675 err = proc_put_char(&buffer, &left, '\n');
2678 if (!err) {
2679 if (write) {
2680 if (*ppos)
2681 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2682 else
2683 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2685 kfree(tmp_bitmap);
2686 *lenp -= left;
2687 *ppos += *lenp;
2688 return 0;
2689 } else {
2690 kfree(tmp_bitmap);
2691 return err;
2695 #else /* CONFIG_PROC_SYSCTL */
2697 int proc_dostring(struct ctl_table *table, int write,
2698 void __user *buffer, size_t *lenp, loff_t *ppos)
2700 return -ENOSYS;
2703 int proc_dointvec(struct ctl_table *table, int write,
2704 void __user *buffer, size_t *lenp, loff_t *ppos)
2706 return -ENOSYS;
2709 int proc_dointvec_minmax(struct ctl_table *table, int write,
2710 void __user *buffer, size_t *lenp, loff_t *ppos)
2712 return -ENOSYS;
2715 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2716 void __user *buffer, size_t *lenp, loff_t *ppos)
2718 return -ENOSYS;
2721 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2722 void __user *buffer, size_t *lenp, loff_t *ppos)
2724 return -ENOSYS;
2727 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2728 void __user *buffer, size_t *lenp, loff_t *ppos)
2730 return -ENOSYS;
2733 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2734 void __user *buffer, size_t *lenp, loff_t *ppos)
2736 return -ENOSYS;
2739 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2740 void __user *buffer,
2741 size_t *lenp, loff_t *ppos)
2743 return -ENOSYS;
2747 #endif /* CONFIG_PROC_SYSCTL */
2750 * No sense putting this after each symbol definition, twice,
2751 * exception granted :-)
2753 EXPORT_SYMBOL(proc_dointvec);
2754 EXPORT_SYMBOL(proc_dointvec_jiffies);
2755 EXPORT_SYMBOL(proc_dointvec_minmax);
2756 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2757 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2758 EXPORT_SYMBOL(proc_dostring);
2759 EXPORT_SYMBOL(proc_doulongvec_minmax);
2760 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);