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>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
57 #include <asm/stacktrace.h>
61 static int deprecated_sysctl_warning(struct __sysctl_args *args);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
78 extern int min_free_kbytes;
79 extern int pid_max_min, pid_max_max;
80 extern int sysctl_drop_caches;
81 extern int percpu_pagelist_fraction;
82 extern int compat_log;
83 extern int latencytop_enabled;
84 extern int sysctl_nr_open_min, sysctl_nr_open_max;
86 extern int sysctl_nr_trim_pages;
88 #ifdef CONFIG_RCU_TORTURE_TEST
89 extern int rcutorture_runnable;
90 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
92 /* Constants used for minimum and maximum */
93 #ifdef CONFIG_DETECT_SOFTLOCKUP
94 static int sixty = 60;
95 static int neg_one = -1;
98 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
104 static int one_hundred = 100;
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;
149 #ifdef CONFIG_RT_MUTEXES
150 extern int max_lock_depth;
153 #ifdef CONFIG_PROC_SYSCTL
154 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
155 void __user *buffer, size_t *lenp, loff_t *ppos);
156 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
157 void __user *buffer, size_t *lenp, loff_t *ppos);
160 static struct ctl_table root_table[];
161 static struct ctl_table_root sysctl_table_root;
162 static struct ctl_table_header root_table_header = {
164 .ctl_table = root_table,
165 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
166 .root = &sysctl_table_root,
167 .set = &sysctl_table_root.default_set,
169 static struct ctl_table_root sysctl_table_root = {
170 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
171 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
174 static struct ctl_table kern_table[];
175 static struct ctl_table vm_table[];
176 static struct ctl_table fs_table[];
177 static struct ctl_table debug_table[];
178 static struct ctl_table dev_table[];
179 extern struct ctl_table random_table[];
180 #ifdef CONFIG_INOTIFY_USER
181 extern struct ctl_table inotify_table[];
184 extern struct ctl_table epoll_table[];
187 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
188 int sysctl_legacy_va_layout;
191 extern int prove_locking;
192 extern int lock_stat;
194 /* The default sysctl tables: */
196 static struct ctl_table root_table[] = {
198 .ctl_name = CTL_KERN,
199 .procname = "kernel",
216 .ctl_name = CTL_DEBUG,
219 .child = debug_table,
228 * NOTE: do not add new entries to this table unless you have read
229 * Documentation/sysctl/ctl_unnumbered.txt
234 #ifdef CONFIG_SCHED_DEBUG
235 static int min_sched_granularity_ns = 100000; /* 100 usecs */
236 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
237 static int min_wakeup_granularity_ns; /* 0 usecs */
238 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
241 static struct ctl_table kern_table[] = {
242 #ifdef CONFIG_SCHED_DEBUG
244 .ctl_name = CTL_UNNUMBERED,
245 .procname = "sched_min_granularity_ns",
246 .data = &sysctl_sched_min_granularity,
247 .maxlen = sizeof(unsigned int),
249 .proc_handler = &sched_nr_latency_handler,
250 .strategy = &sysctl_intvec,
251 .extra1 = &min_sched_granularity_ns,
252 .extra2 = &max_sched_granularity_ns,
255 .ctl_name = CTL_UNNUMBERED,
256 .procname = "sched_latency_ns",
257 .data = &sysctl_sched_latency,
258 .maxlen = sizeof(unsigned int),
260 .proc_handler = &sched_nr_latency_handler,
261 .strategy = &sysctl_intvec,
262 .extra1 = &min_sched_granularity_ns,
263 .extra2 = &max_sched_granularity_ns,
266 .ctl_name = CTL_UNNUMBERED,
267 .procname = "sched_wakeup_granularity_ns",
268 .data = &sysctl_sched_wakeup_granularity,
269 .maxlen = sizeof(unsigned int),
271 .proc_handler = &proc_dointvec_minmax,
272 .strategy = &sysctl_intvec,
273 .extra1 = &min_wakeup_granularity_ns,
274 .extra2 = &max_wakeup_granularity_ns,
277 .ctl_name = CTL_UNNUMBERED,
278 .procname = "sched_shares_ratelimit",
279 .data = &sysctl_sched_shares_ratelimit,
280 .maxlen = sizeof(unsigned int),
282 .proc_handler = &proc_dointvec,
285 .ctl_name = CTL_UNNUMBERED,
286 .procname = "sched_shares_thresh",
287 .data = &sysctl_sched_shares_thresh,
288 .maxlen = sizeof(unsigned int),
290 .proc_handler = &proc_dointvec_minmax,
291 .strategy = &sysctl_intvec,
295 .ctl_name = CTL_UNNUMBERED,
296 .procname = "sched_child_runs_first",
297 .data = &sysctl_sched_child_runs_first,
298 .maxlen = sizeof(unsigned int),
300 .proc_handler = &proc_dointvec,
303 .ctl_name = CTL_UNNUMBERED,
304 .procname = "sched_features",
305 .data = &sysctl_sched_features,
306 .maxlen = sizeof(unsigned int),
308 .proc_handler = &proc_dointvec,
311 .ctl_name = CTL_UNNUMBERED,
312 .procname = "sched_migration_cost",
313 .data = &sysctl_sched_migration_cost,
314 .maxlen = sizeof(unsigned int),
316 .proc_handler = &proc_dointvec,
319 .ctl_name = CTL_UNNUMBERED,
320 .procname = "sched_nr_migrate",
321 .data = &sysctl_sched_nr_migrate,
322 .maxlen = sizeof(unsigned int),
324 .proc_handler = &proc_dointvec,
328 .ctl_name = CTL_UNNUMBERED,
329 .procname = "sched_rt_period_us",
330 .data = &sysctl_sched_rt_period,
331 .maxlen = sizeof(unsigned int),
333 .proc_handler = &sched_rt_handler,
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "sched_rt_runtime_us",
338 .data = &sysctl_sched_rt_runtime,
339 .maxlen = sizeof(int),
341 .proc_handler = &sched_rt_handler,
344 .ctl_name = CTL_UNNUMBERED,
345 .procname = "sched_compat_yield",
346 .data = &sysctl_sched_compat_yield,
347 .maxlen = sizeof(unsigned int),
349 .proc_handler = &proc_dointvec,
351 #ifdef CONFIG_PROVE_LOCKING
353 .ctl_name = CTL_UNNUMBERED,
354 .procname = "prove_locking",
355 .data = &prove_locking,
356 .maxlen = sizeof(int),
358 .proc_handler = &proc_dointvec,
361 #ifdef CONFIG_LOCK_STAT
363 .ctl_name = CTL_UNNUMBERED,
364 .procname = "lock_stat",
366 .maxlen = sizeof(int),
368 .proc_handler = &proc_dointvec,
372 .ctl_name = KERN_PANIC,
374 .data = &panic_timeout,
375 .maxlen = sizeof(int),
377 .proc_handler = &proc_dointvec,
380 .ctl_name = KERN_CORE_USES_PID,
381 .procname = "core_uses_pid",
382 .data = &core_uses_pid,
383 .maxlen = sizeof(int),
385 .proc_handler = &proc_dointvec,
388 .ctl_name = KERN_CORE_PATTERN,
389 .procname = "core_pattern",
390 .data = core_pattern,
391 .maxlen = CORENAME_MAX_SIZE,
393 .proc_handler = &proc_dostring,
394 .strategy = &sysctl_string,
396 #ifdef CONFIG_PROC_SYSCTL
398 .procname = "tainted",
399 .maxlen = sizeof(long),
401 .proc_handler = &proc_taint,
404 #ifdef CONFIG_LATENCYTOP
406 .procname = "latencytop",
407 .data = &latencytop_enabled,
408 .maxlen = sizeof(int),
410 .proc_handler = &proc_dointvec,
413 #ifdef CONFIG_BLK_DEV_INITRD
415 .ctl_name = KERN_REALROOTDEV,
416 .procname = "real-root-dev",
417 .data = &real_root_dev,
418 .maxlen = sizeof(int),
420 .proc_handler = &proc_dointvec,
424 .ctl_name = CTL_UNNUMBERED,
425 .procname = "print-fatal-signals",
426 .data = &print_fatal_signals,
427 .maxlen = sizeof(int),
429 .proc_handler = &proc_dointvec,
433 .ctl_name = KERN_SPARC_REBOOT,
434 .procname = "reboot-cmd",
435 .data = reboot_command,
438 .proc_handler = &proc_dostring,
439 .strategy = &sysctl_string,
442 .ctl_name = KERN_SPARC_STOP_A,
443 .procname = "stop-a",
444 .data = &stop_a_enabled,
445 .maxlen = sizeof (int),
447 .proc_handler = &proc_dointvec,
450 .ctl_name = KERN_SPARC_SCONS_PWROFF,
451 .procname = "scons-poweroff",
452 .data = &scons_pwroff,
453 .maxlen = sizeof (int),
455 .proc_handler = &proc_dointvec,
458 #ifdef CONFIG_SPARC64
460 .ctl_name = CTL_UNNUMBERED,
461 .procname = "tsb-ratio",
462 .data = &sysctl_tsb_ratio,
463 .maxlen = sizeof (int),
465 .proc_handler = &proc_dointvec,
470 .ctl_name = KERN_HPPA_PWRSW,
471 .procname = "soft-power",
472 .data = &pwrsw_enabled,
473 .maxlen = sizeof (int),
475 .proc_handler = &proc_dointvec,
478 .ctl_name = KERN_HPPA_UNALIGNED,
479 .procname = "unaligned-trap",
480 .data = &unaligned_enabled,
481 .maxlen = sizeof (int),
483 .proc_handler = &proc_dointvec,
487 .ctl_name = KERN_CTLALTDEL,
488 .procname = "ctrl-alt-del",
490 .maxlen = sizeof(int),
492 .proc_handler = &proc_dointvec,
494 #ifdef CONFIG_FUNCTION_TRACER
496 .ctl_name = CTL_UNNUMBERED,
497 .procname = "ftrace_enabled",
498 .data = &ftrace_enabled,
499 .maxlen = sizeof(int),
501 .proc_handler = &ftrace_enable_sysctl,
504 #ifdef CONFIG_STACK_TRACER
506 .ctl_name = CTL_UNNUMBERED,
507 .procname = "stack_tracer_enabled",
508 .data = &stack_tracer_enabled,
509 .maxlen = sizeof(int),
511 .proc_handler = &stack_trace_sysctl,
514 #ifdef CONFIG_TRACING
516 .ctl_name = CTL_UNNUMBERED,
517 .procname = "ftrace_dump_on_oops",
518 .data = &ftrace_dump_on_oops,
519 .maxlen = sizeof(int),
521 .proc_handler = &proc_dointvec,
524 #ifdef CONFIG_MODULES
526 .ctl_name = KERN_MODPROBE,
527 .procname = "modprobe",
528 .data = &modprobe_path,
529 .maxlen = KMOD_PATH_LEN,
531 .proc_handler = &proc_dostring,
532 .strategy = &sysctl_string,
535 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
537 .ctl_name = KERN_HOTPLUG,
538 .procname = "hotplug",
539 .data = &uevent_helper,
540 .maxlen = UEVENT_HELPER_PATH_LEN,
542 .proc_handler = &proc_dostring,
543 .strategy = &sysctl_string,
546 #ifdef CONFIG_CHR_DEV_SG
548 .ctl_name = KERN_SG_BIG_BUFF,
549 .procname = "sg-big-buff",
550 .data = &sg_big_buff,
551 .maxlen = sizeof (int),
553 .proc_handler = &proc_dointvec,
556 #ifdef CONFIG_BSD_PROCESS_ACCT
558 .ctl_name = KERN_ACCT,
561 .maxlen = 3*sizeof(int),
563 .proc_handler = &proc_dointvec,
566 #ifdef CONFIG_MAGIC_SYSRQ
568 .ctl_name = KERN_SYSRQ,
570 .data = &__sysrq_enabled,
571 .maxlen = sizeof (int),
573 .proc_handler = &proc_dointvec,
576 #ifdef CONFIG_PROC_SYSCTL
578 .procname = "cad_pid",
580 .maxlen = sizeof (int),
582 .proc_handler = &proc_do_cad_pid,
586 .ctl_name = KERN_MAX_THREADS,
587 .procname = "threads-max",
588 .data = &max_threads,
589 .maxlen = sizeof(int),
591 .proc_handler = &proc_dointvec,
594 .ctl_name = KERN_RANDOM,
595 .procname = "random",
597 .child = random_table,
600 .ctl_name = KERN_OVERFLOWUID,
601 .procname = "overflowuid",
602 .data = &overflowuid,
603 .maxlen = sizeof(int),
605 .proc_handler = &proc_dointvec_minmax,
606 .strategy = &sysctl_intvec,
607 .extra1 = &minolduid,
608 .extra2 = &maxolduid,
611 .ctl_name = KERN_OVERFLOWGID,
612 .procname = "overflowgid",
613 .data = &overflowgid,
614 .maxlen = sizeof(int),
616 .proc_handler = &proc_dointvec_minmax,
617 .strategy = &sysctl_intvec,
618 .extra1 = &minolduid,
619 .extra2 = &maxolduid,
622 #ifdef CONFIG_MATHEMU
624 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
625 .procname = "ieee_emulation_warnings",
626 .data = &sysctl_ieee_emulation_warnings,
627 .maxlen = sizeof(int),
629 .proc_handler = &proc_dointvec,
633 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
634 .procname = "userprocess_debug",
635 .data = &sysctl_userprocess_debug,
636 .maxlen = sizeof(int),
638 .proc_handler = &proc_dointvec,
642 .ctl_name = KERN_PIDMAX,
643 .procname = "pid_max",
645 .maxlen = sizeof (int),
647 .proc_handler = &proc_dointvec_minmax,
648 .strategy = sysctl_intvec,
649 .extra1 = &pid_max_min,
650 .extra2 = &pid_max_max,
653 .ctl_name = KERN_PANIC_ON_OOPS,
654 .procname = "panic_on_oops",
655 .data = &panic_on_oops,
656 .maxlen = sizeof(int),
658 .proc_handler = &proc_dointvec,
660 #if defined CONFIG_PRINTK
662 .ctl_name = KERN_PRINTK,
663 .procname = "printk",
664 .data = &console_loglevel,
665 .maxlen = 4*sizeof(int),
667 .proc_handler = &proc_dointvec,
670 .ctl_name = KERN_PRINTK_RATELIMIT,
671 .procname = "printk_ratelimit",
672 .data = &printk_ratelimit_state.interval,
673 .maxlen = sizeof(int),
675 .proc_handler = &proc_dointvec_jiffies,
676 .strategy = &sysctl_jiffies,
679 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
680 .procname = "printk_ratelimit_burst",
681 .data = &printk_ratelimit_state.burst,
682 .maxlen = sizeof(int),
684 .proc_handler = &proc_dointvec,
688 .ctl_name = KERN_NGROUPS_MAX,
689 .procname = "ngroups_max",
690 .data = &ngroups_max,
691 .maxlen = sizeof (int),
693 .proc_handler = &proc_dointvec,
695 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
697 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
698 .procname = "unknown_nmi_panic",
699 .data = &unknown_nmi_panic,
700 .maxlen = sizeof (int),
702 .proc_handler = &proc_dointvec,
705 .procname = "nmi_watchdog",
706 .data = &nmi_watchdog_enabled,
707 .maxlen = sizeof (int),
709 .proc_handler = &proc_nmi_enabled,
712 #if defined(CONFIG_X86)
714 .ctl_name = KERN_PANIC_ON_NMI,
715 .procname = "panic_on_unrecovered_nmi",
716 .data = &panic_on_unrecovered_nmi,
717 .maxlen = sizeof(int),
719 .proc_handler = &proc_dointvec,
722 .ctl_name = KERN_BOOTLOADER_TYPE,
723 .procname = "bootloader_type",
724 .data = &bootloader_type,
725 .maxlen = sizeof (int),
727 .proc_handler = &proc_dointvec,
730 .ctl_name = CTL_UNNUMBERED,
731 .procname = "kstack_depth_to_print",
732 .data = &kstack_depth_to_print,
733 .maxlen = sizeof(int),
735 .proc_handler = &proc_dointvec,
738 .ctl_name = CTL_UNNUMBERED,
739 .procname = "io_delay_type",
740 .data = &io_delay_type,
741 .maxlen = sizeof(int),
743 .proc_handler = &proc_dointvec,
746 #if defined(CONFIG_MMU)
748 .ctl_name = KERN_RANDOMIZE,
749 .procname = "randomize_va_space",
750 .data = &randomize_va_space,
751 .maxlen = sizeof(int),
753 .proc_handler = &proc_dointvec,
756 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
758 .ctl_name = KERN_SPIN_RETRY,
759 .procname = "spin_retry",
761 .maxlen = sizeof (int),
763 .proc_handler = &proc_dointvec,
766 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
768 .procname = "acpi_video_flags",
769 .data = &acpi_realmode_flags,
770 .maxlen = sizeof (unsigned long),
772 .proc_handler = &proc_doulongvec_minmax,
777 .ctl_name = KERN_IA64_UNALIGNED,
778 .procname = "ignore-unaligned-usertrap",
779 .data = &no_unaligned_warning,
780 .maxlen = sizeof (int),
782 .proc_handler = &proc_dointvec,
785 #ifdef CONFIG_DETECT_SOFTLOCKUP
787 .ctl_name = CTL_UNNUMBERED,
788 .procname = "softlockup_panic",
789 .data = &softlockup_panic,
790 .maxlen = sizeof(int),
792 .proc_handler = &proc_dointvec_minmax,
793 .strategy = &sysctl_intvec,
798 .ctl_name = CTL_UNNUMBERED,
799 .procname = "softlockup_thresh",
800 .data = &softlockup_thresh,
801 .maxlen = sizeof(int),
803 .proc_handler = &proc_dosoftlockup_thresh,
804 .strategy = &sysctl_intvec,
809 #ifdef CONFIG_DETECT_HUNG_TASK
811 .ctl_name = CTL_UNNUMBERED,
812 .procname = "hung_task_panic",
813 .data = &sysctl_hung_task_panic,
814 .maxlen = sizeof(int),
816 .proc_handler = &proc_dointvec_minmax,
817 .strategy = &sysctl_intvec,
822 .ctl_name = CTL_UNNUMBERED,
823 .procname = "hung_task_check_count",
824 .data = &sysctl_hung_task_check_count,
825 .maxlen = sizeof(unsigned long),
827 .proc_handler = &proc_doulongvec_minmax,
828 .strategy = &sysctl_intvec,
831 .ctl_name = CTL_UNNUMBERED,
832 .procname = "hung_task_timeout_secs",
833 .data = &sysctl_hung_task_timeout_secs,
834 .maxlen = sizeof(unsigned long),
836 .proc_handler = &proc_dohung_task_timeout_secs,
837 .strategy = &sysctl_intvec,
840 .ctl_name = CTL_UNNUMBERED,
841 .procname = "hung_task_warnings",
842 .data = &sysctl_hung_task_warnings,
843 .maxlen = sizeof(unsigned long),
845 .proc_handler = &proc_doulongvec_minmax,
846 .strategy = &sysctl_intvec,
851 .ctl_name = KERN_COMPAT_LOG,
852 .procname = "compat-log",
854 .maxlen = sizeof (int),
856 .proc_handler = &proc_dointvec,
859 #ifdef CONFIG_RT_MUTEXES
861 .ctl_name = KERN_MAX_LOCK_DEPTH,
862 .procname = "max_lock_depth",
863 .data = &max_lock_depth,
864 .maxlen = sizeof(int),
866 .proc_handler = &proc_dointvec,
870 .ctl_name = CTL_UNNUMBERED,
871 .procname = "poweroff_cmd",
872 .data = &poweroff_cmd,
873 .maxlen = POWEROFF_CMD_PATH_LEN,
875 .proc_handler = &proc_dostring,
876 .strategy = &sysctl_string,
880 .ctl_name = CTL_UNNUMBERED,
883 .child = key_sysctls,
886 #ifdef CONFIG_RCU_TORTURE_TEST
888 .ctl_name = CTL_UNNUMBERED,
889 .procname = "rcutorture_runnable",
890 .data = &rcutorture_runnable,
891 .maxlen = sizeof(int),
893 .proc_handler = &proc_dointvec,
896 #ifdef CONFIG_UNEVICTABLE_LRU
898 .ctl_name = CTL_UNNUMBERED,
899 .procname = "scan_unevictable_pages",
900 .data = &scan_unevictable_pages,
901 .maxlen = sizeof(scan_unevictable_pages),
903 .proc_handler = &scan_unevictable_handler,
907 * NOTE: do not add new entries to this table unless you have read
908 * Documentation/sysctl/ctl_unnumbered.txt
913 static struct ctl_table vm_table[] = {
915 .ctl_name = VM_OVERCOMMIT_MEMORY,
916 .procname = "overcommit_memory",
917 .data = &sysctl_overcommit_memory,
918 .maxlen = sizeof(sysctl_overcommit_memory),
920 .proc_handler = &proc_dointvec,
923 .ctl_name = VM_PANIC_ON_OOM,
924 .procname = "panic_on_oom",
925 .data = &sysctl_panic_on_oom,
926 .maxlen = sizeof(sysctl_panic_on_oom),
928 .proc_handler = &proc_dointvec,
931 .ctl_name = CTL_UNNUMBERED,
932 .procname = "oom_kill_allocating_task",
933 .data = &sysctl_oom_kill_allocating_task,
934 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
936 .proc_handler = &proc_dointvec,
939 .ctl_name = CTL_UNNUMBERED,
940 .procname = "oom_dump_tasks",
941 .data = &sysctl_oom_dump_tasks,
942 .maxlen = sizeof(sysctl_oom_dump_tasks),
944 .proc_handler = &proc_dointvec,
947 .ctl_name = VM_OVERCOMMIT_RATIO,
948 .procname = "overcommit_ratio",
949 .data = &sysctl_overcommit_ratio,
950 .maxlen = sizeof(sysctl_overcommit_ratio),
952 .proc_handler = &proc_dointvec,
955 .ctl_name = VM_PAGE_CLUSTER,
956 .procname = "page-cluster",
957 .data = &page_cluster,
958 .maxlen = sizeof(int),
960 .proc_handler = &proc_dointvec,
963 .ctl_name = VM_DIRTY_BACKGROUND,
964 .procname = "dirty_background_ratio",
965 .data = &dirty_background_ratio,
966 .maxlen = sizeof(dirty_background_ratio),
968 .proc_handler = &dirty_background_ratio_handler,
969 .strategy = &sysctl_intvec,
971 .extra2 = &one_hundred,
974 .ctl_name = CTL_UNNUMBERED,
975 .procname = "dirty_background_bytes",
976 .data = &dirty_background_bytes,
977 .maxlen = sizeof(dirty_background_bytes),
979 .proc_handler = &dirty_background_bytes_handler,
980 .strategy = &sysctl_intvec,
984 .ctl_name = VM_DIRTY_RATIO,
985 .procname = "dirty_ratio",
986 .data = &vm_dirty_ratio,
987 .maxlen = sizeof(vm_dirty_ratio),
989 .proc_handler = &dirty_ratio_handler,
990 .strategy = &sysctl_intvec,
992 .extra2 = &one_hundred,
995 .ctl_name = CTL_UNNUMBERED,
996 .procname = "dirty_bytes",
997 .data = &vm_dirty_bytes,
998 .maxlen = sizeof(vm_dirty_bytes),
1000 .proc_handler = &dirty_bytes_handler,
1001 .strategy = &sysctl_intvec,
1005 .procname = "dirty_writeback_centisecs",
1006 .data = &dirty_writeback_interval,
1007 .maxlen = sizeof(dirty_writeback_interval),
1009 .proc_handler = &dirty_writeback_centisecs_handler,
1012 .procname = "dirty_expire_centisecs",
1013 .data = &dirty_expire_interval,
1014 .maxlen = sizeof(dirty_expire_interval),
1016 .proc_handler = &proc_dointvec_userhz_jiffies,
1019 .ctl_name = VM_NR_PDFLUSH_THREADS,
1020 .procname = "nr_pdflush_threads",
1021 .data = &nr_pdflush_threads,
1022 .maxlen = sizeof nr_pdflush_threads,
1023 .mode = 0444 /* read-only*/,
1024 .proc_handler = &proc_dointvec,
1027 .ctl_name = VM_SWAPPINESS,
1028 .procname = "swappiness",
1029 .data = &vm_swappiness,
1030 .maxlen = sizeof(vm_swappiness),
1032 .proc_handler = &proc_dointvec_minmax,
1033 .strategy = &sysctl_intvec,
1035 .extra2 = &one_hundred,
1037 #ifdef CONFIG_HUGETLB_PAGE
1039 .procname = "nr_hugepages",
1041 .maxlen = sizeof(unsigned long),
1043 .proc_handler = &hugetlb_sysctl_handler,
1044 .extra1 = (void *)&hugetlb_zero,
1045 .extra2 = (void *)&hugetlb_infinity,
1048 .ctl_name = VM_HUGETLB_GROUP,
1049 .procname = "hugetlb_shm_group",
1050 .data = &sysctl_hugetlb_shm_group,
1051 .maxlen = sizeof(gid_t),
1053 .proc_handler = &proc_dointvec,
1056 .ctl_name = CTL_UNNUMBERED,
1057 .procname = "hugepages_treat_as_movable",
1058 .data = &hugepages_treat_as_movable,
1059 .maxlen = sizeof(int),
1061 .proc_handler = &hugetlb_treat_movable_handler,
1064 .ctl_name = CTL_UNNUMBERED,
1065 .procname = "nr_overcommit_hugepages",
1067 .maxlen = sizeof(unsigned long),
1069 .proc_handler = &hugetlb_overcommit_handler,
1070 .extra1 = (void *)&hugetlb_zero,
1071 .extra2 = (void *)&hugetlb_infinity,
1075 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1076 .procname = "lowmem_reserve_ratio",
1077 .data = &sysctl_lowmem_reserve_ratio,
1078 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1080 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1081 .strategy = &sysctl_intvec,
1084 .ctl_name = VM_DROP_PAGECACHE,
1085 .procname = "drop_caches",
1086 .data = &sysctl_drop_caches,
1087 .maxlen = sizeof(int),
1089 .proc_handler = drop_caches_sysctl_handler,
1090 .strategy = &sysctl_intvec,
1093 .ctl_name = VM_MIN_FREE_KBYTES,
1094 .procname = "min_free_kbytes",
1095 .data = &min_free_kbytes,
1096 .maxlen = sizeof(min_free_kbytes),
1098 .proc_handler = &min_free_kbytes_sysctl_handler,
1099 .strategy = &sysctl_intvec,
1103 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1104 .procname = "percpu_pagelist_fraction",
1105 .data = &percpu_pagelist_fraction,
1106 .maxlen = sizeof(percpu_pagelist_fraction),
1108 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1109 .strategy = &sysctl_intvec,
1110 .extra1 = &min_percpu_pagelist_fract,
1114 .ctl_name = VM_MAX_MAP_COUNT,
1115 .procname = "max_map_count",
1116 .data = &sysctl_max_map_count,
1117 .maxlen = sizeof(sysctl_max_map_count),
1119 .proc_handler = &proc_dointvec
1123 .ctl_name = CTL_UNNUMBERED,
1124 .procname = "nr_trim_pages",
1125 .data = &sysctl_nr_trim_pages,
1126 .maxlen = sizeof(sysctl_nr_trim_pages),
1128 .proc_handler = &proc_dointvec_minmax,
1129 .strategy = &sysctl_intvec,
1134 .ctl_name = VM_LAPTOP_MODE,
1135 .procname = "laptop_mode",
1136 .data = &laptop_mode,
1137 .maxlen = sizeof(laptop_mode),
1139 .proc_handler = &proc_dointvec_jiffies,
1140 .strategy = &sysctl_jiffies,
1143 .ctl_name = VM_BLOCK_DUMP,
1144 .procname = "block_dump",
1145 .data = &block_dump,
1146 .maxlen = sizeof(block_dump),
1148 .proc_handler = &proc_dointvec,
1149 .strategy = &sysctl_intvec,
1153 .ctl_name = VM_VFS_CACHE_PRESSURE,
1154 .procname = "vfs_cache_pressure",
1155 .data = &sysctl_vfs_cache_pressure,
1156 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1158 .proc_handler = &proc_dointvec,
1159 .strategy = &sysctl_intvec,
1162 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1164 .ctl_name = VM_LEGACY_VA_LAYOUT,
1165 .procname = "legacy_va_layout",
1166 .data = &sysctl_legacy_va_layout,
1167 .maxlen = sizeof(sysctl_legacy_va_layout),
1169 .proc_handler = &proc_dointvec,
1170 .strategy = &sysctl_intvec,
1176 .ctl_name = VM_ZONE_RECLAIM_MODE,
1177 .procname = "zone_reclaim_mode",
1178 .data = &zone_reclaim_mode,
1179 .maxlen = sizeof(zone_reclaim_mode),
1181 .proc_handler = &proc_dointvec,
1182 .strategy = &sysctl_intvec,
1186 .ctl_name = VM_MIN_UNMAPPED,
1187 .procname = "min_unmapped_ratio",
1188 .data = &sysctl_min_unmapped_ratio,
1189 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1191 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1192 .strategy = &sysctl_intvec,
1194 .extra2 = &one_hundred,
1197 .ctl_name = VM_MIN_SLAB,
1198 .procname = "min_slab_ratio",
1199 .data = &sysctl_min_slab_ratio,
1200 .maxlen = sizeof(sysctl_min_slab_ratio),
1202 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1203 .strategy = &sysctl_intvec,
1205 .extra2 = &one_hundred,
1210 .ctl_name = CTL_UNNUMBERED,
1211 .procname = "stat_interval",
1212 .data = &sysctl_stat_interval,
1213 .maxlen = sizeof(sysctl_stat_interval),
1215 .proc_handler = &proc_dointvec_jiffies,
1216 .strategy = &sysctl_jiffies,
1219 #ifdef CONFIG_SECURITY
1221 .ctl_name = CTL_UNNUMBERED,
1222 .procname = "mmap_min_addr",
1223 .data = &mmap_min_addr,
1224 .maxlen = sizeof(unsigned long),
1226 .proc_handler = &proc_doulongvec_minmax,
1231 .ctl_name = CTL_UNNUMBERED,
1232 .procname = "numa_zonelist_order",
1233 .data = &numa_zonelist_order,
1234 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1236 .proc_handler = &numa_zonelist_order_handler,
1237 .strategy = &sysctl_string,
1240 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1241 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1243 .ctl_name = VM_VDSO_ENABLED,
1244 .procname = "vdso_enabled",
1245 .data = &vdso_enabled,
1246 .maxlen = sizeof(vdso_enabled),
1248 .proc_handler = &proc_dointvec,
1249 .strategy = &sysctl_intvec,
1253 #ifdef CONFIG_HIGHMEM
1255 .ctl_name = CTL_UNNUMBERED,
1256 .procname = "highmem_is_dirtyable",
1257 .data = &vm_highmem_is_dirtyable,
1258 .maxlen = sizeof(vm_highmem_is_dirtyable),
1260 .proc_handler = &proc_dointvec_minmax,
1261 .strategy = &sysctl_intvec,
1267 * NOTE: do not add new entries to this table unless you have read
1268 * Documentation/sysctl/ctl_unnumbered.txt
1273 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1274 static struct ctl_table binfmt_misc_table[] = {
1279 static struct ctl_table fs_table[] = {
1281 .ctl_name = FS_NRINODE,
1282 .procname = "inode-nr",
1283 .data = &inodes_stat,
1284 .maxlen = 2*sizeof(int),
1286 .proc_handler = &proc_dointvec,
1289 .ctl_name = FS_STATINODE,
1290 .procname = "inode-state",
1291 .data = &inodes_stat,
1292 .maxlen = 7*sizeof(int),
1294 .proc_handler = &proc_dointvec,
1297 .procname = "file-nr",
1298 .data = &files_stat,
1299 .maxlen = 3*sizeof(int),
1301 .proc_handler = &proc_nr_files,
1304 .ctl_name = FS_MAXFILE,
1305 .procname = "file-max",
1306 .data = &files_stat.max_files,
1307 .maxlen = sizeof(int),
1309 .proc_handler = &proc_dointvec,
1312 .ctl_name = CTL_UNNUMBERED,
1313 .procname = "nr_open",
1314 .data = &sysctl_nr_open,
1315 .maxlen = sizeof(int),
1317 .proc_handler = &proc_dointvec_minmax,
1318 .extra1 = &sysctl_nr_open_min,
1319 .extra2 = &sysctl_nr_open_max,
1322 .ctl_name = FS_DENTRY,
1323 .procname = "dentry-state",
1324 .data = &dentry_stat,
1325 .maxlen = 6*sizeof(int),
1327 .proc_handler = &proc_dointvec,
1330 .ctl_name = FS_OVERFLOWUID,
1331 .procname = "overflowuid",
1332 .data = &fs_overflowuid,
1333 .maxlen = sizeof(int),
1335 .proc_handler = &proc_dointvec_minmax,
1336 .strategy = &sysctl_intvec,
1337 .extra1 = &minolduid,
1338 .extra2 = &maxolduid,
1341 .ctl_name = FS_OVERFLOWGID,
1342 .procname = "overflowgid",
1343 .data = &fs_overflowgid,
1344 .maxlen = sizeof(int),
1346 .proc_handler = &proc_dointvec_minmax,
1347 .strategy = &sysctl_intvec,
1348 .extra1 = &minolduid,
1349 .extra2 = &maxolduid,
1351 #ifdef CONFIG_FILE_LOCKING
1353 .ctl_name = FS_LEASES,
1354 .procname = "leases-enable",
1355 .data = &leases_enable,
1356 .maxlen = sizeof(int),
1358 .proc_handler = &proc_dointvec,
1361 #ifdef CONFIG_DNOTIFY
1363 .ctl_name = FS_DIR_NOTIFY,
1364 .procname = "dir-notify-enable",
1365 .data = &dir_notify_enable,
1366 .maxlen = sizeof(int),
1368 .proc_handler = &proc_dointvec,
1372 #ifdef CONFIG_FILE_LOCKING
1374 .ctl_name = FS_LEASE_TIME,
1375 .procname = "lease-break-time",
1376 .data = &lease_break_time,
1377 .maxlen = sizeof(int),
1379 .proc_handler = &proc_dointvec_minmax,
1380 .strategy = &sysctl_intvec,
1387 .procname = "aio-nr",
1389 .maxlen = sizeof(aio_nr),
1391 .proc_handler = &proc_doulongvec_minmax,
1394 .procname = "aio-max-nr",
1395 .data = &aio_max_nr,
1396 .maxlen = sizeof(aio_max_nr),
1398 .proc_handler = &proc_doulongvec_minmax,
1400 #endif /* CONFIG_AIO */
1401 #ifdef CONFIG_INOTIFY_USER
1403 .ctl_name = FS_INOTIFY,
1404 .procname = "inotify",
1406 .child = inotify_table,
1411 .procname = "epoll",
1413 .child = epoll_table,
1418 .ctl_name = KERN_SETUID_DUMPABLE,
1419 .procname = "suid_dumpable",
1420 .data = &suid_dumpable,
1421 .maxlen = sizeof(int),
1423 .proc_handler = &proc_dointvec,
1425 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1427 .ctl_name = CTL_UNNUMBERED,
1428 .procname = "binfmt_misc",
1430 .child = binfmt_misc_table,
1434 * NOTE: do not add new entries to this table unless you have read
1435 * Documentation/sysctl/ctl_unnumbered.txt
1440 static struct ctl_table debug_table[] = {
1441 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1443 .ctl_name = CTL_UNNUMBERED,
1444 .procname = "exception-trace",
1445 .data = &show_unhandled_signals,
1446 .maxlen = sizeof(int),
1448 .proc_handler = proc_dointvec
1454 static struct ctl_table dev_table[] = {
1458 static DEFINE_SPINLOCK(sysctl_lock);
1460 /* called under sysctl_lock */
1461 static int use_table(struct ctl_table_header *p)
1463 if (unlikely(p->unregistering))
1469 /* called under sysctl_lock */
1470 static void unuse_table(struct ctl_table_header *p)
1473 if (unlikely(p->unregistering))
1474 complete(p->unregistering);
1477 /* called under sysctl_lock, will reacquire if has to wait */
1478 static void start_unregistering(struct ctl_table_header *p)
1481 * if p->used is 0, nobody will ever touch that entry again;
1482 * we'll eliminate all paths to it before dropping sysctl_lock
1484 if (unlikely(p->used)) {
1485 struct completion wait;
1486 init_completion(&wait);
1487 p->unregistering = &wait;
1488 spin_unlock(&sysctl_lock);
1489 wait_for_completion(&wait);
1490 spin_lock(&sysctl_lock);
1492 /* anything non-NULL; we'll never dereference it */
1493 p->unregistering = ERR_PTR(-EINVAL);
1496 * do not remove from the list until nobody holds it; walking the
1497 * list in do_sysctl() relies on that.
1499 list_del_init(&p->ctl_entry);
1502 void sysctl_head_get(struct ctl_table_header *head)
1504 spin_lock(&sysctl_lock);
1506 spin_unlock(&sysctl_lock);
1509 void sysctl_head_put(struct ctl_table_header *head)
1511 spin_lock(&sysctl_lock);
1514 spin_unlock(&sysctl_lock);
1517 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1521 spin_lock(&sysctl_lock);
1522 if (!use_table(head))
1523 head = ERR_PTR(-ENOENT);
1524 spin_unlock(&sysctl_lock);
1528 void sysctl_head_finish(struct ctl_table_header *head)
1532 spin_lock(&sysctl_lock);
1534 spin_unlock(&sysctl_lock);
1537 static struct ctl_table_set *
1538 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1540 struct ctl_table_set *set = &root->default_set;
1542 set = root->lookup(root, namespaces);
1546 static struct list_head *
1547 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1549 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1553 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1554 struct ctl_table_header *prev)
1556 struct ctl_table_root *root;
1557 struct list_head *header_list;
1558 struct ctl_table_header *head;
1559 struct list_head *tmp;
1561 spin_lock(&sysctl_lock);
1564 tmp = &prev->ctl_entry;
1568 tmp = &root_table_header.ctl_entry;
1570 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1572 if (!use_table(head))
1574 spin_unlock(&sysctl_lock);
1579 header_list = lookup_header_list(root, namespaces);
1580 if (tmp != header_list)
1584 root = list_entry(root->root_list.next,
1585 struct ctl_table_root, root_list);
1586 if (root == &sysctl_table_root)
1588 header_list = lookup_header_list(root, namespaces);
1589 } while (list_empty(header_list));
1590 tmp = header_list->next;
1593 spin_unlock(&sysctl_lock);
1597 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1599 return __sysctl_head_next(current->nsproxy, prev);
1602 void register_sysctl_root(struct ctl_table_root *root)
1604 spin_lock(&sysctl_lock);
1605 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1606 spin_unlock(&sysctl_lock);
1609 #ifdef CONFIG_SYSCTL_SYSCALL
1610 /* Perform the actual read/write of a sysctl table entry. */
1611 static int do_sysctl_strategy(struct ctl_table_root *root,
1612 struct ctl_table *table,
1613 void __user *oldval, size_t __user *oldlenp,
1614 void __user *newval, size_t newlen)
1622 if (sysctl_perm(root, table, op))
1625 if (table->strategy) {
1626 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1633 /* If there is no strategy routine, or if the strategy returns
1634 * zero, proceed with automatic r/w */
1635 if (table->data && table->maxlen) {
1636 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1643 static int parse_table(int __user *name, int nlen,
1644 void __user *oldval, size_t __user *oldlenp,
1645 void __user *newval, size_t newlen,
1646 struct ctl_table_root *root,
1647 struct ctl_table *table)
1653 if (get_user(n, name))
1655 for ( ; table->ctl_name || table->procname; table++) {
1656 if (!table->ctl_name)
1658 if (n == table->ctl_name) {
1661 if (sysctl_perm(root, table, MAY_EXEC))
1665 table = table->child;
1668 error = do_sysctl_strategy(root, table,
1677 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1678 void __user *newval, size_t newlen)
1680 struct ctl_table_header *head;
1681 int error = -ENOTDIR;
1683 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1687 if (!oldlenp || get_user(old_len, oldlenp))
1691 for (head = sysctl_head_next(NULL); head;
1692 head = sysctl_head_next(head)) {
1693 error = parse_table(name, nlen, oldval, oldlenp,
1695 head->root, head->ctl_table);
1696 if (error != -ENOTDIR) {
1697 sysctl_head_finish(head);
1704 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1706 struct __sysctl_args tmp;
1709 if (copy_from_user(&tmp, args, sizeof(tmp)))
1712 error = deprecated_sysctl_warning(&tmp);
1717 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1718 tmp.newval, tmp.newlen);
1723 #endif /* CONFIG_SYSCTL_SYSCALL */
1726 * sysctl_perm does NOT grant the superuser all rights automatically, because
1727 * some sysctl variables are readonly even to root.
1730 static int test_perm(int mode, int op)
1732 if (!current_euid())
1734 else if (in_egroup_p(0))
1736 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1741 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1746 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1750 if (root->permissions)
1751 mode = root->permissions(root, current->nsproxy, table);
1755 return test_perm(mode, op);
1758 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1760 for (; table->ctl_name || table->procname; table++) {
1761 table->parent = parent;
1763 sysctl_set_parent(table, table->child);
1767 static __init int sysctl_init(void)
1769 sysctl_set_parent(NULL, root_table);
1770 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1773 err = sysctl_check_table(current->nsproxy, root_table);
1779 core_initcall(sysctl_init);
1781 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1782 struct ctl_table *table)
1784 struct ctl_table *p;
1785 const char *s = branch->procname;
1787 /* branch should have named subdirectory as its first element */
1788 if (!s || !branch->child)
1791 /* ... and nothing else */
1792 if (branch[1].procname || branch[1].ctl_name)
1795 /* table should contain subdirectory with the same name */
1796 for (p = table; p->procname || p->ctl_name; p++) {
1799 if (p->procname && strcmp(p->procname, s) == 0)
1805 /* see if attaching q to p would be an improvement */
1806 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1808 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1809 struct ctl_table *next;
1811 int not_in_parent = !p->attached_by;
1813 while ((next = is_branch_in(by, to)) != NULL) {
1814 if (by == q->attached_by)
1816 if (to == p->attached_by)
1822 if (is_better && not_in_parent) {
1823 q->attached_by = by;
1824 q->attached_to = to;
1830 * __register_sysctl_paths - register a sysctl hierarchy
1831 * @root: List of sysctl headers to register on
1832 * @namespaces: Data to compute which lists of sysctl entries are visible
1833 * @path: The path to the directory the sysctl table is in.
1834 * @table: the top-level table structure
1836 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1837 * array. A completely 0 filled entry terminates the table.
1839 * The members of the &struct ctl_table structure are used as follows:
1841 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1842 * must be unique within that level of sysctl
1844 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1845 * enter a sysctl file
1847 * data - a pointer to data for use by proc_handler
1849 * maxlen - the maximum size in bytes of the data
1851 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1853 * child - a pointer to the child sysctl table if this entry is a directory, or
1856 * proc_handler - the text handler routine (described below)
1858 * strategy - the strategy routine (described below)
1860 * de - for internal use by the sysctl routines
1862 * extra1, extra2 - extra pointers usable by the proc handler routines
1864 * Leaf nodes in the sysctl tree will be represented by a single file
1865 * under /proc; non-leaf nodes will be represented by directories.
1867 * sysctl(2) can automatically manage read and write requests through
1868 * the sysctl table. The data and maxlen fields of the ctl_table
1869 * struct enable minimal validation of the values being written to be
1870 * performed, and the mode field allows minimal authentication.
1872 * More sophisticated management can be enabled by the provision of a
1873 * strategy routine with the table entry. This will be called before
1874 * any automatic read or write of the data is performed.
1876 * The strategy routine may return
1878 * < 0 - Error occurred (error is passed to user process)
1880 * 0 - OK - proceed with automatic read or write.
1882 * > 0 - OK - read or write has been done by the strategy routine, so
1883 * return immediately.
1885 * There must be a proc_handler routine for any terminal nodes
1886 * mirrored under /proc/sys (non-terminals are handled by a built-in
1887 * directory handler). Several default handlers are available to
1888 * cover common cases -
1890 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1891 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1892 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1894 * It is the handler's job to read the input buffer from user memory
1895 * and process it. The handler should return 0 on success.
1897 * This routine returns %NULL on a failure to register, and a pointer
1898 * to the table header on success.
1900 struct ctl_table_header *__register_sysctl_paths(
1901 struct ctl_table_root *root,
1902 struct nsproxy *namespaces,
1903 const struct ctl_path *path, struct ctl_table *table)
1905 struct ctl_table_header *header;
1906 struct ctl_table *new, **prevp;
1907 unsigned int n, npath;
1908 struct ctl_table_set *set;
1910 /* Count the path components */
1911 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1915 * For each path component, allocate a 2-element ctl_table array.
1916 * The first array element will be filled with the sysctl entry
1917 * for this, the second will be the sentinel (ctl_name == 0).
1919 * We allocate everything in one go so that we don't have to
1920 * worry about freeing additional memory in unregister_sysctl_table.
1922 header = kzalloc(sizeof(struct ctl_table_header) +
1923 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1927 new = (struct ctl_table *) (header + 1);
1929 /* Now connect the dots */
1930 prevp = &header->ctl_table;
1931 for (n = 0; n < npath; ++n, ++path) {
1932 /* Copy the procname */
1933 new->procname = path->procname;
1934 new->ctl_name = path->ctl_name;
1938 prevp = &new->child;
1943 header->ctl_table_arg = table;
1945 INIT_LIST_HEAD(&header->ctl_entry);
1947 header->unregistering = NULL;
1948 header->root = root;
1949 sysctl_set_parent(NULL, header->ctl_table);
1951 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1952 if (sysctl_check_table(namespaces, header->ctl_table)) {
1957 spin_lock(&sysctl_lock);
1958 header->set = lookup_header_set(root, namespaces);
1959 header->attached_by = header->ctl_table;
1960 header->attached_to = root_table;
1961 header->parent = &root_table_header;
1962 for (set = header->set; set; set = set->parent) {
1963 struct ctl_table_header *p;
1964 list_for_each_entry(p, &set->list, ctl_entry) {
1965 if (p->unregistering)
1967 try_attach(p, header);
1970 header->parent->count++;
1971 list_add_tail(&header->ctl_entry, &header->set->list);
1972 spin_unlock(&sysctl_lock);
1978 * register_sysctl_table_path - register a sysctl table hierarchy
1979 * @path: The path to the directory the sysctl table is in.
1980 * @table: the top-level table structure
1982 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1983 * array. A completely 0 filled entry terminates the table.
1985 * See __register_sysctl_paths for more details.
1987 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1988 struct ctl_table *table)
1990 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1995 * register_sysctl_table - register a sysctl table hierarchy
1996 * @table: the top-level table structure
1998 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1999 * array. A completely 0 filled entry terminates the table.
2001 * See register_sysctl_paths for more details.
2003 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2005 static const struct ctl_path null_path[] = { {} };
2007 return register_sysctl_paths(null_path, table);
2011 * unregister_sysctl_table - unregister a sysctl table hierarchy
2012 * @header: the header returned from register_sysctl_table
2014 * Unregisters the sysctl table and all children. proc entries may not
2015 * actually be removed until they are no longer used by anyone.
2017 void unregister_sysctl_table(struct ctl_table_header * header)
2024 spin_lock(&sysctl_lock);
2025 start_unregistering(header);
2026 if (!--header->parent->count) {
2028 kfree(header->parent);
2030 if (!--header->count)
2032 spin_unlock(&sysctl_lock);
2035 int sysctl_is_seen(struct ctl_table_header *p)
2037 struct ctl_table_set *set = p->set;
2039 spin_lock(&sysctl_lock);
2040 if (p->unregistering)
2042 else if (!set->is_seen)
2045 res = set->is_seen(set);
2046 spin_unlock(&sysctl_lock);
2050 void setup_sysctl_set(struct ctl_table_set *p,
2051 struct ctl_table_set *parent,
2052 int (*is_seen)(struct ctl_table_set *))
2054 INIT_LIST_HEAD(&p->list);
2055 p->parent = parent ? parent : &sysctl_table_root.default_set;
2056 p->is_seen = is_seen;
2059 #else /* !CONFIG_SYSCTL */
2060 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2065 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2066 struct ctl_table *table)
2071 void unregister_sysctl_table(struct ctl_table_header * table)
2075 void setup_sysctl_set(struct ctl_table_set *p,
2076 struct ctl_table_set *parent,
2077 int (*is_seen)(struct ctl_table_set *))
2081 void sysctl_head_put(struct ctl_table_header *head)
2085 #endif /* CONFIG_SYSCTL */
2091 #ifdef CONFIG_PROC_SYSCTL
2093 static int _proc_do_string(void* data, int maxlen, int write,
2094 struct file *filp, void __user *buffer,
2095 size_t *lenp, loff_t *ppos)
2101 if (!data || !maxlen || !*lenp) {
2109 while (len < *lenp) {
2110 if (get_user(c, p++))
2112 if (c == 0 || c == '\n')
2118 if(copy_from_user(data, buffer, len))
2120 ((char *) data)[len] = 0;
2138 if(copy_to_user(buffer, data, len))
2141 if(put_user('\n', ((char __user *) buffer) + len))
2152 * proc_dostring - read a string sysctl
2153 * @table: the sysctl table
2154 * @write: %TRUE if this is a write to the sysctl file
2155 * @filp: the file structure
2156 * @buffer: the user buffer
2157 * @lenp: the size of the user buffer
2158 * @ppos: file position
2160 * Reads/writes a string from/to the user buffer. If the kernel
2161 * buffer provided is not large enough to hold the string, the
2162 * string is truncated. The copied string is %NULL-terminated.
2163 * If the string is being read by the user process, it is copied
2164 * and a newline '\n' is added. It is truncated if the buffer is
2167 * Returns 0 on success.
2169 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2170 void __user *buffer, size_t *lenp, loff_t *ppos)
2172 return _proc_do_string(table->data, table->maxlen, write, filp,
2173 buffer, lenp, ppos);
2177 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2179 int write, void *data)
2182 *valp = *negp ? -*lvalp : *lvalp;
2187 *lvalp = (unsigned long)-val;
2190 *lvalp = (unsigned long)val;
2196 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2197 int write, struct file *filp, void __user *buffer,
2198 size_t *lenp, loff_t *ppos,
2199 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2200 int write, void *data),
2203 #define TMPBUFLEN 21
2204 int *i, vleft, first=1, neg, val;
2208 char buf[TMPBUFLEN], *p;
2209 char __user *s = buffer;
2211 if (!tbl_data || !table->maxlen || !*lenp ||
2212 (*ppos && !write)) {
2217 i = (int *) tbl_data;
2218 vleft = table->maxlen / sizeof(*i);
2222 conv = do_proc_dointvec_conv;
2224 for (; left && vleft--; i++, first=0) {
2239 if (len > sizeof(buf) - 1)
2240 len = sizeof(buf) - 1;
2241 if (copy_from_user(buf, s, len))
2245 if (*p == '-' && left > 1) {
2249 if (*p < '0' || *p > '9')
2252 lval = simple_strtoul(p, &p, 0);
2255 if ((len < left) && *p && !isspace(*p))
2262 if (conv(&neg, &lval, i, 1, data))
2269 if (conv(&neg, &lval, i, 0, data))
2272 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2276 if(copy_to_user(s, buf, len))
2283 if (!write && !first && left) {
2284 if(put_user('\n', s))
2291 if (get_user(c, s++))
2306 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2307 void __user *buffer, size_t *lenp, loff_t *ppos,
2308 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2309 int write, void *data),
2312 return __do_proc_dointvec(table->data, table, write, filp,
2313 buffer, lenp, ppos, conv, data);
2317 * proc_dointvec - read a vector of integers
2318 * @table: the sysctl table
2319 * @write: %TRUE if this is a write to the sysctl file
2320 * @filp: the file structure
2321 * @buffer: the user buffer
2322 * @lenp: the size of the user buffer
2323 * @ppos: file position
2325 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2326 * values from/to the user buffer, treated as an ASCII string.
2328 * Returns 0 on success.
2330 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2331 void __user *buffer, size_t *lenp, loff_t *ppos)
2333 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2338 * Taint values can only be increased
2339 * This means we can safely use a temporary.
2341 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2342 void __user *buffer, size_t *lenp, loff_t *ppos)
2345 unsigned long tmptaint = get_taint();
2348 if (write && !capable(CAP_SYS_ADMIN))
2353 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2359 * Poor man's atomic or. Not worth adding a primitive
2360 * to everyone's atomic.h for this
2363 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2364 if ((tmptaint >> i) & 1)
2372 struct do_proc_dointvec_minmax_conv_param {
2377 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2379 int write, void *data)
2381 struct do_proc_dointvec_minmax_conv_param *param = data;
2383 int val = *negp ? -*lvalp : *lvalp;
2384 if ((param->min && *param->min > val) ||
2385 (param->max && *param->max < val))
2392 *lvalp = (unsigned long)-val;
2395 *lvalp = (unsigned long)val;
2402 * proc_dointvec_minmax - read a vector of integers with min/max values
2403 * @table: the sysctl table
2404 * @write: %TRUE if this is a write to the sysctl file
2405 * @filp: the file structure
2406 * @buffer: the user buffer
2407 * @lenp: the size of the user buffer
2408 * @ppos: file position
2410 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2411 * values from/to the user buffer, treated as an ASCII string.
2413 * This routine will ensure the values are within the range specified by
2414 * table->extra1 (min) and table->extra2 (max).
2416 * Returns 0 on success.
2418 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2419 void __user *buffer, size_t *lenp, loff_t *ppos)
2421 struct do_proc_dointvec_minmax_conv_param param = {
2422 .min = (int *) table->extra1,
2423 .max = (int *) table->extra2,
2425 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2426 do_proc_dointvec_minmax_conv, ¶m);
2429 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2431 void __user *buffer,
2432 size_t *lenp, loff_t *ppos,
2433 unsigned long convmul,
2434 unsigned long convdiv)
2436 #define TMPBUFLEN 21
2437 unsigned long *i, *min, *max, val;
2438 int vleft, first=1, neg;
2440 char buf[TMPBUFLEN], *p;
2441 char __user *s = buffer;
2443 if (!data || !table->maxlen || !*lenp ||
2444 (*ppos && !write)) {
2449 i = (unsigned long *) data;
2450 min = (unsigned long *) table->extra1;
2451 max = (unsigned long *) table->extra2;
2452 vleft = table->maxlen / sizeof(unsigned long);
2455 for (; left && vleft--; i++, min++, max++, first=0) {
2470 if (len > TMPBUFLEN-1)
2472 if (copy_from_user(buf, s, len))
2476 if (*p == '-' && left > 1) {
2480 if (*p < '0' || *p > '9')
2482 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2484 if ((len < left) && *p && !isspace(*p))
2493 if ((min && val < *min) || (max && val > *max))
2500 sprintf(p, "%lu", convdiv * (*i) / convmul);
2504 if(copy_to_user(s, buf, len))
2511 if (!write && !first && left) {
2512 if(put_user('\n', s))
2519 if (get_user(c, s++))
2534 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2536 void __user *buffer,
2537 size_t *lenp, loff_t *ppos,
2538 unsigned long convmul,
2539 unsigned long convdiv)
2541 return __do_proc_doulongvec_minmax(table->data, table, write,
2542 filp, buffer, lenp, ppos, convmul, convdiv);
2546 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2547 * @table: the sysctl table
2548 * @write: %TRUE if this is a write to the sysctl file
2549 * @filp: the file structure
2550 * @buffer: the user buffer
2551 * @lenp: the size of the user buffer
2552 * @ppos: file position
2554 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2555 * values from/to the user buffer, treated as an ASCII string.
2557 * This routine will ensure the values are within the range specified by
2558 * table->extra1 (min) and table->extra2 (max).
2560 * Returns 0 on success.
2562 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2563 void __user *buffer, size_t *lenp, loff_t *ppos)
2565 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2569 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2570 * @table: the sysctl table
2571 * @write: %TRUE if this is a write to the sysctl file
2572 * @filp: the file structure
2573 * @buffer: the user buffer
2574 * @lenp: the size of the user buffer
2575 * @ppos: file position
2577 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2578 * values from/to the user buffer, treated as an ASCII string. The values
2579 * are treated as milliseconds, and converted to jiffies when they are stored.
2581 * This routine will ensure the values are within the range specified by
2582 * table->extra1 (min) and table->extra2 (max).
2584 * Returns 0 on success.
2586 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2588 void __user *buffer,
2589 size_t *lenp, loff_t *ppos)
2591 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2592 lenp, ppos, HZ, 1000l);
2596 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2598 int write, void *data)
2601 if (*lvalp > LONG_MAX / HZ)
2603 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2609 lval = (unsigned long)-val;
2612 lval = (unsigned long)val;
2619 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2621 int write, void *data)
2624 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2626 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2632 lval = (unsigned long)-val;
2635 lval = (unsigned long)val;
2637 *lvalp = jiffies_to_clock_t(lval);
2642 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2644 int write, void *data)
2647 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2653 lval = (unsigned long)-val;
2656 lval = (unsigned long)val;
2658 *lvalp = jiffies_to_msecs(lval);
2664 * proc_dointvec_jiffies - read a vector of integers as seconds
2665 * @table: the sysctl table
2666 * @write: %TRUE if this is a write to the sysctl file
2667 * @filp: the file structure
2668 * @buffer: the user buffer
2669 * @lenp: the size of the user buffer
2670 * @ppos: file position
2672 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2673 * values from/to the user buffer, treated as an ASCII string.
2674 * The values read are assumed to be in seconds, and are converted into
2677 * Returns 0 on success.
2679 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2680 void __user *buffer, size_t *lenp, loff_t *ppos)
2682 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2683 do_proc_dointvec_jiffies_conv,NULL);
2687 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2688 * @table: the sysctl table
2689 * @write: %TRUE if this is a write to the sysctl file
2690 * @filp: the file structure
2691 * @buffer: the user buffer
2692 * @lenp: the size of the user buffer
2693 * @ppos: pointer to the file position
2695 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2696 * values from/to the user buffer, treated as an ASCII string.
2697 * The values read are assumed to be in 1/USER_HZ seconds, and
2698 * are converted into jiffies.
2700 * Returns 0 on success.
2702 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2703 void __user *buffer, size_t *lenp, loff_t *ppos)
2705 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2706 do_proc_dointvec_userhz_jiffies_conv,NULL);
2710 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2711 * @table: the sysctl table
2712 * @write: %TRUE if this is a write to the sysctl file
2713 * @filp: the file structure
2714 * @buffer: the user buffer
2715 * @lenp: the size of the user buffer
2716 * @ppos: file position
2717 * @ppos: the current position in the file
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 1/1000 seconds, and
2722 * are converted into jiffies.
2724 * Returns 0 on success.
2726 int proc_dointvec_ms_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_ms_jiffies_conv, NULL);
2733 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2734 void __user *buffer, size_t *lenp, loff_t *ppos)
2736 struct pid *new_pid;
2740 tmp = pid_vnr(cad_pid);
2742 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2743 lenp, ppos, NULL, NULL);
2747 new_pid = find_get_pid(tmp);
2751 put_pid(xchg(&cad_pid, new_pid));
2755 #else /* CONFIG_PROC_FS */
2757 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2758 void __user *buffer, size_t *lenp, loff_t *ppos)
2763 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2764 void __user *buffer, size_t *lenp, loff_t *ppos)
2769 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2770 void __user *buffer, size_t *lenp, loff_t *ppos)
2775 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2776 void __user *buffer, size_t *lenp, loff_t *ppos)
2781 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2782 void __user *buffer, size_t *lenp, loff_t *ppos)
2787 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2788 void __user *buffer, size_t *lenp, loff_t *ppos)
2793 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2794 void __user *buffer, size_t *lenp, loff_t *ppos)
2799 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2801 void __user *buffer,
2802 size_t *lenp, loff_t *ppos)
2808 #endif /* CONFIG_PROC_FS */
2811 #ifdef CONFIG_SYSCTL_SYSCALL
2813 * General sysctl support routines
2816 /* The generic sysctl data routine (used if no strategy routine supplied) */
2817 int sysctl_data(struct ctl_table *table,
2818 void __user *oldval, size_t __user *oldlenp,
2819 void __user *newval, size_t newlen)
2823 /* Get out of I don't have a variable */
2824 if (!table->data || !table->maxlen)
2827 if (oldval && oldlenp) {
2828 if (get_user(len, oldlenp))
2831 if (len > table->maxlen)
2832 len = table->maxlen;
2833 if (copy_to_user(oldval, table->data, len))
2835 if (put_user(len, oldlenp))
2840 if (newval && newlen) {
2841 if (newlen > table->maxlen)
2842 newlen = table->maxlen;
2844 if (copy_from_user(table->data, newval, newlen))
2850 /* The generic string strategy routine: */
2851 int sysctl_string(struct ctl_table *table,
2852 void __user *oldval, size_t __user *oldlenp,
2853 void __user *newval, size_t newlen)
2855 if (!table->data || !table->maxlen)
2858 if (oldval && oldlenp) {
2860 if (get_user(bufsize, oldlenp))
2863 size_t len = strlen(table->data), copied;
2865 /* This shouldn't trigger for a well-formed sysctl */
2866 if (len > table->maxlen)
2867 len = table->maxlen;
2869 /* Copy up to a max of bufsize-1 bytes of the string */
2870 copied = (len >= bufsize) ? bufsize - 1 : len;
2872 if (copy_to_user(oldval, table->data, copied) ||
2873 put_user(0, (char __user *)(oldval + copied)))
2875 if (put_user(len, oldlenp))
2879 if (newval && newlen) {
2880 size_t len = newlen;
2881 if (len > table->maxlen)
2882 len = table->maxlen;
2883 if(copy_from_user(table->data, newval, len))
2885 if (len == table->maxlen)
2887 ((char *) table->data)[len] = 0;
2893 * This function makes sure that all of the integers in the vector
2894 * are between the minimum and maximum values given in the arrays
2895 * table->extra1 and table->extra2, respectively.
2897 int sysctl_intvec(struct ctl_table *table,
2898 void __user *oldval, size_t __user *oldlenp,
2899 void __user *newval, size_t newlen)
2902 if (newval && newlen) {
2903 int __user *vec = (int __user *) newval;
2904 int *min = (int *) table->extra1;
2905 int *max = (int *) table->extra2;
2909 if (newlen % sizeof(int) != 0)
2912 if (!table->extra1 && !table->extra2)
2915 if (newlen > table->maxlen)
2916 newlen = table->maxlen;
2917 length = newlen / sizeof(int);
2919 for (i = 0; i < length; i++) {
2921 if (get_user(value, vec + i))
2923 if (min && value < min[i])
2925 if (max && value > max[i])
2932 /* Strategy function to convert jiffies to seconds */
2933 int sysctl_jiffies(struct ctl_table *table,
2934 void __user *oldval, size_t __user *oldlenp,
2935 void __user *newval, size_t newlen)
2937 if (oldval && oldlenp) {
2940 if (get_user(olen, oldlenp))
2945 if (olen < sizeof(int))
2948 val = *(int *)(table->data) / HZ;
2949 if (put_user(val, (int __user *)oldval))
2951 if (put_user(sizeof(int), oldlenp))
2955 if (newval && newlen) {
2957 if (newlen != sizeof(int))
2959 if (get_user(new, (int __user *)newval))
2961 *(int *)(table->data) = new*HZ;
2966 /* Strategy function to convert jiffies to seconds */
2967 int sysctl_ms_jiffies(struct ctl_table *table,
2968 void __user *oldval, size_t __user *oldlenp,
2969 void __user *newval, size_t newlen)
2971 if (oldval && oldlenp) {
2974 if (get_user(olen, oldlenp))
2979 if (olen < sizeof(int))
2982 val = jiffies_to_msecs(*(int *)(table->data));
2983 if (put_user(val, (int __user *)oldval))
2985 if (put_user(sizeof(int), oldlenp))
2989 if (newval && newlen) {
2991 if (newlen != sizeof(int))
2993 if (get_user(new, (int __user *)newval))
2995 *(int *)(table->data) = msecs_to_jiffies(new);
3002 #else /* CONFIG_SYSCTL_SYSCALL */
3005 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
3007 struct __sysctl_args tmp;
3010 if (copy_from_user(&tmp, args, sizeof(tmp)))
3013 error = deprecated_sysctl_warning(&tmp);
3015 /* If no error reading the parameters then just -ENOSYS ... */
3022 int sysctl_data(struct ctl_table *table,
3023 void __user *oldval, size_t __user *oldlenp,
3024 void __user *newval, size_t newlen)
3029 int sysctl_string(struct ctl_table *table,
3030 void __user *oldval, size_t __user *oldlenp,
3031 void __user *newval, size_t newlen)
3036 int sysctl_intvec(struct ctl_table *table,
3037 void __user *oldval, size_t __user *oldlenp,
3038 void __user *newval, size_t newlen)
3043 int sysctl_jiffies(struct ctl_table *table,
3044 void __user *oldval, size_t __user *oldlenp,
3045 void __user *newval, size_t newlen)
3050 int sysctl_ms_jiffies(struct ctl_table *table,
3051 void __user *oldval, size_t __user *oldlenp,
3052 void __user *newval, size_t newlen)
3057 #endif /* CONFIG_SYSCTL_SYSCALL */
3059 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3061 static int msg_count;
3062 int name[CTL_MAXNAME];
3065 /* Check args->nlen. */
3066 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3069 /* Read in the sysctl name for better debug message logging */
3070 for (i = 0; i < args->nlen; i++)
3071 if (get_user(name[i], args->name + i))
3074 /* Ignore accesses to kernel.version */
3075 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3078 if (msg_count < 5) {
3081 "warning: process `%s' used the deprecated sysctl "
3082 "system call with ", current->comm);
3083 for (i = 0; i < args->nlen; i++)
3084 printk("%d.", name[i]);
3091 * No sense putting this after each symbol definition, twice,
3092 * exception granted :-)
3094 EXPORT_SYMBOL(proc_dointvec);
3095 EXPORT_SYMBOL(proc_dointvec_jiffies);
3096 EXPORT_SYMBOL(proc_dointvec_minmax);
3097 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3098 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3099 EXPORT_SYMBOL(proc_dostring);
3100 EXPORT_SYMBOL(proc_doulongvec_minmax);
3101 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3102 EXPORT_SYMBOL(register_sysctl_table);
3103 EXPORT_SYMBOL(register_sysctl_paths);
3104 EXPORT_SYMBOL(sysctl_intvec);
3105 EXPORT_SYMBOL(sysctl_jiffies);
3106 EXPORT_SYMBOL(sysctl_ms_jiffies);
3107 EXPORT_SYMBOL(sysctl_string);
3108 EXPORT_SYMBOL(sysctl_data);
3109 EXPORT_SYMBOL(unregister_sysctl_table);