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>
31 #include <linux/init.h>
32 #include <linux/kernel.h>
33 #include <linux/kobject.h>
34 #include <linux/net.h>
35 #include <linux/sysrq.h>
36 #include <linux/highuid.h>
37 #include <linux/writeback.h>
38 #include <linux/hugetlb.h>
39 #include <linux/initrd.h>
40 #include <linux/key.h>
41 #include <linux/times.h>
42 #include <linux/limits.h>
43 #include <linux/dcache.h>
44 #include <linux/syscalls.h>
45 #include <linux/vmstat.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
49 #include <linux/ftrace.h>
50 #include <linux/slow-work.h>
51 #include <linux/perf_event.h>
53 #include <asm/uaccess.h>
54 #include <asm/processor.h>
58 #include <asm/stacktrace.h>
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
77 extern unsigned int core_pipe_limit;
79 extern int min_free_kbytes;
80 extern int pid_max_min, pid_max_max;
81 extern int sysctl_drop_caches;
82 extern int percpu_pagelist_fraction;
83 extern int compat_log;
84 extern int latencytop_enabled;
85 extern int sysctl_nr_open_min, sysctl_nr_open_max;
87 extern int sysctl_nr_trim_pages;
89 #ifdef CONFIG_RCU_TORTURE_TEST
90 extern int rcutorture_runnable;
91 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
93 extern int blk_iopoll_enabled;
96 /* Constants used for minimum and maximum */
97 #ifdef CONFIG_DETECT_SOFTLOCKUP
98 static int sixty = 60;
99 static int neg_one = -1;
103 static int __maybe_unused one = 1;
104 static int __maybe_unused two = 2;
105 static unsigned long one_ul = 1;
106 static int one_hundred = 100;
108 static int ten_thousand = 10000;
111 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
112 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
114 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
115 static int maxolduid = 65535;
116 static int minolduid;
117 static int min_percpu_pagelist_fract = 8;
119 static int ngroups_max = NGROUPS_MAX;
121 #ifdef CONFIG_MODULES
122 extern char modprobe_path[];
123 extern int modules_disabled;
125 #ifdef CONFIG_CHR_DEV_SG
126 extern int sg_big_buff;
130 #include <asm/system.h>
133 #ifdef CONFIG_SPARC64
134 extern int sysctl_tsb_ratio;
138 extern int pwrsw_enabled;
139 extern int unaligned_enabled;
143 #ifdef CONFIG_MATHEMU
144 extern int sysctl_ieee_emulation_warnings;
146 extern int sysctl_userprocess_debug;
147 extern int spin_retry;
150 #ifdef CONFIG_BSD_PROCESS_ACCT
151 extern int acct_parm[];
155 extern int no_unaligned_warning;
156 extern int unaligned_dump_stack;
159 #ifdef CONFIG_RT_MUTEXES
160 extern int max_lock_depth;
163 #ifdef CONFIG_PROC_SYSCTL
164 static int proc_do_cad_pid(struct ctl_table *table, int write,
165 void __user *buffer, size_t *lenp, loff_t *ppos);
166 static int proc_taint(struct ctl_table *table, int write,
167 void __user *buffer, size_t *lenp, loff_t *ppos);
170 static struct ctl_table root_table[];
171 static struct ctl_table_root sysctl_table_root;
172 static struct ctl_table_header root_table_header = {
174 .ctl_table = root_table,
175 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
176 .root = &sysctl_table_root,
177 .set = &sysctl_table_root.default_set,
179 static struct ctl_table_root sysctl_table_root = {
180 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
181 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
184 static struct ctl_table kern_table[];
185 static struct ctl_table vm_table[];
186 static struct ctl_table fs_table[];
187 static struct ctl_table debug_table[];
188 static struct ctl_table dev_table[];
189 extern struct ctl_table random_table[];
190 #ifdef CONFIG_INOTIFY_USER
191 extern struct ctl_table inotify_table[];
194 extern struct ctl_table epoll_table[];
197 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
198 int sysctl_legacy_va_layout;
201 extern int prove_locking;
202 extern int lock_stat;
204 /* The default sysctl tables: */
206 static struct ctl_table root_table[] = {
208 .procname = "kernel",
225 .child = debug_table,
233 * NOTE: do not add new entries to this table unless you have read
234 * Documentation/sysctl/ctl_unnumbered.txt
239 #ifdef CONFIG_SCHED_DEBUG
240 static int min_sched_granularity_ns = 100000; /* 100 usecs */
241 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
242 static int min_wakeup_granularity_ns; /* 0 usecs */
243 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
246 static struct ctl_table kern_table[] = {
248 .procname = "sched_child_runs_first",
249 .data = &sysctl_sched_child_runs_first,
250 .maxlen = sizeof(unsigned int),
252 .proc_handler = proc_dointvec,
254 #ifdef CONFIG_SCHED_DEBUG
256 .procname = "sched_min_granularity_ns",
257 .data = &sysctl_sched_min_granularity,
258 .maxlen = sizeof(unsigned int),
260 .proc_handler = sched_nr_latency_handler,
261 .extra1 = &min_sched_granularity_ns,
262 .extra2 = &max_sched_granularity_ns,
265 .procname = "sched_latency_ns",
266 .data = &sysctl_sched_latency,
267 .maxlen = sizeof(unsigned int),
269 .proc_handler = sched_nr_latency_handler,
270 .extra1 = &min_sched_granularity_ns,
271 .extra2 = &max_sched_granularity_ns,
274 .procname = "sched_wakeup_granularity_ns",
275 .data = &sysctl_sched_wakeup_granularity,
276 .maxlen = sizeof(unsigned int),
278 .proc_handler = proc_dointvec_minmax,
279 .extra1 = &min_wakeup_granularity_ns,
280 .extra2 = &max_wakeup_granularity_ns,
283 .procname = "sched_shares_ratelimit",
284 .data = &sysctl_sched_shares_ratelimit,
285 .maxlen = sizeof(unsigned int),
287 .proc_handler = proc_dointvec,
290 .procname = "sched_shares_thresh",
291 .data = &sysctl_sched_shares_thresh,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = proc_dointvec_minmax,
298 .procname = "sched_features",
299 .data = &sysctl_sched_features,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = proc_dointvec,
305 .procname = "sched_migration_cost",
306 .data = &sysctl_sched_migration_cost,
307 .maxlen = sizeof(unsigned int),
309 .proc_handler = proc_dointvec,
312 .procname = "sched_nr_migrate",
313 .data = &sysctl_sched_nr_migrate,
314 .maxlen = sizeof(unsigned int),
316 .proc_handler = proc_dointvec,
319 .procname = "sched_time_avg",
320 .data = &sysctl_sched_time_avg,
321 .maxlen = sizeof(unsigned int),
323 .proc_handler = proc_dointvec,
326 .procname = "timer_migration",
327 .data = &sysctl_timer_migration,
328 .maxlen = sizeof(unsigned int),
330 .proc_handler = proc_dointvec_minmax,
336 .procname = "sched_rt_period_us",
337 .data = &sysctl_sched_rt_period,
338 .maxlen = sizeof(unsigned int),
340 .proc_handler = sched_rt_handler,
343 .procname = "sched_rt_runtime_us",
344 .data = &sysctl_sched_rt_runtime,
345 .maxlen = sizeof(int),
347 .proc_handler = sched_rt_handler,
350 .procname = "sched_compat_yield",
351 .data = &sysctl_sched_compat_yield,
352 .maxlen = sizeof(unsigned int),
354 .proc_handler = proc_dointvec,
356 #ifdef CONFIG_PROVE_LOCKING
358 .procname = "prove_locking",
359 .data = &prove_locking,
360 .maxlen = sizeof(int),
362 .proc_handler = proc_dointvec,
365 #ifdef CONFIG_LOCK_STAT
367 .procname = "lock_stat",
369 .maxlen = sizeof(int),
371 .proc_handler = proc_dointvec,
376 .data = &panic_timeout,
377 .maxlen = sizeof(int),
379 .proc_handler = proc_dointvec,
382 .procname = "core_uses_pid",
383 .data = &core_uses_pid,
384 .maxlen = sizeof(int),
386 .proc_handler = proc_dointvec,
389 .procname = "core_pattern",
390 .data = core_pattern,
391 .maxlen = CORENAME_MAX_SIZE,
393 .proc_handler = proc_dostring,
396 .procname = "core_pipe_limit",
397 .data = &core_pipe_limit,
398 .maxlen = sizeof(unsigned int),
400 .proc_handler = proc_dointvec,
402 #ifdef CONFIG_PROC_SYSCTL
404 .procname = "tainted",
405 .maxlen = sizeof(long),
407 .proc_handler = proc_taint,
410 #ifdef CONFIG_LATENCYTOP
412 .procname = "latencytop",
413 .data = &latencytop_enabled,
414 .maxlen = sizeof(int),
416 .proc_handler = proc_dointvec,
419 #ifdef CONFIG_BLK_DEV_INITRD
421 .procname = "real-root-dev",
422 .data = &real_root_dev,
423 .maxlen = sizeof(int),
425 .proc_handler = proc_dointvec,
429 .procname = "print-fatal-signals",
430 .data = &print_fatal_signals,
431 .maxlen = sizeof(int),
433 .proc_handler = proc_dointvec,
437 .procname = "reboot-cmd",
438 .data = reboot_command,
441 .proc_handler = proc_dostring,
444 .procname = "stop-a",
445 .data = &stop_a_enabled,
446 .maxlen = sizeof (int),
448 .proc_handler = proc_dointvec,
451 .procname = "scons-poweroff",
452 .data = &scons_pwroff,
453 .maxlen = sizeof (int),
455 .proc_handler = proc_dointvec,
458 #ifdef CONFIG_SPARC64
460 .procname = "tsb-ratio",
461 .data = &sysctl_tsb_ratio,
462 .maxlen = sizeof (int),
464 .proc_handler = proc_dointvec,
469 .procname = "soft-power",
470 .data = &pwrsw_enabled,
471 .maxlen = sizeof (int),
473 .proc_handler = proc_dointvec,
476 .procname = "unaligned-trap",
477 .data = &unaligned_enabled,
478 .maxlen = sizeof (int),
480 .proc_handler = proc_dointvec,
484 .procname = "ctrl-alt-del",
486 .maxlen = sizeof(int),
488 .proc_handler = proc_dointvec,
490 #ifdef CONFIG_FUNCTION_TRACER
492 .procname = "ftrace_enabled",
493 .data = &ftrace_enabled,
494 .maxlen = sizeof(int),
496 .proc_handler = ftrace_enable_sysctl,
499 #ifdef CONFIG_STACK_TRACER
501 .procname = "stack_tracer_enabled",
502 .data = &stack_tracer_enabled,
503 .maxlen = sizeof(int),
505 .proc_handler = stack_trace_sysctl,
508 #ifdef CONFIG_TRACING
510 .procname = "ftrace_dump_on_oops",
511 .data = &ftrace_dump_on_oops,
512 .maxlen = sizeof(int),
514 .proc_handler = proc_dointvec,
517 #ifdef CONFIG_MODULES
519 .procname = "modprobe",
520 .data = &modprobe_path,
521 .maxlen = KMOD_PATH_LEN,
523 .proc_handler = proc_dostring,
526 .procname = "modules_disabled",
527 .data = &modules_disabled,
528 .maxlen = sizeof(int),
530 /* only handle a transition from default "0" to "1" */
531 .proc_handler = proc_dointvec_minmax,
536 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
538 .procname = "hotplug",
539 .data = &uevent_helper,
540 .maxlen = UEVENT_HELPER_PATH_LEN,
542 .proc_handler = proc_dostring,
545 #ifdef CONFIG_CHR_DEV_SG
547 .procname = "sg-big-buff",
548 .data = &sg_big_buff,
549 .maxlen = sizeof (int),
551 .proc_handler = proc_dointvec,
554 #ifdef CONFIG_BSD_PROCESS_ACCT
558 .maxlen = 3*sizeof(int),
560 .proc_handler = proc_dointvec,
563 #ifdef CONFIG_MAGIC_SYSRQ
566 .data = &__sysrq_enabled,
567 .maxlen = sizeof (int),
569 .proc_handler = proc_dointvec,
572 #ifdef CONFIG_PROC_SYSCTL
574 .procname = "cad_pid",
576 .maxlen = sizeof (int),
578 .proc_handler = proc_do_cad_pid,
582 .procname = "threads-max",
583 .data = &max_threads,
584 .maxlen = sizeof(int),
586 .proc_handler = proc_dointvec,
589 .procname = "random",
591 .child = random_table,
594 .procname = "overflowuid",
595 .data = &overflowuid,
596 .maxlen = sizeof(int),
598 .proc_handler = proc_dointvec_minmax,
599 .extra1 = &minolduid,
600 .extra2 = &maxolduid,
603 .procname = "overflowgid",
604 .data = &overflowgid,
605 .maxlen = sizeof(int),
607 .proc_handler = proc_dointvec_minmax,
608 .extra1 = &minolduid,
609 .extra2 = &maxolduid,
612 #ifdef CONFIG_MATHEMU
614 .procname = "ieee_emulation_warnings",
615 .data = &sysctl_ieee_emulation_warnings,
616 .maxlen = sizeof(int),
618 .proc_handler = proc_dointvec,
622 .procname = "userprocess_debug",
623 .data = &sysctl_userprocess_debug,
624 .maxlen = sizeof(int),
626 .proc_handler = proc_dointvec,
630 .procname = "pid_max",
632 .maxlen = sizeof (int),
634 .proc_handler = proc_dointvec_minmax,
635 .extra1 = &pid_max_min,
636 .extra2 = &pid_max_max,
639 .procname = "panic_on_oops",
640 .data = &panic_on_oops,
641 .maxlen = sizeof(int),
643 .proc_handler = proc_dointvec,
645 #if defined CONFIG_PRINTK
647 .procname = "printk",
648 .data = &console_loglevel,
649 .maxlen = 4*sizeof(int),
651 .proc_handler = proc_dointvec,
654 .procname = "printk_ratelimit",
655 .data = &printk_ratelimit_state.interval,
656 .maxlen = sizeof(int),
658 .proc_handler = proc_dointvec_jiffies,
661 .procname = "printk_ratelimit_burst",
662 .data = &printk_ratelimit_state.burst,
663 .maxlen = sizeof(int),
665 .proc_handler = proc_dointvec,
668 .procname = "printk_delay",
669 .data = &printk_delay_msec,
670 .maxlen = sizeof(int),
672 .proc_handler = proc_dointvec_minmax,
674 .extra2 = &ten_thousand,
678 .procname = "ngroups_max",
679 .data = &ngroups_max,
680 .maxlen = sizeof (int),
682 .proc_handler = proc_dointvec,
684 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
686 .procname = "unknown_nmi_panic",
687 .data = &unknown_nmi_panic,
688 .maxlen = sizeof (int),
690 .proc_handler = proc_dointvec,
693 .procname = "nmi_watchdog",
694 .data = &nmi_watchdog_enabled,
695 .maxlen = sizeof (int),
697 .proc_handler = proc_nmi_enabled,
700 #if defined(CONFIG_X86)
702 .procname = "panic_on_unrecovered_nmi",
703 .data = &panic_on_unrecovered_nmi,
704 .maxlen = sizeof(int),
706 .proc_handler = proc_dointvec,
709 .procname = "panic_on_io_nmi",
710 .data = &panic_on_io_nmi,
711 .maxlen = sizeof(int),
713 .proc_handler = proc_dointvec,
716 .procname = "bootloader_type",
717 .data = &bootloader_type,
718 .maxlen = sizeof (int),
720 .proc_handler = proc_dointvec,
723 .procname = "bootloader_version",
724 .data = &bootloader_version,
725 .maxlen = sizeof (int),
727 .proc_handler = proc_dointvec,
730 .procname = "kstack_depth_to_print",
731 .data = &kstack_depth_to_print,
732 .maxlen = sizeof(int),
734 .proc_handler = proc_dointvec,
737 .procname = "io_delay_type",
738 .data = &io_delay_type,
739 .maxlen = sizeof(int),
741 .proc_handler = proc_dointvec,
744 #if defined(CONFIG_MMU)
746 .procname = "randomize_va_space",
747 .data = &randomize_va_space,
748 .maxlen = sizeof(int),
750 .proc_handler = proc_dointvec,
753 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
755 .procname = "spin_retry",
757 .maxlen = sizeof (int),
759 .proc_handler = proc_dointvec,
762 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
764 .procname = "acpi_video_flags",
765 .data = &acpi_realmode_flags,
766 .maxlen = sizeof (unsigned long),
768 .proc_handler = proc_doulongvec_minmax,
773 .procname = "ignore-unaligned-usertrap",
774 .data = &no_unaligned_warning,
775 .maxlen = sizeof (int),
777 .proc_handler = proc_dointvec,
780 .procname = "unaligned-dump-stack",
781 .data = &unaligned_dump_stack,
782 .maxlen = sizeof (int),
784 .proc_handler = proc_dointvec,
787 #ifdef CONFIG_DETECT_SOFTLOCKUP
789 .procname = "softlockup_panic",
790 .data = &softlockup_panic,
791 .maxlen = sizeof(int),
793 .proc_handler = proc_dointvec_minmax,
798 .procname = "softlockup_thresh",
799 .data = &softlockup_thresh,
800 .maxlen = sizeof(int),
802 .proc_handler = proc_dosoftlockup_thresh,
807 #ifdef CONFIG_DETECT_HUNG_TASK
809 .procname = "hung_task_panic",
810 .data = &sysctl_hung_task_panic,
811 .maxlen = sizeof(int),
813 .proc_handler = proc_dointvec_minmax,
818 .procname = "hung_task_check_count",
819 .data = &sysctl_hung_task_check_count,
820 .maxlen = sizeof(unsigned long),
822 .proc_handler = proc_doulongvec_minmax,
825 .procname = "hung_task_timeout_secs",
826 .data = &sysctl_hung_task_timeout_secs,
827 .maxlen = sizeof(unsigned long),
829 .proc_handler = proc_dohung_task_timeout_secs,
832 .procname = "hung_task_warnings",
833 .data = &sysctl_hung_task_warnings,
834 .maxlen = sizeof(unsigned long),
836 .proc_handler = proc_doulongvec_minmax,
841 .procname = "compat-log",
843 .maxlen = sizeof (int),
845 .proc_handler = proc_dointvec,
848 #ifdef CONFIG_RT_MUTEXES
850 .procname = "max_lock_depth",
851 .data = &max_lock_depth,
852 .maxlen = sizeof(int),
854 .proc_handler = proc_dointvec,
858 .procname = "poweroff_cmd",
859 .data = &poweroff_cmd,
860 .maxlen = POWEROFF_CMD_PATH_LEN,
862 .proc_handler = proc_dostring,
868 .child = key_sysctls,
871 #ifdef CONFIG_RCU_TORTURE_TEST
873 .procname = "rcutorture_runnable",
874 .data = &rcutorture_runnable,
875 .maxlen = sizeof(int),
877 .proc_handler = proc_dointvec,
880 #ifdef CONFIG_SLOW_WORK
882 .procname = "slow-work",
884 .child = slow_work_sysctls,
887 #ifdef CONFIG_PERF_EVENTS
889 .procname = "perf_event_paranoid",
890 .data = &sysctl_perf_event_paranoid,
891 .maxlen = sizeof(sysctl_perf_event_paranoid),
893 .proc_handler = proc_dointvec,
896 .procname = "perf_event_mlock_kb",
897 .data = &sysctl_perf_event_mlock,
898 .maxlen = sizeof(sysctl_perf_event_mlock),
900 .proc_handler = proc_dointvec,
903 .procname = "perf_event_max_sample_rate",
904 .data = &sysctl_perf_event_sample_rate,
905 .maxlen = sizeof(sysctl_perf_event_sample_rate),
907 .proc_handler = proc_dointvec,
910 #ifdef CONFIG_KMEMCHECK
912 .procname = "kmemcheck",
913 .data = &kmemcheck_enabled,
914 .maxlen = sizeof(int),
916 .proc_handler = proc_dointvec,
921 .procname = "blk_iopoll",
922 .data = &blk_iopoll_enabled,
923 .maxlen = sizeof(int),
925 .proc_handler = proc_dointvec,
929 * NOTE: do not add new entries to this table unless you have read
930 * Documentation/sysctl/ctl_unnumbered.txt
935 static struct ctl_table vm_table[] = {
937 .procname = "overcommit_memory",
938 .data = &sysctl_overcommit_memory,
939 .maxlen = sizeof(sysctl_overcommit_memory),
941 .proc_handler = proc_dointvec,
944 .procname = "panic_on_oom",
945 .data = &sysctl_panic_on_oom,
946 .maxlen = sizeof(sysctl_panic_on_oom),
948 .proc_handler = proc_dointvec,
951 .procname = "oom_kill_allocating_task",
952 .data = &sysctl_oom_kill_allocating_task,
953 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
955 .proc_handler = proc_dointvec,
958 .procname = "oom_dump_tasks",
959 .data = &sysctl_oom_dump_tasks,
960 .maxlen = sizeof(sysctl_oom_dump_tasks),
962 .proc_handler = proc_dointvec,
965 .procname = "overcommit_ratio",
966 .data = &sysctl_overcommit_ratio,
967 .maxlen = sizeof(sysctl_overcommit_ratio),
969 .proc_handler = proc_dointvec,
972 .procname = "page-cluster",
973 .data = &page_cluster,
974 .maxlen = sizeof(int),
976 .proc_handler = proc_dointvec,
979 .procname = "dirty_background_ratio",
980 .data = &dirty_background_ratio,
981 .maxlen = sizeof(dirty_background_ratio),
983 .proc_handler = dirty_background_ratio_handler,
985 .extra2 = &one_hundred,
988 .procname = "dirty_background_bytes",
989 .data = &dirty_background_bytes,
990 .maxlen = sizeof(dirty_background_bytes),
992 .proc_handler = dirty_background_bytes_handler,
996 .procname = "dirty_ratio",
997 .data = &vm_dirty_ratio,
998 .maxlen = sizeof(vm_dirty_ratio),
1000 .proc_handler = dirty_ratio_handler,
1002 .extra2 = &one_hundred,
1005 .procname = "dirty_bytes",
1006 .data = &vm_dirty_bytes,
1007 .maxlen = sizeof(vm_dirty_bytes),
1009 .proc_handler = dirty_bytes_handler,
1010 .extra1 = &dirty_bytes_min,
1013 .procname = "dirty_writeback_centisecs",
1014 .data = &dirty_writeback_interval,
1015 .maxlen = sizeof(dirty_writeback_interval),
1017 .proc_handler = dirty_writeback_centisecs_handler,
1020 .procname = "dirty_expire_centisecs",
1021 .data = &dirty_expire_interval,
1022 .maxlen = sizeof(dirty_expire_interval),
1024 .proc_handler = proc_dointvec,
1027 .procname = "nr_pdflush_threads",
1028 .data = &nr_pdflush_threads,
1029 .maxlen = sizeof nr_pdflush_threads,
1030 .mode = 0444 /* read-only*/,
1031 .proc_handler = proc_dointvec,
1034 .procname = "swappiness",
1035 .data = &vm_swappiness,
1036 .maxlen = sizeof(vm_swappiness),
1038 .proc_handler = proc_dointvec_minmax,
1040 .extra2 = &one_hundred,
1042 #ifdef CONFIG_HUGETLB_PAGE
1044 .procname = "nr_hugepages",
1046 .maxlen = sizeof(unsigned long),
1048 .proc_handler = hugetlb_sysctl_handler,
1049 .extra1 = (void *)&hugetlb_zero,
1050 .extra2 = (void *)&hugetlb_infinity,
1053 .procname = "hugetlb_shm_group",
1054 .data = &sysctl_hugetlb_shm_group,
1055 .maxlen = sizeof(gid_t),
1057 .proc_handler = proc_dointvec,
1060 .procname = "hugepages_treat_as_movable",
1061 .data = &hugepages_treat_as_movable,
1062 .maxlen = sizeof(int),
1064 .proc_handler = hugetlb_treat_movable_handler,
1067 .procname = "nr_overcommit_hugepages",
1069 .maxlen = sizeof(unsigned long),
1071 .proc_handler = hugetlb_overcommit_handler,
1072 .extra1 = (void *)&hugetlb_zero,
1073 .extra2 = (void *)&hugetlb_infinity,
1077 .procname = "lowmem_reserve_ratio",
1078 .data = &sysctl_lowmem_reserve_ratio,
1079 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1081 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1084 .procname = "drop_caches",
1085 .data = &sysctl_drop_caches,
1086 .maxlen = sizeof(int),
1088 .proc_handler = drop_caches_sysctl_handler,
1091 .procname = "min_free_kbytes",
1092 .data = &min_free_kbytes,
1093 .maxlen = sizeof(min_free_kbytes),
1095 .proc_handler = min_free_kbytes_sysctl_handler,
1099 .procname = "percpu_pagelist_fraction",
1100 .data = &percpu_pagelist_fraction,
1101 .maxlen = sizeof(percpu_pagelist_fraction),
1103 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1104 .extra1 = &min_percpu_pagelist_fract,
1108 .procname = "max_map_count",
1109 .data = &sysctl_max_map_count,
1110 .maxlen = sizeof(sysctl_max_map_count),
1112 .proc_handler = proc_dointvec
1116 .procname = "nr_trim_pages",
1117 .data = &sysctl_nr_trim_pages,
1118 .maxlen = sizeof(sysctl_nr_trim_pages),
1120 .proc_handler = proc_dointvec_minmax,
1125 .procname = "laptop_mode",
1126 .data = &laptop_mode,
1127 .maxlen = sizeof(laptop_mode),
1129 .proc_handler = proc_dointvec_jiffies,
1132 .procname = "block_dump",
1133 .data = &block_dump,
1134 .maxlen = sizeof(block_dump),
1136 .proc_handler = proc_dointvec,
1140 .procname = "vfs_cache_pressure",
1141 .data = &sysctl_vfs_cache_pressure,
1142 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1144 .proc_handler = proc_dointvec,
1147 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1149 .procname = "legacy_va_layout",
1150 .data = &sysctl_legacy_va_layout,
1151 .maxlen = sizeof(sysctl_legacy_va_layout),
1153 .proc_handler = proc_dointvec,
1159 .procname = "zone_reclaim_mode",
1160 .data = &zone_reclaim_mode,
1161 .maxlen = sizeof(zone_reclaim_mode),
1163 .proc_handler = proc_dointvec,
1167 .procname = "min_unmapped_ratio",
1168 .data = &sysctl_min_unmapped_ratio,
1169 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1171 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1173 .extra2 = &one_hundred,
1176 .procname = "min_slab_ratio",
1177 .data = &sysctl_min_slab_ratio,
1178 .maxlen = sizeof(sysctl_min_slab_ratio),
1180 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1182 .extra2 = &one_hundred,
1187 .procname = "stat_interval",
1188 .data = &sysctl_stat_interval,
1189 .maxlen = sizeof(sysctl_stat_interval),
1191 .proc_handler = proc_dointvec_jiffies,
1195 .procname = "mmap_min_addr",
1196 .data = &dac_mmap_min_addr,
1197 .maxlen = sizeof(unsigned long),
1199 .proc_handler = mmap_min_addr_handler,
1203 .procname = "numa_zonelist_order",
1204 .data = &numa_zonelist_order,
1205 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1207 .proc_handler = numa_zonelist_order_handler,
1210 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1211 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1213 .procname = "vdso_enabled",
1214 .data = &vdso_enabled,
1215 .maxlen = sizeof(vdso_enabled),
1217 .proc_handler = proc_dointvec,
1221 #ifdef CONFIG_HIGHMEM
1223 .procname = "highmem_is_dirtyable",
1224 .data = &vm_highmem_is_dirtyable,
1225 .maxlen = sizeof(vm_highmem_is_dirtyable),
1227 .proc_handler = proc_dointvec_minmax,
1233 .procname = "scan_unevictable_pages",
1234 .data = &scan_unevictable_pages,
1235 .maxlen = sizeof(scan_unevictable_pages),
1237 .proc_handler = scan_unevictable_handler,
1239 #ifdef CONFIG_MEMORY_FAILURE
1241 .procname = "memory_failure_early_kill",
1242 .data = &sysctl_memory_failure_early_kill,
1243 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1245 .proc_handler = proc_dointvec_minmax,
1250 .procname = "memory_failure_recovery",
1251 .data = &sysctl_memory_failure_recovery,
1252 .maxlen = sizeof(sysctl_memory_failure_recovery),
1254 .proc_handler = proc_dointvec_minmax,
1261 * NOTE: do not add new entries to this table unless you have read
1262 * Documentation/sysctl/ctl_unnumbered.txt
1267 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1268 static struct ctl_table binfmt_misc_table[] = {
1273 static struct ctl_table fs_table[] = {
1275 .procname = "inode-nr",
1276 .data = &inodes_stat,
1277 .maxlen = 2*sizeof(int),
1279 .proc_handler = proc_dointvec,
1282 .procname = "inode-state",
1283 .data = &inodes_stat,
1284 .maxlen = 7*sizeof(int),
1286 .proc_handler = proc_dointvec,
1289 .procname = "file-nr",
1290 .data = &files_stat,
1291 .maxlen = 3*sizeof(int),
1293 .proc_handler = proc_nr_files,
1296 .procname = "file-max",
1297 .data = &files_stat.max_files,
1298 .maxlen = sizeof(int),
1300 .proc_handler = proc_dointvec,
1303 .procname = "nr_open",
1304 .data = &sysctl_nr_open,
1305 .maxlen = sizeof(int),
1307 .proc_handler = proc_dointvec_minmax,
1308 .extra1 = &sysctl_nr_open_min,
1309 .extra2 = &sysctl_nr_open_max,
1312 .procname = "dentry-state",
1313 .data = &dentry_stat,
1314 .maxlen = 6*sizeof(int),
1316 .proc_handler = proc_dointvec,
1319 .procname = "overflowuid",
1320 .data = &fs_overflowuid,
1321 .maxlen = sizeof(int),
1323 .proc_handler = proc_dointvec_minmax,
1324 .extra1 = &minolduid,
1325 .extra2 = &maxolduid,
1328 .procname = "overflowgid",
1329 .data = &fs_overflowgid,
1330 .maxlen = sizeof(int),
1332 .proc_handler = proc_dointvec_minmax,
1333 .extra1 = &minolduid,
1334 .extra2 = &maxolduid,
1336 #ifdef CONFIG_FILE_LOCKING
1338 .procname = "leases-enable",
1339 .data = &leases_enable,
1340 .maxlen = sizeof(int),
1342 .proc_handler = proc_dointvec,
1345 #ifdef CONFIG_DNOTIFY
1347 .procname = "dir-notify-enable",
1348 .data = &dir_notify_enable,
1349 .maxlen = sizeof(int),
1351 .proc_handler = proc_dointvec,
1355 #ifdef CONFIG_FILE_LOCKING
1357 .procname = "lease-break-time",
1358 .data = &lease_break_time,
1359 .maxlen = sizeof(int),
1361 .proc_handler = proc_dointvec,
1366 .procname = "aio-nr",
1368 .maxlen = sizeof(aio_nr),
1370 .proc_handler = proc_doulongvec_minmax,
1373 .procname = "aio-max-nr",
1374 .data = &aio_max_nr,
1375 .maxlen = sizeof(aio_max_nr),
1377 .proc_handler = proc_doulongvec_minmax,
1379 #endif /* CONFIG_AIO */
1380 #ifdef CONFIG_INOTIFY_USER
1382 .procname = "inotify",
1384 .child = inotify_table,
1389 .procname = "epoll",
1391 .child = epoll_table,
1396 .procname = "suid_dumpable",
1397 .data = &suid_dumpable,
1398 .maxlen = sizeof(int),
1400 .proc_handler = proc_dointvec_minmax,
1404 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1406 .procname = "binfmt_misc",
1408 .child = binfmt_misc_table,
1412 * NOTE: do not add new entries to this table unless you have read
1413 * Documentation/sysctl/ctl_unnumbered.txt
1418 static struct ctl_table debug_table[] = {
1419 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1421 .procname = "exception-trace",
1422 .data = &show_unhandled_signals,
1423 .maxlen = sizeof(int),
1425 .proc_handler = proc_dointvec
1431 static struct ctl_table dev_table[] = {
1435 static DEFINE_SPINLOCK(sysctl_lock);
1437 /* called under sysctl_lock */
1438 static int use_table(struct ctl_table_header *p)
1440 if (unlikely(p->unregistering))
1446 /* called under sysctl_lock */
1447 static void unuse_table(struct ctl_table_header *p)
1450 if (unlikely(p->unregistering))
1451 complete(p->unregistering);
1454 /* called under sysctl_lock, will reacquire if has to wait */
1455 static void start_unregistering(struct ctl_table_header *p)
1458 * if p->used is 0, nobody will ever touch that entry again;
1459 * we'll eliminate all paths to it before dropping sysctl_lock
1461 if (unlikely(p->used)) {
1462 struct completion wait;
1463 init_completion(&wait);
1464 p->unregistering = &wait;
1465 spin_unlock(&sysctl_lock);
1466 wait_for_completion(&wait);
1467 spin_lock(&sysctl_lock);
1469 /* anything non-NULL; we'll never dereference it */
1470 p->unregistering = ERR_PTR(-EINVAL);
1473 * do not remove from the list until nobody holds it; walking the
1474 * list in do_sysctl() relies on that.
1476 list_del_init(&p->ctl_entry);
1479 void sysctl_head_get(struct ctl_table_header *head)
1481 spin_lock(&sysctl_lock);
1483 spin_unlock(&sysctl_lock);
1486 void sysctl_head_put(struct ctl_table_header *head)
1488 spin_lock(&sysctl_lock);
1491 spin_unlock(&sysctl_lock);
1494 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1498 spin_lock(&sysctl_lock);
1499 if (!use_table(head))
1500 head = ERR_PTR(-ENOENT);
1501 spin_unlock(&sysctl_lock);
1505 void sysctl_head_finish(struct ctl_table_header *head)
1509 spin_lock(&sysctl_lock);
1511 spin_unlock(&sysctl_lock);
1514 static struct ctl_table_set *
1515 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1517 struct ctl_table_set *set = &root->default_set;
1519 set = root->lookup(root, namespaces);
1523 static struct list_head *
1524 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1526 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1530 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1531 struct ctl_table_header *prev)
1533 struct ctl_table_root *root;
1534 struct list_head *header_list;
1535 struct ctl_table_header *head;
1536 struct list_head *tmp;
1538 spin_lock(&sysctl_lock);
1541 tmp = &prev->ctl_entry;
1545 tmp = &root_table_header.ctl_entry;
1547 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1549 if (!use_table(head))
1551 spin_unlock(&sysctl_lock);
1556 header_list = lookup_header_list(root, namespaces);
1557 if (tmp != header_list)
1561 root = list_entry(root->root_list.next,
1562 struct ctl_table_root, root_list);
1563 if (root == &sysctl_table_root)
1565 header_list = lookup_header_list(root, namespaces);
1566 } while (list_empty(header_list));
1567 tmp = header_list->next;
1570 spin_unlock(&sysctl_lock);
1574 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1576 return __sysctl_head_next(current->nsproxy, prev);
1579 void register_sysctl_root(struct ctl_table_root *root)
1581 spin_lock(&sysctl_lock);
1582 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1583 spin_unlock(&sysctl_lock);
1587 * sysctl_perm does NOT grant the superuser all rights automatically, because
1588 * some sysctl variables are readonly even to root.
1591 static int test_perm(int mode, int op)
1593 if (!current_euid())
1595 else if (in_egroup_p(0))
1597 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1602 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1607 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1611 if (root->permissions)
1612 mode = root->permissions(root, current->nsproxy, table);
1616 return test_perm(mode, op);
1619 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1621 for (; table->procname; table++) {
1622 table->parent = parent;
1624 sysctl_set_parent(table, table->child);
1628 static __init int sysctl_init(void)
1630 sysctl_set_parent(NULL, root_table);
1631 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1634 err = sysctl_check_table(current->nsproxy, root_table);
1640 core_initcall(sysctl_init);
1642 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1643 struct ctl_table *table)
1645 struct ctl_table *p;
1646 const char *s = branch->procname;
1648 /* branch should have named subdirectory as its first element */
1649 if (!s || !branch->child)
1652 /* ... and nothing else */
1653 if (branch[1].procname)
1656 /* table should contain subdirectory with the same name */
1657 for (p = table; p->procname; p++) {
1660 if (p->procname && strcmp(p->procname, s) == 0)
1666 /* see if attaching q to p would be an improvement */
1667 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1669 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1670 struct ctl_table *next;
1672 int not_in_parent = !p->attached_by;
1674 while ((next = is_branch_in(by, to)) != NULL) {
1675 if (by == q->attached_by)
1677 if (to == p->attached_by)
1683 if (is_better && not_in_parent) {
1684 q->attached_by = by;
1685 q->attached_to = to;
1691 * __register_sysctl_paths - register a sysctl hierarchy
1692 * @root: List of sysctl headers to register on
1693 * @namespaces: Data to compute which lists of sysctl entries are visible
1694 * @path: The path to the directory the sysctl table is in.
1695 * @table: the top-level table structure
1697 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1698 * array. A completely 0 filled entry terminates the table.
1700 * The members of the &struct ctl_table structure are used as follows:
1702 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1703 * enter a sysctl file
1705 * data - a pointer to data for use by proc_handler
1707 * maxlen - the maximum size in bytes of the data
1709 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1711 * child - a pointer to the child sysctl table if this entry is a directory, or
1714 * proc_handler - the text handler routine (described below)
1716 * de - for internal use by the sysctl routines
1718 * extra1, extra2 - extra pointers usable by the proc handler routines
1720 * Leaf nodes in the sysctl tree will be represented by a single file
1721 * under /proc; non-leaf nodes will be represented by directories.
1723 * sysctl(2) can automatically manage read and write requests through
1724 * the sysctl table. The data and maxlen fields of the ctl_table
1725 * struct enable minimal validation of the values being written to be
1726 * performed, and the mode field allows minimal authentication.
1728 * There must be a proc_handler routine for any terminal nodes
1729 * mirrored under /proc/sys (non-terminals are handled by a built-in
1730 * directory handler). Several default handlers are available to
1731 * cover common cases -
1733 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1734 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1735 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1737 * It is the handler's job to read the input buffer from user memory
1738 * and process it. The handler should return 0 on success.
1740 * This routine returns %NULL on a failure to register, and a pointer
1741 * to the table header on success.
1743 struct ctl_table_header *__register_sysctl_paths(
1744 struct ctl_table_root *root,
1745 struct nsproxy *namespaces,
1746 const struct ctl_path *path, struct ctl_table *table)
1748 struct ctl_table_header *header;
1749 struct ctl_table *new, **prevp;
1750 unsigned int n, npath;
1751 struct ctl_table_set *set;
1753 /* Count the path components */
1754 for (npath = 0; path[npath].procname; ++npath)
1758 * For each path component, allocate a 2-element ctl_table array.
1759 * The first array element will be filled with the sysctl entry
1760 * for this, the second will be the sentinel (procname == 0).
1762 * We allocate everything in one go so that we don't have to
1763 * worry about freeing additional memory in unregister_sysctl_table.
1765 header = kzalloc(sizeof(struct ctl_table_header) +
1766 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1770 new = (struct ctl_table *) (header + 1);
1772 /* Now connect the dots */
1773 prevp = &header->ctl_table;
1774 for (n = 0; n < npath; ++n, ++path) {
1775 /* Copy the procname */
1776 new->procname = path->procname;
1780 prevp = &new->child;
1785 header->ctl_table_arg = table;
1787 INIT_LIST_HEAD(&header->ctl_entry);
1789 header->unregistering = NULL;
1790 header->root = root;
1791 sysctl_set_parent(NULL, header->ctl_table);
1793 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1794 if (sysctl_check_table(namespaces, header->ctl_table)) {
1799 spin_lock(&sysctl_lock);
1800 header->set = lookup_header_set(root, namespaces);
1801 header->attached_by = header->ctl_table;
1802 header->attached_to = root_table;
1803 header->parent = &root_table_header;
1804 for (set = header->set; set; set = set->parent) {
1805 struct ctl_table_header *p;
1806 list_for_each_entry(p, &set->list, ctl_entry) {
1807 if (p->unregistering)
1809 try_attach(p, header);
1812 header->parent->count++;
1813 list_add_tail(&header->ctl_entry, &header->set->list);
1814 spin_unlock(&sysctl_lock);
1820 * register_sysctl_table_path - register a sysctl table hierarchy
1821 * @path: The path to the directory the sysctl table is in.
1822 * @table: the top-level table structure
1824 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1825 * array. A completely 0 filled entry terminates the table.
1827 * See __register_sysctl_paths for more details.
1829 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1830 struct ctl_table *table)
1832 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1837 * register_sysctl_table - register a sysctl table hierarchy
1838 * @table: the top-level table structure
1840 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1841 * array. A completely 0 filled entry terminates the table.
1843 * See register_sysctl_paths for more details.
1845 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1847 static const struct ctl_path null_path[] = { {} };
1849 return register_sysctl_paths(null_path, table);
1853 * unregister_sysctl_table - unregister a sysctl table hierarchy
1854 * @header: the header returned from register_sysctl_table
1856 * Unregisters the sysctl table and all children. proc entries may not
1857 * actually be removed until they are no longer used by anyone.
1859 void unregister_sysctl_table(struct ctl_table_header * header)
1866 spin_lock(&sysctl_lock);
1867 start_unregistering(header);
1868 if (!--header->parent->count) {
1870 kfree(header->parent);
1872 if (!--header->count)
1874 spin_unlock(&sysctl_lock);
1877 int sysctl_is_seen(struct ctl_table_header *p)
1879 struct ctl_table_set *set = p->set;
1881 spin_lock(&sysctl_lock);
1882 if (p->unregistering)
1884 else if (!set->is_seen)
1887 res = set->is_seen(set);
1888 spin_unlock(&sysctl_lock);
1892 void setup_sysctl_set(struct ctl_table_set *p,
1893 struct ctl_table_set *parent,
1894 int (*is_seen)(struct ctl_table_set *))
1896 INIT_LIST_HEAD(&p->list);
1897 p->parent = parent ? parent : &sysctl_table_root.default_set;
1898 p->is_seen = is_seen;
1901 #else /* !CONFIG_SYSCTL */
1902 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1907 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1908 struct ctl_table *table)
1913 void unregister_sysctl_table(struct ctl_table_header * table)
1917 void setup_sysctl_set(struct ctl_table_set *p,
1918 struct ctl_table_set *parent,
1919 int (*is_seen)(struct ctl_table_set *))
1923 void sysctl_head_put(struct ctl_table_header *head)
1927 #endif /* CONFIG_SYSCTL */
1933 #ifdef CONFIG_PROC_SYSCTL
1935 static int _proc_do_string(void* data, int maxlen, int write,
1936 void __user *buffer,
1937 size_t *lenp, loff_t *ppos)
1943 if (!data || !maxlen || !*lenp) {
1951 while (len < *lenp) {
1952 if (get_user(c, p++))
1954 if (c == 0 || c == '\n')
1960 if(copy_from_user(data, buffer, len))
1962 ((char *) data)[len] = 0;
1980 if(copy_to_user(buffer, data, len))
1983 if(put_user('\n', ((char __user *) buffer) + len))
1994 * proc_dostring - read a string sysctl
1995 * @table: the sysctl table
1996 * @write: %TRUE if this is a write to the sysctl file
1997 * @buffer: the user buffer
1998 * @lenp: the size of the user buffer
1999 * @ppos: file position
2001 * Reads/writes a string from/to the user buffer. If the kernel
2002 * buffer provided is not large enough to hold the string, the
2003 * string is truncated. The copied string is %NULL-terminated.
2004 * If the string is being read by the user process, it is copied
2005 * and a newline '\n' is added. It is truncated if the buffer is
2008 * Returns 0 on success.
2010 int proc_dostring(struct ctl_table *table, int write,
2011 void __user *buffer, size_t *lenp, loff_t *ppos)
2013 return _proc_do_string(table->data, table->maxlen, write,
2014 buffer, lenp, ppos);
2018 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2020 int write, void *data)
2023 *valp = *negp ? -*lvalp : *lvalp;
2028 *lvalp = (unsigned long)-val;
2031 *lvalp = (unsigned long)val;
2037 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2038 int write, void __user *buffer,
2039 size_t *lenp, loff_t *ppos,
2040 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2041 int write, void *data),
2044 #define TMPBUFLEN 21
2045 int *i, vleft, first = 1, neg;
2049 char buf[TMPBUFLEN], *p;
2050 char __user *s = buffer;
2052 if (!tbl_data || !table->maxlen || !*lenp ||
2053 (*ppos && !write)) {
2058 i = (int *) tbl_data;
2059 vleft = table->maxlen / sizeof(*i);
2063 conv = do_proc_dointvec_conv;
2065 for (; left && vleft--; i++, first=0) {
2080 if (len > sizeof(buf) - 1)
2081 len = sizeof(buf) - 1;
2082 if (copy_from_user(buf, s, len))
2086 if (*p == '-' && left > 1) {
2090 if (*p < '0' || *p > '9')
2093 lval = simple_strtoul(p, &p, 0);
2096 if ((len < left) && *p && !isspace(*p))
2101 if (conv(&neg, &lval, i, 1, data))
2108 if (conv(&neg, &lval, i, 0, data))
2111 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2115 if(copy_to_user(s, buf, len))
2122 if (!write && !first && left) {
2123 if(put_user('\n', s))
2130 if (get_user(c, s++))
2145 static int do_proc_dointvec(struct ctl_table *table, int write,
2146 void __user *buffer, size_t *lenp, loff_t *ppos,
2147 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2148 int write, void *data),
2151 return __do_proc_dointvec(table->data, table, write,
2152 buffer, lenp, ppos, conv, data);
2156 * proc_dointvec - read a vector of integers
2157 * @table: the sysctl table
2158 * @write: %TRUE if this is a write to the sysctl file
2159 * @buffer: the user buffer
2160 * @lenp: the size of the user buffer
2161 * @ppos: file position
2163 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2164 * values from/to the user buffer, treated as an ASCII string.
2166 * Returns 0 on success.
2168 int proc_dointvec(struct ctl_table *table, int write,
2169 void __user *buffer, size_t *lenp, loff_t *ppos)
2171 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2176 * Taint values can only be increased
2177 * This means we can safely use a temporary.
2179 static int proc_taint(struct ctl_table *table, int write,
2180 void __user *buffer, size_t *lenp, loff_t *ppos)
2183 unsigned long tmptaint = get_taint();
2186 if (write && !capable(CAP_SYS_ADMIN))
2191 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2197 * Poor man's atomic or. Not worth adding a primitive
2198 * to everyone's atomic.h for this
2201 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2202 if ((tmptaint >> i) & 1)
2210 struct do_proc_dointvec_minmax_conv_param {
2215 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2217 int write, void *data)
2219 struct do_proc_dointvec_minmax_conv_param *param = data;
2221 int val = *negp ? -*lvalp : *lvalp;
2222 if ((param->min && *param->min > val) ||
2223 (param->max && *param->max < val))
2230 *lvalp = (unsigned long)-val;
2233 *lvalp = (unsigned long)val;
2240 * proc_dointvec_minmax - read a vector of integers with min/max values
2241 * @table: the sysctl table
2242 * @write: %TRUE if this is a write to the sysctl file
2243 * @buffer: the user buffer
2244 * @lenp: the size of the user buffer
2245 * @ppos: file position
2247 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2248 * values from/to the user buffer, treated as an ASCII string.
2250 * This routine will ensure the values are within the range specified by
2251 * table->extra1 (min) and table->extra2 (max).
2253 * Returns 0 on success.
2255 int proc_dointvec_minmax(struct ctl_table *table, int write,
2256 void __user *buffer, size_t *lenp, loff_t *ppos)
2258 struct do_proc_dointvec_minmax_conv_param param = {
2259 .min = (int *) table->extra1,
2260 .max = (int *) table->extra2,
2262 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2263 do_proc_dointvec_minmax_conv, ¶m);
2266 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2267 void __user *buffer,
2268 size_t *lenp, loff_t *ppos,
2269 unsigned long convmul,
2270 unsigned long convdiv)
2272 #define TMPBUFLEN 21
2273 unsigned long *i, *min, *max, val;
2274 int vleft, first=1, neg;
2276 char buf[TMPBUFLEN], *p;
2277 char __user *s = buffer;
2279 if (!data || !table->maxlen || !*lenp ||
2280 (*ppos && !write)) {
2285 i = (unsigned long *) data;
2286 min = (unsigned long *) table->extra1;
2287 max = (unsigned long *) table->extra2;
2288 vleft = table->maxlen / sizeof(unsigned long);
2291 for (; left && vleft--; i++, min++, max++, first=0) {
2306 if (len > TMPBUFLEN-1)
2308 if (copy_from_user(buf, s, len))
2312 if (*p == '-' && left > 1) {
2316 if (*p < '0' || *p > '9')
2318 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2320 if ((len < left) && *p && !isspace(*p))
2329 if ((min && val < *min) || (max && val > *max))
2336 sprintf(p, "%lu", convdiv * (*i) / convmul);
2340 if(copy_to_user(s, buf, len))
2347 if (!write && !first && left) {
2348 if(put_user('\n', s))
2355 if (get_user(c, s++))
2370 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2371 void __user *buffer,
2372 size_t *lenp, loff_t *ppos,
2373 unsigned long convmul,
2374 unsigned long convdiv)
2376 return __do_proc_doulongvec_minmax(table->data, table, write,
2377 buffer, lenp, ppos, convmul, convdiv);
2381 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2382 * @table: the sysctl table
2383 * @write: %TRUE if this is a write to the sysctl file
2384 * @buffer: the user buffer
2385 * @lenp: the size of the user buffer
2386 * @ppos: file position
2388 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2389 * values from/to the user buffer, treated as an ASCII string.
2391 * This routine will ensure the values are within the range specified by
2392 * table->extra1 (min) and table->extra2 (max).
2394 * Returns 0 on success.
2396 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2397 void __user *buffer, size_t *lenp, loff_t *ppos)
2399 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2403 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2404 * @table: the sysctl table
2405 * @write: %TRUE if this is a write to the sysctl file
2406 * @buffer: the user buffer
2407 * @lenp: the size of the user buffer
2408 * @ppos: file position
2410 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2411 * values from/to the user buffer, treated as an ASCII string. The values
2412 * are treated as milliseconds, and converted to jiffies when they are stored.
2414 * This routine will ensure the values are within the range specified by
2415 * table->extra1 (min) and table->extra2 (max).
2417 * Returns 0 on success.
2419 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2420 void __user *buffer,
2421 size_t *lenp, loff_t *ppos)
2423 return do_proc_doulongvec_minmax(table, write, buffer,
2424 lenp, ppos, HZ, 1000l);
2428 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2430 int write, void *data)
2433 if (*lvalp > LONG_MAX / HZ)
2435 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2441 lval = (unsigned long)-val;
2444 lval = (unsigned long)val;
2451 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2453 int write, void *data)
2456 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2458 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2464 lval = (unsigned long)-val;
2467 lval = (unsigned long)val;
2469 *lvalp = jiffies_to_clock_t(lval);
2474 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2476 int write, void *data)
2479 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2485 lval = (unsigned long)-val;
2488 lval = (unsigned long)val;
2490 *lvalp = jiffies_to_msecs(lval);
2496 * proc_dointvec_jiffies - read a vector of integers as seconds
2497 * @table: the sysctl table
2498 * @write: %TRUE if this is a write to the sysctl file
2499 * @buffer: the user buffer
2500 * @lenp: the size of the user buffer
2501 * @ppos: file position
2503 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2504 * values from/to the user buffer, treated as an ASCII string.
2505 * The values read are assumed to be in seconds, and are converted into
2508 * Returns 0 on success.
2510 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2511 void __user *buffer, size_t *lenp, loff_t *ppos)
2513 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2514 do_proc_dointvec_jiffies_conv,NULL);
2518 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2519 * @table: the sysctl table
2520 * @write: %TRUE if this is a write to the sysctl file
2521 * @buffer: the user buffer
2522 * @lenp: the size of the user buffer
2523 * @ppos: pointer to the file position
2525 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2526 * values from/to the user buffer, treated as an ASCII string.
2527 * The values read are assumed to be in 1/USER_HZ seconds, and
2528 * are converted into jiffies.
2530 * Returns 0 on success.
2532 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2533 void __user *buffer, size_t *lenp, loff_t *ppos)
2535 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2536 do_proc_dointvec_userhz_jiffies_conv,NULL);
2540 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2541 * @table: the sysctl table
2542 * @write: %TRUE if this is a write to the sysctl file
2543 * @buffer: the user buffer
2544 * @lenp: the size of the user buffer
2545 * @ppos: file position
2546 * @ppos: the current position in the file
2548 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2549 * values from/to the user buffer, treated as an ASCII string.
2550 * The values read are assumed to be in 1/1000 seconds, and
2551 * are converted into jiffies.
2553 * Returns 0 on success.
2555 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2556 void __user *buffer, size_t *lenp, loff_t *ppos)
2558 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2559 do_proc_dointvec_ms_jiffies_conv, NULL);
2562 static int proc_do_cad_pid(struct ctl_table *table, int write,
2563 void __user *buffer, size_t *lenp, loff_t *ppos)
2565 struct pid *new_pid;
2569 tmp = pid_vnr(cad_pid);
2571 r = __do_proc_dointvec(&tmp, table, write, buffer,
2572 lenp, ppos, NULL, NULL);
2576 new_pid = find_get_pid(tmp);
2580 put_pid(xchg(&cad_pid, new_pid));
2584 #else /* CONFIG_PROC_FS */
2586 int proc_dostring(struct ctl_table *table, int write,
2587 void __user *buffer, size_t *lenp, loff_t *ppos)
2592 int proc_dointvec(struct ctl_table *table, int write,
2593 void __user *buffer, size_t *lenp, loff_t *ppos)
2598 int proc_dointvec_minmax(struct ctl_table *table, int write,
2599 void __user *buffer, size_t *lenp, loff_t *ppos)
2604 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2605 void __user *buffer, size_t *lenp, loff_t *ppos)
2610 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2611 void __user *buffer, size_t *lenp, loff_t *ppos)
2616 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2617 void __user *buffer, size_t *lenp, loff_t *ppos)
2622 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2623 void __user *buffer, size_t *lenp, loff_t *ppos)
2628 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2629 void __user *buffer,
2630 size_t *lenp, loff_t *ppos)
2636 #endif /* CONFIG_PROC_FS */
2639 * No sense putting this after each symbol definition, twice,
2640 * exception granted :-)
2642 EXPORT_SYMBOL(proc_dointvec);
2643 EXPORT_SYMBOL(proc_dointvec_jiffies);
2644 EXPORT_SYMBOL(proc_dointvec_minmax);
2645 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2646 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2647 EXPORT_SYMBOL(proc_dostring);
2648 EXPORT_SYMBOL(proc_doulongvec_minmax);
2649 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2650 EXPORT_SYMBOL(register_sysctl_table);
2651 EXPORT_SYMBOL(register_sysctl_paths);
2652 EXPORT_SYMBOL(unregister_sysctl_table);