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;
101 static unsigned long one_ul = 1;
102 static int one_hundred = 100;
104 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
105 static int maxolduid = 65535;
106 static int minolduid;
107 static int min_percpu_pagelist_fract = 8;
109 static int ngroups_max = NGROUPS_MAX;
111 #ifdef CONFIG_MODULES
112 extern char modprobe_path[];
114 #ifdef CONFIG_CHR_DEV_SG
115 extern int sg_big_buff;
119 #include <asm/system.h>
122 #ifdef CONFIG_SPARC64
123 extern int sysctl_tsb_ratio;
127 extern int pwrsw_enabled;
128 extern int unaligned_enabled;
132 #ifdef CONFIG_MATHEMU
133 extern int sysctl_ieee_emulation_warnings;
135 extern int sysctl_userprocess_debug;
136 extern int spin_retry;
139 #ifdef CONFIG_BSD_PROCESS_ACCT
140 extern int acct_parm[];
144 extern int no_unaligned_warning;
145 extern int unaligned_dump_stack;
148 #ifdef CONFIG_RT_MUTEXES
149 extern int max_lock_depth;
152 #ifdef CONFIG_PROC_SYSCTL
153 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
155 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
156 void __user *buffer, size_t *lenp, loff_t *ppos);
159 static struct ctl_table root_table[];
160 static struct ctl_table_root sysctl_table_root;
161 static struct ctl_table_header root_table_header = {
163 .ctl_table = root_table,
164 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
165 .root = &sysctl_table_root,
166 .set = &sysctl_table_root.default_set,
168 static struct ctl_table_root sysctl_table_root = {
169 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
170 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
173 static struct ctl_table kern_table[];
174 static struct ctl_table vm_table[];
175 static struct ctl_table fs_table[];
176 static struct ctl_table debug_table[];
177 static struct ctl_table dev_table[];
178 extern struct ctl_table random_table[];
179 #ifdef CONFIG_INOTIFY_USER
180 extern struct ctl_table inotify_table[];
183 extern struct ctl_table epoll_table[];
186 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
187 int sysctl_legacy_va_layout;
190 extern int prove_locking;
191 extern int lock_stat;
193 /* The default sysctl tables: */
195 static struct ctl_table root_table[] = {
197 .ctl_name = CTL_KERN,
198 .procname = "kernel",
215 .ctl_name = CTL_DEBUG,
218 .child = debug_table,
227 * NOTE: do not add new entries to this table unless you have read
228 * Documentation/sysctl/ctl_unnumbered.txt
233 #ifdef CONFIG_SCHED_DEBUG
234 static int min_sched_granularity_ns = 100000; /* 100 usecs */
235 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
236 static int min_wakeup_granularity_ns; /* 0 usecs */
237 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
240 static struct ctl_table kern_table[] = {
241 #ifdef CONFIG_SCHED_DEBUG
243 .ctl_name = CTL_UNNUMBERED,
244 .procname = "sched_min_granularity_ns",
245 .data = &sysctl_sched_min_granularity,
246 .maxlen = sizeof(unsigned int),
248 .proc_handler = &sched_nr_latency_handler,
249 .strategy = &sysctl_intvec,
250 .extra1 = &min_sched_granularity_ns,
251 .extra2 = &max_sched_granularity_ns,
254 .ctl_name = CTL_UNNUMBERED,
255 .procname = "sched_latency_ns",
256 .data = &sysctl_sched_latency,
257 .maxlen = sizeof(unsigned int),
259 .proc_handler = &sched_nr_latency_handler,
260 .strategy = &sysctl_intvec,
261 .extra1 = &min_sched_granularity_ns,
262 .extra2 = &max_sched_granularity_ns,
265 .ctl_name = CTL_UNNUMBERED,
266 .procname = "sched_wakeup_granularity_ns",
267 .data = &sysctl_sched_wakeup_granularity,
268 .maxlen = sizeof(unsigned int),
270 .proc_handler = &proc_dointvec_minmax,
271 .strategy = &sysctl_intvec,
272 .extra1 = &min_wakeup_granularity_ns,
273 .extra2 = &max_wakeup_granularity_ns,
276 .ctl_name = CTL_UNNUMBERED,
277 .procname = "sched_shares_ratelimit",
278 .data = &sysctl_sched_shares_ratelimit,
279 .maxlen = sizeof(unsigned int),
281 .proc_handler = &proc_dointvec,
284 .ctl_name = CTL_UNNUMBERED,
285 .procname = "sched_shares_thresh",
286 .data = &sysctl_sched_shares_thresh,
287 .maxlen = sizeof(unsigned int),
289 .proc_handler = &proc_dointvec_minmax,
290 .strategy = &sysctl_intvec,
294 .ctl_name = CTL_UNNUMBERED,
295 .procname = "sched_child_runs_first",
296 .data = &sysctl_sched_child_runs_first,
297 .maxlen = sizeof(unsigned int),
299 .proc_handler = &proc_dointvec,
302 .ctl_name = CTL_UNNUMBERED,
303 .procname = "sched_features",
304 .data = &sysctl_sched_features,
305 .maxlen = sizeof(unsigned int),
307 .proc_handler = &proc_dointvec,
310 .ctl_name = CTL_UNNUMBERED,
311 .procname = "sched_migration_cost",
312 .data = &sysctl_sched_migration_cost,
313 .maxlen = sizeof(unsigned int),
315 .proc_handler = &proc_dointvec,
318 .ctl_name = CTL_UNNUMBERED,
319 .procname = "sched_nr_migrate",
320 .data = &sysctl_sched_nr_migrate,
321 .maxlen = sizeof(unsigned int),
323 .proc_handler = &proc_dointvec,
327 .ctl_name = CTL_UNNUMBERED,
328 .procname = "sched_rt_period_us",
329 .data = &sysctl_sched_rt_period,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = &sched_rt_handler,
335 .ctl_name = CTL_UNNUMBERED,
336 .procname = "sched_rt_runtime_us",
337 .data = &sysctl_sched_rt_runtime,
338 .maxlen = sizeof(int),
340 .proc_handler = &sched_rt_handler,
343 .ctl_name = CTL_UNNUMBERED,
344 .procname = "sched_compat_yield",
345 .data = &sysctl_sched_compat_yield,
346 .maxlen = sizeof(unsigned int),
348 .proc_handler = &proc_dointvec,
350 #ifdef CONFIG_PROVE_LOCKING
352 .ctl_name = CTL_UNNUMBERED,
353 .procname = "prove_locking",
354 .data = &prove_locking,
355 .maxlen = sizeof(int),
357 .proc_handler = &proc_dointvec,
360 #ifdef CONFIG_LOCK_STAT
362 .ctl_name = CTL_UNNUMBERED,
363 .procname = "lock_stat",
365 .maxlen = sizeof(int),
367 .proc_handler = &proc_dointvec,
371 .ctl_name = KERN_PANIC,
373 .data = &panic_timeout,
374 .maxlen = sizeof(int),
376 .proc_handler = &proc_dointvec,
379 .ctl_name = KERN_CORE_USES_PID,
380 .procname = "core_uses_pid",
381 .data = &core_uses_pid,
382 .maxlen = sizeof(int),
384 .proc_handler = &proc_dointvec,
387 .ctl_name = KERN_CORE_PATTERN,
388 .procname = "core_pattern",
389 .data = core_pattern,
390 .maxlen = CORENAME_MAX_SIZE,
392 .proc_handler = &proc_dostring,
393 .strategy = &sysctl_string,
395 #ifdef CONFIG_PROC_SYSCTL
397 .procname = "tainted",
398 .maxlen = sizeof(long),
400 .proc_handler = &proc_taint,
403 #ifdef CONFIG_LATENCYTOP
405 .procname = "latencytop",
406 .data = &latencytop_enabled,
407 .maxlen = sizeof(int),
409 .proc_handler = &proc_dointvec,
412 #ifdef CONFIG_BLK_DEV_INITRD
414 .ctl_name = KERN_REALROOTDEV,
415 .procname = "real-root-dev",
416 .data = &real_root_dev,
417 .maxlen = sizeof(int),
419 .proc_handler = &proc_dointvec,
423 .ctl_name = CTL_UNNUMBERED,
424 .procname = "print-fatal-signals",
425 .data = &print_fatal_signals,
426 .maxlen = sizeof(int),
428 .proc_handler = &proc_dointvec,
432 .ctl_name = KERN_SPARC_REBOOT,
433 .procname = "reboot-cmd",
434 .data = reboot_command,
437 .proc_handler = &proc_dostring,
438 .strategy = &sysctl_string,
441 .ctl_name = KERN_SPARC_STOP_A,
442 .procname = "stop-a",
443 .data = &stop_a_enabled,
444 .maxlen = sizeof (int),
446 .proc_handler = &proc_dointvec,
449 .ctl_name = KERN_SPARC_SCONS_PWROFF,
450 .procname = "scons-poweroff",
451 .data = &scons_pwroff,
452 .maxlen = sizeof (int),
454 .proc_handler = &proc_dointvec,
457 #ifdef CONFIG_SPARC64
459 .ctl_name = CTL_UNNUMBERED,
460 .procname = "tsb-ratio",
461 .data = &sysctl_tsb_ratio,
462 .maxlen = sizeof (int),
464 .proc_handler = &proc_dointvec,
469 .ctl_name = KERN_HPPA_PWRSW,
470 .procname = "soft-power",
471 .data = &pwrsw_enabled,
472 .maxlen = sizeof (int),
474 .proc_handler = &proc_dointvec,
477 .ctl_name = KERN_HPPA_UNALIGNED,
478 .procname = "unaligned-trap",
479 .data = &unaligned_enabled,
480 .maxlen = sizeof (int),
482 .proc_handler = &proc_dointvec,
486 .ctl_name = KERN_CTLALTDEL,
487 .procname = "ctrl-alt-del",
489 .maxlen = sizeof(int),
491 .proc_handler = &proc_dointvec,
493 #ifdef CONFIG_FUNCTION_TRACER
495 .ctl_name = CTL_UNNUMBERED,
496 .procname = "ftrace_enabled",
497 .data = &ftrace_enabled,
498 .maxlen = sizeof(int),
500 .proc_handler = &ftrace_enable_sysctl,
503 #ifdef CONFIG_STACK_TRACER
505 .ctl_name = CTL_UNNUMBERED,
506 .procname = "stack_tracer_enabled",
507 .data = &stack_tracer_enabled,
508 .maxlen = sizeof(int),
510 .proc_handler = &stack_trace_sysctl,
513 #ifdef CONFIG_TRACING
515 .ctl_name = CTL_UNNUMBERED,
516 .procname = "ftrace_dump_on_oops",
517 .data = &ftrace_dump_on_oops,
518 .maxlen = sizeof(int),
520 .proc_handler = &proc_dointvec,
523 #ifdef CONFIG_MODULES
525 .ctl_name = KERN_MODPROBE,
526 .procname = "modprobe",
527 .data = &modprobe_path,
528 .maxlen = KMOD_PATH_LEN,
530 .proc_handler = &proc_dostring,
531 .strategy = &sysctl_string,
534 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
536 .ctl_name = KERN_HOTPLUG,
537 .procname = "hotplug",
538 .data = &uevent_helper,
539 .maxlen = UEVENT_HELPER_PATH_LEN,
541 .proc_handler = &proc_dostring,
542 .strategy = &sysctl_string,
545 #ifdef CONFIG_CHR_DEV_SG
547 .ctl_name = KERN_SG_BIG_BUFF,
548 .procname = "sg-big-buff",
549 .data = &sg_big_buff,
550 .maxlen = sizeof (int),
552 .proc_handler = &proc_dointvec,
555 #ifdef CONFIG_BSD_PROCESS_ACCT
557 .ctl_name = KERN_ACCT,
560 .maxlen = 3*sizeof(int),
562 .proc_handler = &proc_dointvec,
565 #ifdef CONFIG_MAGIC_SYSRQ
567 .ctl_name = KERN_SYSRQ,
569 .data = &__sysrq_enabled,
570 .maxlen = sizeof (int),
572 .proc_handler = &proc_dointvec,
575 #ifdef CONFIG_PROC_SYSCTL
577 .procname = "cad_pid",
579 .maxlen = sizeof (int),
581 .proc_handler = &proc_do_cad_pid,
585 .ctl_name = KERN_MAX_THREADS,
586 .procname = "threads-max",
587 .data = &max_threads,
588 .maxlen = sizeof(int),
590 .proc_handler = &proc_dointvec,
593 .ctl_name = KERN_RANDOM,
594 .procname = "random",
596 .child = random_table,
599 .ctl_name = KERN_OVERFLOWUID,
600 .procname = "overflowuid",
601 .data = &overflowuid,
602 .maxlen = sizeof(int),
604 .proc_handler = &proc_dointvec_minmax,
605 .strategy = &sysctl_intvec,
606 .extra1 = &minolduid,
607 .extra2 = &maxolduid,
610 .ctl_name = KERN_OVERFLOWGID,
611 .procname = "overflowgid",
612 .data = &overflowgid,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec_minmax,
616 .strategy = &sysctl_intvec,
617 .extra1 = &minolduid,
618 .extra2 = &maxolduid,
621 #ifdef CONFIG_MATHEMU
623 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
624 .procname = "ieee_emulation_warnings",
625 .data = &sysctl_ieee_emulation_warnings,
626 .maxlen = sizeof(int),
628 .proc_handler = &proc_dointvec,
632 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
633 .procname = "userprocess_debug",
634 .data = &sysctl_userprocess_debug,
635 .maxlen = sizeof(int),
637 .proc_handler = &proc_dointvec,
641 .ctl_name = KERN_PIDMAX,
642 .procname = "pid_max",
644 .maxlen = sizeof (int),
646 .proc_handler = &proc_dointvec_minmax,
647 .strategy = sysctl_intvec,
648 .extra1 = &pid_max_min,
649 .extra2 = &pid_max_max,
652 .ctl_name = KERN_PANIC_ON_OOPS,
653 .procname = "panic_on_oops",
654 .data = &panic_on_oops,
655 .maxlen = sizeof(int),
657 .proc_handler = &proc_dointvec,
659 #if defined CONFIG_PRINTK
661 .ctl_name = KERN_PRINTK,
662 .procname = "printk",
663 .data = &console_loglevel,
664 .maxlen = 4*sizeof(int),
666 .proc_handler = &proc_dointvec,
669 .ctl_name = KERN_PRINTK_RATELIMIT,
670 .procname = "printk_ratelimit",
671 .data = &printk_ratelimit_state.interval,
672 .maxlen = sizeof(int),
674 .proc_handler = &proc_dointvec_jiffies,
675 .strategy = &sysctl_jiffies,
678 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
679 .procname = "printk_ratelimit_burst",
680 .data = &printk_ratelimit_state.burst,
681 .maxlen = sizeof(int),
683 .proc_handler = &proc_dointvec,
687 .ctl_name = KERN_NGROUPS_MAX,
688 .procname = "ngroups_max",
689 .data = &ngroups_max,
690 .maxlen = sizeof (int),
692 .proc_handler = &proc_dointvec,
694 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
696 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
697 .procname = "unknown_nmi_panic",
698 .data = &unknown_nmi_panic,
699 .maxlen = sizeof (int),
701 .proc_handler = &proc_dointvec,
704 .procname = "nmi_watchdog",
705 .data = &nmi_watchdog_enabled,
706 .maxlen = sizeof (int),
708 .proc_handler = &proc_nmi_enabled,
711 #if defined(CONFIG_X86)
713 .ctl_name = KERN_PANIC_ON_NMI,
714 .procname = "panic_on_unrecovered_nmi",
715 .data = &panic_on_unrecovered_nmi,
716 .maxlen = sizeof(int),
718 .proc_handler = &proc_dointvec,
721 .ctl_name = KERN_BOOTLOADER_TYPE,
722 .procname = "bootloader_type",
723 .data = &bootloader_type,
724 .maxlen = sizeof (int),
726 .proc_handler = &proc_dointvec,
729 .ctl_name = CTL_UNNUMBERED,
730 .procname = "kstack_depth_to_print",
731 .data = &kstack_depth_to_print,
732 .maxlen = sizeof(int),
734 .proc_handler = &proc_dointvec,
737 .ctl_name = CTL_UNNUMBERED,
738 .procname = "io_delay_type",
739 .data = &io_delay_type,
740 .maxlen = sizeof(int),
742 .proc_handler = &proc_dointvec,
745 #if defined(CONFIG_MMU)
747 .ctl_name = KERN_RANDOMIZE,
748 .procname = "randomize_va_space",
749 .data = &randomize_va_space,
750 .maxlen = sizeof(int),
752 .proc_handler = &proc_dointvec,
755 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
757 .ctl_name = KERN_SPIN_RETRY,
758 .procname = "spin_retry",
760 .maxlen = sizeof (int),
762 .proc_handler = &proc_dointvec,
765 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
767 .procname = "acpi_video_flags",
768 .data = &acpi_realmode_flags,
769 .maxlen = sizeof (unsigned long),
771 .proc_handler = &proc_doulongvec_minmax,
776 .ctl_name = KERN_IA64_UNALIGNED,
777 .procname = "ignore-unaligned-usertrap",
778 .data = &no_unaligned_warning,
779 .maxlen = sizeof (int),
781 .proc_handler = &proc_dointvec,
784 .ctl_name = CTL_UNNUMBERED,
785 .procname = "unaligned-dump-stack",
786 .data = &unaligned_dump_stack,
787 .maxlen = sizeof (int),
789 .proc_handler = &proc_dointvec,
792 #ifdef CONFIG_DETECT_SOFTLOCKUP
794 .ctl_name = CTL_UNNUMBERED,
795 .procname = "softlockup_panic",
796 .data = &softlockup_panic,
797 .maxlen = sizeof(int),
799 .proc_handler = &proc_dointvec_minmax,
800 .strategy = &sysctl_intvec,
805 .ctl_name = CTL_UNNUMBERED,
806 .procname = "softlockup_thresh",
807 .data = &softlockup_thresh,
808 .maxlen = sizeof(int),
810 .proc_handler = &proc_dosoftlockup_thresh,
811 .strategy = &sysctl_intvec,
816 .ctl_name = CTL_UNNUMBERED,
817 .procname = "hung_task_check_count",
818 .data = &sysctl_hung_task_check_count,
819 .maxlen = sizeof(unsigned long),
821 .proc_handler = &proc_doulongvec_minmax,
822 .strategy = &sysctl_intvec,
825 .ctl_name = CTL_UNNUMBERED,
826 .procname = "hung_task_timeout_secs",
827 .data = &sysctl_hung_task_timeout_secs,
828 .maxlen = sizeof(unsigned long),
830 .proc_handler = &proc_doulongvec_minmax,
831 .strategy = &sysctl_intvec,
834 .ctl_name = CTL_UNNUMBERED,
835 .procname = "hung_task_warnings",
836 .data = &sysctl_hung_task_warnings,
837 .maxlen = sizeof(unsigned long),
839 .proc_handler = &proc_doulongvec_minmax,
840 .strategy = &sysctl_intvec,
845 .ctl_name = KERN_COMPAT_LOG,
846 .procname = "compat-log",
848 .maxlen = sizeof (int),
850 .proc_handler = &proc_dointvec,
853 #ifdef CONFIG_RT_MUTEXES
855 .ctl_name = KERN_MAX_LOCK_DEPTH,
856 .procname = "max_lock_depth",
857 .data = &max_lock_depth,
858 .maxlen = sizeof(int),
860 .proc_handler = &proc_dointvec,
864 .ctl_name = CTL_UNNUMBERED,
865 .procname = "poweroff_cmd",
866 .data = &poweroff_cmd,
867 .maxlen = POWEROFF_CMD_PATH_LEN,
869 .proc_handler = &proc_dostring,
870 .strategy = &sysctl_string,
874 .ctl_name = CTL_UNNUMBERED,
877 .child = key_sysctls,
880 #ifdef CONFIG_RCU_TORTURE_TEST
882 .ctl_name = CTL_UNNUMBERED,
883 .procname = "rcutorture_runnable",
884 .data = &rcutorture_runnable,
885 .maxlen = sizeof(int),
887 .proc_handler = &proc_dointvec,
890 #ifdef CONFIG_UNEVICTABLE_LRU
892 .ctl_name = CTL_UNNUMBERED,
893 .procname = "scan_unevictable_pages",
894 .data = &scan_unevictable_pages,
895 .maxlen = sizeof(scan_unevictable_pages),
897 .proc_handler = &scan_unevictable_handler,
901 * NOTE: do not add new entries to this table unless you have read
902 * Documentation/sysctl/ctl_unnumbered.txt
907 static struct ctl_table vm_table[] = {
909 .ctl_name = VM_OVERCOMMIT_MEMORY,
910 .procname = "overcommit_memory",
911 .data = &sysctl_overcommit_memory,
912 .maxlen = sizeof(sysctl_overcommit_memory),
914 .proc_handler = &proc_dointvec,
917 .ctl_name = VM_PANIC_ON_OOM,
918 .procname = "panic_on_oom",
919 .data = &sysctl_panic_on_oom,
920 .maxlen = sizeof(sysctl_panic_on_oom),
922 .proc_handler = &proc_dointvec,
925 .ctl_name = CTL_UNNUMBERED,
926 .procname = "oom_kill_allocating_task",
927 .data = &sysctl_oom_kill_allocating_task,
928 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
930 .proc_handler = &proc_dointvec,
933 .ctl_name = CTL_UNNUMBERED,
934 .procname = "oom_dump_tasks",
935 .data = &sysctl_oom_dump_tasks,
936 .maxlen = sizeof(sysctl_oom_dump_tasks),
938 .proc_handler = &proc_dointvec,
941 .ctl_name = VM_OVERCOMMIT_RATIO,
942 .procname = "overcommit_ratio",
943 .data = &sysctl_overcommit_ratio,
944 .maxlen = sizeof(sysctl_overcommit_ratio),
946 .proc_handler = &proc_dointvec,
949 .ctl_name = VM_PAGE_CLUSTER,
950 .procname = "page-cluster",
951 .data = &page_cluster,
952 .maxlen = sizeof(int),
954 .proc_handler = &proc_dointvec,
957 .ctl_name = VM_DIRTY_BACKGROUND,
958 .procname = "dirty_background_ratio",
959 .data = &dirty_background_ratio,
960 .maxlen = sizeof(dirty_background_ratio),
962 .proc_handler = &dirty_background_ratio_handler,
963 .strategy = &sysctl_intvec,
965 .extra2 = &one_hundred,
968 .ctl_name = CTL_UNNUMBERED,
969 .procname = "dirty_background_bytes",
970 .data = &dirty_background_bytes,
971 .maxlen = sizeof(dirty_background_bytes),
973 .proc_handler = &dirty_background_bytes_handler,
974 .strategy = &sysctl_intvec,
978 .ctl_name = VM_DIRTY_RATIO,
979 .procname = "dirty_ratio",
980 .data = &vm_dirty_ratio,
981 .maxlen = sizeof(vm_dirty_ratio),
983 .proc_handler = &dirty_ratio_handler,
984 .strategy = &sysctl_intvec,
986 .extra2 = &one_hundred,
989 .ctl_name = CTL_UNNUMBERED,
990 .procname = "dirty_bytes",
991 .data = &vm_dirty_bytes,
992 .maxlen = sizeof(vm_dirty_bytes),
994 .proc_handler = &dirty_bytes_handler,
995 .strategy = &sysctl_intvec,
999 .procname = "dirty_writeback_centisecs",
1000 .data = &dirty_writeback_interval,
1001 .maxlen = sizeof(dirty_writeback_interval),
1003 .proc_handler = &dirty_writeback_centisecs_handler,
1006 .procname = "dirty_expire_centisecs",
1007 .data = &dirty_expire_interval,
1008 .maxlen = sizeof(dirty_expire_interval),
1010 .proc_handler = &proc_dointvec,
1013 .ctl_name = VM_NR_PDFLUSH_THREADS,
1014 .procname = "nr_pdflush_threads",
1015 .data = &nr_pdflush_threads,
1016 .maxlen = sizeof nr_pdflush_threads,
1017 .mode = 0444 /* read-only*/,
1018 .proc_handler = &proc_dointvec,
1021 .ctl_name = VM_SWAPPINESS,
1022 .procname = "swappiness",
1023 .data = &vm_swappiness,
1024 .maxlen = sizeof(vm_swappiness),
1026 .proc_handler = &proc_dointvec_minmax,
1027 .strategy = &sysctl_intvec,
1029 .extra2 = &one_hundred,
1031 #ifdef CONFIG_HUGETLB_PAGE
1033 .procname = "nr_hugepages",
1035 .maxlen = sizeof(unsigned long),
1037 .proc_handler = &hugetlb_sysctl_handler,
1038 .extra1 = (void *)&hugetlb_zero,
1039 .extra2 = (void *)&hugetlb_infinity,
1042 .ctl_name = VM_HUGETLB_GROUP,
1043 .procname = "hugetlb_shm_group",
1044 .data = &sysctl_hugetlb_shm_group,
1045 .maxlen = sizeof(gid_t),
1047 .proc_handler = &proc_dointvec,
1050 .ctl_name = CTL_UNNUMBERED,
1051 .procname = "hugepages_treat_as_movable",
1052 .data = &hugepages_treat_as_movable,
1053 .maxlen = sizeof(int),
1055 .proc_handler = &hugetlb_treat_movable_handler,
1058 .ctl_name = CTL_UNNUMBERED,
1059 .procname = "nr_overcommit_hugepages",
1061 .maxlen = sizeof(unsigned long),
1063 .proc_handler = &hugetlb_overcommit_handler,
1064 .extra1 = (void *)&hugetlb_zero,
1065 .extra2 = (void *)&hugetlb_infinity,
1069 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1070 .procname = "lowmem_reserve_ratio",
1071 .data = &sysctl_lowmem_reserve_ratio,
1072 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1074 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1075 .strategy = &sysctl_intvec,
1078 .ctl_name = VM_DROP_PAGECACHE,
1079 .procname = "drop_caches",
1080 .data = &sysctl_drop_caches,
1081 .maxlen = sizeof(int),
1083 .proc_handler = drop_caches_sysctl_handler,
1084 .strategy = &sysctl_intvec,
1087 .ctl_name = VM_MIN_FREE_KBYTES,
1088 .procname = "min_free_kbytes",
1089 .data = &min_free_kbytes,
1090 .maxlen = sizeof(min_free_kbytes),
1092 .proc_handler = &min_free_kbytes_sysctl_handler,
1093 .strategy = &sysctl_intvec,
1097 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1098 .procname = "percpu_pagelist_fraction",
1099 .data = &percpu_pagelist_fraction,
1100 .maxlen = sizeof(percpu_pagelist_fraction),
1102 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1103 .strategy = &sysctl_intvec,
1104 .extra1 = &min_percpu_pagelist_fract,
1108 .ctl_name = VM_MAX_MAP_COUNT,
1109 .procname = "max_map_count",
1110 .data = &sysctl_max_map_count,
1111 .maxlen = sizeof(sysctl_max_map_count),
1113 .proc_handler = &proc_dointvec
1117 .ctl_name = CTL_UNNUMBERED,
1118 .procname = "nr_trim_pages",
1119 .data = &sysctl_nr_trim_pages,
1120 .maxlen = sizeof(sysctl_nr_trim_pages),
1122 .proc_handler = &proc_dointvec_minmax,
1123 .strategy = &sysctl_intvec,
1128 .ctl_name = VM_LAPTOP_MODE,
1129 .procname = "laptop_mode",
1130 .data = &laptop_mode,
1131 .maxlen = sizeof(laptop_mode),
1133 .proc_handler = &proc_dointvec_jiffies,
1134 .strategy = &sysctl_jiffies,
1137 .ctl_name = VM_BLOCK_DUMP,
1138 .procname = "block_dump",
1139 .data = &block_dump,
1140 .maxlen = sizeof(block_dump),
1142 .proc_handler = &proc_dointvec,
1143 .strategy = &sysctl_intvec,
1147 .ctl_name = VM_VFS_CACHE_PRESSURE,
1148 .procname = "vfs_cache_pressure",
1149 .data = &sysctl_vfs_cache_pressure,
1150 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1152 .proc_handler = &proc_dointvec,
1153 .strategy = &sysctl_intvec,
1156 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1158 .ctl_name = VM_LEGACY_VA_LAYOUT,
1159 .procname = "legacy_va_layout",
1160 .data = &sysctl_legacy_va_layout,
1161 .maxlen = sizeof(sysctl_legacy_va_layout),
1163 .proc_handler = &proc_dointvec,
1164 .strategy = &sysctl_intvec,
1170 .ctl_name = VM_ZONE_RECLAIM_MODE,
1171 .procname = "zone_reclaim_mode",
1172 .data = &zone_reclaim_mode,
1173 .maxlen = sizeof(zone_reclaim_mode),
1175 .proc_handler = &proc_dointvec,
1176 .strategy = &sysctl_intvec,
1180 .ctl_name = VM_MIN_UNMAPPED,
1181 .procname = "min_unmapped_ratio",
1182 .data = &sysctl_min_unmapped_ratio,
1183 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1185 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1186 .strategy = &sysctl_intvec,
1188 .extra2 = &one_hundred,
1191 .ctl_name = VM_MIN_SLAB,
1192 .procname = "min_slab_ratio",
1193 .data = &sysctl_min_slab_ratio,
1194 .maxlen = sizeof(sysctl_min_slab_ratio),
1196 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1197 .strategy = &sysctl_intvec,
1199 .extra2 = &one_hundred,
1204 .ctl_name = CTL_UNNUMBERED,
1205 .procname = "stat_interval",
1206 .data = &sysctl_stat_interval,
1207 .maxlen = sizeof(sysctl_stat_interval),
1209 .proc_handler = &proc_dointvec_jiffies,
1210 .strategy = &sysctl_jiffies,
1213 #ifdef CONFIG_SECURITY
1215 .ctl_name = CTL_UNNUMBERED,
1216 .procname = "mmap_min_addr",
1217 .data = &mmap_min_addr,
1218 .maxlen = sizeof(unsigned long),
1220 .proc_handler = &proc_doulongvec_minmax,
1225 .ctl_name = CTL_UNNUMBERED,
1226 .procname = "numa_zonelist_order",
1227 .data = &numa_zonelist_order,
1228 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1230 .proc_handler = &numa_zonelist_order_handler,
1231 .strategy = &sysctl_string,
1234 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1235 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1237 .ctl_name = VM_VDSO_ENABLED,
1238 .procname = "vdso_enabled",
1239 .data = &vdso_enabled,
1240 .maxlen = sizeof(vdso_enabled),
1242 .proc_handler = &proc_dointvec,
1243 .strategy = &sysctl_intvec,
1247 #ifdef CONFIG_HIGHMEM
1249 .ctl_name = CTL_UNNUMBERED,
1250 .procname = "highmem_is_dirtyable",
1251 .data = &vm_highmem_is_dirtyable,
1252 .maxlen = sizeof(vm_highmem_is_dirtyable),
1254 .proc_handler = &proc_dointvec_minmax,
1255 .strategy = &sysctl_intvec,
1261 * NOTE: do not add new entries to this table unless you have read
1262 * Documentation/sysctl/ctl_unnumbered.txt
1267 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1268 static struct ctl_table binfmt_misc_table[] = {
1273 static struct ctl_table fs_table[] = {
1275 .ctl_name = FS_NRINODE,
1276 .procname = "inode-nr",
1277 .data = &inodes_stat,
1278 .maxlen = 2*sizeof(int),
1280 .proc_handler = &proc_dointvec,
1283 .ctl_name = FS_STATINODE,
1284 .procname = "inode-state",
1285 .data = &inodes_stat,
1286 .maxlen = 7*sizeof(int),
1288 .proc_handler = &proc_dointvec,
1291 .procname = "file-nr",
1292 .data = &files_stat,
1293 .maxlen = 3*sizeof(int),
1295 .proc_handler = &proc_nr_files,
1298 .ctl_name = FS_MAXFILE,
1299 .procname = "file-max",
1300 .data = &files_stat.max_files,
1301 .maxlen = sizeof(int),
1303 .proc_handler = &proc_dointvec,
1306 .ctl_name = CTL_UNNUMBERED,
1307 .procname = "nr_open",
1308 .data = &sysctl_nr_open,
1309 .maxlen = sizeof(int),
1311 .proc_handler = &proc_dointvec_minmax,
1312 .extra1 = &sysctl_nr_open_min,
1313 .extra2 = &sysctl_nr_open_max,
1316 .ctl_name = FS_DENTRY,
1317 .procname = "dentry-state",
1318 .data = &dentry_stat,
1319 .maxlen = 6*sizeof(int),
1321 .proc_handler = &proc_dointvec,
1324 .ctl_name = FS_OVERFLOWUID,
1325 .procname = "overflowuid",
1326 .data = &fs_overflowuid,
1327 .maxlen = sizeof(int),
1329 .proc_handler = &proc_dointvec_minmax,
1330 .strategy = &sysctl_intvec,
1331 .extra1 = &minolduid,
1332 .extra2 = &maxolduid,
1335 .ctl_name = FS_OVERFLOWGID,
1336 .procname = "overflowgid",
1337 .data = &fs_overflowgid,
1338 .maxlen = sizeof(int),
1340 .proc_handler = &proc_dointvec_minmax,
1341 .strategy = &sysctl_intvec,
1342 .extra1 = &minolduid,
1343 .extra2 = &maxolduid,
1345 #ifdef CONFIG_FILE_LOCKING
1347 .ctl_name = FS_LEASES,
1348 .procname = "leases-enable",
1349 .data = &leases_enable,
1350 .maxlen = sizeof(int),
1352 .proc_handler = &proc_dointvec,
1355 #ifdef CONFIG_DNOTIFY
1357 .ctl_name = FS_DIR_NOTIFY,
1358 .procname = "dir-notify-enable",
1359 .data = &dir_notify_enable,
1360 .maxlen = sizeof(int),
1362 .proc_handler = &proc_dointvec,
1366 #ifdef CONFIG_FILE_LOCKING
1368 .ctl_name = FS_LEASE_TIME,
1369 .procname = "lease-break-time",
1370 .data = &lease_break_time,
1371 .maxlen = sizeof(int),
1373 .proc_handler = &proc_dointvec,
1378 .procname = "aio-nr",
1380 .maxlen = sizeof(aio_nr),
1382 .proc_handler = &proc_doulongvec_minmax,
1385 .procname = "aio-max-nr",
1386 .data = &aio_max_nr,
1387 .maxlen = sizeof(aio_max_nr),
1389 .proc_handler = &proc_doulongvec_minmax,
1391 #endif /* CONFIG_AIO */
1392 #ifdef CONFIG_INOTIFY_USER
1394 .ctl_name = FS_INOTIFY,
1395 .procname = "inotify",
1397 .child = inotify_table,
1402 .procname = "epoll",
1404 .child = epoll_table,
1409 .ctl_name = KERN_SETUID_DUMPABLE,
1410 .procname = "suid_dumpable",
1411 .data = &suid_dumpable,
1412 .maxlen = sizeof(int),
1414 .proc_handler = &proc_dointvec_minmax,
1415 .strategy = &sysctl_intvec,
1419 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1421 .ctl_name = CTL_UNNUMBERED,
1422 .procname = "binfmt_misc",
1424 .child = binfmt_misc_table,
1428 * NOTE: do not add new entries to this table unless you have read
1429 * Documentation/sysctl/ctl_unnumbered.txt
1434 static struct ctl_table debug_table[] = {
1435 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1437 .ctl_name = CTL_UNNUMBERED,
1438 .procname = "exception-trace",
1439 .data = &show_unhandled_signals,
1440 .maxlen = sizeof(int),
1442 .proc_handler = proc_dointvec
1448 static struct ctl_table dev_table[] = {
1452 static DEFINE_SPINLOCK(sysctl_lock);
1454 /* called under sysctl_lock */
1455 static int use_table(struct ctl_table_header *p)
1457 if (unlikely(p->unregistering))
1463 /* called under sysctl_lock */
1464 static void unuse_table(struct ctl_table_header *p)
1467 if (unlikely(p->unregistering))
1468 complete(p->unregistering);
1471 /* called under sysctl_lock, will reacquire if has to wait */
1472 static void start_unregistering(struct ctl_table_header *p)
1475 * if p->used is 0, nobody will ever touch that entry again;
1476 * we'll eliminate all paths to it before dropping sysctl_lock
1478 if (unlikely(p->used)) {
1479 struct completion wait;
1480 init_completion(&wait);
1481 p->unregistering = &wait;
1482 spin_unlock(&sysctl_lock);
1483 wait_for_completion(&wait);
1484 spin_lock(&sysctl_lock);
1486 /* anything non-NULL; we'll never dereference it */
1487 p->unregistering = ERR_PTR(-EINVAL);
1490 * do not remove from the list until nobody holds it; walking the
1491 * list in do_sysctl() relies on that.
1493 list_del_init(&p->ctl_entry);
1496 void sysctl_head_get(struct ctl_table_header *head)
1498 spin_lock(&sysctl_lock);
1500 spin_unlock(&sysctl_lock);
1503 void sysctl_head_put(struct ctl_table_header *head)
1505 spin_lock(&sysctl_lock);
1508 spin_unlock(&sysctl_lock);
1511 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1515 spin_lock(&sysctl_lock);
1516 if (!use_table(head))
1517 head = ERR_PTR(-ENOENT);
1518 spin_unlock(&sysctl_lock);
1522 void sysctl_head_finish(struct ctl_table_header *head)
1526 spin_lock(&sysctl_lock);
1528 spin_unlock(&sysctl_lock);
1531 static struct ctl_table_set *
1532 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1534 struct ctl_table_set *set = &root->default_set;
1536 set = root->lookup(root, namespaces);
1540 static struct list_head *
1541 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1543 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1547 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1548 struct ctl_table_header *prev)
1550 struct ctl_table_root *root;
1551 struct list_head *header_list;
1552 struct ctl_table_header *head;
1553 struct list_head *tmp;
1555 spin_lock(&sysctl_lock);
1558 tmp = &prev->ctl_entry;
1562 tmp = &root_table_header.ctl_entry;
1564 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1566 if (!use_table(head))
1568 spin_unlock(&sysctl_lock);
1573 header_list = lookup_header_list(root, namespaces);
1574 if (tmp != header_list)
1578 root = list_entry(root->root_list.next,
1579 struct ctl_table_root, root_list);
1580 if (root == &sysctl_table_root)
1582 header_list = lookup_header_list(root, namespaces);
1583 } while (list_empty(header_list));
1584 tmp = header_list->next;
1587 spin_unlock(&sysctl_lock);
1591 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1593 return __sysctl_head_next(current->nsproxy, prev);
1596 void register_sysctl_root(struct ctl_table_root *root)
1598 spin_lock(&sysctl_lock);
1599 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1600 spin_unlock(&sysctl_lock);
1603 #ifdef CONFIG_SYSCTL_SYSCALL
1604 /* Perform the actual read/write of a sysctl table entry. */
1605 static int do_sysctl_strategy(struct ctl_table_root *root,
1606 struct ctl_table *table,
1607 void __user *oldval, size_t __user *oldlenp,
1608 void __user *newval, size_t newlen)
1616 if (sysctl_perm(root, table, op))
1619 if (table->strategy) {
1620 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1627 /* If there is no strategy routine, or if the strategy returns
1628 * zero, proceed with automatic r/w */
1629 if (table->data && table->maxlen) {
1630 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1637 static int parse_table(int __user *name, int nlen,
1638 void __user *oldval, size_t __user *oldlenp,
1639 void __user *newval, size_t newlen,
1640 struct ctl_table_root *root,
1641 struct ctl_table *table)
1647 if (get_user(n, name))
1649 for ( ; table->ctl_name || table->procname; table++) {
1650 if (!table->ctl_name)
1652 if (n == table->ctl_name) {
1655 if (sysctl_perm(root, table, MAY_EXEC))
1659 table = table->child;
1662 error = do_sysctl_strategy(root, table,
1671 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1672 void __user *newval, size_t newlen)
1674 struct ctl_table_header *head;
1675 int error = -ENOTDIR;
1677 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1681 if (!oldlenp || get_user(old_len, oldlenp))
1685 for (head = sysctl_head_next(NULL); head;
1686 head = sysctl_head_next(head)) {
1687 error = parse_table(name, nlen, oldval, oldlenp,
1689 head->root, head->ctl_table);
1690 if (error != -ENOTDIR) {
1691 sysctl_head_finish(head);
1698 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1700 struct __sysctl_args tmp;
1703 if (copy_from_user(&tmp, args, sizeof(tmp)))
1706 error = deprecated_sysctl_warning(&tmp);
1711 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1712 tmp.newval, tmp.newlen);
1717 #endif /* CONFIG_SYSCTL_SYSCALL */
1720 * sysctl_perm does NOT grant the superuser all rights automatically, because
1721 * some sysctl variables are readonly even to root.
1724 static int test_perm(int mode, int op)
1726 if (!current_euid())
1728 else if (in_egroup_p(0))
1730 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1735 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1740 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1744 if (root->permissions)
1745 mode = root->permissions(root, current->nsproxy, table);
1749 return test_perm(mode, op);
1752 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1754 for (; table->ctl_name || table->procname; table++) {
1755 table->parent = parent;
1757 sysctl_set_parent(table, table->child);
1761 static __init int sysctl_init(void)
1763 sysctl_set_parent(NULL, root_table);
1764 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1767 err = sysctl_check_table(current->nsproxy, root_table);
1773 core_initcall(sysctl_init);
1775 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1776 struct ctl_table *table)
1778 struct ctl_table *p;
1779 const char *s = branch->procname;
1781 /* branch should have named subdirectory as its first element */
1782 if (!s || !branch->child)
1785 /* ... and nothing else */
1786 if (branch[1].procname || branch[1].ctl_name)
1789 /* table should contain subdirectory with the same name */
1790 for (p = table; p->procname || p->ctl_name; p++) {
1793 if (p->procname && strcmp(p->procname, s) == 0)
1799 /* see if attaching q to p would be an improvement */
1800 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1802 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1803 struct ctl_table *next;
1805 int not_in_parent = !p->attached_by;
1807 while ((next = is_branch_in(by, to)) != NULL) {
1808 if (by == q->attached_by)
1810 if (to == p->attached_by)
1816 if (is_better && not_in_parent) {
1817 q->attached_by = by;
1818 q->attached_to = to;
1824 * __register_sysctl_paths - register a sysctl hierarchy
1825 * @root: List of sysctl headers to register on
1826 * @namespaces: Data to compute which lists of sysctl entries are visible
1827 * @path: The path to the directory the sysctl table is in.
1828 * @table: the top-level table structure
1830 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1831 * array. A completely 0 filled entry terminates the table.
1833 * The members of the &struct ctl_table structure are used as follows:
1835 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1836 * must be unique within that level of sysctl
1838 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1839 * enter a sysctl file
1841 * data - a pointer to data for use by proc_handler
1843 * maxlen - the maximum size in bytes of the data
1845 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1847 * child - a pointer to the child sysctl table if this entry is a directory, or
1850 * proc_handler - the text handler routine (described below)
1852 * strategy - the strategy routine (described below)
1854 * de - for internal use by the sysctl routines
1856 * extra1, extra2 - extra pointers usable by the proc handler routines
1858 * Leaf nodes in the sysctl tree will be represented by a single file
1859 * under /proc; non-leaf nodes will be represented by directories.
1861 * sysctl(2) can automatically manage read and write requests through
1862 * the sysctl table. The data and maxlen fields of the ctl_table
1863 * struct enable minimal validation of the values being written to be
1864 * performed, and the mode field allows minimal authentication.
1866 * More sophisticated management can be enabled by the provision of a
1867 * strategy routine with the table entry. This will be called before
1868 * any automatic read or write of the data is performed.
1870 * The strategy routine may return
1872 * < 0 - Error occurred (error is passed to user process)
1874 * 0 - OK - proceed with automatic read or write.
1876 * > 0 - OK - read or write has been done by the strategy routine, so
1877 * return immediately.
1879 * There must be a proc_handler routine for any terminal nodes
1880 * mirrored under /proc/sys (non-terminals are handled by a built-in
1881 * directory handler). Several default handlers are available to
1882 * cover common cases -
1884 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1885 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1886 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1888 * It is the handler's job to read the input buffer from user memory
1889 * and process it. The handler should return 0 on success.
1891 * This routine returns %NULL on a failure to register, and a pointer
1892 * to the table header on success.
1894 struct ctl_table_header *__register_sysctl_paths(
1895 struct ctl_table_root *root,
1896 struct nsproxy *namespaces,
1897 const struct ctl_path *path, struct ctl_table *table)
1899 struct ctl_table_header *header;
1900 struct ctl_table *new, **prevp;
1901 unsigned int n, npath;
1902 struct ctl_table_set *set;
1904 /* Count the path components */
1905 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1909 * For each path component, allocate a 2-element ctl_table array.
1910 * The first array element will be filled with the sysctl entry
1911 * for this, the second will be the sentinel (ctl_name == 0).
1913 * We allocate everything in one go so that we don't have to
1914 * worry about freeing additional memory in unregister_sysctl_table.
1916 header = kzalloc(sizeof(struct ctl_table_header) +
1917 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1921 new = (struct ctl_table *) (header + 1);
1923 /* Now connect the dots */
1924 prevp = &header->ctl_table;
1925 for (n = 0; n < npath; ++n, ++path) {
1926 /* Copy the procname */
1927 new->procname = path->procname;
1928 new->ctl_name = path->ctl_name;
1932 prevp = &new->child;
1937 header->ctl_table_arg = table;
1939 INIT_LIST_HEAD(&header->ctl_entry);
1941 header->unregistering = NULL;
1942 header->root = root;
1943 sysctl_set_parent(NULL, header->ctl_table);
1945 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1946 if (sysctl_check_table(namespaces, header->ctl_table)) {
1951 spin_lock(&sysctl_lock);
1952 header->set = lookup_header_set(root, namespaces);
1953 header->attached_by = header->ctl_table;
1954 header->attached_to = root_table;
1955 header->parent = &root_table_header;
1956 for (set = header->set; set; set = set->parent) {
1957 struct ctl_table_header *p;
1958 list_for_each_entry(p, &set->list, ctl_entry) {
1959 if (p->unregistering)
1961 try_attach(p, header);
1964 header->parent->count++;
1965 list_add_tail(&header->ctl_entry, &header->set->list);
1966 spin_unlock(&sysctl_lock);
1972 * register_sysctl_table_path - register a sysctl table hierarchy
1973 * @path: The path to the directory the sysctl table is in.
1974 * @table: the top-level table structure
1976 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1977 * array. A completely 0 filled entry terminates the table.
1979 * See __register_sysctl_paths for more details.
1981 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1982 struct ctl_table *table)
1984 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1989 * register_sysctl_table - register a sysctl table hierarchy
1990 * @table: the top-level table structure
1992 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1993 * array. A completely 0 filled entry terminates the table.
1995 * See register_sysctl_paths for more details.
1997 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1999 static const struct ctl_path null_path[] = { {} };
2001 return register_sysctl_paths(null_path, table);
2005 * unregister_sysctl_table - unregister a sysctl table hierarchy
2006 * @header: the header returned from register_sysctl_table
2008 * Unregisters the sysctl table and all children. proc entries may not
2009 * actually be removed until they are no longer used by anyone.
2011 void unregister_sysctl_table(struct ctl_table_header * header)
2018 spin_lock(&sysctl_lock);
2019 start_unregistering(header);
2020 if (!--header->parent->count) {
2022 kfree(header->parent);
2024 if (!--header->count)
2026 spin_unlock(&sysctl_lock);
2029 int sysctl_is_seen(struct ctl_table_header *p)
2031 struct ctl_table_set *set = p->set;
2033 spin_lock(&sysctl_lock);
2034 if (p->unregistering)
2036 else if (!set->is_seen)
2039 res = set->is_seen(set);
2040 spin_unlock(&sysctl_lock);
2044 void setup_sysctl_set(struct ctl_table_set *p,
2045 struct ctl_table_set *parent,
2046 int (*is_seen)(struct ctl_table_set *))
2048 INIT_LIST_HEAD(&p->list);
2049 p->parent = parent ? parent : &sysctl_table_root.default_set;
2050 p->is_seen = is_seen;
2053 #else /* !CONFIG_SYSCTL */
2054 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2059 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2060 struct ctl_table *table)
2065 void unregister_sysctl_table(struct ctl_table_header * table)
2069 void setup_sysctl_set(struct ctl_table_set *p,
2070 struct ctl_table_set *parent,
2071 int (*is_seen)(struct ctl_table_set *))
2075 void sysctl_head_put(struct ctl_table_header *head)
2079 #endif /* CONFIG_SYSCTL */
2085 #ifdef CONFIG_PROC_SYSCTL
2087 static int _proc_do_string(void* data, int maxlen, int write,
2088 struct file *filp, void __user *buffer,
2089 size_t *lenp, loff_t *ppos)
2095 if (!data || !maxlen || !*lenp) {
2103 while (len < *lenp) {
2104 if (get_user(c, p++))
2106 if (c == 0 || c == '\n')
2112 if(copy_from_user(data, buffer, len))
2114 ((char *) data)[len] = 0;
2132 if(copy_to_user(buffer, data, len))
2135 if(put_user('\n', ((char __user *) buffer) + len))
2146 * proc_dostring - read a string sysctl
2147 * @table: the sysctl table
2148 * @write: %TRUE if this is a write to the sysctl file
2149 * @filp: the file structure
2150 * @buffer: the user buffer
2151 * @lenp: the size of the user buffer
2152 * @ppos: file position
2154 * Reads/writes a string from/to the user buffer. If the kernel
2155 * buffer provided is not large enough to hold the string, the
2156 * string is truncated. The copied string is %NULL-terminated.
2157 * If the string is being read by the user process, it is copied
2158 * and a newline '\n' is added. It is truncated if the buffer is
2161 * Returns 0 on success.
2163 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2164 void __user *buffer, size_t *lenp, loff_t *ppos)
2166 return _proc_do_string(table->data, table->maxlen, write, filp,
2167 buffer, lenp, ppos);
2171 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2173 int write, void *data)
2176 *valp = *negp ? -*lvalp : *lvalp;
2181 *lvalp = (unsigned long)-val;
2184 *lvalp = (unsigned long)val;
2190 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2191 int write, struct file *filp, void __user *buffer,
2192 size_t *lenp, loff_t *ppos,
2193 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2194 int write, void *data),
2197 #define TMPBUFLEN 21
2198 int *i, vleft, first=1, neg, val;
2202 char buf[TMPBUFLEN], *p;
2203 char __user *s = buffer;
2205 if (!tbl_data || !table->maxlen || !*lenp ||
2206 (*ppos && !write)) {
2211 i = (int *) tbl_data;
2212 vleft = table->maxlen / sizeof(*i);
2216 conv = do_proc_dointvec_conv;
2218 for (; left && vleft--; i++, first=0) {
2233 if (len > sizeof(buf) - 1)
2234 len = sizeof(buf) - 1;
2235 if (copy_from_user(buf, s, len))
2239 if (*p == '-' && left > 1) {
2243 if (*p < '0' || *p > '9')
2246 lval = simple_strtoul(p, &p, 0);
2249 if ((len < left) && *p && !isspace(*p))
2256 if (conv(&neg, &lval, i, 1, data))
2263 if (conv(&neg, &lval, i, 0, data))
2266 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2270 if(copy_to_user(s, buf, len))
2277 if (!write && !first && left) {
2278 if(put_user('\n', s))
2285 if (get_user(c, s++))
2300 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2301 void __user *buffer, size_t *lenp, loff_t *ppos,
2302 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2303 int write, void *data),
2306 return __do_proc_dointvec(table->data, table, write, filp,
2307 buffer, lenp, ppos, conv, data);
2311 * proc_dointvec - read a vector of integers
2312 * @table: the sysctl table
2313 * @write: %TRUE if this is a write to the sysctl file
2314 * @filp: the file structure
2315 * @buffer: the user buffer
2316 * @lenp: the size of the user buffer
2317 * @ppos: file position
2319 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2320 * values from/to the user buffer, treated as an ASCII string.
2322 * Returns 0 on success.
2324 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2325 void __user *buffer, size_t *lenp, loff_t *ppos)
2327 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2332 * Taint values can only be increased
2333 * This means we can safely use a temporary.
2335 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2336 void __user *buffer, size_t *lenp, loff_t *ppos)
2339 unsigned long tmptaint = get_taint();
2342 if (write && !capable(CAP_SYS_ADMIN))
2347 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2353 * Poor man's atomic or. Not worth adding a primitive
2354 * to everyone's atomic.h for this
2357 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2358 if ((tmptaint >> i) & 1)
2366 struct do_proc_dointvec_minmax_conv_param {
2371 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2373 int write, void *data)
2375 struct do_proc_dointvec_minmax_conv_param *param = data;
2377 int val = *negp ? -*lvalp : *lvalp;
2378 if ((param->min && *param->min > val) ||
2379 (param->max && *param->max < val))
2386 *lvalp = (unsigned long)-val;
2389 *lvalp = (unsigned long)val;
2396 * proc_dointvec_minmax - read a vector of integers with min/max values
2397 * @table: the sysctl table
2398 * @write: %TRUE if this is a write to the sysctl file
2399 * @filp: the file structure
2400 * @buffer: the user buffer
2401 * @lenp: the size of the user buffer
2402 * @ppos: file position
2404 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2405 * values from/to the user buffer, treated as an ASCII string.
2407 * This routine will ensure the values are within the range specified by
2408 * table->extra1 (min) and table->extra2 (max).
2410 * Returns 0 on success.
2412 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2413 void __user *buffer, size_t *lenp, loff_t *ppos)
2415 struct do_proc_dointvec_minmax_conv_param param = {
2416 .min = (int *) table->extra1,
2417 .max = (int *) table->extra2,
2419 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2420 do_proc_dointvec_minmax_conv, ¶m);
2423 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2425 void __user *buffer,
2426 size_t *lenp, loff_t *ppos,
2427 unsigned long convmul,
2428 unsigned long convdiv)
2430 #define TMPBUFLEN 21
2431 unsigned long *i, *min, *max, val;
2432 int vleft, first=1, neg;
2434 char buf[TMPBUFLEN], *p;
2435 char __user *s = buffer;
2437 if (!data || !table->maxlen || !*lenp ||
2438 (*ppos && !write)) {
2443 i = (unsigned long *) data;
2444 min = (unsigned long *) table->extra1;
2445 max = (unsigned long *) table->extra2;
2446 vleft = table->maxlen / sizeof(unsigned long);
2449 for (; left && vleft--; i++, min++, max++, first=0) {
2464 if (len > TMPBUFLEN-1)
2466 if (copy_from_user(buf, s, len))
2470 if (*p == '-' && left > 1) {
2474 if (*p < '0' || *p > '9')
2476 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2478 if ((len < left) && *p && !isspace(*p))
2487 if ((min && val < *min) || (max && val > *max))
2494 sprintf(p, "%lu", convdiv * (*i) / convmul);
2498 if(copy_to_user(s, buf, len))
2505 if (!write && !first && left) {
2506 if(put_user('\n', s))
2513 if (get_user(c, s++))
2528 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2530 void __user *buffer,
2531 size_t *lenp, loff_t *ppos,
2532 unsigned long convmul,
2533 unsigned long convdiv)
2535 return __do_proc_doulongvec_minmax(table->data, table, write,
2536 filp, buffer, lenp, ppos, convmul, convdiv);
2540 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2541 * @table: the sysctl table
2542 * @write: %TRUE if this is a write to the sysctl file
2543 * @filp: the file structure
2544 * @buffer: the user buffer
2545 * @lenp: the size of the user buffer
2546 * @ppos: file position
2548 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2549 * values from/to the user buffer, treated as an ASCII string.
2551 * This routine will ensure the values are within the range specified by
2552 * table->extra1 (min) and table->extra2 (max).
2554 * Returns 0 on success.
2556 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2557 void __user *buffer, size_t *lenp, loff_t *ppos)
2559 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2563 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2564 * @table: the sysctl table
2565 * @write: %TRUE if this is a write to the sysctl file
2566 * @filp: the file structure
2567 * @buffer: the user buffer
2568 * @lenp: the size of the user buffer
2569 * @ppos: file position
2571 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2572 * values from/to the user buffer, treated as an ASCII string. The values
2573 * are treated as milliseconds, and converted to jiffies when they are stored.
2575 * This routine will ensure the values are within the range specified by
2576 * table->extra1 (min) and table->extra2 (max).
2578 * Returns 0 on success.
2580 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2582 void __user *buffer,
2583 size_t *lenp, loff_t *ppos)
2585 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2586 lenp, ppos, HZ, 1000l);
2590 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2592 int write, void *data)
2595 if (*lvalp > LONG_MAX / HZ)
2597 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2603 lval = (unsigned long)-val;
2606 lval = (unsigned long)val;
2613 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2615 int write, void *data)
2618 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2620 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2626 lval = (unsigned long)-val;
2629 lval = (unsigned long)val;
2631 *lvalp = jiffies_to_clock_t(lval);
2636 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2638 int write, void *data)
2641 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2647 lval = (unsigned long)-val;
2650 lval = (unsigned long)val;
2652 *lvalp = jiffies_to_msecs(lval);
2658 * proc_dointvec_jiffies - read a vector of integers as seconds
2659 * @table: the sysctl table
2660 * @write: %TRUE if this is a write to the sysctl file
2661 * @filp: the file structure
2662 * @buffer: the user buffer
2663 * @lenp: the size of the user buffer
2664 * @ppos: file position
2666 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2667 * values from/to the user buffer, treated as an ASCII string.
2668 * The values read are assumed to be in seconds, and are converted into
2671 * Returns 0 on success.
2673 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2674 void __user *buffer, size_t *lenp, loff_t *ppos)
2676 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2677 do_proc_dointvec_jiffies_conv,NULL);
2681 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2682 * @table: the sysctl table
2683 * @write: %TRUE if this is a write to the sysctl file
2684 * @filp: the file structure
2685 * @buffer: the user buffer
2686 * @lenp: the size of the user buffer
2687 * @ppos: pointer to the file position
2689 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2690 * values from/to the user buffer, treated as an ASCII string.
2691 * The values read are assumed to be in 1/USER_HZ seconds, and
2692 * are converted into jiffies.
2694 * Returns 0 on success.
2696 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2697 void __user *buffer, size_t *lenp, loff_t *ppos)
2699 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2700 do_proc_dointvec_userhz_jiffies_conv,NULL);
2704 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2705 * @table: the sysctl table
2706 * @write: %TRUE if this is a write to the sysctl file
2707 * @filp: the file structure
2708 * @buffer: the user buffer
2709 * @lenp: the size of the user buffer
2710 * @ppos: file position
2711 * @ppos: the current position in the file
2713 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2714 * values from/to the user buffer, treated as an ASCII string.
2715 * The values read are assumed to be in 1/1000 seconds, and
2716 * are converted into jiffies.
2718 * Returns 0 on success.
2720 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2721 void __user *buffer, size_t *lenp, loff_t *ppos)
2723 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2724 do_proc_dointvec_ms_jiffies_conv, NULL);
2727 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2728 void __user *buffer, size_t *lenp, loff_t *ppos)
2730 struct pid *new_pid;
2734 tmp = pid_vnr(cad_pid);
2736 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2737 lenp, ppos, NULL, NULL);
2741 new_pid = find_get_pid(tmp);
2745 put_pid(xchg(&cad_pid, new_pid));
2749 #else /* CONFIG_PROC_FS */
2751 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2752 void __user *buffer, size_t *lenp, loff_t *ppos)
2757 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2758 void __user *buffer, size_t *lenp, loff_t *ppos)
2763 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2764 void __user *buffer, size_t *lenp, loff_t *ppos)
2769 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2770 void __user *buffer, size_t *lenp, loff_t *ppos)
2775 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2776 void __user *buffer, size_t *lenp, loff_t *ppos)
2781 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2782 void __user *buffer, size_t *lenp, loff_t *ppos)
2787 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2788 void __user *buffer, size_t *lenp, loff_t *ppos)
2793 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2795 void __user *buffer,
2796 size_t *lenp, loff_t *ppos)
2802 #endif /* CONFIG_PROC_FS */
2805 #ifdef CONFIG_SYSCTL_SYSCALL
2807 * General sysctl support routines
2810 /* The generic sysctl data routine (used if no strategy routine supplied) */
2811 int sysctl_data(struct ctl_table *table,
2812 void __user *oldval, size_t __user *oldlenp,
2813 void __user *newval, size_t newlen)
2817 /* Get out of I don't have a variable */
2818 if (!table->data || !table->maxlen)
2821 if (oldval && oldlenp) {
2822 if (get_user(len, oldlenp))
2825 if (len > table->maxlen)
2826 len = table->maxlen;
2827 if (copy_to_user(oldval, table->data, len))
2829 if (put_user(len, oldlenp))
2834 if (newval && newlen) {
2835 if (newlen > table->maxlen)
2836 newlen = table->maxlen;
2838 if (copy_from_user(table->data, newval, newlen))
2844 /* The generic string strategy routine: */
2845 int sysctl_string(struct ctl_table *table,
2846 void __user *oldval, size_t __user *oldlenp,
2847 void __user *newval, size_t newlen)
2849 if (!table->data || !table->maxlen)
2852 if (oldval && oldlenp) {
2854 if (get_user(bufsize, oldlenp))
2857 size_t len = strlen(table->data), copied;
2859 /* This shouldn't trigger for a well-formed sysctl */
2860 if (len > table->maxlen)
2861 len = table->maxlen;
2863 /* Copy up to a max of bufsize-1 bytes of the string */
2864 copied = (len >= bufsize) ? bufsize - 1 : len;
2866 if (copy_to_user(oldval, table->data, copied) ||
2867 put_user(0, (char __user *)(oldval + copied)))
2869 if (put_user(len, oldlenp))
2873 if (newval && newlen) {
2874 size_t len = newlen;
2875 if (len > table->maxlen)
2876 len = table->maxlen;
2877 if(copy_from_user(table->data, newval, len))
2879 if (len == table->maxlen)
2881 ((char *) table->data)[len] = 0;
2887 * This function makes sure that all of the integers in the vector
2888 * are between the minimum and maximum values given in the arrays
2889 * table->extra1 and table->extra2, respectively.
2891 int sysctl_intvec(struct ctl_table *table,
2892 void __user *oldval, size_t __user *oldlenp,
2893 void __user *newval, size_t newlen)
2896 if (newval && newlen) {
2897 int __user *vec = (int __user *) newval;
2898 int *min = (int *) table->extra1;
2899 int *max = (int *) table->extra2;
2903 if (newlen % sizeof(int) != 0)
2906 if (!table->extra1 && !table->extra2)
2909 if (newlen > table->maxlen)
2910 newlen = table->maxlen;
2911 length = newlen / sizeof(int);
2913 for (i = 0; i < length; i++) {
2915 if (get_user(value, vec + i))
2917 if (min && value < min[i])
2919 if (max && value > max[i])
2926 /* Strategy function to convert jiffies to seconds */
2927 int sysctl_jiffies(struct ctl_table *table,
2928 void __user *oldval, size_t __user *oldlenp,
2929 void __user *newval, size_t newlen)
2931 if (oldval && oldlenp) {
2934 if (get_user(olen, oldlenp))
2939 if (olen < sizeof(int))
2942 val = *(int *)(table->data) / HZ;
2943 if (put_user(val, (int __user *)oldval))
2945 if (put_user(sizeof(int), oldlenp))
2949 if (newval && newlen) {
2951 if (newlen != sizeof(int))
2953 if (get_user(new, (int __user *)newval))
2955 *(int *)(table->data) = new*HZ;
2960 /* Strategy function to convert jiffies to seconds */
2961 int sysctl_ms_jiffies(struct ctl_table *table,
2962 void __user *oldval, size_t __user *oldlenp,
2963 void __user *newval, size_t newlen)
2965 if (oldval && oldlenp) {
2968 if (get_user(olen, oldlenp))
2973 if (olen < sizeof(int))
2976 val = jiffies_to_msecs(*(int *)(table->data));
2977 if (put_user(val, (int __user *)oldval))
2979 if (put_user(sizeof(int), oldlenp))
2983 if (newval && newlen) {
2985 if (newlen != sizeof(int))
2987 if (get_user(new, (int __user *)newval))
2989 *(int *)(table->data) = msecs_to_jiffies(new);
2996 #else /* CONFIG_SYSCTL_SYSCALL */
2999 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3001 struct __sysctl_args tmp;
3004 if (copy_from_user(&tmp, args, sizeof(tmp)))
3007 error = deprecated_sysctl_warning(&tmp);
3009 /* If no error reading the parameters then just -ENOSYS ... */
3016 int sysctl_data(struct ctl_table *table,
3017 void __user *oldval, size_t __user *oldlenp,
3018 void __user *newval, size_t newlen)
3023 int sysctl_string(struct ctl_table *table,
3024 void __user *oldval, size_t __user *oldlenp,
3025 void __user *newval, size_t newlen)
3030 int sysctl_intvec(struct ctl_table *table,
3031 void __user *oldval, size_t __user *oldlenp,
3032 void __user *newval, size_t newlen)
3037 int sysctl_jiffies(struct ctl_table *table,
3038 void __user *oldval, size_t __user *oldlenp,
3039 void __user *newval, size_t newlen)
3044 int sysctl_ms_jiffies(struct ctl_table *table,
3045 void __user *oldval, size_t __user *oldlenp,
3046 void __user *newval, size_t newlen)
3051 #endif /* CONFIG_SYSCTL_SYSCALL */
3053 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3055 static int msg_count;
3056 int name[CTL_MAXNAME];
3059 /* Check args->nlen. */
3060 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3063 /* Read in the sysctl name for better debug message logging */
3064 for (i = 0; i < args->nlen; i++)
3065 if (get_user(name[i], args->name + i))
3068 /* Ignore accesses to kernel.version */
3069 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3072 if (msg_count < 5) {
3075 "warning: process `%s' used the deprecated sysctl "
3076 "system call with ", current->comm);
3077 for (i = 0; i < args->nlen; i++)
3078 printk("%d.", name[i]);
3085 * No sense putting this after each symbol definition, twice,
3086 * exception granted :-)
3088 EXPORT_SYMBOL(proc_dointvec);
3089 EXPORT_SYMBOL(proc_dointvec_jiffies);
3090 EXPORT_SYMBOL(proc_dointvec_minmax);
3091 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3092 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3093 EXPORT_SYMBOL(proc_dostring);
3094 EXPORT_SYMBOL(proc_doulongvec_minmax);
3095 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3096 EXPORT_SYMBOL(register_sysctl_table);
3097 EXPORT_SYMBOL(register_sysctl_paths);
3098 EXPORT_SYMBOL(sysctl_intvec);
3099 EXPORT_SYMBOL(sysctl_jiffies);
3100 EXPORT_SYMBOL(sysctl_ms_jiffies);
3101 EXPORT_SYMBOL(sysctl_string);
3102 EXPORT_SYMBOL(sysctl_data);
3103 EXPORT_SYMBOL(unregister_sysctl_table);