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/kmemcheck.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
52 #include <linux/perf_event.h>
54 #include <asm/uaccess.h>
55 #include <asm/processor.h>
59 #include <asm/stacktrace.h>
63 static int deprecated_sysctl_warning(struct __sysctl_args *args);
65 #if defined(CONFIG_SYSCTL)
67 /* External variables not in a header file. */
69 extern int print_fatal_signals;
70 extern int sysctl_overcommit_memory;
71 extern int sysctl_overcommit_ratio;
72 extern int sysctl_panic_on_oom;
73 extern int sysctl_oom_kill_allocating_task;
74 extern int sysctl_oom_dump_tasks;
75 extern int max_threads;
76 extern int core_uses_pid;
77 extern int suid_dumpable;
78 extern char core_pattern[];
80 extern int min_free_kbytes;
81 extern int pid_max_min, pid_max_max;
82 extern int sysctl_drop_caches;
83 extern int percpu_pagelist_fraction;
84 extern int compat_log;
85 extern int latencytop_enabled;
86 extern int sysctl_nr_open_min, sysctl_nr_open_max;
88 extern int sysctl_nr_trim_pages;
90 #ifdef CONFIG_RCU_TORTURE_TEST
91 extern int rcutorture_runnable;
92 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
94 extern int blk_iopoll_enabled;
97 /* Constants used for minimum and maximum */
98 #ifdef CONFIG_DETECT_SOFTLOCKUP
99 static int sixty = 60;
100 static int neg_one = -1;
104 static int __maybe_unused one = 1;
105 static int __maybe_unused two = 2;
106 static unsigned long one_ul = 1;
107 static int one_hundred = 100;
109 static int ten_thousand = 10000;
112 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
113 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
115 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
116 static int maxolduid = 65535;
117 static int minolduid;
118 static int min_percpu_pagelist_fract = 8;
120 static int ngroups_max = NGROUPS_MAX;
122 #ifdef CONFIG_MODULES
123 extern char modprobe_path[];
124 extern int modules_disabled;
126 #ifdef CONFIG_CHR_DEV_SG
127 extern int sg_big_buff;
131 #include <asm/system.h>
134 #ifdef CONFIG_SPARC64
135 extern int sysctl_tsb_ratio;
139 extern int pwrsw_enabled;
140 extern int unaligned_enabled;
144 #ifdef CONFIG_MATHEMU
145 extern int sysctl_ieee_emulation_warnings;
147 extern int sysctl_userprocess_debug;
148 extern int spin_retry;
151 #ifdef CONFIG_BSD_PROCESS_ACCT
152 extern int acct_parm[];
156 extern int no_unaligned_warning;
157 extern int unaligned_dump_stack;
160 #ifdef CONFIG_RT_MUTEXES
161 extern int max_lock_depth;
164 #ifdef CONFIG_PROC_SYSCTL
165 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
166 void __user *buffer, size_t *lenp, loff_t *ppos);
167 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
171 static struct ctl_table root_table[];
172 static struct ctl_table_root sysctl_table_root;
173 static struct ctl_table_header root_table_header = {
175 .ctl_table = root_table,
176 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
177 .root = &sysctl_table_root,
178 .set = &sysctl_table_root.default_set,
180 static struct ctl_table_root sysctl_table_root = {
181 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
182 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
185 static struct ctl_table kern_table[];
186 static struct ctl_table vm_table[];
187 static struct ctl_table fs_table[];
188 static struct ctl_table debug_table[];
189 static struct ctl_table dev_table[];
190 extern struct ctl_table random_table[];
191 #ifdef CONFIG_INOTIFY_USER
192 extern struct ctl_table inotify_table[];
195 extern struct ctl_table epoll_table[];
198 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
199 int sysctl_legacy_va_layout;
202 extern int prove_locking;
203 extern int lock_stat;
205 /* The default sysctl tables: */
207 static struct ctl_table root_table[] = {
209 .ctl_name = CTL_KERN,
210 .procname = "kernel",
227 .ctl_name = CTL_DEBUG,
230 .child = debug_table,
239 * NOTE: do not add new entries to this table unless you have read
240 * Documentation/sysctl/ctl_unnumbered.txt
245 #ifdef CONFIG_SCHED_DEBUG
246 static int min_sched_granularity_ns = 100000; /* 100 usecs */
247 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
248 static int min_wakeup_granularity_ns; /* 0 usecs */
249 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
252 static struct ctl_table kern_table[] = {
254 .ctl_name = CTL_UNNUMBERED,
255 .procname = "sched_child_runs_first",
256 .data = &sysctl_sched_child_runs_first,
257 .maxlen = sizeof(unsigned int),
259 .proc_handler = &proc_dointvec,
261 #ifdef CONFIG_SCHED_DEBUG
263 .ctl_name = CTL_UNNUMBERED,
264 .procname = "sched_min_granularity_ns",
265 .data = &sysctl_sched_min_granularity,
266 .maxlen = sizeof(unsigned int),
268 .proc_handler = &sched_nr_latency_handler,
269 .strategy = &sysctl_intvec,
270 .extra1 = &min_sched_granularity_ns,
271 .extra2 = &max_sched_granularity_ns,
274 .ctl_name = CTL_UNNUMBERED,
275 .procname = "sched_latency_ns",
276 .data = &sysctl_sched_latency,
277 .maxlen = sizeof(unsigned int),
279 .proc_handler = &sched_nr_latency_handler,
280 .strategy = &sysctl_intvec,
281 .extra1 = &min_sched_granularity_ns,
282 .extra2 = &max_sched_granularity_ns,
285 .ctl_name = CTL_UNNUMBERED,
286 .procname = "sched_wakeup_granularity_ns",
287 .data = &sysctl_sched_wakeup_granularity,
288 .maxlen = sizeof(unsigned int),
290 .proc_handler = &proc_dointvec_minmax,
291 .strategy = &sysctl_intvec,
292 .extra1 = &min_wakeup_granularity_ns,
293 .extra2 = &max_wakeup_granularity_ns,
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_shares_ratelimit",
298 .data = &sysctl_sched_shares_ratelimit,
299 .maxlen = sizeof(unsigned int),
301 .proc_handler = &proc_dointvec,
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_shares_thresh",
306 .data = &sysctl_sched_shares_thresh,
307 .maxlen = sizeof(unsigned int),
309 .proc_handler = &proc_dointvec_minmax,
310 .strategy = &sysctl_intvec,
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_features",
316 .data = &sysctl_sched_features,
317 .maxlen = sizeof(unsigned int),
319 .proc_handler = &proc_dointvec,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_migration_cost",
324 .data = &sysctl_sched_migration_cost,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = &proc_dointvec,
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "sched_nr_migrate",
332 .data = &sysctl_sched_nr_migrate,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = &proc_dointvec,
338 .ctl_name = CTL_UNNUMBERED,
339 .procname = "sched_time_avg",
340 .data = &sysctl_sched_time_avg,
341 .maxlen = sizeof(unsigned int),
343 .proc_handler = &proc_dointvec,
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "timer_migration",
348 .data = &sysctl_timer_migration,
349 .maxlen = sizeof(unsigned int),
351 .proc_handler = &proc_dointvec_minmax,
352 .strategy = &sysctl_intvec,
358 .ctl_name = CTL_UNNUMBERED,
359 .procname = "sched_rt_period_us",
360 .data = &sysctl_sched_rt_period,
361 .maxlen = sizeof(unsigned int),
363 .proc_handler = &sched_rt_handler,
366 .ctl_name = CTL_UNNUMBERED,
367 .procname = "sched_rt_runtime_us",
368 .data = &sysctl_sched_rt_runtime,
369 .maxlen = sizeof(int),
371 .proc_handler = &sched_rt_handler,
374 .ctl_name = CTL_UNNUMBERED,
375 .procname = "sched_compat_yield",
376 .data = &sysctl_sched_compat_yield,
377 .maxlen = sizeof(unsigned int),
379 .proc_handler = &proc_dointvec,
381 #ifdef CONFIG_PROVE_LOCKING
383 .ctl_name = CTL_UNNUMBERED,
384 .procname = "prove_locking",
385 .data = &prove_locking,
386 .maxlen = sizeof(int),
388 .proc_handler = &proc_dointvec,
391 #ifdef CONFIG_LOCK_STAT
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "lock_stat",
396 .maxlen = sizeof(int),
398 .proc_handler = &proc_dointvec,
402 .ctl_name = KERN_PANIC,
404 .data = &panic_timeout,
405 .maxlen = sizeof(int),
407 .proc_handler = &proc_dointvec,
410 .ctl_name = KERN_CORE_USES_PID,
411 .procname = "core_uses_pid",
412 .data = &core_uses_pid,
413 .maxlen = sizeof(int),
415 .proc_handler = &proc_dointvec,
418 .ctl_name = KERN_CORE_PATTERN,
419 .procname = "core_pattern",
420 .data = core_pattern,
421 .maxlen = CORENAME_MAX_SIZE,
423 .proc_handler = &proc_dostring,
424 .strategy = &sysctl_string,
426 #ifdef CONFIG_PROC_SYSCTL
428 .procname = "tainted",
429 .maxlen = sizeof(long),
431 .proc_handler = &proc_taint,
434 #ifdef CONFIG_LATENCYTOP
436 .procname = "latencytop",
437 .data = &latencytop_enabled,
438 .maxlen = sizeof(int),
440 .proc_handler = &proc_dointvec,
443 #ifdef CONFIG_BLK_DEV_INITRD
445 .ctl_name = KERN_REALROOTDEV,
446 .procname = "real-root-dev",
447 .data = &real_root_dev,
448 .maxlen = sizeof(int),
450 .proc_handler = &proc_dointvec,
454 .ctl_name = CTL_UNNUMBERED,
455 .procname = "print-fatal-signals",
456 .data = &print_fatal_signals,
457 .maxlen = sizeof(int),
459 .proc_handler = &proc_dointvec,
463 .ctl_name = KERN_SPARC_REBOOT,
464 .procname = "reboot-cmd",
465 .data = reboot_command,
468 .proc_handler = &proc_dostring,
469 .strategy = &sysctl_string,
472 .ctl_name = KERN_SPARC_STOP_A,
473 .procname = "stop-a",
474 .data = &stop_a_enabled,
475 .maxlen = sizeof (int),
477 .proc_handler = &proc_dointvec,
480 .ctl_name = KERN_SPARC_SCONS_PWROFF,
481 .procname = "scons-poweroff",
482 .data = &scons_pwroff,
483 .maxlen = sizeof (int),
485 .proc_handler = &proc_dointvec,
488 #ifdef CONFIG_SPARC64
490 .ctl_name = CTL_UNNUMBERED,
491 .procname = "tsb-ratio",
492 .data = &sysctl_tsb_ratio,
493 .maxlen = sizeof (int),
495 .proc_handler = &proc_dointvec,
500 .ctl_name = KERN_HPPA_PWRSW,
501 .procname = "soft-power",
502 .data = &pwrsw_enabled,
503 .maxlen = sizeof (int),
505 .proc_handler = &proc_dointvec,
508 .ctl_name = KERN_HPPA_UNALIGNED,
509 .procname = "unaligned-trap",
510 .data = &unaligned_enabled,
511 .maxlen = sizeof (int),
513 .proc_handler = &proc_dointvec,
517 .ctl_name = KERN_CTLALTDEL,
518 .procname = "ctrl-alt-del",
520 .maxlen = sizeof(int),
522 .proc_handler = &proc_dointvec,
524 #ifdef CONFIG_FUNCTION_TRACER
526 .ctl_name = CTL_UNNUMBERED,
527 .procname = "ftrace_enabled",
528 .data = &ftrace_enabled,
529 .maxlen = sizeof(int),
531 .proc_handler = &ftrace_enable_sysctl,
534 #ifdef CONFIG_STACK_TRACER
536 .ctl_name = CTL_UNNUMBERED,
537 .procname = "stack_tracer_enabled",
538 .data = &stack_tracer_enabled,
539 .maxlen = sizeof(int),
541 .proc_handler = &stack_trace_sysctl,
544 #ifdef CONFIG_TRACING
546 .ctl_name = CTL_UNNUMBERED,
547 .procname = "ftrace_dump_on_oops",
548 .data = &ftrace_dump_on_oops,
549 .maxlen = sizeof(int),
551 .proc_handler = &proc_dointvec,
554 #ifdef CONFIG_MODULES
556 .ctl_name = KERN_MODPROBE,
557 .procname = "modprobe",
558 .data = &modprobe_path,
559 .maxlen = KMOD_PATH_LEN,
561 .proc_handler = &proc_dostring,
562 .strategy = &sysctl_string,
565 .ctl_name = CTL_UNNUMBERED,
566 .procname = "modules_disabled",
567 .data = &modules_disabled,
568 .maxlen = sizeof(int),
570 /* only handle a transition from default "0" to "1" */
571 .proc_handler = &proc_dointvec_minmax,
576 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
578 .ctl_name = KERN_HOTPLUG,
579 .procname = "hotplug",
580 .data = &uevent_helper,
581 .maxlen = UEVENT_HELPER_PATH_LEN,
583 .proc_handler = &proc_dostring,
584 .strategy = &sysctl_string,
587 #ifdef CONFIG_CHR_DEV_SG
589 .ctl_name = KERN_SG_BIG_BUFF,
590 .procname = "sg-big-buff",
591 .data = &sg_big_buff,
592 .maxlen = sizeof (int),
594 .proc_handler = &proc_dointvec,
597 #ifdef CONFIG_BSD_PROCESS_ACCT
599 .ctl_name = KERN_ACCT,
602 .maxlen = 3*sizeof(int),
604 .proc_handler = &proc_dointvec,
607 #ifdef CONFIG_MAGIC_SYSRQ
609 .ctl_name = KERN_SYSRQ,
611 .data = &__sysrq_enabled,
612 .maxlen = sizeof (int),
614 .proc_handler = &proc_dointvec,
617 #ifdef CONFIG_PROC_SYSCTL
619 .procname = "cad_pid",
621 .maxlen = sizeof (int),
623 .proc_handler = &proc_do_cad_pid,
627 .ctl_name = KERN_MAX_THREADS,
628 .procname = "threads-max",
629 .data = &max_threads,
630 .maxlen = sizeof(int),
632 .proc_handler = &proc_dointvec,
635 .ctl_name = KERN_RANDOM,
636 .procname = "random",
638 .child = random_table,
641 .ctl_name = KERN_OVERFLOWUID,
642 .procname = "overflowuid",
643 .data = &overflowuid,
644 .maxlen = sizeof(int),
646 .proc_handler = &proc_dointvec_minmax,
647 .strategy = &sysctl_intvec,
648 .extra1 = &minolduid,
649 .extra2 = &maxolduid,
652 .ctl_name = KERN_OVERFLOWGID,
653 .procname = "overflowgid",
654 .data = &overflowgid,
655 .maxlen = sizeof(int),
657 .proc_handler = &proc_dointvec_minmax,
658 .strategy = &sysctl_intvec,
659 .extra1 = &minolduid,
660 .extra2 = &maxolduid,
663 #ifdef CONFIG_MATHEMU
665 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
666 .procname = "ieee_emulation_warnings",
667 .data = &sysctl_ieee_emulation_warnings,
668 .maxlen = sizeof(int),
670 .proc_handler = &proc_dointvec,
674 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
675 .procname = "userprocess_debug",
676 .data = &sysctl_userprocess_debug,
677 .maxlen = sizeof(int),
679 .proc_handler = &proc_dointvec,
683 .ctl_name = KERN_PIDMAX,
684 .procname = "pid_max",
686 .maxlen = sizeof (int),
688 .proc_handler = &proc_dointvec_minmax,
689 .strategy = sysctl_intvec,
690 .extra1 = &pid_max_min,
691 .extra2 = &pid_max_max,
694 .ctl_name = KERN_PANIC_ON_OOPS,
695 .procname = "panic_on_oops",
696 .data = &panic_on_oops,
697 .maxlen = sizeof(int),
699 .proc_handler = &proc_dointvec,
701 #if defined CONFIG_PRINTK
703 .ctl_name = KERN_PRINTK,
704 .procname = "printk",
705 .data = &console_loglevel,
706 .maxlen = 4*sizeof(int),
708 .proc_handler = &proc_dointvec,
711 .ctl_name = KERN_PRINTK_RATELIMIT,
712 .procname = "printk_ratelimit",
713 .data = &printk_ratelimit_state.interval,
714 .maxlen = sizeof(int),
716 .proc_handler = &proc_dointvec_jiffies,
717 .strategy = &sysctl_jiffies,
720 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
721 .procname = "printk_ratelimit_burst",
722 .data = &printk_ratelimit_state.burst,
723 .maxlen = sizeof(int),
725 .proc_handler = &proc_dointvec,
728 .ctl_name = CTL_UNNUMBERED,
729 .procname = "printk_delay",
730 .data = &printk_delay_msec,
731 .maxlen = sizeof(int),
733 .proc_handler = &proc_dointvec_minmax,
734 .strategy = &sysctl_intvec,
736 .extra2 = &ten_thousand,
740 .ctl_name = KERN_NGROUPS_MAX,
741 .procname = "ngroups_max",
742 .data = &ngroups_max,
743 .maxlen = sizeof (int),
745 .proc_handler = &proc_dointvec,
747 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
749 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
750 .procname = "unknown_nmi_panic",
751 .data = &unknown_nmi_panic,
752 .maxlen = sizeof (int),
754 .proc_handler = &proc_dointvec,
757 .procname = "nmi_watchdog",
758 .data = &nmi_watchdog_enabled,
759 .maxlen = sizeof (int),
761 .proc_handler = &proc_nmi_enabled,
764 #if defined(CONFIG_X86)
766 .ctl_name = KERN_PANIC_ON_NMI,
767 .procname = "panic_on_unrecovered_nmi",
768 .data = &panic_on_unrecovered_nmi,
769 .maxlen = sizeof(int),
771 .proc_handler = &proc_dointvec,
774 .ctl_name = CTL_UNNUMBERED,
775 .procname = "panic_on_io_nmi",
776 .data = &panic_on_io_nmi,
777 .maxlen = sizeof(int),
779 .proc_handler = &proc_dointvec,
782 .ctl_name = KERN_BOOTLOADER_TYPE,
783 .procname = "bootloader_type",
784 .data = &bootloader_type,
785 .maxlen = sizeof (int),
787 .proc_handler = &proc_dointvec,
790 .ctl_name = CTL_UNNUMBERED,
791 .procname = "bootloader_version",
792 .data = &bootloader_version,
793 .maxlen = sizeof (int),
795 .proc_handler = &proc_dointvec,
798 .ctl_name = CTL_UNNUMBERED,
799 .procname = "kstack_depth_to_print",
800 .data = &kstack_depth_to_print,
801 .maxlen = sizeof(int),
803 .proc_handler = &proc_dointvec,
806 .ctl_name = CTL_UNNUMBERED,
807 .procname = "io_delay_type",
808 .data = &io_delay_type,
809 .maxlen = sizeof(int),
811 .proc_handler = &proc_dointvec,
814 #if defined(CONFIG_MMU)
816 .ctl_name = KERN_RANDOMIZE,
817 .procname = "randomize_va_space",
818 .data = &randomize_va_space,
819 .maxlen = sizeof(int),
821 .proc_handler = &proc_dointvec,
824 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
826 .ctl_name = KERN_SPIN_RETRY,
827 .procname = "spin_retry",
829 .maxlen = sizeof (int),
831 .proc_handler = &proc_dointvec,
834 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
836 .procname = "acpi_video_flags",
837 .data = &acpi_realmode_flags,
838 .maxlen = sizeof (unsigned long),
840 .proc_handler = &proc_doulongvec_minmax,
845 .ctl_name = KERN_IA64_UNALIGNED,
846 .procname = "ignore-unaligned-usertrap",
847 .data = &no_unaligned_warning,
848 .maxlen = sizeof (int),
850 .proc_handler = &proc_dointvec,
853 .ctl_name = CTL_UNNUMBERED,
854 .procname = "unaligned-dump-stack",
855 .data = &unaligned_dump_stack,
856 .maxlen = sizeof (int),
858 .proc_handler = &proc_dointvec,
861 #ifdef CONFIG_DETECT_SOFTLOCKUP
863 .ctl_name = CTL_UNNUMBERED,
864 .procname = "softlockup_panic",
865 .data = &softlockup_panic,
866 .maxlen = sizeof(int),
868 .proc_handler = &proc_dointvec_minmax,
869 .strategy = &sysctl_intvec,
874 .ctl_name = CTL_UNNUMBERED,
875 .procname = "softlockup_thresh",
876 .data = &softlockup_thresh,
877 .maxlen = sizeof(int),
879 .proc_handler = &proc_dosoftlockup_thresh,
880 .strategy = &sysctl_intvec,
885 #ifdef CONFIG_DETECT_HUNG_TASK
887 .ctl_name = CTL_UNNUMBERED,
888 .procname = "hung_task_panic",
889 .data = &sysctl_hung_task_panic,
890 .maxlen = sizeof(int),
892 .proc_handler = &proc_dointvec_minmax,
893 .strategy = &sysctl_intvec,
898 .ctl_name = CTL_UNNUMBERED,
899 .procname = "hung_task_check_count",
900 .data = &sysctl_hung_task_check_count,
901 .maxlen = sizeof(unsigned long),
903 .proc_handler = &proc_doulongvec_minmax,
904 .strategy = &sysctl_intvec,
907 .ctl_name = CTL_UNNUMBERED,
908 .procname = "hung_task_timeout_secs",
909 .data = &sysctl_hung_task_timeout_secs,
910 .maxlen = sizeof(unsigned long),
912 .proc_handler = &proc_dohung_task_timeout_secs,
913 .strategy = &sysctl_intvec,
916 .ctl_name = CTL_UNNUMBERED,
917 .procname = "hung_task_warnings",
918 .data = &sysctl_hung_task_warnings,
919 .maxlen = sizeof(unsigned long),
921 .proc_handler = &proc_doulongvec_minmax,
922 .strategy = &sysctl_intvec,
927 .ctl_name = KERN_COMPAT_LOG,
928 .procname = "compat-log",
930 .maxlen = sizeof (int),
932 .proc_handler = &proc_dointvec,
935 #ifdef CONFIG_RT_MUTEXES
937 .ctl_name = KERN_MAX_LOCK_DEPTH,
938 .procname = "max_lock_depth",
939 .data = &max_lock_depth,
940 .maxlen = sizeof(int),
942 .proc_handler = &proc_dointvec,
946 .ctl_name = CTL_UNNUMBERED,
947 .procname = "poweroff_cmd",
948 .data = &poweroff_cmd,
949 .maxlen = POWEROFF_CMD_PATH_LEN,
951 .proc_handler = &proc_dostring,
952 .strategy = &sysctl_string,
956 .ctl_name = CTL_UNNUMBERED,
959 .child = key_sysctls,
962 #ifdef CONFIG_RCU_TORTURE_TEST
964 .ctl_name = CTL_UNNUMBERED,
965 .procname = "rcutorture_runnable",
966 .data = &rcutorture_runnable,
967 .maxlen = sizeof(int),
969 .proc_handler = &proc_dointvec,
972 #ifdef CONFIG_SLOW_WORK
974 .ctl_name = CTL_UNNUMBERED,
975 .procname = "slow-work",
977 .child = slow_work_sysctls,
980 #ifdef CONFIG_PERF_EVENTS
982 .ctl_name = CTL_UNNUMBERED,
983 .procname = "perf_event_paranoid",
984 .data = &sysctl_perf_event_paranoid,
985 .maxlen = sizeof(sysctl_perf_event_paranoid),
987 .proc_handler = &proc_dointvec,
990 .ctl_name = CTL_UNNUMBERED,
991 .procname = "perf_event_mlock_kb",
992 .data = &sysctl_perf_event_mlock,
993 .maxlen = sizeof(sysctl_perf_event_mlock),
995 .proc_handler = &proc_dointvec,
998 .ctl_name = CTL_UNNUMBERED,
999 .procname = "perf_event_max_sample_rate",
1000 .data = &sysctl_perf_event_sample_rate,
1001 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1003 .proc_handler = &proc_dointvec,
1006 #ifdef CONFIG_KMEMCHECK
1008 .ctl_name = CTL_UNNUMBERED,
1009 .procname = "kmemcheck",
1010 .data = &kmemcheck_enabled,
1011 .maxlen = sizeof(int),
1013 .proc_handler = &proc_dointvec,
1018 .ctl_name = CTL_UNNUMBERED,
1019 .procname = "blk_iopoll",
1020 .data = &blk_iopoll_enabled,
1021 .maxlen = sizeof(int),
1023 .proc_handler = &proc_dointvec,
1027 * NOTE: do not add new entries to this table unless you have read
1028 * Documentation/sysctl/ctl_unnumbered.txt
1033 static struct ctl_table vm_table[] = {
1035 .ctl_name = VM_OVERCOMMIT_MEMORY,
1036 .procname = "overcommit_memory",
1037 .data = &sysctl_overcommit_memory,
1038 .maxlen = sizeof(sysctl_overcommit_memory),
1040 .proc_handler = &proc_dointvec,
1043 .ctl_name = VM_PANIC_ON_OOM,
1044 .procname = "panic_on_oom",
1045 .data = &sysctl_panic_on_oom,
1046 .maxlen = sizeof(sysctl_panic_on_oom),
1048 .proc_handler = &proc_dointvec,
1051 .ctl_name = CTL_UNNUMBERED,
1052 .procname = "oom_kill_allocating_task",
1053 .data = &sysctl_oom_kill_allocating_task,
1054 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1056 .proc_handler = &proc_dointvec,
1059 .ctl_name = CTL_UNNUMBERED,
1060 .procname = "oom_dump_tasks",
1061 .data = &sysctl_oom_dump_tasks,
1062 .maxlen = sizeof(sysctl_oom_dump_tasks),
1064 .proc_handler = &proc_dointvec,
1067 .ctl_name = VM_OVERCOMMIT_RATIO,
1068 .procname = "overcommit_ratio",
1069 .data = &sysctl_overcommit_ratio,
1070 .maxlen = sizeof(sysctl_overcommit_ratio),
1072 .proc_handler = &proc_dointvec,
1075 .ctl_name = VM_PAGE_CLUSTER,
1076 .procname = "page-cluster",
1077 .data = &page_cluster,
1078 .maxlen = sizeof(int),
1080 .proc_handler = &proc_dointvec,
1083 .ctl_name = VM_DIRTY_BACKGROUND,
1084 .procname = "dirty_background_ratio",
1085 .data = &dirty_background_ratio,
1086 .maxlen = sizeof(dirty_background_ratio),
1088 .proc_handler = &dirty_background_ratio_handler,
1089 .strategy = &sysctl_intvec,
1091 .extra2 = &one_hundred,
1094 .ctl_name = CTL_UNNUMBERED,
1095 .procname = "dirty_background_bytes",
1096 .data = &dirty_background_bytes,
1097 .maxlen = sizeof(dirty_background_bytes),
1099 .proc_handler = &dirty_background_bytes_handler,
1100 .strategy = &sysctl_intvec,
1104 .ctl_name = VM_DIRTY_RATIO,
1105 .procname = "dirty_ratio",
1106 .data = &vm_dirty_ratio,
1107 .maxlen = sizeof(vm_dirty_ratio),
1109 .proc_handler = &dirty_ratio_handler,
1110 .strategy = &sysctl_intvec,
1112 .extra2 = &one_hundred,
1115 .ctl_name = CTL_UNNUMBERED,
1116 .procname = "dirty_bytes",
1117 .data = &vm_dirty_bytes,
1118 .maxlen = sizeof(vm_dirty_bytes),
1120 .proc_handler = &dirty_bytes_handler,
1121 .strategy = &sysctl_intvec,
1122 .extra1 = &dirty_bytes_min,
1125 .procname = "dirty_writeback_centisecs",
1126 .data = &dirty_writeback_interval,
1127 .maxlen = sizeof(dirty_writeback_interval),
1129 .proc_handler = &dirty_writeback_centisecs_handler,
1132 .procname = "dirty_expire_centisecs",
1133 .data = &dirty_expire_interval,
1134 .maxlen = sizeof(dirty_expire_interval),
1136 .proc_handler = &proc_dointvec,
1139 .ctl_name = VM_NR_PDFLUSH_THREADS,
1140 .procname = "nr_pdflush_threads",
1141 .data = &nr_pdflush_threads,
1142 .maxlen = sizeof nr_pdflush_threads,
1143 .mode = 0444 /* read-only*/,
1144 .proc_handler = &proc_dointvec,
1147 .ctl_name = VM_SWAPPINESS,
1148 .procname = "swappiness",
1149 .data = &vm_swappiness,
1150 .maxlen = sizeof(vm_swappiness),
1152 .proc_handler = &proc_dointvec_minmax,
1153 .strategy = &sysctl_intvec,
1155 .extra2 = &one_hundred,
1157 #ifdef CONFIG_HUGETLB_PAGE
1159 .procname = "nr_hugepages",
1161 .maxlen = sizeof(unsigned long),
1163 .proc_handler = &hugetlb_sysctl_handler,
1164 .extra1 = (void *)&hugetlb_zero,
1165 .extra2 = (void *)&hugetlb_infinity,
1168 .ctl_name = VM_HUGETLB_GROUP,
1169 .procname = "hugetlb_shm_group",
1170 .data = &sysctl_hugetlb_shm_group,
1171 .maxlen = sizeof(gid_t),
1173 .proc_handler = &proc_dointvec,
1176 .ctl_name = CTL_UNNUMBERED,
1177 .procname = "hugepages_treat_as_movable",
1178 .data = &hugepages_treat_as_movable,
1179 .maxlen = sizeof(int),
1181 .proc_handler = &hugetlb_treat_movable_handler,
1184 .ctl_name = CTL_UNNUMBERED,
1185 .procname = "nr_overcommit_hugepages",
1187 .maxlen = sizeof(unsigned long),
1189 .proc_handler = &hugetlb_overcommit_handler,
1190 .extra1 = (void *)&hugetlb_zero,
1191 .extra2 = (void *)&hugetlb_infinity,
1195 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1196 .procname = "lowmem_reserve_ratio",
1197 .data = &sysctl_lowmem_reserve_ratio,
1198 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1200 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1201 .strategy = &sysctl_intvec,
1204 .ctl_name = VM_DROP_PAGECACHE,
1205 .procname = "drop_caches",
1206 .data = &sysctl_drop_caches,
1207 .maxlen = sizeof(int),
1209 .proc_handler = drop_caches_sysctl_handler,
1210 .strategy = &sysctl_intvec,
1213 .ctl_name = VM_MIN_FREE_KBYTES,
1214 .procname = "min_free_kbytes",
1215 .data = &min_free_kbytes,
1216 .maxlen = sizeof(min_free_kbytes),
1218 .proc_handler = &min_free_kbytes_sysctl_handler,
1219 .strategy = &sysctl_intvec,
1223 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1224 .procname = "percpu_pagelist_fraction",
1225 .data = &percpu_pagelist_fraction,
1226 .maxlen = sizeof(percpu_pagelist_fraction),
1228 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1229 .strategy = &sysctl_intvec,
1230 .extra1 = &min_percpu_pagelist_fract,
1234 .ctl_name = VM_MAX_MAP_COUNT,
1235 .procname = "max_map_count",
1236 .data = &sysctl_max_map_count,
1237 .maxlen = sizeof(sysctl_max_map_count),
1239 .proc_handler = &proc_dointvec
1243 .ctl_name = CTL_UNNUMBERED,
1244 .procname = "nr_trim_pages",
1245 .data = &sysctl_nr_trim_pages,
1246 .maxlen = sizeof(sysctl_nr_trim_pages),
1248 .proc_handler = &proc_dointvec_minmax,
1249 .strategy = &sysctl_intvec,
1254 .ctl_name = VM_LAPTOP_MODE,
1255 .procname = "laptop_mode",
1256 .data = &laptop_mode,
1257 .maxlen = sizeof(laptop_mode),
1259 .proc_handler = &proc_dointvec_jiffies,
1260 .strategy = &sysctl_jiffies,
1263 .ctl_name = VM_BLOCK_DUMP,
1264 .procname = "block_dump",
1265 .data = &block_dump,
1266 .maxlen = sizeof(block_dump),
1268 .proc_handler = &proc_dointvec,
1269 .strategy = &sysctl_intvec,
1273 .ctl_name = VM_VFS_CACHE_PRESSURE,
1274 .procname = "vfs_cache_pressure",
1275 .data = &sysctl_vfs_cache_pressure,
1276 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1278 .proc_handler = &proc_dointvec,
1279 .strategy = &sysctl_intvec,
1282 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1284 .ctl_name = VM_LEGACY_VA_LAYOUT,
1285 .procname = "legacy_va_layout",
1286 .data = &sysctl_legacy_va_layout,
1287 .maxlen = sizeof(sysctl_legacy_va_layout),
1289 .proc_handler = &proc_dointvec,
1290 .strategy = &sysctl_intvec,
1296 .ctl_name = VM_ZONE_RECLAIM_MODE,
1297 .procname = "zone_reclaim_mode",
1298 .data = &zone_reclaim_mode,
1299 .maxlen = sizeof(zone_reclaim_mode),
1301 .proc_handler = &proc_dointvec,
1302 .strategy = &sysctl_intvec,
1306 .ctl_name = VM_MIN_UNMAPPED,
1307 .procname = "min_unmapped_ratio",
1308 .data = &sysctl_min_unmapped_ratio,
1309 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1311 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1312 .strategy = &sysctl_intvec,
1314 .extra2 = &one_hundred,
1317 .ctl_name = VM_MIN_SLAB,
1318 .procname = "min_slab_ratio",
1319 .data = &sysctl_min_slab_ratio,
1320 .maxlen = sizeof(sysctl_min_slab_ratio),
1322 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1323 .strategy = &sysctl_intvec,
1325 .extra2 = &one_hundred,
1330 .ctl_name = CTL_UNNUMBERED,
1331 .procname = "stat_interval",
1332 .data = &sysctl_stat_interval,
1333 .maxlen = sizeof(sysctl_stat_interval),
1335 .proc_handler = &proc_dointvec_jiffies,
1336 .strategy = &sysctl_jiffies,
1340 .ctl_name = CTL_UNNUMBERED,
1341 .procname = "mmap_min_addr",
1342 .data = &dac_mmap_min_addr,
1343 .maxlen = sizeof(unsigned long),
1345 .proc_handler = &mmap_min_addr_handler,
1349 .ctl_name = CTL_UNNUMBERED,
1350 .procname = "numa_zonelist_order",
1351 .data = &numa_zonelist_order,
1352 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1354 .proc_handler = &numa_zonelist_order_handler,
1355 .strategy = &sysctl_string,
1358 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1359 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1361 .ctl_name = VM_VDSO_ENABLED,
1362 .procname = "vdso_enabled",
1363 .data = &vdso_enabled,
1364 .maxlen = sizeof(vdso_enabled),
1366 .proc_handler = &proc_dointvec,
1367 .strategy = &sysctl_intvec,
1371 #ifdef CONFIG_HIGHMEM
1373 .ctl_name = CTL_UNNUMBERED,
1374 .procname = "highmem_is_dirtyable",
1375 .data = &vm_highmem_is_dirtyable,
1376 .maxlen = sizeof(vm_highmem_is_dirtyable),
1378 .proc_handler = &proc_dointvec_minmax,
1379 .strategy = &sysctl_intvec,
1385 .ctl_name = CTL_UNNUMBERED,
1386 .procname = "scan_unevictable_pages",
1387 .data = &scan_unevictable_pages,
1388 .maxlen = sizeof(scan_unevictable_pages),
1390 .proc_handler = &scan_unevictable_handler,
1393 * NOTE: do not add new entries to this table unless you have read
1394 * Documentation/sysctl/ctl_unnumbered.txt
1399 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1400 static struct ctl_table binfmt_misc_table[] = {
1405 static struct ctl_table fs_table[] = {
1407 .ctl_name = FS_NRINODE,
1408 .procname = "inode-nr",
1409 .data = &inodes_stat,
1410 .maxlen = 2*sizeof(int),
1412 .proc_handler = &proc_dointvec,
1415 .ctl_name = FS_STATINODE,
1416 .procname = "inode-state",
1417 .data = &inodes_stat,
1418 .maxlen = 7*sizeof(int),
1420 .proc_handler = &proc_dointvec,
1423 .procname = "file-nr",
1424 .data = &files_stat,
1425 .maxlen = 3*sizeof(int),
1427 .proc_handler = &proc_nr_files,
1430 .ctl_name = FS_MAXFILE,
1431 .procname = "file-max",
1432 .data = &files_stat.max_files,
1433 .maxlen = sizeof(int),
1435 .proc_handler = &proc_dointvec,
1438 .ctl_name = CTL_UNNUMBERED,
1439 .procname = "nr_open",
1440 .data = &sysctl_nr_open,
1441 .maxlen = sizeof(int),
1443 .proc_handler = &proc_dointvec_minmax,
1444 .extra1 = &sysctl_nr_open_min,
1445 .extra2 = &sysctl_nr_open_max,
1448 .ctl_name = FS_DENTRY,
1449 .procname = "dentry-state",
1450 .data = &dentry_stat,
1451 .maxlen = 6*sizeof(int),
1453 .proc_handler = &proc_dointvec,
1456 .ctl_name = FS_OVERFLOWUID,
1457 .procname = "overflowuid",
1458 .data = &fs_overflowuid,
1459 .maxlen = sizeof(int),
1461 .proc_handler = &proc_dointvec_minmax,
1462 .strategy = &sysctl_intvec,
1463 .extra1 = &minolduid,
1464 .extra2 = &maxolduid,
1467 .ctl_name = FS_OVERFLOWGID,
1468 .procname = "overflowgid",
1469 .data = &fs_overflowgid,
1470 .maxlen = sizeof(int),
1472 .proc_handler = &proc_dointvec_minmax,
1473 .strategy = &sysctl_intvec,
1474 .extra1 = &minolduid,
1475 .extra2 = &maxolduid,
1477 #ifdef CONFIG_FILE_LOCKING
1479 .ctl_name = FS_LEASES,
1480 .procname = "leases-enable",
1481 .data = &leases_enable,
1482 .maxlen = sizeof(int),
1484 .proc_handler = &proc_dointvec,
1487 #ifdef CONFIG_DNOTIFY
1489 .ctl_name = FS_DIR_NOTIFY,
1490 .procname = "dir-notify-enable",
1491 .data = &dir_notify_enable,
1492 .maxlen = sizeof(int),
1494 .proc_handler = &proc_dointvec,
1498 #ifdef CONFIG_FILE_LOCKING
1500 .ctl_name = FS_LEASE_TIME,
1501 .procname = "lease-break-time",
1502 .data = &lease_break_time,
1503 .maxlen = sizeof(int),
1505 .proc_handler = &proc_dointvec,
1510 .procname = "aio-nr",
1512 .maxlen = sizeof(aio_nr),
1514 .proc_handler = &proc_doulongvec_minmax,
1517 .procname = "aio-max-nr",
1518 .data = &aio_max_nr,
1519 .maxlen = sizeof(aio_max_nr),
1521 .proc_handler = &proc_doulongvec_minmax,
1523 #endif /* CONFIG_AIO */
1524 #ifdef CONFIG_INOTIFY_USER
1526 .ctl_name = FS_INOTIFY,
1527 .procname = "inotify",
1529 .child = inotify_table,
1534 .procname = "epoll",
1536 .child = epoll_table,
1541 .ctl_name = KERN_SETUID_DUMPABLE,
1542 .procname = "suid_dumpable",
1543 .data = &suid_dumpable,
1544 .maxlen = sizeof(int),
1546 .proc_handler = &proc_dointvec_minmax,
1547 .strategy = &sysctl_intvec,
1551 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1553 .ctl_name = CTL_UNNUMBERED,
1554 .procname = "binfmt_misc",
1556 .child = binfmt_misc_table,
1560 * NOTE: do not add new entries to this table unless you have read
1561 * Documentation/sysctl/ctl_unnumbered.txt
1566 static struct ctl_table debug_table[] = {
1567 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1569 .ctl_name = CTL_UNNUMBERED,
1570 .procname = "exception-trace",
1571 .data = &show_unhandled_signals,
1572 .maxlen = sizeof(int),
1574 .proc_handler = proc_dointvec
1580 static struct ctl_table dev_table[] = {
1584 static DEFINE_SPINLOCK(sysctl_lock);
1586 /* called under sysctl_lock */
1587 static int use_table(struct ctl_table_header *p)
1589 if (unlikely(p->unregistering))
1595 /* called under sysctl_lock */
1596 static void unuse_table(struct ctl_table_header *p)
1599 if (unlikely(p->unregistering))
1600 complete(p->unregistering);
1603 /* called under sysctl_lock, will reacquire if has to wait */
1604 static void start_unregistering(struct ctl_table_header *p)
1607 * if p->used is 0, nobody will ever touch that entry again;
1608 * we'll eliminate all paths to it before dropping sysctl_lock
1610 if (unlikely(p->used)) {
1611 struct completion wait;
1612 init_completion(&wait);
1613 p->unregistering = &wait;
1614 spin_unlock(&sysctl_lock);
1615 wait_for_completion(&wait);
1616 spin_lock(&sysctl_lock);
1618 /* anything non-NULL; we'll never dereference it */
1619 p->unregistering = ERR_PTR(-EINVAL);
1622 * do not remove from the list until nobody holds it; walking the
1623 * list in do_sysctl() relies on that.
1625 list_del_init(&p->ctl_entry);
1628 void sysctl_head_get(struct ctl_table_header *head)
1630 spin_lock(&sysctl_lock);
1632 spin_unlock(&sysctl_lock);
1635 void sysctl_head_put(struct ctl_table_header *head)
1637 spin_lock(&sysctl_lock);
1640 spin_unlock(&sysctl_lock);
1643 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1647 spin_lock(&sysctl_lock);
1648 if (!use_table(head))
1649 head = ERR_PTR(-ENOENT);
1650 spin_unlock(&sysctl_lock);
1654 void sysctl_head_finish(struct ctl_table_header *head)
1658 spin_lock(&sysctl_lock);
1660 spin_unlock(&sysctl_lock);
1663 static struct ctl_table_set *
1664 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1666 struct ctl_table_set *set = &root->default_set;
1668 set = root->lookup(root, namespaces);
1672 static struct list_head *
1673 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1675 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1679 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1680 struct ctl_table_header *prev)
1682 struct ctl_table_root *root;
1683 struct list_head *header_list;
1684 struct ctl_table_header *head;
1685 struct list_head *tmp;
1687 spin_lock(&sysctl_lock);
1690 tmp = &prev->ctl_entry;
1694 tmp = &root_table_header.ctl_entry;
1696 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1698 if (!use_table(head))
1700 spin_unlock(&sysctl_lock);
1705 header_list = lookup_header_list(root, namespaces);
1706 if (tmp != header_list)
1710 root = list_entry(root->root_list.next,
1711 struct ctl_table_root, root_list);
1712 if (root == &sysctl_table_root)
1714 header_list = lookup_header_list(root, namespaces);
1715 } while (list_empty(header_list));
1716 tmp = header_list->next;
1719 spin_unlock(&sysctl_lock);
1723 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1725 return __sysctl_head_next(current->nsproxy, prev);
1728 void register_sysctl_root(struct ctl_table_root *root)
1730 spin_lock(&sysctl_lock);
1731 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1732 spin_unlock(&sysctl_lock);
1735 #ifdef CONFIG_SYSCTL_SYSCALL
1736 /* Perform the actual read/write of a sysctl table entry. */
1737 static int do_sysctl_strategy(struct ctl_table_root *root,
1738 struct ctl_table *table,
1739 void __user *oldval, size_t __user *oldlenp,
1740 void __user *newval, size_t newlen)
1748 if (sysctl_perm(root, table, op))
1751 if (table->strategy) {
1752 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1759 /* If there is no strategy routine, or if the strategy returns
1760 * zero, proceed with automatic r/w */
1761 if (table->data && table->maxlen) {
1762 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1769 static int parse_table(int __user *name, int nlen,
1770 void __user *oldval, size_t __user *oldlenp,
1771 void __user *newval, size_t newlen,
1772 struct ctl_table_root *root,
1773 struct ctl_table *table)
1779 if (get_user(n, name))
1781 for ( ; table->ctl_name || table->procname; table++) {
1782 if (!table->ctl_name)
1784 if (n == table->ctl_name) {
1787 if (sysctl_perm(root, table, MAY_EXEC))
1791 table = table->child;
1794 error = do_sysctl_strategy(root, table,
1803 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1804 void __user *newval, size_t newlen)
1806 struct ctl_table_header *head;
1807 int error = -ENOTDIR;
1809 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1813 if (!oldlenp || get_user(old_len, oldlenp))
1817 for (head = sysctl_head_next(NULL); head;
1818 head = sysctl_head_next(head)) {
1819 error = parse_table(name, nlen, oldval, oldlenp,
1821 head->root, head->ctl_table);
1822 if (error != -ENOTDIR) {
1823 sysctl_head_finish(head);
1830 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1832 struct __sysctl_args tmp;
1835 if (copy_from_user(&tmp, args, sizeof(tmp)))
1838 error = deprecated_sysctl_warning(&tmp);
1843 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1844 tmp.newval, tmp.newlen);
1849 #endif /* CONFIG_SYSCTL_SYSCALL */
1852 * sysctl_perm does NOT grant the superuser all rights automatically, because
1853 * some sysctl variables are readonly even to root.
1856 static int test_perm(int mode, int op)
1858 if (!current_euid())
1860 else if (in_egroup_p(0))
1862 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1867 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1872 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1876 if (root->permissions)
1877 mode = root->permissions(root, current->nsproxy, table);
1881 return test_perm(mode, op);
1884 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1886 for (; table->ctl_name || table->procname; table++) {
1887 table->parent = parent;
1889 sysctl_set_parent(table, table->child);
1893 static __init int sysctl_init(void)
1895 sysctl_set_parent(NULL, root_table);
1896 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1899 err = sysctl_check_table(current->nsproxy, root_table);
1905 core_initcall(sysctl_init);
1907 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1908 struct ctl_table *table)
1910 struct ctl_table *p;
1911 const char *s = branch->procname;
1913 /* branch should have named subdirectory as its first element */
1914 if (!s || !branch->child)
1917 /* ... and nothing else */
1918 if (branch[1].procname || branch[1].ctl_name)
1921 /* table should contain subdirectory with the same name */
1922 for (p = table; p->procname || p->ctl_name; p++) {
1925 if (p->procname && strcmp(p->procname, s) == 0)
1931 /* see if attaching q to p would be an improvement */
1932 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1934 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1935 struct ctl_table *next;
1937 int not_in_parent = !p->attached_by;
1939 while ((next = is_branch_in(by, to)) != NULL) {
1940 if (by == q->attached_by)
1942 if (to == p->attached_by)
1948 if (is_better && not_in_parent) {
1949 q->attached_by = by;
1950 q->attached_to = to;
1956 * __register_sysctl_paths - register a sysctl hierarchy
1957 * @root: List of sysctl headers to register on
1958 * @namespaces: Data to compute which lists of sysctl entries are visible
1959 * @path: The path to the directory the sysctl table is in.
1960 * @table: the top-level table structure
1962 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1963 * array. A completely 0 filled entry terminates the table.
1965 * The members of the &struct ctl_table structure are used as follows:
1967 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1968 * must be unique within that level of sysctl
1970 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1971 * enter a sysctl file
1973 * data - a pointer to data for use by proc_handler
1975 * maxlen - the maximum size in bytes of the data
1977 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1979 * child - a pointer to the child sysctl table if this entry is a directory, or
1982 * proc_handler - the text handler routine (described below)
1984 * strategy - the strategy routine (described below)
1986 * de - for internal use by the sysctl routines
1988 * extra1, extra2 - extra pointers usable by the proc handler routines
1990 * Leaf nodes in the sysctl tree will be represented by a single file
1991 * under /proc; non-leaf nodes will be represented by directories.
1993 * sysctl(2) can automatically manage read and write requests through
1994 * the sysctl table. The data and maxlen fields of the ctl_table
1995 * struct enable minimal validation of the values being written to be
1996 * performed, and the mode field allows minimal authentication.
1998 * More sophisticated management can be enabled by the provision of a
1999 * strategy routine with the table entry. This will be called before
2000 * any automatic read or write of the data is performed.
2002 * The strategy routine may return
2004 * < 0 - Error occurred (error is passed to user process)
2006 * 0 - OK - proceed with automatic read or write.
2008 * > 0 - OK - read or write has been done by the strategy routine, so
2009 * return immediately.
2011 * There must be a proc_handler routine for any terminal nodes
2012 * mirrored under /proc/sys (non-terminals are handled by a built-in
2013 * directory handler). Several default handlers are available to
2014 * cover common cases -
2016 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2017 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2018 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2020 * It is the handler's job to read the input buffer from user memory
2021 * and process it. The handler should return 0 on success.
2023 * This routine returns %NULL on a failure to register, and a pointer
2024 * to the table header on success.
2026 struct ctl_table_header *__register_sysctl_paths(
2027 struct ctl_table_root *root,
2028 struct nsproxy *namespaces,
2029 const struct ctl_path *path, struct ctl_table *table)
2031 struct ctl_table_header *header;
2032 struct ctl_table *new, **prevp;
2033 unsigned int n, npath;
2034 struct ctl_table_set *set;
2036 /* Count the path components */
2037 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2041 * For each path component, allocate a 2-element ctl_table array.
2042 * The first array element will be filled with the sysctl entry
2043 * for this, the second will be the sentinel (ctl_name == 0).
2045 * We allocate everything in one go so that we don't have to
2046 * worry about freeing additional memory in unregister_sysctl_table.
2048 header = kzalloc(sizeof(struct ctl_table_header) +
2049 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2053 new = (struct ctl_table *) (header + 1);
2055 /* Now connect the dots */
2056 prevp = &header->ctl_table;
2057 for (n = 0; n < npath; ++n, ++path) {
2058 /* Copy the procname */
2059 new->procname = path->procname;
2060 new->ctl_name = path->ctl_name;
2064 prevp = &new->child;
2069 header->ctl_table_arg = table;
2071 INIT_LIST_HEAD(&header->ctl_entry);
2073 header->unregistering = NULL;
2074 header->root = root;
2075 sysctl_set_parent(NULL, header->ctl_table);
2077 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2078 if (sysctl_check_table(namespaces, header->ctl_table)) {
2083 spin_lock(&sysctl_lock);
2084 header->set = lookup_header_set(root, namespaces);
2085 header->attached_by = header->ctl_table;
2086 header->attached_to = root_table;
2087 header->parent = &root_table_header;
2088 for (set = header->set; set; set = set->parent) {
2089 struct ctl_table_header *p;
2090 list_for_each_entry(p, &set->list, ctl_entry) {
2091 if (p->unregistering)
2093 try_attach(p, header);
2096 header->parent->count++;
2097 list_add_tail(&header->ctl_entry, &header->set->list);
2098 spin_unlock(&sysctl_lock);
2104 * register_sysctl_table_path - register a sysctl table hierarchy
2105 * @path: The path to the directory the sysctl table is in.
2106 * @table: the top-level table structure
2108 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2109 * array. A completely 0 filled entry terminates the table.
2111 * See __register_sysctl_paths for more details.
2113 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2114 struct ctl_table *table)
2116 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2121 * register_sysctl_table - register a sysctl table hierarchy
2122 * @table: the top-level table structure
2124 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2125 * array. A completely 0 filled entry terminates the table.
2127 * See register_sysctl_paths for more details.
2129 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2131 static const struct ctl_path null_path[] = { {} };
2133 return register_sysctl_paths(null_path, table);
2137 * unregister_sysctl_table - unregister a sysctl table hierarchy
2138 * @header: the header returned from register_sysctl_table
2140 * Unregisters the sysctl table and all children. proc entries may not
2141 * actually be removed until they are no longer used by anyone.
2143 void unregister_sysctl_table(struct ctl_table_header * header)
2150 spin_lock(&sysctl_lock);
2151 start_unregistering(header);
2152 if (!--header->parent->count) {
2154 kfree(header->parent);
2156 if (!--header->count)
2158 spin_unlock(&sysctl_lock);
2161 int sysctl_is_seen(struct ctl_table_header *p)
2163 struct ctl_table_set *set = p->set;
2165 spin_lock(&sysctl_lock);
2166 if (p->unregistering)
2168 else if (!set->is_seen)
2171 res = set->is_seen(set);
2172 spin_unlock(&sysctl_lock);
2176 void setup_sysctl_set(struct ctl_table_set *p,
2177 struct ctl_table_set *parent,
2178 int (*is_seen)(struct ctl_table_set *))
2180 INIT_LIST_HEAD(&p->list);
2181 p->parent = parent ? parent : &sysctl_table_root.default_set;
2182 p->is_seen = is_seen;
2185 #else /* !CONFIG_SYSCTL */
2186 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2191 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2192 struct ctl_table *table)
2197 void unregister_sysctl_table(struct ctl_table_header * table)
2201 void setup_sysctl_set(struct ctl_table_set *p,
2202 struct ctl_table_set *parent,
2203 int (*is_seen)(struct ctl_table_set *))
2207 void sysctl_head_put(struct ctl_table_header *head)
2211 #endif /* CONFIG_SYSCTL */
2217 #ifdef CONFIG_PROC_SYSCTL
2219 static int _proc_do_string(void* data, int maxlen, int write,
2220 struct file *filp, void __user *buffer,
2221 size_t *lenp, loff_t *ppos)
2227 if (!data || !maxlen || !*lenp) {
2235 while (len < *lenp) {
2236 if (get_user(c, p++))
2238 if (c == 0 || c == '\n')
2244 if(copy_from_user(data, buffer, len))
2246 ((char *) data)[len] = 0;
2264 if(copy_to_user(buffer, data, len))
2267 if(put_user('\n', ((char __user *) buffer) + len))
2278 * proc_dostring - read a string sysctl
2279 * @table: the sysctl table
2280 * @write: %TRUE if this is a write to the sysctl file
2281 * @filp: the file structure
2282 * @buffer: the user buffer
2283 * @lenp: the size of the user buffer
2284 * @ppos: file position
2286 * Reads/writes a string from/to the user buffer. If the kernel
2287 * buffer provided is not large enough to hold the string, the
2288 * string is truncated. The copied string is %NULL-terminated.
2289 * If the string is being read by the user process, it is copied
2290 * and a newline '\n' is added. It is truncated if the buffer is
2293 * Returns 0 on success.
2295 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2296 void __user *buffer, size_t *lenp, loff_t *ppos)
2298 return _proc_do_string(table->data, table->maxlen, write, filp,
2299 buffer, lenp, ppos);
2303 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2305 int write, void *data)
2308 *valp = *negp ? -*lvalp : *lvalp;
2313 *lvalp = (unsigned long)-val;
2316 *lvalp = (unsigned long)val;
2322 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2323 int write, struct file *filp, void __user *buffer,
2324 size_t *lenp, loff_t *ppos,
2325 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2326 int write, void *data),
2329 #define TMPBUFLEN 21
2330 int *i, vleft, first = 1, neg;
2334 char buf[TMPBUFLEN], *p;
2335 char __user *s = buffer;
2337 if (!tbl_data || !table->maxlen || !*lenp ||
2338 (*ppos && !write)) {
2343 i = (int *) tbl_data;
2344 vleft = table->maxlen / sizeof(*i);
2348 conv = do_proc_dointvec_conv;
2350 for (; left && vleft--; i++, first=0) {
2365 if (len > sizeof(buf) - 1)
2366 len = sizeof(buf) - 1;
2367 if (copy_from_user(buf, s, len))
2371 if (*p == '-' && left > 1) {
2375 if (*p < '0' || *p > '9')
2378 lval = simple_strtoul(p, &p, 0);
2381 if ((len < left) && *p && !isspace(*p))
2386 if (conv(&neg, &lval, i, 1, data))
2393 if (conv(&neg, &lval, i, 0, data))
2396 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2400 if(copy_to_user(s, buf, len))
2407 if (!write && !first && left) {
2408 if(put_user('\n', s))
2415 if (get_user(c, s++))
2430 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2431 void __user *buffer, size_t *lenp, loff_t *ppos,
2432 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2433 int write, void *data),
2436 return __do_proc_dointvec(table->data, table, write, filp,
2437 buffer, lenp, ppos, conv, data);
2441 * proc_dointvec - read a vector of integers
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @filp: the file structure
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
2447 * @ppos: file position
2449 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2450 * values from/to the user buffer, treated as an ASCII string.
2452 * Returns 0 on success.
2454 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2455 void __user *buffer, size_t *lenp, loff_t *ppos)
2457 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2462 * Taint values can only be increased
2463 * This means we can safely use a temporary.
2465 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2466 void __user *buffer, size_t *lenp, loff_t *ppos)
2469 unsigned long tmptaint = get_taint();
2472 if (write && !capable(CAP_SYS_ADMIN))
2477 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2483 * Poor man's atomic or. Not worth adding a primitive
2484 * to everyone's atomic.h for this
2487 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2488 if ((tmptaint >> i) & 1)
2496 struct do_proc_dointvec_minmax_conv_param {
2501 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2503 int write, void *data)
2505 struct do_proc_dointvec_minmax_conv_param *param = data;
2507 int val = *negp ? -*lvalp : *lvalp;
2508 if ((param->min && *param->min > val) ||
2509 (param->max && *param->max < val))
2516 *lvalp = (unsigned long)-val;
2519 *lvalp = (unsigned long)val;
2526 * proc_dointvec_minmax - read a vector of integers with min/max values
2527 * @table: the sysctl table
2528 * @write: %TRUE if this is a write to the sysctl file
2529 * @filp: the file structure
2530 * @buffer: the user buffer
2531 * @lenp: the size of the user buffer
2532 * @ppos: file position
2534 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2535 * values from/to the user buffer, treated as an ASCII string.
2537 * This routine will ensure the values are within the range specified by
2538 * table->extra1 (min) and table->extra2 (max).
2540 * Returns 0 on success.
2542 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2543 void __user *buffer, size_t *lenp, loff_t *ppos)
2545 struct do_proc_dointvec_minmax_conv_param param = {
2546 .min = (int *) table->extra1,
2547 .max = (int *) table->extra2,
2549 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2550 do_proc_dointvec_minmax_conv, ¶m);
2553 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2555 void __user *buffer,
2556 size_t *lenp, loff_t *ppos,
2557 unsigned long convmul,
2558 unsigned long convdiv)
2560 #define TMPBUFLEN 21
2561 unsigned long *i, *min, *max, val;
2562 int vleft, first=1, neg;
2564 char buf[TMPBUFLEN], *p;
2565 char __user *s = buffer;
2567 if (!data || !table->maxlen || !*lenp ||
2568 (*ppos && !write)) {
2573 i = (unsigned long *) data;
2574 min = (unsigned long *) table->extra1;
2575 max = (unsigned long *) table->extra2;
2576 vleft = table->maxlen / sizeof(unsigned long);
2579 for (; left && vleft--; i++, min++, max++, first=0) {
2594 if (len > TMPBUFLEN-1)
2596 if (copy_from_user(buf, s, len))
2600 if (*p == '-' && left > 1) {
2604 if (*p < '0' || *p > '9')
2606 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2608 if ((len < left) && *p && !isspace(*p))
2617 if ((min && val < *min) || (max && val > *max))
2624 sprintf(p, "%lu", convdiv * (*i) / convmul);
2628 if(copy_to_user(s, buf, len))
2635 if (!write && !first && left) {
2636 if(put_user('\n', s))
2643 if (get_user(c, s++))
2658 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2660 void __user *buffer,
2661 size_t *lenp, loff_t *ppos,
2662 unsigned long convmul,
2663 unsigned long convdiv)
2665 return __do_proc_doulongvec_minmax(table->data, table, write,
2666 filp, buffer, lenp, ppos, convmul, convdiv);
2670 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2671 * @table: the sysctl table
2672 * @write: %TRUE if this is a write to the sysctl file
2673 * @filp: the file structure
2674 * @buffer: the user buffer
2675 * @lenp: the size of the user buffer
2676 * @ppos: file position
2678 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2679 * values from/to the user buffer, treated as an ASCII string.
2681 * This routine will ensure the values are within the range specified by
2682 * table->extra1 (min) and table->extra2 (max).
2684 * Returns 0 on success.
2686 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2687 void __user *buffer, size_t *lenp, loff_t *ppos)
2689 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2693 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2694 * @table: the sysctl table
2695 * @write: %TRUE if this is a write to the sysctl file
2696 * @filp: the file structure
2697 * @buffer: the user buffer
2698 * @lenp: the size of the user buffer
2699 * @ppos: file position
2701 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2702 * values from/to the user buffer, treated as an ASCII string. The values
2703 * are treated as milliseconds, and converted to jiffies when they are stored.
2705 * This routine will ensure the values are within the range specified by
2706 * table->extra1 (min) and table->extra2 (max).
2708 * Returns 0 on success.
2710 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2712 void __user *buffer,
2713 size_t *lenp, loff_t *ppos)
2715 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2716 lenp, ppos, HZ, 1000l);
2720 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2722 int write, void *data)
2725 if (*lvalp > LONG_MAX / HZ)
2727 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2733 lval = (unsigned long)-val;
2736 lval = (unsigned long)val;
2743 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2745 int write, void *data)
2748 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2750 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2756 lval = (unsigned long)-val;
2759 lval = (unsigned long)val;
2761 *lvalp = jiffies_to_clock_t(lval);
2766 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2768 int write, void *data)
2771 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2777 lval = (unsigned long)-val;
2780 lval = (unsigned long)val;
2782 *lvalp = jiffies_to_msecs(lval);
2788 * proc_dointvec_jiffies - read a vector of integers as seconds
2789 * @table: the sysctl table
2790 * @write: %TRUE if this is a write to the sysctl file
2791 * @filp: the file structure
2792 * @buffer: the user buffer
2793 * @lenp: the size of the user buffer
2794 * @ppos: file position
2796 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2797 * values from/to the user buffer, treated as an ASCII string.
2798 * The values read are assumed to be in seconds, and are converted into
2801 * Returns 0 on success.
2803 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2804 void __user *buffer, size_t *lenp, loff_t *ppos)
2806 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2807 do_proc_dointvec_jiffies_conv,NULL);
2811 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2812 * @table: the sysctl table
2813 * @write: %TRUE if this is a write to the sysctl file
2814 * @filp: the file structure
2815 * @buffer: the user buffer
2816 * @lenp: the size of the user buffer
2817 * @ppos: pointer to the file position
2819 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2820 * values from/to the user buffer, treated as an ASCII string.
2821 * The values read are assumed to be in 1/USER_HZ seconds, and
2822 * are converted into jiffies.
2824 * Returns 0 on success.
2826 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2827 void __user *buffer, size_t *lenp, loff_t *ppos)
2829 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2830 do_proc_dointvec_userhz_jiffies_conv,NULL);
2834 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2835 * @table: the sysctl table
2836 * @write: %TRUE if this is a write to the sysctl file
2837 * @filp: the file structure
2838 * @buffer: the user buffer
2839 * @lenp: the size of the user buffer
2840 * @ppos: file position
2841 * @ppos: the current position in the file
2843 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2844 * values from/to the user buffer, treated as an ASCII string.
2845 * The values read are assumed to be in 1/1000 seconds, and
2846 * are converted into jiffies.
2848 * Returns 0 on success.
2850 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2851 void __user *buffer, size_t *lenp, loff_t *ppos)
2853 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2854 do_proc_dointvec_ms_jiffies_conv, NULL);
2857 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2858 void __user *buffer, size_t *lenp, loff_t *ppos)
2860 struct pid *new_pid;
2864 tmp = pid_vnr(cad_pid);
2866 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2867 lenp, ppos, NULL, NULL);
2871 new_pid = find_get_pid(tmp);
2875 put_pid(xchg(&cad_pid, new_pid));
2879 #else /* CONFIG_PROC_FS */
2881 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2882 void __user *buffer, size_t *lenp, loff_t *ppos)
2887 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2888 void __user *buffer, size_t *lenp, loff_t *ppos)
2893 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2894 void __user *buffer, size_t *lenp, loff_t *ppos)
2899 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2900 void __user *buffer, size_t *lenp, loff_t *ppos)
2905 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2906 void __user *buffer, size_t *lenp, loff_t *ppos)
2911 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2912 void __user *buffer, size_t *lenp, loff_t *ppos)
2917 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2918 void __user *buffer, size_t *lenp, loff_t *ppos)
2923 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2925 void __user *buffer,
2926 size_t *lenp, loff_t *ppos)
2932 #endif /* CONFIG_PROC_FS */
2935 #ifdef CONFIG_SYSCTL_SYSCALL
2937 * General sysctl support routines
2940 /* The generic sysctl data routine (used if no strategy routine supplied) */
2941 int sysctl_data(struct ctl_table *table,
2942 void __user *oldval, size_t __user *oldlenp,
2943 void __user *newval, size_t newlen)
2947 /* Get out of I don't have a variable */
2948 if (!table->data || !table->maxlen)
2951 if (oldval && oldlenp) {
2952 if (get_user(len, oldlenp))
2955 if (len > table->maxlen)
2956 len = table->maxlen;
2957 if (copy_to_user(oldval, table->data, len))
2959 if (put_user(len, oldlenp))
2964 if (newval && newlen) {
2965 if (newlen > table->maxlen)
2966 newlen = table->maxlen;
2968 if (copy_from_user(table->data, newval, newlen))
2974 /* The generic string strategy routine: */
2975 int sysctl_string(struct ctl_table *table,
2976 void __user *oldval, size_t __user *oldlenp,
2977 void __user *newval, size_t newlen)
2979 if (!table->data || !table->maxlen)
2982 if (oldval && oldlenp) {
2984 if (get_user(bufsize, oldlenp))
2987 size_t len = strlen(table->data), copied;
2989 /* This shouldn't trigger for a well-formed sysctl */
2990 if (len > table->maxlen)
2991 len = table->maxlen;
2993 /* Copy up to a max of bufsize-1 bytes of the string */
2994 copied = (len >= bufsize) ? bufsize - 1 : len;
2996 if (copy_to_user(oldval, table->data, copied) ||
2997 put_user(0, (char __user *)(oldval + copied)))
2999 if (put_user(len, oldlenp))
3003 if (newval && newlen) {
3004 size_t len = newlen;
3005 if (len > table->maxlen)
3006 len = table->maxlen;
3007 if(copy_from_user(table->data, newval, len))
3009 if (len == table->maxlen)
3011 ((char *) table->data)[len] = 0;
3017 * This function makes sure that all of the integers in the vector
3018 * are between the minimum and maximum values given in the arrays
3019 * table->extra1 and table->extra2, respectively.
3021 int sysctl_intvec(struct ctl_table *table,
3022 void __user *oldval, size_t __user *oldlenp,
3023 void __user *newval, size_t newlen)
3026 if (newval && newlen) {
3027 int __user *vec = (int __user *) newval;
3028 int *min = (int *) table->extra1;
3029 int *max = (int *) table->extra2;
3033 if (newlen % sizeof(int) != 0)
3036 if (!table->extra1 && !table->extra2)
3039 if (newlen > table->maxlen)
3040 newlen = table->maxlen;
3041 length = newlen / sizeof(int);
3043 for (i = 0; i < length; i++) {
3045 if (get_user(value, vec + i))
3047 if (min && value < min[i])
3049 if (max && value > max[i])
3056 /* Strategy function to convert jiffies to seconds */
3057 int sysctl_jiffies(struct ctl_table *table,
3058 void __user *oldval, size_t __user *oldlenp,
3059 void __user *newval, size_t newlen)
3061 if (oldval && oldlenp) {
3064 if (get_user(olen, oldlenp))
3069 if (olen < sizeof(int))
3072 val = *(int *)(table->data) / HZ;
3073 if (put_user(val, (int __user *)oldval))
3075 if (put_user(sizeof(int), oldlenp))
3079 if (newval && newlen) {
3081 if (newlen != sizeof(int))
3083 if (get_user(new, (int __user *)newval))
3085 *(int *)(table->data) = new*HZ;
3090 /* Strategy function to convert jiffies to seconds */
3091 int sysctl_ms_jiffies(struct ctl_table *table,
3092 void __user *oldval, size_t __user *oldlenp,
3093 void __user *newval, size_t newlen)
3095 if (oldval && oldlenp) {
3098 if (get_user(olen, oldlenp))
3103 if (olen < sizeof(int))
3106 val = jiffies_to_msecs(*(int *)(table->data));
3107 if (put_user(val, (int __user *)oldval))
3109 if (put_user(sizeof(int), oldlenp))
3113 if (newval && newlen) {
3115 if (newlen != sizeof(int))
3117 if (get_user(new, (int __user *)newval))
3119 *(int *)(table->data) = msecs_to_jiffies(new);
3126 #else /* CONFIG_SYSCTL_SYSCALL */
3129 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3131 struct __sysctl_args tmp;
3134 if (copy_from_user(&tmp, args, sizeof(tmp)))
3137 error = deprecated_sysctl_warning(&tmp);
3139 /* If no error reading the parameters then just -ENOSYS ... */
3146 int sysctl_data(struct ctl_table *table,
3147 void __user *oldval, size_t __user *oldlenp,
3148 void __user *newval, size_t newlen)
3153 int sysctl_string(struct ctl_table *table,
3154 void __user *oldval, size_t __user *oldlenp,
3155 void __user *newval, size_t newlen)
3160 int sysctl_intvec(struct ctl_table *table,
3161 void __user *oldval, size_t __user *oldlenp,
3162 void __user *newval, size_t newlen)
3167 int sysctl_jiffies(struct ctl_table *table,
3168 void __user *oldval, size_t __user *oldlenp,
3169 void __user *newval, size_t newlen)
3174 int sysctl_ms_jiffies(struct ctl_table *table,
3175 void __user *oldval, size_t __user *oldlenp,
3176 void __user *newval, size_t newlen)
3181 #endif /* CONFIG_SYSCTL_SYSCALL */
3183 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3185 static int msg_count;
3186 int name[CTL_MAXNAME];
3189 /* Check args->nlen. */
3190 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3193 /* Read in the sysctl name for better debug message logging */
3194 for (i = 0; i < args->nlen; i++)
3195 if (get_user(name[i], args->name + i))
3198 /* Ignore accesses to kernel.version */
3199 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3202 if (msg_count < 5) {
3205 "warning: process `%s' used the deprecated sysctl "
3206 "system call with ", current->comm);
3207 for (i = 0; i < args->nlen; i++)
3208 printk("%d.", name[i]);
3215 * No sense putting this after each symbol definition, twice,
3216 * exception granted :-)
3218 EXPORT_SYMBOL(proc_dointvec);
3219 EXPORT_SYMBOL(proc_dointvec_jiffies);
3220 EXPORT_SYMBOL(proc_dointvec_minmax);
3221 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3222 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3223 EXPORT_SYMBOL(proc_dostring);
3224 EXPORT_SYMBOL(proc_doulongvec_minmax);
3225 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3226 EXPORT_SYMBOL(register_sysctl_table);
3227 EXPORT_SYMBOL(register_sysctl_paths);
3228 EXPORT_SYMBOL(sysctl_intvec);
3229 EXPORT_SYMBOL(sysctl_jiffies);
3230 EXPORT_SYMBOL(sysctl_ms_jiffies);
3231 EXPORT_SYMBOL(sysctl_string);
3232 EXPORT_SYMBOL(sysctl_data);
3233 EXPORT_SYMBOL(unregister_sysctl_table);