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. */
737 static int one_hundred = 100;
740 static ctl_table vm_table[] = {
742 .ctl_name = VM_OVERCOMMIT_MEMORY,
743 .procname = "overcommit_memory",
744 .data = &sysctl_overcommit_memory,
745 .maxlen = sizeof(sysctl_overcommit_memory),
747 .proc_handler = &proc_dointvec,
750 .ctl_name = VM_PANIC_ON_OOM,
751 .procname = "panic_on_oom",
752 .data = &sysctl_panic_on_oom,
753 .maxlen = sizeof(sysctl_panic_on_oom),
755 .proc_handler = &proc_dointvec,
758 .ctl_name = VM_OVERCOMMIT_RATIO,
759 .procname = "overcommit_ratio",
760 .data = &sysctl_overcommit_ratio,
761 .maxlen = sizeof(sysctl_overcommit_ratio),
763 .proc_handler = &proc_dointvec,
766 .ctl_name = VM_PAGE_CLUSTER,
767 .procname = "page-cluster",
768 .data = &page_cluster,
769 .maxlen = sizeof(int),
771 .proc_handler = &proc_dointvec,
774 .ctl_name = VM_DIRTY_BACKGROUND,
775 .procname = "dirty_background_ratio",
776 .data = &dirty_background_ratio,
777 .maxlen = sizeof(dirty_background_ratio),
779 .proc_handler = &proc_dointvec_minmax,
780 .strategy = &sysctl_intvec,
782 .extra2 = &one_hundred,
785 .ctl_name = VM_DIRTY_RATIO,
786 .procname = "dirty_ratio",
787 .data = &vm_dirty_ratio,
788 .maxlen = sizeof(vm_dirty_ratio),
790 .proc_handler = &proc_dointvec_minmax,
791 .strategy = &sysctl_intvec,
793 .extra2 = &one_hundred,
796 .ctl_name = VM_DIRTY_WB_CS,
797 .procname = "dirty_writeback_centisecs",
798 .data = &dirty_writeback_interval,
799 .maxlen = sizeof(dirty_writeback_interval),
801 .proc_handler = &dirty_writeback_centisecs_handler,
804 .ctl_name = VM_DIRTY_EXPIRE_CS,
805 .procname = "dirty_expire_centisecs",
806 .data = &dirty_expire_interval,
807 .maxlen = sizeof(dirty_expire_interval),
809 .proc_handler = &proc_dointvec_userhz_jiffies,
812 .ctl_name = VM_NR_PDFLUSH_THREADS,
813 .procname = "nr_pdflush_threads",
814 .data = &nr_pdflush_threads,
815 .maxlen = sizeof nr_pdflush_threads,
816 .mode = 0444 /* read-only*/,
817 .proc_handler = &proc_dointvec,
820 .ctl_name = VM_SWAPPINESS,
821 .procname = "swappiness",
822 .data = &vm_swappiness,
823 .maxlen = sizeof(vm_swappiness),
825 .proc_handler = &proc_dointvec_minmax,
826 .strategy = &sysctl_intvec,
828 .extra2 = &one_hundred,
830 #ifdef CONFIG_HUGETLB_PAGE
832 .ctl_name = VM_HUGETLB_PAGES,
833 .procname = "nr_hugepages",
834 .data = &max_huge_pages,
835 .maxlen = sizeof(unsigned long),
837 .proc_handler = &hugetlb_sysctl_handler,
838 .extra1 = (void *)&hugetlb_zero,
839 .extra2 = (void *)&hugetlb_infinity,
842 .ctl_name = VM_HUGETLB_GROUP,
843 .procname = "hugetlb_shm_group",
844 .data = &sysctl_hugetlb_shm_group,
845 .maxlen = sizeof(gid_t),
847 .proc_handler = &proc_dointvec,
850 .ctl_name = CTL_UNNUMBERED,
851 .procname = "hugepages_treat_as_movable",
852 .data = &hugepages_treat_as_movable,
853 .maxlen = sizeof(int),
855 .proc_handler = &hugetlb_treat_movable_handler,
859 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
860 .procname = "lowmem_reserve_ratio",
861 .data = &sysctl_lowmem_reserve_ratio,
862 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
864 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
865 .strategy = &sysctl_intvec,
868 .ctl_name = VM_DROP_PAGECACHE,
869 .procname = "drop_caches",
870 .data = &sysctl_drop_caches,
871 .maxlen = sizeof(int),
873 .proc_handler = drop_caches_sysctl_handler,
874 .strategy = &sysctl_intvec,
877 .ctl_name = VM_MIN_FREE_KBYTES,
878 .procname = "min_free_kbytes",
879 .data = &min_free_kbytes,
880 .maxlen = sizeof(min_free_kbytes),
882 .proc_handler = &min_free_kbytes_sysctl_handler,
883 .strategy = &sysctl_intvec,
887 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
888 .procname = "percpu_pagelist_fraction",
889 .data = &percpu_pagelist_fraction,
890 .maxlen = sizeof(percpu_pagelist_fraction),
892 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
893 .strategy = &sysctl_intvec,
894 .extra1 = &min_percpu_pagelist_fract,
898 .ctl_name = VM_MAX_MAP_COUNT,
899 .procname = "max_map_count",
900 .data = &sysctl_max_map_count,
901 .maxlen = sizeof(sysctl_max_map_count),
903 .proc_handler = &proc_dointvec
907 .ctl_name = VM_LAPTOP_MODE,
908 .procname = "laptop_mode",
909 .data = &laptop_mode,
910 .maxlen = sizeof(laptop_mode),
912 .proc_handler = &proc_dointvec_jiffies,
913 .strategy = &sysctl_jiffies,
916 .ctl_name = VM_BLOCK_DUMP,
917 .procname = "block_dump",
919 .maxlen = sizeof(block_dump),
921 .proc_handler = &proc_dointvec,
922 .strategy = &sysctl_intvec,
926 .ctl_name = VM_VFS_CACHE_PRESSURE,
927 .procname = "vfs_cache_pressure",
928 .data = &sysctl_vfs_cache_pressure,
929 .maxlen = sizeof(sysctl_vfs_cache_pressure),
931 .proc_handler = &proc_dointvec,
932 .strategy = &sysctl_intvec,
935 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
937 .ctl_name = VM_LEGACY_VA_LAYOUT,
938 .procname = "legacy_va_layout",
939 .data = &sysctl_legacy_va_layout,
940 .maxlen = sizeof(sysctl_legacy_va_layout),
942 .proc_handler = &proc_dointvec,
943 .strategy = &sysctl_intvec,
949 .ctl_name = VM_ZONE_RECLAIM_MODE,
950 .procname = "zone_reclaim_mode",
951 .data = &zone_reclaim_mode,
952 .maxlen = sizeof(zone_reclaim_mode),
954 .proc_handler = &proc_dointvec,
955 .strategy = &sysctl_intvec,
959 .ctl_name = VM_MIN_UNMAPPED,
960 .procname = "min_unmapped_ratio",
961 .data = &sysctl_min_unmapped_ratio,
962 .maxlen = sizeof(sysctl_min_unmapped_ratio),
964 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
965 .strategy = &sysctl_intvec,
967 .extra2 = &one_hundred,
970 .ctl_name = VM_MIN_SLAB,
971 .procname = "min_slab_ratio",
972 .data = &sysctl_min_slab_ratio,
973 .maxlen = sizeof(sysctl_min_slab_ratio),
975 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
976 .strategy = &sysctl_intvec,
978 .extra2 = &one_hundred,
983 .ctl_name = CTL_UNNUMBERED,
984 .procname = "stat_interval",
985 .data = &sysctl_stat_interval,
986 .maxlen = sizeof(sysctl_stat_interval),
988 .proc_handler = &proc_dointvec_jiffies,
989 .strategy = &sysctl_jiffies,
992 #ifdef CONFIG_SECURITY
994 .ctl_name = CTL_UNNUMBERED,
995 .procname = "mmap_min_addr",
996 .data = &mmap_min_addr,
997 .maxlen = sizeof(unsigned long),
999 .proc_handler = &proc_doulongvec_minmax,
1003 .ctl_name = CTL_UNNUMBERED,
1004 .procname = "numa_zonelist_order",
1005 .data = &numa_zonelist_order,
1006 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1008 .proc_handler = &numa_zonelist_order_handler,
1009 .strategy = &sysctl_string,
1013 #if defined(CONFIG_X86_32) || \
1014 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1016 .ctl_name = VM_VDSO_ENABLED,
1017 .procname = "vdso_enabled",
1018 .data = &vdso_enabled,
1019 .maxlen = sizeof(vdso_enabled),
1021 .proc_handler = &proc_dointvec,
1022 .strategy = &sysctl_intvec,
1027 * NOTE: do not add new entries to this table unless you have read
1028 * Documentation/sysctl/ctl_unnumbered.txt
1033 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1034 static ctl_table binfmt_misc_table[] = {
1039 static ctl_table fs_table[] = {
1041 .ctl_name = FS_NRINODE,
1042 .procname = "inode-nr",
1043 .data = &inodes_stat,
1044 .maxlen = 2*sizeof(int),
1046 .proc_handler = &proc_dointvec,
1049 .ctl_name = FS_STATINODE,
1050 .procname = "inode-state",
1051 .data = &inodes_stat,
1052 .maxlen = 7*sizeof(int),
1054 .proc_handler = &proc_dointvec,
1057 .ctl_name = FS_NRFILE,
1058 .procname = "file-nr",
1059 .data = &files_stat,
1060 .maxlen = 3*sizeof(int),
1062 .proc_handler = &proc_nr_files,
1065 .ctl_name = FS_MAXFILE,
1066 .procname = "file-max",
1067 .data = &files_stat.max_files,
1068 .maxlen = sizeof(int),
1070 .proc_handler = &proc_dointvec,
1073 .ctl_name = FS_DENTRY,
1074 .procname = "dentry-state",
1075 .data = &dentry_stat,
1076 .maxlen = 6*sizeof(int),
1078 .proc_handler = &proc_dointvec,
1081 .ctl_name = FS_OVERFLOWUID,
1082 .procname = "overflowuid",
1083 .data = &fs_overflowuid,
1084 .maxlen = sizeof(int),
1086 .proc_handler = &proc_dointvec_minmax,
1087 .strategy = &sysctl_intvec,
1088 .extra1 = &minolduid,
1089 .extra2 = &maxolduid,
1092 .ctl_name = FS_OVERFLOWGID,
1093 .procname = "overflowgid",
1094 .data = &fs_overflowgid,
1095 .maxlen = sizeof(int),
1097 .proc_handler = &proc_dointvec_minmax,
1098 .strategy = &sysctl_intvec,
1099 .extra1 = &minolduid,
1100 .extra2 = &maxolduid,
1103 .ctl_name = FS_LEASES,
1104 .procname = "leases-enable",
1105 .data = &leases_enable,
1106 .maxlen = sizeof(int),
1108 .proc_handler = &proc_dointvec,
1110 #ifdef CONFIG_DNOTIFY
1112 .ctl_name = FS_DIR_NOTIFY,
1113 .procname = "dir-notify-enable",
1114 .data = &dir_notify_enable,
1115 .maxlen = sizeof(int),
1117 .proc_handler = &proc_dointvec,
1122 .ctl_name = FS_LEASE_TIME,
1123 .procname = "lease-break-time",
1124 .data = &lease_break_time,
1125 .maxlen = sizeof(int),
1127 .proc_handler = &proc_dointvec_minmax,
1128 .strategy = &sysctl_intvec,
1133 .ctl_name = FS_AIO_NR,
1134 .procname = "aio-nr",
1136 .maxlen = sizeof(aio_nr),
1138 .proc_handler = &proc_doulongvec_minmax,
1141 .ctl_name = FS_AIO_MAX_NR,
1142 .procname = "aio-max-nr",
1143 .data = &aio_max_nr,
1144 .maxlen = sizeof(aio_max_nr),
1146 .proc_handler = &proc_doulongvec_minmax,
1148 #ifdef CONFIG_INOTIFY_USER
1150 .ctl_name = FS_INOTIFY,
1151 .procname = "inotify",
1153 .child = inotify_table,
1158 .ctl_name = KERN_SETUID_DUMPABLE,
1159 .procname = "suid_dumpable",
1160 .data = &suid_dumpable,
1161 .maxlen = sizeof(int),
1163 .proc_handler = &proc_dointvec,
1165 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1167 .ctl_name = CTL_UNNUMBERED,
1168 .procname = "binfmt_misc",
1170 .child = binfmt_misc_table,
1174 * NOTE: do not add new entries to this table unless you have read
1175 * Documentation/sysctl/ctl_unnumbered.txt
1180 static ctl_table debug_table[] = {
1184 static ctl_table dev_table[] = {
1188 static DEFINE_SPINLOCK(sysctl_lock);
1190 /* called under sysctl_lock */
1191 static int use_table(struct ctl_table_header *p)
1193 if (unlikely(p->unregistering))
1199 /* called under sysctl_lock */
1200 static void unuse_table(struct ctl_table_header *p)
1203 if (unlikely(p->unregistering))
1204 complete(p->unregistering);
1207 /* called under sysctl_lock, will reacquire if has to wait */
1208 static void start_unregistering(struct ctl_table_header *p)
1211 * if p->used is 0, nobody will ever touch that entry again;
1212 * we'll eliminate all paths to it before dropping sysctl_lock
1214 if (unlikely(p->used)) {
1215 struct completion wait;
1216 init_completion(&wait);
1217 p->unregistering = &wait;
1218 spin_unlock(&sysctl_lock);
1219 wait_for_completion(&wait);
1220 spin_lock(&sysctl_lock);
1223 * do not remove from the list until nobody holds it; walking the
1224 * list in do_sysctl() relies on that.
1226 list_del_init(&p->ctl_entry);
1229 void sysctl_head_finish(struct ctl_table_header *head)
1233 spin_lock(&sysctl_lock);
1235 spin_unlock(&sysctl_lock);
1238 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1240 struct ctl_table_header *head;
1241 struct list_head *tmp;
1242 spin_lock(&sysctl_lock);
1244 tmp = &prev->ctl_entry;
1248 tmp = &root_table_header.ctl_entry;
1250 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1252 if (!use_table(head))
1254 spin_unlock(&sysctl_lock);
1258 if (tmp == &root_table_header.ctl_entry)
1261 spin_unlock(&sysctl_lock);
1265 #ifdef CONFIG_SYSCTL_SYSCALL
1266 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1267 void __user *newval, size_t newlen)
1269 struct ctl_table_header *head;
1270 int error = -ENOTDIR;
1272 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1276 if (!oldlenp || get_user(old_len, oldlenp))
1280 for (head = sysctl_head_next(NULL); head;
1281 head = sysctl_head_next(head)) {
1282 error = parse_table(name, nlen, oldval, oldlenp,
1283 newval, newlen, head->ctl_table);
1284 if (error != -ENOTDIR) {
1285 sysctl_head_finish(head);
1292 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1294 struct __sysctl_args tmp;
1297 if (copy_from_user(&tmp, args, sizeof(tmp)))
1301 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1302 tmp.newval, tmp.newlen);
1306 #endif /* CONFIG_SYSCTL_SYSCALL */
1309 * sysctl_perm does NOT grant the superuser all rights automatically, because
1310 * some sysctl variables are readonly even to root.
1313 static int test_perm(int mode, int op)
1317 else if (in_egroup_p(0))
1319 if ((mode & op & 0007) == op)
1324 int sysctl_perm(ctl_table *table, int op)
1327 error = security_sysctl(table, op);
1330 return test_perm(table->mode, op);
1333 #ifdef CONFIG_SYSCTL_SYSCALL
1334 static int parse_table(int __user *name, int nlen,
1335 void __user *oldval, size_t __user *oldlenp,
1336 void __user *newval, size_t newlen,
1343 if (get_user(n, name))
1345 for ( ; table->ctl_name || table->procname; table++) {
1346 if (!table->ctl_name)
1348 if (n == table->ctl_name) {
1351 if (sysctl_perm(table, 001))
1355 table = table->child;
1358 error = do_sysctl_strategy(table, name, nlen,
1367 /* Perform the actual read/write of a sysctl table entry. */
1368 int do_sysctl_strategy (ctl_table *table,
1369 int __user *name, int nlen,
1370 void __user *oldval, size_t __user *oldlenp,
1371 void __user *newval, size_t newlen)
1380 if (sysctl_perm(table, op))
1383 if (table->strategy) {
1384 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1392 /* If there is no strategy routine, or if the strategy returns
1393 * zero, proceed with automatic r/w */
1394 if (table->data && table->maxlen) {
1395 if (oldval && oldlenp) {
1396 if (get_user(len, oldlenp))
1399 if (len > table->maxlen)
1400 len = table->maxlen;
1401 if(copy_to_user(oldval, table->data, len))
1403 if(put_user(len, oldlenp))
1407 if (newval && newlen) {
1409 if (len > table->maxlen)
1410 len = table->maxlen;
1411 if(copy_from_user(table->data, newval, len))
1417 #endif /* CONFIG_SYSCTL_SYSCALL */
1419 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1421 for (; table->ctl_name || table->procname; table++) {
1422 table->parent = parent;
1424 sysctl_set_parent(table, table->child);
1428 static __init int sysctl_init(void)
1430 sysctl_set_parent(NULL, root_table);
1434 core_initcall(sysctl_init);
1437 * register_sysctl_table - register a sysctl hierarchy
1438 * @table: the top-level table structure
1440 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1441 * array. An entry with a ctl_name of 0 terminates the table.
1443 * The members of the &ctl_table structure are used as follows:
1445 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1446 * must be unique within that level of sysctl
1448 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1449 * enter a sysctl file
1451 * data - a pointer to data for use by proc_handler
1453 * maxlen - the maximum size in bytes of the data
1455 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1457 * child - a pointer to the child sysctl table if this entry is a directory, or
1460 * proc_handler - the text handler routine (described below)
1462 * strategy - the strategy routine (described below)
1464 * de - for internal use by the sysctl routines
1466 * extra1, extra2 - extra pointers usable by the proc handler routines
1468 * Leaf nodes in the sysctl tree will be represented by a single file
1469 * under /proc; non-leaf nodes will be represented by directories.
1471 * sysctl(2) can automatically manage read and write requests through
1472 * the sysctl table. The data and maxlen fields of the ctl_table
1473 * struct enable minimal validation of the values being written to be
1474 * performed, and the mode field allows minimal authentication.
1476 * More sophisticated management can be enabled by the provision of a
1477 * strategy routine with the table entry. This will be called before
1478 * any automatic read or write of the data is performed.
1480 * The strategy routine may return
1482 * < 0 - Error occurred (error is passed to user process)
1484 * 0 - OK - proceed with automatic read or write.
1486 * > 0 - OK - read or write has been done by the strategy routine, so
1487 * return immediately.
1489 * There must be a proc_handler routine for any terminal nodes
1490 * mirrored under /proc/sys (non-terminals are handled by a built-in
1491 * directory handler). Several default handlers are available to
1492 * cover common cases -
1494 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1495 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1496 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1498 * It is the handler's job to read the input buffer from user memory
1499 * and process it. The handler should return 0 on success.
1501 * This routine returns %NULL on a failure to register, and a pointer
1502 * to the table header on success.
1504 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1506 struct ctl_table_header *tmp;
1507 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1510 tmp->ctl_table = table;
1511 INIT_LIST_HEAD(&tmp->ctl_entry);
1513 tmp->unregistering = NULL;
1514 sysctl_set_parent(NULL, table);
1515 spin_lock(&sysctl_lock);
1516 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1517 spin_unlock(&sysctl_lock);
1522 * unregister_sysctl_table - unregister a sysctl table hierarchy
1523 * @header: the header returned from register_sysctl_table
1525 * Unregisters the sysctl table and all children. proc entries may not
1526 * actually be removed until they are no longer used by anyone.
1528 void unregister_sysctl_table(struct ctl_table_header * header)
1531 spin_lock(&sysctl_lock);
1532 start_unregistering(header);
1533 spin_unlock(&sysctl_lock);
1537 #else /* !CONFIG_SYSCTL */
1538 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1543 void unregister_sysctl_table(struct ctl_table_header * table)
1547 #endif /* CONFIG_SYSCTL */
1553 #ifdef CONFIG_PROC_SYSCTL
1555 static int _proc_do_string(void* data, int maxlen, int write,
1556 struct file *filp, void __user *buffer,
1557 size_t *lenp, loff_t *ppos)
1563 if (!data || !maxlen || !*lenp) {
1571 while (len < *lenp) {
1572 if (get_user(c, p++))
1574 if (c == 0 || c == '\n')
1580 if(copy_from_user(data, buffer, len))
1582 ((char *) data)[len] = 0;
1600 if(copy_to_user(buffer, data, len))
1603 if(put_user('\n', ((char __user *) buffer) + len))
1614 * proc_dostring - read a string sysctl
1615 * @table: the sysctl table
1616 * @write: %TRUE if this is a write to the sysctl file
1617 * @filp: the file structure
1618 * @buffer: the user buffer
1619 * @lenp: the size of the user buffer
1620 * @ppos: file position
1622 * Reads/writes a string from/to the user buffer. If the kernel
1623 * buffer provided is not large enough to hold the string, the
1624 * string is truncated. The copied string is %NULL-terminated.
1625 * If the string is being read by the user process, it is copied
1626 * and a newline '\n' is added. It is truncated if the buffer is
1629 * Returns 0 on success.
1631 int proc_dostring(ctl_table *table, int write, struct file *filp,
1632 void __user *buffer, size_t *lenp, loff_t *ppos)
1634 return _proc_do_string(table->data, table->maxlen, write, filp,
1635 buffer, lenp, ppos);
1639 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1641 int write, void *data)
1644 *valp = *negp ? -*lvalp : *lvalp;
1649 *lvalp = (unsigned long)-val;
1652 *lvalp = (unsigned long)val;
1658 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1659 int write, struct file *filp, void __user *buffer,
1660 size_t *lenp, loff_t *ppos,
1661 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1662 int write, void *data),
1665 #define TMPBUFLEN 21
1666 int *i, vleft, first=1, neg, val;
1670 char buf[TMPBUFLEN], *p;
1671 char __user *s = buffer;
1673 if (!tbl_data || !table->maxlen || !*lenp ||
1674 (*ppos && !write)) {
1679 i = (int *) tbl_data;
1680 vleft = table->maxlen / sizeof(*i);
1684 conv = do_proc_dointvec_conv;
1686 for (; left && vleft--; i++, first=0) {
1701 if (len > sizeof(buf) - 1)
1702 len = sizeof(buf) - 1;
1703 if (copy_from_user(buf, s, len))
1707 if (*p == '-' && left > 1) {
1711 if (*p < '0' || *p > '9')
1714 lval = simple_strtoul(p, &p, 0);
1717 if ((len < left) && *p && !isspace(*p))
1724 if (conv(&neg, &lval, i, 1, data))
1731 if (conv(&neg, &lval, i, 0, data))
1734 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1738 if(copy_to_user(s, buf, len))
1745 if (!write && !first && left) {
1746 if(put_user('\n', s))
1753 if (get_user(c, s++))
1768 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1769 void __user *buffer, size_t *lenp, loff_t *ppos,
1770 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1771 int write, void *data),
1774 return __do_proc_dointvec(table->data, table, write, filp,
1775 buffer, lenp, ppos, conv, data);
1779 * proc_dointvec - read a vector of integers
1780 * @table: the sysctl table
1781 * @write: %TRUE if this is a write to the sysctl file
1782 * @filp: the file structure
1783 * @buffer: the user buffer
1784 * @lenp: the size of the user buffer
1785 * @ppos: file position
1787 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1788 * values from/to the user buffer, treated as an ASCII string.
1790 * Returns 0 on success.
1792 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1793 void __user *buffer, size_t *lenp, loff_t *ppos)
1795 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1803 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1805 int write, void *data)
1807 int op = *(int *)data;
1809 int val = *negp ? -*lvalp : *lvalp;
1811 case OP_SET: *valp = val; break;
1812 case OP_AND: *valp &= val; break;
1813 case OP_OR: *valp |= val; break;
1819 *lvalp = (unsigned long)-val;
1822 *lvalp = (unsigned long)val;
1829 * init may raise the set.
1832 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1833 void __user *buffer, size_t *lenp, loff_t *ppos)
1837 if (write && !capable(CAP_SYS_MODULE)) {
1841 op = is_init(current) ? OP_SET : OP_AND;
1842 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1843 do_proc_dointvec_bset_conv,&op);
1847 * Taint values can only be increased
1849 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1850 void __user *buffer, size_t *lenp, loff_t *ppos)
1854 if (write && !capable(CAP_SYS_ADMIN))
1858 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1859 do_proc_dointvec_bset_conv,&op);
1862 struct do_proc_dointvec_minmax_conv_param {
1867 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1869 int write, void *data)
1871 struct do_proc_dointvec_minmax_conv_param *param = data;
1873 int val = *negp ? -*lvalp : *lvalp;
1874 if ((param->min && *param->min > val) ||
1875 (param->max && *param->max < val))
1882 *lvalp = (unsigned long)-val;
1885 *lvalp = (unsigned long)val;
1892 * proc_dointvec_minmax - read a vector of integers with min/max values
1893 * @table: the sysctl table
1894 * @write: %TRUE if this is a write to the sysctl file
1895 * @filp: the file structure
1896 * @buffer: the user buffer
1897 * @lenp: the size of the user buffer
1898 * @ppos: file position
1900 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1901 * values from/to the user buffer, treated as an ASCII string.
1903 * This routine will ensure the values are within the range specified by
1904 * table->extra1 (min) and table->extra2 (max).
1906 * Returns 0 on success.
1908 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1909 void __user *buffer, size_t *lenp, loff_t *ppos)
1911 struct do_proc_dointvec_minmax_conv_param param = {
1912 .min = (int *) table->extra1,
1913 .max = (int *) table->extra2,
1915 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1916 do_proc_dointvec_minmax_conv, ¶m);
1919 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1921 void __user *buffer,
1922 size_t *lenp, loff_t *ppos,
1923 unsigned long convmul,
1924 unsigned long convdiv)
1926 #define TMPBUFLEN 21
1927 unsigned long *i, *min, *max, val;
1928 int vleft, first=1, neg;
1930 char buf[TMPBUFLEN], *p;
1931 char __user *s = buffer;
1933 if (!data || !table->maxlen || !*lenp ||
1934 (*ppos && !write)) {
1939 i = (unsigned long *) data;
1940 min = (unsigned long *) table->extra1;
1941 max = (unsigned long *) table->extra2;
1942 vleft = table->maxlen / sizeof(unsigned long);
1945 for (; left && vleft--; i++, min++, max++, first=0) {
1960 if (len > TMPBUFLEN-1)
1962 if (copy_from_user(buf, s, len))
1966 if (*p == '-' && left > 1) {
1970 if (*p < '0' || *p > '9')
1972 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1974 if ((len < left) && *p && !isspace(*p))
1983 if ((min && val < *min) || (max && val > *max))
1990 sprintf(p, "%lu", convdiv * (*i) / convmul);
1994 if(copy_to_user(s, buf, len))
2001 if (!write && !first && left) {
2002 if(put_user('\n', s))
2009 if (get_user(c, s++))
2024 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2026 void __user *buffer,
2027 size_t *lenp, loff_t *ppos,
2028 unsigned long convmul,
2029 unsigned long convdiv)
2031 return __do_proc_doulongvec_minmax(table->data, table, write,
2032 filp, buffer, lenp, ppos, convmul, convdiv);
2036 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2037 * @table: the sysctl table
2038 * @write: %TRUE if this is a write to the sysctl file
2039 * @filp: the file structure
2040 * @buffer: the user buffer
2041 * @lenp: the size of the user buffer
2042 * @ppos: file position
2044 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2045 * values from/to the user buffer, treated as an ASCII string.
2047 * This routine will ensure the values are within the range specified by
2048 * table->extra1 (min) and table->extra2 (max).
2050 * Returns 0 on success.
2052 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2053 void __user *buffer, size_t *lenp, loff_t *ppos)
2055 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2059 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2060 * @table: the sysctl table
2061 * @write: %TRUE if this is a write to the sysctl file
2062 * @filp: the file structure
2063 * @buffer: the user buffer
2064 * @lenp: the size of the user buffer
2065 * @ppos: file position
2067 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2068 * values from/to the user buffer, treated as an ASCII string. The values
2069 * are treated as milliseconds, and converted to jiffies when they are stored.
2071 * This routine will ensure the values are within the range specified by
2072 * table->extra1 (min) and table->extra2 (max).
2074 * Returns 0 on success.
2076 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2078 void __user *buffer,
2079 size_t *lenp, loff_t *ppos)
2081 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2082 lenp, ppos, HZ, 1000l);
2086 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2088 int write, void *data)
2091 if (*lvalp > LONG_MAX / HZ)
2093 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2099 lval = (unsigned long)-val;
2102 lval = (unsigned long)val;
2109 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2111 int write, void *data)
2114 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2116 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2122 lval = (unsigned long)-val;
2125 lval = (unsigned long)val;
2127 *lvalp = jiffies_to_clock_t(lval);
2132 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2134 int write, void *data)
2137 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2143 lval = (unsigned long)-val;
2146 lval = (unsigned long)val;
2148 *lvalp = jiffies_to_msecs(lval);
2154 * proc_dointvec_jiffies - read a vector of integers as seconds
2155 * @table: the sysctl table
2156 * @write: %TRUE if this is a write to the sysctl file
2157 * @filp: the file structure
2158 * @buffer: the user buffer
2159 * @lenp: the size of the user buffer
2160 * @ppos: file position
2162 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2163 * values from/to the user buffer, treated as an ASCII string.
2164 * The values read are assumed to be in seconds, and are converted into
2167 * Returns 0 on success.
2169 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2170 void __user *buffer, size_t *lenp, loff_t *ppos)
2172 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2173 do_proc_dointvec_jiffies_conv,NULL);
2177 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2178 * @table: the sysctl table
2179 * @write: %TRUE if this is a write to the sysctl file
2180 * @filp: the file structure
2181 * @buffer: the user buffer
2182 * @lenp: the size of the user buffer
2183 * @ppos: pointer to the file position
2185 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2186 * values from/to the user buffer, treated as an ASCII string.
2187 * The values read are assumed to be in 1/USER_HZ seconds, and
2188 * are converted into jiffies.
2190 * Returns 0 on success.
2192 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2193 void __user *buffer, size_t *lenp, loff_t *ppos)
2195 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2196 do_proc_dointvec_userhz_jiffies_conv,NULL);
2200 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2201 * @table: the sysctl table
2202 * @write: %TRUE if this is a write to the sysctl file
2203 * @filp: the file structure
2204 * @buffer: the user buffer
2205 * @lenp: the size of the user buffer
2206 * @ppos: file position
2207 * @ppos: the current position in the file
2209 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2210 * values from/to the user buffer, treated as an ASCII string.
2211 * The values read are assumed to be in 1/1000 seconds, and
2212 * are converted into jiffies.
2214 * Returns 0 on success.
2216 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2217 void __user *buffer, size_t *lenp, loff_t *ppos)
2219 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2220 do_proc_dointvec_ms_jiffies_conv, NULL);
2223 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2226 struct pid *new_pid;
2230 tmp = pid_nr(cad_pid);
2232 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2233 lenp, ppos, NULL, NULL);
2237 new_pid = find_get_pid(tmp);
2241 put_pid(xchg(&cad_pid, new_pid));
2245 #else /* CONFIG_PROC_FS */
2247 int proc_dostring(ctl_table *table, int write, struct file *filp,
2248 void __user *buffer, size_t *lenp, loff_t *ppos)
2253 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2254 void __user *buffer, size_t *lenp, loff_t *ppos)
2259 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2260 void __user *buffer, size_t *lenp, loff_t *ppos)
2265 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2266 void __user *buffer, size_t *lenp, loff_t *ppos)
2271 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2272 void __user *buffer, size_t *lenp, loff_t *ppos)
2277 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2278 void __user *buffer, size_t *lenp, loff_t *ppos)
2283 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2284 void __user *buffer, size_t *lenp, loff_t *ppos)
2289 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2290 void __user *buffer, size_t *lenp, loff_t *ppos)
2295 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2297 void __user *buffer,
2298 size_t *lenp, loff_t *ppos)
2304 #endif /* CONFIG_PROC_FS */
2307 #ifdef CONFIG_SYSCTL_SYSCALL
2309 * General sysctl support routines
2312 /* The generic string strategy routine: */
2313 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2314 void __user *oldval, size_t __user *oldlenp,
2315 void __user *newval, size_t newlen)
2317 if (!table->data || !table->maxlen)
2320 if (oldval && oldlenp) {
2322 if (get_user(bufsize, oldlenp))
2325 size_t len = strlen(table->data), copied;
2327 /* This shouldn't trigger for a well-formed sysctl */
2328 if (len > table->maxlen)
2329 len = table->maxlen;
2331 /* Copy up to a max of bufsize-1 bytes of the string */
2332 copied = (len >= bufsize) ? bufsize - 1 : len;
2334 if (copy_to_user(oldval, table->data, copied) ||
2335 put_user(0, (char __user *)(oldval + copied)))
2337 if (put_user(len, oldlenp))
2341 if (newval && newlen) {
2342 size_t len = newlen;
2343 if (len > table->maxlen)
2344 len = table->maxlen;
2345 if(copy_from_user(table->data, newval, len))
2347 if (len == table->maxlen)
2349 ((char *) table->data)[len] = 0;
2355 * This function makes sure that all of the integers in the vector
2356 * are between the minimum and maximum values given in the arrays
2357 * table->extra1 and table->extra2, respectively.
2359 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2360 void __user *oldval, size_t __user *oldlenp,
2361 void __user *newval, size_t newlen)
2364 if (newval && newlen) {
2365 int __user *vec = (int __user *) newval;
2366 int *min = (int *) table->extra1;
2367 int *max = (int *) table->extra2;
2371 if (newlen % sizeof(int) != 0)
2374 if (!table->extra1 && !table->extra2)
2377 if (newlen > table->maxlen)
2378 newlen = table->maxlen;
2379 length = newlen / sizeof(int);
2381 for (i = 0; i < length; i++) {
2383 if (get_user(value, vec + i))
2385 if (min && value < min[i])
2387 if (max && value > max[i])
2394 /* Strategy function to convert jiffies to seconds */
2395 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2396 void __user *oldval, size_t __user *oldlenp,
2397 void __user *newval, size_t newlen)
2399 if (oldval && oldlenp) {
2402 if (get_user(olen, oldlenp))
2407 if (olen < sizeof(int))
2410 val = *(int *)(table->data) / HZ;
2411 if (put_user(val, (int __user *)oldval))
2413 if (put_user(sizeof(int), oldlenp))
2417 if (newval && newlen) {
2419 if (newlen != sizeof(int))
2421 if (get_user(new, (int __user *)newval))
2423 *(int *)(table->data) = new*HZ;
2428 /* Strategy function to convert jiffies to seconds */
2429 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2430 void __user *oldval, size_t __user *oldlenp,
2431 void __user *newval, size_t newlen)
2433 if (oldval && oldlenp) {
2436 if (get_user(olen, oldlenp))
2441 if (olen < sizeof(int))
2444 val = jiffies_to_msecs(*(int *)(table->data));
2445 if (put_user(val, (int __user *)oldval))
2447 if (put_user(sizeof(int), oldlenp))
2451 if (newval && newlen) {
2453 if (newlen != sizeof(int))
2455 if (get_user(new, (int __user *)newval))
2457 *(int *)(table->data) = msecs_to_jiffies(new);
2464 #else /* CONFIG_SYSCTL_SYSCALL */
2467 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2469 static int msg_count;
2470 struct __sysctl_args tmp;
2471 int name[CTL_MAXNAME];
2474 /* Read in the sysctl name for better debug message logging */
2475 if (copy_from_user(&tmp, args, sizeof(tmp)))
2477 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2479 for (i = 0; i < tmp.nlen; i++)
2480 if (get_user(name[i], tmp.name + i))
2483 /* Ignore accesses to kernel.version */
2484 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2487 if (msg_count < 5) {
2490 "warning: process `%s' used the removed sysctl "
2491 "system call with ", current->comm);
2492 for (i = 0; i < tmp.nlen; i++)
2493 printk("%d.", name[i]);
2500 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2501 void __user *oldval, size_t __user *oldlenp,
2502 void __user *newval, size_t newlen)
2507 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2508 void __user *oldval, size_t __user *oldlenp,
2509 void __user *newval, size_t newlen)
2514 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2515 void __user *oldval, size_t __user *oldlenp,
2516 void __user *newval, size_t newlen)
2521 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2522 void __user *oldval, size_t __user *oldlenp,
2523 void __user *newval, size_t newlen)
2528 #endif /* CONFIG_SYSCTL_SYSCALL */
2531 * No sense putting this after each symbol definition, twice,
2532 * exception granted :-)
2534 EXPORT_SYMBOL(proc_dointvec);
2535 EXPORT_SYMBOL(proc_dointvec_jiffies);
2536 EXPORT_SYMBOL(proc_dointvec_minmax);
2537 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2538 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2539 EXPORT_SYMBOL(proc_dostring);
2540 EXPORT_SYMBOL(proc_doulongvec_minmax);
2541 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2542 EXPORT_SYMBOL(register_sysctl_table);
2543 EXPORT_SYMBOL(sysctl_intvec);
2544 EXPORT_SYMBOL(sysctl_jiffies);
2545 EXPORT_SYMBOL(sysctl_ms_jiffies);
2546 EXPORT_SYMBOL(sysctl_string);
2547 EXPORT_SYMBOL(unregister_sysctl_table);