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/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
53 #include <asm/uaccess.h>
54 #include <asm/processor.h>
58 #include <asm/stacktrace.h>
62 static int deprecated_sysctl_warning(struct __sysctl_args *args);
64 #if defined(CONFIG_SYSCTL)
66 /* External variables not in a header file. */
68 extern int print_fatal_signals;
69 extern int sysctl_overcommit_memory;
70 extern int sysctl_overcommit_ratio;
71 extern int sysctl_panic_on_oom;
72 extern int sysctl_oom_kill_allocating_task;
73 extern int sysctl_oom_dump_tasks;
74 extern int max_threads;
75 extern int core_uses_pid;
76 extern int suid_dumpable;
77 extern char core_pattern[];
79 extern int min_free_kbytes;
80 extern int pid_max_min, pid_max_max;
81 extern int sysctl_drop_caches;
82 extern int percpu_pagelist_fraction;
83 extern int compat_log;
84 extern int latencytop_enabled;
85 extern int sysctl_nr_open_min, sysctl_nr_open_max;
87 extern int sysctl_nr_trim_pages;
89 #ifdef CONFIG_RCU_TORTURE_TEST
90 extern int rcutorture_runnable;
91 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
93 /* Constants used for minimum and maximum */
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty = 60;
96 static int neg_one = -1;
100 static int __maybe_unused one = 1;
101 static int __maybe_unused two = 2;
102 static unsigned long one_ul = 1;
103 static int one_hundred = 100;
104 static int one_thousand = 1000;
106 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107 static int maxolduid = 65535;
108 static int minolduid;
109 static int min_percpu_pagelist_fract = 8;
111 static int ngroups_max = NGROUPS_MAX;
113 #ifdef CONFIG_MODULES
114 extern char modprobe_path[];
116 #ifdef CONFIG_CHR_DEV_SG
117 extern int sg_big_buff;
121 #include <asm/system.h>
124 #ifdef CONFIG_SPARC64
125 extern int sysctl_tsb_ratio;
129 extern int pwrsw_enabled;
130 extern int unaligned_enabled;
134 #ifdef CONFIG_MATHEMU
135 extern int sysctl_ieee_emulation_warnings;
137 extern int sysctl_userprocess_debug;
138 extern int spin_retry;
141 #ifdef CONFIG_BSD_PROCESS_ACCT
142 extern int acct_parm[];
146 extern int no_unaligned_warning;
147 extern int unaligned_dump_stack;
150 #ifdef CONFIG_RT_MUTEXES
151 extern int max_lock_depth;
154 #ifdef CONFIG_PROC_SYSCTL
155 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
156 void __user *buffer, size_t *lenp, loff_t *ppos);
157 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
158 void __user *buffer, size_t *lenp, loff_t *ppos);
161 static struct ctl_table root_table[];
162 static struct ctl_table_root sysctl_table_root;
163 static struct ctl_table_header root_table_header = {
165 .ctl_table = root_table,
166 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
167 .root = &sysctl_table_root,
168 .set = &sysctl_table_root.default_set,
170 static struct ctl_table_root sysctl_table_root = {
171 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
172 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
175 static struct ctl_table kern_table[];
176 static struct ctl_table vm_table[];
177 static struct ctl_table fs_table[];
178 static struct ctl_table debug_table[];
179 static struct ctl_table dev_table[];
180 extern struct ctl_table random_table[];
181 #ifdef CONFIG_INOTIFY_USER
182 extern struct ctl_table inotify_table[];
185 extern struct ctl_table epoll_table[];
188 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
189 int sysctl_legacy_va_layout;
192 extern int prove_locking;
193 extern int lock_stat;
195 /* The default sysctl tables: */
197 static struct ctl_table root_table[] = {
199 .ctl_name = CTL_KERN,
200 .procname = "kernel",
217 .ctl_name = CTL_DEBUG,
220 .child = debug_table,
229 * NOTE: do not add new entries to this table unless you have read
230 * Documentation/sysctl/ctl_unnumbered.txt
235 #ifdef CONFIG_SCHED_DEBUG
236 static int min_sched_granularity_ns = 100000; /* 100 usecs */
237 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
238 static int min_wakeup_granularity_ns; /* 0 usecs */
239 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
242 static struct ctl_table kern_table[] = {
243 #ifdef CONFIG_SCHED_DEBUG
245 .ctl_name = CTL_UNNUMBERED,
246 .procname = "sched_min_granularity_ns",
247 .data = &sysctl_sched_min_granularity,
248 .maxlen = sizeof(unsigned int),
250 .proc_handler = &sched_nr_latency_handler,
251 .strategy = &sysctl_intvec,
252 .extra1 = &min_sched_granularity_ns,
253 .extra2 = &max_sched_granularity_ns,
256 .ctl_name = CTL_UNNUMBERED,
257 .procname = "sched_latency_ns",
258 .data = &sysctl_sched_latency,
259 .maxlen = sizeof(unsigned int),
261 .proc_handler = &sched_nr_latency_handler,
262 .strategy = &sysctl_intvec,
263 .extra1 = &min_sched_granularity_ns,
264 .extra2 = &max_sched_granularity_ns,
267 .ctl_name = CTL_UNNUMBERED,
268 .procname = "sched_wakeup_granularity_ns",
269 .data = &sysctl_sched_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_shares_ratelimit",
280 .data = &sysctl_sched_shares_ratelimit,
281 .maxlen = sizeof(unsigned int),
283 .proc_handler = &proc_dointvec,
286 .ctl_name = CTL_UNNUMBERED,
287 .procname = "sched_shares_thresh",
288 .data = &sysctl_sched_shares_thresh,
289 .maxlen = sizeof(unsigned int),
291 .proc_handler = &proc_dointvec_minmax,
292 .strategy = &sysctl_intvec,
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_child_runs_first",
298 .data = &sysctl_sched_child_runs_first,
299 .maxlen = sizeof(unsigned int),
301 .proc_handler = &proc_dointvec,
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_features",
306 .data = &sysctl_sched_features,
307 .maxlen = sizeof(unsigned int),
309 .proc_handler = &proc_dointvec,
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "sched_migration_cost",
314 .data = &sysctl_sched_migration_cost,
315 .maxlen = sizeof(unsigned int),
317 .proc_handler = &proc_dointvec,
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "sched_nr_migrate",
322 .data = &sysctl_sched_nr_migrate,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = &proc_dointvec,
328 .ctl_name = CTL_UNNUMBERED,
329 .procname = "timer_migration",
330 .data = &sysctl_timer_migration,
331 .maxlen = sizeof(unsigned int),
333 .proc_handler = &proc_dointvec,
337 .ctl_name = CTL_UNNUMBERED,
338 .procname = "sched_rt_period_us",
339 .data = &sysctl_sched_rt_period,
340 .maxlen = sizeof(unsigned int),
342 .proc_handler = &sched_rt_handler,
345 .ctl_name = CTL_UNNUMBERED,
346 .procname = "sched_rt_runtime_us",
347 .data = &sysctl_sched_rt_runtime,
348 .maxlen = sizeof(int),
350 .proc_handler = &sched_rt_handler,
353 .ctl_name = CTL_UNNUMBERED,
354 .procname = "sched_compat_yield",
355 .data = &sysctl_sched_compat_yield,
356 .maxlen = sizeof(unsigned int),
358 .proc_handler = &proc_dointvec,
360 #ifdef CONFIG_PROVE_LOCKING
362 .ctl_name = CTL_UNNUMBERED,
363 .procname = "prove_locking",
364 .data = &prove_locking,
365 .maxlen = sizeof(int),
367 .proc_handler = &proc_dointvec,
370 #ifdef CONFIG_LOCK_STAT
372 .ctl_name = CTL_UNNUMBERED,
373 .procname = "lock_stat",
375 .maxlen = sizeof(int),
377 .proc_handler = &proc_dointvec,
381 .ctl_name = KERN_PANIC,
383 .data = &panic_timeout,
384 .maxlen = sizeof(int),
386 .proc_handler = &proc_dointvec,
389 .ctl_name = KERN_CORE_USES_PID,
390 .procname = "core_uses_pid",
391 .data = &core_uses_pid,
392 .maxlen = sizeof(int),
394 .proc_handler = &proc_dointvec,
397 .ctl_name = KERN_CORE_PATTERN,
398 .procname = "core_pattern",
399 .data = core_pattern,
400 .maxlen = CORENAME_MAX_SIZE,
402 .proc_handler = &proc_dostring,
403 .strategy = &sysctl_string,
405 #ifdef CONFIG_PROC_SYSCTL
407 .procname = "tainted",
408 .maxlen = sizeof(long),
410 .proc_handler = &proc_taint,
413 #ifdef CONFIG_LATENCYTOP
415 .procname = "latencytop",
416 .data = &latencytop_enabled,
417 .maxlen = sizeof(int),
419 .proc_handler = &proc_dointvec,
422 #ifdef CONFIG_BLK_DEV_INITRD
424 .ctl_name = KERN_REALROOTDEV,
425 .procname = "real-root-dev",
426 .data = &real_root_dev,
427 .maxlen = sizeof(int),
429 .proc_handler = &proc_dointvec,
433 .ctl_name = CTL_UNNUMBERED,
434 .procname = "print-fatal-signals",
435 .data = &print_fatal_signals,
436 .maxlen = sizeof(int),
438 .proc_handler = &proc_dointvec,
442 .ctl_name = KERN_SPARC_REBOOT,
443 .procname = "reboot-cmd",
444 .data = reboot_command,
447 .proc_handler = &proc_dostring,
448 .strategy = &sysctl_string,
451 .ctl_name = KERN_SPARC_STOP_A,
452 .procname = "stop-a",
453 .data = &stop_a_enabled,
454 .maxlen = sizeof (int),
456 .proc_handler = &proc_dointvec,
459 .ctl_name = KERN_SPARC_SCONS_PWROFF,
460 .procname = "scons-poweroff",
461 .data = &scons_pwroff,
462 .maxlen = sizeof (int),
464 .proc_handler = &proc_dointvec,
467 #ifdef CONFIG_SPARC64
469 .ctl_name = CTL_UNNUMBERED,
470 .procname = "tsb-ratio",
471 .data = &sysctl_tsb_ratio,
472 .maxlen = sizeof (int),
474 .proc_handler = &proc_dointvec,
479 .ctl_name = KERN_HPPA_PWRSW,
480 .procname = "soft-power",
481 .data = &pwrsw_enabled,
482 .maxlen = sizeof (int),
484 .proc_handler = &proc_dointvec,
487 .ctl_name = KERN_HPPA_UNALIGNED,
488 .procname = "unaligned-trap",
489 .data = &unaligned_enabled,
490 .maxlen = sizeof (int),
492 .proc_handler = &proc_dointvec,
496 .ctl_name = KERN_CTLALTDEL,
497 .procname = "ctrl-alt-del",
499 .maxlen = sizeof(int),
501 .proc_handler = &proc_dointvec,
503 #ifdef CONFIG_FUNCTION_TRACER
505 .ctl_name = CTL_UNNUMBERED,
506 .procname = "ftrace_enabled",
507 .data = &ftrace_enabled,
508 .maxlen = sizeof(int),
510 .proc_handler = &ftrace_enable_sysctl,
513 #ifdef CONFIG_STACK_TRACER
515 .ctl_name = CTL_UNNUMBERED,
516 .procname = "stack_tracer_enabled",
517 .data = &stack_tracer_enabled,
518 .maxlen = sizeof(int),
520 .proc_handler = &stack_trace_sysctl,
523 #ifdef CONFIG_TRACING
525 .ctl_name = CTL_UNNUMBERED,
526 .procname = "ftrace_dump_on_oops",
527 .data = &ftrace_dump_on_oops,
528 .maxlen = sizeof(int),
530 .proc_handler = &proc_dointvec,
533 #ifdef CONFIG_MODULES
535 .ctl_name = KERN_MODPROBE,
536 .procname = "modprobe",
537 .data = &modprobe_path,
538 .maxlen = KMOD_PATH_LEN,
540 .proc_handler = &proc_dostring,
541 .strategy = &sysctl_string,
544 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
546 .ctl_name = KERN_HOTPLUG,
547 .procname = "hotplug",
548 .data = &uevent_helper,
549 .maxlen = UEVENT_HELPER_PATH_LEN,
551 .proc_handler = &proc_dostring,
552 .strategy = &sysctl_string,
555 #ifdef CONFIG_CHR_DEV_SG
557 .ctl_name = KERN_SG_BIG_BUFF,
558 .procname = "sg-big-buff",
559 .data = &sg_big_buff,
560 .maxlen = sizeof (int),
562 .proc_handler = &proc_dointvec,
565 #ifdef CONFIG_BSD_PROCESS_ACCT
567 .ctl_name = KERN_ACCT,
570 .maxlen = 3*sizeof(int),
572 .proc_handler = &proc_dointvec,
575 #ifdef CONFIG_MAGIC_SYSRQ
577 .ctl_name = KERN_SYSRQ,
579 .data = &__sysrq_enabled,
580 .maxlen = sizeof (int),
582 .proc_handler = &proc_dointvec,
585 #ifdef CONFIG_PROC_SYSCTL
587 .procname = "cad_pid",
589 .maxlen = sizeof (int),
591 .proc_handler = &proc_do_cad_pid,
595 .ctl_name = KERN_MAX_THREADS,
596 .procname = "threads-max",
597 .data = &max_threads,
598 .maxlen = sizeof(int),
600 .proc_handler = &proc_dointvec,
603 .ctl_name = KERN_RANDOM,
604 .procname = "random",
606 .child = random_table,
609 .ctl_name = KERN_OVERFLOWUID,
610 .procname = "overflowuid",
611 .data = &overflowuid,
612 .maxlen = sizeof(int),
614 .proc_handler = &proc_dointvec_minmax,
615 .strategy = &sysctl_intvec,
616 .extra1 = &minolduid,
617 .extra2 = &maxolduid,
620 .ctl_name = KERN_OVERFLOWGID,
621 .procname = "overflowgid",
622 .data = &overflowgid,
623 .maxlen = sizeof(int),
625 .proc_handler = &proc_dointvec_minmax,
626 .strategy = &sysctl_intvec,
627 .extra1 = &minolduid,
628 .extra2 = &maxolduid,
631 #ifdef CONFIG_MATHEMU
633 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
634 .procname = "ieee_emulation_warnings",
635 .data = &sysctl_ieee_emulation_warnings,
636 .maxlen = sizeof(int),
638 .proc_handler = &proc_dointvec,
642 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
643 .procname = "userprocess_debug",
644 .data = &sysctl_userprocess_debug,
645 .maxlen = sizeof(int),
647 .proc_handler = &proc_dointvec,
651 .ctl_name = KERN_PIDMAX,
652 .procname = "pid_max",
654 .maxlen = sizeof (int),
656 .proc_handler = &proc_dointvec_minmax,
657 .strategy = sysctl_intvec,
658 .extra1 = &pid_max_min,
659 .extra2 = &pid_max_max,
662 .ctl_name = KERN_PANIC_ON_OOPS,
663 .procname = "panic_on_oops",
664 .data = &panic_on_oops,
665 .maxlen = sizeof(int),
667 .proc_handler = &proc_dointvec,
669 #if defined CONFIG_PRINTK
671 .ctl_name = KERN_PRINTK,
672 .procname = "printk",
673 .data = &console_loglevel,
674 .maxlen = 4*sizeof(int),
676 .proc_handler = &proc_dointvec,
679 .ctl_name = KERN_PRINTK_RATELIMIT,
680 .procname = "printk_ratelimit",
681 .data = &printk_ratelimit_state.interval,
682 .maxlen = sizeof(int),
684 .proc_handler = &proc_dointvec_jiffies,
685 .strategy = &sysctl_jiffies,
688 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
689 .procname = "printk_ratelimit_burst",
690 .data = &printk_ratelimit_state.burst,
691 .maxlen = sizeof(int),
693 .proc_handler = &proc_dointvec,
697 .ctl_name = KERN_NGROUPS_MAX,
698 .procname = "ngroups_max",
699 .data = &ngroups_max,
700 .maxlen = sizeof (int),
702 .proc_handler = &proc_dointvec,
704 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
706 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
707 .procname = "unknown_nmi_panic",
708 .data = &unknown_nmi_panic,
709 .maxlen = sizeof (int),
711 .proc_handler = &proc_dointvec,
714 .procname = "nmi_watchdog",
715 .data = &nmi_watchdog_enabled,
716 .maxlen = sizeof (int),
718 .proc_handler = &proc_nmi_enabled,
721 #if defined(CONFIG_X86)
723 .ctl_name = KERN_PANIC_ON_NMI,
724 .procname = "panic_on_unrecovered_nmi",
725 .data = &panic_on_unrecovered_nmi,
726 .maxlen = sizeof(int),
728 .proc_handler = &proc_dointvec,
731 .ctl_name = KERN_BOOTLOADER_TYPE,
732 .procname = "bootloader_type",
733 .data = &bootloader_type,
734 .maxlen = sizeof (int),
736 .proc_handler = &proc_dointvec,
739 .ctl_name = CTL_UNNUMBERED,
740 .procname = "kstack_depth_to_print",
741 .data = &kstack_depth_to_print,
742 .maxlen = sizeof(int),
744 .proc_handler = &proc_dointvec,
747 .ctl_name = CTL_UNNUMBERED,
748 .procname = "io_delay_type",
749 .data = &io_delay_type,
750 .maxlen = sizeof(int),
752 .proc_handler = &proc_dointvec,
755 #if defined(CONFIG_MMU)
757 .ctl_name = KERN_RANDOMIZE,
758 .procname = "randomize_va_space",
759 .data = &randomize_va_space,
760 .maxlen = sizeof(int),
762 .proc_handler = &proc_dointvec,
765 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
767 .ctl_name = KERN_SPIN_RETRY,
768 .procname = "spin_retry",
770 .maxlen = sizeof (int),
772 .proc_handler = &proc_dointvec,
775 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
777 .procname = "acpi_video_flags",
778 .data = &acpi_realmode_flags,
779 .maxlen = sizeof (unsigned long),
781 .proc_handler = &proc_doulongvec_minmax,
786 .ctl_name = KERN_IA64_UNALIGNED,
787 .procname = "ignore-unaligned-usertrap",
788 .data = &no_unaligned_warning,
789 .maxlen = sizeof (int),
791 .proc_handler = &proc_dointvec,
794 .ctl_name = CTL_UNNUMBERED,
795 .procname = "unaligned-dump-stack",
796 .data = &unaligned_dump_stack,
797 .maxlen = sizeof (int),
799 .proc_handler = &proc_dointvec,
802 #ifdef CONFIG_DETECT_SOFTLOCKUP
804 .ctl_name = CTL_UNNUMBERED,
805 .procname = "softlockup_panic",
806 .data = &softlockup_panic,
807 .maxlen = sizeof(int),
809 .proc_handler = &proc_dointvec_minmax,
810 .strategy = &sysctl_intvec,
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "softlockup_thresh",
817 .data = &softlockup_thresh,
818 .maxlen = sizeof(int),
820 .proc_handler = &proc_dosoftlockup_thresh,
821 .strategy = &sysctl_intvec,
826 #ifdef CONFIG_DETECT_HUNG_TASK
828 .ctl_name = CTL_UNNUMBERED,
829 .procname = "hung_task_panic",
830 .data = &sysctl_hung_task_panic,
831 .maxlen = sizeof(int),
833 .proc_handler = &proc_dointvec_minmax,
834 .strategy = &sysctl_intvec,
839 .ctl_name = CTL_UNNUMBERED,
840 .procname = "hung_task_check_count",
841 .data = &sysctl_hung_task_check_count,
842 .maxlen = sizeof(unsigned long),
844 .proc_handler = &proc_doulongvec_minmax,
845 .strategy = &sysctl_intvec,
848 .ctl_name = CTL_UNNUMBERED,
849 .procname = "hung_task_timeout_secs",
850 .data = &sysctl_hung_task_timeout_secs,
851 .maxlen = sizeof(unsigned long),
853 .proc_handler = &proc_dohung_task_timeout_secs,
854 .strategy = &sysctl_intvec,
857 .ctl_name = CTL_UNNUMBERED,
858 .procname = "hung_task_warnings",
859 .data = &sysctl_hung_task_warnings,
860 .maxlen = sizeof(unsigned long),
862 .proc_handler = &proc_doulongvec_minmax,
863 .strategy = &sysctl_intvec,
868 .ctl_name = KERN_COMPAT_LOG,
869 .procname = "compat-log",
871 .maxlen = sizeof (int),
873 .proc_handler = &proc_dointvec,
876 #ifdef CONFIG_RT_MUTEXES
878 .ctl_name = KERN_MAX_LOCK_DEPTH,
879 .procname = "max_lock_depth",
880 .data = &max_lock_depth,
881 .maxlen = sizeof(int),
883 .proc_handler = &proc_dointvec,
887 .ctl_name = CTL_UNNUMBERED,
888 .procname = "poweroff_cmd",
889 .data = &poweroff_cmd,
890 .maxlen = POWEROFF_CMD_PATH_LEN,
892 .proc_handler = &proc_dostring,
893 .strategy = &sysctl_string,
897 .ctl_name = CTL_UNNUMBERED,
900 .child = key_sysctls,
903 #ifdef CONFIG_RCU_TORTURE_TEST
905 .ctl_name = CTL_UNNUMBERED,
906 .procname = "rcutorture_runnable",
907 .data = &rcutorture_runnable,
908 .maxlen = sizeof(int),
910 .proc_handler = &proc_dointvec,
913 #ifdef CONFIG_SLOW_WORK
915 .ctl_name = CTL_UNNUMBERED,
916 .procname = "slow-work",
918 .child = slow_work_sysctls,
922 * NOTE: do not add new entries to this table unless you have read
923 * Documentation/sysctl/ctl_unnumbered.txt
928 static struct ctl_table vm_table[] = {
930 .ctl_name = VM_OVERCOMMIT_MEMORY,
931 .procname = "overcommit_memory",
932 .data = &sysctl_overcommit_memory,
933 .maxlen = sizeof(sysctl_overcommit_memory),
935 .proc_handler = &proc_dointvec,
938 .ctl_name = VM_PANIC_ON_OOM,
939 .procname = "panic_on_oom",
940 .data = &sysctl_panic_on_oom,
941 .maxlen = sizeof(sysctl_panic_on_oom),
943 .proc_handler = &proc_dointvec,
946 .ctl_name = CTL_UNNUMBERED,
947 .procname = "oom_kill_allocating_task",
948 .data = &sysctl_oom_kill_allocating_task,
949 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
951 .proc_handler = &proc_dointvec,
954 .ctl_name = CTL_UNNUMBERED,
955 .procname = "oom_dump_tasks",
956 .data = &sysctl_oom_dump_tasks,
957 .maxlen = sizeof(sysctl_oom_dump_tasks),
959 .proc_handler = &proc_dointvec,
962 .ctl_name = VM_OVERCOMMIT_RATIO,
963 .procname = "overcommit_ratio",
964 .data = &sysctl_overcommit_ratio,
965 .maxlen = sizeof(sysctl_overcommit_ratio),
967 .proc_handler = &proc_dointvec,
970 .ctl_name = VM_PAGE_CLUSTER,
971 .procname = "page-cluster",
972 .data = &page_cluster,
973 .maxlen = sizeof(int),
975 .proc_handler = &proc_dointvec,
978 .ctl_name = VM_DIRTY_BACKGROUND,
979 .procname = "dirty_background_ratio",
980 .data = &dirty_background_ratio,
981 .maxlen = sizeof(dirty_background_ratio),
983 .proc_handler = &dirty_background_ratio_handler,
984 .strategy = &sysctl_intvec,
986 .extra2 = &one_hundred,
989 .ctl_name = CTL_UNNUMBERED,
990 .procname = "dirty_background_bytes",
991 .data = &dirty_background_bytes,
992 .maxlen = sizeof(dirty_background_bytes),
994 .proc_handler = &dirty_background_bytes_handler,
995 .strategy = &sysctl_intvec,
999 .ctl_name = VM_DIRTY_RATIO,
1000 .procname = "dirty_ratio",
1001 .data = &vm_dirty_ratio,
1002 .maxlen = sizeof(vm_dirty_ratio),
1004 .proc_handler = &dirty_ratio_handler,
1005 .strategy = &sysctl_intvec,
1007 .extra2 = &one_hundred,
1010 .ctl_name = CTL_UNNUMBERED,
1011 .procname = "dirty_bytes",
1012 .data = &vm_dirty_bytes,
1013 .maxlen = sizeof(vm_dirty_bytes),
1015 .proc_handler = &dirty_bytes_handler,
1016 .strategy = &sysctl_intvec,
1020 .procname = "dirty_writeback_centisecs",
1021 .data = &dirty_writeback_interval,
1022 .maxlen = sizeof(dirty_writeback_interval),
1024 .proc_handler = &dirty_writeback_centisecs_handler,
1027 .procname = "dirty_expire_centisecs",
1028 .data = &dirty_expire_interval,
1029 .maxlen = sizeof(dirty_expire_interval),
1031 .proc_handler = &proc_dointvec,
1034 .ctl_name = VM_NR_PDFLUSH_THREADS,
1035 .procname = "nr_pdflush_threads",
1036 .data = &nr_pdflush_threads,
1037 .maxlen = sizeof nr_pdflush_threads,
1038 .mode = 0444 /* read-only*/,
1039 .proc_handler = &proc_dointvec,
1042 .ctl_name = CTL_UNNUMBERED,
1043 .procname = "nr_pdflush_threads_min",
1044 .data = &nr_pdflush_threads_min,
1045 .maxlen = sizeof nr_pdflush_threads_min,
1046 .mode = 0644 /* read-write */,
1047 .proc_handler = &proc_dointvec_minmax,
1048 .strategy = &sysctl_intvec,
1050 .extra2 = &nr_pdflush_threads_max,
1053 .ctl_name = CTL_UNNUMBERED,
1054 .procname = "nr_pdflush_threads_max",
1055 .data = &nr_pdflush_threads_max,
1056 .maxlen = sizeof nr_pdflush_threads_max,
1057 .mode = 0644 /* read-write */,
1058 .proc_handler = &proc_dointvec_minmax,
1059 .strategy = &sysctl_intvec,
1060 .extra1 = &nr_pdflush_threads_min,
1061 .extra2 = &one_thousand,
1064 .ctl_name = VM_SWAPPINESS,
1065 .procname = "swappiness",
1066 .data = &vm_swappiness,
1067 .maxlen = sizeof(vm_swappiness),
1069 .proc_handler = &proc_dointvec_minmax,
1070 .strategy = &sysctl_intvec,
1072 .extra2 = &one_hundred,
1074 #ifdef CONFIG_HUGETLB_PAGE
1076 .procname = "nr_hugepages",
1078 .maxlen = sizeof(unsigned long),
1080 .proc_handler = &hugetlb_sysctl_handler,
1081 .extra1 = (void *)&hugetlb_zero,
1082 .extra2 = (void *)&hugetlb_infinity,
1085 .ctl_name = VM_HUGETLB_GROUP,
1086 .procname = "hugetlb_shm_group",
1087 .data = &sysctl_hugetlb_shm_group,
1088 .maxlen = sizeof(gid_t),
1090 .proc_handler = &proc_dointvec,
1093 .ctl_name = CTL_UNNUMBERED,
1094 .procname = "hugepages_treat_as_movable",
1095 .data = &hugepages_treat_as_movable,
1096 .maxlen = sizeof(int),
1098 .proc_handler = &hugetlb_treat_movable_handler,
1101 .ctl_name = CTL_UNNUMBERED,
1102 .procname = "nr_overcommit_hugepages",
1104 .maxlen = sizeof(unsigned long),
1106 .proc_handler = &hugetlb_overcommit_handler,
1107 .extra1 = (void *)&hugetlb_zero,
1108 .extra2 = (void *)&hugetlb_infinity,
1112 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1113 .procname = "lowmem_reserve_ratio",
1114 .data = &sysctl_lowmem_reserve_ratio,
1115 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1117 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1118 .strategy = &sysctl_intvec,
1121 .ctl_name = VM_DROP_PAGECACHE,
1122 .procname = "drop_caches",
1123 .data = &sysctl_drop_caches,
1124 .maxlen = sizeof(int),
1126 .proc_handler = drop_caches_sysctl_handler,
1127 .strategy = &sysctl_intvec,
1130 .ctl_name = VM_MIN_FREE_KBYTES,
1131 .procname = "min_free_kbytes",
1132 .data = &min_free_kbytes,
1133 .maxlen = sizeof(min_free_kbytes),
1135 .proc_handler = &min_free_kbytes_sysctl_handler,
1136 .strategy = &sysctl_intvec,
1140 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1141 .procname = "percpu_pagelist_fraction",
1142 .data = &percpu_pagelist_fraction,
1143 .maxlen = sizeof(percpu_pagelist_fraction),
1145 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1146 .strategy = &sysctl_intvec,
1147 .extra1 = &min_percpu_pagelist_fract,
1151 .ctl_name = VM_MAX_MAP_COUNT,
1152 .procname = "max_map_count",
1153 .data = &sysctl_max_map_count,
1154 .maxlen = sizeof(sysctl_max_map_count),
1156 .proc_handler = &proc_dointvec
1160 .ctl_name = CTL_UNNUMBERED,
1161 .procname = "nr_trim_pages",
1162 .data = &sysctl_nr_trim_pages,
1163 .maxlen = sizeof(sysctl_nr_trim_pages),
1165 .proc_handler = &proc_dointvec_minmax,
1166 .strategy = &sysctl_intvec,
1171 .ctl_name = VM_LAPTOP_MODE,
1172 .procname = "laptop_mode",
1173 .data = &laptop_mode,
1174 .maxlen = sizeof(laptop_mode),
1176 .proc_handler = &proc_dointvec_jiffies,
1177 .strategy = &sysctl_jiffies,
1180 .ctl_name = VM_BLOCK_DUMP,
1181 .procname = "block_dump",
1182 .data = &block_dump,
1183 .maxlen = sizeof(block_dump),
1185 .proc_handler = &proc_dointvec,
1186 .strategy = &sysctl_intvec,
1190 .ctl_name = VM_VFS_CACHE_PRESSURE,
1191 .procname = "vfs_cache_pressure",
1192 .data = &sysctl_vfs_cache_pressure,
1193 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1195 .proc_handler = &proc_dointvec,
1196 .strategy = &sysctl_intvec,
1199 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1201 .ctl_name = VM_LEGACY_VA_LAYOUT,
1202 .procname = "legacy_va_layout",
1203 .data = &sysctl_legacy_va_layout,
1204 .maxlen = sizeof(sysctl_legacy_va_layout),
1206 .proc_handler = &proc_dointvec,
1207 .strategy = &sysctl_intvec,
1213 .ctl_name = VM_ZONE_RECLAIM_MODE,
1214 .procname = "zone_reclaim_mode",
1215 .data = &zone_reclaim_mode,
1216 .maxlen = sizeof(zone_reclaim_mode),
1218 .proc_handler = &proc_dointvec,
1219 .strategy = &sysctl_intvec,
1223 .ctl_name = VM_MIN_UNMAPPED,
1224 .procname = "min_unmapped_ratio",
1225 .data = &sysctl_min_unmapped_ratio,
1226 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1228 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1229 .strategy = &sysctl_intvec,
1231 .extra2 = &one_hundred,
1234 .ctl_name = VM_MIN_SLAB,
1235 .procname = "min_slab_ratio",
1236 .data = &sysctl_min_slab_ratio,
1237 .maxlen = sizeof(sysctl_min_slab_ratio),
1239 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1240 .strategy = &sysctl_intvec,
1242 .extra2 = &one_hundred,
1247 .ctl_name = CTL_UNNUMBERED,
1248 .procname = "stat_interval",
1249 .data = &sysctl_stat_interval,
1250 .maxlen = sizeof(sysctl_stat_interval),
1252 .proc_handler = &proc_dointvec_jiffies,
1253 .strategy = &sysctl_jiffies,
1256 #ifdef CONFIG_SECURITY
1258 .ctl_name = CTL_UNNUMBERED,
1259 .procname = "mmap_min_addr",
1260 .data = &mmap_min_addr,
1261 .maxlen = sizeof(unsigned long),
1263 .proc_handler = &proc_doulongvec_minmax,
1268 .ctl_name = CTL_UNNUMBERED,
1269 .procname = "numa_zonelist_order",
1270 .data = &numa_zonelist_order,
1271 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1273 .proc_handler = &numa_zonelist_order_handler,
1274 .strategy = &sysctl_string,
1277 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1278 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1280 .ctl_name = VM_VDSO_ENABLED,
1281 .procname = "vdso_enabled",
1282 .data = &vdso_enabled,
1283 .maxlen = sizeof(vdso_enabled),
1285 .proc_handler = &proc_dointvec,
1286 .strategy = &sysctl_intvec,
1290 #ifdef CONFIG_HIGHMEM
1292 .ctl_name = CTL_UNNUMBERED,
1293 .procname = "highmem_is_dirtyable",
1294 .data = &vm_highmem_is_dirtyable,
1295 .maxlen = sizeof(vm_highmem_is_dirtyable),
1297 .proc_handler = &proc_dointvec_minmax,
1298 .strategy = &sysctl_intvec,
1303 #ifdef CONFIG_UNEVICTABLE_LRU
1305 .ctl_name = CTL_UNNUMBERED,
1306 .procname = "scan_unevictable_pages",
1307 .data = &scan_unevictable_pages,
1308 .maxlen = sizeof(scan_unevictable_pages),
1310 .proc_handler = &scan_unevictable_handler,
1314 * NOTE: do not add new entries to this table unless you have read
1315 * Documentation/sysctl/ctl_unnumbered.txt
1320 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1321 static struct ctl_table binfmt_misc_table[] = {
1326 static struct ctl_table fs_table[] = {
1328 .ctl_name = FS_NRINODE,
1329 .procname = "inode-nr",
1330 .data = &inodes_stat,
1331 .maxlen = 2*sizeof(int),
1333 .proc_handler = &proc_dointvec,
1336 .ctl_name = FS_STATINODE,
1337 .procname = "inode-state",
1338 .data = &inodes_stat,
1339 .maxlen = 7*sizeof(int),
1341 .proc_handler = &proc_dointvec,
1344 .procname = "file-nr",
1345 .data = &files_stat,
1346 .maxlen = 3*sizeof(int),
1348 .proc_handler = &proc_nr_files,
1351 .ctl_name = FS_MAXFILE,
1352 .procname = "file-max",
1353 .data = &files_stat.max_files,
1354 .maxlen = sizeof(int),
1356 .proc_handler = &proc_dointvec,
1359 .ctl_name = CTL_UNNUMBERED,
1360 .procname = "nr_open",
1361 .data = &sysctl_nr_open,
1362 .maxlen = sizeof(int),
1364 .proc_handler = &proc_dointvec_minmax,
1365 .extra1 = &sysctl_nr_open_min,
1366 .extra2 = &sysctl_nr_open_max,
1369 .ctl_name = FS_DENTRY,
1370 .procname = "dentry-state",
1371 .data = &dentry_stat,
1372 .maxlen = 6*sizeof(int),
1374 .proc_handler = &proc_dointvec,
1377 .ctl_name = FS_OVERFLOWUID,
1378 .procname = "overflowuid",
1379 .data = &fs_overflowuid,
1380 .maxlen = sizeof(int),
1382 .proc_handler = &proc_dointvec_minmax,
1383 .strategy = &sysctl_intvec,
1384 .extra1 = &minolduid,
1385 .extra2 = &maxolduid,
1388 .ctl_name = FS_OVERFLOWGID,
1389 .procname = "overflowgid",
1390 .data = &fs_overflowgid,
1391 .maxlen = sizeof(int),
1393 .proc_handler = &proc_dointvec_minmax,
1394 .strategy = &sysctl_intvec,
1395 .extra1 = &minolduid,
1396 .extra2 = &maxolduid,
1398 #ifdef CONFIG_FILE_LOCKING
1400 .ctl_name = FS_LEASES,
1401 .procname = "leases-enable",
1402 .data = &leases_enable,
1403 .maxlen = sizeof(int),
1405 .proc_handler = &proc_dointvec,
1408 #ifdef CONFIG_DNOTIFY
1410 .ctl_name = FS_DIR_NOTIFY,
1411 .procname = "dir-notify-enable",
1412 .data = &dir_notify_enable,
1413 .maxlen = sizeof(int),
1415 .proc_handler = &proc_dointvec,
1419 #ifdef CONFIG_FILE_LOCKING
1421 .ctl_name = FS_LEASE_TIME,
1422 .procname = "lease-break-time",
1423 .data = &lease_break_time,
1424 .maxlen = sizeof(int),
1426 .proc_handler = &proc_dointvec,
1431 .procname = "aio-nr",
1433 .maxlen = sizeof(aio_nr),
1435 .proc_handler = &proc_doulongvec_minmax,
1438 .procname = "aio-max-nr",
1439 .data = &aio_max_nr,
1440 .maxlen = sizeof(aio_max_nr),
1442 .proc_handler = &proc_doulongvec_minmax,
1444 #endif /* CONFIG_AIO */
1445 #ifdef CONFIG_INOTIFY_USER
1447 .ctl_name = FS_INOTIFY,
1448 .procname = "inotify",
1450 .child = inotify_table,
1455 .procname = "epoll",
1457 .child = epoll_table,
1462 .ctl_name = KERN_SETUID_DUMPABLE,
1463 .procname = "suid_dumpable",
1464 .data = &suid_dumpable,
1465 .maxlen = sizeof(int),
1467 .proc_handler = &proc_dointvec_minmax,
1468 .strategy = &sysctl_intvec,
1472 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1474 .ctl_name = CTL_UNNUMBERED,
1475 .procname = "binfmt_misc",
1477 .child = binfmt_misc_table,
1481 * NOTE: do not add new entries to this table unless you have read
1482 * Documentation/sysctl/ctl_unnumbered.txt
1487 static struct ctl_table debug_table[] = {
1488 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1490 .ctl_name = CTL_UNNUMBERED,
1491 .procname = "exception-trace",
1492 .data = &show_unhandled_signals,
1493 .maxlen = sizeof(int),
1495 .proc_handler = proc_dointvec
1501 static struct ctl_table dev_table[] = {
1505 static DEFINE_SPINLOCK(sysctl_lock);
1507 /* called under sysctl_lock */
1508 static int use_table(struct ctl_table_header *p)
1510 if (unlikely(p->unregistering))
1516 /* called under sysctl_lock */
1517 static void unuse_table(struct ctl_table_header *p)
1520 if (unlikely(p->unregistering))
1521 complete(p->unregistering);
1524 /* called under sysctl_lock, will reacquire if has to wait */
1525 static void start_unregistering(struct ctl_table_header *p)
1528 * if p->used is 0, nobody will ever touch that entry again;
1529 * we'll eliminate all paths to it before dropping sysctl_lock
1531 if (unlikely(p->used)) {
1532 struct completion wait;
1533 init_completion(&wait);
1534 p->unregistering = &wait;
1535 spin_unlock(&sysctl_lock);
1536 wait_for_completion(&wait);
1537 spin_lock(&sysctl_lock);
1539 /* anything non-NULL; we'll never dereference it */
1540 p->unregistering = ERR_PTR(-EINVAL);
1543 * do not remove from the list until nobody holds it; walking the
1544 * list in do_sysctl() relies on that.
1546 list_del_init(&p->ctl_entry);
1549 void sysctl_head_get(struct ctl_table_header *head)
1551 spin_lock(&sysctl_lock);
1553 spin_unlock(&sysctl_lock);
1556 void sysctl_head_put(struct ctl_table_header *head)
1558 spin_lock(&sysctl_lock);
1561 spin_unlock(&sysctl_lock);
1564 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1568 spin_lock(&sysctl_lock);
1569 if (!use_table(head))
1570 head = ERR_PTR(-ENOENT);
1571 spin_unlock(&sysctl_lock);
1575 void sysctl_head_finish(struct ctl_table_header *head)
1579 spin_lock(&sysctl_lock);
1581 spin_unlock(&sysctl_lock);
1584 static struct ctl_table_set *
1585 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1587 struct ctl_table_set *set = &root->default_set;
1589 set = root->lookup(root, namespaces);
1593 static struct list_head *
1594 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1596 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1600 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1601 struct ctl_table_header *prev)
1603 struct ctl_table_root *root;
1604 struct list_head *header_list;
1605 struct ctl_table_header *head;
1606 struct list_head *tmp;
1608 spin_lock(&sysctl_lock);
1611 tmp = &prev->ctl_entry;
1615 tmp = &root_table_header.ctl_entry;
1617 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1619 if (!use_table(head))
1621 spin_unlock(&sysctl_lock);
1626 header_list = lookup_header_list(root, namespaces);
1627 if (tmp != header_list)
1631 root = list_entry(root->root_list.next,
1632 struct ctl_table_root, root_list);
1633 if (root == &sysctl_table_root)
1635 header_list = lookup_header_list(root, namespaces);
1636 } while (list_empty(header_list));
1637 tmp = header_list->next;
1640 spin_unlock(&sysctl_lock);
1644 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1646 return __sysctl_head_next(current->nsproxy, prev);
1649 void register_sysctl_root(struct ctl_table_root *root)
1651 spin_lock(&sysctl_lock);
1652 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1653 spin_unlock(&sysctl_lock);
1656 #ifdef CONFIG_SYSCTL_SYSCALL
1657 /* Perform the actual read/write of a sysctl table entry. */
1658 static int do_sysctl_strategy(struct ctl_table_root *root,
1659 struct ctl_table *table,
1660 void __user *oldval, size_t __user *oldlenp,
1661 void __user *newval, size_t newlen)
1669 if (sysctl_perm(root, table, op))
1672 if (table->strategy) {
1673 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1680 /* If there is no strategy routine, or if the strategy returns
1681 * zero, proceed with automatic r/w */
1682 if (table->data && table->maxlen) {
1683 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1690 static int parse_table(int __user *name, int nlen,
1691 void __user *oldval, size_t __user *oldlenp,
1692 void __user *newval, size_t newlen,
1693 struct ctl_table_root *root,
1694 struct ctl_table *table)
1700 if (get_user(n, name))
1702 for ( ; table->ctl_name || table->procname; table++) {
1703 if (!table->ctl_name)
1705 if (n == table->ctl_name) {
1708 if (sysctl_perm(root, table, MAY_EXEC))
1712 table = table->child;
1715 error = do_sysctl_strategy(root, table,
1724 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1725 void __user *newval, size_t newlen)
1727 struct ctl_table_header *head;
1728 int error = -ENOTDIR;
1730 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1734 if (!oldlenp || get_user(old_len, oldlenp))
1738 for (head = sysctl_head_next(NULL); head;
1739 head = sysctl_head_next(head)) {
1740 error = parse_table(name, nlen, oldval, oldlenp,
1742 head->root, head->ctl_table);
1743 if (error != -ENOTDIR) {
1744 sysctl_head_finish(head);
1751 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1753 struct __sysctl_args tmp;
1756 if (copy_from_user(&tmp, args, sizeof(tmp)))
1759 error = deprecated_sysctl_warning(&tmp);
1764 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1765 tmp.newval, tmp.newlen);
1770 #endif /* CONFIG_SYSCTL_SYSCALL */
1773 * sysctl_perm does NOT grant the superuser all rights automatically, because
1774 * some sysctl variables are readonly even to root.
1777 static int test_perm(int mode, int op)
1779 if (!current_euid())
1781 else if (in_egroup_p(0))
1783 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1788 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1793 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1797 if (root->permissions)
1798 mode = root->permissions(root, current->nsproxy, table);
1802 return test_perm(mode, op);
1805 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1807 for (; table->ctl_name || table->procname; table++) {
1808 table->parent = parent;
1810 sysctl_set_parent(table, table->child);
1814 static __init int sysctl_init(void)
1816 sysctl_set_parent(NULL, root_table);
1817 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1820 err = sysctl_check_table(current->nsproxy, root_table);
1826 core_initcall(sysctl_init);
1828 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1829 struct ctl_table *table)
1831 struct ctl_table *p;
1832 const char *s = branch->procname;
1834 /* branch should have named subdirectory as its first element */
1835 if (!s || !branch->child)
1838 /* ... and nothing else */
1839 if (branch[1].procname || branch[1].ctl_name)
1842 /* table should contain subdirectory with the same name */
1843 for (p = table; p->procname || p->ctl_name; p++) {
1846 if (p->procname && strcmp(p->procname, s) == 0)
1852 /* see if attaching q to p would be an improvement */
1853 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1855 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1856 struct ctl_table *next;
1858 int not_in_parent = !p->attached_by;
1860 while ((next = is_branch_in(by, to)) != NULL) {
1861 if (by == q->attached_by)
1863 if (to == p->attached_by)
1869 if (is_better && not_in_parent) {
1870 q->attached_by = by;
1871 q->attached_to = to;
1877 * __register_sysctl_paths - register a sysctl hierarchy
1878 * @root: List of sysctl headers to register on
1879 * @namespaces: Data to compute which lists of sysctl entries are visible
1880 * @path: The path to the directory the sysctl table is in.
1881 * @table: the top-level table structure
1883 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1884 * array. A completely 0 filled entry terminates the table.
1886 * The members of the &struct ctl_table structure are used as follows:
1888 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1889 * must be unique within that level of sysctl
1891 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1892 * enter a sysctl file
1894 * data - a pointer to data for use by proc_handler
1896 * maxlen - the maximum size in bytes of the data
1898 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1900 * child - a pointer to the child sysctl table if this entry is a directory, or
1903 * proc_handler - the text handler routine (described below)
1905 * strategy - the strategy routine (described below)
1907 * de - for internal use by the sysctl routines
1909 * extra1, extra2 - extra pointers usable by the proc handler routines
1911 * Leaf nodes in the sysctl tree will be represented by a single file
1912 * under /proc; non-leaf nodes will be represented by directories.
1914 * sysctl(2) can automatically manage read and write requests through
1915 * the sysctl table. The data and maxlen fields of the ctl_table
1916 * struct enable minimal validation of the values being written to be
1917 * performed, and the mode field allows minimal authentication.
1919 * More sophisticated management can be enabled by the provision of a
1920 * strategy routine with the table entry. This will be called before
1921 * any automatic read or write of the data is performed.
1923 * The strategy routine may return
1925 * < 0 - Error occurred (error is passed to user process)
1927 * 0 - OK - proceed with automatic read or write.
1929 * > 0 - OK - read or write has been done by the strategy routine, so
1930 * return immediately.
1932 * There must be a proc_handler routine for any terminal nodes
1933 * mirrored under /proc/sys (non-terminals are handled by a built-in
1934 * directory handler). Several default handlers are available to
1935 * cover common cases -
1937 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1938 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1939 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1941 * It is the handler's job to read the input buffer from user memory
1942 * and process it. The handler should return 0 on success.
1944 * This routine returns %NULL on a failure to register, and a pointer
1945 * to the table header on success.
1947 struct ctl_table_header *__register_sysctl_paths(
1948 struct ctl_table_root *root,
1949 struct nsproxy *namespaces,
1950 const struct ctl_path *path, struct ctl_table *table)
1952 struct ctl_table_header *header;
1953 struct ctl_table *new, **prevp;
1954 unsigned int n, npath;
1955 struct ctl_table_set *set;
1957 /* Count the path components */
1958 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1962 * For each path component, allocate a 2-element ctl_table array.
1963 * The first array element will be filled with the sysctl entry
1964 * for this, the second will be the sentinel (ctl_name == 0).
1966 * We allocate everything in one go so that we don't have to
1967 * worry about freeing additional memory in unregister_sysctl_table.
1969 header = kzalloc(sizeof(struct ctl_table_header) +
1970 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1974 new = (struct ctl_table *) (header + 1);
1976 /* Now connect the dots */
1977 prevp = &header->ctl_table;
1978 for (n = 0; n < npath; ++n, ++path) {
1979 /* Copy the procname */
1980 new->procname = path->procname;
1981 new->ctl_name = path->ctl_name;
1985 prevp = &new->child;
1990 header->ctl_table_arg = table;
1992 INIT_LIST_HEAD(&header->ctl_entry);
1994 header->unregistering = NULL;
1995 header->root = root;
1996 sysctl_set_parent(NULL, header->ctl_table);
1998 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1999 if (sysctl_check_table(namespaces, header->ctl_table)) {
2004 spin_lock(&sysctl_lock);
2005 header->set = lookup_header_set(root, namespaces);
2006 header->attached_by = header->ctl_table;
2007 header->attached_to = root_table;
2008 header->parent = &root_table_header;
2009 for (set = header->set; set; set = set->parent) {
2010 struct ctl_table_header *p;
2011 list_for_each_entry(p, &set->list, ctl_entry) {
2012 if (p->unregistering)
2014 try_attach(p, header);
2017 header->parent->count++;
2018 list_add_tail(&header->ctl_entry, &header->set->list);
2019 spin_unlock(&sysctl_lock);
2025 * register_sysctl_table_path - register a sysctl table hierarchy
2026 * @path: The path to the directory the sysctl table is in.
2027 * @table: the top-level table structure
2029 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2030 * array. A completely 0 filled entry terminates the table.
2032 * See __register_sysctl_paths for more details.
2034 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2035 struct ctl_table *table)
2037 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2042 * register_sysctl_table - register a sysctl table hierarchy
2043 * @table: the top-level table structure
2045 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2046 * array. A completely 0 filled entry terminates the table.
2048 * See register_sysctl_paths for more details.
2050 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2052 static const struct ctl_path null_path[] = { {} };
2054 return register_sysctl_paths(null_path, table);
2058 * unregister_sysctl_table - unregister a sysctl table hierarchy
2059 * @header: the header returned from register_sysctl_table
2061 * Unregisters the sysctl table and all children. proc entries may not
2062 * actually be removed until they are no longer used by anyone.
2064 void unregister_sysctl_table(struct ctl_table_header * header)
2071 spin_lock(&sysctl_lock);
2072 start_unregistering(header);
2073 if (!--header->parent->count) {
2075 kfree(header->parent);
2077 if (!--header->count)
2079 spin_unlock(&sysctl_lock);
2082 int sysctl_is_seen(struct ctl_table_header *p)
2084 struct ctl_table_set *set = p->set;
2086 spin_lock(&sysctl_lock);
2087 if (p->unregistering)
2089 else if (!set->is_seen)
2092 res = set->is_seen(set);
2093 spin_unlock(&sysctl_lock);
2097 void setup_sysctl_set(struct ctl_table_set *p,
2098 struct ctl_table_set *parent,
2099 int (*is_seen)(struct ctl_table_set *))
2101 INIT_LIST_HEAD(&p->list);
2102 p->parent = parent ? parent : &sysctl_table_root.default_set;
2103 p->is_seen = is_seen;
2106 #else /* !CONFIG_SYSCTL */
2107 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2112 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2113 struct ctl_table *table)
2118 void unregister_sysctl_table(struct ctl_table_header * table)
2122 void setup_sysctl_set(struct ctl_table_set *p,
2123 struct ctl_table_set *parent,
2124 int (*is_seen)(struct ctl_table_set *))
2128 void sysctl_head_put(struct ctl_table_header *head)
2132 #endif /* CONFIG_SYSCTL */
2138 #ifdef CONFIG_PROC_SYSCTL
2140 static int _proc_do_string(void* data, int maxlen, int write,
2141 struct file *filp, void __user *buffer,
2142 size_t *lenp, loff_t *ppos)
2148 if (!data || !maxlen || !*lenp) {
2156 while (len < *lenp) {
2157 if (get_user(c, p++))
2159 if (c == 0 || c == '\n')
2165 if(copy_from_user(data, buffer, len))
2167 ((char *) data)[len] = 0;
2185 if(copy_to_user(buffer, data, len))
2188 if(put_user('\n', ((char __user *) buffer) + len))
2199 * proc_dostring - read a string sysctl
2200 * @table: the sysctl table
2201 * @write: %TRUE if this is a write to the sysctl file
2202 * @filp: the file structure
2203 * @buffer: the user buffer
2204 * @lenp: the size of the user buffer
2205 * @ppos: file position
2207 * Reads/writes a string from/to the user buffer. If the kernel
2208 * buffer provided is not large enough to hold the string, the
2209 * string is truncated. The copied string is %NULL-terminated.
2210 * If the string is being read by the user process, it is copied
2211 * and a newline '\n' is added. It is truncated if the buffer is
2214 * Returns 0 on success.
2216 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2217 void __user *buffer, size_t *lenp, loff_t *ppos)
2219 return _proc_do_string(table->data, table->maxlen, write, filp,
2220 buffer, lenp, ppos);
2224 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2226 int write, void *data)
2229 *valp = *negp ? -*lvalp : *lvalp;
2234 *lvalp = (unsigned long)-val;
2237 *lvalp = (unsigned long)val;
2243 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2244 int write, struct file *filp, void __user *buffer,
2245 size_t *lenp, loff_t *ppos,
2246 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2247 int write, void *data),
2250 #define TMPBUFLEN 21
2251 int *i, vleft, first=1, neg, val;
2255 char buf[TMPBUFLEN], *p;
2256 char __user *s = buffer;
2258 if (!tbl_data || !table->maxlen || !*lenp ||
2259 (*ppos && !write)) {
2264 i = (int *) tbl_data;
2265 vleft = table->maxlen / sizeof(*i);
2269 conv = do_proc_dointvec_conv;
2271 for (; left && vleft--; i++, first=0) {
2286 if (len > sizeof(buf) - 1)
2287 len = sizeof(buf) - 1;
2288 if (copy_from_user(buf, s, len))
2292 if (*p == '-' && left > 1) {
2296 if (*p < '0' || *p > '9')
2299 lval = simple_strtoul(p, &p, 0);
2302 if ((len < left) && *p && !isspace(*p))
2309 if (conv(&neg, &lval, i, 1, data))
2316 if (conv(&neg, &lval, i, 0, data))
2319 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2323 if(copy_to_user(s, buf, len))
2330 if (!write && !first && left) {
2331 if(put_user('\n', s))
2338 if (get_user(c, s++))
2353 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2354 void __user *buffer, size_t *lenp, loff_t *ppos,
2355 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2356 int write, void *data),
2359 return __do_proc_dointvec(table->data, table, write, filp,
2360 buffer, lenp, ppos, conv, data);
2364 * proc_dointvec - read a vector of integers
2365 * @table: the sysctl table
2366 * @write: %TRUE if this is a write to the sysctl file
2367 * @filp: the file structure
2368 * @buffer: the user buffer
2369 * @lenp: the size of the user buffer
2370 * @ppos: file position
2372 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2373 * values from/to the user buffer, treated as an ASCII string.
2375 * Returns 0 on success.
2377 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2378 void __user *buffer, size_t *lenp, loff_t *ppos)
2380 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2385 * Taint values can only be increased
2386 * This means we can safely use a temporary.
2388 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2389 void __user *buffer, size_t *lenp, loff_t *ppos)
2392 unsigned long tmptaint = get_taint();
2395 if (write && !capable(CAP_SYS_ADMIN))
2400 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2406 * Poor man's atomic or. Not worth adding a primitive
2407 * to everyone's atomic.h for this
2410 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2411 if ((tmptaint >> i) & 1)
2419 struct do_proc_dointvec_minmax_conv_param {
2424 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2426 int write, void *data)
2428 struct do_proc_dointvec_minmax_conv_param *param = data;
2430 int val = *negp ? -*lvalp : *lvalp;
2431 if ((param->min && *param->min > val) ||
2432 (param->max && *param->max < val))
2439 *lvalp = (unsigned long)-val;
2442 *lvalp = (unsigned long)val;
2449 * proc_dointvec_minmax - read a vector of integers with min/max values
2450 * @table: the sysctl table
2451 * @write: %TRUE if this is a write to the sysctl file
2452 * @filp: the file structure
2453 * @buffer: the user buffer
2454 * @lenp: the size of the user buffer
2455 * @ppos: file position
2457 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2458 * values from/to the user buffer, treated as an ASCII string.
2460 * This routine will ensure the values are within the range specified by
2461 * table->extra1 (min) and table->extra2 (max).
2463 * Returns 0 on success.
2465 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2466 void __user *buffer, size_t *lenp, loff_t *ppos)
2468 struct do_proc_dointvec_minmax_conv_param param = {
2469 .min = (int *) table->extra1,
2470 .max = (int *) table->extra2,
2472 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2473 do_proc_dointvec_minmax_conv, ¶m);
2476 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2478 void __user *buffer,
2479 size_t *lenp, loff_t *ppos,
2480 unsigned long convmul,
2481 unsigned long convdiv)
2483 #define TMPBUFLEN 21
2484 unsigned long *i, *min, *max, val;
2485 int vleft, first=1, neg;
2487 char buf[TMPBUFLEN], *p;
2488 char __user *s = buffer;
2490 if (!data || !table->maxlen || !*lenp ||
2491 (*ppos && !write)) {
2496 i = (unsigned long *) data;
2497 min = (unsigned long *) table->extra1;
2498 max = (unsigned long *) table->extra2;
2499 vleft = table->maxlen / sizeof(unsigned long);
2502 for (; left && vleft--; i++, min++, max++, first=0) {
2517 if (len > TMPBUFLEN-1)
2519 if (copy_from_user(buf, s, len))
2523 if (*p == '-' && left > 1) {
2527 if (*p < '0' || *p > '9')
2529 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2531 if ((len < left) && *p && !isspace(*p))
2540 if ((min && val < *min) || (max && val > *max))
2547 sprintf(p, "%lu", convdiv * (*i) / convmul);
2551 if(copy_to_user(s, buf, len))
2558 if (!write && !first && left) {
2559 if(put_user('\n', s))
2566 if (get_user(c, s++))
2581 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2583 void __user *buffer,
2584 size_t *lenp, loff_t *ppos,
2585 unsigned long convmul,
2586 unsigned long convdiv)
2588 return __do_proc_doulongvec_minmax(table->data, table, write,
2589 filp, buffer, lenp, ppos, convmul, convdiv);
2593 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2594 * @table: the sysctl table
2595 * @write: %TRUE if this is a write to the sysctl file
2596 * @filp: the file structure
2597 * @buffer: the user buffer
2598 * @lenp: the size of the user buffer
2599 * @ppos: file position
2601 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2602 * values from/to the user buffer, treated as an ASCII string.
2604 * This routine will ensure the values are within the range specified by
2605 * table->extra1 (min) and table->extra2 (max).
2607 * Returns 0 on success.
2609 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2610 void __user *buffer, size_t *lenp, loff_t *ppos)
2612 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2616 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2617 * @table: the sysctl table
2618 * @write: %TRUE if this is a write to the sysctl file
2619 * @filp: the file structure
2620 * @buffer: the user buffer
2621 * @lenp: the size of the user buffer
2622 * @ppos: file position
2624 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2625 * values from/to the user buffer, treated as an ASCII string. The values
2626 * are treated as milliseconds, and converted to jiffies when they are stored.
2628 * This routine will ensure the values are within the range specified by
2629 * table->extra1 (min) and table->extra2 (max).
2631 * Returns 0 on success.
2633 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2635 void __user *buffer,
2636 size_t *lenp, loff_t *ppos)
2638 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2639 lenp, ppos, HZ, 1000l);
2643 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2645 int write, void *data)
2648 if (*lvalp > LONG_MAX / HZ)
2650 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2656 lval = (unsigned long)-val;
2659 lval = (unsigned long)val;
2666 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2668 int write, void *data)
2671 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2673 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2679 lval = (unsigned long)-val;
2682 lval = (unsigned long)val;
2684 *lvalp = jiffies_to_clock_t(lval);
2689 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2691 int write, void *data)
2694 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2700 lval = (unsigned long)-val;
2703 lval = (unsigned long)val;
2705 *lvalp = jiffies_to_msecs(lval);
2711 * proc_dointvec_jiffies - read a vector of integers as seconds
2712 * @table: the sysctl table
2713 * @write: %TRUE if this is a write to the sysctl file
2714 * @filp: the file structure
2715 * @buffer: the user buffer
2716 * @lenp: the size of the user buffer
2717 * @ppos: file position
2719 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2720 * values from/to the user buffer, treated as an ASCII string.
2721 * The values read are assumed to be in seconds, and are converted into
2724 * Returns 0 on success.
2726 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2727 void __user *buffer, size_t *lenp, loff_t *ppos)
2729 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2730 do_proc_dointvec_jiffies_conv,NULL);
2734 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2735 * @table: the sysctl table
2736 * @write: %TRUE if this is a write to the sysctl file
2737 * @filp: the file structure
2738 * @buffer: the user buffer
2739 * @lenp: the size of the user buffer
2740 * @ppos: pointer to the file position
2742 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2743 * values from/to the user buffer, treated as an ASCII string.
2744 * The values read are assumed to be in 1/USER_HZ seconds, and
2745 * are converted into jiffies.
2747 * Returns 0 on success.
2749 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2750 void __user *buffer, size_t *lenp, loff_t *ppos)
2752 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2753 do_proc_dointvec_userhz_jiffies_conv,NULL);
2757 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2758 * @table: the sysctl table
2759 * @write: %TRUE if this is a write to the sysctl file
2760 * @filp: the file structure
2761 * @buffer: the user buffer
2762 * @lenp: the size of the user buffer
2763 * @ppos: file position
2764 * @ppos: the current position in the file
2766 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2767 * values from/to the user buffer, treated as an ASCII string.
2768 * The values read are assumed to be in 1/1000 seconds, and
2769 * are converted into jiffies.
2771 * Returns 0 on success.
2773 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2774 void __user *buffer, size_t *lenp, loff_t *ppos)
2776 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2777 do_proc_dointvec_ms_jiffies_conv, NULL);
2780 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2781 void __user *buffer, size_t *lenp, loff_t *ppos)
2783 struct pid *new_pid;
2787 tmp = pid_vnr(cad_pid);
2789 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2790 lenp, ppos, NULL, NULL);
2794 new_pid = find_get_pid(tmp);
2798 put_pid(xchg(&cad_pid, new_pid));
2802 #else /* CONFIG_PROC_FS */
2804 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2805 void __user *buffer, size_t *lenp, loff_t *ppos)
2810 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2811 void __user *buffer, size_t *lenp, loff_t *ppos)
2816 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2817 void __user *buffer, size_t *lenp, loff_t *ppos)
2822 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2823 void __user *buffer, size_t *lenp, loff_t *ppos)
2828 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2829 void __user *buffer, size_t *lenp, loff_t *ppos)
2834 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2835 void __user *buffer, size_t *lenp, loff_t *ppos)
2840 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2841 void __user *buffer, size_t *lenp, loff_t *ppos)
2846 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2848 void __user *buffer,
2849 size_t *lenp, loff_t *ppos)
2855 #endif /* CONFIG_PROC_FS */
2858 #ifdef CONFIG_SYSCTL_SYSCALL
2860 * General sysctl support routines
2863 /* The generic sysctl data routine (used if no strategy routine supplied) */
2864 int sysctl_data(struct ctl_table *table,
2865 void __user *oldval, size_t __user *oldlenp,
2866 void __user *newval, size_t newlen)
2870 /* Get out of I don't have a variable */
2871 if (!table->data || !table->maxlen)
2874 if (oldval && oldlenp) {
2875 if (get_user(len, oldlenp))
2878 if (len > table->maxlen)
2879 len = table->maxlen;
2880 if (copy_to_user(oldval, table->data, len))
2882 if (put_user(len, oldlenp))
2887 if (newval && newlen) {
2888 if (newlen > table->maxlen)
2889 newlen = table->maxlen;
2891 if (copy_from_user(table->data, newval, newlen))
2897 /* The generic string strategy routine: */
2898 int sysctl_string(struct ctl_table *table,
2899 void __user *oldval, size_t __user *oldlenp,
2900 void __user *newval, size_t newlen)
2902 if (!table->data || !table->maxlen)
2905 if (oldval && oldlenp) {
2907 if (get_user(bufsize, oldlenp))
2910 size_t len = strlen(table->data), copied;
2912 /* This shouldn't trigger for a well-formed sysctl */
2913 if (len > table->maxlen)
2914 len = table->maxlen;
2916 /* Copy up to a max of bufsize-1 bytes of the string */
2917 copied = (len >= bufsize) ? bufsize - 1 : len;
2919 if (copy_to_user(oldval, table->data, copied) ||
2920 put_user(0, (char __user *)(oldval + copied)))
2922 if (put_user(len, oldlenp))
2926 if (newval && newlen) {
2927 size_t len = newlen;
2928 if (len > table->maxlen)
2929 len = table->maxlen;
2930 if(copy_from_user(table->data, newval, len))
2932 if (len == table->maxlen)
2934 ((char *) table->data)[len] = 0;
2940 * This function makes sure that all of the integers in the vector
2941 * are between the minimum and maximum values given in the arrays
2942 * table->extra1 and table->extra2, respectively.
2944 int sysctl_intvec(struct ctl_table *table,
2945 void __user *oldval, size_t __user *oldlenp,
2946 void __user *newval, size_t newlen)
2949 if (newval && newlen) {
2950 int __user *vec = (int __user *) newval;
2951 int *min = (int *) table->extra1;
2952 int *max = (int *) table->extra2;
2956 if (newlen % sizeof(int) != 0)
2959 if (!table->extra1 && !table->extra2)
2962 if (newlen > table->maxlen)
2963 newlen = table->maxlen;
2964 length = newlen / sizeof(int);
2966 for (i = 0; i < length; i++) {
2968 if (get_user(value, vec + i))
2970 if (min && value < min[i])
2972 if (max && value > max[i])
2979 /* Strategy function to convert jiffies to seconds */
2980 int sysctl_jiffies(struct ctl_table *table,
2981 void __user *oldval, size_t __user *oldlenp,
2982 void __user *newval, size_t newlen)
2984 if (oldval && oldlenp) {
2987 if (get_user(olen, oldlenp))
2992 if (olen < sizeof(int))
2995 val = *(int *)(table->data) / HZ;
2996 if (put_user(val, (int __user *)oldval))
2998 if (put_user(sizeof(int), oldlenp))
3002 if (newval && newlen) {
3004 if (newlen != sizeof(int))
3006 if (get_user(new, (int __user *)newval))
3008 *(int *)(table->data) = new*HZ;
3013 /* Strategy function to convert jiffies to seconds */
3014 int sysctl_ms_jiffies(struct ctl_table *table,
3015 void __user *oldval, size_t __user *oldlenp,
3016 void __user *newval, size_t newlen)
3018 if (oldval && oldlenp) {
3021 if (get_user(olen, oldlenp))
3026 if (olen < sizeof(int))
3029 val = jiffies_to_msecs(*(int *)(table->data));
3030 if (put_user(val, (int __user *)oldval))
3032 if (put_user(sizeof(int), oldlenp))
3036 if (newval && newlen) {
3038 if (newlen != sizeof(int))
3040 if (get_user(new, (int __user *)newval))
3042 *(int *)(table->data) = msecs_to_jiffies(new);
3049 #else /* CONFIG_SYSCTL_SYSCALL */
3052 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3054 struct __sysctl_args tmp;
3057 if (copy_from_user(&tmp, args, sizeof(tmp)))
3060 error = deprecated_sysctl_warning(&tmp);
3062 /* If no error reading the parameters then just -ENOSYS ... */
3069 int sysctl_data(struct ctl_table *table,
3070 void __user *oldval, size_t __user *oldlenp,
3071 void __user *newval, size_t newlen)
3076 int sysctl_string(struct ctl_table *table,
3077 void __user *oldval, size_t __user *oldlenp,
3078 void __user *newval, size_t newlen)
3083 int sysctl_intvec(struct ctl_table *table,
3084 void __user *oldval, size_t __user *oldlenp,
3085 void __user *newval, size_t newlen)
3090 int sysctl_jiffies(struct ctl_table *table,
3091 void __user *oldval, size_t __user *oldlenp,
3092 void __user *newval, size_t newlen)
3097 int sysctl_ms_jiffies(struct ctl_table *table,
3098 void __user *oldval, size_t __user *oldlenp,
3099 void __user *newval, size_t newlen)
3104 #endif /* CONFIG_SYSCTL_SYSCALL */
3106 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3108 static int msg_count;
3109 int name[CTL_MAXNAME];
3112 /* Check args->nlen. */
3113 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3116 /* Read in the sysctl name for better debug message logging */
3117 for (i = 0; i < args->nlen; i++)
3118 if (get_user(name[i], args->name + i))
3121 /* Ignore accesses to kernel.version */
3122 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3125 if (msg_count < 5) {
3128 "warning: process `%s' used the deprecated sysctl "
3129 "system call with ", current->comm);
3130 for (i = 0; i < args->nlen; i++)
3131 printk("%d.", name[i]);
3138 * No sense putting this after each symbol definition, twice,
3139 * exception granted :-)
3141 EXPORT_SYMBOL(proc_dointvec);
3142 EXPORT_SYMBOL(proc_dointvec_jiffies);
3143 EXPORT_SYMBOL(proc_dointvec_minmax);
3144 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3145 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3146 EXPORT_SYMBOL(proc_dostring);
3147 EXPORT_SYMBOL(proc_doulongvec_minmax);
3148 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3149 EXPORT_SYMBOL(register_sysctl_table);
3150 EXPORT_SYMBOL(register_sysctl_paths);
3151 EXPORT_SYMBOL(sysctl_intvec);
3152 EXPORT_SYMBOL(sysctl_jiffies);
3153 EXPORT_SYMBOL(sysctl_ms_jiffies);
3154 EXPORT_SYMBOL(sysctl_string);
3155 EXPORT_SYMBOL(sysctl_data);
3156 EXPORT_SYMBOL(unregister_sysctl_table);