Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / kernel / sysctl.c
blob32641d5daf862d92223e2ec8b8c201bf98905f25
1 /*
2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
31 #include <linux/fs.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/times.h>
42 #include <linux/limits.h>
43 #include <linux/dcache.h>
44 #include <linux/syscalls.h>
45 #include <linux/nfs_fs.h>
46 #include <linux/acpi.h>
47 #include <linux/reboot.h>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
52 #ifdef CONFIG_X86
53 #include <asm/nmi.h>
54 #include <asm/stacktrace.h>
55 #include <asm/io.h>
56 #endif
58 static int deprecated_sysctl_warning(struct __sysctl_args *args);
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
63 extern int C_A_D;
64 extern int print_fatal_signals;
65 extern int sysctl_overcommit_memory;
66 extern int sysctl_overcommit_ratio;
67 extern int sysctl_panic_on_oom;
68 extern int sysctl_oom_kill_allocating_task;
69 extern int sysctl_oom_dump_tasks;
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 pid_max_min, pid_max_max;
77 extern int sysctl_drop_caches;
78 extern int percpu_pagelist_fraction;
79 extern int compat_log;
80 extern int maps_protect;
81 extern int sysctl_stat_interval;
82 extern int latencytop_enabled;
84 /* Constants used for minimum and maximum */
85 #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
86 static int one = 1;
87 #endif
89 #ifdef CONFIG_DETECT_SOFTLOCKUP
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,
314 <<<<<<< HEAD:kernel/sysctl.c
315 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
317 .ctl_name = CTL_UNNUMBERED,
318 .procname = "sched_min_bal_int_shares",
319 .data = &sysctl_sched_min_bal_int_shares,
320 .maxlen = sizeof(unsigned int),
321 .mode = 0644,
322 .proc_handler = &proc_dointvec,
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "sched_max_bal_int_shares",
327 .data = &sysctl_sched_max_bal_int_shares,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
330 .proc_handler = &proc_dointvec,
332 #endif
333 =======
334 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:kernel/sysctl.c
335 #endif
337 .ctl_name = CTL_UNNUMBERED,
338 .procname = "sched_rt_period_us",
339 .data = &sysctl_sched_rt_period,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
345 .ctl_name = CTL_UNNUMBERED,
346 .procname = "sched_rt_runtime_us",
347 .data = &sysctl_sched_rt_runtime,
348 .maxlen = sizeof(int),
349 .mode = 0644,
350 .proc_handler = &proc_dointvec,
353 .ctl_name = CTL_UNNUMBERED,
354 .procname = "sched_compat_yield",
355 .data = &sysctl_sched_compat_yield,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
358 .proc_handler = &proc_dointvec,
360 #ifdef CONFIG_PROVE_LOCKING
362 .ctl_name = CTL_UNNUMBERED,
363 .procname = "prove_locking",
364 .data = &prove_locking,
365 .maxlen = sizeof(int),
366 .mode = 0644,
367 .proc_handler = &proc_dointvec,
369 #endif
370 #ifdef CONFIG_LOCK_STAT
372 .ctl_name = CTL_UNNUMBERED,
373 .procname = "lock_stat",
374 .data = &lock_stat,
375 .maxlen = sizeof(int),
376 .mode = 0644,
377 .proc_handler = &proc_dointvec,
379 #endif
381 .ctl_name = KERN_PANIC,
382 .procname = "panic",
383 .data = &panic_timeout,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = &proc_dointvec,
389 .ctl_name = KERN_CORE_USES_PID,
390 .procname = "core_uses_pid",
391 .data = &core_uses_pid,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = &proc_dointvec,
397 .ctl_name = KERN_CORE_PATTERN,
398 .procname = "core_pattern",
399 .data = core_pattern,
400 .maxlen = CORENAME_MAX_SIZE,
401 .mode = 0644,
402 .proc_handler = &proc_dostring,
403 .strategy = &sysctl_string,
405 #ifdef CONFIG_PROC_SYSCTL
407 .procname = "tainted",
408 .data = &tainted,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec_taint,
413 #endif
414 #ifdef CONFIG_LATENCYTOP
416 .procname = "latencytop",
417 .data = &latencytop_enabled,
418 .maxlen = sizeof(int),
419 .mode = 0644,
420 .proc_handler = &proc_dointvec,
422 #endif
423 #ifdef CONFIG_BLK_DEV_INITRD
425 .ctl_name = KERN_REALROOTDEV,
426 .procname = "real-root-dev",
427 .data = &real_root_dev,
428 .maxlen = sizeof(int),
429 .mode = 0644,
430 .proc_handler = &proc_dointvec,
432 #endif
434 .ctl_name = CTL_UNNUMBERED,
435 .procname = "print-fatal-signals",
436 .data = &print_fatal_signals,
437 .maxlen = sizeof(int),
438 .mode = 0644,
439 .proc_handler = &proc_dointvec,
441 #ifdef __sparc__
443 .ctl_name = KERN_SPARC_REBOOT,
444 .procname = "reboot-cmd",
445 .data = reboot_command,
446 .maxlen = 256,
447 .mode = 0644,
448 .proc_handler = &proc_dostring,
449 .strategy = &sysctl_string,
452 .ctl_name = KERN_SPARC_STOP_A,
453 .procname = "stop-a",
454 .data = &stop_a_enabled,
455 .maxlen = sizeof (int),
456 .mode = 0644,
457 .proc_handler = &proc_dointvec,
460 .ctl_name = KERN_SPARC_SCONS_PWROFF,
461 .procname = "scons-poweroff",
462 .data = &scons_pwroff,
463 .maxlen = sizeof (int),
464 .mode = 0644,
465 .proc_handler = &proc_dointvec,
467 #endif
468 #ifdef __hppa__
470 .ctl_name = KERN_HPPA_PWRSW,
471 .procname = "soft-power",
472 .data = &pwrsw_enabled,
473 .maxlen = sizeof (int),
474 .mode = 0644,
475 .proc_handler = &proc_dointvec,
478 .ctl_name = KERN_HPPA_UNALIGNED,
479 .procname = "unaligned-trap",
480 .data = &unaligned_enabled,
481 .maxlen = sizeof (int),
482 .mode = 0644,
483 .proc_handler = &proc_dointvec,
485 #endif
487 .ctl_name = KERN_CTLALTDEL,
488 .procname = "ctrl-alt-del",
489 .data = &C_A_D,
490 .maxlen = sizeof(int),
491 .mode = 0644,
492 .proc_handler = &proc_dointvec,
494 #ifdef CONFIG_KMOD
496 .ctl_name = KERN_MODPROBE,
497 .procname = "modprobe",
498 .data = &modprobe_path,
499 .maxlen = KMOD_PATH_LEN,
500 .mode = 0644,
501 .proc_handler = &proc_dostring,
502 .strategy = &sysctl_string,
504 #endif
505 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
507 .ctl_name = KERN_HOTPLUG,
508 .procname = "hotplug",
509 .data = &uevent_helper,
510 .maxlen = UEVENT_HELPER_PATH_LEN,
511 .mode = 0644,
512 .proc_handler = &proc_dostring,
513 .strategy = &sysctl_string,
515 #endif
516 #ifdef CONFIG_CHR_DEV_SG
518 .ctl_name = KERN_SG_BIG_BUFF,
519 .procname = "sg-big-buff",
520 .data = &sg_big_buff,
521 .maxlen = sizeof (int),
522 .mode = 0444,
523 .proc_handler = &proc_dointvec,
525 #endif
526 #ifdef CONFIG_BSD_PROCESS_ACCT
528 .ctl_name = KERN_ACCT,
529 .procname = "acct",
530 .data = &acct_parm,
531 .maxlen = 3*sizeof(int),
532 .mode = 0644,
533 .proc_handler = &proc_dointvec,
535 #endif
536 #ifdef CONFIG_MAGIC_SYSRQ
538 .ctl_name = KERN_SYSRQ,
539 .procname = "sysrq",
540 .data = &__sysrq_enabled,
541 .maxlen = sizeof (int),
542 .mode = 0644,
543 .proc_handler = &proc_dointvec,
545 #endif
546 #ifdef CONFIG_PROC_SYSCTL
548 .procname = "cad_pid",
549 .data = NULL,
550 .maxlen = sizeof (int),
551 .mode = 0600,
552 .proc_handler = &proc_do_cad_pid,
554 #endif
556 .ctl_name = KERN_MAX_THREADS,
557 .procname = "threads-max",
558 .data = &max_threads,
559 .maxlen = sizeof(int),
560 .mode = 0644,
561 .proc_handler = &proc_dointvec,
564 .ctl_name = KERN_RANDOM,
565 .procname = "random",
566 .mode = 0555,
567 .child = random_table,
570 .ctl_name = KERN_OVERFLOWUID,
571 .procname = "overflowuid",
572 .data = &overflowuid,
573 .maxlen = sizeof(int),
574 .mode = 0644,
575 .proc_handler = &proc_dointvec_minmax,
576 .strategy = &sysctl_intvec,
577 .extra1 = &minolduid,
578 .extra2 = &maxolduid,
581 .ctl_name = KERN_OVERFLOWGID,
582 .procname = "overflowgid",
583 .data = &overflowgid,
584 .maxlen = sizeof(int),
585 .mode = 0644,
586 .proc_handler = &proc_dointvec_minmax,
587 .strategy = &sysctl_intvec,
588 .extra1 = &minolduid,
589 .extra2 = &maxolduid,
591 #ifdef CONFIG_S390
592 #ifdef CONFIG_MATHEMU
594 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
595 .procname = "ieee_emulation_warnings",
596 .data = &sysctl_ieee_emulation_warnings,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = &proc_dointvec,
601 #endif
602 #ifdef CONFIG_NO_IDLE_HZ
604 .ctl_name = KERN_HZ_TIMER,
605 .procname = "hz_timer",
606 .data = &sysctl_hz_timer,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec,
611 #endif
613 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
614 .procname = "userprocess_debug",
615 .data = &sysctl_userprocess_debug,
616 .maxlen = sizeof(int),
617 .mode = 0644,
618 .proc_handler = &proc_dointvec,
620 #endif
622 .ctl_name = KERN_PIDMAX,
623 .procname = "pid_max",
624 .data = &pid_max,
625 .maxlen = sizeof (int),
626 .mode = 0644,
627 .proc_handler = &proc_dointvec_minmax,
628 .strategy = sysctl_intvec,
629 .extra1 = &pid_max_min,
630 .extra2 = &pid_max_max,
633 .ctl_name = KERN_PANIC_ON_OOPS,
634 .procname = "panic_on_oops",
635 .data = &panic_on_oops,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec,
640 #if defined CONFIG_PRINTK
642 .ctl_name = KERN_PRINTK,
643 .procname = "printk",
644 .data = &console_loglevel,
645 .maxlen = 4*sizeof(int),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec,
650 .ctl_name = KERN_PRINTK_RATELIMIT,
651 .procname = "printk_ratelimit",
652 .data = &printk_ratelimit_jiffies,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec_jiffies,
656 .strategy = &sysctl_jiffies,
659 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
660 .procname = "printk_ratelimit_burst",
661 .data = &printk_ratelimit_burst,
662 .maxlen = sizeof(int),
663 .mode = 0644,
664 .proc_handler = &proc_dointvec,
666 #endif
668 .ctl_name = KERN_NGROUPS_MAX,
669 .procname = "ngroups_max",
670 .data = &ngroups_max,
671 .maxlen = sizeof (int),
672 .mode = 0444,
673 .proc_handler = &proc_dointvec,
675 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
677 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
678 .procname = "unknown_nmi_panic",
679 .data = &unknown_nmi_panic,
680 .maxlen = sizeof (int),
681 .mode = 0644,
682 .proc_handler = &proc_dointvec,
685 .procname = "nmi_watchdog",
686 .data = &nmi_watchdog_enabled,
687 .maxlen = sizeof (int),
688 .mode = 0644,
689 .proc_handler = &proc_nmi_enabled,
691 #endif
692 #if defined(CONFIG_X86)
694 .ctl_name = KERN_PANIC_ON_NMI,
695 .procname = "panic_on_unrecovered_nmi",
696 .data = &panic_on_unrecovered_nmi,
697 .maxlen = sizeof(int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec,
702 .ctl_name = KERN_BOOTLOADER_TYPE,
703 .procname = "bootloader_type",
704 .data = &bootloader_type,
705 .maxlen = sizeof (int),
706 .mode = 0444,
707 .proc_handler = &proc_dointvec,
710 .ctl_name = CTL_UNNUMBERED,
711 .procname = "kstack_depth_to_print",
712 .data = &kstack_depth_to_print,
713 .maxlen = sizeof(int),
714 .mode = 0644,
715 .proc_handler = &proc_dointvec,
718 .ctl_name = CTL_UNNUMBERED,
719 .procname = "io_delay_type",
720 .data = &io_delay_type,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = &proc_dointvec,
725 #endif
726 #if defined(CONFIG_MMU)
728 .ctl_name = KERN_RANDOMIZE,
729 .procname = "randomize_va_space",
730 .data = &randomize_va_space,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = &proc_dointvec,
735 #endif
736 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
738 .ctl_name = KERN_SPIN_RETRY,
739 .procname = "spin_retry",
740 .data = &spin_retry,
741 .maxlen = sizeof (int),
742 .mode = 0644,
743 .proc_handler = &proc_dointvec,
745 #endif
746 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
748 .procname = "acpi_video_flags",
749 .data = &acpi_realmode_flags,
750 .maxlen = sizeof (unsigned long),
751 .mode = 0644,
752 .proc_handler = &proc_doulongvec_minmax,
754 #endif
755 #ifdef CONFIG_IA64
757 .ctl_name = KERN_IA64_UNALIGNED,
758 .procname = "ignore-unaligned-usertrap",
759 .data = &no_unaligned_warning,
760 .maxlen = sizeof (int),
761 .mode = 0644,
762 .proc_handler = &proc_dointvec,
764 #endif
765 #ifdef CONFIG_DETECT_SOFTLOCKUP
767 .ctl_name = CTL_UNNUMBERED,
768 .procname = "softlockup_thresh",
769 .data = &softlockup_thresh,
770 .maxlen = sizeof(unsigned long),
771 .mode = 0644,
772 .proc_handler = &proc_doulongvec_minmax,
773 .strategy = &sysctl_intvec,
774 .extra1 = &one,
775 .extra2 = &sixty,
778 .ctl_name = CTL_UNNUMBERED,
779 .procname = "hung_task_check_count",
780 .data = &sysctl_hung_task_check_count,
781 .maxlen = sizeof(unsigned long),
782 .mode = 0644,
783 .proc_handler = &proc_doulongvec_minmax,
784 .strategy = &sysctl_intvec,
787 .ctl_name = CTL_UNNUMBERED,
788 .procname = "hung_task_timeout_secs",
789 .data = &sysctl_hung_task_timeout_secs,
790 .maxlen = sizeof(unsigned long),
791 .mode = 0644,
792 .proc_handler = &proc_doulongvec_minmax,
793 .strategy = &sysctl_intvec,
796 .ctl_name = CTL_UNNUMBERED,
797 .procname = "hung_task_warnings",
798 .data = &sysctl_hung_task_warnings,
799 .maxlen = sizeof(unsigned long),
800 .mode = 0644,
801 .proc_handler = &proc_doulongvec_minmax,
802 .strategy = &sysctl_intvec,
804 #endif
805 #ifdef CONFIG_COMPAT
807 .ctl_name = KERN_COMPAT_LOG,
808 .procname = "compat-log",
809 .data = &compat_log,
810 .maxlen = sizeof (int),
811 .mode = 0644,
812 .proc_handler = &proc_dointvec,
814 #endif
815 #ifdef CONFIG_RT_MUTEXES
817 .ctl_name = KERN_MAX_LOCK_DEPTH,
818 .procname = "max_lock_depth",
819 .data = &max_lock_depth,
820 .maxlen = sizeof(int),
821 .mode = 0644,
822 .proc_handler = &proc_dointvec,
824 #endif
825 #ifdef CONFIG_PROC_FS
827 .ctl_name = CTL_UNNUMBERED,
828 .procname = "maps_protect",
829 .data = &maps_protect,
830 .maxlen = sizeof(int),
831 .mode = 0644,
832 .proc_handler = &proc_dointvec,
834 #endif
836 .ctl_name = CTL_UNNUMBERED,
837 .procname = "poweroff_cmd",
838 .data = &poweroff_cmd,
839 .maxlen = POWEROFF_CMD_PATH_LEN,
840 .mode = 0644,
841 .proc_handler = &proc_dostring,
842 .strategy = &sysctl_string,
845 * NOTE: do not add new entries to this table unless you have read
846 * Documentation/sysctl/ctl_unnumbered.txt
848 { .ctl_name = 0 }
851 static struct ctl_table vm_table[] = {
853 .ctl_name = VM_OVERCOMMIT_MEMORY,
854 .procname = "overcommit_memory",
855 .data = &sysctl_overcommit_memory,
856 .maxlen = sizeof(sysctl_overcommit_memory),
857 .mode = 0644,
858 .proc_handler = &proc_dointvec,
861 .ctl_name = VM_PANIC_ON_OOM,
862 .procname = "panic_on_oom",
863 .data = &sysctl_panic_on_oom,
864 .maxlen = sizeof(sysctl_panic_on_oom),
865 .mode = 0644,
866 .proc_handler = &proc_dointvec,
869 .ctl_name = CTL_UNNUMBERED,
870 .procname = "oom_kill_allocating_task",
871 .data = &sysctl_oom_kill_allocating_task,
872 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
873 .mode = 0644,
874 .proc_handler = &proc_dointvec,
877 .ctl_name = CTL_UNNUMBERED,
878 .procname = "oom_dump_tasks",
879 .data = &sysctl_oom_dump_tasks,
880 .maxlen = sizeof(sysctl_oom_dump_tasks),
881 .mode = 0644,
882 .proc_handler = &proc_dointvec,
885 .ctl_name = VM_OVERCOMMIT_RATIO,
886 .procname = "overcommit_ratio",
887 .data = &sysctl_overcommit_ratio,
888 .maxlen = sizeof(sysctl_overcommit_ratio),
889 .mode = 0644,
890 .proc_handler = &proc_dointvec,
893 .ctl_name = VM_PAGE_CLUSTER,
894 .procname = "page-cluster",
895 .data = &page_cluster,
896 .maxlen = sizeof(int),
897 .mode = 0644,
898 .proc_handler = &proc_dointvec,
901 .ctl_name = VM_DIRTY_BACKGROUND,
902 .procname = "dirty_background_ratio",
903 .data = &dirty_background_ratio,
904 .maxlen = sizeof(dirty_background_ratio),
905 .mode = 0644,
906 .proc_handler = &proc_dointvec_minmax,
907 .strategy = &sysctl_intvec,
908 .extra1 = &zero,
909 .extra2 = &one_hundred,
912 .ctl_name = VM_DIRTY_RATIO,
913 .procname = "dirty_ratio",
914 .data = &vm_dirty_ratio,
915 .maxlen = sizeof(vm_dirty_ratio),
916 .mode = 0644,
917 .proc_handler = &dirty_ratio_handler,
918 .strategy = &sysctl_intvec,
919 .extra1 = &zero,
920 .extra2 = &one_hundred,
923 .procname = "dirty_writeback_centisecs",
924 .data = &dirty_writeback_interval,
925 .maxlen = sizeof(dirty_writeback_interval),
926 .mode = 0644,
927 .proc_handler = &dirty_writeback_centisecs_handler,
930 .procname = "dirty_expire_centisecs",
931 .data = &dirty_expire_interval,
932 .maxlen = sizeof(dirty_expire_interval),
933 .mode = 0644,
934 .proc_handler = &proc_dointvec_userhz_jiffies,
937 .ctl_name = VM_NR_PDFLUSH_THREADS,
938 .procname = "nr_pdflush_threads",
939 .data = &nr_pdflush_threads,
940 .maxlen = sizeof nr_pdflush_threads,
941 .mode = 0444 /* read-only*/,
942 .proc_handler = &proc_dointvec,
945 .ctl_name = VM_SWAPPINESS,
946 .procname = "swappiness",
947 .data = &vm_swappiness,
948 .maxlen = sizeof(vm_swappiness),
949 .mode = 0644,
950 .proc_handler = &proc_dointvec_minmax,
951 .strategy = &sysctl_intvec,
952 .extra1 = &zero,
953 .extra2 = &one_hundred,
955 #ifdef CONFIG_HUGETLB_PAGE
957 .procname = "nr_hugepages",
958 .data = &max_huge_pages,
959 .maxlen = sizeof(unsigned long),
960 .mode = 0644,
961 .proc_handler = &hugetlb_sysctl_handler,
962 .extra1 = (void *)&hugetlb_zero,
963 .extra2 = (void *)&hugetlb_infinity,
966 .ctl_name = VM_HUGETLB_GROUP,
967 .procname = "hugetlb_shm_group",
968 .data = &sysctl_hugetlb_shm_group,
969 .maxlen = sizeof(gid_t),
970 .mode = 0644,
971 .proc_handler = &proc_dointvec,
974 .ctl_name = CTL_UNNUMBERED,
975 .procname = "hugepages_treat_as_movable",
976 .data = &hugepages_treat_as_movable,
977 .maxlen = sizeof(int),
978 .mode = 0644,
979 .proc_handler = &hugetlb_treat_movable_handler,
982 .ctl_name = CTL_UNNUMBERED,
983 .procname = "nr_overcommit_hugepages",
984 .data = &sysctl_overcommit_huge_pages,
985 .maxlen = sizeof(sysctl_overcommit_huge_pages),
986 .mode = 0644,
987 .proc_handler = &hugetlb_overcommit_handler,
989 #endif
991 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
992 .procname = "lowmem_reserve_ratio",
993 .data = &sysctl_lowmem_reserve_ratio,
994 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
995 .mode = 0644,
996 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
997 .strategy = &sysctl_intvec,
1000 .ctl_name = VM_DROP_PAGECACHE,
1001 .procname = "drop_caches",
1002 .data = &sysctl_drop_caches,
1003 .maxlen = sizeof(int),
1004 .mode = 0644,
1005 .proc_handler = drop_caches_sysctl_handler,
1006 .strategy = &sysctl_intvec,
1009 .ctl_name = VM_MIN_FREE_KBYTES,
1010 .procname = "min_free_kbytes",
1011 .data = &min_free_kbytes,
1012 .maxlen = sizeof(min_free_kbytes),
1013 .mode = 0644,
1014 .proc_handler = &min_free_kbytes_sysctl_handler,
1015 .strategy = &sysctl_intvec,
1016 .extra1 = &zero,
1019 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1020 .procname = "percpu_pagelist_fraction",
1021 .data = &percpu_pagelist_fraction,
1022 .maxlen = sizeof(percpu_pagelist_fraction),
1023 .mode = 0644,
1024 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1025 .strategy = &sysctl_intvec,
1026 .extra1 = &min_percpu_pagelist_fract,
1028 #ifdef CONFIG_MMU
1030 .ctl_name = VM_MAX_MAP_COUNT,
1031 .procname = "max_map_count",
1032 .data = &sysctl_max_map_count,
1033 .maxlen = sizeof(sysctl_max_map_count),
1034 .mode = 0644,
1035 .proc_handler = &proc_dointvec
1037 #endif
1039 .ctl_name = VM_LAPTOP_MODE,
1040 .procname = "laptop_mode",
1041 .data = &laptop_mode,
1042 .maxlen = sizeof(laptop_mode),
1043 .mode = 0644,
1044 .proc_handler = &proc_dointvec_jiffies,
1045 .strategy = &sysctl_jiffies,
1048 .ctl_name = VM_BLOCK_DUMP,
1049 .procname = "block_dump",
1050 .data = &block_dump,
1051 .maxlen = sizeof(block_dump),
1052 .mode = 0644,
1053 .proc_handler = &proc_dointvec,
1054 .strategy = &sysctl_intvec,
1055 .extra1 = &zero,
1058 .ctl_name = VM_VFS_CACHE_PRESSURE,
1059 .procname = "vfs_cache_pressure",
1060 .data = &sysctl_vfs_cache_pressure,
1061 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1062 .mode = 0644,
1063 .proc_handler = &proc_dointvec,
1064 .strategy = &sysctl_intvec,
1065 .extra1 = &zero,
1067 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1069 .ctl_name = VM_LEGACY_VA_LAYOUT,
1070 .procname = "legacy_va_layout",
1071 .data = &sysctl_legacy_va_layout,
1072 .maxlen = sizeof(sysctl_legacy_va_layout),
1073 .mode = 0644,
1074 .proc_handler = &proc_dointvec,
1075 .strategy = &sysctl_intvec,
1076 .extra1 = &zero,
1078 #endif
1079 #ifdef CONFIG_NUMA
1081 .ctl_name = VM_ZONE_RECLAIM_MODE,
1082 .procname = "zone_reclaim_mode",
1083 .data = &zone_reclaim_mode,
1084 .maxlen = sizeof(zone_reclaim_mode),
1085 .mode = 0644,
1086 .proc_handler = &proc_dointvec,
1087 .strategy = &sysctl_intvec,
1088 .extra1 = &zero,
1091 .ctl_name = VM_MIN_UNMAPPED,
1092 .procname = "min_unmapped_ratio",
1093 .data = &sysctl_min_unmapped_ratio,
1094 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1095 .mode = 0644,
1096 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1097 .strategy = &sysctl_intvec,
1098 .extra1 = &zero,
1099 .extra2 = &one_hundred,
1102 .ctl_name = VM_MIN_SLAB,
1103 .procname = "min_slab_ratio",
1104 .data = &sysctl_min_slab_ratio,
1105 .maxlen = sizeof(sysctl_min_slab_ratio),
1106 .mode = 0644,
1107 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1108 .strategy = &sysctl_intvec,
1109 .extra1 = &zero,
1110 .extra2 = &one_hundred,
1112 #endif
1113 #ifdef CONFIG_SMP
1115 .ctl_name = CTL_UNNUMBERED,
1116 .procname = "stat_interval",
1117 .data = &sysctl_stat_interval,
1118 .maxlen = sizeof(sysctl_stat_interval),
1119 .mode = 0644,
1120 .proc_handler = &proc_dointvec_jiffies,
1121 .strategy = &sysctl_jiffies,
1123 #endif
1124 #ifdef CONFIG_SECURITY
1126 .ctl_name = CTL_UNNUMBERED,
1127 .procname = "mmap_min_addr",
1128 .data = &mmap_min_addr,
1129 .maxlen = sizeof(unsigned long),
1130 .mode = 0644,
1131 .proc_handler = &proc_doulongvec_minmax,
1133 #endif
1134 #ifdef CONFIG_NUMA
1136 .ctl_name = CTL_UNNUMBERED,
1137 .procname = "numa_zonelist_order",
1138 .data = &numa_zonelist_order,
1139 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1140 .mode = 0644,
1141 .proc_handler = &numa_zonelist_order_handler,
1142 .strategy = &sysctl_string,
1144 #endif
1145 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1146 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1148 .ctl_name = VM_VDSO_ENABLED,
1149 .procname = "vdso_enabled",
1150 .data = &vdso_enabled,
1151 .maxlen = sizeof(vdso_enabled),
1152 .mode = 0644,
1153 .proc_handler = &proc_dointvec,
1154 .strategy = &sysctl_intvec,
1155 .extra1 = &zero,
1157 #endif
1158 #ifdef CONFIG_HIGHMEM
1160 .ctl_name = CTL_UNNUMBERED,
1161 .procname = "highmem_is_dirtyable",
1162 .data = &vm_highmem_is_dirtyable,
1163 .maxlen = sizeof(vm_highmem_is_dirtyable),
1164 .mode = 0644,
1165 .proc_handler = &proc_dointvec_minmax,
1166 .strategy = &sysctl_intvec,
1167 .extra1 = &zero,
1168 .extra2 = &one,
1170 #endif
1172 * NOTE: do not add new entries to this table unless you have read
1173 * Documentation/sysctl/ctl_unnumbered.txt
1175 { .ctl_name = 0 }
1178 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1179 static struct ctl_table binfmt_misc_table[] = {
1180 { .ctl_name = 0 }
1182 #endif
1184 static struct ctl_table fs_table[] = {
1186 .ctl_name = FS_NRINODE,
1187 .procname = "inode-nr",
1188 .data = &inodes_stat,
1189 .maxlen = 2*sizeof(int),
1190 .mode = 0444,
1191 .proc_handler = &proc_dointvec,
1194 .ctl_name = FS_STATINODE,
1195 .procname = "inode-state",
1196 .data = &inodes_stat,
1197 .maxlen = 7*sizeof(int),
1198 .mode = 0444,
1199 .proc_handler = &proc_dointvec,
1202 .procname = "file-nr",
1203 .data = &files_stat,
1204 .maxlen = 3*sizeof(int),
1205 .mode = 0444,
1206 .proc_handler = &proc_nr_files,
1209 .ctl_name = FS_MAXFILE,
1210 .procname = "file-max",
1211 .data = &files_stat.max_files,
1212 .maxlen = sizeof(int),
1213 .mode = 0644,
1214 .proc_handler = &proc_dointvec,
1217 .ctl_name = CTL_UNNUMBERED,
1218 .procname = "nr_open",
1219 .data = &sysctl_nr_open,
1220 .maxlen = sizeof(int),
1221 .mode = 0644,
1222 .proc_handler = &proc_dointvec,
1225 .ctl_name = FS_DENTRY,
1226 .procname = "dentry-state",
1227 .data = &dentry_stat,
1228 .maxlen = 6*sizeof(int),
1229 .mode = 0444,
1230 .proc_handler = &proc_dointvec,
1233 .ctl_name = FS_OVERFLOWUID,
1234 .procname = "overflowuid",
1235 .data = &fs_overflowuid,
1236 .maxlen = sizeof(int),
1237 .mode = 0644,
1238 .proc_handler = &proc_dointvec_minmax,
1239 .strategy = &sysctl_intvec,
1240 .extra1 = &minolduid,
1241 .extra2 = &maxolduid,
1244 .ctl_name = FS_OVERFLOWGID,
1245 .procname = "overflowgid",
1246 .data = &fs_overflowgid,
1247 .maxlen = sizeof(int),
1248 .mode = 0644,
1249 .proc_handler = &proc_dointvec_minmax,
1250 .strategy = &sysctl_intvec,
1251 .extra1 = &minolduid,
1252 .extra2 = &maxolduid,
1255 .ctl_name = FS_LEASES,
1256 .procname = "leases-enable",
1257 .data = &leases_enable,
1258 .maxlen = sizeof(int),
1259 .mode = 0644,
1260 .proc_handler = &proc_dointvec,
1262 #ifdef CONFIG_DNOTIFY
1264 .ctl_name = FS_DIR_NOTIFY,
1265 .procname = "dir-notify-enable",
1266 .data = &dir_notify_enable,
1267 .maxlen = sizeof(int),
1268 .mode = 0644,
1269 .proc_handler = &proc_dointvec,
1271 #endif
1272 #ifdef CONFIG_MMU
1274 .ctl_name = FS_LEASE_TIME,
1275 .procname = "lease-break-time",
1276 .data = &lease_break_time,
1277 .maxlen = sizeof(int),
1278 .mode = 0644,
1279 .proc_handler = &proc_dointvec_minmax,
1280 .strategy = &sysctl_intvec,
1281 .extra1 = &zero,
1282 .extra2 = &two,
1285 .procname = "aio-nr",
1286 .data = &aio_nr,
1287 .maxlen = sizeof(aio_nr),
1288 .mode = 0444,
1289 .proc_handler = &proc_doulongvec_minmax,
1292 .procname = "aio-max-nr",
1293 .data = &aio_max_nr,
1294 .maxlen = sizeof(aio_max_nr),
1295 .mode = 0644,
1296 .proc_handler = &proc_doulongvec_minmax,
1298 #ifdef CONFIG_INOTIFY_USER
1300 .ctl_name = FS_INOTIFY,
1301 .procname = "inotify",
1302 .mode = 0555,
1303 .child = inotify_table,
1305 #endif
1306 #endif
1308 .ctl_name = KERN_SETUID_DUMPABLE,
1309 .procname = "suid_dumpable",
1310 .data = &suid_dumpable,
1311 .maxlen = sizeof(int),
1312 .mode = 0644,
1313 .proc_handler = &proc_dointvec,
1315 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1317 .ctl_name = CTL_UNNUMBERED,
1318 .procname = "binfmt_misc",
1319 .mode = 0555,
1320 .child = binfmt_misc_table,
1322 #endif
1324 * NOTE: do not add new entries to this table unless you have read
1325 * Documentation/sysctl/ctl_unnumbered.txt
1327 { .ctl_name = 0 }
1330 static struct ctl_table debug_table[] = {
1331 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1333 .ctl_name = CTL_UNNUMBERED,
1334 .procname = "exception-trace",
1335 .data = &show_unhandled_signals,
1336 .maxlen = sizeof(int),
1337 .mode = 0644,
1338 .proc_handler = proc_dointvec
1340 #endif
1341 { .ctl_name = 0 }
1344 static struct ctl_table dev_table[] = {
1345 { .ctl_name = 0 }
1348 static DEFINE_SPINLOCK(sysctl_lock);
1350 /* called under sysctl_lock */
1351 static int use_table(struct ctl_table_header *p)
1353 if (unlikely(p->unregistering))
1354 return 0;
1355 p->used++;
1356 return 1;
1359 /* called under sysctl_lock */
1360 static void unuse_table(struct ctl_table_header *p)
1362 if (!--p->used)
1363 if (unlikely(p->unregistering))
1364 complete(p->unregistering);
1367 /* called under sysctl_lock, will reacquire if has to wait */
1368 static void start_unregistering(struct ctl_table_header *p)
1371 * if p->used is 0, nobody will ever touch that entry again;
1372 * we'll eliminate all paths to it before dropping sysctl_lock
1374 if (unlikely(p->used)) {
1375 struct completion wait;
1376 init_completion(&wait);
1377 p->unregistering = &wait;
1378 spin_unlock(&sysctl_lock);
1379 wait_for_completion(&wait);
1380 spin_lock(&sysctl_lock);
1383 * do not remove from the list until nobody holds it; walking the
1384 * list in do_sysctl() relies on that.
1386 list_del_init(&p->ctl_entry);
1389 void sysctl_head_finish(struct ctl_table_header *head)
1391 if (!head)
1392 return;
1393 spin_lock(&sysctl_lock);
1394 unuse_table(head);
1395 spin_unlock(&sysctl_lock);
1398 static struct list_head *
1399 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1401 struct list_head *header_list;
1402 header_list = &root->header_list;
1403 if (root->lookup)
1404 header_list = root->lookup(root, namespaces);
1405 return header_list;
1408 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1409 struct ctl_table_header *prev)
1411 struct ctl_table_root *root;
1412 struct list_head *header_list;
1413 struct ctl_table_header *head;
1414 struct list_head *tmp;
1416 spin_lock(&sysctl_lock);
1417 if (prev) {
1418 head = prev;
1419 tmp = &prev->ctl_entry;
1420 unuse_table(prev);
1421 goto next;
1423 tmp = &root_table_header.ctl_entry;
1424 for (;;) {
1425 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1427 if (!use_table(head))
1428 goto next;
1429 spin_unlock(&sysctl_lock);
1430 return head;
1431 next:
1432 root = head->root;
1433 tmp = tmp->next;
1434 header_list = lookup_header_list(root, namespaces);
1435 if (tmp != header_list)
1436 continue;
1438 do {
1439 root = list_entry(root->root_list.next,
1440 struct ctl_table_root, root_list);
1441 if (root == &sysctl_table_root)
1442 goto out;
1443 header_list = lookup_header_list(root, namespaces);
1444 } while (list_empty(header_list));
1445 tmp = header_list->next;
1447 out:
1448 spin_unlock(&sysctl_lock);
1449 return NULL;
1452 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1454 return __sysctl_head_next(current->nsproxy, prev);
1457 void register_sysctl_root(struct ctl_table_root *root)
1459 spin_lock(&sysctl_lock);
1460 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1461 spin_unlock(&sysctl_lock);
1464 #ifdef CONFIG_SYSCTL_SYSCALL
1465 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1466 void __user *newval, size_t newlen)
1468 struct ctl_table_header *head;
1469 int error = -ENOTDIR;
1471 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1472 return -ENOTDIR;
1473 if (oldval) {
1474 int old_len;
1475 if (!oldlenp || get_user(old_len, oldlenp))
1476 return -EFAULT;
1479 for (head = sysctl_head_next(NULL); head;
1480 head = sysctl_head_next(head)) {
1481 error = parse_table(name, nlen, oldval, oldlenp,
1482 newval, newlen, head->ctl_table);
1483 if (error != -ENOTDIR) {
1484 sysctl_head_finish(head);
1485 break;
1488 return error;
1491 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1493 struct __sysctl_args tmp;
1494 int error;
1496 if (copy_from_user(&tmp, args, sizeof(tmp)))
1497 return -EFAULT;
1499 error = deprecated_sysctl_warning(&tmp);
1500 if (error)
1501 goto out;
1503 lock_kernel();
1504 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1505 tmp.newval, tmp.newlen);
1506 unlock_kernel();
1507 out:
1508 return error;
1510 #endif /* CONFIG_SYSCTL_SYSCALL */
1513 * sysctl_perm does NOT grant the superuser all rights automatically, because
1514 * some sysctl variables are readonly even to root.
1517 static int test_perm(int mode, int op)
1519 if (!current->euid)
1520 mode >>= 6;
1521 else if (in_egroup_p(0))
1522 mode >>= 3;
1523 if ((mode & op & 0007) == op)
1524 return 0;
1525 return -EACCES;
1528 int sysctl_perm(struct ctl_table *table, int op)
1530 int error;
1531 error = security_sysctl(table, op);
1532 if (error)
1533 return error;
1534 return test_perm(table->mode, op);
1537 #ifdef CONFIG_SYSCTL_SYSCALL
1538 static int parse_table(int __user *name, int nlen,
1539 void __user *oldval, size_t __user *oldlenp,
1540 void __user *newval, size_t newlen,
1541 struct ctl_table *table)
1543 int n;
1544 repeat:
1545 if (!nlen)
1546 return -ENOTDIR;
1547 if (get_user(n, name))
1548 return -EFAULT;
1549 for ( ; table->ctl_name || table->procname; table++) {
1550 if (!table->ctl_name)
1551 continue;
1552 if (n == table->ctl_name) {
1553 int error;
1554 if (table->child) {
1555 if (sysctl_perm(table, 001))
1556 return -EPERM;
1557 name++;
1558 nlen--;
1559 table = table->child;
1560 goto repeat;
1562 error = do_sysctl_strategy(table, name, nlen,
1563 oldval, oldlenp,
1564 newval, newlen);
1565 return error;
1568 return -ENOTDIR;
1571 /* Perform the actual read/write of a sysctl table entry. */
1572 int do_sysctl_strategy (struct ctl_table *table,
1573 int __user *name, int nlen,
1574 void __user *oldval, size_t __user *oldlenp,
1575 void __user *newval, size_t newlen)
1577 int op = 0, rc;
1579 if (oldval)
1580 op |= 004;
1581 if (newval)
1582 op |= 002;
1583 if (sysctl_perm(table, op))
1584 return -EPERM;
1586 if (table->strategy) {
1587 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1588 newval, newlen);
1589 if (rc < 0)
1590 return rc;
1591 if (rc > 0)
1592 return 0;
1595 /* If there is no strategy routine, or if the strategy returns
1596 * zero, proceed with automatic r/w */
1597 if (table->data && table->maxlen) {
1598 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1599 newval, newlen);
1600 if (rc < 0)
1601 return rc;
1603 return 0;
1605 #endif /* CONFIG_SYSCTL_SYSCALL */
1607 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1609 for (; table->ctl_name || table->procname; table++) {
1610 table->parent = parent;
1611 if (table->child)
1612 sysctl_set_parent(table, table->child);
1616 static __init int sysctl_init(void)
1618 int err;
1619 sysctl_set_parent(NULL, root_table);
1620 err = sysctl_check_table(current->nsproxy, root_table);
1621 return 0;
1624 core_initcall(sysctl_init);
1627 * __register_sysctl_paths - register a sysctl hierarchy
1628 * @root: List of sysctl headers to register on
1629 * @namespaces: Data to compute which lists of sysctl entries are visible
1630 * @path: The path to the directory the sysctl table is in.
1631 * @table: the top-level table structure
1633 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1634 * array. A completely 0 filled entry terminates the table.
1636 * The members of the &struct ctl_table structure are used as follows:
1638 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1639 * must be unique within that level of sysctl
1641 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1642 * enter a sysctl file
1644 * data - a pointer to data for use by proc_handler
1646 * maxlen - the maximum size in bytes of the data
1648 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1650 * child - a pointer to the child sysctl table if this entry is a directory, or
1651 * %NULL.
1653 * proc_handler - the text handler routine (described below)
1655 * strategy - the strategy routine (described below)
1657 * de - for internal use by the sysctl routines
1659 * extra1, extra2 - extra pointers usable by the proc handler routines
1661 * Leaf nodes in the sysctl tree will be represented by a single file
1662 * under /proc; non-leaf nodes will be represented by directories.
1664 * sysctl(2) can automatically manage read and write requests through
1665 * the sysctl table. The data and maxlen fields of the ctl_table
1666 * struct enable minimal validation of the values being written to be
1667 * performed, and the mode field allows minimal authentication.
1669 * More sophisticated management can be enabled by the provision of a
1670 * strategy routine with the table entry. This will be called before
1671 * any automatic read or write of the data is performed.
1673 * The strategy routine may return
1675 * < 0 - Error occurred (error is passed to user process)
1677 * 0 - OK - proceed with automatic read or write.
1679 * > 0 - OK - read or write has been done by the strategy routine, so
1680 * return immediately.
1682 * There must be a proc_handler routine for any terminal nodes
1683 * mirrored under /proc/sys (non-terminals are handled by a built-in
1684 * directory handler). Several default handlers are available to
1685 * cover common cases -
1687 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1688 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1689 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1691 * It is the handler's job to read the input buffer from user memory
1692 * and process it. The handler should return 0 on success.
1694 * This routine returns %NULL on a failure to register, and a pointer
1695 * to the table header on success.
1697 struct ctl_table_header *__register_sysctl_paths(
1698 struct ctl_table_root *root,
1699 struct nsproxy *namespaces,
1700 const struct ctl_path *path, struct ctl_table *table)
1702 struct list_head *header_list;
1703 struct ctl_table_header *header;
1704 struct ctl_table *new, **prevp;
1705 unsigned int n, npath;
1707 /* Count the path components */
1708 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1712 * For each path component, allocate a 2-element ctl_table array.
1713 * The first array element will be filled with the sysctl entry
1714 * for this, the second will be the sentinel (ctl_name == 0).
1716 * We allocate everything in one go so that we don't have to
1717 * worry about freeing additional memory in unregister_sysctl_table.
1719 header = kzalloc(sizeof(struct ctl_table_header) +
1720 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1721 if (!header)
1722 return NULL;
1724 new = (struct ctl_table *) (header + 1);
1726 /* Now connect the dots */
1727 prevp = &header->ctl_table;
1728 for (n = 0; n < npath; ++n, ++path) {
1729 /* Copy the procname */
1730 new->procname = path->procname;
1731 new->ctl_name = path->ctl_name;
1732 new->mode = 0555;
1734 *prevp = new;
1735 prevp = &new->child;
1737 new += 2;
1739 *prevp = table;
1740 header->ctl_table_arg = table;
1742 INIT_LIST_HEAD(&header->ctl_entry);
1743 header->used = 0;
1744 header->unregistering = NULL;
1745 header->root = root;
1746 sysctl_set_parent(NULL, header->ctl_table);
1747 if (sysctl_check_table(namespaces, header->ctl_table)) {
1748 kfree(header);
1749 return NULL;
1751 spin_lock(&sysctl_lock);
1752 header_list = lookup_header_list(root, namespaces);
1753 list_add_tail(&header->ctl_entry, header_list);
1754 spin_unlock(&sysctl_lock);
1756 return header;
1760 * register_sysctl_table_path - register a sysctl table hierarchy
1761 * @path: The path to the directory the sysctl table is in.
1762 * @table: the top-level table structure
1764 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1765 * array. A completely 0 filled entry terminates the table.
1767 * See __register_sysctl_paths for more details.
1769 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1770 struct ctl_table *table)
1772 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1773 path, table);
1777 * register_sysctl_table - register a sysctl table hierarchy
1778 * @table: the top-level table structure
1780 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1781 * array. A completely 0 filled entry terminates the table.
1783 * See register_sysctl_paths for more details.
1785 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1787 static const struct ctl_path null_path[] = { {} };
1789 return register_sysctl_paths(null_path, table);
1793 * unregister_sysctl_table - unregister a sysctl table hierarchy
1794 * @header: the header returned from register_sysctl_table
1796 * Unregisters the sysctl table and all children. proc entries may not
1797 * actually be removed until they are no longer used by anyone.
1799 void unregister_sysctl_table(struct ctl_table_header * header)
1801 might_sleep();
1803 if (header == NULL)
1804 return;
1806 spin_lock(&sysctl_lock);
1807 start_unregistering(header);
1808 spin_unlock(&sysctl_lock);
1809 kfree(header);
1812 #else /* !CONFIG_SYSCTL */
1813 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1815 return NULL;
1818 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1819 struct ctl_table *table)
1821 return NULL;
1824 void unregister_sysctl_table(struct ctl_table_header * table)
1828 #endif /* CONFIG_SYSCTL */
1831 * /proc/sys support
1834 #ifdef CONFIG_PROC_SYSCTL
1836 static int _proc_do_string(void* data, int maxlen, int write,
1837 struct file *filp, void __user *buffer,
1838 size_t *lenp, loff_t *ppos)
1840 size_t len;
1841 char __user *p;
1842 char c;
1844 if (!data || !maxlen || !*lenp) {
1845 *lenp = 0;
1846 return 0;
1849 if (write) {
1850 len = 0;
1851 p = buffer;
1852 while (len < *lenp) {
1853 if (get_user(c, p++))
1854 return -EFAULT;
1855 if (c == 0 || c == '\n')
1856 break;
1857 len++;
1859 if (len >= maxlen)
1860 len = maxlen-1;
1861 if(copy_from_user(data, buffer, len))
1862 return -EFAULT;
1863 ((char *) data)[len] = 0;
1864 *ppos += *lenp;
1865 } else {
1866 len = strlen(data);
1867 if (len > maxlen)
1868 len = maxlen;
1870 if (*ppos > len) {
1871 *lenp = 0;
1872 return 0;
1875 data += *ppos;
1876 len -= *ppos;
1878 if (len > *lenp)
1879 len = *lenp;
1880 if (len)
1881 if(copy_to_user(buffer, data, len))
1882 return -EFAULT;
1883 if (len < *lenp) {
1884 if(put_user('\n', ((char __user *) buffer) + len))
1885 return -EFAULT;
1886 len++;
1888 *lenp = len;
1889 *ppos += len;
1891 return 0;
1895 * proc_dostring - read a string sysctl
1896 * @table: the sysctl table
1897 * @write: %TRUE if this is a write to the sysctl file
1898 * @filp: the file structure
1899 * @buffer: the user buffer
1900 * @lenp: the size of the user buffer
1901 * @ppos: file position
1903 * Reads/writes a string from/to the user buffer. If the kernel
1904 * buffer provided is not large enough to hold the string, the
1905 * string is truncated. The copied string is %NULL-terminated.
1906 * If the string is being read by the user process, it is copied
1907 * and a newline '\n' is added. It is truncated if the buffer is
1908 * not large enough.
1910 * Returns 0 on success.
1912 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1913 void __user *buffer, size_t *lenp, loff_t *ppos)
1915 return _proc_do_string(table->data, table->maxlen, write, filp,
1916 buffer, lenp, ppos);
1920 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1921 int *valp,
1922 int write, void *data)
1924 if (write) {
1925 *valp = *negp ? -*lvalp : *lvalp;
1926 } else {
1927 int val = *valp;
1928 if (val < 0) {
1929 *negp = -1;
1930 *lvalp = (unsigned long)-val;
1931 } else {
1932 *negp = 0;
1933 *lvalp = (unsigned long)val;
1936 return 0;
1939 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1940 int write, struct file *filp, void __user *buffer,
1941 size_t *lenp, loff_t *ppos,
1942 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1943 int write, void *data),
1944 void *data)
1946 #define TMPBUFLEN 21
1947 int *i, vleft, first=1, neg, val;
1948 unsigned long lval;
1949 size_t left, len;
1951 char buf[TMPBUFLEN], *p;
1952 char __user *s = buffer;
1954 if (!tbl_data || !table->maxlen || !*lenp ||
1955 (*ppos && !write)) {
1956 *lenp = 0;
1957 return 0;
1960 i = (int *) tbl_data;
1961 vleft = table->maxlen / sizeof(*i);
1962 left = *lenp;
1964 if (!conv)
1965 conv = do_proc_dointvec_conv;
1967 for (; left && vleft--; i++, first=0) {
1968 if (write) {
1969 while (left) {
1970 char c;
1971 if (get_user(c, s))
1972 return -EFAULT;
1973 if (!isspace(c))
1974 break;
1975 left--;
1976 s++;
1978 if (!left)
1979 break;
1980 neg = 0;
1981 len = left;
1982 if (len > sizeof(buf) - 1)
1983 len = sizeof(buf) - 1;
1984 if (copy_from_user(buf, s, len))
1985 return -EFAULT;
1986 buf[len] = 0;
1987 p = buf;
1988 if (*p == '-' && left > 1) {
1989 neg = 1;
1990 p++;
1992 if (*p < '0' || *p > '9')
1993 break;
1995 lval = simple_strtoul(p, &p, 0);
1997 len = p-buf;
1998 if ((len < left) && *p && !isspace(*p))
1999 break;
2000 if (neg)
2001 val = -val;
2002 s += len;
2003 left -= len;
2005 if (conv(&neg, &lval, i, 1, data))
2006 break;
2007 } else {
2008 p = buf;
2009 if (!first)
2010 *p++ = '\t';
2012 if (conv(&neg, &lval, i, 0, data))
2013 break;
2015 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2016 len = strlen(buf);
2017 if (len > left)
2018 len = left;
2019 if(copy_to_user(s, buf, len))
2020 return -EFAULT;
2021 left -= len;
2022 s += len;
2026 if (!write && !first && left) {
2027 if(put_user('\n', s))
2028 return -EFAULT;
2029 left--, s++;
2031 if (write) {
2032 while (left) {
2033 char c;
2034 if (get_user(c, s++))
2035 return -EFAULT;
2036 if (!isspace(c))
2037 break;
2038 left--;
2041 if (write && first)
2042 return -EINVAL;
2043 *lenp -= left;
2044 *ppos += *lenp;
2045 return 0;
2046 #undef TMPBUFLEN
2049 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2050 void __user *buffer, size_t *lenp, loff_t *ppos,
2051 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2052 int write, void *data),
2053 void *data)
2055 return __do_proc_dointvec(table->data, table, write, filp,
2056 buffer, lenp, ppos, conv, data);
2060 * proc_dointvec - read a vector of integers
2061 * @table: the sysctl table
2062 * @write: %TRUE if this is a write to the sysctl file
2063 * @filp: the file structure
2064 * @buffer: the user buffer
2065 * @lenp: the size of the user buffer
2066 * @ppos: file position
2068 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2069 * values from/to the user buffer, treated as an ASCII string.
2071 * Returns 0 on success.
2073 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2074 void __user *buffer, size_t *lenp, loff_t *ppos)
2076 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2077 NULL,NULL);
2080 #define OP_SET 0
2081 #define OP_AND 1
2082 #define OP_OR 2
2084 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2085 int *valp,
2086 int write, void *data)
2088 int op = *(int *)data;
2089 if (write) {
2090 int val = *negp ? -*lvalp : *lvalp;
2091 switch(op) {
2092 case OP_SET: *valp = val; break;
2093 case OP_AND: *valp &= val; break;
2094 case OP_OR: *valp |= val; break;
2096 } else {
2097 int val = *valp;
2098 if (val < 0) {
2099 *negp = -1;
2100 *lvalp = (unsigned long)-val;
2101 } else {
2102 *negp = 0;
2103 *lvalp = (unsigned long)val;
2106 return 0;
2110 * Taint values can only be increased
2112 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2113 void __user *buffer, size_t *lenp, loff_t *ppos)
2115 int op;
2117 if (write && !capable(CAP_SYS_ADMIN))
2118 return -EPERM;
2120 op = OP_OR;
2121 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2122 do_proc_dointvec_bset_conv,&op);
2125 struct do_proc_dointvec_minmax_conv_param {
2126 int *min;
2127 int *max;
2130 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2131 int *valp,
2132 int write, void *data)
2134 struct do_proc_dointvec_minmax_conv_param *param = data;
2135 if (write) {
2136 int val = *negp ? -*lvalp : *lvalp;
2137 if ((param->min && *param->min > val) ||
2138 (param->max && *param->max < val))
2139 return -EINVAL;
2140 *valp = val;
2141 } else {
2142 int val = *valp;
2143 if (val < 0) {
2144 *negp = -1;
2145 *lvalp = (unsigned long)-val;
2146 } else {
2147 *negp = 0;
2148 *lvalp = (unsigned long)val;
2151 return 0;
2155 * proc_dointvec_minmax - read a vector of integers with min/max values
2156 * @table: the sysctl table
2157 * @write: %TRUE if this is a write to the sysctl file
2158 * @filp: the file structure
2159 * @buffer: the user buffer
2160 * @lenp: the size of the user buffer
2161 * @ppos: file position
2163 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2164 * values from/to the user buffer, treated as an ASCII string.
2166 * This routine will ensure the values are within the range specified by
2167 * table->extra1 (min) and table->extra2 (max).
2169 * Returns 0 on success.
2171 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2172 void __user *buffer, size_t *lenp, loff_t *ppos)
2174 struct do_proc_dointvec_minmax_conv_param param = {
2175 .min = (int *) table->extra1,
2176 .max = (int *) table->extra2,
2178 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2179 do_proc_dointvec_minmax_conv, &param);
2182 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2183 struct file *filp,
2184 void __user *buffer,
2185 size_t *lenp, loff_t *ppos,
2186 unsigned long convmul,
2187 unsigned long convdiv)
2189 #define TMPBUFLEN 21
2190 unsigned long *i, *min, *max, val;
2191 int vleft, first=1, neg;
2192 size_t len, left;
2193 char buf[TMPBUFLEN], *p;
2194 char __user *s = buffer;
2196 if (!data || !table->maxlen || !*lenp ||
2197 (*ppos && !write)) {
2198 *lenp = 0;
2199 return 0;
2202 i = (unsigned long *) data;
2203 min = (unsigned long *) table->extra1;
2204 max = (unsigned long *) table->extra2;
2205 vleft = table->maxlen / sizeof(unsigned long);
2206 left = *lenp;
2208 for (; left && vleft--; i++, min++, max++, first=0) {
2209 if (write) {
2210 while (left) {
2211 char c;
2212 if (get_user(c, s))
2213 return -EFAULT;
2214 if (!isspace(c))
2215 break;
2216 left--;
2217 s++;
2219 if (!left)
2220 break;
2221 neg = 0;
2222 len = left;
2223 if (len > TMPBUFLEN-1)
2224 len = TMPBUFLEN-1;
2225 if (copy_from_user(buf, s, len))
2226 return -EFAULT;
2227 buf[len] = 0;
2228 p = buf;
2229 if (*p == '-' && left > 1) {
2230 neg = 1;
2231 p++;
2233 if (*p < '0' || *p > '9')
2234 break;
2235 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2236 len = p-buf;
2237 if ((len < left) && *p && !isspace(*p))
2238 break;
2239 if (neg)
2240 val = -val;
2241 s += len;
2242 left -= len;
2244 if(neg)
2245 continue;
2246 if ((min && val < *min) || (max && val > *max))
2247 continue;
2248 *i = val;
2249 } else {
2250 p = buf;
2251 if (!first)
2252 *p++ = '\t';
2253 sprintf(p, "%lu", convdiv * (*i) / convmul);
2254 len = strlen(buf);
2255 if (len > left)
2256 len = left;
2257 if(copy_to_user(s, buf, len))
2258 return -EFAULT;
2259 left -= len;
2260 s += len;
2264 if (!write && !first && left) {
2265 if(put_user('\n', s))
2266 return -EFAULT;
2267 left--, s++;
2269 if (write) {
2270 while (left) {
2271 char c;
2272 if (get_user(c, s++))
2273 return -EFAULT;
2274 if (!isspace(c))
2275 break;
2276 left--;
2279 if (write && first)
2280 return -EINVAL;
2281 *lenp -= left;
2282 *ppos += *lenp;
2283 return 0;
2284 #undef TMPBUFLEN
2287 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2288 struct file *filp,
2289 void __user *buffer,
2290 size_t *lenp, loff_t *ppos,
2291 unsigned long convmul,
2292 unsigned long convdiv)
2294 return __do_proc_doulongvec_minmax(table->data, table, write,
2295 filp, buffer, lenp, ppos, convmul, convdiv);
2299 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2300 * @table: the sysctl table
2301 * @write: %TRUE if this is a write to the sysctl file
2302 * @filp: the file structure
2303 * @buffer: the user buffer
2304 * @lenp: the size of the user buffer
2305 * @ppos: file position
2307 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2308 * values from/to the user buffer, treated as an ASCII string.
2310 * This routine will ensure the values are within the range specified by
2311 * table->extra1 (min) and table->extra2 (max).
2313 * Returns 0 on success.
2315 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2316 void __user *buffer, size_t *lenp, loff_t *ppos)
2318 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2322 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2323 * @table: the sysctl table
2324 * @write: %TRUE if this is a write to the sysctl file
2325 * @filp: the file structure
2326 * @buffer: the user buffer
2327 * @lenp: the size of the user buffer
2328 * @ppos: file position
2330 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2331 * values from/to the user buffer, treated as an ASCII string. The values
2332 * are treated as milliseconds, and converted to jiffies when they are stored.
2334 * This routine will ensure the values are within the range specified by
2335 * table->extra1 (min) and table->extra2 (max).
2337 * Returns 0 on success.
2339 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2340 struct file *filp,
2341 void __user *buffer,
2342 size_t *lenp, loff_t *ppos)
2344 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2345 lenp, ppos, HZ, 1000l);
2349 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2350 int *valp,
2351 int write, void *data)
2353 if (write) {
2354 if (*lvalp > LONG_MAX / HZ)
2355 return 1;
2356 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2357 } else {
2358 int val = *valp;
2359 unsigned long lval;
2360 if (val < 0) {
2361 *negp = -1;
2362 lval = (unsigned long)-val;
2363 } else {
2364 *negp = 0;
2365 lval = (unsigned long)val;
2367 *lvalp = lval / HZ;
2369 return 0;
2372 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2373 int *valp,
2374 int write, void *data)
2376 if (write) {
2377 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2378 return 1;
2379 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2380 } else {
2381 int val = *valp;
2382 unsigned long lval;
2383 if (val < 0) {
2384 *negp = -1;
2385 lval = (unsigned long)-val;
2386 } else {
2387 *negp = 0;
2388 lval = (unsigned long)val;
2390 *lvalp = jiffies_to_clock_t(lval);
2392 return 0;
2395 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2396 int *valp,
2397 int write, void *data)
2399 if (write) {
2400 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2401 } else {
2402 int val = *valp;
2403 unsigned long lval;
2404 if (val < 0) {
2405 *negp = -1;
2406 lval = (unsigned long)-val;
2407 } else {
2408 *negp = 0;
2409 lval = (unsigned long)val;
2411 *lvalp = jiffies_to_msecs(lval);
2413 return 0;
2417 * proc_dointvec_jiffies - read a vector of integers as seconds
2418 * @table: the sysctl table
2419 * @write: %TRUE if this is a write to the sysctl file
2420 * @filp: the file structure
2421 * @buffer: the user buffer
2422 * @lenp: the size of the user buffer
2423 * @ppos: file position
2425 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2426 * values from/to the user buffer, treated as an ASCII string.
2427 * The values read are assumed to be in seconds, and are converted into
2428 * jiffies.
2430 * Returns 0 on success.
2432 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2433 void __user *buffer, size_t *lenp, loff_t *ppos)
2435 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2436 do_proc_dointvec_jiffies_conv,NULL);
2440 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2441 * @table: the sysctl table
2442 * @write: %TRUE if this is a write to the sysctl file
2443 * @filp: the file structure
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: pointer to the file position
2448 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2449 * values from/to the user buffer, treated as an ASCII string.
2450 * The values read are assumed to be in 1/USER_HZ seconds, and
2451 * are converted into jiffies.
2453 * Returns 0 on success.
2455 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2456 void __user *buffer, size_t *lenp, loff_t *ppos)
2458 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2459 do_proc_dointvec_userhz_jiffies_conv,NULL);
2463 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2464 * @table: the sysctl table
2465 * @write: %TRUE if this is a write to the sysctl file
2466 * @filp: the file structure
2467 * @buffer: the user buffer
2468 * @lenp: the size of the user buffer
2469 * @ppos: file position
2470 * @ppos: the current position in the file
2472 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2473 * values from/to the user buffer, treated as an ASCII string.
2474 * The values read are assumed to be in 1/1000 seconds, and
2475 * are converted into jiffies.
2477 * Returns 0 on success.
2479 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2480 void __user *buffer, size_t *lenp, loff_t *ppos)
2482 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2483 do_proc_dointvec_ms_jiffies_conv, NULL);
2486 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2487 void __user *buffer, size_t *lenp, loff_t *ppos)
2489 struct pid *new_pid;
2490 pid_t tmp;
2491 int r;
2493 tmp = pid_vnr(cad_pid);
2495 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2496 lenp, ppos, NULL, NULL);
2497 if (r || !write)
2498 return r;
2500 new_pid = find_get_pid(tmp);
2501 if (!new_pid)
2502 return -ESRCH;
2504 put_pid(xchg(&cad_pid, new_pid));
2505 return 0;
2508 #else /* CONFIG_PROC_FS */
2510 int proc_dostring(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(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);