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,
312 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_min_bal_int_shares",
316 .data = &sysctl_sched_min_bal_int_shares,
317 .maxlen = sizeof(unsigned int),
319 .proc_handler = &proc_dointvec,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_max_bal_int_shares",
324 .data = &sysctl_sched_max_bal_int_shares,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = &proc_dointvec,
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_compat_yield",
334 .data = &sysctl_sched_compat_yield,
335 .maxlen = sizeof(unsigned int),
337 .proc_handler = &proc_dointvec,
339 #ifdef CONFIG_PROVE_LOCKING
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "prove_locking",
343 .data = &prove_locking,
344 .maxlen = sizeof(int),
346 .proc_handler = &proc_dointvec,
349 #ifdef CONFIG_LOCK_STAT
351 .ctl_name = CTL_UNNUMBERED,
352 .procname = "lock_stat",
354 .maxlen = sizeof(int),
356 .proc_handler = &proc_dointvec,
360 .ctl_name = KERN_PANIC,
362 .data = &panic_timeout,
363 .maxlen = sizeof(int),
365 .proc_handler = &proc_dointvec,
368 .ctl_name = KERN_CORE_USES_PID,
369 .procname = "core_uses_pid",
370 .data = &core_uses_pid,
371 .maxlen = sizeof(int),
373 .proc_handler = &proc_dointvec,
375 #ifdef CONFIG_AUDITSYSCALL
377 .ctl_name = CTL_UNNUMBERED,
378 .procname = "audit_argv_kb",
379 .data = &audit_argv_kb,
380 .maxlen = sizeof(int),
382 .proc_handler = &proc_dointvec,
386 .ctl_name = KERN_CORE_PATTERN,
387 .procname = "core_pattern",
388 .data = core_pattern,
389 .maxlen = CORENAME_MAX_SIZE,
391 .proc_handler = &proc_dostring,
392 .strategy = &sysctl_string,
394 #ifdef CONFIG_PROC_SYSCTL
396 .procname = "tainted",
398 .maxlen = sizeof(int),
400 .proc_handler = &proc_dointvec_taint,
403 #ifdef CONFIG_SECURITY_CAPABILITIES
405 .procname = "cap-bound",
407 .maxlen = sizeof(kernel_cap_t),
409 .proc_handler = &proc_dointvec_bset,
411 #endif /* def CONFIG_SECURITY_CAPABILITIES */
412 #ifdef CONFIG_BLK_DEV_INITRD
414 .ctl_name = KERN_REALROOTDEV,
415 .procname = "real-root-dev",
416 .data = &real_root_dev,
417 .maxlen = sizeof(int),
419 .proc_handler = &proc_dointvec,
423 .ctl_name = CTL_UNNUMBERED,
424 .procname = "print-fatal-signals",
425 .data = &print_fatal_signals,
426 .maxlen = sizeof(int),
428 .proc_handler = &proc_dointvec,
432 .ctl_name = KERN_SPARC_REBOOT,
433 .procname = "reboot-cmd",
434 .data = reboot_command,
437 .proc_handler = &proc_dostring,
438 .strategy = &sysctl_string,
441 .ctl_name = KERN_SPARC_STOP_A,
442 .procname = "stop-a",
443 .data = &stop_a_enabled,
444 .maxlen = sizeof (int),
446 .proc_handler = &proc_dointvec,
449 .ctl_name = KERN_SPARC_SCONS_PWROFF,
450 .procname = "scons-poweroff",
451 .data = &scons_pwroff,
452 .maxlen = sizeof (int),
454 .proc_handler = &proc_dointvec,
459 .ctl_name = KERN_HPPA_PWRSW,
460 .procname = "soft-power",
461 .data = &pwrsw_enabled,
462 .maxlen = sizeof (int),
464 .proc_handler = &proc_dointvec,
467 .ctl_name = KERN_HPPA_UNALIGNED,
468 .procname = "unaligned-trap",
469 .data = &unaligned_enabled,
470 .maxlen = sizeof (int),
472 .proc_handler = &proc_dointvec,
476 .ctl_name = KERN_CTLALTDEL,
477 .procname = "ctrl-alt-del",
479 .maxlen = sizeof(int),
481 .proc_handler = &proc_dointvec,
484 .ctl_name = KERN_PRINTK,
485 .procname = "printk",
486 .data = &console_loglevel,
487 .maxlen = 4*sizeof(int),
489 .proc_handler = &proc_dointvec,
493 .ctl_name = KERN_MODPROBE,
494 .procname = "modprobe",
495 .data = &modprobe_path,
496 .maxlen = KMOD_PATH_LEN,
498 .proc_handler = &proc_dostring,
499 .strategy = &sysctl_string,
502 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
504 .ctl_name = KERN_HOTPLUG,
505 .procname = "hotplug",
506 .data = &uevent_helper,
507 .maxlen = UEVENT_HELPER_PATH_LEN,
509 .proc_handler = &proc_dostring,
510 .strategy = &sysctl_string,
513 #ifdef CONFIG_CHR_DEV_SG
515 .ctl_name = KERN_SG_BIG_BUFF,
516 .procname = "sg-big-buff",
517 .data = &sg_big_buff,
518 .maxlen = sizeof (int),
520 .proc_handler = &proc_dointvec,
523 #ifdef CONFIG_BSD_PROCESS_ACCT
525 .ctl_name = KERN_ACCT,
528 .maxlen = 3*sizeof(int),
530 .proc_handler = &proc_dointvec,
533 #ifdef CONFIG_MAGIC_SYSRQ
535 .ctl_name = KERN_SYSRQ,
537 .data = &__sysrq_enabled,
538 .maxlen = sizeof (int),
540 .proc_handler = &proc_dointvec,
543 #ifdef CONFIG_PROC_SYSCTL
545 .procname = "cad_pid",
547 .maxlen = sizeof (int),
549 .proc_handler = &proc_do_cad_pid,
553 .ctl_name = KERN_MAX_THREADS,
554 .procname = "threads-max",
555 .data = &max_threads,
556 .maxlen = sizeof(int),
558 .proc_handler = &proc_dointvec,
561 .ctl_name = KERN_RANDOM,
562 .procname = "random",
564 .child = random_table,
567 .ctl_name = KERN_OVERFLOWUID,
568 .procname = "overflowuid",
569 .data = &overflowuid,
570 .maxlen = sizeof(int),
572 .proc_handler = &proc_dointvec_minmax,
573 .strategy = &sysctl_intvec,
574 .extra1 = &minolduid,
575 .extra2 = &maxolduid,
578 .ctl_name = KERN_OVERFLOWGID,
579 .procname = "overflowgid",
580 .data = &overflowgid,
581 .maxlen = sizeof(int),
583 .proc_handler = &proc_dointvec_minmax,
584 .strategy = &sysctl_intvec,
585 .extra1 = &minolduid,
586 .extra2 = &maxolduid,
589 #ifdef CONFIG_MATHEMU
591 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
592 .procname = "ieee_emulation_warnings",
593 .data = &sysctl_ieee_emulation_warnings,
594 .maxlen = sizeof(int),
596 .proc_handler = &proc_dointvec,
599 #ifdef CONFIG_NO_IDLE_HZ
601 .ctl_name = KERN_HZ_TIMER,
602 .procname = "hz_timer",
603 .data = &sysctl_hz_timer,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
610 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
611 .procname = "userprocess_debug",
612 .data = &sysctl_userprocess_debug,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
619 .ctl_name = KERN_PIDMAX,
620 .procname = "pid_max",
622 .maxlen = sizeof (int),
624 .proc_handler = &proc_dointvec_minmax,
625 .strategy = sysctl_intvec,
626 .extra1 = &pid_max_min,
627 .extra2 = &pid_max_max,
630 .ctl_name = KERN_PANIC_ON_OOPS,
631 .procname = "panic_on_oops",
632 .data = &panic_on_oops,
633 .maxlen = sizeof(int),
635 .proc_handler = &proc_dointvec,
638 .ctl_name = KERN_PRINTK_RATELIMIT,
639 .procname = "printk_ratelimit",
640 .data = &printk_ratelimit_jiffies,
641 .maxlen = sizeof(int),
643 .proc_handler = &proc_dointvec_jiffies,
644 .strategy = &sysctl_jiffies,
647 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
648 .procname = "printk_ratelimit_burst",
649 .data = &printk_ratelimit_burst,
650 .maxlen = sizeof(int),
652 .proc_handler = &proc_dointvec,
655 .ctl_name = KERN_NGROUPS_MAX,
656 .procname = "ngroups_max",
657 .data = &ngroups_max,
658 .maxlen = sizeof (int),
660 .proc_handler = &proc_dointvec,
662 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
664 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
665 .procname = "unknown_nmi_panic",
666 .data = &unknown_nmi_panic,
667 .maxlen = sizeof (int),
669 .proc_handler = &proc_dointvec,
672 .procname = "nmi_watchdog",
673 .data = &nmi_watchdog_enabled,
674 .maxlen = sizeof (int),
676 .proc_handler = &proc_nmi_enabled,
679 #if defined(CONFIG_X86)
681 .ctl_name = KERN_PANIC_ON_NMI,
682 .procname = "panic_on_unrecovered_nmi",
683 .data = &panic_on_unrecovered_nmi,
684 .maxlen = sizeof(int),
686 .proc_handler = &proc_dointvec,
689 .ctl_name = KERN_BOOTLOADER_TYPE,
690 .procname = "bootloader_type",
691 .data = &bootloader_type,
692 .maxlen = sizeof (int),
694 .proc_handler = &proc_dointvec,
697 .ctl_name = CTL_UNNUMBERED,
698 .procname = "kstack_depth_to_print",
699 .data = &kstack_depth_to_print,
700 .maxlen = sizeof(int),
702 .proc_handler = &proc_dointvec,
705 #if defined(CONFIG_MMU)
707 .ctl_name = KERN_RANDOMIZE,
708 .procname = "randomize_va_space",
709 .data = &randomize_va_space,
710 .maxlen = sizeof(int),
712 .proc_handler = &proc_dointvec,
715 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
717 .ctl_name = KERN_SPIN_RETRY,
718 .procname = "spin_retry",
720 .maxlen = sizeof (int),
722 .proc_handler = &proc_dointvec,
725 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
727 .procname = "acpi_video_flags",
728 .data = &acpi_realmode_flags,
729 .maxlen = sizeof (unsigned long),
731 .proc_handler = &proc_doulongvec_minmax,
736 .ctl_name = KERN_IA64_UNALIGNED,
737 .procname = "ignore-unaligned-usertrap",
738 .data = &no_unaligned_warning,
739 .maxlen = sizeof (int),
741 .proc_handler = &proc_dointvec,
744 #ifdef CONFIG_DETECT_SOFTLOCKUP
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "softlockup_thresh",
748 .data = &softlockup_thresh,
749 .maxlen = sizeof(int),
751 .proc_handler = &proc_dointvec_minmax,
752 .strategy = &sysctl_intvec,
759 .ctl_name = KERN_COMPAT_LOG,
760 .procname = "compat-log",
762 .maxlen = sizeof (int),
764 .proc_handler = &proc_dointvec,
767 #ifdef CONFIG_RT_MUTEXES
769 .ctl_name = KERN_MAX_LOCK_DEPTH,
770 .procname = "max_lock_depth",
771 .data = &max_lock_depth,
772 .maxlen = sizeof(int),
774 .proc_handler = &proc_dointvec,
777 #ifdef CONFIG_PROC_FS
779 .ctl_name = CTL_UNNUMBERED,
780 .procname = "maps_protect",
781 .data = &maps_protect,
782 .maxlen = sizeof(int),
784 .proc_handler = &proc_dointvec,
788 .ctl_name = CTL_UNNUMBERED,
789 .procname = "poweroff_cmd",
790 .data = &poweroff_cmd,
791 .maxlen = POWEROFF_CMD_PATH_LEN,
793 .proc_handler = &proc_dostring,
794 .strategy = &sysctl_string,
797 * NOTE: do not add new entries to this table unless you have read
798 * Documentation/sysctl/ctl_unnumbered.txt
803 static struct ctl_table vm_table[] = {
805 .ctl_name = VM_OVERCOMMIT_MEMORY,
806 .procname = "overcommit_memory",
807 .data = &sysctl_overcommit_memory,
808 .maxlen = sizeof(sysctl_overcommit_memory),
810 .proc_handler = &proc_dointvec,
813 .ctl_name = VM_PANIC_ON_OOM,
814 .procname = "panic_on_oom",
815 .data = &sysctl_panic_on_oom,
816 .maxlen = sizeof(sysctl_panic_on_oom),
818 .proc_handler = &proc_dointvec,
821 .ctl_name = CTL_UNNUMBERED,
822 .procname = "oom_kill_allocating_task",
823 .data = &sysctl_oom_kill_allocating_task,
824 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
826 .proc_handler = &proc_dointvec,
829 .ctl_name = VM_OVERCOMMIT_RATIO,
830 .procname = "overcommit_ratio",
831 .data = &sysctl_overcommit_ratio,
832 .maxlen = sizeof(sysctl_overcommit_ratio),
834 .proc_handler = &proc_dointvec,
837 .ctl_name = VM_PAGE_CLUSTER,
838 .procname = "page-cluster",
839 .data = &page_cluster,
840 .maxlen = sizeof(int),
842 .proc_handler = &proc_dointvec,
845 .ctl_name = VM_DIRTY_BACKGROUND,
846 .procname = "dirty_background_ratio",
847 .data = &dirty_background_ratio,
848 .maxlen = sizeof(dirty_background_ratio),
850 .proc_handler = &proc_dointvec_minmax,
851 .strategy = &sysctl_intvec,
853 .extra2 = &one_hundred,
856 .ctl_name = VM_DIRTY_RATIO,
857 .procname = "dirty_ratio",
858 .data = &vm_dirty_ratio,
859 .maxlen = sizeof(vm_dirty_ratio),
861 .proc_handler = &dirty_ratio_handler,
862 .strategy = &sysctl_intvec,
864 .extra2 = &one_hundred,
867 .procname = "dirty_writeback_centisecs",
868 .data = &dirty_writeback_interval,
869 .maxlen = sizeof(dirty_writeback_interval),
871 .proc_handler = &dirty_writeback_centisecs_handler,
874 .procname = "dirty_expire_centisecs",
875 .data = &dirty_expire_interval,
876 .maxlen = sizeof(dirty_expire_interval),
878 .proc_handler = &proc_dointvec_userhz_jiffies,
881 .ctl_name = VM_NR_PDFLUSH_THREADS,
882 .procname = "nr_pdflush_threads",
883 .data = &nr_pdflush_threads,
884 .maxlen = sizeof nr_pdflush_threads,
885 .mode = 0444 /* read-only*/,
886 .proc_handler = &proc_dointvec,
889 .ctl_name = VM_SWAPPINESS,
890 .procname = "swappiness",
891 .data = &vm_swappiness,
892 .maxlen = sizeof(vm_swappiness),
894 .proc_handler = &proc_dointvec_minmax,
895 .strategy = &sysctl_intvec,
897 .extra2 = &one_hundred,
899 #ifdef CONFIG_HUGETLB_PAGE
901 .procname = "nr_hugepages",
902 .data = &max_huge_pages,
903 .maxlen = sizeof(unsigned long),
905 .proc_handler = &hugetlb_sysctl_handler,
906 .extra1 = (void *)&hugetlb_zero,
907 .extra2 = (void *)&hugetlb_infinity,
910 .ctl_name = VM_HUGETLB_GROUP,
911 .procname = "hugetlb_shm_group",
912 .data = &sysctl_hugetlb_shm_group,
913 .maxlen = sizeof(gid_t),
915 .proc_handler = &proc_dointvec,
918 .ctl_name = CTL_UNNUMBERED,
919 .procname = "hugepages_treat_as_movable",
920 .data = &hugepages_treat_as_movable,
921 .maxlen = sizeof(int),
923 .proc_handler = &hugetlb_treat_movable_handler,
926 .ctl_name = CTL_UNNUMBERED,
927 .procname = "nr_overcommit_hugepages",
928 .data = &nr_overcommit_huge_pages,
929 .maxlen = sizeof(nr_overcommit_huge_pages),
931 .proc_handler = &proc_doulongvec_minmax,
935 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
936 .procname = "lowmem_reserve_ratio",
937 .data = &sysctl_lowmem_reserve_ratio,
938 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
940 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
941 .strategy = &sysctl_intvec,
944 .ctl_name = VM_DROP_PAGECACHE,
945 .procname = "drop_caches",
946 .data = &sysctl_drop_caches,
947 .maxlen = sizeof(int),
949 .proc_handler = drop_caches_sysctl_handler,
950 .strategy = &sysctl_intvec,
953 .ctl_name = VM_MIN_FREE_KBYTES,
954 .procname = "min_free_kbytes",
955 .data = &min_free_kbytes,
956 .maxlen = sizeof(min_free_kbytes),
958 .proc_handler = &min_free_kbytes_sysctl_handler,
959 .strategy = &sysctl_intvec,
963 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
964 .procname = "percpu_pagelist_fraction",
965 .data = &percpu_pagelist_fraction,
966 .maxlen = sizeof(percpu_pagelist_fraction),
968 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
969 .strategy = &sysctl_intvec,
970 .extra1 = &min_percpu_pagelist_fract,
974 .ctl_name = VM_MAX_MAP_COUNT,
975 .procname = "max_map_count",
976 .data = &sysctl_max_map_count,
977 .maxlen = sizeof(sysctl_max_map_count),
979 .proc_handler = &proc_dointvec
983 .ctl_name = VM_LAPTOP_MODE,
984 .procname = "laptop_mode",
985 .data = &laptop_mode,
986 .maxlen = sizeof(laptop_mode),
988 .proc_handler = &proc_dointvec_jiffies,
989 .strategy = &sysctl_jiffies,
992 .ctl_name = VM_BLOCK_DUMP,
993 .procname = "block_dump",
995 .maxlen = sizeof(block_dump),
997 .proc_handler = &proc_dointvec,
998 .strategy = &sysctl_intvec,
1002 .ctl_name = VM_VFS_CACHE_PRESSURE,
1003 .procname = "vfs_cache_pressure",
1004 .data = &sysctl_vfs_cache_pressure,
1005 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1007 .proc_handler = &proc_dointvec,
1008 .strategy = &sysctl_intvec,
1011 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1013 .ctl_name = VM_LEGACY_VA_LAYOUT,
1014 .procname = "legacy_va_layout",
1015 .data = &sysctl_legacy_va_layout,
1016 .maxlen = sizeof(sysctl_legacy_va_layout),
1018 .proc_handler = &proc_dointvec,
1019 .strategy = &sysctl_intvec,
1025 .ctl_name = VM_ZONE_RECLAIM_MODE,
1026 .procname = "zone_reclaim_mode",
1027 .data = &zone_reclaim_mode,
1028 .maxlen = sizeof(zone_reclaim_mode),
1030 .proc_handler = &proc_dointvec,
1031 .strategy = &sysctl_intvec,
1035 .ctl_name = VM_MIN_UNMAPPED,
1036 .procname = "min_unmapped_ratio",
1037 .data = &sysctl_min_unmapped_ratio,
1038 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1040 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1041 .strategy = &sysctl_intvec,
1043 .extra2 = &one_hundred,
1046 .ctl_name = VM_MIN_SLAB,
1047 .procname = "min_slab_ratio",
1048 .data = &sysctl_min_slab_ratio,
1049 .maxlen = sizeof(sysctl_min_slab_ratio),
1051 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1052 .strategy = &sysctl_intvec,
1054 .extra2 = &one_hundred,
1059 .ctl_name = CTL_UNNUMBERED,
1060 .procname = "stat_interval",
1061 .data = &sysctl_stat_interval,
1062 .maxlen = sizeof(sysctl_stat_interval),
1064 .proc_handler = &proc_dointvec_jiffies,
1065 .strategy = &sysctl_jiffies,
1068 #ifdef CONFIG_SECURITY
1070 .ctl_name = CTL_UNNUMBERED,
1071 .procname = "mmap_min_addr",
1072 .data = &mmap_min_addr,
1073 .maxlen = sizeof(unsigned long),
1075 .proc_handler = &proc_doulongvec_minmax,
1080 .ctl_name = CTL_UNNUMBERED,
1081 .procname = "numa_zonelist_order",
1082 .data = &numa_zonelist_order,
1083 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1085 .proc_handler = &numa_zonelist_order_handler,
1086 .strategy = &sysctl_string,
1089 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1090 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1092 .ctl_name = VM_VDSO_ENABLED,
1093 .procname = "vdso_enabled",
1094 .data = &vdso_enabled,
1095 .maxlen = sizeof(vdso_enabled),
1097 .proc_handler = &proc_dointvec,
1098 .strategy = &sysctl_intvec,
1103 * NOTE: do not add new entries to this table unless you have read
1104 * Documentation/sysctl/ctl_unnumbered.txt
1109 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1110 static struct ctl_table binfmt_misc_table[] = {
1115 static struct ctl_table fs_table[] = {
1117 .ctl_name = FS_NRINODE,
1118 .procname = "inode-nr",
1119 .data = &inodes_stat,
1120 .maxlen = 2*sizeof(int),
1122 .proc_handler = &proc_dointvec,
1125 .ctl_name = FS_STATINODE,
1126 .procname = "inode-state",
1127 .data = &inodes_stat,
1128 .maxlen = 7*sizeof(int),
1130 .proc_handler = &proc_dointvec,
1133 .procname = "file-nr",
1134 .data = &files_stat,
1135 .maxlen = 3*sizeof(int),
1137 .proc_handler = &proc_nr_files,
1140 .ctl_name = FS_MAXFILE,
1141 .procname = "file-max",
1142 .data = &files_stat.max_files,
1143 .maxlen = sizeof(int),
1145 .proc_handler = &proc_dointvec,
1148 .ctl_name = FS_DENTRY,
1149 .procname = "dentry-state",
1150 .data = &dentry_stat,
1151 .maxlen = 6*sizeof(int),
1153 .proc_handler = &proc_dointvec,
1156 .ctl_name = FS_OVERFLOWUID,
1157 .procname = "overflowuid",
1158 .data = &fs_overflowuid,
1159 .maxlen = sizeof(int),
1161 .proc_handler = &proc_dointvec_minmax,
1162 .strategy = &sysctl_intvec,
1163 .extra1 = &minolduid,
1164 .extra2 = &maxolduid,
1167 .ctl_name = FS_OVERFLOWGID,
1168 .procname = "overflowgid",
1169 .data = &fs_overflowgid,
1170 .maxlen = sizeof(int),
1172 .proc_handler = &proc_dointvec_minmax,
1173 .strategy = &sysctl_intvec,
1174 .extra1 = &minolduid,
1175 .extra2 = &maxolduid,
1178 .ctl_name = FS_LEASES,
1179 .procname = "leases-enable",
1180 .data = &leases_enable,
1181 .maxlen = sizeof(int),
1183 .proc_handler = &proc_dointvec,
1185 #ifdef CONFIG_DNOTIFY
1187 .ctl_name = FS_DIR_NOTIFY,
1188 .procname = "dir-notify-enable",
1189 .data = &dir_notify_enable,
1190 .maxlen = sizeof(int),
1192 .proc_handler = &proc_dointvec,
1197 .ctl_name = FS_LEASE_TIME,
1198 .procname = "lease-break-time",
1199 .data = &lease_break_time,
1200 .maxlen = sizeof(int),
1202 .proc_handler = &proc_dointvec_minmax,
1203 .strategy = &sysctl_intvec,
1208 .procname = "aio-nr",
1210 .maxlen = sizeof(aio_nr),
1212 .proc_handler = &proc_doulongvec_minmax,
1215 .procname = "aio-max-nr",
1216 .data = &aio_max_nr,
1217 .maxlen = sizeof(aio_max_nr),
1219 .proc_handler = &proc_doulongvec_minmax,
1221 #ifdef CONFIG_INOTIFY_USER
1223 .ctl_name = FS_INOTIFY,
1224 .procname = "inotify",
1226 .child = inotify_table,
1231 .ctl_name = KERN_SETUID_DUMPABLE,
1232 .procname = "suid_dumpable",
1233 .data = &suid_dumpable,
1234 .maxlen = sizeof(int),
1236 .proc_handler = &proc_dointvec,
1238 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1240 .ctl_name = CTL_UNNUMBERED,
1241 .procname = "binfmt_misc",
1243 .child = binfmt_misc_table,
1247 * NOTE: do not add new entries to this table unless you have read
1248 * Documentation/sysctl/ctl_unnumbered.txt
1253 static struct ctl_table debug_table[] = {
1254 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1256 .ctl_name = CTL_UNNUMBERED,
1257 .procname = "exception-trace",
1258 .data = &show_unhandled_signals,
1259 .maxlen = sizeof(int),
1261 .proc_handler = proc_dointvec
1267 static struct ctl_table dev_table[] = {
1271 static DEFINE_SPINLOCK(sysctl_lock);
1273 /* called under sysctl_lock */
1274 static int use_table(struct ctl_table_header *p)
1276 if (unlikely(p->unregistering))
1282 /* called under sysctl_lock */
1283 static void unuse_table(struct ctl_table_header *p)
1286 if (unlikely(p->unregistering))
1287 complete(p->unregistering);
1290 /* called under sysctl_lock, will reacquire if has to wait */
1291 static void start_unregistering(struct ctl_table_header *p)
1294 * if p->used is 0, nobody will ever touch that entry again;
1295 * we'll eliminate all paths to it before dropping sysctl_lock
1297 if (unlikely(p->used)) {
1298 struct completion wait;
1299 init_completion(&wait);
1300 p->unregistering = &wait;
1301 spin_unlock(&sysctl_lock);
1302 wait_for_completion(&wait);
1303 spin_lock(&sysctl_lock);
1306 * do not remove from the list until nobody holds it; walking the
1307 * list in do_sysctl() relies on that.
1309 list_del_init(&p->ctl_entry);
1312 void sysctl_head_finish(struct ctl_table_header *head)
1316 spin_lock(&sysctl_lock);
1318 spin_unlock(&sysctl_lock);
1321 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1323 struct ctl_table_header *head;
1324 struct list_head *tmp;
1325 spin_lock(&sysctl_lock);
1327 tmp = &prev->ctl_entry;
1331 tmp = &root_table_header.ctl_entry;
1333 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1335 if (!use_table(head))
1337 spin_unlock(&sysctl_lock);
1341 if (tmp == &root_table_header.ctl_entry)
1344 spin_unlock(&sysctl_lock);
1348 #ifdef CONFIG_SYSCTL_SYSCALL
1349 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1350 void __user *newval, size_t newlen)
1352 struct ctl_table_header *head;
1353 int error = -ENOTDIR;
1355 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1359 if (!oldlenp || get_user(old_len, oldlenp))
1363 for (head = sysctl_head_next(NULL); head;
1364 head = sysctl_head_next(head)) {
1365 error = parse_table(name, nlen, oldval, oldlenp,
1366 newval, newlen, head->ctl_table);
1367 if (error != -ENOTDIR) {
1368 sysctl_head_finish(head);
1375 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1377 struct __sysctl_args tmp;
1380 if (copy_from_user(&tmp, args, sizeof(tmp)))
1383 error = deprecated_sysctl_warning(&tmp);
1388 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1389 tmp.newval, tmp.newlen);
1394 #endif /* CONFIG_SYSCTL_SYSCALL */
1397 * sysctl_perm does NOT grant the superuser all rights automatically, because
1398 * some sysctl variables are readonly even to root.
1401 static int test_perm(int mode, int op)
1405 else if (in_egroup_p(0))
1407 if ((mode & op & 0007) == op)
1412 int sysctl_perm(struct ctl_table *table, int op)
1415 error = security_sysctl(table, op);
1418 return test_perm(table->mode, op);
1421 #ifdef CONFIG_SYSCTL_SYSCALL
1422 static int parse_table(int __user *name, int nlen,
1423 void __user *oldval, size_t __user *oldlenp,
1424 void __user *newval, size_t newlen,
1425 struct ctl_table *table)
1431 if (get_user(n, name))
1433 for ( ; table->ctl_name || table->procname; table++) {
1434 if (!table->ctl_name)
1436 if (n == table->ctl_name) {
1439 if (sysctl_perm(table, 001))
1443 table = table->child;
1446 error = do_sysctl_strategy(table, name, nlen,
1455 /* Perform the actual read/write of a sysctl table entry. */
1456 int do_sysctl_strategy (struct ctl_table *table,
1457 int __user *name, int nlen,
1458 void __user *oldval, size_t __user *oldlenp,
1459 void __user *newval, size_t newlen)
1467 if (sysctl_perm(table, op))
1470 if (table->strategy) {
1471 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1479 /* If there is no strategy routine, or if the strategy returns
1480 * zero, proceed with automatic r/w */
1481 if (table->data && table->maxlen) {
1482 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1489 #endif /* CONFIG_SYSCTL_SYSCALL */
1491 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1493 for (; table->ctl_name || table->procname; table++) {
1494 table->parent = parent;
1496 sysctl_set_parent(table, table->child);
1500 static __init int sysctl_init(void)
1503 sysctl_set_parent(NULL, root_table);
1504 err = sysctl_check_table(root_table);
1508 core_initcall(sysctl_init);
1511 * register_sysctl_table - register a sysctl hierarchy
1512 * @table: the top-level table structure
1514 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1515 * array. An entry with a ctl_name of 0 terminates the table.
1517 * The members of the &struct ctl_table structure are used as follows:
1519 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1520 * must be unique within that level of sysctl
1522 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1523 * enter a sysctl file
1525 * data - a pointer to data for use by proc_handler
1527 * maxlen - the maximum size in bytes of the data
1529 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1531 * child - a pointer to the child sysctl table if this entry is a directory, or
1534 * proc_handler - the text handler routine (described below)
1536 * strategy - the strategy routine (described below)
1538 * de - for internal use by the sysctl routines
1540 * extra1, extra2 - extra pointers usable by the proc handler routines
1542 * Leaf nodes in the sysctl tree will be represented by a single file
1543 * under /proc; non-leaf nodes will be represented by directories.
1545 * sysctl(2) can automatically manage read and write requests through
1546 * the sysctl table. The data and maxlen fields of the ctl_table
1547 * struct enable minimal validation of the values being written to be
1548 * performed, and the mode field allows minimal authentication.
1550 * More sophisticated management can be enabled by the provision of a
1551 * strategy routine with the table entry. This will be called before
1552 * any automatic read or write of the data is performed.
1554 * The strategy routine may return
1556 * < 0 - Error occurred (error is passed to user process)
1558 * 0 - OK - proceed with automatic read or write.
1560 * > 0 - OK - read or write has been done by the strategy routine, so
1561 * return immediately.
1563 * There must be a proc_handler routine for any terminal nodes
1564 * mirrored under /proc/sys (non-terminals are handled by a built-in
1565 * directory handler). Several default handlers are available to
1566 * cover common cases -
1568 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1569 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1570 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1572 * It is the handler's job to read the input buffer from user memory
1573 * and process it. The handler should return 0 on success.
1575 * This routine returns %NULL on a failure to register, and a pointer
1576 * to the table header on success.
1578 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1580 struct ctl_table_header *tmp;
1581 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1584 tmp->ctl_table = table;
1585 INIT_LIST_HEAD(&tmp->ctl_entry);
1587 tmp->unregistering = NULL;
1588 sysctl_set_parent(NULL, table);
1589 if (sysctl_check_table(tmp->ctl_table)) {
1593 spin_lock(&sysctl_lock);
1594 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1595 spin_unlock(&sysctl_lock);
1600 * unregister_sysctl_table - unregister a sysctl table hierarchy
1601 * @header: the header returned from register_sysctl_table
1603 * Unregisters the sysctl table and all children. proc entries may not
1604 * actually be removed until they are no longer used by anyone.
1606 void unregister_sysctl_table(struct ctl_table_header * header)
1613 spin_lock(&sysctl_lock);
1614 start_unregistering(header);
1615 spin_unlock(&sysctl_lock);
1619 #else /* !CONFIG_SYSCTL */
1620 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1625 void unregister_sysctl_table(struct ctl_table_header * table)
1629 #endif /* CONFIG_SYSCTL */
1635 #ifdef CONFIG_PROC_SYSCTL
1637 static int _proc_do_string(void* data, int maxlen, int write,
1638 struct file *filp, void __user *buffer,
1639 size_t *lenp, loff_t *ppos)
1645 if (!data || !maxlen || !*lenp) {
1653 while (len < *lenp) {
1654 if (get_user(c, p++))
1656 if (c == 0 || c == '\n')
1662 if(copy_from_user(data, buffer, len))
1664 ((char *) data)[len] = 0;
1682 if(copy_to_user(buffer, data, len))
1685 if(put_user('\n', ((char __user *) buffer) + len))
1696 * proc_dostring - read a string sysctl
1697 * @table: the sysctl table
1698 * @write: %TRUE if this is a write to the sysctl file
1699 * @filp: the file structure
1700 * @buffer: the user buffer
1701 * @lenp: the size of the user buffer
1702 * @ppos: file position
1704 * Reads/writes a string from/to the user buffer. If the kernel
1705 * buffer provided is not large enough to hold the string, the
1706 * string is truncated. The copied string is %NULL-terminated.
1707 * If the string is being read by the user process, it is copied
1708 * and a newline '\n' is added. It is truncated if the buffer is
1711 * Returns 0 on success.
1713 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1714 void __user *buffer, size_t *lenp, loff_t *ppos)
1716 return _proc_do_string(table->data, table->maxlen, write, filp,
1717 buffer, lenp, ppos);
1721 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1723 int write, void *data)
1726 *valp = *negp ? -*lvalp : *lvalp;
1731 *lvalp = (unsigned long)-val;
1734 *lvalp = (unsigned long)val;
1740 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1741 int write, struct file *filp, void __user *buffer,
1742 size_t *lenp, loff_t *ppos,
1743 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1744 int write, void *data),
1747 #define TMPBUFLEN 21
1748 int *i, vleft, first=1, neg, val;
1752 char buf[TMPBUFLEN], *p;
1753 char __user *s = buffer;
1755 if (!tbl_data || !table->maxlen || !*lenp ||
1756 (*ppos && !write)) {
1761 i = (int *) tbl_data;
1762 vleft = table->maxlen / sizeof(*i);
1766 conv = do_proc_dointvec_conv;
1768 for (; left && vleft--; i++, first=0) {
1783 if (len > sizeof(buf) - 1)
1784 len = sizeof(buf) - 1;
1785 if (copy_from_user(buf, s, len))
1789 if (*p == '-' && left > 1) {
1793 if (*p < '0' || *p > '9')
1796 lval = simple_strtoul(p, &p, 0);
1799 if ((len < left) && *p && !isspace(*p))
1806 if (conv(&neg, &lval, i, 1, data))
1813 if (conv(&neg, &lval, i, 0, data))
1816 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1820 if(copy_to_user(s, buf, len))
1827 if (!write && !first && left) {
1828 if(put_user('\n', s))
1835 if (get_user(c, s++))
1850 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1851 void __user *buffer, size_t *lenp, loff_t *ppos,
1852 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1853 int write, void *data),
1856 return __do_proc_dointvec(table->data, table, write, filp,
1857 buffer, lenp, ppos, conv, data);
1861 * proc_dointvec - read a vector of integers
1862 * @table: the sysctl table
1863 * @write: %TRUE if this is a write to the sysctl file
1864 * @filp: the file structure
1865 * @buffer: the user buffer
1866 * @lenp: the size of the user buffer
1867 * @ppos: file position
1869 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1870 * values from/to the user buffer, treated as an ASCII string.
1872 * Returns 0 on success.
1874 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1875 void __user *buffer, size_t *lenp, loff_t *ppos)
1877 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1885 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1887 int write, void *data)
1889 int op = *(int *)data;
1891 int val = *negp ? -*lvalp : *lvalp;
1893 case OP_SET: *valp = val; break;
1894 case OP_AND: *valp &= val; break;
1895 case OP_OR: *valp |= val; break;
1901 *lvalp = (unsigned long)-val;
1904 *lvalp = (unsigned long)val;
1910 #ifdef CONFIG_SECURITY_CAPABILITIES
1912 * init may raise the set.
1915 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1916 void __user *buffer, size_t *lenp, loff_t *ppos)
1920 if (write && !capable(CAP_SYS_MODULE)) {
1924 op = is_global_init(current) ? OP_SET : OP_AND;
1925 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1926 do_proc_dointvec_bset_conv,&op);
1928 #endif /* def CONFIG_SECURITY_CAPABILITIES */
1931 * Taint values can only be increased
1933 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1934 void __user *buffer, size_t *lenp, loff_t *ppos)
1938 if (write && !capable(CAP_SYS_ADMIN))
1942 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1943 do_proc_dointvec_bset_conv,&op);
1946 struct do_proc_dointvec_minmax_conv_param {
1951 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1953 int write, void *data)
1955 struct do_proc_dointvec_minmax_conv_param *param = data;
1957 int val = *negp ? -*lvalp : *lvalp;
1958 if ((param->min && *param->min > val) ||
1959 (param->max && *param->max < val))
1966 *lvalp = (unsigned long)-val;
1969 *lvalp = (unsigned long)val;
1976 * proc_dointvec_minmax - read a vector of integers with min/max values
1977 * @table: the sysctl table
1978 * @write: %TRUE if this is a write to the sysctl file
1979 * @filp: the file structure
1980 * @buffer: the user buffer
1981 * @lenp: the size of the user buffer
1982 * @ppos: file position
1984 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1985 * values from/to the user buffer, treated as an ASCII string.
1987 * This routine will ensure the values are within the range specified by
1988 * table->extra1 (min) and table->extra2 (max).
1990 * Returns 0 on success.
1992 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1993 void __user *buffer, size_t *lenp, loff_t *ppos)
1995 struct do_proc_dointvec_minmax_conv_param param = {
1996 .min = (int *) table->extra1,
1997 .max = (int *) table->extra2,
1999 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2000 do_proc_dointvec_minmax_conv, ¶m);
2003 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2005 void __user *buffer,
2006 size_t *lenp, loff_t *ppos,
2007 unsigned long convmul,
2008 unsigned long convdiv)
2010 #define TMPBUFLEN 21
2011 unsigned long *i, *min, *max, val;
2012 int vleft, first=1, neg;
2014 char buf[TMPBUFLEN], *p;
2015 char __user *s = buffer;
2017 if (!data || !table->maxlen || !*lenp ||
2018 (*ppos && !write)) {
2023 i = (unsigned long *) data;
2024 min = (unsigned long *) table->extra1;
2025 max = (unsigned long *) table->extra2;
2026 vleft = table->maxlen / sizeof(unsigned long);
2029 for (; left && vleft--; i++, min++, max++, first=0) {
2044 if (len > TMPBUFLEN-1)
2046 if (copy_from_user(buf, s, len))
2050 if (*p == '-' && left > 1) {
2054 if (*p < '0' || *p > '9')
2056 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2058 if ((len < left) && *p && !isspace(*p))
2067 if ((min && val < *min) || (max && val > *max))
2074 sprintf(p, "%lu", convdiv * (*i) / convmul);
2078 if(copy_to_user(s, buf, len))
2085 if (!write && !first && left) {
2086 if(put_user('\n', s))
2093 if (get_user(c, s++))
2108 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2110 void __user *buffer,
2111 size_t *lenp, loff_t *ppos,
2112 unsigned long convmul,
2113 unsigned long convdiv)
2115 return __do_proc_doulongvec_minmax(table->data, table, write,
2116 filp, buffer, lenp, ppos, convmul, convdiv);
2120 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2121 * @table: the sysctl table
2122 * @write: %TRUE if this is a write to the sysctl file
2123 * @filp: the file structure
2124 * @buffer: the user buffer
2125 * @lenp: the size of the user buffer
2126 * @ppos: file position
2128 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2129 * values from/to the user buffer, treated as an ASCII string.
2131 * This routine will ensure the values are within the range specified by
2132 * table->extra1 (min) and table->extra2 (max).
2134 * Returns 0 on success.
2136 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2137 void __user *buffer, size_t *lenp, loff_t *ppos)
2139 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2143 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2144 * @table: the sysctl table
2145 * @write: %TRUE if this is a write to the sysctl file
2146 * @filp: the file structure
2147 * @buffer: the user buffer
2148 * @lenp: the size of the user buffer
2149 * @ppos: file position
2151 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2152 * values from/to the user buffer, treated as an ASCII string. The values
2153 * are treated as milliseconds, and converted to jiffies when they are stored.
2155 * This routine will ensure the values are within the range specified by
2156 * table->extra1 (min) and table->extra2 (max).
2158 * Returns 0 on success.
2160 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2162 void __user *buffer,
2163 size_t *lenp, loff_t *ppos)
2165 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2166 lenp, ppos, HZ, 1000l);
2170 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2172 int write, void *data)
2175 if (*lvalp > LONG_MAX / HZ)
2177 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2183 lval = (unsigned long)-val;
2186 lval = (unsigned long)val;
2193 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2195 int write, void *data)
2198 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2200 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2206 lval = (unsigned long)-val;
2209 lval = (unsigned long)val;
2211 *lvalp = jiffies_to_clock_t(lval);
2216 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2218 int write, void *data)
2221 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2227 lval = (unsigned long)-val;
2230 lval = (unsigned long)val;
2232 *lvalp = jiffies_to_msecs(lval);
2238 * proc_dointvec_jiffies - read a vector of integers as seconds
2239 * @table: the sysctl table
2240 * @write: %TRUE if this is a write to the sysctl file
2241 * @filp: the file structure
2242 * @buffer: the user buffer
2243 * @lenp: the size of the user buffer
2244 * @ppos: file position
2246 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2247 * values from/to the user buffer, treated as an ASCII string.
2248 * The values read are assumed to be in seconds, and are converted into
2251 * Returns 0 on success.
2253 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2254 void __user *buffer, size_t *lenp, loff_t *ppos)
2256 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2257 do_proc_dointvec_jiffies_conv,NULL);
2261 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2262 * @table: the sysctl table
2263 * @write: %TRUE if this is a write to the sysctl file
2264 * @filp: the file structure
2265 * @buffer: the user buffer
2266 * @lenp: the size of the user buffer
2267 * @ppos: pointer to the file position
2269 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2270 * values from/to the user buffer, treated as an ASCII string.
2271 * The values read are assumed to be in 1/USER_HZ seconds, and
2272 * are converted into jiffies.
2274 * Returns 0 on success.
2276 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2277 void __user *buffer, size_t *lenp, loff_t *ppos)
2279 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2280 do_proc_dointvec_userhz_jiffies_conv,NULL);
2284 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2285 * @table: the sysctl table
2286 * @write: %TRUE if this is a write to the sysctl file
2287 * @filp: the file structure
2288 * @buffer: the user buffer
2289 * @lenp: the size of the user buffer
2290 * @ppos: file position
2291 * @ppos: the current position in the file
2293 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2294 * values from/to the user buffer, treated as an ASCII string.
2295 * The values read are assumed to be in 1/1000 seconds, and
2296 * are converted into jiffies.
2298 * Returns 0 on success.
2300 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2301 void __user *buffer, size_t *lenp, loff_t *ppos)
2303 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2304 do_proc_dointvec_ms_jiffies_conv, NULL);
2307 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2308 void __user *buffer, size_t *lenp, loff_t *ppos)
2310 struct pid *new_pid;
2314 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
2316 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2317 lenp, ppos, NULL, NULL);
2321 new_pid = find_get_pid(tmp);
2325 put_pid(xchg(&cad_pid, new_pid));
2329 #else /* CONFIG_PROC_FS */
2331 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2332 void __user *buffer, size_t *lenp, loff_t *ppos)
2337 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2338 void __user *buffer, size_t *lenp, loff_t *ppos)
2343 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2344 void __user *buffer, size_t *lenp, loff_t *ppos)
2349 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2350 void __user *buffer, size_t *lenp, loff_t *ppos)
2355 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2356 void __user *buffer, size_t *lenp, loff_t *ppos)
2361 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2362 void __user *buffer, size_t *lenp, loff_t *ppos)
2367 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2368 void __user *buffer, size_t *lenp, loff_t *ppos)
2373 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2374 void __user *buffer, size_t *lenp, loff_t *ppos)
2379 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2381 void __user *buffer,
2382 size_t *lenp, loff_t *ppos)
2388 #endif /* CONFIG_PROC_FS */
2391 #ifdef CONFIG_SYSCTL_SYSCALL
2393 * General sysctl support routines
2396 /* The generic sysctl data routine (used if no strategy routine supplied) */
2397 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2398 void __user *oldval, size_t __user *oldlenp,
2399 void __user *newval, size_t newlen)
2403 /* Get out of I don't have a variable */
2404 if (!table->data || !table->maxlen)
2407 if (oldval && oldlenp) {
2408 if (get_user(len, oldlenp))
2411 if (len > table->maxlen)
2412 len = table->maxlen;
2413 if (copy_to_user(oldval, table->data, len))
2415 if (put_user(len, oldlenp))
2420 if (newval && newlen) {
2421 if (newlen > table->maxlen)
2422 newlen = table->maxlen;
2424 if (copy_from_user(table->data, newval, newlen))
2430 /* The generic string strategy routine: */
2431 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2432 void __user *oldval, size_t __user *oldlenp,
2433 void __user *newval, size_t newlen)
2435 if (!table->data || !table->maxlen)
2438 if (oldval && oldlenp) {
2440 if (get_user(bufsize, oldlenp))
2443 size_t len = strlen(table->data), copied;
2445 /* This shouldn't trigger for a well-formed sysctl */
2446 if (len > table->maxlen)
2447 len = table->maxlen;
2449 /* Copy up to a max of bufsize-1 bytes of the string */
2450 copied = (len >= bufsize) ? bufsize - 1 : len;
2452 if (copy_to_user(oldval, table->data, copied) ||
2453 put_user(0, (char __user *)(oldval + copied)))
2455 if (put_user(len, oldlenp))
2459 if (newval && newlen) {
2460 size_t len = newlen;
2461 if (len > table->maxlen)
2462 len = table->maxlen;
2463 if(copy_from_user(table->data, newval, len))
2465 if (len == table->maxlen)
2467 ((char *) table->data)[len] = 0;
2473 * This function makes sure that all of the integers in the vector
2474 * are between the minimum and maximum values given in the arrays
2475 * table->extra1 and table->extra2, respectively.
2477 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2478 void __user *oldval, size_t __user *oldlenp,
2479 void __user *newval, size_t newlen)
2482 if (newval && newlen) {
2483 int __user *vec = (int __user *) newval;
2484 int *min = (int *) table->extra1;
2485 int *max = (int *) table->extra2;
2489 if (newlen % sizeof(int) != 0)
2492 if (!table->extra1 && !table->extra2)
2495 if (newlen > table->maxlen)
2496 newlen = table->maxlen;
2497 length = newlen / sizeof(int);
2499 for (i = 0; i < length; i++) {
2501 if (get_user(value, vec + i))
2503 if (min && value < min[i])
2505 if (max && value > max[i])
2512 /* Strategy function to convert jiffies to seconds */
2513 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2514 void __user *oldval, size_t __user *oldlenp,
2515 void __user *newval, size_t newlen)
2517 if (oldval && oldlenp) {
2520 if (get_user(olen, oldlenp))
2525 if (olen < sizeof(int))
2528 val = *(int *)(table->data) / HZ;
2529 if (put_user(val, (int __user *)oldval))
2531 if (put_user(sizeof(int), oldlenp))
2535 if (newval && newlen) {
2537 if (newlen != sizeof(int))
2539 if (get_user(new, (int __user *)newval))
2541 *(int *)(table->data) = new*HZ;
2546 /* Strategy function to convert jiffies to seconds */
2547 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2548 void __user *oldval, size_t __user *oldlenp,
2549 void __user *newval, size_t newlen)
2551 if (oldval && oldlenp) {
2554 if (get_user(olen, oldlenp))
2559 if (olen < sizeof(int))
2562 val = jiffies_to_msecs(*(int *)(table->data));
2563 if (put_user(val, (int __user *)oldval))
2565 if (put_user(sizeof(int), oldlenp))
2569 if (newval && newlen) {
2571 if (newlen != sizeof(int))
2573 if (get_user(new, (int __user *)newval))
2575 *(int *)(table->data) = msecs_to_jiffies(new);
2582 #else /* CONFIG_SYSCTL_SYSCALL */
2585 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2587 struct __sysctl_args tmp;
2590 if (copy_from_user(&tmp, args, sizeof(tmp)))
2593 error = deprecated_sysctl_warning(&tmp);
2595 /* If no error reading the parameters then just -ENOSYS ... */
2602 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2603 void __user *oldval, size_t __user *oldlenp,
2604 void __user *newval, size_t newlen)
2609 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2610 void __user *oldval, size_t __user *oldlenp,
2611 void __user *newval, size_t newlen)
2616 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2617 void __user *oldval, size_t __user *oldlenp,
2618 void __user *newval, size_t newlen)
2623 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2624 void __user *oldval, size_t __user *oldlenp,
2625 void __user *newval, size_t newlen)
2630 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2631 void __user *oldval, size_t __user *oldlenp,
2632 void __user *newval, size_t newlen)
2637 #endif /* CONFIG_SYSCTL_SYSCALL */
2639 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2641 static int msg_count;
2642 int name[CTL_MAXNAME];
2645 /* Check args->nlen. */
2646 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2649 /* Read in the sysctl name for better debug message logging */
2650 for (i = 0; i < args->nlen; i++)
2651 if (get_user(name[i], args->name + i))
2654 /* Ignore accesses to kernel.version */
2655 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2658 if (msg_count < 5) {
2661 "warning: process `%s' used the deprecated sysctl "
2662 "system call with ", current->comm);
2663 for (i = 0; i < args->nlen; i++)
2664 printk("%d.", name[i]);
2671 * No sense putting this after each symbol definition, twice,
2672 * exception granted :-)
2674 EXPORT_SYMBOL(proc_dointvec);
2675 EXPORT_SYMBOL(proc_dointvec_jiffies);
2676 EXPORT_SYMBOL(proc_dointvec_minmax);
2677 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2678 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2679 EXPORT_SYMBOL(proc_dostring);
2680 EXPORT_SYMBOL(proc_doulongvec_minmax);
2681 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2682 EXPORT_SYMBOL(register_sysctl_table);
2683 EXPORT_SYMBOL(sysctl_intvec);
2684 EXPORT_SYMBOL(sysctl_jiffies);
2685 EXPORT_SYMBOL(sysctl_ms_jiffies);
2686 EXPORT_SYMBOL(sysctl_string);
2687 EXPORT_SYMBOL(sysctl_data);
2688 EXPORT_SYMBOL(unregister_sysctl_table);