keys: make the keyring quotas controllable through /proc/sys
[linux-2.6/openmoko-kernel.git] / kernel / sysctl.c
blob0a1d2733cf4130028ab2f9d49c0cbfddd6f9a7e9
1 /*
2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
31 #include <linux/fs.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/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 sysctl_oom_dump_tasks;
71 extern int max_threads;
72 extern int core_uses_pid;
73 extern int suid_dumpable;
74 extern char core_pattern[];
75 extern int pid_max;
76 extern int min_free_kbytes;
77 extern int pid_max_min, pid_max_max;
78 extern int sysctl_drop_caches;
79 extern int percpu_pagelist_fraction;
80 extern int compat_log;
81 extern int maps_protect;
82 extern int sysctl_stat_interval;
83 extern int latencytop_enabled;
85 /* Constants used for minimum and maximum */
86 #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
87 static int one = 1;
88 #endif
90 #ifdef CONFIG_DETECT_SOFTLOCKUP
91 static int sixty = 60;
92 #endif
94 #ifdef CONFIG_MMU
95 static int two = 2;
96 #endif
98 static int zero;
99 static int one_hundred = 100;
101 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
102 static int maxolduid = 65535;
103 static int minolduid;
104 static int min_percpu_pagelist_fract = 8;
106 static int ngroups_max = NGROUPS_MAX;
108 #ifdef CONFIG_KMOD
109 extern char modprobe_path[];
110 #endif
111 #ifdef CONFIG_CHR_DEV_SG
112 extern int sg_big_buff;
113 #endif
115 #ifdef __sparc__
116 extern char reboot_command [];
117 extern int stop_a_enabled;
118 extern int scons_pwroff;
119 #endif
121 #ifdef __hppa__
122 extern int pwrsw_enabled;
123 extern int unaligned_enabled;
124 #endif
126 #ifdef CONFIG_S390
127 #ifdef CONFIG_MATHEMU
128 extern int sysctl_ieee_emulation_warnings;
129 #endif
130 extern int sysctl_userprocess_debug;
131 extern int spin_retry;
132 #endif
134 extern int sysctl_hz_timer;
136 #ifdef CONFIG_BSD_PROCESS_ACCT
137 extern int acct_parm[];
138 #endif
140 #ifdef CONFIG_IA64
141 extern int no_unaligned_warning;
142 #endif
144 #ifdef CONFIG_RT_MUTEXES
145 extern int max_lock_depth;
146 #endif
148 #ifdef CONFIG_SYSCTL_SYSCALL
149 static int parse_table(int __user *, int, void __user *, size_t __user *,
150 void __user *, size_t, struct ctl_table *);
151 #endif
154 #ifdef CONFIG_PROC_SYSCTL
155 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
156 void __user *buffer, size_t *lenp, loff_t *ppos);
157 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
158 void __user *buffer, size_t *lenp, loff_t *ppos);
159 #endif
161 static struct ctl_table root_table[];
162 static struct ctl_table_root sysctl_table_root;
163 static struct ctl_table_header root_table_header = {
164 .ctl_table = root_table,
165 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
166 .root = &sysctl_table_root,
168 static struct ctl_table_root sysctl_table_root = {
169 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
170 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
173 static struct ctl_table kern_table[];
174 static struct ctl_table vm_table[];
175 static struct ctl_table fs_table[];
176 static struct ctl_table debug_table[];
177 static struct ctl_table dev_table[];
178 extern struct ctl_table random_table[];
179 #ifdef CONFIG_INOTIFY_USER
180 extern struct ctl_table inotify_table[];
181 #endif
183 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
184 int sysctl_legacy_va_layout;
185 #endif
187 extern int prove_locking;
188 extern int lock_stat;
190 /* The default sysctl tables: */
192 static struct ctl_table root_table[] = {
194 .ctl_name = CTL_KERN,
195 .procname = "kernel",
196 .mode = 0555,
197 .child = kern_table,
200 .ctl_name = CTL_VM,
201 .procname = "vm",
202 .mode = 0555,
203 .child = vm_table,
206 .ctl_name = CTL_FS,
207 .procname = "fs",
208 .mode = 0555,
209 .child = fs_table,
212 .ctl_name = CTL_DEBUG,
213 .procname = "debug",
214 .mode = 0555,
215 .child = debug_table,
218 .ctl_name = CTL_DEV,
219 .procname = "dev",
220 .mode = 0555,
221 .child = dev_table,
224 * NOTE: do not add new entries to this table unless you have read
225 * Documentation/sysctl/ctl_unnumbered.txt
227 { .ctl_name = 0 }
230 #ifdef CONFIG_SCHED_DEBUG
231 static int min_sched_granularity_ns = 100000; /* 100 usecs */
232 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
233 static int min_wakeup_granularity_ns; /* 0 usecs */
234 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
235 #endif
237 static struct ctl_table kern_table[] = {
238 #ifdef CONFIG_SCHED_DEBUG
240 .ctl_name = CTL_UNNUMBERED,
241 .procname = "sched_min_granularity_ns",
242 .data = &sysctl_sched_min_granularity,
243 .maxlen = sizeof(unsigned int),
244 .mode = 0644,
245 .proc_handler = &sched_nr_latency_handler,
246 .strategy = &sysctl_intvec,
247 .extra1 = &min_sched_granularity_ns,
248 .extra2 = &max_sched_granularity_ns,
251 .ctl_name = CTL_UNNUMBERED,
252 .procname = "sched_latency_ns",
253 .data = &sysctl_sched_latency,
254 .maxlen = sizeof(unsigned int),
255 .mode = 0644,
256 .proc_handler = &sched_nr_latency_handler,
257 .strategy = &sysctl_intvec,
258 .extra1 = &min_sched_granularity_ns,
259 .extra2 = &max_sched_granularity_ns,
262 .ctl_name = CTL_UNNUMBERED,
263 .procname = "sched_wakeup_granularity_ns",
264 .data = &sysctl_sched_wakeup_granularity,
265 .maxlen = sizeof(unsigned int),
266 .mode = 0644,
267 .proc_handler = &proc_dointvec_minmax,
268 .strategy = &sysctl_intvec,
269 .extra1 = &min_wakeup_granularity_ns,
270 .extra2 = &max_wakeup_granularity_ns,
273 .ctl_name = CTL_UNNUMBERED,
274 .procname = "sched_child_runs_first",
275 .data = &sysctl_sched_child_runs_first,
276 .maxlen = sizeof(unsigned int),
277 .mode = 0644,
278 .proc_handler = &proc_dointvec,
281 .ctl_name = CTL_UNNUMBERED,
282 .procname = "sched_features",
283 .data = &sysctl_sched_features,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_migration_cost",
291 .data = &sysctl_sched_migration_cost,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec,
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_nr_migrate",
299 .data = &sysctl_sched_nr_migrate,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
302 .proc_handler = &proc_dointvec,
304 #endif
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_rt_period_us",
308 .data = &sysctl_sched_rt_period,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
311 .proc_handler = &sched_rt_handler,
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_rt_runtime_us",
316 .data = &sysctl_sched_rt_runtime,
317 .maxlen = sizeof(int),
318 .mode = 0644,
319 .proc_handler = &sched_rt_handler,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_compat_yield",
324 .data = &sysctl_sched_compat_yield,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
329 #ifdef CONFIG_PROVE_LOCKING
331 .ctl_name = CTL_UNNUMBERED,
332 .procname = "prove_locking",
333 .data = &prove_locking,
334 .maxlen = sizeof(int),
335 .mode = 0644,
336 .proc_handler = &proc_dointvec,
338 #endif
339 #ifdef CONFIG_LOCK_STAT
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "lock_stat",
343 .data = &lock_stat,
344 .maxlen = sizeof(int),
345 .mode = 0644,
346 .proc_handler = &proc_dointvec,
348 #endif
350 .ctl_name = KERN_PANIC,
351 .procname = "panic",
352 .data = &panic_timeout,
353 .maxlen = sizeof(int),
354 .mode = 0644,
355 .proc_handler = &proc_dointvec,
358 .ctl_name = KERN_CORE_USES_PID,
359 .procname = "core_uses_pid",
360 .data = &core_uses_pid,
361 .maxlen = sizeof(int),
362 .mode = 0644,
363 .proc_handler = &proc_dointvec,
366 .ctl_name = KERN_CORE_PATTERN,
367 .procname = "core_pattern",
368 .data = core_pattern,
369 .maxlen = CORENAME_MAX_SIZE,
370 .mode = 0644,
371 .proc_handler = &proc_dostring,
372 .strategy = &sysctl_string,
374 #ifdef CONFIG_PROC_SYSCTL
376 .procname = "tainted",
377 .data = &tainted,
378 .maxlen = sizeof(int),
379 .mode = 0644,
380 .proc_handler = &proc_dointvec_taint,
382 #endif
383 #ifdef CONFIG_LATENCYTOP
385 .procname = "latencytop",
386 .data = &latencytop_enabled,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
391 #endif
392 #ifdef CONFIG_BLK_DEV_INITRD
394 .ctl_name = KERN_REALROOTDEV,
395 .procname = "real-root-dev",
396 .data = &real_root_dev,
397 .maxlen = sizeof(int),
398 .mode = 0644,
399 .proc_handler = &proc_dointvec,
401 #endif
403 .ctl_name = CTL_UNNUMBERED,
404 .procname = "print-fatal-signals",
405 .data = &print_fatal_signals,
406 .maxlen = sizeof(int),
407 .mode = 0644,
408 .proc_handler = &proc_dointvec,
410 #ifdef __sparc__
412 .ctl_name = KERN_SPARC_REBOOT,
413 .procname = "reboot-cmd",
414 .data = reboot_command,
415 .maxlen = 256,
416 .mode = 0644,
417 .proc_handler = &proc_dostring,
418 .strategy = &sysctl_string,
421 .ctl_name = KERN_SPARC_STOP_A,
422 .procname = "stop-a",
423 .data = &stop_a_enabled,
424 .maxlen = sizeof (int),
425 .mode = 0644,
426 .proc_handler = &proc_dointvec,
429 .ctl_name = KERN_SPARC_SCONS_PWROFF,
430 .procname = "scons-poweroff",
431 .data = &scons_pwroff,
432 .maxlen = sizeof (int),
433 .mode = 0644,
434 .proc_handler = &proc_dointvec,
436 #endif
437 #ifdef __hppa__
439 .ctl_name = KERN_HPPA_PWRSW,
440 .procname = "soft-power",
441 .data = &pwrsw_enabled,
442 .maxlen = sizeof (int),
443 .mode = 0644,
444 .proc_handler = &proc_dointvec,
447 .ctl_name = KERN_HPPA_UNALIGNED,
448 .procname = "unaligned-trap",
449 .data = &unaligned_enabled,
450 .maxlen = sizeof (int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
454 #endif
456 .ctl_name = KERN_CTLALTDEL,
457 .procname = "ctrl-alt-del",
458 .data = &C_A_D,
459 .maxlen = sizeof(int),
460 .mode = 0644,
461 .proc_handler = &proc_dointvec,
463 #ifdef CONFIG_KMOD
465 .ctl_name = KERN_MODPROBE,
466 .procname = "modprobe",
467 .data = &modprobe_path,
468 .maxlen = KMOD_PATH_LEN,
469 .mode = 0644,
470 .proc_handler = &proc_dostring,
471 .strategy = &sysctl_string,
473 #endif
474 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
476 .ctl_name = KERN_HOTPLUG,
477 .procname = "hotplug",
478 .data = &uevent_helper,
479 .maxlen = UEVENT_HELPER_PATH_LEN,
480 .mode = 0644,
481 .proc_handler = &proc_dostring,
482 .strategy = &sysctl_string,
484 #endif
485 #ifdef CONFIG_CHR_DEV_SG
487 .ctl_name = KERN_SG_BIG_BUFF,
488 .procname = "sg-big-buff",
489 .data = &sg_big_buff,
490 .maxlen = sizeof (int),
491 .mode = 0444,
492 .proc_handler = &proc_dointvec,
494 #endif
495 #ifdef CONFIG_BSD_PROCESS_ACCT
497 .ctl_name = KERN_ACCT,
498 .procname = "acct",
499 .data = &acct_parm,
500 .maxlen = 3*sizeof(int),
501 .mode = 0644,
502 .proc_handler = &proc_dointvec,
504 #endif
505 #ifdef CONFIG_MAGIC_SYSRQ
507 .ctl_name = KERN_SYSRQ,
508 .procname = "sysrq",
509 .data = &__sysrq_enabled,
510 .maxlen = sizeof (int),
511 .mode = 0644,
512 .proc_handler = &proc_dointvec,
514 #endif
515 #ifdef CONFIG_PROC_SYSCTL
517 .procname = "cad_pid",
518 .data = NULL,
519 .maxlen = sizeof (int),
520 .mode = 0600,
521 .proc_handler = &proc_do_cad_pid,
523 #endif
525 .ctl_name = KERN_MAX_THREADS,
526 .procname = "threads-max",
527 .data = &max_threads,
528 .maxlen = sizeof(int),
529 .mode = 0644,
530 .proc_handler = &proc_dointvec,
533 .ctl_name = KERN_RANDOM,
534 .procname = "random",
535 .mode = 0555,
536 .child = random_table,
539 .ctl_name = KERN_OVERFLOWUID,
540 .procname = "overflowuid",
541 .data = &overflowuid,
542 .maxlen = sizeof(int),
543 .mode = 0644,
544 .proc_handler = &proc_dointvec_minmax,
545 .strategy = &sysctl_intvec,
546 .extra1 = &minolduid,
547 .extra2 = &maxolduid,
550 .ctl_name = KERN_OVERFLOWGID,
551 .procname = "overflowgid",
552 .data = &overflowgid,
553 .maxlen = sizeof(int),
554 .mode = 0644,
555 .proc_handler = &proc_dointvec_minmax,
556 .strategy = &sysctl_intvec,
557 .extra1 = &minolduid,
558 .extra2 = &maxolduid,
560 #ifdef CONFIG_S390
561 #ifdef CONFIG_MATHEMU
563 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
564 .procname = "ieee_emulation_warnings",
565 .data = &sysctl_ieee_emulation_warnings,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec,
570 #endif
571 #ifdef CONFIG_NO_IDLE_HZ
573 .ctl_name = KERN_HZ_TIMER,
574 .procname = "hz_timer",
575 .data = &sysctl_hz_timer,
576 .maxlen = sizeof(int),
577 .mode = 0644,
578 .proc_handler = &proc_dointvec,
580 #endif
582 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
583 .procname = "userprocess_debug",
584 .data = &sysctl_userprocess_debug,
585 .maxlen = sizeof(int),
586 .mode = 0644,
587 .proc_handler = &proc_dointvec,
589 #endif
591 .ctl_name = KERN_PIDMAX,
592 .procname = "pid_max",
593 .data = &pid_max,
594 .maxlen = sizeof (int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec_minmax,
597 .strategy = sysctl_intvec,
598 .extra1 = &pid_max_min,
599 .extra2 = &pid_max_max,
602 .ctl_name = KERN_PANIC_ON_OOPS,
603 .procname = "panic_on_oops",
604 .data = &panic_on_oops,
605 .maxlen = sizeof(int),
606 .mode = 0644,
607 .proc_handler = &proc_dointvec,
609 #if defined CONFIG_PRINTK
611 .ctl_name = KERN_PRINTK,
612 .procname = "printk",
613 .data = &console_loglevel,
614 .maxlen = 4*sizeof(int),
615 .mode = 0644,
616 .proc_handler = &proc_dointvec,
619 .ctl_name = KERN_PRINTK_RATELIMIT,
620 .procname = "printk_ratelimit",
621 .data = &printk_ratelimit_jiffies,
622 .maxlen = sizeof(int),
623 .mode = 0644,
624 .proc_handler = &proc_dointvec_jiffies,
625 .strategy = &sysctl_jiffies,
628 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
629 .procname = "printk_ratelimit_burst",
630 .data = &printk_ratelimit_burst,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
635 #endif
637 .ctl_name = KERN_NGROUPS_MAX,
638 .procname = "ngroups_max",
639 .data = &ngroups_max,
640 .maxlen = sizeof (int),
641 .mode = 0444,
642 .proc_handler = &proc_dointvec,
644 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
646 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
647 .procname = "unknown_nmi_panic",
648 .data = &unknown_nmi_panic,
649 .maxlen = sizeof (int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec,
654 .procname = "nmi_watchdog",
655 .data = &nmi_watchdog_enabled,
656 .maxlen = sizeof (int),
657 .mode = 0644,
658 .proc_handler = &proc_nmi_enabled,
660 #endif
661 #if defined(CONFIG_X86)
663 .ctl_name = KERN_PANIC_ON_NMI,
664 .procname = "panic_on_unrecovered_nmi",
665 .data = &panic_on_unrecovered_nmi,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = &proc_dointvec,
671 .ctl_name = KERN_BOOTLOADER_TYPE,
672 .procname = "bootloader_type",
673 .data = &bootloader_type,
674 .maxlen = sizeof (int),
675 .mode = 0444,
676 .proc_handler = &proc_dointvec,
679 .ctl_name = CTL_UNNUMBERED,
680 .procname = "kstack_depth_to_print",
681 .data = &kstack_depth_to_print,
682 .maxlen = sizeof(int),
683 .mode = 0644,
684 .proc_handler = &proc_dointvec,
687 .ctl_name = CTL_UNNUMBERED,
688 .procname = "io_delay_type",
689 .data = &io_delay_type,
690 .maxlen = sizeof(int),
691 .mode = 0644,
692 .proc_handler = &proc_dointvec,
694 #endif
695 #if defined(CONFIG_MMU)
697 .ctl_name = KERN_RANDOMIZE,
698 .procname = "randomize_va_space",
699 .data = &randomize_va_space,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 .proc_handler = &proc_dointvec,
704 #endif
705 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
707 .ctl_name = KERN_SPIN_RETRY,
708 .procname = "spin_retry",
709 .data = &spin_retry,
710 .maxlen = sizeof (int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
714 #endif
715 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
717 .procname = "acpi_video_flags",
718 .data = &acpi_realmode_flags,
719 .maxlen = sizeof (unsigned long),
720 .mode = 0644,
721 .proc_handler = &proc_doulongvec_minmax,
723 #endif
724 #ifdef CONFIG_IA64
726 .ctl_name = KERN_IA64_UNALIGNED,
727 .procname = "ignore-unaligned-usertrap",
728 .data = &no_unaligned_warning,
729 .maxlen = sizeof (int),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec,
733 #endif
734 #ifdef CONFIG_DETECT_SOFTLOCKUP
736 .ctl_name = CTL_UNNUMBERED,
737 .procname = "softlockup_thresh",
738 .data = &softlockup_thresh,
739 .maxlen = sizeof(unsigned long),
740 .mode = 0644,
741 .proc_handler = &proc_doulongvec_minmax,
742 .strategy = &sysctl_intvec,
743 .extra1 = &one,
744 .extra2 = &sixty,
747 .ctl_name = CTL_UNNUMBERED,
748 .procname = "hung_task_check_count",
749 .data = &sysctl_hung_task_check_count,
750 .maxlen = sizeof(unsigned long),
751 .mode = 0644,
752 .proc_handler = &proc_doulongvec_minmax,
753 .strategy = &sysctl_intvec,
756 .ctl_name = CTL_UNNUMBERED,
757 .procname = "hung_task_timeout_secs",
758 .data = &sysctl_hung_task_timeout_secs,
759 .maxlen = sizeof(unsigned long),
760 .mode = 0644,
761 .proc_handler = &proc_doulongvec_minmax,
762 .strategy = &sysctl_intvec,
765 .ctl_name = CTL_UNNUMBERED,
766 .procname = "hung_task_warnings",
767 .data = &sysctl_hung_task_warnings,
768 .maxlen = sizeof(unsigned long),
769 .mode = 0644,
770 .proc_handler = &proc_doulongvec_minmax,
771 .strategy = &sysctl_intvec,
773 #endif
774 #ifdef CONFIG_COMPAT
776 .ctl_name = KERN_COMPAT_LOG,
777 .procname = "compat-log",
778 .data = &compat_log,
779 .maxlen = sizeof (int),
780 .mode = 0644,
781 .proc_handler = &proc_dointvec,
783 #endif
784 #ifdef CONFIG_RT_MUTEXES
786 .ctl_name = KERN_MAX_LOCK_DEPTH,
787 .procname = "max_lock_depth",
788 .data = &max_lock_depth,
789 .maxlen = sizeof(int),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec,
793 #endif
794 #ifdef CONFIG_PROC_FS
796 .ctl_name = CTL_UNNUMBERED,
797 .procname = "maps_protect",
798 .data = &maps_protect,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
803 #endif
805 .ctl_name = CTL_UNNUMBERED,
806 .procname = "poweroff_cmd",
807 .data = &poweroff_cmd,
808 .maxlen = POWEROFF_CMD_PATH_LEN,
809 .mode = 0644,
810 .proc_handler = &proc_dostring,
811 .strategy = &sysctl_string,
813 #ifdef CONFIG_KEYS
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "keys",
817 .mode = 0555,
818 .child = key_sysctls,
820 #endif
822 * NOTE: do not add new entries to this table unless you have read
823 * Documentation/sysctl/ctl_unnumbered.txt
825 { .ctl_name = 0 }
828 static struct ctl_table vm_table[] = {
830 .ctl_name = VM_OVERCOMMIT_MEMORY,
831 .procname = "overcommit_memory",
832 .data = &sysctl_overcommit_memory,
833 .maxlen = sizeof(sysctl_overcommit_memory),
834 .mode = 0644,
835 .proc_handler = &proc_dointvec,
838 .ctl_name = VM_PANIC_ON_OOM,
839 .procname = "panic_on_oom",
840 .data = &sysctl_panic_on_oom,
841 .maxlen = sizeof(sysctl_panic_on_oom),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec,
846 .ctl_name = CTL_UNNUMBERED,
847 .procname = "oom_kill_allocating_task",
848 .data = &sysctl_oom_kill_allocating_task,
849 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
850 .mode = 0644,
851 .proc_handler = &proc_dointvec,
854 .ctl_name = CTL_UNNUMBERED,
855 .procname = "oom_dump_tasks",
856 .data = &sysctl_oom_dump_tasks,
857 .maxlen = sizeof(sysctl_oom_dump_tasks),
858 .mode = 0644,
859 .proc_handler = &proc_dointvec,
862 .ctl_name = VM_OVERCOMMIT_RATIO,
863 .procname = "overcommit_ratio",
864 .data = &sysctl_overcommit_ratio,
865 .maxlen = sizeof(sysctl_overcommit_ratio),
866 .mode = 0644,
867 .proc_handler = &proc_dointvec,
870 .ctl_name = VM_PAGE_CLUSTER,
871 .procname = "page-cluster",
872 .data = &page_cluster,
873 .maxlen = sizeof(int),
874 .mode = 0644,
875 .proc_handler = &proc_dointvec,
878 .ctl_name = VM_DIRTY_BACKGROUND,
879 .procname = "dirty_background_ratio",
880 .data = &dirty_background_ratio,
881 .maxlen = sizeof(dirty_background_ratio),
882 .mode = 0644,
883 .proc_handler = &proc_dointvec_minmax,
884 .strategy = &sysctl_intvec,
885 .extra1 = &zero,
886 .extra2 = &one_hundred,
889 .ctl_name = VM_DIRTY_RATIO,
890 .procname = "dirty_ratio",
891 .data = &vm_dirty_ratio,
892 .maxlen = sizeof(vm_dirty_ratio),
893 .mode = 0644,
894 .proc_handler = &dirty_ratio_handler,
895 .strategy = &sysctl_intvec,
896 .extra1 = &zero,
897 .extra2 = &one_hundred,
900 .procname = "dirty_writeback_centisecs",
901 .data = &dirty_writeback_interval,
902 .maxlen = sizeof(dirty_writeback_interval),
903 .mode = 0644,
904 .proc_handler = &dirty_writeback_centisecs_handler,
907 .procname = "dirty_expire_centisecs",
908 .data = &dirty_expire_interval,
909 .maxlen = sizeof(dirty_expire_interval),
910 .mode = 0644,
911 .proc_handler = &proc_dointvec_userhz_jiffies,
914 .ctl_name = VM_NR_PDFLUSH_THREADS,
915 .procname = "nr_pdflush_threads",
916 .data = &nr_pdflush_threads,
917 .maxlen = sizeof nr_pdflush_threads,
918 .mode = 0444 /* read-only*/,
919 .proc_handler = &proc_dointvec,
922 .ctl_name = VM_SWAPPINESS,
923 .procname = "swappiness",
924 .data = &vm_swappiness,
925 .maxlen = sizeof(vm_swappiness),
926 .mode = 0644,
927 .proc_handler = &proc_dointvec_minmax,
928 .strategy = &sysctl_intvec,
929 .extra1 = &zero,
930 .extra2 = &one_hundred,
932 #ifdef CONFIG_HUGETLB_PAGE
934 .procname = "nr_hugepages",
935 .data = &max_huge_pages,
936 .maxlen = sizeof(unsigned long),
937 .mode = 0644,
938 .proc_handler = &hugetlb_sysctl_handler,
939 .extra1 = (void *)&hugetlb_zero,
940 .extra2 = (void *)&hugetlb_infinity,
943 .ctl_name = VM_HUGETLB_GROUP,
944 .procname = "hugetlb_shm_group",
945 .data = &sysctl_hugetlb_shm_group,
946 .maxlen = sizeof(gid_t),
947 .mode = 0644,
948 .proc_handler = &proc_dointvec,
951 .ctl_name = CTL_UNNUMBERED,
952 .procname = "hugepages_treat_as_movable",
953 .data = &hugepages_treat_as_movable,
954 .maxlen = sizeof(int),
955 .mode = 0644,
956 .proc_handler = &hugetlb_treat_movable_handler,
959 .ctl_name = CTL_UNNUMBERED,
960 .procname = "nr_overcommit_hugepages",
961 .data = &sysctl_overcommit_huge_pages,
962 .maxlen = sizeof(sysctl_overcommit_huge_pages),
963 .mode = 0644,
964 .proc_handler = &hugetlb_overcommit_handler,
966 #endif
968 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
969 .procname = "lowmem_reserve_ratio",
970 .data = &sysctl_lowmem_reserve_ratio,
971 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
972 .mode = 0644,
973 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
974 .strategy = &sysctl_intvec,
977 .ctl_name = VM_DROP_PAGECACHE,
978 .procname = "drop_caches",
979 .data = &sysctl_drop_caches,
980 .maxlen = sizeof(int),
981 .mode = 0644,
982 .proc_handler = drop_caches_sysctl_handler,
983 .strategy = &sysctl_intvec,
986 .ctl_name = VM_MIN_FREE_KBYTES,
987 .procname = "min_free_kbytes",
988 .data = &min_free_kbytes,
989 .maxlen = sizeof(min_free_kbytes),
990 .mode = 0644,
991 .proc_handler = &min_free_kbytes_sysctl_handler,
992 .strategy = &sysctl_intvec,
993 .extra1 = &zero,
996 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
997 .procname = "percpu_pagelist_fraction",
998 .data = &percpu_pagelist_fraction,
999 .maxlen = sizeof(percpu_pagelist_fraction),
1000 .mode = 0644,
1001 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1002 .strategy = &sysctl_intvec,
1003 .extra1 = &min_percpu_pagelist_fract,
1005 #ifdef CONFIG_MMU
1007 .ctl_name = VM_MAX_MAP_COUNT,
1008 .procname = "max_map_count",
1009 .data = &sysctl_max_map_count,
1010 .maxlen = sizeof(sysctl_max_map_count),
1011 .mode = 0644,
1012 .proc_handler = &proc_dointvec
1014 #endif
1016 .ctl_name = VM_LAPTOP_MODE,
1017 .procname = "laptop_mode",
1018 .data = &laptop_mode,
1019 .maxlen = sizeof(laptop_mode),
1020 .mode = 0644,
1021 .proc_handler = &proc_dointvec_jiffies,
1022 .strategy = &sysctl_jiffies,
1025 .ctl_name = VM_BLOCK_DUMP,
1026 .procname = "block_dump",
1027 .data = &block_dump,
1028 .maxlen = sizeof(block_dump),
1029 .mode = 0644,
1030 .proc_handler = &proc_dointvec,
1031 .strategy = &sysctl_intvec,
1032 .extra1 = &zero,
1035 .ctl_name = VM_VFS_CACHE_PRESSURE,
1036 .procname = "vfs_cache_pressure",
1037 .data = &sysctl_vfs_cache_pressure,
1038 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1039 .mode = 0644,
1040 .proc_handler = &proc_dointvec,
1041 .strategy = &sysctl_intvec,
1042 .extra1 = &zero,
1044 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1046 .ctl_name = VM_LEGACY_VA_LAYOUT,
1047 .procname = "legacy_va_layout",
1048 .data = &sysctl_legacy_va_layout,
1049 .maxlen = sizeof(sysctl_legacy_va_layout),
1050 .mode = 0644,
1051 .proc_handler = &proc_dointvec,
1052 .strategy = &sysctl_intvec,
1053 .extra1 = &zero,
1055 #endif
1056 #ifdef CONFIG_NUMA
1058 .ctl_name = VM_ZONE_RECLAIM_MODE,
1059 .procname = "zone_reclaim_mode",
1060 .data = &zone_reclaim_mode,
1061 .maxlen = sizeof(zone_reclaim_mode),
1062 .mode = 0644,
1063 .proc_handler = &proc_dointvec,
1064 .strategy = &sysctl_intvec,
1065 .extra1 = &zero,
1068 .ctl_name = VM_MIN_UNMAPPED,
1069 .procname = "min_unmapped_ratio",
1070 .data = &sysctl_min_unmapped_ratio,
1071 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1072 .mode = 0644,
1073 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1074 .strategy = &sysctl_intvec,
1075 .extra1 = &zero,
1076 .extra2 = &one_hundred,
1079 .ctl_name = VM_MIN_SLAB,
1080 .procname = "min_slab_ratio",
1081 .data = &sysctl_min_slab_ratio,
1082 .maxlen = sizeof(sysctl_min_slab_ratio),
1083 .mode = 0644,
1084 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1085 .strategy = &sysctl_intvec,
1086 .extra1 = &zero,
1087 .extra2 = &one_hundred,
1089 #endif
1090 #ifdef CONFIG_SMP
1092 .ctl_name = CTL_UNNUMBERED,
1093 .procname = "stat_interval",
1094 .data = &sysctl_stat_interval,
1095 .maxlen = sizeof(sysctl_stat_interval),
1096 .mode = 0644,
1097 .proc_handler = &proc_dointvec_jiffies,
1098 .strategy = &sysctl_jiffies,
1100 #endif
1101 #ifdef CONFIG_SECURITY
1103 .ctl_name = CTL_UNNUMBERED,
1104 .procname = "mmap_min_addr",
1105 .data = &mmap_min_addr,
1106 .maxlen = sizeof(unsigned long),
1107 .mode = 0644,
1108 .proc_handler = &proc_doulongvec_minmax,
1110 #endif
1111 #ifdef CONFIG_NUMA
1113 .ctl_name = CTL_UNNUMBERED,
1114 .procname = "numa_zonelist_order",
1115 .data = &numa_zonelist_order,
1116 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1117 .mode = 0644,
1118 .proc_handler = &numa_zonelist_order_handler,
1119 .strategy = &sysctl_string,
1121 #endif
1122 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1123 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1125 .ctl_name = VM_VDSO_ENABLED,
1126 .procname = "vdso_enabled",
1127 .data = &vdso_enabled,
1128 .maxlen = sizeof(vdso_enabled),
1129 .mode = 0644,
1130 .proc_handler = &proc_dointvec,
1131 .strategy = &sysctl_intvec,
1132 .extra1 = &zero,
1134 #endif
1135 #ifdef CONFIG_HIGHMEM
1137 .ctl_name = CTL_UNNUMBERED,
1138 .procname = "highmem_is_dirtyable",
1139 .data = &vm_highmem_is_dirtyable,
1140 .maxlen = sizeof(vm_highmem_is_dirtyable),
1141 .mode = 0644,
1142 .proc_handler = &proc_dointvec_minmax,
1143 .strategy = &sysctl_intvec,
1144 .extra1 = &zero,
1145 .extra2 = &one,
1147 #endif
1149 * NOTE: do not add new entries to this table unless you have read
1150 * Documentation/sysctl/ctl_unnumbered.txt
1152 { .ctl_name = 0 }
1155 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1156 static struct ctl_table binfmt_misc_table[] = {
1157 { .ctl_name = 0 }
1159 #endif
1161 static struct ctl_table fs_table[] = {
1163 .ctl_name = FS_NRINODE,
1164 .procname = "inode-nr",
1165 .data = &inodes_stat,
1166 .maxlen = 2*sizeof(int),
1167 .mode = 0444,
1168 .proc_handler = &proc_dointvec,
1171 .ctl_name = FS_STATINODE,
1172 .procname = "inode-state",
1173 .data = &inodes_stat,
1174 .maxlen = 7*sizeof(int),
1175 .mode = 0444,
1176 .proc_handler = &proc_dointvec,
1179 .procname = "file-nr",
1180 .data = &files_stat,
1181 .maxlen = 3*sizeof(int),
1182 .mode = 0444,
1183 .proc_handler = &proc_nr_files,
1186 .ctl_name = FS_MAXFILE,
1187 .procname = "file-max",
1188 .data = &files_stat.max_files,
1189 .maxlen = sizeof(int),
1190 .mode = 0644,
1191 .proc_handler = &proc_dointvec,
1194 .ctl_name = CTL_UNNUMBERED,
1195 .procname = "nr_open",
1196 .data = &sysctl_nr_open,
1197 .maxlen = sizeof(int),
1198 .mode = 0644,
1199 .proc_handler = &proc_dointvec,
1202 .ctl_name = FS_DENTRY,
1203 .procname = "dentry-state",
1204 .data = &dentry_stat,
1205 .maxlen = 6*sizeof(int),
1206 .mode = 0444,
1207 .proc_handler = &proc_dointvec,
1210 .ctl_name = FS_OVERFLOWUID,
1211 .procname = "overflowuid",
1212 .data = &fs_overflowuid,
1213 .maxlen = sizeof(int),
1214 .mode = 0644,
1215 .proc_handler = &proc_dointvec_minmax,
1216 .strategy = &sysctl_intvec,
1217 .extra1 = &minolduid,
1218 .extra2 = &maxolduid,
1221 .ctl_name = FS_OVERFLOWGID,
1222 .procname = "overflowgid",
1223 .data = &fs_overflowgid,
1224 .maxlen = sizeof(int),
1225 .mode = 0644,
1226 .proc_handler = &proc_dointvec_minmax,
1227 .strategy = &sysctl_intvec,
1228 .extra1 = &minolduid,
1229 .extra2 = &maxolduid,
1232 .ctl_name = FS_LEASES,
1233 .procname = "leases-enable",
1234 .data = &leases_enable,
1235 .maxlen = sizeof(int),
1236 .mode = 0644,
1237 .proc_handler = &proc_dointvec,
1239 #ifdef CONFIG_DNOTIFY
1241 .ctl_name = FS_DIR_NOTIFY,
1242 .procname = "dir-notify-enable",
1243 .data = &dir_notify_enable,
1244 .maxlen = sizeof(int),
1245 .mode = 0644,
1246 .proc_handler = &proc_dointvec,
1248 #endif
1249 #ifdef CONFIG_MMU
1251 .ctl_name = FS_LEASE_TIME,
1252 .procname = "lease-break-time",
1253 .data = &lease_break_time,
1254 .maxlen = sizeof(int),
1255 .mode = 0644,
1256 .proc_handler = &proc_dointvec_minmax,
1257 .strategy = &sysctl_intvec,
1258 .extra1 = &zero,
1259 .extra2 = &two,
1262 .procname = "aio-nr",
1263 .data = &aio_nr,
1264 .maxlen = sizeof(aio_nr),
1265 .mode = 0444,
1266 .proc_handler = &proc_doulongvec_minmax,
1269 .procname = "aio-max-nr",
1270 .data = &aio_max_nr,
1271 .maxlen = sizeof(aio_max_nr),
1272 .mode = 0644,
1273 .proc_handler = &proc_doulongvec_minmax,
1275 #ifdef CONFIG_INOTIFY_USER
1277 .ctl_name = FS_INOTIFY,
1278 .procname = "inotify",
1279 .mode = 0555,
1280 .child = inotify_table,
1282 #endif
1283 #endif
1285 .ctl_name = KERN_SETUID_DUMPABLE,
1286 .procname = "suid_dumpable",
1287 .data = &suid_dumpable,
1288 .maxlen = sizeof(int),
1289 .mode = 0644,
1290 .proc_handler = &proc_dointvec,
1292 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1294 .ctl_name = CTL_UNNUMBERED,
1295 .procname = "binfmt_misc",
1296 .mode = 0555,
1297 .child = binfmt_misc_table,
1299 #endif
1301 * NOTE: do not add new entries to this table unless you have read
1302 * Documentation/sysctl/ctl_unnumbered.txt
1304 { .ctl_name = 0 }
1307 static struct ctl_table debug_table[] = {
1308 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1310 .ctl_name = CTL_UNNUMBERED,
1311 .procname = "exception-trace",
1312 .data = &show_unhandled_signals,
1313 .maxlen = sizeof(int),
1314 .mode = 0644,
1315 .proc_handler = proc_dointvec
1317 #endif
1318 { .ctl_name = 0 }
1321 static struct ctl_table dev_table[] = {
1322 { .ctl_name = 0 }
1325 static DEFINE_SPINLOCK(sysctl_lock);
1327 /* called under sysctl_lock */
1328 static int use_table(struct ctl_table_header *p)
1330 if (unlikely(p->unregistering))
1331 return 0;
1332 p->used++;
1333 return 1;
1336 /* called under sysctl_lock */
1337 static void unuse_table(struct ctl_table_header *p)
1339 if (!--p->used)
1340 if (unlikely(p->unregistering))
1341 complete(p->unregistering);
1344 /* called under sysctl_lock, will reacquire if has to wait */
1345 static void start_unregistering(struct ctl_table_header *p)
1348 * if p->used is 0, nobody will ever touch that entry again;
1349 * we'll eliminate all paths to it before dropping sysctl_lock
1351 if (unlikely(p->used)) {
1352 struct completion wait;
1353 init_completion(&wait);
1354 p->unregistering = &wait;
1355 spin_unlock(&sysctl_lock);
1356 wait_for_completion(&wait);
1357 spin_lock(&sysctl_lock);
1360 * do not remove from the list until nobody holds it; walking the
1361 * list in do_sysctl() relies on that.
1363 list_del_init(&p->ctl_entry);
1366 void sysctl_head_finish(struct ctl_table_header *head)
1368 if (!head)
1369 return;
1370 spin_lock(&sysctl_lock);
1371 unuse_table(head);
1372 spin_unlock(&sysctl_lock);
1375 static struct list_head *
1376 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1378 struct list_head *header_list;
1379 header_list = &root->header_list;
1380 if (root->lookup)
1381 header_list = root->lookup(root, namespaces);
1382 return header_list;
1385 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1386 struct ctl_table_header *prev)
1388 struct ctl_table_root *root;
1389 struct list_head *header_list;
1390 struct ctl_table_header *head;
1391 struct list_head *tmp;
1393 spin_lock(&sysctl_lock);
1394 if (prev) {
1395 head = prev;
1396 tmp = &prev->ctl_entry;
1397 unuse_table(prev);
1398 goto next;
1400 tmp = &root_table_header.ctl_entry;
1401 for (;;) {
1402 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1404 if (!use_table(head))
1405 goto next;
1406 spin_unlock(&sysctl_lock);
1407 return head;
1408 next:
1409 root = head->root;
1410 tmp = tmp->next;
1411 header_list = lookup_header_list(root, namespaces);
1412 if (tmp != header_list)
1413 continue;
1415 do {
1416 root = list_entry(root->root_list.next,
1417 struct ctl_table_root, root_list);
1418 if (root == &sysctl_table_root)
1419 goto out;
1420 header_list = lookup_header_list(root, namespaces);
1421 } while (list_empty(header_list));
1422 tmp = header_list->next;
1424 out:
1425 spin_unlock(&sysctl_lock);
1426 return NULL;
1429 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1431 return __sysctl_head_next(current->nsproxy, prev);
1434 void register_sysctl_root(struct ctl_table_root *root)
1436 spin_lock(&sysctl_lock);
1437 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1438 spin_unlock(&sysctl_lock);
1441 #ifdef CONFIG_SYSCTL_SYSCALL
1442 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1443 void __user *newval, size_t newlen)
1445 struct ctl_table_header *head;
1446 int error = -ENOTDIR;
1448 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1449 return -ENOTDIR;
1450 if (oldval) {
1451 int old_len;
1452 if (!oldlenp || get_user(old_len, oldlenp))
1453 return -EFAULT;
1456 for (head = sysctl_head_next(NULL); head;
1457 head = sysctl_head_next(head)) {
1458 error = parse_table(name, nlen, oldval, oldlenp,
1459 newval, newlen, head->ctl_table);
1460 if (error != -ENOTDIR) {
1461 sysctl_head_finish(head);
1462 break;
1465 return error;
1468 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1470 struct __sysctl_args tmp;
1471 int error;
1473 if (copy_from_user(&tmp, args, sizeof(tmp)))
1474 return -EFAULT;
1476 error = deprecated_sysctl_warning(&tmp);
1477 if (error)
1478 goto out;
1480 lock_kernel();
1481 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1482 tmp.newval, tmp.newlen);
1483 unlock_kernel();
1484 out:
1485 return error;
1487 #endif /* CONFIG_SYSCTL_SYSCALL */
1490 * sysctl_perm does NOT grant the superuser all rights automatically, because
1491 * some sysctl variables are readonly even to root.
1494 static int test_perm(int mode, int op)
1496 if (!current->euid)
1497 mode >>= 6;
1498 else if (in_egroup_p(0))
1499 mode >>= 3;
1500 if ((mode & op & 0007) == op)
1501 return 0;
1502 return -EACCES;
1505 int sysctl_perm(struct ctl_table *table, int op)
1507 int error;
1508 error = security_sysctl(table, op);
1509 if (error)
1510 return error;
1511 return test_perm(table->mode, op);
1514 #ifdef CONFIG_SYSCTL_SYSCALL
1515 static int parse_table(int __user *name, int nlen,
1516 void __user *oldval, size_t __user *oldlenp,
1517 void __user *newval, size_t newlen,
1518 struct ctl_table *table)
1520 int n;
1521 repeat:
1522 if (!nlen)
1523 return -ENOTDIR;
1524 if (get_user(n, name))
1525 return -EFAULT;
1526 for ( ; table->ctl_name || table->procname; table++) {
1527 if (!table->ctl_name)
1528 continue;
1529 if (n == table->ctl_name) {
1530 int error;
1531 if (table->child) {
1532 if (sysctl_perm(table, 001))
1533 return -EPERM;
1534 name++;
1535 nlen--;
1536 table = table->child;
1537 goto repeat;
1539 error = do_sysctl_strategy(table, name, nlen,
1540 oldval, oldlenp,
1541 newval, newlen);
1542 return error;
1545 return -ENOTDIR;
1548 /* Perform the actual read/write of a sysctl table entry. */
1549 int do_sysctl_strategy (struct ctl_table *table,
1550 int __user *name, int nlen,
1551 void __user *oldval, size_t __user *oldlenp,
1552 void __user *newval, size_t newlen)
1554 int op = 0, rc;
1556 if (oldval)
1557 op |= 004;
1558 if (newval)
1559 op |= 002;
1560 if (sysctl_perm(table, op))
1561 return -EPERM;
1563 if (table->strategy) {
1564 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1565 newval, newlen);
1566 if (rc < 0)
1567 return rc;
1568 if (rc > 0)
1569 return 0;
1572 /* If there is no strategy routine, or if the strategy returns
1573 * zero, proceed with automatic r/w */
1574 if (table->data && table->maxlen) {
1575 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1576 newval, newlen);
1577 if (rc < 0)
1578 return rc;
1580 return 0;
1582 #endif /* CONFIG_SYSCTL_SYSCALL */
1584 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1586 for (; table->ctl_name || table->procname; table++) {
1587 table->parent = parent;
1588 if (table->child)
1589 sysctl_set_parent(table, table->child);
1593 static __init int sysctl_init(void)
1595 int err;
1596 sysctl_set_parent(NULL, root_table);
1597 err = sysctl_check_table(current->nsproxy, root_table);
1598 return 0;
1601 core_initcall(sysctl_init);
1604 * __register_sysctl_paths - register a sysctl hierarchy
1605 * @root: List of sysctl headers to register on
1606 * @namespaces: Data to compute which lists of sysctl entries are visible
1607 * @path: The path to the directory the sysctl table is in.
1608 * @table: the top-level table structure
1610 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1611 * array. A completely 0 filled entry terminates the table.
1613 * The members of the &struct ctl_table structure are used as follows:
1615 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1616 * must be unique within that level of sysctl
1618 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1619 * enter a sysctl file
1621 * data - a pointer to data for use by proc_handler
1623 * maxlen - the maximum size in bytes of the data
1625 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1627 * child - a pointer to the child sysctl table if this entry is a directory, or
1628 * %NULL.
1630 * proc_handler - the text handler routine (described below)
1632 * strategy - the strategy routine (described below)
1634 * de - for internal use by the sysctl routines
1636 * extra1, extra2 - extra pointers usable by the proc handler routines
1638 * Leaf nodes in the sysctl tree will be represented by a single file
1639 * under /proc; non-leaf nodes will be represented by directories.
1641 * sysctl(2) can automatically manage read and write requests through
1642 * the sysctl table. The data and maxlen fields of the ctl_table
1643 * struct enable minimal validation of the values being written to be
1644 * performed, and the mode field allows minimal authentication.
1646 * More sophisticated management can be enabled by the provision of a
1647 * strategy routine with the table entry. This will be called before
1648 * any automatic read or write of the data is performed.
1650 * The strategy routine may return
1652 * < 0 - Error occurred (error is passed to user process)
1654 * 0 - OK - proceed with automatic read or write.
1656 * > 0 - OK - read or write has been done by the strategy routine, so
1657 * return immediately.
1659 * There must be a proc_handler routine for any terminal nodes
1660 * mirrored under /proc/sys (non-terminals are handled by a built-in
1661 * directory handler). Several default handlers are available to
1662 * cover common cases -
1664 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1665 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1666 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1668 * It is the handler's job to read the input buffer from user memory
1669 * and process it. The handler should return 0 on success.
1671 * This routine returns %NULL on a failure to register, and a pointer
1672 * to the table header on success.
1674 struct ctl_table_header *__register_sysctl_paths(
1675 struct ctl_table_root *root,
1676 struct nsproxy *namespaces,
1677 const struct ctl_path *path, struct ctl_table *table)
1679 struct list_head *header_list;
1680 struct ctl_table_header *header;
1681 struct ctl_table *new, **prevp;
1682 unsigned int n, npath;
1684 /* Count the path components */
1685 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1689 * For each path component, allocate a 2-element ctl_table array.
1690 * The first array element will be filled with the sysctl entry
1691 * for this, the second will be the sentinel (ctl_name == 0).
1693 * We allocate everything in one go so that we don't have to
1694 * worry about freeing additional memory in unregister_sysctl_table.
1696 header = kzalloc(sizeof(struct ctl_table_header) +
1697 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1698 if (!header)
1699 return NULL;
1701 new = (struct ctl_table *) (header + 1);
1703 /* Now connect the dots */
1704 prevp = &header->ctl_table;
1705 for (n = 0; n < npath; ++n, ++path) {
1706 /* Copy the procname */
1707 new->procname = path->procname;
1708 new->ctl_name = path->ctl_name;
1709 new->mode = 0555;
1711 *prevp = new;
1712 prevp = &new->child;
1714 new += 2;
1716 *prevp = table;
1717 header->ctl_table_arg = table;
1719 INIT_LIST_HEAD(&header->ctl_entry);
1720 header->used = 0;
1721 header->unregistering = NULL;
1722 header->root = root;
1723 sysctl_set_parent(NULL, header->ctl_table);
1724 if (sysctl_check_table(namespaces, header->ctl_table)) {
1725 kfree(header);
1726 return NULL;
1728 spin_lock(&sysctl_lock);
1729 header_list = lookup_header_list(root, namespaces);
1730 list_add_tail(&header->ctl_entry, header_list);
1731 spin_unlock(&sysctl_lock);
1733 return header;
1737 * register_sysctl_table_path - register a sysctl table hierarchy
1738 * @path: The path to the directory the sysctl table is in.
1739 * @table: the top-level table structure
1741 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1742 * array. A completely 0 filled entry terminates the table.
1744 * See __register_sysctl_paths for more details.
1746 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1747 struct ctl_table *table)
1749 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1750 path, table);
1754 * register_sysctl_table - register a sysctl table hierarchy
1755 * @table: the top-level table structure
1757 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1758 * array. A completely 0 filled entry terminates the table.
1760 * See register_sysctl_paths for more details.
1762 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1764 static const struct ctl_path null_path[] = { {} };
1766 return register_sysctl_paths(null_path, table);
1770 * unregister_sysctl_table - unregister a sysctl table hierarchy
1771 * @header: the header returned from register_sysctl_table
1773 * Unregisters the sysctl table and all children. proc entries may not
1774 * actually be removed until they are no longer used by anyone.
1776 void unregister_sysctl_table(struct ctl_table_header * header)
1778 might_sleep();
1780 if (header == NULL)
1781 return;
1783 spin_lock(&sysctl_lock);
1784 start_unregistering(header);
1785 spin_unlock(&sysctl_lock);
1786 kfree(header);
1789 #else /* !CONFIG_SYSCTL */
1790 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1792 return NULL;
1795 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1796 struct ctl_table *table)
1798 return NULL;
1801 void unregister_sysctl_table(struct ctl_table_header * table)
1805 #endif /* CONFIG_SYSCTL */
1808 * /proc/sys support
1811 #ifdef CONFIG_PROC_SYSCTL
1813 static int _proc_do_string(void* data, int maxlen, int write,
1814 struct file *filp, void __user *buffer,
1815 size_t *lenp, loff_t *ppos)
1817 size_t len;
1818 char __user *p;
1819 char c;
1821 if (!data || !maxlen || !*lenp) {
1822 *lenp = 0;
1823 return 0;
1826 if (write) {
1827 len = 0;
1828 p = buffer;
1829 while (len < *lenp) {
1830 if (get_user(c, p++))
1831 return -EFAULT;
1832 if (c == 0 || c == '\n')
1833 break;
1834 len++;
1836 if (len >= maxlen)
1837 len = maxlen-1;
1838 if(copy_from_user(data, buffer, len))
1839 return -EFAULT;
1840 ((char *) data)[len] = 0;
1841 *ppos += *lenp;
1842 } else {
1843 len = strlen(data);
1844 if (len > maxlen)
1845 len = maxlen;
1847 if (*ppos > len) {
1848 *lenp = 0;
1849 return 0;
1852 data += *ppos;
1853 len -= *ppos;
1855 if (len > *lenp)
1856 len = *lenp;
1857 if (len)
1858 if(copy_to_user(buffer, data, len))
1859 return -EFAULT;
1860 if (len < *lenp) {
1861 if(put_user('\n', ((char __user *) buffer) + len))
1862 return -EFAULT;
1863 len++;
1865 *lenp = len;
1866 *ppos += len;
1868 return 0;
1872 * proc_dostring - read a string sysctl
1873 * @table: the sysctl table
1874 * @write: %TRUE if this is a write to the sysctl file
1875 * @filp: the file structure
1876 * @buffer: the user buffer
1877 * @lenp: the size of the user buffer
1878 * @ppos: file position
1880 * Reads/writes a string from/to the user buffer. If the kernel
1881 * buffer provided is not large enough to hold the string, the
1882 * string is truncated. The copied string is %NULL-terminated.
1883 * If the string is being read by the user process, it is copied
1884 * and a newline '\n' is added. It is truncated if the buffer is
1885 * not large enough.
1887 * Returns 0 on success.
1889 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1890 void __user *buffer, size_t *lenp, loff_t *ppos)
1892 return _proc_do_string(table->data, table->maxlen, write, filp,
1893 buffer, lenp, ppos);
1897 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1898 int *valp,
1899 int write, void *data)
1901 if (write) {
1902 *valp = *negp ? -*lvalp : *lvalp;
1903 } else {
1904 int val = *valp;
1905 if (val < 0) {
1906 *negp = -1;
1907 *lvalp = (unsigned long)-val;
1908 } else {
1909 *negp = 0;
1910 *lvalp = (unsigned long)val;
1913 return 0;
1916 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1917 int write, struct file *filp, void __user *buffer,
1918 size_t *lenp, loff_t *ppos,
1919 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1920 int write, void *data),
1921 void *data)
1923 #define TMPBUFLEN 21
1924 int *i, vleft, first=1, neg, val;
1925 unsigned long lval;
1926 size_t left, len;
1928 char buf[TMPBUFLEN], *p;
1929 char __user *s = buffer;
1931 if (!tbl_data || !table->maxlen || !*lenp ||
1932 (*ppos && !write)) {
1933 *lenp = 0;
1934 return 0;
1937 i = (int *) tbl_data;
1938 vleft = table->maxlen / sizeof(*i);
1939 left = *lenp;
1941 if (!conv)
1942 conv = do_proc_dointvec_conv;
1944 for (; left && vleft--; i++, first=0) {
1945 if (write) {
1946 while (left) {
1947 char c;
1948 if (get_user(c, s))
1949 return -EFAULT;
1950 if (!isspace(c))
1951 break;
1952 left--;
1953 s++;
1955 if (!left)
1956 break;
1957 neg = 0;
1958 len = left;
1959 if (len > sizeof(buf) - 1)
1960 len = sizeof(buf) - 1;
1961 if (copy_from_user(buf, s, len))
1962 return -EFAULT;
1963 buf[len] = 0;
1964 p = buf;
1965 if (*p == '-' && left > 1) {
1966 neg = 1;
1967 p++;
1969 if (*p < '0' || *p > '9')
1970 break;
1972 lval = simple_strtoul(p, &p, 0);
1974 len = p-buf;
1975 if ((len < left) && *p && !isspace(*p))
1976 break;
1977 if (neg)
1978 val = -val;
1979 s += len;
1980 left -= len;
1982 if (conv(&neg, &lval, i, 1, data))
1983 break;
1984 } else {
1985 p = buf;
1986 if (!first)
1987 *p++ = '\t';
1989 if (conv(&neg, &lval, i, 0, data))
1990 break;
1992 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1993 len = strlen(buf);
1994 if (len > left)
1995 len = left;
1996 if(copy_to_user(s, buf, len))
1997 return -EFAULT;
1998 left -= len;
1999 s += len;
2003 if (!write && !first && left) {
2004 if(put_user('\n', s))
2005 return -EFAULT;
2006 left--, s++;
2008 if (write) {
2009 while (left) {
2010 char c;
2011 if (get_user(c, s++))
2012 return -EFAULT;
2013 if (!isspace(c))
2014 break;
2015 left--;
2018 if (write && first)
2019 return -EINVAL;
2020 *lenp -= left;
2021 *ppos += *lenp;
2022 return 0;
2023 #undef TMPBUFLEN
2026 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2027 void __user *buffer, size_t *lenp, loff_t *ppos,
2028 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2029 int write, void *data),
2030 void *data)
2032 return __do_proc_dointvec(table->data, table, write, filp,
2033 buffer, lenp, ppos, conv, data);
2037 * proc_dointvec - read a vector of integers
2038 * @table: the sysctl table
2039 * @write: %TRUE if this is a write to the sysctl file
2040 * @filp: the file structure
2041 * @buffer: the user buffer
2042 * @lenp: the size of the user buffer
2043 * @ppos: file position
2045 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2046 * values from/to the user buffer, treated as an ASCII string.
2048 * Returns 0 on success.
2050 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2051 void __user *buffer, size_t *lenp, loff_t *ppos)
2053 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2054 NULL,NULL);
2057 #define OP_SET 0
2058 #define OP_AND 1
2059 #define OP_OR 2
2061 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2062 int *valp,
2063 int write, void *data)
2065 int op = *(int *)data;
2066 if (write) {
2067 int val = *negp ? -*lvalp : *lvalp;
2068 switch(op) {
2069 case OP_SET: *valp = val; break;
2070 case OP_AND: *valp &= val; break;
2071 case OP_OR: *valp |= val; break;
2073 } else {
2074 int val = *valp;
2075 if (val < 0) {
2076 *negp = -1;
2077 *lvalp = (unsigned long)-val;
2078 } else {
2079 *negp = 0;
2080 *lvalp = (unsigned long)val;
2083 return 0;
2087 * Taint values can only be increased
2089 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2090 void __user *buffer, size_t *lenp, loff_t *ppos)
2092 int op;
2094 if (write && !capable(CAP_SYS_ADMIN))
2095 return -EPERM;
2097 op = OP_OR;
2098 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2099 do_proc_dointvec_bset_conv,&op);
2102 struct do_proc_dointvec_minmax_conv_param {
2103 int *min;
2104 int *max;
2107 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2108 int *valp,
2109 int write, void *data)
2111 struct do_proc_dointvec_minmax_conv_param *param = data;
2112 if (write) {
2113 int val = *negp ? -*lvalp : *lvalp;
2114 if ((param->min && *param->min > val) ||
2115 (param->max && *param->max < val))
2116 return -EINVAL;
2117 *valp = val;
2118 } else {
2119 int val = *valp;
2120 if (val < 0) {
2121 *negp = -1;
2122 *lvalp = (unsigned long)-val;
2123 } else {
2124 *negp = 0;
2125 *lvalp = (unsigned long)val;
2128 return 0;
2132 * proc_dointvec_minmax - read a vector of integers with min/max values
2133 * @table: the sysctl table
2134 * @write: %TRUE if this is a write to the sysctl file
2135 * @filp: the file structure
2136 * @buffer: the user buffer
2137 * @lenp: the size of the user buffer
2138 * @ppos: file position
2140 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2141 * values from/to the user buffer, treated as an ASCII string.
2143 * This routine will ensure the values are within the range specified by
2144 * table->extra1 (min) and table->extra2 (max).
2146 * Returns 0 on success.
2148 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2149 void __user *buffer, size_t *lenp, loff_t *ppos)
2151 struct do_proc_dointvec_minmax_conv_param param = {
2152 .min = (int *) table->extra1,
2153 .max = (int *) table->extra2,
2155 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2156 do_proc_dointvec_minmax_conv, &param);
2159 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2160 struct file *filp,
2161 void __user *buffer,
2162 size_t *lenp, loff_t *ppos,
2163 unsigned long convmul,
2164 unsigned long convdiv)
2166 #define TMPBUFLEN 21
2167 unsigned long *i, *min, *max, val;
2168 int vleft, first=1, neg;
2169 size_t len, left;
2170 char buf[TMPBUFLEN], *p;
2171 char __user *s = buffer;
2173 if (!data || !table->maxlen || !*lenp ||
2174 (*ppos && !write)) {
2175 *lenp = 0;
2176 return 0;
2179 i = (unsigned long *) data;
2180 min = (unsigned long *) table->extra1;
2181 max = (unsigned long *) table->extra2;
2182 vleft = table->maxlen / sizeof(unsigned long);
2183 left = *lenp;
2185 for (; left && vleft--; i++, min++, max++, first=0) {
2186 if (write) {
2187 while (left) {
2188 char c;
2189 if (get_user(c, s))
2190 return -EFAULT;
2191 if (!isspace(c))
2192 break;
2193 left--;
2194 s++;
2196 if (!left)
2197 break;
2198 neg = 0;
2199 len = left;
2200 if (len > TMPBUFLEN-1)
2201 len = TMPBUFLEN-1;
2202 if (copy_from_user(buf, s, len))
2203 return -EFAULT;
2204 buf[len] = 0;
2205 p = buf;
2206 if (*p == '-' && left > 1) {
2207 neg = 1;
2208 p++;
2210 if (*p < '0' || *p > '9')
2211 break;
2212 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2213 len = p-buf;
2214 if ((len < left) && *p && !isspace(*p))
2215 break;
2216 if (neg)
2217 val = -val;
2218 s += len;
2219 left -= len;
2221 if(neg)
2222 continue;
2223 if ((min && val < *min) || (max && val > *max))
2224 continue;
2225 *i = val;
2226 } else {
2227 p = buf;
2228 if (!first)
2229 *p++ = '\t';
2230 sprintf(p, "%lu", convdiv * (*i) / convmul);
2231 len = strlen(buf);
2232 if (len > left)
2233 len = left;
2234 if(copy_to_user(s, buf, len))
2235 return -EFAULT;
2236 left -= len;
2237 s += len;
2241 if (!write && !first && left) {
2242 if(put_user('\n', s))
2243 return -EFAULT;
2244 left--, s++;
2246 if (write) {
2247 while (left) {
2248 char c;
2249 if (get_user(c, s++))
2250 return -EFAULT;
2251 if (!isspace(c))
2252 break;
2253 left--;
2256 if (write && first)
2257 return -EINVAL;
2258 *lenp -= left;
2259 *ppos += *lenp;
2260 return 0;
2261 #undef TMPBUFLEN
2264 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2265 struct file *filp,
2266 void __user *buffer,
2267 size_t *lenp, loff_t *ppos,
2268 unsigned long convmul,
2269 unsigned long convdiv)
2271 return __do_proc_doulongvec_minmax(table->data, table, write,
2272 filp, buffer, lenp, ppos, convmul, convdiv);
2276 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2277 * @table: the sysctl table
2278 * @write: %TRUE if this is a write to the sysctl file
2279 * @filp: the file structure
2280 * @buffer: the user buffer
2281 * @lenp: the size of the user buffer
2282 * @ppos: file position
2284 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2285 * values from/to the user buffer, treated as an ASCII string.
2287 * This routine will ensure the values are within the range specified by
2288 * table->extra1 (min) and table->extra2 (max).
2290 * Returns 0 on success.
2292 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2293 void __user *buffer, size_t *lenp, loff_t *ppos)
2295 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2299 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values 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. The values
2309 * are treated as milliseconds, and converted to jiffies when they are stored.
2311 * This routine will ensure the values are within the range specified by
2312 * table->extra1 (min) and table->extra2 (max).
2314 * Returns 0 on success.
2316 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2317 struct file *filp,
2318 void __user *buffer,
2319 size_t *lenp, loff_t *ppos)
2321 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2322 lenp, ppos, HZ, 1000l);
2326 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2327 int *valp,
2328 int write, void *data)
2330 if (write) {
2331 if (*lvalp > LONG_MAX / HZ)
2332 return 1;
2333 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2334 } else {
2335 int val = *valp;
2336 unsigned long lval;
2337 if (val < 0) {
2338 *negp = -1;
2339 lval = (unsigned long)-val;
2340 } else {
2341 *negp = 0;
2342 lval = (unsigned long)val;
2344 *lvalp = lval / HZ;
2346 return 0;
2349 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2350 int *valp,
2351 int write, void *data)
2353 if (write) {
2354 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2355 return 1;
2356 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
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 = jiffies_to_clock_t(lval);
2369 return 0;
2372 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2373 int *valp,
2374 int write, void *data)
2376 if (write) {
2377 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2378 } else {
2379 int val = *valp;
2380 unsigned long lval;
2381 if (val < 0) {
2382 *negp = -1;
2383 lval = (unsigned long)-val;
2384 } else {
2385 *negp = 0;
2386 lval = (unsigned long)val;
2388 *lvalp = jiffies_to_msecs(lval);
2390 return 0;
2394 * proc_dointvec_jiffies - read a vector of integers as seconds
2395 * @table: the sysctl table
2396 * @write: %TRUE if this is a write to the sysctl file
2397 * @filp: the file structure
2398 * @buffer: the user buffer
2399 * @lenp: the size of the user buffer
2400 * @ppos: file position
2402 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2403 * values from/to the user buffer, treated as an ASCII string.
2404 * The values read are assumed to be in seconds, and are converted into
2405 * jiffies.
2407 * Returns 0 on success.
2409 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2410 void __user *buffer, size_t *lenp, loff_t *ppos)
2412 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2413 do_proc_dointvec_jiffies_conv,NULL);
2417 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ 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: pointer to the 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 1/USER_HZ seconds, and
2428 * are converted into jiffies.
2430 * Returns 0 on success.
2432 int proc_dointvec_userhz_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_userhz_jiffies_conv,NULL);
2440 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
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: file position
2447 * @ppos: the current position in the file
2449 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2450 * values from/to the user buffer, treated as an ASCII string.
2451 * The values read are assumed to be in 1/1000 seconds, and
2452 * are converted into jiffies.
2454 * Returns 0 on success.
2456 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2457 void __user *buffer, size_t *lenp, loff_t *ppos)
2459 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2460 do_proc_dointvec_ms_jiffies_conv, NULL);
2463 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2464 void __user *buffer, size_t *lenp, loff_t *ppos)
2466 struct pid *new_pid;
2467 pid_t tmp;
2468 int r;
2470 tmp = pid_vnr(cad_pid);
2472 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2473 lenp, ppos, NULL, NULL);
2474 if (r || !write)
2475 return r;
2477 new_pid = find_get_pid(tmp);
2478 if (!new_pid)
2479 return -ESRCH;
2481 put_pid(xchg(&cad_pid, new_pid));
2482 return 0;
2485 #else /* CONFIG_PROC_FS */
2487 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2488 void __user *buffer, size_t *lenp, loff_t *ppos)
2490 return -ENOSYS;
2493 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2494 void __user *buffer, size_t *lenp, loff_t *ppos)
2496 return -ENOSYS;
2499 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2500 void __user *buffer, size_t *lenp, loff_t *ppos)
2502 return -ENOSYS;
2505 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2506 void __user *buffer, size_t *lenp, loff_t *ppos)
2508 return -ENOSYS;
2511 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2512 void __user *buffer, size_t *lenp, loff_t *ppos)
2514 return -ENOSYS;
2517 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2518 void __user *buffer, size_t *lenp, loff_t *ppos)
2520 return -ENOSYS;
2523 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2524 void __user *buffer, size_t *lenp, loff_t *ppos)
2526 return -ENOSYS;
2529 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2530 struct file *filp,
2531 void __user *buffer,
2532 size_t *lenp, loff_t *ppos)
2534 return -ENOSYS;
2538 #endif /* CONFIG_PROC_FS */
2541 #ifdef CONFIG_SYSCTL_SYSCALL
2543 * General sysctl support routines
2546 /* The generic sysctl data routine (used if no strategy routine supplied) */
2547 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2548 void __user *oldval, size_t __user *oldlenp,
2549 void __user *newval, size_t newlen)
2551 size_t len;
2553 /* Get out of I don't have a variable */
2554 if (!table->data || !table->maxlen)
2555 return -ENOTDIR;
2557 if (oldval && oldlenp) {
2558 if (get_user(len, oldlenp))
2559 return -EFAULT;
2560 if (len) {
2561 if (len > table->maxlen)
2562 len = table->maxlen;
2563 if (copy_to_user(oldval, table->data, len))
2564 return -EFAULT;
2565 if (put_user(len, oldlenp))
2566 return -EFAULT;
2570 if (newval && newlen) {
2571 if (newlen > table->maxlen)
2572 newlen = table->maxlen;
2574 if (copy_from_user(table->data, newval, newlen))
2575 return -EFAULT;
2577 return 1;
2580 /* The generic string strategy routine: */
2581 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2582 void __user *oldval, size_t __user *oldlenp,
2583 void __user *newval, size_t newlen)
2585 if (!table->data || !table->maxlen)
2586 return -ENOTDIR;
2588 if (oldval && oldlenp) {
2589 size_t bufsize;
2590 if (get_user(bufsize, oldlenp))
2591 return -EFAULT;
2592 if (bufsize) {
2593 size_t len = strlen(table->data), copied;
2595 /* This shouldn't trigger for a well-formed sysctl */
2596 if (len > table->maxlen)
2597 len = table->maxlen;
2599 /* Copy up to a max of bufsize-1 bytes of the string */
2600 copied = (len >= bufsize) ? bufsize - 1 : len;
2602 if (copy_to_user(oldval, table->data, copied) ||
2603 put_user(0, (char __user *)(oldval + copied)))
2604 return -EFAULT;
2605 if (put_user(len, oldlenp))
2606 return -EFAULT;
2609 if (newval && newlen) {
2610 size_t len = newlen;
2611 if (len > table->maxlen)
2612 len = table->maxlen;
2613 if(copy_from_user(table->data, newval, len))
2614 return -EFAULT;
2615 if (len == table->maxlen)
2616 len--;
2617 ((char *) table->data)[len] = 0;
2619 return 1;
2623 * This function makes sure that all of the integers in the vector
2624 * are between the minimum and maximum values given in the arrays
2625 * table->extra1 and table->extra2, respectively.
2627 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2628 void __user *oldval, size_t __user *oldlenp,
2629 void __user *newval, size_t newlen)
2632 if (newval && newlen) {
2633 int __user *vec = (int __user *) newval;
2634 int *min = (int *) table->extra1;
2635 int *max = (int *) table->extra2;
2636 size_t length;
2637 int i;
2639 if (newlen % sizeof(int) != 0)
2640 return -EINVAL;
2642 if (!table->extra1 && !table->extra2)
2643 return 0;
2645 if (newlen > table->maxlen)
2646 newlen = table->maxlen;
2647 length = newlen / sizeof(int);
2649 for (i = 0; i < length; i++) {
2650 int value;
2651 if (get_user(value, vec + i))
2652 return -EFAULT;
2653 if (min && value < min[i])
2654 return -EINVAL;
2655 if (max && value > max[i])
2656 return -EINVAL;
2659 return 0;
2662 /* Strategy function to convert jiffies to seconds */
2663 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2664 void __user *oldval, size_t __user *oldlenp,
2665 void __user *newval, size_t newlen)
2667 if (oldval && oldlenp) {
2668 size_t olen;
2670 if (get_user(olen, oldlenp))
2671 return -EFAULT;
2672 if (olen) {
2673 int val;
2675 if (olen < sizeof(int))
2676 return -EINVAL;
2678 val = *(int *)(table->data) / HZ;
2679 if (put_user(val, (int __user *)oldval))
2680 return -EFAULT;
2681 if (put_user(sizeof(int), oldlenp))
2682 return -EFAULT;
2685 if (newval && newlen) {
2686 int new;
2687 if (newlen != sizeof(int))
2688 return -EINVAL;
2689 if (get_user(new, (int __user *)newval))
2690 return -EFAULT;
2691 *(int *)(table->data) = new*HZ;
2693 return 1;
2696 /* Strategy function to convert jiffies to seconds */
2697 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2698 void __user *oldval, size_t __user *oldlenp,
2699 void __user *newval, size_t newlen)
2701 if (oldval && oldlenp) {
2702 size_t olen;
2704 if (get_user(olen, oldlenp))
2705 return -EFAULT;
2706 if (olen) {
2707 int val;
2709 if (olen < sizeof(int))
2710 return -EINVAL;
2712 val = jiffies_to_msecs(*(int *)(table->data));
2713 if (put_user(val, (int __user *)oldval))
2714 return -EFAULT;
2715 if (put_user(sizeof(int), oldlenp))
2716 return -EFAULT;
2719 if (newval && newlen) {
2720 int new;
2721 if (newlen != sizeof(int))
2722 return -EINVAL;
2723 if (get_user(new, (int __user *)newval))
2724 return -EFAULT;
2725 *(int *)(table->data) = msecs_to_jiffies(new);
2727 return 1;
2732 #else /* CONFIG_SYSCTL_SYSCALL */
2735 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2737 struct __sysctl_args tmp;
2738 int error;
2740 if (copy_from_user(&tmp, args, sizeof(tmp)))
2741 return -EFAULT;
2743 error = deprecated_sysctl_warning(&tmp);
2745 /* If no error reading the parameters then just -ENOSYS ... */
2746 if (!error)
2747 error = -ENOSYS;
2749 return error;
2752 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2753 void __user *oldval, size_t __user *oldlenp,
2754 void __user *newval, size_t newlen)
2756 return -ENOSYS;
2759 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2760 void __user *oldval, size_t __user *oldlenp,
2761 void __user *newval, size_t newlen)
2763 return -ENOSYS;
2766 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2767 void __user *oldval, size_t __user *oldlenp,
2768 void __user *newval, size_t newlen)
2770 return -ENOSYS;
2773 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2774 void __user *oldval, size_t __user *oldlenp,
2775 void __user *newval, size_t newlen)
2777 return -ENOSYS;
2780 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2781 void __user *oldval, size_t __user *oldlenp,
2782 void __user *newval, size_t newlen)
2784 return -ENOSYS;
2787 #endif /* CONFIG_SYSCTL_SYSCALL */
2789 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2791 static int msg_count;
2792 int name[CTL_MAXNAME];
2793 int i;
2795 /* Check args->nlen. */
2796 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2797 return -ENOTDIR;
2799 /* Read in the sysctl name for better debug message logging */
2800 for (i = 0; i < args->nlen; i++)
2801 if (get_user(name[i], args->name + i))
2802 return -EFAULT;
2804 /* Ignore accesses to kernel.version */
2805 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2806 return 0;
2808 if (msg_count < 5) {
2809 msg_count++;
2810 printk(KERN_INFO
2811 "warning: process `%s' used the deprecated sysctl "
2812 "system call with ", current->comm);
2813 for (i = 0; i < args->nlen; i++)
2814 printk("%d.", name[i]);
2815 printk("\n");
2817 return 0;
2821 * No sense putting this after each symbol definition, twice,
2822 * exception granted :-)
2824 EXPORT_SYMBOL(proc_dointvec);
2825 EXPORT_SYMBOL(proc_dointvec_jiffies);
2826 EXPORT_SYMBOL(proc_dointvec_minmax);
2827 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2828 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2829 EXPORT_SYMBOL(proc_dostring);
2830 EXPORT_SYMBOL(proc_doulongvec_minmax);
2831 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2832 EXPORT_SYMBOL(register_sysctl_table);
2833 EXPORT_SYMBOL(register_sysctl_paths);
2834 EXPORT_SYMBOL(sysctl_intvec);
2835 EXPORT_SYMBOL(sysctl_jiffies);
2836 EXPORT_SYMBOL(sysctl_ms_jiffies);
2837 EXPORT_SYMBOL(sysctl_string);
2838 EXPORT_SYMBOL(sysctl_data);
2839 EXPORT_SYMBOL(unregister_sysctl_table);