vmalloc(): adjust gfp mask passed on nested vmalloc() invocation
[linux-2.6/libata-dev.git] / kernel / sysctl.c
blob60fc931310957c8ee00c6b1087d6039c6998a3a9
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/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/kmemcheck.h>
30 #include <linux/fs.h>
31 #include <linux/init.h>
32 #include <linux/kernel.h>
33 #include <linux/kobject.h>
34 #include <linux/net.h>
35 #include <linux/sysrq.h>
36 #include <linux/highuid.h>
37 #include <linux/writeback.h>
38 #include <linux/ratelimit.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
52 #include <linux/perf_event.h>
54 #include <asm/uaccess.h>
55 #include <asm/processor.h>
57 #ifdef CONFIG_X86
58 #include <asm/nmi.h>
59 #include <asm/stacktrace.h>
60 #include <asm/io.h>
61 #endif
64 #if defined(CONFIG_SYSCTL)
66 /* External variables not in a header file. */
67 extern int C_A_D;
68 extern int print_fatal_signals;
69 extern int sysctl_overcommit_memory;
70 extern int sysctl_overcommit_ratio;
71 extern int sysctl_panic_on_oom;
72 extern int sysctl_oom_kill_allocating_task;
73 extern int sysctl_oom_dump_tasks;
74 extern int max_threads;
75 extern int core_uses_pid;
76 extern int suid_dumpable;
77 extern char core_pattern[];
78 extern unsigned int core_pipe_limit;
79 extern int pid_max;
80 extern int min_free_kbytes;
81 extern int pid_max_min, pid_max_max;
82 extern int sysctl_drop_caches;
83 extern int percpu_pagelist_fraction;
84 extern int compat_log;
85 extern int latencytop_enabled;
86 extern int sysctl_nr_open_min, sysctl_nr_open_max;
87 #ifndef CONFIG_MMU
88 extern int sysctl_nr_trim_pages;
89 #endif
90 #ifdef CONFIG_RCU_TORTURE_TEST
91 extern int rcutorture_runnable;
92 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
93 #ifdef CONFIG_BLOCK
94 extern int blk_iopoll_enabled;
95 #endif
97 /* Constants used for minimum and maximum */
98 #ifdef CONFIG_DETECT_SOFTLOCKUP
99 static int sixty = 60;
100 static int neg_one = -1;
101 #endif
103 static int zero;
104 static int __maybe_unused one = 1;
105 static int __maybe_unused two = 2;
106 static unsigned long one_ul = 1;
107 static int one_hundred = 100;
108 #ifdef CONFIG_PRINTK
109 static int ten_thousand = 10000;
110 #endif
112 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
113 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
115 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
116 static int maxolduid = 65535;
117 static int minolduid;
118 static int min_percpu_pagelist_fract = 8;
120 static int ngroups_max = NGROUPS_MAX;
122 #ifdef CONFIG_MODULES
123 extern char modprobe_path[];
124 extern int modules_disabled;
125 #endif
126 #ifdef CONFIG_CHR_DEV_SG
127 extern int sg_big_buff;
128 #endif
130 #ifdef CONFIG_SPARC
131 #include <asm/system.h>
132 #endif
134 #ifdef CONFIG_SPARC64
135 extern int sysctl_tsb_ratio;
136 #endif
138 #ifdef __hppa__
139 extern int pwrsw_enabled;
140 extern int unaligned_enabled;
141 #endif
143 #ifdef CONFIG_S390
144 #ifdef CONFIG_MATHEMU
145 extern int sysctl_ieee_emulation_warnings;
146 #endif
147 extern int sysctl_userprocess_debug;
148 extern int spin_retry;
149 #endif
151 #ifdef CONFIG_BSD_PROCESS_ACCT
152 extern int acct_parm[];
153 #endif
155 #ifdef CONFIG_IA64
156 extern int no_unaligned_warning;
157 extern int unaligned_dump_stack;
158 #endif
160 extern struct ratelimit_state printk_ratelimit_state;
162 #ifdef CONFIG_RT_MUTEXES
163 extern int max_lock_depth;
164 #endif
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
169 static int proc_taint(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171 #endif
173 static struct ctl_table root_table[];
174 static struct ctl_table_root sysctl_table_root;
175 static struct ctl_table_header root_table_header = {
176 .count = 1,
177 .ctl_table = root_table,
178 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
179 .root = &sysctl_table_root,
180 .set = &sysctl_table_root.default_set,
182 static struct ctl_table_root sysctl_table_root = {
183 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
184 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
187 static struct ctl_table kern_table[];
188 static struct ctl_table vm_table[];
189 static struct ctl_table fs_table[];
190 static struct ctl_table debug_table[];
191 static struct ctl_table dev_table[];
192 extern struct ctl_table random_table[];
193 #ifdef CONFIG_INOTIFY_USER
194 extern struct ctl_table inotify_table[];
195 #endif
196 #ifdef CONFIG_EPOLL
197 extern struct ctl_table epoll_table[];
198 #endif
200 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
201 int sysctl_legacy_va_layout;
202 #endif
204 extern int prove_locking;
205 extern int lock_stat;
207 /* The default sysctl tables: */
209 static struct ctl_table root_table[] = {
211 .procname = "kernel",
212 .mode = 0555,
213 .child = kern_table,
216 .procname = "vm",
217 .mode = 0555,
218 .child = vm_table,
221 .procname = "fs",
222 .mode = 0555,
223 .child = fs_table,
226 .procname = "debug",
227 .mode = 0555,
228 .child = debug_table,
231 .procname = "dev",
232 .mode = 0555,
233 .child = dev_table,
236 * NOTE: do not add new entries to this table unless you have read
237 * Documentation/sysctl/ctl_unnumbered.txt
242 #ifdef CONFIG_SCHED_DEBUG
243 static int min_sched_granularity_ns = 100000; /* 100 usecs */
244 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
245 static int min_wakeup_granularity_ns; /* 0 usecs */
246 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
247 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
248 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
249 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
250 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
251 #endif
253 static struct ctl_table kern_table[] = {
255 .procname = "sched_child_runs_first",
256 .data = &sysctl_sched_child_runs_first,
257 .maxlen = sizeof(unsigned int),
258 .mode = 0644,
259 .proc_handler = proc_dointvec,
261 #ifdef CONFIG_SCHED_DEBUG
263 .procname = "sched_min_granularity_ns",
264 .data = &sysctl_sched_min_granularity,
265 .maxlen = sizeof(unsigned int),
266 .mode = 0644,
267 .proc_handler = sched_proc_update_handler,
268 .extra1 = &min_sched_granularity_ns,
269 .extra2 = &max_sched_granularity_ns,
272 .procname = "sched_latency_ns",
273 .data = &sysctl_sched_latency,
274 .maxlen = sizeof(unsigned int),
275 .mode = 0644,
276 .proc_handler = sched_proc_update_handler,
277 .extra1 = &min_sched_granularity_ns,
278 .extra2 = &max_sched_granularity_ns,
281 .procname = "sched_wakeup_granularity_ns",
282 .data = &sysctl_sched_wakeup_granularity,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
285 .proc_handler = sched_proc_update_handler,
286 .extra1 = &min_wakeup_granularity_ns,
287 .extra2 = &max_wakeup_granularity_ns,
290 .procname = "sched_shares_ratelimit",
291 .data = &sysctl_sched_shares_ratelimit,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = sched_proc_update_handler,
295 .extra1 = &min_sched_shares_ratelimit,
296 .extra2 = &max_sched_shares_ratelimit,
299 .procname = "sched_tunable_scaling",
300 .data = &sysctl_sched_tunable_scaling,
301 .maxlen = sizeof(enum sched_tunable_scaling),
302 .mode = 0644,
303 .proc_handler = sched_proc_update_handler,
304 .extra1 = &min_sched_tunable_scaling,
305 .extra2 = &max_sched_tunable_scaling,
308 .procname = "sched_shares_thresh",
309 .data = &sysctl_sched_shares_thresh,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = proc_dointvec_minmax,
313 .extra1 = &zero,
316 .procname = "sched_migration_cost",
317 .data = &sysctl_sched_migration_cost,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
320 .proc_handler = proc_dointvec,
323 .procname = "sched_nr_migrate",
324 .data = &sysctl_sched_nr_migrate,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
327 .proc_handler = proc_dointvec,
330 .procname = "sched_time_avg",
331 .data = &sysctl_sched_time_avg,
332 .maxlen = sizeof(unsigned int),
333 .mode = 0644,
334 .proc_handler = proc_dointvec,
337 .procname = "timer_migration",
338 .data = &sysctl_timer_migration,
339 .maxlen = sizeof(unsigned int),
340 .mode = 0644,
341 .proc_handler = proc_dointvec_minmax,
342 .extra1 = &zero,
343 .extra2 = &one,
345 #endif
347 .procname = "sched_rt_period_us",
348 .data = &sysctl_sched_rt_period,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
351 .proc_handler = sched_rt_handler,
354 .procname = "sched_rt_runtime_us",
355 .data = &sysctl_sched_rt_runtime,
356 .maxlen = sizeof(int),
357 .mode = 0644,
358 .proc_handler = sched_rt_handler,
361 .procname = "sched_compat_yield",
362 .data = &sysctl_sched_compat_yield,
363 .maxlen = sizeof(unsigned int),
364 .mode = 0644,
365 .proc_handler = proc_dointvec,
367 #ifdef CONFIG_PROVE_LOCKING
369 .procname = "prove_locking",
370 .data = &prove_locking,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = proc_dointvec,
375 #endif
376 #ifdef CONFIG_LOCK_STAT
378 .procname = "lock_stat",
379 .data = &lock_stat,
380 .maxlen = sizeof(int),
381 .mode = 0644,
382 .proc_handler = proc_dointvec,
384 #endif
386 .procname = "panic",
387 .data = &panic_timeout,
388 .maxlen = sizeof(int),
389 .mode = 0644,
390 .proc_handler = proc_dointvec,
393 .procname = "core_uses_pid",
394 .data = &core_uses_pid,
395 .maxlen = sizeof(int),
396 .mode = 0644,
397 .proc_handler = proc_dointvec,
400 .procname = "core_pattern",
401 .data = core_pattern,
402 .maxlen = CORENAME_MAX_SIZE,
403 .mode = 0644,
404 .proc_handler = proc_dostring,
407 .procname = "core_pipe_limit",
408 .data = &core_pipe_limit,
409 .maxlen = sizeof(unsigned int),
410 .mode = 0644,
411 .proc_handler = proc_dointvec,
413 #ifdef CONFIG_PROC_SYSCTL
415 .procname = "tainted",
416 .maxlen = sizeof(long),
417 .mode = 0644,
418 .proc_handler = proc_taint,
420 #endif
421 #ifdef CONFIG_LATENCYTOP
423 .procname = "latencytop",
424 .data = &latencytop_enabled,
425 .maxlen = sizeof(int),
426 .mode = 0644,
427 .proc_handler = proc_dointvec,
429 #endif
430 #ifdef CONFIG_BLK_DEV_INITRD
432 .procname = "real-root-dev",
433 .data = &real_root_dev,
434 .maxlen = sizeof(int),
435 .mode = 0644,
436 .proc_handler = proc_dointvec,
438 #endif
440 .procname = "print-fatal-signals",
441 .data = &print_fatal_signals,
442 .maxlen = sizeof(int),
443 .mode = 0644,
444 .proc_handler = proc_dointvec,
446 #ifdef CONFIG_SPARC
448 .procname = "reboot-cmd",
449 .data = reboot_command,
450 .maxlen = 256,
451 .mode = 0644,
452 .proc_handler = proc_dostring,
455 .procname = "stop-a",
456 .data = &stop_a_enabled,
457 .maxlen = sizeof (int),
458 .mode = 0644,
459 .proc_handler = proc_dointvec,
462 .procname = "scons-poweroff",
463 .data = &scons_pwroff,
464 .maxlen = sizeof (int),
465 .mode = 0644,
466 .proc_handler = proc_dointvec,
468 #endif
469 #ifdef CONFIG_SPARC64
471 .procname = "tsb-ratio",
472 .data = &sysctl_tsb_ratio,
473 .maxlen = sizeof (int),
474 .mode = 0644,
475 .proc_handler = proc_dointvec,
477 #endif
478 #ifdef __hppa__
480 .procname = "soft-power",
481 .data = &pwrsw_enabled,
482 .maxlen = sizeof (int),
483 .mode = 0644,
484 .proc_handler = proc_dointvec,
487 .procname = "unaligned-trap",
488 .data = &unaligned_enabled,
489 .maxlen = sizeof (int),
490 .mode = 0644,
491 .proc_handler = proc_dointvec,
493 #endif
495 .procname = "ctrl-alt-del",
496 .data = &C_A_D,
497 .maxlen = sizeof(int),
498 .mode = 0644,
499 .proc_handler = proc_dointvec,
501 #ifdef CONFIG_FUNCTION_TRACER
503 .procname = "ftrace_enabled",
504 .data = &ftrace_enabled,
505 .maxlen = sizeof(int),
506 .mode = 0644,
507 .proc_handler = ftrace_enable_sysctl,
509 #endif
510 #ifdef CONFIG_STACK_TRACER
512 .procname = "stack_tracer_enabled",
513 .data = &stack_tracer_enabled,
514 .maxlen = sizeof(int),
515 .mode = 0644,
516 .proc_handler = stack_trace_sysctl,
518 #endif
519 #ifdef CONFIG_TRACING
521 .procname = "ftrace_dump_on_oops",
522 .data = &ftrace_dump_on_oops,
523 .maxlen = sizeof(int),
524 .mode = 0644,
525 .proc_handler = proc_dointvec,
527 #endif
528 #ifdef CONFIG_MODULES
530 .procname = "modprobe",
531 .data = &modprobe_path,
532 .maxlen = KMOD_PATH_LEN,
533 .mode = 0644,
534 .proc_handler = proc_dostring,
537 .procname = "modules_disabled",
538 .data = &modules_disabled,
539 .maxlen = sizeof(int),
540 .mode = 0644,
541 /* only handle a transition from default "0" to "1" */
542 .proc_handler = proc_dointvec_minmax,
543 .extra1 = &one,
544 .extra2 = &one,
546 #endif
547 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
549 .procname = "hotplug",
550 .data = &uevent_helper,
551 .maxlen = UEVENT_HELPER_PATH_LEN,
552 .mode = 0644,
553 .proc_handler = proc_dostring,
555 #endif
556 #ifdef CONFIG_CHR_DEV_SG
558 .procname = "sg-big-buff",
559 .data = &sg_big_buff,
560 .maxlen = sizeof (int),
561 .mode = 0444,
562 .proc_handler = proc_dointvec,
564 #endif
565 #ifdef CONFIG_BSD_PROCESS_ACCT
567 .procname = "acct",
568 .data = &acct_parm,
569 .maxlen = 3*sizeof(int),
570 .mode = 0644,
571 .proc_handler = proc_dointvec,
573 #endif
574 #ifdef CONFIG_MAGIC_SYSRQ
576 .procname = "sysrq",
577 .data = &__sysrq_enabled,
578 .maxlen = sizeof (int),
579 .mode = 0644,
580 .proc_handler = proc_dointvec,
582 #endif
583 #ifdef CONFIG_PROC_SYSCTL
585 .procname = "cad_pid",
586 .data = NULL,
587 .maxlen = sizeof (int),
588 .mode = 0600,
589 .proc_handler = proc_do_cad_pid,
591 #endif
593 .procname = "threads-max",
594 .data = &max_threads,
595 .maxlen = sizeof(int),
596 .mode = 0644,
597 .proc_handler = proc_dointvec,
600 .procname = "random",
601 .mode = 0555,
602 .child = random_table,
605 .procname = "overflowuid",
606 .data = &overflowuid,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = proc_dointvec_minmax,
610 .extra1 = &minolduid,
611 .extra2 = &maxolduid,
614 .procname = "overflowgid",
615 .data = &overflowgid,
616 .maxlen = sizeof(int),
617 .mode = 0644,
618 .proc_handler = proc_dointvec_minmax,
619 .extra1 = &minolduid,
620 .extra2 = &maxolduid,
622 #ifdef CONFIG_S390
623 #ifdef CONFIG_MATHEMU
625 .procname = "ieee_emulation_warnings",
626 .data = &sysctl_ieee_emulation_warnings,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = proc_dointvec,
631 #endif
633 .procname = "userprocess_debug",
634 .data = &sysctl_userprocess_debug,
635 .maxlen = sizeof(int),
636 .mode = 0644,
637 .proc_handler = proc_dointvec,
639 #endif
641 .procname = "pid_max",
642 .data = &pid_max,
643 .maxlen = sizeof (int),
644 .mode = 0644,
645 .proc_handler = proc_dointvec_minmax,
646 .extra1 = &pid_max_min,
647 .extra2 = &pid_max_max,
650 .procname = "panic_on_oops",
651 .data = &panic_on_oops,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 .proc_handler = proc_dointvec,
656 #if defined CONFIG_PRINTK
658 .procname = "printk",
659 .data = &console_loglevel,
660 .maxlen = 4*sizeof(int),
661 .mode = 0644,
662 .proc_handler = proc_dointvec,
665 .procname = "printk_ratelimit",
666 .data = &printk_ratelimit_state.interval,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = proc_dointvec_jiffies,
672 .procname = "printk_ratelimit_burst",
673 .data = &printk_ratelimit_state.burst,
674 .maxlen = sizeof(int),
675 .mode = 0644,
676 .proc_handler = proc_dointvec,
679 .procname = "printk_delay",
680 .data = &printk_delay_msec,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 .proc_handler = proc_dointvec_minmax,
684 .extra1 = &zero,
685 .extra2 = &ten_thousand,
687 #endif
689 .procname = "ngroups_max",
690 .data = &ngroups_max,
691 .maxlen = sizeof (int),
692 .mode = 0444,
693 .proc_handler = proc_dointvec,
695 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
697 .procname = "unknown_nmi_panic",
698 .data = &unknown_nmi_panic,
699 .maxlen = sizeof (int),
700 .mode = 0644,
701 .proc_handler = proc_dointvec,
704 .procname = "nmi_watchdog",
705 .data = &nmi_watchdog_enabled,
706 .maxlen = sizeof (int),
707 .mode = 0644,
708 .proc_handler = proc_nmi_enabled,
710 #endif
711 #if defined(CONFIG_X86)
713 .procname = "panic_on_unrecovered_nmi",
714 .data = &panic_on_unrecovered_nmi,
715 .maxlen = sizeof(int),
716 .mode = 0644,
717 .proc_handler = proc_dointvec,
720 .procname = "panic_on_io_nmi",
721 .data = &panic_on_io_nmi,
722 .maxlen = sizeof(int),
723 .mode = 0644,
724 .proc_handler = proc_dointvec,
727 .procname = "bootloader_type",
728 .data = &bootloader_type,
729 .maxlen = sizeof (int),
730 .mode = 0444,
731 .proc_handler = proc_dointvec,
734 .procname = "bootloader_version",
735 .data = &bootloader_version,
736 .maxlen = sizeof (int),
737 .mode = 0444,
738 .proc_handler = proc_dointvec,
741 .procname = "kstack_depth_to_print",
742 .data = &kstack_depth_to_print,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = proc_dointvec,
748 .procname = "io_delay_type",
749 .data = &io_delay_type,
750 .maxlen = sizeof(int),
751 .mode = 0644,
752 .proc_handler = proc_dointvec,
754 #endif
755 #if defined(CONFIG_MMU)
757 .procname = "randomize_va_space",
758 .data = &randomize_va_space,
759 .maxlen = sizeof(int),
760 .mode = 0644,
761 .proc_handler = proc_dointvec,
763 #endif
764 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
766 .procname = "spin_retry",
767 .data = &spin_retry,
768 .maxlen = sizeof (int),
769 .mode = 0644,
770 .proc_handler = proc_dointvec,
772 #endif
773 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
775 .procname = "acpi_video_flags",
776 .data = &acpi_realmode_flags,
777 .maxlen = sizeof (unsigned long),
778 .mode = 0644,
779 .proc_handler = proc_doulongvec_minmax,
781 #endif
782 #ifdef CONFIG_IA64
784 .procname = "ignore-unaligned-usertrap",
785 .data = &no_unaligned_warning,
786 .maxlen = sizeof (int),
787 .mode = 0644,
788 .proc_handler = proc_dointvec,
791 .procname = "unaligned-dump-stack",
792 .data = &unaligned_dump_stack,
793 .maxlen = sizeof (int),
794 .mode = 0644,
795 .proc_handler = proc_dointvec,
797 #endif
798 #ifdef CONFIG_DETECT_SOFTLOCKUP
800 .procname = "softlockup_panic",
801 .data = &softlockup_panic,
802 .maxlen = sizeof(int),
803 .mode = 0644,
804 .proc_handler = proc_dointvec_minmax,
805 .extra1 = &zero,
806 .extra2 = &one,
809 .procname = "softlockup_thresh",
810 .data = &softlockup_thresh,
811 .maxlen = sizeof(int),
812 .mode = 0644,
813 .proc_handler = proc_dosoftlockup_thresh,
814 .extra1 = &neg_one,
815 .extra2 = &sixty,
817 #endif
818 #ifdef CONFIG_DETECT_HUNG_TASK
820 .procname = "hung_task_panic",
821 .data = &sysctl_hung_task_panic,
822 .maxlen = sizeof(int),
823 .mode = 0644,
824 .proc_handler = proc_dointvec_minmax,
825 .extra1 = &zero,
826 .extra2 = &one,
829 .procname = "hung_task_check_count",
830 .data = &sysctl_hung_task_check_count,
831 .maxlen = sizeof(unsigned long),
832 .mode = 0644,
833 .proc_handler = proc_doulongvec_minmax,
836 .procname = "hung_task_timeout_secs",
837 .data = &sysctl_hung_task_timeout_secs,
838 .maxlen = sizeof(unsigned long),
839 .mode = 0644,
840 .proc_handler = proc_dohung_task_timeout_secs,
843 .procname = "hung_task_warnings",
844 .data = &sysctl_hung_task_warnings,
845 .maxlen = sizeof(unsigned long),
846 .mode = 0644,
847 .proc_handler = proc_doulongvec_minmax,
849 #endif
850 #ifdef CONFIG_COMPAT
852 .procname = "compat-log",
853 .data = &compat_log,
854 .maxlen = sizeof (int),
855 .mode = 0644,
856 .proc_handler = proc_dointvec,
858 #endif
859 #ifdef CONFIG_RT_MUTEXES
861 .procname = "max_lock_depth",
862 .data = &max_lock_depth,
863 .maxlen = sizeof(int),
864 .mode = 0644,
865 .proc_handler = proc_dointvec,
867 #endif
869 .procname = "poweroff_cmd",
870 .data = &poweroff_cmd,
871 .maxlen = POWEROFF_CMD_PATH_LEN,
872 .mode = 0644,
873 .proc_handler = proc_dostring,
875 #ifdef CONFIG_KEYS
877 .procname = "keys",
878 .mode = 0555,
879 .child = key_sysctls,
881 #endif
882 #ifdef CONFIG_RCU_TORTURE_TEST
884 .procname = "rcutorture_runnable",
885 .data = &rcutorture_runnable,
886 .maxlen = sizeof(int),
887 .mode = 0644,
888 .proc_handler = proc_dointvec,
890 #endif
891 #ifdef CONFIG_SLOW_WORK
893 .procname = "slow-work",
894 .mode = 0555,
895 .child = slow_work_sysctls,
897 #endif
898 #ifdef CONFIG_PERF_EVENTS
900 .procname = "perf_event_paranoid",
901 .data = &sysctl_perf_event_paranoid,
902 .maxlen = sizeof(sysctl_perf_event_paranoid),
903 .mode = 0644,
904 .proc_handler = proc_dointvec,
907 .procname = "perf_event_mlock_kb",
908 .data = &sysctl_perf_event_mlock,
909 .maxlen = sizeof(sysctl_perf_event_mlock),
910 .mode = 0644,
911 .proc_handler = proc_dointvec,
914 .procname = "perf_event_max_sample_rate",
915 .data = &sysctl_perf_event_sample_rate,
916 .maxlen = sizeof(sysctl_perf_event_sample_rate),
917 .mode = 0644,
918 .proc_handler = proc_dointvec,
920 #endif
921 #ifdef CONFIG_KMEMCHECK
923 .procname = "kmemcheck",
924 .data = &kmemcheck_enabled,
925 .maxlen = sizeof(int),
926 .mode = 0644,
927 .proc_handler = proc_dointvec,
929 #endif
930 #ifdef CONFIG_BLOCK
932 .procname = "blk_iopoll",
933 .data = &blk_iopoll_enabled,
934 .maxlen = sizeof(int),
935 .mode = 0644,
936 .proc_handler = proc_dointvec,
938 #endif
940 * NOTE: do not add new entries to this table unless you have read
941 * Documentation/sysctl/ctl_unnumbered.txt
946 static struct ctl_table vm_table[] = {
948 .procname = "overcommit_memory",
949 .data = &sysctl_overcommit_memory,
950 .maxlen = sizeof(sysctl_overcommit_memory),
951 .mode = 0644,
952 .proc_handler = proc_dointvec,
955 .procname = "panic_on_oom",
956 .data = &sysctl_panic_on_oom,
957 .maxlen = sizeof(sysctl_panic_on_oom),
958 .mode = 0644,
959 .proc_handler = proc_dointvec,
962 .procname = "oom_kill_allocating_task",
963 .data = &sysctl_oom_kill_allocating_task,
964 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
965 .mode = 0644,
966 .proc_handler = proc_dointvec,
969 .procname = "oom_dump_tasks",
970 .data = &sysctl_oom_dump_tasks,
971 .maxlen = sizeof(sysctl_oom_dump_tasks),
972 .mode = 0644,
973 .proc_handler = proc_dointvec,
976 .procname = "overcommit_ratio",
977 .data = &sysctl_overcommit_ratio,
978 .maxlen = sizeof(sysctl_overcommit_ratio),
979 .mode = 0644,
980 .proc_handler = proc_dointvec,
983 .procname = "page-cluster",
984 .data = &page_cluster,
985 .maxlen = sizeof(int),
986 .mode = 0644,
987 .proc_handler = proc_dointvec,
990 .procname = "dirty_background_ratio",
991 .data = &dirty_background_ratio,
992 .maxlen = sizeof(dirty_background_ratio),
993 .mode = 0644,
994 .proc_handler = dirty_background_ratio_handler,
995 .extra1 = &zero,
996 .extra2 = &one_hundred,
999 .procname = "dirty_background_bytes",
1000 .data = &dirty_background_bytes,
1001 .maxlen = sizeof(dirty_background_bytes),
1002 .mode = 0644,
1003 .proc_handler = dirty_background_bytes_handler,
1004 .extra1 = &one_ul,
1007 .procname = "dirty_ratio",
1008 .data = &vm_dirty_ratio,
1009 .maxlen = sizeof(vm_dirty_ratio),
1010 .mode = 0644,
1011 .proc_handler = dirty_ratio_handler,
1012 .extra1 = &zero,
1013 .extra2 = &one_hundred,
1016 .procname = "dirty_bytes",
1017 .data = &vm_dirty_bytes,
1018 .maxlen = sizeof(vm_dirty_bytes),
1019 .mode = 0644,
1020 .proc_handler = dirty_bytes_handler,
1021 .extra1 = &dirty_bytes_min,
1024 .procname = "dirty_writeback_centisecs",
1025 .data = &dirty_writeback_interval,
1026 .maxlen = sizeof(dirty_writeback_interval),
1027 .mode = 0644,
1028 .proc_handler = dirty_writeback_centisecs_handler,
1031 .procname = "dirty_expire_centisecs",
1032 .data = &dirty_expire_interval,
1033 .maxlen = sizeof(dirty_expire_interval),
1034 .mode = 0644,
1035 .proc_handler = proc_dointvec,
1038 .procname = "nr_pdflush_threads",
1039 .data = &nr_pdflush_threads,
1040 .maxlen = sizeof nr_pdflush_threads,
1041 .mode = 0444 /* read-only*/,
1042 .proc_handler = proc_dointvec,
1045 .procname = "swappiness",
1046 .data = &vm_swappiness,
1047 .maxlen = sizeof(vm_swappiness),
1048 .mode = 0644,
1049 .proc_handler = proc_dointvec_minmax,
1050 .extra1 = &zero,
1051 .extra2 = &one_hundred,
1053 #ifdef CONFIG_HUGETLB_PAGE
1055 .procname = "nr_hugepages",
1056 .data = NULL,
1057 .maxlen = sizeof(unsigned long),
1058 .mode = 0644,
1059 .proc_handler = hugetlb_sysctl_handler,
1060 .extra1 = (void *)&hugetlb_zero,
1061 .extra2 = (void *)&hugetlb_infinity,
1063 #ifdef CONFIG_NUMA
1065 .procname = "nr_hugepages_mempolicy",
1066 .data = NULL,
1067 .maxlen = sizeof(unsigned long),
1068 .mode = 0644,
1069 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1070 .extra1 = (void *)&hugetlb_zero,
1071 .extra2 = (void *)&hugetlb_infinity,
1073 #endif
1075 .procname = "hugetlb_shm_group",
1076 .data = &sysctl_hugetlb_shm_group,
1077 .maxlen = sizeof(gid_t),
1078 .mode = 0644,
1079 .proc_handler = proc_dointvec,
1082 .procname = "hugepages_treat_as_movable",
1083 .data = &hugepages_treat_as_movable,
1084 .maxlen = sizeof(int),
1085 .mode = 0644,
1086 .proc_handler = hugetlb_treat_movable_handler,
1089 .procname = "nr_overcommit_hugepages",
1090 .data = NULL,
1091 .maxlen = sizeof(unsigned long),
1092 .mode = 0644,
1093 .proc_handler = hugetlb_overcommit_handler,
1094 .extra1 = (void *)&hugetlb_zero,
1095 .extra2 = (void *)&hugetlb_infinity,
1097 #endif
1099 .procname = "lowmem_reserve_ratio",
1100 .data = &sysctl_lowmem_reserve_ratio,
1101 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1102 .mode = 0644,
1103 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1106 .procname = "drop_caches",
1107 .data = &sysctl_drop_caches,
1108 .maxlen = sizeof(int),
1109 .mode = 0644,
1110 .proc_handler = drop_caches_sysctl_handler,
1113 .procname = "min_free_kbytes",
1114 .data = &min_free_kbytes,
1115 .maxlen = sizeof(min_free_kbytes),
1116 .mode = 0644,
1117 .proc_handler = min_free_kbytes_sysctl_handler,
1118 .extra1 = &zero,
1121 .procname = "percpu_pagelist_fraction",
1122 .data = &percpu_pagelist_fraction,
1123 .maxlen = sizeof(percpu_pagelist_fraction),
1124 .mode = 0644,
1125 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1126 .extra1 = &min_percpu_pagelist_fract,
1128 #ifdef CONFIG_MMU
1130 .procname = "max_map_count",
1131 .data = &sysctl_max_map_count,
1132 .maxlen = sizeof(sysctl_max_map_count),
1133 .mode = 0644,
1134 .proc_handler = proc_dointvec
1136 #else
1138 .procname = "nr_trim_pages",
1139 .data = &sysctl_nr_trim_pages,
1140 .maxlen = sizeof(sysctl_nr_trim_pages),
1141 .mode = 0644,
1142 .proc_handler = proc_dointvec_minmax,
1143 .extra1 = &zero,
1145 #endif
1147 .procname = "laptop_mode",
1148 .data = &laptop_mode,
1149 .maxlen = sizeof(laptop_mode),
1150 .mode = 0644,
1151 .proc_handler = proc_dointvec_jiffies,
1154 .procname = "block_dump",
1155 .data = &block_dump,
1156 .maxlen = sizeof(block_dump),
1157 .mode = 0644,
1158 .proc_handler = proc_dointvec,
1159 .extra1 = &zero,
1162 .procname = "vfs_cache_pressure",
1163 .data = &sysctl_vfs_cache_pressure,
1164 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1165 .mode = 0644,
1166 .proc_handler = proc_dointvec,
1167 .extra1 = &zero,
1169 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1171 .procname = "legacy_va_layout",
1172 .data = &sysctl_legacy_va_layout,
1173 .maxlen = sizeof(sysctl_legacy_va_layout),
1174 .mode = 0644,
1175 .proc_handler = proc_dointvec,
1176 .extra1 = &zero,
1178 #endif
1179 #ifdef CONFIG_NUMA
1181 .procname = "zone_reclaim_mode",
1182 .data = &zone_reclaim_mode,
1183 .maxlen = sizeof(zone_reclaim_mode),
1184 .mode = 0644,
1185 .proc_handler = proc_dointvec,
1186 .extra1 = &zero,
1189 .procname = "min_unmapped_ratio",
1190 .data = &sysctl_min_unmapped_ratio,
1191 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1192 .mode = 0644,
1193 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1194 .extra1 = &zero,
1195 .extra2 = &one_hundred,
1198 .procname = "min_slab_ratio",
1199 .data = &sysctl_min_slab_ratio,
1200 .maxlen = sizeof(sysctl_min_slab_ratio),
1201 .mode = 0644,
1202 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1203 .extra1 = &zero,
1204 .extra2 = &one_hundred,
1206 #endif
1207 #ifdef CONFIG_SMP
1209 .procname = "stat_interval",
1210 .data = &sysctl_stat_interval,
1211 .maxlen = sizeof(sysctl_stat_interval),
1212 .mode = 0644,
1213 .proc_handler = proc_dointvec_jiffies,
1215 #endif
1217 .procname = "mmap_min_addr",
1218 .data = &dac_mmap_min_addr,
1219 .maxlen = sizeof(unsigned long),
1220 .mode = 0644,
1221 .proc_handler = mmap_min_addr_handler,
1223 #ifdef CONFIG_NUMA
1225 .procname = "numa_zonelist_order",
1226 .data = &numa_zonelist_order,
1227 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1228 .mode = 0644,
1229 .proc_handler = numa_zonelist_order_handler,
1231 #endif
1232 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1233 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1235 .procname = "vdso_enabled",
1236 .data = &vdso_enabled,
1237 .maxlen = sizeof(vdso_enabled),
1238 .mode = 0644,
1239 .proc_handler = proc_dointvec,
1240 .extra1 = &zero,
1242 #endif
1243 #ifdef CONFIG_HIGHMEM
1245 .procname = "highmem_is_dirtyable",
1246 .data = &vm_highmem_is_dirtyable,
1247 .maxlen = sizeof(vm_highmem_is_dirtyable),
1248 .mode = 0644,
1249 .proc_handler = proc_dointvec_minmax,
1250 .extra1 = &zero,
1251 .extra2 = &one,
1253 #endif
1255 .procname = "scan_unevictable_pages",
1256 .data = &scan_unevictable_pages,
1257 .maxlen = sizeof(scan_unevictable_pages),
1258 .mode = 0644,
1259 .proc_handler = scan_unevictable_handler,
1261 #ifdef CONFIG_MEMORY_FAILURE
1263 .procname = "memory_failure_early_kill",
1264 .data = &sysctl_memory_failure_early_kill,
1265 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1266 .mode = 0644,
1267 .proc_handler = proc_dointvec_minmax,
1268 .extra1 = &zero,
1269 .extra2 = &one,
1272 .procname = "memory_failure_recovery",
1273 .data = &sysctl_memory_failure_recovery,
1274 .maxlen = sizeof(sysctl_memory_failure_recovery),
1275 .mode = 0644,
1276 .proc_handler = proc_dointvec_minmax,
1277 .extra1 = &zero,
1278 .extra2 = &one,
1280 #endif
1283 * NOTE: do not add new entries to this table unless you have read
1284 * Documentation/sysctl/ctl_unnumbered.txt
1289 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1290 static struct ctl_table binfmt_misc_table[] = {
1293 #endif
1295 static struct ctl_table fs_table[] = {
1297 .procname = "inode-nr",
1298 .data = &inodes_stat,
1299 .maxlen = 2*sizeof(int),
1300 .mode = 0444,
1301 .proc_handler = proc_dointvec,
1304 .procname = "inode-state",
1305 .data = &inodes_stat,
1306 .maxlen = 7*sizeof(int),
1307 .mode = 0444,
1308 .proc_handler = proc_dointvec,
1311 .procname = "file-nr",
1312 .data = &files_stat,
1313 .maxlen = 3*sizeof(int),
1314 .mode = 0444,
1315 .proc_handler = proc_nr_files,
1318 .procname = "file-max",
1319 .data = &files_stat.max_files,
1320 .maxlen = sizeof(int),
1321 .mode = 0644,
1322 .proc_handler = proc_dointvec,
1325 .procname = "nr_open",
1326 .data = &sysctl_nr_open,
1327 .maxlen = sizeof(int),
1328 .mode = 0644,
1329 .proc_handler = proc_dointvec_minmax,
1330 .extra1 = &sysctl_nr_open_min,
1331 .extra2 = &sysctl_nr_open_max,
1334 .procname = "dentry-state",
1335 .data = &dentry_stat,
1336 .maxlen = 6*sizeof(int),
1337 .mode = 0444,
1338 .proc_handler = proc_dointvec,
1341 .procname = "overflowuid",
1342 .data = &fs_overflowuid,
1343 .maxlen = sizeof(int),
1344 .mode = 0644,
1345 .proc_handler = proc_dointvec_minmax,
1346 .extra1 = &minolduid,
1347 .extra2 = &maxolduid,
1350 .procname = "overflowgid",
1351 .data = &fs_overflowgid,
1352 .maxlen = sizeof(int),
1353 .mode = 0644,
1354 .proc_handler = proc_dointvec_minmax,
1355 .extra1 = &minolduid,
1356 .extra2 = &maxolduid,
1358 #ifdef CONFIG_FILE_LOCKING
1360 .procname = "leases-enable",
1361 .data = &leases_enable,
1362 .maxlen = sizeof(int),
1363 .mode = 0644,
1364 .proc_handler = proc_dointvec,
1366 #endif
1367 #ifdef CONFIG_DNOTIFY
1369 .procname = "dir-notify-enable",
1370 .data = &dir_notify_enable,
1371 .maxlen = sizeof(int),
1372 .mode = 0644,
1373 .proc_handler = proc_dointvec,
1375 #endif
1376 #ifdef CONFIG_MMU
1377 #ifdef CONFIG_FILE_LOCKING
1379 .procname = "lease-break-time",
1380 .data = &lease_break_time,
1381 .maxlen = sizeof(int),
1382 .mode = 0644,
1383 .proc_handler = proc_dointvec,
1385 #endif
1386 #ifdef CONFIG_AIO
1388 .procname = "aio-nr",
1389 .data = &aio_nr,
1390 .maxlen = sizeof(aio_nr),
1391 .mode = 0444,
1392 .proc_handler = proc_doulongvec_minmax,
1395 .procname = "aio-max-nr",
1396 .data = &aio_max_nr,
1397 .maxlen = sizeof(aio_max_nr),
1398 .mode = 0644,
1399 .proc_handler = proc_doulongvec_minmax,
1401 #endif /* CONFIG_AIO */
1402 #ifdef CONFIG_INOTIFY_USER
1404 .procname = "inotify",
1405 .mode = 0555,
1406 .child = inotify_table,
1408 #endif
1409 #ifdef CONFIG_EPOLL
1411 .procname = "epoll",
1412 .mode = 0555,
1413 .child = epoll_table,
1415 #endif
1416 #endif
1418 .procname = "suid_dumpable",
1419 .data = &suid_dumpable,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
1422 .proc_handler = proc_dointvec_minmax,
1423 .extra1 = &zero,
1424 .extra2 = &two,
1426 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1428 .procname = "binfmt_misc",
1429 .mode = 0555,
1430 .child = binfmt_misc_table,
1432 #endif
1434 * NOTE: do not add new entries to this table unless you have read
1435 * Documentation/sysctl/ctl_unnumbered.txt
1440 static struct ctl_table debug_table[] = {
1441 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1443 .procname = "exception-trace",
1444 .data = &show_unhandled_signals,
1445 .maxlen = sizeof(int),
1446 .mode = 0644,
1447 .proc_handler = proc_dointvec
1449 #endif
1453 static struct ctl_table dev_table[] = {
1457 static DEFINE_SPINLOCK(sysctl_lock);
1459 /* called under sysctl_lock */
1460 static int use_table(struct ctl_table_header *p)
1462 if (unlikely(p->unregistering))
1463 return 0;
1464 p->used++;
1465 return 1;
1468 /* called under sysctl_lock */
1469 static void unuse_table(struct ctl_table_header *p)
1471 if (!--p->used)
1472 if (unlikely(p->unregistering))
1473 complete(p->unregistering);
1476 /* called under sysctl_lock, will reacquire if has to wait */
1477 static void start_unregistering(struct ctl_table_header *p)
1480 * if p->used is 0, nobody will ever touch that entry again;
1481 * we'll eliminate all paths to it before dropping sysctl_lock
1483 if (unlikely(p->used)) {
1484 struct completion wait;
1485 init_completion(&wait);
1486 p->unregistering = &wait;
1487 spin_unlock(&sysctl_lock);
1488 wait_for_completion(&wait);
1489 spin_lock(&sysctl_lock);
1490 } else {
1491 /* anything non-NULL; we'll never dereference it */
1492 p->unregistering = ERR_PTR(-EINVAL);
1495 * do not remove from the list until nobody holds it; walking the
1496 * list in do_sysctl() relies on that.
1498 list_del_init(&p->ctl_entry);
1501 void sysctl_head_get(struct ctl_table_header *head)
1503 spin_lock(&sysctl_lock);
1504 head->count++;
1505 spin_unlock(&sysctl_lock);
1508 void sysctl_head_put(struct ctl_table_header *head)
1510 spin_lock(&sysctl_lock);
1511 if (!--head->count)
1512 kfree(head);
1513 spin_unlock(&sysctl_lock);
1516 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1518 if (!head)
1519 BUG();
1520 spin_lock(&sysctl_lock);
1521 if (!use_table(head))
1522 head = ERR_PTR(-ENOENT);
1523 spin_unlock(&sysctl_lock);
1524 return head;
1527 void sysctl_head_finish(struct ctl_table_header *head)
1529 if (!head)
1530 return;
1531 spin_lock(&sysctl_lock);
1532 unuse_table(head);
1533 spin_unlock(&sysctl_lock);
1536 static struct ctl_table_set *
1537 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1539 struct ctl_table_set *set = &root->default_set;
1540 if (root->lookup)
1541 set = root->lookup(root, namespaces);
1542 return set;
1545 static struct list_head *
1546 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1548 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1549 return &set->list;
1552 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1553 struct ctl_table_header *prev)
1555 struct ctl_table_root *root;
1556 struct list_head *header_list;
1557 struct ctl_table_header *head;
1558 struct list_head *tmp;
1560 spin_lock(&sysctl_lock);
1561 if (prev) {
1562 head = prev;
1563 tmp = &prev->ctl_entry;
1564 unuse_table(prev);
1565 goto next;
1567 tmp = &root_table_header.ctl_entry;
1568 for (;;) {
1569 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1571 if (!use_table(head))
1572 goto next;
1573 spin_unlock(&sysctl_lock);
1574 return head;
1575 next:
1576 root = head->root;
1577 tmp = tmp->next;
1578 header_list = lookup_header_list(root, namespaces);
1579 if (tmp != header_list)
1580 continue;
1582 do {
1583 root = list_entry(root->root_list.next,
1584 struct ctl_table_root, root_list);
1585 if (root == &sysctl_table_root)
1586 goto out;
1587 header_list = lookup_header_list(root, namespaces);
1588 } while (list_empty(header_list));
1589 tmp = header_list->next;
1591 out:
1592 spin_unlock(&sysctl_lock);
1593 return NULL;
1596 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1598 return __sysctl_head_next(current->nsproxy, prev);
1601 void register_sysctl_root(struct ctl_table_root *root)
1603 spin_lock(&sysctl_lock);
1604 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1605 spin_unlock(&sysctl_lock);
1609 * sysctl_perm does NOT grant the superuser all rights automatically, because
1610 * some sysctl variables are readonly even to root.
1613 static int test_perm(int mode, int op)
1615 if (!current_euid())
1616 mode >>= 6;
1617 else if (in_egroup_p(0))
1618 mode >>= 3;
1619 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1620 return 0;
1621 return -EACCES;
1624 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1626 int error;
1627 int mode;
1629 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1630 if (error)
1631 return error;
1633 if (root->permissions)
1634 mode = root->permissions(root, current->nsproxy, table);
1635 else
1636 mode = table->mode;
1638 return test_perm(mode, op);
1641 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1643 for (; table->procname; table++) {
1644 table->parent = parent;
1645 if (table->child)
1646 sysctl_set_parent(table, table->child);
1650 static __init int sysctl_init(void)
1652 sysctl_set_parent(NULL, root_table);
1653 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1655 int err;
1656 err = sysctl_check_table(current->nsproxy, root_table);
1658 #endif
1659 return 0;
1662 core_initcall(sysctl_init);
1664 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1665 struct ctl_table *table)
1667 struct ctl_table *p;
1668 const char *s = branch->procname;
1670 /* branch should have named subdirectory as its first element */
1671 if (!s || !branch->child)
1672 return NULL;
1674 /* ... and nothing else */
1675 if (branch[1].procname)
1676 return NULL;
1678 /* table should contain subdirectory with the same name */
1679 for (p = table; p->procname; p++) {
1680 if (!p->child)
1681 continue;
1682 if (p->procname && strcmp(p->procname, s) == 0)
1683 return p;
1685 return NULL;
1688 /* see if attaching q to p would be an improvement */
1689 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1691 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1692 struct ctl_table *next;
1693 int is_better = 0;
1694 int not_in_parent = !p->attached_by;
1696 while ((next = is_branch_in(by, to)) != NULL) {
1697 if (by == q->attached_by)
1698 is_better = 1;
1699 if (to == p->attached_by)
1700 not_in_parent = 1;
1701 by = by->child;
1702 to = next->child;
1705 if (is_better && not_in_parent) {
1706 q->attached_by = by;
1707 q->attached_to = to;
1708 q->parent = p;
1713 * __register_sysctl_paths - register a sysctl hierarchy
1714 * @root: List of sysctl headers to register on
1715 * @namespaces: Data to compute which lists of sysctl entries are visible
1716 * @path: The path to the directory the sysctl table is in.
1717 * @table: the top-level table structure
1719 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1720 * array. A completely 0 filled entry terminates the table.
1722 * The members of the &struct ctl_table structure are used as follows:
1724 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1725 * enter a sysctl file
1727 * data - a pointer to data for use by proc_handler
1729 * maxlen - the maximum size in bytes of the data
1731 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1733 * child - a pointer to the child sysctl table if this entry is a directory, or
1734 * %NULL.
1736 * proc_handler - the text handler routine (described below)
1738 * de - for internal use by the sysctl routines
1740 * extra1, extra2 - extra pointers usable by the proc handler routines
1742 * Leaf nodes in the sysctl tree will be represented by a single file
1743 * under /proc; non-leaf nodes will be represented by directories.
1745 * sysctl(2) can automatically manage read and write requests through
1746 * the sysctl table. The data and maxlen fields of the ctl_table
1747 * struct enable minimal validation of the values being written to be
1748 * performed, and the mode field allows minimal authentication.
1750 * There must be a proc_handler routine for any terminal nodes
1751 * mirrored under /proc/sys (non-terminals are handled by a built-in
1752 * directory handler). Several default handlers are available to
1753 * cover common cases -
1755 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1756 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1757 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1759 * It is the handler's job to read the input buffer from user memory
1760 * and process it. The handler should return 0 on success.
1762 * This routine returns %NULL on a failure to register, and a pointer
1763 * to the table header on success.
1765 struct ctl_table_header *__register_sysctl_paths(
1766 struct ctl_table_root *root,
1767 struct nsproxy *namespaces,
1768 const struct ctl_path *path, struct ctl_table *table)
1770 struct ctl_table_header *header;
1771 struct ctl_table *new, **prevp;
1772 unsigned int n, npath;
1773 struct ctl_table_set *set;
1775 /* Count the path components */
1776 for (npath = 0; path[npath].procname; ++npath)
1780 * For each path component, allocate a 2-element ctl_table array.
1781 * The first array element will be filled with the sysctl entry
1782 * for this, the second will be the sentinel (procname == 0).
1784 * We allocate everything in one go so that we don't have to
1785 * worry about freeing additional memory in unregister_sysctl_table.
1787 header = kzalloc(sizeof(struct ctl_table_header) +
1788 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1789 if (!header)
1790 return NULL;
1792 new = (struct ctl_table *) (header + 1);
1794 /* Now connect the dots */
1795 prevp = &header->ctl_table;
1796 for (n = 0; n < npath; ++n, ++path) {
1797 /* Copy the procname */
1798 new->procname = path->procname;
1799 new->mode = 0555;
1801 *prevp = new;
1802 prevp = &new->child;
1804 new += 2;
1806 *prevp = table;
1807 header->ctl_table_arg = table;
1809 INIT_LIST_HEAD(&header->ctl_entry);
1810 header->used = 0;
1811 header->unregistering = NULL;
1812 header->root = root;
1813 sysctl_set_parent(NULL, header->ctl_table);
1814 header->count = 1;
1815 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1816 if (sysctl_check_table(namespaces, header->ctl_table)) {
1817 kfree(header);
1818 return NULL;
1820 #endif
1821 spin_lock(&sysctl_lock);
1822 header->set = lookup_header_set(root, namespaces);
1823 header->attached_by = header->ctl_table;
1824 header->attached_to = root_table;
1825 header->parent = &root_table_header;
1826 for (set = header->set; set; set = set->parent) {
1827 struct ctl_table_header *p;
1828 list_for_each_entry(p, &set->list, ctl_entry) {
1829 if (p->unregistering)
1830 continue;
1831 try_attach(p, header);
1834 header->parent->count++;
1835 list_add_tail(&header->ctl_entry, &header->set->list);
1836 spin_unlock(&sysctl_lock);
1838 return header;
1842 * register_sysctl_table_path - register a sysctl table hierarchy
1843 * @path: The path to the directory the sysctl table is in.
1844 * @table: the top-level table structure
1846 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1847 * array. A completely 0 filled entry terminates the table.
1849 * See __register_sysctl_paths for more details.
1851 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1852 struct ctl_table *table)
1854 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1855 path, table);
1859 * register_sysctl_table - register a sysctl table hierarchy
1860 * @table: the top-level table structure
1862 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1863 * array. A completely 0 filled entry terminates the table.
1865 * See register_sysctl_paths for more details.
1867 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1869 static const struct ctl_path null_path[] = { {} };
1871 return register_sysctl_paths(null_path, table);
1875 * unregister_sysctl_table - unregister a sysctl table hierarchy
1876 * @header: the header returned from register_sysctl_table
1878 * Unregisters the sysctl table and all children. proc entries may not
1879 * actually be removed until they are no longer used by anyone.
1881 void unregister_sysctl_table(struct ctl_table_header * header)
1883 might_sleep();
1885 if (header == NULL)
1886 return;
1888 spin_lock(&sysctl_lock);
1889 start_unregistering(header);
1890 if (!--header->parent->count) {
1891 WARN_ON(1);
1892 kfree(header->parent);
1894 if (!--header->count)
1895 kfree(header);
1896 spin_unlock(&sysctl_lock);
1899 int sysctl_is_seen(struct ctl_table_header *p)
1901 struct ctl_table_set *set = p->set;
1902 int res;
1903 spin_lock(&sysctl_lock);
1904 if (p->unregistering)
1905 res = 0;
1906 else if (!set->is_seen)
1907 res = 1;
1908 else
1909 res = set->is_seen(set);
1910 spin_unlock(&sysctl_lock);
1911 return res;
1914 void setup_sysctl_set(struct ctl_table_set *p,
1915 struct ctl_table_set *parent,
1916 int (*is_seen)(struct ctl_table_set *))
1918 INIT_LIST_HEAD(&p->list);
1919 p->parent = parent ? parent : &sysctl_table_root.default_set;
1920 p->is_seen = is_seen;
1923 #else /* !CONFIG_SYSCTL */
1924 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1926 return NULL;
1929 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1930 struct ctl_table *table)
1932 return NULL;
1935 void unregister_sysctl_table(struct ctl_table_header * table)
1939 void setup_sysctl_set(struct ctl_table_set *p,
1940 struct ctl_table_set *parent,
1941 int (*is_seen)(struct ctl_table_set *))
1945 void sysctl_head_put(struct ctl_table_header *head)
1949 #endif /* CONFIG_SYSCTL */
1952 * /proc/sys support
1955 #ifdef CONFIG_PROC_SYSCTL
1957 static int _proc_do_string(void* data, int maxlen, int write,
1958 void __user *buffer,
1959 size_t *lenp, loff_t *ppos)
1961 size_t len;
1962 char __user *p;
1963 char c;
1965 if (!data || !maxlen || !*lenp) {
1966 *lenp = 0;
1967 return 0;
1970 if (write) {
1971 len = 0;
1972 p = buffer;
1973 while (len < *lenp) {
1974 if (get_user(c, p++))
1975 return -EFAULT;
1976 if (c == 0 || c == '\n')
1977 break;
1978 len++;
1980 if (len >= maxlen)
1981 len = maxlen-1;
1982 if(copy_from_user(data, buffer, len))
1983 return -EFAULT;
1984 ((char *) data)[len] = 0;
1985 *ppos += *lenp;
1986 } else {
1987 len = strlen(data);
1988 if (len > maxlen)
1989 len = maxlen;
1991 if (*ppos > len) {
1992 *lenp = 0;
1993 return 0;
1996 data += *ppos;
1997 len -= *ppos;
1999 if (len > *lenp)
2000 len = *lenp;
2001 if (len)
2002 if(copy_to_user(buffer, data, len))
2003 return -EFAULT;
2004 if (len < *lenp) {
2005 if(put_user('\n', ((char __user *) buffer) + len))
2006 return -EFAULT;
2007 len++;
2009 *lenp = len;
2010 *ppos += len;
2012 return 0;
2016 * proc_dostring - read a string sysctl
2017 * @table: the sysctl table
2018 * @write: %TRUE if this is a write to the sysctl file
2019 * @buffer: the user buffer
2020 * @lenp: the size of the user buffer
2021 * @ppos: file position
2023 * Reads/writes a string from/to the user buffer. If the kernel
2024 * buffer provided is not large enough to hold the string, the
2025 * string is truncated. The copied string is %NULL-terminated.
2026 * If the string is being read by the user process, it is copied
2027 * and a newline '\n' is added. It is truncated if the buffer is
2028 * not large enough.
2030 * Returns 0 on success.
2032 int proc_dostring(struct ctl_table *table, int write,
2033 void __user *buffer, size_t *lenp, loff_t *ppos)
2035 return _proc_do_string(table->data, table->maxlen, write,
2036 buffer, lenp, ppos);
2040 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2041 int *valp,
2042 int write, void *data)
2044 if (write) {
2045 *valp = *negp ? -*lvalp : *lvalp;
2046 } else {
2047 int val = *valp;
2048 if (val < 0) {
2049 *negp = -1;
2050 *lvalp = (unsigned long)-val;
2051 } else {
2052 *negp = 0;
2053 *lvalp = (unsigned long)val;
2056 return 0;
2059 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2060 int write, void __user *buffer,
2061 size_t *lenp, loff_t *ppos,
2062 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2063 int write, void *data),
2064 void *data)
2066 #define TMPBUFLEN 21
2067 int *i, vleft, first = 1, neg;
2068 unsigned long lval;
2069 size_t left, len;
2071 char buf[TMPBUFLEN], *p;
2072 char __user *s = buffer;
2074 if (!tbl_data || !table->maxlen || !*lenp ||
2075 (*ppos && !write)) {
2076 *lenp = 0;
2077 return 0;
2080 i = (int *) tbl_data;
2081 vleft = table->maxlen / sizeof(*i);
2082 left = *lenp;
2084 if (!conv)
2085 conv = do_proc_dointvec_conv;
2087 for (; left && vleft--; i++, first=0) {
2088 if (write) {
2089 while (left) {
2090 char c;
2091 if (get_user(c, s))
2092 return -EFAULT;
2093 if (!isspace(c))
2094 break;
2095 left--;
2096 s++;
2098 if (!left)
2099 break;
2100 neg = 0;
2101 len = left;
2102 if (len > sizeof(buf) - 1)
2103 len = sizeof(buf) - 1;
2104 if (copy_from_user(buf, s, len))
2105 return -EFAULT;
2106 buf[len] = 0;
2107 p = buf;
2108 if (*p == '-' && left > 1) {
2109 neg = 1;
2110 p++;
2112 if (*p < '0' || *p > '9')
2113 break;
2115 lval = simple_strtoul(p, &p, 0);
2117 len = p-buf;
2118 if ((len < left) && *p && !isspace(*p))
2119 break;
2120 s += len;
2121 left -= len;
2123 if (conv(&neg, &lval, i, 1, data))
2124 break;
2125 } else {
2126 p = buf;
2127 if (!first)
2128 *p++ = '\t';
2130 if (conv(&neg, &lval, i, 0, data))
2131 break;
2133 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2134 len = strlen(buf);
2135 if (len > left)
2136 len = left;
2137 if(copy_to_user(s, buf, len))
2138 return -EFAULT;
2139 left -= len;
2140 s += len;
2144 if (!write && !first && left) {
2145 if(put_user('\n', s))
2146 return -EFAULT;
2147 left--, s++;
2149 if (write) {
2150 while (left) {
2151 char c;
2152 if (get_user(c, s++))
2153 return -EFAULT;
2154 if (!isspace(c))
2155 break;
2156 left--;
2159 if (write && first)
2160 return -EINVAL;
2161 *lenp -= left;
2162 *ppos += *lenp;
2163 return 0;
2164 #undef TMPBUFLEN
2167 static int do_proc_dointvec(struct ctl_table *table, int write,
2168 void __user *buffer, size_t *lenp, loff_t *ppos,
2169 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2170 int write, void *data),
2171 void *data)
2173 return __do_proc_dointvec(table->data, table, write,
2174 buffer, lenp, ppos, conv, data);
2178 * proc_dointvec - read a vector of integers
2179 * @table: the sysctl table
2180 * @write: %TRUE if this is a write to the sysctl file
2181 * @buffer: the user buffer
2182 * @lenp: the size of the user buffer
2183 * @ppos: file position
2185 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2186 * values from/to the user buffer, treated as an ASCII string.
2188 * Returns 0 on success.
2190 int proc_dointvec(struct ctl_table *table, int write,
2191 void __user *buffer, size_t *lenp, loff_t *ppos)
2193 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2194 NULL,NULL);
2198 * Taint values can only be increased
2199 * This means we can safely use a temporary.
2201 static int proc_taint(struct ctl_table *table, int write,
2202 void __user *buffer, size_t *lenp, loff_t *ppos)
2204 struct ctl_table t;
2205 unsigned long tmptaint = get_taint();
2206 int err;
2208 if (write && !capable(CAP_SYS_ADMIN))
2209 return -EPERM;
2211 t = *table;
2212 t.data = &tmptaint;
2213 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2214 if (err < 0)
2215 return err;
2217 if (write) {
2219 * Poor man's atomic or. Not worth adding a primitive
2220 * to everyone's atomic.h for this
2222 int i;
2223 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2224 if ((tmptaint >> i) & 1)
2225 add_taint(i);
2229 return err;
2232 struct do_proc_dointvec_minmax_conv_param {
2233 int *min;
2234 int *max;
2237 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2238 int *valp,
2239 int write, void *data)
2241 struct do_proc_dointvec_minmax_conv_param *param = data;
2242 if (write) {
2243 int val = *negp ? -*lvalp : *lvalp;
2244 if ((param->min && *param->min > val) ||
2245 (param->max && *param->max < val))
2246 return -EINVAL;
2247 *valp = val;
2248 } else {
2249 int val = *valp;
2250 if (val < 0) {
2251 *negp = -1;
2252 *lvalp = (unsigned long)-val;
2253 } else {
2254 *negp = 0;
2255 *lvalp = (unsigned long)val;
2258 return 0;
2262 * proc_dointvec_minmax - read a vector of integers with min/max values
2263 * @table: the sysctl table
2264 * @write: %TRUE if this is a write to the sysctl file
2265 * @buffer: the user buffer
2266 * @lenp: the size of the user buffer
2267 * @ppos: file position
2269 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2270 * values from/to the user buffer, treated as an ASCII string.
2272 * This routine will ensure the values are within the range specified by
2273 * table->extra1 (min) and table->extra2 (max).
2275 * Returns 0 on success.
2277 int proc_dointvec_minmax(struct ctl_table *table, int write,
2278 void __user *buffer, size_t *lenp, loff_t *ppos)
2280 struct do_proc_dointvec_minmax_conv_param param = {
2281 .min = (int *) table->extra1,
2282 .max = (int *) table->extra2,
2284 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2285 do_proc_dointvec_minmax_conv, &param);
2288 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2289 void __user *buffer,
2290 size_t *lenp, loff_t *ppos,
2291 unsigned long convmul,
2292 unsigned long convdiv)
2294 #define TMPBUFLEN 21
2295 unsigned long *i, *min, *max, val;
2296 int vleft, first=1, neg;
2297 size_t len, left;
2298 char buf[TMPBUFLEN], *p;
2299 char __user *s = buffer;
2301 if (!data || !table->maxlen || !*lenp ||
2302 (*ppos && !write)) {
2303 *lenp = 0;
2304 return 0;
2307 i = (unsigned long *) data;
2308 min = (unsigned long *) table->extra1;
2309 max = (unsigned long *) table->extra2;
2310 vleft = table->maxlen / sizeof(unsigned long);
2311 left = *lenp;
2313 for (; left && vleft--; i++, min++, max++, first=0) {
2314 if (write) {
2315 while (left) {
2316 char c;
2317 if (get_user(c, s))
2318 return -EFAULT;
2319 if (!isspace(c))
2320 break;
2321 left--;
2322 s++;
2324 if (!left)
2325 break;
2326 neg = 0;
2327 len = left;
2328 if (len > TMPBUFLEN-1)
2329 len = TMPBUFLEN-1;
2330 if (copy_from_user(buf, s, len))
2331 return -EFAULT;
2332 buf[len] = 0;
2333 p = buf;
2334 if (*p == '-' && left > 1) {
2335 neg = 1;
2336 p++;
2338 if (*p < '0' || *p > '9')
2339 break;
2340 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2341 len = p-buf;
2342 if ((len < left) && *p && !isspace(*p))
2343 break;
2344 if (neg)
2345 val = -val;
2346 s += len;
2347 left -= len;
2349 if(neg)
2350 continue;
2351 if ((min && val < *min) || (max && val > *max))
2352 continue;
2353 *i = val;
2354 } else {
2355 p = buf;
2356 if (!first)
2357 *p++ = '\t';
2358 sprintf(p, "%lu", convdiv * (*i) / convmul);
2359 len = strlen(buf);
2360 if (len > left)
2361 len = left;
2362 if(copy_to_user(s, buf, len))
2363 return -EFAULT;
2364 left -= len;
2365 s += len;
2369 if (!write && !first && left) {
2370 if(put_user('\n', s))
2371 return -EFAULT;
2372 left--, s++;
2374 if (write) {
2375 while (left) {
2376 char c;
2377 if (get_user(c, s++))
2378 return -EFAULT;
2379 if (!isspace(c))
2380 break;
2381 left--;
2384 if (write && first)
2385 return -EINVAL;
2386 *lenp -= left;
2387 *ppos += *lenp;
2388 return 0;
2389 #undef TMPBUFLEN
2392 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2393 void __user *buffer,
2394 size_t *lenp, loff_t *ppos,
2395 unsigned long convmul,
2396 unsigned long convdiv)
2398 return __do_proc_doulongvec_minmax(table->data, table, write,
2399 buffer, lenp, ppos, convmul, convdiv);
2403 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2404 * @table: the sysctl table
2405 * @write: %TRUE if this is a write to the sysctl file
2406 * @buffer: the user buffer
2407 * @lenp: the size of the user buffer
2408 * @ppos: file position
2410 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2411 * values from/to the user buffer, treated as an ASCII string.
2413 * This routine will ensure the values are within the range specified by
2414 * table->extra1 (min) and table->extra2 (max).
2416 * Returns 0 on success.
2418 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2419 void __user *buffer, size_t *lenp, loff_t *ppos)
2421 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2425 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2426 * @table: the sysctl table
2427 * @write: %TRUE if this is a write to the sysctl file
2428 * @buffer: the user buffer
2429 * @lenp: the size of the user buffer
2430 * @ppos: file position
2432 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2433 * values from/to the user buffer, treated as an ASCII string. The values
2434 * are treated as milliseconds, and converted to jiffies when they are stored.
2436 * This routine will ensure the values are within the range specified by
2437 * table->extra1 (min) and table->extra2 (max).
2439 * Returns 0 on success.
2441 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2442 void __user *buffer,
2443 size_t *lenp, loff_t *ppos)
2445 return do_proc_doulongvec_minmax(table, write, buffer,
2446 lenp, ppos, HZ, 1000l);
2450 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2451 int *valp,
2452 int write, void *data)
2454 if (write) {
2455 if (*lvalp > LONG_MAX / HZ)
2456 return 1;
2457 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2458 } else {
2459 int val = *valp;
2460 unsigned long lval;
2461 if (val < 0) {
2462 *negp = -1;
2463 lval = (unsigned long)-val;
2464 } else {
2465 *negp = 0;
2466 lval = (unsigned long)val;
2468 *lvalp = lval / HZ;
2470 return 0;
2473 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2474 int *valp,
2475 int write, void *data)
2477 if (write) {
2478 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2479 return 1;
2480 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2481 } else {
2482 int val = *valp;
2483 unsigned long lval;
2484 if (val < 0) {
2485 *negp = -1;
2486 lval = (unsigned long)-val;
2487 } else {
2488 *negp = 0;
2489 lval = (unsigned long)val;
2491 *lvalp = jiffies_to_clock_t(lval);
2493 return 0;
2496 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2497 int *valp,
2498 int write, void *data)
2500 if (write) {
2501 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2502 } else {
2503 int val = *valp;
2504 unsigned long lval;
2505 if (val < 0) {
2506 *negp = -1;
2507 lval = (unsigned long)-val;
2508 } else {
2509 *negp = 0;
2510 lval = (unsigned long)val;
2512 *lvalp = jiffies_to_msecs(lval);
2514 return 0;
2518 * proc_dointvec_jiffies - read a vector of integers as seconds
2519 * @table: the sysctl table
2520 * @write: %TRUE if this is a write to the sysctl file
2521 * @buffer: the user buffer
2522 * @lenp: the size of the user buffer
2523 * @ppos: file position
2525 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2526 * values from/to the user buffer, treated as an ASCII string.
2527 * The values read are assumed to be in seconds, and are converted into
2528 * jiffies.
2530 * Returns 0 on success.
2532 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2533 void __user *buffer, size_t *lenp, loff_t *ppos)
2535 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2536 do_proc_dointvec_jiffies_conv,NULL);
2540 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2541 * @table: the sysctl table
2542 * @write: %TRUE if this is a write to the sysctl file
2543 * @buffer: the user buffer
2544 * @lenp: the size of the user buffer
2545 * @ppos: pointer to the file position
2547 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2548 * values from/to the user buffer, treated as an ASCII string.
2549 * The values read are assumed to be in 1/USER_HZ seconds, and
2550 * are converted into jiffies.
2552 * Returns 0 on success.
2554 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2555 void __user *buffer, size_t *lenp, loff_t *ppos)
2557 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2558 do_proc_dointvec_userhz_jiffies_conv,NULL);
2562 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2563 * @table: the sysctl table
2564 * @write: %TRUE if this is a write to the sysctl file
2565 * @buffer: the user buffer
2566 * @lenp: the size of the user buffer
2567 * @ppos: file position
2568 * @ppos: the current position in the file
2570 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2571 * values from/to the user buffer, treated as an ASCII string.
2572 * The values read are assumed to be in 1/1000 seconds, and
2573 * are converted into jiffies.
2575 * Returns 0 on success.
2577 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2578 void __user *buffer, size_t *lenp, loff_t *ppos)
2580 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2581 do_proc_dointvec_ms_jiffies_conv, NULL);
2584 static int proc_do_cad_pid(struct ctl_table *table, int write,
2585 void __user *buffer, size_t *lenp, loff_t *ppos)
2587 struct pid *new_pid;
2588 pid_t tmp;
2589 int r;
2591 tmp = pid_vnr(cad_pid);
2593 r = __do_proc_dointvec(&tmp, table, write, buffer,
2594 lenp, ppos, NULL, NULL);
2595 if (r || !write)
2596 return r;
2598 new_pid = find_get_pid(tmp);
2599 if (!new_pid)
2600 return -ESRCH;
2602 put_pid(xchg(&cad_pid, new_pid));
2603 return 0;
2606 #else /* CONFIG_PROC_FS */
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_FS */
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);
2672 EXPORT_SYMBOL(register_sysctl_table);
2673 EXPORT_SYMBOL(register_sysctl_paths);
2674 EXPORT_SYMBOL(unregister_sysctl_table);