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_min_granularity_ns",
226 .data = &sysctl_sched_min_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_latency_ns",
237 .data = &sysctl_sched_latency,
238 .maxlen = sizeof(unsigned int),
240 .proc_handler = &proc_dointvec_minmax,
241 .strategy = &sysctl_intvec,
242 .extra1 = &min_sched_granularity_ns,
243 .extra2 = &max_sched_granularity_ns,
246 .ctl_name = CTL_UNNUMBERED,
247 .procname = "sched_wakeup_granularity_ns",
248 .data = &sysctl_sched_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_batch_wakeup_granularity_ns",
259 .data = &sysctl_sched_batch_wakeup_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_stat_granularity_ns",
270 .data = &sysctl_sched_stat_granularity,
271 .maxlen = sizeof(unsigned int),
273 .proc_handler = &proc_dointvec_minmax,
274 .strategy = &sysctl_intvec,
275 .extra1 = &min_wakeup_granularity_ns,
276 .extra2 = &max_wakeup_granularity_ns,
279 .ctl_name = CTL_UNNUMBERED,
280 .procname = "sched_runtime_limit_ns",
281 .data = &sysctl_sched_runtime_limit,
282 .maxlen = sizeof(unsigned int),
284 .proc_handler = &proc_dointvec_minmax,
285 .strategy = &sysctl_intvec,
286 .extra1 = &min_sched_granularity_ns,
287 .extra2 = &max_sched_granularity_ns,
290 .ctl_name = CTL_UNNUMBERED,
291 .procname = "sched_child_runs_first",
292 .data = &sysctl_sched_child_runs_first,
293 .maxlen = sizeof(unsigned int),
295 .proc_handler = &proc_dointvec,
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "sched_features",
300 .data = &sysctl_sched_features,
301 .maxlen = sizeof(unsigned int),
303 .proc_handler = &proc_dointvec,
306 #ifdef CONFIG_PROVE_LOCKING
308 .ctl_name = CTL_UNNUMBERED,
309 .procname = "prove_locking",
310 .data = &prove_locking,
311 .maxlen = sizeof(int),
313 .proc_handler = &proc_dointvec,
316 #ifdef CONFIG_LOCK_STAT
318 .ctl_name = CTL_UNNUMBERED,
319 .procname = "lock_stat",
321 .maxlen = sizeof(int),
323 .proc_handler = &proc_dointvec,
327 .ctl_name = KERN_PANIC,
329 .data = &panic_timeout,
330 .maxlen = sizeof(int),
332 .proc_handler = &proc_dointvec,
335 .ctl_name = KERN_CORE_USES_PID,
336 .procname = "core_uses_pid",
337 .data = &core_uses_pid,
338 .maxlen = sizeof(int),
340 .proc_handler = &proc_dointvec,
342 #ifdef CONFIG_AUDITSYSCALL
344 .ctl_name = CTL_UNNUMBERED,
345 .procname = "audit_argv_kb",
346 .data = &audit_argv_kb,
347 .maxlen = sizeof(int),
349 .proc_handler = &proc_dointvec,
353 .ctl_name = KERN_CORE_PATTERN,
354 .procname = "core_pattern",
355 .data = core_pattern,
356 .maxlen = CORENAME_MAX_SIZE,
358 .proc_handler = &proc_dostring,
359 .strategy = &sysctl_string,
361 #ifdef CONFIG_PROC_SYSCTL
363 .ctl_name = KERN_TAINTED,
364 .procname = "tainted",
366 .maxlen = sizeof(int),
368 .proc_handler = &proc_dointvec_taint,
372 .ctl_name = KERN_CAP_BSET,
373 .procname = "cap-bound",
375 .maxlen = sizeof(kernel_cap_t),
377 .proc_handler = &proc_dointvec_bset,
379 #ifdef CONFIG_BLK_DEV_INITRD
381 .ctl_name = KERN_REALROOTDEV,
382 .procname = "real-root-dev",
383 .data = &real_root_dev,
384 .maxlen = sizeof(int),
386 .proc_handler = &proc_dointvec,
390 .ctl_name = CTL_UNNUMBERED,
391 .procname = "print-fatal-signals",
392 .data = &print_fatal_signals,
393 .maxlen = sizeof(int),
395 .proc_handler = &proc_dointvec,
399 .ctl_name = KERN_SPARC_REBOOT,
400 .procname = "reboot-cmd",
401 .data = reboot_command,
404 .proc_handler = &proc_dostring,
405 .strategy = &sysctl_string,
408 .ctl_name = KERN_SPARC_STOP_A,
409 .procname = "stop-a",
410 .data = &stop_a_enabled,
411 .maxlen = sizeof (int),
413 .proc_handler = &proc_dointvec,
416 .ctl_name = KERN_SPARC_SCONS_PWROFF,
417 .procname = "scons-poweroff",
418 .data = &scons_pwroff,
419 .maxlen = sizeof (int),
421 .proc_handler = &proc_dointvec,
426 .ctl_name = KERN_HPPA_PWRSW,
427 .procname = "soft-power",
428 .data = &pwrsw_enabled,
429 .maxlen = sizeof (int),
431 .proc_handler = &proc_dointvec,
434 .ctl_name = KERN_HPPA_UNALIGNED,
435 .procname = "unaligned-trap",
436 .data = &unaligned_enabled,
437 .maxlen = sizeof (int),
439 .proc_handler = &proc_dointvec,
443 .ctl_name = KERN_CTLALTDEL,
444 .procname = "ctrl-alt-del",
446 .maxlen = sizeof(int),
448 .proc_handler = &proc_dointvec,
451 .ctl_name = KERN_PRINTK,
452 .procname = "printk",
453 .data = &console_loglevel,
454 .maxlen = 4*sizeof(int),
456 .proc_handler = &proc_dointvec,
460 .ctl_name = KERN_MODPROBE,
461 .procname = "modprobe",
462 .data = &modprobe_path,
463 .maxlen = KMOD_PATH_LEN,
465 .proc_handler = &proc_dostring,
466 .strategy = &sysctl_string,
469 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
471 .ctl_name = KERN_HOTPLUG,
472 .procname = "hotplug",
473 .data = &uevent_helper,
474 .maxlen = UEVENT_HELPER_PATH_LEN,
476 .proc_handler = &proc_dostring,
477 .strategy = &sysctl_string,
480 #ifdef CONFIG_CHR_DEV_SG
482 .ctl_name = KERN_SG_BIG_BUFF,
483 .procname = "sg-big-buff",
484 .data = &sg_big_buff,
485 .maxlen = sizeof (int),
487 .proc_handler = &proc_dointvec,
490 #ifdef CONFIG_BSD_PROCESS_ACCT
492 .ctl_name = KERN_ACCT,
495 .maxlen = 3*sizeof(int),
497 .proc_handler = &proc_dointvec,
500 #ifdef CONFIG_MAGIC_SYSRQ
502 .ctl_name = KERN_SYSRQ,
504 .data = &__sysrq_enabled,
505 .maxlen = sizeof (int),
507 .proc_handler = &proc_dointvec,
510 #ifdef CONFIG_PROC_SYSCTL
512 .ctl_name = KERN_CADPID,
513 .procname = "cad_pid",
515 .maxlen = sizeof (int),
517 .proc_handler = &proc_do_cad_pid,
521 .ctl_name = KERN_MAX_THREADS,
522 .procname = "threads-max",
523 .data = &max_threads,
524 .maxlen = sizeof(int),
526 .proc_handler = &proc_dointvec,
529 .ctl_name = KERN_RANDOM,
530 .procname = "random",
532 .child = random_table,
534 #ifdef CONFIG_UNIX98_PTYS
536 .ctl_name = KERN_PTY,
543 .ctl_name = KERN_OVERFLOWUID,
544 .procname = "overflowuid",
545 .data = &overflowuid,
546 .maxlen = sizeof(int),
548 .proc_handler = &proc_dointvec_minmax,
549 .strategy = &sysctl_intvec,
550 .extra1 = &minolduid,
551 .extra2 = &maxolduid,
554 .ctl_name = KERN_OVERFLOWGID,
555 .procname = "overflowgid",
556 .data = &overflowgid,
557 .maxlen = sizeof(int),
559 .proc_handler = &proc_dointvec_minmax,
560 .strategy = &sysctl_intvec,
561 .extra1 = &minolduid,
562 .extra2 = &maxolduid,
565 #ifdef CONFIG_MATHEMU
567 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
568 .procname = "ieee_emulation_warnings",
569 .data = &sysctl_ieee_emulation_warnings,
570 .maxlen = sizeof(int),
572 .proc_handler = &proc_dointvec,
575 #ifdef CONFIG_NO_IDLE_HZ
577 .ctl_name = KERN_HZ_TIMER,
578 .procname = "hz_timer",
579 .data = &sysctl_hz_timer,
580 .maxlen = sizeof(int),
582 .proc_handler = &proc_dointvec,
586 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
587 .procname = "userprocess_debug",
588 .data = &sysctl_userprocess_debug,
589 .maxlen = sizeof(int),
591 .proc_handler = &proc_dointvec,
595 .ctl_name = KERN_PIDMAX,
596 .procname = "pid_max",
598 .maxlen = sizeof (int),
600 .proc_handler = &proc_dointvec_minmax,
601 .strategy = sysctl_intvec,
602 .extra1 = &pid_max_min,
603 .extra2 = &pid_max_max,
606 .ctl_name = KERN_PANIC_ON_OOPS,
607 .procname = "panic_on_oops",
608 .data = &panic_on_oops,
609 .maxlen = sizeof(int),
611 .proc_handler = &proc_dointvec,
614 .ctl_name = KERN_PRINTK_RATELIMIT,
615 .procname = "printk_ratelimit",
616 .data = &printk_ratelimit_jiffies,
617 .maxlen = sizeof(int),
619 .proc_handler = &proc_dointvec_jiffies,
620 .strategy = &sysctl_jiffies,
623 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
624 .procname = "printk_ratelimit_burst",
625 .data = &printk_ratelimit_burst,
626 .maxlen = sizeof(int),
628 .proc_handler = &proc_dointvec,
631 .ctl_name = KERN_NGROUPS_MAX,
632 .procname = "ngroups_max",
633 .data = &ngroups_max,
634 .maxlen = sizeof (int),
636 .proc_handler = &proc_dointvec,
638 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
640 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
641 .procname = "unknown_nmi_panic",
642 .data = &unknown_nmi_panic,
643 .maxlen = sizeof (int),
645 .proc_handler = &proc_dointvec,
648 .ctl_name = KERN_NMI_WATCHDOG,
649 .procname = "nmi_watchdog",
650 .data = &nmi_watchdog_enabled,
651 .maxlen = sizeof (int),
653 .proc_handler = &proc_nmi_enabled,
656 #if defined(CONFIG_X86)
658 .ctl_name = KERN_PANIC_ON_NMI,
659 .procname = "panic_on_unrecovered_nmi",
660 .data = &panic_on_unrecovered_nmi,
661 .maxlen = sizeof(int),
663 .proc_handler = &proc_dointvec,
666 .ctl_name = KERN_BOOTLOADER_TYPE,
667 .procname = "bootloader_type",
668 .data = &bootloader_type,
669 .maxlen = sizeof (int),
671 .proc_handler = &proc_dointvec,
674 .ctl_name = CTL_UNNUMBERED,
675 .procname = "kstack_depth_to_print",
676 .data = &kstack_depth_to_print,
677 .maxlen = sizeof(int),
679 .proc_handler = &proc_dointvec,
682 #if defined(CONFIG_MMU)
684 .ctl_name = KERN_RANDOMIZE,
685 .procname = "randomize_va_space",
686 .data = &randomize_va_space,
687 .maxlen = sizeof(int),
689 .proc_handler = &proc_dointvec,
692 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
694 .ctl_name = KERN_SPIN_RETRY,
695 .procname = "spin_retry",
697 .maxlen = sizeof (int),
699 .proc_handler = &proc_dointvec,
702 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
704 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
705 .procname = "acpi_video_flags",
706 .data = &acpi_realmode_flags,
707 .maxlen = sizeof (unsigned long),
709 .proc_handler = &proc_doulongvec_minmax,
714 .ctl_name = KERN_IA64_UNALIGNED,
715 .procname = "ignore-unaligned-usertrap",
716 .data = &no_unaligned_warning,
717 .maxlen = sizeof (int),
719 .proc_handler = &proc_dointvec,
724 .ctl_name = KERN_COMPAT_LOG,
725 .procname = "compat-log",
727 .maxlen = sizeof (int),
729 .proc_handler = &proc_dointvec,
732 #ifdef CONFIG_RT_MUTEXES
734 .ctl_name = KERN_MAX_LOCK_DEPTH,
735 .procname = "max_lock_depth",
736 .data = &max_lock_depth,
737 .maxlen = sizeof(int),
739 .proc_handler = &proc_dointvec,
742 #ifdef CONFIG_PROC_FS
744 .ctl_name = CTL_UNNUMBERED,
745 .procname = "maps_protect",
746 .data = &maps_protect,
747 .maxlen = sizeof(int),
749 .proc_handler = &proc_dointvec,
753 .ctl_name = CTL_UNNUMBERED,
754 .procname = "poweroff_cmd",
755 .data = &poweroff_cmd,
756 .maxlen = POWEROFF_CMD_PATH_LEN,
758 .proc_handler = &proc_dostring,
759 .strategy = &sysctl_string,
762 * NOTE: do not add new entries to this table unless you have read
763 * Documentation/sysctl/ctl_unnumbered.txt
768 /* Constants for minimum and maximum testing in vm_table.
769 We use these as one-element integer vectors. */
772 static int one_hundred = 100;
775 static ctl_table vm_table[] = {
777 .ctl_name = VM_OVERCOMMIT_MEMORY,
778 .procname = "overcommit_memory",
779 .data = &sysctl_overcommit_memory,
780 .maxlen = sizeof(sysctl_overcommit_memory),
782 .proc_handler = &proc_dointvec,
785 .ctl_name = VM_PANIC_ON_OOM,
786 .procname = "panic_on_oom",
787 .data = &sysctl_panic_on_oom,
788 .maxlen = sizeof(sysctl_panic_on_oom),
790 .proc_handler = &proc_dointvec,
793 .ctl_name = VM_OVERCOMMIT_RATIO,
794 .procname = "overcommit_ratio",
795 .data = &sysctl_overcommit_ratio,
796 .maxlen = sizeof(sysctl_overcommit_ratio),
798 .proc_handler = &proc_dointvec,
801 .ctl_name = VM_PAGE_CLUSTER,
802 .procname = "page-cluster",
803 .data = &page_cluster,
804 .maxlen = sizeof(int),
806 .proc_handler = &proc_dointvec,
809 .ctl_name = VM_DIRTY_BACKGROUND,
810 .procname = "dirty_background_ratio",
811 .data = &dirty_background_ratio,
812 .maxlen = sizeof(dirty_background_ratio),
814 .proc_handler = &proc_dointvec_minmax,
815 .strategy = &sysctl_intvec,
817 .extra2 = &one_hundred,
820 .ctl_name = VM_DIRTY_RATIO,
821 .procname = "dirty_ratio",
822 .data = &vm_dirty_ratio,
823 .maxlen = sizeof(vm_dirty_ratio),
825 .proc_handler = &proc_dointvec_minmax,
826 .strategy = &sysctl_intvec,
828 .extra2 = &one_hundred,
831 .ctl_name = VM_DIRTY_WB_CS,
832 .procname = "dirty_writeback_centisecs",
833 .data = &dirty_writeback_interval,
834 .maxlen = sizeof(dirty_writeback_interval),
836 .proc_handler = &dirty_writeback_centisecs_handler,
839 .ctl_name = VM_DIRTY_EXPIRE_CS,
840 .procname = "dirty_expire_centisecs",
841 .data = &dirty_expire_interval,
842 .maxlen = sizeof(dirty_expire_interval),
844 .proc_handler = &proc_dointvec_userhz_jiffies,
847 .ctl_name = VM_NR_PDFLUSH_THREADS,
848 .procname = "nr_pdflush_threads",
849 .data = &nr_pdflush_threads,
850 .maxlen = sizeof nr_pdflush_threads,
851 .mode = 0444 /* read-only*/,
852 .proc_handler = &proc_dointvec,
855 .ctl_name = VM_SWAPPINESS,
856 .procname = "swappiness",
857 .data = &vm_swappiness,
858 .maxlen = sizeof(vm_swappiness),
860 .proc_handler = &proc_dointvec_minmax,
861 .strategy = &sysctl_intvec,
863 .extra2 = &one_hundred,
865 #ifdef CONFIG_HUGETLB_PAGE
867 .ctl_name = VM_HUGETLB_PAGES,
868 .procname = "nr_hugepages",
869 .data = &max_huge_pages,
870 .maxlen = sizeof(unsigned long),
872 .proc_handler = &hugetlb_sysctl_handler,
873 .extra1 = (void *)&hugetlb_zero,
874 .extra2 = (void *)&hugetlb_infinity,
877 .ctl_name = VM_HUGETLB_GROUP,
878 .procname = "hugetlb_shm_group",
879 .data = &sysctl_hugetlb_shm_group,
880 .maxlen = sizeof(gid_t),
882 .proc_handler = &proc_dointvec,
885 .ctl_name = CTL_UNNUMBERED,
886 .procname = "hugepages_treat_as_movable",
887 .data = &hugepages_treat_as_movable,
888 .maxlen = sizeof(int),
890 .proc_handler = &hugetlb_treat_movable_handler,
894 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
895 .procname = "lowmem_reserve_ratio",
896 .data = &sysctl_lowmem_reserve_ratio,
897 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
899 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
900 .strategy = &sysctl_intvec,
903 .ctl_name = VM_DROP_PAGECACHE,
904 .procname = "drop_caches",
905 .data = &sysctl_drop_caches,
906 .maxlen = sizeof(int),
908 .proc_handler = drop_caches_sysctl_handler,
909 .strategy = &sysctl_intvec,
912 .ctl_name = VM_MIN_FREE_KBYTES,
913 .procname = "min_free_kbytes",
914 .data = &min_free_kbytes,
915 .maxlen = sizeof(min_free_kbytes),
917 .proc_handler = &min_free_kbytes_sysctl_handler,
918 .strategy = &sysctl_intvec,
922 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
923 .procname = "percpu_pagelist_fraction",
924 .data = &percpu_pagelist_fraction,
925 .maxlen = sizeof(percpu_pagelist_fraction),
927 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
928 .strategy = &sysctl_intvec,
929 .extra1 = &min_percpu_pagelist_fract,
933 .ctl_name = VM_MAX_MAP_COUNT,
934 .procname = "max_map_count",
935 .data = &sysctl_max_map_count,
936 .maxlen = sizeof(sysctl_max_map_count),
938 .proc_handler = &proc_dointvec
942 .ctl_name = VM_LAPTOP_MODE,
943 .procname = "laptop_mode",
944 .data = &laptop_mode,
945 .maxlen = sizeof(laptop_mode),
947 .proc_handler = &proc_dointvec_jiffies,
948 .strategy = &sysctl_jiffies,
951 .ctl_name = VM_BLOCK_DUMP,
952 .procname = "block_dump",
954 .maxlen = sizeof(block_dump),
956 .proc_handler = &proc_dointvec,
957 .strategy = &sysctl_intvec,
961 .ctl_name = VM_VFS_CACHE_PRESSURE,
962 .procname = "vfs_cache_pressure",
963 .data = &sysctl_vfs_cache_pressure,
964 .maxlen = sizeof(sysctl_vfs_cache_pressure),
966 .proc_handler = &proc_dointvec,
967 .strategy = &sysctl_intvec,
970 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
972 .ctl_name = VM_LEGACY_VA_LAYOUT,
973 .procname = "legacy_va_layout",
974 .data = &sysctl_legacy_va_layout,
975 .maxlen = sizeof(sysctl_legacy_va_layout),
977 .proc_handler = &proc_dointvec,
978 .strategy = &sysctl_intvec,
984 .ctl_name = VM_ZONE_RECLAIM_MODE,
985 .procname = "zone_reclaim_mode",
986 .data = &zone_reclaim_mode,
987 .maxlen = sizeof(zone_reclaim_mode),
989 .proc_handler = &proc_dointvec,
990 .strategy = &sysctl_intvec,
994 .ctl_name = VM_MIN_UNMAPPED,
995 .procname = "min_unmapped_ratio",
996 .data = &sysctl_min_unmapped_ratio,
997 .maxlen = sizeof(sysctl_min_unmapped_ratio),
999 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1000 .strategy = &sysctl_intvec,
1002 .extra2 = &one_hundred,
1005 .ctl_name = VM_MIN_SLAB,
1006 .procname = "min_slab_ratio",
1007 .data = &sysctl_min_slab_ratio,
1008 .maxlen = sizeof(sysctl_min_slab_ratio),
1010 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1011 .strategy = &sysctl_intvec,
1013 .extra2 = &one_hundred,
1018 .ctl_name = CTL_UNNUMBERED,
1019 .procname = "stat_interval",
1020 .data = &sysctl_stat_interval,
1021 .maxlen = sizeof(sysctl_stat_interval),
1023 .proc_handler = &proc_dointvec_jiffies,
1024 .strategy = &sysctl_jiffies,
1027 #ifdef CONFIG_SECURITY
1029 .ctl_name = CTL_UNNUMBERED,
1030 .procname = "mmap_min_addr",
1031 .data = &mmap_min_addr,
1032 .maxlen = sizeof(unsigned long),
1034 .proc_handler = &proc_doulongvec_minmax,
1039 .ctl_name = CTL_UNNUMBERED,
1040 .procname = "numa_zonelist_order",
1041 .data = &numa_zonelist_order,
1042 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1044 .proc_handler = &numa_zonelist_order_handler,
1045 .strategy = &sysctl_string,
1048 #if defined(CONFIG_X86_32) || \
1049 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1051 .ctl_name = VM_VDSO_ENABLED,
1052 .procname = "vdso_enabled",
1053 .data = &vdso_enabled,
1054 .maxlen = sizeof(vdso_enabled),
1056 .proc_handler = &proc_dointvec,
1057 .strategy = &sysctl_intvec,
1062 * NOTE: do not add new entries to this table unless you have read
1063 * Documentation/sysctl/ctl_unnumbered.txt
1068 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1069 static ctl_table binfmt_misc_table[] = {
1074 static ctl_table fs_table[] = {
1076 .ctl_name = FS_NRINODE,
1077 .procname = "inode-nr",
1078 .data = &inodes_stat,
1079 .maxlen = 2*sizeof(int),
1081 .proc_handler = &proc_dointvec,
1084 .ctl_name = FS_STATINODE,
1085 .procname = "inode-state",
1086 .data = &inodes_stat,
1087 .maxlen = 7*sizeof(int),
1089 .proc_handler = &proc_dointvec,
1092 .ctl_name = FS_NRFILE,
1093 .procname = "file-nr",
1094 .data = &files_stat,
1095 .maxlen = 3*sizeof(int),
1097 .proc_handler = &proc_nr_files,
1100 .ctl_name = FS_MAXFILE,
1101 .procname = "file-max",
1102 .data = &files_stat.max_files,
1103 .maxlen = sizeof(int),
1105 .proc_handler = &proc_dointvec,
1108 .ctl_name = FS_DENTRY,
1109 .procname = "dentry-state",
1110 .data = &dentry_stat,
1111 .maxlen = 6*sizeof(int),
1113 .proc_handler = &proc_dointvec,
1116 .ctl_name = FS_OVERFLOWUID,
1117 .procname = "overflowuid",
1118 .data = &fs_overflowuid,
1119 .maxlen = sizeof(int),
1121 .proc_handler = &proc_dointvec_minmax,
1122 .strategy = &sysctl_intvec,
1123 .extra1 = &minolduid,
1124 .extra2 = &maxolduid,
1127 .ctl_name = FS_OVERFLOWGID,
1128 .procname = "overflowgid",
1129 .data = &fs_overflowgid,
1130 .maxlen = sizeof(int),
1132 .proc_handler = &proc_dointvec_minmax,
1133 .strategy = &sysctl_intvec,
1134 .extra1 = &minolduid,
1135 .extra2 = &maxolduid,
1138 .ctl_name = FS_LEASES,
1139 .procname = "leases-enable",
1140 .data = &leases_enable,
1141 .maxlen = sizeof(int),
1143 .proc_handler = &proc_dointvec,
1145 #ifdef CONFIG_DNOTIFY
1147 .ctl_name = FS_DIR_NOTIFY,
1148 .procname = "dir-notify-enable",
1149 .data = &dir_notify_enable,
1150 .maxlen = sizeof(int),
1152 .proc_handler = &proc_dointvec,
1157 .ctl_name = FS_LEASE_TIME,
1158 .procname = "lease-break-time",
1159 .data = &lease_break_time,
1160 .maxlen = sizeof(int),
1162 .proc_handler = &proc_dointvec_minmax,
1163 .strategy = &sysctl_intvec,
1168 .ctl_name = FS_AIO_NR,
1169 .procname = "aio-nr",
1171 .maxlen = sizeof(aio_nr),
1173 .proc_handler = &proc_doulongvec_minmax,
1176 .ctl_name = FS_AIO_MAX_NR,
1177 .procname = "aio-max-nr",
1178 .data = &aio_max_nr,
1179 .maxlen = sizeof(aio_max_nr),
1181 .proc_handler = &proc_doulongvec_minmax,
1183 #ifdef CONFIG_INOTIFY_USER
1185 .ctl_name = FS_INOTIFY,
1186 .procname = "inotify",
1188 .child = inotify_table,
1193 .ctl_name = KERN_SETUID_DUMPABLE,
1194 .procname = "suid_dumpable",
1195 .data = &suid_dumpable,
1196 .maxlen = sizeof(int),
1198 .proc_handler = &proc_dointvec,
1200 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1202 .ctl_name = CTL_UNNUMBERED,
1203 .procname = "binfmt_misc",
1205 .child = binfmt_misc_table,
1209 * NOTE: do not add new entries to this table unless you have read
1210 * Documentation/sysctl/ctl_unnumbered.txt
1215 static ctl_table debug_table[] = {
1218 .ctl_name = CTL_UNNUMBERED,
1219 .procname = "exception-trace",
1220 .data = &show_unhandled_signals,
1221 .maxlen = sizeof(int),
1223 .proc_handler = proc_dointvec
1229 static ctl_table dev_table[] = {
1233 static DEFINE_SPINLOCK(sysctl_lock);
1235 /* called under sysctl_lock */
1236 static int use_table(struct ctl_table_header *p)
1238 if (unlikely(p->unregistering))
1244 /* called under sysctl_lock */
1245 static void unuse_table(struct ctl_table_header *p)
1248 if (unlikely(p->unregistering))
1249 complete(p->unregistering);
1252 /* called under sysctl_lock, will reacquire if has to wait */
1253 static void start_unregistering(struct ctl_table_header *p)
1256 * if p->used is 0, nobody will ever touch that entry again;
1257 * we'll eliminate all paths to it before dropping sysctl_lock
1259 if (unlikely(p->used)) {
1260 struct completion wait;
1261 init_completion(&wait);
1262 p->unregistering = &wait;
1263 spin_unlock(&sysctl_lock);
1264 wait_for_completion(&wait);
1265 spin_lock(&sysctl_lock);
1268 * do not remove from the list until nobody holds it; walking the
1269 * list in do_sysctl() relies on that.
1271 list_del_init(&p->ctl_entry);
1274 void sysctl_head_finish(struct ctl_table_header *head)
1278 spin_lock(&sysctl_lock);
1280 spin_unlock(&sysctl_lock);
1283 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1285 struct ctl_table_header *head;
1286 struct list_head *tmp;
1287 spin_lock(&sysctl_lock);
1289 tmp = &prev->ctl_entry;
1293 tmp = &root_table_header.ctl_entry;
1295 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1297 if (!use_table(head))
1299 spin_unlock(&sysctl_lock);
1303 if (tmp == &root_table_header.ctl_entry)
1306 spin_unlock(&sysctl_lock);
1310 #ifdef CONFIG_SYSCTL_SYSCALL
1311 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1312 void __user *newval, size_t newlen)
1314 struct ctl_table_header *head;
1315 int error = -ENOTDIR;
1317 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1321 if (!oldlenp || get_user(old_len, oldlenp))
1325 for (head = sysctl_head_next(NULL); head;
1326 head = sysctl_head_next(head)) {
1327 error = parse_table(name, nlen, oldval, oldlenp,
1328 newval, newlen, head->ctl_table);
1329 if (error != -ENOTDIR) {
1330 sysctl_head_finish(head);
1337 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1339 struct __sysctl_args tmp;
1342 if (copy_from_user(&tmp, args, sizeof(tmp)))
1346 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1347 tmp.newval, tmp.newlen);
1351 #endif /* CONFIG_SYSCTL_SYSCALL */
1354 * sysctl_perm does NOT grant the superuser all rights automatically, because
1355 * some sysctl variables are readonly even to root.
1358 static int test_perm(int mode, int op)
1362 else if (in_egroup_p(0))
1364 if ((mode & op & 0007) == op)
1369 int sysctl_perm(ctl_table *table, int op)
1372 error = security_sysctl(table, op);
1375 return test_perm(table->mode, op);
1378 #ifdef CONFIG_SYSCTL_SYSCALL
1379 static int parse_table(int __user *name, int nlen,
1380 void __user *oldval, size_t __user *oldlenp,
1381 void __user *newval, size_t newlen,
1388 if (get_user(n, name))
1390 for ( ; table->ctl_name || table->procname; table++) {
1391 if (!table->ctl_name)
1393 if (n == table->ctl_name) {
1396 if (sysctl_perm(table, 001))
1400 table = table->child;
1403 error = do_sysctl_strategy(table, name, nlen,
1412 /* Perform the actual read/write of a sysctl table entry. */
1413 int do_sysctl_strategy (ctl_table *table,
1414 int __user *name, int nlen,
1415 void __user *oldval, size_t __user *oldlenp,
1416 void __user *newval, size_t newlen)
1425 if (sysctl_perm(table, op))
1428 if (table->strategy) {
1429 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1437 /* If there is no strategy routine, or if the strategy returns
1438 * zero, proceed with automatic r/w */
1439 if (table->data && table->maxlen) {
1440 if (oldval && oldlenp) {
1441 if (get_user(len, oldlenp))
1444 if (len > table->maxlen)
1445 len = table->maxlen;
1446 if(copy_to_user(oldval, table->data, len))
1448 if(put_user(len, oldlenp))
1452 if (newval && newlen) {
1454 if (len > table->maxlen)
1455 len = table->maxlen;
1456 if(copy_from_user(table->data, newval, len))
1462 #endif /* CONFIG_SYSCTL_SYSCALL */
1464 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1466 for (; table->ctl_name || table->procname; table++) {
1467 table->parent = parent;
1469 sysctl_set_parent(table, table->child);
1473 static __init int sysctl_init(void)
1475 sysctl_set_parent(NULL, root_table);
1479 core_initcall(sysctl_init);
1482 * register_sysctl_table - register a sysctl hierarchy
1483 * @table: the top-level table structure
1485 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1486 * array. An entry with a ctl_name of 0 terminates the table.
1488 * The members of the &ctl_table structure are used as follows:
1490 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1491 * must be unique within that level of sysctl
1493 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1494 * enter a sysctl file
1496 * data - a pointer to data for use by proc_handler
1498 * maxlen - the maximum size in bytes of the data
1500 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1502 * child - a pointer to the child sysctl table if this entry is a directory, or
1505 * proc_handler - the text handler routine (described below)
1507 * strategy - the strategy routine (described below)
1509 * de - for internal use by the sysctl routines
1511 * extra1, extra2 - extra pointers usable by the proc handler routines
1513 * Leaf nodes in the sysctl tree will be represented by a single file
1514 * under /proc; non-leaf nodes will be represented by directories.
1516 * sysctl(2) can automatically manage read and write requests through
1517 * the sysctl table. The data and maxlen fields of the ctl_table
1518 * struct enable minimal validation of the values being written to be
1519 * performed, and the mode field allows minimal authentication.
1521 * More sophisticated management can be enabled by the provision of a
1522 * strategy routine with the table entry. This will be called before
1523 * any automatic read or write of the data is performed.
1525 * The strategy routine may return
1527 * < 0 - Error occurred (error is passed to user process)
1529 * 0 - OK - proceed with automatic read or write.
1531 * > 0 - OK - read or write has been done by the strategy routine, so
1532 * return immediately.
1534 * There must be a proc_handler routine for any terminal nodes
1535 * mirrored under /proc/sys (non-terminals are handled by a built-in
1536 * directory handler). Several default handlers are available to
1537 * cover common cases -
1539 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1540 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1541 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1543 * It is the handler's job to read the input buffer from user memory
1544 * and process it. The handler should return 0 on success.
1546 * This routine returns %NULL on a failure to register, and a pointer
1547 * to the table header on success.
1549 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1551 struct ctl_table_header *tmp;
1552 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1555 tmp->ctl_table = table;
1556 INIT_LIST_HEAD(&tmp->ctl_entry);
1558 tmp->unregistering = NULL;
1559 sysctl_set_parent(NULL, table);
1560 spin_lock(&sysctl_lock);
1561 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1562 spin_unlock(&sysctl_lock);
1567 * unregister_sysctl_table - unregister a sysctl table hierarchy
1568 * @header: the header returned from register_sysctl_table
1570 * Unregisters the sysctl table and all children. proc entries may not
1571 * actually be removed until they are no longer used by anyone.
1573 void unregister_sysctl_table(struct ctl_table_header * header)
1576 spin_lock(&sysctl_lock);
1577 start_unregistering(header);
1578 spin_unlock(&sysctl_lock);
1582 #else /* !CONFIG_SYSCTL */
1583 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1588 void unregister_sysctl_table(struct ctl_table_header * table)
1592 #endif /* CONFIG_SYSCTL */
1598 #ifdef CONFIG_PROC_SYSCTL
1600 static int _proc_do_string(void* data, int maxlen, int write,
1601 struct file *filp, void __user *buffer,
1602 size_t *lenp, loff_t *ppos)
1608 if (!data || !maxlen || !*lenp) {
1616 while (len < *lenp) {
1617 if (get_user(c, p++))
1619 if (c == 0 || c == '\n')
1625 if(copy_from_user(data, buffer, len))
1627 ((char *) data)[len] = 0;
1645 if(copy_to_user(buffer, data, len))
1648 if(put_user('\n', ((char __user *) buffer) + len))
1659 * proc_dostring - read a string sysctl
1660 * @table: the sysctl table
1661 * @write: %TRUE if this is a write to the sysctl file
1662 * @filp: the file structure
1663 * @buffer: the user buffer
1664 * @lenp: the size of the user buffer
1665 * @ppos: file position
1667 * Reads/writes a string from/to the user buffer. If the kernel
1668 * buffer provided is not large enough to hold the string, the
1669 * string is truncated. The copied string is %NULL-terminated.
1670 * If the string is being read by the user process, it is copied
1671 * and a newline '\n' is added. It is truncated if the buffer is
1674 * Returns 0 on success.
1676 int proc_dostring(ctl_table *table, int write, struct file *filp,
1677 void __user *buffer, size_t *lenp, loff_t *ppos)
1679 return _proc_do_string(table->data, table->maxlen, write, filp,
1680 buffer, lenp, ppos);
1684 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1686 int write, void *data)
1689 *valp = *negp ? -*lvalp : *lvalp;
1694 *lvalp = (unsigned long)-val;
1697 *lvalp = (unsigned long)val;
1703 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1704 int write, struct file *filp, void __user *buffer,
1705 size_t *lenp, loff_t *ppos,
1706 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1707 int write, void *data),
1710 #define TMPBUFLEN 21
1711 int *i, vleft, first=1, neg, val;
1715 char buf[TMPBUFLEN], *p;
1716 char __user *s = buffer;
1718 if (!tbl_data || !table->maxlen || !*lenp ||
1719 (*ppos && !write)) {
1724 i = (int *) tbl_data;
1725 vleft = table->maxlen / sizeof(*i);
1729 conv = do_proc_dointvec_conv;
1731 for (; left && vleft--; i++, first=0) {
1746 if (len > sizeof(buf) - 1)
1747 len = sizeof(buf) - 1;
1748 if (copy_from_user(buf, s, len))
1752 if (*p == '-' && left > 1) {
1756 if (*p < '0' || *p > '9')
1759 lval = simple_strtoul(p, &p, 0);
1762 if ((len < left) && *p && !isspace(*p))
1769 if (conv(&neg, &lval, i, 1, data))
1776 if (conv(&neg, &lval, i, 0, data))
1779 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1783 if(copy_to_user(s, buf, len))
1790 if (!write && !first && left) {
1791 if(put_user('\n', s))
1798 if (get_user(c, s++))
1813 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1814 void __user *buffer, size_t *lenp, loff_t *ppos,
1815 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1816 int write, void *data),
1819 return __do_proc_dointvec(table->data, table, write, filp,
1820 buffer, lenp, ppos, conv, data);
1824 * proc_dointvec - read a vector of integers
1825 * @table: the sysctl table
1826 * @write: %TRUE if this is a write to the sysctl file
1827 * @filp: the file structure
1828 * @buffer: the user buffer
1829 * @lenp: the size of the user buffer
1830 * @ppos: file position
1832 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1833 * values from/to the user buffer, treated as an ASCII string.
1835 * Returns 0 on success.
1837 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1838 void __user *buffer, size_t *lenp, loff_t *ppos)
1840 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1848 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1850 int write, void *data)
1852 int op = *(int *)data;
1854 int val = *negp ? -*lvalp : *lvalp;
1856 case OP_SET: *valp = val; break;
1857 case OP_AND: *valp &= val; break;
1858 case OP_OR: *valp |= val; break;
1864 *lvalp = (unsigned long)-val;
1867 *lvalp = (unsigned long)val;
1874 * init may raise the set.
1877 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1878 void __user *buffer, size_t *lenp, loff_t *ppos)
1882 if (write && !capable(CAP_SYS_MODULE)) {
1886 op = is_init(current) ? OP_SET : OP_AND;
1887 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1888 do_proc_dointvec_bset_conv,&op);
1892 * Taint values can only be increased
1894 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1895 void __user *buffer, size_t *lenp, loff_t *ppos)
1899 if (write && !capable(CAP_SYS_ADMIN))
1903 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1904 do_proc_dointvec_bset_conv,&op);
1907 struct do_proc_dointvec_minmax_conv_param {
1912 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1914 int write, void *data)
1916 struct do_proc_dointvec_minmax_conv_param *param = data;
1918 int val = *negp ? -*lvalp : *lvalp;
1919 if ((param->min && *param->min > val) ||
1920 (param->max && *param->max < val))
1927 *lvalp = (unsigned long)-val;
1930 *lvalp = (unsigned long)val;
1937 * proc_dointvec_minmax - read a vector of integers with min/max values
1938 * @table: the sysctl table
1939 * @write: %TRUE if this is a write to the sysctl file
1940 * @filp: the file structure
1941 * @buffer: the user buffer
1942 * @lenp: the size of the user buffer
1943 * @ppos: file position
1945 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1946 * values from/to the user buffer, treated as an ASCII string.
1948 * This routine will ensure the values are within the range specified by
1949 * table->extra1 (min) and table->extra2 (max).
1951 * Returns 0 on success.
1953 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1954 void __user *buffer, size_t *lenp, loff_t *ppos)
1956 struct do_proc_dointvec_minmax_conv_param param = {
1957 .min = (int *) table->extra1,
1958 .max = (int *) table->extra2,
1960 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1961 do_proc_dointvec_minmax_conv, ¶m);
1964 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1966 void __user *buffer,
1967 size_t *lenp, loff_t *ppos,
1968 unsigned long convmul,
1969 unsigned long convdiv)
1971 #define TMPBUFLEN 21
1972 unsigned long *i, *min, *max, val;
1973 int vleft, first=1, neg;
1975 char buf[TMPBUFLEN], *p;
1976 char __user *s = buffer;
1978 if (!data || !table->maxlen || !*lenp ||
1979 (*ppos && !write)) {
1984 i = (unsigned long *) data;
1985 min = (unsigned long *) table->extra1;
1986 max = (unsigned long *) table->extra2;
1987 vleft = table->maxlen / sizeof(unsigned long);
1990 for (; left && vleft--; i++, min++, max++, first=0) {
2005 if (len > TMPBUFLEN-1)
2007 if (copy_from_user(buf, s, len))
2011 if (*p == '-' && left > 1) {
2015 if (*p < '0' || *p > '9')
2017 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2019 if ((len < left) && *p && !isspace(*p))
2028 if ((min && val < *min) || (max && val > *max))
2035 sprintf(p, "%lu", convdiv * (*i) / convmul);
2039 if(copy_to_user(s, buf, len))
2046 if (!write && !first && left) {
2047 if(put_user('\n', s))
2054 if (get_user(c, s++))
2069 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2071 void __user *buffer,
2072 size_t *lenp, loff_t *ppos,
2073 unsigned long convmul,
2074 unsigned long convdiv)
2076 return __do_proc_doulongvec_minmax(table->data, table, write,
2077 filp, buffer, lenp, ppos, convmul, convdiv);
2081 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2082 * @table: the sysctl table
2083 * @write: %TRUE if this is a write to the sysctl file
2084 * @filp: the file structure
2085 * @buffer: the user buffer
2086 * @lenp: the size of the user buffer
2087 * @ppos: file position
2089 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2090 * values from/to the user buffer, treated as an ASCII string.
2092 * This routine will ensure the values are within the range specified by
2093 * table->extra1 (min) and table->extra2 (max).
2095 * Returns 0 on success.
2097 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2098 void __user *buffer, size_t *lenp, loff_t *ppos)
2100 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2104 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2105 * @table: the sysctl table
2106 * @write: %TRUE if this is a write to the sysctl file
2107 * @filp: the file structure
2108 * @buffer: the user buffer
2109 * @lenp: the size of the user buffer
2110 * @ppos: file position
2112 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2113 * values from/to the user buffer, treated as an ASCII string. The values
2114 * are treated as milliseconds, and converted to jiffies when they are stored.
2116 * This routine will ensure the values are within the range specified by
2117 * table->extra1 (min) and table->extra2 (max).
2119 * Returns 0 on success.
2121 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2123 void __user *buffer,
2124 size_t *lenp, loff_t *ppos)
2126 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2127 lenp, ppos, HZ, 1000l);
2131 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2133 int write, void *data)
2136 if (*lvalp > LONG_MAX / HZ)
2138 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2144 lval = (unsigned long)-val;
2147 lval = (unsigned long)val;
2154 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2156 int write, void *data)
2159 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2161 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2167 lval = (unsigned long)-val;
2170 lval = (unsigned long)val;
2172 *lvalp = jiffies_to_clock_t(lval);
2177 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2179 int write, void *data)
2182 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2188 lval = (unsigned long)-val;
2191 lval = (unsigned long)val;
2193 *lvalp = jiffies_to_msecs(lval);
2199 * proc_dointvec_jiffies - read a vector of integers as seconds
2200 * @table: the sysctl table
2201 * @write: %TRUE if this is a write to the sysctl file
2202 * @filp: the file structure
2203 * @buffer: the user buffer
2204 * @lenp: the size of the user buffer
2205 * @ppos: file position
2207 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2208 * values from/to the user buffer, treated as an ASCII string.
2209 * The values read are assumed to be in seconds, and are converted into
2212 * Returns 0 on success.
2214 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2215 void __user *buffer, size_t *lenp, loff_t *ppos)
2217 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2218 do_proc_dointvec_jiffies_conv,NULL);
2222 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2223 * @table: the sysctl table
2224 * @write: %TRUE if this is a write to the sysctl file
2225 * @filp: the file structure
2226 * @buffer: the user buffer
2227 * @lenp: the size of the user buffer
2228 * @ppos: pointer to the file position
2230 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2231 * values from/to the user buffer, treated as an ASCII string.
2232 * The values read are assumed to be in 1/USER_HZ seconds, and
2233 * are converted into jiffies.
2235 * Returns 0 on success.
2237 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2238 void __user *buffer, size_t *lenp, loff_t *ppos)
2240 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2241 do_proc_dointvec_userhz_jiffies_conv,NULL);
2245 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2246 * @table: the sysctl table
2247 * @write: %TRUE if this is a write to the sysctl file
2248 * @filp: the file structure
2249 * @buffer: the user buffer
2250 * @lenp: the size of the user buffer
2251 * @ppos: file position
2252 * @ppos: the current position in the file
2254 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2255 * values from/to the user buffer, treated as an ASCII string.
2256 * The values read are assumed to be in 1/1000 seconds, and
2257 * are converted into jiffies.
2259 * Returns 0 on success.
2261 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2262 void __user *buffer, size_t *lenp, loff_t *ppos)
2264 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2265 do_proc_dointvec_ms_jiffies_conv, NULL);
2268 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2269 void __user *buffer, size_t *lenp, loff_t *ppos)
2271 struct pid *new_pid;
2275 tmp = pid_nr(cad_pid);
2277 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2278 lenp, ppos, NULL, NULL);
2282 new_pid = find_get_pid(tmp);
2286 put_pid(xchg(&cad_pid, new_pid));
2290 #else /* CONFIG_PROC_FS */
2292 int proc_dostring(ctl_table *table, int write, struct file *filp,
2293 void __user *buffer, size_t *lenp, loff_t *ppos)
2298 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2299 void __user *buffer, size_t *lenp, loff_t *ppos)
2304 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2310 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2311 void __user *buffer, size_t *lenp, loff_t *ppos)
2316 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2317 void __user *buffer, size_t *lenp, loff_t *ppos)
2322 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2323 void __user *buffer, size_t *lenp, loff_t *ppos)
2328 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2329 void __user *buffer, size_t *lenp, loff_t *ppos)
2334 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2335 void __user *buffer, size_t *lenp, loff_t *ppos)
2340 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2342 void __user *buffer,
2343 size_t *lenp, loff_t *ppos)
2349 #endif /* CONFIG_PROC_FS */
2352 #ifdef CONFIG_SYSCTL_SYSCALL
2354 * General sysctl support routines
2357 /* The generic string strategy routine: */
2358 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2359 void __user *oldval, size_t __user *oldlenp,
2360 void __user *newval, size_t newlen)
2362 if (!table->data || !table->maxlen)
2365 if (oldval && oldlenp) {
2367 if (get_user(bufsize, oldlenp))
2370 size_t len = strlen(table->data), copied;
2372 /* This shouldn't trigger for a well-formed sysctl */
2373 if (len > table->maxlen)
2374 len = table->maxlen;
2376 /* Copy up to a max of bufsize-1 bytes of the string */
2377 copied = (len >= bufsize) ? bufsize - 1 : len;
2379 if (copy_to_user(oldval, table->data, copied) ||
2380 put_user(0, (char __user *)(oldval + copied)))
2382 if (put_user(len, oldlenp))
2386 if (newval && newlen) {
2387 size_t len = newlen;
2388 if (len > table->maxlen)
2389 len = table->maxlen;
2390 if(copy_from_user(table->data, newval, len))
2392 if (len == table->maxlen)
2394 ((char *) table->data)[len] = 0;
2400 * This function makes sure that all of the integers in the vector
2401 * are between the minimum and maximum values given in the arrays
2402 * table->extra1 and table->extra2, respectively.
2404 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2405 void __user *oldval, size_t __user *oldlenp,
2406 void __user *newval, size_t newlen)
2409 if (newval && newlen) {
2410 int __user *vec = (int __user *) newval;
2411 int *min = (int *) table->extra1;
2412 int *max = (int *) table->extra2;
2416 if (newlen % sizeof(int) != 0)
2419 if (!table->extra1 && !table->extra2)
2422 if (newlen > table->maxlen)
2423 newlen = table->maxlen;
2424 length = newlen / sizeof(int);
2426 for (i = 0; i < length; i++) {
2428 if (get_user(value, vec + i))
2430 if (min && value < min[i])
2432 if (max && value > max[i])
2439 /* Strategy function to convert jiffies to seconds */
2440 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2441 void __user *oldval, size_t __user *oldlenp,
2442 void __user *newval, size_t newlen)
2444 if (oldval && oldlenp) {
2447 if (get_user(olen, oldlenp))
2452 if (olen < sizeof(int))
2455 val = *(int *)(table->data) / HZ;
2456 if (put_user(val, (int __user *)oldval))
2458 if (put_user(sizeof(int), oldlenp))
2462 if (newval && newlen) {
2464 if (newlen != sizeof(int))
2466 if (get_user(new, (int __user *)newval))
2468 *(int *)(table->data) = new*HZ;
2473 /* Strategy function to convert jiffies to seconds */
2474 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2475 void __user *oldval, size_t __user *oldlenp,
2476 void __user *newval, size_t newlen)
2478 if (oldval && oldlenp) {
2481 if (get_user(olen, oldlenp))
2486 if (olen < sizeof(int))
2489 val = jiffies_to_msecs(*(int *)(table->data));
2490 if (put_user(val, (int __user *)oldval))
2492 if (put_user(sizeof(int), oldlenp))
2496 if (newval && newlen) {
2498 if (newlen != sizeof(int))
2500 if (get_user(new, (int __user *)newval))
2502 *(int *)(table->data) = msecs_to_jiffies(new);
2509 #else /* CONFIG_SYSCTL_SYSCALL */
2512 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2514 static int msg_count;
2515 struct __sysctl_args tmp;
2516 int name[CTL_MAXNAME];
2519 /* Read in the sysctl name for better debug message logging */
2520 if (copy_from_user(&tmp, args, sizeof(tmp)))
2522 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2524 for (i = 0; i < tmp.nlen; i++)
2525 if (get_user(name[i], tmp.name + i))
2528 /* Ignore accesses to kernel.version */
2529 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2532 if (msg_count < 5) {
2535 "warning: process `%s' used the removed sysctl "
2536 "system call with ", current->comm);
2537 for (i = 0; i < tmp.nlen; i++)
2538 printk("%d.", name[i]);
2545 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2546 void __user *oldval, size_t __user *oldlenp,
2547 void __user *newval, size_t newlen)
2552 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2553 void __user *oldval, size_t __user *oldlenp,
2554 void __user *newval, size_t newlen)
2559 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2560 void __user *oldval, size_t __user *oldlenp,
2561 void __user *newval, size_t newlen)
2566 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2567 void __user *oldval, size_t __user *oldlenp,
2568 void __user *newval, size_t newlen)
2573 #endif /* CONFIG_SYSCTL_SYSCALL */
2576 * No sense putting this after each symbol definition, twice,
2577 * exception granted :-)
2579 EXPORT_SYMBOL(proc_dointvec);
2580 EXPORT_SYMBOL(proc_dointvec_jiffies);
2581 EXPORT_SYMBOL(proc_dointvec_minmax);
2582 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2583 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2584 EXPORT_SYMBOL(proc_dostring);
2585 EXPORT_SYMBOL(proc_doulongvec_minmax);
2586 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2587 EXPORT_SYMBOL(register_sysctl_table);
2588 EXPORT_SYMBOL(sysctl_intvec);
2589 EXPORT_SYMBOL(sysctl_jiffies);
2590 EXPORT_SYMBOL(sysctl_ms_jiffies);
2591 EXPORT_SYMBOL(sysctl_string);
2592 EXPORT_SYMBOL(unregister_sysctl_table);