x86: add PUD_PAGE_SIZE
[wrt350n-kernel.git] / kernel / sysctl.c
blob7cb1ac3e6fff9583c0d880788190d14da6e2ced1
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 latencytop_enabled;
86 /* Constants used for minimum and maximum */
87 #ifdef CONFIG_DETECT_SOFTLOCKUP
88 static int one = 1;
89 static int sixty = 60;
90 #endif
92 #ifdef CONFIG_MMU
93 static int two = 2;
94 #endif
96 static int zero;
97 static int one_hundred = 100;
99 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
100 static int maxolduid = 65535;
101 static int minolduid;
102 static int min_percpu_pagelist_fract = 8;
104 static int ngroups_max = NGROUPS_MAX;
106 #ifdef CONFIG_KMOD
107 extern char modprobe_path[];
108 #endif
109 #ifdef CONFIG_CHR_DEV_SG
110 extern int sg_big_buff;
111 #endif
113 #ifdef __sparc__
114 extern char reboot_command [];
115 extern int stop_a_enabled;
116 extern int scons_pwroff;
117 #endif
119 #ifdef __hppa__
120 extern int pwrsw_enabled;
121 extern int unaligned_enabled;
122 #endif
124 #ifdef CONFIG_S390
125 #ifdef CONFIG_MATHEMU
126 extern int sysctl_ieee_emulation_warnings;
127 #endif
128 extern int sysctl_userprocess_debug;
129 extern int spin_retry;
130 #endif
132 extern int sysctl_hz_timer;
134 #ifdef CONFIG_BSD_PROCESS_ACCT
135 extern int acct_parm[];
136 #endif
138 #ifdef CONFIG_IA64
139 extern int no_unaligned_warning;
140 #endif
142 #ifdef CONFIG_RT_MUTEXES
143 extern int max_lock_depth;
144 #endif
146 #ifdef CONFIG_SYSCTL_SYSCALL
147 static int parse_table(int __user *, int, void __user *, size_t __user *,
148 void __user *, size_t, struct ctl_table *);
149 #endif
152 #ifdef CONFIG_PROC_SYSCTL
153 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
155 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
156 void __user *buffer, size_t *lenp, loff_t *ppos);
157 #endif
159 static struct ctl_table root_table[];
160 static struct ctl_table_root sysctl_table_root;
161 static struct ctl_table_header root_table_header = {
162 .ctl_table = root_table,
163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
164 .root = &sysctl_table_root,
166 static struct ctl_table_root sysctl_table_root = {
167 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
168 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
171 static struct ctl_table kern_table[];
172 static struct ctl_table vm_table[];
173 static struct ctl_table fs_table[];
174 static struct ctl_table debug_table[];
175 static struct ctl_table dev_table[];
176 extern struct ctl_table random_table[];
177 #ifdef CONFIG_INOTIFY_USER
178 extern struct ctl_table inotify_table[];
179 #endif
181 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
182 int sysctl_legacy_va_layout;
183 #endif
185 extern int prove_locking;
186 extern int lock_stat;
188 /* The default sysctl tables: */
190 static struct ctl_table root_table[] = {
192 .ctl_name = CTL_KERN,
193 .procname = "kernel",
194 .mode = 0555,
195 .child = kern_table,
198 .ctl_name = CTL_VM,
199 .procname = "vm",
200 .mode = 0555,
201 .child = vm_table,
204 .ctl_name = CTL_FS,
205 .procname = "fs",
206 .mode = 0555,
207 .child = fs_table,
210 .ctl_name = CTL_DEBUG,
211 .procname = "debug",
212 .mode = 0555,
213 .child = debug_table,
216 .ctl_name = CTL_DEV,
217 .procname = "dev",
218 .mode = 0555,
219 .child = dev_table,
222 * NOTE: do not add new entries to this table unless you have read
223 * Documentation/sysctl/ctl_unnumbered.txt
225 { .ctl_name = 0 }
228 #ifdef CONFIG_SCHED_DEBUG
229 static int min_sched_granularity_ns = 100000; /* 100 usecs */
230 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
231 static int min_wakeup_granularity_ns; /* 0 usecs */
232 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
233 #endif
235 static struct ctl_table kern_table[] = {
236 #ifdef CONFIG_SCHED_DEBUG
238 .ctl_name = CTL_UNNUMBERED,
239 .procname = "sched_min_granularity_ns",
240 .data = &sysctl_sched_min_granularity,
241 .maxlen = sizeof(unsigned int),
242 .mode = 0644,
243 .proc_handler = &sched_nr_latency_handler,
244 .strategy = &sysctl_intvec,
245 .extra1 = &min_sched_granularity_ns,
246 .extra2 = &max_sched_granularity_ns,
249 .ctl_name = CTL_UNNUMBERED,
250 .procname = "sched_latency_ns",
251 .data = &sysctl_sched_latency,
252 .maxlen = sizeof(unsigned int),
253 .mode = 0644,
254 .proc_handler = &sched_nr_latency_handler,
255 .strategy = &sysctl_intvec,
256 .extra1 = &min_sched_granularity_ns,
257 .extra2 = &max_sched_granularity_ns,
260 .ctl_name = CTL_UNNUMBERED,
261 .procname = "sched_wakeup_granularity_ns",
262 .data = &sysctl_sched_wakeup_granularity,
263 .maxlen = sizeof(unsigned int),
264 .mode = 0644,
265 .proc_handler = &proc_dointvec_minmax,
266 .strategy = &sysctl_intvec,
267 .extra1 = &min_wakeup_granularity_ns,
268 .extra2 = &max_wakeup_granularity_ns,
271 .ctl_name = CTL_UNNUMBERED,
272 .procname = "sched_batch_wakeup_granularity_ns",
273 .data = &sysctl_sched_batch_wakeup_granularity,
274 .maxlen = sizeof(unsigned int),
275 .mode = 0644,
276 .proc_handler = &proc_dointvec_minmax,
277 .strategy = &sysctl_intvec,
278 .extra1 = &min_wakeup_granularity_ns,
279 .extra2 = &max_wakeup_granularity_ns,
282 .ctl_name = CTL_UNNUMBERED,
283 .procname = "sched_child_runs_first",
284 .data = &sysctl_sched_child_runs_first,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = &proc_dointvec,
290 .ctl_name = CTL_UNNUMBERED,
291 .procname = "sched_features",
292 .data = &sysctl_sched_features,
293 .maxlen = sizeof(unsigned int),
294 .mode = 0644,
295 .proc_handler = &proc_dointvec,
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "sched_migration_cost",
300 .data = &sysctl_sched_migration_cost,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
303 .proc_handler = &proc_dointvec,
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_nr_migrate",
308 .data = &sysctl_sched_nr_migrate,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
311 .proc_handler = &proc_dointvec,
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_rt_period_ms",
316 .data = &sysctl_sched_rt_period,
317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
319 .proc_handler = &proc_dointvec,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_rt_ratio",
324 .data = &sysctl_sched_rt_ratio,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
329 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
331 .ctl_name = CTL_UNNUMBERED,
332 .procname = "sched_min_bal_int_shares",
333 .data = &sysctl_sched_min_bal_int_shares,
334 .maxlen = sizeof(unsigned int),
335 .mode = 0644,
336 .proc_handler = &proc_dointvec,
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "sched_max_bal_int_shares",
341 .data = &sysctl_sched_max_bal_int_shares,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = &proc_dointvec,
346 #endif
347 #endif
349 .ctl_name = CTL_UNNUMBERED,
350 .procname = "sched_compat_yield",
351 .data = &sysctl_sched_compat_yield,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
356 #ifdef CONFIG_PROVE_LOCKING
358 .ctl_name = CTL_UNNUMBERED,
359 .procname = "prove_locking",
360 .data = &prove_locking,
361 .maxlen = sizeof(int),
362 .mode = 0644,
363 .proc_handler = &proc_dointvec,
365 #endif
366 #ifdef CONFIG_LOCK_STAT
368 .ctl_name = CTL_UNNUMBERED,
369 .procname = "lock_stat",
370 .data = &lock_stat,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = &proc_dointvec,
375 #endif
377 .ctl_name = KERN_PANIC,
378 .procname = "panic",
379 .data = &panic_timeout,
380 .maxlen = sizeof(int),
381 .mode = 0644,
382 .proc_handler = &proc_dointvec,
385 .ctl_name = KERN_CORE_USES_PID,
386 .procname = "core_uses_pid",
387 .data = &core_uses_pid,
388 .maxlen = sizeof(int),
389 .mode = 0644,
390 .proc_handler = &proc_dointvec,
393 .ctl_name = KERN_CORE_PATTERN,
394 .procname = "core_pattern",
395 .data = core_pattern,
396 .maxlen = CORENAME_MAX_SIZE,
397 .mode = 0644,
398 .proc_handler = &proc_dostring,
399 .strategy = &sysctl_string,
401 #ifdef CONFIG_PROC_SYSCTL
403 .procname = "tainted",
404 .data = &tainted,
405 .maxlen = sizeof(int),
406 .mode = 0644,
407 .proc_handler = &proc_dointvec_taint,
409 #endif
410 #ifdef CONFIG_LATENCYTOP
412 .procname = "latencytop",
413 .data = &latencytop_enabled,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = &proc_dointvec,
418 #endif
419 #ifdef CONFIG_SECURITY_CAPABILITIES
421 .procname = "cap-bound",
422 .data = &cap_bset,
423 .maxlen = sizeof(kernel_cap_t),
424 .mode = 0600,
425 .proc_handler = &proc_dointvec_bset,
427 #endif /* def CONFIG_SECURITY_CAPABILITIES */
428 #ifdef CONFIG_BLK_DEV_INITRD
430 .ctl_name = KERN_REALROOTDEV,
431 .procname = "real-root-dev",
432 .data = &real_root_dev,
433 .maxlen = sizeof(int),
434 .mode = 0644,
435 .proc_handler = &proc_dointvec,
437 #endif
439 .ctl_name = CTL_UNNUMBERED,
440 .procname = "print-fatal-signals",
441 .data = &print_fatal_signals,
442 .maxlen = sizeof(int),
443 .mode = 0644,
444 .proc_handler = &proc_dointvec,
446 #ifdef __sparc__
448 .ctl_name = KERN_SPARC_REBOOT,
449 .procname = "reboot-cmd",
450 .data = reboot_command,
451 .maxlen = 256,
452 .mode = 0644,
453 .proc_handler = &proc_dostring,
454 .strategy = &sysctl_string,
457 .ctl_name = KERN_SPARC_STOP_A,
458 .procname = "stop-a",
459 .data = &stop_a_enabled,
460 .maxlen = sizeof (int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
465 .ctl_name = KERN_SPARC_SCONS_PWROFF,
466 .procname = "scons-poweroff",
467 .data = &scons_pwroff,
468 .maxlen = sizeof (int),
469 .mode = 0644,
470 .proc_handler = &proc_dointvec,
472 #endif
473 #ifdef __hppa__
475 .ctl_name = KERN_HPPA_PWRSW,
476 .procname = "soft-power",
477 .data = &pwrsw_enabled,
478 .maxlen = sizeof (int),
479 .mode = 0644,
480 .proc_handler = &proc_dointvec,
483 .ctl_name = KERN_HPPA_UNALIGNED,
484 .procname = "unaligned-trap",
485 .data = &unaligned_enabled,
486 .maxlen = sizeof (int),
487 .mode = 0644,
488 .proc_handler = &proc_dointvec,
490 #endif
492 .ctl_name = KERN_CTLALTDEL,
493 .procname = "ctrl-alt-del",
494 .data = &C_A_D,
495 .maxlen = sizeof(int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
500 .ctl_name = KERN_PRINTK,
501 .procname = "printk",
502 .data = &console_loglevel,
503 .maxlen = 4*sizeof(int),
504 .mode = 0644,
505 .proc_handler = &proc_dointvec,
507 #ifdef CONFIG_KMOD
509 .ctl_name = KERN_MODPROBE,
510 .procname = "modprobe",
511 .data = &modprobe_path,
512 .maxlen = KMOD_PATH_LEN,
513 .mode = 0644,
514 .proc_handler = &proc_dostring,
515 .strategy = &sysctl_string,
517 #endif
518 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
520 .ctl_name = KERN_HOTPLUG,
521 .procname = "hotplug",
522 .data = &uevent_helper,
523 .maxlen = UEVENT_HELPER_PATH_LEN,
524 .mode = 0644,
525 .proc_handler = &proc_dostring,
526 .strategy = &sysctl_string,
528 #endif
529 #ifdef CONFIG_CHR_DEV_SG
531 .ctl_name = KERN_SG_BIG_BUFF,
532 .procname = "sg-big-buff",
533 .data = &sg_big_buff,
534 .maxlen = sizeof (int),
535 .mode = 0444,
536 .proc_handler = &proc_dointvec,
538 #endif
539 #ifdef CONFIG_BSD_PROCESS_ACCT
541 .ctl_name = KERN_ACCT,
542 .procname = "acct",
543 .data = &acct_parm,
544 .maxlen = 3*sizeof(int),
545 .mode = 0644,
546 .proc_handler = &proc_dointvec,
548 #endif
549 #ifdef CONFIG_MAGIC_SYSRQ
551 .ctl_name = KERN_SYSRQ,
552 .procname = "sysrq",
553 .data = &__sysrq_enabled,
554 .maxlen = sizeof (int),
555 .mode = 0644,
556 .proc_handler = &proc_dointvec,
558 #endif
559 #ifdef CONFIG_PROC_SYSCTL
561 .procname = "cad_pid",
562 .data = NULL,
563 .maxlen = sizeof (int),
564 .mode = 0600,
565 .proc_handler = &proc_do_cad_pid,
567 #endif
569 .ctl_name = KERN_MAX_THREADS,
570 .procname = "threads-max",
571 .data = &max_threads,
572 .maxlen = sizeof(int),
573 .mode = 0644,
574 .proc_handler = &proc_dointvec,
577 .ctl_name = KERN_RANDOM,
578 .procname = "random",
579 .mode = 0555,
580 .child = random_table,
583 .ctl_name = KERN_OVERFLOWUID,
584 .procname = "overflowuid",
585 .data = &overflowuid,
586 .maxlen = sizeof(int),
587 .mode = 0644,
588 .proc_handler = &proc_dointvec_minmax,
589 .strategy = &sysctl_intvec,
590 .extra1 = &minolduid,
591 .extra2 = &maxolduid,
594 .ctl_name = KERN_OVERFLOWGID,
595 .procname = "overflowgid",
596 .data = &overflowgid,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = &proc_dointvec_minmax,
600 .strategy = &sysctl_intvec,
601 .extra1 = &minolduid,
602 .extra2 = &maxolduid,
604 #ifdef CONFIG_S390
605 #ifdef CONFIG_MATHEMU
607 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
608 .procname = "ieee_emulation_warnings",
609 .data = &sysctl_ieee_emulation_warnings,
610 .maxlen = sizeof(int),
611 .mode = 0644,
612 .proc_handler = &proc_dointvec,
614 #endif
615 #ifdef CONFIG_NO_IDLE_HZ
617 .ctl_name = KERN_HZ_TIMER,
618 .procname = "hz_timer",
619 .data = &sysctl_hz_timer,
620 .maxlen = sizeof(int),
621 .mode = 0644,
622 .proc_handler = &proc_dointvec,
624 #endif
626 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
627 .procname = "userprocess_debug",
628 .data = &sysctl_userprocess_debug,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = &proc_dointvec,
633 #endif
635 .ctl_name = KERN_PIDMAX,
636 .procname = "pid_max",
637 .data = &pid_max,
638 .maxlen = sizeof (int),
639 .mode = 0644,
640 .proc_handler = &proc_dointvec_minmax,
641 .strategy = sysctl_intvec,
642 .extra1 = &pid_max_min,
643 .extra2 = &pid_max_max,
646 .ctl_name = KERN_PANIC_ON_OOPS,
647 .procname = "panic_on_oops",
648 .data = &panic_on_oops,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec,
654 .ctl_name = KERN_PRINTK_RATELIMIT,
655 .procname = "printk_ratelimit",
656 .data = &printk_ratelimit_jiffies,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 .proc_handler = &proc_dointvec_jiffies,
660 .strategy = &sysctl_jiffies,
663 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
664 .procname = "printk_ratelimit_burst",
665 .data = &printk_ratelimit_burst,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = &proc_dointvec,
671 .ctl_name = KERN_NGROUPS_MAX,
672 .procname = "ngroups_max",
673 .data = &ngroups_max,
674 .maxlen = sizeof (int),
675 .mode = 0444,
676 .proc_handler = &proc_dointvec,
678 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
680 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
681 .procname = "unknown_nmi_panic",
682 .data = &unknown_nmi_panic,
683 .maxlen = sizeof (int),
684 .mode = 0644,
685 .proc_handler = &proc_dointvec,
688 .procname = "nmi_watchdog",
689 .data = &nmi_watchdog_enabled,
690 .maxlen = sizeof (int),
691 .mode = 0644,
692 .proc_handler = &proc_nmi_enabled,
694 #endif
695 #if defined(CONFIG_X86)
697 .ctl_name = KERN_PANIC_ON_NMI,
698 .procname = "panic_on_unrecovered_nmi",
699 .data = &panic_on_unrecovered_nmi,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 .proc_handler = &proc_dointvec,
705 .ctl_name = KERN_BOOTLOADER_TYPE,
706 .procname = "bootloader_type",
707 .data = &bootloader_type,
708 .maxlen = sizeof (int),
709 .mode = 0444,
710 .proc_handler = &proc_dointvec,
713 .ctl_name = CTL_UNNUMBERED,
714 .procname = "kstack_depth_to_print",
715 .data = &kstack_depth_to_print,
716 .maxlen = sizeof(int),
717 .mode = 0644,
718 .proc_handler = &proc_dointvec,
721 .ctl_name = CTL_UNNUMBERED,
722 .procname = "io_delay_type",
723 .data = &io_delay_type,
724 .maxlen = sizeof(int),
725 .mode = 0644,
726 .proc_handler = &proc_dointvec,
728 #endif
729 #if defined(CONFIG_MMU)
731 .ctl_name = KERN_RANDOMIZE,
732 .procname = "randomize_va_space",
733 .data = &randomize_va_space,
734 .maxlen = sizeof(int),
735 .mode = 0644,
736 .proc_handler = &proc_dointvec,
738 #endif
739 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
741 .ctl_name = KERN_SPIN_RETRY,
742 .procname = "spin_retry",
743 .data = &spin_retry,
744 .maxlen = sizeof (int),
745 .mode = 0644,
746 .proc_handler = &proc_dointvec,
748 #endif
749 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
751 .procname = "acpi_video_flags",
752 .data = &acpi_realmode_flags,
753 .maxlen = sizeof (unsigned long),
754 .mode = 0644,
755 .proc_handler = &proc_doulongvec_minmax,
757 #endif
758 #ifdef CONFIG_IA64
760 .ctl_name = KERN_IA64_UNALIGNED,
761 .procname = "ignore-unaligned-usertrap",
762 .data = &no_unaligned_warning,
763 .maxlen = sizeof (int),
764 .mode = 0644,
765 .proc_handler = &proc_dointvec,
767 #endif
768 #ifdef CONFIG_DETECT_SOFTLOCKUP
770 .ctl_name = CTL_UNNUMBERED,
771 .procname = "softlockup_thresh",
772 .data = &softlockup_thresh,
773 .maxlen = sizeof(unsigned long),
774 .mode = 0644,
775 .proc_handler = &proc_doulongvec_minmax,
776 .strategy = &sysctl_intvec,
777 .extra1 = &one,
778 .extra2 = &sixty,
781 .ctl_name = CTL_UNNUMBERED,
782 .procname = "hung_task_check_count",
783 .data = &sysctl_hung_task_check_count,
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_timeout_secs",
792 .data = &sysctl_hung_task_timeout_secs,
793 .maxlen = sizeof(unsigned long),
794 .mode = 0644,
795 .proc_handler = &proc_doulongvec_minmax,
796 .strategy = &sysctl_intvec,
799 .ctl_name = CTL_UNNUMBERED,
800 .procname = "hung_task_warnings",
801 .data = &sysctl_hung_task_warnings,
802 .maxlen = sizeof(unsigned long),
803 .mode = 0644,
804 .proc_handler = &proc_doulongvec_minmax,
805 .strategy = &sysctl_intvec,
807 #endif
808 #ifdef CONFIG_COMPAT
810 .ctl_name = KERN_COMPAT_LOG,
811 .procname = "compat-log",
812 .data = &compat_log,
813 .maxlen = sizeof (int),
814 .mode = 0644,
815 .proc_handler = &proc_dointvec,
817 #endif
818 #ifdef CONFIG_RT_MUTEXES
820 .ctl_name = KERN_MAX_LOCK_DEPTH,
821 .procname = "max_lock_depth",
822 .data = &max_lock_depth,
823 .maxlen = sizeof(int),
824 .mode = 0644,
825 .proc_handler = &proc_dointvec,
827 #endif
828 #ifdef CONFIG_PROC_FS
830 .ctl_name = CTL_UNNUMBERED,
831 .procname = "maps_protect",
832 .data = &maps_protect,
833 .maxlen = sizeof(int),
834 .mode = 0644,
835 .proc_handler = &proc_dointvec,
837 #endif
839 .ctl_name = CTL_UNNUMBERED,
840 .procname = "poweroff_cmd",
841 .data = &poweroff_cmd,
842 .maxlen = POWEROFF_CMD_PATH_LEN,
843 .mode = 0644,
844 .proc_handler = &proc_dostring,
845 .strategy = &sysctl_string,
848 * NOTE: do not add new entries to this table unless you have read
849 * Documentation/sysctl/ctl_unnumbered.txt
851 { .ctl_name = 0 }
854 static struct ctl_table vm_table[] = {
856 .ctl_name = VM_OVERCOMMIT_MEMORY,
857 .procname = "overcommit_memory",
858 .data = &sysctl_overcommit_memory,
859 .maxlen = sizeof(sysctl_overcommit_memory),
860 .mode = 0644,
861 .proc_handler = &proc_dointvec,
864 .ctl_name = VM_PANIC_ON_OOM,
865 .procname = "panic_on_oom",
866 .data = &sysctl_panic_on_oom,
867 .maxlen = sizeof(sysctl_panic_on_oom),
868 .mode = 0644,
869 .proc_handler = &proc_dointvec,
872 .ctl_name = CTL_UNNUMBERED,
873 .procname = "oom_kill_allocating_task",
874 .data = &sysctl_oom_kill_allocating_task,
875 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
876 .mode = 0644,
877 .proc_handler = &proc_dointvec,
880 .ctl_name = VM_OVERCOMMIT_RATIO,
881 .procname = "overcommit_ratio",
882 .data = &sysctl_overcommit_ratio,
883 .maxlen = sizeof(sysctl_overcommit_ratio),
884 .mode = 0644,
885 .proc_handler = &proc_dointvec,
888 .ctl_name = VM_PAGE_CLUSTER,
889 .procname = "page-cluster",
890 .data = &page_cluster,
891 .maxlen = sizeof(int),
892 .mode = 0644,
893 .proc_handler = &proc_dointvec,
896 .ctl_name = VM_DIRTY_BACKGROUND,
897 .procname = "dirty_background_ratio",
898 .data = &dirty_background_ratio,
899 .maxlen = sizeof(dirty_background_ratio),
900 .mode = 0644,
901 .proc_handler = &proc_dointvec_minmax,
902 .strategy = &sysctl_intvec,
903 .extra1 = &zero,
904 .extra2 = &one_hundred,
907 .ctl_name = VM_DIRTY_RATIO,
908 .procname = "dirty_ratio",
909 .data = &vm_dirty_ratio,
910 .maxlen = sizeof(vm_dirty_ratio),
911 .mode = 0644,
912 .proc_handler = &dirty_ratio_handler,
913 .strategy = &sysctl_intvec,
914 .extra1 = &zero,
915 .extra2 = &one_hundred,
918 .procname = "dirty_writeback_centisecs",
919 .data = &dirty_writeback_interval,
920 .maxlen = sizeof(dirty_writeback_interval),
921 .mode = 0644,
922 .proc_handler = &dirty_writeback_centisecs_handler,
925 .procname = "dirty_expire_centisecs",
926 .data = &dirty_expire_interval,
927 .maxlen = sizeof(dirty_expire_interval),
928 .mode = 0644,
929 .proc_handler = &proc_dointvec_userhz_jiffies,
932 .ctl_name = VM_NR_PDFLUSH_THREADS,
933 .procname = "nr_pdflush_threads",
934 .data = &nr_pdflush_threads,
935 .maxlen = sizeof nr_pdflush_threads,
936 .mode = 0444 /* read-only*/,
937 .proc_handler = &proc_dointvec,
940 .ctl_name = VM_SWAPPINESS,
941 .procname = "swappiness",
942 .data = &vm_swappiness,
943 .maxlen = sizeof(vm_swappiness),
944 .mode = 0644,
945 .proc_handler = &proc_dointvec_minmax,
946 .strategy = &sysctl_intvec,
947 .extra1 = &zero,
948 .extra2 = &one_hundred,
950 #ifdef CONFIG_HUGETLB_PAGE
952 .procname = "nr_hugepages",
953 .data = &max_huge_pages,
954 .maxlen = sizeof(unsigned long),
955 .mode = 0644,
956 .proc_handler = &hugetlb_sysctl_handler,
957 .extra1 = (void *)&hugetlb_zero,
958 .extra2 = (void *)&hugetlb_infinity,
961 .ctl_name = VM_HUGETLB_GROUP,
962 .procname = "hugetlb_shm_group",
963 .data = &sysctl_hugetlb_shm_group,
964 .maxlen = sizeof(gid_t),
965 .mode = 0644,
966 .proc_handler = &proc_dointvec,
969 .ctl_name = CTL_UNNUMBERED,
970 .procname = "hugepages_treat_as_movable",
971 .data = &hugepages_treat_as_movable,
972 .maxlen = sizeof(int),
973 .mode = 0644,
974 .proc_handler = &hugetlb_treat_movable_handler,
977 .ctl_name = CTL_UNNUMBERED,
978 .procname = "nr_overcommit_hugepages",
979 .data = &nr_overcommit_huge_pages,
980 .maxlen = sizeof(nr_overcommit_huge_pages),
981 .mode = 0644,
982 .proc_handler = &proc_doulongvec_minmax,
984 #endif
986 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
987 .procname = "lowmem_reserve_ratio",
988 .data = &sysctl_lowmem_reserve_ratio,
989 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
990 .mode = 0644,
991 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
992 .strategy = &sysctl_intvec,
995 .ctl_name = VM_DROP_PAGECACHE,
996 .procname = "drop_caches",
997 .data = &sysctl_drop_caches,
998 .maxlen = sizeof(int),
999 .mode = 0644,
1000 .proc_handler = drop_caches_sysctl_handler,
1001 .strategy = &sysctl_intvec,
1004 .ctl_name = VM_MIN_FREE_KBYTES,
1005 .procname = "min_free_kbytes",
1006 .data = &min_free_kbytes,
1007 .maxlen = sizeof(min_free_kbytes),
1008 .mode = 0644,
1009 .proc_handler = &min_free_kbytes_sysctl_handler,
1010 .strategy = &sysctl_intvec,
1011 .extra1 = &zero,
1014 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1015 .procname = "percpu_pagelist_fraction",
1016 .data = &percpu_pagelist_fraction,
1017 .maxlen = sizeof(percpu_pagelist_fraction),
1018 .mode = 0644,
1019 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1021 .extra1 = &min_percpu_pagelist_fract,
1023 #ifdef CONFIG_MMU
1025 .ctl_name = VM_MAX_MAP_COUNT,
1026 .procname = "max_map_count",
1027 .data = &sysctl_max_map_count,
1028 .maxlen = sizeof(sysctl_max_map_count),
1029 .mode = 0644,
1030 .proc_handler = &proc_dointvec
1032 #endif
1034 .ctl_name = VM_LAPTOP_MODE,
1035 .procname = "laptop_mode",
1036 .data = &laptop_mode,
1037 .maxlen = sizeof(laptop_mode),
1038 .mode = 0644,
1039 .proc_handler = &proc_dointvec_jiffies,
1040 .strategy = &sysctl_jiffies,
1043 .ctl_name = VM_BLOCK_DUMP,
1044 .procname = "block_dump",
1045 .data = &block_dump,
1046 .maxlen = sizeof(block_dump),
1047 .mode = 0644,
1048 .proc_handler = &proc_dointvec,
1049 .strategy = &sysctl_intvec,
1050 .extra1 = &zero,
1053 .ctl_name = VM_VFS_CACHE_PRESSURE,
1054 .procname = "vfs_cache_pressure",
1055 .data = &sysctl_vfs_cache_pressure,
1056 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1057 .mode = 0644,
1058 .proc_handler = &proc_dointvec,
1059 .strategy = &sysctl_intvec,
1060 .extra1 = &zero,
1062 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1064 .ctl_name = VM_LEGACY_VA_LAYOUT,
1065 .procname = "legacy_va_layout",
1066 .data = &sysctl_legacy_va_layout,
1067 .maxlen = sizeof(sysctl_legacy_va_layout),
1068 .mode = 0644,
1069 .proc_handler = &proc_dointvec,
1070 .strategy = &sysctl_intvec,
1071 .extra1 = &zero,
1073 #endif
1074 #ifdef CONFIG_NUMA
1076 .ctl_name = VM_ZONE_RECLAIM_MODE,
1077 .procname = "zone_reclaim_mode",
1078 .data = &zone_reclaim_mode,
1079 .maxlen = sizeof(zone_reclaim_mode),
1080 .mode = 0644,
1081 .proc_handler = &proc_dointvec,
1082 .strategy = &sysctl_intvec,
1083 .extra1 = &zero,
1086 .ctl_name = VM_MIN_UNMAPPED,
1087 .procname = "min_unmapped_ratio",
1088 .data = &sysctl_min_unmapped_ratio,
1089 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1090 .mode = 0644,
1091 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1092 .strategy = &sysctl_intvec,
1093 .extra1 = &zero,
1094 .extra2 = &one_hundred,
1097 .ctl_name = VM_MIN_SLAB,
1098 .procname = "min_slab_ratio",
1099 .data = &sysctl_min_slab_ratio,
1100 .maxlen = sizeof(sysctl_min_slab_ratio),
1101 .mode = 0644,
1102 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1103 .strategy = &sysctl_intvec,
1104 .extra1 = &zero,
1105 .extra2 = &one_hundred,
1107 #endif
1108 #ifdef CONFIG_SMP
1110 .ctl_name = CTL_UNNUMBERED,
1111 .procname = "stat_interval",
1112 .data = &sysctl_stat_interval,
1113 .maxlen = sizeof(sysctl_stat_interval),
1114 .mode = 0644,
1115 .proc_handler = &proc_dointvec_jiffies,
1116 .strategy = &sysctl_jiffies,
1118 #endif
1119 #ifdef CONFIG_SECURITY
1121 .ctl_name = CTL_UNNUMBERED,
1122 .procname = "mmap_min_addr",
1123 .data = &mmap_min_addr,
1124 .maxlen = sizeof(unsigned long),
1125 .mode = 0644,
1126 .proc_handler = &proc_doulongvec_minmax,
1128 #endif
1129 #ifdef CONFIG_NUMA
1131 .ctl_name = CTL_UNNUMBERED,
1132 .procname = "numa_zonelist_order",
1133 .data = &numa_zonelist_order,
1134 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1135 .mode = 0644,
1136 .proc_handler = &numa_zonelist_order_handler,
1137 .strategy = &sysctl_string,
1139 #endif
1140 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1141 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1143 .ctl_name = VM_VDSO_ENABLED,
1144 .procname = "vdso_enabled",
1145 .data = &vdso_enabled,
1146 .maxlen = sizeof(vdso_enabled),
1147 .mode = 0644,
1148 .proc_handler = &proc_dointvec,
1149 .strategy = &sysctl_intvec,
1150 .extra1 = &zero,
1152 #endif
1154 * NOTE: do not add new entries to this table unless you have read
1155 * Documentation/sysctl/ctl_unnumbered.txt
1157 { .ctl_name = 0 }
1160 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1161 static struct ctl_table binfmt_misc_table[] = {
1162 { .ctl_name = 0 }
1164 #endif
1166 static struct ctl_table fs_table[] = {
1168 .ctl_name = FS_NRINODE,
1169 .procname = "inode-nr",
1170 .data = &inodes_stat,
1171 .maxlen = 2*sizeof(int),
1172 .mode = 0444,
1173 .proc_handler = &proc_dointvec,
1176 .ctl_name = FS_STATINODE,
1177 .procname = "inode-state",
1178 .data = &inodes_stat,
1179 .maxlen = 7*sizeof(int),
1180 .mode = 0444,
1181 .proc_handler = &proc_dointvec,
1184 .procname = "file-nr",
1185 .data = &files_stat,
1186 .maxlen = 3*sizeof(int),
1187 .mode = 0444,
1188 .proc_handler = &proc_nr_files,
1191 .ctl_name = FS_MAXFILE,
1192 .procname = "file-max",
1193 .data = &files_stat.max_files,
1194 .maxlen = sizeof(int),
1195 .mode = 0644,
1196 .proc_handler = &proc_dointvec,
1199 .ctl_name = FS_DENTRY,
1200 .procname = "dentry-state",
1201 .data = &dentry_stat,
1202 .maxlen = 6*sizeof(int),
1203 .mode = 0444,
1204 .proc_handler = &proc_dointvec,
1207 .ctl_name = FS_OVERFLOWUID,
1208 .procname = "overflowuid",
1209 .data = &fs_overflowuid,
1210 .maxlen = sizeof(int),
1211 .mode = 0644,
1212 .proc_handler = &proc_dointvec_minmax,
1213 .strategy = &sysctl_intvec,
1214 .extra1 = &minolduid,
1215 .extra2 = &maxolduid,
1218 .ctl_name = FS_OVERFLOWGID,
1219 .procname = "overflowgid",
1220 .data = &fs_overflowgid,
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_LEASES,
1230 .procname = "leases-enable",
1231 .data = &leases_enable,
1232 .maxlen = sizeof(int),
1233 .mode = 0644,
1234 .proc_handler = &proc_dointvec,
1236 #ifdef CONFIG_DNOTIFY
1238 .ctl_name = FS_DIR_NOTIFY,
1239 .procname = "dir-notify-enable",
1240 .data = &dir_notify_enable,
1241 .maxlen = sizeof(int),
1242 .mode = 0644,
1243 .proc_handler = &proc_dointvec,
1245 #endif
1246 #ifdef CONFIG_MMU
1248 .ctl_name = FS_LEASE_TIME,
1249 .procname = "lease-break-time",
1250 .data = &lease_break_time,
1251 .maxlen = sizeof(int),
1252 .mode = 0644,
1253 .proc_handler = &proc_dointvec_minmax,
1254 .strategy = &sysctl_intvec,
1255 .extra1 = &zero,
1256 .extra2 = &two,
1259 .procname = "aio-nr",
1260 .data = &aio_nr,
1261 .maxlen = sizeof(aio_nr),
1262 .mode = 0444,
1263 .proc_handler = &proc_doulongvec_minmax,
1266 .procname = "aio-max-nr",
1267 .data = &aio_max_nr,
1268 .maxlen = sizeof(aio_max_nr),
1269 .mode = 0644,
1270 .proc_handler = &proc_doulongvec_minmax,
1272 #ifdef CONFIG_INOTIFY_USER
1274 .ctl_name = FS_INOTIFY,
1275 .procname = "inotify",
1276 .mode = 0555,
1277 .child = inotify_table,
1279 #endif
1280 #endif
1282 .ctl_name = KERN_SETUID_DUMPABLE,
1283 .procname = "suid_dumpable",
1284 .data = &suid_dumpable,
1285 .maxlen = sizeof(int),
1286 .mode = 0644,
1287 .proc_handler = &proc_dointvec,
1289 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1291 .ctl_name = CTL_UNNUMBERED,
1292 .procname = "binfmt_misc",
1293 .mode = 0555,
1294 .child = binfmt_misc_table,
1296 #endif
1298 * NOTE: do not add new entries to this table unless you have read
1299 * Documentation/sysctl/ctl_unnumbered.txt
1301 { .ctl_name = 0 }
1304 static struct ctl_table debug_table[] = {
1305 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1307 .ctl_name = CTL_UNNUMBERED,
1308 .procname = "exception-trace",
1309 .data = &show_unhandled_signals,
1310 .maxlen = sizeof(int),
1311 .mode = 0644,
1312 .proc_handler = proc_dointvec
1314 #endif
1315 { .ctl_name = 0 }
1318 static struct ctl_table dev_table[] = {
1319 { .ctl_name = 0 }
1322 static DEFINE_SPINLOCK(sysctl_lock);
1324 /* called under sysctl_lock */
1325 static int use_table(struct ctl_table_header *p)
1327 if (unlikely(p->unregistering))
1328 return 0;
1329 p->used++;
1330 return 1;
1333 /* called under sysctl_lock */
1334 static void unuse_table(struct ctl_table_header *p)
1336 if (!--p->used)
1337 if (unlikely(p->unregistering))
1338 complete(p->unregistering);
1341 /* called under sysctl_lock, will reacquire if has to wait */
1342 static void start_unregistering(struct ctl_table_header *p)
1345 * if p->used is 0, nobody will ever touch that entry again;
1346 * we'll eliminate all paths to it before dropping sysctl_lock
1348 if (unlikely(p->used)) {
1349 struct completion wait;
1350 init_completion(&wait);
1351 p->unregistering = &wait;
1352 spin_unlock(&sysctl_lock);
1353 wait_for_completion(&wait);
1354 spin_lock(&sysctl_lock);
1357 * do not remove from the list until nobody holds it; walking the
1358 * list in do_sysctl() relies on that.
1360 list_del_init(&p->ctl_entry);
1363 void sysctl_head_finish(struct ctl_table_header *head)
1365 if (!head)
1366 return;
1367 spin_lock(&sysctl_lock);
1368 unuse_table(head);
1369 spin_unlock(&sysctl_lock);
1372 static struct list_head *
1373 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1375 struct list_head *header_list;
1376 header_list = &root->header_list;
1377 if (root->lookup)
1378 header_list = root->lookup(root, namespaces);
1379 return header_list;
1382 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1383 struct ctl_table_header *prev)
1385 struct ctl_table_root *root;
1386 struct list_head *header_list;
1387 struct ctl_table_header *head;
1388 struct list_head *tmp;
1390 spin_lock(&sysctl_lock);
1391 if (prev) {
1392 head = prev;
1393 tmp = &prev->ctl_entry;
1394 unuse_table(prev);
1395 goto next;
1397 tmp = &root_table_header.ctl_entry;
1398 for (;;) {
1399 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1401 if (!use_table(head))
1402 goto next;
1403 spin_unlock(&sysctl_lock);
1404 return head;
1405 next:
1406 root = head->root;
1407 tmp = tmp->next;
1408 header_list = lookup_header_list(root, namespaces);
1409 if (tmp != header_list)
1410 continue;
1412 do {
1413 root = list_entry(root->root_list.next,
1414 struct ctl_table_root, root_list);
1415 if (root == &sysctl_table_root)
1416 goto out;
1417 header_list = lookup_header_list(root, namespaces);
1418 } while (list_empty(header_list));
1419 tmp = header_list->next;
1421 out:
1422 spin_unlock(&sysctl_lock);
1423 return NULL;
1426 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1428 return __sysctl_head_next(current->nsproxy, prev);
1431 void register_sysctl_root(struct ctl_table_root *root)
1433 spin_lock(&sysctl_lock);
1434 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1435 spin_unlock(&sysctl_lock);
1438 #ifdef CONFIG_SYSCTL_SYSCALL
1439 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1440 void __user *newval, size_t newlen)
1442 struct ctl_table_header *head;
1443 int error = -ENOTDIR;
1445 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1446 return -ENOTDIR;
1447 if (oldval) {
1448 int old_len;
1449 if (!oldlenp || get_user(old_len, oldlenp))
1450 return -EFAULT;
1453 for (head = sysctl_head_next(NULL); head;
1454 head = sysctl_head_next(head)) {
1455 error = parse_table(name, nlen, oldval, oldlenp,
1456 newval, newlen, head->ctl_table);
1457 if (error != -ENOTDIR) {
1458 sysctl_head_finish(head);
1459 break;
1462 return error;
1465 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1467 struct __sysctl_args tmp;
1468 int error;
1470 if (copy_from_user(&tmp, args, sizeof(tmp)))
1471 return -EFAULT;
1473 error = deprecated_sysctl_warning(&tmp);
1474 if (error)
1475 goto out;
1477 lock_kernel();
1478 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1479 tmp.newval, tmp.newlen);
1480 unlock_kernel();
1481 out:
1482 return error;
1484 #endif /* CONFIG_SYSCTL_SYSCALL */
1487 * sysctl_perm does NOT grant the superuser all rights automatically, because
1488 * some sysctl variables are readonly even to root.
1491 static int test_perm(int mode, int op)
1493 if (!current->euid)
1494 mode >>= 6;
1495 else if (in_egroup_p(0))
1496 mode >>= 3;
1497 if ((mode & op & 0007) == op)
1498 return 0;
1499 return -EACCES;
1502 int sysctl_perm(struct ctl_table *table, int op)
1504 int error;
1505 error = security_sysctl(table, op);
1506 if (error)
1507 return error;
1508 return test_perm(table->mode, op);
1511 #ifdef CONFIG_SYSCTL_SYSCALL
1512 static int parse_table(int __user *name, int nlen,
1513 void __user *oldval, size_t __user *oldlenp,
1514 void __user *newval, size_t newlen,
1515 struct ctl_table *table)
1517 int n;
1518 repeat:
1519 if (!nlen)
1520 return -ENOTDIR;
1521 if (get_user(n, name))
1522 return -EFAULT;
1523 for ( ; table->ctl_name || table->procname; table++) {
1524 if (!table->ctl_name)
1525 continue;
1526 if (n == table->ctl_name) {
1527 int error;
1528 if (table->child) {
1529 if (sysctl_perm(table, 001))
1530 return -EPERM;
1531 name++;
1532 nlen--;
1533 table = table->child;
1534 goto repeat;
1536 error = do_sysctl_strategy(table, name, nlen,
1537 oldval, oldlenp,
1538 newval, newlen);
1539 return error;
1542 return -ENOTDIR;
1545 /* Perform the actual read/write of a sysctl table entry. */
1546 int do_sysctl_strategy (struct ctl_table *table,
1547 int __user *name, int nlen,
1548 void __user *oldval, size_t __user *oldlenp,
1549 void __user *newval, size_t newlen)
1551 int op = 0, rc;
1553 if (oldval)
1554 op |= 004;
1555 if (newval)
1556 op |= 002;
1557 if (sysctl_perm(table, op))
1558 return -EPERM;
1560 if (table->strategy) {
1561 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1562 newval, newlen);
1563 if (rc < 0)
1564 return rc;
1565 if (rc > 0)
1566 return 0;
1569 /* If there is no strategy routine, or if the strategy returns
1570 * zero, proceed with automatic r/w */
1571 if (table->data && table->maxlen) {
1572 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1573 newval, newlen);
1574 if (rc < 0)
1575 return rc;
1577 return 0;
1579 #endif /* CONFIG_SYSCTL_SYSCALL */
1581 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1583 for (; table->ctl_name || table->procname; table++) {
1584 table->parent = parent;
1585 if (table->child)
1586 sysctl_set_parent(table, table->child);
1590 static __init int sysctl_init(void)
1592 int err;
1593 sysctl_set_parent(NULL, root_table);
1594 err = sysctl_check_table(current->nsproxy, root_table);
1595 return 0;
1598 core_initcall(sysctl_init);
1601 * __register_sysctl_paths - register a sysctl hierarchy
1602 * @root: List of sysctl headers to register on
1603 * @namespaces: Data to compute which lists of sysctl entries are visible
1604 * @path: The path to the directory the sysctl table is in.
1605 * @table: the top-level table structure
1607 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1608 * array. A completely 0 filled entry terminates the table.
1610 * The members of the &struct ctl_table structure are used as follows:
1612 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1613 * must be unique within that level of sysctl
1615 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1616 * enter a sysctl file
1618 * data - a pointer to data for use by proc_handler
1620 * maxlen - the maximum size in bytes of the data
1622 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1624 * child - a pointer to the child sysctl table if this entry is a directory, or
1625 * %NULL.
1627 * proc_handler - the text handler routine (described below)
1629 * strategy - the strategy routine (described below)
1631 * de - for internal use by the sysctl routines
1633 * extra1, extra2 - extra pointers usable by the proc handler routines
1635 * Leaf nodes in the sysctl tree will be represented by a single file
1636 * under /proc; non-leaf nodes will be represented by directories.
1638 * sysctl(2) can automatically manage read and write requests through
1639 * the sysctl table. The data and maxlen fields of the ctl_table
1640 * struct enable minimal validation of the values being written to be
1641 * performed, and the mode field allows minimal authentication.
1643 * More sophisticated management can be enabled by the provision of a
1644 * strategy routine with the table entry. This will be called before
1645 * any automatic read or write of the data is performed.
1647 * The strategy routine may return
1649 * < 0 - Error occurred (error is passed to user process)
1651 * 0 - OK - proceed with automatic read or write.
1653 * > 0 - OK - read or write has been done by the strategy routine, so
1654 * return immediately.
1656 * There must be a proc_handler routine for any terminal nodes
1657 * mirrored under /proc/sys (non-terminals are handled by a built-in
1658 * directory handler). Several default handlers are available to
1659 * cover common cases -
1661 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1662 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1663 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1665 * It is the handler's job to read the input buffer from user memory
1666 * and process it. The handler should return 0 on success.
1668 * This routine returns %NULL on a failure to register, and a pointer
1669 * to the table header on success.
1671 struct ctl_table_header *__register_sysctl_paths(
1672 struct ctl_table_root *root,
1673 struct nsproxy *namespaces,
1674 const struct ctl_path *path, struct ctl_table *table)
1676 struct list_head *header_list;
1677 struct ctl_table_header *header;
1678 struct ctl_table *new, **prevp;
1679 unsigned int n, npath;
1681 /* Count the path components */
1682 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1686 * For each path component, allocate a 2-element ctl_table array.
1687 * The first array element will be filled with the sysctl entry
1688 * for this, the second will be the sentinel (ctl_name == 0).
1690 * We allocate everything in one go so that we don't have to
1691 * worry about freeing additional memory in unregister_sysctl_table.
1693 header = kzalloc(sizeof(struct ctl_table_header) +
1694 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1695 if (!header)
1696 return NULL;
1698 new = (struct ctl_table *) (header + 1);
1700 /* Now connect the dots */
1701 prevp = &header->ctl_table;
1702 for (n = 0; n < npath; ++n, ++path) {
1703 /* Copy the procname */
1704 new->procname = path->procname;
1705 new->ctl_name = path->ctl_name;
1706 new->mode = 0555;
1708 *prevp = new;
1709 prevp = &new->child;
1711 new += 2;
1713 *prevp = table;
1714 header->ctl_table_arg = table;
1716 INIT_LIST_HEAD(&header->ctl_entry);
1717 header->used = 0;
1718 header->unregistering = NULL;
1719 header->root = root;
1720 sysctl_set_parent(NULL, header->ctl_table);
1721 if (sysctl_check_table(namespaces, header->ctl_table)) {
1722 kfree(header);
1723 return NULL;
1725 spin_lock(&sysctl_lock);
1726 header_list = lookup_header_list(root, namespaces);
1727 list_add_tail(&header->ctl_entry, header_list);
1728 spin_unlock(&sysctl_lock);
1730 return header;
1734 * register_sysctl_table_path - register a sysctl table hierarchy
1735 * @path: The path to the directory the sysctl table is in.
1736 * @table: the top-level table structure
1738 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1739 * array. A completely 0 filled entry terminates the table.
1741 * See __register_sysctl_paths for more details.
1743 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1744 struct ctl_table *table)
1746 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1747 path, table);
1751 * register_sysctl_table - register a sysctl table hierarchy
1752 * @table: the top-level table structure
1754 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1755 * array. A completely 0 filled entry terminates the table.
1757 * See register_sysctl_paths for more details.
1759 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1761 static const struct ctl_path null_path[] = { {} };
1763 return register_sysctl_paths(null_path, table);
1767 * unregister_sysctl_table - unregister a sysctl table hierarchy
1768 * @header: the header returned from register_sysctl_table
1770 * Unregisters the sysctl table and all children. proc entries may not
1771 * actually be removed until they are no longer used by anyone.
1773 void unregister_sysctl_table(struct ctl_table_header * header)
1775 might_sleep();
1777 if (header == NULL)
1778 return;
1780 spin_lock(&sysctl_lock);
1781 start_unregistering(header);
1782 spin_unlock(&sysctl_lock);
1783 kfree(header);
1786 #else /* !CONFIG_SYSCTL */
1787 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1789 return NULL;
1792 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1793 struct ctl_table *table)
1795 return NULL;
1798 void unregister_sysctl_table(struct ctl_table_header * table)
1802 #endif /* CONFIG_SYSCTL */
1805 * /proc/sys support
1808 #ifdef CONFIG_PROC_SYSCTL
1810 static int _proc_do_string(void* data, int maxlen, int write,
1811 struct file *filp, void __user *buffer,
1812 size_t *lenp, loff_t *ppos)
1814 size_t len;
1815 char __user *p;
1816 char c;
1818 if (!data || !maxlen || !*lenp) {
1819 *lenp = 0;
1820 return 0;
1823 if (write) {
1824 len = 0;
1825 p = buffer;
1826 while (len < *lenp) {
1827 if (get_user(c, p++))
1828 return -EFAULT;
1829 if (c == 0 || c == '\n')
1830 break;
1831 len++;
1833 if (len >= maxlen)
1834 len = maxlen-1;
1835 if(copy_from_user(data, buffer, len))
1836 return -EFAULT;
1837 ((char *) data)[len] = 0;
1838 *ppos += *lenp;
1839 } else {
1840 len = strlen(data);
1841 if (len > maxlen)
1842 len = maxlen;
1844 if (*ppos > len) {
1845 *lenp = 0;
1846 return 0;
1849 data += *ppos;
1850 len -= *ppos;
1852 if (len > *lenp)
1853 len = *lenp;
1854 if (len)
1855 if(copy_to_user(buffer, data, len))
1856 return -EFAULT;
1857 if (len < *lenp) {
1858 if(put_user('\n', ((char __user *) buffer) + len))
1859 return -EFAULT;
1860 len++;
1862 *lenp = len;
1863 *ppos += len;
1865 return 0;
1869 * proc_dostring - read a string sysctl
1870 * @table: the sysctl table
1871 * @write: %TRUE if this is a write to the sysctl file
1872 * @filp: the file structure
1873 * @buffer: the user buffer
1874 * @lenp: the size of the user buffer
1875 * @ppos: file position
1877 * Reads/writes a string from/to the user buffer. If the kernel
1878 * buffer provided is not large enough to hold the string, the
1879 * string is truncated. The copied string is %NULL-terminated.
1880 * If the string is being read by the user process, it is copied
1881 * and a newline '\n' is added. It is truncated if the buffer is
1882 * not large enough.
1884 * Returns 0 on success.
1886 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1887 void __user *buffer, size_t *lenp, loff_t *ppos)
1889 return _proc_do_string(table->data, table->maxlen, write, filp,
1890 buffer, lenp, ppos);
1894 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1895 int *valp,
1896 int write, void *data)
1898 if (write) {
1899 *valp = *negp ? -*lvalp : *lvalp;
1900 } else {
1901 int val = *valp;
1902 if (val < 0) {
1903 *negp = -1;
1904 *lvalp = (unsigned long)-val;
1905 } else {
1906 *negp = 0;
1907 *lvalp = (unsigned long)val;
1910 return 0;
1913 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1914 int write, struct file *filp, void __user *buffer,
1915 size_t *lenp, loff_t *ppos,
1916 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1917 int write, void *data),
1918 void *data)
1920 #define TMPBUFLEN 21
1921 int *i, vleft, first=1, neg, val;
1922 unsigned long lval;
1923 size_t left, len;
1925 char buf[TMPBUFLEN], *p;
1926 char __user *s = buffer;
1928 if (!tbl_data || !table->maxlen || !*lenp ||
1929 (*ppos && !write)) {
1930 *lenp = 0;
1931 return 0;
1934 i = (int *) tbl_data;
1935 vleft = table->maxlen / sizeof(*i);
1936 left = *lenp;
1938 if (!conv)
1939 conv = do_proc_dointvec_conv;
1941 for (; left && vleft--; i++, first=0) {
1942 if (write) {
1943 while (left) {
1944 char c;
1945 if (get_user(c, s))
1946 return -EFAULT;
1947 if (!isspace(c))
1948 break;
1949 left--;
1950 s++;
1952 if (!left)
1953 break;
1954 neg = 0;
1955 len = left;
1956 if (len > sizeof(buf) - 1)
1957 len = sizeof(buf) - 1;
1958 if (copy_from_user(buf, s, len))
1959 return -EFAULT;
1960 buf[len] = 0;
1961 p = buf;
1962 if (*p == '-' && left > 1) {
1963 neg = 1;
1964 p++;
1966 if (*p < '0' || *p > '9')
1967 break;
1969 lval = simple_strtoul(p, &p, 0);
1971 len = p-buf;
1972 if ((len < left) && *p && !isspace(*p))
1973 break;
1974 if (neg)
1975 val = -val;
1976 s += len;
1977 left -= len;
1979 if (conv(&neg, &lval, i, 1, data))
1980 break;
1981 } else {
1982 p = buf;
1983 if (!first)
1984 *p++ = '\t';
1986 if (conv(&neg, &lval, i, 0, data))
1987 break;
1989 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1990 len = strlen(buf);
1991 if (len > left)
1992 len = left;
1993 if(copy_to_user(s, buf, len))
1994 return -EFAULT;
1995 left -= len;
1996 s += len;
2000 if (!write && !first && left) {
2001 if(put_user('\n', s))
2002 return -EFAULT;
2003 left--, s++;
2005 if (write) {
2006 while (left) {
2007 char c;
2008 if (get_user(c, s++))
2009 return -EFAULT;
2010 if (!isspace(c))
2011 break;
2012 left--;
2015 if (write && first)
2016 return -EINVAL;
2017 *lenp -= left;
2018 *ppos += *lenp;
2019 return 0;
2020 #undef TMPBUFLEN
2023 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2024 void __user *buffer, size_t *lenp, loff_t *ppos,
2025 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2026 int write, void *data),
2027 void *data)
2029 return __do_proc_dointvec(table->data, table, write, filp,
2030 buffer, lenp, ppos, conv, data);
2034 * proc_dointvec - read a vector of integers
2035 * @table: the sysctl table
2036 * @write: %TRUE if this is a write to the sysctl file
2037 * @filp: the file structure
2038 * @buffer: the user buffer
2039 * @lenp: the size of the user buffer
2040 * @ppos: file position
2042 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2043 * values from/to the user buffer, treated as an ASCII string.
2045 * Returns 0 on success.
2047 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2048 void __user *buffer, size_t *lenp, loff_t *ppos)
2050 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2051 NULL,NULL);
2054 #define OP_SET 0
2055 #define OP_AND 1
2056 #define OP_OR 2
2058 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2059 int *valp,
2060 int write, void *data)
2062 int op = *(int *)data;
2063 if (write) {
2064 int val = *negp ? -*lvalp : *lvalp;
2065 switch(op) {
2066 case OP_SET: *valp = val; break;
2067 case OP_AND: *valp &= val; break;
2068 case OP_OR: *valp |= val; break;
2070 } else {
2071 int val = *valp;
2072 if (val < 0) {
2073 *negp = -1;
2074 *lvalp = (unsigned long)-val;
2075 } else {
2076 *negp = 0;
2077 *lvalp = (unsigned long)val;
2080 return 0;
2083 #ifdef CONFIG_SECURITY_CAPABILITIES
2085 * init may raise the set.
2088 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2089 void __user *buffer, size_t *lenp, loff_t *ppos)
2091 int op;
2093 if (write && !capable(CAP_SYS_MODULE)) {
2094 return -EPERM;
2097 op = is_global_init(current) ? OP_SET : OP_AND;
2098 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2099 do_proc_dointvec_bset_conv,&op);
2101 #endif /* def CONFIG_SECURITY_CAPABILITIES */
2104 * Taint values can only be increased
2106 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2107 void __user *buffer, size_t *lenp, loff_t *ppos)
2109 int op;
2111 if (write && !capable(CAP_SYS_ADMIN))
2112 return -EPERM;
2114 op = OP_OR;
2115 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2116 do_proc_dointvec_bset_conv,&op);
2119 struct do_proc_dointvec_minmax_conv_param {
2120 int *min;
2121 int *max;
2124 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2125 int *valp,
2126 int write, void *data)
2128 struct do_proc_dointvec_minmax_conv_param *param = data;
2129 if (write) {
2130 int val = *negp ? -*lvalp : *lvalp;
2131 if ((param->min && *param->min > val) ||
2132 (param->max && *param->max < val))
2133 return -EINVAL;
2134 *valp = val;
2135 } else {
2136 int val = *valp;
2137 if (val < 0) {
2138 *negp = -1;
2139 *lvalp = (unsigned long)-val;
2140 } else {
2141 *negp = 0;
2142 *lvalp = (unsigned long)val;
2145 return 0;
2149 * proc_dointvec_minmax - read a vector of integers with min/max values
2150 * @table: the sysctl table
2151 * @write: %TRUE if this is a write to the sysctl file
2152 * @filp: the file structure
2153 * @buffer: the user buffer
2154 * @lenp: the size of the user buffer
2155 * @ppos: file position
2157 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2158 * values from/to the user buffer, treated as an ASCII string.
2160 * This routine will ensure the values are within the range specified by
2161 * table->extra1 (min) and table->extra2 (max).
2163 * Returns 0 on success.
2165 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2166 void __user *buffer, size_t *lenp, loff_t *ppos)
2168 struct do_proc_dointvec_minmax_conv_param param = {
2169 .min = (int *) table->extra1,
2170 .max = (int *) table->extra2,
2172 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2173 do_proc_dointvec_minmax_conv, &param);
2176 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2177 struct file *filp,
2178 void __user *buffer,
2179 size_t *lenp, loff_t *ppos,
2180 unsigned long convmul,
2181 unsigned long convdiv)
2183 #define TMPBUFLEN 21
2184 unsigned long *i, *min, *max, val;
2185 int vleft, first=1, neg;
2186 size_t len, left;
2187 char buf[TMPBUFLEN], *p;
2188 char __user *s = buffer;
2190 if (!data || !table->maxlen || !*lenp ||
2191 (*ppos && !write)) {
2192 *lenp = 0;
2193 return 0;
2196 i = (unsigned long *) data;
2197 min = (unsigned long *) table->extra1;
2198 max = (unsigned long *) table->extra2;
2199 vleft = table->maxlen / sizeof(unsigned long);
2200 left = *lenp;
2202 for (; left && vleft--; i++, min++, max++, first=0) {
2203 if (write) {
2204 while (left) {
2205 char c;
2206 if (get_user(c, s))
2207 return -EFAULT;
2208 if (!isspace(c))
2209 break;
2210 left--;
2211 s++;
2213 if (!left)
2214 break;
2215 neg = 0;
2216 len = left;
2217 if (len > TMPBUFLEN-1)
2218 len = TMPBUFLEN-1;
2219 if (copy_from_user(buf, s, len))
2220 return -EFAULT;
2221 buf[len] = 0;
2222 p = buf;
2223 if (*p == '-' && left > 1) {
2224 neg = 1;
2225 p++;
2227 if (*p < '0' || *p > '9')
2228 break;
2229 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2230 len = p-buf;
2231 if ((len < left) && *p && !isspace(*p))
2232 break;
2233 if (neg)
2234 val = -val;
2235 s += len;
2236 left -= len;
2238 if(neg)
2239 continue;
2240 if ((min && val < *min) || (max && val > *max))
2241 continue;
2242 *i = val;
2243 } else {
2244 p = buf;
2245 if (!first)
2246 *p++ = '\t';
2247 sprintf(p, "%lu", convdiv * (*i) / convmul);
2248 len = strlen(buf);
2249 if (len > left)
2250 len = left;
2251 if(copy_to_user(s, buf, len))
2252 return -EFAULT;
2253 left -= len;
2254 s += len;
2258 if (!write && !first && left) {
2259 if(put_user('\n', s))
2260 return -EFAULT;
2261 left--, s++;
2263 if (write) {
2264 while (left) {
2265 char c;
2266 if (get_user(c, s++))
2267 return -EFAULT;
2268 if (!isspace(c))
2269 break;
2270 left--;
2273 if (write && first)
2274 return -EINVAL;
2275 *lenp -= left;
2276 *ppos += *lenp;
2277 return 0;
2278 #undef TMPBUFLEN
2281 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2282 struct file *filp,
2283 void __user *buffer,
2284 size_t *lenp, loff_t *ppos,
2285 unsigned long convmul,
2286 unsigned long convdiv)
2288 return __do_proc_doulongvec_minmax(table->data, table, write,
2289 filp, buffer, lenp, ppos, convmul, convdiv);
2293 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2294 * @table: the sysctl table
2295 * @write: %TRUE if this is a write to the sysctl file
2296 * @filp: the file structure
2297 * @buffer: the user buffer
2298 * @lenp: the size of the user buffer
2299 * @ppos: file position
2301 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2302 * values from/to the user buffer, treated as an ASCII string.
2304 * This routine will ensure the values are within the range specified by
2305 * table->extra1 (min) and table->extra2 (max).
2307 * Returns 0 on success.
2309 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2310 void __user *buffer, size_t *lenp, loff_t *ppos)
2312 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2316 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2317 * @table: the sysctl table
2318 * @write: %TRUE if this is a write to the sysctl file
2319 * @filp: the file structure
2320 * @buffer: the user buffer
2321 * @lenp: the size of the user buffer
2322 * @ppos: file position
2324 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2325 * values from/to the user buffer, treated as an ASCII string. The values
2326 * are treated as milliseconds, and converted to jiffies when they are stored.
2328 * This routine will ensure the values are within the range specified by
2329 * table->extra1 (min) and table->extra2 (max).
2331 * Returns 0 on success.
2333 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2334 struct file *filp,
2335 void __user *buffer,
2336 size_t *lenp, loff_t *ppos)
2338 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2339 lenp, ppos, HZ, 1000l);
2343 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2344 int *valp,
2345 int write, void *data)
2347 if (write) {
2348 if (*lvalp > LONG_MAX / HZ)
2349 return 1;
2350 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2351 } else {
2352 int val = *valp;
2353 unsigned long lval;
2354 if (val < 0) {
2355 *negp = -1;
2356 lval = (unsigned long)-val;
2357 } else {
2358 *negp = 0;
2359 lval = (unsigned long)val;
2361 *lvalp = lval / HZ;
2363 return 0;
2366 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2367 int *valp,
2368 int write, void *data)
2370 if (write) {
2371 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2372 return 1;
2373 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2374 } else {
2375 int val = *valp;
2376 unsigned long lval;
2377 if (val < 0) {
2378 *negp = -1;
2379 lval = (unsigned long)-val;
2380 } else {
2381 *negp = 0;
2382 lval = (unsigned long)val;
2384 *lvalp = jiffies_to_clock_t(lval);
2386 return 0;
2389 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2390 int *valp,
2391 int write, void *data)
2393 if (write) {
2394 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2395 } else {
2396 int val = *valp;
2397 unsigned long lval;
2398 if (val < 0) {
2399 *negp = -1;
2400 lval = (unsigned long)-val;
2401 } else {
2402 *negp = 0;
2403 lval = (unsigned long)val;
2405 *lvalp = jiffies_to_msecs(lval);
2407 return 0;
2411 * proc_dointvec_jiffies - read a vector of integers as seconds
2412 * @table: the sysctl table
2413 * @write: %TRUE if this is a write to the sysctl file
2414 * @filp: the file structure
2415 * @buffer: the user buffer
2416 * @lenp: the size of the user buffer
2417 * @ppos: file position
2419 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2420 * values from/to the user buffer, treated as an ASCII string.
2421 * The values read are assumed to be in seconds, and are converted into
2422 * jiffies.
2424 * Returns 0 on success.
2426 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2427 void __user *buffer, size_t *lenp, loff_t *ppos)
2429 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2430 do_proc_dointvec_jiffies_conv,NULL);
2434 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2435 * @table: the sysctl table
2436 * @write: %TRUE if this is a write to the sysctl file
2437 * @filp: the file structure
2438 * @buffer: the user buffer
2439 * @lenp: the size of the user buffer
2440 * @ppos: pointer to the file position
2442 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2443 * values from/to the user buffer, treated as an ASCII string.
2444 * The values read are assumed to be in 1/USER_HZ seconds, and
2445 * are converted into jiffies.
2447 * Returns 0 on success.
2449 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2450 void __user *buffer, size_t *lenp, loff_t *ppos)
2452 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2453 do_proc_dointvec_userhz_jiffies_conv,NULL);
2457 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2458 * @table: the sysctl table
2459 * @write: %TRUE if this is a write to the sysctl file
2460 * @filp: the file structure
2461 * @buffer: the user buffer
2462 * @lenp: the size of the user buffer
2463 * @ppos: file position
2464 * @ppos: the current position in the file
2466 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2467 * values from/to the user buffer, treated as an ASCII string.
2468 * The values read are assumed to be in 1/1000 seconds, and
2469 * are converted into jiffies.
2471 * Returns 0 on success.
2473 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2474 void __user *buffer, size_t *lenp, loff_t *ppos)
2476 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2477 do_proc_dointvec_ms_jiffies_conv, NULL);
2480 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2481 void __user *buffer, size_t *lenp, loff_t *ppos)
2483 struct pid *new_pid;
2484 pid_t tmp;
2485 int r;
2487 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
2489 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2490 lenp, ppos, NULL, NULL);
2491 if (r || !write)
2492 return r;
2494 new_pid = find_get_pid(tmp);
2495 if (!new_pid)
2496 return -ESRCH;
2498 put_pid(xchg(&cad_pid, new_pid));
2499 return 0;
2502 #else /* CONFIG_PROC_FS */
2504 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2505 void __user *buffer, size_t *lenp, loff_t *ppos)
2507 return -ENOSYS;
2510 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2511 void __user *buffer, size_t *lenp, loff_t *ppos)
2513 return -ENOSYS;
2516 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2517 void __user *buffer, size_t *lenp, loff_t *ppos)
2519 return -ENOSYS;
2522 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2523 void __user *buffer, size_t *lenp, loff_t *ppos)
2525 return -ENOSYS;
2528 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2529 void __user *buffer, size_t *lenp, loff_t *ppos)
2531 return -ENOSYS;
2534 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2535 void __user *buffer, size_t *lenp, loff_t *ppos)
2537 return -ENOSYS;
2540 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2541 void __user *buffer, size_t *lenp, loff_t *ppos)
2543 return -ENOSYS;
2546 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2547 void __user *buffer, size_t *lenp, loff_t *ppos)
2549 return -ENOSYS;
2552 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2553 struct file *filp,
2554 void __user *buffer,
2555 size_t *lenp, loff_t *ppos)
2557 return -ENOSYS;
2561 #endif /* CONFIG_PROC_FS */
2564 #ifdef CONFIG_SYSCTL_SYSCALL
2566 * General sysctl support routines
2569 /* The generic sysctl data routine (used if no strategy routine supplied) */
2570 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2571 void __user *oldval, size_t __user *oldlenp,
2572 void __user *newval, size_t newlen)
2574 size_t len;
2576 /* Get out of I don't have a variable */
2577 if (!table->data || !table->maxlen)
2578 return -ENOTDIR;
2580 if (oldval && oldlenp) {
2581 if (get_user(len, oldlenp))
2582 return -EFAULT;
2583 if (len) {
2584 if (len > table->maxlen)
2585 len = table->maxlen;
2586 if (copy_to_user(oldval, table->data, len))
2587 return -EFAULT;
2588 if (put_user(len, oldlenp))
2589 return -EFAULT;
2593 if (newval && newlen) {
2594 if (newlen > table->maxlen)
2595 newlen = table->maxlen;
2597 if (copy_from_user(table->data, newval, newlen))
2598 return -EFAULT;
2600 return 1;
2603 /* The generic string strategy routine: */
2604 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2605 void __user *oldval, size_t __user *oldlenp,
2606 void __user *newval, size_t newlen)
2608 if (!table->data || !table->maxlen)
2609 return -ENOTDIR;
2611 if (oldval && oldlenp) {
2612 size_t bufsize;
2613 if (get_user(bufsize, oldlenp))
2614 return -EFAULT;
2615 if (bufsize) {
2616 size_t len = strlen(table->data), copied;
2618 /* This shouldn't trigger for a well-formed sysctl */
2619 if (len > table->maxlen)
2620 len = table->maxlen;
2622 /* Copy up to a max of bufsize-1 bytes of the string */
2623 copied = (len >= bufsize) ? bufsize - 1 : len;
2625 if (copy_to_user(oldval, table->data, copied) ||
2626 put_user(0, (char __user *)(oldval + copied)))
2627 return -EFAULT;
2628 if (put_user(len, oldlenp))
2629 return -EFAULT;
2632 if (newval && newlen) {
2633 size_t len = newlen;
2634 if (len > table->maxlen)
2635 len = table->maxlen;
2636 if(copy_from_user(table->data, newval, len))
2637 return -EFAULT;
2638 if (len == table->maxlen)
2639 len--;
2640 ((char *) table->data)[len] = 0;
2642 return 1;
2646 * This function makes sure that all of the integers in the vector
2647 * are between the minimum and maximum values given in the arrays
2648 * table->extra1 and table->extra2, respectively.
2650 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2651 void __user *oldval, size_t __user *oldlenp,
2652 void __user *newval, size_t newlen)
2655 if (newval && newlen) {
2656 int __user *vec = (int __user *) newval;
2657 int *min = (int *) table->extra1;
2658 int *max = (int *) table->extra2;
2659 size_t length;
2660 int i;
2662 if (newlen % sizeof(int) != 0)
2663 return -EINVAL;
2665 if (!table->extra1 && !table->extra2)
2666 return 0;
2668 if (newlen > table->maxlen)
2669 newlen = table->maxlen;
2670 length = newlen / sizeof(int);
2672 for (i = 0; i < length; i++) {
2673 int value;
2674 if (get_user(value, vec + i))
2675 return -EFAULT;
2676 if (min && value < min[i])
2677 return -EINVAL;
2678 if (max && value > max[i])
2679 return -EINVAL;
2682 return 0;
2685 /* Strategy function to convert jiffies to seconds */
2686 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2687 void __user *oldval, size_t __user *oldlenp,
2688 void __user *newval, size_t newlen)
2690 if (oldval && oldlenp) {
2691 size_t olen;
2693 if (get_user(olen, oldlenp))
2694 return -EFAULT;
2695 if (olen) {
2696 int val;
2698 if (olen < sizeof(int))
2699 return -EINVAL;
2701 val = *(int *)(table->data) / HZ;
2702 if (put_user(val, (int __user *)oldval))
2703 return -EFAULT;
2704 if (put_user(sizeof(int), oldlenp))
2705 return -EFAULT;
2708 if (newval && newlen) {
2709 int new;
2710 if (newlen != sizeof(int))
2711 return -EINVAL;
2712 if (get_user(new, (int __user *)newval))
2713 return -EFAULT;
2714 *(int *)(table->data) = new*HZ;
2716 return 1;
2719 /* Strategy function to convert jiffies to seconds */
2720 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2721 void __user *oldval, size_t __user *oldlenp,
2722 void __user *newval, size_t newlen)
2724 if (oldval && oldlenp) {
2725 size_t olen;
2727 if (get_user(olen, oldlenp))
2728 return -EFAULT;
2729 if (olen) {
2730 int val;
2732 if (olen < sizeof(int))
2733 return -EINVAL;
2735 val = jiffies_to_msecs(*(int *)(table->data));
2736 if (put_user(val, (int __user *)oldval))
2737 return -EFAULT;
2738 if (put_user(sizeof(int), oldlenp))
2739 return -EFAULT;
2742 if (newval && newlen) {
2743 int new;
2744 if (newlen != sizeof(int))
2745 return -EINVAL;
2746 if (get_user(new, (int __user *)newval))
2747 return -EFAULT;
2748 *(int *)(table->data) = msecs_to_jiffies(new);
2750 return 1;
2755 #else /* CONFIG_SYSCTL_SYSCALL */
2758 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2760 struct __sysctl_args tmp;
2761 int error;
2763 if (copy_from_user(&tmp, args, sizeof(tmp)))
2764 return -EFAULT;
2766 error = deprecated_sysctl_warning(&tmp);
2768 /* If no error reading the parameters then just -ENOSYS ... */
2769 if (!error)
2770 error = -ENOSYS;
2772 return error;
2775 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2776 void __user *oldval, size_t __user *oldlenp,
2777 void __user *newval, size_t newlen)
2779 return -ENOSYS;
2782 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2783 void __user *oldval, size_t __user *oldlenp,
2784 void __user *newval, size_t newlen)
2786 return -ENOSYS;
2789 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2790 void __user *oldval, size_t __user *oldlenp,
2791 void __user *newval, size_t newlen)
2793 return -ENOSYS;
2796 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2797 void __user *oldval, size_t __user *oldlenp,
2798 void __user *newval, size_t newlen)
2800 return -ENOSYS;
2803 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2804 void __user *oldval, size_t __user *oldlenp,
2805 void __user *newval, size_t newlen)
2807 return -ENOSYS;
2810 #endif /* CONFIG_SYSCTL_SYSCALL */
2812 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2814 static int msg_count;
2815 int name[CTL_MAXNAME];
2816 int i;
2818 /* Check args->nlen. */
2819 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2820 return -ENOTDIR;
2822 /* Read in the sysctl name for better debug message logging */
2823 for (i = 0; i < args->nlen; i++)
2824 if (get_user(name[i], args->name + i))
2825 return -EFAULT;
2827 /* Ignore accesses to kernel.version */
2828 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2829 return 0;
2831 if (msg_count < 5) {
2832 msg_count++;
2833 printk(KERN_INFO
2834 "warning: process `%s' used the deprecated sysctl "
2835 "system call with ", current->comm);
2836 for (i = 0; i < args->nlen; i++)
2837 printk("%d.", name[i]);
2838 printk("\n");
2840 return 0;
2844 * No sense putting this after each symbol definition, twice,
2845 * exception granted :-)
2847 EXPORT_SYMBOL(proc_dointvec);
2848 EXPORT_SYMBOL(proc_dointvec_jiffies);
2849 EXPORT_SYMBOL(proc_dointvec_minmax);
2850 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2851 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2852 EXPORT_SYMBOL(proc_dostring);
2853 EXPORT_SYMBOL(proc_doulongvec_minmax);
2854 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2855 EXPORT_SYMBOL(register_sysctl_table);
2856 EXPORT_SYMBOL(register_sysctl_paths);
2857 EXPORT_SYMBOL(sysctl_intvec);
2858 EXPORT_SYMBOL(sysctl_jiffies);
2859 EXPORT_SYMBOL(sysctl_ms_jiffies);
2860 EXPORT_SYMBOL(sysctl_string);
2861 EXPORT_SYMBOL(sysctl_data);
2862 EXPORT_SYMBOL(unregister_sysctl_table);