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>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/security.h>
42 #include <linux/initrd.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
51 #include <asm/uaccess.h>
52 #include <asm/processor.h>
56 #include <asm/stacktrace.h>
59 #if defined(CONFIG_SYSCTL)
61 /* External variables not in a header file. */
63 extern int print_fatal_signals;
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;
81 extern int audit_argv_kb;
83 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
84 static int maxolduid = 65535;
86 static int min_percpu_pagelist_fract = 8;
88 static int ngroups_max = NGROUPS_MAX;
91 extern char modprobe_path[];
93 #ifdef CONFIG_CHR_DEV_SG
94 extern int sg_big_buff;
98 extern char reboot_command [];
99 extern int stop_a_enabled;
100 extern int scons_pwroff;
104 extern int pwrsw_enabled;
105 extern int unaligned_enabled;
109 #ifdef CONFIG_MATHEMU
110 extern int sysctl_ieee_emulation_warnings;
112 extern int sysctl_userprocess_debug;
113 extern int spin_retry;
116 extern int sysctl_hz_timer;
118 #ifdef CONFIG_BSD_PROCESS_ACCT
119 extern int acct_parm[];
123 extern int no_unaligned_warning;
126 #ifdef CONFIG_RT_MUTEXES
127 extern int max_lock_depth;
130 #ifdef CONFIG_SYSCTL_SYSCALL
131 static int parse_table(int __user *, int, void __user *, size_t __user *,
132 void __user *, size_t, ctl_table *);
136 #ifdef CONFIG_PROC_SYSCTL
137 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
138 void __user *buffer, size_t *lenp, loff_t *ppos);
139 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
140 void __user *buffer, size_t *lenp, loff_t *ppos);
143 static ctl_table root_table[];
144 static struct ctl_table_header root_table_header =
145 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
147 static ctl_table kern_table[];
148 static ctl_table vm_table[];
149 static ctl_table fs_table[];
150 static ctl_table debug_table[];
151 static ctl_table dev_table[];
152 extern ctl_table random_table[];
153 #ifdef CONFIG_UNIX98_PTYS
154 extern ctl_table pty_table[];
156 #ifdef CONFIG_INOTIFY_USER
157 extern ctl_table inotify_table[];
160 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
161 int sysctl_legacy_va_layout;
165 /* The default sysctl tables: */
167 static ctl_table root_table[] = {
169 .ctl_name = CTL_KERN,
170 .procname = "kernel",
195 .ctl_name = CTL_DEBUG,
198 .child = debug_table,
207 * NOTE: do not add new entries to this table unless you have read
208 * Documentation/sysctl/ctl_unnumbered.txt
213 #ifdef CONFIG_SCHED_DEBUG
214 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
215 static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
216 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
217 static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
220 static ctl_table kern_table[] = {
221 #ifdef CONFIG_SCHED_DEBUG
223 .ctl_name = CTL_UNNUMBERED,
224 .procname = "sched_granularity_ns",
225 .data = &sysctl_sched_granularity,
226 .maxlen = sizeof(unsigned int),
228 .proc_handler = &proc_dointvec_minmax,
229 .strategy = &sysctl_intvec,
230 .extra1 = &min_sched_granularity_ns,
231 .extra2 = &max_sched_granularity_ns,
234 .ctl_name = CTL_UNNUMBERED,
235 .procname = "sched_wakeup_granularity_ns",
236 .data = &sysctl_sched_wakeup_granularity,
237 .maxlen = sizeof(unsigned int),
239 .proc_handler = &proc_dointvec_minmax,
240 .strategy = &sysctl_intvec,
241 .extra1 = &min_wakeup_granularity_ns,
242 .extra2 = &max_wakeup_granularity_ns,
245 .ctl_name = CTL_UNNUMBERED,
246 .procname = "sched_batch_wakeup_granularity_ns",
247 .data = &sysctl_sched_batch_wakeup_granularity,
248 .maxlen = sizeof(unsigned int),
250 .proc_handler = &proc_dointvec_minmax,
251 .strategy = &sysctl_intvec,
252 .extra1 = &min_wakeup_granularity_ns,
253 .extra2 = &max_wakeup_granularity_ns,
256 .ctl_name = CTL_UNNUMBERED,
257 .procname = "sched_stat_granularity_ns",
258 .data = &sysctl_sched_stat_granularity,
259 .maxlen = sizeof(unsigned int),
261 .proc_handler = &proc_dointvec_minmax,
262 .strategy = &sysctl_intvec,
263 .extra1 = &min_wakeup_granularity_ns,
264 .extra2 = &max_wakeup_granularity_ns,
267 .ctl_name = CTL_UNNUMBERED,
268 .procname = "sched_runtime_limit_ns",
269 .data = &sysctl_sched_runtime_limit,
270 .maxlen = sizeof(unsigned int),
272 .proc_handler = &proc_dointvec_minmax,
273 .strategy = &sysctl_intvec,
274 .extra1 = &min_sched_granularity_ns,
275 .extra2 = &max_sched_granularity_ns,
278 .ctl_name = CTL_UNNUMBERED,
279 .procname = "sched_child_runs_first",
280 .data = &sysctl_sched_child_runs_first,
281 .maxlen = sizeof(unsigned int),
283 .proc_handler = &proc_dointvec,
286 .ctl_name = CTL_UNNUMBERED,
287 .procname = "sched_features",
288 .data = &sysctl_sched_features,
289 .maxlen = sizeof(unsigned int),
291 .proc_handler = &proc_dointvec,
295 .ctl_name = KERN_PANIC,
297 .data = &panic_timeout,
298 .maxlen = sizeof(int),
300 .proc_handler = &proc_dointvec,
303 .ctl_name = KERN_CORE_USES_PID,
304 .procname = "core_uses_pid",
305 .data = &core_uses_pid,
306 .maxlen = sizeof(int),
308 .proc_handler = &proc_dointvec,
310 #ifdef CONFIG_AUDITSYSCALL
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "audit_argv_kb",
314 .data = &audit_argv_kb,
315 .maxlen = sizeof(int),
317 .proc_handler = &proc_dointvec,
321 .ctl_name = KERN_CORE_PATTERN,
322 .procname = "core_pattern",
323 .data = core_pattern,
324 .maxlen = CORENAME_MAX_SIZE,
326 .proc_handler = &proc_dostring,
327 .strategy = &sysctl_string,
329 #ifdef CONFIG_PROC_SYSCTL
331 .ctl_name = KERN_TAINTED,
332 .procname = "tainted",
334 .maxlen = sizeof(int),
336 .proc_handler = &proc_dointvec_taint,
340 .ctl_name = KERN_CAP_BSET,
341 .procname = "cap-bound",
343 .maxlen = sizeof(kernel_cap_t),
345 .proc_handler = &proc_dointvec_bset,
347 #ifdef CONFIG_BLK_DEV_INITRD
349 .ctl_name = KERN_REALROOTDEV,
350 .procname = "real-root-dev",
351 .data = &real_root_dev,
352 .maxlen = sizeof(int),
354 .proc_handler = &proc_dointvec,
358 .ctl_name = CTL_UNNUMBERED,
359 .procname = "print-fatal-signals",
360 .data = &print_fatal_signals,
361 .maxlen = sizeof(int),
363 .proc_handler = &proc_dointvec,
367 .ctl_name = KERN_SPARC_REBOOT,
368 .procname = "reboot-cmd",
369 .data = reboot_command,
372 .proc_handler = &proc_dostring,
373 .strategy = &sysctl_string,
376 .ctl_name = KERN_SPARC_STOP_A,
377 .procname = "stop-a",
378 .data = &stop_a_enabled,
379 .maxlen = sizeof (int),
381 .proc_handler = &proc_dointvec,
384 .ctl_name = KERN_SPARC_SCONS_PWROFF,
385 .procname = "scons-poweroff",
386 .data = &scons_pwroff,
387 .maxlen = sizeof (int),
389 .proc_handler = &proc_dointvec,
394 .ctl_name = KERN_HPPA_PWRSW,
395 .procname = "soft-power",
396 .data = &pwrsw_enabled,
397 .maxlen = sizeof (int),
399 .proc_handler = &proc_dointvec,
402 .ctl_name = KERN_HPPA_UNALIGNED,
403 .procname = "unaligned-trap",
404 .data = &unaligned_enabled,
405 .maxlen = sizeof (int),
407 .proc_handler = &proc_dointvec,
411 .ctl_name = KERN_CTLALTDEL,
412 .procname = "ctrl-alt-del",
414 .maxlen = sizeof(int),
416 .proc_handler = &proc_dointvec,
419 .ctl_name = KERN_PRINTK,
420 .procname = "printk",
421 .data = &console_loglevel,
422 .maxlen = 4*sizeof(int),
424 .proc_handler = &proc_dointvec,
428 .ctl_name = KERN_MODPROBE,
429 .procname = "modprobe",
430 .data = &modprobe_path,
431 .maxlen = KMOD_PATH_LEN,
433 .proc_handler = &proc_dostring,
434 .strategy = &sysctl_string,
437 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
439 .ctl_name = KERN_HOTPLUG,
440 .procname = "hotplug",
441 .data = &uevent_helper,
442 .maxlen = UEVENT_HELPER_PATH_LEN,
444 .proc_handler = &proc_dostring,
445 .strategy = &sysctl_string,
448 #ifdef CONFIG_CHR_DEV_SG
450 .ctl_name = KERN_SG_BIG_BUFF,
451 .procname = "sg-big-buff",
452 .data = &sg_big_buff,
453 .maxlen = sizeof (int),
455 .proc_handler = &proc_dointvec,
458 #ifdef CONFIG_BSD_PROCESS_ACCT
460 .ctl_name = KERN_ACCT,
463 .maxlen = 3*sizeof(int),
465 .proc_handler = &proc_dointvec,
468 #ifdef CONFIG_MAGIC_SYSRQ
470 .ctl_name = KERN_SYSRQ,
472 .data = &__sysrq_enabled,
473 .maxlen = sizeof (int),
475 .proc_handler = &proc_dointvec,
478 #ifdef CONFIG_PROC_SYSCTL
480 .ctl_name = KERN_CADPID,
481 .procname = "cad_pid",
483 .maxlen = sizeof (int),
485 .proc_handler = &proc_do_cad_pid,
489 .ctl_name = KERN_MAX_THREADS,
490 .procname = "threads-max",
491 .data = &max_threads,
492 .maxlen = sizeof(int),
494 .proc_handler = &proc_dointvec,
497 .ctl_name = KERN_RANDOM,
498 .procname = "random",
500 .child = random_table,
502 #ifdef CONFIG_UNIX98_PTYS
504 .ctl_name = KERN_PTY,
511 .ctl_name = KERN_OVERFLOWUID,
512 .procname = "overflowuid",
513 .data = &overflowuid,
514 .maxlen = sizeof(int),
516 .proc_handler = &proc_dointvec_minmax,
517 .strategy = &sysctl_intvec,
518 .extra1 = &minolduid,
519 .extra2 = &maxolduid,
522 .ctl_name = KERN_OVERFLOWGID,
523 .procname = "overflowgid",
524 .data = &overflowgid,
525 .maxlen = sizeof(int),
527 .proc_handler = &proc_dointvec_minmax,
528 .strategy = &sysctl_intvec,
529 .extra1 = &minolduid,
530 .extra2 = &maxolduid,
533 #ifdef CONFIG_MATHEMU
535 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
536 .procname = "ieee_emulation_warnings",
537 .data = &sysctl_ieee_emulation_warnings,
538 .maxlen = sizeof(int),
540 .proc_handler = &proc_dointvec,
543 #ifdef CONFIG_NO_IDLE_HZ
545 .ctl_name = KERN_HZ_TIMER,
546 .procname = "hz_timer",
547 .data = &sysctl_hz_timer,
548 .maxlen = sizeof(int),
550 .proc_handler = &proc_dointvec,
554 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
555 .procname = "userprocess_debug",
556 .data = &sysctl_userprocess_debug,
557 .maxlen = sizeof(int),
559 .proc_handler = &proc_dointvec,
563 .ctl_name = KERN_PIDMAX,
564 .procname = "pid_max",
566 .maxlen = sizeof (int),
568 .proc_handler = &proc_dointvec_minmax,
569 .strategy = sysctl_intvec,
570 .extra1 = &pid_max_min,
571 .extra2 = &pid_max_max,
574 .ctl_name = KERN_PANIC_ON_OOPS,
575 .procname = "panic_on_oops",
576 .data = &panic_on_oops,
577 .maxlen = sizeof(int),
579 .proc_handler = &proc_dointvec,
582 .ctl_name = KERN_PRINTK_RATELIMIT,
583 .procname = "printk_ratelimit",
584 .data = &printk_ratelimit_jiffies,
585 .maxlen = sizeof(int),
587 .proc_handler = &proc_dointvec_jiffies,
588 .strategy = &sysctl_jiffies,
591 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
592 .procname = "printk_ratelimit_burst",
593 .data = &printk_ratelimit_burst,
594 .maxlen = sizeof(int),
596 .proc_handler = &proc_dointvec,
599 .ctl_name = KERN_NGROUPS_MAX,
600 .procname = "ngroups_max",
601 .data = &ngroups_max,
602 .maxlen = sizeof (int),
604 .proc_handler = &proc_dointvec,
606 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
608 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
609 .procname = "unknown_nmi_panic",
610 .data = &unknown_nmi_panic,
611 .maxlen = sizeof (int),
613 .proc_handler = &proc_dointvec,
616 .ctl_name = KERN_NMI_WATCHDOG,
617 .procname = "nmi_watchdog",
618 .data = &nmi_watchdog_enabled,
619 .maxlen = sizeof (int),
621 .proc_handler = &proc_nmi_enabled,
624 #if defined(CONFIG_X86)
626 .ctl_name = KERN_PANIC_ON_NMI,
627 .procname = "panic_on_unrecovered_nmi",
628 .data = &panic_on_unrecovered_nmi,
629 .maxlen = sizeof(int),
631 .proc_handler = &proc_dointvec,
634 .ctl_name = KERN_BOOTLOADER_TYPE,
635 .procname = "bootloader_type",
636 .data = &bootloader_type,
637 .maxlen = sizeof (int),
639 .proc_handler = &proc_dointvec,
642 .ctl_name = CTL_UNNUMBERED,
643 .procname = "kstack_depth_to_print",
644 .data = &kstack_depth_to_print,
645 .maxlen = sizeof(int),
647 .proc_handler = &proc_dointvec,
650 #if defined(CONFIG_MMU)
652 .ctl_name = KERN_RANDOMIZE,
653 .procname = "randomize_va_space",
654 .data = &randomize_va_space,
655 .maxlen = sizeof(int),
657 .proc_handler = &proc_dointvec,
660 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
662 .ctl_name = KERN_SPIN_RETRY,
663 .procname = "spin_retry",
665 .maxlen = sizeof (int),
667 .proc_handler = &proc_dointvec,
670 #ifdef CONFIG_ACPI_SLEEP
672 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
673 .procname = "acpi_video_flags",
674 .data = &acpi_realmode_flags,
675 .maxlen = sizeof (unsigned long),
677 .proc_handler = &proc_doulongvec_minmax,
682 .ctl_name = KERN_IA64_UNALIGNED,
683 .procname = "ignore-unaligned-usertrap",
684 .data = &no_unaligned_warning,
685 .maxlen = sizeof (int),
687 .proc_handler = &proc_dointvec,
692 .ctl_name = KERN_COMPAT_LOG,
693 .procname = "compat-log",
695 .maxlen = sizeof (int),
697 .proc_handler = &proc_dointvec,
700 #ifdef CONFIG_RT_MUTEXES
702 .ctl_name = KERN_MAX_LOCK_DEPTH,
703 .procname = "max_lock_depth",
704 .data = &max_lock_depth,
705 .maxlen = sizeof(int),
707 .proc_handler = &proc_dointvec,
710 #ifdef CONFIG_PROC_FS
712 .ctl_name = CTL_UNNUMBERED,
713 .procname = "maps_protect",
714 .data = &maps_protect,
715 .maxlen = sizeof(int),
717 .proc_handler = &proc_dointvec,
721 .ctl_name = CTL_UNNUMBERED,
722 .procname = "poweroff_cmd",
723 .data = &poweroff_cmd,
724 .maxlen = POWEROFF_CMD_PATH_LEN,
726 .proc_handler = &proc_dostring,
727 .strategy = &sysctl_string,
733 /* Constants for minimum and maximum testing in vm_table.
734 We use these as one-element integer vectors. */
736 static int one_hundred = 100;
739 static ctl_table vm_table[] = {
741 .ctl_name = VM_OVERCOMMIT_MEMORY,
742 .procname = "overcommit_memory",
743 .data = &sysctl_overcommit_memory,
744 .maxlen = sizeof(sysctl_overcommit_memory),
746 .proc_handler = &proc_dointvec,
749 .ctl_name = VM_PANIC_ON_OOM,
750 .procname = "panic_on_oom",
751 .data = &sysctl_panic_on_oom,
752 .maxlen = sizeof(sysctl_panic_on_oom),
754 .proc_handler = &proc_dointvec,
757 .ctl_name = VM_OVERCOMMIT_RATIO,
758 .procname = "overcommit_ratio",
759 .data = &sysctl_overcommit_ratio,
760 .maxlen = sizeof(sysctl_overcommit_ratio),
762 .proc_handler = &proc_dointvec,
765 .ctl_name = VM_PAGE_CLUSTER,
766 .procname = "page-cluster",
767 .data = &page_cluster,
768 .maxlen = sizeof(int),
770 .proc_handler = &proc_dointvec,
773 .ctl_name = VM_DIRTY_BACKGROUND,
774 .procname = "dirty_background_ratio",
775 .data = &dirty_background_ratio,
776 .maxlen = sizeof(dirty_background_ratio),
778 .proc_handler = &proc_dointvec_minmax,
779 .strategy = &sysctl_intvec,
781 .extra2 = &one_hundred,
784 .ctl_name = VM_DIRTY_RATIO,
785 .procname = "dirty_ratio",
786 .data = &vm_dirty_ratio,
787 .maxlen = sizeof(vm_dirty_ratio),
789 .proc_handler = &proc_dointvec_minmax,
790 .strategy = &sysctl_intvec,
792 .extra2 = &one_hundred,
795 .ctl_name = VM_DIRTY_WB_CS,
796 .procname = "dirty_writeback_centisecs",
797 .data = &dirty_writeback_interval,
798 .maxlen = sizeof(dirty_writeback_interval),
800 .proc_handler = &dirty_writeback_centisecs_handler,
803 .ctl_name = VM_DIRTY_EXPIRE_CS,
804 .procname = "dirty_expire_centisecs",
805 .data = &dirty_expire_interval,
806 .maxlen = sizeof(dirty_expire_interval),
808 .proc_handler = &proc_dointvec_userhz_jiffies,
811 .ctl_name = VM_NR_PDFLUSH_THREADS,
812 .procname = "nr_pdflush_threads",
813 .data = &nr_pdflush_threads,
814 .maxlen = sizeof nr_pdflush_threads,
815 .mode = 0444 /* read-only*/,
816 .proc_handler = &proc_dointvec,
819 .ctl_name = VM_SWAPPINESS,
820 .procname = "swappiness",
821 .data = &vm_swappiness,
822 .maxlen = sizeof(vm_swappiness),
824 .proc_handler = &proc_dointvec_minmax,
825 .strategy = &sysctl_intvec,
827 .extra2 = &one_hundred,
829 #ifdef CONFIG_HUGETLB_PAGE
831 .ctl_name = VM_HUGETLB_PAGES,
832 .procname = "nr_hugepages",
833 .data = &max_huge_pages,
834 .maxlen = sizeof(unsigned long),
836 .proc_handler = &hugetlb_sysctl_handler,
837 .extra1 = (void *)&hugetlb_zero,
838 .extra2 = (void *)&hugetlb_infinity,
841 .ctl_name = VM_HUGETLB_GROUP,
842 .procname = "hugetlb_shm_group",
843 .data = &sysctl_hugetlb_shm_group,
844 .maxlen = sizeof(gid_t),
846 .proc_handler = &proc_dointvec,
849 .ctl_name = CTL_UNNUMBERED,
850 .procname = "hugepages_treat_as_movable",
851 .data = &hugepages_treat_as_movable,
852 .maxlen = sizeof(int),
854 .proc_handler = &hugetlb_treat_movable_handler,
858 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
859 .procname = "lowmem_reserve_ratio",
860 .data = &sysctl_lowmem_reserve_ratio,
861 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
863 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
864 .strategy = &sysctl_intvec,
867 .ctl_name = VM_DROP_PAGECACHE,
868 .procname = "drop_caches",
869 .data = &sysctl_drop_caches,
870 .maxlen = sizeof(int),
872 .proc_handler = drop_caches_sysctl_handler,
873 .strategy = &sysctl_intvec,
876 .ctl_name = VM_MIN_FREE_KBYTES,
877 .procname = "min_free_kbytes",
878 .data = &min_free_kbytes,
879 .maxlen = sizeof(min_free_kbytes),
881 .proc_handler = &min_free_kbytes_sysctl_handler,
882 .strategy = &sysctl_intvec,
886 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
887 .procname = "percpu_pagelist_fraction",
888 .data = &percpu_pagelist_fraction,
889 .maxlen = sizeof(percpu_pagelist_fraction),
891 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
892 .strategy = &sysctl_intvec,
893 .extra1 = &min_percpu_pagelist_fract,
897 .ctl_name = VM_MAX_MAP_COUNT,
898 .procname = "max_map_count",
899 .data = &sysctl_max_map_count,
900 .maxlen = sizeof(sysctl_max_map_count),
902 .proc_handler = &proc_dointvec
906 .ctl_name = VM_LAPTOP_MODE,
907 .procname = "laptop_mode",
908 .data = &laptop_mode,
909 .maxlen = sizeof(laptop_mode),
911 .proc_handler = &proc_dointvec_jiffies,
912 .strategy = &sysctl_jiffies,
915 .ctl_name = VM_BLOCK_DUMP,
916 .procname = "block_dump",
918 .maxlen = sizeof(block_dump),
920 .proc_handler = &proc_dointvec,
921 .strategy = &sysctl_intvec,
925 .ctl_name = VM_VFS_CACHE_PRESSURE,
926 .procname = "vfs_cache_pressure",
927 .data = &sysctl_vfs_cache_pressure,
928 .maxlen = sizeof(sysctl_vfs_cache_pressure),
930 .proc_handler = &proc_dointvec,
931 .strategy = &sysctl_intvec,
934 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
936 .ctl_name = VM_LEGACY_VA_LAYOUT,
937 .procname = "legacy_va_layout",
938 .data = &sysctl_legacy_va_layout,
939 .maxlen = sizeof(sysctl_legacy_va_layout),
941 .proc_handler = &proc_dointvec,
942 .strategy = &sysctl_intvec,
948 .ctl_name = VM_ZONE_RECLAIM_MODE,
949 .procname = "zone_reclaim_mode",
950 .data = &zone_reclaim_mode,
951 .maxlen = sizeof(zone_reclaim_mode),
953 .proc_handler = &proc_dointvec,
954 .strategy = &sysctl_intvec,
958 .ctl_name = VM_MIN_UNMAPPED,
959 .procname = "min_unmapped_ratio",
960 .data = &sysctl_min_unmapped_ratio,
961 .maxlen = sizeof(sysctl_min_unmapped_ratio),
963 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
964 .strategy = &sysctl_intvec,
966 .extra2 = &one_hundred,
969 .ctl_name = VM_MIN_SLAB,
970 .procname = "min_slab_ratio",
971 .data = &sysctl_min_slab_ratio,
972 .maxlen = sizeof(sysctl_min_slab_ratio),
974 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
975 .strategy = &sysctl_intvec,
977 .extra2 = &one_hundred,
982 .ctl_name = CTL_UNNUMBERED,
983 .procname = "stat_interval",
984 .data = &sysctl_stat_interval,
985 .maxlen = sizeof(sysctl_stat_interval),
987 .proc_handler = &proc_dointvec_jiffies,
988 .strategy = &sysctl_jiffies,
991 #ifdef CONFIG_SECURITY
993 .ctl_name = CTL_UNNUMBERED,
994 .procname = "mmap_min_addr",
995 .data = &mmap_min_addr,
996 .maxlen = sizeof(unsigned long),
998 .proc_handler = &proc_doulongvec_minmax,
1002 .ctl_name = CTL_UNNUMBERED,
1003 .procname = "numa_zonelist_order",
1004 .data = &numa_zonelist_order,
1005 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1007 .proc_handler = &numa_zonelist_order_handler,
1008 .strategy = &sysctl_string,
1012 #if defined(CONFIG_X86_32) || \
1013 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1015 .ctl_name = VM_VDSO_ENABLED,
1016 .procname = "vdso_enabled",
1017 .data = &vdso_enabled,
1018 .maxlen = sizeof(vdso_enabled),
1020 .proc_handler = &proc_dointvec,
1021 .strategy = &sysctl_intvec,
1026 * NOTE: do not add new entries to this table unless you have read
1027 * Documentation/sysctl/ctl_unnumbered.txt
1032 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1033 static ctl_table binfmt_misc_table[] = {
1038 static ctl_table fs_table[] = {
1040 .ctl_name = FS_NRINODE,
1041 .procname = "inode-nr",
1042 .data = &inodes_stat,
1043 .maxlen = 2*sizeof(int),
1045 .proc_handler = &proc_dointvec,
1048 .ctl_name = FS_STATINODE,
1049 .procname = "inode-state",
1050 .data = &inodes_stat,
1051 .maxlen = 7*sizeof(int),
1053 .proc_handler = &proc_dointvec,
1056 .ctl_name = FS_NRFILE,
1057 .procname = "file-nr",
1058 .data = &files_stat,
1059 .maxlen = 3*sizeof(int),
1061 .proc_handler = &proc_nr_files,
1064 .ctl_name = FS_MAXFILE,
1065 .procname = "file-max",
1066 .data = &files_stat.max_files,
1067 .maxlen = sizeof(int),
1069 .proc_handler = &proc_dointvec,
1072 .ctl_name = FS_DENTRY,
1073 .procname = "dentry-state",
1074 .data = &dentry_stat,
1075 .maxlen = 6*sizeof(int),
1077 .proc_handler = &proc_dointvec,
1080 .ctl_name = FS_OVERFLOWUID,
1081 .procname = "overflowuid",
1082 .data = &fs_overflowuid,
1083 .maxlen = sizeof(int),
1085 .proc_handler = &proc_dointvec_minmax,
1086 .strategy = &sysctl_intvec,
1087 .extra1 = &minolduid,
1088 .extra2 = &maxolduid,
1091 .ctl_name = FS_OVERFLOWGID,
1092 .procname = "overflowgid",
1093 .data = &fs_overflowgid,
1094 .maxlen = sizeof(int),
1096 .proc_handler = &proc_dointvec_minmax,
1097 .strategy = &sysctl_intvec,
1098 .extra1 = &minolduid,
1099 .extra2 = &maxolduid,
1102 .ctl_name = FS_LEASES,
1103 .procname = "leases-enable",
1104 .data = &leases_enable,
1105 .maxlen = sizeof(int),
1107 .proc_handler = &proc_dointvec,
1109 #ifdef CONFIG_DNOTIFY
1111 .ctl_name = FS_DIR_NOTIFY,
1112 .procname = "dir-notify-enable",
1113 .data = &dir_notify_enable,
1114 .maxlen = sizeof(int),
1116 .proc_handler = &proc_dointvec,
1121 .ctl_name = FS_LEASE_TIME,
1122 .procname = "lease-break-time",
1123 .data = &lease_break_time,
1124 .maxlen = sizeof(int),
1126 .proc_handler = &proc_dointvec,
1129 .ctl_name = FS_AIO_NR,
1130 .procname = "aio-nr",
1132 .maxlen = sizeof(aio_nr),
1134 .proc_handler = &proc_doulongvec_minmax,
1137 .ctl_name = FS_AIO_MAX_NR,
1138 .procname = "aio-max-nr",
1139 .data = &aio_max_nr,
1140 .maxlen = sizeof(aio_max_nr),
1142 .proc_handler = &proc_doulongvec_minmax,
1144 #ifdef CONFIG_INOTIFY_USER
1146 .ctl_name = FS_INOTIFY,
1147 .procname = "inotify",
1149 .child = inotify_table,
1154 .ctl_name = KERN_SETUID_DUMPABLE,
1155 .procname = "suid_dumpable",
1156 .data = &suid_dumpable,
1157 .maxlen = sizeof(int),
1159 .proc_handler = &proc_dointvec,
1161 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1163 .ctl_name = CTL_UNNUMBERED,
1164 .procname = "binfmt_misc",
1166 .child = binfmt_misc_table,
1170 * NOTE: do not add new entries to this table unless you have read
1171 * Documentation/sysctl/ctl_unnumbered.txt
1176 static ctl_table debug_table[] = {
1180 static ctl_table dev_table[] = {
1184 static DEFINE_SPINLOCK(sysctl_lock);
1186 /* called under sysctl_lock */
1187 static int use_table(struct ctl_table_header *p)
1189 if (unlikely(p->unregistering))
1195 /* called under sysctl_lock */
1196 static void unuse_table(struct ctl_table_header *p)
1199 if (unlikely(p->unregistering))
1200 complete(p->unregistering);
1203 /* called under sysctl_lock, will reacquire if has to wait */
1204 static void start_unregistering(struct ctl_table_header *p)
1207 * if p->used is 0, nobody will ever touch that entry again;
1208 * we'll eliminate all paths to it before dropping sysctl_lock
1210 if (unlikely(p->used)) {
1211 struct completion wait;
1212 init_completion(&wait);
1213 p->unregistering = &wait;
1214 spin_unlock(&sysctl_lock);
1215 wait_for_completion(&wait);
1216 spin_lock(&sysctl_lock);
1219 * do not remove from the list until nobody holds it; walking the
1220 * list in do_sysctl() relies on that.
1222 list_del_init(&p->ctl_entry);
1225 void sysctl_head_finish(struct ctl_table_header *head)
1229 spin_lock(&sysctl_lock);
1231 spin_unlock(&sysctl_lock);
1234 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1236 struct ctl_table_header *head;
1237 struct list_head *tmp;
1238 spin_lock(&sysctl_lock);
1240 tmp = &prev->ctl_entry;
1244 tmp = &root_table_header.ctl_entry;
1246 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1248 if (!use_table(head))
1250 spin_unlock(&sysctl_lock);
1254 if (tmp == &root_table_header.ctl_entry)
1257 spin_unlock(&sysctl_lock);
1261 #ifdef CONFIG_SYSCTL_SYSCALL
1262 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1263 void __user *newval, size_t newlen)
1265 struct ctl_table_header *head;
1266 int error = -ENOTDIR;
1268 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1272 if (!oldlenp || get_user(old_len, oldlenp))
1276 for (head = sysctl_head_next(NULL); head;
1277 head = sysctl_head_next(head)) {
1278 error = parse_table(name, nlen, oldval, oldlenp,
1279 newval, newlen, head->ctl_table);
1280 if (error != -ENOTDIR) {
1281 sysctl_head_finish(head);
1288 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1290 struct __sysctl_args tmp;
1293 if (copy_from_user(&tmp, args, sizeof(tmp)))
1297 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1298 tmp.newval, tmp.newlen);
1302 #endif /* CONFIG_SYSCTL_SYSCALL */
1305 * sysctl_perm does NOT grant the superuser all rights automatically, because
1306 * some sysctl variables are readonly even to root.
1309 static int test_perm(int mode, int op)
1313 else if (in_egroup_p(0))
1315 if ((mode & op & 0007) == op)
1320 int sysctl_perm(ctl_table *table, int op)
1323 error = security_sysctl(table, op);
1326 return test_perm(table->mode, op);
1329 #ifdef CONFIG_SYSCTL_SYSCALL
1330 static int parse_table(int __user *name, int nlen,
1331 void __user *oldval, size_t __user *oldlenp,
1332 void __user *newval, size_t newlen,
1339 if (get_user(n, name))
1341 for ( ; table->ctl_name || table->procname; table++) {
1342 if (!table->ctl_name)
1344 if (n == table->ctl_name) {
1347 if (sysctl_perm(table, 001))
1351 table = table->child;
1354 error = do_sysctl_strategy(table, name, nlen,
1363 /* Perform the actual read/write of a sysctl table entry. */
1364 int do_sysctl_strategy (ctl_table *table,
1365 int __user *name, int nlen,
1366 void __user *oldval, size_t __user *oldlenp,
1367 void __user *newval, size_t newlen)
1376 if (sysctl_perm(table, op))
1379 if (table->strategy) {
1380 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1388 /* If there is no strategy routine, or if the strategy returns
1389 * zero, proceed with automatic r/w */
1390 if (table->data && table->maxlen) {
1391 if (oldval && oldlenp) {
1392 if (get_user(len, oldlenp))
1395 if (len > table->maxlen)
1396 len = table->maxlen;
1397 if(copy_to_user(oldval, table->data, len))
1399 if(put_user(len, oldlenp))
1403 if (newval && newlen) {
1405 if (len > table->maxlen)
1406 len = table->maxlen;
1407 if(copy_from_user(table->data, newval, len))
1413 #endif /* CONFIG_SYSCTL_SYSCALL */
1415 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1417 for (; table->ctl_name || table->procname; table++) {
1418 table->parent = parent;
1420 sysctl_set_parent(table, table->child);
1424 static __init int sysctl_init(void)
1426 sysctl_set_parent(NULL, root_table);
1430 core_initcall(sysctl_init);
1433 * register_sysctl_table - register a sysctl hierarchy
1434 * @table: the top-level table structure
1436 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1437 * array. An entry with a ctl_name of 0 terminates the table.
1439 * The members of the &ctl_table structure are used as follows:
1441 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1442 * must be unique within that level of sysctl
1444 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1445 * enter a sysctl file
1447 * data - a pointer to data for use by proc_handler
1449 * maxlen - the maximum size in bytes of the data
1451 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1453 * child - a pointer to the child sysctl table if this entry is a directory, or
1456 * proc_handler - the text handler routine (described below)
1458 * strategy - the strategy routine (described below)
1460 * de - for internal use by the sysctl routines
1462 * extra1, extra2 - extra pointers usable by the proc handler routines
1464 * Leaf nodes in the sysctl tree will be represented by a single file
1465 * under /proc; non-leaf nodes will be represented by directories.
1467 * sysctl(2) can automatically manage read and write requests through
1468 * the sysctl table. The data and maxlen fields of the ctl_table
1469 * struct enable minimal validation of the values being written to be
1470 * performed, and the mode field allows minimal authentication.
1472 * More sophisticated management can be enabled by the provision of a
1473 * strategy routine with the table entry. This will be called before
1474 * any automatic read or write of the data is performed.
1476 * The strategy routine may return
1478 * < 0 - Error occurred (error is passed to user process)
1480 * 0 - OK - proceed with automatic read or write.
1482 * > 0 - OK - read or write has been done by the strategy routine, so
1483 * return immediately.
1485 * There must be a proc_handler routine for any terminal nodes
1486 * mirrored under /proc/sys (non-terminals are handled by a built-in
1487 * directory handler). Several default handlers are available to
1488 * cover common cases -
1490 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1491 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1492 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1494 * It is the handler's job to read the input buffer from user memory
1495 * and process it. The handler should return 0 on success.
1497 * This routine returns %NULL on a failure to register, and a pointer
1498 * to the table header on success.
1500 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1502 struct ctl_table_header *tmp;
1503 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1506 tmp->ctl_table = table;
1507 INIT_LIST_HEAD(&tmp->ctl_entry);
1509 tmp->unregistering = NULL;
1510 sysctl_set_parent(NULL, table);
1511 spin_lock(&sysctl_lock);
1512 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1513 spin_unlock(&sysctl_lock);
1518 * unregister_sysctl_table - unregister a sysctl table hierarchy
1519 * @header: the header returned from register_sysctl_table
1521 * Unregisters the sysctl table and all children. proc entries may not
1522 * actually be removed until they are no longer used by anyone.
1524 void unregister_sysctl_table(struct ctl_table_header * header)
1527 spin_lock(&sysctl_lock);
1528 start_unregistering(header);
1529 spin_unlock(&sysctl_lock);
1533 #else /* !CONFIG_SYSCTL */
1534 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1539 void unregister_sysctl_table(struct ctl_table_header * table)
1543 #endif /* CONFIG_SYSCTL */
1549 #ifdef CONFIG_PROC_SYSCTL
1551 static int _proc_do_string(void* data, int maxlen, int write,
1552 struct file *filp, void __user *buffer,
1553 size_t *lenp, loff_t *ppos)
1559 if (!data || !maxlen || !*lenp) {
1567 while (len < *lenp) {
1568 if (get_user(c, p++))
1570 if (c == 0 || c == '\n')
1576 if(copy_from_user(data, buffer, len))
1578 ((char *) data)[len] = 0;
1596 if(copy_to_user(buffer, data, len))
1599 if(put_user('\n', ((char __user *) buffer) + len))
1610 * proc_dostring - read a string sysctl
1611 * @table: the sysctl table
1612 * @write: %TRUE if this is a write to the sysctl file
1613 * @filp: the file structure
1614 * @buffer: the user buffer
1615 * @lenp: the size of the user buffer
1616 * @ppos: file position
1618 * Reads/writes a string from/to the user buffer. If the kernel
1619 * buffer provided is not large enough to hold the string, the
1620 * string is truncated. The copied string is %NULL-terminated.
1621 * If the string is being read by the user process, it is copied
1622 * and a newline '\n' is added. It is truncated if the buffer is
1625 * Returns 0 on success.
1627 int proc_dostring(ctl_table *table, int write, struct file *filp,
1628 void __user *buffer, size_t *lenp, loff_t *ppos)
1630 return _proc_do_string(table->data, table->maxlen, write, filp,
1631 buffer, lenp, ppos);
1635 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1637 int write, void *data)
1640 *valp = *negp ? -*lvalp : *lvalp;
1645 *lvalp = (unsigned long)-val;
1648 *lvalp = (unsigned long)val;
1654 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1655 int write, struct file *filp, void __user *buffer,
1656 size_t *lenp, loff_t *ppos,
1657 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1658 int write, void *data),
1661 #define TMPBUFLEN 21
1662 int *i, vleft, first=1, neg, val;
1666 char buf[TMPBUFLEN], *p;
1667 char __user *s = buffer;
1669 if (!tbl_data || !table->maxlen || !*lenp ||
1670 (*ppos && !write)) {
1675 i = (int *) tbl_data;
1676 vleft = table->maxlen / sizeof(*i);
1680 conv = do_proc_dointvec_conv;
1682 for (; left && vleft--; i++, first=0) {
1697 if (len > sizeof(buf) - 1)
1698 len = sizeof(buf) - 1;
1699 if (copy_from_user(buf, s, len))
1703 if (*p == '-' && left > 1) {
1707 if (*p < '0' || *p > '9')
1710 lval = simple_strtoul(p, &p, 0);
1713 if ((len < left) && *p && !isspace(*p))
1720 if (conv(&neg, &lval, i, 1, data))
1727 if (conv(&neg, &lval, i, 0, data))
1730 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1734 if(copy_to_user(s, buf, len))
1741 if (!write && !first && left) {
1742 if(put_user('\n', s))
1749 if (get_user(c, s++))
1764 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1765 void __user *buffer, size_t *lenp, loff_t *ppos,
1766 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1767 int write, void *data),
1770 return __do_proc_dointvec(table->data, table, write, filp,
1771 buffer, lenp, ppos, conv, data);
1775 * proc_dointvec - read a vector of integers
1776 * @table: the sysctl table
1777 * @write: %TRUE if this is a write to the sysctl file
1778 * @filp: the file structure
1779 * @buffer: the user buffer
1780 * @lenp: the size of the user buffer
1781 * @ppos: file position
1783 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1784 * values from/to the user buffer, treated as an ASCII string.
1786 * Returns 0 on success.
1788 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1789 void __user *buffer, size_t *lenp, loff_t *ppos)
1791 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1799 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1801 int write, void *data)
1803 int op = *(int *)data;
1805 int val = *negp ? -*lvalp : *lvalp;
1807 case OP_SET: *valp = val; break;
1808 case OP_AND: *valp &= val; break;
1809 case OP_OR: *valp |= val; break;
1815 *lvalp = (unsigned long)-val;
1818 *lvalp = (unsigned long)val;
1825 * init may raise the set.
1828 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1829 void __user *buffer, size_t *lenp, loff_t *ppos)
1833 if (write && !capable(CAP_SYS_MODULE)) {
1837 op = is_init(current) ? OP_SET : OP_AND;
1838 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1839 do_proc_dointvec_bset_conv,&op);
1843 * Taint values can only be increased
1845 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1846 void __user *buffer, size_t *lenp, loff_t *ppos)
1850 if (write && !capable(CAP_SYS_ADMIN))
1854 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1855 do_proc_dointvec_bset_conv,&op);
1858 struct do_proc_dointvec_minmax_conv_param {
1863 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1865 int write, void *data)
1867 struct do_proc_dointvec_minmax_conv_param *param = data;
1869 int val = *negp ? -*lvalp : *lvalp;
1870 if ((param->min && *param->min > val) ||
1871 (param->max && *param->max < val))
1878 *lvalp = (unsigned long)-val;
1881 *lvalp = (unsigned long)val;
1888 * proc_dointvec_minmax - read a vector of integers with min/max values
1889 * @table: the sysctl table
1890 * @write: %TRUE if this is a write to the sysctl file
1891 * @filp: the file structure
1892 * @buffer: the user buffer
1893 * @lenp: the size of the user buffer
1894 * @ppos: file position
1896 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1897 * values from/to the user buffer, treated as an ASCII string.
1899 * This routine will ensure the values are within the range specified by
1900 * table->extra1 (min) and table->extra2 (max).
1902 * Returns 0 on success.
1904 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1905 void __user *buffer, size_t *lenp, loff_t *ppos)
1907 struct do_proc_dointvec_minmax_conv_param param = {
1908 .min = (int *) table->extra1,
1909 .max = (int *) table->extra2,
1911 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1912 do_proc_dointvec_minmax_conv, ¶m);
1915 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1917 void __user *buffer,
1918 size_t *lenp, loff_t *ppos,
1919 unsigned long convmul,
1920 unsigned long convdiv)
1922 #define TMPBUFLEN 21
1923 unsigned long *i, *min, *max, val;
1924 int vleft, first=1, neg;
1926 char buf[TMPBUFLEN], *p;
1927 char __user *s = buffer;
1929 if (!data || !table->maxlen || !*lenp ||
1930 (*ppos && !write)) {
1935 i = (unsigned long *) data;
1936 min = (unsigned long *) table->extra1;
1937 max = (unsigned long *) table->extra2;
1938 vleft = table->maxlen / sizeof(unsigned long);
1941 for (; left && vleft--; i++, min++, max++, first=0) {
1956 if (len > TMPBUFLEN-1)
1958 if (copy_from_user(buf, s, len))
1962 if (*p == '-' && left > 1) {
1966 if (*p < '0' || *p > '9')
1968 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1970 if ((len < left) && *p && !isspace(*p))
1979 if ((min && val < *min) || (max && val > *max))
1986 sprintf(p, "%lu", convdiv * (*i) / convmul);
1990 if(copy_to_user(s, buf, len))
1997 if (!write && !first && left) {
1998 if(put_user('\n', s))
2005 if (get_user(c, s++))
2020 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2022 void __user *buffer,
2023 size_t *lenp, loff_t *ppos,
2024 unsigned long convmul,
2025 unsigned long convdiv)
2027 return __do_proc_doulongvec_minmax(table->data, table, write,
2028 filp, buffer, lenp, ppos, convmul, convdiv);
2032 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2033 * @table: the sysctl table
2034 * @write: %TRUE if this is a write to the sysctl file
2035 * @filp: the file structure
2036 * @buffer: the user buffer
2037 * @lenp: the size of the user buffer
2038 * @ppos: file position
2040 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2041 * values from/to the user buffer, treated as an ASCII string.
2043 * This routine will ensure the values are within the range specified by
2044 * table->extra1 (min) and table->extra2 (max).
2046 * Returns 0 on success.
2048 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2049 void __user *buffer, size_t *lenp, loff_t *ppos)
2051 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2055 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2056 * @table: the sysctl table
2057 * @write: %TRUE if this is a write to the sysctl file
2058 * @filp: the file structure
2059 * @buffer: the user buffer
2060 * @lenp: the size of the user buffer
2061 * @ppos: file position
2063 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2064 * values from/to the user buffer, treated as an ASCII string. The values
2065 * are treated as milliseconds, and converted to jiffies when they are stored.
2067 * This routine will ensure the values are within the range specified by
2068 * table->extra1 (min) and table->extra2 (max).
2070 * Returns 0 on success.
2072 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2074 void __user *buffer,
2075 size_t *lenp, loff_t *ppos)
2077 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2078 lenp, ppos, HZ, 1000l);
2082 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2084 int write, void *data)
2087 if (*lvalp > LONG_MAX / HZ)
2089 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2095 lval = (unsigned long)-val;
2098 lval = (unsigned long)val;
2105 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2107 int write, void *data)
2110 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2112 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2118 lval = (unsigned long)-val;
2121 lval = (unsigned long)val;
2123 *lvalp = jiffies_to_clock_t(lval);
2128 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2130 int write, void *data)
2133 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2139 lval = (unsigned long)-val;
2142 lval = (unsigned long)val;
2144 *lvalp = jiffies_to_msecs(lval);
2150 * proc_dointvec_jiffies - read a vector of integers as seconds
2151 * @table: the sysctl table
2152 * @write: %TRUE if this is a write to the sysctl file
2153 * @filp: the file structure
2154 * @buffer: the user buffer
2155 * @lenp: the size of the user buffer
2156 * @ppos: file position
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 seconds, and are converted into
2163 * Returns 0 on success.
2165 int proc_dointvec_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_jiffies_conv,NULL);
2173 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2174 * @table: the sysctl table
2175 * @write: %TRUE if this is a write to the sysctl file
2176 * @filp: the file structure
2177 * @buffer: the user buffer
2178 * @lenp: the size of the user buffer
2179 * @ppos: pointer to the file position
2181 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2182 * values from/to the user buffer, treated as an ASCII string.
2183 * The values read are assumed to be in 1/USER_HZ seconds, and
2184 * are converted into jiffies.
2186 * Returns 0 on success.
2188 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2189 void __user *buffer, size_t *lenp, loff_t *ppos)
2191 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2192 do_proc_dointvec_userhz_jiffies_conv,NULL);
2196 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2197 * @table: the sysctl table
2198 * @write: %TRUE if this is a write to the sysctl file
2199 * @filp: the file structure
2200 * @buffer: the user buffer
2201 * @lenp: the size of the user buffer
2202 * @ppos: file position
2203 * @ppos: the current position in the file
2205 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2206 * values from/to the user buffer, treated as an ASCII string.
2207 * The values read are assumed to be in 1/1000 seconds, and
2208 * are converted into jiffies.
2210 * Returns 0 on success.
2212 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2213 void __user *buffer, size_t *lenp, loff_t *ppos)
2215 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2216 do_proc_dointvec_ms_jiffies_conv, NULL);
2219 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2220 void __user *buffer, size_t *lenp, loff_t *ppos)
2222 struct pid *new_pid;
2226 tmp = pid_nr(cad_pid);
2228 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2229 lenp, ppos, NULL, NULL);
2233 new_pid = find_get_pid(tmp);
2237 put_pid(xchg(&cad_pid, new_pid));
2241 #else /* CONFIG_PROC_FS */
2243 int proc_dostring(ctl_table *table, int write, struct file *filp,
2244 void __user *buffer, size_t *lenp, loff_t *ppos)
2249 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2250 void __user *buffer, size_t *lenp, loff_t *ppos)
2255 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2256 void __user *buffer, size_t *lenp, loff_t *ppos)
2261 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2262 void __user *buffer, size_t *lenp, loff_t *ppos)
2267 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2268 void __user *buffer, size_t *lenp, loff_t *ppos)
2273 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2274 void __user *buffer, size_t *lenp, loff_t *ppos)
2279 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2280 void __user *buffer, size_t *lenp, loff_t *ppos)
2285 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2286 void __user *buffer, size_t *lenp, loff_t *ppos)
2291 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2293 void __user *buffer,
2294 size_t *lenp, loff_t *ppos)
2300 #endif /* CONFIG_PROC_FS */
2303 #ifdef CONFIG_SYSCTL_SYSCALL
2305 * General sysctl support routines
2308 /* The generic string strategy routine: */
2309 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2310 void __user *oldval, size_t __user *oldlenp,
2311 void __user *newval, size_t newlen)
2313 if (!table->data || !table->maxlen)
2316 if (oldval && oldlenp) {
2318 if (get_user(bufsize, oldlenp))
2321 size_t len = strlen(table->data), copied;
2323 /* This shouldn't trigger for a well-formed sysctl */
2324 if (len > table->maxlen)
2325 len = table->maxlen;
2327 /* Copy up to a max of bufsize-1 bytes of the string */
2328 copied = (len >= bufsize) ? bufsize - 1 : len;
2330 if (copy_to_user(oldval, table->data, copied) ||
2331 put_user(0, (char __user *)(oldval + copied)))
2333 if (put_user(len, oldlenp))
2337 if (newval && newlen) {
2338 size_t len = newlen;
2339 if (len > table->maxlen)
2340 len = table->maxlen;
2341 if(copy_from_user(table->data, newval, len))
2343 if (len == table->maxlen)
2345 ((char *) table->data)[len] = 0;
2351 * This function makes sure that all of the integers in the vector
2352 * are between the minimum and maximum values given in the arrays
2353 * table->extra1 and table->extra2, respectively.
2355 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2356 void __user *oldval, size_t __user *oldlenp,
2357 void __user *newval, size_t newlen)
2360 if (newval && newlen) {
2361 int __user *vec = (int __user *) newval;
2362 int *min = (int *) table->extra1;
2363 int *max = (int *) table->extra2;
2367 if (newlen % sizeof(int) != 0)
2370 if (!table->extra1 && !table->extra2)
2373 if (newlen > table->maxlen)
2374 newlen = table->maxlen;
2375 length = newlen / sizeof(int);
2377 for (i = 0; i < length; i++) {
2379 if (get_user(value, vec + i))
2381 if (min && value < min[i])
2383 if (max && value > max[i])
2390 /* Strategy function to convert jiffies to seconds */
2391 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2392 void __user *oldval, size_t __user *oldlenp,
2393 void __user *newval, size_t newlen)
2395 if (oldval && oldlenp) {
2398 if (get_user(olen, oldlenp))
2403 if (olen < sizeof(int))
2406 val = *(int *)(table->data) / HZ;
2407 if (put_user(val, (int __user *)oldval))
2409 if (put_user(sizeof(int), oldlenp))
2413 if (newval && newlen) {
2415 if (newlen != sizeof(int))
2417 if (get_user(new, (int __user *)newval))
2419 *(int *)(table->data) = new*HZ;
2424 /* Strategy function to convert jiffies to seconds */
2425 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2426 void __user *oldval, size_t __user *oldlenp,
2427 void __user *newval, size_t newlen)
2429 if (oldval && oldlenp) {
2432 if (get_user(olen, oldlenp))
2437 if (olen < sizeof(int))
2440 val = jiffies_to_msecs(*(int *)(table->data));
2441 if (put_user(val, (int __user *)oldval))
2443 if (put_user(sizeof(int), oldlenp))
2447 if (newval && newlen) {
2449 if (newlen != sizeof(int))
2451 if (get_user(new, (int __user *)newval))
2453 *(int *)(table->data) = msecs_to_jiffies(new);
2460 #else /* CONFIG_SYSCTL_SYSCALL */
2463 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2465 static int msg_count;
2466 struct __sysctl_args tmp;
2467 int name[CTL_MAXNAME];
2470 /* Read in the sysctl name for better debug message logging */
2471 if (copy_from_user(&tmp, args, sizeof(tmp)))
2473 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2475 for (i = 0; i < tmp.nlen; i++)
2476 if (get_user(name[i], tmp.name + i))
2479 /* Ignore accesses to kernel.version */
2480 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2483 if (msg_count < 5) {
2486 "warning: process `%s' used the removed sysctl "
2487 "system call with ", current->comm);
2488 for (i = 0; i < tmp.nlen; i++)
2489 printk("%d.", name[i]);
2496 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2497 void __user *oldval, size_t __user *oldlenp,
2498 void __user *newval, size_t newlen)
2503 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2504 void __user *oldval, size_t __user *oldlenp,
2505 void __user *newval, size_t newlen)
2510 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2511 void __user *oldval, size_t __user *oldlenp,
2512 void __user *newval, size_t newlen)
2517 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2518 void __user *oldval, size_t __user *oldlenp,
2519 void __user *newval, size_t newlen)
2524 #endif /* CONFIG_SYSCTL_SYSCALL */
2527 * No sense putting this after each symbol definition, twice,
2528 * exception granted :-)
2530 EXPORT_SYMBOL(proc_dointvec);
2531 EXPORT_SYMBOL(proc_dointvec_jiffies);
2532 EXPORT_SYMBOL(proc_dointvec_minmax);
2533 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2534 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2535 EXPORT_SYMBOL(proc_dostring);
2536 EXPORT_SYMBOL(proc_doulongvec_minmax);
2537 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2538 EXPORT_SYMBOL(register_sysctl_table);
2539 EXPORT_SYMBOL(sysctl_intvec);
2540 EXPORT_SYMBOL(sysctl_jiffies);
2541 EXPORT_SYMBOL(sysctl_ms_jiffies);
2542 EXPORT_SYMBOL(sysctl_string);
2543 EXPORT_SYMBOL(unregister_sysctl_table);