x86: move all asm/pgtable constants into one place
[wrt350n-kernel.git] / kernel / sysctl.c
blob357b68ba23ecd7975f93e4273787cf1041ca8df8
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/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
53 #ifdef CONFIG_X86
54 #include <asm/nmi.h>
55 #include <asm/stacktrace.h>
56 #include <asm/io.h>
57 #endif
59 static int deprecated_sysctl_warning(struct __sysctl_args *args);
61 #if defined(CONFIG_SYSCTL)
63 /* External variables not in a header file. */
64 extern int C_A_D;
65 extern int print_fatal_signals;
66 extern int sysctl_overcommit_memory;
67 extern int sysctl_overcommit_ratio;
68 extern int sysctl_panic_on_oom;
69 extern int sysctl_oom_kill_allocating_task;
70 extern int max_threads;
71 extern int core_uses_pid;
72 extern int suid_dumpable;
73 extern char core_pattern[];
74 extern int pid_max;
75 extern int min_free_kbytes;
76 extern int printk_ratelimit_jiffies;
77 extern int printk_ratelimit_burst;
78 extern int pid_max_min, pid_max_max;
79 extern int sysctl_drop_caches;
80 extern int percpu_pagelist_fraction;
81 extern int compat_log;
82 extern int maps_protect;
83 extern int sysctl_stat_interval;
84 extern int audit_argv_kb;
85 extern int latencytop_enabled;
87 /* Constants used for minimum and maximum */
88 #ifdef CONFIG_DETECT_SOFTLOCKUP
89 static int one = 1;
90 static int sixty = 60;
91 #endif
93 #ifdef CONFIG_MMU
94 static int two = 2;
95 #endif
97 static int zero;
98 static int one_hundred = 100;
100 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
101 static int maxolduid = 65535;
102 static int minolduid;
103 static int min_percpu_pagelist_fract = 8;
105 static int ngroups_max = NGROUPS_MAX;
107 #ifdef CONFIG_KMOD
108 extern char modprobe_path[];
109 #endif
110 #ifdef CONFIG_CHR_DEV_SG
111 extern int sg_big_buff;
112 #endif
114 #ifdef __sparc__
115 extern char reboot_command [];
116 extern int stop_a_enabled;
117 extern int scons_pwroff;
118 #endif
120 #ifdef __hppa__
121 extern int pwrsw_enabled;
122 extern int unaligned_enabled;
123 #endif
125 #ifdef CONFIG_S390
126 #ifdef CONFIG_MATHEMU
127 extern int sysctl_ieee_emulation_warnings;
128 #endif
129 extern int sysctl_userprocess_debug;
130 extern int spin_retry;
131 #endif
133 extern int sysctl_hz_timer;
135 #ifdef CONFIG_BSD_PROCESS_ACCT
136 extern int acct_parm[];
137 #endif
139 #ifdef CONFIG_IA64
140 extern int no_unaligned_warning;
141 #endif
143 #ifdef CONFIG_RT_MUTEXES
144 extern int max_lock_depth;
145 #endif
147 #ifdef CONFIG_SYSCTL_SYSCALL
148 static int parse_table(int __user *, int, void __user *, size_t __user *,
149 void __user *, size_t, struct ctl_table *);
150 #endif
153 #ifdef CONFIG_PROC_SYSCTL
154 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
155 void __user *buffer, size_t *lenp, loff_t *ppos);
156 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
157 void __user *buffer, size_t *lenp, loff_t *ppos);
158 #endif
160 static struct ctl_table root_table[];
161 static struct ctl_table_root sysctl_table_root;
162 static struct ctl_table_header root_table_header = {
163 .ctl_table = root_table,
164 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
165 .root = &sysctl_table_root,
167 static struct ctl_table_root sysctl_table_root = {
168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
169 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
172 static struct ctl_table kern_table[];
173 static struct ctl_table vm_table[];
174 static struct ctl_table fs_table[];
175 static struct ctl_table debug_table[];
176 static struct ctl_table dev_table[];
177 extern struct ctl_table random_table[];
178 #ifdef CONFIG_INOTIFY_USER
179 extern struct ctl_table inotify_table[];
180 #endif
182 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183 int sysctl_legacy_va_layout;
184 #endif
186 extern int prove_locking;
187 extern int lock_stat;
189 /* The default sysctl tables: */
191 static struct ctl_table root_table[] = {
193 .ctl_name = CTL_KERN,
194 .procname = "kernel",
195 .mode = 0555,
196 .child = kern_table,
199 .ctl_name = CTL_VM,
200 .procname = "vm",
201 .mode = 0555,
202 .child = vm_table,
205 .ctl_name = CTL_FS,
206 .procname = "fs",
207 .mode = 0555,
208 .child = fs_table,
211 .ctl_name = CTL_DEBUG,
212 .procname = "debug",
213 .mode = 0555,
214 .child = debug_table,
217 .ctl_name = CTL_DEV,
218 .procname = "dev",
219 .mode = 0555,
220 .child = dev_table,
223 * NOTE: do not add new entries to this table unless you have read
224 * Documentation/sysctl/ctl_unnumbered.txt
226 { .ctl_name = 0 }
229 #ifdef CONFIG_SCHED_DEBUG
230 static int min_sched_granularity_ns = 100000; /* 100 usecs */
231 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
232 static int min_wakeup_granularity_ns; /* 0 usecs */
233 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
234 #endif
236 static struct ctl_table kern_table[] = {
237 #ifdef CONFIG_SCHED_DEBUG
239 .ctl_name = CTL_UNNUMBERED,
240 .procname = "sched_min_granularity_ns",
241 .data = &sysctl_sched_min_granularity,
242 .maxlen = sizeof(unsigned int),
243 .mode = 0644,
244 .proc_handler = &sched_nr_latency_handler,
245 .strategy = &sysctl_intvec,
246 .extra1 = &min_sched_granularity_ns,
247 .extra2 = &max_sched_granularity_ns,
250 .ctl_name = CTL_UNNUMBERED,
251 .procname = "sched_latency_ns",
252 .data = &sysctl_sched_latency,
253 .maxlen = sizeof(unsigned int),
254 .mode = 0644,
255 .proc_handler = &sched_nr_latency_handler,
256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
261 .ctl_name = CTL_UNNUMBERED,
262 .procname = "sched_wakeup_granularity_ns",
263 .data = &sysctl_sched_wakeup_granularity,
264 .maxlen = sizeof(unsigned int),
265 .mode = 0644,
266 .proc_handler = &proc_dointvec_minmax,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_wakeup_granularity_ns,
269 .extra2 = &max_wakeup_granularity_ns,
272 .ctl_name = CTL_UNNUMBERED,
273 .procname = "sched_batch_wakeup_granularity_ns",
274 .data = &sysctl_sched_batch_wakeup_granularity,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
277 .proc_handler = &proc_dointvec_minmax,
278 .strategy = &sysctl_intvec,
279 .extra1 = &min_wakeup_granularity_ns,
280 .extra2 = &max_wakeup_granularity_ns,
283 .ctl_name = CTL_UNNUMBERED,
284 .procname = "sched_child_runs_first",
285 .data = &sysctl_sched_child_runs_first,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
288 .proc_handler = &proc_dointvec,
291 .ctl_name = CTL_UNNUMBERED,
292 .procname = "sched_features",
293 .data = &sysctl_sched_features,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec,
299 .ctl_name = CTL_UNNUMBERED,
300 .procname = "sched_migration_cost",
301 .data = &sysctl_sched_migration_cost,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_nr_migrate",
309 .data = &sysctl_sched_nr_migrate,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = &proc_dointvec,
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_rt_period_ms",
317 .data = &sysctl_sched_rt_period,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_rt_ratio",
325 .data = &sysctl_sched_rt_ratio,
326 .maxlen = sizeof(unsigned int),
327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
330 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_min_bal_int_shares",
334 .data = &sysctl_sched_min_bal_int_shares,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_max_bal_int_shares",
342 .data = &sysctl_sched_max_bal_int_shares,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = &proc_dointvec,
347 #endif
348 #endif
350 .ctl_name = CTL_UNNUMBERED,
351 .procname = "sched_compat_yield",
352 .data = &sysctl_sched_compat_yield,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
355 .proc_handler = &proc_dointvec,
357 #ifdef CONFIG_PROVE_LOCKING
359 .ctl_name = CTL_UNNUMBERED,
360 .procname = "prove_locking",
361 .data = &prove_locking,
362 .maxlen = sizeof(int),
363 .mode = 0644,
364 .proc_handler = &proc_dointvec,
366 #endif
367 #ifdef CONFIG_LOCK_STAT
369 .ctl_name = CTL_UNNUMBERED,
370 .procname = "lock_stat",
371 .data = &lock_stat,
372 .maxlen = sizeof(int),
373 .mode = 0644,
374 .proc_handler = &proc_dointvec,
376 #endif
378 .ctl_name = KERN_PANIC,
379 .procname = "panic",
380 .data = &panic_timeout,
381 .maxlen = sizeof(int),
382 .mode = 0644,
383 .proc_handler = &proc_dointvec,
386 .ctl_name = KERN_CORE_USES_PID,
387 .procname = "core_uses_pid",
388 .data = &core_uses_pid,
389 .maxlen = sizeof(int),
390 .mode = 0644,
391 .proc_handler = &proc_dointvec,
393 #ifdef CONFIG_AUDITSYSCALL
395 .ctl_name = CTL_UNNUMBERED,
396 .procname = "audit_argv_kb",
397 .data = &audit_argv_kb,
398 .maxlen = sizeof(int),
399 .mode = 0644,
400 .proc_handler = &proc_dointvec,
402 #endif
404 .ctl_name = KERN_CORE_PATTERN,
405 .procname = "core_pattern",
406 .data = core_pattern,
407 .maxlen = CORENAME_MAX_SIZE,
408 .mode = 0644,
409 .proc_handler = &proc_dostring,
410 .strategy = &sysctl_string,
412 #ifdef CONFIG_PROC_SYSCTL
414 .procname = "tainted",
415 .data = &tainted,
416 .maxlen = sizeof(int),
417 .mode = 0644,
418 .proc_handler = &proc_dointvec_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_SECURITY_CAPABILITIES
432 .procname = "cap-bound",
433 .data = &cap_bset,
434 .maxlen = sizeof(kernel_cap_t),
435 .mode = 0600,
436 .proc_handler = &proc_dointvec_bset,
438 #endif /* def CONFIG_SECURITY_CAPABILITIES */
439 #ifdef CONFIG_BLK_DEV_INITRD
441 .ctl_name = KERN_REALROOTDEV,
442 .procname = "real-root-dev",
443 .data = &real_root_dev,
444 .maxlen = sizeof(int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
448 #endif
450 .ctl_name = CTL_UNNUMBERED,
451 .procname = "print-fatal-signals",
452 .data = &print_fatal_signals,
453 .maxlen = sizeof(int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
457 #ifdef __sparc__
459 .ctl_name = KERN_SPARC_REBOOT,
460 .procname = "reboot-cmd",
461 .data = reboot_command,
462 .maxlen = 256,
463 .mode = 0644,
464 .proc_handler = &proc_dostring,
465 .strategy = &sysctl_string,
468 .ctl_name = KERN_SPARC_STOP_A,
469 .procname = "stop-a",
470 .data = &stop_a_enabled,
471 .maxlen = sizeof (int),
472 .mode = 0644,
473 .proc_handler = &proc_dointvec,
476 .ctl_name = KERN_SPARC_SCONS_PWROFF,
477 .procname = "scons-poweroff",
478 .data = &scons_pwroff,
479 .maxlen = sizeof (int),
480 .mode = 0644,
481 .proc_handler = &proc_dointvec,
483 #endif
484 #ifdef __hppa__
486 .ctl_name = KERN_HPPA_PWRSW,
487 .procname = "soft-power",
488 .data = &pwrsw_enabled,
489 .maxlen = sizeof (int),
490 .mode = 0644,
491 .proc_handler = &proc_dointvec,
494 .ctl_name = KERN_HPPA_UNALIGNED,
495 .procname = "unaligned-trap",
496 .data = &unaligned_enabled,
497 .maxlen = sizeof (int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec,
501 #endif
503 .ctl_name = KERN_CTLALTDEL,
504 .procname = "ctrl-alt-del",
505 .data = &C_A_D,
506 .maxlen = sizeof(int),
507 .mode = 0644,
508 .proc_handler = &proc_dointvec,
511 .ctl_name = KERN_PRINTK,
512 .procname = "printk",
513 .data = &console_loglevel,
514 .maxlen = 4*sizeof(int),
515 .mode = 0644,
516 .proc_handler = &proc_dointvec,
518 #ifdef CONFIG_KMOD
520 .ctl_name = KERN_MODPROBE,
521 .procname = "modprobe",
522 .data = &modprobe_path,
523 .maxlen = KMOD_PATH_LEN,
524 .mode = 0644,
525 .proc_handler = &proc_dostring,
526 .strategy = &sysctl_string,
528 #endif
529 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
531 .ctl_name = KERN_HOTPLUG,
532 .procname = "hotplug",
533 .data = &uevent_helper,
534 .maxlen = UEVENT_HELPER_PATH_LEN,
535 .mode = 0644,
536 .proc_handler = &proc_dostring,
537 .strategy = &sysctl_string,
539 #endif
540 #ifdef CONFIG_CHR_DEV_SG
542 .ctl_name = KERN_SG_BIG_BUFF,
543 .procname = "sg-big-buff",
544 .data = &sg_big_buff,
545 .maxlen = sizeof (int),
546 .mode = 0444,
547 .proc_handler = &proc_dointvec,
549 #endif
550 #ifdef CONFIG_BSD_PROCESS_ACCT
552 .ctl_name = KERN_ACCT,
553 .procname = "acct",
554 .data = &acct_parm,
555 .maxlen = 3*sizeof(int),
556 .mode = 0644,
557 .proc_handler = &proc_dointvec,
559 #endif
560 #ifdef CONFIG_MAGIC_SYSRQ
562 .ctl_name = KERN_SYSRQ,
563 .procname = "sysrq",
564 .data = &__sysrq_enabled,
565 .maxlen = sizeof (int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
569 #endif
570 #ifdef CONFIG_PROC_SYSCTL
572 .procname = "cad_pid",
573 .data = NULL,
574 .maxlen = sizeof (int),
575 .mode = 0600,
576 .proc_handler = &proc_do_cad_pid,
578 #endif
580 .ctl_name = KERN_MAX_THREADS,
581 .procname = "threads-max",
582 .data = &max_threads,
583 .maxlen = sizeof(int),
584 .mode = 0644,
585 .proc_handler = &proc_dointvec,
588 .ctl_name = KERN_RANDOM,
589 .procname = "random",
590 .mode = 0555,
591 .child = random_table,
594 .ctl_name = KERN_OVERFLOWUID,
595 .procname = "overflowuid",
596 .data = &overflowuid,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = &proc_dointvec_minmax,
600 .strategy = &sysctl_intvec,
601 .extra1 = &minolduid,
602 .extra2 = &maxolduid,
605 .ctl_name = KERN_OVERFLOWGID,
606 .procname = "overflowgid",
607 .data = &overflowgid,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec_minmax,
611 .strategy = &sysctl_intvec,
612 .extra1 = &minolduid,
613 .extra2 = &maxolduid,
615 #ifdef CONFIG_S390
616 #ifdef CONFIG_MATHEMU
618 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
619 .procname = "ieee_emulation_warnings",
620 .data = &sysctl_ieee_emulation_warnings,
621 .maxlen = sizeof(int),
622 .mode = 0644,
623 .proc_handler = &proc_dointvec,
625 #endif
626 #ifdef CONFIG_NO_IDLE_HZ
628 .ctl_name = KERN_HZ_TIMER,
629 .procname = "hz_timer",
630 .data = &sysctl_hz_timer,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
635 #endif
637 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
638 .procname = "userprocess_debug",
639 .data = &sysctl_userprocess_debug,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 .proc_handler = &proc_dointvec,
644 #endif
646 .ctl_name = KERN_PIDMAX,
647 .procname = "pid_max",
648 .data = &pid_max,
649 .maxlen = sizeof (int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec_minmax,
652 .strategy = sysctl_intvec,
653 .extra1 = &pid_max_min,
654 .extra2 = &pid_max_max,
657 .ctl_name = KERN_PANIC_ON_OOPS,
658 .procname = "panic_on_oops",
659 .data = &panic_on_oops,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
665 .ctl_name = KERN_PRINTK_RATELIMIT,
666 .procname = "printk_ratelimit",
667 .data = &printk_ratelimit_jiffies,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec_jiffies,
671 .strategy = &sysctl_jiffies,
674 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
675 .procname = "printk_ratelimit_burst",
676 .data = &printk_ratelimit_burst,
677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec,
682 .ctl_name = KERN_NGROUPS_MAX,
683 .procname = "ngroups_max",
684 .data = &ngroups_max,
685 .maxlen = sizeof (int),
686 .mode = 0444,
687 .proc_handler = &proc_dointvec,
689 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
691 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
692 .procname = "unknown_nmi_panic",
693 .data = &unknown_nmi_panic,
694 .maxlen = sizeof (int),
695 .mode = 0644,
696 .proc_handler = &proc_dointvec,
699 .procname = "nmi_watchdog",
700 .data = &nmi_watchdog_enabled,
701 .maxlen = sizeof (int),
702 .mode = 0644,
703 .proc_handler = &proc_nmi_enabled,
705 #endif
706 #if defined(CONFIG_X86)
708 .ctl_name = KERN_PANIC_ON_NMI,
709 .procname = "panic_on_unrecovered_nmi",
710 .data = &panic_on_unrecovered_nmi,
711 .maxlen = sizeof(int),
712 .mode = 0644,
713 .proc_handler = &proc_dointvec,
716 .ctl_name = KERN_BOOTLOADER_TYPE,
717 .procname = "bootloader_type",
718 .data = &bootloader_type,
719 .maxlen = sizeof (int),
720 .mode = 0444,
721 .proc_handler = &proc_dointvec,
724 .ctl_name = CTL_UNNUMBERED,
725 .procname = "kstack_depth_to_print",
726 .data = &kstack_depth_to_print,
727 .maxlen = sizeof(int),
728 .mode = 0644,
729 .proc_handler = &proc_dointvec,
732 .ctl_name = CTL_UNNUMBERED,
733 .procname = "io_delay_type",
734 .data = &io_delay_type,
735 .maxlen = sizeof(int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
739 #endif
740 #if defined(CONFIG_MMU)
742 .ctl_name = KERN_RANDOMIZE,
743 .procname = "randomize_va_space",
744 .data = &randomize_va_space,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec,
749 #endif
750 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
752 .ctl_name = KERN_SPIN_RETRY,
753 .procname = "spin_retry",
754 .data = &spin_retry,
755 .maxlen = sizeof (int),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
759 #endif
760 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
762 .procname = "acpi_video_flags",
763 .data = &acpi_realmode_flags,
764 .maxlen = sizeof (unsigned long),
765 .mode = 0644,
766 .proc_handler = &proc_doulongvec_minmax,
768 #endif
769 #ifdef CONFIG_IA64
771 .ctl_name = KERN_IA64_UNALIGNED,
772 .procname = "ignore-unaligned-usertrap",
773 .data = &no_unaligned_warning,
774 .maxlen = sizeof (int),
775 .mode = 0644,
776 .proc_handler = &proc_dointvec,
778 #endif
779 #ifdef CONFIG_DETECT_SOFTLOCKUP
781 .ctl_name = CTL_UNNUMBERED,
782 .procname = "softlockup_thresh",
783 .data = &softlockup_thresh,
784 .maxlen = sizeof(unsigned long),
785 .mode = 0644,
786 .proc_handler = &proc_doulongvec_minmax,
787 .strategy = &sysctl_intvec,
788 .extra1 = &one,
789 .extra2 = &sixty,
792 .ctl_name = CTL_UNNUMBERED,
793 .procname = "hung_task_check_count",
794 .data = &sysctl_hung_task_check_count,
795 .maxlen = sizeof(unsigned long),
796 .mode = 0644,
797 .proc_handler = &proc_doulongvec_minmax,
798 .strategy = &sysctl_intvec,
801 .ctl_name = CTL_UNNUMBERED,
802 .procname = "hung_task_timeout_secs",
803 .data = &sysctl_hung_task_timeout_secs,
804 .maxlen = sizeof(unsigned long),
805 .mode = 0644,
806 .proc_handler = &proc_doulongvec_minmax,
807 .strategy = &sysctl_intvec,
810 .ctl_name = CTL_UNNUMBERED,
811 .procname = "hung_task_warnings",
812 .data = &sysctl_hung_task_warnings,
813 .maxlen = sizeof(unsigned long),
814 .mode = 0644,
815 .proc_handler = &proc_doulongvec_minmax,
816 .strategy = &sysctl_intvec,
818 #endif
819 #ifdef CONFIG_COMPAT
821 .ctl_name = KERN_COMPAT_LOG,
822 .procname = "compat-log",
823 .data = &compat_log,
824 .maxlen = sizeof (int),
825 .mode = 0644,
826 .proc_handler = &proc_dointvec,
828 #endif
829 #ifdef CONFIG_RT_MUTEXES
831 .ctl_name = KERN_MAX_LOCK_DEPTH,
832 .procname = "max_lock_depth",
833 .data = &max_lock_depth,
834 .maxlen = sizeof(int),
835 .mode = 0644,
836 .proc_handler = &proc_dointvec,
838 #endif
839 #ifdef CONFIG_PROC_FS
841 .ctl_name = CTL_UNNUMBERED,
842 .procname = "maps_protect",
843 .data = &maps_protect,
844 .maxlen = sizeof(int),
845 .mode = 0644,
846 .proc_handler = &proc_dointvec,
848 #endif
850 .ctl_name = CTL_UNNUMBERED,
851 .procname = "poweroff_cmd",
852 .data = &poweroff_cmd,
853 .maxlen = POWEROFF_CMD_PATH_LEN,
854 .mode = 0644,
855 .proc_handler = &proc_dostring,
856 .strategy = &sysctl_string,
859 * NOTE: do not add new entries to this table unless you have read
860 * Documentation/sysctl/ctl_unnumbered.txt
862 { .ctl_name = 0 }
865 static struct ctl_table vm_table[] = {
867 .ctl_name = VM_OVERCOMMIT_MEMORY,
868 .procname = "overcommit_memory",
869 .data = &sysctl_overcommit_memory,
870 .maxlen = sizeof(sysctl_overcommit_memory),
871 .mode = 0644,
872 .proc_handler = &proc_dointvec,
875 .ctl_name = VM_PANIC_ON_OOM,
876 .procname = "panic_on_oom",
877 .data = &sysctl_panic_on_oom,
878 .maxlen = sizeof(sysctl_panic_on_oom),
879 .mode = 0644,
880 .proc_handler = &proc_dointvec,
883 .ctl_name = CTL_UNNUMBERED,
884 .procname = "oom_kill_allocating_task",
885 .data = &sysctl_oom_kill_allocating_task,
886 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
887 .mode = 0644,
888 .proc_handler = &proc_dointvec,
891 .ctl_name = VM_OVERCOMMIT_RATIO,
892 .procname = "overcommit_ratio",
893 .data = &sysctl_overcommit_ratio,
894 .maxlen = sizeof(sysctl_overcommit_ratio),
895 .mode = 0644,
896 .proc_handler = &proc_dointvec,
899 .ctl_name = VM_PAGE_CLUSTER,
900 .procname = "page-cluster",
901 .data = &page_cluster,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = &proc_dointvec,
907 .ctl_name = VM_DIRTY_BACKGROUND,
908 .procname = "dirty_background_ratio",
909 .data = &dirty_background_ratio,
910 .maxlen = sizeof(dirty_background_ratio),
911 .mode = 0644,
912 .proc_handler = &proc_dointvec_minmax,
913 .strategy = &sysctl_intvec,
914 .extra1 = &zero,
915 .extra2 = &one_hundred,
918 .ctl_name = VM_DIRTY_RATIO,
919 .procname = "dirty_ratio",
920 .data = &vm_dirty_ratio,
921 .maxlen = sizeof(vm_dirty_ratio),
922 .mode = 0644,
923 .proc_handler = &dirty_ratio_handler,
924 .strategy = &sysctl_intvec,
925 .extra1 = &zero,
926 .extra2 = &one_hundred,
929 .procname = "dirty_writeback_centisecs",
930 .data = &dirty_writeback_interval,
931 .maxlen = sizeof(dirty_writeback_interval),
932 .mode = 0644,
933 .proc_handler = &dirty_writeback_centisecs_handler,
936 .procname = "dirty_expire_centisecs",
937 .data = &dirty_expire_interval,
938 .maxlen = sizeof(dirty_expire_interval),
939 .mode = 0644,
940 .proc_handler = &proc_dointvec_userhz_jiffies,
943 .ctl_name = VM_NR_PDFLUSH_THREADS,
944 .procname = "nr_pdflush_threads",
945 .data = &nr_pdflush_threads,
946 .maxlen = sizeof nr_pdflush_threads,
947 .mode = 0444 /* read-only*/,
948 .proc_handler = &proc_dointvec,
951 .ctl_name = VM_SWAPPINESS,
952 .procname = "swappiness",
953 .data = &vm_swappiness,
954 .maxlen = sizeof(vm_swappiness),
955 .mode = 0644,
956 .proc_handler = &proc_dointvec_minmax,
957 .strategy = &sysctl_intvec,
958 .extra1 = &zero,
959 .extra2 = &one_hundred,
961 #ifdef CONFIG_HUGETLB_PAGE
963 .procname = "nr_hugepages",
964 .data = &max_huge_pages,
965 .maxlen = sizeof(unsigned long),
966 .mode = 0644,
967 .proc_handler = &hugetlb_sysctl_handler,
968 .extra1 = (void *)&hugetlb_zero,
969 .extra2 = (void *)&hugetlb_infinity,
972 .ctl_name = VM_HUGETLB_GROUP,
973 .procname = "hugetlb_shm_group",
974 .data = &sysctl_hugetlb_shm_group,
975 .maxlen = sizeof(gid_t),
976 .mode = 0644,
977 .proc_handler = &proc_dointvec,
980 .ctl_name = CTL_UNNUMBERED,
981 .procname = "hugepages_treat_as_movable",
982 .data = &hugepages_treat_as_movable,
983 .maxlen = sizeof(int),
984 .mode = 0644,
985 .proc_handler = &hugetlb_treat_movable_handler,
988 .ctl_name = CTL_UNNUMBERED,
989 .procname = "nr_overcommit_hugepages",
990 .data = &nr_overcommit_huge_pages,
991 .maxlen = sizeof(nr_overcommit_huge_pages),
992 .mode = 0644,
993 .proc_handler = &proc_doulongvec_minmax,
995 #endif
997 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
998 .procname = "lowmem_reserve_ratio",
999 .data = &sysctl_lowmem_reserve_ratio,
1000 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1001 .mode = 0644,
1002 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1003 .strategy = &sysctl_intvec,
1006 .ctl_name = VM_DROP_PAGECACHE,
1007 .procname = "drop_caches",
1008 .data = &sysctl_drop_caches,
1009 .maxlen = sizeof(int),
1010 .mode = 0644,
1011 .proc_handler = drop_caches_sysctl_handler,
1012 .strategy = &sysctl_intvec,
1015 .ctl_name = VM_MIN_FREE_KBYTES,
1016 .procname = "min_free_kbytes",
1017 .data = &min_free_kbytes,
1018 .maxlen = sizeof(min_free_kbytes),
1019 .mode = 0644,
1020 .proc_handler = &min_free_kbytes_sysctl_handler,
1021 .strategy = &sysctl_intvec,
1022 .extra1 = &zero,
1025 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1026 .procname = "percpu_pagelist_fraction",
1027 .data = &percpu_pagelist_fraction,
1028 .maxlen = sizeof(percpu_pagelist_fraction),
1029 .mode = 0644,
1030 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1031 .strategy = &sysctl_intvec,
1032 .extra1 = &min_percpu_pagelist_fract,
1034 #ifdef CONFIG_MMU
1036 .ctl_name = VM_MAX_MAP_COUNT,
1037 .procname = "max_map_count",
1038 .data = &sysctl_max_map_count,
1039 .maxlen = sizeof(sysctl_max_map_count),
1040 .mode = 0644,
1041 .proc_handler = &proc_dointvec
1043 #endif
1045 .ctl_name = VM_LAPTOP_MODE,
1046 .procname = "laptop_mode",
1047 .data = &laptop_mode,
1048 .maxlen = sizeof(laptop_mode),
1049 .mode = 0644,
1050 .proc_handler = &proc_dointvec_jiffies,
1051 .strategy = &sysctl_jiffies,
1054 .ctl_name = VM_BLOCK_DUMP,
1055 .procname = "block_dump",
1056 .data = &block_dump,
1057 .maxlen = sizeof(block_dump),
1058 .mode = 0644,
1059 .proc_handler = &proc_dointvec,
1060 .strategy = &sysctl_intvec,
1061 .extra1 = &zero,
1064 .ctl_name = VM_VFS_CACHE_PRESSURE,
1065 .procname = "vfs_cache_pressure",
1066 .data = &sysctl_vfs_cache_pressure,
1067 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1068 .mode = 0644,
1069 .proc_handler = &proc_dointvec,
1070 .strategy = &sysctl_intvec,
1071 .extra1 = &zero,
1073 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1075 .ctl_name = VM_LEGACY_VA_LAYOUT,
1076 .procname = "legacy_va_layout",
1077 .data = &sysctl_legacy_va_layout,
1078 .maxlen = sizeof(sysctl_legacy_va_layout),
1079 .mode = 0644,
1080 .proc_handler = &proc_dointvec,
1081 .strategy = &sysctl_intvec,
1082 .extra1 = &zero,
1084 #endif
1085 #ifdef CONFIG_NUMA
1087 .ctl_name = VM_ZONE_RECLAIM_MODE,
1088 .procname = "zone_reclaim_mode",
1089 .data = &zone_reclaim_mode,
1090 .maxlen = sizeof(zone_reclaim_mode),
1091 .mode = 0644,
1092 .proc_handler = &proc_dointvec,
1093 .strategy = &sysctl_intvec,
1094 .extra1 = &zero,
1097 .ctl_name = VM_MIN_UNMAPPED,
1098 .procname = "min_unmapped_ratio",
1099 .data = &sysctl_min_unmapped_ratio,
1100 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1101 .mode = 0644,
1102 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1103 .strategy = &sysctl_intvec,
1104 .extra1 = &zero,
1105 .extra2 = &one_hundred,
1108 .ctl_name = VM_MIN_SLAB,
1109 .procname = "min_slab_ratio",
1110 .data = &sysctl_min_slab_ratio,
1111 .maxlen = sizeof(sysctl_min_slab_ratio),
1112 .mode = 0644,
1113 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1114 .strategy = &sysctl_intvec,
1115 .extra1 = &zero,
1116 .extra2 = &one_hundred,
1118 #endif
1119 #ifdef CONFIG_SMP
1121 .ctl_name = CTL_UNNUMBERED,
1122 .procname = "stat_interval",
1123 .data = &sysctl_stat_interval,
1124 .maxlen = sizeof(sysctl_stat_interval),
1125 .mode = 0644,
1126 .proc_handler = &proc_dointvec_jiffies,
1127 .strategy = &sysctl_jiffies,
1129 #endif
1130 #ifdef CONFIG_SECURITY
1132 .ctl_name = CTL_UNNUMBERED,
1133 .procname = "mmap_min_addr",
1134 .data = &mmap_min_addr,
1135 .maxlen = sizeof(unsigned long),
1136 .mode = 0644,
1137 .proc_handler = &proc_doulongvec_minmax,
1139 #endif
1140 #ifdef CONFIG_NUMA
1142 .ctl_name = CTL_UNNUMBERED,
1143 .procname = "numa_zonelist_order",
1144 .data = &numa_zonelist_order,
1145 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1146 .mode = 0644,
1147 .proc_handler = &numa_zonelist_order_handler,
1148 .strategy = &sysctl_string,
1150 #endif
1151 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1152 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1154 .ctl_name = VM_VDSO_ENABLED,
1155 .procname = "vdso_enabled",
1156 .data = &vdso_enabled,
1157 .maxlen = sizeof(vdso_enabled),
1158 .mode = 0644,
1159 .proc_handler = &proc_dointvec,
1160 .strategy = &sysctl_intvec,
1161 .extra1 = &zero,
1163 #endif
1165 * NOTE: do not add new entries to this table unless you have read
1166 * Documentation/sysctl/ctl_unnumbered.txt
1168 { .ctl_name = 0 }
1171 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1172 static struct ctl_table binfmt_misc_table[] = {
1173 { .ctl_name = 0 }
1175 #endif
1177 static struct ctl_table fs_table[] = {
1179 .ctl_name = FS_NRINODE,
1180 .procname = "inode-nr",
1181 .data = &inodes_stat,
1182 .maxlen = 2*sizeof(int),
1183 .mode = 0444,
1184 .proc_handler = &proc_dointvec,
1187 .ctl_name = FS_STATINODE,
1188 .procname = "inode-state",
1189 .data = &inodes_stat,
1190 .maxlen = 7*sizeof(int),
1191 .mode = 0444,
1192 .proc_handler = &proc_dointvec,
1195 .procname = "file-nr",
1196 .data = &files_stat,
1197 .maxlen = 3*sizeof(int),
1198 .mode = 0444,
1199 .proc_handler = &proc_nr_files,
1202 .ctl_name = FS_MAXFILE,
1203 .procname = "file-max",
1204 .data = &files_stat.max_files,
1205 .maxlen = sizeof(int),
1206 .mode = 0644,
1207 .proc_handler = &proc_dointvec,
1210 .ctl_name = FS_DENTRY,
1211 .procname = "dentry-state",
1212 .data = &dentry_stat,
1213 .maxlen = 6*sizeof(int),
1214 .mode = 0444,
1215 .proc_handler = &proc_dointvec,
1218 .ctl_name = FS_OVERFLOWUID,
1219 .procname = "overflowuid",
1220 .data = &fs_overflowuid,
1221 .maxlen = sizeof(int),
1222 .mode = 0644,
1223 .proc_handler = &proc_dointvec_minmax,
1224 .strategy = &sysctl_intvec,
1225 .extra1 = &minolduid,
1226 .extra2 = &maxolduid,
1229 .ctl_name = FS_OVERFLOWGID,
1230 .procname = "overflowgid",
1231 .data = &fs_overflowgid,
1232 .maxlen = sizeof(int),
1233 .mode = 0644,
1234 .proc_handler = &proc_dointvec_minmax,
1235 .strategy = &sysctl_intvec,
1236 .extra1 = &minolduid,
1237 .extra2 = &maxolduid,
1240 .ctl_name = FS_LEASES,
1241 .procname = "leases-enable",
1242 .data = &leases_enable,
1243 .maxlen = sizeof(int),
1244 .mode = 0644,
1245 .proc_handler = &proc_dointvec,
1247 #ifdef CONFIG_DNOTIFY
1249 .ctl_name = FS_DIR_NOTIFY,
1250 .procname = "dir-notify-enable",
1251 .data = &dir_notify_enable,
1252 .maxlen = sizeof(int),
1253 .mode = 0644,
1254 .proc_handler = &proc_dointvec,
1256 #endif
1257 #ifdef CONFIG_MMU
1259 .ctl_name = FS_LEASE_TIME,
1260 .procname = "lease-break-time",
1261 .data = &lease_break_time,
1262 .maxlen = sizeof(int),
1263 .mode = 0644,
1264 .proc_handler = &proc_dointvec_minmax,
1265 .strategy = &sysctl_intvec,
1266 .extra1 = &zero,
1267 .extra2 = &two,
1270 .procname = "aio-nr",
1271 .data = &aio_nr,
1272 .maxlen = sizeof(aio_nr),
1273 .mode = 0444,
1274 .proc_handler = &proc_doulongvec_minmax,
1277 .procname = "aio-max-nr",
1278 .data = &aio_max_nr,
1279 .maxlen = sizeof(aio_max_nr),
1280 .mode = 0644,
1281 .proc_handler = &proc_doulongvec_minmax,
1283 #ifdef CONFIG_INOTIFY_USER
1285 .ctl_name = FS_INOTIFY,
1286 .procname = "inotify",
1287 .mode = 0555,
1288 .child = inotify_table,
1290 #endif
1291 #endif
1293 .ctl_name = KERN_SETUID_DUMPABLE,
1294 .procname = "suid_dumpable",
1295 .data = &suid_dumpable,
1296 .maxlen = sizeof(int),
1297 .mode = 0644,
1298 .proc_handler = &proc_dointvec,
1300 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1302 .ctl_name = CTL_UNNUMBERED,
1303 .procname = "binfmt_misc",
1304 .mode = 0555,
1305 .child = binfmt_misc_table,
1307 #endif
1309 * NOTE: do not add new entries to this table unless you have read
1310 * Documentation/sysctl/ctl_unnumbered.txt
1312 { .ctl_name = 0 }
1315 static struct ctl_table debug_table[] = {
1316 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1318 .ctl_name = CTL_UNNUMBERED,
1319 .procname = "exception-trace",
1320 .data = &show_unhandled_signals,
1321 .maxlen = sizeof(int),
1322 .mode = 0644,
1323 .proc_handler = proc_dointvec
1325 #endif
1326 { .ctl_name = 0 }
1329 static struct ctl_table dev_table[] = {
1330 { .ctl_name = 0 }
1333 static DEFINE_SPINLOCK(sysctl_lock);
1335 /* called under sysctl_lock */
1336 static int use_table(struct ctl_table_header *p)
1338 if (unlikely(p->unregistering))
1339 return 0;
1340 p->used++;
1341 return 1;
1344 /* called under sysctl_lock */
1345 static void unuse_table(struct ctl_table_header *p)
1347 if (!--p->used)
1348 if (unlikely(p->unregistering))
1349 complete(p->unregistering);
1352 /* called under sysctl_lock, will reacquire if has to wait */
1353 static void start_unregistering(struct ctl_table_header *p)
1356 * if p->used is 0, nobody will ever touch that entry again;
1357 * we'll eliminate all paths to it before dropping sysctl_lock
1359 if (unlikely(p->used)) {
1360 struct completion wait;
1361 init_completion(&wait);
1362 p->unregistering = &wait;
1363 spin_unlock(&sysctl_lock);
1364 wait_for_completion(&wait);
1365 spin_lock(&sysctl_lock);
1368 * do not remove from the list until nobody holds it; walking the
1369 * list in do_sysctl() relies on that.
1371 list_del_init(&p->ctl_entry);
1374 void sysctl_head_finish(struct ctl_table_header *head)
1376 if (!head)
1377 return;
1378 spin_lock(&sysctl_lock);
1379 unuse_table(head);
1380 spin_unlock(&sysctl_lock);
1383 static struct list_head *
1384 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1386 struct list_head *header_list;
1387 header_list = &root->header_list;
1388 if (root->lookup)
1389 header_list = root->lookup(root, namespaces);
1390 return header_list;
1393 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1394 struct ctl_table_header *prev)
1396 struct ctl_table_root *root;
1397 struct list_head *header_list;
1398 struct ctl_table_header *head;
1399 struct list_head *tmp;
1401 spin_lock(&sysctl_lock);
1402 if (prev) {
1403 head = prev;
1404 tmp = &prev->ctl_entry;
1405 unuse_table(prev);
1406 goto next;
1408 tmp = &root_table_header.ctl_entry;
1409 for (;;) {
1410 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1412 if (!use_table(head))
1413 goto next;
1414 spin_unlock(&sysctl_lock);
1415 return head;
1416 next:
1417 root = head->root;
1418 tmp = tmp->next;
1419 header_list = lookup_header_list(root, namespaces);
1420 if (tmp != header_list)
1421 continue;
1423 do {
1424 root = list_entry(root->root_list.next,
1425 struct ctl_table_root, root_list);
1426 if (root == &sysctl_table_root)
1427 goto out;
1428 header_list = lookup_header_list(root, namespaces);
1429 } while (list_empty(header_list));
1430 tmp = header_list->next;
1432 out:
1433 spin_unlock(&sysctl_lock);
1434 return NULL;
1437 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1439 return __sysctl_head_next(current->nsproxy, prev);
1442 void register_sysctl_root(struct ctl_table_root *root)
1444 spin_lock(&sysctl_lock);
1445 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1446 spin_unlock(&sysctl_lock);
1449 #ifdef CONFIG_SYSCTL_SYSCALL
1450 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1451 void __user *newval, size_t newlen)
1453 struct ctl_table_header *head;
1454 int error = -ENOTDIR;
1456 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1457 return -ENOTDIR;
1458 if (oldval) {
1459 int old_len;
1460 if (!oldlenp || get_user(old_len, oldlenp))
1461 return -EFAULT;
1464 for (head = sysctl_head_next(NULL); head;
1465 head = sysctl_head_next(head)) {
1466 error = parse_table(name, nlen, oldval, oldlenp,
1467 newval, newlen, head->ctl_table);
1468 if (error != -ENOTDIR) {
1469 sysctl_head_finish(head);
1470 break;
1473 return error;
1476 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1478 struct __sysctl_args tmp;
1479 int error;
1481 if (copy_from_user(&tmp, args, sizeof(tmp)))
1482 return -EFAULT;
1484 error = deprecated_sysctl_warning(&tmp);
1485 if (error)
1486 goto out;
1488 lock_kernel();
1489 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1490 tmp.newval, tmp.newlen);
1491 unlock_kernel();
1492 out:
1493 return error;
1495 #endif /* CONFIG_SYSCTL_SYSCALL */
1498 * sysctl_perm does NOT grant the superuser all rights automatically, because
1499 * some sysctl variables are readonly even to root.
1502 static int test_perm(int mode, int op)
1504 if (!current->euid)
1505 mode >>= 6;
1506 else if (in_egroup_p(0))
1507 mode >>= 3;
1508 if ((mode & op & 0007) == op)
1509 return 0;
1510 return -EACCES;
1513 int sysctl_perm(struct ctl_table *table, int op)
1515 int error;
1516 error = security_sysctl(table, op);
1517 if (error)
1518 return error;
1519 return test_perm(table->mode, op);
1522 #ifdef CONFIG_SYSCTL_SYSCALL
1523 static int parse_table(int __user *name, int nlen,
1524 void __user *oldval, size_t __user *oldlenp,
1525 void __user *newval, size_t newlen,
1526 struct ctl_table *table)
1528 int n;
1529 repeat:
1530 if (!nlen)
1531 return -ENOTDIR;
1532 if (get_user(n, name))
1533 return -EFAULT;
1534 for ( ; table->ctl_name || table->procname; table++) {
1535 if (!table->ctl_name)
1536 continue;
1537 if (n == table->ctl_name) {
1538 int error;
1539 if (table->child) {
1540 if (sysctl_perm(table, 001))
1541 return -EPERM;
1542 name++;
1543 nlen--;
1544 table = table->child;
1545 goto repeat;
1547 error = do_sysctl_strategy(table, name, nlen,
1548 oldval, oldlenp,
1549 newval, newlen);
1550 return error;
1553 return -ENOTDIR;
1556 /* Perform the actual read/write of a sysctl table entry. */
1557 int do_sysctl_strategy (struct ctl_table *table,
1558 int __user *name, int nlen,
1559 void __user *oldval, size_t __user *oldlenp,
1560 void __user *newval, size_t newlen)
1562 int op = 0, rc;
1564 if (oldval)
1565 op |= 004;
1566 if (newval)
1567 op |= 002;
1568 if (sysctl_perm(table, op))
1569 return -EPERM;
1571 if (table->strategy) {
1572 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1573 newval, newlen);
1574 if (rc < 0)
1575 return rc;
1576 if (rc > 0)
1577 return 0;
1580 /* If there is no strategy routine, or if the strategy returns
1581 * zero, proceed with automatic r/w */
1582 if (table->data && table->maxlen) {
1583 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1584 newval, newlen);
1585 if (rc < 0)
1586 return rc;
1588 return 0;
1590 #endif /* CONFIG_SYSCTL_SYSCALL */
1592 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1594 for (; table->ctl_name || table->procname; table++) {
1595 table->parent = parent;
1596 if (table->child)
1597 sysctl_set_parent(table, table->child);
1601 static __init int sysctl_init(void)
1603 int err;
1604 sysctl_set_parent(NULL, root_table);
1605 err = sysctl_check_table(current->nsproxy, root_table);
1606 return 0;
1609 core_initcall(sysctl_init);
1612 * __register_sysctl_paths - register a sysctl hierarchy
1613 * @root: List of sysctl headers to register on
1614 * @namespaces: Data to compute which lists of sysctl entries are visible
1615 * @path: The path to the directory the sysctl table is in.
1616 * @table: the top-level table structure
1618 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1619 * array. A completely 0 filled entry terminates the table.
1621 * The members of the &struct ctl_table structure are used as follows:
1623 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1624 * must be unique within that level of sysctl
1626 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1627 * enter a sysctl file
1629 * data - a pointer to data for use by proc_handler
1631 * maxlen - the maximum size in bytes of the data
1633 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1635 * child - a pointer to the child sysctl table if this entry is a directory, or
1636 * %NULL.
1638 * proc_handler - the text handler routine (described below)
1640 * strategy - the strategy routine (described below)
1642 * de - for internal use by the sysctl routines
1644 * extra1, extra2 - extra pointers usable by the proc handler routines
1646 * Leaf nodes in the sysctl tree will be represented by a single file
1647 * under /proc; non-leaf nodes will be represented by directories.
1649 * sysctl(2) can automatically manage read and write requests through
1650 * the sysctl table. The data and maxlen fields of the ctl_table
1651 * struct enable minimal validation of the values being written to be
1652 * performed, and the mode field allows minimal authentication.
1654 * More sophisticated management can be enabled by the provision of a
1655 * strategy routine with the table entry. This will be called before
1656 * any automatic read or write of the data is performed.
1658 * The strategy routine may return
1660 * < 0 - Error occurred (error is passed to user process)
1662 * 0 - OK - proceed with automatic read or write.
1664 * > 0 - OK - read or write has been done by the strategy routine, so
1665 * return immediately.
1667 * There must be a proc_handler routine for any terminal nodes
1668 * mirrored under /proc/sys (non-terminals are handled by a built-in
1669 * directory handler). Several default handlers are available to
1670 * cover common cases -
1672 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1673 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1674 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1676 * It is the handler's job to read the input buffer from user memory
1677 * and process it. The handler should return 0 on success.
1679 * This routine returns %NULL on a failure to register, and a pointer
1680 * to the table header on success.
1682 struct ctl_table_header *__register_sysctl_paths(
1683 struct ctl_table_root *root,
1684 struct nsproxy *namespaces,
1685 const struct ctl_path *path, struct ctl_table *table)
1687 struct list_head *header_list;
1688 struct ctl_table_header *header;
1689 struct ctl_table *new, **prevp;
1690 unsigned int n, npath;
1692 /* Count the path components */
1693 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1697 * For each path component, allocate a 2-element ctl_table array.
1698 * The first array element will be filled with the sysctl entry
1699 * for this, the second will be the sentinel (ctl_name == 0).
1701 * We allocate everything in one go so that we don't have to
1702 * worry about freeing additional memory in unregister_sysctl_table.
1704 header = kzalloc(sizeof(struct ctl_table_header) +
1705 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1706 if (!header)
1707 return NULL;
1709 new = (struct ctl_table *) (header + 1);
1711 /* Now connect the dots */
1712 prevp = &header->ctl_table;
1713 for (n = 0; n < npath; ++n, ++path) {
1714 /* Copy the procname */
1715 new->procname = path->procname;
1716 new->ctl_name = path->ctl_name;
1717 new->mode = 0555;
1719 *prevp = new;
1720 prevp = &new->child;
1722 new += 2;
1724 *prevp = table;
1725 header->ctl_table_arg = table;
1727 INIT_LIST_HEAD(&header->ctl_entry);
1728 header->used = 0;
1729 header->unregistering = NULL;
1730 header->root = root;
1731 sysctl_set_parent(NULL, header->ctl_table);
1732 if (sysctl_check_table(namespaces, header->ctl_table)) {
1733 kfree(header);
1734 return NULL;
1736 spin_lock(&sysctl_lock);
1737 header_list = lookup_header_list(root, namespaces);
1738 list_add_tail(&header->ctl_entry, header_list);
1739 spin_unlock(&sysctl_lock);
1741 return header;
1745 * register_sysctl_table_path - register a sysctl table hierarchy
1746 * @path: The path to the directory the sysctl table is in.
1747 * @table: the top-level table structure
1749 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1750 * array. A completely 0 filled entry terminates the table.
1752 * See __register_sysctl_paths for more details.
1754 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1755 struct ctl_table *table)
1757 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1758 path, table);
1762 * register_sysctl_table - register a sysctl table hierarchy
1763 * @table: the top-level table structure
1765 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1766 * array. A completely 0 filled entry terminates the table.
1768 * See register_sysctl_paths for more details.
1770 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1772 static const struct ctl_path null_path[] = { {} };
1774 return register_sysctl_paths(null_path, table);
1778 * unregister_sysctl_table - unregister a sysctl table hierarchy
1779 * @header: the header returned from register_sysctl_table
1781 * Unregisters the sysctl table and all children. proc entries may not
1782 * actually be removed until they are no longer used by anyone.
1784 void unregister_sysctl_table(struct ctl_table_header * header)
1786 might_sleep();
1788 if (header == NULL)
1789 return;
1791 spin_lock(&sysctl_lock);
1792 start_unregistering(header);
1793 spin_unlock(&sysctl_lock);
1794 kfree(header);
1797 #else /* !CONFIG_SYSCTL */
1798 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1800 return NULL;
1803 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1804 struct ctl_table *table)
1806 return NULL;
1809 void unregister_sysctl_table(struct ctl_table_header * table)
1813 #endif /* CONFIG_SYSCTL */
1816 * /proc/sys support
1819 #ifdef CONFIG_PROC_SYSCTL
1821 static int _proc_do_string(void* data, int maxlen, int write,
1822 struct file *filp, void __user *buffer,
1823 size_t *lenp, loff_t *ppos)
1825 size_t len;
1826 char __user *p;
1827 char c;
1829 if (!data || !maxlen || !*lenp) {
1830 *lenp = 0;
1831 return 0;
1834 if (write) {
1835 len = 0;
1836 p = buffer;
1837 while (len < *lenp) {
1838 if (get_user(c, p++))
1839 return -EFAULT;
1840 if (c == 0 || c == '\n')
1841 break;
1842 len++;
1844 if (len >= maxlen)
1845 len = maxlen-1;
1846 if(copy_from_user(data, buffer, len))
1847 return -EFAULT;
1848 ((char *) data)[len] = 0;
1849 *ppos += *lenp;
1850 } else {
1851 len = strlen(data);
1852 if (len > maxlen)
1853 len = maxlen;
1855 if (*ppos > len) {
1856 *lenp = 0;
1857 return 0;
1860 data += *ppos;
1861 len -= *ppos;
1863 if (len > *lenp)
1864 len = *lenp;
1865 if (len)
1866 if(copy_to_user(buffer, data, len))
1867 return -EFAULT;
1868 if (len < *lenp) {
1869 if(put_user('\n', ((char __user *) buffer) + len))
1870 return -EFAULT;
1871 len++;
1873 *lenp = len;
1874 *ppos += len;
1876 return 0;
1880 * proc_dostring - read a string sysctl
1881 * @table: the sysctl table
1882 * @write: %TRUE if this is a write to the sysctl file
1883 * @filp: the file structure
1884 * @buffer: the user buffer
1885 * @lenp: the size of the user buffer
1886 * @ppos: file position
1888 * Reads/writes a string from/to the user buffer. If the kernel
1889 * buffer provided is not large enough to hold the string, the
1890 * string is truncated. The copied string is %NULL-terminated.
1891 * If the string is being read by the user process, it is copied
1892 * and a newline '\n' is added. It is truncated if the buffer is
1893 * not large enough.
1895 * Returns 0 on success.
1897 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1898 void __user *buffer, size_t *lenp, loff_t *ppos)
1900 return _proc_do_string(table->data, table->maxlen, write, filp,
1901 buffer, lenp, ppos);
1905 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1906 int *valp,
1907 int write, void *data)
1909 if (write) {
1910 *valp = *negp ? -*lvalp : *lvalp;
1911 } else {
1912 int val = *valp;
1913 if (val < 0) {
1914 *negp = -1;
1915 *lvalp = (unsigned long)-val;
1916 } else {
1917 *negp = 0;
1918 *lvalp = (unsigned long)val;
1921 return 0;
1924 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1925 int write, struct file *filp, void __user *buffer,
1926 size_t *lenp, loff_t *ppos,
1927 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1928 int write, void *data),
1929 void *data)
1931 #define TMPBUFLEN 21
1932 int *i, vleft, first=1, neg, val;
1933 unsigned long lval;
1934 size_t left, len;
1936 char buf[TMPBUFLEN], *p;
1937 char __user *s = buffer;
1939 if (!tbl_data || !table->maxlen || !*lenp ||
1940 (*ppos && !write)) {
1941 *lenp = 0;
1942 return 0;
1945 i = (int *) tbl_data;
1946 vleft = table->maxlen / sizeof(*i);
1947 left = *lenp;
1949 if (!conv)
1950 conv = do_proc_dointvec_conv;
1952 for (; left && vleft--; i++, first=0) {
1953 if (write) {
1954 while (left) {
1955 char c;
1956 if (get_user(c, s))
1957 return -EFAULT;
1958 if (!isspace(c))
1959 break;
1960 left--;
1961 s++;
1963 if (!left)
1964 break;
1965 neg = 0;
1966 len = left;
1967 if (len > sizeof(buf) - 1)
1968 len = sizeof(buf) - 1;
1969 if (copy_from_user(buf, s, len))
1970 return -EFAULT;
1971 buf[len] = 0;
1972 p = buf;
1973 if (*p == '-' && left > 1) {
1974 neg = 1;
1975 p++;
1977 if (*p < '0' || *p > '9')
1978 break;
1980 lval = simple_strtoul(p, &p, 0);
1982 len = p-buf;
1983 if ((len < left) && *p && !isspace(*p))
1984 break;
1985 if (neg)
1986 val = -val;
1987 s += len;
1988 left -= len;
1990 if (conv(&neg, &lval, i, 1, data))
1991 break;
1992 } else {
1993 p = buf;
1994 if (!first)
1995 *p++ = '\t';
1997 if (conv(&neg, &lval, i, 0, data))
1998 break;
2000 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2001 len = strlen(buf);
2002 if (len > left)
2003 len = left;
2004 if(copy_to_user(s, buf, len))
2005 return -EFAULT;
2006 left -= len;
2007 s += len;
2011 if (!write && !first && left) {
2012 if(put_user('\n', s))
2013 return -EFAULT;
2014 left--, s++;
2016 if (write) {
2017 while (left) {
2018 char c;
2019 if (get_user(c, s++))
2020 return -EFAULT;
2021 if (!isspace(c))
2022 break;
2023 left--;
2026 if (write && first)
2027 return -EINVAL;
2028 *lenp -= left;
2029 *ppos += *lenp;
2030 return 0;
2031 #undef TMPBUFLEN
2034 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2035 void __user *buffer, size_t *lenp, loff_t *ppos,
2036 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2037 int write, void *data),
2038 void *data)
2040 return __do_proc_dointvec(table->data, table, write, filp,
2041 buffer, lenp, ppos, conv, data);
2045 * proc_dointvec - read a vector of integers
2046 * @table: the sysctl table
2047 * @write: %TRUE if this is a write to the sysctl file
2048 * @filp: the file structure
2049 * @buffer: the user buffer
2050 * @lenp: the size of the user buffer
2051 * @ppos: file position
2053 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2054 * values from/to the user buffer, treated as an ASCII string.
2056 * Returns 0 on success.
2058 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2059 void __user *buffer, size_t *lenp, loff_t *ppos)
2061 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2062 NULL,NULL);
2065 #define OP_SET 0
2066 #define OP_AND 1
2067 #define OP_OR 2
2069 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2070 int *valp,
2071 int write, void *data)
2073 int op = *(int *)data;
2074 if (write) {
2075 int val = *negp ? -*lvalp : *lvalp;
2076 switch(op) {
2077 case OP_SET: *valp = val; break;
2078 case OP_AND: *valp &= val; break;
2079 case OP_OR: *valp |= val; break;
2081 } else {
2082 int val = *valp;
2083 if (val < 0) {
2084 *negp = -1;
2085 *lvalp = (unsigned long)-val;
2086 } else {
2087 *negp = 0;
2088 *lvalp = (unsigned long)val;
2091 return 0;
2094 #ifdef CONFIG_SECURITY_CAPABILITIES
2096 * init may raise the set.
2099 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2100 void __user *buffer, size_t *lenp, loff_t *ppos)
2102 int op;
2104 if (write && !capable(CAP_SYS_MODULE)) {
2105 return -EPERM;
2108 op = is_global_init(current) ? OP_SET : OP_AND;
2109 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2110 do_proc_dointvec_bset_conv,&op);
2112 #endif /* def CONFIG_SECURITY_CAPABILITIES */
2115 * Taint values can only be increased
2117 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2118 void __user *buffer, size_t *lenp, loff_t *ppos)
2120 int op;
2122 if (write && !capable(CAP_SYS_ADMIN))
2123 return -EPERM;
2125 op = OP_OR;
2126 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2127 do_proc_dointvec_bset_conv,&op);
2130 struct do_proc_dointvec_minmax_conv_param {
2131 int *min;
2132 int *max;
2135 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2136 int *valp,
2137 int write, void *data)
2139 struct do_proc_dointvec_minmax_conv_param *param = data;
2140 if (write) {
2141 int val = *negp ? -*lvalp : *lvalp;
2142 if ((param->min && *param->min > val) ||
2143 (param->max && *param->max < val))
2144 return -EINVAL;
2145 *valp = val;
2146 } else {
2147 int val = *valp;
2148 if (val < 0) {
2149 *negp = -1;
2150 *lvalp = (unsigned long)-val;
2151 } else {
2152 *negp = 0;
2153 *lvalp = (unsigned long)val;
2156 return 0;
2160 * proc_dointvec_minmax - read a vector of integers with min/max values
2161 * @table: the sysctl table
2162 * @write: %TRUE if this is a write to the sysctl file
2163 * @filp: the file structure
2164 * @buffer: the user buffer
2165 * @lenp: the size of the user buffer
2166 * @ppos: file position
2168 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2169 * values from/to the user buffer, treated as an ASCII string.
2171 * This routine will ensure the values are within the range specified by
2172 * table->extra1 (min) and table->extra2 (max).
2174 * Returns 0 on success.
2176 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2177 void __user *buffer, size_t *lenp, loff_t *ppos)
2179 struct do_proc_dointvec_minmax_conv_param param = {
2180 .min = (int *) table->extra1,
2181 .max = (int *) table->extra2,
2183 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2184 do_proc_dointvec_minmax_conv, &param);
2187 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2188 struct file *filp,
2189 void __user *buffer,
2190 size_t *lenp, loff_t *ppos,
2191 unsigned long convmul,
2192 unsigned long convdiv)
2194 #define TMPBUFLEN 21
2195 unsigned long *i, *min, *max, val;
2196 int vleft, first=1, neg;
2197 size_t len, left;
2198 char buf[TMPBUFLEN], *p;
2199 char __user *s = buffer;
2201 if (!data || !table->maxlen || !*lenp ||
2202 (*ppos && !write)) {
2203 *lenp = 0;
2204 return 0;
2207 i = (unsigned long *) data;
2208 min = (unsigned long *) table->extra1;
2209 max = (unsigned long *) table->extra2;
2210 vleft = table->maxlen / sizeof(unsigned long);
2211 left = *lenp;
2213 for (; left && vleft--; i++, min++, max++, first=0) {
2214 if (write) {
2215 while (left) {
2216 char c;
2217 if (get_user(c, s))
2218 return -EFAULT;
2219 if (!isspace(c))
2220 break;
2221 left--;
2222 s++;
2224 if (!left)
2225 break;
2226 neg = 0;
2227 len = left;
2228 if (len > TMPBUFLEN-1)
2229 len = TMPBUFLEN-1;
2230 if (copy_from_user(buf, s, len))
2231 return -EFAULT;
2232 buf[len] = 0;
2233 p = buf;
2234 if (*p == '-' && left > 1) {
2235 neg = 1;
2236 p++;
2238 if (*p < '0' || *p > '9')
2239 break;
2240 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2241 len = p-buf;
2242 if ((len < left) && *p && !isspace(*p))
2243 break;
2244 if (neg)
2245 val = -val;
2246 s += len;
2247 left -= len;
2249 if(neg)
2250 continue;
2251 if ((min && val < *min) || (max && val > *max))
2252 continue;
2253 *i = val;
2254 } else {
2255 p = buf;
2256 if (!first)
2257 *p++ = '\t';
2258 sprintf(p, "%lu", convdiv * (*i) / convmul);
2259 len = strlen(buf);
2260 if (len > left)
2261 len = left;
2262 if(copy_to_user(s, buf, len))
2263 return -EFAULT;
2264 left -= len;
2265 s += len;
2269 if (!write && !first && left) {
2270 if(put_user('\n', s))
2271 return -EFAULT;
2272 left--, s++;
2274 if (write) {
2275 while (left) {
2276 char c;
2277 if (get_user(c, s++))
2278 return -EFAULT;
2279 if (!isspace(c))
2280 break;
2281 left--;
2284 if (write && first)
2285 return -EINVAL;
2286 *lenp -= left;
2287 *ppos += *lenp;
2288 return 0;
2289 #undef TMPBUFLEN
2292 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2293 struct file *filp,
2294 void __user *buffer,
2295 size_t *lenp, loff_t *ppos,
2296 unsigned long convmul,
2297 unsigned long convdiv)
2299 return __do_proc_doulongvec_minmax(table->data, table, write,
2300 filp, buffer, lenp, ppos, convmul, convdiv);
2304 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2305 * @table: the sysctl table
2306 * @write: %TRUE if this is a write to the sysctl file
2307 * @filp: the file structure
2308 * @buffer: the user buffer
2309 * @lenp: the size of the user buffer
2310 * @ppos: file position
2312 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2313 * values from/to the user buffer, treated as an ASCII string.
2315 * This routine will ensure the values are within the range specified by
2316 * table->extra1 (min) and table->extra2 (max).
2318 * Returns 0 on success.
2320 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2321 void __user *buffer, size_t *lenp, loff_t *ppos)
2323 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2327 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2328 * @table: the sysctl table
2329 * @write: %TRUE if this is a write to the sysctl file
2330 * @filp: the file structure
2331 * @buffer: the user buffer
2332 * @lenp: the size of the user buffer
2333 * @ppos: file position
2335 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2336 * values from/to the user buffer, treated as an ASCII string. The values
2337 * are treated as milliseconds, and converted to jiffies when they are stored.
2339 * This routine will ensure the values are within the range specified by
2340 * table->extra1 (min) and table->extra2 (max).
2342 * Returns 0 on success.
2344 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2345 struct file *filp,
2346 void __user *buffer,
2347 size_t *lenp, loff_t *ppos)
2349 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2350 lenp, ppos, HZ, 1000l);
2354 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2355 int *valp,
2356 int write, void *data)
2358 if (write) {
2359 if (*lvalp > LONG_MAX / HZ)
2360 return 1;
2361 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2362 } else {
2363 int val = *valp;
2364 unsigned long lval;
2365 if (val < 0) {
2366 *negp = -1;
2367 lval = (unsigned long)-val;
2368 } else {
2369 *negp = 0;
2370 lval = (unsigned long)val;
2372 *lvalp = lval / HZ;
2374 return 0;
2377 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2378 int *valp,
2379 int write, void *data)
2381 if (write) {
2382 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2383 return 1;
2384 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2385 } else {
2386 int val = *valp;
2387 unsigned long lval;
2388 if (val < 0) {
2389 *negp = -1;
2390 lval = (unsigned long)-val;
2391 } else {
2392 *negp = 0;
2393 lval = (unsigned long)val;
2395 *lvalp = jiffies_to_clock_t(lval);
2397 return 0;
2400 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2401 int *valp,
2402 int write, void *data)
2404 if (write) {
2405 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2406 } else {
2407 int val = *valp;
2408 unsigned long lval;
2409 if (val < 0) {
2410 *negp = -1;
2411 lval = (unsigned long)-val;
2412 } else {
2413 *negp = 0;
2414 lval = (unsigned long)val;
2416 *lvalp = jiffies_to_msecs(lval);
2418 return 0;
2422 * proc_dointvec_jiffies - read a vector of integers as seconds
2423 * @table: the sysctl table
2424 * @write: %TRUE if this is a write to the sysctl file
2425 * @filp: the file structure
2426 * @buffer: the user buffer
2427 * @lenp: the size of the user buffer
2428 * @ppos: file position
2430 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2431 * values from/to the user buffer, treated as an ASCII string.
2432 * The values read are assumed to be in seconds, and are converted into
2433 * jiffies.
2435 * Returns 0 on success.
2437 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2438 void __user *buffer, size_t *lenp, loff_t *ppos)
2440 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2441 do_proc_dointvec_jiffies_conv,NULL);
2445 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2446 * @table: the sysctl table
2447 * @write: %TRUE if this is a write to the sysctl file
2448 * @filp: the file structure
2449 * @buffer: the user buffer
2450 * @lenp: the size of the user buffer
2451 * @ppos: pointer to the file position
2453 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2454 * values from/to the user buffer, treated as an ASCII string.
2455 * The values read are assumed to be in 1/USER_HZ seconds, and
2456 * are converted into jiffies.
2458 * Returns 0 on success.
2460 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2461 void __user *buffer, size_t *lenp, loff_t *ppos)
2463 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2464 do_proc_dointvec_userhz_jiffies_conv,NULL);
2468 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2469 * @table: the sysctl table
2470 * @write: %TRUE if this is a write to the sysctl file
2471 * @filp: the file structure
2472 * @buffer: the user buffer
2473 * @lenp: the size of the user buffer
2474 * @ppos: file position
2475 * @ppos: the current position in the file
2477 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2478 * values from/to the user buffer, treated as an ASCII string.
2479 * The values read are assumed to be in 1/1000 seconds, and
2480 * are converted into jiffies.
2482 * Returns 0 on success.
2484 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2485 void __user *buffer, size_t *lenp, loff_t *ppos)
2487 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2488 do_proc_dointvec_ms_jiffies_conv, NULL);
2491 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2492 void __user *buffer, size_t *lenp, loff_t *ppos)
2494 struct pid *new_pid;
2495 pid_t tmp;
2496 int r;
2498 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
2500 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2501 lenp, ppos, NULL, NULL);
2502 if (r || !write)
2503 return r;
2505 new_pid = find_get_pid(tmp);
2506 if (!new_pid)
2507 return -ESRCH;
2509 put_pid(xchg(&cad_pid, new_pid));
2510 return 0;
2513 #else /* CONFIG_PROC_FS */
2515 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2516 void __user *buffer, size_t *lenp, loff_t *ppos)
2518 return -ENOSYS;
2521 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2522 void __user *buffer, size_t *lenp, loff_t *ppos)
2524 return -ENOSYS;
2527 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2528 void __user *buffer, size_t *lenp, loff_t *ppos)
2530 return -ENOSYS;
2533 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2534 void __user *buffer, size_t *lenp, loff_t *ppos)
2536 return -ENOSYS;
2539 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2540 void __user *buffer, size_t *lenp, loff_t *ppos)
2542 return -ENOSYS;
2545 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2546 void __user *buffer, size_t *lenp, loff_t *ppos)
2548 return -ENOSYS;
2551 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2552 void __user *buffer, size_t *lenp, loff_t *ppos)
2554 return -ENOSYS;
2557 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2558 void __user *buffer, size_t *lenp, loff_t *ppos)
2560 return -ENOSYS;
2563 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2564 struct file *filp,
2565 void __user *buffer,
2566 size_t *lenp, loff_t *ppos)
2568 return -ENOSYS;
2572 #endif /* CONFIG_PROC_FS */
2575 #ifdef CONFIG_SYSCTL_SYSCALL
2577 * General sysctl support routines
2580 /* The generic sysctl data routine (used if no strategy routine supplied) */
2581 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2582 void __user *oldval, size_t __user *oldlenp,
2583 void __user *newval, size_t newlen)
2585 size_t len;
2587 /* Get out of I don't have a variable */
2588 if (!table->data || !table->maxlen)
2589 return -ENOTDIR;
2591 if (oldval && oldlenp) {
2592 if (get_user(len, oldlenp))
2593 return -EFAULT;
2594 if (len) {
2595 if (len > table->maxlen)
2596 len = table->maxlen;
2597 if (copy_to_user(oldval, table->data, len))
2598 return -EFAULT;
2599 if (put_user(len, oldlenp))
2600 return -EFAULT;
2604 if (newval && newlen) {
2605 if (newlen > table->maxlen)
2606 newlen = table->maxlen;
2608 if (copy_from_user(table->data, newval, newlen))
2609 return -EFAULT;
2611 return 1;
2614 /* The generic string strategy routine: */
2615 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2616 void __user *oldval, size_t __user *oldlenp,
2617 void __user *newval, size_t newlen)
2619 if (!table->data || !table->maxlen)
2620 return -ENOTDIR;
2622 if (oldval && oldlenp) {
2623 size_t bufsize;
2624 if (get_user(bufsize, oldlenp))
2625 return -EFAULT;
2626 if (bufsize) {
2627 size_t len = strlen(table->data), copied;
2629 /* This shouldn't trigger for a well-formed sysctl */
2630 if (len > table->maxlen)
2631 len = table->maxlen;
2633 /* Copy up to a max of bufsize-1 bytes of the string */
2634 copied = (len >= bufsize) ? bufsize - 1 : len;
2636 if (copy_to_user(oldval, table->data, copied) ||
2637 put_user(0, (char __user *)(oldval + copied)))
2638 return -EFAULT;
2639 if (put_user(len, oldlenp))
2640 return -EFAULT;
2643 if (newval && newlen) {
2644 size_t len = newlen;
2645 if (len > table->maxlen)
2646 len = table->maxlen;
2647 if(copy_from_user(table->data, newval, len))
2648 return -EFAULT;
2649 if (len == table->maxlen)
2650 len--;
2651 ((char *) table->data)[len] = 0;
2653 return 1;
2657 * This function makes sure that all of the integers in the vector
2658 * are between the minimum and maximum values given in the arrays
2659 * table->extra1 and table->extra2, respectively.
2661 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2662 void __user *oldval, size_t __user *oldlenp,
2663 void __user *newval, size_t newlen)
2666 if (newval && newlen) {
2667 int __user *vec = (int __user *) newval;
2668 int *min = (int *) table->extra1;
2669 int *max = (int *) table->extra2;
2670 size_t length;
2671 int i;
2673 if (newlen % sizeof(int) != 0)
2674 return -EINVAL;
2676 if (!table->extra1 && !table->extra2)
2677 return 0;
2679 if (newlen > table->maxlen)
2680 newlen = table->maxlen;
2681 length = newlen / sizeof(int);
2683 for (i = 0; i < length; i++) {
2684 int value;
2685 if (get_user(value, vec + i))
2686 return -EFAULT;
2687 if (min && value < min[i])
2688 return -EINVAL;
2689 if (max && value > max[i])
2690 return -EINVAL;
2693 return 0;
2696 /* Strategy function to convert jiffies to seconds */
2697 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2698 void __user *oldval, size_t __user *oldlenp,
2699 void __user *newval, size_t newlen)
2701 if (oldval && oldlenp) {
2702 size_t olen;
2704 if (get_user(olen, oldlenp))
2705 return -EFAULT;
2706 if (olen) {
2707 int val;
2709 if (olen < sizeof(int))
2710 return -EINVAL;
2712 val = *(int *)(table->data) / HZ;
2713 if (put_user(val, (int __user *)oldval))
2714 return -EFAULT;
2715 if (put_user(sizeof(int), oldlenp))
2716 return -EFAULT;
2719 if (newval && newlen) {
2720 int new;
2721 if (newlen != sizeof(int))
2722 return -EINVAL;
2723 if (get_user(new, (int __user *)newval))
2724 return -EFAULT;
2725 *(int *)(table->data) = new*HZ;
2727 return 1;
2730 /* Strategy function to convert jiffies to seconds */
2731 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2732 void __user *oldval, size_t __user *oldlenp,
2733 void __user *newval, size_t newlen)
2735 if (oldval && oldlenp) {
2736 size_t olen;
2738 if (get_user(olen, oldlenp))
2739 return -EFAULT;
2740 if (olen) {
2741 int val;
2743 if (olen < sizeof(int))
2744 return -EINVAL;
2746 val = jiffies_to_msecs(*(int *)(table->data));
2747 if (put_user(val, (int __user *)oldval))
2748 return -EFAULT;
2749 if (put_user(sizeof(int), oldlenp))
2750 return -EFAULT;
2753 if (newval && newlen) {
2754 int new;
2755 if (newlen != sizeof(int))
2756 return -EINVAL;
2757 if (get_user(new, (int __user *)newval))
2758 return -EFAULT;
2759 *(int *)(table->data) = msecs_to_jiffies(new);
2761 return 1;
2766 #else /* CONFIG_SYSCTL_SYSCALL */
2769 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2771 struct __sysctl_args tmp;
2772 int error;
2774 if (copy_from_user(&tmp, args, sizeof(tmp)))
2775 return -EFAULT;
2777 error = deprecated_sysctl_warning(&tmp);
2779 /* If no error reading the parameters then just -ENOSYS ... */
2780 if (!error)
2781 error = -ENOSYS;
2783 return error;
2786 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2787 void __user *oldval, size_t __user *oldlenp,
2788 void __user *newval, size_t newlen)
2790 return -ENOSYS;
2793 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2794 void __user *oldval, size_t __user *oldlenp,
2795 void __user *newval, size_t newlen)
2797 return -ENOSYS;
2800 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2801 void __user *oldval, size_t __user *oldlenp,
2802 void __user *newval, size_t newlen)
2804 return -ENOSYS;
2807 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2808 void __user *oldval, size_t __user *oldlenp,
2809 void __user *newval, size_t newlen)
2811 return -ENOSYS;
2814 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2815 void __user *oldval, size_t __user *oldlenp,
2816 void __user *newval, size_t newlen)
2818 return -ENOSYS;
2821 #endif /* CONFIG_SYSCTL_SYSCALL */
2823 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2825 static int msg_count;
2826 int name[CTL_MAXNAME];
2827 int i;
2829 /* Check args->nlen. */
2830 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2831 return -ENOTDIR;
2833 /* Read in the sysctl name for better debug message logging */
2834 for (i = 0; i < args->nlen; i++)
2835 if (get_user(name[i], args->name + i))
2836 return -EFAULT;
2838 /* Ignore accesses to kernel.version */
2839 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2840 return 0;
2842 if (msg_count < 5) {
2843 msg_count++;
2844 printk(KERN_INFO
2845 "warning: process `%s' used the deprecated sysctl "
2846 "system call with ", current->comm);
2847 for (i = 0; i < args->nlen; i++)
2848 printk("%d.", name[i]);
2849 printk("\n");
2851 return 0;
2855 * No sense putting this after each symbol definition, twice,
2856 * exception granted :-)
2858 EXPORT_SYMBOL(proc_dointvec);
2859 EXPORT_SYMBOL(proc_dointvec_jiffies);
2860 EXPORT_SYMBOL(proc_dointvec_minmax);
2861 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2862 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2863 EXPORT_SYMBOL(proc_dostring);
2864 EXPORT_SYMBOL(proc_doulongvec_minmax);
2865 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2866 EXPORT_SYMBOL(register_sysctl_table);
2867 EXPORT_SYMBOL(register_sysctl_paths);
2868 EXPORT_SYMBOL(sysctl_intvec);
2869 EXPORT_SYMBOL(sysctl_jiffies);
2870 EXPORT_SYMBOL(sysctl_ms_jiffies);
2871 EXPORT_SYMBOL(sysctl_string);
2872 EXPORT_SYMBOL(sysctl_data);
2873 EXPORT_SYMBOL(unregister_sysctl_table);