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 static int deprecated_sysctl_warning(struct __sysctl_args *args);
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
64 extern int print_fatal_signals;
65 extern int sysctl_overcommit_memory;
66 extern int sysctl_overcommit_ratio;
67 extern int sysctl_panic_on_oom;
68 extern int sysctl_oom_kill_allocating_task;
69 extern int max_threads;
70 extern int core_uses_pid;
71 extern int suid_dumpable;
72 extern char core_pattern[];
74 extern int min_free_kbytes;
75 extern int printk_ratelimit_jiffies;
76 extern int printk_ratelimit_burst;
77 extern int pid_max_min, pid_max_max;
78 extern int sysctl_drop_caches;
79 extern int percpu_pagelist_fraction;
80 extern int compat_log;
81 extern int maps_protect;
82 extern int sysctl_stat_interval;
83 extern int audit_argv_kb;
85 /* Constants used for minimum and maximum */
86 #ifdef CONFIG_DETECT_SOFTLOCKUP
88 static int sixty = 60;
96 static int one_hundred = 100;
98 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
99 static int maxolduid = 65535;
100 static int minolduid;
101 static int min_percpu_pagelist_fract = 8;
103 static int ngroups_max = NGROUPS_MAX;
106 extern char modprobe_path[];
108 #ifdef CONFIG_CHR_DEV_SG
109 extern int sg_big_buff;
113 extern char reboot_command [];
114 extern int stop_a_enabled;
115 extern int scons_pwroff;
119 extern int pwrsw_enabled;
120 extern int unaligned_enabled;
124 #ifdef CONFIG_MATHEMU
125 extern int sysctl_ieee_emulation_warnings;
127 extern int sysctl_userprocess_debug;
128 extern int spin_retry;
131 extern int sysctl_hz_timer;
133 #ifdef CONFIG_BSD_PROCESS_ACCT
134 extern int acct_parm[];
138 extern int no_unaligned_warning;
141 #ifdef CONFIG_RT_MUTEXES
142 extern int max_lock_depth;
145 #ifdef CONFIG_SYSCTL_SYSCALL
146 static int parse_table(int __user *, int, void __user *, size_t __user *,
147 void __user *, size_t, struct ctl_table *);
151 #ifdef CONFIG_PROC_SYSCTL
152 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
153 void __user *buffer, size_t *lenp, loff_t *ppos);
154 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
155 void __user *buffer, size_t *lenp, loff_t *ppos);
158 static struct ctl_table root_table[];
159 static struct ctl_table_header root_table_header =
160 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
162 static struct ctl_table kern_table[];
163 static struct ctl_table vm_table[];
164 static struct ctl_table fs_table[];
165 static struct ctl_table debug_table[];
166 static struct ctl_table dev_table[];
167 extern struct ctl_table random_table[];
168 #ifdef CONFIG_INOTIFY_USER
169 extern struct ctl_table inotify_table[];
172 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
173 int sysctl_legacy_va_layout;
176 extern int prove_locking;
177 extern int lock_stat;
179 /* The default sysctl tables: */
181 static struct ctl_table root_table[] = {
183 .ctl_name = CTL_KERN,
184 .procname = "kernel",
209 .ctl_name = CTL_DEBUG,
212 .child = debug_table,
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
227 #ifdef CONFIG_SCHED_DEBUG
228 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
229 static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
230 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
231 static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
234 static struct ctl_table kern_table[] = {
235 #ifdef CONFIG_SCHED_DEBUG
237 .ctl_name = CTL_UNNUMBERED,
238 .procname = "sched_nr_latency",
239 .data = &sysctl_sched_nr_latency,
240 .maxlen = sizeof(unsigned int),
242 .proc_handler = &proc_dointvec,
245 .ctl_name = CTL_UNNUMBERED,
246 .procname = "sched_latency_ns",
247 .data = &sysctl_sched_latency,
248 .maxlen = sizeof(unsigned int),
250 .proc_handler = &proc_dointvec_minmax,
251 .strategy = &sysctl_intvec,
252 .extra1 = &min_sched_granularity_ns,
253 .extra2 = &max_sched_granularity_ns,
256 .ctl_name = CTL_UNNUMBERED,
257 .procname = "sched_wakeup_granularity_ns",
258 .data = &sysctl_sched_wakeup_granularity,
259 .maxlen = sizeof(unsigned int),
261 .proc_handler = &proc_dointvec_minmax,
262 .strategy = &sysctl_intvec,
263 .extra1 = &min_wakeup_granularity_ns,
264 .extra2 = &max_wakeup_granularity_ns,
267 .ctl_name = CTL_UNNUMBERED,
268 .procname = "sched_batch_wakeup_granularity_ns",
269 .data = &sysctl_sched_batch_wakeup_granularity,
270 .maxlen = sizeof(unsigned int),
272 .proc_handler = &proc_dointvec_minmax,
273 .strategy = &sysctl_intvec,
274 .extra1 = &min_wakeup_granularity_ns,
275 .extra2 = &max_wakeup_granularity_ns,
278 .ctl_name = CTL_UNNUMBERED,
279 .procname = "sched_child_runs_first",
280 .data = &sysctl_sched_child_runs_first,
281 .maxlen = sizeof(unsigned int),
283 .proc_handler = &proc_dointvec,
286 .ctl_name = CTL_UNNUMBERED,
287 .procname = "sched_features",
288 .data = &sysctl_sched_features,
289 .maxlen = sizeof(unsigned int),
291 .proc_handler = &proc_dointvec,
294 .ctl_name = CTL_UNNUMBERED,
295 .procname = "sched_migration_cost",
296 .data = &sysctl_sched_migration_cost,
297 .maxlen = sizeof(unsigned int),
299 .proc_handler = &proc_dointvec,
303 .ctl_name = CTL_UNNUMBERED,
304 .procname = "sched_compat_yield",
305 .data = &sysctl_sched_compat_yield,
306 .maxlen = sizeof(unsigned int),
308 .proc_handler = &proc_dointvec,
310 #ifdef CONFIG_PROVE_LOCKING
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "prove_locking",
314 .data = &prove_locking,
315 .maxlen = sizeof(int),
317 .proc_handler = &proc_dointvec,
320 #ifdef CONFIG_LOCK_STAT
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "lock_stat",
325 .maxlen = sizeof(int),
327 .proc_handler = &proc_dointvec,
331 .ctl_name = KERN_PANIC,
333 .data = &panic_timeout,
334 .maxlen = sizeof(int),
336 .proc_handler = &proc_dointvec,
339 .ctl_name = KERN_CORE_USES_PID,
340 .procname = "core_uses_pid",
341 .data = &core_uses_pid,
342 .maxlen = sizeof(int),
344 .proc_handler = &proc_dointvec,
346 #ifdef CONFIG_AUDITSYSCALL
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "audit_argv_kb",
350 .data = &audit_argv_kb,
351 .maxlen = sizeof(int),
353 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_CORE_PATTERN,
358 .procname = "core_pattern",
359 .data = core_pattern,
360 .maxlen = CORENAME_MAX_SIZE,
362 .proc_handler = &proc_dostring,
363 .strategy = &sysctl_string,
365 #ifdef CONFIG_PROC_SYSCTL
367 .procname = "tainted",
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_dointvec_taint,
375 .procname = "cap-bound",
377 .maxlen = sizeof(kernel_cap_t),
379 .proc_handler = &proc_dointvec_bset,
381 #ifdef CONFIG_BLK_DEV_INITRD
383 .ctl_name = KERN_REALROOTDEV,
384 .procname = "real-root-dev",
385 .data = &real_root_dev,
386 .maxlen = sizeof(int),
388 .proc_handler = &proc_dointvec,
392 .ctl_name = CTL_UNNUMBERED,
393 .procname = "print-fatal-signals",
394 .data = &print_fatal_signals,
395 .maxlen = sizeof(int),
397 .proc_handler = &proc_dointvec,
401 .ctl_name = KERN_SPARC_REBOOT,
402 .procname = "reboot-cmd",
403 .data = reboot_command,
406 .proc_handler = &proc_dostring,
407 .strategy = &sysctl_string,
410 .ctl_name = KERN_SPARC_STOP_A,
411 .procname = "stop-a",
412 .data = &stop_a_enabled,
413 .maxlen = sizeof (int),
415 .proc_handler = &proc_dointvec,
418 .ctl_name = KERN_SPARC_SCONS_PWROFF,
419 .procname = "scons-poweroff",
420 .data = &scons_pwroff,
421 .maxlen = sizeof (int),
423 .proc_handler = &proc_dointvec,
428 .ctl_name = KERN_HPPA_PWRSW,
429 .procname = "soft-power",
430 .data = &pwrsw_enabled,
431 .maxlen = sizeof (int),
433 .proc_handler = &proc_dointvec,
436 .ctl_name = KERN_HPPA_UNALIGNED,
437 .procname = "unaligned-trap",
438 .data = &unaligned_enabled,
439 .maxlen = sizeof (int),
441 .proc_handler = &proc_dointvec,
445 .ctl_name = KERN_CTLALTDEL,
446 .procname = "ctrl-alt-del",
448 .maxlen = sizeof(int),
450 .proc_handler = &proc_dointvec,
453 .ctl_name = KERN_PRINTK,
454 .procname = "printk",
455 .data = &console_loglevel,
456 .maxlen = 4*sizeof(int),
458 .proc_handler = &proc_dointvec,
462 .ctl_name = KERN_MODPROBE,
463 .procname = "modprobe",
464 .data = &modprobe_path,
465 .maxlen = KMOD_PATH_LEN,
467 .proc_handler = &proc_dostring,
468 .strategy = &sysctl_string,
471 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
473 .ctl_name = KERN_HOTPLUG,
474 .procname = "hotplug",
475 .data = &uevent_helper,
476 .maxlen = UEVENT_HELPER_PATH_LEN,
478 .proc_handler = &proc_dostring,
479 .strategy = &sysctl_string,
482 #ifdef CONFIG_CHR_DEV_SG
484 .ctl_name = KERN_SG_BIG_BUFF,
485 .procname = "sg-big-buff",
486 .data = &sg_big_buff,
487 .maxlen = sizeof (int),
489 .proc_handler = &proc_dointvec,
492 #ifdef CONFIG_BSD_PROCESS_ACCT
494 .ctl_name = KERN_ACCT,
497 .maxlen = 3*sizeof(int),
499 .proc_handler = &proc_dointvec,
502 #ifdef CONFIG_MAGIC_SYSRQ
504 .ctl_name = KERN_SYSRQ,
506 .data = &__sysrq_enabled,
507 .maxlen = sizeof (int),
509 .proc_handler = &proc_dointvec,
512 #ifdef CONFIG_PROC_SYSCTL
514 .procname = "cad_pid",
516 .maxlen = sizeof (int),
518 .proc_handler = &proc_do_cad_pid,
522 .ctl_name = KERN_MAX_THREADS,
523 .procname = "threads-max",
524 .data = &max_threads,
525 .maxlen = sizeof(int),
527 .proc_handler = &proc_dointvec,
530 .ctl_name = KERN_RANDOM,
531 .procname = "random",
533 .child = random_table,
536 .ctl_name = KERN_OVERFLOWUID,
537 .procname = "overflowuid",
538 .data = &overflowuid,
539 .maxlen = sizeof(int),
541 .proc_handler = &proc_dointvec_minmax,
542 .strategy = &sysctl_intvec,
543 .extra1 = &minolduid,
544 .extra2 = &maxolduid,
547 .ctl_name = KERN_OVERFLOWGID,
548 .procname = "overflowgid",
549 .data = &overflowgid,
550 .maxlen = sizeof(int),
552 .proc_handler = &proc_dointvec_minmax,
553 .strategy = &sysctl_intvec,
554 .extra1 = &minolduid,
555 .extra2 = &maxolduid,
558 #ifdef CONFIG_MATHEMU
560 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
561 .procname = "ieee_emulation_warnings",
562 .data = &sysctl_ieee_emulation_warnings,
563 .maxlen = sizeof(int),
565 .proc_handler = &proc_dointvec,
568 #ifdef CONFIG_NO_IDLE_HZ
570 .ctl_name = KERN_HZ_TIMER,
571 .procname = "hz_timer",
572 .data = &sysctl_hz_timer,
573 .maxlen = sizeof(int),
575 .proc_handler = &proc_dointvec,
579 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
580 .procname = "userprocess_debug",
581 .data = &sysctl_userprocess_debug,
582 .maxlen = sizeof(int),
584 .proc_handler = &proc_dointvec,
588 .ctl_name = KERN_PIDMAX,
589 .procname = "pid_max",
591 .maxlen = sizeof (int),
593 .proc_handler = &proc_dointvec_minmax,
594 .strategy = sysctl_intvec,
595 .extra1 = &pid_max_min,
596 .extra2 = &pid_max_max,
599 .ctl_name = KERN_PANIC_ON_OOPS,
600 .procname = "panic_on_oops",
601 .data = &panic_on_oops,
602 .maxlen = sizeof(int),
604 .proc_handler = &proc_dointvec,
607 .ctl_name = KERN_PRINTK_RATELIMIT,
608 .procname = "printk_ratelimit",
609 .data = &printk_ratelimit_jiffies,
610 .maxlen = sizeof(int),
612 .proc_handler = &proc_dointvec_jiffies,
613 .strategy = &sysctl_jiffies,
616 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
617 .procname = "printk_ratelimit_burst",
618 .data = &printk_ratelimit_burst,
619 .maxlen = sizeof(int),
621 .proc_handler = &proc_dointvec,
624 .ctl_name = KERN_NGROUPS_MAX,
625 .procname = "ngroups_max",
626 .data = &ngroups_max,
627 .maxlen = sizeof (int),
629 .proc_handler = &proc_dointvec,
631 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
633 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
634 .procname = "unknown_nmi_panic",
635 .data = &unknown_nmi_panic,
636 .maxlen = sizeof (int),
638 .proc_handler = &proc_dointvec,
641 .procname = "nmi_watchdog",
642 .data = &nmi_watchdog_enabled,
643 .maxlen = sizeof (int),
645 .proc_handler = &proc_nmi_enabled,
648 #if defined(CONFIG_X86)
650 .ctl_name = KERN_PANIC_ON_NMI,
651 .procname = "panic_on_unrecovered_nmi",
652 .data = &panic_on_unrecovered_nmi,
653 .maxlen = sizeof(int),
655 .proc_handler = &proc_dointvec,
658 .ctl_name = KERN_BOOTLOADER_TYPE,
659 .procname = "bootloader_type",
660 .data = &bootloader_type,
661 .maxlen = sizeof (int),
663 .proc_handler = &proc_dointvec,
666 .ctl_name = CTL_UNNUMBERED,
667 .procname = "kstack_depth_to_print",
668 .data = &kstack_depth_to_print,
669 .maxlen = sizeof(int),
671 .proc_handler = &proc_dointvec,
674 #if defined(CONFIG_MMU)
676 .ctl_name = KERN_RANDOMIZE,
677 .procname = "randomize_va_space",
678 .data = &randomize_va_space,
679 .maxlen = sizeof(int),
681 .proc_handler = &proc_dointvec,
684 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
686 .ctl_name = KERN_SPIN_RETRY,
687 .procname = "spin_retry",
689 .maxlen = sizeof (int),
691 .proc_handler = &proc_dointvec,
694 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
696 .procname = "acpi_video_flags",
697 .data = &acpi_realmode_flags,
698 .maxlen = sizeof (unsigned long),
700 .proc_handler = &proc_doulongvec_minmax,
705 .ctl_name = KERN_IA64_UNALIGNED,
706 .procname = "ignore-unaligned-usertrap",
707 .data = &no_unaligned_warning,
708 .maxlen = sizeof (int),
710 .proc_handler = &proc_dointvec,
713 #ifdef CONFIG_DETECT_SOFTLOCKUP
715 .ctl_name = CTL_UNNUMBERED,
716 .procname = "softlockup_thresh",
717 .data = &softlockup_thresh,
718 .maxlen = sizeof(int),
720 .proc_handler = &proc_dointvec_minmax,
721 .strategy = &sysctl_intvec,
728 .ctl_name = KERN_COMPAT_LOG,
729 .procname = "compat-log",
731 .maxlen = sizeof (int),
733 .proc_handler = &proc_dointvec,
736 #ifdef CONFIG_RT_MUTEXES
738 .ctl_name = KERN_MAX_LOCK_DEPTH,
739 .procname = "max_lock_depth",
740 .data = &max_lock_depth,
741 .maxlen = sizeof(int),
743 .proc_handler = &proc_dointvec,
746 #ifdef CONFIG_PROC_FS
748 .ctl_name = CTL_UNNUMBERED,
749 .procname = "maps_protect",
750 .data = &maps_protect,
751 .maxlen = sizeof(int),
753 .proc_handler = &proc_dointvec,
757 .ctl_name = CTL_UNNUMBERED,
758 .procname = "poweroff_cmd",
759 .data = &poweroff_cmd,
760 .maxlen = POWEROFF_CMD_PATH_LEN,
762 .proc_handler = &proc_dostring,
763 .strategy = &sysctl_string,
766 * NOTE: do not add new entries to this table unless you have read
767 * Documentation/sysctl/ctl_unnumbered.txt
772 static struct ctl_table vm_table[] = {
774 .ctl_name = VM_OVERCOMMIT_MEMORY,
775 .procname = "overcommit_memory",
776 .data = &sysctl_overcommit_memory,
777 .maxlen = sizeof(sysctl_overcommit_memory),
779 .proc_handler = &proc_dointvec,
782 .ctl_name = VM_PANIC_ON_OOM,
783 .procname = "panic_on_oom",
784 .data = &sysctl_panic_on_oom,
785 .maxlen = sizeof(sysctl_panic_on_oom),
787 .proc_handler = &proc_dointvec,
790 .ctl_name = CTL_UNNUMBERED,
791 .procname = "oom_kill_allocating_task",
792 .data = &sysctl_oom_kill_allocating_task,
793 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
795 .proc_handler = &proc_dointvec,
798 .ctl_name = VM_OVERCOMMIT_RATIO,
799 .procname = "overcommit_ratio",
800 .data = &sysctl_overcommit_ratio,
801 .maxlen = sizeof(sysctl_overcommit_ratio),
803 .proc_handler = &proc_dointvec,
806 .ctl_name = VM_PAGE_CLUSTER,
807 .procname = "page-cluster",
808 .data = &page_cluster,
809 .maxlen = sizeof(int),
811 .proc_handler = &proc_dointvec,
814 .ctl_name = VM_DIRTY_BACKGROUND,
815 .procname = "dirty_background_ratio",
816 .data = &dirty_background_ratio,
817 .maxlen = sizeof(dirty_background_ratio),
819 .proc_handler = &proc_dointvec_minmax,
820 .strategy = &sysctl_intvec,
822 .extra2 = &one_hundred,
825 .ctl_name = VM_DIRTY_RATIO,
826 .procname = "dirty_ratio",
827 .data = &vm_dirty_ratio,
828 .maxlen = sizeof(vm_dirty_ratio),
830 .proc_handler = &dirty_ratio_handler,
831 .strategy = &sysctl_intvec,
833 .extra2 = &one_hundred,
836 .procname = "dirty_writeback_centisecs",
837 .data = &dirty_writeback_interval,
838 .maxlen = sizeof(dirty_writeback_interval),
840 .proc_handler = &dirty_writeback_centisecs_handler,
843 .procname = "dirty_expire_centisecs",
844 .data = &dirty_expire_interval,
845 .maxlen = sizeof(dirty_expire_interval),
847 .proc_handler = &proc_dointvec_userhz_jiffies,
850 .ctl_name = VM_NR_PDFLUSH_THREADS,
851 .procname = "nr_pdflush_threads",
852 .data = &nr_pdflush_threads,
853 .maxlen = sizeof nr_pdflush_threads,
854 .mode = 0444 /* read-only*/,
855 .proc_handler = &proc_dointvec,
858 .ctl_name = VM_SWAPPINESS,
859 .procname = "swappiness",
860 .data = &vm_swappiness,
861 .maxlen = sizeof(vm_swappiness),
863 .proc_handler = &proc_dointvec_minmax,
864 .strategy = &sysctl_intvec,
866 .extra2 = &one_hundred,
868 #ifdef CONFIG_HUGETLB_PAGE
870 .procname = "nr_hugepages",
871 .data = &max_huge_pages,
872 .maxlen = sizeof(unsigned long),
874 .proc_handler = &hugetlb_sysctl_handler,
875 .extra1 = (void *)&hugetlb_zero,
876 .extra2 = (void *)&hugetlb_infinity,
879 .ctl_name = VM_HUGETLB_GROUP,
880 .procname = "hugetlb_shm_group",
881 .data = &sysctl_hugetlb_shm_group,
882 .maxlen = sizeof(gid_t),
884 .proc_handler = &proc_dointvec,
887 .ctl_name = CTL_UNNUMBERED,
888 .procname = "hugepages_treat_as_movable",
889 .data = &hugepages_treat_as_movable,
890 .maxlen = sizeof(int),
892 .proc_handler = &hugetlb_treat_movable_handler,
895 .ctl_name = CTL_UNNUMBERED,
896 .procname = "hugetlb_dynamic_pool",
897 .data = &hugetlb_dynamic_pool,
898 .maxlen = sizeof(hugetlb_dynamic_pool),
900 .proc_handler = &proc_dointvec,
904 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
905 .procname = "lowmem_reserve_ratio",
906 .data = &sysctl_lowmem_reserve_ratio,
907 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
909 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
910 .strategy = &sysctl_intvec,
913 .ctl_name = VM_DROP_PAGECACHE,
914 .procname = "drop_caches",
915 .data = &sysctl_drop_caches,
916 .maxlen = sizeof(int),
918 .proc_handler = drop_caches_sysctl_handler,
919 .strategy = &sysctl_intvec,
922 .ctl_name = VM_MIN_FREE_KBYTES,
923 .procname = "min_free_kbytes",
924 .data = &min_free_kbytes,
925 .maxlen = sizeof(min_free_kbytes),
927 .proc_handler = &min_free_kbytes_sysctl_handler,
928 .strategy = &sysctl_intvec,
932 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
933 .procname = "percpu_pagelist_fraction",
934 .data = &percpu_pagelist_fraction,
935 .maxlen = sizeof(percpu_pagelist_fraction),
937 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
938 .strategy = &sysctl_intvec,
939 .extra1 = &min_percpu_pagelist_fract,
943 .ctl_name = VM_MAX_MAP_COUNT,
944 .procname = "max_map_count",
945 .data = &sysctl_max_map_count,
946 .maxlen = sizeof(sysctl_max_map_count),
948 .proc_handler = &proc_dointvec
952 .ctl_name = VM_LAPTOP_MODE,
953 .procname = "laptop_mode",
954 .data = &laptop_mode,
955 .maxlen = sizeof(laptop_mode),
957 .proc_handler = &proc_dointvec_jiffies,
958 .strategy = &sysctl_jiffies,
961 .ctl_name = VM_BLOCK_DUMP,
962 .procname = "block_dump",
964 .maxlen = sizeof(block_dump),
966 .proc_handler = &proc_dointvec,
967 .strategy = &sysctl_intvec,
971 .ctl_name = VM_VFS_CACHE_PRESSURE,
972 .procname = "vfs_cache_pressure",
973 .data = &sysctl_vfs_cache_pressure,
974 .maxlen = sizeof(sysctl_vfs_cache_pressure),
976 .proc_handler = &proc_dointvec,
977 .strategy = &sysctl_intvec,
980 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
982 .ctl_name = VM_LEGACY_VA_LAYOUT,
983 .procname = "legacy_va_layout",
984 .data = &sysctl_legacy_va_layout,
985 .maxlen = sizeof(sysctl_legacy_va_layout),
987 .proc_handler = &proc_dointvec,
988 .strategy = &sysctl_intvec,
994 .ctl_name = VM_ZONE_RECLAIM_MODE,
995 .procname = "zone_reclaim_mode",
996 .data = &zone_reclaim_mode,
997 .maxlen = sizeof(zone_reclaim_mode),
999 .proc_handler = &proc_dointvec,
1000 .strategy = &sysctl_intvec,
1004 .ctl_name = VM_MIN_UNMAPPED,
1005 .procname = "min_unmapped_ratio",
1006 .data = &sysctl_min_unmapped_ratio,
1007 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1009 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1010 .strategy = &sysctl_intvec,
1012 .extra2 = &one_hundred,
1015 .ctl_name = VM_MIN_SLAB,
1016 .procname = "min_slab_ratio",
1017 .data = &sysctl_min_slab_ratio,
1018 .maxlen = sizeof(sysctl_min_slab_ratio),
1020 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1021 .strategy = &sysctl_intvec,
1023 .extra2 = &one_hundred,
1028 .ctl_name = CTL_UNNUMBERED,
1029 .procname = "stat_interval",
1030 .data = &sysctl_stat_interval,
1031 .maxlen = sizeof(sysctl_stat_interval),
1033 .proc_handler = &proc_dointvec_jiffies,
1034 .strategy = &sysctl_jiffies,
1037 #ifdef CONFIG_SECURITY
1039 .ctl_name = CTL_UNNUMBERED,
1040 .procname = "mmap_min_addr",
1041 .data = &mmap_min_addr,
1042 .maxlen = sizeof(unsigned long),
1044 .proc_handler = &proc_doulongvec_minmax,
1049 .ctl_name = CTL_UNNUMBERED,
1050 .procname = "numa_zonelist_order",
1051 .data = &numa_zonelist_order,
1052 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1054 .proc_handler = &numa_zonelist_order_handler,
1055 .strategy = &sysctl_string,
1058 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1059 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1061 .ctl_name = VM_VDSO_ENABLED,
1062 .procname = "vdso_enabled",
1063 .data = &vdso_enabled,
1064 .maxlen = sizeof(vdso_enabled),
1066 .proc_handler = &proc_dointvec,
1067 .strategy = &sysctl_intvec,
1072 * NOTE: do not add new entries to this table unless you have read
1073 * Documentation/sysctl/ctl_unnumbered.txt
1078 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1079 static struct ctl_table binfmt_misc_table[] = {
1084 static struct ctl_table fs_table[] = {
1086 .ctl_name = FS_NRINODE,
1087 .procname = "inode-nr",
1088 .data = &inodes_stat,
1089 .maxlen = 2*sizeof(int),
1091 .proc_handler = &proc_dointvec,
1094 .ctl_name = FS_STATINODE,
1095 .procname = "inode-state",
1096 .data = &inodes_stat,
1097 .maxlen = 7*sizeof(int),
1099 .proc_handler = &proc_dointvec,
1102 .procname = "file-nr",
1103 .data = &files_stat,
1104 .maxlen = 3*sizeof(int),
1106 .proc_handler = &proc_nr_files,
1109 .ctl_name = FS_MAXFILE,
1110 .procname = "file-max",
1111 .data = &files_stat.max_files,
1112 .maxlen = sizeof(int),
1114 .proc_handler = &proc_dointvec,
1117 .ctl_name = FS_DENTRY,
1118 .procname = "dentry-state",
1119 .data = &dentry_stat,
1120 .maxlen = 6*sizeof(int),
1122 .proc_handler = &proc_dointvec,
1125 .ctl_name = FS_OVERFLOWUID,
1126 .procname = "overflowuid",
1127 .data = &fs_overflowuid,
1128 .maxlen = sizeof(int),
1130 .proc_handler = &proc_dointvec_minmax,
1131 .strategy = &sysctl_intvec,
1132 .extra1 = &minolduid,
1133 .extra2 = &maxolduid,
1136 .ctl_name = FS_OVERFLOWGID,
1137 .procname = "overflowgid",
1138 .data = &fs_overflowgid,
1139 .maxlen = sizeof(int),
1141 .proc_handler = &proc_dointvec_minmax,
1142 .strategy = &sysctl_intvec,
1143 .extra1 = &minolduid,
1144 .extra2 = &maxolduid,
1147 .ctl_name = FS_LEASES,
1148 .procname = "leases-enable",
1149 .data = &leases_enable,
1150 .maxlen = sizeof(int),
1152 .proc_handler = &proc_dointvec,
1154 #ifdef CONFIG_DNOTIFY
1156 .ctl_name = FS_DIR_NOTIFY,
1157 .procname = "dir-notify-enable",
1158 .data = &dir_notify_enable,
1159 .maxlen = sizeof(int),
1161 .proc_handler = &proc_dointvec,
1166 .ctl_name = FS_LEASE_TIME,
1167 .procname = "lease-break-time",
1168 .data = &lease_break_time,
1169 .maxlen = sizeof(int),
1171 .proc_handler = &proc_dointvec_minmax,
1172 .strategy = &sysctl_intvec,
1177 .procname = "aio-nr",
1179 .maxlen = sizeof(aio_nr),
1181 .proc_handler = &proc_doulongvec_minmax,
1184 .procname = "aio-max-nr",
1185 .data = &aio_max_nr,
1186 .maxlen = sizeof(aio_max_nr),
1188 .proc_handler = &proc_doulongvec_minmax,
1190 #ifdef CONFIG_INOTIFY_USER
1192 .ctl_name = FS_INOTIFY,
1193 .procname = "inotify",
1195 .child = inotify_table,
1200 .ctl_name = KERN_SETUID_DUMPABLE,
1201 .procname = "suid_dumpable",
1202 .data = &suid_dumpable,
1203 .maxlen = sizeof(int),
1205 .proc_handler = &proc_dointvec,
1207 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1209 .ctl_name = CTL_UNNUMBERED,
1210 .procname = "binfmt_misc",
1212 .child = binfmt_misc_table,
1216 * NOTE: do not add new entries to this table unless you have read
1217 * Documentation/sysctl/ctl_unnumbered.txt
1222 static struct ctl_table debug_table[] = {
1223 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1225 .ctl_name = CTL_UNNUMBERED,
1226 .procname = "exception-trace",
1227 .data = &show_unhandled_signals,
1228 .maxlen = sizeof(int),
1230 .proc_handler = proc_dointvec
1236 static struct ctl_table dev_table[] = {
1240 static DEFINE_SPINLOCK(sysctl_lock);
1242 /* called under sysctl_lock */
1243 static int use_table(struct ctl_table_header *p)
1245 if (unlikely(p->unregistering))
1251 /* called under sysctl_lock */
1252 static void unuse_table(struct ctl_table_header *p)
1255 if (unlikely(p->unregistering))
1256 complete(p->unregistering);
1259 /* called under sysctl_lock, will reacquire if has to wait */
1260 static void start_unregistering(struct ctl_table_header *p)
1263 * if p->used is 0, nobody will ever touch that entry again;
1264 * we'll eliminate all paths to it before dropping sysctl_lock
1266 if (unlikely(p->used)) {
1267 struct completion wait;
1268 init_completion(&wait);
1269 p->unregistering = &wait;
1270 spin_unlock(&sysctl_lock);
1271 wait_for_completion(&wait);
1272 spin_lock(&sysctl_lock);
1275 * do not remove from the list until nobody holds it; walking the
1276 * list in do_sysctl() relies on that.
1278 list_del_init(&p->ctl_entry);
1281 void sysctl_head_finish(struct ctl_table_header *head)
1285 spin_lock(&sysctl_lock);
1287 spin_unlock(&sysctl_lock);
1290 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1292 struct ctl_table_header *head;
1293 struct list_head *tmp;
1294 spin_lock(&sysctl_lock);
1296 tmp = &prev->ctl_entry;
1300 tmp = &root_table_header.ctl_entry;
1302 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1304 if (!use_table(head))
1306 spin_unlock(&sysctl_lock);
1310 if (tmp == &root_table_header.ctl_entry)
1313 spin_unlock(&sysctl_lock);
1317 #ifdef CONFIG_SYSCTL_SYSCALL
1318 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1319 void __user *newval, size_t newlen)
1321 struct ctl_table_header *head;
1322 int error = -ENOTDIR;
1324 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1328 if (!oldlenp || get_user(old_len, oldlenp))
1332 for (head = sysctl_head_next(NULL); head;
1333 head = sysctl_head_next(head)) {
1334 error = parse_table(name, nlen, oldval, oldlenp,
1335 newval, newlen, head->ctl_table);
1336 if (error != -ENOTDIR) {
1337 sysctl_head_finish(head);
1344 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1346 struct __sysctl_args tmp;
1349 if (copy_from_user(&tmp, args, sizeof(tmp)))
1352 error = deprecated_sysctl_warning(&tmp);
1357 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1358 tmp.newval, tmp.newlen);
1363 #endif /* CONFIG_SYSCTL_SYSCALL */
1366 * sysctl_perm does NOT grant the superuser all rights automatically, because
1367 * some sysctl variables are readonly even to root.
1370 static int test_perm(int mode, int op)
1374 else if (in_egroup_p(0))
1376 if ((mode & op & 0007) == op)
1381 int sysctl_perm(struct ctl_table *table, int op)
1384 error = security_sysctl(table, op);
1387 return test_perm(table->mode, op);
1390 #ifdef CONFIG_SYSCTL_SYSCALL
1391 static int parse_table(int __user *name, int nlen,
1392 void __user *oldval, size_t __user *oldlenp,
1393 void __user *newval, size_t newlen,
1394 struct ctl_table *table)
1400 if (get_user(n, name))
1402 for ( ; table->ctl_name || table->procname; table++) {
1403 if (!table->ctl_name)
1405 if (n == table->ctl_name) {
1408 if (sysctl_perm(table, 001))
1412 table = table->child;
1415 error = do_sysctl_strategy(table, name, nlen,
1424 /* Perform the actual read/write of a sysctl table entry. */
1425 int do_sysctl_strategy (struct ctl_table *table,
1426 int __user *name, int nlen,
1427 void __user *oldval, size_t __user *oldlenp,
1428 void __user *newval, size_t newlen)
1436 if (sysctl_perm(table, op))
1439 if (table->strategy) {
1440 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1448 /* If there is no strategy routine, or if the strategy returns
1449 * zero, proceed with automatic r/w */
1450 if (table->data && table->maxlen) {
1451 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1458 #endif /* CONFIG_SYSCTL_SYSCALL */
1460 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1462 for (; table->ctl_name || table->procname; table++) {
1463 table->parent = parent;
1465 sysctl_set_parent(table, table->child);
1469 static __init int sysctl_init(void)
1472 sysctl_set_parent(NULL, root_table);
1473 err = sysctl_check_table(root_table);
1477 core_initcall(sysctl_init);
1480 * register_sysctl_table - register a sysctl hierarchy
1481 * @table: the top-level table structure
1483 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1484 * array. An entry with a ctl_name of 0 terminates the table.
1486 * The members of the &struct ctl_table structure are used as follows:
1488 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1489 * must be unique within that level of sysctl
1491 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1492 * enter a sysctl file
1494 * data - a pointer to data for use by proc_handler
1496 * maxlen - the maximum size in bytes of the data
1498 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1500 * child - a pointer to the child sysctl table if this entry is a directory, or
1503 * proc_handler - the text handler routine (described below)
1505 * strategy - the strategy routine (described below)
1507 * de - for internal use by the sysctl routines
1509 * extra1, extra2 - extra pointers usable by the proc handler routines
1511 * Leaf nodes in the sysctl tree will be represented by a single file
1512 * under /proc; non-leaf nodes will be represented by directories.
1514 * sysctl(2) can automatically manage read and write requests through
1515 * the sysctl table. The data and maxlen fields of the ctl_table
1516 * struct enable minimal validation of the values being written to be
1517 * performed, and the mode field allows minimal authentication.
1519 * More sophisticated management can be enabled by the provision of a
1520 * strategy routine with the table entry. This will be called before
1521 * any automatic read or write of the data is performed.
1523 * The strategy routine may return
1525 * < 0 - Error occurred (error is passed to user process)
1527 * 0 - OK - proceed with automatic read or write.
1529 * > 0 - OK - read or write has been done by the strategy routine, so
1530 * return immediately.
1532 * There must be a proc_handler routine for any terminal nodes
1533 * mirrored under /proc/sys (non-terminals are handled by a built-in
1534 * directory handler). Several default handlers are available to
1535 * cover common cases -
1537 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1538 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1539 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1541 * It is the handler's job to read the input buffer from user memory
1542 * and process it. The handler should return 0 on success.
1544 * This routine returns %NULL on a failure to register, and a pointer
1545 * to the table header on success.
1547 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1549 struct ctl_table_header *tmp;
1550 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1553 tmp->ctl_table = table;
1554 INIT_LIST_HEAD(&tmp->ctl_entry);
1556 tmp->unregistering = NULL;
1557 sysctl_set_parent(NULL, table);
1558 if (sysctl_check_table(tmp->ctl_table)) {
1562 spin_lock(&sysctl_lock);
1563 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1564 spin_unlock(&sysctl_lock);
1569 * unregister_sysctl_table - unregister a sysctl table hierarchy
1570 * @header: the header returned from register_sysctl_table
1572 * Unregisters the sysctl table and all children. proc entries may not
1573 * actually be removed until they are no longer used by anyone.
1575 void unregister_sysctl_table(struct ctl_table_header * header)
1578 spin_lock(&sysctl_lock);
1579 start_unregistering(header);
1580 spin_unlock(&sysctl_lock);
1584 #else /* !CONFIG_SYSCTL */
1585 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1590 void unregister_sysctl_table(struct ctl_table_header * table)
1594 #endif /* CONFIG_SYSCTL */
1600 #ifdef CONFIG_PROC_SYSCTL
1602 static int _proc_do_string(void* data, int maxlen, int write,
1603 struct file *filp, void __user *buffer,
1604 size_t *lenp, loff_t *ppos)
1610 if (!data || !maxlen || !*lenp) {
1618 while (len < *lenp) {
1619 if (get_user(c, p++))
1621 if (c == 0 || c == '\n')
1627 if(copy_from_user(data, buffer, len))
1629 ((char *) data)[len] = 0;
1647 if(copy_to_user(buffer, data, len))
1650 if(put_user('\n', ((char __user *) buffer) + len))
1661 * proc_dostring - read a string sysctl
1662 * @table: the sysctl table
1663 * @write: %TRUE if this is a write to the sysctl file
1664 * @filp: the file structure
1665 * @buffer: the user buffer
1666 * @lenp: the size of the user buffer
1667 * @ppos: file position
1669 * Reads/writes a string from/to the user buffer. If the kernel
1670 * buffer provided is not large enough to hold the string, the
1671 * string is truncated. The copied string is %NULL-terminated.
1672 * If the string is being read by the user process, it is copied
1673 * and a newline '\n' is added. It is truncated if the buffer is
1676 * Returns 0 on success.
1678 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1679 void __user *buffer, size_t *lenp, loff_t *ppos)
1681 return _proc_do_string(table->data, table->maxlen, write, filp,
1682 buffer, lenp, ppos);
1686 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1688 int write, void *data)
1691 *valp = *negp ? -*lvalp : *lvalp;
1696 *lvalp = (unsigned long)-val;
1699 *lvalp = (unsigned long)val;
1705 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1706 int write, struct file *filp, void __user *buffer,
1707 size_t *lenp, loff_t *ppos,
1708 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1709 int write, void *data),
1712 #define TMPBUFLEN 21
1713 int *i, vleft, first=1, neg, val;
1717 char buf[TMPBUFLEN], *p;
1718 char __user *s = buffer;
1720 if (!tbl_data || !table->maxlen || !*lenp ||
1721 (*ppos && !write)) {
1726 i = (int *) tbl_data;
1727 vleft = table->maxlen / sizeof(*i);
1731 conv = do_proc_dointvec_conv;
1733 for (; left && vleft--; i++, first=0) {
1748 if (len > sizeof(buf) - 1)
1749 len = sizeof(buf) - 1;
1750 if (copy_from_user(buf, s, len))
1754 if (*p == '-' && left > 1) {
1758 if (*p < '0' || *p > '9')
1761 lval = simple_strtoul(p, &p, 0);
1764 if ((len < left) && *p && !isspace(*p))
1771 if (conv(&neg, &lval, i, 1, data))
1778 if (conv(&neg, &lval, i, 0, data))
1781 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1785 if(copy_to_user(s, buf, len))
1792 if (!write && !first && left) {
1793 if(put_user('\n', s))
1800 if (get_user(c, s++))
1815 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1816 void __user *buffer, size_t *lenp, loff_t *ppos,
1817 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1818 int write, void *data),
1821 return __do_proc_dointvec(table->data, table, write, filp,
1822 buffer, lenp, ppos, conv, data);
1826 * proc_dointvec - read a vector of integers
1827 * @table: the sysctl table
1828 * @write: %TRUE if this is a write to the sysctl file
1829 * @filp: the file structure
1830 * @buffer: the user buffer
1831 * @lenp: the size of the user buffer
1832 * @ppos: file position
1834 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1835 * values from/to the user buffer, treated as an ASCII string.
1837 * Returns 0 on success.
1839 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1840 void __user *buffer, size_t *lenp, loff_t *ppos)
1842 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1850 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1852 int write, void *data)
1854 int op = *(int *)data;
1856 int val = *negp ? -*lvalp : *lvalp;
1858 case OP_SET: *valp = val; break;
1859 case OP_AND: *valp &= val; break;
1860 case OP_OR: *valp |= val; break;
1866 *lvalp = (unsigned long)-val;
1869 *lvalp = (unsigned long)val;
1876 * init may raise the set.
1879 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1880 void __user *buffer, size_t *lenp, loff_t *ppos)
1884 if (write && !capable(CAP_SYS_MODULE)) {
1888 op = is_init(current) ? OP_SET : OP_AND;
1889 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1890 do_proc_dointvec_bset_conv,&op);
1894 * Taint values can only be increased
1896 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1897 void __user *buffer, size_t *lenp, loff_t *ppos)
1901 if (write && !capable(CAP_SYS_ADMIN))
1905 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1906 do_proc_dointvec_bset_conv,&op);
1909 struct do_proc_dointvec_minmax_conv_param {
1914 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1916 int write, void *data)
1918 struct do_proc_dointvec_minmax_conv_param *param = data;
1920 int val = *negp ? -*lvalp : *lvalp;
1921 if ((param->min && *param->min > val) ||
1922 (param->max && *param->max < val))
1929 *lvalp = (unsigned long)-val;
1932 *lvalp = (unsigned long)val;
1939 * proc_dointvec_minmax - read a vector of integers with min/max values
1940 * @table: the sysctl table
1941 * @write: %TRUE if this is a write to the sysctl file
1942 * @filp: the file structure
1943 * @buffer: the user buffer
1944 * @lenp: the size of the user buffer
1945 * @ppos: file position
1947 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1948 * values from/to the user buffer, treated as an ASCII string.
1950 * This routine will ensure the values are within the range specified by
1951 * table->extra1 (min) and table->extra2 (max).
1953 * Returns 0 on success.
1955 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1956 void __user *buffer, size_t *lenp, loff_t *ppos)
1958 struct do_proc_dointvec_minmax_conv_param param = {
1959 .min = (int *) table->extra1,
1960 .max = (int *) table->extra2,
1962 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1963 do_proc_dointvec_minmax_conv, ¶m);
1966 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1968 void __user *buffer,
1969 size_t *lenp, loff_t *ppos,
1970 unsigned long convmul,
1971 unsigned long convdiv)
1973 #define TMPBUFLEN 21
1974 unsigned long *i, *min, *max, val;
1975 int vleft, first=1, neg;
1977 char buf[TMPBUFLEN], *p;
1978 char __user *s = buffer;
1980 if (!data || !table->maxlen || !*lenp ||
1981 (*ppos && !write)) {
1986 i = (unsigned long *) data;
1987 min = (unsigned long *) table->extra1;
1988 max = (unsigned long *) table->extra2;
1989 vleft = table->maxlen / sizeof(unsigned long);
1992 for (; left && vleft--; i++, min++, max++, first=0) {
2007 if (len > TMPBUFLEN-1)
2009 if (copy_from_user(buf, s, len))
2013 if (*p == '-' && left > 1) {
2017 if (*p < '0' || *p > '9')
2019 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2021 if ((len < left) && *p && !isspace(*p))
2030 if ((min && val < *min) || (max && val > *max))
2037 sprintf(p, "%lu", convdiv * (*i) / convmul);
2041 if(copy_to_user(s, buf, len))
2048 if (!write && !first && left) {
2049 if(put_user('\n', s))
2056 if (get_user(c, s++))
2071 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2073 void __user *buffer,
2074 size_t *lenp, loff_t *ppos,
2075 unsigned long convmul,
2076 unsigned long convdiv)
2078 return __do_proc_doulongvec_minmax(table->data, table, write,
2079 filp, buffer, lenp, ppos, convmul, convdiv);
2083 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2084 * @table: the sysctl table
2085 * @write: %TRUE if this is a write to the sysctl file
2086 * @filp: the file structure
2087 * @buffer: the user buffer
2088 * @lenp: the size of the user buffer
2089 * @ppos: file position
2091 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2092 * values from/to the user buffer, treated as an ASCII string.
2094 * This routine will ensure the values are within the range specified by
2095 * table->extra1 (min) and table->extra2 (max).
2097 * Returns 0 on success.
2099 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2100 void __user *buffer, size_t *lenp, loff_t *ppos)
2102 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2106 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2107 * @table: the sysctl table
2108 * @write: %TRUE if this is a write to the sysctl file
2109 * @filp: the file structure
2110 * @buffer: the user buffer
2111 * @lenp: the size of the user buffer
2112 * @ppos: file position
2114 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2115 * values from/to the user buffer, treated as an ASCII string. The values
2116 * are treated as milliseconds, and converted to jiffies when they are stored.
2118 * This routine will ensure the values are within the range specified by
2119 * table->extra1 (min) and table->extra2 (max).
2121 * Returns 0 on success.
2123 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2125 void __user *buffer,
2126 size_t *lenp, loff_t *ppos)
2128 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2129 lenp, ppos, HZ, 1000l);
2133 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2135 int write, void *data)
2138 if (*lvalp > LONG_MAX / HZ)
2140 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2146 lval = (unsigned long)-val;
2149 lval = (unsigned long)val;
2156 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2158 int write, void *data)
2161 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2163 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2169 lval = (unsigned long)-val;
2172 lval = (unsigned long)val;
2174 *lvalp = jiffies_to_clock_t(lval);
2179 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2181 int write, void *data)
2184 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2190 lval = (unsigned long)-val;
2193 lval = (unsigned long)val;
2195 *lvalp = jiffies_to_msecs(lval);
2201 * proc_dointvec_jiffies - read a vector of integers as seconds
2202 * @table: the sysctl table
2203 * @write: %TRUE if this is a write to the sysctl file
2204 * @filp: the file structure
2205 * @buffer: the user buffer
2206 * @lenp: the size of the user buffer
2207 * @ppos: file position
2209 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2210 * values from/to the user buffer, treated as an ASCII string.
2211 * The values read are assumed to be in seconds, and are converted into
2214 * Returns 0 on success.
2216 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2217 void __user *buffer, size_t *lenp, loff_t *ppos)
2219 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2220 do_proc_dointvec_jiffies_conv,NULL);
2224 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2225 * @table: the sysctl table
2226 * @write: %TRUE if this is a write to the sysctl file
2227 * @filp: the file structure
2228 * @buffer: the user buffer
2229 * @lenp: the size of the user buffer
2230 * @ppos: pointer to the file position
2232 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2233 * values from/to the user buffer, treated as an ASCII string.
2234 * The values read are assumed to be in 1/USER_HZ seconds, and
2235 * are converted into jiffies.
2237 * Returns 0 on success.
2239 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2240 void __user *buffer, size_t *lenp, loff_t *ppos)
2242 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2243 do_proc_dointvec_userhz_jiffies_conv,NULL);
2247 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2248 * @table: the sysctl table
2249 * @write: %TRUE if this is a write to the sysctl file
2250 * @filp: the file structure
2251 * @buffer: the user buffer
2252 * @lenp: the size of the user buffer
2253 * @ppos: file position
2254 * @ppos: the current position in the file
2256 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2257 * values from/to the user buffer, treated as an ASCII string.
2258 * The values read are assumed to be in 1/1000 seconds, and
2259 * are converted into jiffies.
2261 * Returns 0 on success.
2263 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2264 void __user *buffer, size_t *lenp, loff_t *ppos)
2266 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2267 do_proc_dointvec_ms_jiffies_conv, NULL);
2270 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2271 void __user *buffer, size_t *lenp, loff_t *ppos)
2273 struct pid *new_pid;
2277 tmp = pid_nr(cad_pid);
2279 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2280 lenp, ppos, NULL, NULL);
2284 new_pid = find_get_pid(tmp);
2288 put_pid(xchg(&cad_pid, new_pid));
2292 #else /* CONFIG_PROC_FS */
2294 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2295 void __user *buffer, size_t *lenp, loff_t *ppos)
2300 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2301 void __user *buffer, size_t *lenp, loff_t *ppos)
2306 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2307 void __user *buffer, size_t *lenp, loff_t *ppos)
2312 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2313 void __user *buffer, size_t *lenp, loff_t *ppos)
2318 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2319 void __user *buffer, size_t *lenp, loff_t *ppos)
2324 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2325 void __user *buffer, size_t *lenp, loff_t *ppos)
2330 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2331 void __user *buffer, size_t *lenp, loff_t *ppos)
2336 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2337 void __user *buffer, size_t *lenp, loff_t *ppos)
2342 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2344 void __user *buffer,
2345 size_t *lenp, loff_t *ppos)
2351 #endif /* CONFIG_PROC_FS */
2354 #ifdef CONFIG_SYSCTL_SYSCALL
2356 * General sysctl support routines
2359 /* The generic sysctl data routine (used if no strategy routine supplied) */
2360 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2361 void __user *oldval, size_t __user *oldlenp,
2362 void __user *newval, size_t newlen)
2366 /* Get out of I don't have a variable */
2367 if (!table->data || !table->maxlen)
2370 if (oldval && oldlenp) {
2371 if (get_user(len, oldlenp))
2374 if (len > table->maxlen)
2375 len = table->maxlen;
2376 if (copy_to_user(oldval, table->data, len))
2378 if (put_user(len, oldlenp))
2383 if (newval && newlen) {
2384 if (newlen > table->maxlen)
2385 newlen = table->maxlen;
2387 if (copy_from_user(table->data, newval, newlen))
2393 /* The generic string strategy routine: */
2394 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2395 void __user *oldval, size_t __user *oldlenp,
2396 void __user *newval, size_t newlen)
2398 if (!table->data || !table->maxlen)
2401 if (oldval && oldlenp) {
2403 if (get_user(bufsize, oldlenp))
2406 size_t len = strlen(table->data), copied;
2408 /* This shouldn't trigger for a well-formed sysctl */
2409 if (len > table->maxlen)
2410 len = table->maxlen;
2412 /* Copy up to a max of bufsize-1 bytes of the string */
2413 copied = (len >= bufsize) ? bufsize - 1 : len;
2415 if (copy_to_user(oldval, table->data, copied) ||
2416 put_user(0, (char __user *)(oldval + copied)))
2418 if (put_user(len, oldlenp))
2422 if (newval && newlen) {
2423 size_t len = newlen;
2424 if (len > table->maxlen)
2425 len = table->maxlen;
2426 if(copy_from_user(table->data, newval, len))
2428 if (len == table->maxlen)
2430 ((char *) table->data)[len] = 0;
2436 * This function makes sure that all of the integers in the vector
2437 * are between the minimum and maximum values given in the arrays
2438 * table->extra1 and table->extra2, respectively.
2440 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2441 void __user *oldval, size_t __user *oldlenp,
2442 void __user *newval, size_t newlen)
2445 if (newval && newlen) {
2446 int __user *vec = (int __user *) newval;
2447 int *min = (int *) table->extra1;
2448 int *max = (int *) table->extra2;
2452 if (newlen % sizeof(int) != 0)
2455 if (!table->extra1 && !table->extra2)
2458 if (newlen > table->maxlen)
2459 newlen = table->maxlen;
2460 length = newlen / sizeof(int);
2462 for (i = 0; i < length; i++) {
2464 if (get_user(value, vec + i))
2466 if (min && value < min[i])
2468 if (max && value > max[i])
2475 /* Strategy function to convert jiffies to seconds */
2476 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2477 void __user *oldval, size_t __user *oldlenp,
2478 void __user *newval, size_t newlen)
2480 if (oldval && oldlenp) {
2483 if (get_user(olen, oldlenp))
2488 if (olen < sizeof(int))
2491 val = *(int *)(table->data) / HZ;
2492 if (put_user(val, (int __user *)oldval))
2494 if (put_user(sizeof(int), oldlenp))
2498 if (newval && newlen) {
2500 if (newlen != sizeof(int))
2502 if (get_user(new, (int __user *)newval))
2504 *(int *)(table->data) = new*HZ;
2509 /* Strategy function to convert jiffies to seconds */
2510 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2511 void __user *oldval, size_t __user *oldlenp,
2512 void __user *newval, size_t newlen)
2514 if (oldval && oldlenp) {
2517 if (get_user(olen, oldlenp))
2522 if (olen < sizeof(int))
2525 val = jiffies_to_msecs(*(int *)(table->data));
2526 if (put_user(val, (int __user *)oldval))
2528 if (put_user(sizeof(int), oldlenp))
2532 if (newval && newlen) {
2534 if (newlen != sizeof(int))
2536 if (get_user(new, (int __user *)newval))
2538 *(int *)(table->data) = msecs_to_jiffies(new);
2545 #else /* CONFIG_SYSCTL_SYSCALL */
2548 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2550 struct __sysctl_args tmp;
2553 if (copy_from_user(&tmp, args, sizeof(tmp)))
2556 error = deprecated_sysctl_warning(&tmp);
2558 /* If no error reading the parameters then just -ENOSYS ... */
2565 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2566 void __user *oldval, size_t __user *oldlenp,
2567 void __user *newval, size_t newlen)
2572 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2573 void __user *oldval, size_t __user *oldlenp,
2574 void __user *newval, size_t newlen)
2579 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2580 void __user *oldval, size_t __user *oldlenp,
2581 void __user *newval, size_t newlen)
2586 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2587 void __user *oldval, size_t __user *oldlenp,
2588 void __user *newval, size_t newlen)
2593 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2594 void __user *oldval, size_t __user *oldlenp,
2595 void __user *newval, size_t newlen)
2600 #endif /* CONFIG_SYSCTL_SYSCALL */
2602 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2604 static int msg_count;
2605 int name[CTL_MAXNAME];
2608 /* Read in the sysctl name for better debug message logging */
2609 for (i = 0; i < args->nlen; i++)
2610 if (get_user(name[i], args->name + i))
2613 /* Ignore accesses to kernel.version */
2614 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2617 if (msg_count < 5) {
2620 "warning: process `%s' used the deprecated sysctl "
2621 "system call with ", current->comm);
2622 for (i = 0; i < args->nlen; i++)
2623 printk("%d.", name[i]);
2630 * No sense putting this after each symbol definition, twice,
2631 * exception granted :-)
2633 EXPORT_SYMBOL(proc_dointvec);
2634 EXPORT_SYMBOL(proc_dointvec_jiffies);
2635 EXPORT_SYMBOL(proc_dointvec_minmax);
2636 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2637 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2638 EXPORT_SYMBOL(proc_dostring);
2639 EXPORT_SYMBOL(proc_doulongvec_minmax);
2640 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2641 EXPORT_SYMBOL(register_sysctl_table);
2642 EXPORT_SYMBOL(sysctl_intvec);
2643 EXPORT_SYMBOL(sysctl_jiffies);
2644 EXPORT_SYMBOL(sysctl_ms_jiffies);
2645 EXPORT_SYMBOL(sysctl_string);
2646 EXPORT_SYMBOL(sysctl_data);
2647 EXPORT_SYMBOL(unregister_sysctl_table);