2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
52 #include <linux/perf_counter.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 /* Constants used for minimum and maximum */
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty = 60;
97 static int neg_one = -1;
101 static int __maybe_unused one = 1;
102 static int __maybe_unused two = 2;
103 static unsigned long one_ul = 1;
104 static int one_hundred = 100;
106 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
107 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
109 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110 static int maxolduid = 65535;
111 static int minolduid;
112 static int min_percpu_pagelist_fract = 8;
114 static int ngroups_max = NGROUPS_MAX;
116 #ifdef CONFIG_MODULES
117 extern char modprobe_path[];
119 #ifdef CONFIG_CHR_DEV_SG
120 extern int sg_big_buff;
124 #include <asm/system.h>
127 #ifdef CONFIG_SPARC64
128 extern int sysctl_tsb_ratio;
132 extern int pwrsw_enabled;
133 extern int unaligned_enabled;
137 #ifdef CONFIG_MATHEMU
138 extern int sysctl_ieee_emulation_warnings;
140 extern int sysctl_userprocess_debug;
141 extern int spin_retry;
144 #ifdef CONFIG_BSD_PROCESS_ACCT
145 extern int acct_parm[];
149 extern int no_unaligned_warning;
150 extern int unaligned_dump_stack;
153 #ifdef CONFIG_RT_MUTEXES
154 extern int max_lock_depth;
157 #ifdef CONFIG_PROC_SYSCTL
158 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
159 void __user *buffer, size_t *lenp, loff_t *ppos);
160 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
161 void __user *buffer, size_t *lenp, loff_t *ppos);
164 static struct ctl_table root_table[];
165 static struct ctl_table_root sysctl_table_root;
166 static struct ctl_table_header root_table_header = {
168 .ctl_table = root_table,
169 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
170 .root = &sysctl_table_root,
171 .set = &sysctl_table_root.default_set,
173 static struct ctl_table_root sysctl_table_root = {
174 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
175 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
178 static struct ctl_table kern_table[];
179 static struct ctl_table vm_table[];
180 static struct ctl_table fs_table[];
181 static struct ctl_table debug_table[];
182 static struct ctl_table dev_table[];
183 extern struct ctl_table random_table[];
184 #ifdef CONFIG_INOTIFY_USER
185 extern struct ctl_table inotify_table[];
188 extern struct ctl_table epoll_table[];
191 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
192 int sysctl_legacy_va_layout;
195 extern int prove_locking;
196 extern int lock_stat;
198 /* The default sysctl tables: */
200 static struct ctl_table root_table[] = {
202 .ctl_name = CTL_KERN,
203 .procname = "kernel",
220 .ctl_name = CTL_DEBUG,
223 .child = debug_table,
232 * NOTE: do not add new entries to this table unless you have read
233 * Documentation/sysctl/ctl_unnumbered.txt
238 #ifdef CONFIG_SCHED_DEBUG
239 static int min_sched_granularity_ns = 100000; /* 100 usecs */
240 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
241 static int min_wakeup_granularity_ns; /* 0 usecs */
242 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
245 static struct ctl_table kern_table[] = {
246 #ifdef CONFIG_SCHED_DEBUG
248 .ctl_name = CTL_UNNUMBERED,
249 .procname = "sched_min_granularity_ns",
250 .data = &sysctl_sched_min_granularity,
251 .maxlen = sizeof(unsigned int),
253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
259 .ctl_name = CTL_UNNUMBERED,
260 .procname = "sched_latency_ns",
261 .data = &sysctl_sched_latency,
262 .maxlen = sizeof(unsigned int),
264 .proc_handler = &sched_nr_latency_handler,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_sched_granularity_ns,
267 .extra2 = &max_sched_granularity_ns,
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "sched_wakeup_granularity_ns",
272 .data = &sysctl_sched_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
281 .ctl_name = CTL_UNNUMBERED,
282 .procname = "sched_shares_ratelimit",
283 .data = &sysctl_sched_shares_ratelimit,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = &proc_dointvec,
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_shares_thresh",
291 .data = &sysctl_sched_shares_thresh,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = &proc_dointvec_minmax,
295 .strategy = &sysctl_intvec,
299 .ctl_name = CTL_UNNUMBERED,
300 .procname = "sched_child_runs_first",
301 .data = &sysctl_sched_child_runs_first,
302 .maxlen = sizeof(unsigned int),
304 .proc_handler = &proc_dointvec,
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_features",
309 .data = &sysctl_sched_features,
310 .maxlen = sizeof(unsigned int),
312 .proc_handler = &proc_dointvec,
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_migration_cost",
317 .data = &sysctl_sched_migration_cost,
318 .maxlen = sizeof(unsigned int),
320 .proc_handler = &proc_dointvec,
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_nr_migrate",
325 .data = &sysctl_sched_nr_migrate,
326 .maxlen = sizeof(unsigned int),
328 .proc_handler = &proc_dointvec,
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_rt_period_us",
334 .data = &sysctl_sched_rt_period,
335 .maxlen = sizeof(unsigned int),
337 .proc_handler = &sched_rt_handler,
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_rt_runtime_us",
342 .data = &sysctl_sched_rt_runtime,
343 .maxlen = sizeof(int),
345 .proc_handler = &sched_rt_handler,
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "sched_compat_yield",
350 .data = &sysctl_sched_compat_yield,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = &proc_dointvec,
355 #ifdef CONFIG_PROVE_LOCKING
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "prove_locking",
359 .data = &prove_locking,
360 .maxlen = sizeof(int),
362 .proc_handler = &proc_dointvec,
365 #ifdef CONFIG_LOCK_STAT
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "lock_stat",
370 .maxlen = sizeof(int),
372 .proc_handler = &proc_dointvec,
376 .ctl_name = KERN_PANIC,
378 .data = &panic_timeout,
379 .maxlen = sizeof(int),
381 .proc_handler = &proc_dointvec,
384 .ctl_name = KERN_CORE_USES_PID,
385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
389 .proc_handler = &proc_dointvec,
392 .ctl_name = KERN_CORE_PATTERN,
393 .procname = "core_pattern",
394 .data = core_pattern,
395 .maxlen = CORENAME_MAX_SIZE,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
400 #ifdef CONFIG_PROC_SYSCTL
402 .procname = "tainted",
403 .maxlen = sizeof(long),
405 .proc_handler = &proc_taint,
408 #ifdef CONFIG_LATENCYTOP
410 .procname = "latencytop",
411 .data = &latencytop_enabled,
412 .maxlen = sizeof(int),
414 .proc_handler = &proc_dointvec,
417 #ifdef CONFIG_BLK_DEV_INITRD
419 .ctl_name = KERN_REALROOTDEV,
420 .procname = "real-root-dev",
421 .data = &real_root_dev,
422 .maxlen = sizeof(int),
424 .proc_handler = &proc_dointvec,
428 .ctl_name = CTL_UNNUMBERED,
429 .procname = "print-fatal-signals",
430 .data = &print_fatal_signals,
431 .maxlen = sizeof(int),
433 .proc_handler = &proc_dointvec,
437 .ctl_name = KERN_SPARC_REBOOT,
438 .procname = "reboot-cmd",
439 .data = reboot_command,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
446 .ctl_name = KERN_SPARC_STOP_A,
447 .procname = "stop-a",
448 .data = &stop_a_enabled,
449 .maxlen = sizeof (int),
451 .proc_handler = &proc_dointvec,
454 .ctl_name = KERN_SPARC_SCONS_PWROFF,
455 .procname = "scons-poweroff",
456 .data = &scons_pwroff,
457 .maxlen = sizeof (int),
459 .proc_handler = &proc_dointvec,
462 #ifdef CONFIG_SPARC64
464 .ctl_name = CTL_UNNUMBERED,
465 .procname = "tsb-ratio",
466 .data = &sysctl_tsb_ratio,
467 .maxlen = sizeof (int),
469 .proc_handler = &proc_dointvec,
474 .ctl_name = KERN_HPPA_PWRSW,
475 .procname = "soft-power",
476 .data = &pwrsw_enabled,
477 .maxlen = sizeof (int),
479 .proc_handler = &proc_dointvec,
482 .ctl_name = KERN_HPPA_UNALIGNED,
483 .procname = "unaligned-trap",
484 .data = &unaligned_enabled,
485 .maxlen = sizeof (int),
487 .proc_handler = &proc_dointvec,
491 .ctl_name = KERN_CTLALTDEL,
492 .procname = "ctrl-alt-del",
494 .maxlen = sizeof(int),
496 .proc_handler = &proc_dointvec,
498 #ifdef CONFIG_FUNCTION_TRACER
500 .ctl_name = CTL_UNNUMBERED,
501 .procname = "ftrace_enabled",
502 .data = &ftrace_enabled,
503 .maxlen = sizeof(int),
505 .proc_handler = &ftrace_enable_sysctl,
508 #ifdef CONFIG_STACK_TRACER
510 .ctl_name = CTL_UNNUMBERED,
511 .procname = "stack_tracer_enabled",
512 .data = &stack_tracer_enabled,
513 .maxlen = sizeof(int),
515 .proc_handler = &stack_trace_sysctl,
518 #ifdef CONFIG_TRACING
520 .ctl_name = CTL_UNNUMBERED,
521 .procname = "ftrace_dump_on_oops",
522 .data = &ftrace_dump_on_oops,
523 .maxlen = sizeof(int),
525 .proc_handler = &proc_dointvec,
528 #ifdef CONFIG_MODULES
530 .ctl_name = KERN_MODPROBE,
531 .procname = "modprobe",
532 .data = &modprobe_path,
533 .maxlen = KMOD_PATH_LEN,
535 .proc_handler = &proc_dostring,
536 .strategy = &sysctl_string,
539 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
541 .ctl_name = KERN_HOTPLUG,
542 .procname = "hotplug",
543 .data = &uevent_helper,
544 .maxlen = UEVENT_HELPER_PATH_LEN,
546 .proc_handler = &proc_dostring,
547 .strategy = &sysctl_string,
550 #ifdef CONFIG_CHR_DEV_SG
552 .ctl_name = KERN_SG_BIG_BUFF,
553 .procname = "sg-big-buff",
554 .data = &sg_big_buff,
555 .maxlen = sizeof (int),
557 .proc_handler = &proc_dointvec,
560 #ifdef CONFIG_BSD_PROCESS_ACCT
562 .ctl_name = KERN_ACCT,
565 .maxlen = 3*sizeof(int),
567 .proc_handler = &proc_dointvec,
570 #ifdef CONFIG_MAGIC_SYSRQ
572 .ctl_name = KERN_SYSRQ,
574 .data = &__sysrq_enabled,
575 .maxlen = sizeof (int),
577 .proc_handler = &proc_dointvec,
580 #ifdef CONFIG_PROC_SYSCTL
582 .procname = "cad_pid",
584 .maxlen = sizeof (int),
586 .proc_handler = &proc_do_cad_pid,
590 .ctl_name = KERN_MAX_THREADS,
591 .procname = "threads-max",
592 .data = &max_threads,
593 .maxlen = sizeof(int),
595 .proc_handler = &proc_dointvec,
598 .ctl_name = KERN_RANDOM,
599 .procname = "random",
601 .child = random_table,
604 .ctl_name = KERN_OVERFLOWUID,
605 .procname = "overflowuid",
606 .data = &overflowuid,
607 .maxlen = sizeof(int),
609 .proc_handler = &proc_dointvec_minmax,
610 .strategy = &sysctl_intvec,
611 .extra1 = &minolduid,
612 .extra2 = &maxolduid,
615 .ctl_name = KERN_OVERFLOWGID,
616 .procname = "overflowgid",
617 .data = &overflowgid,
618 .maxlen = sizeof(int),
620 .proc_handler = &proc_dointvec_minmax,
621 .strategy = &sysctl_intvec,
622 .extra1 = &minolduid,
623 .extra2 = &maxolduid,
626 #ifdef CONFIG_MATHEMU
628 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
629 .procname = "ieee_emulation_warnings",
630 .data = &sysctl_ieee_emulation_warnings,
631 .maxlen = sizeof(int),
633 .proc_handler = &proc_dointvec,
637 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
638 .procname = "userprocess_debug",
639 .data = &sysctl_userprocess_debug,
640 .maxlen = sizeof(int),
642 .proc_handler = &proc_dointvec,
646 .ctl_name = KERN_PIDMAX,
647 .procname = "pid_max",
649 .maxlen = sizeof (int),
651 .proc_handler = &proc_dointvec_minmax,
652 .strategy = sysctl_intvec,
653 .extra1 = &pid_max_min,
654 .extra2 = &pid_max_max,
657 .ctl_name = KERN_PANIC_ON_OOPS,
658 .procname = "panic_on_oops",
659 .data = &panic_on_oops,
660 .maxlen = sizeof(int),
662 .proc_handler = &proc_dointvec,
664 #if defined CONFIG_PRINTK
666 .ctl_name = KERN_PRINTK,
667 .procname = "printk",
668 .data = &console_loglevel,
669 .maxlen = 4*sizeof(int),
671 .proc_handler = &proc_dointvec,
674 .ctl_name = KERN_PRINTK_RATELIMIT,
675 .procname = "printk_ratelimit",
676 .data = &printk_ratelimit_state.interval,
677 .maxlen = sizeof(int),
679 .proc_handler = &proc_dointvec_jiffies,
680 .strategy = &sysctl_jiffies,
683 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
684 .procname = "printk_ratelimit_burst",
685 .data = &printk_ratelimit_state.burst,
686 .maxlen = sizeof(int),
688 .proc_handler = &proc_dointvec,
692 .ctl_name = KERN_NGROUPS_MAX,
693 .procname = "ngroups_max",
694 .data = &ngroups_max,
695 .maxlen = sizeof (int),
697 .proc_handler = &proc_dointvec,
699 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
701 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
702 .procname = "unknown_nmi_panic",
703 .data = &unknown_nmi_panic,
704 .maxlen = sizeof (int),
706 .proc_handler = &proc_dointvec,
709 .procname = "nmi_watchdog",
710 .data = &nmi_watchdog_enabled,
711 .maxlen = sizeof (int),
713 .proc_handler = &proc_nmi_enabled,
716 #if defined(CONFIG_X86)
718 .ctl_name = KERN_PANIC_ON_NMI,
719 .procname = "panic_on_unrecovered_nmi",
720 .data = &panic_on_unrecovered_nmi,
721 .maxlen = sizeof(int),
723 .proc_handler = &proc_dointvec,
726 .ctl_name = KERN_BOOTLOADER_TYPE,
727 .procname = "bootloader_type",
728 .data = &bootloader_type,
729 .maxlen = sizeof (int),
731 .proc_handler = &proc_dointvec,
734 .ctl_name = CTL_UNNUMBERED,
735 .procname = "bootloader_version",
736 .data = &bootloader_version,
737 .maxlen = sizeof (int),
739 .proc_handler = &proc_dointvec,
742 .ctl_name = CTL_UNNUMBERED,
743 .procname = "kstack_depth_to_print",
744 .data = &kstack_depth_to_print,
745 .maxlen = sizeof(int),
747 .proc_handler = &proc_dointvec,
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "io_delay_type",
752 .data = &io_delay_type,
753 .maxlen = sizeof(int),
755 .proc_handler = &proc_dointvec,
758 #if defined(CONFIG_MMU)
760 .ctl_name = KERN_RANDOMIZE,
761 .procname = "randomize_va_space",
762 .data = &randomize_va_space,
763 .maxlen = sizeof(int),
765 .proc_handler = &proc_dointvec,
768 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
770 .ctl_name = KERN_SPIN_RETRY,
771 .procname = "spin_retry",
773 .maxlen = sizeof (int),
775 .proc_handler = &proc_dointvec,
778 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
780 .procname = "acpi_video_flags",
781 .data = &acpi_realmode_flags,
782 .maxlen = sizeof (unsigned long),
784 .proc_handler = &proc_doulongvec_minmax,
789 .ctl_name = KERN_IA64_UNALIGNED,
790 .procname = "ignore-unaligned-usertrap",
791 .data = &no_unaligned_warning,
792 .maxlen = sizeof (int),
794 .proc_handler = &proc_dointvec,
797 .ctl_name = CTL_UNNUMBERED,
798 .procname = "unaligned-dump-stack",
799 .data = &unaligned_dump_stack,
800 .maxlen = sizeof (int),
802 .proc_handler = &proc_dointvec,
805 #ifdef CONFIG_DETECT_SOFTLOCKUP
807 .ctl_name = CTL_UNNUMBERED,
808 .procname = "softlockup_panic",
809 .data = &softlockup_panic,
810 .maxlen = sizeof(int),
812 .proc_handler = &proc_dointvec_minmax,
813 .strategy = &sysctl_intvec,
818 .ctl_name = CTL_UNNUMBERED,
819 .procname = "softlockup_thresh",
820 .data = &softlockup_thresh,
821 .maxlen = sizeof(int),
823 .proc_handler = &proc_dosoftlockup_thresh,
824 .strategy = &sysctl_intvec,
829 #ifdef CONFIG_DETECT_HUNG_TASK
831 .ctl_name = CTL_UNNUMBERED,
832 .procname = "hung_task_panic",
833 .data = &sysctl_hung_task_panic,
834 .maxlen = sizeof(int),
836 .proc_handler = &proc_dointvec_minmax,
837 .strategy = &sysctl_intvec,
842 .ctl_name = CTL_UNNUMBERED,
843 .procname = "hung_task_check_count",
844 .data = &sysctl_hung_task_check_count,
845 .maxlen = sizeof(unsigned long),
847 .proc_handler = &proc_doulongvec_minmax,
848 .strategy = &sysctl_intvec,
851 .ctl_name = CTL_UNNUMBERED,
852 .procname = "hung_task_timeout_secs",
853 .data = &sysctl_hung_task_timeout_secs,
854 .maxlen = sizeof(unsigned long),
856 .proc_handler = &proc_dohung_task_timeout_secs,
857 .strategy = &sysctl_intvec,
860 .ctl_name = CTL_UNNUMBERED,
861 .procname = "hung_task_warnings",
862 .data = &sysctl_hung_task_warnings,
863 .maxlen = sizeof(unsigned long),
865 .proc_handler = &proc_doulongvec_minmax,
866 .strategy = &sysctl_intvec,
871 .ctl_name = KERN_COMPAT_LOG,
872 .procname = "compat-log",
874 .maxlen = sizeof (int),
876 .proc_handler = &proc_dointvec,
879 #ifdef CONFIG_RT_MUTEXES
881 .ctl_name = KERN_MAX_LOCK_DEPTH,
882 .procname = "max_lock_depth",
883 .data = &max_lock_depth,
884 .maxlen = sizeof(int),
886 .proc_handler = &proc_dointvec,
890 .ctl_name = CTL_UNNUMBERED,
891 .procname = "poweroff_cmd",
892 .data = &poweroff_cmd,
893 .maxlen = POWEROFF_CMD_PATH_LEN,
895 .proc_handler = &proc_dostring,
896 .strategy = &sysctl_string,
900 .ctl_name = CTL_UNNUMBERED,
903 .child = key_sysctls,
906 #ifdef CONFIG_RCU_TORTURE_TEST
908 .ctl_name = CTL_UNNUMBERED,
909 .procname = "rcutorture_runnable",
910 .data = &rcutorture_runnable,
911 .maxlen = sizeof(int),
913 .proc_handler = &proc_dointvec,
916 #ifdef CONFIG_SLOW_WORK
918 .ctl_name = CTL_UNNUMBERED,
919 .procname = "slow-work",
921 .child = slow_work_sysctls,
924 #ifdef CONFIG_PERF_COUNTERS
926 .ctl_name = CTL_UNNUMBERED,
927 .procname = "perf_counter_paranoid",
928 .data = &sysctl_perf_counter_paranoid,
929 .maxlen = sizeof(sysctl_perf_counter_paranoid),
931 .proc_handler = &proc_dointvec,
934 .ctl_name = CTL_UNNUMBERED,
935 .procname = "perf_counter_mlock_kb",
936 .data = &sysctl_perf_counter_mlock,
937 .maxlen = sizeof(sysctl_perf_counter_mlock),
939 .proc_handler = &proc_dointvec,
942 .ctl_name = CTL_UNNUMBERED,
943 .procname = "perf_counter_max_sample_rate",
944 .data = &sysctl_perf_counter_sample_rate,
945 .maxlen = sizeof(sysctl_perf_counter_sample_rate),
947 .proc_handler = &proc_dointvec,
951 * NOTE: do not add new entries to this table unless you have read
952 * Documentation/sysctl/ctl_unnumbered.txt
957 static struct ctl_table vm_table[] = {
959 .ctl_name = VM_OVERCOMMIT_MEMORY,
960 .procname = "overcommit_memory",
961 .data = &sysctl_overcommit_memory,
962 .maxlen = sizeof(sysctl_overcommit_memory),
964 .proc_handler = &proc_dointvec,
967 .ctl_name = VM_PANIC_ON_OOM,
968 .procname = "panic_on_oom",
969 .data = &sysctl_panic_on_oom,
970 .maxlen = sizeof(sysctl_panic_on_oom),
972 .proc_handler = &proc_dointvec,
975 .ctl_name = CTL_UNNUMBERED,
976 .procname = "oom_kill_allocating_task",
977 .data = &sysctl_oom_kill_allocating_task,
978 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
980 .proc_handler = &proc_dointvec,
983 .ctl_name = CTL_UNNUMBERED,
984 .procname = "oom_dump_tasks",
985 .data = &sysctl_oom_dump_tasks,
986 .maxlen = sizeof(sysctl_oom_dump_tasks),
988 .proc_handler = &proc_dointvec,
991 .ctl_name = VM_OVERCOMMIT_RATIO,
992 .procname = "overcommit_ratio",
993 .data = &sysctl_overcommit_ratio,
994 .maxlen = sizeof(sysctl_overcommit_ratio),
996 .proc_handler = &proc_dointvec,
999 .ctl_name = VM_PAGE_CLUSTER,
1000 .procname = "page-cluster",
1001 .data = &page_cluster,
1002 .maxlen = sizeof(int),
1004 .proc_handler = &proc_dointvec,
1007 .ctl_name = VM_DIRTY_BACKGROUND,
1008 .procname = "dirty_background_ratio",
1009 .data = &dirty_background_ratio,
1010 .maxlen = sizeof(dirty_background_ratio),
1012 .proc_handler = &dirty_background_ratio_handler,
1013 .strategy = &sysctl_intvec,
1015 .extra2 = &one_hundred,
1018 .ctl_name = CTL_UNNUMBERED,
1019 .procname = "dirty_background_bytes",
1020 .data = &dirty_background_bytes,
1021 .maxlen = sizeof(dirty_background_bytes),
1023 .proc_handler = &dirty_background_bytes_handler,
1024 .strategy = &sysctl_intvec,
1028 .ctl_name = VM_DIRTY_RATIO,
1029 .procname = "dirty_ratio",
1030 .data = &vm_dirty_ratio,
1031 .maxlen = sizeof(vm_dirty_ratio),
1033 .proc_handler = &dirty_ratio_handler,
1034 .strategy = &sysctl_intvec,
1036 .extra2 = &one_hundred,
1039 .ctl_name = CTL_UNNUMBERED,
1040 .procname = "dirty_bytes",
1041 .data = &vm_dirty_bytes,
1042 .maxlen = sizeof(vm_dirty_bytes),
1044 .proc_handler = &dirty_bytes_handler,
1045 .strategy = &sysctl_intvec,
1046 .extra1 = &dirty_bytes_min,
1049 .procname = "dirty_writeback_centisecs",
1050 .data = &dirty_writeback_interval,
1051 .maxlen = sizeof(dirty_writeback_interval),
1053 .proc_handler = &dirty_writeback_centisecs_handler,
1056 .procname = "dirty_expire_centisecs",
1057 .data = &dirty_expire_interval,
1058 .maxlen = sizeof(dirty_expire_interval),
1060 .proc_handler = &proc_dointvec,
1063 .ctl_name = VM_NR_PDFLUSH_THREADS,
1064 .procname = "nr_pdflush_threads",
1065 .data = &nr_pdflush_threads,
1066 .maxlen = sizeof nr_pdflush_threads,
1067 .mode = 0444 /* read-only*/,
1068 .proc_handler = &proc_dointvec,
1071 .ctl_name = VM_SWAPPINESS,
1072 .procname = "swappiness",
1073 .data = &vm_swappiness,
1074 .maxlen = sizeof(vm_swappiness),
1076 .proc_handler = &proc_dointvec_minmax,
1077 .strategy = &sysctl_intvec,
1079 .extra2 = &one_hundred,
1081 #ifdef CONFIG_HUGETLB_PAGE
1083 .procname = "nr_hugepages",
1085 .maxlen = sizeof(unsigned long),
1087 .proc_handler = &hugetlb_sysctl_handler,
1088 .extra1 = (void *)&hugetlb_zero,
1089 .extra2 = (void *)&hugetlb_infinity,
1092 .ctl_name = VM_HUGETLB_GROUP,
1093 .procname = "hugetlb_shm_group",
1094 .data = &sysctl_hugetlb_shm_group,
1095 .maxlen = sizeof(gid_t),
1097 .proc_handler = &proc_dointvec,
1100 .ctl_name = CTL_UNNUMBERED,
1101 .procname = "hugepages_treat_as_movable",
1102 .data = &hugepages_treat_as_movable,
1103 .maxlen = sizeof(int),
1105 .proc_handler = &hugetlb_treat_movable_handler,
1108 .ctl_name = CTL_UNNUMBERED,
1109 .procname = "nr_overcommit_hugepages",
1111 .maxlen = sizeof(unsigned long),
1113 .proc_handler = &hugetlb_overcommit_handler,
1114 .extra1 = (void *)&hugetlb_zero,
1115 .extra2 = (void *)&hugetlb_infinity,
1119 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1120 .procname = "lowmem_reserve_ratio",
1121 .data = &sysctl_lowmem_reserve_ratio,
1122 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1124 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1125 .strategy = &sysctl_intvec,
1128 .ctl_name = VM_DROP_PAGECACHE,
1129 .procname = "drop_caches",
1130 .data = &sysctl_drop_caches,
1131 .maxlen = sizeof(int),
1133 .proc_handler = drop_caches_sysctl_handler,
1134 .strategy = &sysctl_intvec,
1137 .ctl_name = VM_MIN_FREE_KBYTES,
1138 .procname = "min_free_kbytes",
1139 .data = &min_free_kbytes,
1140 .maxlen = sizeof(min_free_kbytes),
1142 .proc_handler = &min_free_kbytes_sysctl_handler,
1143 .strategy = &sysctl_intvec,
1147 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1148 .procname = "percpu_pagelist_fraction",
1149 .data = &percpu_pagelist_fraction,
1150 .maxlen = sizeof(percpu_pagelist_fraction),
1152 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1153 .strategy = &sysctl_intvec,
1154 .extra1 = &min_percpu_pagelist_fract,
1158 .ctl_name = VM_MAX_MAP_COUNT,
1159 .procname = "max_map_count",
1160 .data = &sysctl_max_map_count,
1161 .maxlen = sizeof(sysctl_max_map_count),
1163 .proc_handler = &proc_dointvec
1167 .ctl_name = CTL_UNNUMBERED,
1168 .procname = "nr_trim_pages",
1169 .data = &sysctl_nr_trim_pages,
1170 .maxlen = sizeof(sysctl_nr_trim_pages),
1172 .proc_handler = &proc_dointvec_minmax,
1173 .strategy = &sysctl_intvec,
1178 .ctl_name = VM_LAPTOP_MODE,
1179 .procname = "laptop_mode",
1180 .data = &laptop_mode,
1181 .maxlen = sizeof(laptop_mode),
1183 .proc_handler = &proc_dointvec_jiffies,
1184 .strategy = &sysctl_jiffies,
1187 .ctl_name = VM_BLOCK_DUMP,
1188 .procname = "block_dump",
1189 .data = &block_dump,
1190 .maxlen = sizeof(block_dump),
1192 .proc_handler = &proc_dointvec,
1193 .strategy = &sysctl_intvec,
1197 .ctl_name = VM_VFS_CACHE_PRESSURE,
1198 .procname = "vfs_cache_pressure",
1199 .data = &sysctl_vfs_cache_pressure,
1200 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1202 .proc_handler = &proc_dointvec,
1203 .strategy = &sysctl_intvec,
1206 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1208 .ctl_name = VM_LEGACY_VA_LAYOUT,
1209 .procname = "legacy_va_layout",
1210 .data = &sysctl_legacy_va_layout,
1211 .maxlen = sizeof(sysctl_legacy_va_layout),
1213 .proc_handler = &proc_dointvec,
1214 .strategy = &sysctl_intvec,
1220 .ctl_name = VM_ZONE_RECLAIM_MODE,
1221 .procname = "zone_reclaim_mode",
1222 .data = &zone_reclaim_mode,
1223 .maxlen = sizeof(zone_reclaim_mode),
1225 .proc_handler = &proc_dointvec,
1226 .strategy = &sysctl_intvec,
1230 .ctl_name = VM_MIN_UNMAPPED,
1231 .procname = "min_unmapped_ratio",
1232 .data = &sysctl_min_unmapped_ratio,
1233 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1235 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1236 .strategy = &sysctl_intvec,
1238 .extra2 = &one_hundred,
1241 .ctl_name = VM_MIN_SLAB,
1242 .procname = "min_slab_ratio",
1243 .data = &sysctl_min_slab_ratio,
1244 .maxlen = sizeof(sysctl_min_slab_ratio),
1246 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1247 .strategy = &sysctl_intvec,
1249 .extra2 = &one_hundred,
1254 .ctl_name = CTL_UNNUMBERED,
1255 .procname = "stat_interval",
1256 .data = &sysctl_stat_interval,
1257 .maxlen = sizeof(sysctl_stat_interval),
1259 .proc_handler = &proc_dointvec_jiffies,
1260 .strategy = &sysctl_jiffies,
1263 #ifdef CONFIG_SECURITY
1265 .ctl_name = CTL_UNNUMBERED,
1266 .procname = "mmap_min_addr",
1267 .data = &mmap_min_addr,
1268 .maxlen = sizeof(unsigned long),
1270 .proc_handler = &proc_doulongvec_minmax,
1275 .ctl_name = CTL_UNNUMBERED,
1276 .procname = "numa_zonelist_order",
1277 .data = &numa_zonelist_order,
1278 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1280 .proc_handler = &numa_zonelist_order_handler,
1281 .strategy = &sysctl_string,
1284 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1285 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1287 .ctl_name = VM_VDSO_ENABLED,
1288 .procname = "vdso_enabled",
1289 .data = &vdso_enabled,
1290 .maxlen = sizeof(vdso_enabled),
1292 .proc_handler = &proc_dointvec,
1293 .strategy = &sysctl_intvec,
1297 #ifdef CONFIG_HIGHMEM
1299 .ctl_name = CTL_UNNUMBERED,
1300 .procname = "highmem_is_dirtyable",
1301 .data = &vm_highmem_is_dirtyable,
1302 .maxlen = sizeof(vm_highmem_is_dirtyable),
1304 .proc_handler = &proc_dointvec_minmax,
1305 .strategy = &sysctl_intvec,
1310 #ifdef CONFIG_UNEVICTABLE_LRU
1312 .ctl_name = CTL_UNNUMBERED,
1313 .procname = "scan_unevictable_pages",
1314 .data = &scan_unevictable_pages,
1315 .maxlen = sizeof(scan_unevictable_pages),
1317 .proc_handler = &scan_unevictable_handler,
1321 * NOTE: do not add new entries to this table unless you have read
1322 * Documentation/sysctl/ctl_unnumbered.txt
1327 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1328 static struct ctl_table binfmt_misc_table[] = {
1333 static struct ctl_table fs_table[] = {
1335 .ctl_name = FS_NRINODE,
1336 .procname = "inode-nr",
1337 .data = &inodes_stat,
1338 .maxlen = 2*sizeof(int),
1340 .proc_handler = &proc_dointvec,
1343 .ctl_name = FS_STATINODE,
1344 .procname = "inode-state",
1345 .data = &inodes_stat,
1346 .maxlen = 7*sizeof(int),
1348 .proc_handler = &proc_dointvec,
1351 .procname = "file-nr",
1352 .data = &files_stat,
1353 .maxlen = 3*sizeof(int),
1355 .proc_handler = &proc_nr_files,
1358 .ctl_name = FS_MAXFILE,
1359 .procname = "file-max",
1360 .data = &files_stat.max_files,
1361 .maxlen = sizeof(int),
1363 .proc_handler = &proc_dointvec,
1366 .ctl_name = CTL_UNNUMBERED,
1367 .procname = "nr_open",
1368 .data = &sysctl_nr_open,
1369 .maxlen = sizeof(int),
1371 .proc_handler = &proc_dointvec_minmax,
1372 .extra1 = &sysctl_nr_open_min,
1373 .extra2 = &sysctl_nr_open_max,
1376 .ctl_name = FS_DENTRY,
1377 .procname = "dentry-state",
1378 .data = &dentry_stat,
1379 .maxlen = 6*sizeof(int),
1381 .proc_handler = &proc_dointvec,
1384 .ctl_name = FS_OVERFLOWUID,
1385 .procname = "overflowuid",
1386 .data = &fs_overflowuid,
1387 .maxlen = sizeof(int),
1389 .proc_handler = &proc_dointvec_minmax,
1390 .strategy = &sysctl_intvec,
1391 .extra1 = &minolduid,
1392 .extra2 = &maxolduid,
1395 .ctl_name = FS_OVERFLOWGID,
1396 .procname = "overflowgid",
1397 .data = &fs_overflowgid,
1398 .maxlen = sizeof(int),
1400 .proc_handler = &proc_dointvec_minmax,
1401 .strategy = &sysctl_intvec,
1402 .extra1 = &minolduid,
1403 .extra2 = &maxolduid,
1405 #ifdef CONFIG_FILE_LOCKING
1407 .ctl_name = FS_LEASES,
1408 .procname = "leases-enable",
1409 .data = &leases_enable,
1410 .maxlen = sizeof(int),
1412 .proc_handler = &proc_dointvec,
1415 #ifdef CONFIG_DNOTIFY
1417 .ctl_name = FS_DIR_NOTIFY,
1418 .procname = "dir-notify-enable",
1419 .data = &dir_notify_enable,
1420 .maxlen = sizeof(int),
1422 .proc_handler = &proc_dointvec,
1426 #ifdef CONFIG_FILE_LOCKING
1428 .ctl_name = FS_LEASE_TIME,
1429 .procname = "lease-break-time",
1430 .data = &lease_break_time,
1431 .maxlen = sizeof(int),
1433 .proc_handler = &proc_dointvec,
1438 .procname = "aio-nr",
1440 .maxlen = sizeof(aio_nr),
1442 .proc_handler = &proc_doulongvec_minmax,
1445 .procname = "aio-max-nr",
1446 .data = &aio_max_nr,
1447 .maxlen = sizeof(aio_max_nr),
1449 .proc_handler = &proc_doulongvec_minmax,
1451 #endif /* CONFIG_AIO */
1452 #ifdef CONFIG_INOTIFY_USER
1454 .ctl_name = FS_INOTIFY,
1455 .procname = "inotify",
1457 .child = inotify_table,
1462 .procname = "epoll",
1464 .child = epoll_table,
1469 .ctl_name = KERN_SETUID_DUMPABLE,
1470 .procname = "suid_dumpable",
1471 .data = &suid_dumpable,
1472 .maxlen = sizeof(int),
1474 .proc_handler = &proc_dointvec_minmax,
1475 .strategy = &sysctl_intvec,
1479 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1481 .ctl_name = CTL_UNNUMBERED,
1482 .procname = "binfmt_misc",
1484 .child = binfmt_misc_table,
1488 * NOTE: do not add new entries to this table unless you have read
1489 * Documentation/sysctl/ctl_unnumbered.txt
1494 static struct ctl_table debug_table[] = {
1495 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1497 .ctl_name = CTL_UNNUMBERED,
1498 .procname = "exception-trace",
1499 .data = &show_unhandled_signals,
1500 .maxlen = sizeof(int),
1502 .proc_handler = proc_dointvec
1508 static struct ctl_table dev_table[] = {
1512 static DEFINE_SPINLOCK(sysctl_lock);
1514 /* called under sysctl_lock */
1515 static int use_table(struct ctl_table_header *p)
1517 if (unlikely(p->unregistering))
1523 /* called under sysctl_lock */
1524 static void unuse_table(struct ctl_table_header *p)
1527 if (unlikely(p->unregistering))
1528 complete(p->unregistering);
1531 /* called under sysctl_lock, will reacquire if has to wait */
1532 static void start_unregistering(struct ctl_table_header *p)
1535 * if p->used is 0, nobody will ever touch that entry again;
1536 * we'll eliminate all paths to it before dropping sysctl_lock
1538 if (unlikely(p->used)) {
1539 struct completion wait;
1540 init_completion(&wait);
1541 p->unregistering = &wait;
1542 spin_unlock(&sysctl_lock);
1543 wait_for_completion(&wait);
1544 spin_lock(&sysctl_lock);
1546 /* anything non-NULL; we'll never dereference it */
1547 p->unregistering = ERR_PTR(-EINVAL);
1550 * do not remove from the list until nobody holds it; walking the
1551 * list in do_sysctl() relies on that.
1553 list_del_init(&p->ctl_entry);
1556 void sysctl_head_get(struct ctl_table_header *head)
1558 spin_lock(&sysctl_lock);
1560 spin_unlock(&sysctl_lock);
1563 void sysctl_head_put(struct ctl_table_header *head)
1565 spin_lock(&sysctl_lock);
1568 spin_unlock(&sysctl_lock);
1571 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1575 spin_lock(&sysctl_lock);
1576 if (!use_table(head))
1577 head = ERR_PTR(-ENOENT);
1578 spin_unlock(&sysctl_lock);
1582 void sysctl_head_finish(struct ctl_table_header *head)
1586 spin_lock(&sysctl_lock);
1588 spin_unlock(&sysctl_lock);
1591 static struct ctl_table_set *
1592 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1594 struct ctl_table_set *set = &root->default_set;
1596 set = root->lookup(root, namespaces);
1600 static struct list_head *
1601 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1603 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1607 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1608 struct ctl_table_header *prev)
1610 struct ctl_table_root *root;
1611 struct list_head *header_list;
1612 struct ctl_table_header *head;
1613 struct list_head *tmp;
1615 spin_lock(&sysctl_lock);
1618 tmp = &prev->ctl_entry;
1622 tmp = &root_table_header.ctl_entry;
1624 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1626 if (!use_table(head))
1628 spin_unlock(&sysctl_lock);
1633 header_list = lookup_header_list(root, namespaces);
1634 if (tmp != header_list)
1638 root = list_entry(root->root_list.next,
1639 struct ctl_table_root, root_list);
1640 if (root == &sysctl_table_root)
1642 header_list = lookup_header_list(root, namespaces);
1643 } while (list_empty(header_list));
1644 tmp = header_list->next;
1647 spin_unlock(&sysctl_lock);
1651 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1653 return __sysctl_head_next(current->nsproxy, prev);
1656 void register_sysctl_root(struct ctl_table_root *root)
1658 spin_lock(&sysctl_lock);
1659 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1660 spin_unlock(&sysctl_lock);
1663 #ifdef CONFIG_SYSCTL_SYSCALL
1664 /* Perform the actual read/write of a sysctl table entry. */
1665 static int do_sysctl_strategy(struct ctl_table_root *root,
1666 struct ctl_table *table,
1667 void __user *oldval, size_t __user *oldlenp,
1668 void __user *newval, size_t newlen)
1676 if (sysctl_perm(root, table, op))
1679 if (table->strategy) {
1680 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1687 /* If there is no strategy routine, or if the strategy returns
1688 * zero, proceed with automatic r/w */
1689 if (table->data && table->maxlen) {
1690 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1697 static int parse_table(int __user *name, int nlen,
1698 void __user *oldval, size_t __user *oldlenp,
1699 void __user *newval, size_t newlen,
1700 struct ctl_table_root *root,
1701 struct ctl_table *table)
1707 if (get_user(n, name))
1709 for ( ; table->ctl_name || table->procname; table++) {
1710 if (!table->ctl_name)
1712 if (n == table->ctl_name) {
1715 if (sysctl_perm(root, table, MAY_EXEC))
1719 table = table->child;
1722 error = do_sysctl_strategy(root, table,
1731 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1732 void __user *newval, size_t newlen)
1734 struct ctl_table_header *head;
1735 int error = -ENOTDIR;
1737 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1741 if (!oldlenp || get_user(old_len, oldlenp))
1745 for (head = sysctl_head_next(NULL); head;
1746 head = sysctl_head_next(head)) {
1747 error = parse_table(name, nlen, oldval, oldlenp,
1749 head->root, head->ctl_table);
1750 if (error != -ENOTDIR) {
1751 sysctl_head_finish(head);
1758 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1760 struct __sysctl_args tmp;
1763 if (copy_from_user(&tmp, args, sizeof(tmp)))
1766 error = deprecated_sysctl_warning(&tmp);
1771 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1772 tmp.newval, tmp.newlen);
1777 #endif /* CONFIG_SYSCTL_SYSCALL */
1780 * sysctl_perm does NOT grant the superuser all rights automatically, because
1781 * some sysctl variables are readonly even to root.
1784 static int test_perm(int mode, int op)
1786 if (!current_euid())
1788 else if (in_egroup_p(0))
1790 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1795 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1800 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1804 if (root->permissions)
1805 mode = root->permissions(root, current->nsproxy, table);
1809 return test_perm(mode, op);
1812 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1814 for (; table->ctl_name || table->procname; table++) {
1815 table->parent = parent;
1817 sysctl_set_parent(table, table->child);
1821 static __init int sysctl_init(void)
1823 sysctl_set_parent(NULL, root_table);
1824 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1827 err = sysctl_check_table(current->nsproxy, root_table);
1833 core_initcall(sysctl_init);
1835 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1836 struct ctl_table *table)
1838 struct ctl_table *p;
1839 const char *s = branch->procname;
1841 /* branch should have named subdirectory as its first element */
1842 if (!s || !branch->child)
1845 /* ... and nothing else */
1846 if (branch[1].procname || branch[1].ctl_name)
1849 /* table should contain subdirectory with the same name */
1850 for (p = table; p->procname || p->ctl_name; p++) {
1853 if (p->procname && strcmp(p->procname, s) == 0)
1859 /* see if attaching q to p would be an improvement */
1860 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1862 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1863 struct ctl_table *next;
1865 int not_in_parent = !p->attached_by;
1867 while ((next = is_branch_in(by, to)) != NULL) {
1868 if (by == q->attached_by)
1870 if (to == p->attached_by)
1876 if (is_better && not_in_parent) {
1877 q->attached_by = by;
1878 q->attached_to = to;
1884 * __register_sysctl_paths - register a sysctl hierarchy
1885 * @root: List of sysctl headers to register on
1886 * @namespaces: Data to compute which lists of sysctl entries are visible
1887 * @path: The path to the directory the sysctl table is in.
1888 * @table: the top-level table structure
1890 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1891 * array. A completely 0 filled entry terminates the table.
1893 * The members of the &struct ctl_table structure are used as follows:
1895 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1896 * must be unique within that level of sysctl
1898 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1899 * enter a sysctl file
1901 * data - a pointer to data for use by proc_handler
1903 * maxlen - the maximum size in bytes of the data
1905 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1907 * child - a pointer to the child sysctl table if this entry is a directory, or
1910 * proc_handler - the text handler routine (described below)
1912 * strategy - the strategy routine (described below)
1914 * de - for internal use by the sysctl routines
1916 * extra1, extra2 - extra pointers usable by the proc handler routines
1918 * Leaf nodes in the sysctl tree will be represented by a single file
1919 * under /proc; non-leaf nodes will be represented by directories.
1921 * sysctl(2) can automatically manage read and write requests through
1922 * the sysctl table. The data and maxlen fields of the ctl_table
1923 * struct enable minimal validation of the values being written to be
1924 * performed, and the mode field allows minimal authentication.
1926 * More sophisticated management can be enabled by the provision of a
1927 * strategy routine with the table entry. This will be called before
1928 * any automatic read or write of the data is performed.
1930 * The strategy routine may return
1932 * < 0 - Error occurred (error is passed to user process)
1934 * 0 - OK - proceed with automatic read or write.
1936 * > 0 - OK - read or write has been done by the strategy routine, so
1937 * return immediately.
1939 * There must be a proc_handler routine for any terminal nodes
1940 * mirrored under /proc/sys (non-terminals are handled by a built-in
1941 * directory handler). Several default handlers are available to
1942 * cover common cases -
1944 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1945 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1946 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1948 * It is the handler's job to read the input buffer from user memory
1949 * and process it. The handler should return 0 on success.
1951 * This routine returns %NULL on a failure to register, and a pointer
1952 * to the table header on success.
1954 struct ctl_table_header *__register_sysctl_paths(
1955 struct ctl_table_root *root,
1956 struct nsproxy *namespaces,
1957 const struct ctl_path *path, struct ctl_table *table)
1959 struct ctl_table_header *header;
1960 struct ctl_table *new, **prevp;
1961 unsigned int n, npath;
1962 struct ctl_table_set *set;
1964 /* Count the path components */
1965 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1969 * For each path component, allocate a 2-element ctl_table array.
1970 * The first array element will be filled with the sysctl entry
1971 * for this, the second will be the sentinel (ctl_name == 0).
1973 * We allocate everything in one go so that we don't have to
1974 * worry about freeing additional memory in unregister_sysctl_table.
1976 header = kzalloc(sizeof(struct ctl_table_header) +
1977 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1981 new = (struct ctl_table *) (header + 1);
1983 /* Now connect the dots */
1984 prevp = &header->ctl_table;
1985 for (n = 0; n < npath; ++n, ++path) {
1986 /* Copy the procname */
1987 new->procname = path->procname;
1988 new->ctl_name = path->ctl_name;
1992 prevp = &new->child;
1997 header->ctl_table_arg = table;
1999 INIT_LIST_HEAD(&header->ctl_entry);
2001 header->unregistering = NULL;
2002 header->root = root;
2003 sysctl_set_parent(NULL, header->ctl_table);
2005 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2006 if (sysctl_check_table(namespaces, header->ctl_table)) {
2011 spin_lock(&sysctl_lock);
2012 header->set = lookup_header_set(root, namespaces);
2013 header->attached_by = header->ctl_table;
2014 header->attached_to = root_table;
2015 header->parent = &root_table_header;
2016 for (set = header->set; set; set = set->parent) {
2017 struct ctl_table_header *p;
2018 list_for_each_entry(p, &set->list, ctl_entry) {
2019 if (p->unregistering)
2021 try_attach(p, header);
2024 header->parent->count++;
2025 list_add_tail(&header->ctl_entry, &header->set->list);
2026 spin_unlock(&sysctl_lock);
2032 * register_sysctl_table_path - register a sysctl table hierarchy
2033 * @path: The path to the directory the sysctl table is in.
2034 * @table: the top-level table structure
2036 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2037 * array. A completely 0 filled entry terminates the table.
2039 * See __register_sysctl_paths for more details.
2041 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2042 struct ctl_table *table)
2044 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2049 * register_sysctl_table - register a sysctl table hierarchy
2050 * @table: the top-level table structure
2052 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2053 * array. A completely 0 filled entry terminates the table.
2055 * See register_sysctl_paths for more details.
2057 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2059 static const struct ctl_path null_path[] = { {} };
2061 return register_sysctl_paths(null_path, table);
2065 * unregister_sysctl_table - unregister a sysctl table hierarchy
2066 * @header: the header returned from register_sysctl_table
2068 * Unregisters the sysctl table and all children. proc entries may not
2069 * actually be removed until they are no longer used by anyone.
2071 void unregister_sysctl_table(struct ctl_table_header * header)
2078 spin_lock(&sysctl_lock);
2079 start_unregistering(header);
2080 if (!--header->parent->count) {
2082 kfree(header->parent);
2084 if (!--header->count)
2086 spin_unlock(&sysctl_lock);
2089 int sysctl_is_seen(struct ctl_table_header *p)
2091 struct ctl_table_set *set = p->set;
2093 spin_lock(&sysctl_lock);
2094 if (p->unregistering)
2096 else if (!set->is_seen)
2099 res = set->is_seen(set);
2100 spin_unlock(&sysctl_lock);
2104 void setup_sysctl_set(struct ctl_table_set *p,
2105 struct ctl_table_set *parent,
2106 int (*is_seen)(struct ctl_table_set *))
2108 INIT_LIST_HEAD(&p->list);
2109 p->parent = parent ? parent : &sysctl_table_root.default_set;
2110 p->is_seen = is_seen;
2113 #else /* !CONFIG_SYSCTL */
2114 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2119 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2120 struct ctl_table *table)
2125 void unregister_sysctl_table(struct ctl_table_header * table)
2129 void setup_sysctl_set(struct ctl_table_set *p,
2130 struct ctl_table_set *parent,
2131 int (*is_seen)(struct ctl_table_set *))
2135 void sysctl_head_put(struct ctl_table_header *head)
2139 #endif /* CONFIG_SYSCTL */
2145 #ifdef CONFIG_PROC_SYSCTL
2147 static int _proc_do_string(void* data, int maxlen, int write,
2148 struct file *filp, void __user *buffer,
2149 size_t *lenp, loff_t *ppos)
2155 if (!data || !maxlen || !*lenp) {
2163 while (len < *lenp) {
2164 if (get_user(c, p++))
2166 if (c == 0 || c == '\n')
2172 if(copy_from_user(data, buffer, len))
2174 ((char *) data)[len] = 0;
2192 if(copy_to_user(buffer, data, len))
2195 if(put_user('\n', ((char __user *) buffer) + len))
2206 * proc_dostring - read a string sysctl
2207 * @table: the sysctl table
2208 * @write: %TRUE if this is a write to the sysctl file
2209 * @filp: the file structure
2210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2214 * Reads/writes a string from/to the user buffer. If the kernel
2215 * buffer provided is not large enough to hold the string, the
2216 * string is truncated. The copied string is %NULL-terminated.
2217 * If the string is being read by the user process, it is copied
2218 * and a newline '\n' is added. It is truncated if the buffer is
2221 * Returns 0 on success.
2223 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2226 return _proc_do_string(table->data, table->maxlen, write, filp,
2227 buffer, lenp, ppos);
2231 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2233 int write, void *data)
2236 *valp = *negp ? -*lvalp : *lvalp;
2241 *lvalp = (unsigned long)-val;
2244 *lvalp = (unsigned long)val;
2250 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2251 int write, struct file *filp, void __user *buffer,
2252 size_t *lenp, loff_t *ppos,
2253 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2254 int write, void *data),
2257 #define TMPBUFLEN 21
2258 int *i, vleft, first=1, neg, val;
2262 char buf[TMPBUFLEN], *p;
2263 char __user *s = buffer;
2265 if (!tbl_data || !table->maxlen || !*lenp ||
2266 (*ppos && !write)) {
2271 i = (int *) tbl_data;
2272 vleft = table->maxlen / sizeof(*i);
2276 conv = do_proc_dointvec_conv;
2278 for (; left && vleft--; i++, first=0) {
2293 if (len > sizeof(buf) - 1)
2294 len = sizeof(buf) - 1;
2295 if (copy_from_user(buf, s, len))
2299 if (*p == '-' && left > 1) {
2303 if (*p < '0' || *p > '9')
2306 lval = simple_strtoul(p, &p, 0);
2309 if ((len < left) && *p && !isspace(*p))
2316 if (conv(&neg, &lval, i, 1, data))
2323 if (conv(&neg, &lval, i, 0, data))
2326 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2330 if(copy_to_user(s, buf, len))
2337 if (!write && !first && left) {
2338 if(put_user('\n', s))
2345 if (get_user(c, s++))
2360 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2361 void __user *buffer, size_t *lenp, loff_t *ppos,
2362 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2363 int write, void *data),
2366 return __do_proc_dointvec(table->data, table, write, filp,
2367 buffer, lenp, ppos, conv, data);
2371 * proc_dointvec - read a vector of integers
2372 * @table: the sysctl table
2373 * @write: %TRUE if this is a write to the sysctl file
2374 * @filp: the file structure
2375 * @buffer: the user buffer
2376 * @lenp: the size of the user buffer
2377 * @ppos: file position
2379 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2380 * values from/to the user buffer, treated as an ASCII string.
2382 * Returns 0 on success.
2384 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2385 void __user *buffer, size_t *lenp, loff_t *ppos)
2387 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2392 * Taint values can only be increased
2393 * This means we can safely use a temporary.
2395 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2396 void __user *buffer, size_t *lenp, loff_t *ppos)
2399 unsigned long tmptaint = get_taint();
2402 if (write && !capable(CAP_SYS_ADMIN))
2407 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2413 * Poor man's atomic or. Not worth adding a primitive
2414 * to everyone's atomic.h for this
2417 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2418 if ((tmptaint >> i) & 1)
2426 struct do_proc_dointvec_minmax_conv_param {
2431 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2433 int write, void *data)
2435 struct do_proc_dointvec_minmax_conv_param *param = data;
2437 int val = *negp ? -*lvalp : *lvalp;
2438 if ((param->min && *param->min > val) ||
2439 (param->max && *param->max < val))
2446 *lvalp = (unsigned long)-val;
2449 *lvalp = (unsigned long)val;
2456 * proc_dointvec_minmax - read a vector of integers with min/max values
2457 * @table: the sysctl table
2458 * @write: %TRUE if this is a write to the sysctl file
2459 * @filp: the file structure
2460 * @buffer: the user buffer
2461 * @lenp: the size of the user buffer
2462 * @ppos: file position
2464 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2465 * values from/to the user buffer, treated as an ASCII string.
2467 * This routine will ensure the values are within the range specified by
2468 * table->extra1 (min) and table->extra2 (max).
2470 * Returns 0 on success.
2472 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2473 void __user *buffer, size_t *lenp, loff_t *ppos)
2475 struct do_proc_dointvec_minmax_conv_param param = {
2476 .min = (int *) table->extra1,
2477 .max = (int *) table->extra2,
2479 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2480 do_proc_dointvec_minmax_conv, ¶m);
2483 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2485 void __user *buffer,
2486 size_t *lenp, loff_t *ppos,
2487 unsigned long convmul,
2488 unsigned long convdiv)
2490 #define TMPBUFLEN 21
2491 unsigned long *i, *min, *max, val;
2492 int vleft, first=1, neg;
2494 char buf[TMPBUFLEN], *p;
2495 char __user *s = buffer;
2497 if (!data || !table->maxlen || !*lenp ||
2498 (*ppos && !write)) {
2503 i = (unsigned long *) data;
2504 min = (unsigned long *) table->extra1;
2505 max = (unsigned long *) table->extra2;
2506 vleft = table->maxlen / sizeof(unsigned long);
2509 for (; left && vleft--; i++, min++, max++, first=0) {
2524 if (len > TMPBUFLEN-1)
2526 if (copy_from_user(buf, s, len))
2530 if (*p == '-' && left > 1) {
2534 if (*p < '0' || *p > '9')
2536 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2538 if ((len < left) && *p && !isspace(*p))
2547 if ((min && val < *min) || (max && val > *max))
2554 sprintf(p, "%lu", convdiv * (*i) / convmul);
2558 if(copy_to_user(s, buf, len))
2565 if (!write && !first && left) {
2566 if(put_user('\n', s))
2573 if (get_user(c, s++))
2588 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2590 void __user *buffer,
2591 size_t *lenp, loff_t *ppos,
2592 unsigned long convmul,
2593 unsigned long convdiv)
2595 return __do_proc_doulongvec_minmax(table->data, table, write,
2596 filp, buffer, lenp, ppos, convmul, convdiv);
2600 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2601 * @table: the sysctl table
2602 * @write: %TRUE if this is a write to the sysctl file
2603 * @filp: the file structure
2604 * @buffer: the user buffer
2605 * @lenp: the size of the user buffer
2606 * @ppos: file position
2608 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2609 * values from/to the user buffer, treated as an ASCII string.
2611 * This routine will ensure the values are within the range specified by
2612 * table->extra1 (min) and table->extra2 (max).
2614 * Returns 0 on success.
2616 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2617 void __user *buffer, size_t *lenp, loff_t *ppos)
2619 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2623 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2624 * @table: the sysctl table
2625 * @write: %TRUE if this is a write to the sysctl file
2626 * @filp: the file structure
2627 * @buffer: the user buffer
2628 * @lenp: the size of the user buffer
2629 * @ppos: file position
2631 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2632 * values from/to the user buffer, treated as an ASCII string. The values
2633 * are treated as milliseconds, and converted to jiffies when they are stored.
2635 * This routine will ensure the values are within the range specified by
2636 * table->extra1 (min) and table->extra2 (max).
2638 * Returns 0 on success.
2640 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2642 void __user *buffer,
2643 size_t *lenp, loff_t *ppos)
2645 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2646 lenp, ppos, HZ, 1000l);
2650 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2652 int write, void *data)
2655 if (*lvalp > LONG_MAX / HZ)
2657 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2663 lval = (unsigned long)-val;
2666 lval = (unsigned long)val;
2673 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2675 int write, void *data)
2678 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2680 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2686 lval = (unsigned long)-val;
2689 lval = (unsigned long)val;
2691 *lvalp = jiffies_to_clock_t(lval);
2696 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2698 int write, void *data)
2701 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2707 lval = (unsigned long)-val;
2710 lval = (unsigned long)val;
2712 *lvalp = jiffies_to_msecs(lval);
2718 * proc_dointvec_jiffies - read a vector of integers as seconds
2719 * @table: the sysctl table
2720 * @write: %TRUE if this is a write to the sysctl file
2721 * @filp: the file structure
2722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
2724 * @ppos: file position
2726 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2727 * values from/to the user buffer, treated as an ASCII string.
2728 * The values read are assumed to be in seconds, and are converted into
2731 * Returns 0 on success.
2733 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2734 void __user *buffer, size_t *lenp, loff_t *ppos)
2736 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2737 do_proc_dointvec_jiffies_conv,NULL);
2741 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
2744 * @filp: the file structure
2745 * @buffer: the user buffer
2746 * @lenp: the size of the user buffer
2747 * @ppos: pointer to the file position
2749 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2750 * values from/to the user buffer, treated as an ASCII string.
2751 * The values read are assumed to be in 1/USER_HZ seconds, and
2752 * are converted into jiffies.
2754 * Returns 0 on success.
2756 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2757 void __user *buffer, size_t *lenp, loff_t *ppos)
2759 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2760 do_proc_dointvec_userhz_jiffies_conv,NULL);
2764 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2765 * @table: the sysctl table
2766 * @write: %TRUE if this is a write to the sysctl file
2767 * @filp: the file structure
2768 * @buffer: the user buffer
2769 * @lenp: the size of the user buffer
2770 * @ppos: file position
2771 * @ppos: the current position in the file
2773 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2774 * values from/to the user buffer, treated as an ASCII string.
2775 * The values read are assumed to be in 1/1000 seconds, and
2776 * are converted into jiffies.
2778 * Returns 0 on success.
2780 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2781 void __user *buffer, size_t *lenp, loff_t *ppos)
2783 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2784 do_proc_dointvec_ms_jiffies_conv, NULL);
2787 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2788 void __user *buffer, size_t *lenp, loff_t *ppos)
2790 struct pid *new_pid;
2794 tmp = pid_vnr(cad_pid);
2796 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2797 lenp, ppos, NULL, NULL);
2801 new_pid = find_get_pid(tmp);
2805 put_pid(xchg(&cad_pid, new_pid));
2809 #else /* CONFIG_PROC_FS */
2811 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2812 void __user *buffer, size_t *lenp, loff_t *ppos)
2817 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2818 void __user *buffer, size_t *lenp, loff_t *ppos)
2823 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2824 void __user *buffer, size_t *lenp, loff_t *ppos)
2829 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2830 void __user *buffer, size_t *lenp, loff_t *ppos)
2835 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2836 void __user *buffer, size_t *lenp, loff_t *ppos)
2841 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2842 void __user *buffer, size_t *lenp, loff_t *ppos)
2847 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2848 void __user *buffer, size_t *lenp, loff_t *ppos)
2853 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2855 void __user *buffer,
2856 size_t *lenp, loff_t *ppos)
2862 #endif /* CONFIG_PROC_FS */
2865 #ifdef CONFIG_SYSCTL_SYSCALL
2867 * General sysctl support routines
2870 /* The generic sysctl data routine (used if no strategy routine supplied) */
2871 int sysctl_data(struct ctl_table *table,
2872 void __user *oldval, size_t __user *oldlenp,
2873 void __user *newval, size_t newlen)
2877 /* Get out of I don't have a variable */
2878 if (!table->data || !table->maxlen)
2881 if (oldval && oldlenp) {
2882 if (get_user(len, oldlenp))
2885 if (len > table->maxlen)
2886 len = table->maxlen;
2887 if (copy_to_user(oldval, table->data, len))
2889 if (put_user(len, oldlenp))
2894 if (newval && newlen) {
2895 if (newlen > table->maxlen)
2896 newlen = table->maxlen;
2898 if (copy_from_user(table->data, newval, newlen))
2904 /* The generic string strategy routine: */
2905 int sysctl_string(struct ctl_table *table,
2906 void __user *oldval, size_t __user *oldlenp,
2907 void __user *newval, size_t newlen)
2909 if (!table->data || !table->maxlen)
2912 if (oldval && oldlenp) {
2914 if (get_user(bufsize, oldlenp))
2917 size_t len = strlen(table->data), copied;
2919 /* This shouldn't trigger for a well-formed sysctl */
2920 if (len > table->maxlen)
2921 len = table->maxlen;
2923 /* Copy up to a max of bufsize-1 bytes of the string */
2924 copied = (len >= bufsize) ? bufsize - 1 : len;
2926 if (copy_to_user(oldval, table->data, copied) ||
2927 put_user(0, (char __user *)(oldval + copied)))
2929 if (put_user(len, oldlenp))
2933 if (newval && newlen) {
2934 size_t len = newlen;
2935 if (len > table->maxlen)
2936 len = table->maxlen;
2937 if(copy_from_user(table->data, newval, len))
2939 if (len == table->maxlen)
2941 ((char *) table->data)[len] = 0;
2947 * This function makes sure that all of the integers in the vector
2948 * are between the minimum and maximum values given in the arrays
2949 * table->extra1 and table->extra2, respectively.
2951 int sysctl_intvec(struct ctl_table *table,
2952 void __user *oldval, size_t __user *oldlenp,
2953 void __user *newval, size_t newlen)
2956 if (newval && newlen) {
2957 int __user *vec = (int __user *) newval;
2958 int *min = (int *) table->extra1;
2959 int *max = (int *) table->extra2;
2963 if (newlen % sizeof(int) != 0)
2966 if (!table->extra1 && !table->extra2)
2969 if (newlen > table->maxlen)
2970 newlen = table->maxlen;
2971 length = newlen / sizeof(int);
2973 for (i = 0; i < length; i++) {
2975 if (get_user(value, vec + i))
2977 if (min && value < min[i])
2979 if (max && value > max[i])
2986 /* Strategy function to convert jiffies to seconds */
2987 int sysctl_jiffies(struct ctl_table *table,
2988 void __user *oldval, size_t __user *oldlenp,
2989 void __user *newval, size_t newlen)
2991 if (oldval && oldlenp) {
2994 if (get_user(olen, oldlenp))
2999 if (olen < sizeof(int))
3002 val = *(int *)(table->data) / HZ;
3003 if (put_user(val, (int __user *)oldval))
3005 if (put_user(sizeof(int), oldlenp))
3009 if (newval && newlen) {
3011 if (newlen != sizeof(int))
3013 if (get_user(new, (int __user *)newval))
3015 *(int *)(table->data) = new*HZ;
3020 /* Strategy function to convert jiffies to seconds */
3021 int sysctl_ms_jiffies(struct ctl_table *table,
3022 void __user *oldval, size_t __user *oldlenp,
3023 void __user *newval, size_t newlen)
3025 if (oldval && oldlenp) {
3028 if (get_user(olen, oldlenp))
3033 if (olen < sizeof(int))
3036 val = jiffies_to_msecs(*(int *)(table->data));
3037 if (put_user(val, (int __user *)oldval))
3039 if (put_user(sizeof(int), oldlenp))
3043 if (newval && newlen) {
3045 if (newlen != sizeof(int))
3047 if (get_user(new, (int __user *)newval))
3049 *(int *)(table->data) = msecs_to_jiffies(new);
3056 #else /* CONFIG_SYSCTL_SYSCALL */
3059 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3061 struct __sysctl_args tmp;
3064 if (copy_from_user(&tmp, args, sizeof(tmp)))
3067 error = deprecated_sysctl_warning(&tmp);
3069 /* If no error reading the parameters then just -ENOSYS ... */
3076 int sysctl_data(struct ctl_table *table,
3077 void __user *oldval, size_t __user *oldlenp,
3078 void __user *newval, size_t newlen)
3083 int sysctl_string(struct ctl_table *table,
3084 void __user *oldval, size_t __user *oldlenp,
3085 void __user *newval, size_t newlen)
3090 int sysctl_intvec(struct ctl_table *table,
3091 void __user *oldval, size_t __user *oldlenp,
3092 void __user *newval, size_t newlen)
3097 int sysctl_jiffies(struct ctl_table *table,
3098 void __user *oldval, size_t __user *oldlenp,
3099 void __user *newval, size_t newlen)
3104 int sysctl_ms_jiffies(struct ctl_table *table,
3105 void __user *oldval, size_t __user *oldlenp,
3106 void __user *newval, size_t newlen)
3111 #endif /* CONFIG_SYSCTL_SYSCALL */
3113 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3115 static int msg_count;
3116 int name[CTL_MAXNAME];
3119 /* Check args->nlen. */
3120 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3123 /* Read in the sysctl name for better debug message logging */
3124 for (i = 0; i < args->nlen; i++)
3125 if (get_user(name[i], args->name + i))
3128 /* Ignore accesses to kernel.version */
3129 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3132 if (msg_count < 5) {
3135 "warning: process `%s' used the deprecated sysctl "
3136 "system call with ", current->comm);
3137 for (i = 0; i < args->nlen; i++)
3138 printk("%d.", name[i]);
3145 * No sense putting this after each symbol definition, twice,
3146 * exception granted :-)
3148 EXPORT_SYMBOL(proc_dointvec);
3149 EXPORT_SYMBOL(proc_dointvec_jiffies);
3150 EXPORT_SYMBOL(proc_dointvec_minmax);
3151 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3152 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3153 EXPORT_SYMBOL(proc_dostring);
3154 EXPORT_SYMBOL(proc_doulongvec_minmax);
3155 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3156 EXPORT_SYMBOL(register_sysctl_table);
3157 EXPORT_SYMBOL(register_sysctl_paths);
3158 EXPORT_SYMBOL(sysctl_intvec);
3159 EXPORT_SYMBOL(sysctl_jiffies);
3160 EXPORT_SYMBOL(sysctl_ms_jiffies);
3161 EXPORT_SYMBOL(sysctl_string);
3162 EXPORT_SYMBOL(sysctl_data);
3163 EXPORT_SYMBOL(unregister_sysctl_table);