PCI hotplug: shpchp: replace printk with dev_printk
[linux-2.6/mini2440.git] / kernel / sysctl.c
bloba13bd4dfaeb1becfff933212893ea1c422ff0a04
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/utsname.h>
30 #include <linux/smp_lock.h>
31 #include <linux/fs.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.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>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
55 #ifdef CONFIG_X86
56 #include <asm/nmi.h>
57 #include <asm/stacktrace.h>
58 #include <asm/io.h>
59 #endif
61 static int deprecated_sysctl_warning(struct __sysctl_args *args);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
66 extern int C_A_D;
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
77 extern int pid_max;
78 extern int min_free_kbytes;
79 extern int pid_max_min, pid_max_max;
80 extern int sysctl_drop_caches;
81 extern int percpu_pagelist_fraction;
82 extern int compat_log;
83 extern int latencytop_enabled;
84 extern int sysctl_nr_open_min, sysctl_nr_open_max;
85 #ifdef CONFIG_RCU_TORTURE_TEST
86 extern int rcutorture_runnable;
87 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
89 /* Constants used for minimum and maximum */
90 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
91 static int one = 1;
92 #endif
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty = 60;
96 static int neg_one = -1;
97 #endif
99 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
100 static int two = 2;
101 #endif
103 static int zero;
104 static int one_hundred = 100;
106 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107 static int maxolduid = 65535;
108 static int minolduid;
109 static int min_percpu_pagelist_fract = 8;
111 static int ngroups_max = NGROUPS_MAX;
113 #ifdef CONFIG_MODULES
114 extern char modprobe_path[];
115 #endif
116 #ifdef CONFIG_CHR_DEV_SG
117 extern int sg_big_buff;
118 #endif
120 #ifdef CONFIG_SPARC
121 #include <asm/system.h>
122 #endif
124 #ifdef __hppa__
125 extern int pwrsw_enabled;
126 extern int unaligned_enabled;
127 #endif
129 #ifdef CONFIG_S390
130 #ifdef CONFIG_MATHEMU
131 extern int sysctl_ieee_emulation_warnings;
132 #endif
133 extern int sysctl_userprocess_debug;
134 extern int spin_retry;
135 #endif
137 #ifdef CONFIG_BSD_PROCESS_ACCT
138 extern int acct_parm[];
139 #endif
141 #ifdef CONFIG_IA64
142 extern int no_unaligned_warning;
143 #endif
145 #ifdef CONFIG_RT_MUTEXES
146 extern int max_lock_depth;
147 #endif
149 #ifdef CONFIG_PROC_SYSCTL
150 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
151 void __user *buffer, size_t *lenp, loff_t *ppos);
152 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
153 void __user *buffer, size_t *lenp, loff_t *ppos);
154 #endif
156 static struct ctl_table root_table[];
157 static struct ctl_table_root sysctl_table_root;
158 static struct ctl_table_header root_table_header = {
159 .count = 1,
160 .ctl_table = root_table,
161 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
162 .root = &sysctl_table_root,
163 .set = &sysctl_table_root.default_set,
165 static struct ctl_table_root sysctl_table_root = {
166 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
167 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
170 static struct ctl_table kern_table[];
171 static struct ctl_table vm_table[];
172 static struct ctl_table fs_table[];
173 static struct ctl_table debug_table[];
174 static struct ctl_table dev_table[];
175 extern struct ctl_table random_table[];
176 #ifdef CONFIG_INOTIFY_USER
177 extern struct ctl_table inotify_table[];
178 #endif
180 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
181 int sysctl_legacy_va_layout;
182 #endif
184 extern int prove_locking;
185 extern int lock_stat;
187 /* The default sysctl tables: */
189 static struct ctl_table root_table[] = {
191 .ctl_name = CTL_KERN,
192 .procname = "kernel",
193 .mode = 0555,
194 .child = kern_table,
197 .ctl_name = CTL_VM,
198 .procname = "vm",
199 .mode = 0555,
200 .child = vm_table,
203 .ctl_name = CTL_FS,
204 .procname = "fs",
205 .mode = 0555,
206 .child = fs_table,
209 .ctl_name = CTL_DEBUG,
210 .procname = "debug",
211 .mode = 0555,
212 .child = debug_table,
215 .ctl_name = CTL_DEV,
216 .procname = "dev",
217 .mode = 0555,
218 .child = dev_table,
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
224 { .ctl_name = 0 }
227 #ifdef CONFIG_SCHED_DEBUG
228 static int min_sched_granularity_ns = 100000; /* 100 usecs */
229 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230 static int min_wakeup_granularity_ns; /* 0 usecs */
231 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
232 #endif
234 static struct ctl_table kern_table[] = {
235 #ifdef CONFIG_SCHED_DEBUG
237 .ctl_name = CTL_UNNUMBERED,
238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
240 .maxlen = sizeof(unsigned int),
241 .mode = 0644,
242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
248 .ctl_name = CTL_UNNUMBERED,
249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
259 .ctl_name = CTL_UNNUMBERED,
260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "sched_shares_ratelimit",
272 .data = &sysctl_sched_shares_ratelimit,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec,
278 .ctl_name = CTL_UNNUMBERED,
279 .procname = "sched_shares_thresh",
280 .data = &sysctl_sched_shares_thresh,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec_minmax,
284 .strategy = &sysctl_intvec,
285 .extra1 = &zero,
288 .ctl_name = CTL_UNNUMBERED,
289 .procname = "sched_child_runs_first",
290 .data = &sysctl_sched_child_runs_first,
291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
293 .proc_handler = &proc_dointvec,
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_features",
298 .data = &sysctl_sched_features,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
301 .proc_handler = &proc_dointvec,
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_migration_cost",
306 .data = &sysctl_sched_migration_cost,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = &proc_dointvec,
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "sched_nr_migrate",
314 .data = &sysctl_sched_nr_migrate,
315 .maxlen = sizeof(unsigned int),
316 .mode = 0644,
317 .proc_handler = &proc_dointvec,
319 #endif
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_rt_period_us",
323 .data = &sysctl_sched_rt_period,
324 .maxlen = sizeof(unsigned int),
325 .mode = 0644,
326 .proc_handler = &sched_rt_handler,
329 .ctl_name = CTL_UNNUMBERED,
330 .procname = "sched_rt_runtime_us",
331 .data = &sysctl_sched_rt_runtime,
332 .maxlen = sizeof(int),
333 .mode = 0644,
334 .proc_handler = &sched_rt_handler,
337 .ctl_name = CTL_UNNUMBERED,
338 .procname = "sched_compat_yield",
339 .data = &sysctl_sched_compat_yield,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
344 #ifdef CONFIG_PROVE_LOCKING
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "prove_locking",
348 .data = &prove_locking,
349 .maxlen = sizeof(int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec,
353 #endif
354 #ifdef CONFIG_LOCK_STAT
356 .ctl_name = CTL_UNNUMBERED,
357 .procname = "lock_stat",
358 .data = &lock_stat,
359 .maxlen = sizeof(int),
360 .mode = 0644,
361 .proc_handler = &proc_dointvec,
363 #endif
365 .ctl_name = KERN_PANIC,
366 .procname = "panic",
367 .data = &panic_timeout,
368 .maxlen = sizeof(int),
369 .mode = 0644,
370 .proc_handler = &proc_dointvec,
373 .ctl_name = KERN_CORE_USES_PID,
374 .procname = "core_uses_pid",
375 .data = &core_uses_pid,
376 .maxlen = sizeof(int),
377 .mode = 0644,
378 .proc_handler = &proc_dointvec,
381 .ctl_name = KERN_CORE_PATTERN,
382 .procname = "core_pattern",
383 .data = core_pattern,
384 .maxlen = CORENAME_MAX_SIZE,
385 .mode = 0644,
386 .proc_handler = &proc_dostring,
387 .strategy = &sysctl_string,
389 #ifdef CONFIG_PROC_SYSCTL
391 .procname = "tainted",
392 .maxlen = sizeof(long),
393 .mode = 0644,
394 .proc_handler = &proc_taint,
396 #endif
397 #ifdef CONFIG_LATENCYTOP
399 .procname = "latencytop",
400 .data = &latencytop_enabled,
401 .maxlen = sizeof(int),
402 .mode = 0644,
403 .proc_handler = &proc_dointvec,
405 #endif
406 #ifdef CONFIG_BLK_DEV_INITRD
408 .ctl_name = KERN_REALROOTDEV,
409 .procname = "real-root-dev",
410 .data = &real_root_dev,
411 .maxlen = sizeof(int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
415 #endif
417 .ctl_name = CTL_UNNUMBERED,
418 .procname = "print-fatal-signals",
419 .data = &print_fatal_signals,
420 .maxlen = sizeof(int),
421 .mode = 0644,
422 .proc_handler = &proc_dointvec,
424 #ifdef CONFIG_SPARC
426 .ctl_name = KERN_SPARC_REBOOT,
427 .procname = "reboot-cmd",
428 .data = reboot_command,
429 .maxlen = 256,
430 .mode = 0644,
431 .proc_handler = &proc_dostring,
432 .strategy = &sysctl_string,
435 .ctl_name = KERN_SPARC_STOP_A,
436 .procname = "stop-a",
437 .data = &stop_a_enabled,
438 .maxlen = sizeof (int),
439 .mode = 0644,
440 .proc_handler = &proc_dointvec,
443 .ctl_name = KERN_SPARC_SCONS_PWROFF,
444 .procname = "scons-poweroff",
445 .data = &scons_pwroff,
446 .maxlen = sizeof (int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
450 #endif
451 #ifdef __hppa__
453 .ctl_name = KERN_HPPA_PWRSW,
454 .procname = "soft-power",
455 .data = &pwrsw_enabled,
456 .maxlen = sizeof (int),
457 .mode = 0644,
458 .proc_handler = &proc_dointvec,
461 .ctl_name = KERN_HPPA_UNALIGNED,
462 .procname = "unaligned-trap",
463 .data = &unaligned_enabled,
464 .maxlen = sizeof (int),
465 .mode = 0644,
466 .proc_handler = &proc_dointvec,
468 #endif
470 .ctl_name = KERN_CTLALTDEL,
471 .procname = "ctrl-alt-del",
472 .data = &C_A_D,
473 .maxlen = sizeof(int),
474 .mode = 0644,
475 .proc_handler = &proc_dointvec,
477 #ifdef CONFIG_FTRACE
479 .ctl_name = CTL_UNNUMBERED,
480 .procname = "ftrace_enabled",
481 .data = &ftrace_enabled,
482 .maxlen = sizeof(int),
483 .mode = 0644,
484 .proc_handler = &ftrace_enable_sysctl,
486 #endif
487 #ifdef CONFIG_MODULES
489 .ctl_name = KERN_MODPROBE,
490 .procname = "modprobe",
491 .data = &modprobe_path,
492 .maxlen = KMOD_PATH_LEN,
493 .mode = 0644,
494 .proc_handler = &proc_dostring,
495 .strategy = &sysctl_string,
497 #endif
498 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
500 .ctl_name = KERN_HOTPLUG,
501 .procname = "hotplug",
502 .data = &uevent_helper,
503 .maxlen = UEVENT_HELPER_PATH_LEN,
504 .mode = 0644,
505 .proc_handler = &proc_dostring,
506 .strategy = &sysctl_string,
508 #endif
509 #ifdef CONFIG_CHR_DEV_SG
511 .ctl_name = KERN_SG_BIG_BUFF,
512 .procname = "sg-big-buff",
513 .data = &sg_big_buff,
514 .maxlen = sizeof (int),
515 .mode = 0444,
516 .proc_handler = &proc_dointvec,
518 #endif
519 #ifdef CONFIG_BSD_PROCESS_ACCT
521 .ctl_name = KERN_ACCT,
522 .procname = "acct",
523 .data = &acct_parm,
524 .maxlen = 3*sizeof(int),
525 .mode = 0644,
526 .proc_handler = &proc_dointvec,
528 #endif
529 #ifdef CONFIG_MAGIC_SYSRQ
531 .ctl_name = KERN_SYSRQ,
532 .procname = "sysrq",
533 .data = &__sysrq_enabled,
534 .maxlen = sizeof (int),
535 .mode = 0644,
536 .proc_handler = &proc_dointvec,
538 #endif
539 #ifdef CONFIG_PROC_SYSCTL
541 .procname = "cad_pid",
542 .data = NULL,
543 .maxlen = sizeof (int),
544 .mode = 0600,
545 .proc_handler = &proc_do_cad_pid,
547 #endif
549 .ctl_name = KERN_MAX_THREADS,
550 .procname = "threads-max",
551 .data = &max_threads,
552 .maxlen = sizeof(int),
553 .mode = 0644,
554 .proc_handler = &proc_dointvec,
557 .ctl_name = KERN_RANDOM,
558 .procname = "random",
559 .mode = 0555,
560 .child = random_table,
563 .ctl_name = KERN_OVERFLOWUID,
564 .procname = "overflowuid",
565 .data = &overflowuid,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec_minmax,
569 .strategy = &sysctl_intvec,
570 .extra1 = &minolduid,
571 .extra2 = &maxolduid,
574 .ctl_name = KERN_OVERFLOWGID,
575 .procname = "overflowgid",
576 .data = &overflowgid,
577 .maxlen = sizeof(int),
578 .mode = 0644,
579 .proc_handler = &proc_dointvec_minmax,
580 .strategy = &sysctl_intvec,
581 .extra1 = &minolduid,
582 .extra2 = &maxolduid,
584 #ifdef CONFIG_S390
585 #ifdef CONFIG_MATHEMU
587 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
588 .procname = "ieee_emulation_warnings",
589 .data = &sysctl_ieee_emulation_warnings,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec,
594 #endif
596 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
597 .procname = "userprocess_debug",
598 .data = &sysctl_userprocess_debug,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = &proc_dointvec,
603 #endif
605 .ctl_name = KERN_PIDMAX,
606 .procname = "pid_max",
607 .data = &pid_max,
608 .maxlen = sizeof (int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec_minmax,
611 .strategy = sysctl_intvec,
612 .extra1 = &pid_max_min,
613 .extra2 = &pid_max_max,
616 .ctl_name = KERN_PANIC_ON_OOPS,
617 .procname = "panic_on_oops",
618 .data = &panic_on_oops,
619 .maxlen = sizeof(int),
620 .mode = 0644,
621 .proc_handler = &proc_dointvec,
623 #if defined CONFIG_PRINTK
625 .ctl_name = KERN_PRINTK,
626 .procname = "printk",
627 .data = &console_loglevel,
628 .maxlen = 4*sizeof(int),
629 .mode = 0644,
630 .proc_handler = &proc_dointvec,
633 .ctl_name = KERN_PRINTK_RATELIMIT,
634 .procname = "printk_ratelimit",
635 .data = &printk_ratelimit_state.interval,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec_jiffies,
639 .strategy = &sysctl_jiffies,
642 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
643 .procname = "printk_ratelimit_burst",
644 .data = &printk_ratelimit_state.burst,
645 .maxlen = sizeof(int),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec,
649 #endif
651 .ctl_name = KERN_NGROUPS_MAX,
652 .procname = "ngroups_max",
653 .data = &ngroups_max,
654 .maxlen = sizeof (int),
655 .mode = 0444,
656 .proc_handler = &proc_dointvec,
658 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
660 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
661 .procname = "unknown_nmi_panic",
662 .data = &unknown_nmi_panic,
663 .maxlen = sizeof (int),
664 .mode = 0644,
665 .proc_handler = &proc_dointvec,
668 .procname = "nmi_watchdog",
669 .data = &nmi_watchdog_enabled,
670 .maxlen = sizeof (int),
671 .mode = 0644,
672 .proc_handler = &proc_nmi_enabled,
674 #endif
675 #if defined(CONFIG_X86)
677 .ctl_name = KERN_PANIC_ON_NMI,
678 .procname = "panic_on_unrecovered_nmi",
679 .data = &panic_on_unrecovered_nmi,
680 .maxlen = sizeof(int),
681 .mode = 0644,
682 .proc_handler = &proc_dointvec,
685 .ctl_name = KERN_BOOTLOADER_TYPE,
686 .procname = "bootloader_type",
687 .data = &bootloader_type,
688 .maxlen = sizeof (int),
689 .mode = 0444,
690 .proc_handler = &proc_dointvec,
693 .ctl_name = CTL_UNNUMBERED,
694 .procname = "kstack_depth_to_print",
695 .data = &kstack_depth_to_print,
696 .maxlen = sizeof(int),
697 .mode = 0644,
698 .proc_handler = &proc_dointvec,
701 .ctl_name = CTL_UNNUMBERED,
702 .procname = "io_delay_type",
703 .data = &io_delay_type,
704 .maxlen = sizeof(int),
705 .mode = 0644,
706 .proc_handler = &proc_dointvec,
708 #endif
709 #if defined(CONFIG_MMU)
711 .ctl_name = KERN_RANDOMIZE,
712 .procname = "randomize_va_space",
713 .data = &randomize_va_space,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = &proc_dointvec,
718 #endif
719 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
721 .ctl_name = KERN_SPIN_RETRY,
722 .procname = "spin_retry",
723 .data = &spin_retry,
724 .maxlen = sizeof (int),
725 .mode = 0644,
726 .proc_handler = &proc_dointvec,
728 #endif
729 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
731 .procname = "acpi_video_flags",
732 .data = &acpi_realmode_flags,
733 .maxlen = sizeof (unsigned long),
734 .mode = 0644,
735 .proc_handler = &proc_doulongvec_minmax,
737 #endif
738 #ifdef CONFIG_IA64
740 .ctl_name = KERN_IA64_UNALIGNED,
741 .procname = "ignore-unaligned-usertrap",
742 .data = &no_unaligned_warning,
743 .maxlen = sizeof (int),
744 .mode = 0644,
745 .proc_handler = &proc_dointvec,
747 #endif
748 #ifdef CONFIG_DETECT_SOFTLOCKUP
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "softlockup_panic",
752 .data = &softlockup_panic,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = &proc_dointvec_minmax,
756 .strategy = &sysctl_intvec,
757 .extra1 = &zero,
758 .extra2 = &one,
761 .ctl_name = CTL_UNNUMBERED,
762 .procname = "softlockup_thresh",
763 .data = &softlockup_thresh,
764 .maxlen = sizeof(int),
765 .mode = 0644,
766 .proc_handler = &proc_dointvec_minmax,
767 .strategy = &sysctl_intvec,
768 .extra1 = &neg_one,
769 .extra2 = &sixty,
772 .ctl_name = CTL_UNNUMBERED,
773 .procname = "hung_task_check_count",
774 .data = &sysctl_hung_task_check_count,
775 .maxlen = sizeof(unsigned long),
776 .mode = 0644,
777 .proc_handler = &proc_doulongvec_minmax,
778 .strategy = &sysctl_intvec,
781 .ctl_name = CTL_UNNUMBERED,
782 .procname = "hung_task_timeout_secs",
783 .data = &sysctl_hung_task_timeout_secs,
784 .maxlen = sizeof(unsigned long),
785 .mode = 0644,
786 .proc_handler = &proc_doulongvec_minmax,
787 .strategy = &sysctl_intvec,
790 .ctl_name = CTL_UNNUMBERED,
791 .procname = "hung_task_warnings",
792 .data = &sysctl_hung_task_warnings,
793 .maxlen = sizeof(unsigned long),
794 .mode = 0644,
795 .proc_handler = &proc_doulongvec_minmax,
796 .strategy = &sysctl_intvec,
798 #endif
799 #ifdef CONFIG_COMPAT
801 .ctl_name = KERN_COMPAT_LOG,
802 .procname = "compat-log",
803 .data = &compat_log,
804 .maxlen = sizeof (int),
805 .mode = 0644,
806 .proc_handler = &proc_dointvec,
808 #endif
809 #ifdef CONFIG_RT_MUTEXES
811 .ctl_name = KERN_MAX_LOCK_DEPTH,
812 .procname = "max_lock_depth",
813 .data = &max_lock_depth,
814 .maxlen = sizeof(int),
815 .mode = 0644,
816 .proc_handler = &proc_dointvec,
818 #endif
820 .ctl_name = CTL_UNNUMBERED,
821 .procname = "poweroff_cmd",
822 .data = &poweroff_cmd,
823 .maxlen = POWEROFF_CMD_PATH_LEN,
824 .mode = 0644,
825 .proc_handler = &proc_dostring,
826 .strategy = &sysctl_string,
828 #ifdef CONFIG_KEYS
830 .ctl_name = CTL_UNNUMBERED,
831 .procname = "keys",
832 .mode = 0555,
833 .child = key_sysctls,
835 #endif
836 #ifdef CONFIG_RCU_TORTURE_TEST
838 .ctl_name = CTL_UNNUMBERED,
839 .procname = "rcutorture_runnable",
840 .data = &rcutorture_runnable,
841 .maxlen = sizeof(int),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec,
845 #endif
846 #ifdef CONFIG_UNEVICTABLE_LRU
848 .ctl_name = CTL_UNNUMBERED,
849 .procname = "scan_unevictable_pages",
850 .data = &scan_unevictable_pages,
851 .maxlen = sizeof(scan_unevictable_pages),
852 .mode = 0644,
853 .proc_handler = &scan_unevictable_handler,
855 #endif
857 * NOTE: do not add new entries to this table unless you have read
858 * Documentation/sysctl/ctl_unnumbered.txt
860 { .ctl_name = 0 }
863 static struct ctl_table vm_table[] = {
865 .ctl_name = VM_OVERCOMMIT_MEMORY,
866 .procname = "overcommit_memory",
867 .data = &sysctl_overcommit_memory,
868 .maxlen = sizeof(sysctl_overcommit_memory),
869 .mode = 0644,
870 .proc_handler = &proc_dointvec,
873 .ctl_name = VM_PANIC_ON_OOM,
874 .procname = "panic_on_oom",
875 .data = &sysctl_panic_on_oom,
876 .maxlen = sizeof(sysctl_panic_on_oom),
877 .mode = 0644,
878 .proc_handler = &proc_dointvec,
881 .ctl_name = CTL_UNNUMBERED,
882 .procname = "oom_kill_allocating_task",
883 .data = &sysctl_oom_kill_allocating_task,
884 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
885 .mode = 0644,
886 .proc_handler = &proc_dointvec,
889 .ctl_name = CTL_UNNUMBERED,
890 .procname = "oom_dump_tasks",
891 .data = &sysctl_oom_dump_tasks,
892 .maxlen = sizeof(sysctl_oom_dump_tasks),
893 .mode = 0644,
894 .proc_handler = &proc_dointvec,
897 .ctl_name = VM_OVERCOMMIT_RATIO,
898 .procname = "overcommit_ratio",
899 .data = &sysctl_overcommit_ratio,
900 .maxlen = sizeof(sysctl_overcommit_ratio),
901 .mode = 0644,
902 .proc_handler = &proc_dointvec,
905 .ctl_name = VM_PAGE_CLUSTER,
906 .procname = "page-cluster",
907 .data = &page_cluster,
908 .maxlen = sizeof(int),
909 .mode = 0644,
910 .proc_handler = &proc_dointvec,
913 .ctl_name = VM_DIRTY_BACKGROUND,
914 .procname = "dirty_background_ratio",
915 .data = &dirty_background_ratio,
916 .maxlen = sizeof(dirty_background_ratio),
917 .mode = 0644,
918 .proc_handler = &proc_dointvec_minmax,
919 .strategy = &sysctl_intvec,
920 .extra1 = &zero,
921 .extra2 = &one_hundred,
924 .ctl_name = VM_DIRTY_RATIO,
925 .procname = "dirty_ratio",
926 .data = &vm_dirty_ratio,
927 .maxlen = sizeof(vm_dirty_ratio),
928 .mode = 0644,
929 .proc_handler = &dirty_ratio_handler,
930 .strategy = &sysctl_intvec,
931 .extra1 = &zero,
932 .extra2 = &one_hundred,
935 .procname = "dirty_writeback_centisecs",
936 .data = &dirty_writeback_interval,
937 .maxlen = sizeof(dirty_writeback_interval),
938 .mode = 0644,
939 .proc_handler = &dirty_writeback_centisecs_handler,
942 .procname = "dirty_expire_centisecs",
943 .data = &dirty_expire_interval,
944 .maxlen = sizeof(dirty_expire_interval),
945 .mode = 0644,
946 .proc_handler = &proc_dointvec_userhz_jiffies,
949 .ctl_name = VM_NR_PDFLUSH_THREADS,
950 .procname = "nr_pdflush_threads",
951 .data = &nr_pdflush_threads,
952 .maxlen = sizeof nr_pdflush_threads,
953 .mode = 0444 /* read-only*/,
954 .proc_handler = &proc_dointvec,
957 .ctl_name = VM_SWAPPINESS,
958 .procname = "swappiness",
959 .data = &vm_swappiness,
960 .maxlen = sizeof(vm_swappiness),
961 .mode = 0644,
962 .proc_handler = &proc_dointvec_minmax,
963 .strategy = &sysctl_intvec,
964 .extra1 = &zero,
965 .extra2 = &one_hundred,
967 #ifdef CONFIG_HUGETLB_PAGE
969 .procname = "nr_hugepages",
970 .data = NULL,
971 .maxlen = sizeof(unsigned long),
972 .mode = 0644,
973 .proc_handler = &hugetlb_sysctl_handler,
974 .extra1 = (void *)&hugetlb_zero,
975 .extra2 = (void *)&hugetlb_infinity,
978 .ctl_name = VM_HUGETLB_GROUP,
979 .procname = "hugetlb_shm_group",
980 .data = &sysctl_hugetlb_shm_group,
981 .maxlen = sizeof(gid_t),
982 .mode = 0644,
983 .proc_handler = &proc_dointvec,
986 .ctl_name = CTL_UNNUMBERED,
987 .procname = "hugepages_treat_as_movable",
988 .data = &hugepages_treat_as_movable,
989 .maxlen = sizeof(int),
990 .mode = 0644,
991 .proc_handler = &hugetlb_treat_movable_handler,
994 .ctl_name = CTL_UNNUMBERED,
995 .procname = "nr_overcommit_hugepages",
996 .data = NULL,
997 .maxlen = sizeof(unsigned long),
998 .mode = 0644,
999 .proc_handler = &hugetlb_overcommit_handler,
1000 .extra1 = (void *)&hugetlb_zero,
1001 .extra2 = (void *)&hugetlb_infinity,
1003 #endif
1005 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1006 .procname = "lowmem_reserve_ratio",
1007 .data = &sysctl_lowmem_reserve_ratio,
1008 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1009 .mode = 0644,
1010 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1011 .strategy = &sysctl_intvec,
1014 .ctl_name = VM_DROP_PAGECACHE,
1015 .procname = "drop_caches",
1016 .data = &sysctl_drop_caches,
1017 .maxlen = sizeof(int),
1018 .mode = 0644,
1019 .proc_handler = drop_caches_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1023 .ctl_name = VM_MIN_FREE_KBYTES,
1024 .procname = "min_free_kbytes",
1025 .data = &min_free_kbytes,
1026 .maxlen = sizeof(min_free_kbytes),
1027 .mode = 0644,
1028 .proc_handler = &min_free_kbytes_sysctl_handler,
1029 .strategy = &sysctl_intvec,
1030 .extra1 = &zero,
1033 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1034 .procname = "percpu_pagelist_fraction",
1035 .data = &percpu_pagelist_fraction,
1036 .maxlen = sizeof(percpu_pagelist_fraction),
1037 .mode = 0644,
1038 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1039 .strategy = &sysctl_intvec,
1040 .extra1 = &min_percpu_pagelist_fract,
1042 #ifdef CONFIG_MMU
1044 .ctl_name = VM_MAX_MAP_COUNT,
1045 .procname = "max_map_count",
1046 .data = &sysctl_max_map_count,
1047 .maxlen = sizeof(sysctl_max_map_count),
1048 .mode = 0644,
1049 .proc_handler = &proc_dointvec
1051 #endif
1053 .ctl_name = VM_LAPTOP_MODE,
1054 .procname = "laptop_mode",
1055 .data = &laptop_mode,
1056 .maxlen = sizeof(laptop_mode),
1057 .mode = 0644,
1058 .proc_handler = &proc_dointvec_jiffies,
1059 .strategy = &sysctl_jiffies,
1062 .ctl_name = VM_BLOCK_DUMP,
1063 .procname = "block_dump",
1064 .data = &block_dump,
1065 .maxlen = sizeof(block_dump),
1066 .mode = 0644,
1067 .proc_handler = &proc_dointvec,
1068 .strategy = &sysctl_intvec,
1069 .extra1 = &zero,
1072 .ctl_name = VM_VFS_CACHE_PRESSURE,
1073 .procname = "vfs_cache_pressure",
1074 .data = &sysctl_vfs_cache_pressure,
1075 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1076 .mode = 0644,
1077 .proc_handler = &proc_dointvec,
1078 .strategy = &sysctl_intvec,
1079 .extra1 = &zero,
1081 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1083 .ctl_name = VM_LEGACY_VA_LAYOUT,
1084 .procname = "legacy_va_layout",
1085 .data = &sysctl_legacy_va_layout,
1086 .maxlen = sizeof(sysctl_legacy_va_layout),
1087 .mode = 0644,
1088 .proc_handler = &proc_dointvec,
1089 .strategy = &sysctl_intvec,
1090 .extra1 = &zero,
1092 #endif
1093 #ifdef CONFIG_NUMA
1095 .ctl_name = VM_ZONE_RECLAIM_MODE,
1096 .procname = "zone_reclaim_mode",
1097 .data = &zone_reclaim_mode,
1098 .maxlen = sizeof(zone_reclaim_mode),
1099 .mode = 0644,
1100 .proc_handler = &proc_dointvec,
1101 .strategy = &sysctl_intvec,
1102 .extra1 = &zero,
1105 .ctl_name = VM_MIN_UNMAPPED,
1106 .procname = "min_unmapped_ratio",
1107 .data = &sysctl_min_unmapped_ratio,
1108 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1109 .mode = 0644,
1110 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1111 .strategy = &sysctl_intvec,
1112 .extra1 = &zero,
1113 .extra2 = &one_hundred,
1116 .ctl_name = VM_MIN_SLAB,
1117 .procname = "min_slab_ratio",
1118 .data = &sysctl_min_slab_ratio,
1119 .maxlen = sizeof(sysctl_min_slab_ratio),
1120 .mode = 0644,
1121 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1122 .strategy = &sysctl_intvec,
1123 .extra1 = &zero,
1124 .extra2 = &one_hundred,
1126 #endif
1127 #ifdef CONFIG_SMP
1129 .ctl_name = CTL_UNNUMBERED,
1130 .procname = "stat_interval",
1131 .data = &sysctl_stat_interval,
1132 .maxlen = sizeof(sysctl_stat_interval),
1133 .mode = 0644,
1134 .proc_handler = &proc_dointvec_jiffies,
1135 .strategy = &sysctl_jiffies,
1137 #endif
1138 #ifdef CONFIG_SECURITY
1140 .ctl_name = CTL_UNNUMBERED,
1141 .procname = "mmap_min_addr",
1142 .data = &mmap_min_addr,
1143 .maxlen = sizeof(unsigned long),
1144 .mode = 0644,
1145 .proc_handler = &proc_doulongvec_minmax,
1147 #endif
1148 #ifdef CONFIG_NUMA
1150 .ctl_name = CTL_UNNUMBERED,
1151 .procname = "numa_zonelist_order",
1152 .data = &numa_zonelist_order,
1153 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1154 .mode = 0644,
1155 .proc_handler = &numa_zonelist_order_handler,
1156 .strategy = &sysctl_string,
1158 #endif
1159 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1160 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1162 .ctl_name = VM_VDSO_ENABLED,
1163 .procname = "vdso_enabled",
1164 .data = &vdso_enabled,
1165 .maxlen = sizeof(vdso_enabled),
1166 .mode = 0644,
1167 .proc_handler = &proc_dointvec,
1168 .strategy = &sysctl_intvec,
1169 .extra1 = &zero,
1171 #endif
1172 #ifdef CONFIG_HIGHMEM
1174 .ctl_name = CTL_UNNUMBERED,
1175 .procname = "highmem_is_dirtyable",
1176 .data = &vm_highmem_is_dirtyable,
1177 .maxlen = sizeof(vm_highmem_is_dirtyable),
1178 .mode = 0644,
1179 .proc_handler = &proc_dointvec_minmax,
1180 .strategy = &sysctl_intvec,
1181 .extra1 = &zero,
1182 .extra2 = &one,
1184 #endif
1186 * NOTE: do not add new entries to this table unless you have read
1187 * Documentation/sysctl/ctl_unnumbered.txt
1189 { .ctl_name = 0 }
1192 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1193 static struct ctl_table binfmt_misc_table[] = {
1194 { .ctl_name = 0 }
1196 #endif
1198 static struct ctl_table fs_table[] = {
1200 .ctl_name = FS_NRINODE,
1201 .procname = "inode-nr",
1202 .data = &inodes_stat,
1203 .maxlen = 2*sizeof(int),
1204 .mode = 0444,
1205 .proc_handler = &proc_dointvec,
1208 .ctl_name = FS_STATINODE,
1209 .procname = "inode-state",
1210 .data = &inodes_stat,
1211 .maxlen = 7*sizeof(int),
1212 .mode = 0444,
1213 .proc_handler = &proc_dointvec,
1216 .procname = "file-nr",
1217 .data = &files_stat,
1218 .maxlen = 3*sizeof(int),
1219 .mode = 0444,
1220 .proc_handler = &proc_nr_files,
1223 .ctl_name = FS_MAXFILE,
1224 .procname = "file-max",
1225 .data = &files_stat.max_files,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
1228 .proc_handler = &proc_dointvec,
1231 .ctl_name = CTL_UNNUMBERED,
1232 .procname = "nr_open",
1233 .data = &sysctl_nr_open,
1234 .maxlen = sizeof(int),
1235 .mode = 0644,
1236 .proc_handler = &proc_dointvec_minmax,
1237 .extra1 = &sysctl_nr_open_min,
1238 .extra2 = &sysctl_nr_open_max,
1241 .ctl_name = FS_DENTRY,
1242 .procname = "dentry-state",
1243 .data = &dentry_stat,
1244 .maxlen = 6*sizeof(int),
1245 .mode = 0444,
1246 .proc_handler = &proc_dointvec,
1249 .ctl_name = FS_OVERFLOWUID,
1250 .procname = "overflowuid",
1251 .data = &fs_overflowuid,
1252 .maxlen = sizeof(int),
1253 .mode = 0644,
1254 .proc_handler = &proc_dointvec_minmax,
1255 .strategy = &sysctl_intvec,
1256 .extra1 = &minolduid,
1257 .extra2 = &maxolduid,
1260 .ctl_name = FS_OVERFLOWGID,
1261 .procname = "overflowgid",
1262 .data = &fs_overflowgid,
1263 .maxlen = sizeof(int),
1264 .mode = 0644,
1265 .proc_handler = &proc_dointvec_minmax,
1266 .strategy = &sysctl_intvec,
1267 .extra1 = &minolduid,
1268 .extra2 = &maxolduid,
1270 #ifdef CONFIG_FILE_LOCKING
1272 .ctl_name = FS_LEASES,
1273 .procname = "leases-enable",
1274 .data = &leases_enable,
1275 .maxlen = sizeof(int),
1276 .mode = 0644,
1277 .proc_handler = &proc_dointvec,
1279 #endif
1280 #ifdef CONFIG_DNOTIFY
1282 .ctl_name = FS_DIR_NOTIFY,
1283 .procname = "dir-notify-enable",
1284 .data = &dir_notify_enable,
1285 .maxlen = sizeof(int),
1286 .mode = 0644,
1287 .proc_handler = &proc_dointvec,
1289 #endif
1290 #ifdef CONFIG_MMU
1291 #ifdef CONFIG_FILE_LOCKING
1293 .ctl_name = FS_LEASE_TIME,
1294 .procname = "lease-break-time",
1295 .data = &lease_break_time,
1296 .maxlen = sizeof(int),
1297 .mode = 0644,
1298 .proc_handler = &proc_dointvec_minmax,
1299 .strategy = &sysctl_intvec,
1300 .extra1 = &zero,
1301 .extra2 = &two,
1303 #endif
1304 #ifdef CONFIG_AIO
1306 .procname = "aio-nr",
1307 .data = &aio_nr,
1308 .maxlen = sizeof(aio_nr),
1309 .mode = 0444,
1310 .proc_handler = &proc_doulongvec_minmax,
1313 .procname = "aio-max-nr",
1314 .data = &aio_max_nr,
1315 .maxlen = sizeof(aio_max_nr),
1316 .mode = 0644,
1317 .proc_handler = &proc_doulongvec_minmax,
1319 #endif /* CONFIG_AIO */
1320 #ifdef CONFIG_INOTIFY_USER
1322 .ctl_name = FS_INOTIFY,
1323 .procname = "inotify",
1324 .mode = 0555,
1325 .child = inotify_table,
1327 #endif
1328 #endif
1330 .ctl_name = KERN_SETUID_DUMPABLE,
1331 .procname = "suid_dumpable",
1332 .data = &suid_dumpable,
1333 .maxlen = sizeof(int),
1334 .mode = 0644,
1335 .proc_handler = &proc_dointvec,
1337 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1339 .ctl_name = CTL_UNNUMBERED,
1340 .procname = "binfmt_misc",
1341 .mode = 0555,
1342 .child = binfmt_misc_table,
1344 #endif
1346 * NOTE: do not add new entries to this table unless you have read
1347 * Documentation/sysctl/ctl_unnumbered.txt
1349 { .ctl_name = 0 }
1352 static struct ctl_table debug_table[] = {
1353 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1355 .ctl_name = CTL_UNNUMBERED,
1356 .procname = "exception-trace",
1357 .data = &show_unhandled_signals,
1358 .maxlen = sizeof(int),
1359 .mode = 0644,
1360 .proc_handler = proc_dointvec
1362 #endif
1363 { .ctl_name = 0 }
1366 static struct ctl_table dev_table[] = {
1367 { .ctl_name = 0 }
1370 static DEFINE_SPINLOCK(sysctl_lock);
1372 /* called under sysctl_lock */
1373 static int use_table(struct ctl_table_header *p)
1375 if (unlikely(p->unregistering))
1376 return 0;
1377 p->used++;
1378 return 1;
1381 /* called under sysctl_lock */
1382 static void unuse_table(struct ctl_table_header *p)
1384 if (!--p->used)
1385 if (unlikely(p->unregistering))
1386 complete(p->unregistering);
1389 /* called under sysctl_lock, will reacquire if has to wait */
1390 static void start_unregistering(struct ctl_table_header *p)
1393 * if p->used is 0, nobody will ever touch that entry again;
1394 * we'll eliminate all paths to it before dropping sysctl_lock
1396 if (unlikely(p->used)) {
1397 struct completion wait;
1398 init_completion(&wait);
1399 p->unregistering = &wait;
1400 spin_unlock(&sysctl_lock);
1401 wait_for_completion(&wait);
1402 spin_lock(&sysctl_lock);
1403 } else {
1404 /* anything non-NULL; we'll never dereference it */
1405 p->unregistering = ERR_PTR(-EINVAL);
1408 * do not remove from the list until nobody holds it; walking the
1409 * list in do_sysctl() relies on that.
1411 list_del_init(&p->ctl_entry);
1414 void sysctl_head_get(struct ctl_table_header *head)
1416 spin_lock(&sysctl_lock);
1417 head->count++;
1418 spin_unlock(&sysctl_lock);
1421 void sysctl_head_put(struct ctl_table_header *head)
1423 spin_lock(&sysctl_lock);
1424 if (!--head->count)
1425 kfree(head);
1426 spin_unlock(&sysctl_lock);
1429 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1431 if (!head)
1432 BUG();
1433 spin_lock(&sysctl_lock);
1434 if (!use_table(head))
1435 head = ERR_PTR(-ENOENT);
1436 spin_unlock(&sysctl_lock);
1437 return head;
1440 void sysctl_head_finish(struct ctl_table_header *head)
1442 if (!head)
1443 return;
1444 spin_lock(&sysctl_lock);
1445 unuse_table(head);
1446 spin_unlock(&sysctl_lock);
1449 static struct ctl_table_set *
1450 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1452 struct ctl_table_set *set = &root->default_set;
1453 if (root->lookup)
1454 set = root->lookup(root, namespaces);
1455 return set;
1458 static struct list_head *
1459 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1461 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1462 return &set->list;
1465 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1466 struct ctl_table_header *prev)
1468 struct ctl_table_root *root;
1469 struct list_head *header_list;
1470 struct ctl_table_header *head;
1471 struct list_head *tmp;
1473 spin_lock(&sysctl_lock);
1474 if (prev) {
1475 head = prev;
1476 tmp = &prev->ctl_entry;
1477 unuse_table(prev);
1478 goto next;
1480 tmp = &root_table_header.ctl_entry;
1481 for (;;) {
1482 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1484 if (!use_table(head))
1485 goto next;
1486 spin_unlock(&sysctl_lock);
1487 return head;
1488 next:
1489 root = head->root;
1490 tmp = tmp->next;
1491 header_list = lookup_header_list(root, namespaces);
1492 if (tmp != header_list)
1493 continue;
1495 do {
1496 root = list_entry(root->root_list.next,
1497 struct ctl_table_root, root_list);
1498 if (root == &sysctl_table_root)
1499 goto out;
1500 header_list = lookup_header_list(root, namespaces);
1501 } while (list_empty(header_list));
1502 tmp = header_list->next;
1504 out:
1505 spin_unlock(&sysctl_lock);
1506 return NULL;
1509 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1511 return __sysctl_head_next(current->nsproxy, prev);
1514 void register_sysctl_root(struct ctl_table_root *root)
1516 spin_lock(&sysctl_lock);
1517 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1518 spin_unlock(&sysctl_lock);
1521 #ifdef CONFIG_SYSCTL_SYSCALL
1522 /* Perform the actual read/write of a sysctl table entry. */
1523 static int do_sysctl_strategy(struct ctl_table_root *root,
1524 struct ctl_table *table,
1525 void __user *oldval, size_t __user *oldlenp,
1526 void __user *newval, size_t newlen)
1528 int op = 0, rc;
1530 if (oldval)
1531 op |= MAY_READ;
1532 if (newval)
1533 op |= MAY_WRITE;
1534 if (sysctl_perm(root, table, op))
1535 return -EPERM;
1537 if (table->strategy) {
1538 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1539 if (rc < 0)
1540 return rc;
1541 if (rc > 0)
1542 return 0;
1545 /* If there is no strategy routine, or if the strategy returns
1546 * zero, proceed with automatic r/w */
1547 if (table->data && table->maxlen) {
1548 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1549 if (rc < 0)
1550 return rc;
1552 return 0;
1555 static int parse_table(int __user *name, int nlen,
1556 void __user *oldval, size_t __user *oldlenp,
1557 void __user *newval, size_t newlen,
1558 struct ctl_table_root *root,
1559 struct ctl_table *table)
1561 int n;
1562 repeat:
1563 if (!nlen)
1564 return -ENOTDIR;
1565 if (get_user(n, name))
1566 return -EFAULT;
1567 for ( ; table->ctl_name || table->procname; table++) {
1568 if (!table->ctl_name)
1569 continue;
1570 if (n == table->ctl_name) {
1571 int error;
1572 if (table->child) {
1573 if (sysctl_perm(root, table, MAY_EXEC))
1574 return -EPERM;
1575 name++;
1576 nlen--;
1577 table = table->child;
1578 goto repeat;
1580 error = do_sysctl_strategy(root, table,
1581 oldval, oldlenp,
1582 newval, newlen);
1583 return error;
1586 return -ENOTDIR;
1589 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1590 void __user *newval, size_t newlen)
1592 struct ctl_table_header *head;
1593 int error = -ENOTDIR;
1595 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1596 return -ENOTDIR;
1597 if (oldval) {
1598 int old_len;
1599 if (!oldlenp || get_user(old_len, oldlenp))
1600 return -EFAULT;
1603 for (head = sysctl_head_next(NULL); head;
1604 head = sysctl_head_next(head)) {
1605 error = parse_table(name, nlen, oldval, oldlenp,
1606 newval, newlen,
1607 head->root, head->ctl_table);
1608 if (error != -ENOTDIR) {
1609 sysctl_head_finish(head);
1610 break;
1613 return error;
1616 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1618 struct __sysctl_args tmp;
1619 int error;
1621 if (copy_from_user(&tmp, args, sizeof(tmp)))
1622 return -EFAULT;
1624 error = deprecated_sysctl_warning(&tmp);
1625 if (error)
1626 goto out;
1628 lock_kernel();
1629 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1630 tmp.newval, tmp.newlen);
1631 unlock_kernel();
1632 out:
1633 return error;
1635 #endif /* CONFIG_SYSCTL_SYSCALL */
1638 * sysctl_perm does NOT grant the superuser all rights automatically, because
1639 * some sysctl variables are readonly even to root.
1642 static int test_perm(int mode, int op)
1644 if (!current->euid)
1645 mode >>= 6;
1646 else if (in_egroup_p(0))
1647 mode >>= 3;
1648 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1649 return 0;
1650 return -EACCES;
1653 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1655 int error;
1656 int mode;
1658 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1659 if (error)
1660 return error;
1662 if (root->permissions)
1663 mode = root->permissions(root, current->nsproxy, table);
1664 else
1665 mode = table->mode;
1667 return test_perm(mode, op);
1670 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1672 for (; table->ctl_name || table->procname; table++) {
1673 table->parent = parent;
1674 if (table->child)
1675 sysctl_set_parent(table, table->child);
1679 static __init int sysctl_init(void)
1681 sysctl_set_parent(NULL, root_table);
1682 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1684 int err;
1685 err = sysctl_check_table(current->nsproxy, root_table);
1687 #endif
1688 return 0;
1691 core_initcall(sysctl_init);
1693 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1694 struct ctl_table *table)
1696 struct ctl_table *p;
1697 const char *s = branch->procname;
1699 /* branch should have named subdirectory as its first element */
1700 if (!s || !branch->child)
1701 return NULL;
1703 /* ... and nothing else */
1704 if (branch[1].procname || branch[1].ctl_name)
1705 return NULL;
1707 /* table should contain subdirectory with the same name */
1708 for (p = table; p->procname || p->ctl_name; p++) {
1709 if (!p->child)
1710 continue;
1711 if (p->procname && strcmp(p->procname, s) == 0)
1712 return p;
1714 return NULL;
1717 /* see if attaching q to p would be an improvement */
1718 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1720 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1721 struct ctl_table *next;
1722 int is_better = 0;
1723 int not_in_parent = !p->attached_by;
1725 while ((next = is_branch_in(by, to)) != NULL) {
1726 if (by == q->attached_by)
1727 is_better = 1;
1728 if (to == p->attached_by)
1729 not_in_parent = 1;
1730 by = by->child;
1731 to = next->child;
1734 if (is_better && not_in_parent) {
1735 q->attached_by = by;
1736 q->attached_to = to;
1737 q->parent = p;
1742 * __register_sysctl_paths - register a sysctl hierarchy
1743 * @root: List of sysctl headers to register on
1744 * @namespaces: Data to compute which lists of sysctl entries are visible
1745 * @path: The path to the directory the sysctl table is in.
1746 * @table: the top-level table structure
1748 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1749 * array. A completely 0 filled entry terminates the table.
1751 * The members of the &struct ctl_table structure are used as follows:
1753 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1754 * must be unique within that level of sysctl
1756 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1757 * enter a sysctl file
1759 * data - a pointer to data for use by proc_handler
1761 * maxlen - the maximum size in bytes of the data
1763 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1765 * child - a pointer to the child sysctl table if this entry is a directory, or
1766 * %NULL.
1768 * proc_handler - the text handler routine (described below)
1770 * strategy - the strategy routine (described below)
1772 * de - for internal use by the sysctl routines
1774 * extra1, extra2 - extra pointers usable by the proc handler routines
1776 * Leaf nodes in the sysctl tree will be represented by a single file
1777 * under /proc; non-leaf nodes will be represented by directories.
1779 * sysctl(2) can automatically manage read and write requests through
1780 * the sysctl table. The data and maxlen fields of the ctl_table
1781 * struct enable minimal validation of the values being written to be
1782 * performed, and the mode field allows minimal authentication.
1784 * More sophisticated management can be enabled by the provision of a
1785 * strategy routine with the table entry. This will be called before
1786 * any automatic read or write of the data is performed.
1788 * The strategy routine may return
1790 * < 0 - Error occurred (error is passed to user process)
1792 * 0 - OK - proceed with automatic read or write.
1794 * > 0 - OK - read or write has been done by the strategy routine, so
1795 * return immediately.
1797 * There must be a proc_handler routine for any terminal nodes
1798 * mirrored under /proc/sys (non-terminals are handled by a built-in
1799 * directory handler). Several default handlers are available to
1800 * cover common cases -
1802 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1803 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1804 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1806 * It is the handler's job to read the input buffer from user memory
1807 * and process it. The handler should return 0 on success.
1809 * This routine returns %NULL on a failure to register, and a pointer
1810 * to the table header on success.
1812 struct ctl_table_header *__register_sysctl_paths(
1813 struct ctl_table_root *root,
1814 struct nsproxy *namespaces,
1815 const struct ctl_path *path, struct ctl_table *table)
1817 struct ctl_table_header *header;
1818 struct ctl_table *new, **prevp;
1819 unsigned int n, npath;
1820 struct ctl_table_set *set;
1822 /* Count the path components */
1823 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1827 * For each path component, allocate a 2-element ctl_table array.
1828 * The first array element will be filled with the sysctl entry
1829 * for this, the second will be the sentinel (ctl_name == 0).
1831 * We allocate everything in one go so that we don't have to
1832 * worry about freeing additional memory in unregister_sysctl_table.
1834 header = kzalloc(sizeof(struct ctl_table_header) +
1835 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1836 if (!header)
1837 return NULL;
1839 new = (struct ctl_table *) (header + 1);
1841 /* Now connect the dots */
1842 prevp = &header->ctl_table;
1843 for (n = 0; n < npath; ++n, ++path) {
1844 /* Copy the procname */
1845 new->procname = path->procname;
1846 new->ctl_name = path->ctl_name;
1847 new->mode = 0555;
1849 *prevp = new;
1850 prevp = &new->child;
1852 new += 2;
1854 *prevp = table;
1855 header->ctl_table_arg = table;
1857 INIT_LIST_HEAD(&header->ctl_entry);
1858 header->used = 0;
1859 header->unregistering = NULL;
1860 header->root = root;
1861 sysctl_set_parent(NULL, header->ctl_table);
1862 header->count = 1;
1863 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1864 if (sysctl_check_table(namespaces, header->ctl_table)) {
1865 kfree(header);
1866 return NULL;
1868 #endif
1869 spin_lock(&sysctl_lock);
1870 header->set = lookup_header_set(root, namespaces);
1871 header->attached_by = header->ctl_table;
1872 header->attached_to = root_table;
1873 header->parent = &root_table_header;
1874 for (set = header->set; set; set = set->parent) {
1875 struct ctl_table_header *p;
1876 list_for_each_entry(p, &set->list, ctl_entry) {
1877 if (p->unregistering)
1878 continue;
1879 try_attach(p, header);
1882 header->parent->count++;
1883 list_add_tail(&header->ctl_entry, &header->set->list);
1884 spin_unlock(&sysctl_lock);
1886 return header;
1890 * register_sysctl_table_path - register a sysctl table hierarchy
1891 * @path: The path to the directory the sysctl table is in.
1892 * @table: the top-level table structure
1894 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1895 * array. A completely 0 filled entry terminates the table.
1897 * See __register_sysctl_paths for more details.
1899 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1900 struct ctl_table *table)
1902 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1903 path, table);
1907 * register_sysctl_table - register a sysctl table hierarchy
1908 * @table: the top-level table structure
1910 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1911 * array. A completely 0 filled entry terminates the table.
1913 * See register_sysctl_paths for more details.
1915 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1917 static const struct ctl_path null_path[] = { {} };
1919 return register_sysctl_paths(null_path, table);
1923 * unregister_sysctl_table - unregister a sysctl table hierarchy
1924 * @header: the header returned from register_sysctl_table
1926 * Unregisters the sysctl table and all children. proc entries may not
1927 * actually be removed until they are no longer used by anyone.
1929 void unregister_sysctl_table(struct ctl_table_header * header)
1931 might_sleep();
1933 if (header == NULL)
1934 return;
1936 spin_lock(&sysctl_lock);
1937 start_unregistering(header);
1938 if (!--header->parent->count) {
1939 WARN_ON(1);
1940 kfree(header->parent);
1942 if (!--header->count)
1943 kfree(header);
1944 spin_unlock(&sysctl_lock);
1947 int sysctl_is_seen(struct ctl_table_header *p)
1949 struct ctl_table_set *set = p->set;
1950 int res;
1951 spin_lock(&sysctl_lock);
1952 if (p->unregistering)
1953 res = 0;
1954 else if (!set->is_seen)
1955 res = 1;
1956 else
1957 res = set->is_seen(set);
1958 spin_unlock(&sysctl_lock);
1959 return res;
1962 void setup_sysctl_set(struct ctl_table_set *p,
1963 struct ctl_table_set *parent,
1964 int (*is_seen)(struct ctl_table_set *))
1966 INIT_LIST_HEAD(&p->list);
1967 p->parent = parent ? parent : &sysctl_table_root.default_set;
1968 p->is_seen = is_seen;
1971 #else /* !CONFIG_SYSCTL */
1972 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1974 return NULL;
1977 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1978 struct ctl_table *table)
1980 return NULL;
1983 void unregister_sysctl_table(struct ctl_table_header * table)
1987 void setup_sysctl_set(struct ctl_table_set *p,
1988 struct ctl_table_set *parent,
1989 int (*is_seen)(struct ctl_table_set *))
1993 void sysctl_head_put(struct ctl_table_header *head)
1997 #endif /* CONFIG_SYSCTL */
2000 * /proc/sys support
2003 #ifdef CONFIG_PROC_SYSCTL
2005 static int _proc_do_string(void* data, int maxlen, int write,
2006 struct file *filp, void __user *buffer,
2007 size_t *lenp, loff_t *ppos)
2009 size_t len;
2010 char __user *p;
2011 char c;
2013 if (!data || !maxlen || !*lenp) {
2014 *lenp = 0;
2015 return 0;
2018 if (write) {
2019 len = 0;
2020 p = buffer;
2021 while (len < *lenp) {
2022 if (get_user(c, p++))
2023 return -EFAULT;
2024 if (c == 0 || c == '\n')
2025 break;
2026 len++;
2028 if (len >= maxlen)
2029 len = maxlen-1;
2030 if(copy_from_user(data, buffer, len))
2031 return -EFAULT;
2032 ((char *) data)[len] = 0;
2033 *ppos += *lenp;
2034 } else {
2035 len = strlen(data);
2036 if (len > maxlen)
2037 len = maxlen;
2039 if (*ppos > len) {
2040 *lenp = 0;
2041 return 0;
2044 data += *ppos;
2045 len -= *ppos;
2047 if (len > *lenp)
2048 len = *lenp;
2049 if (len)
2050 if(copy_to_user(buffer, data, len))
2051 return -EFAULT;
2052 if (len < *lenp) {
2053 if(put_user('\n', ((char __user *) buffer) + len))
2054 return -EFAULT;
2055 len++;
2057 *lenp = len;
2058 *ppos += len;
2060 return 0;
2064 * proc_dostring - read a string sysctl
2065 * @table: the sysctl table
2066 * @write: %TRUE if this is a write to the sysctl file
2067 * @filp: the file structure
2068 * @buffer: the user buffer
2069 * @lenp: the size of the user buffer
2070 * @ppos: file position
2072 * Reads/writes a string from/to the user buffer. If the kernel
2073 * buffer provided is not large enough to hold the string, the
2074 * string is truncated. The copied string is %NULL-terminated.
2075 * If the string is being read by the user process, it is copied
2076 * and a newline '\n' is added. It is truncated if the buffer is
2077 * not large enough.
2079 * Returns 0 on success.
2081 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2082 void __user *buffer, size_t *lenp, loff_t *ppos)
2084 return _proc_do_string(table->data, table->maxlen, write, filp,
2085 buffer, lenp, ppos);
2089 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2090 int *valp,
2091 int write, void *data)
2093 if (write) {
2094 *valp = *negp ? -*lvalp : *lvalp;
2095 } else {
2096 int val = *valp;
2097 if (val < 0) {
2098 *negp = -1;
2099 *lvalp = (unsigned long)-val;
2100 } else {
2101 *negp = 0;
2102 *lvalp = (unsigned long)val;
2105 return 0;
2108 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2109 int write, struct file *filp, void __user *buffer,
2110 size_t *lenp, loff_t *ppos,
2111 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2112 int write, void *data),
2113 void *data)
2115 #define TMPBUFLEN 21
2116 int *i, vleft, first=1, neg, val;
2117 unsigned long lval;
2118 size_t left, len;
2120 char buf[TMPBUFLEN], *p;
2121 char __user *s = buffer;
2123 if (!tbl_data || !table->maxlen || !*lenp ||
2124 (*ppos && !write)) {
2125 *lenp = 0;
2126 return 0;
2129 i = (int *) tbl_data;
2130 vleft = table->maxlen / sizeof(*i);
2131 left = *lenp;
2133 if (!conv)
2134 conv = do_proc_dointvec_conv;
2136 for (; left && vleft--; i++, first=0) {
2137 if (write) {
2138 while (left) {
2139 char c;
2140 if (get_user(c, s))
2141 return -EFAULT;
2142 if (!isspace(c))
2143 break;
2144 left--;
2145 s++;
2147 if (!left)
2148 break;
2149 neg = 0;
2150 len = left;
2151 if (len > sizeof(buf) - 1)
2152 len = sizeof(buf) - 1;
2153 if (copy_from_user(buf, s, len))
2154 return -EFAULT;
2155 buf[len] = 0;
2156 p = buf;
2157 if (*p == '-' && left > 1) {
2158 neg = 1;
2159 p++;
2161 if (*p < '0' || *p > '9')
2162 break;
2164 lval = simple_strtoul(p, &p, 0);
2166 len = p-buf;
2167 if ((len < left) && *p && !isspace(*p))
2168 break;
2169 if (neg)
2170 val = -val;
2171 s += len;
2172 left -= len;
2174 if (conv(&neg, &lval, i, 1, data))
2175 break;
2176 } else {
2177 p = buf;
2178 if (!first)
2179 *p++ = '\t';
2181 if (conv(&neg, &lval, i, 0, data))
2182 break;
2184 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2185 len = strlen(buf);
2186 if (len > left)
2187 len = left;
2188 if(copy_to_user(s, buf, len))
2189 return -EFAULT;
2190 left -= len;
2191 s += len;
2195 if (!write && !first && left) {
2196 if(put_user('\n', s))
2197 return -EFAULT;
2198 left--, s++;
2200 if (write) {
2201 while (left) {
2202 char c;
2203 if (get_user(c, s++))
2204 return -EFAULT;
2205 if (!isspace(c))
2206 break;
2207 left--;
2210 if (write && first)
2211 return -EINVAL;
2212 *lenp -= left;
2213 *ppos += *lenp;
2214 return 0;
2215 #undef TMPBUFLEN
2218 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2219 void __user *buffer, size_t *lenp, loff_t *ppos,
2220 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2221 int write, void *data),
2222 void *data)
2224 return __do_proc_dointvec(table->data, table, write, filp,
2225 buffer, lenp, ppos, conv, data);
2229 * proc_dointvec - read a vector of integers
2230 * @table: the sysctl table
2231 * @write: %TRUE if this is a write to the sysctl file
2232 * @filp: the file structure
2233 * @buffer: the user buffer
2234 * @lenp: the size of the user buffer
2235 * @ppos: file position
2237 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2238 * values from/to the user buffer, treated as an ASCII string.
2240 * Returns 0 on success.
2242 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2243 void __user *buffer, size_t *lenp, loff_t *ppos)
2245 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2246 NULL,NULL);
2250 * Taint values can only be increased
2251 * This means we can safely use a temporary.
2253 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2254 void __user *buffer, size_t *lenp, loff_t *ppos)
2256 struct ctl_table t;
2257 unsigned long tmptaint = get_taint();
2258 int err;
2260 if (write && !capable(CAP_SYS_ADMIN))
2261 return -EPERM;
2263 t = *table;
2264 t.data = &tmptaint;
2265 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2266 if (err < 0)
2267 return err;
2269 if (write) {
2271 * Poor man's atomic or. Not worth adding a primitive
2272 * to everyone's atomic.h for this
2274 int i;
2275 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2276 if ((tmptaint >> i) & 1)
2277 add_taint(i);
2281 return err;
2284 struct do_proc_dointvec_minmax_conv_param {
2285 int *min;
2286 int *max;
2289 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2290 int *valp,
2291 int write, void *data)
2293 struct do_proc_dointvec_minmax_conv_param *param = data;
2294 if (write) {
2295 int val = *negp ? -*lvalp : *lvalp;
2296 if ((param->min && *param->min > val) ||
2297 (param->max && *param->max < val))
2298 return -EINVAL;
2299 *valp = val;
2300 } else {
2301 int val = *valp;
2302 if (val < 0) {
2303 *negp = -1;
2304 *lvalp = (unsigned long)-val;
2305 } else {
2306 *negp = 0;
2307 *lvalp = (unsigned long)val;
2310 return 0;
2314 * proc_dointvec_minmax - read a vector of integers with min/max values
2315 * @table: the sysctl table
2316 * @write: %TRUE if this is a write to the sysctl file
2317 * @filp: the file structure
2318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2322 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2323 * values from/to the user buffer, treated as an ASCII string.
2325 * This routine will ensure the values are within the range specified by
2326 * table->extra1 (min) and table->extra2 (max).
2328 * Returns 0 on success.
2330 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2331 void __user *buffer, size_t *lenp, loff_t *ppos)
2333 struct do_proc_dointvec_minmax_conv_param param = {
2334 .min = (int *) table->extra1,
2335 .max = (int *) table->extra2,
2337 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2338 do_proc_dointvec_minmax_conv, &param);
2341 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2342 struct file *filp,
2343 void __user *buffer,
2344 size_t *lenp, loff_t *ppos,
2345 unsigned long convmul,
2346 unsigned long convdiv)
2348 #define TMPBUFLEN 21
2349 unsigned long *i, *min, *max, val;
2350 int vleft, first=1, neg;
2351 size_t len, left;
2352 char buf[TMPBUFLEN], *p;
2353 char __user *s = buffer;
2355 if (!data || !table->maxlen || !*lenp ||
2356 (*ppos && !write)) {
2357 *lenp = 0;
2358 return 0;
2361 i = (unsigned long *) data;
2362 min = (unsigned long *) table->extra1;
2363 max = (unsigned long *) table->extra2;
2364 vleft = table->maxlen / sizeof(unsigned long);
2365 left = *lenp;
2367 for (; left && vleft--; i++, min++, max++, first=0) {
2368 if (write) {
2369 while (left) {
2370 char c;
2371 if (get_user(c, s))
2372 return -EFAULT;
2373 if (!isspace(c))
2374 break;
2375 left--;
2376 s++;
2378 if (!left)
2379 break;
2380 neg = 0;
2381 len = left;
2382 if (len > TMPBUFLEN-1)
2383 len = TMPBUFLEN-1;
2384 if (copy_from_user(buf, s, len))
2385 return -EFAULT;
2386 buf[len] = 0;
2387 p = buf;
2388 if (*p == '-' && left > 1) {
2389 neg = 1;
2390 p++;
2392 if (*p < '0' || *p > '9')
2393 break;
2394 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2395 len = p-buf;
2396 if ((len < left) && *p && !isspace(*p))
2397 break;
2398 if (neg)
2399 val = -val;
2400 s += len;
2401 left -= len;
2403 if(neg)
2404 continue;
2405 if ((min && val < *min) || (max && val > *max))
2406 continue;
2407 *i = val;
2408 } else {
2409 p = buf;
2410 if (!first)
2411 *p++ = '\t';
2412 sprintf(p, "%lu", convdiv * (*i) / convmul);
2413 len = strlen(buf);
2414 if (len > left)
2415 len = left;
2416 if(copy_to_user(s, buf, len))
2417 return -EFAULT;
2418 left -= len;
2419 s += len;
2423 if (!write && !first && left) {
2424 if(put_user('\n', s))
2425 return -EFAULT;
2426 left--, s++;
2428 if (write) {
2429 while (left) {
2430 char c;
2431 if (get_user(c, s++))
2432 return -EFAULT;
2433 if (!isspace(c))
2434 break;
2435 left--;
2438 if (write && first)
2439 return -EINVAL;
2440 *lenp -= left;
2441 *ppos += *lenp;
2442 return 0;
2443 #undef TMPBUFLEN
2446 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2447 struct file *filp,
2448 void __user *buffer,
2449 size_t *lenp, loff_t *ppos,
2450 unsigned long convmul,
2451 unsigned long convdiv)
2453 return __do_proc_doulongvec_minmax(table->data, table, write,
2454 filp, buffer, lenp, ppos, convmul, convdiv);
2458 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2459 * @table: the sysctl table
2460 * @write: %TRUE if this is a write to the sysctl file
2461 * @filp: the file structure
2462 * @buffer: the user buffer
2463 * @lenp: the size of the user buffer
2464 * @ppos: file position
2466 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2467 * values from/to the user buffer, treated as an ASCII string.
2469 * This routine will ensure the values are within the range specified by
2470 * table->extra1 (min) and table->extra2 (max).
2472 * Returns 0 on success.
2474 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2475 void __user *buffer, size_t *lenp, loff_t *ppos)
2477 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2481 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
2484 * @filp: the file structure
2485 * @buffer: the user buffer
2486 * @lenp: the size of the user buffer
2487 * @ppos: file position
2489 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2490 * values from/to the user buffer, treated as an ASCII string. The values
2491 * are treated as milliseconds, and converted to jiffies when they are stored.
2493 * This routine will ensure the values are within the range specified by
2494 * table->extra1 (min) and table->extra2 (max).
2496 * Returns 0 on success.
2498 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2499 struct file *filp,
2500 void __user *buffer,
2501 size_t *lenp, loff_t *ppos)
2503 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2504 lenp, ppos, HZ, 1000l);
2508 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2509 int *valp,
2510 int write, void *data)
2512 if (write) {
2513 if (*lvalp > LONG_MAX / HZ)
2514 return 1;
2515 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2516 } else {
2517 int val = *valp;
2518 unsigned long lval;
2519 if (val < 0) {
2520 *negp = -1;
2521 lval = (unsigned long)-val;
2522 } else {
2523 *negp = 0;
2524 lval = (unsigned long)val;
2526 *lvalp = lval / HZ;
2528 return 0;
2531 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2532 int *valp,
2533 int write, void *data)
2535 if (write) {
2536 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2537 return 1;
2538 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2539 } else {
2540 int val = *valp;
2541 unsigned long lval;
2542 if (val < 0) {
2543 *negp = -1;
2544 lval = (unsigned long)-val;
2545 } else {
2546 *negp = 0;
2547 lval = (unsigned long)val;
2549 *lvalp = jiffies_to_clock_t(lval);
2551 return 0;
2554 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2555 int *valp,
2556 int write, void *data)
2558 if (write) {
2559 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2560 } else {
2561 int val = *valp;
2562 unsigned long lval;
2563 if (val < 0) {
2564 *negp = -1;
2565 lval = (unsigned long)-val;
2566 } else {
2567 *negp = 0;
2568 lval = (unsigned long)val;
2570 *lvalp = jiffies_to_msecs(lval);
2572 return 0;
2576 * proc_dointvec_jiffies - read a vector of integers as seconds
2577 * @table: the sysctl table
2578 * @write: %TRUE if this is a write to the sysctl file
2579 * @filp: the file structure
2580 * @buffer: the user buffer
2581 * @lenp: the size of the user buffer
2582 * @ppos: file position
2584 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2585 * values from/to the user buffer, treated as an ASCII string.
2586 * The values read are assumed to be in seconds, and are converted into
2587 * jiffies.
2589 * Returns 0 on success.
2591 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2592 void __user *buffer, size_t *lenp, loff_t *ppos)
2594 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2595 do_proc_dointvec_jiffies_conv,NULL);
2599 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2600 * @table: the sysctl table
2601 * @write: %TRUE if this is a write to the sysctl file
2602 * @filp: the file structure
2603 * @buffer: the user buffer
2604 * @lenp: the size of the user buffer
2605 * @ppos: pointer to the file position
2607 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2608 * values from/to the user buffer, treated as an ASCII string.
2609 * The values read are assumed to be in 1/USER_HZ seconds, and
2610 * are converted into jiffies.
2612 * Returns 0 on success.
2614 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2615 void __user *buffer, size_t *lenp, loff_t *ppos)
2617 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2618 do_proc_dointvec_userhz_jiffies_conv,NULL);
2622 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2623 * @table: the sysctl table
2624 * @write: %TRUE if this is a write to the sysctl file
2625 * @filp: the file structure
2626 * @buffer: the user buffer
2627 * @lenp: the size of the user buffer
2628 * @ppos: file position
2629 * @ppos: the current position in the file
2631 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2632 * values from/to the user buffer, treated as an ASCII string.
2633 * The values read are assumed to be in 1/1000 seconds, and
2634 * are converted into jiffies.
2636 * Returns 0 on success.
2638 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2639 void __user *buffer, size_t *lenp, loff_t *ppos)
2641 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2642 do_proc_dointvec_ms_jiffies_conv, NULL);
2645 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2646 void __user *buffer, size_t *lenp, loff_t *ppos)
2648 struct pid *new_pid;
2649 pid_t tmp;
2650 int r;
2652 tmp = pid_vnr(cad_pid);
2654 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2655 lenp, ppos, NULL, NULL);
2656 if (r || !write)
2657 return r;
2659 new_pid = find_get_pid(tmp);
2660 if (!new_pid)
2661 return -ESRCH;
2663 put_pid(xchg(&cad_pid, new_pid));
2664 return 0;
2667 #else /* CONFIG_PROC_FS */
2669 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2670 void __user *buffer, size_t *lenp, loff_t *ppos)
2672 return -ENOSYS;
2675 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2676 void __user *buffer, size_t *lenp, loff_t *ppos)
2678 return -ENOSYS;
2681 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2682 void __user *buffer, size_t *lenp, loff_t *ppos)
2684 return -ENOSYS;
2687 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2688 void __user *buffer, size_t *lenp, loff_t *ppos)
2690 return -ENOSYS;
2693 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2694 void __user *buffer, size_t *lenp, loff_t *ppos)
2696 return -ENOSYS;
2699 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2700 void __user *buffer, size_t *lenp, loff_t *ppos)
2702 return -ENOSYS;
2705 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2706 void __user *buffer, size_t *lenp, loff_t *ppos)
2708 return -ENOSYS;
2711 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2712 struct file *filp,
2713 void __user *buffer,
2714 size_t *lenp, loff_t *ppos)
2716 return -ENOSYS;
2720 #endif /* CONFIG_PROC_FS */
2723 #ifdef CONFIG_SYSCTL_SYSCALL
2725 * General sysctl support routines
2728 /* The generic sysctl data routine (used if no strategy routine supplied) */
2729 int sysctl_data(struct ctl_table *table,
2730 void __user *oldval, size_t __user *oldlenp,
2731 void __user *newval, size_t newlen)
2733 size_t len;
2735 /* Get out of I don't have a variable */
2736 if (!table->data || !table->maxlen)
2737 return -ENOTDIR;
2739 if (oldval && oldlenp) {
2740 if (get_user(len, oldlenp))
2741 return -EFAULT;
2742 if (len) {
2743 if (len > table->maxlen)
2744 len = table->maxlen;
2745 if (copy_to_user(oldval, table->data, len))
2746 return -EFAULT;
2747 if (put_user(len, oldlenp))
2748 return -EFAULT;
2752 if (newval && newlen) {
2753 if (newlen > table->maxlen)
2754 newlen = table->maxlen;
2756 if (copy_from_user(table->data, newval, newlen))
2757 return -EFAULT;
2759 return 1;
2762 /* The generic string strategy routine: */
2763 int sysctl_string(struct ctl_table *table,
2764 void __user *oldval, size_t __user *oldlenp,
2765 void __user *newval, size_t newlen)
2767 if (!table->data || !table->maxlen)
2768 return -ENOTDIR;
2770 if (oldval && oldlenp) {
2771 size_t bufsize;
2772 if (get_user(bufsize, oldlenp))
2773 return -EFAULT;
2774 if (bufsize) {
2775 size_t len = strlen(table->data), copied;
2777 /* This shouldn't trigger for a well-formed sysctl */
2778 if (len > table->maxlen)
2779 len = table->maxlen;
2781 /* Copy up to a max of bufsize-1 bytes of the string */
2782 copied = (len >= bufsize) ? bufsize - 1 : len;
2784 if (copy_to_user(oldval, table->data, copied) ||
2785 put_user(0, (char __user *)(oldval + copied)))
2786 return -EFAULT;
2787 if (put_user(len, oldlenp))
2788 return -EFAULT;
2791 if (newval && newlen) {
2792 size_t len = newlen;
2793 if (len > table->maxlen)
2794 len = table->maxlen;
2795 if(copy_from_user(table->data, newval, len))
2796 return -EFAULT;
2797 if (len == table->maxlen)
2798 len--;
2799 ((char *) table->data)[len] = 0;
2801 return 1;
2805 * This function makes sure that all of the integers in the vector
2806 * are between the minimum and maximum values given in the arrays
2807 * table->extra1 and table->extra2, respectively.
2809 int sysctl_intvec(struct ctl_table *table,
2810 void __user *oldval, size_t __user *oldlenp,
2811 void __user *newval, size_t newlen)
2814 if (newval && newlen) {
2815 int __user *vec = (int __user *) newval;
2816 int *min = (int *) table->extra1;
2817 int *max = (int *) table->extra2;
2818 size_t length;
2819 int i;
2821 if (newlen % sizeof(int) != 0)
2822 return -EINVAL;
2824 if (!table->extra1 && !table->extra2)
2825 return 0;
2827 if (newlen > table->maxlen)
2828 newlen = table->maxlen;
2829 length = newlen / sizeof(int);
2831 for (i = 0; i < length; i++) {
2832 int value;
2833 if (get_user(value, vec + i))
2834 return -EFAULT;
2835 if (min && value < min[i])
2836 return -EINVAL;
2837 if (max && value > max[i])
2838 return -EINVAL;
2841 return 0;
2844 /* Strategy function to convert jiffies to seconds */
2845 int sysctl_jiffies(struct ctl_table *table,
2846 void __user *oldval, size_t __user *oldlenp,
2847 void __user *newval, size_t newlen)
2849 if (oldval && oldlenp) {
2850 size_t olen;
2852 if (get_user(olen, oldlenp))
2853 return -EFAULT;
2854 if (olen) {
2855 int val;
2857 if (olen < sizeof(int))
2858 return -EINVAL;
2860 val = *(int *)(table->data) / HZ;
2861 if (put_user(val, (int __user *)oldval))
2862 return -EFAULT;
2863 if (put_user(sizeof(int), oldlenp))
2864 return -EFAULT;
2867 if (newval && newlen) {
2868 int new;
2869 if (newlen != sizeof(int))
2870 return -EINVAL;
2871 if (get_user(new, (int __user *)newval))
2872 return -EFAULT;
2873 *(int *)(table->data) = new*HZ;
2875 return 1;
2878 /* Strategy function to convert jiffies to seconds */
2879 int sysctl_ms_jiffies(struct ctl_table *table,
2880 void __user *oldval, size_t __user *oldlenp,
2881 void __user *newval, size_t newlen)
2883 if (oldval && oldlenp) {
2884 size_t olen;
2886 if (get_user(olen, oldlenp))
2887 return -EFAULT;
2888 if (olen) {
2889 int val;
2891 if (olen < sizeof(int))
2892 return -EINVAL;
2894 val = jiffies_to_msecs(*(int *)(table->data));
2895 if (put_user(val, (int __user *)oldval))
2896 return -EFAULT;
2897 if (put_user(sizeof(int), oldlenp))
2898 return -EFAULT;
2901 if (newval && newlen) {
2902 int new;
2903 if (newlen != sizeof(int))
2904 return -EINVAL;
2905 if (get_user(new, (int __user *)newval))
2906 return -EFAULT;
2907 *(int *)(table->data) = msecs_to_jiffies(new);
2909 return 1;
2914 #else /* CONFIG_SYSCTL_SYSCALL */
2917 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2919 struct __sysctl_args tmp;
2920 int error;
2922 if (copy_from_user(&tmp, args, sizeof(tmp)))
2923 return -EFAULT;
2925 error = deprecated_sysctl_warning(&tmp);
2927 /* If no error reading the parameters then just -ENOSYS ... */
2928 if (!error)
2929 error = -ENOSYS;
2931 return error;
2934 int sysctl_data(struct ctl_table *table,
2935 void __user *oldval, size_t __user *oldlenp,
2936 void __user *newval, size_t newlen)
2938 return -ENOSYS;
2941 int sysctl_string(struct ctl_table *table,
2942 void __user *oldval, size_t __user *oldlenp,
2943 void __user *newval, size_t newlen)
2945 return -ENOSYS;
2948 int sysctl_intvec(struct ctl_table *table,
2949 void __user *oldval, size_t __user *oldlenp,
2950 void __user *newval, size_t newlen)
2952 return -ENOSYS;
2955 int sysctl_jiffies(struct ctl_table *table,
2956 void __user *oldval, size_t __user *oldlenp,
2957 void __user *newval, size_t newlen)
2959 return -ENOSYS;
2962 int sysctl_ms_jiffies(struct ctl_table *table,
2963 void __user *oldval, size_t __user *oldlenp,
2964 void __user *newval, size_t newlen)
2966 return -ENOSYS;
2969 #endif /* CONFIG_SYSCTL_SYSCALL */
2971 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2973 static int msg_count;
2974 int name[CTL_MAXNAME];
2975 int i;
2977 /* Check args->nlen. */
2978 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2979 return -ENOTDIR;
2981 /* Read in the sysctl name for better debug message logging */
2982 for (i = 0; i < args->nlen; i++)
2983 if (get_user(name[i], args->name + i))
2984 return -EFAULT;
2986 /* Ignore accesses to kernel.version */
2987 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2988 return 0;
2990 if (msg_count < 5) {
2991 msg_count++;
2992 printk(KERN_INFO
2993 "warning: process `%s' used the deprecated sysctl "
2994 "system call with ", current->comm);
2995 for (i = 0; i < args->nlen; i++)
2996 printk("%d.", name[i]);
2997 printk("\n");
2999 return 0;
3003 * No sense putting this after each symbol definition, twice,
3004 * exception granted :-)
3006 EXPORT_SYMBOL(proc_dointvec);
3007 EXPORT_SYMBOL(proc_dointvec_jiffies);
3008 EXPORT_SYMBOL(proc_dointvec_minmax);
3009 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3010 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3011 EXPORT_SYMBOL(proc_dostring);
3012 EXPORT_SYMBOL(proc_doulongvec_minmax);
3013 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3014 EXPORT_SYMBOL(register_sysctl_table);
3015 EXPORT_SYMBOL(register_sysctl_paths);
3016 EXPORT_SYMBOL(sysctl_intvec);
3017 EXPORT_SYMBOL(sysctl_jiffies);
3018 EXPORT_SYMBOL(sysctl_ms_jiffies);
3019 EXPORT_SYMBOL(sysctl_string);
3020 EXPORT_SYMBOL(sysctl_data);
3021 EXPORT_SYMBOL(unregister_sysctl_table);