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
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
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>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/capability.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.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>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
52 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
53 void __user *buffer, size_t *lenp, loff_t *ppos);
57 #include <asm/stacktrace.h>
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
64 extern int sysctl_overcommit_memory;
65 extern int sysctl_overcommit_ratio;
66 extern int sysctl_panic_on_oom;
67 extern int max_threads;
68 extern int core_uses_pid;
69 extern int suid_dumpable;
70 extern char core_pattern[];
72 extern int min_free_kbytes;
73 extern int printk_ratelimit_jiffies;
74 extern int printk_ratelimit_burst;
75 extern int pid_max_min, pid_max_max;
76 extern int sysctl_drop_caches;
77 extern int percpu_pagelist_fraction;
78 extern int compat_log;
79 extern int maps_protect;
80 extern int sysctl_stat_interval;
82 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83 static int maxolduid = 65535;
85 static int min_percpu_pagelist_fract = 8;
87 static int ngroups_max = NGROUPS_MAX;
90 extern char modprobe_path[];
92 #ifdef CONFIG_CHR_DEV_SG
93 extern int sg_big_buff;
97 extern char reboot_command [];
98 extern int stop_a_enabled;
99 extern int scons_pwroff;
103 extern int pwrsw_enabled;
104 extern int unaligned_enabled;
108 #ifdef CONFIG_MATHEMU
109 extern int sysctl_ieee_emulation_warnings;
111 extern int sysctl_userprocess_debug;
112 extern int spin_retry;
115 extern int sysctl_hz_timer;
117 #ifdef CONFIG_BSD_PROCESS_ACCT
118 extern int acct_parm[];
122 extern int no_unaligned_warning;
125 #ifdef CONFIG_RT_MUTEXES
126 extern int max_lock_depth;
129 #ifdef CONFIG_SYSCTL_SYSCALL
130 static int parse_table(int __user *, int, void __user *, size_t __user *,
131 void __user *, size_t, ctl_table *);
135 #ifdef CONFIG_PROC_SYSCTL
136 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
137 void __user *buffer, size_t *lenp, loff_t *ppos);
138 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
139 void __user *buffer, size_t *lenp, loff_t *ppos);
142 static ctl_table root_table[];
143 static struct ctl_table_header root_table_header =
144 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
146 static ctl_table kern_table[];
147 static ctl_table vm_table[];
148 static ctl_table fs_table[];
149 static ctl_table debug_table[];
150 static ctl_table dev_table[];
151 extern ctl_table random_table[];
152 #ifdef CONFIG_UNIX98_PTYS
153 extern ctl_table pty_table[];
155 #ifdef CONFIG_INOTIFY_USER
156 extern ctl_table inotify_table[];
159 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
160 int sysctl_legacy_va_layout;
164 /* The default sysctl tables: */
166 static ctl_table root_table[] = {
168 .ctl_name = CTL_KERN,
169 .procname = "kernel",
194 .ctl_name = CTL_DEBUG,
197 .child = debug_table,
209 #ifdef CONFIG_SCHED_DEBUG
210 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
211 static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
212 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
213 static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
216 static ctl_table kern_table[] = {
217 #ifdef CONFIG_SCHED_DEBUG
219 .ctl_name = CTL_UNNUMBERED,
220 .procname = "sched_granularity_ns",
221 .data = &sysctl_sched_granularity,
222 .maxlen = sizeof(unsigned int),
224 .proc_handler = &proc_dointvec_minmax,
225 .strategy = &sysctl_intvec,
226 .extra1 = &min_sched_granularity_ns,
227 .extra2 = &max_sched_granularity_ns,
230 .ctl_name = CTL_UNNUMBERED,
231 .procname = "sched_wakeup_granularity_ns",
232 .data = &sysctl_sched_wakeup_granularity,
233 .maxlen = sizeof(unsigned int),
235 .proc_handler = &proc_dointvec_minmax,
236 .strategy = &sysctl_intvec,
237 .extra1 = &min_wakeup_granularity_ns,
238 .extra2 = &max_wakeup_granularity_ns,
241 .ctl_name = CTL_UNNUMBERED,
242 .procname = "sched_batch_wakeup_granularity_ns",
243 .data = &sysctl_sched_batch_wakeup_granularity,
244 .maxlen = sizeof(unsigned int),
246 .proc_handler = &proc_dointvec_minmax,
247 .strategy = &sysctl_intvec,
248 .extra1 = &min_wakeup_granularity_ns,
249 .extra2 = &max_wakeup_granularity_ns,
252 .ctl_name = CTL_UNNUMBERED,
253 .procname = "sched_stat_granularity_ns",
254 .data = &sysctl_sched_stat_granularity,
255 .maxlen = sizeof(unsigned int),
257 .proc_handler = &proc_dointvec_minmax,
258 .strategy = &sysctl_intvec,
259 .extra1 = &min_wakeup_granularity_ns,
260 .extra2 = &max_wakeup_granularity_ns,
263 .ctl_name = CTL_UNNUMBERED,
264 .procname = "sched_runtime_limit_ns",
265 .data = &sysctl_sched_runtime_limit,
266 .maxlen = sizeof(unsigned int),
268 .proc_handler = &proc_dointvec_minmax,
269 .strategy = &sysctl_intvec,
270 .extra1 = &min_sched_granularity_ns,
271 .extra2 = &max_sched_granularity_ns,
274 .ctl_name = CTL_UNNUMBERED,
275 .procname = "sched_child_runs_first",
276 .data = &sysctl_sched_child_runs_first,
277 .maxlen = sizeof(unsigned int),
279 .proc_handler = &proc_dointvec,
282 .ctl_name = CTL_UNNUMBERED,
283 .procname = "sched_features",
284 .data = &sysctl_sched_features,
285 .maxlen = sizeof(unsigned int),
287 .proc_handler = &proc_dointvec,
291 .ctl_name = KERN_PANIC,
293 .data = &panic_timeout,
294 .maxlen = sizeof(int),
296 .proc_handler = &proc_dointvec,
299 .ctl_name = KERN_CORE_USES_PID,
300 .procname = "core_uses_pid",
301 .data = &core_uses_pid,
302 .maxlen = sizeof(int),
304 .proc_handler = &proc_dointvec,
307 .ctl_name = KERN_CORE_PATTERN,
308 .procname = "core_pattern",
309 .data = core_pattern,
310 .maxlen = CORENAME_MAX_SIZE,
312 .proc_handler = &proc_dostring,
313 .strategy = &sysctl_string,
315 #ifdef CONFIG_PROC_SYSCTL
317 .ctl_name = KERN_TAINTED,
318 .procname = "tainted",
320 .maxlen = sizeof(int),
322 .proc_handler = &proc_dointvec_taint,
326 .ctl_name = KERN_CAP_BSET,
327 .procname = "cap-bound",
329 .maxlen = sizeof(kernel_cap_t),
331 .proc_handler = &proc_dointvec_bset,
333 #ifdef CONFIG_BLK_DEV_INITRD
335 .ctl_name = KERN_REALROOTDEV,
336 .procname = "real-root-dev",
337 .data = &real_root_dev,
338 .maxlen = sizeof(int),
340 .proc_handler = &proc_dointvec,
345 .ctl_name = KERN_SPARC_REBOOT,
346 .procname = "reboot-cmd",
347 .data = reboot_command,
350 .proc_handler = &proc_dostring,
351 .strategy = &sysctl_string,
354 .ctl_name = KERN_SPARC_STOP_A,
355 .procname = "stop-a",
356 .data = &stop_a_enabled,
357 .maxlen = sizeof (int),
359 .proc_handler = &proc_dointvec,
362 .ctl_name = KERN_SPARC_SCONS_PWROFF,
363 .procname = "scons-poweroff",
364 .data = &scons_pwroff,
365 .maxlen = sizeof (int),
367 .proc_handler = &proc_dointvec,
372 .ctl_name = KERN_HPPA_PWRSW,
373 .procname = "soft-power",
374 .data = &pwrsw_enabled,
375 .maxlen = sizeof (int),
377 .proc_handler = &proc_dointvec,
380 .ctl_name = KERN_HPPA_UNALIGNED,
381 .procname = "unaligned-trap",
382 .data = &unaligned_enabled,
383 .maxlen = sizeof (int),
385 .proc_handler = &proc_dointvec,
389 .ctl_name = KERN_CTLALTDEL,
390 .procname = "ctrl-alt-del",
392 .maxlen = sizeof(int),
394 .proc_handler = &proc_dointvec,
397 .ctl_name = KERN_PRINTK,
398 .procname = "printk",
399 .data = &console_loglevel,
400 .maxlen = 4*sizeof(int),
402 .proc_handler = &proc_dointvec,
406 .ctl_name = KERN_MODPROBE,
407 .procname = "modprobe",
408 .data = &modprobe_path,
409 .maxlen = KMOD_PATH_LEN,
411 .proc_handler = &proc_dostring,
412 .strategy = &sysctl_string,
415 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
417 .ctl_name = KERN_HOTPLUG,
418 .procname = "hotplug",
419 .data = &uevent_helper,
420 .maxlen = UEVENT_HELPER_PATH_LEN,
422 .proc_handler = &proc_dostring,
423 .strategy = &sysctl_string,
426 #ifdef CONFIG_CHR_DEV_SG
428 .ctl_name = KERN_SG_BIG_BUFF,
429 .procname = "sg-big-buff",
430 .data = &sg_big_buff,
431 .maxlen = sizeof (int),
433 .proc_handler = &proc_dointvec,
436 #ifdef CONFIG_BSD_PROCESS_ACCT
438 .ctl_name = KERN_ACCT,
441 .maxlen = 3*sizeof(int),
443 .proc_handler = &proc_dointvec,
446 #ifdef CONFIG_MAGIC_SYSRQ
448 .ctl_name = KERN_SYSRQ,
450 .data = &__sysrq_enabled,
451 .maxlen = sizeof (int),
453 .proc_handler = &proc_dointvec,
456 #ifdef CONFIG_PROC_SYSCTL
458 .ctl_name = KERN_CADPID,
459 .procname = "cad_pid",
461 .maxlen = sizeof (int),
463 .proc_handler = &proc_do_cad_pid,
467 .ctl_name = KERN_MAX_THREADS,
468 .procname = "threads-max",
469 .data = &max_threads,
470 .maxlen = sizeof(int),
472 .proc_handler = &proc_dointvec,
475 .ctl_name = KERN_RANDOM,
476 .procname = "random",
478 .child = random_table,
480 #ifdef CONFIG_UNIX98_PTYS
482 .ctl_name = KERN_PTY,
489 .ctl_name = KERN_OVERFLOWUID,
490 .procname = "overflowuid",
491 .data = &overflowuid,
492 .maxlen = sizeof(int),
494 .proc_handler = &proc_dointvec_minmax,
495 .strategy = &sysctl_intvec,
496 .extra1 = &minolduid,
497 .extra2 = &maxolduid,
500 .ctl_name = KERN_OVERFLOWGID,
501 .procname = "overflowgid",
502 .data = &overflowgid,
503 .maxlen = sizeof(int),
505 .proc_handler = &proc_dointvec_minmax,
506 .strategy = &sysctl_intvec,
507 .extra1 = &minolduid,
508 .extra2 = &maxolduid,
511 #ifdef CONFIG_MATHEMU
513 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
514 .procname = "ieee_emulation_warnings",
515 .data = &sysctl_ieee_emulation_warnings,
516 .maxlen = sizeof(int),
518 .proc_handler = &proc_dointvec,
521 #ifdef CONFIG_NO_IDLE_HZ
523 .ctl_name = KERN_HZ_TIMER,
524 .procname = "hz_timer",
525 .data = &sysctl_hz_timer,
526 .maxlen = sizeof(int),
528 .proc_handler = &proc_dointvec,
532 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
533 .procname = "userprocess_debug",
534 .data = &sysctl_userprocess_debug,
535 .maxlen = sizeof(int),
537 .proc_handler = &proc_dointvec,
541 .ctl_name = KERN_PIDMAX,
542 .procname = "pid_max",
544 .maxlen = sizeof (int),
546 .proc_handler = &proc_dointvec_minmax,
547 .strategy = sysctl_intvec,
548 .extra1 = &pid_max_min,
549 .extra2 = &pid_max_max,
552 .ctl_name = KERN_PANIC_ON_OOPS,
553 .procname = "panic_on_oops",
554 .data = &panic_on_oops,
555 .maxlen = sizeof(int),
557 .proc_handler = &proc_dointvec,
560 .ctl_name = KERN_PRINTK_RATELIMIT,
561 .procname = "printk_ratelimit",
562 .data = &printk_ratelimit_jiffies,
563 .maxlen = sizeof(int),
565 .proc_handler = &proc_dointvec_jiffies,
566 .strategy = &sysctl_jiffies,
569 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
570 .procname = "printk_ratelimit_burst",
571 .data = &printk_ratelimit_burst,
572 .maxlen = sizeof(int),
574 .proc_handler = &proc_dointvec,
577 .ctl_name = KERN_NGROUPS_MAX,
578 .procname = "ngroups_max",
579 .data = &ngroups_max,
580 .maxlen = sizeof (int),
582 .proc_handler = &proc_dointvec,
584 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
586 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
587 .procname = "unknown_nmi_panic",
588 .data = &unknown_nmi_panic,
589 .maxlen = sizeof (int),
591 .proc_handler = &proc_dointvec,
594 .ctl_name = KERN_NMI_WATCHDOG,
595 .procname = "nmi_watchdog",
596 .data = &nmi_watchdog_enabled,
597 .maxlen = sizeof (int),
599 .proc_handler = &proc_nmi_enabled,
602 #if defined(CONFIG_X86)
604 .ctl_name = KERN_PANIC_ON_NMI,
605 .procname = "panic_on_unrecovered_nmi",
606 .data = &panic_on_unrecovered_nmi,
607 .maxlen = sizeof(int),
609 .proc_handler = &proc_dointvec,
612 .ctl_name = KERN_BOOTLOADER_TYPE,
613 .procname = "bootloader_type",
614 .data = &bootloader_type,
615 .maxlen = sizeof (int),
617 .proc_handler = &proc_dointvec,
620 .ctl_name = CTL_UNNUMBERED,
621 .procname = "kstack_depth_to_print",
622 .data = &kstack_depth_to_print,
623 .maxlen = sizeof(int),
625 .proc_handler = &proc_dointvec,
628 #if defined(CONFIG_MMU)
630 .ctl_name = KERN_RANDOMIZE,
631 .procname = "randomize_va_space",
632 .data = &randomize_va_space,
633 .maxlen = sizeof(int),
635 .proc_handler = &proc_dointvec,
638 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
640 .ctl_name = KERN_SPIN_RETRY,
641 .procname = "spin_retry",
643 .maxlen = sizeof (int),
645 .proc_handler = &proc_dointvec,
648 #ifdef CONFIG_ACPI_SLEEP
650 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
651 .procname = "acpi_video_flags",
652 .data = &acpi_video_flags,
653 .maxlen = sizeof (unsigned long),
655 .proc_handler = &proc_doulongvec_minmax,
660 .ctl_name = KERN_IA64_UNALIGNED,
661 .procname = "ignore-unaligned-usertrap",
662 .data = &no_unaligned_warning,
663 .maxlen = sizeof (int),
665 .proc_handler = &proc_dointvec,
670 .ctl_name = KERN_COMPAT_LOG,
671 .procname = "compat-log",
673 .maxlen = sizeof (int),
675 .proc_handler = &proc_dointvec,
678 #ifdef CONFIG_RT_MUTEXES
680 .ctl_name = KERN_MAX_LOCK_DEPTH,
681 .procname = "max_lock_depth",
682 .data = &max_lock_depth,
683 .maxlen = sizeof(int),
685 .proc_handler = &proc_dointvec,
688 #ifdef CONFIG_PROC_FS
690 .ctl_name = CTL_UNNUMBERED,
691 .procname = "maps_protect",
692 .data = &maps_protect,
693 .maxlen = sizeof(int),
695 .proc_handler = &proc_dointvec,
702 /* Constants for minimum and maximum testing in vm_table.
703 We use these as one-element integer vectors. */
705 static int one_hundred = 100;
708 static ctl_table vm_table[] = {
710 .ctl_name = VM_OVERCOMMIT_MEMORY,
711 .procname = "overcommit_memory",
712 .data = &sysctl_overcommit_memory,
713 .maxlen = sizeof(sysctl_overcommit_memory),
715 .proc_handler = &proc_dointvec,
718 .ctl_name = VM_PANIC_ON_OOM,
719 .procname = "panic_on_oom",
720 .data = &sysctl_panic_on_oom,
721 .maxlen = sizeof(sysctl_panic_on_oom),
723 .proc_handler = &proc_dointvec,
726 .ctl_name = VM_OVERCOMMIT_RATIO,
727 .procname = "overcommit_ratio",
728 .data = &sysctl_overcommit_ratio,
729 .maxlen = sizeof(sysctl_overcommit_ratio),
731 .proc_handler = &proc_dointvec,
734 .ctl_name = VM_PAGE_CLUSTER,
735 .procname = "page-cluster",
736 .data = &page_cluster,
737 .maxlen = sizeof(int),
739 .proc_handler = &proc_dointvec,
742 .ctl_name = VM_DIRTY_BACKGROUND,
743 .procname = "dirty_background_ratio",
744 .data = &dirty_background_ratio,
745 .maxlen = sizeof(dirty_background_ratio),
747 .proc_handler = &proc_dointvec_minmax,
748 .strategy = &sysctl_intvec,
750 .extra2 = &one_hundred,
753 .ctl_name = VM_DIRTY_RATIO,
754 .procname = "dirty_ratio",
755 .data = &vm_dirty_ratio,
756 .maxlen = sizeof(vm_dirty_ratio),
758 .proc_handler = &proc_dointvec_minmax,
759 .strategy = &sysctl_intvec,
761 .extra2 = &one_hundred,
764 .ctl_name = VM_DIRTY_WB_CS,
765 .procname = "dirty_writeback_centisecs",
766 .data = &dirty_writeback_interval,
767 .maxlen = sizeof(dirty_writeback_interval),
769 .proc_handler = &dirty_writeback_centisecs_handler,
772 .ctl_name = VM_DIRTY_EXPIRE_CS,
773 .procname = "dirty_expire_centisecs",
774 .data = &dirty_expire_interval,
775 .maxlen = sizeof(dirty_expire_interval),
777 .proc_handler = &proc_dointvec_userhz_jiffies,
780 .ctl_name = VM_NR_PDFLUSH_THREADS,
781 .procname = "nr_pdflush_threads",
782 .data = &nr_pdflush_threads,
783 .maxlen = sizeof nr_pdflush_threads,
784 .mode = 0444 /* read-only*/,
785 .proc_handler = &proc_dointvec,
788 .ctl_name = VM_SWAPPINESS,
789 .procname = "swappiness",
790 .data = &vm_swappiness,
791 .maxlen = sizeof(vm_swappiness),
793 .proc_handler = &proc_dointvec_minmax,
794 .strategy = &sysctl_intvec,
796 .extra2 = &one_hundred,
798 #ifdef CONFIG_HUGETLB_PAGE
800 .ctl_name = VM_HUGETLB_PAGES,
801 .procname = "nr_hugepages",
802 .data = &max_huge_pages,
803 .maxlen = sizeof(unsigned long),
805 .proc_handler = &hugetlb_sysctl_handler,
806 .extra1 = (void *)&hugetlb_zero,
807 .extra2 = (void *)&hugetlb_infinity,
810 .ctl_name = VM_HUGETLB_GROUP,
811 .procname = "hugetlb_shm_group",
812 .data = &sysctl_hugetlb_shm_group,
813 .maxlen = sizeof(gid_t),
815 .proc_handler = &proc_dointvec,
819 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
820 .procname = "lowmem_reserve_ratio",
821 .data = &sysctl_lowmem_reserve_ratio,
822 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
824 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
825 .strategy = &sysctl_intvec,
828 .ctl_name = VM_DROP_PAGECACHE,
829 .procname = "drop_caches",
830 .data = &sysctl_drop_caches,
831 .maxlen = sizeof(int),
833 .proc_handler = drop_caches_sysctl_handler,
834 .strategy = &sysctl_intvec,
837 .ctl_name = VM_MIN_FREE_KBYTES,
838 .procname = "min_free_kbytes",
839 .data = &min_free_kbytes,
840 .maxlen = sizeof(min_free_kbytes),
842 .proc_handler = &min_free_kbytes_sysctl_handler,
843 .strategy = &sysctl_intvec,
847 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
848 .procname = "percpu_pagelist_fraction",
849 .data = &percpu_pagelist_fraction,
850 .maxlen = sizeof(percpu_pagelist_fraction),
852 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
853 .strategy = &sysctl_intvec,
854 .extra1 = &min_percpu_pagelist_fract,
858 .ctl_name = VM_MAX_MAP_COUNT,
859 .procname = "max_map_count",
860 .data = &sysctl_max_map_count,
861 .maxlen = sizeof(sysctl_max_map_count),
863 .proc_handler = &proc_dointvec
867 .ctl_name = VM_LAPTOP_MODE,
868 .procname = "laptop_mode",
869 .data = &laptop_mode,
870 .maxlen = sizeof(laptop_mode),
872 .proc_handler = &proc_dointvec_jiffies,
873 .strategy = &sysctl_jiffies,
876 .ctl_name = VM_BLOCK_DUMP,
877 .procname = "block_dump",
879 .maxlen = sizeof(block_dump),
881 .proc_handler = &proc_dointvec,
882 .strategy = &sysctl_intvec,
886 .ctl_name = VM_VFS_CACHE_PRESSURE,
887 .procname = "vfs_cache_pressure",
888 .data = &sysctl_vfs_cache_pressure,
889 .maxlen = sizeof(sysctl_vfs_cache_pressure),
891 .proc_handler = &proc_dointvec,
892 .strategy = &sysctl_intvec,
895 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
897 .ctl_name = VM_LEGACY_VA_LAYOUT,
898 .procname = "legacy_va_layout",
899 .data = &sysctl_legacy_va_layout,
900 .maxlen = sizeof(sysctl_legacy_va_layout),
902 .proc_handler = &proc_dointvec,
903 .strategy = &sysctl_intvec,
909 .ctl_name = VM_ZONE_RECLAIM_MODE,
910 .procname = "zone_reclaim_mode",
911 .data = &zone_reclaim_mode,
912 .maxlen = sizeof(zone_reclaim_mode),
914 .proc_handler = &proc_dointvec,
915 .strategy = &sysctl_intvec,
919 .ctl_name = VM_MIN_UNMAPPED,
920 .procname = "min_unmapped_ratio",
921 .data = &sysctl_min_unmapped_ratio,
922 .maxlen = sizeof(sysctl_min_unmapped_ratio),
924 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
925 .strategy = &sysctl_intvec,
927 .extra2 = &one_hundred,
930 .ctl_name = VM_MIN_SLAB,
931 .procname = "min_slab_ratio",
932 .data = &sysctl_min_slab_ratio,
933 .maxlen = sizeof(sysctl_min_slab_ratio),
935 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
936 .strategy = &sysctl_intvec,
938 .extra2 = &one_hundred,
943 .ctl_name = CTL_UNNUMBERED,
944 .procname = "stat_interval",
945 .data = &sysctl_stat_interval,
946 .maxlen = sizeof(sysctl_stat_interval),
948 .proc_handler = &proc_dointvec_jiffies,
949 .strategy = &sysctl_jiffies,
952 #ifdef CONFIG_SECURITY
954 .ctl_name = CTL_UNNUMBERED,
955 .procname = "mmap_min_addr",
956 .data = &mmap_min_addr,
957 .maxlen = sizeof(unsigned long),
959 .proc_handler = &proc_doulongvec_minmax,
963 .ctl_name = CTL_UNNUMBERED,
964 .procname = "numa_zonelist_order",
965 .data = &numa_zonelist_order,
966 .maxlen = NUMA_ZONELIST_ORDER_LEN,
968 .proc_handler = &numa_zonelist_order_handler,
969 .strategy = &sysctl_string,
973 #if defined(CONFIG_X86_32) || \
974 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
976 .ctl_name = VM_VDSO_ENABLED,
977 .procname = "vdso_enabled",
978 .data = &vdso_enabled,
979 .maxlen = sizeof(vdso_enabled),
981 .proc_handler = &proc_dointvec,
982 .strategy = &sysctl_intvec,
989 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
990 static ctl_table binfmt_misc_table[] = {
995 static ctl_table fs_table[] = {
997 .ctl_name = FS_NRINODE,
998 .procname = "inode-nr",
999 .data = &inodes_stat,
1000 .maxlen = 2*sizeof(int),
1002 .proc_handler = &proc_dointvec,
1005 .ctl_name = FS_STATINODE,
1006 .procname = "inode-state",
1007 .data = &inodes_stat,
1008 .maxlen = 7*sizeof(int),
1010 .proc_handler = &proc_dointvec,
1013 .ctl_name = FS_NRFILE,
1014 .procname = "file-nr",
1015 .data = &files_stat,
1016 .maxlen = 3*sizeof(int),
1018 .proc_handler = &proc_nr_files,
1021 .ctl_name = FS_MAXFILE,
1022 .procname = "file-max",
1023 .data = &files_stat.max_files,
1024 .maxlen = sizeof(int),
1026 .proc_handler = &proc_dointvec,
1029 .ctl_name = FS_DENTRY,
1030 .procname = "dentry-state",
1031 .data = &dentry_stat,
1032 .maxlen = 6*sizeof(int),
1034 .proc_handler = &proc_dointvec,
1037 .ctl_name = FS_OVERFLOWUID,
1038 .procname = "overflowuid",
1039 .data = &fs_overflowuid,
1040 .maxlen = sizeof(int),
1042 .proc_handler = &proc_dointvec_minmax,
1043 .strategy = &sysctl_intvec,
1044 .extra1 = &minolduid,
1045 .extra2 = &maxolduid,
1048 .ctl_name = FS_OVERFLOWGID,
1049 .procname = "overflowgid",
1050 .data = &fs_overflowgid,
1051 .maxlen = sizeof(int),
1053 .proc_handler = &proc_dointvec_minmax,
1054 .strategy = &sysctl_intvec,
1055 .extra1 = &minolduid,
1056 .extra2 = &maxolduid,
1059 .ctl_name = FS_LEASES,
1060 .procname = "leases-enable",
1061 .data = &leases_enable,
1062 .maxlen = sizeof(int),
1064 .proc_handler = &proc_dointvec,
1066 #ifdef CONFIG_DNOTIFY
1068 .ctl_name = FS_DIR_NOTIFY,
1069 .procname = "dir-notify-enable",
1070 .data = &dir_notify_enable,
1071 .maxlen = sizeof(int),
1073 .proc_handler = &proc_dointvec,
1078 .ctl_name = FS_LEASE_TIME,
1079 .procname = "lease-break-time",
1080 .data = &lease_break_time,
1081 .maxlen = sizeof(int),
1083 .proc_handler = &proc_dointvec,
1086 .ctl_name = FS_AIO_NR,
1087 .procname = "aio-nr",
1089 .maxlen = sizeof(aio_nr),
1091 .proc_handler = &proc_doulongvec_minmax,
1094 .ctl_name = FS_AIO_MAX_NR,
1095 .procname = "aio-max-nr",
1096 .data = &aio_max_nr,
1097 .maxlen = sizeof(aio_max_nr),
1099 .proc_handler = &proc_doulongvec_minmax,
1101 #ifdef CONFIG_INOTIFY_USER
1103 .ctl_name = FS_INOTIFY,
1104 .procname = "inotify",
1106 .child = inotify_table,
1111 .ctl_name = KERN_SETUID_DUMPABLE,
1112 .procname = "suid_dumpable",
1113 .data = &suid_dumpable,
1114 .maxlen = sizeof(int),
1116 .proc_handler = &proc_dointvec,
1118 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1120 .ctl_name = CTL_UNNUMBERED,
1121 .procname = "binfmt_misc",
1123 .child = binfmt_misc_table,
1129 static ctl_table debug_table[] = {
1133 static ctl_table dev_table[] = {
1137 static DEFINE_SPINLOCK(sysctl_lock);
1139 /* called under sysctl_lock */
1140 static int use_table(struct ctl_table_header *p)
1142 if (unlikely(p->unregistering))
1148 /* called under sysctl_lock */
1149 static void unuse_table(struct ctl_table_header *p)
1152 if (unlikely(p->unregistering))
1153 complete(p->unregistering);
1156 /* called under sysctl_lock, will reacquire if has to wait */
1157 static void start_unregistering(struct ctl_table_header *p)
1160 * if p->used is 0, nobody will ever touch that entry again;
1161 * we'll eliminate all paths to it before dropping sysctl_lock
1163 if (unlikely(p->used)) {
1164 struct completion wait;
1165 init_completion(&wait);
1166 p->unregistering = &wait;
1167 spin_unlock(&sysctl_lock);
1168 wait_for_completion(&wait);
1169 spin_lock(&sysctl_lock);
1172 * do not remove from the list until nobody holds it; walking the
1173 * list in do_sysctl() relies on that.
1175 list_del_init(&p->ctl_entry);
1178 void sysctl_head_finish(struct ctl_table_header *head)
1182 spin_lock(&sysctl_lock);
1184 spin_unlock(&sysctl_lock);
1187 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1189 struct ctl_table_header *head;
1190 struct list_head *tmp;
1191 spin_lock(&sysctl_lock);
1193 tmp = &prev->ctl_entry;
1197 tmp = &root_table_header.ctl_entry;
1199 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1201 if (!use_table(head))
1203 spin_unlock(&sysctl_lock);
1207 if (tmp == &root_table_header.ctl_entry)
1210 spin_unlock(&sysctl_lock);
1214 #ifdef CONFIG_SYSCTL_SYSCALL
1215 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1216 void __user *newval, size_t newlen)
1218 struct ctl_table_header *head;
1219 int error = -ENOTDIR;
1221 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1225 if (!oldlenp || get_user(old_len, oldlenp))
1229 for (head = sysctl_head_next(NULL); head;
1230 head = sysctl_head_next(head)) {
1231 error = parse_table(name, nlen, oldval, oldlenp,
1232 newval, newlen, head->ctl_table);
1233 if (error != -ENOTDIR) {
1234 sysctl_head_finish(head);
1241 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1243 struct __sysctl_args tmp;
1246 if (copy_from_user(&tmp, args, sizeof(tmp)))
1250 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1251 tmp.newval, tmp.newlen);
1255 #endif /* CONFIG_SYSCTL_SYSCALL */
1258 * sysctl_perm does NOT grant the superuser all rights automatically, because
1259 * some sysctl variables are readonly even to root.
1262 static int test_perm(int mode, int op)
1266 else if (in_egroup_p(0))
1268 if ((mode & op & 0007) == op)
1273 int sysctl_perm(ctl_table *table, int op)
1276 error = security_sysctl(table, op);
1279 return test_perm(table->mode, op);
1282 #ifdef CONFIG_SYSCTL_SYSCALL
1283 static int parse_table(int __user *name, int nlen,
1284 void __user *oldval, size_t __user *oldlenp,
1285 void __user *newval, size_t newlen,
1292 if (get_user(n, name))
1294 for ( ; table->ctl_name || table->procname; table++) {
1295 if (!table->ctl_name)
1297 if (n == table->ctl_name) {
1300 if (sysctl_perm(table, 001))
1304 table = table->child;
1307 error = do_sysctl_strategy(table, name, nlen,
1316 /* Perform the actual read/write of a sysctl table entry. */
1317 int do_sysctl_strategy (ctl_table *table,
1318 int __user *name, int nlen,
1319 void __user *oldval, size_t __user *oldlenp,
1320 void __user *newval, size_t newlen)
1329 if (sysctl_perm(table, op))
1332 if (table->strategy) {
1333 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1341 /* If there is no strategy routine, or if the strategy returns
1342 * zero, proceed with automatic r/w */
1343 if (table->data && table->maxlen) {
1344 if (oldval && oldlenp) {
1345 if (get_user(len, oldlenp))
1348 if (len > table->maxlen)
1349 len = table->maxlen;
1350 if(copy_to_user(oldval, table->data, len))
1352 if(put_user(len, oldlenp))
1356 if (newval && newlen) {
1358 if (len > table->maxlen)
1359 len = table->maxlen;
1360 if(copy_from_user(table->data, newval, len))
1366 #endif /* CONFIG_SYSCTL_SYSCALL */
1368 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1370 for (; table->ctl_name || table->procname; table++) {
1371 table->parent = parent;
1373 sysctl_set_parent(table, table->child);
1377 static __init int sysctl_init(void)
1379 sysctl_set_parent(NULL, root_table);
1383 core_initcall(sysctl_init);
1386 * register_sysctl_table - register a sysctl hierarchy
1387 * @table: the top-level table structure
1389 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1390 * array. An entry with a ctl_name of 0 terminates the table.
1392 * The members of the &ctl_table structure are used as follows:
1394 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1395 * must be unique within that level of sysctl
1397 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1398 * enter a sysctl file
1400 * data - a pointer to data for use by proc_handler
1402 * maxlen - the maximum size in bytes of the data
1404 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1406 * child - a pointer to the child sysctl table if this entry is a directory, or
1409 * proc_handler - the text handler routine (described below)
1411 * strategy - the strategy routine (described below)
1413 * de - for internal use by the sysctl routines
1415 * extra1, extra2 - extra pointers usable by the proc handler routines
1417 * Leaf nodes in the sysctl tree will be represented by a single file
1418 * under /proc; non-leaf nodes will be represented by directories.
1420 * sysctl(2) can automatically manage read and write requests through
1421 * the sysctl table. The data and maxlen fields of the ctl_table
1422 * struct enable minimal validation of the values being written to be
1423 * performed, and the mode field allows minimal authentication.
1425 * More sophisticated management can be enabled by the provision of a
1426 * strategy routine with the table entry. This will be called before
1427 * any automatic read or write of the data is performed.
1429 * The strategy routine may return
1431 * < 0 - Error occurred (error is passed to user process)
1433 * 0 - OK - proceed with automatic read or write.
1435 * > 0 - OK - read or write has been done by the strategy routine, so
1436 * return immediately.
1438 * There must be a proc_handler routine for any terminal nodes
1439 * mirrored under /proc/sys (non-terminals are handled by a built-in
1440 * directory handler). Several default handlers are available to
1441 * cover common cases -
1443 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1444 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1445 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1447 * It is the handler's job to read the input buffer from user memory
1448 * and process it. The handler should return 0 on success.
1450 * This routine returns %NULL on a failure to register, and a pointer
1451 * to the table header on success.
1453 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1455 struct ctl_table_header *tmp;
1456 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1459 tmp->ctl_table = table;
1460 INIT_LIST_HEAD(&tmp->ctl_entry);
1462 tmp->unregistering = NULL;
1463 sysctl_set_parent(NULL, table);
1464 spin_lock(&sysctl_lock);
1465 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1466 spin_unlock(&sysctl_lock);
1471 * unregister_sysctl_table - unregister a sysctl table hierarchy
1472 * @header: the header returned from register_sysctl_table
1474 * Unregisters the sysctl table and all children. proc entries may not
1475 * actually be removed until they are no longer used by anyone.
1477 void unregister_sysctl_table(struct ctl_table_header * header)
1480 spin_lock(&sysctl_lock);
1481 start_unregistering(header);
1482 spin_unlock(&sysctl_lock);
1486 #else /* !CONFIG_SYSCTL */
1487 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1492 void unregister_sysctl_table(struct ctl_table_header * table)
1496 #endif /* CONFIG_SYSCTL */
1502 #ifdef CONFIG_PROC_SYSCTL
1504 static int _proc_do_string(void* data, int maxlen, int write,
1505 struct file *filp, void __user *buffer,
1506 size_t *lenp, loff_t *ppos)
1512 if (!data || !maxlen || !*lenp) {
1520 while (len < *lenp) {
1521 if (get_user(c, p++))
1523 if (c == 0 || c == '\n')
1529 if(copy_from_user(data, buffer, len))
1531 ((char *) data)[len] = 0;
1549 if(copy_to_user(buffer, data, len))
1552 if(put_user('\n', ((char __user *) buffer) + len))
1563 * proc_dostring - read a string sysctl
1564 * @table: the sysctl table
1565 * @write: %TRUE if this is a write to the sysctl file
1566 * @filp: the file structure
1567 * @buffer: the user buffer
1568 * @lenp: the size of the user buffer
1569 * @ppos: file position
1571 * Reads/writes a string from/to the user buffer. If the kernel
1572 * buffer provided is not large enough to hold the string, the
1573 * string is truncated. The copied string is %NULL-terminated.
1574 * If the string is being read by the user process, it is copied
1575 * and a newline '\n' is added. It is truncated if the buffer is
1578 * Returns 0 on success.
1580 int proc_dostring(ctl_table *table, int write, struct file *filp,
1581 void __user *buffer, size_t *lenp, loff_t *ppos)
1583 return _proc_do_string(table->data, table->maxlen, write, filp,
1584 buffer, lenp, ppos);
1588 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1590 int write, void *data)
1593 *valp = *negp ? -*lvalp : *lvalp;
1598 *lvalp = (unsigned long)-val;
1601 *lvalp = (unsigned long)val;
1607 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1608 int write, struct file *filp, void __user *buffer,
1609 size_t *lenp, loff_t *ppos,
1610 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1611 int write, void *data),
1614 #define TMPBUFLEN 21
1615 int *i, vleft, first=1, neg, val;
1619 char buf[TMPBUFLEN], *p;
1620 char __user *s = buffer;
1622 if (!tbl_data || !table->maxlen || !*lenp ||
1623 (*ppos && !write)) {
1628 i = (int *) tbl_data;
1629 vleft = table->maxlen / sizeof(*i);
1633 conv = do_proc_dointvec_conv;
1635 for (; left && vleft--; i++, first=0) {
1650 if (len > sizeof(buf) - 1)
1651 len = sizeof(buf) - 1;
1652 if (copy_from_user(buf, s, len))
1656 if (*p == '-' && left > 1) {
1660 if (*p < '0' || *p > '9')
1663 lval = simple_strtoul(p, &p, 0);
1666 if ((len < left) && *p && !isspace(*p))
1673 if (conv(&neg, &lval, i, 1, data))
1680 if (conv(&neg, &lval, i, 0, data))
1683 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1687 if(copy_to_user(s, buf, len))
1694 if (!write && !first && left) {
1695 if(put_user('\n', s))
1702 if (get_user(c, s++))
1717 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1718 void __user *buffer, size_t *lenp, loff_t *ppos,
1719 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1720 int write, void *data),
1723 return __do_proc_dointvec(table->data, table, write, filp,
1724 buffer, lenp, ppos, conv, data);
1728 * proc_dointvec - read a vector of integers
1729 * @table: the sysctl table
1730 * @write: %TRUE if this is a write to the sysctl file
1731 * @filp: the file structure
1732 * @buffer: the user buffer
1733 * @lenp: the size of the user buffer
1734 * @ppos: file position
1736 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1737 * values from/to the user buffer, treated as an ASCII string.
1739 * Returns 0 on success.
1741 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1742 void __user *buffer, size_t *lenp, loff_t *ppos)
1744 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1752 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1754 int write, void *data)
1756 int op = *(int *)data;
1758 int val = *negp ? -*lvalp : *lvalp;
1760 case OP_SET: *valp = val; break;
1761 case OP_AND: *valp &= val; break;
1762 case OP_OR: *valp |= val; break;
1768 *lvalp = (unsigned long)-val;
1771 *lvalp = (unsigned long)val;
1778 * init may raise the set.
1781 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1782 void __user *buffer, size_t *lenp, loff_t *ppos)
1786 if (write && !capable(CAP_SYS_MODULE)) {
1790 op = is_init(current) ? OP_SET : OP_AND;
1791 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1792 do_proc_dointvec_bset_conv,&op);
1796 * Taint values can only be increased
1798 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1799 void __user *buffer, size_t *lenp, loff_t *ppos)
1803 if (write && !capable(CAP_SYS_ADMIN))
1807 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1808 do_proc_dointvec_bset_conv,&op);
1811 struct do_proc_dointvec_minmax_conv_param {
1816 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1818 int write, void *data)
1820 struct do_proc_dointvec_minmax_conv_param *param = data;
1822 int val = *negp ? -*lvalp : *lvalp;
1823 if ((param->min && *param->min > val) ||
1824 (param->max && *param->max < val))
1831 *lvalp = (unsigned long)-val;
1834 *lvalp = (unsigned long)val;
1841 * proc_dointvec_minmax - read a vector of integers with min/max values
1842 * @table: the sysctl table
1843 * @write: %TRUE if this is a write to the sysctl file
1844 * @filp: the file structure
1845 * @buffer: the user buffer
1846 * @lenp: the size of the user buffer
1847 * @ppos: file position
1849 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1850 * values from/to the user buffer, treated as an ASCII string.
1852 * This routine will ensure the values are within the range specified by
1853 * table->extra1 (min) and table->extra2 (max).
1855 * Returns 0 on success.
1857 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1858 void __user *buffer, size_t *lenp, loff_t *ppos)
1860 struct do_proc_dointvec_minmax_conv_param param = {
1861 .min = (int *) table->extra1,
1862 .max = (int *) table->extra2,
1864 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1865 do_proc_dointvec_minmax_conv, ¶m);
1868 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1870 void __user *buffer,
1871 size_t *lenp, loff_t *ppos,
1872 unsigned long convmul,
1873 unsigned long convdiv)
1875 #define TMPBUFLEN 21
1876 unsigned long *i, *min, *max, val;
1877 int vleft, first=1, neg;
1879 char buf[TMPBUFLEN], *p;
1880 char __user *s = buffer;
1882 if (!data || !table->maxlen || !*lenp ||
1883 (*ppos && !write)) {
1888 i = (unsigned long *) data;
1889 min = (unsigned long *) table->extra1;
1890 max = (unsigned long *) table->extra2;
1891 vleft = table->maxlen / sizeof(unsigned long);
1894 for (; left && vleft--; i++, min++, max++, first=0) {
1909 if (len > TMPBUFLEN-1)
1911 if (copy_from_user(buf, s, len))
1915 if (*p == '-' && left > 1) {
1919 if (*p < '0' || *p > '9')
1921 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1923 if ((len < left) && *p && !isspace(*p))
1932 if ((min && val < *min) || (max && val > *max))
1939 sprintf(p, "%lu", convdiv * (*i) / convmul);
1943 if(copy_to_user(s, buf, len))
1950 if (!write && !first && left) {
1951 if(put_user('\n', s))
1958 if (get_user(c, s++))
1973 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1975 void __user *buffer,
1976 size_t *lenp, loff_t *ppos,
1977 unsigned long convmul,
1978 unsigned long convdiv)
1980 return __do_proc_doulongvec_minmax(table->data, table, write,
1981 filp, buffer, lenp, ppos, convmul, convdiv);
1985 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1986 * @table: the sysctl table
1987 * @write: %TRUE if this is a write to the sysctl file
1988 * @filp: the file structure
1989 * @buffer: the user buffer
1990 * @lenp: the size of the user buffer
1991 * @ppos: file position
1993 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1994 * values from/to the user buffer, treated as an ASCII string.
1996 * This routine will ensure the values are within the range specified by
1997 * table->extra1 (min) and table->extra2 (max).
1999 * Returns 0 on success.
2001 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2002 void __user *buffer, size_t *lenp, loff_t *ppos)
2004 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2008 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2009 * @table: the sysctl table
2010 * @write: %TRUE if this is a write to the sysctl file
2011 * @filp: the file structure
2012 * @buffer: the user buffer
2013 * @lenp: the size of the user buffer
2014 * @ppos: file position
2016 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2017 * values from/to the user buffer, treated as an ASCII string. The values
2018 * are treated as milliseconds, and converted to jiffies when they are stored.
2020 * This routine will ensure the values are within the range specified by
2021 * table->extra1 (min) and table->extra2 (max).
2023 * Returns 0 on success.
2025 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2027 void __user *buffer,
2028 size_t *lenp, loff_t *ppos)
2030 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2031 lenp, ppos, HZ, 1000l);
2035 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2037 int write, void *data)
2040 if (*lvalp > LONG_MAX / HZ)
2042 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2048 lval = (unsigned long)-val;
2051 lval = (unsigned long)val;
2058 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2060 int write, void *data)
2063 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2065 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2071 lval = (unsigned long)-val;
2074 lval = (unsigned long)val;
2076 *lvalp = jiffies_to_clock_t(lval);
2081 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2083 int write, void *data)
2086 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2092 lval = (unsigned long)-val;
2095 lval = (unsigned long)val;
2097 *lvalp = jiffies_to_msecs(lval);
2103 * proc_dointvec_jiffies - read a vector of integers as seconds
2104 * @table: the sysctl table
2105 * @write: %TRUE if this is a write to the sysctl file
2106 * @filp: the file structure
2107 * @buffer: the user buffer
2108 * @lenp: the size of the user buffer
2109 * @ppos: file position
2111 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2112 * values from/to the user buffer, treated as an ASCII string.
2113 * The values read are assumed to be in seconds, and are converted into
2116 * Returns 0 on success.
2118 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2119 void __user *buffer, size_t *lenp, loff_t *ppos)
2121 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2122 do_proc_dointvec_jiffies_conv,NULL);
2126 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2127 * @table: the sysctl table
2128 * @write: %TRUE if this is a write to the sysctl file
2129 * @filp: the file structure
2130 * @buffer: the user buffer
2131 * @lenp: the size of the user buffer
2132 * @ppos: pointer to the file position
2134 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2135 * values from/to the user buffer, treated as an ASCII string.
2136 * The values read are assumed to be in 1/USER_HZ seconds, and
2137 * are converted into jiffies.
2139 * Returns 0 on success.
2141 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2142 void __user *buffer, size_t *lenp, loff_t *ppos)
2144 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2145 do_proc_dointvec_userhz_jiffies_conv,NULL);
2149 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2150 * @table: the sysctl table
2151 * @write: %TRUE if this is a write to the sysctl file
2152 * @filp: the file structure
2153 * @buffer: the user buffer
2154 * @lenp: the size of the user buffer
2155 * @ppos: file position
2156 * @ppos: the current position in the file
2158 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2159 * values from/to the user buffer, treated as an ASCII string.
2160 * The values read are assumed to be in 1/1000 seconds, and
2161 * are converted into jiffies.
2163 * Returns 0 on success.
2165 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2166 void __user *buffer, size_t *lenp, loff_t *ppos)
2168 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2169 do_proc_dointvec_ms_jiffies_conv, NULL);
2172 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2173 void __user *buffer, size_t *lenp, loff_t *ppos)
2175 struct pid *new_pid;
2179 tmp = pid_nr(cad_pid);
2181 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2182 lenp, ppos, NULL, NULL);
2186 new_pid = find_get_pid(tmp);
2190 put_pid(xchg(&cad_pid, new_pid));
2194 #else /* CONFIG_PROC_FS */
2196 int proc_dostring(ctl_table *table, int write, struct file *filp,
2197 void __user *buffer, size_t *lenp, loff_t *ppos)
2202 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2203 void __user *buffer, size_t *lenp, loff_t *ppos)
2208 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2209 void __user *buffer, size_t *lenp, loff_t *ppos)
2214 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2215 void __user *buffer, size_t *lenp, loff_t *ppos)
2220 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2221 void __user *buffer, size_t *lenp, loff_t *ppos)
2226 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2227 void __user *buffer, size_t *lenp, loff_t *ppos)
2232 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2233 void __user *buffer, size_t *lenp, loff_t *ppos)
2238 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2239 void __user *buffer, size_t *lenp, loff_t *ppos)
2244 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2246 void __user *buffer,
2247 size_t *lenp, loff_t *ppos)
2253 #endif /* CONFIG_PROC_FS */
2256 #ifdef CONFIG_SYSCTL_SYSCALL
2258 * General sysctl support routines
2261 /* The generic string strategy routine: */
2262 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2263 void __user *oldval, size_t __user *oldlenp,
2264 void __user *newval, size_t newlen)
2266 if (!table->data || !table->maxlen)
2269 if (oldval && oldlenp) {
2271 if (get_user(bufsize, oldlenp))
2274 size_t len = strlen(table->data), copied;
2276 /* This shouldn't trigger for a well-formed sysctl */
2277 if (len > table->maxlen)
2278 len = table->maxlen;
2280 /* Copy up to a max of bufsize-1 bytes of the string */
2281 copied = (len >= bufsize) ? bufsize - 1 : len;
2283 if (copy_to_user(oldval, table->data, copied) ||
2284 put_user(0, (char __user *)(oldval + copied)))
2286 if (put_user(len, oldlenp))
2290 if (newval && newlen) {
2291 size_t len = newlen;
2292 if (len > table->maxlen)
2293 len = table->maxlen;
2294 if(copy_from_user(table->data, newval, len))
2296 if (len == table->maxlen)
2298 ((char *) table->data)[len] = 0;
2304 * This function makes sure that all of the integers in the vector
2305 * are between the minimum and maximum values given in the arrays
2306 * table->extra1 and table->extra2, respectively.
2308 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2309 void __user *oldval, size_t __user *oldlenp,
2310 void __user *newval, size_t newlen)
2313 if (newval && newlen) {
2314 int __user *vec = (int __user *) newval;
2315 int *min = (int *) table->extra1;
2316 int *max = (int *) table->extra2;
2320 if (newlen % sizeof(int) != 0)
2323 if (!table->extra1 && !table->extra2)
2326 if (newlen > table->maxlen)
2327 newlen = table->maxlen;
2328 length = newlen / sizeof(int);
2330 for (i = 0; i < length; i++) {
2332 if (get_user(value, vec + i))
2334 if (min && value < min[i])
2336 if (max && value > max[i])
2343 /* Strategy function to convert jiffies to seconds */
2344 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2345 void __user *oldval, size_t __user *oldlenp,
2346 void __user *newval, size_t newlen)
2348 if (oldval && oldlenp) {
2351 if (get_user(olen, oldlenp))
2356 if (olen < sizeof(int))
2359 val = *(int *)(table->data) / HZ;
2360 if (put_user(val, (int __user *)oldval))
2362 if (put_user(sizeof(int), oldlenp))
2366 if (newval && newlen) {
2368 if (newlen != sizeof(int))
2370 if (get_user(new, (int __user *)newval))
2372 *(int *)(table->data) = new*HZ;
2377 /* Strategy function to convert jiffies to seconds */
2378 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2379 void __user *oldval, size_t __user *oldlenp,
2380 void __user *newval, size_t newlen)
2382 if (oldval && oldlenp) {
2385 if (get_user(olen, oldlenp))
2390 if (olen < sizeof(int))
2393 val = jiffies_to_msecs(*(int *)(table->data));
2394 if (put_user(val, (int __user *)oldval))
2396 if (put_user(sizeof(int), oldlenp))
2400 if (newval && newlen) {
2402 if (newlen != sizeof(int))
2404 if (get_user(new, (int __user *)newval))
2406 *(int *)(table->data) = msecs_to_jiffies(new);
2413 #else /* CONFIG_SYSCTL_SYSCALL */
2416 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2418 static int msg_count;
2419 struct __sysctl_args tmp;
2420 int name[CTL_MAXNAME];
2423 /* Read in the sysctl name for better debug message logging */
2424 if (copy_from_user(&tmp, args, sizeof(tmp)))
2426 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2428 for (i = 0; i < tmp.nlen; i++)
2429 if (get_user(name[i], tmp.name + i))
2432 /* Ignore accesses to kernel.version */
2433 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2436 if (msg_count < 5) {
2439 "warning: process `%s' used the removed sysctl "
2440 "system call with ", current->comm);
2441 for (i = 0; i < tmp.nlen; i++)
2442 printk("%d.", name[i]);
2449 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2450 void __user *oldval, size_t __user *oldlenp,
2451 void __user *newval, size_t newlen)
2456 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2457 void __user *oldval, size_t __user *oldlenp,
2458 void __user *newval, size_t newlen)
2463 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2464 void __user *oldval, size_t __user *oldlenp,
2465 void __user *newval, size_t newlen)
2470 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2471 void __user *oldval, size_t __user *oldlenp,
2472 void __user *newval, size_t newlen)
2477 #endif /* CONFIG_SYSCTL_SYSCALL */
2480 * No sense putting this after each symbol definition, twice,
2481 * exception granted :-)
2483 EXPORT_SYMBOL(proc_dointvec);
2484 EXPORT_SYMBOL(proc_dointvec_jiffies);
2485 EXPORT_SYMBOL(proc_dointvec_minmax);
2486 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2487 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2488 EXPORT_SYMBOL(proc_dostring);
2489 EXPORT_SYMBOL(proc_doulongvec_minmax);
2490 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2491 EXPORT_SYMBOL(register_sysctl_table);
2492 EXPORT_SYMBOL(sysctl_intvec);
2493 EXPORT_SYMBOL(sysctl_jiffies);
2494 EXPORT_SYMBOL(sysctl_ms_jiffies);
2495 EXPORT_SYMBOL(sysctl_string);
2496 EXPORT_SYMBOL(unregister_sysctl_table);