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/security.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 int min_sched_granularity_ns = 100000; /* 100 usecs */
229 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230 static int min_wakeup_granularity_ns; /* 0 usecs */
231 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
234 static struct ctl_table kern_table[] = {
235 #ifdef CONFIG_SCHED_DEBUG
237 .ctl_name = CTL_UNNUMBERED,
238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
240 .maxlen = sizeof(unsigned int),
242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
248 .ctl_name = CTL_UNNUMBERED,
249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
259 .ctl_name = CTL_UNNUMBERED,
260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "sched_batch_wakeup_granularity_ns",
272 .data = &sysctl_sched_batch_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
281 .ctl_name = CTL_UNNUMBERED,
282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = &proc_dointvec,
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_features",
291 .data = &sysctl_sched_features,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = &proc_dointvec,
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_migration_cost",
299 .data = &sysctl_sched_migration_cost,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = &proc_dointvec,
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "sched_nr_migrate",
307 .data = &sysctl_sched_nr_migrate,
308 .maxlen = sizeof(unsigned int),
310 .proc_handler = &proc_dointvec,
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "sched_rt_period_ms",
315 .data = &sysctl_sched_rt_period,
316 .maxlen = sizeof(unsigned int),
318 .proc_handler = &proc_dointvec,
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_rt_ratio",
323 .data = &sysctl_sched_rt_ratio,
324 .maxlen = sizeof(unsigned int),
326 .proc_handler = &proc_dointvec,
328 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "sched_min_bal_int_shares",
332 .data = &sysctl_sched_min_bal_int_shares,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = &proc_dointvec,
338 .ctl_name = CTL_UNNUMBERED,
339 .procname = "sched_max_bal_int_shares",
340 .data = &sysctl_sched_max_bal_int_shares,
341 .maxlen = sizeof(unsigned int),
343 .proc_handler = &proc_dointvec,
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "sched_compat_yield",
350 .data = &sysctl_sched_compat_yield,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = &proc_dointvec,
355 #ifdef CONFIG_PROVE_LOCKING
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "prove_locking",
359 .data = &prove_locking,
360 .maxlen = sizeof(int),
362 .proc_handler = &proc_dointvec,
365 #ifdef CONFIG_LOCK_STAT
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "lock_stat",
370 .maxlen = sizeof(int),
372 .proc_handler = &proc_dointvec,
376 .ctl_name = KERN_PANIC,
378 .data = &panic_timeout,
379 .maxlen = sizeof(int),
381 .proc_handler = &proc_dointvec,
384 .ctl_name = KERN_CORE_USES_PID,
385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
389 .proc_handler = &proc_dointvec,
391 #ifdef CONFIG_AUDITSYSCALL
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "audit_argv_kb",
395 .data = &audit_argv_kb,
396 .maxlen = sizeof(int),
398 .proc_handler = &proc_dointvec,
402 .ctl_name = KERN_CORE_PATTERN,
403 .procname = "core_pattern",
404 .data = core_pattern,
405 .maxlen = CORENAME_MAX_SIZE,
407 .proc_handler = &proc_dostring,
408 .strategy = &sysctl_string,
410 #ifdef CONFIG_PROC_SYSCTL
412 .procname = "tainted",
414 .maxlen = sizeof(int),
416 .proc_handler = &proc_dointvec_taint,
419 #ifdef CONFIG_SECURITY_CAPABILITIES
421 .procname = "cap-bound",
423 .maxlen = sizeof(kernel_cap_t),
425 .proc_handler = &proc_dointvec_bset,
427 #endif /* def CONFIG_SECURITY_CAPABILITIES */
428 #ifdef CONFIG_BLK_DEV_INITRD
430 .ctl_name = KERN_REALROOTDEV,
431 .procname = "real-root-dev",
432 .data = &real_root_dev,
433 .maxlen = sizeof(int),
435 .proc_handler = &proc_dointvec,
439 .ctl_name = CTL_UNNUMBERED,
440 .procname = "print-fatal-signals",
441 .data = &print_fatal_signals,
442 .maxlen = sizeof(int),
444 .proc_handler = &proc_dointvec,
448 .ctl_name = KERN_SPARC_REBOOT,
449 .procname = "reboot-cmd",
450 .data = reboot_command,
453 .proc_handler = &proc_dostring,
454 .strategy = &sysctl_string,
457 .ctl_name = KERN_SPARC_STOP_A,
458 .procname = "stop-a",
459 .data = &stop_a_enabled,
460 .maxlen = sizeof (int),
462 .proc_handler = &proc_dointvec,
465 .ctl_name = KERN_SPARC_SCONS_PWROFF,
466 .procname = "scons-poweroff",
467 .data = &scons_pwroff,
468 .maxlen = sizeof (int),
470 .proc_handler = &proc_dointvec,
475 .ctl_name = KERN_HPPA_PWRSW,
476 .procname = "soft-power",
477 .data = &pwrsw_enabled,
478 .maxlen = sizeof (int),
480 .proc_handler = &proc_dointvec,
483 .ctl_name = KERN_HPPA_UNALIGNED,
484 .procname = "unaligned-trap",
485 .data = &unaligned_enabled,
486 .maxlen = sizeof (int),
488 .proc_handler = &proc_dointvec,
492 .ctl_name = KERN_CTLALTDEL,
493 .procname = "ctrl-alt-del",
495 .maxlen = sizeof(int),
497 .proc_handler = &proc_dointvec,
500 .ctl_name = KERN_PRINTK,
501 .procname = "printk",
502 .data = &console_loglevel,
503 .maxlen = 4*sizeof(int),
505 .proc_handler = &proc_dointvec,
509 .ctl_name = KERN_MODPROBE,
510 .procname = "modprobe",
511 .data = &modprobe_path,
512 .maxlen = KMOD_PATH_LEN,
514 .proc_handler = &proc_dostring,
515 .strategy = &sysctl_string,
518 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
520 .ctl_name = KERN_HOTPLUG,
521 .procname = "hotplug",
522 .data = &uevent_helper,
523 .maxlen = UEVENT_HELPER_PATH_LEN,
525 .proc_handler = &proc_dostring,
526 .strategy = &sysctl_string,
529 #ifdef CONFIG_CHR_DEV_SG
531 .ctl_name = KERN_SG_BIG_BUFF,
532 .procname = "sg-big-buff",
533 .data = &sg_big_buff,
534 .maxlen = sizeof (int),
536 .proc_handler = &proc_dointvec,
539 #ifdef CONFIG_BSD_PROCESS_ACCT
541 .ctl_name = KERN_ACCT,
544 .maxlen = 3*sizeof(int),
546 .proc_handler = &proc_dointvec,
549 #ifdef CONFIG_MAGIC_SYSRQ
551 .ctl_name = KERN_SYSRQ,
553 .data = &__sysrq_enabled,
554 .maxlen = sizeof (int),
556 .proc_handler = &proc_dointvec,
559 #ifdef CONFIG_PROC_SYSCTL
561 .procname = "cad_pid",
563 .maxlen = sizeof (int),
565 .proc_handler = &proc_do_cad_pid,
569 .ctl_name = KERN_MAX_THREADS,
570 .procname = "threads-max",
571 .data = &max_threads,
572 .maxlen = sizeof(int),
574 .proc_handler = &proc_dointvec,
577 .ctl_name = KERN_RANDOM,
578 .procname = "random",
580 .child = random_table,
583 .ctl_name = KERN_OVERFLOWUID,
584 .procname = "overflowuid",
585 .data = &overflowuid,
586 .maxlen = sizeof(int),
588 .proc_handler = &proc_dointvec_minmax,
589 .strategy = &sysctl_intvec,
590 .extra1 = &minolduid,
591 .extra2 = &maxolduid,
594 .ctl_name = KERN_OVERFLOWGID,
595 .procname = "overflowgid",
596 .data = &overflowgid,
597 .maxlen = sizeof(int),
599 .proc_handler = &proc_dointvec_minmax,
600 .strategy = &sysctl_intvec,
601 .extra1 = &minolduid,
602 .extra2 = &maxolduid,
605 #ifdef CONFIG_MATHEMU
607 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
608 .procname = "ieee_emulation_warnings",
609 .data = &sysctl_ieee_emulation_warnings,
610 .maxlen = sizeof(int),
612 .proc_handler = &proc_dointvec,
615 #ifdef CONFIG_NO_IDLE_HZ
617 .ctl_name = KERN_HZ_TIMER,
618 .procname = "hz_timer",
619 .data = &sysctl_hz_timer,
620 .maxlen = sizeof(int),
622 .proc_handler = &proc_dointvec,
626 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
627 .procname = "userprocess_debug",
628 .data = &sysctl_userprocess_debug,
629 .maxlen = sizeof(int),
631 .proc_handler = &proc_dointvec,
635 .ctl_name = KERN_PIDMAX,
636 .procname = "pid_max",
638 .maxlen = sizeof (int),
640 .proc_handler = &proc_dointvec_minmax,
641 .strategy = sysctl_intvec,
642 .extra1 = &pid_max_min,
643 .extra2 = &pid_max_max,
646 .ctl_name = KERN_PANIC_ON_OOPS,
647 .procname = "panic_on_oops",
648 .data = &panic_on_oops,
649 .maxlen = sizeof(int),
651 .proc_handler = &proc_dointvec,
654 .ctl_name = KERN_PRINTK_RATELIMIT,
655 .procname = "printk_ratelimit",
656 .data = &printk_ratelimit_jiffies,
657 .maxlen = sizeof(int),
659 .proc_handler = &proc_dointvec_jiffies,
660 .strategy = &sysctl_jiffies,
663 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
664 .procname = "printk_ratelimit_burst",
665 .data = &printk_ratelimit_burst,
666 .maxlen = sizeof(int),
668 .proc_handler = &proc_dointvec,
671 .ctl_name = KERN_NGROUPS_MAX,
672 .procname = "ngroups_max",
673 .data = &ngroups_max,
674 .maxlen = sizeof (int),
676 .proc_handler = &proc_dointvec,
678 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
680 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
681 .procname = "unknown_nmi_panic",
682 .data = &unknown_nmi_panic,
683 .maxlen = sizeof (int),
685 .proc_handler = &proc_dointvec,
688 .procname = "nmi_watchdog",
689 .data = &nmi_watchdog_enabled,
690 .maxlen = sizeof (int),
692 .proc_handler = &proc_nmi_enabled,
695 #if defined(CONFIG_X86)
697 .ctl_name = KERN_PANIC_ON_NMI,
698 .procname = "panic_on_unrecovered_nmi",
699 .data = &panic_on_unrecovered_nmi,
700 .maxlen = sizeof(int),
702 .proc_handler = &proc_dointvec,
705 .ctl_name = KERN_BOOTLOADER_TYPE,
706 .procname = "bootloader_type",
707 .data = &bootloader_type,
708 .maxlen = sizeof (int),
710 .proc_handler = &proc_dointvec,
713 .ctl_name = CTL_UNNUMBERED,
714 .procname = "kstack_depth_to_print",
715 .data = &kstack_depth_to_print,
716 .maxlen = sizeof(int),
718 .proc_handler = &proc_dointvec,
721 #if defined(CONFIG_MMU)
723 .ctl_name = KERN_RANDOMIZE,
724 .procname = "randomize_va_space",
725 .data = &randomize_va_space,
726 .maxlen = sizeof(int),
728 .proc_handler = &proc_dointvec,
731 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
733 .ctl_name = KERN_SPIN_RETRY,
734 .procname = "spin_retry",
736 .maxlen = sizeof (int),
738 .proc_handler = &proc_dointvec,
741 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
743 .procname = "acpi_video_flags",
744 .data = &acpi_realmode_flags,
745 .maxlen = sizeof (unsigned long),
747 .proc_handler = &proc_doulongvec_minmax,
752 .ctl_name = KERN_IA64_UNALIGNED,
753 .procname = "ignore-unaligned-usertrap",
754 .data = &no_unaligned_warning,
755 .maxlen = sizeof (int),
757 .proc_handler = &proc_dointvec,
760 #ifdef CONFIG_DETECT_SOFTLOCKUP
762 .ctl_name = CTL_UNNUMBERED,
763 .procname = "softlockup_thresh",
764 .data = &softlockup_thresh,
765 .maxlen = sizeof(int),
767 .proc_handler = &proc_dointvec_minmax,
768 .strategy = &sysctl_intvec,
773 .ctl_name = CTL_UNNUMBERED,
774 .procname = "hung_task_check_count",
775 .data = &sysctl_hung_task_check_count,
776 .maxlen = sizeof(int),
778 .proc_handler = &proc_dointvec_minmax,
779 .strategy = &sysctl_intvec,
782 .ctl_name = CTL_UNNUMBERED,
783 .procname = "hung_task_timeout_secs",
784 .data = &sysctl_hung_task_timeout_secs,
785 .maxlen = sizeof(int),
787 .proc_handler = &proc_dointvec_minmax,
788 .strategy = &sysctl_intvec,
791 .ctl_name = CTL_UNNUMBERED,
792 .procname = "hung_task_warnings",
793 .data = &sysctl_hung_task_warnings,
794 .maxlen = sizeof(int),
796 .proc_handler = &proc_dointvec_minmax,
797 .strategy = &sysctl_intvec,
802 .ctl_name = KERN_COMPAT_LOG,
803 .procname = "compat-log",
805 .maxlen = sizeof (int),
807 .proc_handler = &proc_dointvec,
810 #ifdef CONFIG_RT_MUTEXES
812 .ctl_name = KERN_MAX_LOCK_DEPTH,
813 .procname = "max_lock_depth",
814 .data = &max_lock_depth,
815 .maxlen = sizeof(int),
817 .proc_handler = &proc_dointvec,
820 #ifdef CONFIG_PROC_FS
822 .ctl_name = CTL_UNNUMBERED,
823 .procname = "maps_protect",
824 .data = &maps_protect,
825 .maxlen = sizeof(int),
827 .proc_handler = &proc_dointvec,
831 .ctl_name = CTL_UNNUMBERED,
832 .procname = "poweroff_cmd",
833 .data = &poweroff_cmd,
834 .maxlen = POWEROFF_CMD_PATH_LEN,
836 .proc_handler = &proc_dostring,
837 .strategy = &sysctl_string,
840 * NOTE: do not add new entries to this table unless you have read
841 * Documentation/sysctl/ctl_unnumbered.txt
846 static struct ctl_table vm_table[] = {
848 .ctl_name = VM_OVERCOMMIT_MEMORY,
849 .procname = "overcommit_memory",
850 .data = &sysctl_overcommit_memory,
851 .maxlen = sizeof(sysctl_overcommit_memory),
853 .proc_handler = &proc_dointvec,
856 .ctl_name = VM_PANIC_ON_OOM,
857 .procname = "panic_on_oom",
858 .data = &sysctl_panic_on_oom,
859 .maxlen = sizeof(sysctl_panic_on_oom),
861 .proc_handler = &proc_dointvec,
864 .ctl_name = CTL_UNNUMBERED,
865 .procname = "oom_kill_allocating_task",
866 .data = &sysctl_oom_kill_allocating_task,
867 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
869 .proc_handler = &proc_dointvec,
872 .ctl_name = VM_OVERCOMMIT_RATIO,
873 .procname = "overcommit_ratio",
874 .data = &sysctl_overcommit_ratio,
875 .maxlen = sizeof(sysctl_overcommit_ratio),
877 .proc_handler = &proc_dointvec,
880 .ctl_name = VM_PAGE_CLUSTER,
881 .procname = "page-cluster",
882 .data = &page_cluster,
883 .maxlen = sizeof(int),
885 .proc_handler = &proc_dointvec,
888 .ctl_name = VM_DIRTY_BACKGROUND,
889 .procname = "dirty_background_ratio",
890 .data = &dirty_background_ratio,
891 .maxlen = sizeof(dirty_background_ratio),
893 .proc_handler = &proc_dointvec_minmax,
894 .strategy = &sysctl_intvec,
896 .extra2 = &one_hundred,
899 .ctl_name = VM_DIRTY_RATIO,
900 .procname = "dirty_ratio",
901 .data = &vm_dirty_ratio,
902 .maxlen = sizeof(vm_dirty_ratio),
904 .proc_handler = &dirty_ratio_handler,
905 .strategy = &sysctl_intvec,
907 .extra2 = &one_hundred,
910 .procname = "dirty_writeback_centisecs",
911 .data = &dirty_writeback_interval,
912 .maxlen = sizeof(dirty_writeback_interval),
914 .proc_handler = &dirty_writeback_centisecs_handler,
917 .procname = "dirty_expire_centisecs",
918 .data = &dirty_expire_interval,
919 .maxlen = sizeof(dirty_expire_interval),
921 .proc_handler = &proc_dointvec_userhz_jiffies,
924 .ctl_name = VM_NR_PDFLUSH_THREADS,
925 .procname = "nr_pdflush_threads",
926 .data = &nr_pdflush_threads,
927 .maxlen = sizeof nr_pdflush_threads,
928 .mode = 0444 /* read-only*/,
929 .proc_handler = &proc_dointvec,
932 .ctl_name = VM_SWAPPINESS,
933 .procname = "swappiness",
934 .data = &vm_swappiness,
935 .maxlen = sizeof(vm_swappiness),
937 .proc_handler = &proc_dointvec_minmax,
938 .strategy = &sysctl_intvec,
940 .extra2 = &one_hundred,
942 #ifdef CONFIG_HUGETLB_PAGE
944 .procname = "nr_hugepages",
945 .data = &max_huge_pages,
946 .maxlen = sizeof(unsigned long),
948 .proc_handler = &hugetlb_sysctl_handler,
949 .extra1 = (void *)&hugetlb_zero,
950 .extra2 = (void *)&hugetlb_infinity,
953 .ctl_name = VM_HUGETLB_GROUP,
954 .procname = "hugetlb_shm_group",
955 .data = &sysctl_hugetlb_shm_group,
956 .maxlen = sizeof(gid_t),
958 .proc_handler = &proc_dointvec,
961 .ctl_name = CTL_UNNUMBERED,
962 .procname = "hugepages_treat_as_movable",
963 .data = &hugepages_treat_as_movable,
964 .maxlen = sizeof(int),
966 .proc_handler = &hugetlb_treat_movable_handler,
969 .ctl_name = CTL_UNNUMBERED,
970 .procname = "nr_overcommit_hugepages",
971 .data = &nr_overcommit_huge_pages,
972 .maxlen = sizeof(nr_overcommit_huge_pages),
974 .proc_handler = &proc_doulongvec_minmax,
978 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
979 .procname = "lowmem_reserve_ratio",
980 .data = &sysctl_lowmem_reserve_ratio,
981 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
983 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
984 .strategy = &sysctl_intvec,
987 .ctl_name = VM_DROP_PAGECACHE,
988 .procname = "drop_caches",
989 .data = &sysctl_drop_caches,
990 .maxlen = sizeof(int),
992 .proc_handler = drop_caches_sysctl_handler,
993 .strategy = &sysctl_intvec,
996 .ctl_name = VM_MIN_FREE_KBYTES,
997 .procname = "min_free_kbytes",
998 .data = &min_free_kbytes,
999 .maxlen = sizeof(min_free_kbytes),
1001 .proc_handler = &min_free_kbytes_sysctl_handler,
1002 .strategy = &sysctl_intvec,
1006 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1007 .procname = "percpu_pagelist_fraction",
1008 .data = &percpu_pagelist_fraction,
1009 .maxlen = sizeof(percpu_pagelist_fraction),
1011 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1012 .strategy = &sysctl_intvec,
1013 .extra1 = &min_percpu_pagelist_fract,
1017 .ctl_name = VM_MAX_MAP_COUNT,
1018 .procname = "max_map_count",
1019 .data = &sysctl_max_map_count,
1020 .maxlen = sizeof(sysctl_max_map_count),
1022 .proc_handler = &proc_dointvec
1026 .ctl_name = VM_LAPTOP_MODE,
1027 .procname = "laptop_mode",
1028 .data = &laptop_mode,
1029 .maxlen = sizeof(laptop_mode),
1031 .proc_handler = &proc_dointvec_jiffies,
1032 .strategy = &sysctl_jiffies,
1035 .ctl_name = VM_BLOCK_DUMP,
1036 .procname = "block_dump",
1037 .data = &block_dump,
1038 .maxlen = sizeof(block_dump),
1040 .proc_handler = &proc_dointvec,
1041 .strategy = &sysctl_intvec,
1045 .ctl_name = VM_VFS_CACHE_PRESSURE,
1046 .procname = "vfs_cache_pressure",
1047 .data = &sysctl_vfs_cache_pressure,
1048 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1050 .proc_handler = &proc_dointvec,
1051 .strategy = &sysctl_intvec,
1054 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1056 .ctl_name = VM_LEGACY_VA_LAYOUT,
1057 .procname = "legacy_va_layout",
1058 .data = &sysctl_legacy_va_layout,
1059 .maxlen = sizeof(sysctl_legacy_va_layout),
1061 .proc_handler = &proc_dointvec,
1062 .strategy = &sysctl_intvec,
1068 .ctl_name = VM_ZONE_RECLAIM_MODE,
1069 .procname = "zone_reclaim_mode",
1070 .data = &zone_reclaim_mode,
1071 .maxlen = sizeof(zone_reclaim_mode),
1073 .proc_handler = &proc_dointvec,
1074 .strategy = &sysctl_intvec,
1078 .ctl_name = VM_MIN_UNMAPPED,
1079 .procname = "min_unmapped_ratio",
1080 .data = &sysctl_min_unmapped_ratio,
1081 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1083 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1084 .strategy = &sysctl_intvec,
1086 .extra2 = &one_hundred,
1089 .ctl_name = VM_MIN_SLAB,
1090 .procname = "min_slab_ratio",
1091 .data = &sysctl_min_slab_ratio,
1092 .maxlen = sizeof(sysctl_min_slab_ratio),
1094 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1095 .strategy = &sysctl_intvec,
1097 .extra2 = &one_hundred,
1102 .ctl_name = CTL_UNNUMBERED,
1103 .procname = "stat_interval",
1104 .data = &sysctl_stat_interval,
1105 .maxlen = sizeof(sysctl_stat_interval),
1107 .proc_handler = &proc_dointvec_jiffies,
1108 .strategy = &sysctl_jiffies,
1111 #ifdef CONFIG_SECURITY
1113 .ctl_name = CTL_UNNUMBERED,
1114 .procname = "mmap_min_addr",
1115 .data = &mmap_min_addr,
1116 .maxlen = sizeof(unsigned long),
1118 .proc_handler = &proc_doulongvec_minmax,
1123 .ctl_name = CTL_UNNUMBERED,
1124 .procname = "numa_zonelist_order",
1125 .data = &numa_zonelist_order,
1126 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1128 .proc_handler = &numa_zonelist_order_handler,
1129 .strategy = &sysctl_string,
1132 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1133 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1135 .ctl_name = VM_VDSO_ENABLED,
1136 .procname = "vdso_enabled",
1137 .data = &vdso_enabled,
1138 .maxlen = sizeof(vdso_enabled),
1140 .proc_handler = &proc_dointvec,
1141 .strategy = &sysctl_intvec,
1146 * NOTE: do not add new entries to this table unless you have read
1147 * Documentation/sysctl/ctl_unnumbered.txt
1152 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1153 static struct ctl_table binfmt_misc_table[] = {
1158 static struct ctl_table fs_table[] = {
1160 .ctl_name = FS_NRINODE,
1161 .procname = "inode-nr",
1162 .data = &inodes_stat,
1163 .maxlen = 2*sizeof(int),
1165 .proc_handler = &proc_dointvec,
1168 .ctl_name = FS_STATINODE,
1169 .procname = "inode-state",
1170 .data = &inodes_stat,
1171 .maxlen = 7*sizeof(int),
1173 .proc_handler = &proc_dointvec,
1176 .procname = "file-nr",
1177 .data = &files_stat,
1178 .maxlen = 3*sizeof(int),
1180 .proc_handler = &proc_nr_files,
1183 .ctl_name = FS_MAXFILE,
1184 .procname = "file-max",
1185 .data = &files_stat.max_files,
1186 .maxlen = sizeof(int),
1188 .proc_handler = &proc_dointvec,
1191 .ctl_name = FS_DENTRY,
1192 .procname = "dentry-state",
1193 .data = &dentry_stat,
1194 .maxlen = 6*sizeof(int),
1196 .proc_handler = &proc_dointvec,
1199 .ctl_name = FS_OVERFLOWUID,
1200 .procname = "overflowuid",
1201 .data = &fs_overflowuid,
1202 .maxlen = sizeof(int),
1204 .proc_handler = &proc_dointvec_minmax,
1205 .strategy = &sysctl_intvec,
1206 .extra1 = &minolduid,
1207 .extra2 = &maxolduid,
1210 .ctl_name = FS_OVERFLOWGID,
1211 .procname = "overflowgid",
1212 .data = &fs_overflowgid,
1213 .maxlen = sizeof(int),
1215 .proc_handler = &proc_dointvec_minmax,
1216 .strategy = &sysctl_intvec,
1217 .extra1 = &minolduid,
1218 .extra2 = &maxolduid,
1221 .ctl_name = FS_LEASES,
1222 .procname = "leases-enable",
1223 .data = &leases_enable,
1224 .maxlen = sizeof(int),
1226 .proc_handler = &proc_dointvec,
1228 #ifdef CONFIG_DNOTIFY
1230 .ctl_name = FS_DIR_NOTIFY,
1231 .procname = "dir-notify-enable",
1232 .data = &dir_notify_enable,
1233 .maxlen = sizeof(int),
1235 .proc_handler = &proc_dointvec,
1240 .ctl_name = FS_LEASE_TIME,
1241 .procname = "lease-break-time",
1242 .data = &lease_break_time,
1243 .maxlen = sizeof(int),
1245 .proc_handler = &proc_dointvec_minmax,
1246 .strategy = &sysctl_intvec,
1251 .procname = "aio-nr",
1253 .maxlen = sizeof(aio_nr),
1255 .proc_handler = &proc_doulongvec_minmax,
1258 .procname = "aio-max-nr",
1259 .data = &aio_max_nr,
1260 .maxlen = sizeof(aio_max_nr),
1262 .proc_handler = &proc_doulongvec_minmax,
1264 #ifdef CONFIG_INOTIFY_USER
1266 .ctl_name = FS_INOTIFY,
1267 .procname = "inotify",
1269 .child = inotify_table,
1274 .ctl_name = KERN_SETUID_DUMPABLE,
1275 .procname = "suid_dumpable",
1276 .data = &suid_dumpable,
1277 .maxlen = sizeof(int),
1279 .proc_handler = &proc_dointvec,
1281 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1283 .ctl_name = CTL_UNNUMBERED,
1284 .procname = "binfmt_misc",
1286 .child = binfmt_misc_table,
1290 * NOTE: do not add new entries to this table unless you have read
1291 * Documentation/sysctl/ctl_unnumbered.txt
1296 static struct ctl_table debug_table[] = {
1297 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1299 .ctl_name = CTL_UNNUMBERED,
1300 .procname = "exception-trace",
1301 .data = &show_unhandled_signals,
1302 .maxlen = sizeof(int),
1304 .proc_handler = proc_dointvec
1310 static struct ctl_table dev_table[] = {
1314 static DEFINE_SPINLOCK(sysctl_lock);
1316 /* called under sysctl_lock */
1317 static int use_table(struct ctl_table_header *p)
1319 if (unlikely(p->unregistering))
1325 /* called under sysctl_lock */
1326 static void unuse_table(struct ctl_table_header *p)
1329 if (unlikely(p->unregistering))
1330 complete(p->unregistering);
1333 /* called under sysctl_lock, will reacquire if has to wait */
1334 static void start_unregistering(struct ctl_table_header *p)
1337 * if p->used is 0, nobody will ever touch that entry again;
1338 * we'll eliminate all paths to it before dropping sysctl_lock
1340 if (unlikely(p->used)) {
1341 struct completion wait;
1342 init_completion(&wait);
1343 p->unregistering = &wait;
1344 spin_unlock(&sysctl_lock);
1345 wait_for_completion(&wait);
1346 spin_lock(&sysctl_lock);
1349 * do not remove from the list until nobody holds it; walking the
1350 * list in do_sysctl() relies on that.
1352 list_del_init(&p->ctl_entry);
1355 void sysctl_head_finish(struct ctl_table_header *head)
1359 spin_lock(&sysctl_lock);
1361 spin_unlock(&sysctl_lock);
1364 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1366 struct ctl_table_header *head;
1367 struct list_head *tmp;
1368 spin_lock(&sysctl_lock);
1370 tmp = &prev->ctl_entry;
1374 tmp = &root_table_header.ctl_entry;
1376 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1378 if (!use_table(head))
1380 spin_unlock(&sysctl_lock);
1384 if (tmp == &root_table_header.ctl_entry)
1387 spin_unlock(&sysctl_lock);
1391 #ifdef CONFIG_SYSCTL_SYSCALL
1392 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1393 void __user *newval, size_t newlen)
1395 struct ctl_table_header *head;
1396 int error = -ENOTDIR;
1398 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1402 if (!oldlenp || get_user(old_len, oldlenp))
1406 for (head = sysctl_head_next(NULL); head;
1407 head = sysctl_head_next(head)) {
1408 error = parse_table(name, nlen, oldval, oldlenp,
1409 newval, newlen, head->ctl_table);
1410 if (error != -ENOTDIR) {
1411 sysctl_head_finish(head);
1418 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1420 struct __sysctl_args tmp;
1423 if (copy_from_user(&tmp, args, sizeof(tmp)))
1426 error = deprecated_sysctl_warning(&tmp);
1431 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1432 tmp.newval, tmp.newlen);
1437 #endif /* CONFIG_SYSCTL_SYSCALL */
1440 * sysctl_perm does NOT grant the superuser all rights automatically, because
1441 * some sysctl variables are readonly even to root.
1444 static int test_perm(int mode, int op)
1448 else if (in_egroup_p(0))
1450 if ((mode & op & 0007) == op)
1455 int sysctl_perm(struct ctl_table *table, int op)
1458 error = security_sysctl(table, op);
1461 return test_perm(table->mode, op);
1464 #ifdef CONFIG_SYSCTL_SYSCALL
1465 static int parse_table(int __user *name, int nlen,
1466 void __user *oldval, size_t __user *oldlenp,
1467 void __user *newval, size_t newlen,
1468 struct ctl_table *table)
1474 if (get_user(n, name))
1476 for ( ; table->ctl_name || table->procname; table++) {
1477 if (!table->ctl_name)
1479 if (n == table->ctl_name) {
1482 if (sysctl_perm(table, 001))
1486 table = table->child;
1489 error = do_sysctl_strategy(table, name, nlen,
1498 /* Perform the actual read/write of a sysctl table entry. */
1499 int do_sysctl_strategy (struct ctl_table *table,
1500 int __user *name, int nlen,
1501 void __user *oldval, size_t __user *oldlenp,
1502 void __user *newval, size_t newlen)
1510 if (sysctl_perm(table, op))
1513 if (table->strategy) {
1514 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1522 /* If there is no strategy routine, or if the strategy returns
1523 * zero, proceed with automatic r/w */
1524 if (table->data && table->maxlen) {
1525 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1532 #endif /* CONFIG_SYSCTL_SYSCALL */
1534 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1536 for (; table->ctl_name || table->procname; table++) {
1537 table->parent = parent;
1539 sysctl_set_parent(table, table->child);
1543 static __init int sysctl_init(void)
1546 sysctl_set_parent(NULL, root_table);
1547 err = sysctl_check_table(root_table);
1551 core_initcall(sysctl_init);
1554 * register_sysctl_table - register a sysctl hierarchy
1555 * @table: the top-level table structure
1557 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1558 * array. An entry with a ctl_name of 0 terminates the table.
1560 * The members of the &struct ctl_table structure are used as follows:
1562 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1563 * must be unique within that level of sysctl
1565 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1566 * enter a sysctl file
1568 * data - a pointer to data for use by proc_handler
1570 * maxlen - the maximum size in bytes of the data
1572 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1574 * child - a pointer to the child sysctl table if this entry is a directory, or
1577 * proc_handler - the text handler routine (described below)
1579 * strategy - the strategy routine (described below)
1581 * de - for internal use by the sysctl routines
1583 * extra1, extra2 - extra pointers usable by the proc handler routines
1585 * Leaf nodes in the sysctl tree will be represented by a single file
1586 * under /proc; non-leaf nodes will be represented by directories.
1588 * sysctl(2) can automatically manage read and write requests through
1589 * the sysctl table. The data and maxlen fields of the ctl_table
1590 * struct enable minimal validation of the values being written to be
1591 * performed, and the mode field allows minimal authentication.
1593 * More sophisticated management can be enabled by the provision of a
1594 * strategy routine with the table entry. This will be called before
1595 * any automatic read or write of the data is performed.
1597 * The strategy routine may return
1599 * < 0 - Error occurred (error is passed to user process)
1601 * 0 - OK - proceed with automatic read or write.
1603 * > 0 - OK - read or write has been done by the strategy routine, so
1604 * return immediately.
1606 * There must be a proc_handler routine for any terminal nodes
1607 * mirrored under /proc/sys (non-terminals are handled by a built-in
1608 * directory handler). Several default handlers are available to
1609 * cover common cases -
1611 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1612 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1613 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1615 * It is the handler's job to read the input buffer from user memory
1616 * and process it. The handler should return 0 on success.
1618 * This routine returns %NULL on a failure to register, and a pointer
1619 * to the table header on success.
1621 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1623 struct ctl_table_header *tmp;
1624 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1627 tmp->ctl_table = table;
1628 INIT_LIST_HEAD(&tmp->ctl_entry);
1630 tmp->unregistering = NULL;
1631 sysctl_set_parent(NULL, table);
1632 if (sysctl_check_table(tmp->ctl_table)) {
1636 spin_lock(&sysctl_lock);
1637 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1638 spin_unlock(&sysctl_lock);
1643 * unregister_sysctl_table - unregister a sysctl table hierarchy
1644 * @header: the header returned from register_sysctl_table
1646 * Unregisters the sysctl table and all children. proc entries may not
1647 * actually be removed until they are no longer used by anyone.
1649 void unregister_sysctl_table(struct ctl_table_header * header)
1656 spin_lock(&sysctl_lock);
1657 start_unregistering(header);
1658 spin_unlock(&sysctl_lock);
1662 #else /* !CONFIG_SYSCTL */
1663 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1668 void unregister_sysctl_table(struct ctl_table_header * table)
1672 #endif /* CONFIG_SYSCTL */
1678 #ifdef CONFIG_PROC_SYSCTL
1680 static int _proc_do_string(void* data, int maxlen, int write,
1681 struct file *filp, void __user *buffer,
1682 size_t *lenp, loff_t *ppos)
1688 if (!data || !maxlen || !*lenp) {
1696 while (len < *lenp) {
1697 if (get_user(c, p++))
1699 if (c == 0 || c == '\n')
1705 if(copy_from_user(data, buffer, len))
1707 ((char *) data)[len] = 0;
1725 if(copy_to_user(buffer, data, len))
1728 if(put_user('\n', ((char __user *) buffer) + len))
1739 * proc_dostring - read a string sysctl
1740 * @table: the sysctl table
1741 * @write: %TRUE if this is a write to the sysctl file
1742 * @filp: the file structure
1743 * @buffer: the user buffer
1744 * @lenp: the size of the user buffer
1745 * @ppos: file position
1747 * Reads/writes a string from/to the user buffer. If the kernel
1748 * buffer provided is not large enough to hold the string, the
1749 * string is truncated. The copied string is %NULL-terminated.
1750 * If the string is being read by the user process, it is copied
1751 * and a newline '\n' is added. It is truncated if the buffer is
1754 * Returns 0 on success.
1756 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1757 void __user *buffer, size_t *lenp, loff_t *ppos)
1759 return _proc_do_string(table->data, table->maxlen, write, filp,
1760 buffer, lenp, ppos);
1764 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1766 int write, void *data)
1769 *valp = *negp ? -*lvalp : *lvalp;
1774 *lvalp = (unsigned long)-val;
1777 *lvalp = (unsigned long)val;
1783 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1784 int write, struct file *filp, void __user *buffer,
1785 size_t *lenp, loff_t *ppos,
1786 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1787 int write, void *data),
1790 #define TMPBUFLEN 21
1791 int *i, vleft, first=1, neg, val;
1795 char buf[TMPBUFLEN], *p;
1796 char __user *s = buffer;
1798 if (!tbl_data || !table->maxlen || !*lenp ||
1799 (*ppos && !write)) {
1804 i = (int *) tbl_data;
1805 vleft = table->maxlen / sizeof(*i);
1809 conv = do_proc_dointvec_conv;
1811 for (; left && vleft--; i++, first=0) {
1826 if (len > sizeof(buf) - 1)
1827 len = sizeof(buf) - 1;
1828 if (copy_from_user(buf, s, len))
1832 if (*p == '-' && left > 1) {
1836 if (*p < '0' || *p > '9')
1839 lval = simple_strtoul(p, &p, 0);
1842 if ((len < left) && *p && !isspace(*p))
1849 if (conv(&neg, &lval, i, 1, data))
1856 if (conv(&neg, &lval, i, 0, data))
1859 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1863 if(copy_to_user(s, buf, len))
1870 if (!write && !first && left) {
1871 if(put_user('\n', s))
1878 if (get_user(c, s++))
1893 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1894 void __user *buffer, size_t *lenp, loff_t *ppos,
1895 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1896 int write, void *data),
1899 return __do_proc_dointvec(table->data, table, write, filp,
1900 buffer, lenp, ppos, conv, data);
1904 * proc_dointvec - read a vector of integers
1905 * @table: the sysctl table
1906 * @write: %TRUE if this is a write to the sysctl file
1907 * @filp: the file structure
1908 * @buffer: the user buffer
1909 * @lenp: the size of the user buffer
1910 * @ppos: file position
1912 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1913 * values from/to the user buffer, treated as an ASCII string.
1915 * Returns 0 on success.
1917 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1918 void __user *buffer, size_t *lenp, loff_t *ppos)
1920 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1928 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1930 int write, void *data)
1932 int op = *(int *)data;
1934 int val = *negp ? -*lvalp : *lvalp;
1936 case OP_SET: *valp = val; break;
1937 case OP_AND: *valp &= val; break;
1938 case OP_OR: *valp |= val; break;
1944 *lvalp = (unsigned long)-val;
1947 *lvalp = (unsigned long)val;
1953 #ifdef CONFIG_SECURITY_CAPABILITIES
1955 * init may raise the set.
1958 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1959 void __user *buffer, size_t *lenp, loff_t *ppos)
1963 if (write && !capable(CAP_SYS_MODULE)) {
1967 op = is_global_init(current) ? OP_SET : OP_AND;
1968 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1969 do_proc_dointvec_bset_conv,&op);
1971 #endif /* def CONFIG_SECURITY_CAPABILITIES */
1974 * Taint values can only be increased
1976 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1977 void __user *buffer, size_t *lenp, loff_t *ppos)
1981 if (write && !capable(CAP_SYS_ADMIN))
1985 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1986 do_proc_dointvec_bset_conv,&op);
1989 struct do_proc_dointvec_minmax_conv_param {
1994 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1996 int write, void *data)
1998 struct do_proc_dointvec_minmax_conv_param *param = data;
2000 int val = *negp ? -*lvalp : *lvalp;
2001 if ((param->min && *param->min > val) ||
2002 (param->max && *param->max < val))
2009 *lvalp = (unsigned long)-val;
2012 *lvalp = (unsigned long)val;
2019 * proc_dointvec_minmax - read a vector of integers with min/max values
2020 * @table: the sysctl table
2021 * @write: %TRUE if this is a write to the sysctl file
2022 * @filp: the file structure
2023 * @buffer: the user buffer
2024 * @lenp: the size of the user buffer
2025 * @ppos: file position
2027 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2028 * values from/to the user buffer, treated as an ASCII string.
2030 * This routine will ensure the values are within the range specified by
2031 * table->extra1 (min) and table->extra2 (max).
2033 * Returns 0 on success.
2035 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2036 void __user *buffer, size_t *lenp, loff_t *ppos)
2038 struct do_proc_dointvec_minmax_conv_param param = {
2039 .min = (int *) table->extra1,
2040 .max = (int *) table->extra2,
2042 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2043 do_proc_dointvec_minmax_conv, ¶m);
2046 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2048 void __user *buffer,
2049 size_t *lenp, loff_t *ppos,
2050 unsigned long convmul,
2051 unsigned long convdiv)
2053 #define TMPBUFLEN 21
2054 unsigned long *i, *min, *max, val;
2055 int vleft, first=1, neg;
2057 char buf[TMPBUFLEN], *p;
2058 char __user *s = buffer;
2060 if (!data || !table->maxlen || !*lenp ||
2061 (*ppos && !write)) {
2066 i = (unsigned long *) data;
2067 min = (unsigned long *) table->extra1;
2068 max = (unsigned long *) table->extra2;
2069 vleft = table->maxlen / sizeof(unsigned long);
2072 for (; left && vleft--; i++, min++, max++, first=0) {
2087 if (len > TMPBUFLEN-1)
2089 if (copy_from_user(buf, s, len))
2093 if (*p == '-' && left > 1) {
2097 if (*p < '0' || *p > '9')
2099 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2101 if ((len < left) && *p && !isspace(*p))
2110 if ((min && val < *min) || (max && val > *max))
2117 sprintf(p, "%lu", convdiv * (*i) / convmul);
2121 if(copy_to_user(s, buf, len))
2128 if (!write && !first && left) {
2129 if(put_user('\n', s))
2136 if (get_user(c, s++))
2151 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2153 void __user *buffer,
2154 size_t *lenp, loff_t *ppos,
2155 unsigned long convmul,
2156 unsigned long convdiv)
2158 return __do_proc_doulongvec_minmax(table->data, table, write,
2159 filp, buffer, lenp, ppos, convmul, convdiv);
2163 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2164 * @table: the sysctl table
2165 * @write: %TRUE if this is a write to the sysctl file
2166 * @filp: the file structure
2167 * @buffer: the user buffer
2168 * @lenp: the size of the user buffer
2169 * @ppos: file position
2171 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2172 * values from/to the user buffer, treated as an ASCII string.
2174 * This routine will ensure the values are within the range specified by
2175 * table->extra1 (min) and table->extra2 (max).
2177 * Returns 0 on success.
2179 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2180 void __user *buffer, size_t *lenp, loff_t *ppos)
2182 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2186 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2187 * @table: the sysctl table
2188 * @write: %TRUE if this is a write to the sysctl file
2189 * @filp: the file structure
2190 * @buffer: the user buffer
2191 * @lenp: the size of the user buffer
2192 * @ppos: file position
2194 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2195 * values from/to the user buffer, treated as an ASCII string. The values
2196 * are treated as milliseconds, and converted to jiffies when they are stored.
2198 * This routine will ensure the values are within the range specified by
2199 * table->extra1 (min) and table->extra2 (max).
2201 * Returns 0 on success.
2203 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2205 void __user *buffer,
2206 size_t *lenp, loff_t *ppos)
2208 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2209 lenp, ppos, HZ, 1000l);
2213 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2215 int write, void *data)
2218 if (*lvalp > LONG_MAX / HZ)
2220 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2226 lval = (unsigned long)-val;
2229 lval = (unsigned long)val;
2236 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2238 int write, void *data)
2241 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2243 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2249 lval = (unsigned long)-val;
2252 lval = (unsigned long)val;
2254 *lvalp = jiffies_to_clock_t(lval);
2259 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2261 int write, void *data)
2264 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2270 lval = (unsigned long)-val;
2273 lval = (unsigned long)val;
2275 *lvalp = jiffies_to_msecs(lval);
2281 * proc_dointvec_jiffies - read a vector of integers as seconds
2282 * @table: the sysctl table
2283 * @write: %TRUE if this is a write to the sysctl file
2284 * @filp: the file structure
2285 * @buffer: the user buffer
2286 * @lenp: the size of the user buffer
2287 * @ppos: file position
2289 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2290 * values from/to the user buffer, treated as an ASCII string.
2291 * The values read are assumed to be in seconds, and are converted into
2294 * Returns 0 on success.
2296 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2297 void __user *buffer, size_t *lenp, loff_t *ppos)
2299 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2300 do_proc_dointvec_jiffies_conv,NULL);
2304 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2305 * @table: the sysctl table
2306 * @write: %TRUE if this is a write to the sysctl file
2307 * @filp: the file structure
2308 * @buffer: the user buffer
2309 * @lenp: the size of the user buffer
2310 * @ppos: pointer to the file position
2312 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2313 * values from/to the user buffer, treated as an ASCII string.
2314 * The values read are assumed to be in 1/USER_HZ seconds, and
2315 * are converted into jiffies.
2317 * Returns 0 on success.
2319 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2320 void __user *buffer, size_t *lenp, loff_t *ppos)
2322 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2323 do_proc_dointvec_userhz_jiffies_conv,NULL);
2327 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2328 * @table: the sysctl table
2329 * @write: %TRUE if this is a write to the sysctl file
2330 * @filp: the file structure
2331 * @buffer: the user buffer
2332 * @lenp: the size of the user buffer
2333 * @ppos: file position
2334 * @ppos: the current position in the file
2336 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2337 * values from/to the user buffer, treated as an ASCII string.
2338 * The values read are assumed to be in 1/1000 seconds, and
2339 * are converted into jiffies.
2341 * Returns 0 on success.
2343 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2344 void __user *buffer, size_t *lenp, loff_t *ppos)
2346 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2347 do_proc_dointvec_ms_jiffies_conv, NULL);
2350 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2351 void __user *buffer, size_t *lenp, loff_t *ppos)
2353 struct pid *new_pid;
2357 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
2359 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2360 lenp, ppos, NULL, NULL);
2364 new_pid = find_get_pid(tmp);
2368 put_pid(xchg(&cad_pid, new_pid));
2372 #else /* CONFIG_PROC_FS */
2374 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2375 void __user *buffer, size_t *lenp, loff_t *ppos)
2380 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2386 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2387 void __user *buffer, size_t *lenp, loff_t *ppos)
2392 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2393 void __user *buffer, size_t *lenp, loff_t *ppos)
2398 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2399 void __user *buffer, size_t *lenp, loff_t *ppos)
2404 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2405 void __user *buffer, size_t *lenp, loff_t *ppos)
2410 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2411 void __user *buffer, size_t *lenp, loff_t *ppos)
2416 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2417 void __user *buffer, size_t *lenp, loff_t *ppos)
2422 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2424 void __user *buffer,
2425 size_t *lenp, loff_t *ppos)
2431 #endif /* CONFIG_PROC_FS */
2434 #ifdef CONFIG_SYSCTL_SYSCALL
2436 * General sysctl support routines
2439 /* The generic sysctl data routine (used if no strategy routine supplied) */
2440 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2441 void __user *oldval, size_t __user *oldlenp,
2442 void __user *newval, size_t newlen)
2446 /* Get out of I don't have a variable */
2447 if (!table->data || !table->maxlen)
2450 if (oldval && oldlenp) {
2451 if (get_user(len, oldlenp))
2454 if (len > table->maxlen)
2455 len = table->maxlen;
2456 if (copy_to_user(oldval, table->data, len))
2458 if (put_user(len, oldlenp))
2463 if (newval && newlen) {
2464 if (newlen > table->maxlen)
2465 newlen = table->maxlen;
2467 if (copy_from_user(table->data, newval, newlen))
2473 /* The generic string strategy routine: */
2474 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2475 void __user *oldval, size_t __user *oldlenp,
2476 void __user *newval, size_t newlen)
2478 if (!table->data || !table->maxlen)
2481 if (oldval && oldlenp) {
2483 if (get_user(bufsize, oldlenp))
2486 size_t len = strlen(table->data), copied;
2488 /* This shouldn't trigger for a well-formed sysctl */
2489 if (len > table->maxlen)
2490 len = table->maxlen;
2492 /* Copy up to a max of bufsize-1 bytes of the string */
2493 copied = (len >= bufsize) ? bufsize - 1 : len;
2495 if (copy_to_user(oldval, table->data, copied) ||
2496 put_user(0, (char __user *)(oldval + copied)))
2498 if (put_user(len, oldlenp))
2502 if (newval && newlen) {
2503 size_t len = newlen;
2504 if (len > table->maxlen)
2505 len = table->maxlen;
2506 if(copy_from_user(table->data, newval, len))
2508 if (len == table->maxlen)
2510 ((char *) table->data)[len] = 0;
2516 * This function makes sure that all of the integers in the vector
2517 * are between the minimum and maximum values given in the arrays
2518 * table->extra1 and table->extra2, respectively.
2520 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2521 void __user *oldval, size_t __user *oldlenp,
2522 void __user *newval, size_t newlen)
2525 if (newval && newlen) {
2526 int __user *vec = (int __user *) newval;
2527 int *min = (int *) table->extra1;
2528 int *max = (int *) table->extra2;
2532 if (newlen % sizeof(int) != 0)
2535 if (!table->extra1 && !table->extra2)
2538 if (newlen > table->maxlen)
2539 newlen = table->maxlen;
2540 length = newlen / sizeof(int);
2542 for (i = 0; i < length; i++) {
2544 if (get_user(value, vec + i))
2546 if (min && value < min[i])
2548 if (max && value > max[i])
2555 /* Strategy function to convert jiffies to seconds */
2556 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2557 void __user *oldval, size_t __user *oldlenp,
2558 void __user *newval, size_t newlen)
2560 if (oldval && oldlenp) {
2563 if (get_user(olen, oldlenp))
2568 if (olen < sizeof(int))
2571 val = *(int *)(table->data) / HZ;
2572 if (put_user(val, (int __user *)oldval))
2574 if (put_user(sizeof(int), oldlenp))
2578 if (newval && newlen) {
2580 if (newlen != sizeof(int))
2582 if (get_user(new, (int __user *)newval))
2584 *(int *)(table->data) = new*HZ;
2589 /* Strategy function to convert jiffies to seconds */
2590 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2591 void __user *oldval, size_t __user *oldlenp,
2592 void __user *newval, size_t newlen)
2594 if (oldval && oldlenp) {
2597 if (get_user(olen, oldlenp))
2602 if (olen < sizeof(int))
2605 val = jiffies_to_msecs(*(int *)(table->data));
2606 if (put_user(val, (int __user *)oldval))
2608 if (put_user(sizeof(int), oldlenp))
2612 if (newval && newlen) {
2614 if (newlen != sizeof(int))
2616 if (get_user(new, (int __user *)newval))
2618 *(int *)(table->data) = msecs_to_jiffies(new);
2625 #else /* CONFIG_SYSCTL_SYSCALL */
2628 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2630 struct __sysctl_args tmp;
2633 if (copy_from_user(&tmp, args, sizeof(tmp)))
2636 error = deprecated_sysctl_warning(&tmp);
2638 /* If no error reading the parameters then just -ENOSYS ... */
2645 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2646 void __user *oldval, size_t __user *oldlenp,
2647 void __user *newval, size_t newlen)
2652 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2653 void __user *oldval, size_t __user *oldlenp,
2654 void __user *newval, size_t newlen)
2659 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2660 void __user *oldval, size_t __user *oldlenp,
2661 void __user *newval, size_t newlen)
2666 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2667 void __user *oldval, size_t __user *oldlenp,
2668 void __user *newval, size_t newlen)
2673 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2674 void __user *oldval, size_t __user *oldlenp,
2675 void __user *newval, size_t newlen)
2680 #endif /* CONFIG_SYSCTL_SYSCALL */
2682 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2684 static int msg_count;
2685 int name[CTL_MAXNAME];
2688 /* Check args->nlen. */
2689 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2692 /* Read in the sysctl name for better debug message logging */
2693 for (i = 0; i < args->nlen; i++)
2694 if (get_user(name[i], args->name + i))
2697 /* Ignore accesses to kernel.version */
2698 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2701 if (msg_count < 5) {
2704 "warning: process `%s' used the deprecated sysctl "
2705 "system call with ", current->comm);
2706 for (i = 0; i < args->nlen; i++)
2707 printk("%d.", name[i]);
2714 * No sense putting this after each symbol definition, twice,
2715 * exception granted :-)
2717 EXPORT_SYMBOL(proc_dointvec);
2718 EXPORT_SYMBOL(proc_dointvec_jiffies);
2719 EXPORT_SYMBOL(proc_dointvec_minmax);
2720 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2721 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2722 EXPORT_SYMBOL(proc_dostring);
2723 EXPORT_SYMBOL(proc_doulongvec_minmax);
2724 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2725 EXPORT_SYMBOL(register_sysctl_table);
2726 EXPORT_SYMBOL(sysctl_intvec);
2727 EXPORT_SYMBOL(sysctl_jiffies);
2728 EXPORT_SYMBOL(sysctl_ms_jiffies);
2729 EXPORT_SYMBOL(sysctl_string);
2730 EXPORT_SYMBOL(sysctl_data);
2731 EXPORT_SYMBOL(unregister_sysctl_table);