sched: cleanup, use NSEC_PER_MSEC and NSEC_PER_SEC
[linux-2.6/mini2440.git] / kernel / sysctl.c
blobadddf682d4cbedf5a1017aa0f7d7ec713915e2c5
1 /*
2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
31 #include <linux/fs.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
53 #ifdef CONFIG_X86
54 #include <asm/nmi.h>
55 #include <asm/stacktrace.h>
56 #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 max_threads;
70 extern int core_uses_pid;
71 extern int suid_dumpable;
72 extern char core_pattern[];
73 extern int pid_max;
74 extern int min_free_kbytes;
75 extern int printk_ratelimit_jiffies;
76 extern int printk_ratelimit_burst;
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 audit_argv_kb;
85 /* Constants used for minimum and maximum */
86 #ifdef CONFIG_DETECT_SOFTLOCKUP
87 static int one = 1;
88 static int sixty = 60;
89 #endif
91 #ifdef CONFIG_MMU
92 static int two = 2;
93 #endif
95 static int zero;
96 static int one_hundred = 100;
98 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
99 static int maxolduid = 65535;
100 static int minolduid;
101 static int min_percpu_pagelist_fract = 8;
103 static int ngroups_max = NGROUPS_MAX;
105 #ifdef CONFIG_KMOD
106 extern char modprobe_path[];
107 #endif
108 #ifdef CONFIG_CHR_DEV_SG
109 extern int sg_big_buff;
110 #endif
112 #ifdef __sparc__
113 extern char reboot_command [];
114 extern int stop_a_enabled;
115 extern int scons_pwroff;
116 #endif
118 #ifdef __hppa__
119 extern int pwrsw_enabled;
120 extern int unaligned_enabled;
121 #endif
123 #ifdef CONFIG_S390
124 #ifdef CONFIG_MATHEMU
125 extern int sysctl_ieee_emulation_warnings;
126 #endif
127 extern int sysctl_userprocess_debug;
128 extern int spin_retry;
129 #endif
131 extern int sysctl_hz_timer;
133 #ifdef CONFIG_BSD_PROCESS_ACCT
134 extern int acct_parm[];
135 #endif
137 #ifdef CONFIG_IA64
138 extern int no_unaligned_warning;
139 #endif
141 #ifdef CONFIG_RT_MUTEXES
142 extern int max_lock_depth;
143 #endif
145 #ifdef CONFIG_SYSCTL_SYSCALL
146 static int parse_table(int __user *, int, void __user *, size_t __user *,
147 void __user *, size_t, struct ctl_table *);
148 #endif
151 #ifdef CONFIG_PROC_SYSCTL
152 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
153 void __user *buffer, size_t *lenp, loff_t *ppos);
154 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
155 void __user *buffer, size_t *lenp, loff_t *ppos);
156 #endif
158 static struct ctl_table root_table[];
159 static struct ctl_table_header root_table_header =
160 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
162 static struct ctl_table kern_table[];
163 static struct ctl_table vm_table[];
164 static struct ctl_table fs_table[];
165 static struct ctl_table debug_table[];
166 static struct ctl_table dev_table[];
167 extern struct ctl_table random_table[];
168 #ifdef CONFIG_INOTIFY_USER
169 extern struct ctl_table inotify_table[];
170 #endif
172 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
173 int sysctl_legacy_va_layout;
174 #endif
176 extern int prove_locking;
177 extern int lock_stat;
179 /* The default sysctl tables: */
181 static struct ctl_table root_table[] = {
183 .ctl_name = CTL_KERN,
184 .procname = "kernel",
185 .mode = 0555,
186 .child = kern_table,
189 .ctl_name = CTL_VM,
190 .procname = "vm",
191 .mode = 0555,
192 .child = vm_table,
194 #ifdef CONFIG_NET
196 .ctl_name = CTL_NET,
197 .procname = "net",
198 .mode = 0555,
199 .child = net_table,
201 #endif
203 .ctl_name = CTL_FS,
204 .procname = "fs",
205 .mode = 0555,
206 .child = fs_table,
209 .ctl_name = CTL_DEBUG,
210 .procname = "debug",
211 .mode = 0555,
212 .child = debug_table,
215 .ctl_name = CTL_DEV,
216 .procname = "dev",
217 .mode = 0555,
218 .child = dev_table,
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
224 { .ctl_name = 0 }
227 #ifdef CONFIG_SCHED_DEBUG
228 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
229 static unsigned long max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
231 static unsigned long max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
232 #endif
234 static struct ctl_table kern_table[] = {
235 #ifdef CONFIG_SCHED_DEBUG
237 .ctl_name = CTL_UNNUMBERED,
238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
240 .maxlen = sizeof(unsigned int),
241 .mode = 0644,
242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
248 .ctl_name = CTL_UNNUMBERED,
249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
259 .ctl_name = CTL_UNNUMBERED,
260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "sched_batch_wakeup_granularity_ns",
272 .data = &sysctl_sched_batch_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
281 .ctl_name = CTL_UNNUMBERED,
282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_features",
291 .data = &sysctl_sched_features,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec,
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_migration_cost",
299 .data = &sysctl_sched_migration_cost,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
302 .proc_handler = &proc_dointvec,
304 #endif
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_compat_yield",
308 .data = &sysctl_sched_compat_yield,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
311 .proc_handler = &proc_dointvec,
313 #ifdef CONFIG_PROVE_LOCKING
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "prove_locking",
317 .data = &prove_locking,
318 .maxlen = sizeof(int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
322 #endif
323 #ifdef CONFIG_LOCK_STAT
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "lock_stat",
327 .data = &lock_stat,
328 .maxlen = sizeof(int),
329 .mode = 0644,
330 .proc_handler = &proc_dointvec,
332 #endif
334 .ctl_name = KERN_PANIC,
335 .procname = "panic",
336 .data = &panic_timeout,
337 .maxlen = sizeof(int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
342 .ctl_name = KERN_CORE_USES_PID,
343 .procname = "core_uses_pid",
344 .data = &core_uses_pid,
345 .maxlen = sizeof(int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
349 #ifdef CONFIG_AUDITSYSCALL
351 .ctl_name = CTL_UNNUMBERED,
352 .procname = "audit_argv_kb",
353 .data = &audit_argv_kb,
354 .maxlen = sizeof(int),
355 .mode = 0644,
356 .proc_handler = &proc_dointvec,
358 #endif
360 .ctl_name = KERN_CORE_PATTERN,
361 .procname = "core_pattern",
362 .data = core_pattern,
363 .maxlen = CORENAME_MAX_SIZE,
364 .mode = 0644,
365 .proc_handler = &proc_dostring,
366 .strategy = &sysctl_string,
368 #ifdef CONFIG_PROC_SYSCTL
370 .procname = "tainted",
371 .data = &tainted,
372 .maxlen = sizeof(int),
373 .mode = 0644,
374 .proc_handler = &proc_dointvec_taint,
376 #endif
377 #ifdef CONFIG_SECURITY_CAPABILITIES
379 .procname = "cap-bound",
380 .data = &cap_bset,
381 .maxlen = sizeof(kernel_cap_t),
382 .mode = 0600,
383 .proc_handler = &proc_dointvec_bset,
385 #endif /* def CONFIG_SECURITY_CAPABILITIES */
386 #ifdef CONFIG_BLK_DEV_INITRD
388 .ctl_name = KERN_REALROOTDEV,
389 .procname = "real-root-dev",
390 .data = &real_root_dev,
391 .maxlen = sizeof(int),
392 .mode = 0644,
393 .proc_handler = &proc_dointvec,
395 #endif
397 .ctl_name = CTL_UNNUMBERED,
398 .procname = "print-fatal-signals",
399 .data = &print_fatal_signals,
400 .maxlen = sizeof(int),
401 .mode = 0644,
402 .proc_handler = &proc_dointvec,
404 #ifdef __sparc__
406 .ctl_name = KERN_SPARC_REBOOT,
407 .procname = "reboot-cmd",
408 .data = reboot_command,
409 .maxlen = 256,
410 .mode = 0644,
411 .proc_handler = &proc_dostring,
412 .strategy = &sysctl_string,
415 .ctl_name = KERN_SPARC_STOP_A,
416 .procname = "stop-a",
417 .data = &stop_a_enabled,
418 .maxlen = sizeof (int),
419 .mode = 0644,
420 .proc_handler = &proc_dointvec,
423 .ctl_name = KERN_SPARC_SCONS_PWROFF,
424 .procname = "scons-poweroff",
425 .data = &scons_pwroff,
426 .maxlen = sizeof (int),
427 .mode = 0644,
428 .proc_handler = &proc_dointvec,
430 #endif
431 #ifdef __hppa__
433 .ctl_name = KERN_HPPA_PWRSW,
434 .procname = "soft-power",
435 .data = &pwrsw_enabled,
436 .maxlen = sizeof (int),
437 .mode = 0644,
438 .proc_handler = &proc_dointvec,
441 .ctl_name = KERN_HPPA_UNALIGNED,
442 .procname = "unaligned-trap",
443 .data = &unaligned_enabled,
444 .maxlen = sizeof (int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
448 #endif
450 .ctl_name = KERN_CTLALTDEL,
451 .procname = "ctrl-alt-del",
452 .data = &C_A_D,
453 .maxlen = sizeof(int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
458 .ctl_name = KERN_PRINTK,
459 .procname = "printk",
460 .data = &console_loglevel,
461 .maxlen = 4*sizeof(int),
462 .mode = 0644,
463 .proc_handler = &proc_dointvec,
465 #ifdef CONFIG_KMOD
467 .ctl_name = KERN_MODPROBE,
468 .procname = "modprobe",
469 .data = &modprobe_path,
470 .maxlen = KMOD_PATH_LEN,
471 .mode = 0644,
472 .proc_handler = &proc_dostring,
473 .strategy = &sysctl_string,
475 #endif
476 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
478 .ctl_name = KERN_HOTPLUG,
479 .procname = "hotplug",
480 .data = &uevent_helper,
481 .maxlen = UEVENT_HELPER_PATH_LEN,
482 .mode = 0644,
483 .proc_handler = &proc_dostring,
484 .strategy = &sysctl_string,
486 #endif
487 #ifdef CONFIG_CHR_DEV_SG
489 .ctl_name = KERN_SG_BIG_BUFF,
490 .procname = "sg-big-buff",
491 .data = &sg_big_buff,
492 .maxlen = sizeof (int),
493 .mode = 0444,
494 .proc_handler = &proc_dointvec,
496 #endif
497 #ifdef CONFIG_BSD_PROCESS_ACCT
499 .ctl_name = KERN_ACCT,
500 .procname = "acct",
501 .data = &acct_parm,
502 .maxlen = 3*sizeof(int),
503 .mode = 0644,
504 .proc_handler = &proc_dointvec,
506 #endif
507 #ifdef CONFIG_MAGIC_SYSRQ
509 .ctl_name = KERN_SYSRQ,
510 .procname = "sysrq",
511 .data = &__sysrq_enabled,
512 .maxlen = sizeof (int),
513 .mode = 0644,
514 .proc_handler = &proc_dointvec,
516 #endif
517 #ifdef CONFIG_PROC_SYSCTL
519 .procname = "cad_pid",
520 .data = NULL,
521 .maxlen = sizeof (int),
522 .mode = 0600,
523 .proc_handler = &proc_do_cad_pid,
525 #endif
527 .ctl_name = KERN_MAX_THREADS,
528 .procname = "threads-max",
529 .data = &max_threads,
530 .maxlen = sizeof(int),
531 .mode = 0644,
532 .proc_handler = &proc_dointvec,
535 .ctl_name = KERN_RANDOM,
536 .procname = "random",
537 .mode = 0555,
538 .child = random_table,
541 .ctl_name = KERN_OVERFLOWUID,
542 .procname = "overflowuid",
543 .data = &overflowuid,
544 .maxlen = sizeof(int),
545 .mode = 0644,
546 .proc_handler = &proc_dointvec_minmax,
547 .strategy = &sysctl_intvec,
548 .extra1 = &minolduid,
549 .extra2 = &maxolduid,
552 .ctl_name = KERN_OVERFLOWGID,
553 .procname = "overflowgid",
554 .data = &overflowgid,
555 .maxlen = sizeof(int),
556 .mode = 0644,
557 .proc_handler = &proc_dointvec_minmax,
558 .strategy = &sysctl_intvec,
559 .extra1 = &minolduid,
560 .extra2 = &maxolduid,
562 #ifdef CONFIG_S390
563 #ifdef CONFIG_MATHEMU
565 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
566 .procname = "ieee_emulation_warnings",
567 .data = &sysctl_ieee_emulation_warnings,
568 .maxlen = sizeof(int),
569 .mode = 0644,
570 .proc_handler = &proc_dointvec,
572 #endif
573 #ifdef CONFIG_NO_IDLE_HZ
575 .ctl_name = KERN_HZ_TIMER,
576 .procname = "hz_timer",
577 .data = &sysctl_hz_timer,
578 .maxlen = sizeof(int),
579 .mode = 0644,
580 .proc_handler = &proc_dointvec,
582 #endif
584 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
585 .procname = "userprocess_debug",
586 .data = &sysctl_userprocess_debug,
587 .maxlen = sizeof(int),
588 .mode = 0644,
589 .proc_handler = &proc_dointvec,
591 #endif
593 .ctl_name = KERN_PIDMAX,
594 .procname = "pid_max",
595 .data = &pid_max,
596 .maxlen = sizeof (int),
597 .mode = 0644,
598 .proc_handler = &proc_dointvec_minmax,
599 .strategy = sysctl_intvec,
600 .extra1 = &pid_max_min,
601 .extra2 = &pid_max_max,
604 .ctl_name = KERN_PANIC_ON_OOPS,
605 .procname = "panic_on_oops",
606 .data = &panic_on_oops,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec,
612 .ctl_name = KERN_PRINTK_RATELIMIT,
613 .procname = "printk_ratelimit",
614 .data = &printk_ratelimit_jiffies,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = &proc_dointvec_jiffies,
618 .strategy = &sysctl_jiffies,
621 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
622 .procname = "printk_ratelimit_burst",
623 .data = &printk_ratelimit_burst,
624 .maxlen = sizeof(int),
625 .mode = 0644,
626 .proc_handler = &proc_dointvec,
629 .ctl_name = KERN_NGROUPS_MAX,
630 .procname = "ngroups_max",
631 .data = &ngroups_max,
632 .maxlen = sizeof (int),
633 .mode = 0444,
634 .proc_handler = &proc_dointvec,
636 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
638 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
639 .procname = "unknown_nmi_panic",
640 .data = &unknown_nmi_panic,
641 .maxlen = sizeof (int),
642 .mode = 0644,
643 .proc_handler = &proc_dointvec,
646 .procname = "nmi_watchdog",
647 .data = &nmi_watchdog_enabled,
648 .maxlen = sizeof (int),
649 .mode = 0644,
650 .proc_handler = &proc_nmi_enabled,
652 #endif
653 #if defined(CONFIG_X86)
655 .ctl_name = KERN_PANIC_ON_NMI,
656 .procname = "panic_on_unrecovered_nmi",
657 .data = &panic_on_unrecovered_nmi,
658 .maxlen = sizeof(int),
659 .mode = 0644,
660 .proc_handler = &proc_dointvec,
663 .ctl_name = KERN_BOOTLOADER_TYPE,
664 .procname = "bootloader_type",
665 .data = &bootloader_type,
666 .maxlen = sizeof (int),
667 .mode = 0444,
668 .proc_handler = &proc_dointvec,
671 .ctl_name = CTL_UNNUMBERED,
672 .procname = "kstack_depth_to_print",
673 .data = &kstack_depth_to_print,
674 .maxlen = sizeof(int),
675 .mode = 0644,
676 .proc_handler = &proc_dointvec,
678 #endif
679 #if defined(CONFIG_MMU)
681 .ctl_name = KERN_RANDOMIZE,
682 .procname = "randomize_va_space",
683 .data = &randomize_va_space,
684 .maxlen = sizeof(int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec,
688 #endif
689 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
691 .ctl_name = KERN_SPIN_RETRY,
692 .procname = "spin_retry",
693 .data = &spin_retry,
694 .maxlen = sizeof (int),
695 .mode = 0644,
696 .proc_handler = &proc_dointvec,
698 #endif
699 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
701 .procname = "acpi_video_flags",
702 .data = &acpi_realmode_flags,
703 .maxlen = sizeof (unsigned long),
704 .mode = 0644,
705 .proc_handler = &proc_doulongvec_minmax,
707 #endif
708 #ifdef CONFIG_IA64
710 .ctl_name = KERN_IA64_UNALIGNED,
711 .procname = "ignore-unaligned-usertrap",
712 .data = &no_unaligned_warning,
713 .maxlen = sizeof (int),
714 .mode = 0644,
715 .proc_handler = &proc_dointvec,
717 #endif
718 #ifdef CONFIG_DETECT_SOFTLOCKUP
720 .ctl_name = CTL_UNNUMBERED,
721 .procname = "softlockup_thresh",
722 .data = &softlockup_thresh,
723 .maxlen = sizeof(int),
724 .mode = 0644,
725 .proc_handler = &proc_dointvec_minmax,
726 .strategy = &sysctl_intvec,
727 .extra1 = &one,
728 .extra2 = &sixty,
730 #endif
731 #ifdef CONFIG_COMPAT
733 .ctl_name = KERN_COMPAT_LOG,
734 .procname = "compat-log",
735 .data = &compat_log,
736 .maxlen = sizeof (int),
737 .mode = 0644,
738 .proc_handler = &proc_dointvec,
740 #endif
741 #ifdef CONFIG_RT_MUTEXES
743 .ctl_name = KERN_MAX_LOCK_DEPTH,
744 .procname = "max_lock_depth",
745 .data = &max_lock_depth,
746 .maxlen = sizeof(int),
747 .mode = 0644,
748 .proc_handler = &proc_dointvec,
750 #endif
751 #ifdef CONFIG_PROC_FS
753 .ctl_name = CTL_UNNUMBERED,
754 .procname = "maps_protect",
755 .data = &maps_protect,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = &proc_dointvec,
760 #endif
762 .ctl_name = CTL_UNNUMBERED,
763 .procname = "poweroff_cmd",
764 .data = &poweroff_cmd,
765 .maxlen = POWEROFF_CMD_PATH_LEN,
766 .mode = 0644,
767 .proc_handler = &proc_dostring,
768 .strategy = &sysctl_string,
771 * NOTE: do not add new entries to this table unless you have read
772 * Documentation/sysctl/ctl_unnumbered.txt
774 { .ctl_name = 0 }
777 static struct ctl_table vm_table[] = {
779 .ctl_name = VM_OVERCOMMIT_MEMORY,
780 .procname = "overcommit_memory",
781 .data = &sysctl_overcommit_memory,
782 .maxlen = sizeof(sysctl_overcommit_memory),
783 .mode = 0644,
784 .proc_handler = &proc_dointvec,
787 .ctl_name = VM_PANIC_ON_OOM,
788 .procname = "panic_on_oom",
789 .data = &sysctl_panic_on_oom,
790 .maxlen = sizeof(sysctl_panic_on_oom),
791 .mode = 0644,
792 .proc_handler = &proc_dointvec,
795 .ctl_name = CTL_UNNUMBERED,
796 .procname = "oom_kill_allocating_task",
797 .data = &sysctl_oom_kill_allocating_task,
798 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
799 .mode = 0644,
800 .proc_handler = &proc_dointvec,
803 .ctl_name = VM_OVERCOMMIT_RATIO,
804 .procname = "overcommit_ratio",
805 .data = &sysctl_overcommit_ratio,
806 .maxlen = sizeof(sysctl_overcommit_ratio),
807 .mode = 0644,
808 .proc_handler = &proc_dointvec,
811 .ctl_name = VM_PAGE_CLUSTER,
812 .procname = "page-cluster",
813 .data = &page_cluster,
814 .maxlen = sizeof(int),
815 .mode = 0644,
816 .proc_handler = &proc_dointvec,
819 .ctl_name = VM_DIRTY_BACKGROUND,
820 .procname = "dirty_background_ratio",
821 .data = &dirty_background_ratio,
822 .maxlen = sizeof(dirty_background_ratio),
823 .mode = 0644,
824 .proc_handler = &proc_dointvec_minmax,
825 .strategy = &sysctl_intvec,
826 .extra1 = &zero,
827 .extra2 = &one_hundred,
830 .ctl_name = VM_DIRTY_RATIO,
831 .procname = "dirty_ratio",
832 .data = &vm_dirty_ratio,
833 .maxlen = sizeof(vm_dirty_ratio),
834 .mode = 0644,
835 .proc_handler = &dirty_ratio_handler,
836 .strategy = &sysctl_intvec,
837 .extra1 = &zero,
838 .extra2 = &one_hundred,
841 .procname = "dirty_writeback_centisecs",
842 .data = &dirty_writeback_interval,
843 .maxlen = sizeof(dirty_writeback_interval),
844 .mode = 0644,
845 .proc_handler = &dirty_writeback_centisecs_handler,
848 .procname = "dirty_expire_centisecs",
849 .data = &dirty_expire_interval,
850 .maxlen = sizeof(dirty_expire_interval),
851 .mode = 0644,
852 .proc_handler = &proc_dointvec_userhz_jiffies,
855 .ctl_name = VM_NR_PDFLUSH_THREADS,
856 .procname = "nr_pdflush_threads",
857 .data = &nr_pdflush_threads,
858 .maxlen = sizeof nr_pdflush_threads,
859 .mode = 0444 /* read-only*/,
860 .proc_handler = &proc_dointvec,
863 .ctl_name = VM_SWAPPINESS,
864 .procname = "swappiness",
865 .data = &vm_swappiness,
866 .maxlen = sizeof(vm_swappiness),
867 .mode = 0644,
868 .proc_handler = &proc_dointvec_minmax,
869 .strategy = &sysctl_intvec,
870 .extra1 = &zero,
871 .extra2 = &one_hundred,
873 #ifdef CONFIG_HUGETLB_PAGE
875 .procname = "nr_hugepages",
876 .data = &max_huge_pages,
877 .maxlen = sizeof(unsigned long),
878 .mode = 0644,
879 .proc_handler = &hugetlb_sysctl_handler,
880 .extra1 = (void *)&hugetlb_zero,
881 .extra2 = (void *)&hugetlb_infinity,
884 .ctl_name = VM_HUGETLB_GROUP,
885 .procname = "hugetlb_shm_group",
886 .data = &sysctl_hugetlb_shm_group,
887 .maxlen = sizeof(gid_t),
888 .mode = 0644,
889 .proc_handler = &proc_dointvec,
892 .ctl_name = CTL_UNNUMBERED,
893 .procname = "hugepages_treat_as_movable",
894 .data = &hugepages_treat_as_movable,
895 .maxlen = sizeof(int),
896 .mode = 0644,
897 .proc_handler = &hugetlb_treat_movable_handler,
900 .ctl_name = CTL_UNNUMBERED,
901 .procname = "hugetlb_dynamic_pool",
902 .data = &hugetlb_dynamic_pool,
903 .maxlen = sizeof(hugetlb_dynamic_pool),
904 .mode = 0644,
905 .proc_handler = &proc_dointvec,
907 #endif
909 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
910 .procname = "lowmem_reserve_ratio",
911 .data = &sysctl_lowmem_reserve_ratio,
912 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
913 .mode = 0644,
914 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
915 .strategy = &sysctl_intvec,
918 .ctl_name = VM_DROP_PAGECACHE,
919 .procname = "drop_caches",
920 .data = &sysctl_drop_caches,
921 .maxlen = sizeof(int),
922 .mode = 0644,
923 .proc_handler = drop_caches_sysctl_handler,
924 .strategy = &sysctl_intvec,
927 .ctl_name = VM_MIN_FREE_KBYTES,
928 .procname = "min_free_kbytes",
929 .data = &min_free_kbytes,
930 .maxlen = sizeof(min_free_kbytes),
931 .mode = 0644,
932 .proc_handler = &min_free_kbytes_sysctl_handler,
933 .strategy = &sysctl_intvec,
934 .extra1 = &zero,
937 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
938 .procname = "percpu_pagelist_fraction",
939 .data = &percpu_pagelist_fraction,
940 .maxlen = sizeof(percpu_pagelist_fraction),
941 .mode = 0644,
942 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
943 .strategy = &sysctl_intvec,
944 .extra1 = &min_percpu_pagelist_fract,
946 #ifdef CONFIG_MMU
948 .ctl_name = VM_MAX_MAP_COUNT,
949 .procname = "max_map_count",
950 .data = &sysctl_max_map_count,
951 .maxlen = sizeof(sysctl_max_map_count),
952 .mode = 0644,
953 .proc_handler = &proc_dointvec
955 #endif
957 .ctl_name = VM_LAPTOP_MODE,
958 .procname = "laptop_mode",
959 .data = &laptop_mode,
960 .maxlen = sizeof(laptop_mode),
961 .mode = 0644,
962 .proc_handler = &proc_dointvec_jiffies,
963 .strategy = &sysctl_jiffies,
966 .ctl_name = VM_BLOCK_DUMP,
967 .procname = "block_dump",
968 .data = &block_dump,
969 .maxlen = sizeof(block_dump),
970 .mode = 0644,
971 .proc_handler = &proc_dointvec,
972 .strategy = &sysctl_intvec,
973 .extra1 = &zero,
976 .ctl_name = VM_VFS_CACHE_PRESSURE,
977 .procname = "vfs_cache_pressure",
978 .data = &sysctl_vfs_cache_pressure,
979 .maxlen = sizeof(sysctl_vfs_cache_pressure),
980 .mode = 0644,
981 .proc_handler = &proc_dointvec,
982 .strategy = &sysctl_intvec,
983 .extra1 = &zero,
985 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
987 .ctl_name = VM_LEGACY_VA_LAYOUT,
988 .procname = "legacy_va_layout",
989 .data = &sysctl_legacy_va_layout,
990 .maxlen = sizeof(sysctl_legacy_va_layout),
991 .mode = 0644,
992 .proc_handler = &proc_dointvec,
993 .strategy = &sysctl_intvec,
994 .extra1 = &zero,
996 #endif
997 #ifdef CONFIG_NUMA
999 .ctl_name = VM_ZONE_RECLAIM_MODE,
1000 .procname = "zone_reclaim_mode",
1001 .data = &zone_reclaim_mode,
1002 .maxlen = sizeof(zone_reclaim_mode),
1003 .mode = 0644,
1004 .proc_handler = &proc_dointvec,
1005 .strategy = &sysctl_intvec,
1006 .extra1 = &zero,
1009 .ctl_name = VM_MIN_UNMAPPED,
1010 .procname = "min_unmapped_ratio",
1011 .data = &sysctl_min_unmapped_ratio,
1012 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1013 .mode = 0644,
1014 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1015 .strategy = &sysctl_intvec,
1016 .extra1 = &zero,
1017 .extra2 = &one_hundred,
1020 .ctl_name = VM_MIN_SLAB,
1021 .procname = "min_slab_ratio",
1022 .data = &sysctl_min_slab_ratio,
1023 .maxlen = sizeof(sysctl_min_slab_ratio),
1024 .mode = 0644,
1025 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1026 .strategy = &sysctl_intvec,
1027 .extra1 = &zero,
1028 .extra2 = &one_hundred,
1030 #endif
1031 #ifdef CONFIG_SMP
1033 .ctl_name = CTL_UNNUMBERED,
1034 .procname = "stat_interval",
1035 .data = &sysctl_stat_interval,
1036 .maxlen = sizeof(sysctl_stat_interval),
1037 .mode = 0644,
1038 .proc_handler = &proc_dointvec_jiffies,
1039 .strategy = &sysctl_jiffies,
1041 #endif
1042 #ifdef CONFIG_SECURITY
1044 .ctl_name = CTL_UNNUMBERED,
1045 .procname = "mmap_min_addr",
1046 .data = &mmap_min_addr,
1047 .maxlen = sizeof(unsigned long),
1048 .mode = 0644,
1049 .proc_handler = &proc_doulongvec_minmax,
1051 #endif
1052 #ifdef CONFIG_NUMA
1054 .ctl_name = CTL_UNNUMBERED,
1055 .procname = "numa_zonelist_order",
1056 .data = &numa_zonelist_order,
1057 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1058 .mode = 0644,
1059 .proc_handler = &numa_zonelist_order_handler,
1060 .strategy = &sysctl_string,
1062 #endif
1063 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1064 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1066 .ctl_name = VM_VDSO_ENABLED,
1067 .procname = "vdso_enabled",
1068 .data = &vdso_enabled,
1069 .maxlen = sizeof(vdso_enabled),
1070 .mode = 0644,
1071 .proc_handler = &proc_dointvec,
1072 .strategy = &sysctl_intvec,
1073 .extra1 = &zero,
1075 #endif
1077 * NOTE: do not add new entries to this table unless you have read
1078 * Documentation/sysctl/ctl_unnumbered.txt
1080 { .ctl_name = 0 }
1083 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1084 static struct ctl_table binfmt_misc_table[] = {
1085 { .ctl_name = 0 }
1087 #endif
1089 static struct ctl_table fs_table[] = {
1091 .ctl_name = FS_NRINODE,
1092 .procname = "inode-nr",
1093 .data = &inodes_stat,
1094 .maxlen = 2*sizeof(int),
1095 .mode = 0444,
1096 .proc_handler = &proc_dointvec,
1099 .ctl_name = FS_STATINODE,
1100 .procname = "inode-state",
1101 .data = &inodes_stat,
1102 .maxlen = 7*sizeof(int),
1103 .mode = 0444,
1104 .proc_handler = &proc_dointvec,
1107 .procname = "file-nr",
1108 .data = &files_stat,
1109 .maxlen = 3*sizeof(int),
1110 .mode = 0444,
1111 .proc_handler = &proc_nr_files,
1114 .ctl_name = FS_MAXFILE,
1115 .procname = "file-max",
1116 .data = &files_stat.max_files,
1117 .maxlen = sizeof(int),
1118 .mode = 0644,
1119 .proc_handler = &proc_dointvec,
1122 .ctl_name = FS_DENTRY,
1123 .procname = "dentry-state",
1124 .data = &dentry_stat,
1125 .maxlen = 6*sizeof(int),
1126 .mode = 0444,
1127 .proc_handler = &proc_dointvec,
1130 .ctl_name = FS_OVERFLOWUID,
1131 .procname = "overflowuid",
1132 .data = &fs_overflowuid,
1133 .maxlen = sizeof(int),
1134 .mode = 0644,
1135 .proc_handler = &proc_dointvec_minmax,
1136 .strategy = &sysctl_intvec,
1137 .extra1 = &minolduid,
1138 .extra2 = &maxolduid,
1141 .ctl_name = FS_OVERFLOWGID,
1142 .procname = "overflowgid",
1143 .data = &fs_overflowgid,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = &proc_dointvec_minmax,
1147 .strategy = &sysctl_intvec,
1148 .extra1 = &minolduid,
1149 .extra2 = &maxolduid,
1152 .ctl_name = FS_LEASES,
1153 .procname = "leases-enable",
1154 .data = &leases_enable,
1155 .maxlen = sizeof(int),
1156 .mode = 0644,
1157 .proc_handler = &proc_dointvec,
1159 #ifdef CONFIG_DNOTIFY
1161 .ctl_name = FS_DIR_NOTIFY,
1162 .procname = "dir-notify-enable",
1163 .data = &dir_notify_enable,
1164 .maxlen = sizeof(int),
1165 .mode = 0644,
1166 .proc_handler = &proc_dointvec,
1168 #endif
1169 #ifdef CONFIG_MMU
1171 .ctl_name = FS_LEASE_TIME,
1172 .procname = "lease-break-time",
1173 .data = &lease_break_time,
1174 .maxlen = sizeof(int),
1175 .mode = 0644,
1176 .proc_handler = &proc_dointvec_minmax,
1177 .strategy = &sysctl_intvec,
1178 .extra1 = &zero,
1179 .extra2 = &two,
1182 .procname = "aio-nr",
1183 .data = &aio_nr,
1184 .maxlen = sizeof(aio_nr),
1185 .mode = 0444,
1186 .proc_handler = &proc_doulongvec_minmax,
1189 .procname = "aio-max-nr",
1190 .data = &aio_max_nr,
1191 .maxlen = sizeof(aio_max_nr),
1192 .mode = 0644,
1193 .proc_handler = &proc_doulongvec_minmax,
1195 #ifdef CONFIG_INOTIFY_USER
1197 .ctl_name = FS_INOTIFY,
1198 .procname = "inotify",
1199 .mode = 0555,
1200 .child = inotify_table,
1202 #endif
1203 #endif
1205 .ctl_name = KERN_SETUID_DUMPABLE,
1206 .procname = "suid_dumpable",
1207 .data = &suid_dumpable,
1208 .maxlen = sizeof(int),
1209 .mode = 0644,
1210 .proc_handler = &proc_dointvec,
1212 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1214 .ctl_name = CTL_UNNUMBERED,
1215 .procname = "binfmt_misc",
1216 .mode = 0555,
1217 .child = binfmt_misc_table,
1219 #endif
1221 * NOTE: do not add new entries to this table unless you have read
1222 * Documentation/sysctl/ctl_unnumbered.txt
1224 { .ctl_name = 0 }
1227 static struct ctl_table debug_table[] = {
1228 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1230 .ctl_name = CTL_UNNUMBERED,
1231 .procname = "exception-trace",
1232 .data = &show_unhandled_signals,
1233 .maxlen = sizeof(int),
1234 .mode = 0644,
1235 .proc_handler = proc_dointvec
1237 #endif
1238 { .ctl_name = 0 }
1241 static struct ctl_table dev_table[] = {
1242 { .ctl_name = 0 }
1245 static DEFINE_SPINLOCK(sysctl_lock);
1247 /* called under sysctl_lock */
1248 static int use_table(struct ctl_table_header *p)
1250 if (unlikely(p->unregistering))
1251 return 0;
1252 p->used++;
1253 return 1;
1256 /* called under sysctl_lock */
1257 static void unuse_table(struct ctl_table_header *p)
1259 if (!--p->used)
1260 if (unlikely(p->unregistering))
1261 complete(p->unregistering);
1264 /* called under sysctl_lock, will reacquire if has to wait */
1265 static void start_unregistering(struct ctl_table_header *p)
1268 * if p->used is 0, nobody will ever touch that entry again;
1269 * we'll eliminate all paths to it before dropping sysctl_lock
1271 if (unlikely(p->used)) {
1272 struct completion wait;
1273 init_completion(&wait);
1274 p->unregistering = &wait;
1275 spin_unlock(&sysctl_lock);
1276 wait_for_completion(&wait);
1277 spin_lock(&sysctl_lock);
1280 * do not remove from the list until nobody holds it; walking the
1281 * list in do_sysctl() relies on that.
1283 list_del_init(&p->ctl_entry);
1286 void sysctl_head_finish(struct ctl_table_header *head)
1288 if (!head)
1289 return;
1290 spin_lock(&sysctl_lock);
1291 unuse_table(head);
1292 spin_unlock(&sysctl_lock);
1295 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1297 struct ctl_table_header *head;
1298 struct list_head *tmp;
1299 spin_lock(&sysctl_lock);
1300 if (prev) {
1301 tmp = &prev->ctl_entry;
1302 unuse_table(prev);
1303 goto next;
1305 tmp = &root_table_header.ctl_entry;
1306 for (;;) {
1307 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1309 if (!use_table(head))
1310 goto next;
1311 spin_unlock(&sysctl_lock);
1312 return head;
1313 next:
1314 tmp = tmp->next;
1315 if (tmp == &root_table_header.ctl_entry)
1316 break;
1318 spin_unlock(&sysctl_lock);
1319 return NULL;
1322 #ifdef CONFIG_SYSCTL_SYSCALL
1323 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1324 void __user *newval, size_t newlen)
1326 struct ctl_table_header *head;
1327 int error = -ENOTDIR;
1329 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1330 return -ENOTDIR;
1331 if (oldval) {
1332 int old_len;
1333 if (!oldlenp || get_user(old_len, oldlenp))
1334 return -EFAULT;
1337 for (head = sysctl_head_next(NULL); head;
1338 head = sysctl_head_next(head)) {
1339 error = parse_table(name, nlen, oldval, oldlenp,
1340 newval, newlen, head->ctl_table);
1341 if (error != -ENOTDIR) {
1342 sysctl_head_finish(head);
1343 break;
1346 return error;
1349 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1351 struct __sysctl_args tmp;
1352 int error;
1354 if (copy_from_user(&tmp, args, sizeof(tmp)))
1355 return -EFAULT;
1357 error = deprecated_sysctl_warning(&tmp);
1358 if (error)
1359 goto out;
1361 lock_kernel();
1362 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1363 tmp.newval, tmp.newlen);
1364 unlock_kernel();
1365 out:
1366 return error;
1368 #endif /* CONFIG_SYSCTL_SYSCALL */
1371 * sysctl_perm does NOT grant the superuser all rights automatically, because
1372 * some sysctl variables are readonly even to root.
1375 static int test_perm(int mode, int op)
1377 if (!current->euid)
1378 mode >>= 6;
1379 else if (in_egroup_p(0))
1380 mode >>= 3;
1381 if ((mode & op & 0007) == op)
1382 return 0;
1383 return -EACCES;
1386 int sysctl_perm(struct ctl_table *table, int op)
1388 int error;
1389 error = security_sysctl(table, op);
1390 if (error)
1391 return error;
1392 return test_perm(table->mode, op);
1395 #ifdef CONFIG_SYSCTL_SYSCALL
1396 static int parse_table(int __user *name, int nlen,
1397 void __user *oldval, size_t __user *oldlenp,
1398 void __user *newval, size_t newlen,
1399 struct ctl_table *table)
1401 int n;
1402 repeat:
1403 if (!nlen)
1404 return -ENOTDIR;
1405 if (get_user(n, name))
1406 return -EFAULT;
1407 for ( ; table->ctl_name || table->procname; table++) {
1408 if (!table->ctl_name)
1409 continue;
1410 if (n == table->ctl_name) {
1411 int error;
1412 if (table->child) {
1413 if (sysctl_perm(table, 001))
1414 return -EPERM;
1415 name++;
1416 nlen--;
1417 table = table->child;
1418 goto repeat;
1420 error = do_sysctl_strategy(table, name, nlen,
1421 oldval, oldlenp,
1422 newval, newlen);
1423 return error;
1426 return -ENOTDIR;
1429 /* Perform the actual read/write of a sysctl table entry. */
1430 int do_sysctl_strategy (struct ctl_table *table,
1431 int __user *name, int nlen,
1432 void __user *oldval, size_t __user *oldlenp,
1433 void __user *newval, size_t newlen)
1435 int op = 0, rc;
1437 if (oldval)
1438 op |= 004;
1439 if (newval)
1440 op |= 002;
1441 if (sysctl_perm(table, op))
1442 return -EPERM;
1444 if (table->strategy) {
1445 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1446 newval, newlen);
1447 if (rc < 0)
1448 return rc;
1449 if (rc > 0)
1450 return 0;
1453 /* If there is no strategy routine, or if the strategy returns
1454 * zero, proceed with automatic r/w */
1455 if (table->data && table->maxlen) {
1456 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1457 newval, newlen);
1458 if (rc < 0)
1459 return rc;
1461 return 0;
1463 #endif /* CONFIG_SYSCTL_SYSCALL */
1465 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1467 for (; table->ctl_name || table->procname; table++) {
1468 table->parent = parent;
1469 if (table->child)
1470 sysctl_set_parent(table, table->child);
1474 static __init int sysctl_init(void)
1476 int err;
1477 sysctl_set_parent(NULL, root_table);
1478 err = sysctl_check_table(root_table);
1479 return 0;
1482 core_initcall(sysctl_init);
1485 * register_sysctl_table - register a sysctl hierarchy
1486 * @table: the top-level table structure
1488 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1489 * array. An entry with a ctl_name of 0 terminates the table.
1491 * The members of the &struct ctl_table structure are used as follows:
1493 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1494 * must be unique within that level of sysctl
1496 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1497 * enter a sysctl file
1499 * data - a pointer to data for use by proc_handler
1501 * maxlen - the maximum size in bytes of the data
1503 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1505 * child - a pointer to the child sysctl table if this entry is a directory, or
1506 * %NULL.
1508 * proc_handler - the text handler routine (described below)
1510 * strategy - the strategy routine (described below)
1512 * de - for internal use by the sysctl routines
1514 * extra1, extra2 - extra pointers usable by the proc handler routines
1516 * Leaf nodes in the sysctl tree will be represented by a single file
1517 * under /proc; non-leaf nodes will be represented by directories.
1519 * sysctl(2) can automatically manage read and write requests through
1520 * the sysctl table. The data and maxlen fields of the ctl_table
1521 * struct enable minimal validation of the values being written to be
1522 * performed, and the mode field allows minimal authentication.
1524 * More sophisticated management can be enabled by the provision of a
1525 * strategy routine with the table entry. This will be called before
1526 * any automatic read or write of the data is performed.
1528 * The strategy routine may return
1530 * < 0 - Error occurred (error is passed to user process)
1532 * 0 - OK - proceed with automatic read or write.
1534 * > 0 - OK - read or write has been done by the strategy routine, so
1535 * return immediately.
1537 * There must be a proc_handler routine for any terminal nodes
1538 * mirrored under /proc/sys (non-terminals are handled by a built-in
1539 * directory handler). Several default handlers are available to
1540 * cover common cases -
1542 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1543 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1544 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1546 * It is the handler's job to read the input buffer from user memory
1547 * and process it. The handler should return 0 on success.
1549 * This routine returns %NULL on a failure to register, and a pointer
1550 * to the table header on success.
1552 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1554 struct ctl_table_header *tmp;
1555 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1556 if (!tmp)
1557 return NULL;
1558 tmp->ctl_table = table;
1559 INIT_LIST_HEAD(&tmp->ctl_entry);
1560 tmp->used = 0;
1561 tmp->unregistering = NULL;
1562 sysctl_set_parent(NULL, table);
1563 if (sysctl_check_table(tmp->ctl_table)) {
1564 kfree(tmp);
1565 return NULL;
1567 spin_lock(&sysctl_lock);
1568 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1569 spin_unlock(&sysctl_lock);
1570 return tmp;
1574 * unregister_sysctl_table - unregister a sysctl table hierarchy
1575 * @header: the header returned from register_sysctl_table
1577 * Unregisters the sysctl table and all children. proc entries may not
1578 * actually be removed until they are no longer used by anyone.
1580 void unregister_sysctl_table(struct ctl_table_header * header)
1582 might_sleep();
1583 spin_lock(&sysctl_lock);
1584 start_unregistering(header);
1585 spin_unlock(&sysctl_lock);
1586 kfree(header);
1589 #else /* !CONFIG_SYSCTL */
1590 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1592 return NULL;
1595 void unregister_sysctl_table(struct ctl_table_header * table)
1599 #endif /* CONFIG_SYSCTL */
1602 * /proc/sys support
1605 #ifdef CONFIG_PROC_SYSCTL
1607 static int _proc_do_string(void* data, int maxlen, int write,
1608 struct file *filp, void __user *buffer,
1609 size_t *lenp, loff_t *ppos)
1611 size_t len;
1612 char __user *p;
1613 char c;
1615 if (!data || !maxlen || !*lenp) {
1616 *lenp = 0;
1617 return 0;
1620 if (write) {
1621 len = 0;
1622 p = buffer;
1623 while (len < *lenp) {
1624 if (get_user(c, p++))
1625 return -EFAULT;
1626 if (c == 0 || c == '\n')
1627 break;
1628 len++;
1630 if (len >= maxlen)
1631 len = maxlen-1;
1632 if(copy_from_user(data, buffer, len))
1633 return -EFAULT;
1634 ((char *) data)[len] = 0;
1635 *ppos += *lenp;
1636 } else {
1637 len = strlen(data);
1638 if (len > maxlen)
1639 len = maxlen;
1641 if (*ppos > len) {
1642 *lenp = 0;
1643 return 0;
1646 data += *ppos;
1647 len -= *ppos;
1649 if (len > *lenp)
1650 len = *lenp;
1651 if (len)
1652 if(copy_to_user(buffer, data, len))
1653 return -EFAULT;
1654 if (len < *lenp) {
1655 if(put_user('\n', ((char __user *) buffer) + len))
1656 return -EFAULT;
1657 len++;
1659 *lenp = len;
1660 *ppos += len;
1662 return 0;
1666 * proc_dostring - read a string sysctl
1667 * @table: the sysctl table
1668 * @write: %TRUE if this is a write to the sysctl file
1669 * @filp: the file structure
1670 * @buffer: the user buffer
1671 * @lenp: the size of the user buffer
1672 * @ppos: file position
1674 * Reads/writes a string from/to the user buffer. If the kernel
1675 * buffer provided is not large enough to hold the string, the
1676 * string is truncated. The copied string is %NULL-terminated.
1677 * If the string is being read by the user process, it is copied
1678 * and a newline '\n' is added. It is truncated if the buffer is
1679 * not large enough.
1681 * Returns 0 on success.
1683 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1684 void __user *buffer, size_t *lenp, loff_t *ppos)
1686 return _proc_do_string(table->data, table->maxlen, write, filp,
1687 buffer, lenp, ppos);
1691 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1692 int *valp,
1693 int write, void *data)
1695 if (write) {
1696 *valp = *negp ? -*lvalp : *lvalp;
1697 } else {
1698 int val = *valp;
1699 if (val < 0) {
1700 *negp = -1;
1701 *lvalp = (unsigned long)-val;
1702 } else {
1703 *negp = 0;
1704 *lvalp = (unsigned long)val;
1707 return 0;
1710 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1711 int write, struct file *filp, void __user *buffer,
1712 size_t *lenp, loff_t *ppos,
1713 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1714 int write, void *data),
1715 void *data)
1717 #define TMPBUFLEN 21
1718 int *i, vleft, first=1, neg, val;
1719 unsigned long lval;
1720 size_t left, len;
1722 char buf[TMPBUFLEN], *p;
1723 char __user *s = buffer;
1725 if (!tbl_data || !table->maxlen || !*lenp ||
1726 (*ppos && !write)) {
1727 *lenp = 0;
1728 return 0;
1731 i = (int *) tbl_data;
1732 vleft = table->maxlen / sizeof(*i);
1733 left = *lenp;
1735 if (!conv)
1736 conv = do_proc_dointvec_conv;
1738 for (; left && vleft--; i++, first=0) {
1739 if (write) {
1740 while (left) {
1741 char c;
1742 if (get_user(c, s))
1743 return -EFAULT;
1744 if (!isspace(c))
1745 break;
1746 left--;
1747 s++;
1749 if (!left)
1750 break;
1751 neg = 0;
1752 len = left;
1753 if (len > sizeof(buf) - 1)
1754 len = sizeof(buf) - 1;
1755 if (copy_from_user(buf, s, len))
1756 return -EFAULT;
1757 buf[len] = 0;
1758 p = buf;
1759 if (*p == '-' && left > 1) {
1760 neg = 1;
1761 p++;
1763 if (*p < '0' || *p > '9')
1764 break;
1766 lval = simple_strtoul(p, &p, 0);
1768 len = p-buf;
1769 if ((len < left) && *p && !isspace(*p))
1770 break;
1771 if (neg)
1772 val = -val;
1773 s += len;
1774 left -= len;
1776 if (conv(&neg, &lval, i, 1, data))
1777 break;
1778 } else {
1779 p = buf;
1780 if (!first)
1781 *p++ = '\t';
1783 if (conv(&neg, &lval, i, 0, data))
1784 break;
1786 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1787 len = strlen(buf);
1788 if (len > left)
1789 len = left;
1790 if(copy_to_user(s, buf, len))
1791 return -EFAULT;
1792 left -= len;
1793 s += len;
1797 if (!write && !first && left) {
1798 if(put_user('\n', s))
1799 return -EFAULT;
1800 left--, s++;
1802 if (write) {
1803 while (left) {
1804 char c;
1805 if (get_user(c, s++))
1806 return -EFAULT;
1807 if (!isspace(c))
1808 break;
1809 left--;
1812 if (write && first)
1813 return -EINVAL;
1814 *lenp -= left;
1815 *ppos += *lenp;
1816 return 0;
1817 #undef TMPBUFLEN
1820 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1821 void __user *buffer, size_t *lenp, loff_t *ppos,
1822 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1823 int write, void *data),
1824 void *data)
1826 return __do_proc_dointvec(table->data, table, write, filp,
1827 buffer, lenp, ppos, conv, data);
1831 * proc_dointvec - read a vector of integers
1832 * @table: the sysctl table
1833 * @write: %TRUE if this is a write to the sysctl file
1834 * @filp: the file structure
1835 * @buffer: the user buffer
1836 * @lenp: the size of the user buffer
1837 * @ppos: file position
1839 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1840 * values from/to the user buffer, treated as an ASCII string.
1842 * Returns 0 on success.
1844 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1845 void __user *buffer, size_t *lenp, loff_t *ppos)
1847 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1848 NULL,NULL);
1851 #define OP_SET 0
1852 #define OP_AND 1
1853 #define OP_OR 2
1855 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1856 int *valp,
1857 int write, void *data)
1859 int op = *(int *)data;
1860 if (write) {
1861 int val = *negp ? -*lvalp : *lvalp;
1862 switch(op) {
1863 case OP_SET: *valp = val; break;
1864 case OP_AND: *valp &= val; break;
1865 case OP_OR: *valp |= val; break;
1867 } else {
1868 int val = *valp;
1869 if (val < 0) {
1870 *negp = -1;
1871 *lvalp = (unsigned long)-val;
1872 } else {
1873 *negp = 0;
1874 *lvalp = (unsigned long)val;
1877 return 0;
1880 #ifdef CONFIG_SECURITY_CAPABILITIES
1882 * init may raise the set.
1885 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1886 void __user *buffer, size_t *lenp, loff_t *ppos)
1888 int op;
1890 if (write && !capable(CAP_SYS_MODULE)) {
1891 return -EPERM;
1894 op = is_global_init(current) ? OP_SET : OP_AND;
1895 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1896 do_proc_dointvec_bset_conv,&op);
1898 #endif /* def CONFIG_SECURITY_CAPABILITIES */
1901 * Taint values can only be increased
1903 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1904 void __user *buffer, size_t *lenp, loff_t *ppos)
1906 int op;
1908 if (write && !capable(CAP_SYS_ADMIN))
1909 return -EPERM;
1911 op = OP_OR;
1912 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1913 do_proc_dointvec_bset_conv,&op);
1916 struct do_proc_dointvec_minmax_conv_param {
1917 int *min;
1918 int *max;
1921 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1922 int *valp,
1923 int write, void *data)
1925 struct do_proc_dointvec_minmax_conv_param *param = data;
1926 if (write) {
1927 int val = *negp ? -*lvalp : *lvalp;
1928 if ((param->min && *param->min > val) ||
1929 (param->max && *param->max < val))
1930 return -EINVAL;
1931 *valp = val;
1932 } else {
1933 int val = *valp;
1934 if (val < 0) {
1935 *negp = -1;
1936 *lvalp = (unsigned long)-val;
1937 } else {
1938 *negp = 0;
1939 *lvalp = (unsigned long)val;
1942 return 0;
1946 * proc_dointvec_minmax - read a vector of integers with min/max values
1947 * @table: the sysctl table
1948 * @write: %TRUE if this is a write to the sysctl file
1949 * @filp: the file structure
1950 * @buffer: the user buffer
1951 * @lenp: the size of the user buffer
1952 * @ppos: file position
1954 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1955 * values from/to the user buffer, treated as an ASCII string.
1957 * This routine will ensure the values are within the range specified by
1958 * table->extra1 (min) and table->extra2 (max).
1960 * Returns 0 on success.
1962 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1963 void __user *buffer, size_t *lenp, loff_t *ppos)
1965 struct do_proc_dointvec_minmax_conv_param param = {
1966 .min = (int *) table->extra1,
1967 .max = (int *) table->extra2,
1969 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1970 do_proc_dointvec_minmax_conv, &param);
1973 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1974 struct file *filp,
1975 void __user *buffer,
1976 size_t *lenp, loff_t *ppos,
1977 unsigned long convmul,
1978 unsigned long convdiv)
1980 #define TMPBUFLEN 21
1981 unsigned long *i, *min, *max, val;
1982 int vleft, first=1, neg;
1983 size_t len, left;
1984 char buf[TMPBUFLEN], *p;
1985 char __user *s = buffer;
1987 if (!data || !table->maxlen || !*lenp ||
1988 (*ppos && !write)) {
1989 *lenp = 0;
1990 return 0;
1993 i = (unsigned long *) data;
1994 min = (unsigned long *) table->extra1;
1995 max = (unsigned long *) table->extra2;
1996 vleft = table->maxlen / sizeof(unsigned long);
1997 left = *lenp;
1999 for (; left && vleft--; i++, min++, max++, first=0) {
2000 if (write) {
2001 while (left) {
2002 char c;
2003 if (get_user(c, s))
2004 return -EFAULT;
2005 if (!isspace(c))
2006 break;
2007 left--;
2008 s++;
2010 if (!left)
2011 break;
2012 neg = 0;
2013 len = left;
2014 if (len > TMPBUFLEN-1)
2015 len = TMPBUFLEN-1;
2016 if (copy_from_user(buf, s, len))
2017 return -EFAULT;
2018 buf[len] = 0;
2019 p = buf;
2020 if (*p == '-' && left > 1) {
2021 neg = 1;
2022 p++;
2024 if (*p < '0' || *p > '9')
2025 break;
2026 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2027 len = p-buf;
2028 if ((len < left) && *p && !isspace(*p))
2029 break;
2030 if (neg)
2031 val = -val;
2032 s += len;
2033 left -= len;
2035 if(neg)
2036 continue;
2037 if ((min && val < *min) || (max && val > *max))
2038 continue;
2039 *i = val;
2040 } else {
2041 p = buf;
2042 if (!first)
2043 *p++ = '\t';
2044 sprintf(p, "%lu", convdiv * (*i) / convmul);
2045 len = strlen(buf);
2046 if (len > left)
2047 len = left;
2048 if(copy_to_user(s, buf, len))
2049 return -EFAULT;
2050 left -= len;
2051 s += len;
2055 if (!write && !first && left) {
2056 if(put_user('\n', s))
2057 return -EFAULT;
2058 left--, s++;
2060 if (write) {
2061 while (left) {
2062 char c;
2063 if (get_user(c, s++))
2064 return -EFAULT;
2065 if (!isspace(c))
2066 break;
2067 left--;
2070 if (write && first)
2071 return -EINVAL;
2072 *lenp -= left;
2073 *ppos += *lenp;
2074 return 0;
2075 #undef TMPBUFLEN
2078 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2079 struct file *filp,
2080 void __user *buffer,
2081 size_t *lenp, loff_t *ppos,
2082 unsigned long convmul,
2083 unsigned long convdiv)
2085 return __do_proc_doulongvec_minmax(table->data, table, write,
2086 filp, buffer, lenp, ppos, convmul, convdiv);
2090 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2091 * @table: the sysctl table
2092 * @write: %TRUE if this is a write to the sysctl file
2093 * @filp: the file structure
2094 * @buffer: the user buffer
2095 * @lenp: the size of the user buffer
2096 * @ppos: file position
2098 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2099 * values from/to the user buffer, treated as an ASCII string.
2101 * This routine will ensure the values are within the range specified by
2102 * table->extra1 (min) and table->extra2 (max).
2104 * Returns 0 on success.
2106 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2107 void __user *buffer, size_t *lenp, loff_t *ppos)
2109 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2113 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2114 * @table: the sysctl table
2115 * @write: %TRUE if this is a write to the sysctl file
2116 * @filp: the file structure
2117 * @buffer: the user buffer
2118 * @lenp: the size of the user buffer
2119 * @ppos: file position
2121 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2122 * values from/to the user buffer, treated as an ASCII string. The values
2123 * are treated as milliseconds, and converted to jiffies when they are stored.
2125 * This routine will ensure the values are within the range specified by
2126 * table->extra1 (min) and table->extra2 (max).
2128 * Returns 0 on success.
2130 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2131 struct file *filp,
2132 void __user *buffer,
2133 size_t *lenp, loff_t *ppos)
2135 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2136 lenp, ppos, HZ, 1000l);
2140 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2141 int *valp,
2142 int write, void *data)
2144 if (write) {
2145 if (*lvalp > LONG_MAX / HZ)
2146 return 1;
2147 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2148 } else {
2149 int val = *valp;
2150 unsigned long lval;
2151 if (val < 0) {
2152 *negp = -1;
2153 lval = (unsigned long)-val;
2154 } else {
2155 *negp = 0;
2156 lval = (unsigned long)val;
2158 *lvalp = lval / HZ;
2160 return 0;
2163 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2164 int *valp,
2165 int write, void *data)
2167 if (write) {
2168 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2169 return 1;
2170 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2171 } else {
2172 int val = *valp;
2173 unsigned long lval;
2174 if (val < 0) {
2175 *negp = -1;
2176 lval = (unsigned long)-val;
2177 } else {
2178 *negp = 0;
2179 lval = (unsigned long)val;
2181 *lvalp = jiffies_to_clock_t(lval);
2183 return 0;
2186 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2187 int *valp,
2188 int write, void *data)
2190 if (write) {
2191 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2192 } else {
2193 int val = *valp;
2194 unsigned long lval;
2195 if (val < 0) {
2196 *negp = -1;
2197 lval = (unsigned long)-val;
2198 } else {
2199 *negp = 0;
2200 lval = (unsigned long)val;
2202 *lvalp = jiffies_to_msecs(lval);
2204 return 0;
2208 * proc_dointvec_jiffies - read a vector of integers as seconds
2209 * @table: the sysctl table
2210 * @write: %TRUE if this is a write to the sysctl file
2211 * @filp: the file structure
2212 * @buffer: the user buffer
2213 * @lenp: the size of the user buffer
2214 * @ppos: file position
2216 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2217 * values from/to the user buffer, treated as an ASCII string.
2218 * The values read are assumed to be in seconds, and are converted into
2219 * jiffies.
2221 * Returns 0 on success.
2223 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2226 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2227 do_proc_dointvec_jiffies_conv,NULL);
2231 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2232 * @table: the sysctl table
2233 * @write: %TRUE if this is a write to the sysctl file
2234 * @filp: the file structure
2235 * @buffer: the user buffer
2236 * @lenp: the size of the user buffer
2237 * @ppos: pointer to the file position
2239 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2240 * values from/to the user buffer, treated as an ASCII string.
2241 * The values read are assumed to be in 1/USER_HZ seconds, and
2242 * are converted into jiffies.
2244 * Returns 0 on success.
2246 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2247 void __user *buffer, size_t *lenp, loff_t *ppos)
2249 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2250 do_proc_dointvec_userhz_jiffies_conv,NULL);
2254 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2255 * @table: the sysctl table
2256 * @write: %TRUE if this is a write to the sysctl file
2257 * @filp: the file structure
2258 * @buffer: the user buffer
2259 * @lenp: the size of the user buffer
2260 * @ppos: file position
2261 * @ppos: the current position in the file
2263 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2264 * values from/to the user buffer, treated as an ASCII string.
2265 * The values read are assumed to be in 1/1000 seconds, and
2266 * are converted into jiffies.
2268 * Returns 0 on success.
2270 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2271 void __user *buffer, size_t *lenp, loff_t *ppos)
2273 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2274 do_proc_dointvec_ms_jiffies_conv, NULL);
2277 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2278 void __user *buffer, size_t *lenp, loff_t *ppos)
2280 struct pid *new_pid;
2281 pid_t tmp;
2282 int r;
2284 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
2286 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2287 lenp, ppos, NULL, NULL);
2288 if (r || !write)
2289 return r;
2291 new_pid = find_get_pid(tmp);
2292 if (!new_pid)
2293 return -ESRCH;
2295 put_pid(xchg(&cad_pid, new_pid));
2296 return 0;
2299 #else /* CONFIG_PROC_FS */
2301 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2302 void __user *buffer, size_t *lenp, loff_t *ppos)
2304 return -ENOSYS;
2307 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2308 void __user *buffer, size_t *lenp, loff_t *ppos)
2310 return -ENOSYS;
2313 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2314 void __user *buffer, size_t *lenp, loff_t *ppos)
2316 return -ENOSYS;
2319 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2320 void __user *buffer, size_t *lenp, loff_t *ppos)
2322 return -ENOSYS;
2325 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2326 void __user *buffer, size_t *lenp, loff_t *ppos)
2328 return -ENOSYS;
2331 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2332 void __user *buffer, size_t *lenp, loff_t *ppos)
2334 return -ENOSYS;
2337 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2338 void __user *buffer, size_t *lenp, loff_t *ppos)
2340 return -ENOSYS;
2343 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2344 void __user *buffer, size_t *lenp, loff_t *ppos)
2346 return -ENOSYS;
2349 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2350 struct file *filp,
2351 void __user *buffer,
2352 size_t *lenp, loff_t *ppos)
2354 return -ENOSYS;
2358 #endif /* CONFIG_PROC_FS */
2361 #ifdef CONFIG_SYSCTL_SYSCALL
2363 * General sysctl support routines
2366 /* The generic sysctl data routine (used if no strategy routine supplied) */
2367 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2368 void __user *oldval, size_t __user *oldlenp,
2369 void __user *newval, size_t newlen)
2371 size_t len;
2373 /* Get out of I don't have a variable */
2374 if (!table->data || !table->maxlen)
2375 return -ENOTDIR;
2377 if (oldval && oldlenp) {
2378 if (get_user(len, oldlenp))
2379 return -EFAULT;
2380 if (len) {
2381 if (len > table->maxlen)
2382 len = table->maxlen;
2383 if (copy_to_user(oldval, table->data, len))
2384 return -EFAULT;
2385 if (put_user(len, oldlenp))
2386 return -EFAULT;
2390 if (newval && newlen) {
2391 if (newlen > table->maxlen)
2392 newlen = table->maxlen;
2394 if (copy_from_user(table->data, newval, newlen))
2395 return -EFAULT;
2397 return 1;
2400 /* The generic string strategy routine: */
2401 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2402 void __user *oldval, size_t __user *oldlenp,
2403 void __user *newval, size_t newlen)
2405 if (!table->data || !table->maxlen)
2406 return -ENOTDIR;
2408 if (oldval && oldlenp) {
2409 size_t bufsize;
2410 if (get_user(bufsize, oldlenp))
2411 return -EFAULT;
2412 if (bufsize) {
2413 size_t len = strlen(table->data), copied;
2415 /* This shouldn't trigger for a well-formed sysctl */
2416 if (len > table->maxlen)
2417 len = table->maxlen;
2419 /* Copy up to a max of bufsize-1 bytes of the string */
2420 copied = (len >= bufsize) ? bufsize - 1 : len;
2422 if (copy_to_user(oldval, table->data, copied) ||
2423 put_user(0, (char __user *)(oldval + copied)))
2424 return -EFAULT;
2425 if (put_user(len, oldlenp))
2426 return -EFAULT;
2429 if (newval && newlen) {
2430 size_t len = newlen;
2431 if (len > table->maxlen)
2432 len = table->maxlen;
2433 if(copy_from_user(table->data, newval, len))
2434 return -EFAULT;
2435 if (len == table->maxlen)
2436 len--;
2437 ((char *) table->data)[len] = 0;
2439 return 1;
2443 * This function makes sure that all of the integers in the vector
2444 * are between the minimum and maximum values given in the arrays
2445 * table->extra1 and table->extra2, respectively.
2447 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2448 void __user *oldval, size_t __user *oldlenp,
2449 void __user *newval, size_t newlen)
2452 if (newval && newlen) {
2453 int __user *vec = (int __user *) newval;
2454 int *min = (int *) table->extra1;
2455 int *max = (int *) table->extra2;
2456 size_t length;
2457 int i;
2459 if (newlen % sizeof(int) != 0)
2460 return -EINVAL;
2462 if (!table->extra1 && !table->extra2)
2463 return 0;
2465 if (newlen > table->maxlen)
2466 newlen = table->maxlen;
2467 length = newlen / sizeof(int);
2469 for (i = 0; i < length; i++) {
2470 int value;
2471 if (get_user(value, vec + i))
2472 return -EFAULT;
2473 if (min && value < min[i])
2474 return -EINVAL;
2475 if (max && value > max[i])
2476 return -EINVAL;
2479 return 0;
2482 /* Strategy function to convert jiffies to seconds */
2483 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2484 void __user *oldval, size_t __user *oldlenp,
2485 void __user *newval, size_t newlen)
2487 if (oldval && oldlenp) {
2488 size_t olen;
2490 if (get_user(olen, oldlenp))
2491 return -EFAULT;
2492 if (olen) {
2493 int val;
2495 if (olen < sizeof(int))
2496 return -EINVAL;
2498 val = *(int *)(table->data) / HZ;
2499 if (put_user(val, (int __user *)oldval))
2500 return -EFAULT;
2501 if (put_user(sizeof(int), oldlenp))
2502 return -EFAULT;
2505 if (newval && newlen) {
2506 int new;
2507 if (newlen != sizeof(int))
2508 return -EINVAL;
2509 if (get_user(new, (int __user *)newval))
2510 return -EFAULT;
2511 *(int *)(table->data) = new*HZ;
2513 return 1;
2516 /* Strategy function to convert jiffies to seconds */
2517 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2518 void __user *oldval, size_t __user *oldlenp,
2519 void __user *newval, size_t newlen)
2521 if (oldval && oldlenp) {
2522 size_t olen;
2524 if (get_user(olen, oldlenp))
2525 return -EFAULT;
2526 if (olen) {
2527 int val;
2529 if (olen < sizeof(int))
2530 return -EINVAL;
2532 val = jiffies_to_msecs(*(int *)(table->data));
2533 if (put_user(val, (int __user *)oldval))
2534 return -EFAULT;
2535 if (put_user(sizeof(int), oldlenp))
2536 return -EFAULT;
2539 if (newval && newlen) {
2540 int new;
2541 if (newlen != sizeof(int))
2542 return -EINVAL;
2543 if (get_user(new, (int __user *)newval))
2544 return -EFAULT;
2545 *(int *)(table->data) = msecs_to_jiffies(new);
2547 return 1;
2552 #else /* CONFIG_SYSCTL_SYSCALL */
2555 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2557 struct __sysctl_args tmp;
2558 int error;
2560 if (copy_from_user(&tmp, args, sizeof(tmp)))
2561 return -EFAULT;
2563 error = deprecated_sysctl_warning(&tmp);
2565 /* If no error reading the parameters then just -ENOSYS ... */
2566 if (!error)
2567 error = -ENOSYS;
2569 return error;
2572 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2573 void __user *oldval, size_t __user *oldlenp,
2574 void __user *newval, size_t newlen)
2576 return -ENOSYS;
2579 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2580 void __user *oldval, size_t __user *oldlenp,
2581 void __user *newval, size_t newlen)
2583 return -ENOSYS;
2586 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2587 void __user *oldval, size_t __user *oldlenp,
2588 void __user *newval, size_t newlen)
2590 return -ENOSYS;
2593 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2594 void __user *oldval, size_t __user *oldlenp,
2595 void __user *newval, size_t newlen)
2597 return -ENOSYS;
2600 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2601 void __user *oldval, size_t __user *oldlenp,
2602 void __user *newval, size_t newlen)
2604 return -ENOSYS;
2607 #endif /* CONFIG_SYSCTL_SYSCALL */
2609 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2611 static int msg_count;
2612 int name[CTL_MAXNAME];
2613 int i;
2615 /* Read in the sysctl name for better debug message logging */
2616 for (i = 0; i < args->nlen; i++)
2617 if (get_user(name[i], args->name + i))
2618 return -EFAULT;
2620 /* Ignore accesses to kernel.version */
2621 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2622 return 0;
2624 if (msg_count < 5) {
2625 msg_count++;
2626 printk(KERN_INFO
2627 "warning: process `%s' used the deprecated sysctl "
2628 "system call with ", current->comm);
2629 for (i = 0; i < args->nlen; i++)
2630 printk("%d.", name[i]);
2631 printk("\n");
2633 return 0;
2637 * No sense putting this after each symbol definition, twice,
2638 * exception granted :-)
2640 EXPORT_SYMBOL(proc_dointvec);
2641 EXPORT_SYMBOL(proc_dointvec_jiffies);
2642 EXPORT_SYMBOL(proc_dointvec_minmax);
2643 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2644 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2645 EXPORT_SYMBOL(proc_dostring);
2646 EXPORT_SYMBOL(proc_doulongvec_minmax);
2647 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2648 EXPORT_SYMBOL(register_sysctl_table);
2649 EXPORT_SYMBOL(sysctl_intvec);
2650 EXPORT_SYMBOL(sysctl_jiffies);
2651 EXPORT_SYMBOL(sysctl_ms_jiffies);
2652 EXPORT_SYMBOL(sysctl_string);
2653 EXPORT_SYMBOL(sysctl_data);
2654 EXPORT_SYMBOL(unregister_sysctl_table);