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 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,
374 #ifdef CONFIG_SECURITY_CAPABILITIES
376 .procname = "cap-bound",
378 .maxlen = sizeof(kernel_cap_t),
380 .proc_handler = &proc_dointvec_bset,
382 #endif /* def CONFIG_SECURITY_CAPABILITIES */
383 #ifdef CONFIG_BLK_DEV_INITRD
385 .ctl_name = KERN_REALROOTDEV,
386 .procname = "real-root-dev",
387 .data = &real_root_dev,
388 .maxlen = sizeof(int),
390 .proc_handler = &proc_dointvec,
394 .ctl_name = CTL_UNNUMBERED,
395 .procname = "print-fatal-signals",
396 .data = &print_fatal_signals,
397 .maxlen = sizeof(int),
399 .proc_handler = &proc_dointvec,
403 .ctl_name = KERN_SPARC_REBOOT,
404 .procname = "reboot-cmd",
405 .data = reboot_command,
408 .proc_handler = &proc_dostring,
409 .strategy = &sysctl_string,
412 .ctl_name = KERN_SPARC_STOP_A,
413 .procname = "stop-a",
414 .data = &stop_a_enabled,
415 .maxlen = sizeof (int),
417 .proc_handler = &proc_dointvec,
420 .ctl_name = KERN_SPARC_SCONS_PWROFF,
421 .procname = "scons-poweroff",
422 .data = &scons_pwroff,
423 .maxlen = sizeof (int),
425 .proc_handler = &proc_dointvec,
430 .ctl_name = KERN_HPPA_PWRSW,
431 .procname = "soft-power",
432 .data = &pwrsw_enabled,
433 .maxlen = sizeof (int),
435 .proc_handler = &proc_dointvec,
438 .ctl_name = KERN_HPPA_UNALIGNED,
439 .procname = "unaligned-trap",
440 .data = &unaligned_enabled,
441 .maxlen = sizeof (int),
443 .proc_handler = &proc_dointvec,
447 .ctl_name = KERN_CTLALTDEL,
448 .procname = "ctrl-alt-del",
450 .maxlen = sizeof(int),
452 .proc_handler = &proc_dointvec,
455 .ctl_name = KERN_PRINTK,
456 .procname = "printk",
457 .data = &console_loglevel,
458 .maxlen = 4*sizeof(int),
460 .proc_handler = &proc_dointvec,
464 .ctl_name = KERN_MODPROBE,
465 .procname = "modprobe",
466 .data = &modprobe_path,
467 .maxlen = KMOD_PATH_LEN,
469 .proc_handler = &proc_dostring,
470 .strategy = &sysctl_string,
473 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
475 .ctl_name = KERN_HOTPLUG,
476 .procname = "hotplug",
477 .data = &uevent_helper,
478 .maxlen = UEVENT_HELPER_PATH_LEN,
480 .proc_handler = &proc_dostring,
481 .strategy = &sysctl_string,
484 #ifdef CONFIG_CHR_DEV_SG
486 .ctl_name = KERN_SG_BIG_BUFF,
487 .procname = "sg-big-buff",
488 .data = &sg_big_buff,
489 .maxlen = sizeof (int),
491 .proc_handler = &proc_dointvec,
494 #ifdef CONFIG_BSD_PROCESS_ACCT
496 .ctl_name = KERN_ACCT,
499 .maxlen = 3*sizeof(int),
501 .proc_handler = &proc_dointvec,
504 #ifdef CONFIG_MAGIC_SYSRQ
506 .ctl_name = KERN_SYSRQ,
508 .data = &__sysrq_enabled,
509 .maxlen = sizeof (int),
511 .proc_handler = &proc_dointvec,
514 #ifdef CONFIG_PROC_SYSCTL
516 .procname = "cad_pid",
518 .maxlen = sizeof (int),
520 .proc_handler = &proc_do_cad_pid,
524 .ctl_name = KERN_MAX_THREADS,
525 .procname = "threads-max",
526 .data = &max_threads,
527 .maxlen = sizeof(int),
529 .proc_handler = &proc_dointvec,
532 .ctl_name = KERN_RANDOM,
533 .procname = "random",
535 .child = random_table,
538 .ctl_name = KERN_OVERFLOWUID,
539 .procname = "overflowuid",
540 .data = &overflowuid,
541 .maxlen = sizeof(int),
543 .proc_handler = &proc_dointvec_minmax,
544 .strategy = &sysctl_intvec,
545 .extra1 = &minolduid,
546 .extra2 = &maxolduid,
549 .ctl_name = KERN_OVERFLOWGID,
550 .procname = "overflowgid",
551 .data = &overflowgid,
552 .maxlen = sizeof(int),
554 .proc_handler = &proc_dointvec_minmax,
555 .strategy = &sysctl_intvec,
556 .extra1 = &minolduid,
557 .extra2 = &maxolduid,
560 #ifdef CONFIG_MATHEMU
562 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
563 .procname = "ieee_emulation_warnings",
564 .data = &sysctl_ieee_emulation_warnings,
565 .maxlen = sizeof(int),
567 .proc_handler = &proc_dointvec,
570 #ifdef CONFIG_NO_IDLE_HZ
572 .ctl_name = KERN_HZ_TIMER,
573 .procname = "hz_timer",
574 .data = &sysctl_hz_timer,
575 .maxlen = sizeof(int),
577 .proc_handler = &proc_dointvec,
581 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
582 .procname = "userprocess_debug",
583 .data = &sysctl_userprocess_debug,
584 .maxlen = sizeof(int),
586 .proc_handler = &proc_dointvec,
590 .ctl_name = KERN_PIDMAX,
591 .procname = "pid_max",
593 .maxlen = sizeof (int),
595 .proc_handler = &proc_dointvec_minmax,
596 .strategy = sysctl_intvec,
597 .extra1 = &pid_max_min,
598 .extra2 = &pid_max_max,
601 .ctl_name = KERN_PANIC_ON_OOPS,
602 .procname = "panic_on_oops",
603 .data = &panic_on_oops,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
609 .ctl_name = KERN_PRINTK_RATELIMIT,
610 .procname = "printk_ratelimit",
611 .data = &printk_ratelimit_jiffies,
612 .maxlen = sizeof(int),
614 .proc_handler = &proc_dointvec_jiffies,
615 .strategy = &sysctl_jiffies,
618 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
619 .procname = "printk_ratelimit_burst",
620 .data = &printk_ratelimit_burst,
621 .maxlen = sizeof(int),
623 .proc_handler = &proc_dointvec,
626 .ctl_name = KERN_NGROUPS_MAX,
627 .procname = "ngroups_max",
628 .data = &ngroups_max,
629 .maxlen = sizeof (int),
631 .proc_handler = &proc_dointvec,
633 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
635 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
636 .procname = "unknown_nmi_panic",
637 .data = &unknown_nmi_panic,
638 .maxlen = sizeof (int),
640 .proc_handler = &proc_dointvec,
643 .procname = "nmi_watchdog",
644 .data = &nmi_watchdog_enabled,
645 .maxlen = sizeof (int),
647 .proc_handler = &proc_nmi_enabled,
650 #if defined(CONFIG_X86)
652 .ctl_name = KERN_PANIC_ON_NMI,
653 .procname = "panic_on_unrecovered_nmi",
654 .data = &panic_on_unrecovered_nmi,
655 .maxlen = sizeof(int),
657 .proc_handler = &proc_dointvec,
660 .ctl_name = KERN_BOOTLOADER_TYPE,
661 .procname = "bootloader_type",
662 .data = &bootloader_type,
663 .maxlen = sizeof (int),
665 .proc_handler = &proc_dointvec,
668 .ctl_name = CTL_UNNUMBERED,
669 .procname = "kstack_depth_to_print",
670 .data = &kstack_depth_to_print,
671 .maxlen = sizeof(int),
673 .proc_handler = &proc_dointvec,
676 #if defined(CONFIG_MMU)
678 .ctl_name = KERN_RANDOMIZE,
679 .procname = "randomize_va_space",
680 .data = &randomize_va_space,
681 .maxlen = sizeof(int),
683 .proc_handler = &proc_dointvec,
686 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
688 .ctl_name = KERN_SPIN_RETRY,
689 .procname = "spin_retry",
691 .maxlen = sizeof (int),
693 .proc_handler = &proc_dointvec,
696 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
698 .procname = "acpi_video_flags",
699 .data = &acpi_realmode_flags,
700 .maxlen = sizeof (unsigned long),
702 .proc_handler = &proc_doulongvec_minmax,
707 .ctl_name = KERN_IA64_UNALIGNED,
708 .procname = "ignore-unaligned-usertrap",
709 .data = &no_unaligned_warning,
710 .maxlen = sizeof (int),
712 .proc_handler = &proc_dointvec,
715 #ifdef CONFIG_DETECT_SOFTLOCKUP
717 .ctl_name = CTL_UNNUMBERED,
718 .procname = "softlockup_thresh",
719 .data = &softlockup_thresh,
720 .maxlen = sizeof(int),
722 .proc_handler = &proc_dointvec_minmax,
723 .strategy = &sysctl_intvec,
730 .ctl_name = KERN_COMPAT_LOG,
731 .procname = "compat-log",
733 .maxlen = sizeof (int),
735 .proc_handler = &proc_dointvec,
738 #ifdef CONFIG_RT_MUTEXES
740 .ctl_name = KERN_MAX_LOCK_DEPTH,
741 .procname = "max_lock_depth",
742 .data = &max_lock_depth,
743 .maxlen = sizeof(int),
745 .proc_handler = &proc_dointvec,
748 #ifdef CONFIG_PROC_FS
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "maps_protect",
752 .data = &maps_protect,
753 .maxlen = sizeof(int),
755 .proc_handler = &proc_dointvec,
759 .ctl_name = CTL_UNNUMBERED,
760 .procname = "poweroff_cmd",
761 .data = &poweroff_cmd,
762 .maxlen = POWEROFF_CMD_PATH_LEN,
764 .proc_handler = &proc_dostring,
765 .strategy = &sysctl_string,
768 * NOTE: do not add new entries to this table unless you have read
769 * Documentation/sysctl/ctl_unnumbered.txt
774 static struct ctl_table vm_table[] = {
776 .ctl_name = VM_OVERCOMMIT_MEMORY,
777 .procname = "overcommit_memory",
778 .data = &sysctl_overcommit_memory,
779 .maxlen = sizeof(sysctl_overcommit_memory),
781 .proc_handler = &proc_dointvec,
784 .ctl_name = VM_PANIC_ON_OOM,
785 .procname = "panic_on_oom",
786 .data = &sysctl_panic_on_oom,
787 .maxlen = sizeof(sysctl_panic_on_oom),
789 .proc_handler = &proc_dointvec,
792 .ctl_name = CTL_UNNUMBERED,
793 .procname = "oom_kill_allocating_task",
794 .data = &sysctl_oom_kill_allocating_task,
795 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
797 .proc_handler = &proc_dointvec,
800 .ctl_name = VM_OVERCOMMIT_RATIO,
801 .procname = "overcommit_ratio",
802 .data = &sysctl_overcommit_ratio,
803 .maxlen = sizeof(sysctl_overcommit_ratio),
805 .proc_handler = &proc_dointvec,
808 .ctl_name = VM_PAGE_CLUSTER,
809 .procname = "page-cluster",
810 .data = &page_cluster,
811 .maxlen = sizeof(int),
813 .proc_handler = &proc_dointvec,
816 .ctl_name = VM_DIRTY_BACKGROUND,
817 .procname = "dirty_background_ratio",
818 .data = &dirty_background_ratio,
819 .maxlen = sizeof(dirty_background_ratio),
821 .proc_handler = &proc_dointvec_minmax,
822 .strategy = &sysctl_intvec,
824 .extra2 = &one_hundred,
827 .ctl_name = VM_DIRTY_RATIO,
828 .procname = "dirty_ratio",
829 .data = &vm_dirty_ratio,
830 .maxlen = sizeof(vm_dirty_ratio),
832 .proc_handler = &dirty_ratio_handler,
833 .strategy = &sysctl_intvec,
835 .extra2 = &one_hundred,
838 .procname = "dirty_writeback_centisecs",
839 .data = &dirty_writeback_interval,
840 .maxlen = sizeof(dirty_writeback_interval),
842 .proc_handler = &dirty_writeback_centisecs_handler,
845 .procname = "dirty_expire_centisecs",
846 .data = &dirty_expire_interval,
847 .maxlen = sizeof(dirty_expire_interval),
849 .proc_handler = &proc_dointvec_userhz_jiffies,
852 .ctl_name = VM_NR_PDFLUSH_THREADS,
853 .procname = "nr_pdflush_threads",
854 .data = &nr_pdflush_threads,
855 .maxlen = sizeof nr_pdflush_threads,
856 .mode = 0444 /* read-only*/,
857 .proc_handler = &proc_dointvec,
860 .ctl_name = VM_SWAPPINESS,
861 .procname = "swappiness",
862 .data = &vm_swappiness,
863 .maxlen = sizeof(vm_swappiness),
865 .proc_handler = &proc_dointvec_minmax,
866 .strategy = &sysctl_intvec,
868 .extra2 = &one_hundred,
870 #ifdef CONFIG_HUGETLB_PAGE
872 .procname = "nr_hugepages",
873 .data = &max_huge_pages,
874 .maxlen = sizeof(unsigned long),
876 .proc_handler = &hugetlb_sysctl_handler,
877 .extra1 = (void *)&hugetlb_zero,
878 .extra2 = (void *)&hugetlb_infinity,
881 .ctl_name = VM_HUGETLB_GROUP,
882 .procname = "hugetlb_shm_group",
883 .data = &sysctl_hugetlb_shm_group,
884 .maxlen = sizeof(gid_t),
886 .proc_handler = &proc_dointvec,
889 .ctl_name = CTL_UNNUMBERED,
890 .procname = "hugepages_treat_as_movable",
891 .data = &hugepages_treat_as_movable,
892 .maxlen = sizeof(int),
894 .proc_handler = &hugetlb_treat_movable_handler,
897 .ctl_name = CTL_UNNUMBERED,
898 .procname = "hugetlb_dynamic_pool",
899 .data = &hugetlb_dynamic_pool,
900 .maxlen = sizeof(hugetlb_dynamic_pool),
902 .proc_handler = &proc_dointvec,
906 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
907 .procname = "lowmem_reserve_ratio",
908 .data = &sysctl_lowmem_reserve_ratio,
909 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
911 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
912 .strategy = &sysctl_intvec,
915 .ctl_name = VM_DROP_PAGECACHE,
916 .procname = "drop_caches",
917 .data = &sysctl_drop_caches,
918 .maxlen = sizeof(int),
920 .proc_handler = drop_caches_sysctl_handler,
921 .strategy = &sysctl_intvec,
924 .ctl_name = VM_MIN_FREE_KBYTES,
925 .procname = "min_free_kbytes",
926 .data = &min_free_kbytes,
927 .maxlen = sizeof(min_free_kbytes),
929 .proc_handler = &min_free_kbytes_sysctl_handler,
930 .strategy = &sysctl_intvec,
934 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
935 .procname = "percpu_pagelist_fraction",
936 .data = &percpu_pagelist_fraction,
937 .maxlen = sizeof(percpu_pagelist_fraction),
939 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
940 .strategy = &sysctl_intvec,
941 .extra1 = &min_percpu_pagelist_fract,
945 .ctl_name = VM_MAX_MAP_COUNT,
946 .procname = "max_map_count",
947 .data = &sysctl_max_map_count,
948 .maxlen = sizeof(sysctl_max_map_count),
950 .proc_handler = &proc_dointvec
954 .ctl_name = VM_LAPTOP_MODE,
955 .procname = "laptop_mode",
956 .data = &laptop_mode,
957 .maxlen = sizeof(laptop_mode),
959 .proc_handler = &proc_dointvec_jiffies,
960 .strategy = &sysctl_jiffies,
963 .ctl_name = VM_BLOCK_DUMP,
964 .procname = "block_dump",
966 .maxlen = sizeof(block_dump),
968 .proc_handler = &proc_dointvec,
969 .strategy = &sysctl_intvec,
973 .ctl_name = VM_VFS_CACHE_PRESSURE,
974 .procname = "vfs_cache_pressure",
975 .data = &sysctl_vfs_cache_pressure,
976 .maxlen = sizeof(sysctl_vfs_cache_pressure),
978 .proc_handler = &proc_dointvec,
979 .strategy = &sysctl_intvec,
982 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
984 .ctl_name = VM_LEGACY_VA_LAYOUT,
985 .procname = "legacy_va_layout",
986 .data = &sysctl_legacy_va_layout,
987 .maxlen = sizeof(sysctl_legacy_va_layout),
989 .proc_handler = &proc_dointvec,
990 .strategy = &sysctl_intvec,
996 .ctl_name = VM_ZONE_RECLAIM_MODE,
997 .procname = "zone_reclaim_mode",
998 .data = &zone_reclaim_mode,
999 .maxlen = sizeof(zone_reclaim_mode),
1001 .proc_handler = &proc_dointvec,
1002 .strategy = &sysctl_intvec,
1006 .ctl_name = VM_MIN_UNMAPPED,
1007 .procname = "min_unmapped_ratio",
1008 .data = &sysctl_min_unmapped_ratio,
1009 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1011 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1012 .strategy = &sysctl_intvec,
1014 .extra2 = &one_hundred,
1017 .ctl_name = VM_MIN_SLAB,
1018 .procname = "min_slab_ratio",
1019 .data = &sysctl_min_slab_ratio,
1020 .maxlen = sizeof(sysctl_min_slab_ratio),
1022 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1023 .strategy = &sysctl_intvec,
1025 .extra2 = &one_hundred,
1030 .ctl_name = CTL_UNNUMBERED,
1031 .procname = "stat_interval",
1032 .data = &sysctl_stat_interval,
1033 .maxlen = sizeof(sysctl_stat_interval),
1035 .proc_handler = &proc_dointvec_jiffies,
1036 .strategy = &sysctl_jiffies,
1039 #ifdef CONFIG_SECURITY
1041 .ctl_name = CTL_UNNUMBERED,
1042 .procname = "mmap_min_addr",
1043 .data = &mmap_min_addr,
1044 .maxlen = sizeof(unsigned long),
1046 .proc_handler = &proc_doulongvec_minmax,
1051 .ctl_name = CTL_UNNUMBERED,
1052 .procname = "numa_zonelist_order",
1053 .data = &numa_zonelist_order,
1054 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1056 .proc_handler = &numa_zonelist_order_handler,
1057 .strategy = &sysctl_string,
1060 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1061 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1063 .ctl_name = VM_VDSO_ENABLED,
1064 .procname = "vdso_enabled",
1065 .data = &vdso_enabled,
1066 .maxlen = sizeof(vdso_enabled),
1068 .proc_handler = &proc_dointvec,
1069 .strategy = &sysctl_intvec,
1074 * NOTE: do not add new entries to this table unless you have read
1075 * Documentation/sysctl/ctl_unnumbered.txt
1080 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1081 static struct ctl_table binfmt_misc_table[] = {
1086 static struct ctl_table fs_table[] = {
1088 .ctl_name = FS_NRINODE,
1089 .procname = "inode-nr",
1090 .data = &inodes_stat,
1091 .maxlen = 2*sizeof(int),
1093 .proc_handler = &proc_dointvec,
1096 .ctl_name = FS_STATINODE,
1097 .procname = "inode-state",
1098 .data = &inodes_stat,
1099 .maxlen = 7*sizeof(int),
1101 .proc_handler = &proc_dointvec,
1104 .procname = "file-nr",
1105 .data = &files_stat,
1106 .maxlen = 3*sizeof(int),
1108 .proc_handler = &proc_nr_files,
1111 .ctl_name = FS_MAXFILE,
1112 .procname = "file-max",
1113 .data = &files_stat.max_files,
1114 .maxlen = sizeof(int),
1116 .proc_handler = &proc_dointvec,
1119 .ctl_name = FS_DENTRY,
1120 .procname = "dentry-state",
1121 .data = &dentry_stat,
1122 .maxlen = 6*sizeof(int),
1124 .proc_handler = &proc_dointvec,
1127 .ctl_name = FS_OVERFLOWUID,
1128 .procname = "overflowuid",
1129 .data = &fs_overflowuid,
1130 .maxlen = sizeof(int),
1132 .proc_handler = &proc_dointvec_minmax,
1133 .strategy = &sysctl_intvec,
1134 .extra1 = &minolduid,
1135 .extra2 = &maxolduid,
1138 .ctl_name = FS_OVERFLOWGID,
1139 .procname = "overflowgid",
1140 .data = &fs_overflowgid,
1141 .maxlen = sizeof(int),
1143 .proc_handler = &proc_dointvec_minmax,
1144 .strategy = &sysctl_intvec,
1145 .extra1 = &minolduid,
1146 .extra2 = &maxolduid,
1149 .ctl_name = FS_LEASES,
1150 .procname = "leases-enable",
1151 .data = &leases_enable,
1152 .maxlen = sizeof(int),
1154 .proc_handler = &proc_dointvec,
1156 #ifdef CONFIG_DNOTIFY
1158 .ctl_name = FS_DIR_NOTIFY,
1159 .procname = "dir-notify-enable",
1160 .data = &dir_notify_enable,
1161 .maxlen = sizeof(int),
1163 .proc_handler = &proc_dointvec,
1168 .ctl_name = FS_LEASE_TIME,
1169 .procname = "lease-break-time",
1170 .data = &lease_break_time,
1171 .maxlen = sizeof(int),
1173 .proc_handler = &proc_dointvec_minmax,
1174 .strategy = &sysctl_intvec,
1179 .procname = "aio-nr",
1181 .maxlen = sizeof(aio_nr),
1183 .proc_handler = &proc_doulongvec_minmax,
1186 .procname = "aio-max-nr",
1187 .data = &aio_max_nr,
1188 .maxlen = sizeof(aio_max_nr),
1190 .proc_handler = &proc_doulongvec_minmax,
1192 #ifdef CONFIG_INOTIFY_USER
1194 .ctl_name = FS_INOTIFY,
1195 .procname = "inotify",
1197 .child = inotify_table,
1202 .ctl_name = KERN_SETUID_DUMPABLE,
1203 .procname = "suid_dumpable",
1204 .data = &suid_dumpable,
1205 .maxlen = sizeof(int),
1207 .proc_handler = &proc_dointvec,
1209 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1211 .ctl_name = CTL_UNNUMBERED,
1212 .procname = "binfmt_misc",
1214 .child = binfmt_misc_table,
1218 * NOTE: do not add new entries to this table unless you have read
1219 * Documentation/sysctl/ctl_unnumbered.txt
1224 static struct ctl_table debug_table[] = {
1225 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1227 .ctl_name = CTL_UNNUMBERED,
1228 .procname = "exception-trace",
1229 .data = &show_unhandled_signals,
1230 .maxlen = sizeof(int),
1232 .proc_handler = proc_dointvec
1238 static struct ctl_table dev_table[] = {
1242 static DEFINE_SPINLOCK(sysctl_lock);
1244 /* called under sysctl_lock */
1245 static int use_table(struct ctl_table_header *p)
1247 if (unlikely(p->unregistering))
1253 /* called under sysctl_lock */
1254 static void unuse_table(struct ctl_table_header *p)
1257 if (unlikely(p->unregistering))
1258 complete(p->unregistering);
1261 /* called under sysctl_lock, will reacquire if has to wait */
1262 static void start_unregistering(struct ctl_table_header *p)
1265 * if p->used is 0, nobody will ever touch that entry again;
1266 * we'll eliminate all paths to it before dropping sysctl_lock
1268 if (unlikely(p->used)) {
1269 struct completion wait;
1270 init_completion(&wait);
1271 p->unregistering = &wait;
1272 spin_unlock(&sysctl_lock);
1273 wait_for_completion(&wait);
1274 spin_lock(&sysctl_lock);
1277 * do not remove from the list until nobody holds it; walking the
1278 * list in do_sysctl() relies on that.
1280 list_del_init(&p->ctl_entry);
1283 void sysctl_head_finish(struct ctl_table_header *head)
1287 spin_lock(&sysctl_lock);
1289 spin_unlock(&sysctl_lock);
1292 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1294 struct ctl_table_header *head;
1295 struct list_head *tmp;
1296 spin_lock(&sysctl_lock);
1298 tmp = &prev->ctl_entry;
1302 tmp = &root_table_header.ctl_entry;
1304 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1306 if (!use_table(head))
1308 spin_unlock(&sysctl_lock);
1312 if (tmp == &root_table_header.ctl_entry)
1315 spin_unlock(&sysctl_lock);
1319 #ifdef CONFIG_SYSCTL_SYSCALL
1320 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1321 void __user *newval, size_t newlen)
1323 struct ctl_table_header *head;
1324 int error = -ENOTDIR;
1326 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1330 if (!oldlenp || get_user(old_len, oldlenp))
1334 for (head = sysctl_head_next(NULL); head;
1335 head = sysctl_head_next(head)) {
1336 error = parse_table(name, nlen, oldval, oldlenp,
1337 newval, newlen, head->ctl_table);
1338 if (error != -ENOTDIR) {
1339 sysctl_head_finish(head);
1346 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1348 struct __sysctl_args tmp;
1351 if (copy_from_user(&tmp, args, sizeof(tmp)))
1354 error = deprecated_sysctl_warning(&tmp);
1359 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1360 tmp.newval, tmp.newlen);
1365 #endif /* CONFIG_SYSCTL_SYSCALL */
1368 * sysctl_perm does NOT grant the superuser all rights automatically, because
1369 * some sysctl variables are readonly even to root.
1372 static int test_perm(int mode, int op)
1376 else if (in_egroup_p(0))
1378 if ((mode & op & 0007) == op)
1383 int sysctl_perm(struct ctl_table *table, int op)
1386 error = security_sysctl(table, op);
1389 return test_perm(table->mode, op);
1392 #ifdef CONFIG_SYSCTL_SYSCALL
1393 static int parse_table(int __user *name, int nlen,
1394 void __user *oldval, size_t __user *oldlenp,
1395 void __user *newval, size_t newlen,
1396 struct ctl_table *table)
1402 if (get_user(n, name))
1404 for ( ; table->ctl_name || table->procname; table++) {
1405 if (!table->ctl_name)
1407 if (n == table->ctl_name) {
1410 if (sysctl_perm(table, 001))
1414 table = table->child;
1417 error = do_sysctl_strategy(table, name, nlen,
1426 /* Perform the actual read/write of a sysctl table entry. */
1427 int do_sysctl_strategy (struct ctl_table *table,
1428 int __user *name, int nlen,
1429 void __user *oldval, size_t __user *oldlenp,
1430 void __user *newval, size_t newlen)
1438 if (sysctl_perm(table, op))
1441 if (table->strategy) {
1442 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1450 /* If there is no strategy routine, or if the strategy returns
1451 * zero, proceed with automatic r/w */
1452 if (table->data && table->maxlen) {
1453 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1460 #endif /* CONFIG_SYSCTL_SYSCALL */
1462 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1464 for (; table->ctl_name || table->procname; table++) {
1465 table->parent = parent;
1467 sysctl_set_parent(table, table->child);
1471 static __init int sysctl_init(void)
1474 sysctl_set_parent(NULL, root_table);
1475 err = sysctl_check_table(root_table);
1479 core_initcall(sysctl_init);
1482 * register_sysctl_table - register a sysctl hierarchy
1483 * @table: the top-level table structure
1485 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1486 * array. An entry with a ctl_name of 0 terminates the table.
1488 * The members of the &struct ctl_table structure are used as follows:
1490 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1491 * must be unique within that level of sysctl
1493 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1494 * enter a sysctl file
1496 * data - a pointer to data for use by proc_handler
1498 * maxlen - the maximum size in bytes of the data
1500 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1502 * child - a pointer to the child sysctl table if this entry is a directory, or
1505 * proc_handler - the text handler routine (described below)
1507 * strategy - the strategy routine (described below)
1509 * de - for internal use by the sysctl routines
1511 * extra1, extra2 - extra pointers usable by the proc handler routines
1513 * Leaf nodes in the sysctl tree will be represented by a single file
1514 * under /proc; non-leaf nodes will be represented by directories.
1516 * sysctl(2) can automatically manage read and write requests through
1517 * the sysctl table. The data and maxlen fields of the ctl_table
1518 * struct enable minimal validation of the values being written to be
1519 * performed, and the mode field allows minimal authentication.
1521 * More sophisticated management can be enabled by the provision of a
1522 * strategy routine with the table entry. This will be called before
1523 * any automatic read or write of the data is performed.
1525 * The strategy routine may return
1527 * < 0 - Error occurred (error is passed to user process)
1529 * 0 - OK - proceed with automatic read or write.
1531 * > 0 - OK - read or write has been done by the strategy routine, so
1532 * return immediately.
1534 * There must be a proc_handler routine for any terminal nodes
1535 * mirrored under /proc/sys (non-terminals are handled by a built-in
1536 * directory handler). Several default handlers are available to
1537 * cover common cases -
1539 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1540 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1541 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1543 * It is the handler's job to read the input buffer from user memory
1544 * and process it. The handler should return 0 on success.
1546 * This routine returns %NULL on a failure to register, and a pointer
1547 * to the table header on success.
1549 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1551 struct ctl_table_header *tmp;
1552 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1555 tmp->ctl_table = table;
1556 INIT_LIST_HEAD(&tmp->ctl_entry);
1558 tmp->unregistering = NULL;
1559 sysctl_set_parent(NULL, table);
1560 if (sysctl_check_table(tmp->ctl_table)) {
1564 spin_lock(&sysctl_lock);
1565 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1566 spin_unlock(&sysctl_lock);
1571 * unregister_sysctl_table - unregister a sysctl table hierarchy
1572 * @header: the header returned from register_sysctl_table
1574 * Unregisters the sysctl table and all children. proc entries may not
1575 * actually be removed until they are no longer used by anyone.
1577 void unregister_sysctl_table(struct ctl_table_header * header)
1580 spin_lock(&sysctl_lock);
1581 start_unregistering(header);
1582 spin_unlock(&sysctl_lock);
1586 #else /* !CONFIG_SYSCTL */
1587 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1592 void unregister_sysctl_table(struct ctl_table_header * table)
1596 #endif /* CONFIG_SYSCTL */
1602 #ifdef CONFIG_PROC_SYSCTL
1604 static int _proc_do_string(void* data, int maxlen, int write,
1605 struct file *filp, void __user *buffer,
1606 size_t *lenp, loff_t *ppos)
1612 if (!data || !maxlen || !*lenp) {
1620 while (len < *lenp) {
1621 if (get_user(c, p++))
1623 if (c == 0 || c == '\n')
1629 if(copy_from_user(data, buffer, len))
1631 ((char *) data)[len] = 0;
1649 if(copy_to_user(buffer, data, len))
1652 if(put_user('\n', ((char __user *) buffer) + len))
1663 * proc_dostring - read a string sysctl
1664 * @table: the sysctl table
1665 * @write: %TRUE if this is a write to the sysctl file
1666 * @filp: the file structure
1667 * @buffer: the user buffer
1668 * @lenp: the size of the user buffer
1669 * @ppos: file position
1671 * Reads/writes a string from/to the user buffer. If the kernel
1672 * buffer provided is not large enough to hold the string, the
1673 * string is truncated. The copied string is %NULL-terminated.
1674 * If the string is being read by the user process, it is copied
1675 * and a newline '\n' is added. It is truncated if the buffer is
1678 * Returns 0 on success.
1680 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1681 void __user *buffer, size_t *lenp, loff_t *ppos)
1683 return _proc_do_string(table->data, table->maxlen, write, filp,
1684 buffer, lenp, ppos);
1688 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1690 int write, void *data)
1693 *valp = *negp ? -*lvalp : *lvalp;
1698 *lvalp = (unsigned long)-val;
1701 *lvalp = (unsigned long)val;
1707 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1708 int write, struct file *filp, void __user *buffer,
1709 size_t *lenp, loff_t *ppos,
1710 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1711 int write, void *data),
1714 #define TMPBUFLEN 21
1715 int *i, vleft, first=1, neg, val;
1719 char buf[TMPBUFLEN], *p;
1720 char __user *s = buffer;
1722 if (!tbl_data || !table->maxlen || !*lenp ||
1723 (*ppos && !write)) {
1728 i = (int *) tbl_data;
1729 vleft = table->maxlen / sizeof(*i);
1733 conv = do_proc_dointvec_conv;
1735 for (; left && vleft--; i++, first=0) {
1750 if (len > sizeof(buf) - 1)
1751 len = sizeof(buf) - 1;
1752 if (copy_from_user(buf, s, len))
1756 if (*p == '-' && left > 1) {
1760 if (*p < '0' || *p > '9')
1763 lval = simple_strtoul(p, &p, 0);
1766 if ((len < left) && *p && !isspace(*p))
1773 if (conv(&neg, &lval, i, 1, data))
1780 if (conv(&neg, &lval, i, 0, data))
1783 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1787 if(copy_to_user(s, buf, len))
1794 if (!write && !first && left) {
1795 if(put_user('\n', s))
1802 if (get_user(c, s++))
1817 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1818 void __user *buffer, size_t *lenp, loff_t *ppos,
1819 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1820 int write, void *data),
1823 return __do_proc_dointvec(table->data, table, write, filp,
1824 buffer, lenp, ppos, conv, data);
1828 * proc_dointvec - read a vector of integers
1829 * @table: the sysctl table
1830 * @write: %TRUE if this is a write to the sysctl file
1831 * @filp: the file structure
1832 * @buffer: the user buffer
1833 * @lenp: the size of the user buffer
1834 * @ppos: file position
1836 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1837 * values from/to the user buffer, treated as an ASCII string.
1839 * Returns 0 on success.
1841 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1842 void __user *buffer, size_t *lenp, loff_t *ppos)
1844 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1852 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1854 int write, void *data)
1856 int op = *(int *)data;
1858 int val = *negp ? -*lvalp : *lvalp;
1860 case OP_SET: *valp = val; break;
1861 case OP_AND: *valp &= val; break;
1862 case OP_OR: *valp |= val; break;
1868 *lvalp = (unsigned long)-val;
1871 *lvalp = (unsigned long)val;
1877 #ifdef CONFIG_SECURITY_CAPABILITIES
1879 * init may raise the set.
1882 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1883 void __user *buffer, size_t *lenp, loff_t *ppos)
1887 if (write && !capable(CAP_SYS_MODULE)) {
1891 op = is_init(current) ? OP_SET : OP_AND;
1892 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1893 do_proc_dointvec_bset_conv,&op);
1895 #endif /* def CONFIG_SECURITY_CAPABILITIES */
1898 * Taint values can only be increased
1900 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1901 void __user *buffer, size_t *lenp, loff_t *ppos)
1905 if (write && !capable(CAP_SYS_ADMIN))
1909 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1910 do_proc_dointvec_bset_conv,&op);
1913 struct do_proc_dointvec_minmax_conv_param {
1918 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1920 int write, void *data)
1922 struct do_proc_dointvec_minmax_conv_param *param = data;
1924 int val = *negp ? -*lvalp : *lvalp;
1925 if ((param->min && *param->min > val) ||
1926 (param->max && *param->max < val))
1933 *lvalp = (unsigned long)-val;
1936 *lvalp = (unsigned long)val;
1943 * proc_dointvec_minmax - read a vector of integers with min/max values
1944 * @table: the sysctl table
1945 * @write: %TRUE if this is a write to the sysctl file
1946 * @filp: the file structure
1947 * @buffer: the user buffer
1948 * @lenp: the size of the user buffer
1949 * @ppos: file position
1951 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1952 * values from/to the user buffer, treated as an ASCII string.
1954 * This routine will ensure the values are within the range specified by
1955 * table->extra1 (min) and table->extra2 (max).
1957 * Returns 0 on success.
1959 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1960 void __user *buffer, size_t *lenp, loff_t *ppos)
1962 struct do_proc_dointvec_minmax_conv_param param = {
1963 .min = (int *) table->extra1,
1964 .max = (int *) table->extra2,
1966 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1967 do_proc_dointvec_minmax_conv, ¶m);
1970 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1972 void __user *buffer,
1973 size_t *lenp, loff_t *ppos,
1974 unsigned long convmul,
1975 unsigned long convdiv)
1977 #define TMPBUFLEN 21
1978 unsigned long *i, *min, *max, val;
1979 int vleft, first=1, neg;
1981 char buf[TMPBUFLEN], *p;
1982 char __user *s = buffer;
1984 if (!data || !table->maxlen || !*lenp ||
1985 (*ppos && !write)) {
1990 i = (unsigned long *) data;
1991 min = (unsigned long *) table->extra1;
1992 max = (unsigned long *) table->extra2;
1993 vleft = table->maxlen / sizeof(unsigned long);
1996 for (; left && vleft--; i++, min++, max++, first=0) {
2011 if (len > TMPBUFLEN-1)
2013 if (copy_from_user(buf, s, len))
2017 if (*p == '-' && left > 1) {
2021 if (*p < '0' || *p > '9')
2023 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2025 if ((len < left) && *p && !isspace(*p))
2034 if ((min && val < *min) || (max && val > *max))
2041 sprintf(p, "%lu", convdiv * (*i) / convmul);
2045 if(copy_to_user(s, buf, len))
2052 if (!write && !first && left) {
2053 if(put_user('\n', s))
2060 if (get_user(c, s++))
2075 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2077 void __user *buffer,
2078 size_t *lenp, loff_t *ppos,
2079 unsigned long convmul,
2080 unsigned long convdiv)
2082 return __do_proc_doulongvec_minmax(table->data, table, write,
2083 filp, buffer, lenp, ppos, convmul, convdiv);
2087 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2088 * @table: the sysctl table
2089 * @write: %TRUE if this is a write to the sysctl file
2090 * @filp: the file structure
2091 * @buffer: the user buffer
2092 * @lenp: the size of the user buffer
2093 * @ppos: file position
2095 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2096 * values from/to the user buffer, treated as an ASCII string.
2098 * This routine will ensure the values are within the range specified by
2099 * table->extra1 (min) and table->extra2 (max).
2101 * Returns 0 on success.
2103 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2104 void __user *buffer, size_t *lenp, loff_t *ppos)
2106 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2110 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2111 * @table: the sysctl table
2112 * @write: %TRUE if this is a write to the sysctl file
2113 * @filp: the file structure
2114 * @buffer: the user buffer
2115 * @lenp: the size of the user buffer
2116 * @ppos: file position
2118 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2119 * values from/to the user buffer, treated as an ASCII string. The values
2120 * are treated as milliseconds, and converted to jiffies when they are stored.
2122 * This routine will ensure the values are within the range specified by
2123 * table->extra1 (min) and table->extra2 (max).
2125 * Returns 0 on success.
2127 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2129 void __user *buffer,
2130 size_t *lenp, loff_t *ppos)
2132 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2133 lenp, ppos, HZ, 1000l);
2137 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2139 int write, void *data)
2142 if (*lvalp > LONG_MAX / HZ)
2144 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2150 lval = (unsigned long)-val;
2153 lval = (unsigned long)val;
2160 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2162 int write, void *data)
2165 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2167 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2173 lval = (unsigned long)-val;
2176 lval = (unsigned long)val;
2178 *lvalp = jiffies_to_clock_t(lval);
2183 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2185 int write, void *data)
2188 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2194 lval = (unsigned long)-val;
2197 lval = (unsigned long)val;
2199 *lvalp = jiffies_to_msecs(lval);
2205 * proc_dointvec_jiffies - read a vector of integers as seconds
2206 * @table: the sysctl table
2207 * @write: %TRUE if this is a write to the sysctl file
2208 * @filp: the file structure
2209 * @buffer: the user buffer
2210 * @lenp: the size of the user buffer
2211 * @ppos: file position
2213 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2214 * values from/to the user buffer, treated as an ASCII string.
2215 * The values read are assumed to be in seconds, and are converted into
2218 * Returns 0 on success.
2220 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2221 void __user *buffer, size_t *lenp, loff_t *ppos)
2223 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2224 do_proc_dointvec_jiffies_conv,NULL);
2228 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
2231 * @filp: the file structure
2232 * @buffer: the user buffer
2233 * @lenp: the size of the user buffer
2234 * @ppos: pointer to the file position
2236 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2237 * values from/to the user buffer, treated as an ASCII string.
2238 * The values read are assumed to be in 1/USER_HZ seconds, and
2239 * are converted into jiffies.
2241 * Returns 0 on success.
2243 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2244 void __user *buffer, size_t *lenp, loff_t *ppos)
2246 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2247 do_proc_dointvec_userhz_jiffies_conv,NULL);
2251 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2252 * @table: the sysctl table
2253 * @write: %TRUE if this is a write to the sysctl file
2254 * @filp: the file structure
2255 * @buffer: the user buffer
2256 * @lenp: the size of the user buffer
2257 * @ppos: file position
2258 * @ppos: the current position in the file
2260 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2261 * values from/to the user buffer, treated as an ASCII string.
2262 * The values read are assumed to be in 1/1000 seconds, and
2263 * are converted into jiffies.
2265 * Returns 0 on success.
2267 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2268 void __user *buffer, size_t *lenp, loff_t *ppos)
2270 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2271 do_proc_dointvec_ms_jiffies_conv, NULL);
2274 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2275 void __user *buffer, size_t *lenp, loff_t *ppos)
2277 struct pid *new_pid;
2281 tmp = pid_nr(cad_pid);
2283 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2284 lenp, ppos, NULL, NULL);
2288 new_pid = find_get_pid(tmp);
2292 put_pid(xchg(&cad_pid, new_pid));
2296 #else /* CONFIG_PROC_FS */
2298 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2299 void __user *buffer, size_t *lenp, loff_t *ppos)
2304 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2310 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2311 void __user *buffer, size_t *lenp, loff_t *ppos)
2316 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2317 void __user *buffer, size_t *lenp, loff_t *ppos)
2322 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2323 void __user *buffer, size_t *lenp, loff_t *ppos)
2328 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2329 void __user *buffer, size_t *lenp, loff_t *ppos)
2334 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2335 void __user *buffer, size_t *lenp, loff_t *ppos)
2340 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2341 void __user *buffer, size_t *lenp, loff_t *ppos)
2346 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2348 void __user *buffer,
2349 size_t *lenp, loff_t *ppos)
2355 #endif /* CONFIG_PROC_FS */
2358 #ifdef CONFIG_SYSCTL_SYSCALL
2360 * General sysctl support routines
2363 /* The generic sysctl data routine (used if no strategy routine supplied) */
2364 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2365 void __user *oldval, size_t __user *oldlenp,
2366 void __user *newval, size_t newlen)
2370 /* Get out of I don't have a variable */
2371 if (!table->data || !table->maxlen)
2374 if (oldval && oldlenp) {
2375 if (get_user(len, oldlenp))
2378 if (len > table->maxlen)
2379 len = table->maxlen;
2380 if (copy_to_user(oldval, table->data, len))
2382 if (put_user(len, oldlenp))
2387 if (newval && newlen) {
2388 if (newlen > table->maxlen)
2389 newlen = table->maxlen;
2391 if (copy_from_user(table->data, newval, newlen))
2397 /* The generic string strategy routine: */
2398 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2399 void __user *oldval, size_t __user *oldlenp,
2400 void __user *newval, size_t newlen)
2402 if (!table->data || !table->maxlen)
2405 if (oldval && oldlenp) {
2407 if (get_user(bufsize, oldlenp))
2410 size_t len = strlen(table->data), copied;
2412 /* This shouldn't trigger for a well-formed sysctl */
2413 if (len > table->maxlen)
2414 len = table->maxlen;
2416 /* Copy up to a max of bufsize-1 bytes of the string */
2417 copied = (len >= bufsize) ? bufsize - 1 : len;
2419 if (copy_to_user(oldval, table->data, copied) ||
2420 put_user(0, (char __user *)(oldval + copied)))
2422 if (put_user(len, oldlenp))
2426 if (newval && newlen) {
2427 size_t len = newlen;
2428 if (len > table->maxlen)
2429 len = table->maxlen;
2430 if(copy_from_user(table->data, newval, len))
2432 if (len == table->maxlen)
2434 ((char *) table->data)[len] = 0;
2440 * This function makes sure that all of the integers in the vector
2441 * are between the minimum and maximum values given in the arrays
2442 * table->extra1 and table->extra2, respectively.
2444 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2445 void __user *oldval, size_t __user *oldlenp,
2446 void __user *newval, size_t newlen)
2449 if (newval && newlen) {
2450 int __user *vec = (int __user *) newval;
2451 int *min = (int *) table->extra1;
2452 int *max = (int *) table->extra2;
2456 if (newlen % sizeof(int) != 0)
2459 if (!table->extra1 && !table->extra2)
2462 if (newlen > table->maxlen)
2463 newlen = table->maxlen;
2464 length = newlen / sizeof(int);
2466 for (i = 0; i < length; i++) {
2468 if (get_user(value, vec + i))
2470 if (min && value < min[i])
2472 if (max && value > max[i])
2479 /* Strategy function to convert jiffies to seconds */
2480 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2481 void __user *oldval, size_t __user *oldlenp,
2482 void __user *newval, size_t newlen)
2484 if (oldval && oldlenp) {
2487 if (get_user(olen, oldlenp))
2492 if (olen < sizeof(int))
2495 val = *(int *)(table->data) / HZ;
2496 if (put_user(val, (int __user *)oldval))
2498 if (put_user(sizeof(int), oldlenp))
2502 if (newval && newlen) {
2504 if (newlen != sizeof(int))
2506 if (get_user(new, (int __user *)newval))
2508 *(int *)(table->data) = new*HZ;
2513 /* Strategy function to convert jiffies to seconds */
2514 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2515 void __user *oldval, size_t __user *oldlenp,
2516 void __user *newval, size_t newlen)
2518 if (oldval && oldlenp) {
2521 if (get_user(olen, oldlenp))
2526 if (olen < sizeof(int))
2529 val = jiffies_to_msecs(*(int *)(table->data));
2530 if (put_user(val, (int __user *)oldval))
2532 if (put_user(sizeof(int), oldlenp))
2536 if (newval && newlen) {
2538 if (newlen != sizeof(int))
2540 if (get_user(new, (int __user *)newval))
2542 *(int *)(table->data) = msecs_to_jiffies(new);
2549 #else /* CONFIG_SYSCTL_SYSCALL */
2552 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2554 struct __sysctl_args tmp;
2557 if (copy_from_user(&tmp, args, sizeof(tmp)))
2560 error = deprecated_sysctl_warning(&tmp);
2562 /* If no error reading the parameters then just -ENOSYS ... */
2569 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2570 void __user *oldval, size_t __user *oldlenp,
2571 void __user *newval, size_t newlen)
2576 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2577 void __user *oldval, size_t __user *oldlenp,
2578 void __user *newval, size_t newlen)
2583 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2584 void __user *oldval, size_t __user *oldlenp,
2585 void __user *newval, size_t newlen)
2590 int sysctl_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)
2597 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2598 void __user *oldval, size_t __user *oldlenp,
2599 void __user *newval, size_t newlen)
2604 #endif /* CONFIG_SYSCTL_SYSCALL */
2606 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2608 static int msg_count;
2609 int name[CTL_MAXNAME];
2612 /* Read in the sysctl name for better debug message logging */
2613 for (i = 0; i < args->nlen; i++)
2614 if (get_user(name[i], args->name + i))
2617 /* Ignore accesses to kernel.version */
2618 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2621 if (msg_count < 5) {
2624 "warning: process `%s' used the deprecated sysctl "
2625 "system call with ", current->comm);
2626 for (i = 0; i < args->nlen; i++)
2627 printk("%d.", name[i]);
2634 * No sense putting this after each symbol definition, twice,
2635 * exception granted :-)
2637 EXPORT_SYMBOL(proc_dointvec);
2638 EXPORT_SYMBOL(proc_dointvec_jiffies);
2639 EXPORT_SYMBOL(proc_dointvec_minmax);
2640 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2641 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2642 EXPORT_SYMBOL(proc_dostring);
2643 EXPORT_SYMBOL(proc_doulongvec_minmax);
2644 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2645 EXPORT_SYMBOL(register_sysctl_table);
2646 EXPORT_SYMBOL(sysctl_intvec);
2647 EXPORT_SYMBOL(sysctl_jiffies);
2648 EXPORT_SYMBOL(sysctl_ms_jiffies);
2649 EXPORT_SYMBOL(sysctl_string);
2650 EXPORT_SYMBOL(sysctl_data);
2651 EXPORT_SYMBOL(unregister_sysctl_table);