Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / kernel / sysctl.c
blob7de6555cfea0f3484e8decbf927c7c456c227175
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 __hppa__
156 extern int pwrsw_enabled;
157 #endif
159 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
160 extern int unaligned_enabled;
161 #endif
163 #ifdef CONFIG_IA64
164 extern int unaligned_dump_stack;
165 #endif
167 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168 extern int no_unaligned_warning;
169 #endif
171 #ifdef CONFIG_PROC_SYSCTL
173 #define SYSCTL_WRITES_LEGACY -1
174 #define SYSCTL_WRITES_WARN 0
175 #define SYSCTL_WRITES_STRICT 1
177 static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
179 static int proc_do_cad_pid(struct ctl_table *table, int write,
180 void __user *buffer, size_t *lenp, loff_t *ppos);
181 static int proc_taint(struct ctl_table *table, int write,
182 void __user *buffer, size_t *lenp, loff_t *ppos);
183 #endif
185 #ifdef CONFIG_PRINTK
186 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
187 void __user *buffer, size_t *lenp, loff_t *ppos);
188 #endif
190 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
192 #ifdef CONFIG_COREDUMP
193 static int proc_dostring_coredump(struct ctl_table *table, int write,
194 void __user *buffer, size_t *lenp, loff_t *ppos);
195 #endif
197 #ifdef CONFIG_MAGIC_SYSRQ
198 /* Note: sysrq code uses it's own private copy */
199 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
201 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
202 void __user *buffer, size_t *lenp,
203 loff_t *ppos)
205 int error;
207 error = proc_dointvec(table, write, buffer, lenp, ppos);
208 if (error)
209 return error;
211 if (write)
212 sysrq_toggle_support(__sysrq_enabled);
214 return 0;
217 #endif
219 static struct ctl_table kern_table[];
220 static struct ctl_table vm_table[];
221 static struct ctl_table fs_table[];
222 static struct ctl_table debug_table[];
223 static struct ctl_table dev_table[];
224 extern struct ctl_table random_table[];
225 #ifdef CONFIG_EPOLL
226 extern struct ctl_table epoll_table[];
227 #endif
229 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
230 int sysctl_legacy_va_layout;
231 #endif
233 /* The default sysctl tables: */
235 static struct ctl_table sysctl_base_table[] = {
237 .procname = "kernel",
238 .mode = 0555,
239 .child = kern_table,
242 .procname = "vm",
243 .mode = 0555,
244 .child = vm_table,
247 .procname = "fs",
248 .mode = 0555,
249 .child = fs_table,
252 .procname = "debug",
253 .mode = 0555,
254 .child = debug_table,
257 .procname = "dev",
258 .mode = 0555,
259 .child = dev_table,
264 #ifdef CONFIG_SCHED_DEBUG
265 static int min_sched_granularity_ns = 100000; /* 100 usecs */
266 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
267 static int min_wakeup_granularity_ns; /* 0 usecs */
268 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
269 #ifdef CONFIG_SMP
270 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
271 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
272 #endif /* CONFIG_SMP */
273 #endif /* CONFIG_SCHED_DEBUG */
275 #ifdef CONFIG_COMPACTION
276 static int min_extfrag_threshold;
277 static int max_extfrag_threshold = 1000;
278 #endif
280 static struct ctl_table kern_table[] = {
282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = proc_dointvec,
288 #ifdef CONFIG_SCHED_DEBUG
290 .procname = "sched_min_granularity_ns",
291 .data = &sysctl_sched_min_granularity,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = sched_proc_update_handler,
295 .extra1 = &min_sched_granularity_ns,
296 .extra2 = &max_sched_granularity_ns,
299 .procname = "sched_latency_ns",
300 .data = &sysctl_sched_latency,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
303 .proc_handler = sched_proc_update_handler,
304 .extra1 = &min_sched_granularity_ns,
305 .extra2 = &max_sched_granularity_ns,
308 .procname = "sched_wakeup_granularity_ns",
309 .data = &sysctl_sched_wakeup_granularity,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = sched_proc_update_handler,
313 .extra1 = &min_wakeup_granularity_ns,
314 .extra2 = &max_wakeup_granularity_ns,
316 #ifdef CONFIG_SMP
318 .procname = "sched_tunable_scaling",
319 .data = &sysctl_sched_tunable_scaling,
320 .maxlen = sizeof(enum sched_tunable_scaling),
321 .mode = 0644,
322 .proc_handler = sched_proc_update_handler,
323 .extra1 = &min_sched_tunable_scaling,
324 .extra2 = &max_sched_tunable_scaling,
327 .procname = "sched_migration_cost_ns",
328 .data = &sysctl_sched_migration_cost,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec,
334 .procname = "sched_nr_migrate",
335 .data = &sysctl_sched_nr_migrate,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec,
341 .procname = "sched_time_avg_ms",
342 .data = &sysctl_sched_time_avg,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = proc_dointvec,
348 .procname = "sched_shares_window_ns",
349 .data = &sysctl_sched_shares_window,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = proc_dointvec,
355 .procname = "timer_migration",
356 .data = &sysctl_timer_migration,
357 .maxlen = sizeof(unsigned int),
358 .mode = 0644,
359 .proc_handler = proc_dointvec_minmax,
360 .extra1 = &zero,
361 .extra2 = &one,
363 #endif /* CONFIG_SMP */
364 #ifdef CONFIG_NUMA_BALANCING
366 .procname = "numa_balancing_scan_delay_ms",
367 .data = &sysctl_numa_balancing_scan_delay,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
370 .proc_handler = proc_dointvec,
373 .procname = "numa_balancing_scan_period_min_ms",
374 .data = &sysctl_numa_balancing_scan_period_min,
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,
394 .procname = "numa_balancing",
395 .data = NULL, /* filled in by handler */
396 .maxlen = sizeof(unsigned int),
397 .mode = 0644,
398 .proc_handler = sysctl_numa_balancing,
399 .extra1 = &zero,
400 .extra2 = &one,
402 #endif /* CONFIG_NUMA_BALANCING */
403 #endif /* CONFIG_SCHED_DEBUG */
405 .procname = "sched_rt_period_us",
406 .data = &sysctl_sched_rt_period,
407 .maxlen = sizeof(unsigned int),
408 .mode = 0644,
409 .proc_handler = sched_rt_handler,
412 .procname = "sched_rt_runtime_us",
413 .data = &sysctl_sched_rt_runtime,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = sched_rt_handler,
419 .procname = "sched_rr_timeslice_ms",
420 .data = &sched_rr_timeslice,
421 .maxlen = sizeof(int),
422 .mode = 0644,
423 .proc_handler = sched_rr_handler,
425 #ifdef CONFIG_SCHED_AUTOGROUP
427 .procname = "sched_autogroup_enabled",
428 .data = &sysctl_sched_autogroup_enabled,
429 .maxlen = sizeof(unsigned int),
430 .mode = 0644,
431 .proc_handler = proc_dointvec_minmax,
432 .extra1 = &zero,
433 .extra2 = &one,
435 #endif
436 #ifdef CONFIG_CFS_BANDWIDTH
438 .procname = "sched_cfs_bandwidth_slice_us",
439 .data = &sysctl_sched_cfs_bandwidth_slice,
440 .maxlen = sizeof(unsigned int),
441 .mode = 0644,
442 .proc_handler = proc_dointvec_minmax,
443 .extra1 = &one,
445 #endif
446 #ifdef CONFIG_PROVE_LOCKING
448 .procname = "prove_locking",
449 .data = &prove_locking,
450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = proc_dointvec,
454 #endif
455 #ifdef CONFIG_LOCK_STAT
457 .procname = "lock_stat",
458 .data = &lock_stat,
459 .maxlen = sizeof(int),
460 .mode = 0644,
461 .proc_handler = proc_dointvec,
463 #endif
465 .procname = "panic",
466 .data = &panic_timeout,
467 .maxlen = sizeof(int),
468 .mode = 0644,
469 .proc_handler = proc_dointvec,
471 #ifdef CONFIG_COREDUMP
473 .procname = "core_uses_pid",
474 .data = &core_uses_pid,
475 .maxlen = sizeof(int),
476 .mode = 0644,
477 .proc_handler = proc_dointvec,
480 .procname = "core_pattern",
481 .data = core_pattern,
482 .maxlen = CORENAME_MAX_SIZE,
483 .mode = 0644,
484 .proc_handler = proc_dostring_coredump,
487 .procname = "core_pipe_limit",
488 .data = &core_pipe_limit,
489 .maxlen = sizeof(unsigned int),
490 .mode = 0644,
491 .proc_handler = proc_dointvec,
493 #endif
494 #ifdef CONFIG_PROC_SYSCTL
496 .procname = "tainted",
497 .maxlen = sizeof(long),
498 .mode = 0644,
499 .proc_handler = proc_taint,
502 .procname = "sysctl_writes_strict",
503 .data = &sysctl_writes_strict,
504 .maxlen = sizeof(int),
505 .mode = 0644,
506 .proc_handler = proc_dointvec_minmax,
507 .extra1 = &neg_one,
508 .extra2 = &one,
510 #endif
511 #ifdef CONFIG_LATENCYTOP
513 .procname = "latencytop",
514 .data = &latencytop_enabled,
515 .maxlen = sizeof(int),
516 .mode = 0644,
517 .proc_handler = proc_dointvec,
519 #endif
520 #ifdef CONFIG_BLK_DEV_INITRD
522 .procname = "real-root-dev",
523 .data = &real_root_dev,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = proc_dointvec,
528 #endif
530 .procname = "print-fatal-signals",
531 .data = &print_fatal_signals,
532 .maxlen = sizeof(int),
533 .mode = 0644,
534 .proc_handler = proc_dointvec,
536 #ifdef CONFIG_SPARC
538 .procname = "reboot-cmd",
539 .data = reboot_command,
540 .maxlen = 256,
541 .mode = 0644,
542 .proc_handler = proc_dostring,
545 .procname = "stop-a",
546 .data = &stop_a_enabled,
547 .maxlen = sizeof (int),
548 .mode = 0644,
549 .proc_handler = proc_dointvec,
552 .procname = "scons-poweroff",
553 .data = &scons_pwroff,
554 .maxlen = sizeof (int),
555 .mode = 0644,
556 .proc_handler = proc_dointvec,
558 #endif
559 #ifdef CONFIG_SPARC64
561 .procname = "tsb-ratio",
562 .data = &sysctl_tsb_ratio,
563 .maxlen = sizeof (int),
564 .mode = 0644,
565 .proc_handler = proc_dointvec,
567 #endif
568 #ifdef __hppa__
570 .procname = "soft-power",
571 .data = &pwrsw_enabled,
572 .maxlen = sizeof (int),
573 .mode = 0644,
574 .proc_handler = proc_dointvec,
576 #endif
577 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
579 .procname = "unaligned-trap",
580 .data = &unaligned_enabled,
581 .maxlen = sizeof (int),
582 .mode = 0644,
583 .proc_handler = proc_dointvec,
585 #endif
587 .procname = "ctrl-alt-del",
588 .data = &C_A_D,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = proc_dointvec,
593 #ifdef CONFIG_FUNCTION_TRACER
595 .procname = "ftrace_enabled",
596 .data = &ftrace_enabled,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = ftrace_enable_sysctl,
601 #endif
602 #ifdef CONFIG_STACK_TRACER
604 .procname = "stack_tracer_enabled",
605 .data = &stack_tracer_enabled,
606 .maxlen = sizeof(int),
607 .mode = 0644,
608 .proc_handler = stack_trace_sysctl,
610 #endif
611 #ifdef CONFIG_TRACING
613 .procname = "ftrace_dump_on_oops",
614 .data = &ftrace_dump_on_oops,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = proc_dointvec,
620 .procname = "traceoff_on_warning",
621 .data = &__disable_trace_on_warning,
622 .maxlen = sizeof(__disable_trace_on_warning),
623 .mode = 0644,
624 .proc_handler = proc_dointvec,
626 #endif
627 #ifdef CONFIG_KEXEC
629 .procname = "kexec_load_disabled",
630 .data = &kexec_load_disabled,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 /* only handle a transition from default "0" to "1" */
634 .proc_handler = proc_dointvec_minmax,
635 .extra1 = &one,
636 .extra2 = &one,
638 #endif
639 #ifdef CONFIG_MODULES
641 .procname = "modprobe",
642 .data = &modprobe_path,
643 .maxlen = KMOD_PATH_LEN,
644 .mode = 0644,
645 .proc_handler = proc_dostring,
648 .procname = "modules_disabled",
649 .data = &modules_disabled,
650 .maxlen = sizeof(int),
651 .mode = 0644,
652 /* only handle a transition from default "0" to "1" */
653 .proc_handler = proc_dointvec_minmax,
654 .extra1 = &one,
655 .extra2 = &one,
657 #endif
658 #ifdef CONFIG_UEVENT_HELPER
660 .procname = "hotplug",
661 .data = &uevent_helper,
662 .maxlen = UEVENT_HELPER_PATH_LEN,
663 .mode = 0644,
664 .proc_handler = proc_dostring,
666 #endif
667 #ifdef CONFIG_CHR_DEV_SG
669 .procname = "sg-big-buff",
670 .data = &sg_big_buff,
671 .maxlen = sizeof (int),
672 .mode = 0444,
673 .proc_handler = proc_dointvec,
675 #endif
676 #ifdef CONFIG_BSD_PROCESS_ACCT
678 .procname = "acct",
679 .data = &acct_parm,
680 .maxlen = 3*sizeof(int),
681 .mode = 0644,
682 .proc_handler = proc_dointvec,
684 #endif
685 #ifdef CONFIG_MAGIC_SYSRQ
687 .procname = "sysrq",
688 .data = &__sysrq_enabled,
689 .maxlen = sizeof (int),
690 .mode = 0644,
691 .proc_handler = sysrq_sysctl_handler,
693 #endif
694 #ifdef CONFIG_PROC_SYSCTL
696 .procname = "cad_pid",
697 .data = NULL,
698 .maxlen = sizeof (int),
699 .mode = 0600,
700 .proc_handler = proc_do_cad_pid,
702 #endif
704 .procname = "threads-max",
705 .data = &max_threads,
706 .maxlen = sizeof(int),
707 .mode = 0644,
708 .proc_handler = proc_dointvec,
711 .procname = "random",
712 .mode = 0555,
713 .child = random_table,
716 .procname = "usermodehelper",
717 .mode = 0555,
718 .child = usermodehelper_table,
721 .procname = "overflowuid",
722 .data = &overflowuid,
723 .maxlen = sizeof(int),
724 .mode = 0644,
725 .proc_handler = proc_dointvec_minmax,
726 .extra1 = &minolduid,
727 .extra2 = &maxolduid,
730 .procname = "overflowgid",
731 .data = &overflowgid,
732 .maxlen = sizeof(int),
733 .mode = 0644,
734 .proc_handler = proc_dointvec_minmax,
735 .extra1 = &minolduid,
736 .extra2 = &maxolduid,
738 #ifdef CONFIG_S390
739 #ifdef CONFIG_MATHEMU
741 .procname = "ieee_emulation_warnings",
742 .data = &sysctl_ieee_emulation_warnings,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = proc_dointvec,
747 #endif
749 .procname = "userprocess_debug",
750 .data = &show_unhandled_signals,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = proc_dointvec,
755 #endif
757 .procname = "pid_max",
758 .data = &pid_max,
759 .maxlen = sizeof (int),
760 .mode = 0644,
761 .proc_handler = proc_dointvec_minmax,
762 .extra1 = &pid_max_min,
763 .extra2 = &pid_max_max,
766 .procname = "panic_on_oops",
767 .data = &panic_on_oops,
768 .maxlen = sizeof(int),
769 .mode = 0644,
770 .proc_handler = proc_dointvec,
772 #if defined CONFIG_PRINTK
774 .procname = "printk",
775 .data = &console_loglevel,
776 .maxlen = 4*sizeof(int),
777 .mode = 0644,
778 .proc_handler = proc_dointvec,
781 .procname = "printk_ratelimit",
782 .data = &printk_ratelimit_state.interval,
783 .maxlen = sizeof(int),
784 .mode = 0644,
785 .proc_handler = proc_dointvec_jiffies,
788 .procname = "printk_ratelimit_burst",
789 .data = &printk_ratelimit_state.burst,
790 .maxlen = sizeof(int),
791 .mode = 0644,
792 .proc_handler = proc_dointvec,
795 .procname = "printk_delay",
796 .data = &printk_delay_msec,
797 .maxlen = sizeof(int),
798 .mode = 0644,
799 .proc_handler = proc_dointvec_minmax,
800 .extra1 = &zero,
801 .extra2 = &ten_thousand,
804 .procname = "dmesg_restrict",
805 .data = &dmesg_restrict,
806 .maxlen = sizeof(int),
807 .mode = 0644,
808 .proc_handler = proc_dointvec_minmax_sysadmin,
809 .extra1 = &zero,
810 .extra2 = &one,
813 .procname = "kptr_restrict",
814 .data = &kptr_restrict,
815 .maxlen = sizeof(int),
816 .mode = 0644,
817 .proc_handler = proc_dointvec_minmax_sysadmin,
818 .extra1 = &zero,
819 .extra2 = &two,
821 #endif
823 .procname = "ngroups_max",
824 .data = &ngroups_max,
825 .maxlen = sizeof (int),
826 .mode = 0444,
827 .proc_handler = proc_dointvec,
830 .procname = "cap_last_cap",
831 .data = (void *)&cap_last_cap,
832 .maxlen = sizeof(int),
833 .mode = 0444,
834 .proc_handler = proc_dointvec,
836 #if defined(CONFIG_LOCKUP_DETECTOR)
838 .procname = "watchdog",
839 .data = &watchdog_user_enabled,
840 .maxlen = sizeof (int),
841 .mode = 0644,
842 .proc_handler = proc_dowatchdog,
843 .extra1 = &zero,
844 .extra2 = &one,
847 .procname = "watchdog_thresh",
848 .data = &watchdog_thresh,
849 .maxlen = sizeof(int),
850 .mode = 0644,
851 .proc_handler = proc_dowatchdog,
852 .extra1 = &zero,
853 .extra2 = &sixty,
856 .procname = "softlockup_panic",
857 .data = &softlockup_panic,
858 .maxlen = sizeof(int),
859 .mode = 0644,
860 .proc_handler = proc_dointvec_minmax,
861 .extra1 = &zero,
862 .extra2 = &one,
865 .procname = "nmi_watchdog",
866 .data = &watchdog_user_enabled,
867 .maxlen = sizeof (int),
868 .mode = 0644,
869 .proc_handler = proc_dowatchdog,
870 .extra1 = &zero,
871 .extra2 = &one,
873 #endif
874 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
876 .procname = "unknown_nmi_panic",
877 .data = &unknown_nmi_panic,
878 .maxlen = sizeof (int),
879 .mode = 0644,
880 .proc_handler = proc_dointvec,
882 #endif
883 #if defined(CONFIG_X86)
885 .procname = "panic_on_unrecovered_nmi",
886 .data = &panic_on_unrecovered_nmi,
887 .maxlen = sizeof(int),
888 .mode = 0644,
889 .proc_handler = proc_dointvec,
892 .procname = "panic_on_io_nmi",
893 .data = &panic_on_io_nmi,
894 .maxlen = sizeof(int),
895 .mode = 0644,
896 .proc_handler = proc_dointvec,
898 #ifdef CONFIG_DEBUG_STACKOVERFLOW
900 .procname = "panic_on_stackoverflow",
901 .data = &sysctl_panic_on_stackoverflow,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = proc_dointvec,
906 #endif
908 .procname = "bootloader_type",
909 .data = &bootloader_type,
910 .maxlen = sizeof (int),
911 .mode = 0444,
912 .proc_handler = proc_dointvec,
915 .procname = "bootloader_version",
916 .data = &bootloader_version,
917 .maxlen = sizeof (int),
918 .mode = 0444,
919 .proc_handler = proc_dointvec,
922 .procname = "kstack_depth_to_print",
923 .data = &kstack_depth_to_print,
924 .maxlen = sizeof(int),
925 .mode = 0644,
926 .proc_handler = proc_dointvec,
929 .procname = "io_delay_type",
930 .data = &io_delay_type,
931 .maxlen = sizeof(int),
932 .mode = 0644,
933 .proc_handler = proc_dointvec,
935 #endif
936 #if defined(CONFIG_MMU)
938 .procname = "randomize_va_space",
939 .data = &randomize_va_space,
940 .maxlen = sizeof(int),
941 .mode = 0644,
942 .proc_handler = proc_dointvec,
944 #endif
945 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
947 .procname = "spin_retry",
948 .data = &spin_retry,
949 .maxlen = sizeof (int),
950 .mode = 0644,
951 .proc_handler = proc_dointvec,
953 #endif
954 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
956 .procname = "acpi_video_flags",
957 .data = &acpi_realmode_flags,
958 .maxlen = sizeof (unsigned long),
959 .mode = 0644,
960 .proc_handler = proc_doulongvec_minmax,
962 #endif
963 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
965 .procname = "ignore-unaligned-usertrap",
966 .data = &no_unaligned_warning,
967 .maxlen = sizeof (int),
968 .mode = 0644,
969 .proc_handler = proc_dointvec,
971 #endif
972 #ifdef CONFIG_IA64
974 .procname = "unaligned-dump-stack",
975 .data = &unaligned_dump_stack,
976 .maxlen = sizeof (int),
977 .mode = 0644,
978 .proc_handler = proc_dointvec,
980 #endif
981 #ifdef CONFIG_DETECT_HUNG_TASK
983 .procname = "hung_task_panic",
984 .data = &sysctl_hung_task_panic,
985 .maxlen = sizeof(int),
986 .mode = 0644,
987 .proc_handler = proc_dointvec_minmax,
988 .extra1 = &zero,
989 .extra2 = &one,
992 .procname = "hung_task_check_count",
993 .data = &sysctl_hung_task_check_count,
994 .maxlen = sizeof(int),
995 .mode = 0644,
996 .proc_handler = proc_dointvec_minmax,
997 .extra1 = &zero,
1000 .procname = "hung_task_timeout_secs",
1001 .data = &sysctl_hung_task_timeout_secs,
1002 .maxlen = sizeof(unsigned long),
1003 .mode = 0644,
1004 .proc_handler = proc_dohung_task_timeout_secs,
1005 .extra2 = &hung_task_timeout_max,
1008 .procname = "hung_task_warnings",
1009 .data = &sysctl_hung_task_warnings,
1010 .maxlen = sizeof(int),
1011 .mode = 0644,
1012 .proc_handler = proc_dointvec_minmax,
1013 .extra1 = &neg_one,
1015 #endif
1016 #ifdef CONFIG_COMPAT
1018 .procname = "compat-log",
1019 .data = &compat_log,
1020 .maxlen = sizeof (int),
1021 .mode = 0644,
1022 .proc_handler = proc_dointvec,
1024 #endif
1025 #ifdef CONFIG_RT_MUTEXES
1027 .procname = "max_lock_depth",
1028 .data = &max_lock_depth,
1029 .maxlen = sizeof(int),
1030 .mode = 0644,
1031 .proc_handler = proc_dointvec,
1033 #endif
1035 .procname = "poweroff_cmd",
1036 .data = &poweroff_cmd,
1037 .maxlen = POWEROFF_CMD_PATH_LEN,
1038 .mode = 0644,
1039 .proc_handler = proc_dostring,
1041 #ifdef CONFIG_KEYS
1043 .procname = "keys",
1044 .mode = 0555,
1045 .child = key_sysctls,
1047 #endif
1048 #ifdef CONFIG_RCU_TORTURE_TEST
1050 .procname = "rcutorture_runnable",
1051 .data = &rcutorture_runnable,
1052 .maxlen = sizeof(int),
1053 .mode = 0644,
1054 .proc_handler = proc_dointvec,
1056 #endif
1057 #ifdef CONFIG_PERF_EVENTS
1059 * User-space scripts rely on the existence of this file
1060 * as a feature check for perf_events being enabled.
1062 * So it's an ABI, do not remove!
1065 .procname = "perf_event_paranoid",
1066 .data = &sysctl_perf_event_paranoid,
1067 .maxlen = sizeof(sysctl_perf_event_paranoid),
1068 .mode = 0644,
1069 .proc_handler = proc_dointvec,
1072 .procname = "perf_event_mlock_kb",
1073 .data = &sysctl_perf_event_mlock,
1074 .maxlen = sizeof(sysctl_perf_event_mlock),
1075 .mode = 0644,
1076 .proc_handler = proc_dointvec,
1079 .procname = "perf_event_max_sample_rate",
1080 .data = &sysctl_perf_event_sample_rate,
1081 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1082 .mode = 0644,
1083 .proc_handler = perf_proc_update_handler,
1084 .extra1 = &one,
1087 .procname = "perf_cpu_time_max_percent",
1088 .data = &sysctl_perf_cpu_time_max_percent,
1089 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1090 .mode = 0644,
1091 .proc_handler = perf_cpu_time_max_percent_handler,
1092 .extra1 = &zero,
1093 .extra2 = &one_hundred,
1095 #endif
1096 #ifdef CONFIG_KMEMCHECK
1098 .procname = "kmemcheck",
1099 .data = &kmemcheck_enabled,
1100 .maxlen = sizeof(int),
1101 .mode = 0644,
1102 .proc_handler = proc_dointvec,
1104 #endif
1108 static struct ctl_table vm_table[] = {
1110 .procname = "overcommit_memory",
1111 .data = &sysctl_overcommit_memory,
1112 .maxlen = sizeof(sysctl_overcommit_memory),
1113 .mode = 0644,
1114 .proc_handler = proc_dointvec_minmax,
1115 .extra1 = &zero,
1116 .extra2 = &two,
1119 .procname = "panic_on_oom",
1120 .data = &sysctl_panic_on_oom,
1121 .maxlen = sizeof(sysctl_panic_on_oom),
1122 .mode = 0644,
1123 .proc_handler = proc_dointvec_minmax,
1124 .extra1 = &zero,
1125 .extra2 = &two,
1128 .procname = "oom_kill_allocating_task",
1129 .data = &sysctl_oom_kill_allocating_task,
1130 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1131 .mode = 0644,
1132 .proc_handler = proc_dointvec,
1135 .procname = "oom_dump_tasks",
1136 .data = &sysctl_oom_dump_tasks,
1137 .maxlen = sizeof(sysctl_oom_dump_tasks),
1138 .mode = 0644,
1139 .proc_handler = proc_dointvec,
1142 .procname = "overcommit_ratio",
1143 .data = &sysctl_overcommit_ratio,
1144 .maxlen = sizeof(sysctl_overcommit_ratio),
1145 .mode = 0644,
1146 .proc_handler = overcommit_ratio_handler,
1149 .procname = "overcommit_kbytes",
1150 .data = &sysctl_overcommit_kbytes,
1151 .maxlen = sizeof(sysctl_overcommit_kbytes),
1152 .mode = 0644,
1153 .proc_handler = overcommit_kbytes_handler,
1156 .procname = "page-cluster",
1157 .data = &page_cluster,
1158 .maxlen = sizeof(int),
1159 .mode = 0644,
1160 .proc_handler = proc_dointvec_minmax,
1161 .extra1 = &zero,
1164 .procname = "dirty_background_ratio",
1165 .data = &dirty_background_ratio,
1166 .maxlen = sizeof(dirty_background_ratio),
1167 .mode = 0644,
1168 .proc_handler = dirty_background_ratio_handler,
1169 .extra1 = &zero,
1170 .extra2 = &one_hundred,
1173 .procname = "dirty_background_bytes",
1174 .data = &dirty_background_bytes,
1175 .maxlen = sizeof(dirty_background_bytes),
1176 .mode = 0644,
1177 .proc_handler = dirty_background_bytes_handler,
1178 .extra1 = &one_ul,
1181 .procname = "dirty_ratio",
1182 .data = &vm_dirty_ratio,
1183 .maxlen = sizeof(vm_dirty_ratio),
1184 .mode = 0644,
1185 .proc_handler = dirty_ratio_handler,
1186 .extra1 = &zero,
1187 .extra2 = &one_hundred,
1190 .procname = "dirty_bytes",
1191 .data = &vm_dirty_bytes,
1192 .maxlen = sizeof(vm_dirty_bytes),
1193 .mode = 0644,
1194 .proc_handler = dirty_bytes_handler,
1195 .extra1 = &dirty_bytes_min,
1198 .procname = "dirty_writeback_centisecs",
1199 .data = &dirty_writeback_interval,
1200 .maxlen = sizeof(dirty_writeback_interval),
1201 .mode = 0644,
1202 .proc_handler = dirty_writeback_centisecs_handler,
1205 .procname = "dirty_expire_centisecs",
1206 .data = &dirty_expire_interval,
1207 .maxlen = sizeof(dirty_expire_interval),
1208 .mode = 0644,
1209 .proc_handler = proc_dointvec_minmax,
1210 .extra1 = &zero,
1213 .procname = "nr_pdflush_threads",
1214 .mode = 0444 /* read-only */,
1215 .proc_handler = pdflush_proc_obsolete,
1218 .procname = "swappiness",
1219 .data = &vm_swappiness,
1220 .maxlen = sizeof(vm_swappiness),
1221 .mode = 0644,
1222 .proc_handler = proc_dointvec_minmax,
1223 .extra1 = &zero,
1224 .extra2 = &one_hundred,
1226 #ifdef CONFIG_HUGETLB_PAGE
1228 .procname = "nr_hugepages",
1229 .data = NULL,
1230 .maxlen = sizeof(unsigned long),
1231 .mode = 0644,
1232 .proc_handler = hugetlb_sysctl_handler,
1233 .extra1 = (void *)&hugetlb_zero,
1234 .extra2 = (void *)&hugetlb_infinity,
1236 #ifdef CONFIG_NUMA
1238 .procname = "nr_hugepages_mempolicy",
1239 .data = NULL,
1240 .maxlen = sizeof(unsigned long),
1241 .mode = 0644,
1242 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1243 .extra1 = (void *)&hugetlb_zero,
1244 .extra2 = (void *)&hugetlb_infinity,
1246 #endif
1248 .procname = "hugetlb_shm_group",
1249 .data = &sysctl_hugetlb_shm_group,
1250 .maxlen = sizeof(gid_t),
1251 .mode = 0644,
1252 .proc_handler = proc_dointvec,
1255 .procname = "hugepages_treat_as_movable",
1256 .data = &hugepages_treat_as_movable,
1257 .maxlen = sizeof(int),
1258 .mode = 0644,
1259 .proc_handler = proc_dointvec,
1262 .procname = "nr_overcommit_hugepages",
1263 .data = NULL,
1264 .maxlen = sizeof(unsigned long),
1265 .mode = 0644,
1266 .proc_handler = hugetlb_overcommit_handler,
1267 .extra1 = (void *)&hugetlb_zero,
1268 .extra2 = (void *)&hugetlb_infinity,
1270 #endif
1272 .procname = "lowmem_reserve_ratio",
1273 .data = &sysctl_lowmem_reserve_ratio,
1274 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1275 .mode = 0644,
1276 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1279 .procname = "drop_caches",
1280 .data = &sysctl_drop_caches,
1281 .maxlen = sizeof(int),
1282 .mode = 0644,
1283 .proc_handler = drop_caches_sysctl_handler,
1284 .extra1 = &one,
1285 .extra2 = &four,
1287 #ifdef CONFIG_COMPACTION
1289 .procname = "compact_memory",
1290 .data = &sysctl_compact_memory,
1291 .maxlen = sizeof(int),
1292 .mode = 0200,
1293 .proc_handler = sysctl_compaction_handler,
1296 .procname = "extfrag_threshold",
1297 .data = &sysctl_extfrag_threshold,
1298 .maxlen = sizeof(int),
1299 .mode = 0644,
1300 .proc_handler = sysctl_extfrag_handler,
1301 .extra1 = &min_extfrag_threshold,
1302 .extra2 = &max_extfrag_threshold,
1305 #endif /* CONFIG_COMPACTION */
1307 .procname = "min_free_kbytes",
1308 .data = &min_free_kbytes,
1309 .maxlen = sizeof(min_free_kbytes),
1310 .mode = 0644,
1311 .proc_handler = min_free_kbytes_sysctl_handler,
1312 .extra1 = &zero,
1315 .procname = "percpu_pagelist_fraction",
1316 .data = &percpu_pagelist_fraction,
1317 .maxlen = sizeof(percpu_pagelist_fraction),
1318 .mode = 0644,
1319 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1320 .extra1 = &min_percpu_pagelist_fract,
1322 #ifdef CONFIG_MMU
1324 .procname = "max_map_count",
1325 .data = &sysctl_max_map_count,
1326 .maxlen = sizeof(sysctl_max_map_count),
1327 .mode = 0644,
1328 .proc_handler = proc_dointvec_minmax,
1329 .extra1 = &zero,
1331 #else
1333 .procname = "nr_trim_pages",
1334 .data = &sysctl_nr_trim_pages,
1335 .maxlen = sizeof(sysctl_nr_trim_pages),
1336 .mode = 0644,
1337 .proc_handler = proc_dointvec_minmax,
1338 .extra1 = &zero,
1340 #endif
1342 .procname = "laptop_mode",
1343 .data = &laptop_mode,
1344 .maxlen = sizeof(laptop_mode),
1345 .mode = 0644,
1346 .proc_handler = proc_dointvec_jiffies,
1349 .procname = "block_dump",
1350 .data = &block_dump,
1351 .maxlen = sizeof(block_dump),
1352 .mode = 0644,
1353 .proc_handler = proc_dointvec,
1354 .extra1 = &zero,
1357 .procname = "vfs_cache_pressure",
1358 .data = &sysctl_vfs_cache_pressure,
1359 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1360 .mode = 0644,
1361 .proc_handler = proc_dointvec,
1362 .extra1 = &zero,
1364 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1366 .procname = "legacy_va_layout",
1367 .data = &sysctl_legacy_va_layout,
1368 .maxlen = sizeof(sysctl_legacy_va_layout),
1369 .mode = 0644,
1370 .proc_handler = proc_dointvec,
1371 .extra1 = &zero,
1373 #endif
1374 #ifdef CONFIG_NUMA
1376 .procname = "zone_reclaim_mode",
1377 .data = &zone_reclaim_mode,
1378 .maxlen = sizeof(zone_reclaim_mode),
1379 .mode = 0644,
1380 .proc_handler = proc_dointvec,
1381 .extra1 = &zero,
1384 .procname = "min_unmapped_ratio",
1385 .data = &sysctl_min_unmapped_ratio,
1386 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1387 .mode = 0644,
1388 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1389 .extra1 = &zero,
1390 .extra2 = &one_hundred,
1393 .procname = "min_slab_ratio",
1394 .data = &sysctl_min_slab_ratio,
1395 .maxlen = sizeof(sysctl_min_slab_ratio),
1396 .mode = 0644,
1397 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1398 .extra1 = &zero,
1399 .extra2 = &one_hundred,
1401 #endif
1402 #ifdef CONFIG_SMP
1404 .procname = "stat_interval",
1405 .data = &sysctl_stat_interval,
1406 .maxlen = sizeof(sysctl_stat_interval),
1407 .mode = 0644,
1408 .proc_handler = proc_dointvec_jiffies,
1410 #endif
1411 #ifdef CONFIG_MMU
1413 .procname = "mmap_min_addr",
1414 .data = &dac_mmap_min_addr,
1415 .maxlen = sizeof(unsigned long),
1416 .mode = 0644,
1417 .proc_handler = mmap_min_addr_handler,
1419 #endif
1420 #ifdef CONFIG_NUMA
1422 .procname = "numa_zonelist_order",
1423 .data = &numa_zonelist_order,
1424 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1425 .mode = 0644,
1426 .proc_handler = numa_zonelist_order_handler,
1428 #endif
1429 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1430 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1432 .procname = "vdso_enabled",
1433 #ifdef CONFIG_X86_32
1434 .data = &vdso32_enabled,
1435 .maxlen = sizeof(vdso32_enabled),
1436 #else
1437 .data = &vdso_enabled,
1438 .maxlen = sizeof(vdso_enabled),
1439 #endif
1440 .mode = 0644,
1441 .proc_handler = proc_dointvec,
1442 .extra1 = &zero,
1444 #endif
1445 #ifdef CONFIG_HIGHMEM
1447 .procname = "highmem_is_dirtyable",
1448 .data = &vm_highmem_is_dirtyable,
1449 .maxlen = sizeof(vm_highmem_is_dirtyable),
1450 .mode = 0644,
1451 .proc_handler = proc_dointvec_minmax,
1452 .extra1 = &zero,
1453 .extra2 = &one,
1455 #endif
1457 .procname = "scan_unevictable_pages",
1458 .data = &scan_unevictable_pages,
1459 .maxlen = sizeof(scan_unevictable_pages),
1460 .mode = 0644,
1461 .proc_handler = scan_unevictable_handler,
1463 #ifdef CONFIG_MEMORY_FAILURE
1465 .procname = "memory_failure_early_kill",
1466 .data = &sysctl_memory_failure_early_kill,
1467 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1468 .mode = 0644,
1469 .proc_handler = proc_dointvec_minmax,
1470 .extra1 = &zero,
1471 .extra2 = &one,
1474 .procname = "memory_failure_recovery",
1475 .data = &sysctl_memory_failure_recovery,
1476 .maxlen = sizeof(sysctl_memory_failure_recovery),
1477 .mode = 0644,
1478 .proc_handler = proc_dointvec_minmax,
1479 .extra1 = &zero,
1480 .extra2 = &one,
1482 #endif
1484 .procname = "user_reserve_kbytes",
1485 .data = &sysctl_user_reserve_kbytes,
1486 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1487 .mode = 0644,
1488 .proc_handler = proc_doulongvec_minmax,
1491 .procname = "admin_reserve_kbytes",
1492 .data = &sysctl_admin_reserve_kbytes,
1493 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1494 .mode = 0644,
1495 .proc_handler = proc_doulongvec_minmax,
1500 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1501 static struct ctl_table binfmt_misc_table[] = {
1504 #endif
1506 static struct ctl_table fs_table[] = {
1508 .procname = "inode-nr",
1509 .data = &inodes_stat,
1510 .maxlen = 2*sizeof(long),
1511 .mode = 0444,
1512 .proc_handler = proc_nr_inodes,
1515 .procname = "inode-state",
1516 .data = &inodes_stat,
1517 .maxlen = 7*sizeof(long),
1518 .mode = 0444,
1519 .proc_handler = proc_nr_inodes,
1522 .procname = "file-nr",
1523 .data = &files_stat,
1524 .maxlen = sizeof(files_stat),
1525 .mode = 0444,
1526 .proc_handler = proc_nr_files,
1529 .procname = "file-max",
1530 .data = &files_stat.max_files,
1531 .maxlen = sizeof(files_stat.max_files),
1532 .mode = 0644,
1533 .proc_handler = proc_doulongvec_minmax,
1536 .procname = "nr_open",
1537 .data = &sysctl_nr_open,
1538 .maxlen = sizeof(int),
1539 .mode = 0644,
1540 .proc_handler = proc_dointvec_minmax,
1541 .extra1 = &sysctl_nr_open_min,
1542 .extra2 = &sysctl_nr_open_max,
1545 .procname = "dentry-state",
1546 .data = &dentry_stat,
1547 .maxlen = 6*sizeof(long),
1548 .mode = 0444,
1549 .proc_handler = proc_nr_dentry,
1552 .procname = "overflowuid",
1553 .data = &fs_overflowuid,
1554 .maxlen = sizeof(int),
1555 .mode = 0644,
1556 .proc_handler = proc_dointvec_minmax,
1557 .extra1 = &minolduid,
1558 .extra2 = &maxolduid,
1561 .procname = "overflowgid",
1562 .data = &fs_overflowgid,
1563 .maxlen = sizeof(int),
1564 .mode = 0644,
1565 .proc_handler = proc_dointvec_minmax,
1566 .extra1 = &minolduid,
1567 .extra2 = &maxolduid,
1569 #ifdef CONFIG_FILE_LOCKING
1571 .procname = "leases-enable",
1572 .data = &leases_enable,
1573 .maxlen = sizeof(int),
1574 .mode = 0644,
1575 .proc_handler = proc_dointvec,
1577 #endif
1578 #ifdef CONFIG_DNOTIFY
1580 .procname = "dir-notify-enable",
1581 .data = &dir_notify_enable,
1582 .maxlen = sizeof(int),
1583 .mode = 0644,
1584 .proc_handler = proc_dointvec,
1586 #endif
1587 #ifdef CONFIG_MMU
1588 #ifdef CONFIG_FILE_LOCKING
1590 .procname = "lease-break-time",
1591 .data = &lease_break_time,
1592 .maxlen = sizeof(int),
1593 .mode = 0644,
1594 .proc_handler = proc_dointvec,
1596 #endif
1597 #ifdef CONFIG_AIO
1599 .procname = "aio-nr",
1600 .data = &aio_nr,
1601 .maxlen = sizeof(aio_nr),
1602 .mode = 0444,
1603 .proc_handler = proc_doulongvec_minmax,
1606 .procname = "aio-max-nr",
1607 .data = &aio_max_nr,
1608 .maxlen = sizeof(aio_max_nr),
1609 .mode = 0644,
1610 .proc_handler = proc_doulongvec_minmax,
1612 #endif /* CONFIG_AIO */
1613 #ifdef CONFIG_INOTIFY_USER
1615 .procname = "inotify",
1616 .mode = 0555,
1617 .child = inotify_table,
1619 #endif
1620 #ifdef CONFIG_EPOLL
1622 .procname = "epoll",
1623 .mode = 0555,
1624 .child = epoll_table,
1626 #endif
1627 #endif
1629 .procname = "protected_symlinks",
1630 .data = &sysctl_protected_symlinks,
1631 .maxlen = sizeof(int),
1632 .mode = 0600,
1633 .proc_handler = proc_dointvec_minmax,
1634 .extra1 = &zero,
1635 .extra2 = &one,
1638 .procname = "protected_hardlinks",
1639 .data = &sysctl_protected_hardlinks,
1640 .maxlen = sizeof(int),
1641 .mode = 0600,
1642 .proc_handler = proc_dointvec_minmax,
1643 .extra1 = &zero,
1644 .extra2 = &one,
1647 .procname = "suid_dumpable",
1648 .data = &suid_dumpable,
1649 .maxlen = sizeof(int),
1650 .mode = 0644,
1651 .proc_handler = proc_dointvec_minmax_coredump,
1652 .extra1 = &zero,
1653 .extra2 = &two,
1655 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1657 .procname = "binfmt_misc",
1658 .mode = 0555,
1659 .child = binfmt_misc_table,
1661 #endif
1663 .procname = "pipe-max-size",
1664 .data = &pipe_max_size,
1665 .maxlen = sizeof(int),
1666 .mode = 0644,
1667 .proc_handler = &pipe_proc_fn,
1668 .extra1 = &pipe_min_size,
1673 static struct ctl_table debug_table[] = {
1674 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1676 .procname = "exception-trace",
1677 .data = &show_unhandled_signals,
1678 .maxlen = sizeof(int),
1679 .mode = 0644,
1680 .proc_handler = proc_dointvec
1682 #endif
1683 #if defined(CONFIG_OPTPROBES)
1685 .procname = "kprobes-optimization",
1686 .data = &sysctl_kprobes_optimization,
1687 .maxlen = sizeof(int),
1688 .mode = 0644,
1689 .proc_handler = proc_kprobes_optimization_handler,
1690 .extra1 = &zero,
1691 .extra2 = &one,
1693 #endif
1697 static struct ctl_table dev_table[] = {
1701 int __init sysctl_init(void)
1703 struct ctl_table_header *hdr;
1705 hdr = register_sysctl_table(sysctl_base_table);
1706 kmemleak_not_leak(hdr);
1707 return 0;
1710 #endif /* CONFIG_SYSCTL */
1713 * /proc/sys support
1716 #ifdef CONFIG_PROC_SYSCTL
1718 static int _proc_do_string(char *data, int maxlen, int write,
1719 char __user *buffer,
1720 size_t *lenp, loff_t *ppos)
1722 size_t len;
1723 char __user *p;
1724 char c;
1726 if (!data || !maxlen || !*lenp) {
1727 *lenp = 0;
1728 return 0;
1731 if (write) {
1732 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1733 /* Only continue writes not past the end of buffer. */
1734 len = strlen(data);
1735 if (len > maxlen - 1)
1736 len = maxlen - 1;
1738 if (*ppos > len)
1739 return 0;
1740 len = *ppos;
1741 } else {
1742 /* Start writing from beginning of buffer. */
1743 len = 0;
1746 *ppos += *lenp;
1747 p = buffer;
1748 while ((p - buffer) < *lenp && len < maxlen - 1) {
1749 if (get_user(c, p++))
1750 return -EFAULT;
1751 if (c == 0 || c == '\n')
1752 break;
1753 data[len++] = c;
1755 data[len] = 0;
1756 } else {
1757 len = strlen(data);
1758 if (len > maxlen)
1759 len = maxlen;
1761 if (*ppos > len) {
1762 *lenp = 0;
1763 return 0;
1766 data += *ppos;
1767 len -= *ppos;
1769 if (len > *lenp)
1770 len = *lenp;
1771 if (len)
1772 if (copy_to_user(buffer, data, len))
1773 return -EFAULT;
1774 if (len < *lenp) {
1775 if (put_user('\n', buffer + len))
1776 return -EFAULT;
1777 len++;
1779 *lenp = len;
1780 *ppos += len;
1782 return 0;
1785 static void warn_sysctl_write(struct ctl_table *table)
1787 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1788 "This will not be supported in the future. To silence this\n"
1789 "warning, set kernel.sysctl_writes_strict = -1\n",
1790 current->comm, table->procname);
1794 * proc_dostring - read a string sysctl
1795 * @table: the sysctl table
1796 * @write: %TRUE if this is a write to the sysctl file
1797 * @buffer: the user buffer
1798 * @lenp: the size of the user buffer
1799 * @ppos: file position
1801 * Reads/writes a string from/to the user buffer. If the kernel
1802 * buffer provided is not large enough to hold the string, the
1803 * string is truncated. The copied string is %NULL-terminated.
1804 * If the string is being read by the user process, it is copied
1805 * and a newline '\n' is added. It is truncated if the buffer is
1806 * not large enough.
1808 * Returns 0 on success.
1810 int proc_dostring(struct ctl_table *table, int write,
1811 void __user *buffer, size_t *lenp, loff_t *ppos)
1813 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1814 warn_sysctl_write(table);
1816 return _proc_do_string((char *)(table->data), table->maxlen, write,
1817 (char __user *)buffer, lenp, ppos);
1820 static size_t proc_skip_spaces(char **buf)
1822 size_t ret;
1823 char *tmp = skip_spaces(*buf);
1824 ret = tmp - *buf;
1825 *buf = tmp;
1826 return ret;
1829 static void proc_skip_char(char **buf, size_t *size, const char v)
1831 while (*size) {
1832 if (**buf != v)
1833 break;
1834 (*size)--;
1835 (*buf)++;
1839 #define TMPBUFLEN 22
1841 * proc_get_long - reads an ASCII formatted integer from a user buffer
1843 * @buf: a kernel buffer
1844 * @size: size of the kernel buffer
1845 * @val: this is where the number will be stored
1846 * @neg: set to %TRUE if number is negative
1847 * @perm_tr: a vector which contains the allowed trailers
1848 * @perm_tr_len: size of the perm_tr vector
1849 * @tr: pointer to store the trailer character
1851 * In case of success %0 is returned and @buf and @size are updated with
1852 * the amount of bytes read. If @tr is non-NULL and a trailing
1853 * character exists (size is non-zero after returning from this
1854 * function), @tr is updated with the trailing character.
1856 static int proc_get_long(char **buf, size_t *size,
1857 unsigned long *val, bool *neg,
1858 const char *perm_tr, unsigned perm_tr_len, char *tr)
1860 int len;
1861 char *p, tmp[TMPBUFLEN];
1863 if (!*size)
1864 return -EINVAL;
1866 len = *size;
1867 if (len > TMPBUFLEN - 1)
1868 len = TMPBUFLEN - 1;
1870 memcpy(tmp, *buf, len);
1872 tmp[len] = 0;
1873 p = tmp;
1874 if (*p == '-' && *size > 1) {
1875 *neg = true;
1876 p++;
1877 } else
1878 *neg = false;
1879 if (!isdigit(*p))
1880 return -EINVAL;
1882 *val = simple_strtoul(p, &p, 0);
1884 len = p - tmp;
1886 /* We don't know if the next char is whitespace thus we may accept
1887 * invalid integers (e.g. 1234...a) or two integers instead of one
1888 * (e.g. 123...1). So lets not allow such large numbers. */
1889 if (len == TMPBUFLEN - 1)
1890 return -EINVAL;
1892 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1893 return -EINVAL;
1895 if (tr && (len < *size))
1896 *tr = *p;
1898 *buf += len;
1899 *size -= len;
1901 return 0;
1905 * proc_put_long - converts an integer to a decimal ASCII formatted string
1907 * @buf: the user buffer
1908 * @size: the size of the user buffer
1909 * @val: the integer to be converted
1910 * @neg: sign of the number, %TRUE for negative
1912 * In case of success %0 is returned and @buf and @size are updated with
1913 * the amount of bytes written.
1915 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1916 bool neg)
1918 int len;
1919 char tmp[TMPBUFLEN], *p = tmp;
1921 sprintf(p, "%s%lu", neg ? "-" : "", val);
1922 len = strlen(tmp);
1923 if (len > *size)
1924 len = *size;
1925 if (copy_to_user(*buf, tmp, len))
1926 return -EFAULT;
1927 *size -= len;
1928 *buf += len;
1929 return 0;
1931 #undef TMPBUFLEN
1933 static int proc_put_char(void __user **buf, size_t *size, char c)
1935 if (*size) {
1936 char __user **buffer = (char __user **)buf;
1937 if (put_user(c, *buffer))
1938 return -EFAULT;
1939 (*size)--, (*buffer)++;
1940 *buf = *buffer;
1942 return 0;
1945 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1946 int *valp,
1947 int write, void *data)
1949 if (write) {
1950 *valp = *negp ? -*lvalp : *lvalp;
1951 } else {
1952 int val = *valp;
1953 if (val < 0) {
1954 *negp = true;
1955 *lvalp = (unsigned long)-val;
1956 } else {
1957 *negp = false;
1958 *lvalp = (unsigned long)val;
1961 return 0;
1964 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1966 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1967 int write, void __user *buffer,
1968 size_t *lenp, loff_t *ppos,
1969 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1970 int write, void *data),
1971 void *data)
1973 int *i, vleft, first = 1, err = 0;
1974 unsigned long page = 0;
1975 size_t left;
1976 char *kbuf;
1978 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1979 *lenp = 0;
1980 return 0;
1983 i = (int *) tbl_data;
1984 vleft = table->maxlen / sizeof(*i);
1985 left = *lenp;
1987 if (!conv)
1988 conv = do_proc_dointvec_conv;
1990 if (write) {
1991 if (*ppos) {
1992 switch (sysctl_writes_strict) {
1993 case SYSCTL_WRITES_STRICT:
1994 goto out;
1995 case SYSCTL_WRITES_WARN:
1996 warn_sysctl_write(table);
1997 break;
1998 default:
1999 break;
2003 if (left > PAGE_SIZE - 1)
2004 left = PAGE_SIZE - 1;
2005 page = __get_free_page(GFP_TEMPORARY);
2006 kbuf = (char *) page;
2007 if (!kbuf)
2008 return -ENOMEM;
2009 if (copy_from_user(kbuf, buffer, left)) {
2010 err = -EFAULT;
2011 goto free;
2013 kbuf[left] = 0;
2016 for (; left && vleft--; i++, first=0) {
2017 unsigned long lval;
2018 bool neg;
2020 if (write) {
2021 left -= proc_skip_spaces(&kbuf);
2023 if (!left)
2024 break;
2025 err = proc_get_long(&kbuf, &left, &lval, &neg,
2026 proc_wspace_sep,
2027 sizeof(proc_wspace_sep), NULL);
2028 if (err)
2029 break;
2030 if (conv(&neg, &lval, i, 1, data)) {
2031 err = -EINVAL;
2032 break;
2034 } else {
2035 if (conv(&neg, &lval, i, 0, data)) {
2036 err = -EINVAL;
2037 break;
2039 if (!first)
2040 err = proc_put_char(&buffer, &left, '\t');
2041 if (err)
2042 break;
2043 err = proc_put_long(&buffer, &left, lval, neg);
2044 if (err)
2045 break;
2049 if (!write && !first && left && !err)
2050 err = proc_put_char(&buffer, &left, '\n');
2051 if (write && !err && left)
2052 left -= proc_skip_spaces(&kbuf);
2053 free:
2054 if (write) {
2055 free_page(page);
2056 if (first)
2057 return err ? : -EINVAL;
2059 *lenp -= left;
2060 out:
2061 *ppos += *lenp;
2062 return err;
2065 static int do_proc_dointvec(struct ctl_table *table, int write,
2066 void __user *buffer, size_t *lenp, loff_t *ppos,
2067 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2068 int write, void *data),
2069 void *data)
2071 return __do_proc_dointvec(table->data, table, write,
2072 buffer, lenp, ppos, conv, data);
2076 * proc_dointvec - read a vector of integers
2077 * @table: the sysctl table
2078 * @write: %TRUE if this is a write to the sysctl file
2079 * @buffer: the user buffer
2080 * @lenp: the size of the user buffer
2081 * @ppos: file position
2083 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2084 * values from/to the user buffer, treated as an ASCII string.
2086 * Returns 0 on success.
2088 int proc_dointvec(struct ctl_table *table, int write,
2089 void __user *buffer, size_t *lenp, loff_t *ppos)
2091 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2092 NULL,NULL);
2096 * Taint values can only be increased
2097 * This means we can safely use a temporary.
2099 static int proc_taint(struct ctl_table *table, int write,
2100 void __user *buffer, size_t *lenp, loff_t *ppos)
2102 struct ctl_table t;
2103 unsigned long tmptaint = get_taint();
2104 int err;
2106 if (write && !capable(CAP_SYS_ADMIN))
2107 return -EPERM;
2109 t = *table;
2110 t.data = &tmptaint;
2111 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2112 if (err < 0)
2113 return err;
2115 if (write) {
2117 * Poor man's atomic or. Not worth adding a primitive
2118 * to everyone's atomic.h for this
2120 int i;
2121 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2122 if ((tmptaint >> i) & 1)
2123 add_taint(i, LOCKDEP_STILL_OK);
2127 return err;
2130 #ifdef CONFIG_PRINTK
2131 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2132 void __user *buffer, size_t *lenp, loff_t *ppos)
2134 if (write && !capable(CAP_SYS_ADMIN))
2135 return -EPERM;
2137 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2139 #endif
2141 struct do_proc_dointvec_minmax_conv_param {
2142 int *min;
2143 int *max;
2146 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2147 int *valp,
2148 int write, void *data)
2150 struct do_proc_dointvec_minmax_conv_param *param = data;
2151 if (write) {
2152 int val = *negp ? -*lvalp : *lvalp;
2153 if ((param->min && *param->min > val) ||
2154 (param->max && *param->max < val))
2155 return -EINVAL;
2156 *valp = val;
2157 } else {
2158 int val = *valp;
2159 if (val < 0) {
2160 *negp = true;
2161 *lvalp = (unsigned long)-val;
2162 } else {
2163 *negp = false;
2164 *lvalp = (unsigned long)val;
2167 return 0;
2171 * proc_dointvec_minmax - read a vector of integers with min/max values
2172 * @table: the sysctl table
2173 * @write: %TRUE if this is a write to the sysctl file
2174 * @buffer: the user buffer
2175 * @lenp: the size of the user buffer
2176 * @ppos: file position
2178 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2179 * values from/to the user buffer, treated as an ASCII string.
2181 * This routine will ensure the values are within the range specified by
2182 * table->extra1 (min) and table->extra2 (max).
2184 * Returns 0 on success.
2186 int proc_dointvec_minmax(struct ctl_table *table, int write,
2187 void __user *buffer, size_t *lenp, loff_t *ppos)
2189 struct do_proc_dointvec_minmax_conv_param param = {
2190 .min = (int *) table->extra1,
2191 .max = (int *) table->extra2,
2193 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2194 do_proc_dointvec_minmax_conv, &param);
2197 static void validate_coredump_safety(void)
2199 #ifdef CONFIG_COREDUMP
2200 if (suid_dumpable == SUID_DUMP_ROOT &&
2201 core_pattern[0] != '/' && core_pattern[0] != '|') {
2202 printk(KERN_WARNING "Unsafe core_pattern used with "\
2203 "suid_dumpable=2. Pipe handler or fully qualified "\
2204 "core dump path required.\n");
2206 #endif
2209 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2210 void __user *buffer, size_t *lenp, loff_t *ppos)
2212 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2213 if (!error)
2214 validate_coredump_safety();
2215 return error;
2218 #ifdef CONFIG_COREDUMP
2219 static int proc_dostring_coredump(struct ctl_table *table, int write,
2220 void __user *buffer, size_t *lenp, loff_t *ppos)
2222 int error = proc_dostring(table, write, buffer, lenp, ppos);
2223 if (!error)
2224 validate_coredump_safety();
2225 return error;
2227 #endif
2229 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2230 void __user *buffer,
2231 size_t *lenp, loff_t *ppos,
2232 unsigned long convmul,
2233 unsigned long convdiv)
2235 unsigned long *i, *min, *max;
2236 int vleft, first = 1, err = 0;
2237 unsigned long page = 0;
2238 size_t left;
2239 char *kbuf;
2241 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2242 *lenp = 0;
2243 return 0;
2246 i = (unsigned long *) data;
2247 min = (unsigned long *) table->extra1;
2248 max = (unsigned long *) table->extra2;
2249 vleft = table->maxlen / sizeof(unsigned long);
2250 left = *lenp;
2252 if (write) {
2253 if (*ppos) {
2254 switch (sysctl_writes_strict) {
2255 case SYSCTL_WRITES_STRICT:
2256 goto out;
2257 case SYSCTL_WRITES_WARN:
2258 warn_sysctl_write(table);
2259 break;
2260 default:
2261 break;
2265 if (left > PAGE_SIZE - 1)
2266 left = PAGE_SIZE - 1;
2267 page = __get_free_page(GFP_TEMPORARY);
2268 kbuf = (char *) page;
2269 if (!kbuf)
2270 return -ENOMEM;
2271 if (copy_from_user(kbuf, buffer, left)) {
2272 err = -EFAULT;
2273 goto free;
2275 kbuf[left] = 0;
2278 for (; left && vleft--; i++, first = 0) {
2279 unsigned long val;
2281 if (write) {
2282 bool neg;
2284 left -= proc_skip_spaces(&kbuf);
2286 err = proc_get_long(&kbuf, &left, &val, &neg,
2287 proc_wspace_sep,
2288 sizeof(proc_wspace_sep), NULL);
2289 if (err)
2290 break;
2291 if (neg)
2292 continue;
2293 if ((min && val < *min) || (max && val > *max))
2294 continue;
2295 *i = val;
2296 } else {
2297 val = convdiv * (*i) / convmul;
2298 if (!first) {
2299 err = proc_put_char(&buffer, &left, '\t');
2300 if (err)
2301 break;
2303 err = proc_put_long(&buffer, &left, val, false);
2304 if (err)
2305 break;
2309 if (!write && !first && left && !err)
2310 err = proc_put_char(&buffer, &left, '\n');
2311 if (write && !err)
2312 left -= proc_skip_spaces(&kbuf);
2313 free:
2314 if (write) {
2315 free_page(page);
2316 if (first)
2317 return err ? : -EINVAL;
2319 *lenp -= left;
2320 out:
2321 *ppos += *lenp;
2322 return err;
2325 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2326 void __user *buffer,
2327 size_t *lenp, loff_t *ppos,
2328 unsigned long convmul,
2329 unsigned long convdiv)
2331 return __do_proc_doulongvec_minmax(table->data, table, write,
2332 buffer, lenp, ppos, convmul, convdiv);
2336 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2337 * @table: the sysctl table
2338 * @write: %TRUE if this is a write to the sysctl file
2339 * @buffer: the user buffer
2340 * @lenp: the size of the user buffer
2341 * @ppos: file position
2343 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2344 * values from/to the user buffer, treated as an ASCII string.
2346 * This routine will ensure the values are within the range specified by
2347 * table->extra1 (min) and table->extra2 (max).
2349 * Returns 0 on success.
2351 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2352 void __user *buffer, size_t *lenp, loff_t *ppos)
2354 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2358 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2359 * @table: the sysctl table
2360 * @write: %TRUE if this is a write to the sysctl file
2361 * @buffer: the user buffer
2362 * @lenp: the size of the user buffer
2363 * @ppos: file position
2365 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2366 * values from/to the user buffer, treated as an ASCII string. The values
2367 * are treated as milliseconds, and converted to jiffies when they are stored.
2369 * This routine will ensure the values are within the range specified by
2370 * table->extra1 (min) and table->extra2 (max).
2372 * Returns 0 on success.
2374 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2375 void __user *buffer,
2376 size_t *lenp, loff_t *ppos)
2378 return do_proc_doulongvec_minmax(table, write, buffer,
2379 lenp, ppos, HZ, 1000l);
2383 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2384 int *valp,
2385 int write, void *data)
2387 if (write) {
2388 if (*lvalp > LONG_MAX / HZ)
2389 return 1;
2390 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2391 } else {
2392 int val = *valp;
2393 unsigned long lval;
2394 if (val < 0) {
2395 *negp = true;
2396 lval = (unsigned long)-val;
2397 } else {
2398 *negp = false;
2399 lval = (unsigned long)val;
2401 *lvalp = lval / HZ;
2403 return 0;
2406 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2407 int *valp,
2408 int write, void *data)
2410 if (write) {
2411 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2412 return 1;
2413 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2414 } else {
2415 int val = *valp;
2416 unsigned long lval;
2417 if (val < 0) {
2418 *negp = true;
2419 lval = (unsigned long)-val;
2420 } else {
2421 *negp = false;
2422 lval = (unsigned long)val;
2424 *lvalp = jiffies_to_clock_t(lval);
2426 return 0;
2429 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2430 int *valp,
2431 int write, void *data)
2433 if (write) {
2434 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2436 if (jif > INT_MAX)
2437 return 1;
2438 *valp = (int)jif;
2439 } else {
2440 int val = *valp;
2441 unsigned long lval;
2442 if (val < 0) {
2443 *negp = true;
2444 lval = (unsigned long)-val;
2445 } else {
2446 *negp = false;
2447 lval = (unsigned long)val;
2449 *lvalp = jiffies_to_msecs(lval);
2451 return 0;
2455 * proc_dointvec_jiffies - read a vector of integers as seconds
2456 * @table: the sysctl table
2457 * @write: %TRUE if this is a write to the sysctl file
2458 * @buffer: the user buffer
2459 * @lenp: the size of the user buffer
2460 * @ppos: file position
2462 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2463 * values from/to the user buffer, treated as an ASCII string.
2464 * The values read are assumed to be in seconds, and are converted into
2465 * jiffies.
2467 * Returns 0 on success.
2469 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2470 void __user *buffer, size_t *lenp, loff_t *ppos)
2472 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2473 do_proc_dointvec_jiffies_conv,NULL);
2477 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2478 * @table: the sysctl table
2479 * @write: %TRUE if this is a write to the sysctl file
2480 * @buffer: the user buffer
2481 * @lenp: the size of the user buffer
2482 * @ppos: pointer to the file position
2484 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2485 * values from/to the user buffer, treated as an ASCII string.
2486 * The values read are assumed to be in 1/USER_HZ seconds, and
2487 * are converted into jiffies.
2489 * Returns 0 on success.
2491 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2492 void __user *buffer, size_t *lenp, loff_t *ppos)
2494 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2495 do_proc_dointvec_userhz_jiffies_conv,NULL);
2499 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2500 * @table: the sysctl table
2501 * @write: %TRUE if this is a write to the sysctl file
2502 * @buffer: the user buffer
2503 * @lenp: the size of the user buffer
2504 * @ppos: file position
2505 * @ppos: the current position in the file
2507 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2508 * values from/to the user buffer, treated as an ASCII string.
2509 * The values read are assumed to be in 1/1000 seconds, and
2510 * are converted into jiffies.
2512 * Returns 0 on success.
2514 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2515 void __user *buffer, size_t *lenp, loff_t *ppos)
2517 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2518 do_proc_dointvec_ms_jiffies_conv, NULL);
2521 static int proc_do_cad_pid(struct ctl_table *table, int write,
2522 void __user *buffer, size_t *lenp, loff_t *ppos)
2524 struct pid *new_pid;
2525 pid_t tmp;
2526 int r;
2528 tmp = pid_vnr(cad_pid);
2530 r = __do_proc_dointvec(&tmp, table, write, buffer,
2531 lenp, ppos, NULL, NULL);
2532 if (r || !write)
2533 return r;
2535 new_pid = find_get_pid(tmp);
2536 if (!new_pid)
2537 return -ESRCH;
2539 put_pid(xchg(&cad_pid, new_pid));
2540 return 0;
2544 * proc_do_large_bitmap - read/write from/to a large bitmap
2545 * @table: the sysctl table
2546 * @write: %TRUE if this is a write to the sysctl file
2547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2551 * The bitmap is stored at table->data and the bitmap length (in bits)
2552 * in table->maxlen.
2554 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2555 * large bitmaps may be represented in a compact manner. Writing into
2556 * the file will clear the bitmap then update it with the given input.
2558 * Returns 0 on success.
2560 int proc_do_large_bitmap(struct ctl_table *table, int write,
2561 void __user *buffer, size_t *lenp, loff_t *ppos)
2563 int err = 0;
2564 bool first = 1;
2565 size_t left = *lenp;
2566 unsigned long bitmap_len = table->maxlen;
2567 unsigned long *bitmap = *(unsigned long **) table->data;
2568 unsigned long *tmp_bitmap = NULL;
2569 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2571 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2572 *lenp = 0;
2573 return 0;
2576 if (write) {
2577 unsigned long page = 0;
2578 char *kbuf;
2580 if (left > PAGE_SIZE - 1)
2581 left = PAGE_SIZE - 1;
2583 page = __get_free_page(GFP_TEMPORARY);
2584 kbuf = (char *) page;
2585 if (!kbuf)
2586 return -ENOMEM;
2587 if (copy_from_user(kbuf, buffer, left)) {
2588 free_page(page);
2589 return -EFAULT;
2591 kbuf[left] = 0;
2593 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2594 GFP_KERNEL);
2595 if (!tmp_bitmap) {
2596 free_page(page);
2597 return -ENOMEM;
2599 proc_skip_char(&kbuf, &left, '\n');
2600 while (!err && left) {
2601 unsigned long val_a, val_b;
2602 bool neg;
2604 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2605 sizeof(tr_a), &c);
2606 if (err)
2607 break;
2608 if (val_a >= bitmap_len || neg) {
2609 err = -EINVAL;
2610 break;
2613 val_b = val_a;
2614 if (left) {
2615 kbuf++;
2616 left--;
2619 if (c == '-') {
2620 err = proc_get_long(&kbuf, &left, &val_b,
2621 &neg, tr_b, sizeof(tr_b),
2622 &c);
2623 if (err)
2624 break;
2625 if (val_b >= bitmap_len || neg ||
2626 val_a > val_b) {
2627 err = -EINVAL;
2628 break;
2630 if (left) {
2631 kbuf++;
2632 left--;
2636 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2637 first = 0;
2638 proc_skip_char(&kbuf, &left, '\n');
2640 free_page(page);
2641 } else {
2642 unsigned long bit_a, bit_b = 0;
2644 while (left) {
2645 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2646 if (bit_a >= bitmap_len)
2647 break;
2648 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2649 bit_a + 1) - 1;
2651 if (!first) {
2652 err = proc_put_char(&buffer, &left, ',');
2653 if (err)
2654 break;
2656 err = proc_put_long(&buffer, &left, bit_a, false);
2657 if (err)
2658 break;
2659 if (bit_a != bit_b) {
2660 err = proc_put_char(&buffer, &left, '-');
2661 if (err)
2662 break;
2663 err = proc_put_long(&buffer, &left, bit_b, false);
2664 if (err)
2665 break;
2668 first = 0; bit_b++;
2670 if (!err)
2671 err = proc_put_char(&buffer, &left, '\n');
2674 if (!err) {
2675 if (write) {
2676 if (*ppos)
2677 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2678 else
2679 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2681 kfree(tmp_bitmap);
2682 *lenp -= left;
2683 *ppos += *lenp;
2684 return 0;
2685 } else {
2686 kfree(tmp_bitmap);
2687 return err;
2691 #else /* CONFIG_PROC_SYSCTL */
2693 int proc_dostring(struct ctl_table *table, int write,
2694 void __user *buffer, size_t *lenp, loff_t *ppos)
2696 return -ENOSYS;
2699 int proc_dointvec(struct ctl_table *table, int write,
2700 void __user *buffer, size_t *lenp, loff_t *ppos)
2702 return -ENOSYS;
2705 int proc_dointvec_minmax(struct ctl_table *table, int write,
2706 void __user *buffer, size_t *lenp, loff_t *ppos)
2708 return -ENOSYS;
2711 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2712 void __user *buffer, size_t *lenp, loff_t *ppos)
2714 return -ENOSYS;
2717 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2718 void __user *buffer, size_t *lenp, loff_t *ppos)
2720 return -ENOSYS;
2723 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2724 void __user *buffer, size_t *lenp, loff_t *ppos)
2726 return -ENOSYS;
2729 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2730 void __user *buffer, size_t *lenp, loff_t *ppos)
2732 return -ENOSYS;
2735 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2736 void __user *buffer,
2737 size_t *lenp, loff_t *ppos)
2739 return -ENOSYS;
2743 #endif /* CONFIG_PROC_SYSCTL */
2746 * No sense putting this after each symbol definition, twice,
2747 * exception granted :-)
2749 EXPORT_SYMBOL(proc_dointvec);
2750 EXPORT_SYMBOL(proc_dointvec_jiffies);
2751 EXPORT_SYMBOL(proc_dointvec_minmax);
2752 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2753 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2754 EXPORT_SYMBOL(proc_dostring);
2755 EXPORT_SYMBOL(proc_doulongvec_minmax);
2756 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);