2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/kmemcheck.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.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[];
80 extern unsigned int core_pipe_limit;
82 extern int min_free_kbytes;
83 extern int pid_max_min, pid_max_max;
84 extern int sysctl_drop_caches;
85 extern int percpu_pagelist_fraction;
86 extern int compat_log;
87 extern int latencytop_enabled;
88 extern int sysctl_nr_open_min, sysctl_nr_open_max;
90 extern int sysctl_nr_trim_pages;
92 #ifdef CONFIG_RCU_TORTURE_TEST
93 extern int rcutorture_runnable;
94 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
96 extern int blk_iopoll_enabled;
99 /* Constants used for minimum and maximum */
100 #ifdef CONFIG_DETECT_SOFTLOCKUP
101 static int sixty = 60;
102 static int neg_one = -1;
106 static int __maybe_unused one = 1;
107 static int __maybe_unused two = 2;
108 static unsigned long one_ul = 1;
109 static int one_hundred = 100;
111 static int ten_thousand = 10000;
114 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
115 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
117 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
118 static int maxolduid = 65535;
119 static int minolduid;
120 static int min_percpu_pagelist_fract = 8;
122 static int ngroups_max = NGROUPS_MAX;
124 #ifdef CONFIG_MODULES
125 extern char modprobe_path[];
126 extern int modules_disabled;
128 #ifdef CONFIG_CHR_DEV_SG
129 extern int sg_big_buff;
133 #include <asm/system.h>
136 #ifdef CONFIG_SPARC64
137 extern int sysctl_tsb_ratio;
141 extern int pwrsw_enabled;
142 extern int unaligned_enabled;
146 #ifdef CONFIG_MATHEMU
147 extern int sysctl_ieee_emulation_warnings;
149 extern int sysctl_userprocess_debug;
150 extern int spin_retry;
153 #ifdef CONFIG_BSD_PROCESS_ACCT
154 extern int acct_parm[];
158 extern int no_unaligned_warning;
159 extern int unaligned_dump_stack;
162 extern struct ratelimit_state printk_ratelimit_state;
164 #ifdef CONFIG_RT_MUTEXES
165 extern int max_lock_depth;
168 #ifdef CONFIG_PROC_SYSCTL
169 static int proc_do_cad_pid(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171 static int proc_taint(struct ctl_table *table, int write,
172 void __user *buffer, size_t *lenp, loff_t *ppos);
175 static struct ctl_table root_table[];
176 static struct ctl_table_root sysctl_table_root;
177 static struct ctl_table_header root_table_header = {
179 .ctl_table = root_table,
180 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
181 .root = &sysctl_table_root,
182 .set = &sysctl_table_root.default_set,
184 static struct ctl_table_root sysctl_table_root = {
185 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
186 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
189 static struct ctl_table kern_table[];
190 static struct ctl_table vm_table[];
191 static struct ctl_table fs_table[];
192 static struct ctl_table debug_table[];
193 static struct ctl_table dev_table[];
194 extern struct ctl_table random_table[];
195 #ifdef CONFIG_INOTIFY_USER
196 extern struct ctl_table inotify_table[];
199 extern struct ctl_table epoll_table[];
202 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
203 int sysctl_legacy_va_layout;
206 extern int prove_locking;
207 extern int lock_stat;
209 /* The default sysctl tables: */
211 static struct ctl_table root_table[] = {
213 .ctl_name = CTL_KERN,
214 .procname = "kernel",
231 .ctl_name = CTL_DEBUG,
234 .child = debug_table,
243 * NOTE: do not add new entries to this table unless you have read
244 * Documentation/sysctl/ctl_unnumbered.txt
249 #ifdef CONFIG_SCHED_DEBUG
250 static int min_sched_granularity_ns = 100000; /* 100 usecs */
251 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
252 static int min_wakeup_granularity_ns; /* 0 usecs */
253 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
254 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
255 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
256 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
257 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
260 static struct ctl_table kern_table[] = {
262 .ctl_name = CTL_UNNUMBERED,
263 .procname = "sched_child_runs_first",
264 .data = &sysctl_sched_child_runs_first,
265 .maxlen = sizeof(unsigned int),
267 .proc_handler = &proc_dointvec,
269 #ifdef CONFIG_SCHED_DEBUG
271 .ctl_name = CTL_UNNUMBERED,
272 .procname = "sched_min_granularity_ns",
273 .data = &sysctl_sched_min_granularity,
274 .maxlen = sizeof(unsigned int),
276 .proc_handler = &sched_proc_update_handler,
277 .strategy = &sysctl_intvec,
278 .extra1 = &min_sched_granularity_ns,
279 .extra2 = &max_sched_granularity_ns,
282 .ctl_name = CTL_UNNUMBERED,
283 .procname = "sched_latency_ns",
284 .data = &sysctl_sched_latency,
285 .maxlen = sizeof(unsigned int),
287 .proc_handler = &sched_proc_update_handler,
288 .strategy = &sysctl_intvec,
289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
293 .ctl_name = CTL_UNNUMBERED,
294 .procname = "sched_wakeup_granularity_ns",
295 .data = &sysctl_sched_wakeup_granularity,
296 .maxlen = sizeof(unsigned int),
298 .proc_handler = &sched_proc_update_handler,
299 .strategy = &sysctl_intvec,
300 .extra1 = &min_wakeup_granularity_ns,
301 .extra2 = &max_wakeup_granularity_ns,
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_shares_ratelimit",
306 .data = &sysctl_sched_shares_ratelimit,
307 .maxlen = sizeof(unsigned int),
309 .proc_handler = &sched_proc_update_handler,
310 .extra1 = &min_sched_shares_ratelimit,
311 .extra2 = &max_sched_shares_ratelimit,
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_tunable_scaling",
316 .data = &sysctl_sched_tunable_scaling,
317 .maxlen = sizeof(enum sched_tunable_scaling),
319 .proc_handler = &sched_proc_update_handler,
320 .strategy = &sysctl_intvec,
321 .extra1 = &min_sched_tunable_scaling,
322 .extra2 = &max_sched_tunable_scaling,
326 .ctl_name = CTL_UNNUMBERED,
327 .procname = "sched_shares_thresh",
328 .data = &sysctl_sched_shares_thresh,
329 .maxlen = sizeof(unsigned int),
331 .proc_handler = &proc_dointvec_minmax,
332 .strategy = &sysctl_intvec,
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "sched_migration_cost",
338 .data = &sysctl_sched_migration_cost,
339 .maxlen = sizeof(unsigned int),
341 .proc_handler = &proc_dointvec,
344 .ctl_name = CTL_UNNUMBERED,
345 .procname = "sched_nr_migrate",
346 .data = &sysctl_sched_nr_migrate,
347 .maxlen = sizeof(unsigned int),
349 .proc_handler = &proc_dointvec,
352 .ctl_name = CTL_UNNUMBERED,
353 .procname = "sched_time_avg",
354 .data = &sysctl_sched_time_avg,
355 .maxlen = sizeof(unsigned int),
357 .proc_handler = &proc_dointvec,
360 .ctl_name = CTL_UNNUMBERED,
361 .procname = "timer_migration",
362 .data = &sysctl_timer_migration,
363 .maxlen = sizeof(unsigned int),
365 .proc_handler = &proc_dointvec_minmax,
366 .strategy = &sysctl_intvec,
372 .ctl_name = CTL_UNNUMBERED,
373 .procname = "sched_rt_period_us",
374 .data = &sysctl_sched_rt_period,
375 .maxlen = sizeof(unsigned int),
377 .proc_handler = &sched_rt_handler,
380 .ctl_name = CTL_UNNUMBERED,
381 .procname = "sched_rt_runtime_us",
382 .data = &sysctl_sched_rt_runtime,
383 .maxlen = sizeof(int),
385 .proc_handler = &sched_rt_handler,
388 .ctl_name = CTL_UNNUMBERED,
389 .procname = "sched_compat_yield",
390 .data = &sysctl_sched_compat_yield,
391 .maxlen = sizeof(unsigned int),
393 .proc_handler = &proc_dointvec,
395 #ifdef CONFIG_PROVE_LOCKING
397 .ctl_name = CTL_UNNUMBERED,
398 .procname = "prove_locking",
399 .data = &prove_locking,
400 .maxlen = sizeof(int),
402 .proc_handler = &proc_dointvec,
405 #ifdef CONFIG_LOCK_STAT
407 .ctl_name = CTL_UNNUMBERED,
408 .procname = "lock_stat",
410 .maxlen = sizeof(int),
412 .proc_handler = &proc_dointvec,
416 .ctl_name = KERN_PANIC,
418 .data = &panic_timeout,
419 .maxlen = sizeof(int),
421 .proc_handler = &proc_dointvec,
424 .ctl_name = KERN_CORE_USES_PID,
425 .procname = "core_uses_pid",
426 .data = &core_uses_pid,
427 .maxlen = sizeof(int),
429 .proc_handler = &proc_dointvec,
432 .ctl_name = KERN_CORE_PATTERN,
433 .procname = "core_pattern",
434 .data = core_pattern,
435 .maxlen = CORENAME_MAX_SIZE,
437 .proc_handler = &proc_dostring,
438 .strategy = &sysctl_string,
441 .ctl_name = CTL_UNNUMBERED,
442 .procname = "core_pipe_limit",
443 .data = &core_pipe_limit,
444 .maxlen = sizeof(unsigned int),
446 .proc_handler = &proc_dointvec,
448 #ifdef CONFIG_PROC_SYSCTL
450 .procname = "tainted",
451 .maxlen = sizeof(long),
453 .proc_handler = &proc_taint,
456 #ifdef CONFIG_LATENCYTOP
458 .procname = "latencytop",
459 .data = &latencytop_enabled,
460 .maxlen = sizeof(int),
462 .proc_handler = &proc_dointvec,
465 #ifdef CONFIG_BLK_DEV_INITRD
467 .ctl_name = KERN_REALROOTDEV,
468 .procname = "real-root-dev",
469 .data = &real_root_dev,
470 .maxlen = sizeof(int),
472 .proc_handler = &proc_dointvec,
476 .ctl_name = CTL_UNNUMBERED,
477 .procname = "print-fatal-signals",
478 .data = &print_fatal_signals,
479 .maxlen = sizeof(int),
481 .proc_handler = &proc_dointvec,
485 .ctl_name = KERN_SPARC_REBOOT,
486 .procname = "reboot-cmd",
487 .data = reboot_command,
490 .proc_handler = &proc_dostring,
491 .strategy = &sysctl_string,
494 .ctl_name = KERN_SPARC_STOP_A,
495 .procname = "stop-a",
496 .data = &stop_a_enabled,
497 .maxlen = sizeof (int),
499 .proc_handler = &proc_dointvec,
502 .ctl_name = KERN_SPARC_SCONS_PWROFF,
503 .procname = "scons-poweroff",
504 .data = &scons_pwroff,
505 .maxlen = sizeof (int),
507 .proc_handler = &proc_dointvec,
510 #ifdef CONFIG_SPARC64
512 .ctl_name = CTL_UNNUMBERED,
513 .procname = "tsb-ratio",
514 .data = &sysctl_tsb_ratio,
515 .maxlen = sizeof (int),
517 .proc_handler = &proc_dointvec,
522 .ctl_name = KERN_HPPA_PWRSW,
523 .procname = "soft-power",
524 .data = &pwrsw_enabled,
525 .maxlen = sizeof (int),
527 .proc_handler = &proc_dointvec,
530 .ctl_name = KERN_HPPA_UNALIGNED,
531 .procname = "unaligned-trap",
532 .data = &unaligned_enabled,
533 .maxlen = sizeof (int),
535 .proc_handler = &proc_dointvec,
539 .ctl_name = KERN_CTLALTDEL,
540 .procname = "ctrl-alt-del",
542 .maxlen = sizeof(int),
544 .proc_handler = &proc_dointvec,
546 #ifdef CONFIG_FUNCTION_TRACER
548 .ctl_name = CTL_UNNUMBERED,
549 .procname = "ftrace_enabled",
550 .data = &ftrace_enabled,
551 .maxlen = sizeof(int),
553 .proc_handler = &ftrace_enable_sysctl,
556 #ifdef CONFIG_STACK_TRACER
558 .ctl_name = CTL_UNNUMBERED,
559 .procname = "stack_tracer_enabled",
560 .data = &stack_tracer_enabled,
561 .maxlen = sizeof(int),
563 .proc_handler = &stack_trace_sysctl,
566 #ifdef CONFIG_TRACING
568 .ctl_name = CTL_UNNUMBERED,
569 .procname = "ftrace_dump_on_oops",
570 .data = &ftrace_dump_on_oops,
571 .maxlen = sizeof(int),
573 .proc_handler = &proc_dointvec,
576 #ifdef CONFIG_MODULES
578 .ctl_name = KERN_MODPROBE,
579 .procname = "modprobe",
580 .data = &modprobe_path,
581 .maxlen = KMOD_PATH_LEN,
583 .proc_handler = &proc_dostring,
584 .strategy = &sysctl_string,
587 .ctl_name = CTL_UNNUMBERED,
588 .procname = "modules_disabled",
589 .data = &modules_disabled,
590 .maxlen = sizeof(int),
592 /* only handle a transition from default "0" to "1" */
593 .proc_handler = &proc_dointvec_minmax,
598 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
600 .ctl_name = KERN_HOTPLUG,
601 .procname = "hotplug",
602 .data = &uevent_helper,
603 .maxlen = UEVENT_HELPER_PATH_LEN,
605 .proc_handler = &proc_dostring,
606 .strategy = &sysctl_string,
609 #ifdef CONFIG_CHR_DEV_SG
611 .ctl_name = KERN_SG_BIG_BUFF,
612 .procname = "sg-big-buff",
613 .data = &sg_big_buff,
614 .maxlen = sizeof (int),
616 .proc_handler = &proc_dointvec,
619 #ifdef CONFIG_BSD_PROCESS_ACCT
621 .ctl_name = KERN_ACCT,
624 .maxlen = 3*sizeof(int),
626 .proc_handler = &proc_dointvec,
629 #ifdef CONFIG_MAGIC_SYSRQ
631 .ctl_name = KERN_SYSRQ,
633 .data = &__sysrq_enabled,
634 .maxlen = sizeof (int),
636 .proc_handler = &proc_dointvec,
639 #ifdef CONFIG_PROC_SYSCTL
641 .procname = "cad_pid",
643 .maxlen = sizeof (int),
645 .proc_handler = &proc_do_cad_pid,
649 .ctl_name = KERN_MAX_THREADS,
650 .procname = "threads-max",
651 .data = &max_threads,
652 .maxlen = sizeof(int),
654 .proc_handler = &proc_dointvec,
657 .ctl_name = KERN_RANDOM,
658 .procname = "random",
660 .child = random_table,
663 .ctl_name = KERN_OVERFLOWUID,
664 .procname = "overflowuid",
665 .data = &overflowuid,
666 .maxlen = sizeof(int),
668 .proc_handler = &proc_dointvec_minmax,
669 .strategy = &sysctl_intvec,
670 .extra1 = &minolduid,
671 .extra2 = &maxolduid,
674 .ctl_name = KERN_OVERFLOWGID,
675 .procname = "overflowgid",
676 .data = &overflowgid,
677 .maxlen = sizeof(int),
679 .proc_handler = &proc_dointvec_minmax,
680 .strategy = &sysctl_intvec,
681 .extra1 = &minolduid,
682 .extra2 = &maxolduid,
685 #ifdef CONFIG_MATHEMU
687 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
688 .procname = "ieee_emulation_warnings",
689 .data = &sysctl_ieee_emulation_warnings,
690 .maxlen = sizeof(int),
692 .proc_handler = &proc_dointvec,
696 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
697 .procname = "userprocess_debug",
698 .data = &sysctl_userprocess_debug,
699 .maxlen = sizeof(int),
701 .proc_handler = &proc_dointvec,
705 .ctl_name = KERN_PIDMAX,
706 .procname = "pid_max",
708 .maxlen = sizeof (int),
710 .proc_handler = &proc_dointvec_minmax,
711 .strategy = sysctl_intvec,
712 .extra1 = &pid_max_min,
713 .extra2 = &pid_max_max,
716 .ctl_name = KERN_PANIC_ON_OOPS,
717 .procname = "panic_on_oops",
718 .data = &panic_on_oops,
719 .maxlen = sizeof(int),
721 .proc_handler = &proc_dointvec,
723 #if defined CONFIG_PRINTK
725 .ctl_name = KERN_PRINTK,
726 .procname = "printk",
727 .data = &console_loglevel,
728 .maxlen = 4*sizeof(int),
730 .proc_handler = &proc_dointvec,
733 .ctl_name = KERN_PRINTK_RATELIMIT,
734 .procname = "printk_ratelimit",
735 .data = &printk_ratelimit_state.interval,
736 .maxlen = sizeof(int),
738 .proc_handler = &proc_dointvec_jiffies,
739 .strategy = &sysctl_jiffies,
742 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
743 .procname = "printk_ratelimit_burst",
744 .data = &printk_ratelimit_state.burst,
745 .maxlen = sizeof(int),
747 .proc_handler = &proc_dointvec,
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "printk_delay",
752 .data = &printk_delay_msec,
753 .maxlen = sizeof(int),
755 .proc_handler = &proc_dointvec_minmax,
756 .strategy = &sysctl_intvec,
758 .extra2 = &ten_thousand,
762 .ctl_name = KERN_NGROUPS_MAX,
763 .procname = "ngroups_max",
764 .data = &ngroups_max,
765 .maxlen = sizeof (int),
767 .proc_handler = &proc_dointvec,
769 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
771 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
772 .procname = "unknown_nmi_panic",
773 .data = &unknown_nmi_panic,
774 .maxlen = sizeof (int),
776 .proc_handler = &proc_dointvec,
779 .procname = "nmi_watchdog",
780 .data = &nmi_watchdog_enabled,
781 .maxlen = sizeof (int),
783 .proc_handler = &proc_nmi_enabled,
786 #if defined(CONFIG_X86)
788 .ctl_name = KERN_PANIC_ON_NMI,
789 .procname = "panic_on_unrecovered_nmi",
790 .data = &panic_on_unrecovered_nmi,
791 .maxlen = sizeof(int),
793 .proc_handler = &proc_dointvec,
796 .ctl_name = CTL_UNNUMBERED,
797 .procname = "panic_on_io_nmi",
798 .data = &panic_on_io_nmi,
799 .maxlen = sizeof(int),
801 .proc_handler = &proc_dointvec,
804 .ctl_name = KERN_BOOTLOADER_TYPE,
805 .procname = "bootloader_type",
806 .data = &bootloader_type,
807 .maxlen = sizeof (int),
809 .proc_handler = &proc_dointvec,
812 .ctl_name = CTL_UNNUMBERED,
813 .procname = "bootloader_version",
814 .data = &bootloader_version,
815 .maxlen = sizeof (int),
817 .proc_handler = &proc_dointvec,
820 .ctl_name = CTL_UNNUMBERED,
821 .procname = "kstack_depth_to_print",
822 .data = &kstack_depth_to_print,
823 .maxlen = sizeof(int),
825 .proc_handler = &proc_dointvec,
828 .ctl_name = CTL_UNNUMBERED,
829 .procname = "io_delay_type",
830 .data = &io_delay_type,
831 .maxlen = sizeof(int),
833 .proc_handler = &proc_dointvec,
836 #if defined(CONFIG_MMU)
838 .ctl_name = KERN_RANDOMIZE,
839 .procname = "randomize_va_space",
840 .data = &randomize_va_space,
841 .maxlen = sizeof(int),
843 .proc_handler = &proc_dointvec,
846 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
848 .ctl_name = KERN_SPIN_RETRY,
849 .procname = "spin_retry",
851 .maxlen = sizeof (int),
853 .proc_handler = &proc_dointvec,
856 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
858 .procname = "acpi_video_flags",
859 .data = &acpi_realmode_flags,
860 .maxlen = sizeof (unsigned long),
862 .proc_handler = &proc_doulongvec_minmax,
867 .ctl_name = KERN_IA64_UNALIGNED,
868 .procname = "ignore-unaligned-usertrap",
869 .data = &no_unaligned_warning,
870 .maxlen = sizeof (int),
872 .proc_handler = &proc_dointvec,
875 .ctl_name = CTL_UNNUMBERED,
876 .procname = "unaligned-dump-stack",
877 .data = &unaligned_dump_stack,
878 .maxlen = sizeof (int),
880 .proc_handler = &proc_dointvec,
883 #ifdef CONFIG_DETECT_SOFTLOCKUP
885 .ctl_name = CTL_UNNUMBERED,
886 .procname = "softlockup_panic",
887 .data = &softlockup_panic,
888 .maxlen = sizeof(int),
890 .proc_handler = &proc_dointvec_minmax,
891 .strategy = &sysctl_intvec,
896 .ctl_name = CTL_UNNUMBERED,
897 .procname = "softlockup_thresh",
898 .data = &softlockup_thresh,
899 .maxlen = sizeof(int),
901 .proc_handler = &proc_dosoftlockup_thresh,
902 .strategy = &sysctl_intvec,
907 #ifdef CONFIG_DETECT_HUNG_TASK
909 .ctl_name = CTL_UNNUMBERED,
910 .procname = "hung_task_panic",
911 .data = &sysctl_hung_task_panic,
912 .maxlen = sizeof(int),
914 .proc_handler = &proc_dointvec_minmax,
915 .strategy = &sysctl_intvec,
920 .ctl_name = CTL_UNNUMBERED,
921 .procname = "hung_task_check_count",
922 .data = &sysctl_hung_task_check_count,
923 .maxlen = sizeof(unsigned long),
925 .proc_handler = &proc_doulongvec_minmax,
926 .strategy = &sysctl_intvec,
929 .ctl_name = CTL_UNNUMBERED,
930 .procname = "hung_task_timeout_secs",
931 .data = &sysctl_hung_task_timeout_secs,
932 .maxlen = sizeof(unsigned long),
934 .proc_handler = &proc_dohung_task_timeout_secs,
935 .strategy = &sysctl_intvec,
938 .ctl_name = CTL_UNNUMBERED,
939 .procname = "hung_task_warnings",
940 .data = &sysctl_hung_task_warnings,
941 .maxlen = sizeof(unsigned long),
943 .proc_handler = &proc_doulongvec_minmax,
944 .strategy = &sysctl_intvec,
949 .ctl_name = KERN_COMPAT_LOG,
950 .procname = "compat-log",
952 .maxlen = sizeof (int),
954 .proc_handler = &proc_dointvec,
957 #ifdef CONFIG_RT_MUTEXES
959 .ctl_name = KERN_MAX_LOCK_DEPTH,
960 .procname = "max_lock_depth",
961 .data = &max_lock_depth,
962 .maxlen = sizeof(int),
964 .proc_handler = &proc_dointvec,
968 .ctl_name = CTL_UNNUMBERED,
969 .procname = "poweroff_cmd",
970 .data = &poweroff_cmd,
971 .maxlen = POWEROFF_CMD_PATH_LEN,
973 .proc_handler = &proc_dostring,
974 .strategy = &sysctl_string,
978 .ctl_name = CTL_UNNUMBERED,
981 .child = key_sysctls,
984 #ifdef CONFIG_RCU_TORTURE_TEST
986 .ctl_name = CTL_UNNUMBERED,
987 .procname = "rcutorture_runnable",
988 .data = &rcutorture_runnable,
989 .maxlen = sizeof(int),
991 .proc_handler = &proc_dointvec,
994 #ifdef CONFIG_SLOW_WORK
996 .ctl_name = CTL_UNNUMBERED,
997 .procname = "slow-work",
999 .child = slow_work_sysctls,
1002 #ifdef CONFIG_PERF_EVENTS
1004 .ctl_name = CTL_UNNUMBERED,
1005 .procname = "perf_event_paranoid",
1006 .data = &sysctl_perf_event_paranoid,
1007 .maxlen = sizeof(sysctl_perf_event_paranoid),
1009 .proc_handler = &proc_dointvec,
1012 .ctl_name = CTL_UNNUMBERED,
1013 .procname = "perf_event_mlock_kb",
1014 .data = &sysctl_perf_event_mlock,
1015 .maxlen = sizeof(sysctl_perf_event_mlock),
1017 .proc_handler = &proc_dointvec,
1020 .ctl_name = CTL_UNNUMBERED,
1021 .procname = "perf_event_max_sample_rate",
1022 .data = &sysctl_perf_event_sample_rate,
1023 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1025 .proc_handler = &proc_dointvec,
1028 #ifdef CONFIG_KMEMCHECK
1030 .ctl_name = CTL_UNNUMBERED,
1031 .procname = "kmemcheck",
1032 .data = &kmemcheck_enabled,
1033 .maxlen = sizeof(int),
1035 .proc_handler = &proc_dointvec,
1040 .ctl_name = CTL_UNNUMBERED,
1041 .procname = "blk_iopoll",
1042 .data = &blk_iopoll_enabled,
1043 .maxlen = sizeof(int),
1045 .proc_handler = &proc_dointvec,
1049 * NOTE: do not add new entries to this table unless you have read
1050 * Documentation/sysctl/ctl_unnumbered.txt
1055 static struct ctl_table vm_table[] = {
1057 .ctl_name = VM_OVERCOMMIT_MEMORY,
1058 .procname = "overcommit_memory",
1059 .data = &sysctl_overcommit_memory,
1060 .maxlen = sizeof(sysctl_overcommit_memory),
1062 .proc_handler = &proc_dointvec,
1065 .ctl_name = VM_PANIC_ON_OOM,
1066 .procname = "panic_on_oom",
1067 .data = &sysctl_panic_on_oom,
1068 .maxlen = sizeof(sysctl_panic_on_oom),
1070 .proc_handler = &proc_dointvec,
1073 .ctl_name = CTL_UNNUMBERED,
1074 .procname = "oom_kill_allocating_task",
1075 .data = &sysctl_oom_kill_allocating_task,
1076 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1078 .proc_handler = &proc_dointvec,
1081 .ctl_name = CTL_UNNUMBERED,
1082 .procname = "oom_dump_tasks",
1083 .data = &sysctl_oom_dump_tasks,
1084 .maxlen = sizeof(sysctl_oom_dump_tasks),
1086 .proc_handler = &proc_dointvec,
1089 .ctl_name = VM_OVERCOMMIT_RATIO,
1090 .procname = "overcommit_ratio",
1091 .data = &sysctl_overcommit_ratio,
1092 .maxlen = sizeof(sysctl_overcommit_ratio),
1094 .proc_handler = &proc_dointvec,
1097 .ctl_name = VM_PAGE_CLUSTER,
1098 .procname = "page-cluster",
1099 .data = &page_cluster,
1100 .maxlen = sizeof(int),
1102 .proc_handler = &proc_dointvec,
1105 .ctl_name = VM_DIRTY_BACKGROUND,
1106 .procname = "dirty_background_ratio",
1107 .data = &dirty_background_ratio,
1108 .maxlen = sizeof(dirty_background_ratio),
1110 .proc_handler = &dirty_background_ratio_handler,
1111 .strategy = &sysctl_intvec,
1113 .extra2 = &one_hundred,
1116 .ctl_name = CTL_UNNUMBERED,
1117 .procname = "dirty_background_bytes",
1118 .data = &dirty_background_bytes,
1119 .maxlen = sizeof(dirty_background_bytes),
1121 .proc_handler = &dirty_background_bytes_handler,
1122 .strategy = &sysctl_intvec,
1126 .ctl_name = VM_DIRTY_RATIO,
1127 .procname = "dirty_ratio",
1128 .data = &vm_dirty_ratio,
1129 .maxlen = sizeof(vm_dirty_ratio),
1131 .proc_handler = &dirty_ratio_handler,
1132 .strategy = &sysctl_intvec,
1134 .extra2 = &one_hundred,
1137 .ctl_name = CTL_UNNUMBERED,
1138 .procname = "dirty_bytes",
1139 .data = &vm_dirty_bytes,
1140 .maxlen = sizeof(vm_dirty_bytes),
1142 .proc_handler = &dirty_bytes_handler,
1143 .strategy = &sysctl_intvec,
1144 .extra1 = &dirty_bytes_min,
1147 .procname = "dirty_writeback_centisecs",
1148 .data = &dirty_writeback_interval,
1149 .maxlen = sizeof(dirty_writeback_interval),
1151 .proc_handler = &dirty_writeback_centisecs_handler,
1154 .procname = "dirty_expire_centisecs",
1155 .data = &dirty_expire_interval,
1156 .maxlen = sizeof(dirty_expire_interval),
1158 .proc_handler = &proc_dointvec,
1161 .ctl_name = VM_NR_PDFLUSH_THREADS,
1162 .procname = "nr_pdflush_threads",
1163 .data = &nr_pdflush_threads,
1164 .maxlen = sizeof nr_pdflush_threads,
1165 .mode = 0444 /* read-only*/,
1166 .proc_handler = &proc_dointvec,
1169 .ctl_name = VM_SWAPPINESS,
1170 .procname = "swappiness",
1171 .data = &vm_swappiness,
1172 .maxlen = sizeof(vm_swappiness),
1174 .proc_handler = &proc_dointvec_minmax,
1175 .strategy = &sysctl_intvec,
1177 .extra2 = &one_hundred,
1179 #ifdef CONFIG_HUGETLB_PAGE
1181 .procname = "nr_hugepages",
1183 .maxlen = sizeof(unsigned long),
1185 .proc_handler = &hugetlb_sysctl_handler,
1186 .extra1 = (void *)&hugetlb_zero,
1187 .extra2 = (void *)&hugetlb_infinity,
1190 .ctl_name = VM_HUGETLB_GROUP,
1191 .procname = "hugetlb_shm_group",
1192 .data = &sysctl_hugetlb_shm_group,
1193 .maxlen = sizeof(gid_t),
1195 .proc_handler = &proc_dointvec,
1198 .ctl_name = CTL_UNNUMBERED,
1199 .procname = "hugepages_treat_as_movable",
1200 .data = &hugepages_treat_as_movable,
1201 .maxlen = sizeof(int),
1203 .proc_handler = &hugetlb_treat_movable_handler,
1206 .ctl_name = CTL_UNNUMBERED,
1207 .procname = "nr_overcommit_hugepages",
1209 .maxlen = sizeof(unsigned long),
1211 .proc_handler = &hugetlb_overcommit_handler,
1212 .extra1 = (void *)&hugetlb_zero,
1213 .extra2 = (void *)&hugetlb_infinity,
1217 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1218 .procname = "lowmem_reserve_ratio",
1219 .data = &sysctl_lowmem_reserve_ratio,
1220 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1222 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1223 .strategy = &sysctl_intvec,
1226 .ctl_name = VM_DROP_PAGECACHE,
1227 .procname = "drop_caches",
1228 .data = &sysctl_drop_caches,
1229 .maxlen = sizeof(int),
1231 .proc_handler = drop_caches_sysctl_handler,
1232 .strategy = &sysctl_intvec,
1235 .ctl_name = VM_MIN_FREE_KBYTES,
1236 .procname = "min_free_kbytes",
1237 .data = &min_free_kbytes,
1238 .maxlen = sizeof(min_free_kbytes),
1240 .proc_handler = &min_free_kbytes_sysctl_handler,
1241 .strategy = &sysctl_intvec,
1245 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1246 .procname = "percpu_pagelist_fraction",
1247 .data = &percpu_pagelist_fraction,
1248 .maxlen = sizeof(percpu_pagelist_fraction),
1250 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1251 .strategy = &sysctl_intvec,
1252 .extra1 = &min_percpu_pagelist_fract,
1256 .ctl_name = VM_MAX_MAP_COUNT,
1257 .procname = "max_map_count",
1258 .data = &sysctl_max_map_count,
1259 .maxlen = sizeof(sysctl_max_map_count),
1261 .proc_handler = &proc_dointvec
1265 .ctl_name = CTL_UNNUMBERED,
1266 .procname = "nr_trim_pages",
1267 .data = &sysctl_nr_trim_pages,
1268 .maxlen = sizeof(sysctl_nr_trim_pages),
1270 .proc_handler = &proc_dointvec_minmax,
1271 .strategy = &sysctl_intvec,
1276 .ctl_name = VM_LAPTOP_MODE,
1277 .procname = "laptop_mode",
1278 .data = &laptop_mode,
1279 .maxlen = sizeof(laptop_mode),
1281 .proc_handler = &proc_dointvec_jiffies,
1282 .strategy = &sysctl_jiffies,
1285 .ctl_name = VM_BLOCK_DUMP,
1286 .procname = "block_dump",
1287 .data = &block_dump,
1288 .maxlen = sizeof(block_dump),
1290 .proc_handler = &proc_dointvec,
1291 .strategy = &sysctl_intvec,
1295 .ctl_name = VM_VFS_CACHE_PRESSURE,
1296 .procname = "vfs_cache_pressure",
1297 .data = &sysctl_vfs_cache_pressure,
1298 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1300 .proc_handler = &proc_dointvec,
1301 .strategy = &sysctl_intvec,
1304 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1306 .ctl_name = VM_LEGACY_VA_LAYOUT,
1307 .procname = "legacy_va_layout",
1308 .data = &sysctl_legacy_va_layout,
1309 .maxlen = sizeof(sysctl_legacy_va_layout),
1311 .proc_handler = &proc_dointvec,
1312 .strategy = &sysctl_intvec,
1318 .ctl_name = VM_ZONE_RECLAIM_MODE,
1319 .procname = "zone_reclaim_mode",
1320 .data = &zone_reclaim_mode,
1321 .maxlen = sizeof(zone_reclaim_mode),
1323 .proc_handler = &proc_dointvec,
1324 .strategy = &sysctl_intvec,
1328 .ctl_name = VM_MIN_UNMAPPED,
1329 .procname = "min_unmapped_ratio",
1330 .data = &sysctl_min_unmapped_ratio,
1331 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1333 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1334 .strategy = &sysctl_intvec,
1336 .extra2 = &one_hundred,
1339 .ctl_name = VM_MIN_SLAB,
1340 .procname = "min_slab_ratio",
1341 .data = &sysctl_min_slab_ratio,
1342 .maxlen = sizeof(sysctl_min_slab_ratio),
1344 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1345 .strategy = &sysctl_intvec,
1347 .extra2 = &one_hundred,
1352 .ctl_name = CTL_UNNUMBERED,
1353 .procname = "stat_interval",
1354 .data = &sysctl_stat_interval,
1355 .maxlen = sizeof(sysctl_stat_interval),
1357 .proc_handler = &proc_dointvec_jiffies,
1358 .strategy = &sysctl_jiffies,
1362 .ctl_name = CTL_UNNUMBERED,
1363 .procname = "mmap_min_addr",
1364 .data = &dac_mmap_min_addr,
1365 .maxlen = sizeof(unsigned long),
1367 .proc_handler = &mmap_min_addr_handler,
1371 .ctl_name = CTL_UNNUMBERED,
1372 .procname = "numa_zonelist_order",
1373 .data = &numa_zonelist_order,
1374 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1376 .proc_handler = &numa_zonelist_order_handler,
1377 .strategy = &sysctl_string,
1380 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1381 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1383 .ctl_name = VM_VDSO_ENABLED,
1384 .procname = "vdso_enabled",
1385 .data = &vdso_enabled,
1386 .maxlen = sizeof(vdso_enabled),
1388 .proc_handler = &proc_dointvec,
1389 .strategy = &sysctl_intvec,
1393 #ifdef CONFIG_HIGHMEM
1395 .ctl_name = CTL_UNNUMBERED,
1396 .procname = "highmem_is_dirtyable",
1397 .data = &vm_highmem_is_dirtyable,
1398 .maxlen = sizeof(vm_highmem_is_dirtyable),
1400 .proc_handler = &proc_dointvec_minmax,
1401 .strategy = &sysctl_intvec,
1407 .ctl_name = CTL_UNNUMBERED,
1408 .procname = "scan_unevictable_pages",
1409 .data = &scan_unevictable_pages,
1410 .maxlen = sizeof(scan_unevictable_pages),
1412 .proc_handler = &scan_unevictable_handler,
1414 #ifdef CONFIG_MEMORY_FAILURE
1416 .ctl_name = CTL_UNNUMBERED,
1417 .procname = "memory_failure_early_kill",
1418 .data = &sysctl_memory_failure_early_kill,
1419 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1421 .proc_handler = &proc_dointvec_minmax,
1422 .strategy = &sysctl_intvec,
1427 .ctl_name = CTL_UNNUMBERED,
1428 .procname = "memory_failure_recovery",
1429 .data = &sysctl_memory_failure_recovery,
1430 .maxlen = sizeof(sysctl_memory_failure_recovery),
1432 .proc_handler = &proc_dointvec_minmax,
1433 .strategy = &sysctl_intvec,
1440 * NOTE: do not add new entries to this table unless you have read
1441 * Documentation/sysctl/ctl_unnumbered.txt
1446 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1447 static struct ctl_table binfmt_misc_table[] = {
1452 static struct ctl_table fs_table[] = {
1454 .ctl_name = FS_NRINODE,
1455 .procname = "inode-nr",
1456 .data = &inodes_stat,
1457 .maxlen = 2*sizeof(int),
1459 .proc_handler = &proc_dointvec,
1462 .ctl_name = FS_STATINODE,
1463 .procname = "inode-state",
1464 .data = &inodes_stat,
1465 .maxlen = 7*sizeof(int),
1467 .proc_handler = &proc_dointvec,
1470 .procname = "file-nr",
1471 .data = &files_stat,
1472 .maxlen = 3*sizeof(int),
1474 .proc_handler = &proc_nr_files,
1477 .ctl_name = FS_MAXFILE,
1478 .procname = "file-max",
1479 .data = &files_stat.max_files,
1480 .maxlen = sizeof(int),
1482 .proc_handler = &proc_dointvec,
1485 .ctl_name = CTL_UNNUMBERED,
1486 .procname = "nr_open",
1487 .data = &sysctl_nr_open,
1488 .maxlen = sizeof(int),
1490 .proc_handler = &proc_dointvec_minmax,
1491 .extra1 = &sysctl_nr_open_min,
1492 .extra2 = &sysctl_nr_open_max,
1495 .ctl_name = FS_DENTRY,
1496 .procname = "dentry-state",
1497 .data = &dentry_stat,
1498 .maxlen = 6*sizeof(int),
1500 .proc_handler = &proc_dointvec,
1503 .ctl_name = FS_OVERFLOWUID,
1504 .procname = "overflowuid",
1505 .data = &fs_overflowuid,
1506 .maxlen = sizeof(int),
1508 .proc_handler = &proc_dointvec_minmax,
1509 .strategy = &sysctl_intvec,
1510 .extra1 = &minolduid,
1511 .extra2 = &maxolduid,
1514 .ctl_name = FS_OVERFLOWGID,
1515 .procname = "overflowgid",
1516 .data = &fs_overflowgid,
1517 .maxlen = sizeof(int),
1519 .proc_handler = &proc_dointvec_minmax,
1520 .strategy = &sysctl_intvec,
1521 .extra1 = &minolduid,
1522 .extra2 = &maxolduid,
1524 #ifdef CONFIG_FILE_LOCKING
1526 .ctl_name = FS_LEASES,
1527 .procname = "leases-enable",
1528 .data = &leases_enable,
1529 .maxlen = sizeof(int),
1531 .proc_handler = &proc_dointvec,
1534 #ifdef CONFIG_DNOTIFY
1536 .ctl_name = FS_DIR_NOTIFY,
1537 .procname = "dir-notify-enable",
1538 .data = &dir_notify_enable,
1539 .maxlen = sizeof(int),
1541 .proc_handler = &proc_dointvec,
1545 #ifdef CONFIG_FILE_LOCKING
1547 .ctl_name = FS_LEASE_TIME,
1548 .procname = "lease-break-time",
1549 .data = &lease_break_time,
1550 .maxlen = sizeof(int),
1552 .proc_handler = &proc_dointvec,
1557 .procname = "aio-nr",
1559 .maxlen = sizeof(aio_nr),
1561 .proc_handler = &proc_doulongvec_minmax,
1564 .procname = "aio-max-nr",
1565 .data = &aio_max_nr,
1566 .maxlen = sizeof(aio_max_nr),
1568 .proc_handler = &proc_doulongvec_minmax,
1570 #endif /* CONFIG_AIO */
1571 #ifdef CONFIG_INOTIFY_USER
1573 .ctl_name = FS_INOTIFY,
1574 .procname = "inotify",
1576 .child = inotify_table,
1581 .procname = "epoll",
1583 .child = epoll_table,
1588 .ctl_name = KERN_SETUID_DUMPABLE,
1589 .procname = "suid_dumpable",
1590 .data = &suid_dumpable,
1591 .maxlen = sizeof(int),
1593 .proc_handler = &proc_dointvec_minmax,
1594 .strategy = &sysctl_intvec,
1598 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1600 .ctl_name = CTL_UNNUMBERED,
1601 .procname = "binfmt_misc",
1603 .child = binfmt_misc_table,
1607 * NOTE: do not add new entries to this table unless you have read
1608 * Documentation/sysctl/ctl_unnumbered.txt
1613 static struct ctl_table debug_table[] = {
1614 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1616 .ctl_name = CTL_UNNUMBERED,
1617 .procname = "exception-trace",
1618 .data = &show_unhandled_signals,
1619 .maxlen = sizeof(int),
1621 .proc_handler = proc_dointvec
1627 static struct ctl_table dev_table[] = {
1631 static DEFINE_SPINLOCK(sysctl_lock);
1633 /* called under sysctl_lock */
1634 static int use_table(struct ctl_table_header *p)
1636 if (unlikely(p->unregistering))
1642 /* called under sysctl_lock */
1643 static void unuse_table(struct ctl_table_header *p)
1646 if (unlikely(p->unregistering))
1647 complete(p->unregistering);
1650 /* called under sysctl_lock, will reacquire if has to wait */
1651 static void start_unregistering(struct ctl_table_header *p)
1654 * if p->used is 0, nobody will ever touch that entry again;
1655 * we'll eliminate all paths to it before dropping sysctl_lock
1657 if (unlikely(p->used)) {
1658 struct completion wait;
1659 init_completion(&wait);
1660 p->unregistering = &wait;
1661 spin_unlock(&sysctl_lock);
1662 wait_for_completion(&wait);
1663 spin_lock(&sysctl_lock);
1665 /* anything non-NULL; we'll never dereference it */
1666 p->unregistering = ERR_PTR(-EINVAL);
1669 * do not remove from the list until nobody holds it; walking the
1670 * list in do_sysctl() relies on that.
1672 list_del_init(&p->ctl_entry);
1675 void sysctl_head_get(struct ctl_table_header *head)
1677 spin_lock(&sysctl_lock);
1679 spin_unlock(&sysctl_lock);
1682 void sysctl_head_put(struct ctl_table_header *head)
1684 spin_lock(&sysctl_lock);
1687 spin_unlock(&sysctl_lock);
1690 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1694 spin_lock(&sysctl_lock);
1695 if (!use_table(head))
1696 head = ERR_PTR(-ENOENT);
1697 spin_unlock(&sysctl_lock);
1701 void sysctl_head_finish(struct ctl_table_header *head)
1705 spin_lock(&sysctl_lock);
1707 spin_unlock(&sysctl_lock);
1710 static struct ctl_table_set *
1711 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1713 struct ctl_table_set *set = &root->default_set;
1715 set = root->lookup(root, namespaces);
1719 static struct list_head *
1720 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1722 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1726 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1727 struct ctl_table_header *prev)
1729 struct ctl_table_root *root;
1730 struct list_head *header_list;
1731 struct ctl_table_header *head;
1732 struct list_head *tmp;
1734 spin_lock(&sysctl_lock);
1737 tmp = &prev->ctl_entry;
1741 tmp = &root_table_header.ctl_entry;
1743 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1745 if (!use_table(head))
1747 spin_unlock(&sysctl_lock);
1752 header_list = lookup_header_list(root, namespaces);
1753 if (tmp != header_list)
1757 root = list_entry(root->root_list.next,
1758 struct ctl_table_root, root_list);
1759 if (root == &sysctl_table_root)
1761 header_list = lookup_header_list(root, namespaces);
1762 } while (list_empty(header_list));
1763 tmp = header_list->next;
1766 spin_unlock(&sysctl_lock);
1770 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1772 return __sysctl_head_next(current->nsproxy, prev);
1775 void register_sysctl_root(struct ctl_table_root *root)
1777 spin_lock(&sysctl_lock);
1778 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1779 spin_unlock(&sysctl_lock);
1782 #ifdef CONFIG_SYSCTL_SYSCALL
1783 /* Perform the actual read/write of a sysctl table entry. */
1784 static int do_sysctl_strategy(struct ctl_table_root *root,
1785 struct ctl_table *table,
1786 void __user *oldval, size_t __user *oldlenp,
1787 void __user *newval, size_t newlen)
1795 if (sysctl_perm(root, table, op))
1798 if (table->strategy) {
1799 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1806 /* If there is no strategy routine, or if the strategy returns
1807 * zero, proceed with automatic r/w */
1808 if (table->data && table->maxlen) {
1809 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1816 static int parse_table(int __user *name, int nlen,
1817 void __user *oldval, size_t __user *oldlenp,
1818 void __user *newval, size_t newlen,
1819 struct ctl_table_root *root,
1820 struct ctl_table *table)
1826 if (get_user(n, name))
1828 for ( ; table->ctl_name || table->procname; table++) {
1829 if (!table->ctl_name)
1831 if (n == table->ctl_name) {
1834 if (sysctl_perm(root, table, MAY_EXEC))
1838 table = table->child;
1841 error = do_sysctl_strategy(root, table,
1850 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1851 void __user *newval, size_t newlen)
1853 struct ctl_table_header *head;
1854 int error = -ENOTDIR;
1856 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1860 if (!oldlenp || get_user(old_len, oldlenp))
1864 for (head = sysctl_head_next(NULL); head;
1865 head = sysctl_head_next(head)) {
1866 error = parse_table(name, nlen, oldval, oldlenp,
1868 head->root, head->ctl_table);
1869 if (error != -ENOTDIR) {
1870 sysctl_head_finish(head);
1877 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1879 struct __sysctl_args tmp;
1882 if (copy_from_user(&tmp, args, sizeof(tmp)))
1885 error = deprecated_sysctl_warning(&tmp);
1890 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1891 tmp.newval, tmp.newlen);
1896 #endif /* CONFIG_SYSCTL_SYSCALL */
1899 * sysctl_perm does NOT grant the superuser all rights automatically, because
1900 * some sysctl variables are readonly even to root.
1903 static int test_perm(int mode, int op)
1905 if (!current_euid())
1907 else if (in_egroup_p(0))
1909 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1914 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1919 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1923 if (root->permissions)
1924 mode = root->permissions(root, current->nsproxy, table);
1928 return test_perm(mode, op);
1931 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1933 for (; table->ctl_name || table->procname; table++) {
1934 table->parent = parent;
1936 sysctl_set_parent(table, table->child);
1940 static __init int sysctl_init(void)
1942 sysctl_set_parent(NULL, root_table);
1943 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1946 err = sysctl_check_table(current->nsproxy, root_table);
1952 core_initcall(sysctl_init);
1954 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1955 struct ctl_table *table)
1957 struct ctl_table *p;
1958 const char *s = branch->procname;
1960 /* branch should have named subdirectory as its first element */
1961 if (!s || !branch->child)
1964 /* ... and nothing else */
1965 if (branch[1].procname || branch[1].ctl_name)
1968 /* table should contain subdirectory with the same name */
1969 for (p = table; p->procname || p->ctl_name; p++) {
1972 if (p->procname && strcmp(p->procname, s) == 0)
1978 /* see if attaching q to p would be an improvement */
1979 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1981 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1982 struct ctl_table *next;
1984 int not_in_parent = !p->attached_by;
1986 while ((next = is_branch_in(by, to)) != NULL) {
1987 if (by == q->attached_by)
1989 if (to == p->attached_by)
1995 if (is_better && not_in_parent) {
1996 q->attached_by = by;
1997 q->attached_to = to;
2003 * __register_sysctl_paths - register a sysctl hierarchy
2004 * @root: List of sysctl headers to register on
2005 * @namespaces: Data to compute which lists of sysctl entries are visible
2006 * @path: The path to the directory the sysctl table is in.
2007 * @table: the top-level table structure
2009 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2010 * array. A completely 0 filled entry terminates the table.
2012 * The members of the &struct ctl_table structure are used as follows:
2014 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
2015 * must be unique within that level of sysctl
2017 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
2018 * enter a sysctl file
2020 * data - a pointer to data for use by proc_handler
2022 * maxlen - the maximum size in bytes of the data
2024 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
2026 * child - a pointer to the child sysctl table if this entry is a directory, or
2029 * proc_handler - the text handler routine (described below)
2031 * strategy - the strategy routine (described below)
2033 * de - for internal use by the sysctl routines
2035 * extra1, extra2 - extra pointers usable by the proc handler routines
2037 * Leaf nodes in the sysctl tree will be represented by a single file
2038 * under /proc; non-leaf nodes will be represented by directories.
2040 * sysctl(2) can automatically manage read and write requests through
2041 * the sysctl table. The data and maxlen fields of the ctl_table
2042 * struct enable minimal validation of the values being written to be
2043 * performed, and the mode field allows minimal authentication.
2045 * More sophisticated management can be enabled by the provision of a
2046 * strategy routine with the table entry. This will be called before
2047 * any automatic read or write of the data is performed.
2049 * The strategy routine may return
2051 * < 0 - Error occurred (error is passed to user process)
2053 * 0 - OK - proceed with automatic read or write.
2055 * > 0 - OK - read or write has been done by the strategy routine, so
2056 * return immediately.
2058 * There must be a proc_handler routine for any terminal nodes
2059 * mirrored under /proc/sys (non-terminals are handled by a built-in
2060 * directory handler). Several default handlers are available to
2061 * cover common cases -
2063 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2064 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2065 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2067 * It is the handler's job to read the input buffer from user memory
2068 * and process it. The handler should return 0 on success.
2070 * This routine returns %NULL on a failure to register, and a pointer
2071 * to the table header on success.
2073 struct ctl_table_header *__register_sysctl_paths(
2074 struct ctl_table_root *root,
2075 struct nsproxy *namespaces,
2076 const struct ctl_path *path, struct ctl_table *table)
2078 struct ctl_table_header *header;
2079 struct ctl_table *new, **prevp;
2080 unsigned int n, npath;
2081 struct ctl_table_set *set;
2083 /* Count the path components */
2084 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2088 * For each path component, allocate a 2-element ctl_table array.
2089 * The first array element will be filled with the sysctl entry
2090 * for this, the second will be the sentinel (ctl_name == 0).
2092 * We allocate everything in one go so that we don't have to
2093 * worry about freeing additional memory in unregister_sysctl_table.
2095 header = kzalloc(sizeof(struct ctl_table_header) +
2096 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2100 new = (struct ctl_table *) (header + 1);
2102 /* Now connect the dots */
2103 prevp = &header->ctl_table;
2104 for (n = 0; n < npath; ++n, ++path) {
2105 /* Copy the procname */
2106 new->procname = path->procname;
2107 new->ctl_name = path->ctl_name;
2111 prevp = &new->child;
2116 header->ctl_table_arg = table;
2118 INIT_LIST_HEAD(&header->ctl_entry);
2120 header->unregistering = NULL;
2121 header->root = root;
2122 sysctl_set_parent(NULL, header->ctl_table);
2124 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2125 if (sysctl_check_table(namespaces, header->ctl_table)) {
2130 spin_lock(&sysctl_lock);
2131 header->set = lookup_header_set(root, namespaces);
2132 header->attached_by = header->ctl_table;
2133 header->attached_to = root_table;
2134 header->parent = &root_table_header;
2135 for (set = header->set; set; set = set->parent) {
2136 struct ctl_table_header *p;
2137 list_for_each_entry(p, &set->list, ctl_entry) {
2138 if (p->unregistering)
2140 try_attach(p, header);
2143 header->parent->count++;
2144 list_add_tail(&header->ctl_entry, &header->set->list);
2145 spin_unlock(&sysctl_lock);
2151 * register_sysctl_table_path - register a sysctl table hierarchy
2152 * @path: The path to the directory the sysctl table is in.
2153 * @table: the top-level table structure
2155 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2156 * array. A completely 0 filled entry terminates the table.
2158 * See __register_sysctl_paths for more details.
2160 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2161 struct ctl_table *table)
2163 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2168 * register_sysctl_table - register a sysctl table hierarchy
2169 * @table: the top-level table structure
2171 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2172 * array. A completely 0 filled entry terminates the table.
2174 * See register_sysctl_paths for more details.
2176 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2178 static const struct ctl_path null_path[] = { {} };
2180 return register_sysctl_paths(null_path, table);
2184 * unregister_sysctl_table - unregister a sysctl table hierarchy
2185 * @header: the header returned from register_sysctl_table
2187 * Unregisters the sysctl table and all children. proc entries may not
2188 * actually be removed until they are no longer used by anyone.
2190 void unregister_sysctl_table(struct ctl_table_header * header)
2197 spin_lock(&sysctl_lock);
2198 start_unregistering(header);
2199 if (!--header->parent->count) {
2201 kfree(header->parent);
2203 if (!--header->count)
2205 spin_unlock(&sysctl_lock);
2208 int sysctl_is_seen(struct ctl_table_header *p)
2210 struct ctl_table_set *set = p->set;
2212 spin_lock(&sysctl_lock);
2213 if (p->unregistering)
2215 else if (!set->is_seen)
2218 res = set->is_seen(set);
2219 spin_unlock(&sysctl_lock);
2223 void setup_sysctl_set(struct ctl_table_set *p,
2224 struct ctl_table_set *parent,
2225 int (*is_seen)(struct ctl_table_set *))
2227 INIT_LIST_HEAD(&p->list);
2228 p->parent = parent ? parent : &sysctl_table_root.default_set;
2229 p->is_seen = is_seen;
2232 #else /* !CONFIG_SYSCTL */
2233 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2238 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2239 struct ctl_table *table)
2244 void unregister_sysctl_table(struct ctl_table_header * table)
2248 void setup_sysctl_set(struct ctl_table_set *p,
2249 struct ctl_table_set *parent,
2250 int (*is_seen)(struct ctl_table_set *))
2254 void sysctl_head_put(struct ctl_table_header *head)
2258 #endif /* CONFIG_SYSCTL */
2264 #ifdef CONFIG_PROC_SYSCTL
2266 static int _proc_do_string(void* data, int maxlen, int write,
2267 void __user *buffer,
2268 size_t *lenp, loff_t *ppos)
2274 if (!data || !maxlen || !*lenp) {
2282 while (len < *lenp) {
2283 if (get_user(c, p++))
2285 if (c == 0 || c == '\n')
2291 if(copy_from_user(data, buffer, len))
2293 ((char *) data)[len] = 0;
2311 if(copy_to_user(buffer, data, len))
2314 if(put_user('\n', ((char __user *) buffer) + len))
2325 * proc_dostring - read a string sysctl
2326 * @table: the sysctl table
2327 * @write: %TRUE if this is a write to the sysctl file
2328 * @buffer: the user buffer
2329 * @lenp: the size of the user buffer
2330 * @ppos: file position
2332 * Reads/writes a string from/to the user buffer. If the kernel
2333 * buffer provided is not large enough to hold the string, the
2334 * string is truncated. The copied string is %NULL-terminated.
2335 * If the string is being read by the user process, it is copied
2336 * and a newline '\n' is added. It is truncated if the buffer is
2339 * Returns 0 on success.
2341 int proc_dostring(struct ctl_table *table, int write,
2342 void __user *buffer, size_t *lenp, loff_t *ppos)
2344 return _proc_do_string(table->data, table->maxlen, write,
2345 buffer, lenp, ppos);
2349 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2351 int write, void *data)
2354 *valp = *negp ? -*lvalp : *lvalp;
2359 *lvalp = (unsigned long)-val;
2362 *lvalp = (unsigned long)val;
2368 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2369 int write, void __user *buffer,
2370 size_t *lenp, loff_t *ppos,
2371 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2372 int write, void *data),
2375 #define TMPBUFLEN 21
2376 int *i, vleft, first = 1, neg;
2380 char buf[TMPBUFLEN], *p;
2381 char __user *s = buffer;
2383 if (!tbl_data || !table->maxlen || !*lenp ||
2384 (*ppos && !write)) {
2389 i = (int *) tbl_data;
2390 vleft = table->maxlen / sizeof(*i);
2394 conv = do_proc_dointvec_conv;
2396 for (; left && vleft--; i++, first=0) {
2411 if (len > sizeof(buf) - 1)
2412 len = sizeof(buf) - 1;
2413 if (copy_from_user(buf, s, len))
2417 if (*p == '-' && left > 1) {
2421 if (*p < '0' || *p > '9')
2424 lval = simple_strtoul(p, &p, 0);
2427 if ((len < left) && *p && !isspace(*p))
2432 if (conv(&neg, &lval, i, 1, data))
2439 if (conv(&neg, &lval, i, 0, data))
2442 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2446 if(copy_to_user(s, buf, len))
2453 if (!write && !first && left) {
2454 if(put_user('\n', s))
2461 if (get_user(c, s++))
2476 static int do_proc_dointvec(struct ctl_table *table, int write,
2477 void __user *buffer, size_t *lenp, loff_t *ppos,
2478 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2479 int write, void *data),
2482 return __do_proc_dointvec(table->data, table, write,
2483 buffer, lenp, ppos, conv, data);
2487 * proc_dointvec - read a vector of integers
2488 * @table: the sysctl table
2489 * @write: %TRUE if this is a write to the sysctl file
2490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
2492 * @ppos: file position
2494 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2495 * values from/to the user buffer, treated as an ASCII string.
2497 * Returns 0 on success.
2499 int proc_dointvec(struct ctl_table *table, int write,
2500 void __user *buffer, size_t *lenp, loff_t *ppos)
2502 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2507 * Taint values can only be increased
2508 * This means we can safely use a temporary.
2510 static int proc_taint(struct ctl_table *table, int write,
2511 void __user *buffer, size_t *lenp, loff_t *ppos)
2514 unsigned long tmptaint = get_taint();
2517 if (write && !capable(CAP_SYS_ADMIN))
2522 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2528 * Poor man's atomic or. Not worth adding a primitive
2529 * to everyone's atomic.h for this
2532 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2533 if ((tmptaint >> i) & 1)
2541 struct do_proc_dointvec_minmax_conv_param {
2546 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2548 int write, void *data)
2550 struct do_proc_dointvec_minmax_conv_param *param = data;
2552 int val = *negp ? -*lvalp : *lvalp;
2553 if ((param->min && *param->min > val) ||
2554 (param->max && *param->max < val))
2561 *lvalp = (unsigned long)-val;
2564 *lvalp = (unsigned long)val;
2571 * proc_dointvec_minmax - read a vector of integers with min/max values
2572 * @table: the sysctl table
2573 * @write: %TRUE if this is a write to the sysctl file
2574 * @buffer: the user buffer
2575 * @lenp: the size of the user buffer
2576 * @ppos: file position
2578 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2579 * values from/to the user buffer, treated as an ASCII string.
2581 * This routine will ensure the values are within the range specified by
2582 * table->extra1 (min) and table->extra2 (max).
2584 * Returns 0 on success.
2586 int proc_dointvec_minmax(struct ctl_table *table, int write,
2587 void __user *buffer, size_t *lenp, loff_t *ppos)
2589 struct do_proc_dointvec_minmax_conv_param param = {
2590 .min = (int *) table->extra1,
2591 .max = (int *) table->extra2,
2593 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2594 do_proc_dointvec_minmax_conv, ¶m);
2597 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2598 void __user *buffer,
2599 size_t *lenp, loff_t *ppos,
2600 unsigned long convmul,
2601 unsigned long convdiv)
2603 #define TMPBUFLEN 21
2604 unsigned long *i, *min, *max, val;
2605 int vleft, first=1, neg;
2607 char buf[TMPBUFLEN], *p;
2608 char __user *s = buffer;
2610 if (!data || !table->maxlen || !*lenp ||
2611 (*ppos && !write)) {
2616 i = (unsigned long *) data;
2617 min = (unsigned long *) table->extra1;
2618 max = (unsigned long *) table->extra2;
2619 vleft = table->maxlen / sizeof(unsigned long);
2622 for (; left && vleft--; i++, min++, max++, first=0) {
2637 if (len > TMPBUFLEN-1)
2639 if (copy_from_user(buf, s, len))
2643 if (*p == '-' && left > 1) {
2647 if (*p < '0' || *p > '9')
2649 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2651 if ((len < left) && *p && !isspace(*p))
2660 if ((min && val < *min) || (max && val > *max))
2667 sprintf(p, "%lu", convdiv * (*i) / convmul);
2671 if(copy_to_user(s, buf, len))
2678 if (!write && !first && left) {
2679 if(put_user('\n', s))
2686 if (get_user(c, s++))
2701 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2702 void __user *buffer,
2703 size_t *lenp, loff_t *ppos,
2704 unsigned long convmul,
2705 unsigned long convdiv)
2707 return __do_proc_doulongvec_minmax(table->data, table, write,
2708 buffer, lenp, ppos, convmul, convdiv);
2712 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2713 * @table: the sysctl table
2714 * @write: %TRUE if this is a write to the sysctl file
2715 * @buffer: the user buffer
2716 * @lenp: the size of the user buffer
2717 * @ppos: file position
2719 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2720 * values from/to the user buffer, treated as an ASCII string.
2722 * This routine will ensure the values are within the range specified by
2723 * table->extra1 (min) and table->extra2 (max).
2725 * Returns 0 on success.
2727 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2728 void __user *buffer, size_t *lenp, loff_t *ppos)
2730 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2734 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2735 * @table: the sysctl table
2736 * @write: %TRUE if this is a write to the sysctl file
2737 * @buffer: the user buffer
2738 * @lenp: the size of the user buffer
2739 * @ppos: file position
2741 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2742 * values from/to the user buffer, treated as an ASCII string. The values
2743 * are treated as milliseconds, and converted to jiffies when they are stored.
2745 * This routine will ensure the values are within the range specified by
2746 * table->extra1 (min) and table->extra2 (max).
2748 * Returns 0 on success.
2750 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2751 void __user *buffer,
2752 size_t *lenp, loff_t *ppos)
2754 return do_proc_doulongvec_minmax(table, write, buffer,
2755 lenp, ppos, HZ, 1000l);
2759 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2761 int write, void *data)
2764 if (*lvalp > LONG_MAX / HZ)
2766 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2772 lval = (unsigned long)-val;
2775 lval = (unsigned long)val;
2782 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2784 int write, void *data)
2787 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2789 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2795 lval = (unsigned long)-val;
2798 lval = (unsigned long)val;
2800 *lvalp = jiffies_to_clock_t(lval);
2805 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2807 int write, void *data)
2810 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2816 lval = (unsigned long)-val;
2819 lval = (unsigned long)val;
2821 *lvalp = jiffies_to_msecs(lval);
2827 * proc_dointvec_jiffies - read a vector of integers as seconds
2828 * @table: the sysctl table
2829 * @write: %TRUE if this is a write to the sysctl file
2830 * @buffer: the user buffer
2831 * @lenp: the size of the user buffer
2832 * @ppos: file position
2834 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2835 * values from/to the user buffer, treated as an ASCII string.
2836 * The values read are assumed to be in seconds, and are converted into
2839 * Returns 0 on success.
2841 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2842 void __user *buffer, size_t *lenp, loff_t *ppos)
2844 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2845 do_proc_dointvec_jiffies_conv,NULL);
2849 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2850 * @table: the sysctl table
2851 * @write: %TRUE if this is a write to the sysctl file
2852 * @buffer: the user buffer
2853 * @lenp: the size of the user buffer
2854 * @ppos: pointer to the file position
2856 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2857 * values from/to the user buffer, treated as an ASCII string.
2858 * The values read are assumed to be in 1/USER_HZ seconds, and
2859 * are converted into jiffies.
2861 * Returns 0 on success.
2863 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2864 void __user *buffer, size_t *lenp, loff_t *ppos)
2866 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2867 do_proc_dointvec_userhz_jiffies_conv,NULL);
2871 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2872 * @table: the sysctl table
2873 * @write: %TRUE if this is a write to the sysctl file
2874 * @buffer: the user buffer
2875 * @lenp: the size of the user buffer
2876 * @ppos: file position
2877 * @ppos: the current position in the file
2879 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2880 * values from/to the user buffer, treated as an ASCII string.
2881 * The values read are assumed to be in 1/1000 seconds, and
2882 * are converted into jiffies.
2884 * Returns 0 on success.
2886 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2887 void __user *buffer, size_t *lenp, loff_t *ppos)
2889 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2890 do_proc_dointvec_ms_jiffies_conv, NULL);
2893 static int proc_do_cad_pid(struct ctl_table *table, int write,
2894 void __user *buffer, size_t *lenp, loff_t *ppos)
2896 struct pid *new_pid;
2900 tmp = pid_vnr(cad_pid);
2902 r = __do_proc_dointvec(&tmp, table, write, buffer,
2903 lenp, ppos, NULL, NULL);
2907 new_pid = find_get_pid(tmp);
2911 put_pid(xchg(&cad_pid, new_pid));
2915 #else /* CONFIG_PROC_FS */
2917 int proc_dostring(struct ctl_table *table, int write,
2918 void __user *buffer, size_t *lenp, loff_t *ppos)
2923 int proc_dointvec(struct ctl_table *table, int write,
2924 void __user *buffer, size_t *lenp, loff_t *ppos)
2929 int proc_dointvec_minmax(struct ctl_table *table, int write,
2930 void __user *buffer, size_t *lenp, loff_t *ppos)
2935 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2936 void __user *buffer, size_t *lenp, loff_t *ppos)
2941 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2942 void __user *buffer, size_t *lenp, loff_t *ppos)
2947 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2948 void __user *buffer, size_t *lenp, loff_t *ppos)
2953 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2954 void __user *buffer, size_t *lenp, loff_t *ppos)
2959 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2960 void __user *buffer,
2961 size_t *lenp, loff_t *ppos)
2967 #endif /* CONFIG_PROC_FS */
2970 #ifdef CONFIG_SYSCTL_SYSCALL
2972 * General sysctl support routines
2975 /* The generic sysctl data routine (used if no strategy routine supplied) */
2976 int sysctl_data(struct ctl_table *table,
2977 void __user *oldval, size_t __user *oldlenp,
2978 void __user *newval, size_t newlen)
2982 /* Get out of I don't have a variable */
2983 if (!table->data || !table->maxlen)
2986 if (oldval && oldlenp) {
2987 if (get_user(len, oldlenp))
2990 if (len > table->maxlen)
2991 len = table->maxlen;
2992 if (copy_to_user(oldval, table->data, len))
2994 if (put_user(len, oldlenp))
2999 if (newval && newlen) {
3000 if (newlen > table->maxlen)
3001 newlen = table->maxlen;
3003 if (copy_from_user(table->data, newval, newlen))
3009 /* The generic string strategy routine: */
3010 int sysctl_string(struct ctl_table *table,
3011 void __user *oldval, size_t __user *oldlenp,
3012 void __user *newval, size_t newlen)
3014 if (!table->data || !table->maxlen)
3017 if (oldval && oldlenp) {
3019 if (get_user(bufsize, oldlenp))
3022 size_t len = strlen(table->data), copied;
3024 /* This shouldn't trigger for a well-formed sysctl */
3025 if (len > table->maxlen)
3026 len = table->maxlen;
3028 /* Copy up to a max of bufsize-1 bytes of the string */
3029 copied = (len >= bufsize) ? bufsize - 1 : len;
3031 if (copy_to_user(oldval, table->data, copied) ||
3032 put_user(0, (char __user *)(oldval + copied)))
3034 if (put_user(len, oldlenp))
3038 if (newval && newlen) {
3039 size_t len = newlen;
3040 if (len > table->maxlen)
3041 len = table->maxlen;
3042 if(copy_from_user(table->data, newval, len))
3044 if (len == table->maxlen)
3046 ((char *) table->data)[len] = 0;
3052 * This function makes sure that all of the integers in the vector
3053 * are between the minimum and maximum values given in the arrays
3054 * table->extra1 and table->extra2, respectively.
3056 int sysctl_intvec(struct ctl_table *table,
3057 void __user *oldval, size_t __user *oldlenp,
3058 void __user *newval, size_t newlen)
3061 if (newval && newlen) {
3062 int __user *vec = (int __user *) newval;
3063 int *min = (int *) table->extra1;
3064 int *max = (int *) table->extra2;
3068 if (newlen % sizeof(int) != 0)
3071 if (!table->extra1 && !table->extra2)
3074 if (newlen > table->maxlen)
3075 newlen = table->maxlen;
3076 length = newlen / sizeof(int);
3078 for (i = 0; i < length; i++) {
3080 if (get_user(value, vec + i))
3082 if (min && value < min[i])
3084 if (max && value > max[i])
3091 /* Strategy function to convert jiffies to seconds */
3092 int sysctl_jiffies(struct ctl_table *table,
3093 void __user *oldval, size_t __user *oldlenp,
3094 void __user *newval, size_t newlen)
3096 if (oldval && oldlenp) {
3099 if (get_user(olen, oldlenp))
3104 if (olen < sizeof(int))
3107 val = *(int *)(table->data) / HZ;
3108 if (put_user(val, (int __user *)oldval))
3110 if (put_user(sizeof(int), oldlenp))
3114 if (newval && newlen) {
3116 if (newlen != sizeof(int))
3118 if (get_user(new, (int __user *)newval))
3120 *(int *)(table->data) = new*HZ;
3125 /* Strategy function to convert jiffies to seconds */
3126 int sysctl_ms_jiffies(struct ctl_table *table,
3127 void __user *oldval, size_t __user *oldlenp,
3128 void __user *newval, size_t newlen)
3130 if (oldval && oldlenp) {
3133 if (get_user(olen, oldlenp))
3138 if (olen < sizeof(int))
3141 val = jiffies_to_msecs(*(int *)(table->data));
3142 if (put_user(val, (int __user *)oldval))
3144 if (put_user(sizeof(int), oldlenp))
3148 if (newval && newlen) {
3150 if (newlen != sizeof(int))
3152 if (get_user(new, (int __user *)newval))
3154 *(int *)(table->data) = msecs_to_jiffies(new);
3161 #else /* CONFIG_SYSCTL_SYSCALL */
3164 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3166 struct __sysctl_args tmp;
3169 if (copy_from_user(&tmp, args, sizeof(tmp)))
3172 error = deprecated_sysctl_warning(&tmp);
3174 /* If no error reading the parameters then just -ENOSYS ... */
3181 int sysctl_data(struct ctl_table *table,
3182 void __user *oldval, size_t __user *oldlenp,
3183 void __user *newval, size_t newlen)
3188 int sysctl_string(struct ctl_table *table,
3189 void __user *oldval, size_t __user *oldlenp,
3190 void __user *newval, size_t newlen)
3195 int sysctl_intvec(struct ctl_table *table,
3196 void __user *oldval, size_t __user *oldlenp,
3197 void __user *newval, size_t newlen)
3202 int sysctl_jiffies(struct ctl_table *table,
3203 void __user *oldval, size_t __user *oldlenp,
3204 void __user *newval, size_t newlen)
3209 int sysctl_ms_jiffies(struct ctl_table *table,
3210 void __user *oldval, size_t __user *oldlenp,
3211 void __user *newval, size_t newlen)
3216 #endif /* CONFIG_SYSCTL_SYSCALL */
3218 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3220 static int msg_count;
3221 int name[CTL_MAXNAME];
3224 /* Check args->nlen. */
3225 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3228 /* Read in the sysctl name for better debug message logging */
3229 for (i = 0; i < args->nlen; i++)
3230 if (get_user(name[i], args->name + i))
3233 /* Ignore accesses to kernel.version */
3234 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3237 if (msg_count < 5) {
3240 "warning: process `%s' used the deprecated sysctl "
3241 "system call with ", current->comm);
3242 for (i = 0; i < args->nlen; i++)
3243 printk("%d.", name[i]);
3250 * No sense putting this after each symbol definition, twice,
3251 * exception granted :-)
3253 EXPORT_SYMBOL(proc_dointvec);
3254 EXPORT_SYMBOL(proc_dointvec_jiffies);
3255 EXPORT_SYMBOL(proc_dointvec_minmax);
3256 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3257 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3258 EXPORT_SYMBOL(proc_dostring);
3259 EXPORT_SYMBOL(proc_doulongvec_minmax);
3260 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3261 EXPORT_SYMBOL(register_sysctl_table);
3262 EXPORT_SYMBOL(register_sysctl_paths);
3263 EXPORT_SYMBOL(sysctl_intvec);
3264 EXPORT_SYMBOL(sysctl_jiffies);
3265 EXPORT_SYMBOL(sysctl_ms_jiffies);
3266 EXPORT_SYMBOL(sysctl_string);
3267 EXPORT_SYMBOL(sysctl_data);
3268 EXPORT_SYMBOL(unregister_sysctl_table);