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/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
55 #include <asm/stacktrace.h>
58 #if defined(CONFIG_SYSCTL)
60 /* External variables not in a header file. */
62 extern int print_fatal_signals;
63 extern int sysctl_overcommit_memory;
64 extern int sysctl_overcommit_ratio;
65 extern int sysctl_panic_on_oom;
66 extern int max_threads;
67 extern int core_uses_pid;
68 extern int suid_dumpable;
69 extern char core_pattern[];
71 extern int min_free_kbytes;
72 extern int printk_ratelimit_jiffies;
73 extern int printk_ratelimit_burst;
74 extern int pid_max_min, pid_max_max;
75 extern int sysctl_drop_caches;
76 extern int percpu_pagelist_fraction;
77 extern int compat_log;
78 extern int maps_protect;
79 extern int sysctl_stat_interval;
80 extern int audit_argv_kb;
82 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83 static int maxolduid = 65535;
85 static int min_percpu_pagelist_fract = 8;
87 static int ngroups_max = NGROUPS_MAX;
90 extern char modprobe_path[];
92 #ifdef CONFIG_CHR_DEV_SG
93 extern int sg_big_buff;
97 extern char reboot_command [];
98 extern int stop_a_enabled;
99 extern int scons_pwroff;
103 extern int pwrsw_enabled;
104 extern int unaligned_enabled;
108 #ifdef CONFIG_MATHEMU
109 extern int sysctl_ieee_emulation_warnings;
111 extern int sysctl_userprocess_debug;
112 extern int spin_retry;
115 extern int sysctl_hz_timer;
117 #ifdef CONFIG_BSD_PROCESS_ACCT
118 extern int acct_parm[];
122 extern int no_unaligned_warning;
125 #ifdef CONFIG_RT_MUTEXES
126 extern int max_lock_depth;
129 #ifdef CONFIG_SYSCTL_SYSCALL
130 static int parse_table(int __user *, int, void __user *, size_t __user *,
131 void __user *, size_t, ctl_table *);
135 #ifdef CONFIG_PROC_SYSCTL
136 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
137 void __user *buffer, size_t *lenp, loff_t *ppos);
138 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
139 void __user *buffer, size_t *lenp, loff_t *ppos);
142 static ctl_table root_table[];
143 static struct ctl_table_header root_table_header =
144 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
146 static ctl_table kern_table[];
147 static ctl_table vm_table[];
148 static ctl_table fs_table[];
149 static ctl_table debug_table[];
150 static ctl_table dev_table[];
151 extern ctl_table random_table[];
152 #ifdef CONFIG_UNIX98_PTYS
153 extern ctl_table pty_table[];
155 #ifdef CONFIG_INOTIFY_USER
156 extern ctl_table inotify_table[];
159 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
160 int sysctl_legacy_va_layout;
163 extern int prove_locking;
164 extern int lock_stat;
166 /* The default sysctl tables: */
168 static ctl_table root_table[] = {
170 .ctl_name = CTL_KERN,
171 .procname = "kernel",
196 .ctl_name = CTL_DEBUG,
199 .child = debug_table,
208 * NOTE: do not add new entries to this table unless you have read
209 * Documentation/sysctl/ctl_unnumbered.txt
214 #ifdef CONFIG_SCHED_DEBUG
215 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
216 static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
217 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
218 static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
221 static ctl_table kern_table[] = {
222 #ifdef CONFIG_SCHED_DEBUG
224 .ctl_name = CTL_UNNUMBERED,
225 .procname = "sched_granularity_ns",
226 .data = &sysctl_sched_granularity,
227 .maxlen = sizeof(unsigned int),
229 .proc_handler = &proc_dointvec_minmax,
230 .strategy = &sysctl_intvec,
231 .extra1 = &min_sched_granularity_ns,
232 .extra2 = &max_sched_granularity_ns,
235 .ctl_name = CTL_UNNUMBERED,
236 .procname = "sched_wakeup_granularity_ns",
237 .data = &sysctl_sched_wakeup_granularity,
238 .maxlen = sizeof(unsigned int),
240 .proc_handler = &proc_dointvec_minmax,
241 .strategy = &sysctl_intvec,
242 .extra1 = &min_wakeup_granularity_ns,
243 .extra2 = &max_wakeup_granularity_ns,
246 .ctl_name = CTL_UNNUMBERED,
247 .procname = "sched_batch_wakeup_granularity_ns",
248 .data = &sysctl_sched_batch_wakeup_granularity,
249 .maxlen = sizeof(unsigned int),
251 .proc_handler = &proc_dointvec_minmax,
252 .strategy = &sysctl_intvec,
253 .extra1 = &min_wakeup_granularity_ns,
254 .extra2 = &max_wakeup_granularity_ns,
257 .ctl_name = CTL_UNNUMBERED,
258 .procname = "sched_stat_granularity_ns",
259 .data = &sysctl_sched_stat_granularity,
260 .maxlen = sizeof(unsigned int),
262 .proc_handler = &proc_dointvec_minmax,
263 .strategy = &sysctl_intvec,
264 .extra1 = &min_wakeup_granularity_ns,
265 .extra2 = &max_wakeup_granularity_ns,
268 .ctl_name = CTL_UNNUMBERED,
269 .procname = "sched_runtime_limit_ns",
270 .data = &sysctl_sched_runtime_limit,
271 .maxlen = sizeof(unsigned int),
273 .proc_handler = &proc_dointvec_minmax,
274 .strategy = &sysctl_intvec,
275 .extra1 = &min_sched_granularity_ns,
276 .extra2 = &max_sched_granularity_ns,
279 .ctl_name = CTL_UNNUMBERED,
280 .procname = "sched_child_runs_first",
281 .data = &sysctl_sched_child_runs_first,
282 .maxlen = sizeof(unsigned int),
284 .proc_handler = &proc_dointvec,
286 #ifdef CONFIG_PROVE_LOCKING
288 .ctl_name = CTL_UNNUMBERED,
289 .procname = "prove_locking",
290 .data = &prove_locking,
291 .maxlen = sizeof(int),
293 .proc_handler = &proc_dointvec,
296 #ifdef CONFIG_LOCK_STAT
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "lock_stat",
301 .maxlen = sizeof(int),
303 .proc_handler = &proc_dointvec,
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_features",
309 .data = &sysctl_sched_features,
310 .maxlen = sizeof(unsigned int),
312 .proc_handler = &proc_dointvec,
316 .ctl_name = KERN_PANIC,
318 .data = &panic_timeout,
319 .maxlen = sizeof(int),
321 .proc_handler = &proc_dointvec,
324 .ctl_name = KERN_CORE_USES_PID,
325 .procname = "core_uses_pid",
326 .data = &core_uses_pid,
327 .maxlen = sizeof(int),
329 .proc_handler = &proc_dointvec,
331 #ifdef CONFIG_AUDITSYSCALL
333 .ctl_name = CTL_UNNUMBERED,
334 .procname = "audit_argv_kb",
335 .data = &audit_argv_kb,
336 .maxlen = sizeof(int),
338 .proc_handler = &proc_dointvec,
342 .ctl_name = KERN_CORE_PATTERN,
343 .procname = "core_pattern",
344 .data = core_pattern,
345 .maxlen = CORENAME_MAX_SIZE,
347 .proc_handler = &proc_dostring,
348 .strategy = &sysctl_string,
350 #ifdef CONFIG_PROC_SYSCTL
352 .ctl_name = KERN_TAINTED,
353 .procname = "tainted",
355 .maxlen = sizeof(int),
357 .proc_handler = &proc_dointvec_taint,
361 .ctl_name = KERN_CAP_BSET,
362 .procname = "cap-bound",
364 .maxlen = sizeof(kernel_cap_t),
366 .proc_handler = &proc_dointvec_bset,
368 #ifdef CONFIG_BLK_DEV_INITRD
370 .ctl_name = KERN_REALROOTDEV,
371 .procname = "real-root-dev",
372 .data = &real_root_dev,
373 .maxlen = sizeof(int),
375 .proc_handler = &proc_dointvec,
379 .ctl_name = CTL_UNNUMBERED,
380 .procname = "print-fatal-signals",
381 .data = &print_fatal_signals,
382 .maxlen = sizeof(int),
384 .proc_handler = &proc_dointvec,
388 .ctl_name = KERN_SPARC_REBOOT,
389 .procname = "reboot-cmd",
390 .data = reboot_command,
393 .proc_handler = &proc_dostring,
394 .strategy = &sysctl_string,
397 .ctl_name = KERN_SPARC_STOP_A,
398 .procname = "stop-a",
399 .data = &stop_a_enabled,
400 .maxlen = sizeof (int),
402 .proc_handler = &proc_dointvec,
405 .ctl_name = KERN_SPARC_SCONS_PWROFF,
406 .procname = "scons-poweroff",
407 .data = &scons_pwroff,
408 .maxlen = sizeof (int),
410 .proc_handler = &proc_dointvec,
415 .ctl_name = KERN_HPPA_PWRSW,
416 .procname = "soft-power",
417 .data = &pwrsw_enabled,
418 .maxlen = sizeof (int),
420 .proc_handler = &proc_dointvec,
423 .ctl_name = KERN_HPPA_UNALIGNED,
424 .procname = "unaligned-trap",
425 .data = &unaligned_enabled,
426 .maxlen = sizeof (int),
428 .proc_handler = &proc_dointvec,
432 .ctl_name = KERN_CTLALTDEL,
433 .procname = "ctrl-alt-del",
435 .maxlen = sizeof(int),
437 .proc_handler = &proc_dointvec,
440 .ctl_name = KERN_PRINTK,
441 .procname = "printk",
442 .data = &console_loglevel,
443 .maxlen = 4*sizeof(int),
445 .proc_handler = &proc_dointvec,
449 .ctl_name = KERN_MODPROBE,
450 .procname = "modprobe",
451 .data = &modprobe_path,
452 .maxlen = KMOD_PATH_LEN,
454 .proc_handler = &proc_dostring,
455 .strategy = &sysctl_string,
458 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
460 .ctl_name = KERN_HOTPLUG,
461 .procname = "hotplug",
462 .data = &uevent_helper,
463 .maxlen = UEVENT_HELPER_PATH_LEN,
465 .proc_handler = &proc_dostring,
466 .strategy = &sysctl_string,
469 #ifdef CONFIG_CHR_DEV_SG
471 .ctl_name = KERN_SG_BIG_BUFF,
472 .procname = "sg-big-buff",
473 .data = &sg_big_buff,
474 .maxlen = sizeof (int),
476 .proc_handler = &proc_dointvec,
479 #ifdef CONFIG_BSD_PROCESS_ACCT
481 .ctl_name = KERN_ACCT,
484 .maxlen = 3*sizeof(int),
486 .proc_handler = &proc_dointvec,
489 #ifdef CONFIG_MAGIC_SYSRQ
491 .ctl_name = KERN_SYSRQ,
493 .data = &__sysrq_enabled,
494 .maxlen = sizeof (int),
496 .proc_handler = &proc_dointvec,
499 #ifdef CONFIG_PROC_SYSCTL
501 .ctl_name = KERN_CADPID,
502 .procname = "cad_pid",
504 .maxlen = sizeof (int),
506 .proc_handler = &proc_do_cad_pid,
510 .ctl_name = KERN_MAX_THREADS,
511 .procname = "threads-max",
512 .data = &max_threads,
513 .maxlen = sizeof(int),
515 .proc_handler = &proc_dointvec,
518 .ctl_name = KERN_RANDOM,
519 .procname = "random",
521 .child = random_table,
523 #ifdef CONFIG_UNIX98_PTYS
525 .ctl_name = KERN_PTY,
532 .ctl_name = KERN_OVERFLOWUID,
533 .procname = "overflowuid",
534 .data = &overflowuid,
535 .maxlen = sizeof(int),
537 .proc_handler = &proc_dointvec_minmax,
538 .strategy = &sysctl_intvec,
539 .extra1 = &minolduid,
540 .extra2 = &maxolduid,
543 .ctl_name = KERN_OVERFLOWGID,
544 .procname = "overflowgid",
545 .data = &overflowgid,
546 .maxlen = sizeof(int),
548 .proc_handler = &proc_dointvec_minmax,
549 .strategy = &sysctl_intvec,
550 .extra1 = &minolduid,
551 .extra2 = &maxolduid,
554 #ifdef CONFIG_MATHEMU
556 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
557 .procname = "ieee_emulation_warnings",
558 .data = &sysctl_ieee_emulation_warnings,
559 .maxlen = sizeof(int),
561 .proc_handler = &proc_dointvec,
564 #ifdef CONFIG_NO_IDLE_HZ
566 .ctl_name = KERN_HZ_TIMER,
567 .procname = "hz_timer",
568 .data = &sysctl_hz_timer,
569 .maxlen = sizeof(int),
571 .proc_handler = &proc_dointvec,
575 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
576 .procname = "userprocess_debug",
577 .data = &sysctl_userprocess_debug,
578 .maxlen = sizeof(int),
580 .proc_handler = &proc_dointvec,
584 .ctl_name = KERN_PIDMAX,
585 .procname = "pid_max",
587 .maxlen = sizeof (int),
589 .proc_handler = &proc_dointvec_minmax,
590 .strategy = sysctl_intvec,
591 .extra1 = &pid_max_min,
592 .extra2 = &pid_max_max,
595 .ctl_name = KERN_PANIC_ON_OOPS,
596 .procname = "panic_on_oops",
597 .data = &panic_on_oops,
598 .maxlen = sizeof(int),
600 .proc_handler = &proc_dointvec,
603 .ctl_name = KERN_PRINTK_RATELIMIT,
604 .procname = "printk_ratelimit",
605 .data = &printk_ratelimit_jiffies,
606 .maxlen = sizeof(int),
608 .proc_handler = &proc_dointvec_jiffies,
609 .strategy = &sysctl_jiffies,
612 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
613 .procname = "printk_ratelimit_burst",
614 .data = &printk_ratelimit_burst,
615 .maxlen = sizeof(int),
617 .proc_handler = &proc_dointvec,
620 .ctl_name = KERN_NGROUPS_MAX,
621 .procname = "ngroups_max",
622 .data = &ngroups_max,
623 .maxlen = sizeof (int),
625 .proc_handler = &proc_dointvec,
627 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
629 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
630 .procname = "unknown_nmi_panic",
631 .data = &unknown_nmi_panic,
632 .maxlen = sizeof (int),
634 .proc_handler = &proc_dointvec,
637 .ctl_name = KERN_NMI_WATCHDOG,
638 .procname = "nmi_watchdog",
639 .data = &nmi_watchdog_enabled,
640 .maxlen = sizeof (int),
642 .proc_handler = &proc_nmi_enabled,
645 #if defined(CONFIG_X86)
647 .ctl_name = KERN_PANIC_ON_NMI,
648 .procname = "panic_on_unrecovered_nmi",
649 .data = &panic_on_unrecovered_nmi,
650 .maxlen = sizeof(int),
652 .proc_handler = &proc_dointvec,
655 .ctl_name = KERN_BOOTLOADER_TYPE,
656 .procname = "bootloader_type",
657 .data = &bootloader_type,
658 .maxlen = sizeof (int),
660 .proc_handler = &proc_dointvec,
663 .ctl_name = CTL_UNNUMBERED,
664 .procname = "kstack_depth_to_print",
665 .data = &kstack_depth_to_print,
666 .maxlen = sizeof(int),
668 .proc_handler = &proc_dointvec,
671 #if defined(CONFIG_MMU)
673 .ctl_name = KERN_RANDOMIZE,
674 .procname = "randomize_va_space",
675 .data = &randomize_va_space,
676 .maxlen = sizeof(int),
678 .proc_handler = &proc_dointvec,
681 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
683 .ctl_name = KERN_SPIN_RETRY,
684 .procname = "spin_retry",
686 .maxlen = sizeof (int),
688 .proc_handler = &proc_dointvec,
691 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
693 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
694 .procname = "acpi_video_flags",
695 .data = &acpi_realmode_flags,
696 .maxlen = sizeof (unsigned long),
698 .proc_handler = &proc_doulongvec_minmax,
703 .ctl_name = KERN_IA64_UNALIGNED,
704 .procname = "ignore-unaligned-usertrap",
705 .data = &no_unaligned_warning,
706 .maxlen = sizeof (int),
708 .proc_handler = &proc_dointvec,
713 .ctl_name = KERN_COMPAT_LOG,
714 .procname = "compat-log",
716 .maxlen = sizeof (int),
718 .proc_handler = &proc_dointvec,
721 #ifdef CONFIG_RT_MUTEXES
723 .ctl_name = KERN_MAX_LOCK_DEPTH,
724 .procname = "max_lock_depth",
725 .data = &max_lock_depth,
726 .maxlen = sizeof(int),
728 .proc_handler = &proc_dointvec,
731 #ifdef CONFIG_PROC_FS
733 .ctl_name = CTL_UNNUMBERED,
734 .procname = "maps_protect",
735 .data = &maps_protect,
736 .maxlen = sizeof(int),
738 .proc_handler = &proc_dointvec,
742 .ctl_name = CTL_UNNUMBERED,
743 .procname = "poweroff_cmd",
744 .data = &poweroff_cmd,
745 .maxlen = POWEROFF_CMD_PATH_LEN,
747 .proc_handler = &proc_dostring,
748 .strategy = &sysctl_string,
751 * NOTE: do not add new entries to this table unless you have read
752 * Documentation/sysctl/ctl_unnumbered.txt
757 /* Constants for minimum and maximum testing in vm_table.
758 We use these as one-element integer vectors. */
761 static int one_hundred = 100;
764 static ctl_table vm_table[] = {
766 .ctl_name = VM_OVERCOMMIT_MEMORY,
767 .procname = "overcommit_memory",
768 .data = &sysctl_overcommit_memory,
769 .maxlen = sizeof(sysctl_overcommit_memory),
771 .proc_handler = &proc_dointvec,
774 .ctl_name = VM_PANIC_ON_OOM,
775 .procname = "panic_on_oom",
776 .data = &sysctl_panic_on_oom,
777 .maxlen = sizeof(sysctl_panic_on_oom),
779 .proc_handler = &proc_dointvec,
782 .ctl_name = VM_OVERCOMMIT_RATIO,
783 .procname = "overcommit_ratio",
784 .data = &sysctl_overcommit_ratio,
785 .maxlen = sizeof(sysctl_overcommit_ratio),
787 .proc_handler = &proc_dointvec,
790 .ctl_name = VM_PAGE_CLUSTER,
791 .procname = "page-cluster",
792 .data = &page_cluster,
793 .maxlen = sizeof(int),
795 .proc_handler = &proc_dointvec,
798 .ctl_name = VM_DIRTY_BACKGROUND,
799 .procname = "dirty_background_ratio",
800 .data = &dirty_background_ratio,
801 .maxlen = sizeof(dirty_background_ratio),
803 .proc_handler = &proc_dointvec_minmax,
804 .strategy = &sysctl_intvec,
806 .extra2 = &one_hundred,
809 .ctl_name = VM_DIRTY_RATIO,
810 .procname = "dirty_ratio",
811 .data = &vm_dirty_ratio,
812 .maxlen = sizeof(vm_dirty_ratio),
814 .proc_handler = &proc_dointvec_minmax,
815 .strategy = &sysctl_intvec,
817 .extra2 = &one_hundred,
820 .ctl_name = VM_DIRTY_WB_CS,
821 .procname = "dirty_writeback_centisecs",
822 .data = &dirty_writeback_interval,
823 .maxlen = sizeof(dirty_writeback_interval),
825 .proc_handler = &dirty_writeback_centisecs_handler,
828 .ctl_name = VM_DIRTY_EXPIRE_CS,
829 .procname = "dirty_expire_centisecs",
830 .data = &dirty_expire_interval,
831 .maxlen = sizeof(dirty_expire_interval),
833 .proc_handler = &proc_dointvec_userhz_jiffies,
836 .ctl_name = VM_NR_PDFLUSH_THREADS,
837 .procname = "nr_pdflush_threads",
838 .data = &nr_pdflush_threads,
839 .maxlen = sizeof nr_pdflush_threads,
840 .mode = 0444 /* read-only*/,
841 .proc_handler = &proc_dointvec,
844 .ctl_name = VM_SWAPPINESS,
845 .procname = "swappiness",
846 .data = &vm_swappiness,
847 .maxlen = sizeof(vm_swappiness),
849 .proc_handler = &proc_dointvec_minmax,
850 .strategy = &sysctl_intvec,
852 .extra2 = &one_hundred,
854 #ifdef CONFIG_HUGETLB_PAGE
856 .ctl_name = VM_HUGETLB_PAGES,
857 .procname = "nr_hugepages",
858 .data = &max_huge_pages,
859 .maxlen = sizeof(unsigned long),
861 .proc_handler = &hugetlb_sysctl_handler,
862 .extra1 = (void *)&hugetlb_zero,
863 .extra2 = (void *)&hugetlb_infinity,
866 .ctl_name = VM_HUGETLB_GROUP,
867 .procname = "hugetlb_shm_group",
868 .data = &sysctl_hugetlb_shm_group,
869 .maxlen = sizeof(gid_t),
871 .proc_handler = &proc_dointvec,
874 .ctl_name = CTL_UNNUMBERED,
875 .procname = "hugepages_treat_as_movable",
876 .data = &hugepages_treat_as_movable,
877 .maxlen = sizeof(int),
879 .proc_handler = &hugetlb_treat_movable_handler,
883 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
884 .procname = "lowmem_reserve_ratio",
885 .data = &sysctl_lowmem_reserve_ratio,
886 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
888 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
889 .strategy = &sysctl_intvec,
892 .ctl_name = VM_DROP_PAGECACHE,
893 .procname = "drop_caches",
894 .data = &sysctl_drop_caches,
895 .maxlen = sizeof(int),
897 .proc_handler = drop_caches_sysctl_handler,
898 .strategy = &sysctl_intvec,
901 .ctl_name = VM_MIN_FREE_KBYTES,
902 .procname = "min_free_kbytes",
903 .data = &min_free_kbytes,
904 .maxlen = sizeof(min_free_kbytes),
906 .proc_handler = &min_free_kbytes_sysctl_handler,
907 .strategy = &sysctl_intvec,
911 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
912 .procname = "percpu_pagelist_fraction",
913 .data = &percpu_pagelist_fraction,
914 .maxlen = sizeof(percpu_pagelist_fraction),
916 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
917 .strategy = &sysctl_intvec,
918 .extra1 = &min_percpu_pagelist_fract,
922 .ctl_name = VM_MAX_MAP_COUNT,
923 .procname = "max_map_count",
924 .data = &sysctl_max_map_count,
925 .maxlen = sizeof(sysctl_max_map_count),
927 .proc_handler = &proc_dointvec
931 .ctl_name = VM_LAPTOP_MODE,
932 .procname = "laptop_mode",
933 .data = &laptop_mode,
934 .maxlen = sizeof(laptop_mode),
936 .proc_handler = &proc_dointvec_jiffies,
937 .strategy = &sysctl_jiffies,
940 .ctl_name = VM_BLOCK_DUMP,
941 .procname = "block_dump",
943 .maxlen = sizeof(block_dump),
945 .proc_handler = &proc_dointvec,
946 .strategy = &sysctl_intvec,
950 .ctl_name = VM_VFS_CACHE_PRESSURE,
951 .procname = "vfs_cache_pressure",
952 .data = &sysctl_vfs_cache_pressure,
953 .maxlen = sizeof(sysctl_vfs_cache_pressure),
955 .proc_handler = &proc_dointvec,
956 .strategy = &sysctl_intvec,
959 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
961 .ctl_name = VM_LEGACY_VA_LAYOUT,
962 .procname = "legacy_va_layout",
963 .data = &sysctl_legacy_va_layout,
964 .maxlen = sizeof(sysctl_legacy_va_layout),
966 .proc_handler = &proc_dointvec,
967 .strategy = &sysctl_intvec,
973 .ctl_name = VM_ZONE_RECLAIM_MODE,
974 .procname = "zone_reclaim_mode",
975 .data = &zone_reclaim_mode,
976 .maxlen = sizeof(zone_reclaim_mode),
978 .proc_handler = &proc_dointvec,
979 .strategy = &sysctl_intvec,
983 .ctl_name = VM_MIN_UNMAPPED,
984 .procname = "min_unmapped_ratio",
985 .data = &sysctl_min_unmapped_ratio,
986 .maxlen = sizeof(sysctl_min_unmapped_ratio),
988 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
989 .strategy = &sysctl_intvec,
991 .extra2 = &one_hundred,
994 .ctl_name = VM_MIN_SLAB,
995 .procname = "min_slab_ratio",
996 .data = &sysctl_min_slab_ratio,
997 .maxlen = sizeof(sysctl_min_slab_ratio),
999 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1000 .strategy = &sysctl_intvec,
1002 .extra2 = &one_hundred,
1007 .ctl_name = CTL_UNNUMBERED,
1008 .procname = "stat_interval",
1009 .data = &sysctl_stat_interval,
1010 .maxlen = sizeof(sysctl_stat_interval),
1012 .proc_handler = &proc_dointvec_jiffies,
1013 .strategy = &sysctl_jiffies,
1016 #ifdef CONFIG_SECURITY
1018 .ctl_name = CTL_UNNUMBERED,
1019 .procname = "mmap_min_addr",
1020 .data = &mmap_min_addr,
1021 .maxlen = sizeof(unsigned long),
1023 .proc_handler = &proc_doulongvec_minmax,
1028 .ctl_name = CTL_UNNUMBERED,
1029 .procname = "numa_zonelist_order",
1030 .data = &numa_zonelist_order,
1031 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1033 .proc_handler = &numa_zonelist_order_handler,
1034 .strategy = &sysctl_string,
1037 #if defined(CONFIG_X86_32) || \
1038 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1040 .ctl_name = VM_VDSO_ENABLED,
1041 .procname = "vdso_enabled",
1042 .data = &vdso_enabled,
1043 .maxlen = sizeof(vdso_enabled),
1045 .proc_handler = &proc_dointvec,
1046 .strategy = &sysctl_intvec,
1051 * NOTE: do not add new entries to this table unless you have read
1052 * Documentation/sysctl/ctl_unnumbered.txt
1057 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1058 static ctl_table binfmt_misc_table[] = {
1063 static ctl_table fs_table[] = {
1065 .ctl_name = FS_NRINODE,
1066 .procname = "inode-nr",
1067 .data = &inodes_stat,
1068 .maxlen = 2*sizeof(int),
1070 .proc_handler = &proc_dointvec,
1073 .ctl_name = FS_STATINODE,
1074 .procname = "inode-state",
1075 .data = &inodes_stat,
1076 .maxlen = 7*sizeof(int),
1078 .proc_handler = &proc_dointvec,
1081 .ctl_name = FS_NRFILE,
1082 .procname = "file-nr",
1083 .data = &files_stat,
1084 .maxlen = 3*sizeof(int),
1086 .proc_handler = &proc_nr_files,
1089 .ctl_name = FS_MAXFILE,
1090 .procname = "file-max",
1091 .data = &files_stat.max_files,
1092 .maxlen = sizeof(int),
1094 .proc_handler = &proc_dointvec,
1097 .ctl_name = FS_DENTRY,
1098 .procname = "dentry-state",
1099 .data = &dentry_stat,
1100 .maxlen = 6*sizeof(int),
1102 .proc_handler = &proc_dointvec,
1105 .ctl_name = FS_OVERFLOWUID,
1106 .procname = "overflowuid",
1107 .data = &fs_overflowuid,
1108 .maxlen = sizeof(int),
1110 .proc_handler = &proc_dointvec_minmax,
1111 .strategy = &sysctl_intvec,
1112 .extra1 = &minolduid,
1113 .extra2 = &maxolduid,
1116 .ctl_name = FS_OVERFLOWGID,
1117 .procname = "overflowgid",
1118 .data = &fs_overflowgid,
1119 .maxlen = sizeof(int),
1121 .proc_handler = &proc_dointvec_minmax,
1122 .strategy = &sysctl_intvec,
1123 .extra1 = &minolduid,
1124 .extra2 = &maxolduid,
1127 .ctl_name = FS_LEASES,
1128 .procname = "leases-enable",
1129 .data = &leases_enable,
1130 .maxlen = sizeof(int),
1132 .proc_handler = &proc_dointvec,
1134 #ifdef CONFIG_DNOTIFY
1136 .ctl_name = FS_DIR_NOTIFY,
1137 .procname = "dir-notify-enable",
1138 .data = &dir_notify_enable,
1139 .maxlen = sizeof(int),
1141 .proc_handler = &proc_dointvec,
1146 .ctl_name = FS_LEASE_TIME,
1147 .procname = "lease-break-time",
1148 .data = &lease_break_time,
1149 .maxlen = sizeof(int),
1151 .proc_handler = &proc_dointvec_minmax,
1152 .strategy = &sysctl_intvec,
1157 .ctl_name = FS_AIO_NR,
1158 .procname = "aio-nr",
1160 .maxlen = sizeof(aio_nr),
1162 .proc_handler = &proc_doulongvec_minmax,
1165 .ctl_name = FS_AIO_MAX_NR,
1166 .procname = "aio-max-nr",
1167 .data = &aio_max_nr,
1168 .maxlen = sizeof(aio_max_nr),
1170 .proc_handler = &proc_doulongvec_minmax,
1172 #ifdef CONFIG_INOTIFY_USER
1174 .ctl_name = FS_INOTIFY,
1175 .procname = "inotify",
1177 .child = inotify_table,
1182 .ctl_name = KERN_SETUID_DUMPABLE,
1183 .procname = "suid_dumpable",
1184 .data = &suid_dumpable,
1185 .maxlen = sizeof(int),
1187 .proc_handler = &proc_dointvec,
1189 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1191 .ctl_name = CTL_UNNUMBERED,
1192 .procname = "binfmt_misc",
1194 .child = binfmt_misc_table,
1198 * NOTE: do not add new entries to this table unless you have read
1199 * Documentation/sysctl/ctl_unnumbered.txt
1204 static ctl_table debug_table[] = {
1207 .ctl_name = CTL_UNNUMBERED,
1208 .procname = "exception-trace",
1209 .data = &show_unhandled_signals,
1210 .maxlen = sizeof(int),
1212 .proc_handler = proc_dointvec
1218 static ctl_table dev_table[] = {
1222 static DEFINE_SPINLOCK(sysctl_lock);
1224 /* called under sysctl_lock */
1225 static int use_table(struct ctl_table_header *p)
1227 if (unlikely(p->unregistering))
1233 /* called under sysctl_lock */
1234 static void unuse_table(struct ctl_table_header *p)
1237 if (unlikely(p->unregistering))
1238 complete(p->unregistering);
1241 /* called under sysctl_lock, will reacquire if has to wait */
1242 static void start_unregistering(struct ctl_table_header *p)
1245 * if p->used is 0, nobody will ever touch that entry again;
1246 * we'll eliminate all paths to it before dropping sysctl_lock
1248 if (unlikely(p->used)) {
1249 struct completion wait;
1250 init_completion(&wait);
1251 p->unregistering = &wait;
1252 spin_unlock(&sysctl_lock);
1253 wait_for_completion(&wait);
1254 spin_lock(&sysctl_lock);
1257 * do not remove from the list until nobody holds it; walking the
1258 * list in do_sysctl() relies on that.
1260 list_del_init(&p->ctl_entry);
1263 void sysctl_head_finish(struct ctl_table_header *head)
1267 spin_lock(&sysctl_lock);
1269 spin_unlock(&sysctl_lock);
1272 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1274 struct ctl_table_header *head;
1275 struct list_head *tmp;
1276 spin_lock(&sysctl_lock);
1278 tmp = &prev->ctl_entry;
1282 tmp = &root_table_header.ctl_entry;
1284 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1286 if (!use_table(head))
1288 spin_unlock(&sysctl_lock);
1292 if (tmp == &root_table_header.ctl_entry)
1295 spin_unlock(&sysctl_lock);
1299 #ifdef CONFIG_SYSCTL_SYSCALL
1300 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1301 void __user *newval, size_t newlen)
1303 struct ctl_table_header *head;
1304 int error = -ENOTDIR;
1306 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1310 if (!oldlenp || get_user(old_len, oldlenp))
1314 for (head = sysctl_head_next(NULL); head;
1315 head = sysctl_head_next(head)) {
1316 error = parse_table(name, nlen, oldval, oldlenp,
1317 newval, newlen, head->ctl_table);
1318 if (error != -ENOTDIR) {
1319 sysctl_head_finish(head);
1326 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1328 struct __sysctl_args tmp;
1331 if (copy_from_user(&tmp, args, sizeof(tmp)))
1335 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1336 tmp.newval, tmp.newlen);
1340 #endif /* CONFIG_SYSCTL_SYSCALL */
1343 * sysctl_perm does NOT grant the superuser all rights automatically, because
1344 * some sysctl variables are readonly even to root.
1347 static int test_perm(int mode, int op)
1351 else if (in_egroup_p(0))
1353 if ((mode & op & 0007) == op)
1358 int sysctl_perm(ctl_table *table, int op)
1361 error = security_sysctl(table, op);
1364 return test_perm(table->mode, op);
1367 #ifdef CONFIG_SYSCTL_SYSCALL
1368 static int parse_table(int __user *name, int nlen,
1369 void __user *oldval, size_t __user *oldlenp,
1370 void __user *newval, size_t newlen,
1377 if (get_user(n, name))
1379 for ( ; table->ctl_name || table->procname; table++) {
1380 if (!table->ctl_name)
1382 if (n == table->ctl_name) {
1385 if (sysctl_perm(table, 001))
1389 table = table->child;
1392 error = do_sysctl_strategy(table, name, nlen,
1401 /* Perform the actual read/write of a sysctl table entry. */
1402 int do_sysctl_strategy (ctl_table *table,
1403 int __user *name, int nlen,
1404 void __user *oldval, size_t __user *oldlenp,
1405 void __user *newval, size_t newlen)
1414 if (sysctl_perm(table, op))
1417 if (table->strategy) {
1418 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1426 /* If there is no strategy routine, or if the strategy returns
1427 * zero, proceed with automatic r/w */
1428 if (table->data && table->maxlen) {
1429 if (oldval && oldlenp) {
1430 if (get_user(len, oldlenp))
1433 if (len > table->maxlen)
1434 len = table->maxlen;
1435 if(copy_to_user(oldval, table->data, len))
1437 if(put_user(len, oldlenp))
1441 if (newval && newlen) {
1443 if (len > table->maxlen)
1444 len = table->maxlen;
1445 if(copy_from_user(table->data, newval, len))
1451 #endif /* CONFIG_SYSCTL_SYSCALL */
1453 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1455 for (; table->ctl_name || table->procname; table++) {
1456 table->parent = parent;
1458 sysctl_set_parent(table, table->child);
1462 static __init int sysctl_init(void)
1464 sysctl_set_parent(NULL, root_table);
1468 core_initcall(sysctl_init);
1471 * register_sysctl_table - register a sysctl hierarchy
1472 * @table: the top-level table structure
1474 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1475 * array. An entry with a ctl_name of 0 terminates the table.
1477 * The members of the &ctl_table structure are used as follows:
1479 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1480 * must be unique within that level of sysctl
1482 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1483 * enter a sysctl file
1485 * data - a pointer to data for use by proc_handler
1487 * maxlen - the maximum size in bytes of the data
1489 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1491 * child - a pointer to the child sysctl table if this entry is a directory, or
1494 * proc_handler - the text handler routine (described below)
1496 * strategy - the strategy routine (described below)
1498 * de - for internal use by the sysctl routines
1500 * extra1, extra2 - extra pointers usable by the proc handler routines
1502 * Leaf nodes in the sysctl tree will be represented by a single file
1503 * under /proc; non-leaf nodes will be represented by directories.
1505 * sysctl(2) can automatically manage read and write requests through
1506 * the sysctl table. The data and maxlen fields of the ctl_table
1507 * struct enable minimal validation of the values being written to be
1508 * performed, and the mode field allows minimal authentication.
1510 * More sophisticated management can be enabled by the provision of a
1511 * strategy routine with the table entry. This will be called before
1512 * any automatic read or write of the data is performed.
1514 * The strategy routine may return
1516 * < 0 - Error occurred (error is passed to user process)
1518 * 0 - OK - proceed with automatic read or write.
1520 * > 0 - OK - read or write has been done by the strategy routine, so
1521 * return immediately.
1523 * There must be a proc_handler routine for any terminal nodes
1524 * mirrored under /proc/sys (non-terminals are handled by a built-in
1525 * directory handler). Several default handlers are available to
1526 * cover common cases -
1528 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1529 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1530 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1532 * It is the handler's job to read the input buffer from user memory
1533 * and process it. The handler should return 0 on success.
1535 * This routine returns %NULL on a failure to register, and a pointer
1536 * to the table header on success.
1538 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1540 struct ctl_table_header *tmp;
1541 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1544 tmp->ctl_table = table;
1545 INIT_LIST_HEAD(&tmp->ctl_entry);
1547 tmp->unregistering = NULL;
1548 sysctl_set_parent(NULL, table);
1549 spin_lock(&sysctl_lock);
1550 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1551 spin_unlock(&sysctl_lock);
1556 * unregister_sysctl_table - unregister a sysctl table hierarchy
1557 * @header: the header returned from register_sysctl_table
1559 * Unregisters the sysctl table and all children. proc entries may not
1560 * actually be removed until they are no longer used by anyone.
1562 void unregister_sysctl_table(struct ctl_table_header * header)
1565 spin_lock(&sysctl_lock);
1566 start_unregistering(header);
1567 spin_unlock(&sysctl_lock);
1571 #else /* !CONFIG_SYSCTL */
1572 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1577 void unregister_sysctl_table(struct ctl_table_header * table)
1581 #endif /* CONFIG_SYSCTL */
1587 #ifdef CONFIG_PROC_SYSCTL
1589 static int _proc_do_string(void* data, int maxlen, int write,
1590 struct file *filp, void __user *buffer,
1591 size_t *lenp, loff_t *ppos)
1597 if (!data || !maxlen || !*lenp) {
1605 while (len < *lenp) {
1606 if (get_user(c, p++))
1608 if (c == 0 || c == '\n')
1614 if(copy_from_user(data, buffer, len))
1616 ((char *) data)[len] = 0;
1634 if(copy_to_user(buffer, data, len))
1637 if(put_user('\n', ((char __user *) buffer) + len))
1648 * proc_dostring - read a string sysctl
1649 * @table: the sysctl table
1650 * @write: %TRUE if this is a write to the sysctl file
1651 * @filp: the file structure
1652 * @buffer: the user buffer
1653 * @lenp: the size of the user buffer
1654 * @ppos: file position
1656 * Reads/writes a string from/to the user buffer. If the kernel
1657 * buffer provided is not large enough to hold the string, the
1658 * string is truncated. The copied string is %NULL-terminated.
1659 * If the string is being read by the user process, it is copied
1660 * and a newline '\n' is added. It is truncated if the buffer is
1663 * Returns 0 on success.
1665 int proc_dostring(ctl_table *table, int write, struct file *filp,
1666 void __user *buffer, size_t *lenp, loff_t *ppos)
1668 return _proc_do_string(table->data, table->maxlen, write, filp,
1669 buffer, lenp, ppos);
1673 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1675 int write, void *data)
1678 *valp = *negp ? -*lvalp : *lvalp;
1683 *lvalp = (unsigned long)-val;
1686 *lvalp = (unsigned long)val;
1692 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1693 int write, struct file *filp, void __user *buffer,
1694 size_t *lenp, loff_t *ppos,
1695 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1696 int write, void *data),
1699 #define TMPBUFLEN 21
1700 int *i, vleft, first=1, neg, val;
1704 char buf[TMPBUFLEN], *p;
1705 char __user *s = buffer;
1707 if (!tbl_data || !table->maxlen || !*lenp ||
1708 (*ppos && !write)) {
1713 i = (int *) tbl_data;
1714 vleft = table->maxlen / sizeof(*i);
1718 conv = do_proc_dointvec_conv;
1720 for (; left && vleft--; i++, first=0) {
1735 if (len > sizeof(buf) - 1)
1736 len = sizeof(buf) - 1;
1737 if (copy_from_user(buf, s, len))
1741 if (*p == '-' && left > 1) {
1745 if (*p < '0' || *p > '9')
1748 lval = simple_strtoul(p, &p, 0);
1751 if ((len < left) && *p && !isspace(*p))
1758 if (conv(&neg, &lval, i, 1, data))
1765 if (conv(&neg, &lval, i, 0, data))
1768 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1772 if(copy_to_user(s, buf, len))
1779 if (!write && !first && left) {
1780 if(put_user('\n', s))
1787 if (get_user(c, s++))
1802 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1803 void __user *buffer, size_t *lenp, loff_t *ppos,
1804 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1805 int write, void *data),
1808 return __do_proc_dointvec(table->data, table, write, filp,
1809 buffer, lenp, ppos, conv, data);
1813 * proc_dointvec - read a vector of integers
1814 * @table: the sysctl table
1815 * @write: %TRUE if this is a write to the sysctl file
1816 * @filp: the file structure
1817 * @buffer: the user buffer
1818 * @lenp: the size of the user buffer
1819 * @ppos: file position
1821 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1822 * values from/to the user buffer, treated as an ASCII string.
1824 * Returns 0 on success.
1826 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1827 void __user *buffer, size_t *lenp, loff_t *ppos)
1829 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1837 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1839 int write, void *data)
1841 int op = *(int *)data;
1843 int val = *negp ? -*lvalp : *lvalp;
1845 case OP_SET: *valp = val; break;
1846 case OP_AND: *valp &= val; break;
1847 case OP_OR: *valp |= val; break;
1853 *lvalp = (unsigned long)-val;
1856 *lvalp = (unsigned long)val;
1863 * init may raise the set.
1866 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1867 void __user *buffer, size_t *lenp, loff_t *ppos)
1871 if (write && !capable(CAP_SYS_MODULE)) {
1875 op = is_init(current) ? OP_SET : OP_AND;
1876 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1877 do_proc_dointvec_bset_conv,&op);
1881 * Taint values can only be increased
1883 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1884 void __user *buffer, size_t *lenp, loff_t *ppos)
1888 if (write && !capable(CAP_SYS_ADMIN))
1892 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1893 do_proc_dointvec_bset_conv,&op);
1896 struct do_proc_dointvec_minmax_conv_param {
1901 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1903 int write, void *data)
1905 struct do_proc_dointvec_minmax_conv_param *param = data;
1907 int val = *negp ? -*lvalp : *lvalp;
1908 if ((param->min && *param->min > val) ||
1909 (param->max && *param->max < val))
1916 *lvalp = (unsigned long)-val;
1919 *lvalp = (unsigned long)val;
1926 * proc_dointvec_minmax - read a vector of integers with min/max values
1927 * @table: the sysctl table
1928 * @write: %TRUE if this is a write to the sysctl file
1929 * @filp: the file structure
1930 * @buffer: the user buffer
1931 * @lenp: the size of the user buffer
1932 * @ppos: file position
1934 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1935 * values from/to the user buffer, treated as an ASCII string.
1937 * This routine will ensure the values are within the range specified by
1938 * table->extra1 (min) and table->extra2 (max).
1940 * Returns 0 on success.
1942 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1943 void __user *buffer, size_t *lenp, loff_t *ppos)
1945 struct do_proc_dointvec_minmax_conv_param param = {
1946 .min = (int *) table->extra1,
1947 .max = (int *) table->extra2,
1949 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1950 do_proc_dointvec_minmax_conv, ¶m);
1953 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1955 void __user *buffer,
1956 size_t *lenp, loff_t *ppos,
1957 unsigned long convmul,
1958 unsigned long convdiv)
1960 #define TMPBUFLEN 21
1961 unsigned long *i, *min, *max, val;
1962 int vleft, first=1, neg;
1964 char buf[TMPBUFLEN], *p;
1965 char __user *s = buffer;
1967 if (!data || !table->maxlen || !*lenp ||
1968 (*ppos && !write)) {
1973 i = (unsigned long *) data;
1974 min = (unsigned long *) table->extra1;
1975 max = (unsigned long *) table->extra2;
1976 vleft = table->maxlen / sizeof(unsigned long);
1979 for (; left && vleft--; i++, min++, max++, first=0) {
1994 if (len > TMPBUFLEN-1)
1996 if (copy_from_user(buf, s, len))
2000 if (*p == '-' && left > 1) {
2004 if (*p < '0' || *p > '9')
2006 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2008 if ((len < left) && *p && !isspace(*p))
2017 if ((min && val < *min) || (max && val > *max))
2024 sprintf(p, "%lu", convdiv * (*i) / convmul);
2028 if(copy_to_user(s, buf, len))
2035 if (!write && !first && left) {
2036 if(put_user('\n', s))
2043 if (get_user(c, s++))
2058 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2060 void __user *buffer,
2061 size_t *lenp, loff_t *ppos,
2062 unsigned long convmul,
2063 unsigned long convdiv)
2065 return __do_proc_doulongvec_minmax(table->data, table, write,
2066 filp, buffer, lenp, ppos, convmul, convdiv);
2070 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2071 * @table: the sysctl table
2072 * @write: %TRUE if this is a write to the sysctl file
2073 * @filp: the file structure
2074 * @buffer: the user buffer
2075 * @lenp: the size of the user buffer
2076 * @ppos: file position
2078 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2079 * values from/to the user buffer, treated as an ASCII string.
2081 * This routine will ensure the values are within the range specified by
2082 * table->extra1 (min) and table->extra2 (max).
2084 * Returns 0 on success.
2086 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2087 void __user *buffer, size_t *lenp, loff_t *ppos)
2089 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2093 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2094 * @table: the sysctl table
2095 * @write: %TRUE if this is a write to the sysctl file
2096 * @filp: the file structure
2097 * @buffer: the user buffer
2098 * @lenp: the size of the user buffer
2099 * @ppos: file position
2101 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2102 * values from/to the user buffer, treated as an ASCII string. The values
2103 * are treated as milliseconds, and converted to jiffies when they are stored.
2105 * This routine will ensure the values are within the range specified by
2106 * table->extra1 (min) and table->extra2 (max).
2108 * Returns 0 on success.
2110 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2112 void __user *buffer,
2113 size_t *lenp, loff_t *ppos)
2115 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2116 lenp, ppos, HZ, 1000l);
2120 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2122 int write, void *data)
2125 if (*lvalp > LONG_MAX / HZ)
2127 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2133 lval = (unsigned long)-val;
2136 lval = (unsigned long)val;
2143 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2145 int write, void *data)
2148 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2150 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2156 lval = (unsigned long)-val;
2159 lval = (unsigned long)val;
2161 *lvalp = jiffies_to_clock_t(lval);
2166 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2168 int write, void *data)
2171 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2177 lval = (unsigned long)-val;
2180 lval = (unsigned long)val;
2182 *lvalp = jiffies_to_msecs(lval);
2188 * proc_dointvec_jiffies - read a vector of integers as seconds
2189 * @table: the sysctl table
2190 * @write: %TRUE if this is a write to the sysctl file
2191 * @filp: the file structure
2192 * @buffer: the user buffer
2193 * @lenp: the size of the user buffer
2194 * @ppos: file position
2196 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2197 * values from/to the user buffer, treated as an ASCII string.
2198 * The values read are assumed to be in seconds, and are converted into
2201 * Returns 0 on success.
2203 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2204 void __user *buffer, size_t *lenp, loff_t *ppos)
2206 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2207 do_proc_dointvec_jiffies_conv,NULL);
2211 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2212 * @table: the sysctl table
2213 * @write: %TRUE if this is a write to the sysctl file
2214 * @filp: the file structure
2215 * @buffer: the user buffer
2216 * @lenp: the size of the user buffer
2217 * @ppos: pointer to the file position
2219 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2220 * values from/to the user buffer, treated as an ASCII string.
2221 * The values read are assumed to be in 1/USER_HZ seconds, and
2222 * are converted into jiffies.
2224 * Returns 0 on success.
2226 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2227 void __user *buffer, size_t *lenp, loff_t *ppos)
2229 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2230 do_proc_dointvec_userhz_jiffies_conv,NULL);
2234 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2235 * @table: the sysctl table
2236 * @write: %TRUE if this is a write to the sysctl file
2237 * @filp: the file structure
2238 * @buffer: the user buffer
2239 * @lenp: the size of the user buffer
2240 * @ppos: file position
2241 * @ppos: the current position in the file
2243 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2244 * values from/to the user buffer, treated as an ASCII string.
2245 * The values read are assumed to be in 1/1000 seconds, and
2246 * are converted into jiffies.
2248 * Returns 0 on success.
2250 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2251 void __user *buffer, size_t *lenp, loff_t *ppos)
2253 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2254 do_proc_dointvec_ms_jiffies_conv, NULL);
2257 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2258 void __user *buffer, size_t *lenp, loff_t *ppos)
2260 struct pid *new_pid;
2264 tmp = pid_nr(cad_pid);
2266 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2267 lenp, ppos, NULL, NULL);
2271 new_pid = find_get_pid(tmp);
2275 put_pid(xchg(&cad_pid, new_pid));
2279 #else /* CONFIG_PROC_FS */
2281 int proc_dostring(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2287 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2288 void __user *buffer, size_t *lenp, loff_t *ppos)
2293 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2299 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2300 void __user *buffer, size_t *lenp, loff_t *ppos)
2305 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2306 void __user *buffer, size_t *lenp, loff_t *ppos)
2311 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2312 void __user *buffer, size_t *lenp, loff_t *ppos)
2317 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2318 void __user *buffer, size_t *lenp, loff_t *ppos)
2323 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2324 void __user *buffer, size_t *lenp, loff_t *ppos)
2329 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2331 void __user *buffer,
2332 size_t *lenp, loff_t *ppos)
2338 #endif /* CONFIG_PROC_FS */
2341 #ifdef CONFIG_SYSCTL_SYSCALL
2343 * General sysctl support routines
2346 /* The generic string strategy routine: */
2347 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2348 void __user *oldval, size_t __user *oldlenp,
2349 void __user *newval, size_t newlen)
2351 if (!table->data || !table->maxlen)
2354 if (oldval && oldlenp) {
2356 if (get_user(bufsize, oldlenp))
2359 size_t len = strlen(table->data), copied;
2361 /* This shouldn't trigger for a well-formed sysctl */
2362 if (len > table->maxlen)
2363 len = table->maxlen;
2365 /* Copy up to a max of bufsize-1 bytes of the string */
2366 copied = (len >= bufsize) ? bufsize - 1 : len;
2368 if (copy_to_user(oldval, table->data, copied) ||
2369 put_user(0, (char __user *)(oldval + copied)))
2371 if (put_user(len, oldlenp))
2375 if (newval && newlen) {
2376 size_t len = newlen;
2377 if (len > table->maxlen)
2378 len = table->maxlen;
2379 if(copy_from_user(table->data, newval, len))
2381 if (len == table->maxlen)
2383 ((char *) table->data)[len] = 0;
2389 * This function makes sure that all of the integers in the vector
2390 * are between the minimum and maximum values given in the arrays
2391 * table->extra1 and table->extra2, respectively.
2393 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2394 void __user *oldval, size_t __user *oldlenp,
2395 void __user *newval, size_t newlen)
2398 if (newval && newlen) {
2399 int __user *vec = (int __user *) newval;
2400 int *min = (int *) table->extra1;
2401 int *max = (int *) table->extra2;
2405 if (newlen % sizeof(int) != 0)
2408 if (!table->extra1 && !table->extra2)
2411 if (newlen > table->maxlen)
2412 newlen = table->maxlen;
2413 length = newlen / sizeof(int);
2415 for (i = 0; i < length; i++) {
2417 if (get_user(value, vec + i))
2419 if (min && value < min[i])
2421 if (max && value > max[i])
2428 /* Strategy function to convert jiffies to seconds */
2429 int sysctl_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 = *(int *)(table->data) / HZ;
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) = new*HZ;
2462 /* Strategy function to convert jiffies to seconds */
2463 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2464 void __user *oldval, size_t __user *oldlenp,
2465 void __user *newval, size_t newlen)
2467 if (oldval && oldlenp) {
2470 if (get_user(olen, oldlenp))
2475 if (olen < sizeof(int))
2478 val = jiffies_to_msecs(*(int *)(table->data));
2479 if (put_user(val, (int __user *)oldval))
2481 if (put_user(sizeof(int), oldlenp))
2485 if (newval && newlen) {
2487 if (newlen != sizeof(int))
2489 if (get_user(new, (int __user *)newval))
2491 *(int *)(table->data) = msecs_to_jiffies(new);
2498 #else /* CONFIG_SYSCTL_SYSCALL */
2501 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2503 static int msg_count;
2504 struct __sysctl_args tmp;
2505 int name[CTL_MAXNAME];
2508 /* Read in the sysctl name for better debug message logging */
2509 if (copy_from_user(&tmp, args, sizeof(tmp)))
2511 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2513 for (i = 0; i < tmp.nlen; i++)
2514 if (get_user(name[i], tmp.name + i))
2517 /* Ignore accesses to kernel.version */
2518 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2521 if (msg_count < 5) {
2524 "warning: process `%s' used the removed sysctl "
2525 "system call with ", current->comm);
2526 for (i = 0; i < tmp.nlen; i++)
2527 printk("%d.", name[i]);
2534 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2535 void __user *oldval, size_t __user *oldlenp,
2536 void __user *newval, size_t newlen)
2541 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2542 void __user *oldval, size_t __user *oldlenp,
2543 void __user *newval, size_t newlen)
2548 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2549 void __user *oldval, size_t __user *oldlenp,
2550 void __user *newval, size_t newlen)
2555 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2556 void __user *oldval, size_t __user *oldlenp,
2557 void __user *newval, size_t newlen)
2562 #endif /* CONFIG_SYSCTL_SYSCALL */
2565 * No sense putting this after each symbol definition, twice,
2566 * exception granted :-)
2568 EXPORT_SYMBOL(proc_dointvec);
2569 EXPORT_SYMBOL(proc_dointvec_jiffies);
2570 EXPORT_SYMBOL(proc_dointvec_minmax);
2571 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2572 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2573 EXPORT_SYMBOL(proc_dostring);
2574 EXPORT_SYMBOL(proc_doulongvec_minmax);
2575 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2576 EXPORT_SYMBOL(register_sysctl_table);
2577 EXPORT_SYMBOL(sysctl_intvec);
2578 EXPORT_SYMBOL(sysctl_jiffies);
2579 EXPORT_SYMBOL(sysctl_ms_jiffies);
2580 EXPORT_SYMBOL(sysctl_string);
2581 EXPORT_SYMBOL(unregister_sysctl_table);