x86/xen: resume timer irqs early
[linux/fpc-iii.git] / kernel / sysctl.c
blob1677410036160565332f8296bb39fe61c2789703
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>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
69 #ifdef CONFIG_X86
70 #include <asm/nmi.h>
71 #include <asm/stacktrace.h>
72 #include <asm/io.h>
73 #endif
74 #ifdef CONFIG_SPARC
75 #include <asm/setup.h>
76 #endif
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
79 #endif
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
82 #endif
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
85 #endif
86 #ifdef CONFIG_CHR_DEV_SG
87 #include <scsi/sg.h>
88 #endif
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
92 #endif
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory;
99 extern int sysctl_overcommit_ratio;
100 extern int max_threads;
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
116 #ifdef CONFIG_BLOCK
117 extern int blk_iopoll_enabled;
118 #endif
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty = 60;
123 #endif
125 static int zero;
126 static int __maybe_unused one = 1;
127 static int __maybe_unused two = 2;
128 static int __maybe_unused three = 3;
129 static unsigned long one_ul = 1;
130 static int one_hundred = 100;
131 #ifdef CONFIG_PRINTK
132 static int ten_thousand = 10000;
133 #endif
135 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
136 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
138 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
139 static int maxolduid = 65535;
140 static int minolduid;
142 static int ngroups_max = NGROUPS_MAX;
143 static const int cap_last_cap = CAP_LAST_CAP;
145 #ifdef CONFIG_INOTIFY_USER
146 #include <linux/inotify.h>
147 #endif
148 #ifdef CONFIG_SPARC
149 #endif
151 #ifdef CONFIG_SPARC64
152 extern int sysctl_tsb_ratio;
153 #endif
155 #ifdef __hppa__
156 extern int pwrsw_enabled;
157 #endif
159 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
160 extern int unaligned_enabled;
161 #endif
163 #ifdef CONFIG_IA64
164 extern int unaligned_dump_stack;
165 #endif
167 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168 extern int no_unaligned_warning;
169 #endif
171 #ifdef CONFIG_PROC_SYSCTL
172 static int proc_do_cad_pid(struct ctl_table *table, int write,
173 void __user *buffer, size_t *lenp, loff_t *ppos);
174 static int proc_taint(struct ctl_table *table, int write,
175 void __user *buffer, size_t *lenp, loff_t *ppos);
176 #endif
178 #ifdef CONFIG_PRINTK
179 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
180 void __user *buffer, size_t *lenp, loff_t *ppos);
181 #endif
183 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
185 #ifdef CONFIG_COREDUMP
186 static int proc_dostring_coredump(struct ctl_table *table, int write,
187 void __user *buffer, size_t *lenp, loff_t *ppos);
188 #endif
190 #ifdef CONFIG_MAGIC_SYSRQ
191 /* Note: sysrq code uses it's own private copy */
192 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
194 static int sysrq_sysctl_handler(ctl_table *table, int write,
195 void __user *buffer, size_t *lenp,
196 loff_t *ppos)
198 int error;
200 error = proc_dointvec(table, write, buffer, lenp, ppos);
201 if (error)
202 return error;
204 if (write)
205 sysrq_toggle_support(__sysrq_enabled);
207 return 0;
210 #endif
212 static struct ctl_table kern_table[];
213 static struct ctl_table vm_table[];
214 static struct ctl_table fs_table[];
215 static struct ctl_table debug_table[];
216 static struct ctl_table dev_table[];
217 extern struct ctl_table random_table[];
218 #ifdef CONFIG_EPOLL
219 extern struct ctl_table epoll_table[];
220 #endif
222 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
223 int sysctl_legacy_va_layout;
224 #endif
226 /* The default sysctl tables: */
228 static struct ctl_table sysctl_base_table[] = {
230 .procname = "kernel",
231 .mode = 0555,
232 .child = kern_table,
235 .procname = "vm",
236 .mode = 0555,
237 .child = vm_table,
240 .procname = "fs",
241 .mode = 0555,
242 .child = fs_table,
245 .procname = "debug",
246 .mode = 0555,
247 .child = debug_table,
250 .procname = "dev",
251 .mode = 0555,
252 .child = dev_table,
257 #ifdef CONFIG_SCHED_DEBUG
258 static int min_sched_granularity_ns = 100000; /* 100 usecs */
259 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
260 static int min_wakeup_granularity_ns; /* 0 usecs */
261 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
262 #ifdef CONFIG_SMP
263 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
264 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
265 #endif /* CONFIG_SMP */
266 #endif /* CONFIG_SCHED_DEBUG */
268 #ifdef CONFIG_COMPACTION
269 static int min_extfrag_threshold;
270 static int max_extfrag_threshold = 1000;
271 #endif
273 static struct ctl_table kern_table[] = {
275 .procname = "sched_child_runs_first",
276 .data = &sysctl_sched_child_runs_first,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
279 .proc_handler = proc_dointvec,
281 #ifdef CONFIG_SCHED_DEBUG
283 .procname = "sched_min_granularity_ns",
284 .data = &sysctl_sched_min_granularity,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = sched_proc_update_handler,
288 .extra1 = &min_sched_granularity_ns,
289 .extra2 = &max_sched_granularity_ns,
292 .procname = "sched_latency_ns",
293 .data = &sysctl_sched_latency,
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_wakeup_granularity_ns",
302 .data = &sysctl_sched_wakeup_granularity,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = sched_proc_update_handler,
306 .extra1 = &min_wakeup_granularity_ns,
307 .extra2 = &max_wakeup_granularity_ns,
309 #ifdef CONFIG_SMP
311 .procname = "sched_tunable_scaling",
312 .data = &sysctl_sched_tunable_scaling,
313 .maxlen = sizeof(enum sched_tunable_scaling),
314 .mode = 0644,
315 .proc_handler = sched_proc_update_handler,
316 .extra1 = &min_sched_tunable_scaling,
317 .extra2 = &max_sched_tunable_scaling,
320 .procname = "sched_migration_cost_ns",
321 .data = &sysctl_sched_migration_cost,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
324 .proc_handler = proc_dointvec,
327 .procname = "sched_nr_migrate",
328 .data = &sysctl_sched_nr_migrate,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec,
334 .procname = "sched_time_avg_ms",
335 .data = &sysctl_sched_time_avg,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec,
341 .procname = "sched_shares_window_ns",
342 .data = &sysctl_sched_shares_window,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = proc_dointvec,
348 .procname = "timer_migration",
349 .data = &sysctl_timer_migration,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = proc_dointvec_minmax,
353 .extra1 = &zero,
354 .extra2 = &one,
356 #endif /* CONFIG_SMP */
357 #ifdef CONFIG_NUMA_BALANCING
359 .procname = "numa_balancing_scan_delay_ms",
360 .data = &sysctl_numa_balancing_scan_delay,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
363 .proc_handler = proc_dointvec,
366 .procname = "numa_balancing_scan_period_min_ms",
367 .data = &sysctl_numa_balancing_scan_period_min,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
370 .proc_handler = proc_dointvec,
373 .procname = "numa_balancing_scan_period_reset",
374 .data = &sysctl_numa_balancing_scan_period_reset,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
377 .proc_handler = proc_dointvec,
380 .procname = "numa_balancing_scan_period_max_ms",
381 .data = &sysctl_numa_balancing_scan_period_max,
382 .maxlen = sizeof(unsigned int),
383 .mode = 0644,
384 .proc_handler = proc_dointvec,
387 .procname = "numa_balancing_scan_size_mb",
388 .data = &sysctl_numa_balancing_scan_size,
389 .maxlen = sizeof(unsigned int),
390 .mode = 0644,
391 .proc_handler = proc_dointvec,
393 #endif /* CONFIG_NUMA_BALANCING */
394 #endif /* CONFIG_SCHED_DEBUG */
396 .procname = "sched_rt_period_us",
397 .data = &sysctl_sched_rt_period,
398 .maxlen = sizeof(unsigned int),
399 .mode = 0644,
400 .proc_handler = sched_rt_handler,
403 .procname = "sched_rt_runtime_us",
404 .data = &sysctl_sched_rt_runtime,
405 .maxlen = sizeof(int),
406 .mode = 0644,
407 .proc_handler = sched_rt_handler,
410 .procname = "sched_rr_timeslice_ms",
411 .data = &sched_rr_timeslice,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = sched_rr_handler,
416 #ifdef CONFIG_SCHED_AUTOGROUP
418 .procname = "sched_autogroup_enabled",
419 .data = &sysctl_sched_autogroup_enabled,
420 .maxlen = sizeof(unsigned int),
421 .mode = 0644,
422 .proc_handler = proc_dointvec_minmax,
423 .extra1 = &zero,
424 .extra2 = &one,
426 #endif
427 #ifdef CONFIG_CFS_BANDWIDTH
429 .procname = "sched_cfs_bandwidth_slice_us",
430 .data = &sysctl_sched_cfs_bandwidth_slice,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
433 .proc_handler = proc_dointvec_minmax,
434 .extra1 = &one,
436 #endif
437 #ifdef CONFIG_PROVE_LOCKING
439 .procname = "prove_locking",
440 .data = &prove_locking,
441 .maxlen = sizeof(int),
442 .mode = 0644,
443 .proc_handler = proc_dointvec,
445 #endif
446 #ifdef CONFIG_LOCK_STAT
448 .procname = "lock_stat",
449 .data = &lock_stat,
450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = proc_dointvec,
454 #endif
456 .procname = "panic",
457 .data = &panic_timeout,
458 .maxlen = sizeof(int),
459 .mode = 0644,
460 .proc_handler = proc_dointvec,
462 #ifdef CONFIG_COREDUMP
464 .procname = "core_uses_pid",
465 .data = &core_uses_pid,
466 .maxlen = sizeof(int),
467 .mode = 0644,
468 .proc_handler = proc_dointvec,
471 .procname = "core_pattern",
472 .data = core_pattern,
473 .maxlen = CORENAME_MAX_SIZE,
474 .mode = 0644,
475 .proc_handler = proc_dostring_coredump,
478 .procname = "core_pipe_limit",
479 .data = &core_pipe_limit,
480 .maxlen = sizeof(unsigned int),
481 .mode = 0644,
482 .proc_handler = proc_dointvec,
484 #endif
485 #ifdef CONFIG_PROC_SYSCTL
487 .procname = "tainted",
488 .maxlen = sizeof(long),
489 .mode = 0644,
490 .proc_handler = proc_taint,
492 #endif
493 #ifdef CONFIG_LATENCYTOP
495 .procname = "latencytop",
496 .data = &latencytop_enabled,
497 .maxlen = sizeof(int),
498 .mode = 0644,
499 .proc_handler = proc_dointvec,
501 #endif
502 #ifdef CONFIG_BLK_DEV_INITRD
504 .procname = "real-root-dev",
505 .data = &real_root_dev,
506 .maxlen = sizeof(int),
507 .mode = 0644,
508 .proc_handler = proc_dointvec,
510 #endif
512 .procname = "print-fatal-signals",
513 .data = &print_fatal_signals,
514 .maxlen = sizeof(int),
515 .mode = 0644,
516 .proc_handler = proc_dointvec,
518 #ifdef CONFIG_SPARC
520 .procname = "reboot-cmd",
521 .data = reboot_command,
522 .maxlen = 256,
523 .mode = 0644,
524 .proc_handler = proc_dostring,
527 .procname = "stop-a",
528 .data = &stop_a_enabled,
529 .maxlen = sizeof (int),
530 .mode = 0644,
531 .proc_handler = proc_dointvec,
534 .procname = "scons-poweroff",
535 .data = &scons_pwroff,
536 .maxlen = sizeof (int),
537 .mode = 0644,
538 .proc_handler = proc_dointvec,
540 #endif
541 #ifdef CONFIG_SPARC64
543 .procname = "tsb-ratio",
544 .data = &sysctl_tsb_ratio,
545 .maxlen = sizeof (int),
546 .mode = 0644,
547 .proc_handler = proc_dointvec,
549 #endif
550 #ifdef __hppa__
552 .procname = "soft-power",
553 .data = &pwrsw_enabled,
554 .maxlen = sizeof (int),
555 .mode = 0644,
556 .proc_handler = proc_dointvec,
558 #endif
559 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
561 .procname = "unaligned-trap",
562 .data = &unaligned_enabled,
563 .maxlen = sizeof (int),
564 .mode = 0644,
565 .proc_handler = proc_dointvec,
567 #endif
569 .procname = "ctrl-alt-del",
570 .data = &C_A_D,
571 .maxlen = sizeof(int),
572 .mode = 0644,
573 .proc_handler = proc_dointvec,
575 #ifdef CONFIG_FUNCTION_TRACER
577 .procname = "ftrace_enabled",
578 .data = &ftrace_enabled,
579 .maxlen = sizeof(int),
580 .mode = 0644,
581 .proc_handler = ftrace_enable_sysctl,
583 #endif
584 #ifdef CONFIG_STACK_TRACER
586 .procname = "stack_tracer_enabled",
587 .data = &stack_tracer_enabled,
588 .maxlen = sizeof(int),
589 .mode = 0644,
590 .proc_handler = stack_trace_sysctl,
592 #endif
593 #ifdef CONFIG_TRACING
595 .procname = "ftrace_dump_on_oops",
596 .data = &ftrace_dump_on_oops,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = proc_dointvec,
602 .procname = "traceoff_on_warning",
603 .data = &__disable_trace_on_warning,
604 .maxlen = sizeof(__disable_trace_on_warning),
605 .mode = 0644,
606 .proc_handler = proc_dointvec,
608 #endif
609 #ifdef CONFIG_MODULES
611 .procname = "modprobe",
612 .data = &modprobe_path,
613 .maxlen = KMOD_PATH_LEN,
614 .mode = 0644,
615 .proc_handler = proc_dostring,
618 .procname = "modules_disabled",
619 .data = &modules_disabled,
620 .maxlen = sizeof(int),
621 .mode = 0644,
622 /* only handle a transition from default "0" to "1" */
623 .proc_handler = proc_dointvec_minmax,
624 .extra1 = &one,
625 .extra2 = &one,
627 #endif
630 .procname = "hotplug",
631 .data = &uevent_helper,
632 .maxlen = UEVENT_HELPER_PATH_LEN,
633 .mode = 0644,
634 .proc_handler = proc_dostring,
637 #ifdef CONFIG_CHR_DEV_SG
639 .procname = "sg-big-buff",
640 .data = &sg_big_buff,
641 .maxlen = sizeof (int),
642 .mode = 0444,
643 .proc_handler = proc_dointvec,
645 #endif
646 #ifdef CONFIG_BSD_PROCESS_ACCT
648 .procname = "acct",
649 .data = &acct_parm,
650 .maxlen = 3*sizeof(int),
651 .mode = 0644,
652 .proc_handler = proc_dointvec,
654 #endif
655 #ifdef CONFIG_MAGIC_SYSRQ
657 .procname = "sysrq",
658 .data = &__sysrq_enabled,
659 .maxlen = sizeof (int),
660 .mode = 0644,
661 .proc_handler = sysrq_sysctl_handler,
663 #endif
664 #ifdef CONFIG_PROC_SYSCTL
666 .procname = "cad_pid",
667 .data = NULL,
668 .maxlen = sizeof (int),
669 .mode = 0600,
670 .proc_handler = proc_do_cad_pid,
672 #endif
674 .procname = "threads-max",
675 .data = &max_threads,
676 .maxlen = sizeof(int),
677 .mode = 0644,
678 .proc_handler = proc_dointvec,
681 .procname = "random",
682 .mode = 0555,
683 .child = random_table,
686 .procname = "usermodehelper",
687 .mode = 0555,
688 .child = usermodehelper_table,
691 .procname = "overflowuid",
692 .data = &overflowuid,
693 .maxlen = sizeof(int),
694 .mode = 0644,
695 .proc_handler = proc_dointvec_minmax,
696 .extra1 = &minolduid,
697 .extra2 = &maxolduid,
700 .procname = "overflowgid",
701 .data = &overflowgid,
702 .maxlen = sizeof(int),
703 .mode = 0644,
704 .proc_handler = proc_dointvec_minmax,
705 .extra1 = &minolduid,
706 .extra2 = &maxolduid,
708 #ifdef CONFIG_S390
709 #ifdef CONFIG_MATHEMU
711 .procname = "ieee_emulation_warnings",
712 .data = &sysctl_ieee_emulation_warnings,
713 .maxlen = sizeof(int),
714 .mode = 0644,
715 .proc_handler = proc_dointvec,
717 #endif
719 .procname = "userprocess_debug",
720 .data = &show_unhandled_signals,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = proc_dointvec,
725 #endif
727 .procname = "pid_max",
728 .data = &pid_max,
729 .maxlen = sizeof (int),
730 .mode = 0644,
731 .proc_handler = proc_dointvec_minmax,
732 .extra1 = &pid_max_min,
733 .extra2 = &pid_max_max,
736 .procname = "panic_on_oops",
737 .data = &panic_on_oops,
738 .maxlen = sizeof(int),
739 .mode = 0644,
740 .proc_handler = proc_dointvec,
742 #if defined CONFIG_PRINTK
744 .procname = "printk",
745 .data = &console_loglevel,
746 .maxlen = 4*sizeof(int),
747 .mode = 0644,
748 .proc_handler = proc_dointvec,
751 .procname = "printk_ratelimit",
752 .data = &printk_ratelimit_state.interval,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = proc_dointvec_jiffies,
758 .procname = "printk_ratelimit_burst",
759 .data = &printk_ratelimit_state.burst,
760 .maxlen = sizeof(int),
761 .mode = 0644,
762 .proc_handler = proc_dointvec,
765 .procname = "printk_delay",
766 .data = &printk_delay_msec,
767 .maxlen = sizeof(int),
768 .mode = 0644,
769 .proc_handler = proc_dointvec_minmax,
770 .extra1 = &zero,
771 .extra2 = &ten_thousand,
774 .procname = "dmesg_restrict",
775 .data = &dmesg_restrict,
776 .maxlen = sizeof(int),
777 .mode = 0644,
778 .proc_handler = proc_dointvec_minmax_sysadmin,
779 .extra1 = &zero,
780 .extra2 = &one,
783 .procname = "kptr_restrict",
784 .data = &kptr_restrict,
785 .maxlen = sizeof(int),
786 .mode = 0644,
787 .proc_handler = proc_dointvec_minmax_sysadmin,
788 .extra1 = &zero,
789 .extra2 = &two,
791 #endif
793 .procname = "ngroups_max",
794 .data = &ngroups_max,
795 .maxlen = sizeof (int),
796 .mode = 0444,
797 .proc_handler = proc_dointvec,
800 .procname = "cap_last_cap",
801 .data = (void *)&cap_last_cap,
802 .maxlen = sizeof(int),
803 .mode = 0444,
804 .proc_handler = proc_dointvec,
806 #if defined(CONFIG_LOCKUP_DETECTOR)
808 .procname = "watchdog",
809 .data = &watchdog_user_enabled,
810 .maxlen = sizeof (int),
811 .mode = 0644,
812 .proc_handler = proc_dowatchdog,
813 .extra1 = &zero,
814 .extra2 = &one,
817 .procname = "watchdog_thresh",
818 .data = &watchdog_thresh,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = proc_dowatchdog,
822 .extra1 = &zero,
823 .extra2 = &sixty,
826 .procname = "softlockup_panic",
827 .data = &softlockup_panic,
828 .maxlen = sizeof(int),
829 .mode = 0644,
830 .proc_handler = proc_dointvec_minmax,
831 .extra1 = &zero,
832 .extra2 = &one,
835 .procname = "nmi_watchdog",
836 .data = &watchdog_user_enabled,
837 .maxlen = sizeof (int),
838 .mode = 0644,
839 .proc_handler = proc_dowatchdog,
840 .extra1 = &zero,
841 .extra2 = &one,
843 #endif
844 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
846 .procname = "unknown_nmi_panic",
847 .data = &unknown_nmi_panic,
848 .maxlen = sizeof (int),
849 .mode = 0644,
850 .proc_handler = proc_dointvec,
852 #endif
853 #if defined(CONFIG_X86)
855 .procname = "panic_on_unrecovered_nmi",
856 .data = &panic_on_unrecovered_nmi,
857 .maxlen = sizeof(int),
858 .mode = 0644,
859 .proc_handler = proc_dointvec,
862 .procname = "panic_on_io_nmi",
863 .data = &panic_on_io_nmi,
864 .maxlen = sizeof(int),
865 .mode = 0644,
866 .proc_handler = proc_dointvec,
868 #ifdef CONFIG_DEBUG_STACKOVERFLOW
870 .procname = "panic_on_stackoverflow",
871 .data = &sysctl_panic_on_stackoverflow,
872 .maxlen = sizeof(int),
873 .mode = 0644,
874 .proc_handler = proc_dointvec,
876 #endif
878 .procname = "bootloader_type",
879 .data = &bootloader_type,
880 .maxlen = sizeof (int),
881 .mode = 0444,
882 .proc_handler = proc_dointvec,
885 .procname = "bootloader_version",
886 .data = &bootloader_version,
887 .maxlen = sizeof (int),
888 .mode = 0444,
889 .proc_handler = proc_dointvec,
892 .procname = "kstack_depth_to_print",
893 .data = &kstack_depth_to_print,
894 .maxlen = sizeof(int),
895 .mode = 0644,
896 .proc_handler = proc_dointvec,
899 .procname = "io_delay_type",
900 .data = &io_delay_type,
901 .maxlen = sizeof(int),
902 .mode = 0644,
903 .proc_handler = proc_dointvec,
905 #endif
906 #if defined(CONFIG_MMU)
908 .procname = "randomize_va_space",
909 .data = &randomize_va_space,
910 .maxlen = sizeof(int),
911 .mode = 0644,
912 .proc_handler = proc_dointvec,
914 #endif
915 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
917 .procname = "spin_retry",
918 .data = &spin_retry,
919 .maxlen = sizeof (int),
920 .mode = 0644,
921 .proc_handler = proc_dointvec,
923 #endif
924 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
926 .procname = "acpi_video_flags",
927 .data = &acpi_realmode_flags,
928 .maxlen = sizeof (unsigned long),
929 .mode = 0644,
930 .proc_handler = proc_doulongvec_minmax,
932 #endif
933 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
935 .procname = "ignore-unaligned-usertrap",
936 .data = &no_unaligned_warning,
937 .maxlen = sizeof (int),
938 .mode = 0644,
939 .proc_handler = proc_dointvec,
941 #endif
942 #ifdef CONFIG_IA64
944 .procname = "unaligned-dump-stack",
945 .data = &unaligned_dump_stack,
946 .maxlen = sizeof (int),
947 .mode = 0644,
948 .proc_handler = proc_dointvec,
950 #endif
951 #ifdef CONFIG_DETECT_HUNG_TASK
953 .procname = "hung_task_panic",
954 .data = &sysctl_hung_task_panic,
955 .maxlen = sizeof(int),
956 .mode = 0644,
957 .proc_handler = proc_dointvec_minmax,
958 .extra1 = &zero,
959 .extra2 = &one,
962 .procname = "hung_task_check_count",
963 .data = &sysctl_hung_task_check_count,
964 .maxlen = sizeof(unsigned long),
965 .mode = 0644,
966 .proc_handler = proc_doulongvec_minmax,
969 .procname = "hung_task_timeout_secs",
970 .data = &sysctl_hung_task_timeout_secs,
971 .maxlen = sizeof(unsigned long),
972 .mode = 0644,
973 .proc_handler = proc_dohung_task_timeout_secs,
976 .procname = "hung_task_warnings",
977 .data = &sysctl_hung_task_warnings,
978 .maxlen = sizeof(unsigned long),
979 .mode = 0644,
980 .proc_handler = proc_doulongvec_minmax,
982 #endif
983 #ifdef CONFIG_COMPAT
985 .procname = "compat-log",
986 .data = &compat_log,
987 .maxlen = sizeof (int),
988 .mode = 0644,
989 .proc_handler = proc_dointvec,
991 #endif
992 #ifdef CONFIG_RT_MUTEXES
994 .procname = "max_lock_depth",
995 .data = &max_lock_depth,
996 .maxlen = sizeof(int),
997 .mode = 0644,
998 .proc_handler = proc_dointvec,
1000 #endif
1002 .procname = "poweroff_cmd",
1003 .data = &poweroff_cmd,
1004 .maxlen = POWEROFF_CMD_PATH_LEN,
1005 .mode = 0644,
1006 .proc_handler = proc_dostring,
1008 #ifdef CONFIG_KEYS
1010 .procname = "keys",
1011 .mode = 0555,
1012 .child = key_sysctls,
1014 #endif
1015 #ifdef CONFIG_RCU_TORTURE_TEST
1017 .procname = "rcutorture_runnable",
1018 .data = &rcutorture_runnable,
1019 .maxlen = sizeof(int),
1020 .mode = 0644,
1021 .proc_handler = proc_dointvec,
1023 #endif
1024 #ifdef CONFIG_PERF_EVENTS
1026 * User-space scripts rely on the existence of this file
1027 * as a feature check for perf_events being enabled.
1029 * So it's an ABI, do not remove!
1032 .procname = "perf_event_paranoid",
1033 .data = &sysctl_perf_event_paranoid,
1034 .maxlen = sizeof(sysctl_perf_event_paranoid),
1035 .mode = 0644,
1036 .proc_handler = proc_dointvec,
1039 .procname = "perf_event_mlock_kb",
1040 .data = &sysctl_perf_event_mlock,
1041 .maxlen = sizeof(sysctl_perf_event_mlock),
1042 .mode = 0644,
1043 .proc_handler = proc_dointvec,
1046 .procname = "perf_event_max_sample_rate",
1047 .data = &sysctl_perf_event_sample_rate,
1048 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1049 .mode = 0644,
1050 .proc_handler = perf_proc_update_handler,
1051 .extra1 = &one,
1054 .procname = "perf_cpu_time_max_percent",
1055 .data = &sysctl_perf_cpu_time_max_percent,
1056 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1057 .mode = 0644,
1058 .proc_handler = perf_cpu_time_max_percent_handler,
1059 .extra1 = &zero,
1060 .extra2 = &one_hundred,
1062 #endif
1063 #ifdef CONFIG_KMEMCHECK
1065 .procname = "kmemcheck",
1066 .data = &kmemcheck_enabled,
1067 .maxlen = sizeof(int),
1068 .mode = 0644,
1069 .proc_handler = proc_dointvec,
1071 #endif
1072 #ifdef CONFIG_BLOCK
1074 .procname = "blk_iopoll",
1075 .data = &blk_iopoll_enabled,
1076 .maxlen = sizeof(int),
1077 .mode = 0644,
1078 .proc_handler = proc_dointvec,
1080 #endif
1084 static struct ctl_table vm_table[] = {
1086 .procname = "overcommit_memory",
1087 .data = &sysctl_overcommit_memory,
1088 .maxlen = sizeof(sysctl_overcommit_memory),
1089 .mode = 0644,
1090 .proc_handler = proc_dointvec_minmax,
1091 .extra1 = &zero,
1092 .extra2 = &two,
1095 .procname = "panic_on_oom",
1096 .data = &sysctl_panic_on_oom,
1097 .maxlen = sizeof(sysctl_panic_on_oom),
1098 .mode = 0644,
1099 .proc_handler = proc_dointvec_minmax,
1100 .extra1 = &zero,
1101 .extra2 = &two,
1104 .procname = "oom_kill_allocating_task",
1105 .data = &sysctl_oom_kill_allocating_task,
1106 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1107 .mode = 0644,
1108 .proc_handler = proc_dointvec,
1111 .procname = "oom_dump_tasks",
1112 .data = &sysctl_oom_dump_tasks,
1113 .maxlen = sizeof(sysctl_oom_dump_tasks),
1114 .mode = 0644,
1115 .proc_handler = proc_dointvec,
1118 .procname = "overcommit_ratio",
1119 .data = &sysctl_overcommit_ratio,
1120 .maxlen = sizeof(sysctl_overcommit_ratio),
1121 .mode = 0644,
1122 .proc_handler = proc_dointvec,
1125 .procname = "page-cluster",
1126 .data = &page_cluster,
1127 .maxlen = sizeof(int),
1128 .mode = 0644,
1129 .proc_handler = proc_dointvec_minmax,
1130 .extra1 = &zero,
1133 .procname = "dirty_background_ratio",
1134 .data = &dirty_background_ratio,
1135 .maxlen = sizeof(dirty_background_ratio),
1136 .mode = 0644,
1137 .proc_handler = dirty_background_ratio_handler,
1138 .extra1 = &zero,
1139 .extra2 = &one_hundred,
1142 .procname = "dirty_background_bytes",
1143 .data = &dirty_background_bytes,
1144 .maxlen = sizeof(dirty_background_bytes),
1145 .mode = 0644,
1146 .proc_handler = dirty_background_bytes_handler,
1147 .extra1 = &one_ul,
1150 .procname = "dirty_ratio",
1151 .data = &vm_dirty_ratio,
1152 .maxlen = sizeof(vm_dirty_ratio),
1153 .mode = 0644,
1154 .proc_handler = dirty_ratio_handler,
1155 .extra1 = &zero,
1156 .extra2 = &one_hundred,
1159 .procname = "dirty_bytes",
1160 .data = &vm_dirty_bytes,
1161 .maxlen = sizeof(vm_dirty_bytes),
1162 .mode = 0644,
1163 .proc_handler = dirty_bytes_handler,
1164 .extra1 = &dirty_bytes_min,
1167 .procname = "dirty_writeback_centisecs",
1168 .data = &dirty_writeback_interval,
1169 .maxlen = sizeof(dirty_writeback_interval),
1170 .mode = 0644,
1171 .proc_handler = dirty_writeback_centisecs_handler,
1174 .procname = "dirty_expire_centisecs",
1175 .data = &dirty_expire_interval,
1176 .maxlen = sizeof(dirty_expire_interval),
1177 .mode = 0644,
1178 .proc_handler = proc_dointvec_minmax,
1179 .extra1 = &zero,
1182 .procname = "nr_pdflush_threads",
1183 .mode = 0444 /* read-only */,
1184 .proc_handler = pdflush_proc_obsolete,
1187 .procname = "swappiness",
1188 .data = &vm_swappiness,
1189 .maxlen = sizeof(vm_swappiness),
1190 .mode = 0644,
1191 .proc_handler = proc_dointvec_minmax,
1192 .extra1 = &zero,
1193 .extra2 = &one_hundred,
1195 #ifdef CONFIG_HUGETLB_PAGE
1197 .procname = "nr_hugepages",
1198 .data = NULL,
1199 .maxlen = sizeof(unsigned long),
1200 .mode = 0644,
1201 .proc_handler = hugetlb_sysctl_handler,
1202 .extra1 = (void *)&hugetlb_zero,
1203 .extra2 = (void *)&hugetlb_infinity,
1205 #ifdef CONFIG_NUMA
1207 .procname = "nr_hugepages_mempolicy",
1208 .data = NULL,
1209 .maxlen = sizeof(unsigned long),
1210 .mode = 0644,
1211 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1212 .extra1 = (void *)&hugetlb_zero,
1213 .extra2 = (void *)&hugetlb_infinity,
1215 #endif
1217 .procname = "hugetlb_shm_group",
1218 .data = &sysctl_hugetlb_shm_group,
1219 .maxlen = sizeof(gid_t),
1220 .mode = 0644,
1221 .proc_handler = proc_dointvec,
1224 .procname = "hugepages_treat_as_movable",
1225 .data = &hugepages_treat_as_movable,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
1228 .proc_handler = proc_dointvec,
1231 .procname = "nr_overcommit_hugepages",
1232 .data = NULL,
1233 .maxlen = sizeof(unsigned long),
1234 .mode = 0644,
1235 .proc_handler = hugetlb_overcommit_handler,
1236 .extra1 = (void *)&hugetlb_zero,
1237 .extra2 = (void *)&hugetlb_infinity,
1239 #endif
1241 .procname = "lowmem_reserve_ratio",
1242 .data = &sysctl_lowmem_reserve_ratio,
1243 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1244 .mode = 0644,
1245 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1248 .procname = "drop_caches",
1249 .data = &sysctl_drop_caches,
1250 .maxlen = sizeof(int),
1251 .mode = 0644,
1252 .proc_handler = drop_caches_sysctl_handler,
1253 .extra1 = &one,
1254 .extra2 = &three,
1256 #ifdef CONFIG_COMPACTION
1258 .procname = "compact_memory",
1259 .data = &sysctl_compact_memory,
1260 .maxlen = sizeof(int),
1261 .mode = 0200,
1262 .proc_handler = sysctl_compaction_handler,
1265 .procname = "extfrag_threshold",
1266 .data = &sysctl_extfrag_threshold,
1267 .maxlen = sizeof(int),
1268 .mode = 0644,
1269 .proc_handler = sysctl_extfrag_handler,
1270 .extra1 = &min_extfrag_threshold,
1271 .extra2 = &max_extfrag_threshold,
1274 #endif /* CONFIG_COMPACTION */
1276 .procname = "min_free_kbytes",
1277 .data = &min_free_kbytes,
1278 .maxlen = sizeof(min_free_kbytes),
1279 .mode = 0644,
1280 .proc_handler = min_free_kbytes_sysctl_handler,
1281 .extra1 = &zero,
1284 .procname = "percpu_pagelist_fraction",
1285 .data = &percpu_pagelist_fraction,
1286 .maxlen = sizeof(percpu_pagelist_fraction),
1287 .mode = 0644,
1288 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1289 .extra1 = &zero,
1291 #ifdef CONFIG_MMU
1293 .procname = "max_map_count",
1294 .data = &sysctl_max_map_count,
1295 .maxlen = sizeof(sysctl_max_map_count),
1296 .mode = 0644,
1297 .proc_handler = proc_dointvec_minmax,
1298 .extra1 = &zero,
1300 #else
1302 .procname = "nr_trim_pages",
1303 .data = &sysctl_nr_trim_pages,
1304 .maxlen = sizeof(sysctl_nr_trim_pages),
1305 .mode = 0644,
1306 .proc_handler = proc_dointvec_minmax,
1307 .extra1 = &zero,
1309 #endif
1311 .procname = "laptop_mode",
1312 .data = &laptop_mode,
1313 .maxlen = sizeof(laptop_mode),
1314 .mode = 0644,
1315 .proc_handler = proc_dointvec_jiffies,
1318 .procname = "block_dump",
1319 .data = &block_dump,
1320 .maxlen = sizeof(block_dump),
1321 .mode = 0644,
1322 .proc_handler = proc_dointvec,
1323 .extra1 = &zero,
1326 .procname = "vfs_cache_pressure",
1327 .data = &sysctl_vfs_cache_pressure,
1328 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1329 .mode = 0644,
1330 .proc_handler = proc_dointvec,
1331 .extra1 = &zero,
1333 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1335 .procname = "legacy_va_layout",
1336 .data = &sysctl_legacy_va_layout,
1337 .maxlen = sizeof(sysctl_legacy_va_layout),
1338 .mode = 0644,
1339 .proc_handler = proc_dointvec,
1340 .extra1 = &zero,
1342 #endif
1343 #ifdef CONFIG_NUMA
1345 .procname = "zone_reclaim_mode",
1346 .data = &zone_reclaim_mode,
1347 .maxlen = sizeof(zone_reclaim_mode),
1348 .mode = 0644,
1349 .proc_handler = proc_dointvec,
1350 .extra1 = &zero,
1353 .procname = "min_unmapped_ratio",
1354 .data = &sysctl_min_unmapped_ratio,
1355 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1356 .mode = 0644,
1357 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1358 .extra1 = &zero,
1359 .extra2 = &one_hundred,
1362 .procname = "min_slab_ratio",
1363 .data = &sysctl_min_slab_ratio,
1364 .maxlen = sizeof(sysctl_min_slab_ratio),
1365 .mode = 0644,
1366 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1367 .extra1 = &zero,
1368 .extra2 = &one_hundred,
1370 #endif
1371 #ifdef CONFIG_SMP
1373 .procname = "stat_interval",
1374 .data = &sysctl_stat_interval,
1375 .maxlen = sizeof(sysctl_stat_interval),
1376 .mode = 0644,
1377 .proc_handler = proc_dointvec_jiffies,
1379 #endif
1380 #ifdef CONFIG_MMU
1382 .procname = "mmap_min_addr",
1383 .data = &dac_mmap_min_addr,
1384 .maxlen = sizeof(unsigned long),
1385 .mode = 0644,
1386 .proc_handler = mmap_min_addr_handler,
1388 #endif
1389 #ifdef CONFIG_NUMA
1391 .procname = "numa_zonelist_order",
1392 .data = &numa_zonelist_order,
1393 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1394 .mode = 0644,
1395 .proc_handler = numa_zonelist_order_handler,
1397 #endif
1398 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1399 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1401 .procname = "vdso_enabled",
1402 .data = &vdso_enabled,
1403 .maxlen = sizeof(vdso_enabled),
1404 .mode = 0644,
1405 .proc_handler = proc_dointvec,
1406 .extra1 = &zero,
1408 #endif
1409 #ifdef CONFIG_HIGHMEM
1411 .procname = "highmem_is_dirtyable",
1412 .data = &vm_highmem_is_dirtyable,
1413 .maxlen = sizeof(vm_highmem_is_dirtyable),
1414 .mode = 0644,
1415 .proc_handler = proc_dointvec_minmax,
1416 .extra1 = &zero,
1417 .extra2 = &one,
1419 #endif
1421 .procname = "scan_unevictable_pages",
1422 .data = &scan_unevictable_pages,
1423 .maxlen = sizeof(scan_unevictable_pages),
1424 .mode = 0644,
1425 .proc_handler = scan_unevictable_handler,
1427 #ifdef CONFIG_MEMORY_FAILURE
1429 .procname = "memory_failure_early_kill",
1430 .data = &sysctl_memory_failure_early_kill,
1431 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1432 .mode = 0644,
1433 .proc_handler = proc_dointvec_minmax,
1434 .extra1 = &zero,
1435 .extra2 = &one,
1438 .procname = "memory_failure_recovery",
1439 .data = &sysctl_memory_failure_recovery,
1440 .maxlen = sizeof(sysctl_memory_failure_recovery),
1441 .mode = 0644,
1442 .proc_handler = proc_dointvec_minmax,
1443 .extra1 = &zero,
1444 .extra2 = &one,
1446 #endif
1448 .procname = "user_reserve_kbytes",
1449 .data = &sysctl_user_reserve_kbytes,
1450 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1451 .mode = 0644,
1452 .proc_handler = proc_doulongvec_minmax,
1455 .procname = "admin_reserve_kbytes",
1456 .data = &sysctl_admin_reserve_kbytes,
1457 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1458 .mode = 0644,
1459 .proc_handler = proc_doulongvec_minmax,
1464 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1465 static struct ctl_table binfmt_misc_table[] = {
1468 #endif
1470 static struct ctl_table fs_table[] = {
1472 .procname = "inode-nr",
1473 .data = &inodes_stat,
1474 .maxlen = 2*sizeof(long),
1475 .mode = 0444,
1476 .proc_handler = proc_nr_inodes,
1479 .procname = "inode-state",
1480 .data = &inodes_stat,
1481 .maxlen = 7*sizeof(long),
1482 .mode = 0444,
1483 .proc_handler = proc_nr_inodes,
1486 .procname = "file-nr",
1487 .data = &files_stat,
1488 .maxlen = sizeof(files_stat),
1489 .mode = 0444,
1490 .proc_handler = proc_nr_files,
1493 .procname = "file-max",
1494 .data = &files_stat.max_files,
1495 .maxlen = sizeof(files_stat.max_files),
1496 .mode = 0644,
1497 .proc_handler = proc_doulongvec_minmax,
1500 .procname = "nr_open",
1501 .data = &sysctl_nr_open,
1502 .maxlen = sizeof(int),
1503 .mode = 0644,
1504 .proc_handler = proc_dointvec_minmax,
1505 .extra1 = &sysctl_nr_open_min,
1506 .extra2 = &sysctl_nr_open_max,
1509 .procname = "dentry-state",
1510 .data = &dentry_stat,
1511 .maxlen = 6*sizeof(long),
1512 .mode = 0444,
1513 .proc_handler = proc_nr_dentry,
1516 .procname = "overflowuid",
1517 .data = &fs_overflowuid,
1518 .maxlen = sizeof(int),
1519 .mode = 0644,
1520 .proc_handler = proc_dointvec_minmax,
1521 .extra1 = &minolduid,
1522 .extra2 = &maxolduid,
1525 .procname = "overflowgid",
1526 .data = &fs_overflowgid,
1527 .maxlen = sizeof(int),
1528 .mode = 0644,
1529 .proc_handler = proc_dointvec_minmax,
1530 .extra1 = &minolduid,
1531 .extra2 = &maxolduid,
1533 #ifdef CONFIG_FILE_LOCKING
1535 .procname = "leases-enable",
1536 .data = &leases_enable,
1537 .maxlen = sizeof(int),
1538 .mode = 0644,
1539 .proc_handler = proc_dointvec,
1541 #endif
1542 #ifdef CONFIG_DNOTIFY
1544 .procname = "dir-notify-enable",
1545 .data = &dir_notify_enable,
1546 .maxlen = sizeof(int),
1547 .mode = 0644,
1548 .proc_handler = proc_dointvec,
1550 #endif
1551 #ifdef CONFIG_MMU
1552 #ifdef CONFIG_FILE_LOCKING
1554 .procname = "lease-break-time",
1555 .data = &lease_break_time,
1556 .maxlen = sizeof(int),
1557 .mode = 0644,
1558 .proc_handler = proc_dointvec,
1560 #endif
1561 #ifdef CONFIG_AIO
1563 .procname = "aio-nr",
1564 .data = &aio_nr,
1565 .maxlen = sizeof(aio_nr),
1566 .mode = 0444,
1567 .proc_handler = proc_doulongvec_minmax,
1570 .procname = "aio-max-nr",
1571 .data = &aio_max_nr,
1572 .maxlen = sizeof(aio_max_nr),
1573 .mode = 0644,
1574 .proc_handler = proc_doulongvec_minmax,
1576 #endif /* CONFIG_AIO */
1577 #ifdef CONFIG_INOTIFY_USER
1579 .procname = "inotify",
1580 .mode = 0555,
1581 .child = inotify_table,
1583 #endif
1584 #ifdef CONFIG_EPOLL
1586 .procname = "epoll",
1587 .mode = 0555,
1588 .child = epoll_table,
1590 #endif
1591 #endif
1593 .procname = "protected_symlinks",
1594 .data = &sysctl_protected_symlinks,
1595 .maxlen = sizeof(int),
1596 .mode = 0600,
1597 .proc_handler = proc_dointvec_minmax,
1598 .extra1 = &zero,
1599 .extra2 = &one,
1602 .procname = "protected_hardlinks",
1603 .data = &sysctl_protected_hardlinks,
1604 .maxlen = sizeof(int),
1605 .mode = 0600,
1606 .proc_handler = proc_dointvec_minmax,
1607 .extra1 = &zero,
1608 .extra2 = &one,
1611 .procname = "suid_dumpable",
1612 .data = &suid_dumpable,
1613 .maxlen = sizeof(int),
1614 .mode = 0644,
1615 .proc_handler = proc_dointvec_minmax_coredump,
1616 .extra1 = &zero,
1617 .extra2 = &two,
1619 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1621 .procname = "binfmt_misc",
1622 .mode = 0555,
1623 .child = binfmt_misc_table,
1625 #endif
1627 .procname = "pipe-max-size",
1628 .data = &pipe_max_size,
1629 .maxlen = sizeof(int),
1630 .mode = 0644,
1631 .proc_handler = &pipe_proc_fn,
1632 .extra1 = &pipe_min_size,
1637 static struct ctl_table debug_table[] = {
1638 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1640 .procname = "exception-trace",
1641 .data = &show_unhandled_signals,
1642 .maxlen = sizeof(int),
1643 .mode = 0644,
1644 .proc_handler = proc_dointvec
1646 #endif
1647 #if defined(CONFIG_OPTPROBES)
1649 .procname = "kprobes-optimization",
1650 .data = &sysctl_kprobes_optimization,
1651 .maxlen = sizeof(int),
1652 .mode = 0644,
1653 .proc_handler = proc_kprobes_optimization_handler,
1654 .extra1 = &zero,
1655 .extra2 = &one,
1657 #endif
1661 static struct ctl_table dev_table[] = {
1665 int __init sysctl_init(void)
1667 struct ctl_table_header *hdr;
1669 hdr = register_sysctl_table(sysctl_base_table);
1670 kmemleak_not_leak(hdr);
1671 return 0;
1674 #endif /* CONFIG_SYSCTL */
1677 * /proc/sys support
1680 #ifdef CONFIG_PROC_SYSCTL
1682 static int _proc_do_string(void* data, int maxlen, int write,
1683 void __user *buffer,
1684 size_t *lenp, loff_t *ppos)
1686 size_t len;
1687 char __user *p;
1688 char c;
1690 if (!data || !maxlen || !*lenp) {
1691 *lenp = 0;
1692 return 0;
1695 if (write) {
1696 len = 0;
1697 p = buffer;
1698 while (len < *lenp) {
1699 if (get_user(c, p++))
1700 return -EFAULT;
1701 if (c == 0 || c == '\n')
1702 break;
1703 len++;
1705 if (len >= maxlen)
1706 len = maxlen-1;
1707 if(copy_from_user(data, buffer, len))
1708 return -EFAULT;
1709 ((char *) data)[len] = 0;
1710 *ppos += *lenp;
1711 } else {
1712 len = strlen(data);
1713 if (len > maxlen)
1714 len = maxlen;
1716 if (*ppos > len) {
1717 *lenp = 0;
1718 return 0;
1721 data += *ppos;
1722 len -= *ppos;
1724 if (len > *lenp)
1725 len = *lenp;
1726 if (len)
1727 if(copy_to_user(buffer, data, len))
1728 return -EFAULT;
1729 if (len < *lenp) {
1730 if(put_user('\n', ((char __user *) buffer) + len))
1731 return -EFAULT;
1732 len++;
1734 *lenp = len;
1735 *ppos += len;
1737 return 0;
1741 * proc_dostring - read a string sysctl
1742 * @table: the sysctl table
1743 * @write: %TRUE if this is a write to the sysctl file
1744 * @buffer: the user buffer
1745 * @lenp: the size of the user buffer
1746 * @ppos: file position
1748 * Reads/writes a string from/to the user buffer. If the kernel
1749 * buffer provided is not large enough to hold the string, the
1750 * string is truncated. The copied string is %NULL-terminated.
1751 * If the string is being read by the user process, it is copied
1752 * and a newline '\n' is added. It is truncated if the buffer is
1753 * not large enough.
1755 * Returns 0 on success.
1757 int proc_dostring(struct ctl_table *table, int write,
1758 void __user *buffer, size_t *lenp, loff_t *ppos)
1760 return _proc_do_string(table->data, table->maxlen, write,
1761 buffer, lenp, ppos);
1764 static size_t proc_skip_spaces(char **buf)
1766 size_t ret;
1767 char *tmp = skip_spaces(*buf);
1768 ret = tmp - *buf;
1769 *buf = tmp;
1770 return ret;
1773 static void proc_skip_char(char **buf, size_t *size, const char v)
1775 while (*size) {
1776 if (**buf != v)
1777 break;
1778 (*size)--;
1779 (*buf)++;
1783 #define TMPBUFLEN 22
1785 * proc_get_long - reads an ASCII formatted integer from a user buffer
1787 * @buf: a kernel buffer
1788 * @size: size of the kernel buffer
1789 * @val: this is where the number will be stored
1790 * @neg: set to %TRUE if number is negative
1791 * @perm_tr: a vector which contains the allowed trailers
1792 * @perm_tr_len: size of the perm_tr vector
1793 * @tr: pointer to store the trailer character
1795 * In case of success %0 is returned and @buf and @size are updated with
1796 * the amount of bytes read. If @tr is non-NULL and a trailing
1797 * character exists (size is non-zero after returning from this
1798 * function), @tr is updated with the trailing character.
1800 static int proc_get_long(char **buf, size_t *size,
1801 unsigned long *val, bool *neg,
1802 const char *perm_tr, unsigned perm_tr_len, char *tr)
1804 int len;
1805 char *p, tmp[TMPBUFLEN];
1807 if (!*size)
1808 return -EINVAL;
1810 len = *size;
1811 if (len > TMPBUFLEN - 1)
1812 len = TMPBUFLEN - 1;
1814 memcpy(tmp, *buf, len);
1816 tmp[len] = 0;
1817 p = tmp;
1818 if (*p == '-' && *size > 1) {
1819 *neg = true;
1820 p++;
1821 } else
1822 *neg = false;
1823 if (!isdigit(*p))
1824 return -EINVAL;
1826 *val = simple_strtoul(p, &p, 0);
1828 len = p - tmp;
1830 /* We don't know if the next char is whitespace thus we may accept
1831 * invalid integers (e.g. 1234...a) or two integers instead of one
1832 * (e.g. 123...1). So lets not allow such large numbers. */
1833 if (len == TMPBUFLEN - 1)
1834 return -EINVAL;
1836 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1837 return -EINVAL;
1839 if (tr && (len < *size))
1840 *tr = *p;
1842 *buf += len;
1843 *size -= len;
1845 return 0;
1849 * proc_put_long - converts an integer to a decimal ASCII formatted string
1851 * @buf: the user buffer
1852 * @size: the size of the user buffer
1853 * @val: the integer to be converted
1854 * @neg: sign of the number, %TRUE for negative
1856 * In case of success %0 is returned and @buf and @size are updated with
1857 * the amount of bytes written.
1859 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1860 bool neg)
1862 int len;
1863 char tmp[TMPBUFLEN], *p = tmp;
1865 sprintf(p, "%s%lu", neg ? "-" : "", val);
1866 len = strlen(tmp);
1867 if (len > *size)
1868 len = *size;
1869 if (copy_to_user(*buf, tmp, len))
1870 return -EFAULT;
1871 *size -= len;
1872 *buf += len;
1873 return 0;
1875 #undef TMPBUFLEN
1877 static int proc_put_char(void __user **buf, size_t *size, char c)
1879 if (*size) {
1880 char __user **buffer = (char __user **)buf;
1881 if (put_user(c, *buffer))
1882 return -EFAULT;
1883 (*size)--, (*buffer)++;
1884 *buf = *buffer;
1886 return 0;
1889 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1890 int *valp,
1891 int write, void *data)
1893 if (write) {
1894 *valp = *negp ? -*lvalp : *lvalp;
1895 } else {
1896 int val = *valp;
1897 if (val < 0) {
1898 *negp = true;
1899 *lvalp = (unsigned long)-val;
1900 } else {
1901 *negp = false;
1902 *lvalp = (unsigned long)val;
1905 return 0;
1908 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1910 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1911 int write, void __user *buffer,
1912 size_t *lenp, loff_t *ppos,
1913 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1914 int write, void *data),
1915 void *data)
1917 int *i, vleft, first = 1, err = 0;
1918 unsigned long page = 0;
1919 size_t left;
1920 char *kbuf;
1922 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1923 *lenp = 0;
1924 return 0;
1927 i = (int *) tbl_data;
1928 vleft = table->maxlen / sizeof(*i);
1929 left = *lenp;
1931 if (!conv)
1932 conv = do_proc_dointvec_conv;
1934 if (write) {
1935 if (left > PAGE_SIZE - 1)
1936 left = PAGE_SIZE - 1;
1937 page = __get_free_page(GFP_TEMPORARY);
1938 kbuf = (char *) page;
1939 if (!kbuf)
1940 return -ENOMEM;
1941 if (copy_from_user(kbuf, buffer, left)) {
1942 err = -EFAULT;
1943 goto free;
1945 kbuf[left] = 0;
1948 for (; left && vleft--; i++, first=0) {
1949 unsigned long lval;
1950 bool neg;
1952 if (write) {
1953 left -= proc_skip_spaces(&kbuf);
1955 if (!left)
1956 break;
1957 err = proc_get_long(&kbuf, &left, &lval, &neg,
1958 proc_wspace_sep,
1959 sizeof(proc_wspace_sep), NULL);
1960 if (err)
1961 break;
1962 if (conv(&neg, &lval, i, 1, data)) {
1963 err = -EINVAL;
1964 break;
1966 } else {
1967 if (conv(&neg, &lval, i, 0, data)) {
1968 err = -EINVAL;
1969 break;
1971 if (!first)
1972 err = proc_put_char(&buffer, &left, '\t');
1973 if (err)
1974 break;
1975 err = proc_put_long(&buffer, &left, lval, neg);
1976 if (err)
1977 break;
1981 if (!write && !first && left && !err)
1982 err = proc_put_char(&buffer, &left, '\n');
1983 if (write && !err && left)
1984 left -= proc_skip_spaces(&kbuf);
1985 free:
1986 if (write) {
1987 free_page(page);
1988 if (first)
1989 return err ? : -EINVAL;
1991 *lenp -= left;
1992 *ppos += *lenp;
1993 return err;
1996 static int do_proc_dointvec(struct ctl_table *table, int write,
1997 void __user *buffer, size_t *lenp, loff_t *ppos,
1998 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1999 int write, void *data),
2000 void *data)
2002 return __do_proc_dointvec(table->data, table, write,
2003 buffer, lenp, ppos, conv, data);
2007 * proc_dointvec - read a vector of integers
2008 * @table: the sysctl table
2009 * @write: %TRUE if this is a write to the sysctl file
2010 * @buffer: the user buffer
2011 * @lenp: the size of the user buffer
2012 * @ppos: file position
2014 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2015 * values from/to the user buffer, treated as an ASCII string.
2017 * Returns 0 on success.
2019 int proc_dointvec(struct ctl_table *table, int write,
2020 void __user *buffer, size_t *lenp, loff_t *ppos)
2022 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2023 NULL,NULL);
2027 * Taint values can only be increased
2028 * This means we can safely use a temporary.
2030 static int proc_taint(struct ctl_table *table, int write,
2031 void __user *buffer, size_t *lenp, loff_t *ppos)
2033 struct ctl_table t;
2034 unsigned long tmptaint = get_taint();
2035 int err;
2037 if (write && !capable(CAP_SYS_ADMIN))
2038 return -EPERM;
2040 t = *table;
2041 t.data = &tmptaint;
2042 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2043 if (err < 0)
2044 return err;
2046 if (write) {
2048 * Poor man's atomic or. Not worth adding a primitive
2049 * to everyone's atomic.h for this
2051 int i;
2052 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2053 if ((tmptaint >> i) & 1)
2054 add_taint(i, LOCKDEP_STILL_OK);
2058 return err;
2061 #ifdef CONFIG_PRINTK
2062 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2063 void __user *buffer, size_t *lenp, loff_t *ppos)
2065 if (write && !capable(CAP_SYS_ADMIN))
2066 return -EPERM;
2068 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2070 #endif
2072 struct do_proc_dointvec_minmax_conv_param {
2073 int *min;
2074 int *max;
2077 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2078 int *valp,
2079 int write, void *data)
2081 struct do_proc_dointvec_minmax_conv_param *param = data;
2082 if (write) {
2083 int val = *negp ? -*lvalp : *lvalp;
2084 if ((param->min && *param->min > val) ||
2085 (param->max && *param->max < val))
2086 return -EINVAL;
2087 *valp = val;
2088 } else {
2089 int val = *valp;
2090 if (val < 0) {
2091 *negp = true;
2092 *lvalp = (unsigned long)-val;
2093 } else {
2094 *negp = false;
2095 *lvalp = (unsigned long)val;
2098 return 0;
2102 * proc_dointvec_minmax - read a vector of integers with min/max values
2103 * @table: the sysctl table
2104 * @write: %TRUE if this is a write to the sysctl file
2105 * @buffer: the user buffer
2106 * @lenp: the size of the user buffer
2107 * @ppos: file position
2109 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2110 * values from/to the user buffer, treated as an ASCII string.
2112 * This routine will ensure the values are within the range specified by
2113 * table->extra1 (min) and table->extra2 (max).
2115 * Returns 0 on success.
2117 int proc_dointvec_minmax(struct ctl_table *table, int write,
2118 void __user *buffer, size_t *lenp, loff_t *ppos)
2120 struct do_proc_dointvec_minmax_conv_param param = {
2121 .min = (int *) table->extra1,
2122 .max = (int *) table->extra2,
2124 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2125 do_proc_dointvec_minmax_conv, &param);
2128 static void validate_coredump_safety(void)
2130 #ifdef CONFIG_COREDUMP
2131 if (suid_dumpable == SUID_DUMP_ROOT &&
2132 core_pattern[0] != '/' && core_pattern[0] != '|') {
2133 printk(KERN_WARNING "Unsafe core_pattern used with "\
2134 "suid_dumpable=2. Pipe handler or fully qualified "\
2135 "core dump path required.\n");
2137 #endif
2140 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2141 void __user *buffer, size_t *lenp, loff_t *ppos)
2143 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2144 if (!error)
2145 validate_coredump_safety();
2146 return error;
2149 #ifdef CONFIG_COREDUMP
2150 static int proc_dostring_coredump(struct ctl_table *table, int write,
2151 void __user *buffer, size_t *lenp, loff_t *ppos)
2153 int error = proc_dostring(table, write, buffer, lenp, ppos);
2154 if (!error)
2155 validate_coredump_safety();
2156 return error;
2158 #endif
2160 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2161 void __user *buffer,
2162 size_t *lenp, loff_t *ppos,
2163 unsigned long convmul,
2164 unsigned long convdiv)
2166 unsigned long *i, *min, *max;
2167 int vleft, first = 1, err = 0;
2168 unsigned long page = 0;
2169 size_t left;
2170 char *kbuf;
2172 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2173 *lenp = 0;
2174 return 0;
2177 i = (unsigned long *) data;
2178 min = (unsigned long *) table->extra1;
2179 max = (unsigned long *) table->extra2;
2180 vleft = table->maxlen / sizeof(unsigned long);
2181 left = *lenp;
2183 if (write) {
2184 if (left > PAGE_SIZE - 1)
2185 left = PAGE_SIZE - 1;
2186 page = __get_free_page(GFP_TEMPORARY);
2187 kbuf = (char *) page;
2188 if (!kbuf)
2189 return -ENOMEM;
2190 if (copy_from_user(kbuf, buffer, left)) {
2191 err = -EFAULT;
2192 goto free;
2194 kbuf[left] = 0;
2197 for (; left && vleft--; i++, first = 0) {
2198 unsigned long val;
2200 if (write) {
2201 bool neg;
2203 left -= proc_skip_spaces(&kbuf);
2205 err = proc_get_long(&kbuf, &left, &val, &neg,
2206 proc_wspace_sep,
2207 sizeof(proc_wspace_sep), NULL);
2208 if (err)
2209 break;
2210 if (neg)
2211 continue;
2212 if ((min && val < *min) || (max && val > *max))
2213 continue;
2214 *i = val;
2215 } else {
2216 val = convdiv * (*i) / convmul;
2217 if (!first)
2218 err = proc_put_char(&buffer, &left, '\t');
2219 err = proc_put_long(&buffer, &left, val, false);
2220 if (err)
2221 break;
2225 if (!write && !first && left && !err)
2226 err = proc_put_char(&buffer, &left, '\n');
2227 if (write && !err)
2228 left -= proc_skip_spaces(&kbuf);
2229 free:
2230 if (write) {
2231 free_page(page);
2232 if (first)
2233 return err ? : -EINVAL;
2235 *lenp -= left;
2236 *ppos += *lenp;
2237 return err;
2240 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2241 void __user *buffer,
2242 size_t *lenp, loff_t *ppos,
2243 unsigned long convmul,
2244 unsigned long convdiv)
2246 return __do_proc_doulongvec_minmax(table->data, table, write,
2247 buffer, lenp, ppos, convmul, convdiv);
2251 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2252 * @table: the sysctl table
2253 * @write: %TRUE if this is a write to the sysctl file
2254 * @buffer: the user buffer
2255 * @lenp: the size of the user buffer
2256 * @ppos: file position
2258 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2259 * values from/to the user buffer, treated as an ASCII string.
2261 * This routine will ensure the values are within the range specified by
2262 * table->extra1 (min) and table->extra2 (max).
2264 * Returns 0 on success.
2266 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2267 void __user *buffer, size_t *lenp, loff_t *ppos)
2269 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2273 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2274 * @table: the sysctl table
2275 * @write: %TRUE if this is a write to the sysctl file
2276 * @buffer: the user buffer
2277 * @lenp: the size of the user buffer
2278 * @ppos: file position
2280 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2281 * values from/to the user buffer, treated as an ASCII string. The values
2282 * are treated as milliseconds, and converted to jiffies when they are stored.
2284 * This routine will ensure the values are within the range specified by
2285 * table->extra1 (min) and table->extra2 (max).
2287 * Returns 0 on success.
2289 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2290 void __user *buffer,
2291 size_t *lenp, loff_t *ppos)
2293 return do_proc_doulongvec_minmax(table, write, buffer,
2294 lenp, ppos, HZ, 1000l);
2298 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2299 int *valp,
2300 int write, void *data)
2302 if (write) {
2303 if (*lvalp > LONG_MAX / HZ)
2304 return 1;
2305 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2306 } else {
2307 int val = *valp;
2308 unsigned long lval;
2309 if (val < 0) {
2310 *negp = true;
2311 lval = (unsigned long)-val;
2312 } else {
2313 *negp = false;
2314 lval = (unsigned long)val;
2316 *lvalp = lval / HZ;
2318 return 0;
2321 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2322 int *valp,
2323 int write, void *data)
2325 if (write) {
2326 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2327 return 1;
2328 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2329 } else {
2330 int val = *valp;
2331 unsigned long lval;
2332 if (val < 0) {
2333 *negp = true;
2334 lval = (unsigned long)-val;
2335 } else {
2336 *negp = false;
2337 lval = (unsigned long)val;
2339 *lvalp = jiffies_to_clock_t(lval);
2341 return 0;
2344 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2345 int *valp,
2346 int write, void *data)
2348 if (write) {
2349 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2351 if (jif > INT_MAX)
2352 return 1;
2353 *valp = (int)jif;
2354 } else {
2355 int val = *valp;
2356 unsigned long lval;
2357 if (val < 0) {
2358 *negp = true;
2359 lval = (unsigned long)-val;
2360 } else {
2361 *negp = false;
2362 lval = (unsigned long)val;
2364 *lvalp = jiffies_to_msecs(lval);
2366 return 0;
2370 * proc_dointvec_jiffies - read a vector of integers as seconds
2371 * @table: the sysctl table
2372 * @write: %TRUE if this is a write to the sysctl file
2373 * @buffer: the user buffer
2374 * @lenp: the size of the user buffer
2375 * @ppos: file position
2377 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2378 * values from/to the user buffer, treated as an ASCII string.
2379 * The values read are assumed to be in seconds, and are converted into
2380 * jiffies.
2382 * Returns 0 on success.
2384 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2385 void __user *buffer, size_t *lenp, loff_t *ppos)
2387 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2388 do_proc_dointvec_jiffies_conv,NULL);
2392 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2393 * @table: the sysctl table
2394 * @write: %TRUE if this is a write to the sysctl file
2395 * @buffer: the user buffer
2396 * @lenp: the size of the user buffer
2397 * @ppos: pointer to the file position
2399 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2400 * values from/to the user buffer, treated as an ASCII string.
2401 * The values read are assumed to be in 1/USER_HZ seconds, and
2402 * are converted into jiffies.
2404 * Returns 0 on success.
2406 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2407 void __user *buffer, size_t *lenp, loff_t *ppos)
2409 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2410 do_proc_dointvec_userhz_jiffies_conv,NULL);
2414 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2415 * @table: the sysctl table
2416 * @write: %TRUE if this is a write to the sysctl file
2417 * @buffer: the user buffer
2418 * @lenp: the size of the user buffer
2419 * @ppos: file position
2420 * @ppos: the current position in the file
2422 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2423 * values from/to the user buffer, treated as an ASCII string.
2424 * The values read are assumed to be in 1/1000 seconds, and
2425 * are converted into jiffies.
2427 * Returns 0 on success.
2429 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2430 void __user *buffer, size_t *lenp, loff_t *ppos)
2432 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2433 do_proc_dointvec_ms_jiffies_conv, NULL);
2436 static int proc_do_cad_pid(struct ctl_table *table, int write,
2437 void __user *buffer, size_t *lenp, loff_t *ppos)
2439 struct pid *new_pid;
2440 pid_t tmp;
2441 int r;
2443 tmp = pid_vnr(cad_pid);
2445 r = __do_proc_dointvec(&tmp, table, write, buffer,
2446 lenp, ppos, NULL, NULL);
2447 if (r || !write)
2448 return r;
2450 new_pid = find_get_pid(tmp);
2451 if (!new_pid)
2452 return -ESRCH;
2454 put_pid(xchg(&cad_pid, new_pid));
2455 return 0;
2459 * proc_do_large_bitmap - read/write from/to a large bitmap
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 * The bitmap is stored at table->data and the bitmap length (in bits)
2467 * in table->maxlen.
2469 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2470 * large bitmaps may be represented in a compact manner. Writing into
2471 * the file will clear the bitmap then update it with the given input.
2473 * Returns 0 on success.
2475 int proc_do_large_bitmap(struct ctl_table *table, int write,
2476 void __user *buffer, size_t *lenp, loff_t *ppos)
2478 int err = 0;
2479 bool first = 1;
2480 size_t left = *lenp;
2481 unsigned long bitmap_len = table->maxlen;
2482 unsigned long *bitmap = (unsigned long *) table->data;
2483 unsigned long *tmp_bitmap = NULL;
2484 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2486 if (!bitmap_len || !left || (*ppos && !write)) {
2487 *lenp = 0;
2488 return 0;
2491 if (write) {
2492 unsigned long page = 0;
2493 char *kbuf;
2495 if (left > PAGE_SIZE - 1)
2496 left = PAGE_SIZE - 1;
2498 page = __get_free_page(GFP_TEMPORARY);
2499 kbuf = (char *) page;
2500 if (!kbuf)
2501 return -ENOMEM;
2502 if (copy_from_user(kbuf, buffer, left)) {
2503 free_page(page);
2504 return -EFAULT;
2506 kbuf[left] = 0;
2508 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2509 GFP_KERNEL);
2510 if (!tmp_bitmap) {
2511 free_page(page);
2512 return -ENOMEM;
2514 proc_skip_char(&kbuf, &left, '\n');
2515 while (!err && left) {
2516 unsigned long val_a, val_b;
2517 bool neg;
2519 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2520 sizeof(tr_a), &c);
2521 if (err)
2522 break;
2523 if (val_a >= bitmap_len || neg) {
2524 err = -EINVAL;
2525 break;
2528 val_b = val_a;
2529 if (left) {
2530 kbuf++;
2531 left--;
2534 if (c == '-') {
2535 err = proc_get_long(&kbuf, &left, &val_b,
2536 &neg, tr_b, sizeof(tr_b),
2537 &c);
2538 if (err)
2539 break;
2540 if (val_b >= bitmap_len || neg ||
2541 val_a > val_b) {
2542 err = -EINVAL;
2543 break;
2545 if (left) {
2546 kbuf++;
2547 left--;
2551 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2552 first = 0;
2553 proc_skip_char(&kbuf, &left, '\n');
2555 free_page(page);
2556 } else {
2557 unsigned long bit_a, bit_b = 0;
2559 while (left) {
2560 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2561 if (bit_a >= bitmap_len)
2562 break;
2563 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2564 bit_a + 1) - 1;
2566 if (!first) {
2567 err = proc_put_char(&buffer, &left, ',');
2568 if (err)
2569 break;
2571 err = proc_put_long(&buffer, &left, bit_a, false);
2572 if (err)
2573 break;
2574 if (bit_a != bit_b) {
2575 err = proc_put_char(&buffer, &left, '-');
2576 if (err)
2577 break;
2578 err = proc_put_long(&buffer, &left, bit_b, false);
2579 if (err)
2580 break;
2583 first = 0; bit_b++;
2585 if (!err)
2586 err = proc_put_char(&buffer, &left, '\n');
2589 if (!err) {
2590 if (write) {
2591 if (*ppos)
2592 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2593 else
2594 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2596 kfree(tmp_bitmap);
2597 *lenp -= left;
2598 *ppos += *lenp;
2599 return 0;
2600 } else {
2601 kfree(tmp_bitmap);
2602 return err;
2606 #else /* CONFIG_PROC_SYSCTL */
2608 int proc_dostring(struct ctl_table *table, int write,
2609 void __user *buffer, size_t *lenp, loff_t *ppos)
2611 return -ENOSYS;
2614 int proc_dointvec(struct ctl_table *table, int write,
2615 void __user *buffer, size_t *lenp, loff_t *ppos)
2617 return -ENOSYS;
2620 int proc_dointvec_minmax(struct ctl_table *table, int write,
2621 void __user *buffer, size_t *lenp, loff_t *ppos)
2623 return -ENOSYS;
2626 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2627 void __user *buffer, size_t *lenp, loff_t *ppos)
2629 return -ENOSYS;
2632 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2633 void __user *buffer, size_t *lenp, loff_t *ppos)
2635 return -ENOSYS;
2638 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2639 void __user *buffer, size_t *lenp, loff_t *ppos)
2641 return -ENOSYS;
2644 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2645 void __user *buffer, size_t *lenp, loff_t *ppos)
2647 return -ENOSYS;
2650 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2651 void __user *buffer,
2652 size_t *lenp, loff_t *ppos)
2654 return -ENOSYS;
2658 #endif /* CONFIG_PROC_SYSCTL */
2661 * No sense putting this after each symbol definition, twice,
2662 * exception granted :-)
2664 EXPORT_SYMBOL(proc_dointvec);
2665 EXPORT_SYMBOL(proc_dointvec_jiffies);
2666 EXPORT_SYMBOL(proc_dointvec_minmax);
2667 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2668 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2669 EXPORT_SYMBOL(proc_dostring);
2670 EXPORT_SYMBOL(proc_doulongvec_minmax);
2671 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);