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/kmemcheck.h>
31 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
55 #include <asm/uaccess.h>
56 #include <asm/processor.h>
60 #include <asm/stacktrace.h>
64 static int deprecated_sysctl_warning(struct __sysctl_args *args);
66 #if defined(CONFIG_SYSCTL)
68 /* External variables not in a header file. */
70 extern int print_fatal_signals;
71 extern int sysctl_overcommit_memory;
72 extern int sysctl_overcommit_ratio;
73 extern int sysctl_panic_on_oom;
74 extern int sysctl_oom_kill_allocating_task;
75 extern int sysctl_oom_dump_tasks;
76 extern int max_threads;
77 extern int core_uses_pid;
78 extern int suid_dumpable;
79 extern char core_pattern[];
81 extern int min_free_kbytes;
82 extern int pid_max_min, pid_max_max;
83 extern int sysctl_drop_caches;
84 extern int percpu_pagelist_fraction;
85 extern int compat_log;
86 extern int latencytop_enabled;
87 extern int sysctl_nr_open_min, sysctl_nr_open_max;
89 extern int sysctl_nr_trim_pages;
91 #ifdef CONFIG_RCU_TORTURE_TEST
92 extern int rcutorture_runnable;
93 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
95 extern int blk_iopoll_enabled;
98 /* Constants used for minimum and maximum */
99 #ifdef CONFIG_DETECT_SOFTLOCKUP
100 static int sixty = 60;
101 static int neg_one = -1;
105 static int __maybe_unused one = 1;
106 static int __maybe_unused two = 2;
107 static unsigned long one_ul = 1;
108 static int one_hundred = 100;
110 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
111 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
113 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
114 static int maxolduid = 65535;
115 static int minolduid;
116 static int min_percpu_pagelist_fract = 8;
118 static int ngroups_max = NGROUPS_MAX;
120 #ifdef CONFIG_MODULES
121 extern char modprobe_path[];
122 extern int modules_disabled;
124 #ifdef CONFIG_CHR_DEV_SG
125 extern int sg_big_buff;
129 #include <asm/system.h>
132 #ifdef CONFIG_SPARC64
133 extern int sysctl_tsb_ratio;
137 extern int pwrsw_enabled;
138 extern int unaligned_enabled;
142 #ifdef CONFIG_MATHEMU
143 extern int sysctl_ieee_emulation_warnings;
145 extern int sysctl_userprocess_debug;
146 extern int spin_retry;
149 #ifdef CONFIG_BSD_PROCESS_ACCT
150 extern int acct_parm[];
154 extern int no_unaligned_warning;
155 extern int unaligned_dump_stack;
158 #ifdef CONFIG_RT_MUTEXES
159 extern int max_lock_depth;
162 #ifdef CONFIG_PROC_SYSCTL
163 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
164 void __user *buffer, size_t *lenp, loff_t *ppos);
165 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
166 void __user *buffer, size_t *lenp, loff_t *ppos);
169 static struct ctl_table root_table[];
170 static struct ctl_table_root sysctl_table_root;
171 static struct ctl_table_header root_table_header = {
173 .ctl_table = root_table,
174 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
175 .root = &sysctl_table_root,
176 .set = &sysctl_table_root.default_set,
178 static struct ctl_table_root sysctl_table_root = {
179 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
180 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
183 static struct ctl_table kern_table[];
184 static struct ctl_table vm_table[];
185 static struct ctl_table fs_table[];
186 static struct ctl_table debug_table[];
187 static struct ctl_table dev_table[];
188 extern struct ctl_table random_table[];
189 #ifdef CONFIG_INOTIFY_USER
190 extern struct ctl_table inotify_table[];
193 extern struct ctl_table epoll_table[];
196 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
197 int sysctl_legacy_va_layout;
200 extern int prove_locking;
201 extern int lock_stat;
203 /* The default sysctl tables: */
205 static struct ctl_table root_table[] = {
207 .ctl_name = CTL_KERN,
208 .procname = "kernel",
225 .ctl_name = CTL_DEBUG,
228 .child = debug_table,
237 * NOTE: do not add new entries to this table unless you have read
238 * Documentation/sysctl/ctl_unnumbered.txt
243 #ifdef CONFIG_SCHED_DEBUG
244 static int min_sched_granularity_ns = 100000; /* 100 usecs */
245 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
246 static int min_wakeup_granularity_ns; /* 0 usecs */
247 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
250 static struct ctl_table kern_table[] = {
252 .ctl_name = CTL_UNNUMBERED,
253 .procname = "sched_child_runs_first",
254 .data = &sysctl_sched_child_runs_first,
255 .maxlen = sizeof(unsigned int),
257 .proc_handler = &proc_dointvec,
259 #ifdef CONFIG_SCHED_DEBUG
261 .ctl_name = CTL_UNNUMBERED,
262 .procname = "sched_min_granularity_ns",
263 .data = &sysctl_sched_min_granularity,
264 .maxlen = sizeof(unsigned int),
266 .proc_handler = &sched_nr_latency_handler,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_sched_granularity_ns,
269 .extra2 = &max_sched_granularity_ns,
272 .ctl_name = CTL_UNNUMBERED,
273 .procname = "sched_latency_ns",
274 .data = &sysctl_sched_latency,
275 .maxlen = sizeof(unsigned int),
277 .proc_handler = &sched_nr_latency_handler,
278 .strategy = &sysctl_intvec,
279 .extra1 = &min_sched_granularity_ns,
280 .extra2 = &max_sched_granularity_ns,
283 .ctl_name = CTL_UNNUMBERED,
284 .procname = "sched_wakeup_granularity_ns",
285 .data = &sysctl_sched_wakeup_granularity,
286 .maxlen = sizeof(unsigned int),
288 .proc_handler = &proc_dointvec_minmax,
289 .strategy = &sysctl_intvec,
290 .extra1 = &min_wakeup_granularity_ns,
291 .extra2 = &max_wakeup_granularity_ns,
294 .ctl_name = CTL_UNNUMBERED,
295 .procname = "sched_shares_ratelimit",
296 .data = &sysctl_sched_shares_ratelimit,
297 .maxlen = sizeof(unsigned int),
299 .proc_handler = &proc_dointvec,
302 .ctl_name = CTL_UNNUMBERED,
303 .procname = "sched_shares_thresh",
304 .data = &sysctl_sched_shares_thresh,
305 .maxlen = sizeof(unsigned int),
307 .proc_handler = &proc_dointvec_minmax,
308 .strategy = &sysctl_intvec,
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "sched_features",
314 .data = &sysctl_sched_features,
315 .maxlen = sizeof(unsigned int),
317 .proc_handler = &proc_dointvec,
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "sched_migration_cost",
322 .data = &sysctl_sched_migration_cost,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = &proc_dointvec,
328 .ctl_name = CTL_UNNUMBERED,
329 .procname = "sched_nr_migrate",
330 .data = &sysctl_sched_nr_migrate,
331 .maxlen = sizeof(unsigned int),
333 .proc_handler = &proc_dointvec,
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "sched_time_avg",
338 .data = &sysctl_sched_time_avg,
339 .maxlen = sizeof(unsigned int),
341 .proc_handler = &proc_dointvec,
344 .ctl_name = CTL_UNNUMBERED,
345 .procname = "timer_migration",
346 .data = &sysctl_timer_migration,
347 .maxlen = sizeof(unsigned int),
349 .proc_handler = &proc_dointvec_minmax,
350 .strategy = &sysctl_intvec,
356 .ctl_name = CTL_UNNUMBERED,
357 .procname = "sched_rt_period_us",
358 .data = &sysctl_sched_rt_period,
359 .maxlen = sizeof(unsigned int),
361 .proc_handler = &sched_rt_handler,
364 .ctl_name = CTL_UNNUMBERED,
365 .procname = "sched_rt_runtime_us",
366 .data = &sysctl_sched_rt_runtime,
367 .maxlen = sizeof(int),
369 .proc_handler = &sched_rt_handler,
372 .ctl_name = CTL_UNNUMBERED,
373 .procname = "sched_compat_yield",
374 .data = &sysctl_sched_compat_yield,
375 .maxlen = sizeof(unsigned int),
377 .proc_handler = &proc_dointvec,
379 #ifdef CONFIG_PROVE_LOCKING
381 .ctl_name = CTL_UNNUMBERED,
382 .procname = "prove_locking",
383 .data = &prove_locking,
384 .maxlen = sizeof(int),
386 .proc_handler = &proc_dointvec,
389 #ifdef CONFIG_LOCK_STAT
391 .ctl_name = CTL_UNNUMBERED,
392 .procname = "lock_stat",
394 .maxlen = sizeof(int),
396 .proc_handler = &proc_dointvec,
400 .ctl_name = KERN_PANIC,
402 .data = &panic_timeout,
403 .maxlen = sizeof(int),
405 .proc_handler = &proc_dointvec,
408 .ctl_name = KERN_CORE_USES_PID,
409 .procname = "core_uses_pid",
410 .data = &core_uses_pid,
411 .maxlen = sizeof(int),
413 .proc_handler = &proc_dointvec,
416 .ctl_name = KERN_CORE_PATTERN,
417 .procname = "core_pattern",
418 .data = core_pattern,
419 .maxlen = CORENAME_MAX_SIZE,
421 .proc_handler = &proc_dostring,
422 .strategy = &sysctl_string,
424 #ifdef CONFIG_PROC_SYSCTL
426 .procname = "tainted",
427 .maxlen = sizeof(long),
429 .proc_handler = &proc_taint,
432 #ifdef CONFIG_LATENCYTOP
434 .procname = "latencytop",
435 .data = &latencytop_enabled,
436 .maxlen = sizeof(int),
438 .proc_handler = &proc_dointvec,
441 #ifdef CONFIG_BLK_DEV_INITRD
443 .ctl_name = KERN_REALROOTDEV,
444 .procname = "real-root-dev",
445 .data = &real_root_dev,
446 .maxlen = sizeof(int),
448 .proc_handler = &proc_dointvec,
452 .ctl_name = CTL_UNNUMBERED,
453 .procname = "print-fatal-signals",
454 .data = &print_fatal_signals,
455 .maxlen = sizeof(int),
457 .proc_handler = &proc_dointvec,
461 .ctl_name = KERN_SPARC_REBOOT,
462 .procname = "reboot-cmd",
463 .data = reboot_command,
466 .proc_handler = &proc_dostring,
467 .strategy = &sysctl_string,
470 .ctl_name = KERN_SPARC_STOP_A,
471 .procname = "stop-a",
472 .data = &stop_a_enabled,
473 .maxlen = sizeof (int),
475 .proc_handler = &proc_dointvec,
478 .ctl_name = KERN_SPARC_SCONS_PWROFF,
479 .procname = "scons-poweroff",
480 .data = &scons_pwroff,
481 .maxlen = sizeof (int),
483 .proc_handler = &proc_dointvec,
486 #ifdef CONFIG_SPARC64
488 .ctl_name = CTL_UNNUMBERED,
489 .procname = "tsb-ratio",
490 .data = &sysctl_tsb_ratio,
491 .maxlen = sizeof (int),
493 .proc_handler = &proc_dointvec,
498 .ctl_name = KERN_HPPA_PWRSW,
499 .procname = "soft-power",
500 .data = &pwrsw_enabled,
501 .maxlen = sizeof (int),
503 .proc_handler = &proc_dointvec,
506 .ctl_name = KERN_HPPA_UNALIGNED,
507 .procname = "unaligned-trap",
508 .data = &unaligned_enabled,
509 .maxlen = sizeof (int),
511 .proc_handler = &proc_dointvec,
515 .ctl_name = KERN_CTLALTDEL,
516 .procname = "ctrl-alt-del",
518 .maxlen = sizeof(int),
520 .proc_handler = &proc_dointvec,
522 #ifdef CONFIG_FUNCTION_TRACER
524 .ctl_name = CTL_UNNUMBERED,
525 .procname = "ftrace_enabled",
526 .data = &ftrace_enabled,
527 .maxlen = sizeof(int),
529 .proc_handler = &ftrace_enable_sysctl,
532 #ifdef CONFIG_STACK_TRACER
534 .ctl_name = CTL_UNNUMBERED,
535 .procname = "stack_tracer_enabled",
536 .data = &stack_tracer_enabled,
537 .maxlen = sizeof(int),
539 .proc_handler = &stack_trace_sysctl,
542 #ifdef CONFIG_TRACING
544 .ctl_name = CTL_UNNUMBERED,
545 .procname = "ftrace_dump_on_oops",
546 .data = &ftrace_dump_on_oops,
547 .maxlen = sizeof(int),
549 .proc_handler = &proc_dointvec,
552 #ifdef CONFIG_MODULES
554 .ctl_name = KERN_MODPROBE,
555 .procname = "modprobe",
556 .data = &modprobe_path,
557 .maxlen = KMOD_PATH_LEN,
559 .proc_handler = &proc_dostring,
560 .strategy = &sysctl_string,
563 .ctl_name = CTL_UNNUMBERED,
564 .procname = "modules_disabled",
565 .data = &modules_disabled,
566 .maxlen = sizeof(int),
568 /* only handle a transition from default "0" to "1" */
569 .proc_handler = &proc_dointvec_minmax,
574 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
576 .ctl_name = KERN_HOTPLUG,
577 .procname = "hotplug",
578 .data = &uevent_helper,
579 .maxlen = UEVENT_HELPER_PATH_LEN,
581 .proc_handler = &proc_dostring,
582 .strategy = &sysctl_string,
585 #ifdef CONFIG_CHR_DEV_SG
587 .ctl_name = KERN_SG_BIG_BUFF,
588 .procname = "sg-big-buff",
589 .data = &sg_big_buff,
590 .maxlen = sizeof (int),
592 .proc_handler = &proc_dointvec,
595 #ifdef CONFIG_BSD_PROCESS_ACCT
597 .ctl_name = KERN_ACCT,
600 .maxlen = 3*sizeof(int),
602 .proc_handler = &proc_dointvec,
605 #ifdef CONFIG_MAGIC_SYSRQ
607 .ctl_name = KERN_SYSRQ,
609 .data = &__sysrq_enabled,
610 .maxlen = sizeof (int),
612 .proc_handler = &proc_dointvec,
615 #ifdef CONFIG_PROC_SYSCTL
617 .procname = "cad_pid",
619 .maxlen = sizeof (int),
621 .proc_handler = &proc_do_cad_pid,
625 .ctl_name = KERN_MAX_THREADS,
626 .procname = "threads-max",
627 .data = &max_threads,
628 .maxlen = sizeof(int),
630 .proc_handler = &proc_dointvec,
633 .ctl_name = KERN_RANDOM,
634 .procname = "random",
636 .child = random_table,
639 .ctl_name = KERN_OVERFLOWUID,
640 .procname = "overflowuid",
641 .data = &overflowuid,
642 .maxlen = sizeof(int),
644 .proc_handler = &proc_dointvec_minmax,
645 .strategy = &sysctl_intvec,
646 .extra1 = &minolduid,
647 .extra2 = &maxolduid,
650 .ctl_name = KERN_OVERFLOWGID,
651 .procname = "overflowgid",
652 .data = &overflowgid,
653 .maxlen = sizeof(int),
655 .proc_handler = &proc_dointvec_minmax,
656 .strategy = &sysctl_intvec,
657 .extra1 = &minolduid,
658 .extra2 = &maxolduid,
661 #ifdef CONFIG_MATHEMU
663 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
664 .procname = "ieee_emulation_warnings",
665 .data = &sysctl_ieee_emulation_warnings,
666 .maxlen = sizeof(int),
668 .proc_handler = &proc_dointvec,
672 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
673 .procname = "userprocess_debug",
674 .data = &sysctl_userprocess_debug,
675 .maxlen = sizeof(int),
677 .proc_handler = &proc_dointvec,
681 .ctl_name = KERN_PIDMAX,
682 .procname = "pid_max",
684 .maxlen = sizeof (int),
686 .proc_handler = &proc_dointvec_minmax,
687 .strategy = sysctl_intvec,
688 .extra1 = &pid_max_min,
689 .extra2 = &pid_max_max,
692 .ctl_name = KERN_PANIC_ON_OOPS,
693 .procname = "panic_on_oops",
694 .data = &panic_on_oops,
695 .maxlen = sizeof(int),
697 .proc_handler = &proc_dointvec,
699 #if defined CONFIG_PRINTK
701 .ctl_name = KERN_PRINTK,
702 .procname = "printk",
703 .data = &console_loglevel,
704 .maxlen = 4*sizeof(int),
706 .proc_handler = &proc_dointvec,
709 .ctl_name = KERN_PRINTK_RATELIMIT,
710 .procname = "printk_ratelimit",
711 .data = &printk_ratelimit_state.interval,
712 .maxlen = sizeof(int),
714 .proc_handler = &proc_dointvec_jiffies,
715 .strategy = &sysctl_jiffies,
718 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
719 .procname = "printk_ratelimit_burst",
720 .data = &printk_ratelimit_state.burst,
721 .maxlen = sizeof(int),
723 .proc_handler = &proc_dointvec,
727 .ctl_name = KERN_NGROUPS_MAX,
728 .procname = "ngroups_max",
729 .data = &ngroups_max,
730 .maxlen = sizeof (int),
732 .proc_handler = &proc_dointvec,
734 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
736 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
737 .procname = "unknown_nmi_panic",
738 .data = &unknown_nmi_panic,
739 .maxlen = sizeof (int),
741 .proc_handler = &proc_dointvec,
744 .procname = "nmi_watchdog",
745 .data = &nmi_watchdog_enabled,
746 .maxlen = sizeof (int),
748 .proc_handler = &proc_nmi_enabled,
751 #if defined(CONFIG_X86)
753 .ctl_name = KERN_PANIC_ON_NMI,
754 .procname = "panic_on_unrecovered_nmi",
755 .data = &panic_on_unrecovered_nmi,
756 .maxlen = sizeof(int),
758 .proc_handler = &proc_dointvec,
761 .ctl_name = CTL_UNNUMBERED,
762 .procname = "panic_on_io_nmi",
763 .data = &panic_on_io_nmi,
764 .maxlen = sizeof(int),
766 .proc_handler = &proc_dointvec,
769 .ctl_name = KERN_BOOTLOADER_TYPE,
770 .procname = "bootloader_type",
771 .data = &bootloader_type,
772 .maxlen = sizeof (int),
774 .proc_handler = &proc_dointvec,
777 .ctl_name = CTL_UNNUMBERED,
778 .procname = "bootloader_version",
779 .data = &bootloader_version,
780 .maxlen = sizeof (int),
782 .proc_handler = &proc_dointvec,
785 .ctl_name = CTL_UNNUMBERED,
786 .procname = "kstack_depth_to_print",
787 .data = &kstack_depth_to_print,
788 .maxlen = sizeof(int),
790 .proc_handler = &proc_dointvec,
793 .ctl_name = CTL_UNNUMBERED,
794 .procname = "io_delay_type",
795 .data = &io_delay_type,
796 .maxlen = sizeof(int),
798 .proc_handler = &proc_dointvec,
801 #if defined(CONFIG_MMU)
803 .ctl_name = KERN_RANDOMIZE,
804 .procname = "randomize_va_space",
805 .data = &randomize_va_space,
806 .maxlen = sizeof(int),
808 .proc_handler = &proc_dointvec,
811 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
813 .ctl_name = KERN_SPIN_RETRY,
814 .procname = "spin_retry",
816 .maxlen = sizeof (int),
818 .proc_handler = &proc_dointvec,
821 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
823 .procname = "acpi_video_flags",
824 .data = &acpi_realmode_flags,
825 .maxlen = sizeof (unsigned long),
827 .proc_handler = &proc_doulongvec_minmax,
832 .ctl_name = KERN_IA64_UNALIGNED,
833 .procname = "ignore-unaligned-usertrap",
834 .data = &no_unaligned_warning,
835 .maxlen = sizeof (int),
837 .proc_handler = &proc_dointvec,
840 .ctl_name = CTL_UNNUMBERED,
841 .procname = "unaligned-dump-stack",
842 .data = &unaligned_dump_stack,
843 .maxlen = sizeof (int),
845 .proc_handler = &proc_dointvec,
848 #ifdef CONFIG_DETECT_SOFTLOCKUP
850 .ctl_name = CTL_UNNUMBERED,
851 .procname = "softlockup_panic",
852 .data = &softlockup_panic,
853 .maxlen = sizeof(int),
855 .proc_handler = &proc_dointvec_minmax,
856 .strategy = &sysctl_intvec,
861 .ctl_name = CTL_UNNUMBERED,
862 .procname = "softlockup_thresh",
863 .data = &softlockup_thresh,
864 .maxlen = sizeof(int),
866 .proc_handler = &proc_dosoftlockup_thresh,
867 .strategy = &sysctl_intvec,
872 #ifdef CONFIG_DETECT_HUNG_TASK
874 .ctl_name = CTL_UNNUMBERED,
875 .procname = "hung_task_panic",
876 .data = &sysctl_hung_task_panic,
877 .maxlen = sizeof(int),
879 .proc_handler = &proc_dointvec_minmax,
880 .strategy = &sysctl_intvec,
885 .ctl_name = CTL_UNNUMBERED,
886 .procname = "hung_task_check_count",
887 .data = &sysctl_hung_task_check_count,
888 .maxlen = sizeof(unsigned long),
890 .proc_handler = &proc_doulongvec_minmax,
891 .strategy = &sysctl_intvec,
894 .ctl_name = CTL_UNNUMBERED,
895 .procname = "hung_task_timeout_secs",
896 .data = &sysctl_hung_task_timeout_secs,
897 .maxlen = sizeof(unsigned long),
899 .proc_handler = &proc_dohung_task_timeout_secs,
900 .strategy = &sysctl_intvec,
903 .ctl_name = CTL_UNNUMBERED,
904 .procname = "hung_task_warnings",
905 .data = &sysctl_hung_task_warnings,
906 .maxlen = sizeof(unsigned long),
908 .proc_handler = &proc_doulongvec_minmax,
909 .strategy = &sysctl_intvec,
914 .ctl_name = KERN_COMPAT_LOG,
915 .procname = "compat-log",
917 .maxlen = sizeof (int),
919 .proc_handler = &proc_dointvec,
922 #ifdef CONFIG_RT_MUTEXES
924 .ctl_name = KERN_MAX_LOCK_DEPTH,
925 .procname = "max_lock_depth",
926 .data = &max_lock_depth,
927 .maxlen = sizeof(int),
929 .proc_handler = &proc_dointvec,
933 .ctl_name = CTL_UNNUMBERED,
934 .procname = "poweroff_cmd",
935 .data = &poweroff_cmd,
936 .maxlen = POWEROFF_CMD_PATH_LEN,
938 .proc_handler = &proc_dostring,
939 .strategy = &sysctl_string,
943 .ctl_name = CTL_UNNUMBERED,
946 .child = key_sysctls,
949 #ifdef CONFIG_RCU_TORTURE_TEST
951 .ctl_name = CTL_UNNUMBERED,
952 .procname = "rcutorture_runnable",
953 .data = &rcutorture_runnable,
954 .maxlen = sizeof(int),
956 .proc_handler = &proc_dointvec,
959 #ifdef CONFIG_SLOW_WORK
961 .ctl_name = CTL_UNNUMBERED,
962 .procname = "slow-work",
964 .child = slow_work_sysctls,
967 #ifdef CONFIG_PERF_EVENTS
969 .ctl_name = CTL_UNNUMBERED,
970 .procname = "perf_event_paranoid",
971 .data = &sysctl_perf_event_paranoid,
972 .maxlen = sizeof(sysctl_perf_event_paranoid),
974 .proc_handler = &proc_dointvec,
977 .ctl_name = CTL_UNNUMBERED,
978 .procname = "perf_event_mlock_kb",
979 .data = &sysctl_perf_event_mlock,
980 .maxlen = sizeof(sysctl_perf_event_mlock),
982 .proc_handler = &proc_dointvec,
985 .ctl_name = CTL_UNNUMBERED,
986 .procname = "perf_event_max_sample_rate",
987 .data = &sysctl_perf_event_sample_rate,
988 .maxlen = sizeof(sysctl_perf_event_sample_rate),
990 .proc_handler = &proc_dointvec,
993 #ifdef CONFIG_KMEMCHECK
995 .ctl_name = CTL_UNNUMBERED,
996 .procname = "kmemcheck",
997 .data = &kmemcheck_enabled,
998 .maxlen = sizeof(int),
1000 .proc_handler = &proc_dointvec,
1005 .ctl_name = CTL_UNNUMBERED,
1006 .procname = "blk_iopoll",
1007 .data = &blk_iopoll_enabled,
1008 .maxlen = sizeof(int),
1010 .proc_handler = &proc_dointvec,
1014 * NOTE: do not add new entries to this table unless you have read
1015 * Documentation/sysctl/ctl_unnumbered.txt
1020 static struct ctl_table vm_table[] = {
1022 .ctl_name = VM_OVERCOMMIT_MEMORY,
1023 .procname = "overcommit_memory",
1024 .data = &sysctl_overcommit_memory,
1025 .maxlen = sizeof(sysctl_overcommit_memory),
1027 .proc_handler = &proc_dointvec,
1030 .ctl_name = VM_PANIC_ON_OOM,
1031 .procname = "panic_on_oom",
1032 .data = &sysctl_panic_on_oom,
1033 .maxlen = sizeof(sysctl_panic_on_oom),
1035 .proc_handler = &proc_dointvec,
1038 .ctl_name = CTL_UNNUMBERED,
1039 .procname = "oom_kill_allocating_task",
1040 .data = &sysctl_oom_kill_allocating_task,
1041 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1043 .proc_handler = &proc_dointvec,
1046 .ctl_name = CTL_UNNUMBERED,
1047 .procname = "oom_dump_tasks",
1048 .data = &sysctl_oom_dump_tasks,
1049 .maxlen = sizeof(sysctl_oom_dump_tasks),
1051 .proc_handler = &proc_dointvec,
1054 .ctl_name = VM_OVERCOMMIT_RATIO,
1055 .procname = "overcommit_ratio",
1056 .data = &sysctl_overcommit_ratio,
1057 .maxlen = sizeof(sysctl_overcommit_ratio),
1059 .proc_handler = &proc_dointvec,
1062 .ctl_name = VM_PAGE_CLUSTER,
1063 .procname = "page-cluster",
1064 .data = &page_cluster,
1065 .maxlen = sizeof(int),
1067 .proc_handler = &proc_dointvec,
1070 .ctl_name = VM_DIRTY_BACKGROUND,
1071 .procname = "dirty_background_ratio",
1072 .data = &dirty_background_ratio,
1073 .maxlen = sizeof(dirty_background_ratio),
1075 .proc_handler = &dirty_background_ratio_handler,
1076 .strategy = &sysctl_intvec,
1078 .extra2 = &one_hundred,
1081 .ctl_name = CTL_UNNUMBERED,
1082 .procname = "dirty_background_bytes",
1083 .data = &dirty_background_bytes,
1084 .maxlen = sizeof(dirty_background_bytes),
1086 .proc_handler = &dirty_background_bytes_handler,
1087 .strategy = &sysctl_intvec,
1091 .ctl_name = VM_DIRTY_RATIO,
1092 .procname = "dirty_ratio",
1093 .data = &vm_dirty_ratio,
1094 .maxlen = sizeof(vm_dirty_ratio),
1096 .proc_handler = &dirty_ratio_handler,
1097 .strategy = &sysctl_intvec,
1099 .extra2 = &one_hundred,
1102 .ctl_name = CTL_UNNUMBERED,
1103 .procname = "dirty_bytes",
1104 .data = &vm_dirty_bytes,
1105 .maxlen = sizeof(vm_dirty_bytes),
1107 .proc_handler = &dirty_bytes_handler,
1108 .strategy = &sysctl_intvec,
1109 .extra1 = &dirty_bytes_min,
1112 .procname = "dirty_writeback_centisecs",
1113 .data = &dirty_writeback_interval,
1114 .maxlen = sizeof(dirty_writeback_interval),
1116 .proc_handler = &dirty_writeback_centisecs_handler,
1119 .procname = "dirty_expire_centisecs",
1120 .data = &dirty_expire_interval,
1121 .maxlen = sizeof(dirty_expire_interval),
1123 .proc_handler = &proc_dointvec,
1126 .ctl_name = VM_NR_PDFLUSH_THREADS,
1127 .procname = "nr_pdflush_threads",
1128 .data = &nr_pdflush_threads,
1129 .maxlen = sizeof nr_pdflush_threads,
1130 .mode = 0444 /* read-only*/,
1131 .proc_handler = &proc_dointvec,
1134 .ctl_name = VM_SWAPPINESS,
1135 .procname = "swappiness",
1136 .data = &vm_swappiness,
1137 .maxlen = sizeof(vm_swappiness),
1139 .proc_handler = &proc_dointvec_minmax,
1140 .strategy = &sysctl_intvec,
1142 .extra2 = &one_hundred,
1144 #ifdef CONFIG_HUGETLB_PAGE
1146 .procname = "nr_hugepages",
1148 .maxlen = sizeof(unsigned long),
1150 .proc_handler = &hugetlb_sysctl_handler,
1151 .extra1 = (void *)&hugetlb_zero,
1152 .extra2 = (void *)&hugetlb_infinity,
1155 .ctl_name = VM_HUGETLB_GROUP,
1156 .procname = "hugetlb_shm_group",
1157 .data = &sysctl_hugetlb_shm_group,
1158 .maxlen = sizeof(gid_t),
1160 .proc_handler = &proc_dointvec,
1163 .ctl_name = CTL_UNNUMBERED,
1164 .procname = "hugepages_treat_as_movable",
1165 .data = &hugepages_treat_as_movable,
1166 .maxlen = sizeof(int),
1168 .proc_handler = &hugetlb_treat_movable_handler,
1171 .ctl_name = CTL_UNNUMBERED,
1172 .procname = "nr_overcommit_hugepages",
1174 .maxlen = sizeof(unsigned long),
1176 .proc_handler = &hugetlb_overcommit_handler,
1177 .extra1 = (void *)&hugetlb_zero,
1178 .extra2 = (void *)&hugetlb_infinity,
1182 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1183 .procname = "lowmem_reserve_ratio",
1184 .data = &sysctl_lowmem_reserve_ratio,
1185 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1187 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1188 .strategy = &sysctl_intvec,
1191 .ctl_name = VM_DROP_PAGECACHE,
1192 .procname = "drop_caches",
1193 .data = &sysctl_drop_caches,
1194 .maxlen = sizeof(int),
1196 .proc_handler = drop_caches_sysctl_handler,
1197 .strategy = &sysctl_intvec,
1200 .ctl_name = VM_MIN_FREE_KBYTES,
1201 .procname = "min_free_kbytes",
1202 .data = &min_free_kbytes,
1203 .maxlen = sizeof(min_free_kbytes),
1205 .proc_handler = &min_free_kbytes_sysctl_handler,
1206 .strategy = &sysctl_intvec,
1210 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1211 .procname = "percpu_pagelist_fraction",
1212 .data = &percpu_pagelist_fraction,
1213 .maxlen = sizeof(percpu_pagelist_fraction),
1215 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1216 .strategy = &sysctl_intvec,
1217 .extra1 = &min_percpu_pagelist_fract,
1221 .ctl_name = VM_MAX_MAP_COUNT,
1222 .procname = "max_map_count",
1223 .data = &sysctl_max_map_count,
1224 .maxlen = sizeof(sysctl_max_map_count),
1226 .proc_handler = &proc_dointvec
1230 .ctl_name = CTL_UNNUMBERED,
1231 .procname = "nr_trim_pages",
1232 .data = &sysctl_nr_trim_pages,
1233 .maxlen = sizeof(sysctl_nr_trim_pages),
1235 .proc_handler = &proc_dointvec_minmax,
1236 .strategy = &sysctl_intvec,
1241 .ctl_name = VM_LAPTOP_MODE,
1242 .procname = "laptop_mode",
1243 .data = &laptop_mode,
1244 .maxlen = sizeof(laptop_mode),
1246 .proc_handler = &proc_dointvec_jiffies,
1247 .strategy = &sysctl_jiffies,
1250 .ctl_name = VM_BLOCK_DUMP,
1251 .procname = "block_dump",
1252 .data = &block_dump,
1253 .maxlen = sizeof(block_dump),
1255 .proc_handler = &proc_dointvec,
1256 .strategy = &sysctl_intvec,
1260 .ctl_name = VM_VFS_CACHE_PRESSURE,
1261 .procname = "vfs_cache_pressure",
1262 .data = &sysctl_vfs_cache_pressure,
1263 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1265 .proc_handler = &proc_dointvec,
1266 .strategy = &sysctl_intvec,
1269 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1271 .ctl_name = VM_LEGACY_VA_LAYOUT,
1272 .procname = "legacy_va_layout",
1273 .data = &sysctl_legacy_va_layout,
1274 .maxlen = sizeof(sysctl_legacy_va_layout),
1276 .proc_handler = &proc_dointvec,
1277 .strategy = &sysctl_intvec,
1283 .ctl_name = VM_ZONE_RECLAIM_MODE,
1284 .procname = "zone_reclaim_mode",
1285 .data = &zone_reclaim_mode,
1286 .maxlen = sizeof(zone_reclaim_mode),
1288 .proc_handler = &proc_dointvec,
1289 .strategy = &sysctl_intvec,
1293 .ctl_name = VM_MIN_UNMAPPED,
1294 .procname = "min_unmapped_ratio",
1295 .data = &sysctl_min_unmapped_ratio,
1296 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1298 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1299 .strategy = &sysctl_intvec,
1301 .extra2 = &one_hundred,
1304 .ctl_name = VM_MIN_SLAB,
1305 .procname = "min_slab_ratio",
1306 .data = &sysctl_min_slab_ratio,
1307 .maxlen = sizeof(sysctl_min_slab_ratio),
1309 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1310 .strategy = &sysctl_intvec,
1312 .extra2 = &one_hundred,
1317 .ctl_name = CTL_UNNUMBERED,
1318 .procname = "stat_interval",
1319 .data = &sysctl_stat_interval,
1320 .maxlen = sizeof(sysctl_stat_interval),
1322 .proc_handler = &proc_dointvec_jiffies,
1323 .strategy = &sysctl_jiffies,
1327 .ctl_name = CTL_UNNUMBERED,
1328 .procname = "mmap_min_addr",
1329 .data = &dac_mmap_min_addr,
1330 .maxlen = sizeof(unsigned long),
1332 .proc_handler = &mmap_min_addr_handler,
1336 .ctl_name = CTL_UNNUMBERED,
1337 .procname = "numa_zonelist_order",
1338 .data = &numa_zonelist_order,
1339 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1341 .proc_handler = &numa_zonelist_order_handler,
1342 .strategy = &sysctl_string,
1345 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1346 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1348 .ctl_name = VM_VDSO_ENABLED,
1349 .procname = "vdso_enabled",
1350 .data = &vdso_enabled,
1351 .maxlen = sizeof(vdso_enabled),
1353 .proc_handler = &proc_dointvec,
1354 .strategy = &sysctl_intvec,
1358 #ifdef CONFIG_HIGHMEM
1360 .ctl_name = CTL_UNNUMBERED,
1361 .procname = "highmem_is_dirtyable",
1362 .data = &vm_highmem_is_dirtyable,
1363 .maxlen = sizeof(vm_highmem_is_dirtyable),
1365 .proc_handler = &proc_dointvec_minmax,
1366 .strategy = &sysctl_intvec,
1372 .ctl_name = CTL_UNNUMBERED,
1373 .procname = "scan_unevictable_pages",
1374 .data = &scan_unevictable_pages,
1375 .maxlen = sizeof(scan_unevictable_pages),
1377 .proc_handler = &scan_unevictable_handler,
1380 * NOTE: do not add new entries to this table unless you have read
1381 * Documentation/sysctl/ctl_unnumbered.txt
1386 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1387 static struct ctl_table binfmt_misc_table[] = {
1392 static struct ctl_table fs_table[] = {
1394 .ctl_name = FS_NRINODE,
1395 .procname = "inode-nr",
1396 .data = &inodes_stat,
1397 .maxlen = 2*sizeof(int),
1399 .proc_handler = &proc_dointvec,
1402 .ctl_name = FS_STATINODE,
1403 .procname = "inode-state",
1404 .data = &inodes_stat,
1405 .maxlen = 7*sizeof(int),
1407 .proc_handler = &proc_dointvec,
1410 .procname = "file-nr",
1411 .data = &files_stat,
1412 .maxlen = 3*sizeof(int),
1414 .proc_handler = &proc_nr_files,
1417 .ctl_name = FS_MAXFILE,
1418 .procname = "file-max",
1419 .data = &files_stat.max_files,
1420 .maxlen = sizeof(int),
1422 .proc_handler = &proc_dointvec,
1425 .ctl_name = CTL_UNNUMBERED,
1426 .procname = "nr_open",
1427 .data = &sysctl_nr_open,
1428 .maxlen = sizeof(int),
1430 .proc_handler = &proc_dointvec_minmax,
1431 .extra1 = &sysctl_nr_open_min,
1432 .extra2 = &sysctl_nr_open_max,
1435 .ctl_name = FS_DENTRY,
1436 .procname = "dentry-state",
1437 .data = &dentry_stat,
1438 .maxlen = 6*sizeof(int),
1440 .proc_handler = &proc_dointvec,
1443 .ctl_name = FS_OVERFLOWUID,
1444 .procname = "overflowuid",
1445 .data = &fs_overflowuid,
1446 .maxlen = sizeof(int),
1448 .proc_handler = &proc_dointvec_minmax,
1449 .strategy = &sysctl_intvec,
1450 .extra1 = &minolduid,
1451 .extra2 = &maxolduid,
1454 .ctl_name = FS_OVERFLOWGID,
1455 .procname = "overflowgid",
1456 .data = &fs_overflowgid,
1457 .maxlen = sizeof(int),
1459 .proc_handler = &proc_dointvec_minmax,
1460 .strategy = &sysctl_intvec,
1461 .extra1 = &minolduid,
1462 .extra2 = &maxolduid,
1464 #ifdef CONFIG_FILE_LOCKING
1466 .ctl_name = FS_LEASES,
1467 .procname = "leases-enable",
1468 .data = &leases_enable,
1469 .maxlen = sizeof(int),
1471 .proc_handler = &proc_dointvec,
1474 #ifdef CONFIG_DNOTIFY
1476 .ctl_name = FS_DIR_NOTIFY,
1477 .procname = "dir-notify-enable",
1478 .data = &dir_notify_enable,
1479 .maxlen = sizeof(int),
1481 .proc_handler = &proc_dointvec,
1485 #ifdef CONFIG_FILE_LOCKING
1487 .ctl_name = FS_LEASE_TIME,
1488 .procname = "lease-break-time",
1489 .data = &lease_break_time,
1490 .maxlen = sizeof(int),
1492 .proc_handler = &proc_dointvec,
1497 .procname = "aio-nr",
1499 .maxlen = sizeof(aio_nr),
1501 .proc_handler = &proc_doulongvec_minmax,
1504 .procname = "aio-max-nr",
1505 .data = &aio_max_nr,
1506 .maxlen = sizeof(aio_max_nr),
1508 .proc_handler = &proc_doulongvec_minmax,
1510 #endif /* CONFIG_AIO */
1511 #ifdef CONFIG_INOTIFY_USER
1513 .ctl_name = FS_INOTIFY,
1514 .procname = "inotify",
1516 .child = inotify_table,
1521 .procname = "epoll",
1523 .child = epoll_table,
1528 .ctl_name = KERN_SETUID_DUMPABLE,
1529 .procname = "suid_dumpable",
1530 .data = &suid_dumpable,
1531 .maxlen = sizeof(int),
1533 .proc_handler = &proc_dointvec_minmax,
1534 .strategy = &sysctl_intvec,
1538 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1540 .ctl_name = CTL_UNNUMBERED,
1541 .procname = "binfmt_misc",
1543 .child = binfmt_misc_table,
1547 * NOTE: do not add new entries to this table unless you have read
1548 * Documentation/sysctl/ctl_unnumbered.txt
1553 static struct ctl_table debug_table[] = {
1554 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1556 .ctl_name = CTL_UNNUMBERED,
1557 .procname = "exception-trace",
1558 .data = &show_unhandled_signals,
1559 .maxlen = sizeof(int),
1561 .proc_handler = proc_dointvec
1567 static struct ctl_table dev_table[] = {
1571 static DEFINE_SPINLOCK(sysctl_lock);
1573 /* called under sysctl_lock */
1574 static int use_table(struct ctl_table_header *p)
1576 if (unlikely(p->unregistering))
1582 /* called under sysctl_lock */
1583 static void unuse_table(struct ctl_table_header *p)
1586 if (unlikely(p->unregistering))
1587 complete(p->unregistering);
1590 /* called under sysctl_lock, will reacquire if has to wait */
1591 static void start_unregistering(struct ctl_table_header *p)
1594 * if p->used is 0, nobody will ever touch that entry again;
1595 * we'll eliminate all paths to it before dropping sysctl_lock
1597 if (unlikely(p->used)) {
1598 struct completion wait;
1599 init_completion(&wait);
1600 p->unregistering = &wait;
1601 spin_unlock(&sysctl_lock);
1602 wait_for_completion(&wait);
1603 spin_lock(&sysctl_lock);
1605 /* anything non-NULL; we'll never dereference it */
1606 p->unregistering = ERR_PTR(-EINVAL);
1609 * do not remove from the list until nobody holds it; walking the
1610 * list in do_sysctl() relies on that.
1612 list_del_init(&p->ctl_entry);
1615 void sysctl_head_get(struct ctl_table_header *head)
1617 spin_lock(&sysctl_lock);
1619 spin_unlock(&sysctl_lock);
1622 void sysctl_head_put(struct ctl_table_header *head)
1624 spin_lock(&sysctl_lock);
1627 spin_unlock(&sysctl_lock);
1630 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1634 spin_lock(&sysctl_lock);
1635 if (!use_table(head))
1636 head = ERR_PTR(-ENOENT);
1637 spin_unlock(&sysctl_lock);
1641 void sysctl_head_finish(struct ctl_table_header *head)
1645 spin_lock(&sysctl_lock);
1647 spin_unlock(&sysctl_lock);
1650 static struct ctl_table_set *
1651 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1653 struct ctl_table_set *set = &root->default_set;
1655 set = root->lookup(root, namespaces);
1659 static struct list_head *
1660 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1662 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1666 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1667 struct ctl_table_header *prev)
1669 struct ctl_table_root *root;
1670 struct list_head *header_list;
1671 struct ctl_table_header *head;
1672 struct list_head *tmp;
1674 spin_lock(&sysctl_lock);
1677 tmp = &prev->ctl_entry;
1681 tmp = &root_table_header.ctl_entry;
1683 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1685 if (!use_table(head))
1687 spin_unlock(&sysctl_lock);
1692 header_list = lookup_header_list(root, namespaces);
1693 if (tmp != header_list)
1697 root = list_entry(root->root_list.next,
1698 struct ctl_table_root, root_list);
1699 if (root == &sysctl_table_root)
1701 header_list = lookup_header_list(root, namespaces);
1702 } while (list_empty(header_list));
1703 tmp = header_list->next;
1706 spin_unlock(&sysctl_lock);
1710 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1712 return __sysctl_head_next(current->nsproxy, prev);
1715 void register_sysctl_root(struct ctl_table_root *root)
1717 spin_lock(&sysctl_lock);
1718 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1719 spin_unlock(&sysctl_lock);
1722 #ifdef CONFIG_SYSCTL_SYSCALL
1723 /* Perform the actual read/write of a sysctl table entry. */
1724 static int do_sysctl_strategy(struct ctl_table_root *root,
1725 struct ctl_table *table,
1726 void __user *oldval, size_t __user *oldlenp,
1727 void __user *newval, size_t newlen)
1735 if (sysctl_perm(root, table, op))
1738 if (table->strategy) {
1739 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1746 /* If there is no strategy routine, or if the strategy returns
1747 * zero, proceed with automatic r/w */
1748 if (table->data && table->maxlen) {
1749 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1756 static int parse_table(int __user *name, int nlen,
1757 void __user *oldval, size_t __user *oldlenp,
1758 void __user *newval, size_t newlen,
1759 struct ctl_table_root *root,
1760 struct ctl_table *table)
1766 if (get_user(n, name))
1768 for ( ; table->ctl_name || table->procname; table++) {
1769 if (!table->ctl_name)
1771 if (n == table->ctl_name) {
1774 if (sysctl_perm(root, table, MAY_EXEC))
1778 table = table->child;
1781 error = do_sysctl_strategy(root, table,
1790 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1791 void __user *newval, size_t newlen)
1793 struct ctl_table_header *head;
1794 int error = -ENOTDIR;
1796 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1800 if (!oldlenp || get_user(old_len, oldlenp))
1804 for (head = sysctl_head_next(NULL); head;
1805 head = sysctl_head_next(head)) {
1806 error = parse_table(name, nlen, oldval, oldlenp,
1808 head->root, head->ctl_table);
1809 if (error != -ENOTDIR) {
1810 sysctl_head_finish(head);
1817 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1819 struct __sysctl_args tmp;
1822 if (copy_from_user(&tmp, args, sizeof(tmp)))
1825 error = deprecated_sysctl_warning(&tmp);
1830 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1831 tmp.newval, tmp.newlen);
1836 #endif /* CONFIG_SYSCTL_SYSCALL */
1839 * sysctl_perm does NOT grant the superuser all rights automatically, because
1840 * some sysctl variables are readonly even to root.
1843 static int test_perm(int mode, int op)
1845 if (!current_euid())
1847 else if (in_egroup_p(0))
1849 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1854 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1859 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1863 if (root->permissions)
1864 mode = root->permissions(root, current->nsproxy, table);
1868 return test_perm(mode, op);
1871 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1873 for (; table->ctl_name || table->procname; table++) {
1874 table->parent = parent;
1876 sysctl_set_parent(table, table->child);
1880 static __init int sysctl_init(void)
1882 sysctl_set_parent(NULL, root_table);
1883 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1886 err = sysctl_check_table(current->nsproxy, root_table);
1892 core_initcall(sysctl_init);
1894 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1895 struct ctl_table *table)
1897 struct ctl_table *p;
1898 const char *s = branch->procname;
1900 /* branch should have named subdirectory as its first element */
1901 if (!s || !branch->child)
1904 /* ... and nothing else */
1905 if (branch[1].procname || branch[1].ctl_name)
1908 /* table should contain subdirectory with the same name */
1909 for (p = table; p->procname || p->ctl_name; p++) {
1912 if (p->procname && strcmp(p->procname, s) == 0)
1918 /* see if attaching q to p would be an improvement */
1919 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1921 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1922 struct ctl_table *next;
1924 int not_in_parent = !p->attached_by;
1926 while ((next = is_branch_in(by, to)) != NULL) {
1927 if (by == q->attached_by)
1929 if (to == p->attached_by)
1935 if (is_better && not_in_parent) {
1936 q->attached_by = by;
1937 q->attached_to = to;
1943 * __register_sysctl_paths - register a sysctl hierarchy
1944 * @root: List of sysctl headers to register on
1945 * @namespaces: Data to compute which lists of sysctl entries are visible
1946 * @path: The path to the directory the sysctl table is in.
1947 * @table: the top-level table structure
1949 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1950 * array. A completely 0 filled entry terminates the table.
1952 * The members of the &struct ctl_table structure are used as follows:
1954 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1955 * must be unique within that level of sysctl
1957 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1958 * enter a sysctl file
1960 * data - a pointer to data for use by proc_handler
1962 * maxlen - the maximum size in bytes of the data
1964 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1966 * child - a pointer to the child sysctl table if this entry is a directory, or
1969 * proc_handler - the text handler routine (described below)
1971 * strategy - the strategy routine (described below)
1973 * de - for internal use by the sysctl routines
1975 * extra1, extra2 - extra pointers usable by the proc handler routines
1977 * Leaf nodes in the sysctl tree will be represented by a single file
1978 * under /proc; non-leaf nodes will be represented by directories.
1980 * sysctl(2) can automatically manage read and write requests through
1981 * the sysctl table. The data and maxlen fields of the ctl_table
1982 * struct enable minimal validation of the values being written to be
1983 * performed, and the mode field allows minimal authentication.
1985 * More sophisticated management can be enabled by the provision of a
1986 * strategy routine with the table entry. This will be called before
1987 * any automatic read or write of the data is performed.
1989 * The strategy routine may return
1991 * < 0 - Error occurred (error is passed to user process)
1993 * 0 - OK - proceed with automatic read or write.
1995 * > 0 - OK - read or write has been done by the strategy routine, so
1996 * return immediately.
1998 * There must be a proc_handler routine for any terminal nodes
1999 * mirrored under /proc/sys (non-terminals are handled by a built-in
2000 * directory handler). Several default handlers are available to
2001 * cover common cases -
2003 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2004 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2005 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2007 * It is the handler's job to read the input buffer from user memory
2008 * and process it. The handler should return 0 on success.
2010 * This routine returns %NULL on a failure to register, and a pointer
2011 * to the table header on success.
2013 struct ctl_table_header *__register_sysctl_paths(
2014 struct ctl_table_root *root,
2015 struct nsproxy *namespaces,
2016 const struct ctl_path *path, struct ctl_table *table)
2018 struct ctl_table_header *header;
2019 struct ctl_table *new, **prevp;
2020 unsigned int n, npath;
2021 struct ctl_table_set *set;
2023 /* Count the path components */
2024 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2028 * For each path component, allocate a 2-element ctl_table array.
2029 * The first array element will be filled with the sysctl entry
2030 * for this, the second will be the sentinel (ctl_name == 0).
2032 * We allocate everything in one go so that we don't have to
2033 * worry about freeing additional memory in unregister_sysctl_table.
2035 header = kzalloc(sizeof(struct ctl_table_header) +
2036 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2040 new = (struct ctl_table *) (header + 1);
2042 /* Now connect the dots */
2043 prevp = &header->ctl_table;
2044 for (n = 0; n < npath; ++n, ++path) {
2045 /* Copy the procname */
2046 new->procname = path->procname;
2047 new->ctl_name = path->ctl_name;
2051 prevp = &new->child;
2056 header->ctl_table_arg = table;
2058 INIT_LIST_HEAD(&header->ctl_entry);
2060 header->unregistering = NULL;
2061 header->root = root;
2062 sysctl_set_parent(NULL, header->ctl_table);
2064 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2065 if (sysctl_check_table(namespaces, header->ctl_table)) {
2070 spin_lock(&sysctl_lock);
2071 header->set = lookup_header_set(root, namespaces);
2072 header->attached_by = header->ctl_table;
2073 header->attached_to = root_table;
2074 header->parent = &root_table_header;
2075 for (set = header->set; set; set = set->parent) {
2076 struct ctl_table_header *p;
2077 list_for_each_entry(p, &set->list, ctl_entry) {
2078 if (p->unregistering)
2080 try_attach(p, header);
2083 header->parent->count++;
2084 list_add_tail(&header->ctl_entry, &header->set->list);
2085 spin_unlock(&sysctl_lock);
2091 * register_sysctl_table_path - register a sysctl table hierarchy
2092 * @path: The path to the directory the sysctl table is in.
2093 * @table: the top-level table structure
2095 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2096 * array. A completely 0 filled entry terminates the table.
2098 * See __register_sysctl_paths for more details.
2100 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2101 struct ctl_table *table)
2103 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2108 * register_sysctl_table - register a sysctl table hierarchy
2109 * @table: the top-level table structure
2111 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2112 * array. A completely 0 filled entry terminates the table.
2114 * See register_sysctl_paths for more details.
2116 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2118 static const struct ctl_path null_path[] = { {} };
2120 return register_sysctl_paths(null_path, table);
2124 * unregister_sysctl_table - unregister a sysctl table hierarchy
2125 * @header: the header returned from register_sysctl_table
2127 * Unregisters the sysctl table and all children. proc entries may not
2128 * actually be removed until they are no longer used by anyone.
2130 void unregister_sysctl_table(struct ctl_table_header * header)
2137 spin_lock(&sysctl_lock);
2138 start_unregistering(header);
2139 if (!--header->parent->count) {
2141 kfree(header->parent);
2143 if (!--header->count)
2145 spin_unlock(&sysctl_lock);
2148 int sysctl_is_seen(struct ctl_table_header *p)
2150 struct ctl_table_set *set = p->set;
2152 spin_lock(&sysctl_lock);
2153 if (p->unregistering)
2155 else if (!set->is_seen)
2158 res = set->is_seen(set);
2159 spin_unlock(&sysctl_lock);
2163 void setup_sysctl_set(struct ctl_table_set *p,
2164 struct ctl_table_set *parent,
2165 int (*is_seen)(struct ctl_table_set *))
2167 INIT_LIST_HEAD(&p->list);
2168 p->parent = parent ? parent : &sysctl_table_root.default_set;
2169 p->is_seen = is_seen;
2172 #else /* !CONFIG_SYSCTL */
2173 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2178 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2179 struct ctl_table *table)
2184 void unregister_sysctl_table(struct ctl_table_header * table)
2188 void setup_sysctl_set(struct ctl_table_set *p,
2189 struct ctl_table_set *parent,
2190 int (*is_seen)(struct ctl_table_set *))
2194 void sysctl_head_put(struct ctl_table_header *head)
2198 #endif /* CONFIG_SYSCTL */
2204 #ifdef CONFIG_PROC_SYSCTL
2206 static int _proc_do_string(void* data, int maxlen, int write,
2207 struct file *filp, void __user *buffer,
2208 size_t *lenp, loff_t *ppos)
2214 if (!data || !maxlen || !*lenp) {
2222 while (len < *lenp) {
2223 if (get_user(c, p++))
2225 if (c == 0 || c == '\n')
2231 if(copy_from_user(data, buffer, len))
2233 ((char *) data)[len] = 0;
2251 if(copy_to_user(buffer, data, len))
2254 if(put_user('\n', ((char __user *) buffer) + len))
2265 * proc_dostring - read a string sysctl
2266 * @table: the sysctl table
2267 * @write: %TRUE if this is a write to the sysctl file
2268 * @filp: the file structure
2269 * @buffer: the user buffer
2270 * @lenp: the size of the user buffer
2271 * @ppos: file position
2273 * Reads/writes a string from/to the user buffer. If the kernel
2274 * buffer provided is not large enough to hold the string, the
2275 * string is truncated. The copied string is %NULL-terminated.
2276 * If the string is being read by the user process, it is copied
2277 * and a newline '\n' is added. It is truncated if the buffer is
2280 * Returns 0 on success.
2282 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2283 void __user *buffer, size_t *lenp, loff_t *ppos)
2285 return _proc_do_string(table->data, table->maxlen, write, filp,
2286 buffer, lenp, ppos);
2290 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2292 int write, void *data)
2295 *valp = *negp ? -*lvalp : *lvalp;
2300 *lvalp = (unsigned long)-val;
2303 *lvalp = (unsigned long)val;
2309 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2310 int write, struct file *filp, void __user *buffer,
2311 size_t *lenp, loff_t *ppos,
2312 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2313 int write, void *data),
2316 #define TMPBUFLEN 21
2317 int *i, vleft, first = 1, neg;
2321 char buf[TMPBUFLEN], *p;
2322 char __user *s = buffer;
2324 if (!tbl_data || !table->maxlen || !*lenp ||
2325 (*ppos && !write)) {
2330 i = (int *) tbl_data;
2331 vleft = table->maxlen / sizeof(*i);
2335 conv = do_proc_dointvec_conv;
2337 for (; left && vleft--; i++, first=0) {
2352 if (len > sizeof(buf) - 1)
2353 len = sizeof(buf) - 1;
2354 if (copy_from_user(buf, s, len))
2358 if (*p == '-' && left > 1) {
2362 if (*p < '0' || *p > '9')
2365 lval = simple_strtoul(p, &p, 0);
2368 if ((len < left) && *p && !isspace(*p))
2373 if (conv(&neg, &lval, i, 1, data))
2380 if (conv(&neg, &lval, i, 0, data))
2383 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2387 if(copy_to_user(s, buf, len))
2394 if (!write && !first && left) {
2395 if(put_user('\n', s))
2402 if (get_user(c, s++))
2417 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2418 void __user *buffer, size_t *lenp, loff_t *ppos,
2419 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2420 int write, void *data),
2423 return __do_proc_dointvec(table->data, table, write, filp,
2424 buffer, lenp, ppos, conv, data);
2428 * proc_dointvec - read a vector of integers
2429 * @table: the sysctl table
2430 * @write: %TRUE if this is a write to the sysctl file
2431 * @filp: the file structure
2432 * @buffer: the user buffer
2433 * @lenp: the size of the user buffer
2434 * @ppos: file position
2436 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2437 * values from/to the user buffer, treated as an ASCII string.
2439 * Returns 0 on success.
2441 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2442 void __user *buffer, size_t *lenp, loff_t *ppos)
2444 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2449 * Taint values can only be increased
2450 * This means we can safely use a temporary.
2452 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2453 void __user *buffer, size_t *lenp, loff_t *ppos)
2456 unsigned long tmptaint = get_taint();
2459 if (write && !capable(CAP_SYS_ADMIN))
2464 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2470 * Poor man's atomic or. Not worth adding a primitive
2471 * to everyone's atomic.h for this
2474 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2475 if ((tmptaint >> i) & 1)
2483 struct do_proc_dointvec_minmax_conv_param {
2488 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2490 int write, void *data)
2492 struct do_proc_dointvec_minmax_conv_param *param = data;
2494 int val = *negp ? -*lvalp : *lvalp;
2495 if ((param->min && *param->min > val) ||
2496 (param->max && *param->max < val))
2503 *lvalp = (unsigned long)-val;
2506 *lvalp = (unsigned long)val;
2513 * proc_dointvec_minmax - read a vector of integers with min/max values
2514 * @table: the sysctl table
2515 * @write: %TRUE if this is a write to the sysctl file
2516 * @filp: the file structure
2517 * @buffer: the user buffer
2518 * @lenp: the size of the user buffer
2519 * @ppos: file position
2521 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2522 * values from/to the user buffer, treated as an ASCII string.
2524 * This routine will ensure the values are within the range specified by
2525 * table->extra1 (min) and table->extra2 (max).
2527 * Returns 0 on success.
2529 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2530 void __user *buffer, size_t *lenp, loff_t *ppos)
2532 struct do_proc_dointvec_minmax_conv_param param = {
2533 .min = (int *) table->extra1,
2534 .max = (int *) table->extra2,
2536 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2537 do_proc_dointvec_minmax_conv, ¶m);
2540 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2542 void __user *buffer,
2543 size_t *lenp, loff_t *ppos,
2544 unsigned long convmul,
2545 unsigned long convdiv)
2547 #define TMPBUFLEN 21
2548 unsigned long *i, *min, *max, val;
2549 int vleft, first=1, neg;
2551 char buf[TMPBUFLEN], *p;
2552 char __user *s = buffer;
2554 if (!data || !table->maxlen || !*lenp ||
2555 (*ppos && !write)) {
2560 i = (unsigned long *) data;
2561 min = (unsigned long *) table->extra1;
2562 max = (unsigned long *) table->extra2;
2563 vleft = table->maxlen / sizeof(unsigned long);
2566 for (; left && vleft--; i++, min++, max++, first=0) {
2581 if (len > TMPBUFLEN-1)
2583 if (copy_from_user(buf, s, len))
2587 if (*p == '-' && left > 1) {
2591 if (*p < '0' || *p > '9')
2593 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2595 if ((len < left) && *p && !isspace(*p))
2604 if ((min && val < *min) || (max && val > *max))
2611 sprintf(p, "%lu", convdiv * (*i) / convmul);
2615 if(copy_to_user(s, buf, len))
2622 if (!write && !first && left) {
2623 if(put_user('\n', s))
2630 if (get_user(c, s++))
2645 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2647 void __user *buffer,
2648 size_t *lenp, loff_t *ppos,
2649 unsigned long convmul,
2650 unsigned long convdiv)
2652 return __do_proc_doulongvec_minmax(table->data, table, write,
2653 filp, buffer, lenp, ppos, convmul, convdiv);
2657 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2658 * @table: the sysctl table
2659 * @write: %TRUE if this is a write to the sysctl file
2660 * @filp: the file structure
2661 * @buffer: the user buffer
2662 * @lenp: the size of the user buffer
2663 * @ppos: file position
2665 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2666 * values from/to the user buffer, treated as an ASCII string.
2668 * This routine will ensure the values are within the range specified by
2669 * table->extra1 (min) and table->extra2 (max).
2671 * Returns 0 on success.
2673 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2674 void __user *buffer, size_t *lenp, loff_t *ppos)
2676 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2680 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2681 * @table: the sysctl table
2682 * @write: %TRUE if this is a write to the sysctl file
2683 * @filp: the file structure
2684 * @buffer: the user buffer
2685 * @lenp: the size of the user buffer
2686 * @ppos: file position
2688 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2689 * values from/to the user buffer, treated as an ASCII string. The values
2690 * are treated as milliseconds, and converted to jiffies when they are stored.
2692 * This routine will ensure the values are within the range specified by
2693 * table->extra1 (min) and table->extra2 (max).
2695 * Returns 0 on success.
2697 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2699 void __user *buffer,
2700 size_t *lenp, loff_t *ppos)
2702 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2703 lenp, ppos, HZ, 1000l);
2707 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2709 int write, void *data)
2712 if (*lvalp > LONG_MAX / HZ)
2714 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2720 lval = (unsigned long)-val;
2723 lval = (unsigned long)val;
2730 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2732 int write, void *data)
2735 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2737 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2743 lval = (unsigned long)-val;
2746 lval = (unsigned long)val;
2748 *lvalp = jiffies_to_clock_t(lval);
2753 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2755 int write, void *data)
2758 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2764 lval = (unsigned long)-val;
2767 lval = (unsigned long)val;
2769 *lvalp = jiffies_to_msecs(lval);
2775 * proc_dointvec_jiffies - read a vector of integers as seconds
2776 * @table: the sysctl table
2777 * @write: %TRUE if this is a write to the sysctl file
2778 * @filp: the file structure
2779 * @buffer: the user buffer
2780 * @lenp: the size of the user buffer
2781 * @ppos: file position
2783 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2784 * values from/to the user buffer, treated as an ASCII string.
2785 * The values read are assumed to be in seconds, and are converted into
2788 * Returns 0 on success.
2790 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2791 void __user *buffer, size_t *lenp, loff_t *ppos)
2793 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2794 do_proc_dointvec_jiffies_conv,NULL);
2798 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2799 * @table: the sysctl table
2800 * @write: %TRUE if this is a write to the sysctl file
2801 * @filp: the file structure
2802 * @buffer: the user buffer
2803 * @lenp: the size of the user buffer
2804 * @ppos: pointer to the file position
2806 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2807 * values from/to the user buffer, treated as an ASCII string.
2808 * The values read are assumed to be in 1/USER_HZ seconds, and
2809 * are converted into jiffies.
2811 * Returns 0 on success.
2813 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2814 void __user *buffer, size_t *lenp, loff_t *ppos)
2816 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2817 do_proc_dointvec_userhz_jiffies_conv,NULL);
2821 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2822 * @table: the sysctl table
2823 * @write: %TRUE if this is a write to the sysctl file
2824 * @filp: the file structure
2825 * @buffer: the user buffer
2826 * @lenp: the size of the user buffer
2827 * @ppos: file position
2828 * @ppos: the current position in the file
2830 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2831 * values from/to the user buffer, treated as an ASCII string.
2832 * The values read are assumed to be in 1/1000 seconds, and
2833 * are converted into jiffies.
2835 * Returns 0 on success.
2837 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2838 void __user *buffer, size_t *lenp, loff_t *ppos)
2840 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2841 do_proc_dointvec_ms_jiffies_conv, NULL);
2844 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2845 void __user *buffer, size_t *lenp, loff_t *ppos)
2847 struct pid *new_pid;
2851 tmp = pid_vnr(cad_pid);
2853 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2854 lenp, ppos, NULL, NULL);
2858 new_pid = find_get_pid(tmp);
2862 put_pid(xchg(&cad_pid, new_pid));
2866 #else /* CONFIG_PROC_FS */
2868 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2869 void __user *buffer, size_t *lenp, loff_t *ppos)
2874 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2875 void __user *buffer, size_t *lenp, loff_t *ppos)
2880 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2881 void __user *buffer, size_t *lenp, loff_t *ppos)
2886 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2887 void __user *buffer, size_t *lenp, loff_t *ppos)
2892 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2893 void __user *buffer, size_t *lenp, loff_t *ppos)
2898 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2899 void __user *buffer, size_t *lenp, loff_t *ppos)
2904 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2905 void __user *buffer, size_t *lenp, loff_t *ppos)
2910 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2912 void __user *buffer,
2913 size_t *lenp, loff_t *ppos)
2919 #endif /* CONFIG_PROC_FS */
2922 #ifdef CONFIG_SYSCTL_SYSCALL
2924 * General sysctl support routines
2927 /* The generic sysctl data routine (used if no strategy routine supplied) */
2928 int sysctl_data(struct ctl_table *table,
2929 void __user *oldval, size_t __user *oldlenp,
2930 void __user *newval, size_t newlen)
2934 /* Get out of I don't have a variable */
2935 if (!table->data || !table->maxlen)
2938 if (oldval && oldlenp) {
2939 if (get_user(len, oldlenp))
2942 if (len > table->maxlen)
2943 len = table->maxlen;
2944 if (copy_to_user(oldval, table->data, len))
2946 if (put_user(len, oldlenp))
2951 if (newval && newlen) {
2952 if (newlen > table->maxlen)
2953 newlen = table->maxlen;
2955 if (copy_from_user(table->data, newval, newlen))
2961 /* The generic string strategy routine: */
2962 int sysctl_string(struct ctl_table *table,
2963 void __user *oldval, size_t __user *oldlenp,
2964 void __user *newval, size_t newlen)
2966 if (!table->data || !table->maxlen)
2969 if (oldval && oldlenp) {
2971 if (get_user(bufsize, oldlenp))
2974 size_t len = strlen(table->data), copied;
2976 /* This shouldn't trigger for a well-formed sysctl */
2977 if (len > table->maxlen)
2978 len = table->maxlen;
2980 /* Copy up to a max of bufsize-1 bytes of the string */
2981 copied = (len >= bufsize) ? bufsize - 1 : len;
2983 if (copy_to_user(oldval, table->data, copied) ||
2984 put_user(0, (char __user *)(oldval + copied)))
2986 if (put_user(len, oldlenp))
2990 if (newval && newlen) {
2991 size_t len = newlen;
2992 if (len > table->maxlen)
2993 len = table->maxlen;
2994 if(copy_from_user(table->data, newval, len))
2996 if (len == table->maxlen)
2998 ((char *) table->data)[len] = 0;
3004 * This function makes sure that all of the integers in the vector
3005 * are between the minimum and maximum values given in the arrays
3006 * table->extra1 and table->extra2, respectively.
3008 int sysctl_intvec(struct ctl_table *table,
3009 void __user *oldval, size_t __user *oldlenp,
3010 void __user *newval, size_t newlen)
3013 if (newval && newlen) {
3014 int __user *vec = (int __user *) newval;
3015 int *min = (int *) table->extra1;
3016 int *max = (int *) table->extra2;
3020 if (newlen % sizeof(int) != 0)
3023 if (!table->extra1 && !table->extra2)
3026 if (newlen > table->maxlen)
3027 newlen = table->maxlen;
3028 length = newlen / sizeof(int);
3030 for (i = 0; i < length; i++) {
3032 if (get_user(value, vec + i))
3034 if (min && value < min[i])
3036 if (max && value > max[i])
3043 /* Strategy function to convert jiffies to seconds */
3044 int sysctl_jiffies(struct ctl_table *table,
3045 void __user *oldval, size_t __user *oldlenp,
3046 void __user *newval, size_t newlen)
3048 if (oldval && oldlenp) {
3051 if (get_user(olen, oldlenp))
3056 if (olen < sizeof(int))
3059 val = *(int *)(table->data) / HZ;
3060 if (put_user(val, (int __user *)oldval))
3062 if (put_user(sizeof(int), oldlenp))
3066 if (newval && newlen) {
3068 if (newlen != sizeof(int))
3070 if (get_user(new, (int __user *)newval))
3072 *(int *)(table->data) = new*HZ;
3077 /* Strategy function to convert jiffies to seconds */
3078 int sysctl_ms_jiffies(struct ctl_table *table,
3079 void __user *oldval, size_t __user *oldlenp,
3080 void __user *newval, size_t newlen)
3082 if (oldval && oldlenp) {
3085 if (get_user(olen, oldlenp))
3090 if (olen < sizeof(int))
3093 val = jiffies_to_msecs(*(int *)(table->data));
3094 if (put_user(val, (int __user *)oldval))
3096 if (put_user(sizeof(int), oldlenp))
3100 if (newval && newlen) {
3102 if (newlen != sizeof(int))
3104 if (get_user(new, (int __user *)newval))
3106 *(int *)(table->data) = msecs_to_jiffies(new);
3113 #else /* CONFIG_SYSCTL_SYSCALL */
3116 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3118 struct __sysctl_args tmp;
3121 if (copy_from_user(&tmp, args, sizeof(tmp)))
3124 error = deprecated_sysctl_warning(&tmp);
3126 /* If no error reading the parameters then just -ENOSYS ... */
3133 int sysctl_data(struct ctl_table *table,
3134 void __user *oldval, size_t __user *oldlenp,
3135 void __user *newval, size_t newlen)
3140 int sysctl_string(struct ctl_table *table,
3141 void __user *oldval, size_t __user *oldlenp,
3142 void __user *newval, size_t newlen)
3147 int sysctl_intvec(struct ctl_table *table,
3148 void __user *oldval, size_t __user *oldlenp,
3149 void __user *newval, size_t newlen)
3154 int sysctl_jiffies(struct ctl_table *table,
3155 void __user *oldval, size_t __user *oldlenp,
3156 void __user *newval, size_t newlen)
3161 int sysctl_ms_jiffies(struct ctl_table *table,
3162 void __user *oldval, size_t __user *oldlenp,
3163 void __user *newval, size_t newlen)
3168 #endif /* CONFIG_SYSCTL_SYSCALL */
3170 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3172 static int msg_count;
3173 int name[CTL_MAXNAME];
3176 /* Check args->nlen. */
3177 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3180 /* Read in the sysctl name for better debug message logging */
3181 for (i = 0; i < args->nlen; i++)
3182 if (get_user(name[i], args->name + i))
3185 /* Ignore accesses to kernel.version */
3186 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3189 if (msg_count < 5) {
3192 "warning: process `%s' used the deprecated sysctl "
3193 "system call with ", current->comm);
3194 for (i = 0; i < args->nlen; i++)
3195 printk("%d.", name[i]);
3202 * No sense putting this after each symbol definition, twice,
3203 * exception granted :-)
3205 EXPORT_SYMBOL(proc_dointvec);
3206 EXPORT_SYMBOL(proc_dointvec_jiffies);
3207 EXPORT_SYMBOL(proc_dointvec_minmax);
3208 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3209 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3210 EXPORT_SYMBOL(proc_dostring);
3211 EXPORT_SYMBOL(proc_doulongvec_minmax);
3212 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3213 EXPORT_SYMBOL(register_sysctl_table);
3214 EXPORT_SYMBOL(register_sysctl_paths);
3215 EXPORT_SYMBOL(sysctl_intvec);
3216 EXPORT_SYMBOL(sysctl_jiffies);
3217 EXPORT_SYMBOL(sysctl_ms_jiffies);
3218 EXPORT_SYMBOL(sysctl_string);
3219 EXPORT_SYMBOL(sysctl_data);
3220 EXPORT_SYMBOL(unregister_sysctl_table);