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 sysctl_oom_kill_allocating_task;
67 extern int max_threads;
68 extern int core_uses_pid;
69 extern int suid_dumpable;
70 extern char core_pattern[];
72 extern int min_free_kbytes;
73 extern int printk_ratelimit_jiffies;
74 extern int printk_ratelimit_burst;
75 extern int pid_max_min, pid_max_max;
76 extern int sysctl_drop_caches;
77 extern int percpu_pagelist_fraction;
78 extern int compat_log;
79 extern int maps_protect;
80 extern int sysctl_stat_interval;
81 extern int audit_argv_kb;
83 /* Constants used for minimum and maximum */
84 #ifdef CONFIG_DETECT_SOFTLOCKUP
86 static int sixty = 60;
94 static int one_hundred = 100;
96 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
97 static int maxolduid = 65535;
99 static int min_percpu_pagelist_fract = 8;
101 static int ngroups_max = NGROUPS_MAX;
104 extern char modprobe_path[];
106 #ifdef CONFIG_CHR_DEV_SG
107 extern int sg_big_buff;
111 extern char reboot_command [];
112 extern int stop_a_enabled;
113 extern int scons_pwroff;
117 extern int pwrsw_enabled;
118 extern int unaligned_enabled;
122 #ifdef CONFIG_MATHEMU
123 extern int sysctl_ieee_emulation_warnings;
125 extern int sysctl_userprocess_debug;
126 extern int spin_retry;
129 extern int sysctl_hz_timer;
131 #ifdef CONFIG_BSD_PROCESS_ACCT
132 extern int acct_parm[];
136 extern int no_unaligned_warning;
139 #ifdef CONFIG_RT_MUTEXES
140 extern int max_lock_depth;
143 #ifdef CONFIG_SYSCTL_SYSCALL
144 static int parse_table(int __user *, int, void __user *, size_t __user *,
145 void __user *, size_t, struct ctl_table *);
149 #ifdef CONFIG_PROC_SYSCTL
150 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
151 void __user *buffer, size_t *lenp, loff_t *ppos);
152 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
153 void __user *buffer, size_t *lenp, loff_t *ppos);
156 static struct ctl_table root_table[];
157 static struct ctl_table_header root_table_header =
158 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
160 static struct ctl_table kern_table[];
161 static struct ctl_table vm_table[];
162 static struct ctl_table fs_table[];
163 static struct ctl_table debug_table[];
164 static struct ctl_table dev_table[];
165 extern struct ctl_table random_table[];
166 #ifdef CONFIG_UNIX98_PTYS
167 extern struct ctl_table pty_table[];
169 #ifdef CONFIG_INOTIFY_USER
170 extern struct ctl_table inotify_table[];
173 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
174 int sysctl_legacy_va_layout;
177 extern int prove_locking;
178 extern int lock_stat;
180 /* The default sysctl tables: */
182 static struct ctl_table root_table[] = {
184 .ctl_name = CTL_KERN,
185 .procname = "kernel",
210 .ctl_name = CTL_DEBUG,
213 .child = debug_table,
222 * NOTE: do not add new entries to this table unless you have read
223 * Documentation/sysctl/ctl_unnumbered.txt
228 #ifdef CONFIG_SCHED_DEBUG
229 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
230 static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
231 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
232 static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
235 static struct ctl_table kern_table[] = {
236 #ifdef CONFIG_SCHED_DEBUG
238 .ctl_name = CTL_UNNUMBERED,
239 .procname = "sched_nr_latency",
240 .data = &sysctl_sched_nr_latency,
241 .maxlen = sizeof(unsigned int),
243 .proc_handler = &proc_dointvec,
246 .ctl_name = CTL_UNNUMBERED,
247 .procname = "sched_latency_ns",
248 .data = &sysctl_sched_latency,
249 .maxlen = sizeof(unsigned int),
251 .proc_handler = &proc_dointvec_minmax,
252 .strategy = &sysctl_intvec,
253 .extra1 = &min_sched_granularity_ns,
254 .extra2 = &max_sched_granularity_ns,
257 .ctl_name = CTL_UNNUMBERED,
258 .procname = "sched_wakeup_granularity_ns",
259 .data = &sysctl_sched_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_batch_wakeup_granularity_ns",
270 .data = &sysctl_sched_batch_wakeup_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_child_runs_first",
281 .data = &sysctl_sched_child_runs_first,
282 .maxlen = sizeof(unsigned int),
284 .proc_handler = &proc_dointvec,
287 .ctl_name = CTL_UNNUMBERED,
288 .procname = "sched_features",
289 .data = &sysctl_sched_features,
290 .maxlen = sizeof(unsigned int),
292 .proc_handler = &proc_dointvec,
295 .ctl_name = CTL_UNNUMBERED,
296 .procname = "sched_migration_cost",
297 .data = &sysctl_sched_migration_cost,
298 .maxlen = sizeof(unsigned int),
300 .proc_handler = &proc_dointvec,
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_compat_yield",
306 .data = &sysctl_sched_compat_yield,
307 .maxlen = sizeof(unsigned int),
309 .proc_handler = &proc_dointvec,
311 #ifdef CONFIG_PROVE_LOCKING
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "prove_locking",
315 .data = &prove_locking,
316 .maxlen = sizeof(int),
318 .proc_handler = &proc_dointvec,
321 #ifdef CONFIG_LOCK_STAT
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "lock_stat",
326 .maxlen = sizeof(int),
328 .proc_handler = &proc_dointvec,
332 .ctl_name = KERN_PANIC,
334 .data = &panic_timeout,
335 .maxlen = sizeof(int),
337 .proc_handler = &proc_dointvec,
340 .ctl_name = KERN_CORE_USES_PID,
341 .procname = "core_uses_pid",
342 .data = &core_uses_pid,
343 .maxlen = sizeof(int),
345 .proc_handler = &proc_dointvec,
347 #ifdef CONFIG_AUDITSYSCALL
349 .ctl_name = CTL_UNNUMBERED,
350 .procname = "audit_argv_kb",
351 .data = &audit_argv_kb,
352 .maxlen = sizeof(int),
354 .proc_handler = &proc_dointvec,
358 .ctl_name = KERN_CORE_PATTERN,
359 .procname = "core_pattern",
360 .data = core_pattern,
361 .maxlen = CORENAME_MAX_SIZE,
363 .proc_handler = &proc_dostring,
364 .strategy = &sysctl_string,
366 #ifdef CONFIG_PROC_SYSCTL
368 .procname = "tainted",
370 .maxlen = sizeof(int),
372 .proc_handler = &proc_dointvec_taint,
376 .procname = "cap-bound",
378 .maxlen = sizeof(kernel_cap_t),
380 .proc_handler = &proc_dointvec_bset,
382 #ifdef CONFIG_BLK_DEV_INITRD
384 .ctl_name = KERN_REALROOTDEV,
385 .procname = "real-root-dev",
386 .data = &real_root_dev,
387 .maxlen = sizeof(int),
389 .proc_handler = &proc_dointvec,
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "print-fatal-signals",
395 .data = &print_fatal_signals,
396 .maxlen = sizeof(int),
398 .proc_handler = &proc_dointvec,
402 .ctl_name = KERN_SPARC_REBOOT,
403 .procname = "reboot-cmd",
404 .data = reboot_command,
407 .proc_handler = &proc_dostring,
408 .strategy = &sysctl_string,
411 .ctl_name = KERN_SPARC_STOP_A,
412 .procname = "stop-a",
413 .data = &stop_a_enabled,
414 .maxlen = sizeof (int),
416 .proc_handler = &proc_dointvec,
419 .ctl_name = KERN_SPARC_SCONS_PWROFF,
420 .procname = "scons-poweroff",
421 .data = &scons_pwroff,
422 .maxlen = sizeof (int),
424 .proc_handler = &proc_dointvec,
429 .ctl_name = KERN_HPPA_PWRSW,
430 .procname = "soft-power",
431 .data = &pwrsw_enabled,
432 .maxlen = sizeof (int),
434 .proc_handler = &proc_dointvec,
437 .ctl_name = KERN_HPPA_UNALIGNED,
438 .procname = "unaligned-trap",
439 .data = &unaligned_enabled,
440 .maxlen = sizeof (int),
442 .proc_handler = &proc_dointvec,
446 .ctl_name = KERN_CTLALTDEL,
447 .procname = "ctrl-alt-del",
449 .maxlen = sizeof(int),
451 .proc_handler = &proc_dointvec,
454 .ctl_name = KERN_PRINTK,
455 .procname = "printk",
456 .data = &console_loglevel,
457 .maxlen = 4*sizeof(int),
459 .proc_handler = &proc_dointvec,
463 .ctl_name = KERN_MODPROBE,
464 .procname = "modprobe",
465 .data = &modprobe_path,
466 .maxlen = KMOD_PATH_LEN,
468 .proc_handler = &proc_dostring,
469 .strategy = &sysctl_string,
472 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
474 .ctl_name = KERN_HOTPLUG,
475 .procname = "hotplug",
476 .data = &uevent_helper,
477 .maxlen = UEVENT_HELPER_PATH_LEN,
479 .proc_handler = &proc_dostring,
480 .strategy = &sysctl_string,
483 #ifdef CONFIG_CHR_DEV_SG
485 .ctl_name = KERN_SG_BIG_BUFF,
486 .procname = "sg-big-buff",
487 .data = &sg_big_buff,
488 .maxlen = sizeof (int),
490 .proc_handler = &proc_dointvec,
493 #ifdef CONFIG_BSD_PROCESS_ACCT
495 .ctl_name = KERN_ACCT,
498 .maxlen = 3*sizeof(int),
500 .proc_handler = &proc_dointvec,
503 #ifdef CONFIG_MAGIC_SYSRQ
505 .ctl_name = KERN_SYSRQ,
507 .data = &__sysrq_enabled,
508 .maxlen = sizeof (int),
510 .proc_handler = &proc_dointvec,
513 #ifdef CONFIG_PROC_SYSCTL
515 .ctl_name = KERN_CADPID,
516 .procname = "cad_pid",
518 .maxlen = sizeof (int),
520 .proc_handler = &proc_do_cad_pid,
524 .ctl_name = KERN_MAX_THREADS,
525 .procname = "threads-max",
526 .data = &max_threads,
527 .maxlen = sizeof(int),
529 .proc_handler = &proc_dointvec,
532 .ctl_name = KERN_RANDOM,
533 .procname = "random",
535 .child = random_table,
537 #ifdef CONFIG_UNIX98_PTYS
539 .ctl_name = KERN_PTY,
546 .ctl_name = KERN_OVERFLOWUID,
547 .procname = "overflowuid",
548 .data = &overflowuid,
549 .maxlen = sizeof(int),
551 .proc_handler = &proc_dointvec_minmax,
552 .strategy = &sysctl_intvec,
553 .extra1 = &minolduid,
554 .extra2 = &maxolduid,
557 .ctl_name = KERN_OVERFLOWGID,
558 .procname = "overflowgid",
559 .data = &overflowgid,
560 .maxlen = sizeof(int),
562 .proc_handler = &proc_dointvec_minmax,
563 .strategy = &sysctl_intvec,
564 .extra1 = &minolduid,
565 .extra2 = &maxolduid,
568 #ifdef CONFIG_MATHEMU
570 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
571 .procname = "ieee_emulation_warnings",
572 .data = &sysctl_ieee_emulation_warnings,
573 .maxlen = sizeof(int),
575 .proc_handler = &proc_dointvec,
578 #ifdef CONFIG_NO_IDLE_HZ
580 .ctl_name = KERN_HZ_TIMER,
581 .procname = "hz_timer",
582 .data = &sysctl_hz_timer,
583 .maxlen = sizeof(int),
585 .proc_handler = &proc_dointvec,
589 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
590 .procname = "userprocess_debug",
591 .data = &sysctl_userprocess_debug,
592 .maxlen = sizeof(int),
594 .proc_handler = &proc_dointvec,
598 .ctl_name = KERN_PIDMAX,
599 .procname = "pid_max",
601 .maxlen = sizeof (int),
603 .proc_handler = &proc_dointvec_minmax,
604 .strategy = sysctl_intvec,
605 .extra1 = &pid_max_min,
606 .extra2 = &pid_max_max,
609 .ctl_name = KERN_PANIC_ON_OOPS,
610 .procname = "panic_on_oops",
611 .data = &panic_on_oops,
612 .maxlen = sizeof(int),
614 .proc_handler = &proc_dointvec,
617 .ctl_name = KERN_PRINTK_RATELIMIT,
618 .procname = "printk_ratelimit",
619 .data = &printk_ratelimit_jiffies,
620 .maxlen = sizeof(int),
622 .proc_handler = &proc_dointvec_jiffies,
623 .strategy = &sysctl_jiffies,
626 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
627 .procname = "printk_ratelimit_burst",
628 .data = &printk_ratelimit_burst,
629 .maxlen = sizeof(int),
631 .proc_handler = &proc_dointvec,
634 .ctl_name = KERN_NGROUPS_MAX,
635 .procname = "ngroups_max",
636 .data = &ngroups_max,
637 .maxlen = sizeof (int),
639 .proc_handler = &proc_dointvec,
641 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
643 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
644 .procname = "unknown_nmi_panic",
645 .data = &unknown_nmi_panic,
646 .maxlen = sizeof (int),
648 .proc_handler = &proc_dointvec,
651 .procname = "nmi_watchdog",
652 .data = &nmi_watchdog_enabled,
653 .maxlen = sizeof (int),
655 .proc_handler = &proc_nmi_enabled,
658 #if defined(CONFIG_X86)
660 .ctl_name = KERN_PANIC_ON_NMI,
661 .procname = "panic_on_unrecovered_nmi",
662 .data = &panic_on_unrecovered_nmi,
663 .maxlen = sizeof(int),
665 .proc_handler = &proc_dointvec,
668 .ctl_name = KERN_BOOTLOADER_TYPE,
669 .procname = "bootloader_type",
670 .data = &bootloader_type,
671 .maxlen = sizeof (int),
673 .proc_handler = &proc_dointvec,
676 .ctl_name = CTL_UNNUMBERED,
677 .procname = "kstack_depth_to_print",
678 .data = &kstack_depth_to_print,
679 .maxlen = sizeof(int),
681 .proc_handler = &proc_dointvec,
684 #if defined(CONFIG_MMU)
686 .ctl_name = KERN_RANDOMIZE,
687 .procname = "randomize_va_space",
688 .data = &randomize_va_space,
689 .maxlen = sizeof(int),
691 .proc_handler = &proc_dointvec,
694 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
696 .ctl_name = KERN_SPIN_RETRY,
697 .procname = "spin_retry",
699 .maxlen = sizeof (int),
701 .proc_handler = &proc_dointvec,
704 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
706 .procname = "acpi_video_flags",
707 .data = &acpi_realmode_flags,
708 .maxlen = sizeof (unsigned long),
710 .proc_handler = &proc_doulongvec_minmax,
715 .ctl_name = KERN_IA64_UNALIGNED,
716 .procname = "ignore-unaligned-usertrap",
717 .data = &no_unaligned_warning,
718 .maxlen = sizeof (int),
720 .proc_handler = &proc_dointvec,
723 #ifdef CONFIG_DETECT_SOFTLOCKUP
725 .ctl_name = CTL_UNNUMBERED,
726 .procname = "softlockup_thresh",
727 .data = &softlockup_thresh,
728 .maxlen = sizeof(int),
730 .proc_handler = &proc_dointvec_minmax,
731 .strategy = &sysctl_intvec,
738 .ctl_name = KERN_COMPAT_LOG,
739 .procname = "compat-log",
741 .maxlen = sizeof (int),
743 .proc_handler = &proc_dointvec,
746 #ifdef CONFIG_RT_MUTEXES
748 .ctl_name = KERN_MAX_LOCK_DEPTH,
749 .procname = "max_lock_depth",
750 .data = &max_lock_depth,
751 .maxlen = sizeof(int),
753 .proc_handler = &proc_dointvec,
756 #ifdef CONFIG_PROC_FS
758 .ctl_name = CTL_UNNUMBERED,
759 .procname = "maps_protect",
760 .data = &maps_protect,
761 .maxlen = sizeof(int),
763 .proc_handler = &proc_dointvec,
767 .ctl_name = CTL_UNNUMBERED,
768 .procname = "poweroff_cmd",
769 .data = &poweroff_cmd,
770 .maxlen = POWEROFF_CMD_PATH_LEN,
772 .proc_handler = &proc_dostring,
773 .strategy = &sysctl_string,
776 * NOTE: do not add new entries to this table unless you have read
777 * Documentation/sysctl/ctl_unnumbered.txt
782 static struct ctl_table vm_table[] = {
784 .ctl_name = VM_OVERCOMMIT_MEMORY,
785 .procname = "overcommit_memory",
786 .data = &sysctl_overcommit_memory,
787 .maxlen = sizeof(sysctl_overcommit_memory),
789 .proc_handler = &proc_dointvec,
792 .ctl_name = VM_PANIC_ON_OOM,
793 .procname = "panic_on_oom",
794 .data = &sysctl_panic_on_oom,
795 .maxlen = sizeof(sysctl_panic_on_oom),
797 .proc_handler = &proc_dointvec,
800 .ctl_name = CTL_UNNUMBERED,
801 .procname = "oom_kill_allocating_task",
802 .data = &sysctl_oom_kill_allocating_task,
803 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
805 .proc_handler = &proc_dointvec,
808 .ctl_name = VM_OVERCOMMIT_RATIO,
809 .procname = "overcommit_ratio",
810 .data = &sysctl_overcommit_ratio,
811 .maxlen = sizeof(sysctl_overcommit_ratio),
813 .proc_handler = &proc_dointvec,
816 .ctl_name = VM_PAGE_CLUSTER,
817 .procname = "page-cluster",
818 .data = &page_cluster,
819 .maxlen = sizeof(int),
821 .proc_handler = &proc_dointvec,
824 .ctl_name = VM_DIRTY_BACKGROUND,
825 .procname = "dirty_background_ratio",
826 .data = &dirty_background_ratio,
827 .maxlen = sizeof(dirty_background_ratio),
829 .proc_handler = &proc_dointvec_minmax,
830 .strategy = &sysctl_intvec,
832 .extra2 = &one_hundred,
835 .ctl_name = VM_DIRTY_RATIO,
836 .procname = "dirty_ratio",
837 .data = &vm_dirty_ratio,
838 .maxlen = sizeof(vm_dirty_ratio),
840 .proc_handler = &dirty_ratio_handler,
841 .strategy = &sysctl_intvec,
843 .extra2 = &one_hundred,
846 .procname = "dirty_writeback_centisecs",
847 .data = &dirty_writeback_interval,
848 .maxlen = sizeof(dirty_writeback_interval),
850 .proc_handler = &dirty_writeback_centisecs_handler,
853 .procname = "dirty_expire_centisecs",
854 .data = &dirty_expire_interval,
855 .maxlen = sizeof(dirty_expire_interval),
857 .proc_handler = &proc_dointvec_userhz_jiffies,
860 .ctl_name = VM_NR_PDFLUSH_THREADS,
861 .procname = "nr_pdflush_threads",
862 .data = &nr_pdflush_threads,
863 .maxlen = sizeof nr_pdflush_threads,
864 .mode = 0444 /* read-only*/,
865 .proc_handler = &proc_dointvec,
868 .ctl_name = VM_SWAPPINESS,
869 .procname = "swappiness",
870 .data = &vm_swappiness,
871 .maxlen = sizeof(vm_swappiness),
873 .proc_handler = &proc_dointvec_minmax,
874 .strategy = &sysctl_intvec,
876 .extra2 = &one_hundred,
878 #ifdef CONFIG_HUGETLB_PAGE
880 .procname = "nr_hugepages",
881 .data = &max_huge_pages,
882 .maxlen = sizeof(unsigned long),
884 .proc_handler = &hugetlb_sysctl_handler,
885 .extra1 = (void *)&hugetlb_zero,
886 .extra2 = (void *)&hugetlb_infinity,
889 .ctl_name = VM_HUGETLB_GROUP,
890 .procname = "hugetlb_shm_group",
891 .data = &sysctl_hugetlb_shm_group,
892 .maxlen = sizeof(gid_t),
894 .proc_handler = &proc_dointvec,
897 .ctl_name = CTL_UNNUMBERED,
898 .procname = "hugepages_treat_as_movable",
899 .data = &hugepages_treat_as_movable,
900 .maxlen = sizeof(int),
902 .proc_handler = &hugetlb_treat_movable_handler,
905 .ctl_name = CTL_UNNUMBERED,
906 .procname = "hugetlb_dynamic_pool",
907 .data = &hugetlb_dynamic_pool,
908 .maxlen = sizeof(hugetlb_dynamic_pool),
910 .proc_handler = &proc_dointvec,
914 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
915 .procname = "lowmem_reserve_ratio",
916 .data = &sysctl_lowmem_reserve_ratio,
917 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
919 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
920 .strategy = &sysctl_intvec,
923 .ctl_name = VM_DROP_PAGECACHE,
924 .procname = "drop_caches",
925 .data = &sysctl_drop_caches,
926 .maxlen = sizeof(int),
928 .proc_handler = drop_caches_sysctl_handler,
929 .strategy = &sysctl_intvec,
932 .ctl_name = VM_MIN_FREE_KBYTES,
933 .procname = "min_free_kbytes",
934 .data = &min_free_kbytes,
935 .maxlen = sizeof(min_free_kbytes),
937 .proc_handler = &min_free_kbytes_sysctl_handler,
938 .strategy = &sysctl_intvec,
942 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
943 .procname = "percpu_pagelist_fraction",
944 .data = &percpu_pagelist_fraction,
945 .maxlen = sizeof(percpu_pagelist_fraction),
947 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
948 .strategy = &sysctl_intvec,
949 .extra1 = &min_percpu_pagelist_fract,
953 .ctl_name = VM_MAX_MAP_COUNT,
954 .procname = "max_map_count",
955 .data = &sysctl_max_map_count,
956 .maxlen = sizeof(sysctl_max_map_count),
958 .proc_handler = &proc_dointvec
962 .ctl_name = VM_LAPTOP_MODE,
963 .procname = "laptop_mode",
964 .data = &laptop_mode,
965 .maxlen = sizeof(laptop_mode),
967 .proc_handler = &proc_dointvec_jiffies,
968 .strategy = &sysctl_jiffies,
971 .ctl_name = VM_BLOCK_DUMP,
972 .procname = "block_dump",
974 .maxlen = sizeof(block_dump),
976 .proc_handler = &proc_dointvec,
977 .strategy = &sysctl_intvec,
981 .ctl_name = VM_VFS_CACHE_PRESSURE,
982 .procname = "vfs_cache_pressure",
983 .data = &sysctl_vfs_cache_pressure,
984 .maxlen = sizeof(sysctl_vfs_cache_pressure),
986 .proc_handler = &proc_dointvec,
987 .strategy = &sysctl_intvec,
990 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
992 .ctl_name = VM_LEGACY_VA_LAYOUT,
993 .procname = "legacy_va_layout",
994 .data = &sysctl_legacy_va_layout,
995 .maxlen = sizeof(sysctl_legacy_va_layout),
997 .proc_handler = &proc_dointvec,
998 .strategy = &sysctl_intvec,
1004 .ctl_name = VM_ZONE_RECLAIM_MODE,
1005 .procname = "zone_reclaim_mode",
1006 .data = &zone_reclaim_mode,
1007 .maxlen = sizeof(zone_reclaim_mode),
1009 .proc_handler = &proc_dointvec,
1010 .strategy = &sysctl_intvec,
1014 .ctl_name = VM_MIN_UNMAPPED,
1015 .procname = "min_unmapped_ratio",
1016 .data = &sysctl_min_unmapped_ratio,
1017 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1019 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1022 .extra2 = &one_hundred,
1025 .ctl_name = VM_MIN_SLAB,
1026 .procname = "min_slab_ratio",
1027 .data = &sysctl_min_slab_ratio,
1028 .maxlen = sizeof(sysctl_min_slab_ratio),
1030 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1031 .strategy = &sysctl_intvec,
1033 .extra2 = &one_hundred,
1038 .ctl_name = CTL_UNNUMBERED,
1039 .procname = "stat_interval",
1040 .data = &sysctl_stat_interval,
1041 .maxlen = sizeof(sysctl_stat_interval),
1043 .proc_handler = &proc_dointvec_jiffies,
1044 .strategy = &sysctl_jiffies,
1047 #ifdef CONFIG_SECURITY
1049 .ctl_name = CTL_UNNUMBERED,
1050 .procname = "mmap_min_addr",
1051 .data = &mmap_min_addr,
1052 .maxlen = sizeof(unsigned long),
1054 .proc_handler = &proc_doulongvec_minmax,
1059 .ctl_name = CTL_UNNUMBERED,
1060 .procname = "numa_zonelist_order",
1061 .data = &numa_zonelist_order,
1062 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1064 .proc_handler = &numa_zonelist_order_handler,
1065 .strategy = &sysctl_string,
1068 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1069 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1071 .ctl_name = VM_VDSO_ENABLED,
1072 .procname = "vdso_enabled",
1073 .data = &vdso_enabled,
1074 .maxlen = sizeof(vdso_enabled),
1076 .proc_handler = &proc_dointvec,
1077 .strategy = &sysctl_intvec,
1082 * NOTE: do not add new entries to this table unless you have read
1083 * Documentation/sysctl/ctl_unnumbered.txt
1088 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1089 static struct ctl_table binfmt_misc_table[] = {
1094 static struct ctl_table fs_table[] = {
1096 .ctl_name = FS_NRINODE,
1097 .procname = "inode-nr",
1098 .data = &inodes_stat,
1099 .maxlen = 2*sizeof(int),
1101 .proc_handler = &proc_dointvec,
1104 .ctl_name = FS_STATINODE,
1105 .procname = "inode-state",
1106 .data = &inodes_stat,
1107 .maxlen = 7*sizeof(int),
1109 .proc_handler = &proc_dointvec,
1112 .procname = "file-nr",
1113 .data = &files_stat,
1114 .maxlen = 3*sizeof(int),
1116 .proc_handler = &proc_nr_files,
1119 .ctl_name = FS_MAXFILE,
1120 .procname = "file-max",
1121 .data = &files_stat.max_files,
1122 .maxlen = sizeof(int),
1124 .proc_handler = &proc_dointvec,
1127 .ctl_name = FS_DENTRY,
1128 .procname = "dentry-state",
1129 .data = &dentry_stat,
1130 .maxlen = 6*sizeof(int),
1132 .proc_handler = &proc_dointvec,
1135 .ctl_name = FS_OVERFLOWUID,
1136 .procname = "overflowuid",
1137 .data = &fs_overflowuid,
1138 .maxlen = sizeof(int),
1140 .proc_handler = &proc_dointvec_minmax,
1141 .strategy = &sysctl_intvec,
1142 .extra1 = &minolduid,
1143 .extra2 = &maxolduid,
1146 .ctl_name = FS_OVERFLOWGID,
1147 .procname = "overflowgid",
1148 .data = &fs_overflowgid,
1149 .maxlen = sizeof(int),
1151 .proc_handler = &proc_dointvec_minmax,
1152 .strategy = &sysctl_intvec,
1153 .extra1 = &minolduid,
1154 .extra2 = &maxolduid,
1157 .ctl_name = FS_LEASES,
1158 .procname = "leases-enable",
1159 .data = &leases_enable,
1160 .maxlen = sizeof(int),
1162 .proc_handler = &proc_dointvec,
1164 #ifdef CONFIG_DNOTIFY
1166 .ctl_name = FS_DIR_NOTIFY,
1167 .procname = "dir-notify-enable",
1168 .data = &dir_notify_enable,
1169 .maxlen = sizeof(int),
1171 .proc_handler = &proc_dointvec,
1176 .ctl_name = FS_LEASE_TIME,
1177 .procname = "lease-break-time",
1178 .data = &lease_break_time,
1179 .maxlen = sizeof(int),
1181 .proc_handler = &proc_dointvec_minmax,
1182 .strategy = &sysctl_intvec,
1187 .procname = "aio-nr",
1189 .maxlen = sizeof(aio_nr),
1191 .proc_handler = &proc_doulongvec_minmax,
1194 .procname = "aio-max-nr",
1195 .data = &aio_max_nr,
1196 .maxlen = sizeof(aio_max_nr),
1198 .proc_handler = &proc_doulongvec_minmax,
1200 #ifdef CONFIG_INOTIFY_USER
1202 .ctl_name = FS_INOTIFY,
1203 .procname = "inotify",
1205 .child = inotify_table,
1210 .ctl_name = KERN_SETUID_DUMPABLE,
1211 .procname = "suid_dumpable",
1212 .data = &suid_dumpable,
1213 .maxlen = sizeof(int),
1215 .proc_handler = &proc_dointvec,
1217 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1219 .ctl_name = CTL_UNNUMBERED,
1220 .procname = "binfmt_misc",
1222 .child = binfmt_misc_table,
1226 * NOTE: do not add new entries to this table unless you have read
1227 * Documentation/sysctl/ctl_unnumbered.txt
1232 static struct ctl_table debug_table[] = {
1233 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1235 .ctl_name = CTL_UNNUMBERED,
1236 .procname = "exception-trace",
1237 .data = &show_unhandled_signals,
1238 .maxlen = sizeof(int),
1240 .proc_handler = proc_dointvec
1246 static struct ctl_table dev_table[] = {
1250 static DEFINE_SPINLOCK(sysctl_lock);
1252 /* called under sysctl_lock */
1253 static int use_table(struct ctl_table_header *p)
1255 if (unlikely(p->unregistering))
1261 /* called under sysctl_lock */
1262 static void unuse_table(struct ctl_table_header *p)
1265 if (unlikely(p->unregistering))
1266 complete(p->unregistering);
1269 /* called under sysctl_lock, will reacquire if has to wait */
1270 static void start_unregistering(struct ctl_table_header *p)
1273 * if p->used is 0, nobody will ever touch that entry again;
1274 * we'll eliminate all paths to it before dropping sysctl_lock
1276 if (unlikely(p->used)) {
1277 struct completion wait;
1278 init_completion(&wait);
1279 p->unregistering = &wait;
1280 spin_unlock(&sysctl_lock);
1281 wait_for_completion(&wait);
1282 spin_lock(&sysctl_lock);
1285 * do not remove from the list until nobody holds it; walking the
1286 * list in do_sysctl() relies on that.
1288 list_del_init(&p->ctl_entry);
1291 void sysctl_head_finish(struct ctl_table_header *head)
1295 spin_lock(&sysctl_lock);
1297 spin_unlock(&sysctl_lock);
1300 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1302 struct ctl_table_header *head;
1303 struct list_head *tmp;
1304 spin_lock(&sysctl_lock);
1306 tmp = &prev->ctl_entry;
1310 tmp = &root_table_header.ctl_entry;
1312 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1314 if (!use_table(head))
1316 spin_unlock(&sysctl_lock);
1320 if (tmp == &root_table_header.ctl_entry)
1323 spin_unlock(&sysctl_lock);
1327 #ifdef CONFIG_SYSCTL_SYSCALL
1328 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1329 void __user *newval, size_t newlen)
1331 struct ctl_table_header *head;
1332 int error = -ENOTDIR;
1334 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1338 if (!oldlenp || get_user(old_len, oldlenp))
1342 for (head = sysctl_head_next(NULL); head;
1343 head = sysctl_head_next(head)) {
1344 error = parse_table(name, nlen, oldval, oldlenp,
1345 newval, newlen, head->ctl_table);
1346 if (error != -ENOTDIR) {
1347 sysctl_head_finish(head);
1354 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1356 struct __sysctl_args tmp;
1359 if (copy_from_user(&tmp, args, sizeof(tmp)))
1363 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1364 tmp.newval, tmp.newlen);
1368 #endif /* CONFIG_SYSCTL_SYSCALL */
1371 * sysctl_perm does NOT grant the superuser all rights automatically, because
1372 * some sysctl variables are readonly even to root.
1375 static int test_perm(int mode, int op)
1379 else if (in_egroup_p(0))
1381 if ((mode & op & 0007) == op)
1386 int sysctl_perm(struct ctl_table *table, int op)
1389 error = security_sysctl(table, op);
1392 return test_perm(table->mode, op);
1395 #ifdef CONFIG_SYSCTL_SYSCALL
1396 static int parse_table(int __user *name, int nlen,
1397 void __user *oldval, size_t __user *oldlenp,
1398 void __user *newval, size_t newlen,
1399 struct ctl_table *table)
1405 if (get_user(n, name))
1407 for ( ; table->ctl_name || table->procname; table++) {
1408 if (!table->ctl_name)
1410 if (n == table->ctl_name) {
1413 if (sysctl_perm(table, 001))
1417 table = table->child;
1420 error = do_sysctl_strategy(table, name, nlen,
1429 /* Perform the actual read/write of a sysctl table entry. */
1430 int do_sysctl_strategy (struct ctl_table *table,
1431 int __user *name, int nlen,
1432 void __user *oldval, size_t __user *oldlenp,
1433 void __user *newval, size_t newlen)
1441 if (sysctl_perm(table, op))
1444 if (table->strategy) {
1445 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1453 /* If there is no strategy routine, or if the strategy returns
1454 * zero, proceed with automatic r/w */
1455 if (table->data && table->maxlen) {
1456 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1463 #endif /* CONFIG_SYSCTL_SYSCALL */
1465 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1467 for (; table->ctl_name || table->procname; table++) {
1468 table->parent = parent;
1470 sysctl_set_parent(table, table->child);
1474 static __init int sysctl_init(void)
1476 sysctl_set_parent(NULL, root_table);
1480 core_initcall(sysctl_init);
1483 * register_sysctl_table - register a sysctl hierarchy
1484 * @table: the top-level table structure
1486 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1487 * array. An entry with a ctl_name of 0 terminates the table.
1489 * The members of the &struct ctl_table structure are used as follows:
1491 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1492 * must be unique within that level of sysctl
1494 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1495 * enter a sysctl file
1497 * data - a pointer to data for use by proc_handler
1499 * maxlen - the maximum size in bytes of the data
1501 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1503 * child - a pointer to the child sysctl table if this entry is a directory, or
1506 * proc_handler - the text handler routine (described below)
1508 * strategy - the strategy routine (described below)
1510 * de - for internal use by the sysctl routines
1512 * extra1, extra2 - extra pointers usable by the proc handler routines
1514 * Leaf nodes in the sysctl tree will be represented by a single file
1515 * under /proc; non-leaf nodes will be represented by directories.
1517 * sysctl(2) can automatically manage read and write requests through
1518 * the sysctl table. The data and maxlen fields of the ctl_table
1519 * struct enable minimal validation of the values being written to be
1520 * performed, and the mode field allows minimal authentication.
1522 * More sophisticated management can be enabled by the provision of a
1523 * strategy routine with the table entry. This will be called before
1524 * any automatic read or write of the data is performed.
1526 * The strategy routine may return
1528 * < 0 - Error occurred (error is passed to user process)
1530 * 0 - OK - proceed with automatic read or write.
1532 * > 0 - OK - read or write has been done by the strategy routine, so
1533 * return immediately.
1535 * There must be a proc_handler routine for any terminal nodes
1536 * mirrored under /proc/sys (non-terminals are handled by a built-in
1537 * directory handler). Several default handlers are available to
1538 * cover common cases -
1540 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1541 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1542 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1544 * It is the handler's job to read the input buffer from user memory
1545 * and process it. The handler should return 0 on success.
1547 * This routine returns %NULL on a failure to register, and a pointer
1548 * to the table header on success.
1550 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1552 struct ctl_table_header *tmp;
1553 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1556 tmp->ctl_table = table;
1557 INIT_LIST_HEAD(&tmp->ctl_entry);
1559 tmp->unregistering = NULL;
1560 sysctl_set_parent(NULL, table);
1561 spin_lock(&sysctl_lock);
1562 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1563 spin_unlock(&sysctl_lock);
1568 * unregister_sysctl_table - unregister a sysctl table hierarchy
1569 * @header: the header returned from register_sysctl_table
1571 * Unregisters the sysctl table and all children. proc entries may not
1572 * actually be removed until they are no longer used by anyone.
1574 void unregister_sysctl_table(struct ctl_table_header * header)
1577 spin_lock(&sysctl_lock);
1578 start_unregistering(header);
1579 spin_unlock(&sysctl_lock);
1583 #else /* !CONFIG_SYSCTL */
1584 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1589 void unregister_sysctl_table(struct ctl_table_header * table)
1593 #endif /* CONFIG_SYSCTL */
1599 #ifdef CONFIG_PROC_SYSCTL
1601 static int _proc_do_string(void* data, int maxlen, int write,
1602 struct file *filp, void __user *buffer,
1603 size_t *lenp, loff_t *ppos)
1609 if (!data || !maxlen || !*lenp) {
1617 while (len < *lenp) {
1618 if (get_user(c, p++))
1620 if (c == 0 || c == '\n')
1626 if(copy_from_user(data, buffer, len))
1628 ((char *) data)[len] = 0;
1646 if(copy_to_user(buffer, data, len))
1649 if(put_user('\n', ((char __user *) buffer) + len))
1660 * proc_dostring - read a string sysctl
1661 * @table: the sysctl table
1662 * @write: %TRUE if this is a write to the sysctl file
1663 * @filp: the file structure
1664 * @buffer: the user buffer
1665 * @lenp: the size of the user buffer
1666 * @ppos: file position
1668 * Reads/writes a string from/to the user buffer. If the kernel
1669 * buffer provided is not large enough to hold the string, the
1670 * string is truncated. The copied string is %NULL-terminated.
1671 * If the string is being read by the user process, it is copied
1672 * and a newline '\n' is added. It is truncated if the buffer is
1675 * Returns 0 on success.
1677 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1678 void __user *buffer, size_t *lenp, loff_t *ppos)
1680 return _proc_do_string(table->data, table->maxlen, write, filp,
1681 buffer, lenp, ppos);
1685 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1687 int write, void *data)
1690 *valp = *negp ? -*lvalp : *lvalp;
1695 *lvalp = (unsigned long)-val;
1698 *lvalp = (unsigned long)val;
1704 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1705 int write, struct file *filp, void __user *buffer,
1706 size_t *lenp, loff_t *ppos,
1707 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1708 int write, void *data),
1711 #define TMPBUFLEN 21
1712 int *i, vleft, first=1, neg, val;
1716 char buf[TMPBUFLEN], *p;
1717 char __user *s = buffer;
1719 if (!tbl_data || !table->maxlen || !*lenp ||
1720 (*ppos && !write)) {
1725 i = (int *) tbl_data;
1726 vleft = table->maxlen / sizeof(*i);
1730 conv = do_proc_dointvec_conv;
1732 for (; left && vleft--; i++, first=0) {
1747 if (len > sizeof(buf) - 1)
1748 len = sizeof(buf) - 1;
1749 if (copy_from_user(buf, s, len))
1753 if (*p == '-' && left > 1) {
1757 if (*p < '0' || *p > '9')
1760 lval = simple_strtoul(p, &p, 0);
1763 if ((len < left) && *p && !isspace(*p))
1770 if (conv(&neg, &lval, i, 1, data))
1777 if (conv(&neg, &lval, i, 0, data))
1780 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1784 if(copy_to_user(s, buf, len))
1791 if (!write && !first && left) {
1792 if(put_user('\n', s))
1799 if (get_user(c, s++))
1814 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1815 void __user *buffer, size_t *lenp, loff_t *ppos,
1816 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1817 int write, void *data),
1820 return __do_proc_dointvec(table->data, table, write, filp,
1821 buffer, lenp, ppos, conv, data);
1825 * proc_dointvec - read a vector of integers
1826 * @table: the sysctl table
1827 * @write: %TRUE if this is a write to the sysctl file
1828 * @filp: the file structure
1829 * @buffer: the user buffer
1830 * @lenp: the size of the user buffer
1831 * @ppos: file position
1833 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1834 * values from/to the user buffer, treated as an ASCII string.
1836 * Returns 0 on success.
1838 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1839 void __user *buffer, size_t *lenp, loff_t *ppos)
1841 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1849 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1851 int write, void *data)
1853 int op = *(int *)data;
1855 int val = *negp ? -*lvalp : *lvalp;
1857 case OP_SET: *valp = val; break;
1858 case OP_AND: *valp &= val; break;
1859 case OP_OR: *valp |= val; break;
1865 *lvalp = (unsigned long)-val;
1868 *lvalp = (unsigned long)val;
1875 * init may raise the set.
1878 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1879 void __user *buffer, size_t *lenp, loff_t *ppos)
1883 if (write && !capable(CAP_SYS_MODULE)) {
1887 op = is_init(current) ? OP_SET : OP_AND;
1888 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1889 do_proc_dointvec_bset_conv,&op);
1893 * Taint values can only be increased
1895 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1896 void __user *buffer, size_t *lenp, loff_t *ppos)
1900 if (write && !capable(CAP_SYS_ADMIN))
1904 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1905 do_proc_dointvec_bset_conv,&op);
1908 struct do_proc_dointvec_minmax_conv_param {
1913 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1915 int write, void *data)
1917 struct do_proc_dointvec_minmax_conv_param *param = data;
1919 int val = *negp ? -*lvalp : *lvalp;
1920 if ((param->min && *param->min > val) ||
1921 (param->max && *param->max < val))
1928 *lvalp = (unsigned long)-val;
1931 *lvalp = (unsigned long)val;
1938 * proc_dointvec_minmax - read a vector of integers with min/max values
1939 * @table: the sysctl table
1940 * @write: %TRUE if this is a write to the sysctl file
1941 * @filp: the file structure
1942 * @buffer: the user buffer
1943 * @lenp: the size of the user buffer
1944 * @ppos: file position
1946 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1947 * values from/to the user buffer, treated as an ASCII string.
1949 * This routine will ensure the values are within the range specified by
1950 * table->extra1 (min) and table->extra2 (max).
1952 * Returns 0 on success.
1954 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1955 void __user *buffer, size_t *lenp, loff_t *ppos)
1957 struct do_proc_dointvec_minmax_conv_param param = {
1958 .min = (int *) table->extra1,
1959 .max = (int *) table->extra2,
1961 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1962 do_proc_dointvec_minmax_conv, ¶m);
1965 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1967 void __user *buffer,
1968 size_t *lenp, loff_t *ppos,
1969 unsigned long convmul,
1970 unsigned long convdiv)
1972 #define TMPBUFLEN 21
1973 unsigned long *i, *min, *max, val;
1974 int vleft, first=1, neg;
1976 char buf[TMPBUFLEN], *p;
1977 char __user *s = buffer;
1979 if (!data || !table->maxlen || !*lenp ||
1980 (*ppos && !write)) {
1985 i = (unsigned long *) data;
1986 min = (unsigned long *) table->extra1;
1987 max = (unsigned long *) table->extra2;
1988 vleft = table->maxlen / sizeof(unsigned long);
1991 for (; left && vleft--; i++, min++, max++, first=0) {
2006 if (len > TMPBUFLEN-1)
2008 if (copy_from_user(buf, s, len))
2012 if (*p == '-' && left > 1) {
2016 if (*p < '0' || *p > '9')
2018 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2020 if ((len < left) && *p && !isspace(*p))
2029 if ((min && val < *min) || (max && val > *max))
2036 sprintf(p, "%lu", convdiv * (*i) / convmul);
2040 if(copy_to_user(s, buf, len))
2047 if (!write && !first && left) {
2048 if(put_user('\n', s))
2055 if (get_user(c, s++))
2070 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2072 void __user *buffer,
2073 size_t *lenp, loff_t *ppos,
2074 unsigned long convmul,
2075 unsigned long convdiv)
2077 return __do_proc_doulongvec_minmax(table->data, table, write,
2078 filp, buffer, lenp, ppos, convmul, convdiv);
2082 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2083 * @table: the sysctl table
2084 * @write: %TRUE if this is a write to the sysctl file
2085 * @filp: the file structure
2086 * @buffer: the user buffer
2087 * @lenp: the size of the user buffer
2088 * @ppos: file position
2090 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2091 * values from/to the user buffer, treated as an ASCII string.
2093 * This routine will ensure the values are within the range specified by
2094 * table->extra1 (min) and table->extra2 (max).
2096 * Returns 0 on success.
2098 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2099 void __user *buffer, size_t *lenp, loff_t *ppos)
2101 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2105 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2106 * @table: the sysctl table
2107 * @write: %TRUE if this is a write to the sysctl file
2108 * @filp: the file structure
2109 * @buffer: the user buffer
2110 * @lenp: the size of the user buffer
2111 * @ppos: file position
2113 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2114 * values from/to the user buffer, treated as an ASCII string. The values
2115 * are treated as milliseconds, and converted to jiffies when they are stored.
2117 * This routine will ensure the values are within the range specified by
2118 * table->extra1 (min) and table->extra2 (max).
2120 * Returns 0 on success.
2122 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2124 void __user *buffer,
2125 size_t *lenp, loff_t *ppos)
2127 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2128 lenp, ppos, HZ, 1000l);
2132 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2134 int write, void *data)
2137 if (*lvalp > LONG_MAX / HZ)
2139 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2145 lval = (unsigned long)-val;
2148 lval = (unsigned long)val;
2155 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2157 int write, void *data)
2160 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2162 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2168 lval = (unsigned long)-val;
2171 lval = (unsigned long)val;
2173 *lvalp = jiffies_to_clock_t(lval);
2178 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2180 int write, void *data)
2183 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2189 lval = (unsigned long)-val;
2192 lval = (unsigned long)val;
2194 *lvalp = jiffies_to_msecs(lval);
2200 * proc_dointvec_jiffies - read a vector of integers as seconds
2201 * @table: the sysctl table
2202 * @write: %TRUE if this is a write to the sysctl file
2203 * @filp: the file structure
2204 * @buffer: the user buffer
2205 * @lenp: the size of the user buffer
2206 * @ppos: file position
2208 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2209 * values from/to the user buffer, treated as an ASCII string.
2210 * The values read are assumed to be in seconds, and are converted into
2213 * Returns 0 on success.
2215 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2216 void __user *buffer, size_t *lenp, loff_t *ppos)
2218 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2219 do_proc_dointvec_jiffies_conv,NULL);
2223 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2224 * @table: the sysctl table
2225 * @write: %TRUE if this is a write to the sysctl file
2226 * @filp: the file structure
2227 * @buffer: the user buffer
2228 * @lenp: the size of the user buffer
2229 * @ppos: pointer to the file position
2231 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2232 * values from/to the user buffer, treated as an ASCII string.
2233 * The values read are assumed to be in 1/USER_HZ seconds, and
2234 * are converted into jiffies.
2236 * Returns 0 on success.
2238 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2239 void __user *buffer, size_t *lenp, loff_t *ppos)
2241 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2242 do_proc_dointvec_userhz_jiffies_conv,NULL);
2246 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2247 * @table: the sysctl table
2248 * @write: %TRUE if this is a write to the sysctl file
2249 * @filp: the file structure
2250 * @buffer: the user buffer
2251 * @lenp: the size of the user buffer
2252 * @ppos: file position
2253 * @ppos: the current position in the file
2255 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2256 * values from/to the user buffer, treated as an ASCII string.
2257 * The values read are assumed to be in 1/1000 seconds, and
2258 * are converted into jiffies.
2260 * Returns 0 on success.
2262 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2263 void __user *buffer, size_t *lenp, loff_t *ppos)
2265 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2266 do_proc_dointvec_ms_jiffies_conv, NULL);
2269 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2270 void __user *buffer, size_t *lenp, loff_t *ppos)
2272 struct pid *new_pid;
2276 tmp = pid_nr(cad_pid);
2278 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2279 lenp, ppos, NULL, NULL);
2283 new_pid = find_get_pid(tmp);
2287 put_pid(xchg(&cad_pid, new_pid));
2291 #else /* CONFIG_PROC_FS */
2293 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2299 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2300 void __user *buffer, size_t *lenp, loff_t *ppos)
2305 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2306 void __user *buffer, size_t *lenp, loff_t *ppos)
2311 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2312 void __user *buffer, size_t *lenp, loff_t *ppos)
2317 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2318 void __user *buffer, size_t *lenp, loff_t *ppos)
2323 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2324 void __user *buffer, size_t *lenp, loff_t *ppos)
2329 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2330 void __user *buffer, size_t *lenp, loff_t *ppos)
2335 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2336 void __user *buffer, size_t *lenp, loff_t *ppos)
2341 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2343 void __user *buffer,
2344 size_t *lenp, loff_t *ppos)
2350 #endif /* CONFIG_PROC_FS */
2353 #ifdef CONFIG_SYSCTL_SYSCALL
2355 * General sysctl support routines
2358 /* The generic sysctl data routine (used if no strategy routine supplied) */
2359 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2360 void __user *oldval, size_t __user *oldlenp,
2361 void __user *newval, size_t newlen)
2365 /* Get out of I don't have a variable */
2366 if (!table->data || !table->maxlen)
2369 if (oldval && oldlenp) {
2370 if (get_user(len, oldlenp))
2373 if (len > table->maxlen)
2374 len = table->maxlen;
2375 if (copy_to_user(oldval, table->data, len))
2377 if (put_user(len, oldlenp))
2382 if (newval && newlen) {
2383 if (newlen > table->maxlen)
2384 newlen = table->maxlen;
2386 if (copy_from_user(table->data, newval, newlen))
2392 /* The generic string strategy routine: */
2393 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2394 void __user *oldval, size_t __user *oldlenp,
2395 void __user *newval, size_t newlen)
2397 if (!table->data || !table->maxlen)
2400 if (oldval && oldlenp) {
2402 if (get_user(bufsize, oldlenp))
2405 size_t len = strlen(table->data), copied;
2407 /* This shouldn't trigger for a well-formed sysctl */
2408 if (len > table->maxlen)
2409 len = table->maxlen;
2411 /* Copy up to a max of bufsize-1 bytes of the string */
2412 copied = (len >= bufsize) ? bufsize - 1 : len;
2414 if (copy_to_user(oldval, table->data, copied) ||
2415 put_user(0, (char __user *)(oldval + copied)))
2417 if (put_user(len, oldlenp))
2421 if (newval && newlen) {
2422 size_t len = newlen;
2423 if (len > table->maxlen)
2424 len = table->maxlen;
2425 if(copy_from_user(table->data, newval, len))
2427 if (len == table->maxlen)
2429 ((char *) table->data)[len] = 0;
2435 * This function makes sure that all of the integers in the vector
2436 * are between the minimum and maximum values given in the arrays
2437 * table->extra1 and table->extra2, respectively.
2439 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2440 void __user *oldval, size_t __user *oldlenp,
2441 void __user *newval, size_t newlen)
2444 if (newval && newlen) {
2445 int __user *vec = (int __user *) newval;
2446 int *min = (int *) table->extra1;
2447 int *max = (int *) table->extra2;
2451 if (newlen % sizeof(int) != 0)
2454 if (!table->extra1 && !table->extra2)
2457 if (newlen > table->maxlen)
2458 newlen = table->maxlen;
2459 length = newlen / sizeof(int);
2461 for (i = 0; i < length; i++) {
2463 if (get_user(value, vec + i))
2465 if (min && value < min[i])
2467 if (max && value > max[i])
2474 /* Strategy function to convert jiffies to seconds */
2475 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2476 void __user *oldval, size_t __user *oldlenp,
2477 void __user *newval, size_t newlen)
2479 if (oldval && oldlenp) {
2482 if (get_user(olen, oldlenp))
2487 if (olen < sizeof(int))
2490 val = *(int *)(table->data) / HZ;
2491 if (put_user(val, (int __user *)oldval))
2493 if (put_user(sizeof(int), oldlenp))
2497 if (newval && newlen) {
2499 if (newlen != sizeof(int))
2501 if (get_user(new, (int __user *)newval))
2503 *(int *)(table->data) = new*HZ;
2508 /* Strategy function to convert jiffies to seconds */
2509 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2510 void __user *oldval, size_t __user *oldlenp,
2511 void __user *newval, size_t newlen)
2513 if (oldval && oldlenp) {
2516 if (get_user(olen, oldlenp))
2521 if (olen < sizeof(int))
2524 val = jiffies_to_msecs(*(int *)(table->data));
2525 if (put_user(val, (int __user *)oldval))
2527 if (put_user(sizeof(int), oldlenp))
2531 if (newval && newlen) {
2533 if (newlen != sizeof(int))
2535 if (get_user(new, (int __user *)newval))
2537 *(int *)(table->data) = msecs_to_jiffies(new);
2544 #else /* CONFIG_SYSCTL_SYSCALL */
2547 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2549 static int msg_count;
2550 struct __sysctl_args tmp;
2551 int name[CTL_MAXNAME];
2554 /* Read in the sysctl name for better debug message logging */
2555 if (copy_from_user(&tmp, args, sizeof(tmp)))
2557 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2559 for (i = 0; i < tmp.nlen; i++)
2560 if (get_user(name[i], tmp.name + i))
2563 /* Ignore accesses to kernel.version */
2564 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2567 if (msg_count < 5) {
2570 "warning: process `%s' used the removed sysctl "
2571 "system call with ", current->comm);
2572 for (i = 0; i < tmp.nlen; i++)
2573 printk("%d.", name[i]);
2580 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2581 void __user *oldval, size_t __user *oldlenp,
2582 void __user *newval, size_t newlen)
2587 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2588 void __user *oldval, size_t __user *oldlenp,
2589 void __user *newval, size_t newlen)
2594 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2595 void __user *oldval, size_t __user *oldlenp,
2596 void __user *newval, size_t newlen)
2601 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2602 void __user *oldval, size_t __user *oldlenp,
2603 void __user *newval, size_t newlen)
2608 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2609 void __user *oldval, size_t __user *oldlenp,
2610 void __user *newval, size_t newlen)
2615 #endif /* CONFIG_SYSCTL_SYSCALL */
2618 * No sense putting this after each symbol definition, twice,
2619 * exception granted :-)
2621 EXPORT_SYMBOL(proc_dointvec);
2622 EXPORT_SYMBOL(proc_dointvec_jiffies);
2623 EXPORT_SYMBOL(proc_dointvec_minmax);
2624 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2625 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2626 EXPORT_SYMBOL(proc_dostring);
2627 EXPORT_SYMBOL(proc_doulongvec_minmax);
2628 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2629 EXPORT_SYMBOL(register_sysctl_table);
2630 EXPORT_SYMBOL(sysctl_intvec);
2631 EXPORT_SYMBOL(sysctl_jiffies);
2632 EXPORT_SYMBOL(sysctl_ms_jiffies);
2633 EXPORT_SYMBOL(sysctl_string);
2634 EXPORT_SYMBOL(sysctl_data);
2635 EXPORT_SYMBOL(unregister_sysctl_table);