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/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
71 #include <asm/stacktrace.h>
75 #include <asm/setup.h>
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
86 #ifdef CONFIG_CHR_DEV_SG
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory;
99 extern int sysctl_overcommit_ratio;
100 extern int max_threads;
101 extern int suid_dumpable;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid;
104 extern char core_pattern[];
105 extern unsigned int core_pipe_limit;
108 extern int pid_max_min, pid_max_max;
109 extern int percpu_pagelist_fraction;
110 extern int compat_log;
111 extern int latencytop_enabled;
112 extern int sysctl_nr_open_min, sysctl_nr_open_max;
114 extern int sysctl_nr_trim_pages;
117 extern int blk_iopoll_enabled;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty = 60;
126 static int __maybe_unused one = 1;
127 static int __maybe_unused two = 2;
128 static int __maybe_unused three = 3;
129 static unsigned long one_ul = 1;
130 static int one_hundred = 100;
132 static int ten_thousand = 10000;
135 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
136 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
138 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
139 static int maxolduid = 65535;
140 static int minolduid;
141 static int min_percpu_pagelist_fract = 8;
143 static int ngroups_max = NGROUPS_MAX;
144 static const int cap_last_cap = CAP_LAST_CAP;
146 #ifdef CONFIG_INOTIFY_USER
147 #include <linux/inotify.h>
152 #ifdef CONFIG_SPARC64
153 extern int sysctl_tsb_ratio;
157 extern int pwrsw_enabled;
160 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
161 extern int unaligned_enabled;
165 extern int unaligned_dump_stack;
168 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
169 extern int no_unaligned_warning;
172 #ifdef CONFIG_PROC_SYSCTL
173 static int proc_do_cad_pid(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp, loff_t *ppos);
175 static int proc_taint(struct ctl_table *table, int write,
176 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
184 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
185 void __user *buffer, size_t *lenp, loff_t *ppos);
186 #ifdef CONFIG_COREDUMP
187 static int proc_dostring_coredump(struct ctl_table *table, int write,
188 void __user *buffer, size_t *lenp, loff_t *ppos);
191 #ifdef CONFIG_MAGIC_SYSRQ
192 /* Note: sysrq code uses it's own private copy */
193 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
195 static int sysrq_sysctl_handler(ctl_table *table, int write,
196 void __user *buffer, size_t *lenp,
201 error = proc_dointvec(table, write, buffer, lenp, ppos);
206 sysrq_toggle_support(__sysrq_enabled);
213 static struct ctl_table kern_table[];
214 static struct ctl_table vm_table[];
215 static struct ctl_table fs_table[];
216 static struct ctl_table debug_table[];
217 static struct ctl_table dev_table[];
218 extern struct ctl_table random_table[];
220 extern struct ctl_table epoll_table[];
223 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
224 int sysctl_legacy_va_layout;
227 /* The default sysctl tables: */
229 static struct ctl_table sysctl_base_table[] = {
231 .procname = "kernel",
248 .child = debug_table,
258 #ifdef CONFIG_SCHED_DEBUG
259 static int min_sched_granularity_ns = 100000; /* 100 usecs */
260 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
261 static int min_wakeup_granularity_ns; /* 0 usecs */
262 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
264 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
265 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
266 #endif /* CONFIG_SMP */
267 #endif /* CONFIG_SCHED_DEBUG */
269 #ifdef CONFIG_COMPACTION
270 static int min_extfrag_threshold;
271 static int max_extfrag_threshold = 1000;
274 static struct ctl_table kern_table[] = {
276 .procname = "sched_child_runs_first",
277 .data = &sysctl_sched_child_runs_first,
278 .maxlen = sizeof(unsigned int),
280 .proc_handler = proc_dointvec,
282 #ifdef CONFIG_SCHED_DEBUG
284 .procname = "sched_min_granularity_ns",
285 .data = &sysctl_sched_min_granularity,
286 .maxlen = sizeof(unsigned int),
288 .proc_handler = sched_proc_update_handler,
289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
293 .procname = "sched_latency_ns",
294 .data = &sysctl_sched_latency,
295 .maxlen = sizeof(unsigned int),
297 .proc_handler = sched_proc_update_handler,
298 .extra1 = &min_sched_granularity_ns,
299 .extra2 = &max_sched_granularity_ns,
302 .procname = "sched_wakeup_granularity_ns",
303 .data = &sysctl_sched_wakeup_granularity,
304 .maxlen = sizeof(unsigned int),
306 .proc_handler = sched_proc_update_handler,
307 .extra1 = &min_wakeup_granularity_ns,
308 .extra2 = &max_wakeup_granularity_ns,
312 .procname = "sched_tunable_scaling",
313 .data = &sysctl_sched_tunable_scaling,
314 .maxlen = sizeof(enum sched_tunable_scaling),
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
321 .procname = "sched_migration_cost_ns",
322 .data = &sysctl_sched_migration_cost,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = proc_dointvec,
328 .procname = "sched_nr_migrate",
329 .data = &sysctl_sched_nr_migrate,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = proc_dointvec,
335 .procname = "sched_time_avg_ms",
336 .data = &sysctl_sched_time_avg,
337 .maxlen = sizeof(unsigned int),
339 .proc_handler = proc_dointvec,
342 .procname = "sched_shares_window_ns",
343 .data = &sysctl_sched_shares_window,
344 .maxlen = sizeof(unsigned int),
346 .proc_handler = proc_dointvec,
349 .procname = "timer_migration",
350 .data = &sysctl_timer_migration,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = proc_dointvec_minmax,
357 #endif /* CONFIG_SMP */
358 #ifdef CONFIG_NUMA_BALANCING
360 .procname = "numa_balancing_scan_delay_ms",
361 .data = &sysctl_numa_balancing_scan_delay,
362 .maxlen = sizeof(unsigned int),
364 .proc_handler = proc_dointvec,
367 .procname = "numa_balancing_scan_period_min_ms",
368 .data = &sysctl_numa_balancing_scan_period_min,
369 .maxlen = sizeof(unsigned int),
371 .proc_handler = proc_dointvec,
374 .procname = "numa_balancing_scan_period_max_ms",
375 .data = &sysctl_numa_balancing_scan_period_max,
376 .maxlen = sizeof(unsigned int),
378 .proc_handler = proc_dointvec,
381 .procname = "numa_balancing_scan_size_mb",
382 .data = &sysctl_numa_balancing_scan_size,
383 .maxlen = sizeof(unsigned int),
385 .proc_handler = proc_dointvec,
388 .procname = "numa_balancing_settle_count",
389 .data = &sysctl_numa_balancing_settle_count,
390 .maxlen = sizeof(unsigned int),
392 .proc_handler = proc_dointvec,
395 .procname = "numa_balancing_migrate_deferred",
396 .data = &sysctl_numa_balancing_migrate_deferred,
397 .maxlen = sizeof(unsigned int),
399 .proc_handler = proc_dointvec,
401 #endif /* CONFIG_NUMA_BALANCING */
402 #endif /* CONFIG_SCHED_DEBUG */
404 .procname = "sched_rt_period_us",
405 .data = &sysctl_sched_rt_period,
406 .maxlen = sizeof(unsigned int),
408 .proc_handler = sched_rt_handler,
411 .procname = "sched_rt_runtime_us",
412 .data = &sysctl_sched_rt_runtime,
413 .maxlen = sizeof(int),
415 .proc_handler = sched_rt_handler,
418 .procname = "sched_rr_timeslice_ms",
419 .data = &sched_rr_timeslice,
420 .maxlen = sizeof(int),
422 .proc_handler = sched_rr_handler,
424 #ifdef CONFIG_SCHED_AUTOGROUP
426 .procname = "sched_autogroup_enabled",
427 .data = &sysctl_sched_autogroup_enabled,
428 .maxlen = sizeof(unsigned int),
430 .proc_handler = proc_dointvec_minmax,
435 #ifdef CONFIG_CFS_BANDWIDTH
437 .procname = "sched_cfs_bandwidth_slice_us",
438 .data = &sysctl_sched_cfs_bandwidth_slice,
439 .maxlen = sizeof(unsigned int),
441 .proc_handler = proc_dointvec_minmax,
445 #ifdef CONFIG_PROVE_LOCKING
447 .procname = "prove_locking",
448 .data = &prove_locking,
449 .maxlen = sizeof(int),
451 .proc_handler = proc_dointvec,
454 #ifdef CONFIG_LOCK_STAT
456 .procname = "lock_stat",
458 .maxlen = sizeof(int),
460 .proc_handler = proc_dointvec,
465 .data = &panic_timeout,
466 .maxlen = sizeof(int),
468 .proc_handler = proc_dointvec,
470 #ifdef CONFIG_COREDUMP
472 .procname = "core_uses_pid",
473 .data = &core_uses_pid,
474 .maxlen = sizeof(int),
476 .proc_handler = proc_dointvec,
479 .procname = "core_pattern",
480 .data = core_pattern,
481 .maxlen = CORENAME_MAX_SIZE,
483 .proc_handler = proc_dostring_coredump,
486 .procname = "core_pipe_limit",
487 .data = &core_pipe_limit,
488 .maxlen = sizeof(unsigned int),
490 .proc_handler = proc_dointvec,
493 #ifdef CONFIG_PROC_SYSCTL
495 .procname = "tainted",
496 .maxlen = sizeof(long),
498 .proc_handler = proc_taint,
501 #ifdef CONFIG_LATENCYTOP
503 .procname = "latencytop",
504 .data = &latencytop_enabled,
505 .maxlen = sizeof(int),
507 .proc_handler = proc_dointvec,
510 #ifdef CONFIG_BLK_DEV_INITRD
512 .procname = "real-root-dev",
513 .data = &real_root_dev,
514 .maxlen = sizeof(int),
516 .proc_handler = proc_dointvec,
520 .procname = "print-fatal-signals",
521 .data = &print_fatal_signals,
522 .maxlen = sizeof(int),
524 .proc_handler = proc_dointvec,
528 .procname = "reboot-cmd",
529 .data = reboot_command,
532 .proc_handler = proc_dostring,
535 .procname = "stop-a",
536 .data = &stop_a_enabled,
537 .maxlen = sizeof (int),
539 .proc_handler = proc_dointvec,
542 .procname = "scons-poweroff",
543 .data = &scons_pwroff,
544 .maxlen = sizeof (int),
546 .proc_handler = proc_dointvec,
549 #ifdef CONFIG_SPARC64
551 .procname = "tsb-ratio",
552 .data = &sysctl_tsb_ratio,
553 .maxlen = sizeof (int),
555 .proc_handler = proc_dointvec,
560 .procname = "soft-power",
561 .data = &pwrsw_enabled,
562 .maxlen = sizeof (int),
564 .proc_handler = proc_dointvec,
567 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
569 .procname = "unaligned-trap",
570 .data = &unaligned_enabled,
571 .maxlen = sizeof (int),
573 .proc_handler = proc_dointvec,
577 .procname = "ctrl-alt-del",
579 .maxlen = sizeof(int),
581 .proc_handler = proc_dointvec,
583 #ifdef CONFIG_FUNCTION_TRACER
585 .procname = "ftrace_enabled",
586 .data = &ftrace_enabled,
587 .maxlen = sizeof(int),
589 .proc_handler = ftrace_enable_sysctl,
592 #ifdef CONFIG_STACK_TRACER
594 .procname = "stack_tracer_enabled",
595 .data = &stack_tracer_enabled,
596 .maxlen = sizeof(int),
598 .proc_handler = stack_trace_sysctl,
601 #ifdef CONFIG_TRACING
603 .procname = "ftrace_dump_on_oops",
604 .data = &ftrace_dump_on_oops,
605 .maxlen = sizeof(int),
607 .proc_handler = proc_dointvec,
610 .procname = "traceoff_on_warning",
611 .data = &__disable_trace_on_warning,
612 .maxlen = sizeof(__disable_trace_on_warning),
614 .proc_handler = proc_dointvec,
617 #ifdef CONFIG_MODULES
619 .procname = "modprobe",
620 .data = &modprobe_path,
621 .maxlen = KMOD_PATH_LEN,
623 .proc_handler = proc_dostring,
626 .procname = "modules_disabled",
627 .data = &modules_disabled,
628 .maxlen = sizeof(int),
630 /* only handle a transition from default "0" to "1" */
631 .proc_handler = proc_dointvec_minmax,
638 .procname = "hotplug",
639 .data = &uevent_helper,
640 .maxlen = UEVENT_HELPER_PATH_LEN,
642 .proc_handler = proc_dostring,
645 #ifdef CONFIG_CHR_DEV_SG
647 .procname = "sg-big-buff",
648 .data = &sg_big_buff,
649 .maxlen = sizeof (int),
651 .proc_handler = proc_dointvec,
654 #ifdef CONFIG_BSD_PROCESS_ACCT
658 .maxlen = 3*sizeof(int),
660 .proc_handler = proc_dointvec,
663 #ifdef CONFIG_MAGIC_SYSRQ
666 .data = &__sysrq_enabled,
667 .maxlen = sizeof (int),
669 .proc_handler = sysrq_sysctl_handler,
672 #ifdef CONFIG_PROC_SYSCTL
674 .procname = "cad_pid",
676 .maxlen = sizeof (int),
678 .proc_handler = proc_do_cad_pid,
682 .procname = "threads-max",
683 .data = &max_threads,
684 .maxlen = sizeof(int),
686 .proc_handler = proc_dointvec,
689 .procname = "random",
691 .child = random_table,
694 .procname = "usermodehelper",
696 .child = usermodehelper_table,
699 .procname = "overflowuid",
700 .data = &overflowuid,
701 .maxlen = sizeof(int),
703 .proc_handler = proc_dointvec_minmax,
704 .extra1 = &minolduid,
705 .extra2 = &maxolduid,
708 .procname = "overflowgid",
709 .data = &overflowgid,
710 .maxlen = sizeof(int),
712 .proc_handler = proc_dointvec_minmax,
713 .extra1 = &minolduid,
714 .extra2 = &maxolduid,
717 #ifdef CONFIG_MATHEMU
719 .procname = "ieee_emulation_warnings",
720 .data = &sysctl_ieee_emulation_warnings,
721 .maxlen = sizeof(int),
723 .proc_handler = proc_dointvec,
727 .procname = "userprocess_debug",
728 .data = &show_unhandled_signals,
729 .maxlen = sizeof(int),
731 .proc_handler = proc_dointvec,
735 .procname = "pid_max",
737 .maxlen = sizeof (int),
739 .proc_handler = proc_dointvec_minmax,
740 .extra1 = &pid_max_min,
741 .extra2 = &pid_max_max,
744 .procname = "panic_on_oops",
745 .data = &panic_on_oops,
746 .maxlen = sizeof(int),
748 .proc_handler = proc_dointvec,
750 #if defined CONFIG_PRINTK
752 .procname = "printk",
753 .data = &console_loglevel,
754 .maxlen = 4*sizeof(int),
756 .proc_handler = proc_dointvec,
759 .procname = "printk_ratelimit",
760 .data = &printk_ratelimit_state.interval,
761 .maxlen = sizeof(int),
763 .proc_handler = proc_dointvec_jiffies,
766 .procname = "printk_ratelimit_burst",
767 .data = &printk_ratelimit_state.burst,
768 .maxlen = sizeof(int),
770 .proc_handler = proc_dointvec,
773 .procname = "printk_delay",
774 .data = &printk_delay_msec,
775 .maxlen = sizeof(int),
777 .proc_handler = proc_dointvec_minmax,
779 .extra2 = &ten_thousand,
782 .procname = "dmesg_restrict",
783 .data = &dmesg_restrict,
784 .maxlen = sizeof(int),
786 .proc_handler = proc_dointvec_minmax_sysadmin,
791 .procname = "kptr_restrict",
792 .data = &kptr_restrict,
793 .maxlen = sizeof(int),
795 .proc_handler = proc_dointvec_minmax_sysadmin,
801 .procname = "ngroups_max",
802 .data = &ngroups_max,
803 .maxlen = sizeof (int),
805 .proc_handler = proc_dointvec,
808 .procname = "cap_last_cap",
809 .data = (void *)&cap_last_cap,
810 .maxlen = sizeof(int),
812 .proc_handler = proc_dointvec,
814 #if defined(CONFIG_LOCKUP_DETECTOR)
816 .procname = "watchdog",
817 .data = &watchdog_user_enabled,
818 .maxlen = sizeof (int),
820 .proc_handler = proc_dowatchdog,
825 .procname = "watchdog_thresh",
826 .data = &watchdog_thresh,
827 .maxlen = sizeof(int),
829 .proc_handler = proc_dowatchdog,
834 .procname = "softlockup_panic",
835 .data = &softlockup_panic,
836 .maxlen = sizeof(int),
838 .proc_handler = proc_dointvec_minmax,
843 .procname = "nmi_watchdog",
844 .data = &watchdog_user_enabled,
845 .maxlen = sizeof (int),
847 .proc_handler = proc_dowatchdog,
852 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
854 .procname = "unknown_nmi_panic",
855 .data = &unknown_nmi_panic,
856 .maxlen = sizeof (int),
858 .proc_handler = proc_dointvec,
861 #if defined(CONFIG_X86)
863 .procname = "panic_on_unrecovered_nmi",
864 .data = &panic_on_unrecovered_nmi,
865 .maxlen = sizeof(int),
867 .proc_handler = proc_dointvec,
870 .procname = "panic_on_io_nmi",
871 .data = &panic_on_io_nmi,
872 .maxlen = sizeof(int),
874 .proc_handler = proc_dointvec,
876 #ifdef CONFIG_DEBUG_STACKOVERFLOW
878 .procname = "panic_on_stackoverflow",
879 .data = &sysctl_panic_on_stackoverflow,
880 .maxlen = sizeof(int),
882 .proc_handler = proc_dointvec,
886 .procname = "bootloader_type",
887 .data = &bootloader_type,
888 .maxlen = sizeof (int),
890 .proc_handler = proc_dointvec,
893 .procname = "bootloader_version",
894 .data = &bootloader_version,
895 .maxlen = sizeof (int),
897 .proc_handler = proc_dointvec,
900 .procname = "kstack_depth_to_print",
901 .data = &kstack_depth_to_print,
902 .maxlen = sizeof(int),
904 .proc_handler = proc_dointvec,
907 .procname = "io_delay_type",
908 .data = &io_delay_type,
909 .maxlen = sizeof(int),
911 .proc_handler = proc_dointvec,
914 #if defined(CONFIG_MMU)
916 .procname = "randomize_va_space",
917 .data = &randomize_va_space,
918 .maxlen = sizeof(int),
920 .proc_handler = proc_dointvec,
923 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
925 .procname = "spin_retry",
927 .maxlen = sizeof (int),
929 .proc_handler = proc_dointvec,
932 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
934 .procname = "acpi_video_flags",
935 .data = &acpi_realmode_flags,
936 .maxlen = sizeof (unsigned long),
938 .proc_handler = proc_doulongvec_minmax,
941 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
943 .procname = "ignore-unaligned-usertrap",
944 .data = &no_unaligned_warning,
945 .maxlen = sizeof (int),
947 .proc_handler = proc_dointvec,
952 .procname = "unaligned-dump-stack",
953 .data = &unaligned_dump_stack,
954 .maxlen = sizeof (int),
956 .proc_handler = proc_dointvec,
959 #ifdef CONFIG_DETECT_HUNG_TASK
961 .procname = "hung_task_panic",
962 .data = &sysctl_hung_task_panic,
963 .maxlen = sizeof(int),
965 .proc_handler = proc_dointvec_minmax,
970 .procname = "hung_task_check_count",
971 .data = &sysctl_hung_task_check_count,
972 .maxlen = sizeof(unsigned long),
974 .proc_handler = proc_doulongvec_minmax,
977 .procname = "hung_task_timeout_secs",
978 .data = &sysctl_hung_task_timeout_secs,
979 .maxlen = sizeof(unsigned long),
981 .proc_handler = proc_dohung_task_timeout_secs,
984 .procname = "hung_task_warnings",
985 .data = &sysctl_hung_task_warnings,
986 .maxlen = sizeof(unsigned long),
988 .proc_handler = proc_doulongvec_minmax,
993 .procname = "compat-log",
995 .maxlen = sizeof (int),
997 .proc_handler = proc_dointvec,
1000 #ifdef CONFIG_RT_MUTEXES
1002 .procname = "max_lock_depth",
1003 .data = &max_lock_depth,
1004 .maxlen = sizeof(int),
1006 .proc_handler = proc_dointvec,
1010 .procname = "poweroff_cmd",
1011 .data = &poweroff_cmd,
1012 .maxlen = POWEROFF_CMD_PATH_LEN,
1014 .proc_handler = proc_dostring,
1020 .child = key_sysctls,
1023 #ifdef CONFIG_RCU_TORTURE_TEST
1025 .procname = "rcutorture_runnable",
1026 .data = &rcutorture_runnable,
1027 .maxlen = sizeof(int),
1029 .proc_handler = proc_dointvec,
1032 #ifdef CONFIG_PERF_EVENTS
1034 * User-space scripts rely on the existence of this file
1035 * as a feature check for perf_events being enabled.
1037 * So it's an ABI, do not remove!
1040 .procname = "perf_event_paranoid",
1041 .data = &sysctl_perf_event_paranoid,
1042 .maxlen = sizeof(sysctl_perf_event_paranoid),
1044 .proc_handler = proc_dointvec,
1047 .procname = "perf_event_mlock_kb",
1048 .data = &sysctl_perf_event_mlock,
1049 .maxlen = sizeof(sysctl_perf_event_mlock),
1051 .proc_handler = proc_dointvec,
1054 .procname = "perf_event_max_sample_rate",
1055 .data = &sysctl_perf_event_sample_rate,
1056 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1058 .proc_handler = perf_proc_update_handler,
1062 .procname = "perf_cpu_time_max_percent",
1063 .data = &sysctl_perf_cpu_time_max_percent,
1064 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1066 .proc_handler = perf_cpu_time_max_percent_handler,
1068 .extra2 = &one_hundred,
1071 #ifdef CONFIG_KMEMCHECK
1073 .procname = "kmemcheck",
1074 .data = &kmemcheck_enabled,
1075 .maxlen = sizeof(int),
1077 .proc_handler = proc_dointvec,
1082 .procname = "blk_iopoll",
1083 .data = &blk_iopoll_enabled,
1084 .maxlen = sizeof(int),
1086 .proc_handler = proc_dointvec,
1092 static struct ctl_table vm_table[] = {
1094 .procname = "overcommit_memory",
1095 .data = &sysctl_overcommit_memory,
1096 .maxlen = sizeof(sysctl_overcommit_memory),
1098 .proc_handler = proc_dointvec_minmax,
1103 .procname = "panic_on_oom",
1104 .data = &sysctl_panic_on_oom,
1105 .maxlen = sizeof(sysctl_panic_on_oom),
1107 .proc_handler = proc_dointvec_minmax,
1112 .procname = "oom_kill_allocating_task",
1113 .data = &sysctl_oom_kill_allocating_task,
1114 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1116 .proc_handler = proc_dointvec,
1119 .procname = "oom_dump_tasks",
1120 .data = &sysctl_oom_dump_tasks,
1121 .maxlen = sizeof(sysctl_oom_dump_tasks),
1123 .proc_handler = proc_dointvec,
1126 .procname = "overcommit_ratio",
1127 .data = &sysctl_overcommit_ratio,
1128 .maxlen = sizeof(sysctl_overcommit_ratio),
1130 .proc_handler = proc_dointvec,
1133 .procname = "page-cluster",
1134 .data = &page_cluster,
1135 .maxlen = sizeof(int),
1137 .proc_handler = proc_dointvec_minmax,
1141 .procname = "dirty_background_ratio",
1142 .data = &dirty_background_ratio,
1143 .maxlen = sizeof(dirty_background_ratio),
1145 .proc_handler = dirty_background_ratio_handler,
1147 .extra2 = &one_hundred,
1150 .procname = "dirty_background_bytes",
1151 .data = &dirty_background_bytes,
1152 .maxlen = sizeof(dirty_background_bytes),
1154 .proc_handler = dirty_background_bytes_handler,
1158 .procname = "dirty_ratio",
1159 .data = &vm_dirty_ratio,
1160 .maxlen = sizeof(vm_dirty_ratio),
1162 .proc_handler = dirty_ratio_handler,
1164 .extra2 = &one_hundred,
1167 .procname = "dirty_bytes",
1168 .data = &vm_dirty_bytes,
1169 .maxlen = sizeof(vm_dirty_bytes),
1171 .proc_handler = dirty_bytes_handler,
1172 .extra1 = &dirty_bytes_min,
1175 .procname = "dirty_writeback_centisecs",
1176 .data = &dirty_writeback_interval,
1177 .maxlen = sizeof(dirty_writeback_interval),
1179 .proc_handler = dirty_writeback_centisecs_handler,
1182 .procname = "dirty_expire_centisecs",
1183 .data = &dirty_expire_interval,
1184 .maxlen = sizeof(dirty_expire_interval),
1186 .proc_handler = proc_dointvec_minmax,
1190 .procname = "nr_pdflush_threads",
1191 .mode = 0444 /* read-only */,
1192 .proc_handler = pdflush_proc_obsolete,
1195 .procname = "swappiness",
1196 .data = &vm_swappiness,
1197 .maxlen = sizeof(vm_swappiness),
1199 .proc_handler = proc_dointvec_minmax,
1201 .extra2 = &one_hundred,
1203 #ifdef CONFIG_HUGETLB_PAGE
1205 .procname = "nr_hugepages",
1207 .maxlen = sizeof(unsigned long),
1209 .proc_handler = hugetlb_sysctl_handler,
1210 .extra1 = (void *)&hugetlb_zero,
1211 .extra2 = (void *)&hugetlb_infinity,
1215 .procname = "nr_hugepages_mempolicy",
1217 .maxlen = sizeof(unsigned long),
1219 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1220 .extra1 = (void *)&hugetlb_zero,
1221 .extra2 = (void *)&hugetlb_infinity,
1225 .procname = "hugetlb_shm_group",
1226 .data = &sysctl_hugetlb_shm_group,
1227 .maxlen = sizeof(gid_t),
1229 .proc_handler = proc_dointvec,
1232 .procname = "hugepages_treat_as_movable",
1233 .data = &hugepages_treat_as_movable,
1234 .maxlen = sizeof(int),
1236 .proc_handler = proc_dointvec,
1239 .procname = "nr_overcommit_hugepages",
1241 .maxlen = sizeof(unsigned long),
1243 .proc_handler = hugetlb_overcommit_handler,
1244 .extra1 = (void *)&hugetlb_zero,
1245 .extra2 = (void *)&hugetlb_infinity,
1249 .procname = "lowmem_reserve_ratio",
1250 .data = &sysctl_lowmem_reserve_ratio,
1251 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1253 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1256 .procname = "drop_caches",
1257 .data = &sysctl_drop_caches,
1258 .maxlen = sizeof(int),
1260 .proc_handler = drop_caches_sysctl_handler,
1264 #ifdef CONFIG_COMPACTION
1266 .procname = "compact_memory",
1267 .data = &sysctl_compact_memory,
1268 .maxlen = sizeof(int),
1270 .proc_handler = sysctl_compaction_handler,
1273 .procname = "extfrag_threshold",
1274 .data = &sysctl_extfrag_threshold,
1275 .maxlen = sizeof(int),
1277 .proc_handler = sysctl_extfrag_handler,
1278 .extra1 = &min_extfrag_threshold,
1279 .extra2 = &max_extfrag_threshold,
1282 #endif /* CONFIG_COMPACTION */
1284 .procname = "min_free_kbytes",
1285 .data = &min_free_kbytes,
1286 .maxlen = sizeof(min_free_kbytes),
1288 .proc_handler = min_free_kbytes_sysctl_handler,
1292 .procname = "percpu_pagelist_fraction",
1293 .data = &percpu_pagelist_fraction,
1294 .maxlen = sizeof(percpu_pagelist_fraction),
1296 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1297 .extra1 = &min_percpu_pagelist_fract,
1301 .procname = "max_map_count",
1302 .data = &sysctl_max_map_count,
1303 .maxlen = sizeof(sysctl_max_map_count),
1305 .proc_handler = proc_dointvec_minmax,
1310 .procname = "nr_trim_pages",
1311 .data = &sysctl_nr_trim_pages,
1312 .maxlen = sizeof(sysctl_nr_trim_pages),
1314 .proc_handler = proc_dointvec_minmax,
1319 .procname = "laptop_mode",
1320 .data = &laptop_mode,
1321 .maxlen = sizeof(laptop_mode),
1323 .proc_handler = proc_dointvec_jiffies,
1326 .procname = "block_dump",
1327 .data = &block_dump,
1328 .maxlen = sizeof(block_dump),
1330 .proc_handler = proc_dointvec,
1334 .procname = "vfs_cache_pressure",
1335 .data = &sysctl_vfs_cache_pressure,
1336 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1338 .proc_handler = proc_dointvec,
1341 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1343 .procname = "legacy_va_layout",
1344 .data = &sysctl_legacy_va_layout,
1345 .maxlen = sizeof(sysctl_legacy_va_layout),
1347 .proc_handler = proc_dointvec,
1353 .procname = "zone_reclaim_mode",
1354 .data = &zone_reclaim_mode,
1355 .maxlen = sizeof(zone_reclaim_mode),
1357 .proc_handler = proc_dointvec,
1361 .procname = "min_unmapped_ratio",
1362 .data = &sysctl_min_unmapped_ratio,
1363 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1365 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1367 .extra2 = &one_hundred,
1370 .procname = "min_slab_ratio",
1371 .data = &sysctl_min_slab_ratio,
1372 .maxlen = sizeof(sysctl_min_slab_ratio),
1374 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1376 .extra2 = &one_hundred,
1381 .procname = "stat_interval",
1382 .data = &sysctl_stat_interval,
1383 .maxlen = sizeof(sysctl_stat_interval),
1385 .proc_handler = proc_dointvec_jiffies,
1390 .procname = "mmap_min_addr",
1391 .data = &dac_mmap_min_addr,
1392 .maxlen = sizeof(unsigned long),
1394 .proc_handler = mmap_min_addr_handler,
1399 .procname = "numa_zonelist_order",
1400 .data = &numa_zonelist_order,
1401 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1403 .proc_handler = numa_zonelist_order_handler,
1406 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1407 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1409 .procname = "vdso_enabled",
1410 .data = &vdso_enabled,
1411 .maxlen = sizeof(vdso_enabled),
1413 .proc_handler = proc_dointvec,
1417 #ifdef CONFIG_HIGHMEM
1419 .procname = "highmem_is_dirtyable",
1420 .data = &vm_highmem_is_dirtyable,
1421 .maxlen = sizeof(vm_highmem_is_dirtyable),
1423 .proc_handler = proc_dointvec_minmax,
1429 .procname = "scan_unevictable_pages",
1430 .data = &scan_unevictable_pages,
1431 .maxlen = sizeof(scan_unevictable_pages),
1433 .proc_handler = scan_unevictable_handler,
1435 #ifdef CONFIG_MEMORY_FAILURE
1437 .procname = "memory_failure_early_kill",
1438 .data = &sysctl_memory_failure_early_kill,
1439 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1441 .proc_handler = proc_dointvec_minmax,
1446 .procname = "memory_failure_recovery",
1447 .data = &sysctl_memory_failure_recovery,
1448 .maxlen = sizeof(sysctl_memory_failure_recovery),
1450 .proc_handler = proc_dointvec_minmax,
1456 .procname = "user_reserve_kbytes",
1457 .data = &sysctl_user_reserve_kbytes,
1458 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1460 .proc_handler = proc_doulongvec_minmax,
1463 .procname = "admin_reserve_kbytes",
1464 .data = &sysctl_admin_reserve_kbytes,
1465 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1467 .proc_handler = proc_doulongvec_minmax,
1472 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1473 static struct ctl_table binfmt_misc_table[] = {
1478 static struct ctl_table fs_table[] = {
1480 .procname = "inode-nr",
1481 .data = &inodes_stat,
1482 .maxlen = 2*sizeof(long),
1484 .proc_handler = proc_nr_inodes,
1487 .procname = "inode-state",
1488 .data = &inodes_stat,
1489 .maxlen = 7*sizeof(long),
1491 .proc_handler = proc_nr_inodes,
1494 .procname = "file-nr",
1495 .data = &files_stat,
1496 .maxlen = sizeof(files_stat),
1498 .proc_handler = proc_nr_files,
1501 .procname = "file-max",
1502 .data = &files_stat.max_files,
1503 .maxlen = sizeof(files_stat.max_files),
1505 .proc_handler = proc_doulongvec_minmax,
1508 .procname = "nr_open",
1509 .data = &sysctl_nr_open,
1510 .maxlen = sizeof(int),
1512 .proc_handler = proc_dointvec_minmax,
1513 .extra1 = &sysctl_nr_open_min,
1514 .extra2 = &sysctl_nr_open_max,
1517 .procname = "dentry-state",
1518 .data = &dentry_stat,
1519 .maxlen = 6*sizeof(long),
1521 .proc_handler = proc_nr_dentry,
1524 .procname = "overflowuid",
1525 .data = &fs_overflowuid,
1526 .maxlen = sizeof(int),
1528 .proc_handler = proc_dointvec_minmax,
1529 .extra1 = &minolduid,
1530 .extra2 = &maxolduid,
1533 .procname = "overflowgid",
1534 .data = &fs_overflowgid,
1535 .maxlen = sizeof(int),
1537 .proc_handler = proc_dointvec_minmax,
1538 .extra1 = &minolduid,
1539 .extra2 = &maxolduid,
1541 #ifdef CONFIG_FILE_LOCKING
1543 .procname = "leases-enable",
1544 .data = &leases_enable,
1545 .maxlen = sizeof(int),
1547 .proc_handler = proc_dointvec,
1550 #ifdef CONFIG_DNOTIFY
1552 .procname = "dir-notify-enable",
1553 .data = &dir_notify_enable,
1554 .maxlen = sizeof(int),
1556 .proc_handler = proc_dointvec,
1560 #ifdef CONFIG_FILE_LOCKING
1562 .procname = "lease-break-time",
1563 .data = &lease_break_time,
1564 .maxlen = sizeof(int),
1566 .proc_handler = proc_dointvec,
1571 .procname = "aio-nr",
1573 .maxlen = sizeof(aio_nr),
1575 .proc_handler = proc_doulongvec_minmax,
1578 .procname = "aio-max-nr",
1579 .data = &aio_max_nr,
1580 .maxlen = sizeof(aio_max_nr),
1582 .proc_handler = proc_doulongvec_minmax,
1584 #endif /* CONFIG_AIO */
1585 #ifdef CONFIG_INOTIFY_USER
1587 .procname = "inotify",
1589 .child = inotify_table,
1594 .procname = "epoll",
1596 .child = epoll_table,
1601 .procname = "protected_symlinks",
1602 .data = &sysctl_protected_symlinks,
1603 .maxlen = sizeof(int),
1605 .proc_handler = proc_dointvec_minmax,
1610 .procname = "protected_hardlinks",
1611 .data = &sysctl_protected_hardlinks,
1612 .maxlen = sizeof(int),
1614 .proc_handler = proc_dointvec_minmax,
1619 .procname = "suid_dumpable",
1620 .data = &suid_dumpable,
1621 .maxlen = sizeof(int),
1623 .proc_handler = proc_dointvec_minmax_coredump,
1627 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1629 .procname = "binfmt_misc",
1631 .child = binfmt_misc_table,
1635 .procname = "pipe-max-size",
1636 .data = &pipe_max_size,
1637 .maxlen = sizeof(int),
1639 .proc_handler = &pipe_proc_fn,
1640 .extra1 = &pipe_min_size,
1645 static struct ctl_table debug_table[] = {
1646 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1648 .procname = "exception-trace",
1649 .data = &show_unhandled_signals,
1650 .maxlen = sizeof(int),
1652 .proc_handler = proc_dointvec
1655 #if defined(CONFIG_OPTPROBES)
1657 .procname = "kprobes-optimization",
1658 .data = &sysctl_kprobes_optimization,
1659 .maxlen = sizeof(int),
1661 .proc_handler = proc_kprobes_optimization_handler,
1669 static struct ctl_table dev_table[] = {
1673 int __init sysctl_init(void)
1675 struct ctl_table_header *hdr;
1677 hdr = register_sysctl_table(sysctl_base_table);
1678 kmemleak_not_leak(hdr);
1682 #endif /* CONFIG_SYSCTL */
1688 #ifdef CONFIG_PROC_SYSCTL
1690 static int _proc_do_string(void* data, int maxlen, int write,
1691 void __user *buffer,
1692 size_t *lenp, loff_t *ppos)
1698 if (!data || !maxlen || !*lenp) {
1706 while (len < *lenp) {
1707 if (get_user(c, p++))
1709 if (c == 0 || c == '\n')
1715 if(copy_from_user(data, buffer, len))
1717 ((char *) data)[len] = 0;
1735 if(copy_to_user(buffer, data, len))
1738 if(put_user('\n', ((char __user *) buffer) + len))
1749 * proc_dostring - read a string sysctl
1750 * @table: the sysctl table
1751 * @write: %TRUE if this is a write to the sysctl file
1752 * @buffer: the user buffer
1753 * @lenp: the size of the user buffer
1754 * @ppos: file position
1756 * Reads/writes a string from/to the user buffer. If the kernel
1757 * buffer provided is not large enough to hold the string, the
1758 * string is truncated. The copied string is %NULL-terminated.
1759 * If the string is being read by the user process, it is copied
1760 * and a newline '\n' is added. It is truncated if the buffer is
1763 * Returns 0 on success.
1765 int proc_dostring(struct ctl_table *table, int write,
1766 void __user *buffer, size_t *lenp, loff_t *ppos)
1768 return _proc_do_string(table->data, table->maxlen, write,
1769 buffer, lenp, ppos);
1772 static size_t proc_skip_spaces(char **buf)
1775 char *tmp = skip_spaces(*buf);
1781 static void proc_skip_char(char **buf, size_t *size, const char v)
1791 #define TMPBUFLEN 22
1793 * proc_get_long - reads an ASCII formatted integer from a user buffer
1795 * @buf: a kernel buffer
1796 * @size: size of the kernel buffer
1797 * @val: this is where the number will be stored
1798 * @neg: set to %TRUE if number is negative
1799 * @perm_tr: a vector which contains the allowed trailers
1800 * @perm_tr_len: size of the perm_tr vector
1801 * @tr: pointer to store the trailer character
1803 * In case of success %0 is returned and @buf and @size are updated with
1804 * the amount of bytes read. If @tr is non-NULL and a trailing
1805 * character exists (size is non-zero after returning from this
1806 * function), @tr is updated with the trailing character.
1808 static int proc_get_long(char **buf, size_t *size,
1809 unsigned long *val, bool *neg,
1810 const char *perm_tr, unsigned perm_tr_len, char *tr)
1813 char *p, tmp[TMPBUFLEN];
1819 if (len > TMPBUFLEN - 1)
1820 len = TMPBUFLEN - 1;
1822 memcpy(tmp, *buf, len);
1826 if (*p == '-' && *size > 1) {
1834 *val = simple_strtoul(p, &p, 0);
1838 /* We don't know if the next char is whitespace thus we may accept
1839 * invalid integers (e.g. 1234...a) or two integers instead of one
1840 * (e.g. 123...1). So lets not allow such large numbers. */
1841 if (len == TMPBUFLEN - 1)
1844 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1847 if (tr && (len < *size))
1857 * proc_put_long - converts an integer to a decimal ASCII formatted string
1859 * @buf: the user buffer
1860 * @size: the size of the user buffer
1861 * @val: the integer to be converted
1862 * @neg: sign of the number, %TRUE for negative
1864 * In case of success %0 is returned and @buf and @size are updated with
1865 * the amount of bytes written.
1867 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1871 char tmp[TMPBUFLEN], *p = tmp;
1873 sprintf(p, "%s%lu", neg ? "-" : "", val);
1877 if (copy_to_user(*buf, tmp, len))
1885 static int proc_put_char(void __user **buf, size_t *size, char c)
1888 char __user **buffer = (char __user **)buf;
1889 if (put_user(c, *buffer))
1891 (*size)--, (*buffer)++;
1897 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1899 int write, void *data)
1902 *valp = *negp ? -*lvalp : *lvalp;
1907 *lvalp = (unsigned long)-val;
1910 *lvalp = (unsigned long)val;
1916 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1918 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1919 int write, void __user *buffer,
1920 size_t *lenp, loff_t *ppos,
1921 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1922 int write, void *data),
1925 int *i, vleft, first = 1, err = 0;
1926 unsigned long page = 0;
1930 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1935 i = (int *) tbl_data;
1936 vleft = table->maxlen / sizeof(*i);
1940 conv = do_proc_dointvec_conv;
1943 if (left > PAGE_SIZE - 1)
1944 left = PAGE_SIZE - 1;
1945 page = __get_free_page(GFP_TEMPORARY);
1946 kbuf = (char *) page;
1949 if (copy_from_user(kbuf, buffer, left)) {
1956 for (; left && vleft--; i++, first=0) {
1961 left -= proc_skip_spaces(&kbuf);
1965 err = proc_get_long(&kbuf, &left, &lval, &neg,
1967 sizeof(proc_wspace_sep), NULL);
1970 if (conv(&neg, &lval, i, 1, data)) {
1975 if (conv(&neg, &lval, i, 0, data)) {
1980 err = proc_put_char(&buffer, &left, '\t');
1983 err = proc_put_long(&buffer, &left, lval, neg);
1989 if (!write && !first && left && !err)
1990 err = proc_put_char(&buffer, &left, '\n');
1991 if (write && !err && left)
1992 left -= proc_skip_spaces(&kbuf);
1997 return err ? : -EINVAL;
2004 static int do_proc_dointvec(struct ctl_table *table, int write,
2005 void __user *buffer, size_t *lenp, loff_t *ppos,
2006 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2007 int write, void *data),
2010 return __do_proc_dointvec(table->data, table, write,
2011 buffer, lenp, ppos, conv, data);
2015 * proc_dointvec - read a vector of integers
2016 * @table: the sysctl table
2017 * @write: %TRUE if this is a write to the sysctl file
2018 * @buffer: the user buffer
2019 * @lenp: the size of the user buffer
2020 * @ppos: file position
2022 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2023 * values from/to the user buffer, treated as an ASCII string.
2025 * Returns 0 on success.
2027 int proc_dointvec(struct ctl_table *table, int write,
2028 void __user *buffer, size_t *lenp, loff_t *ppos)
2030 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2035 * Taint values can only be increased
2036 * This means we can safely use a temporary.
2038 static int proc_taint(struct ctl_table *table, int write,
2039 void __user *buffer, size_t *lenp, loff_t *ppos)
2042 unsigned long tmptaint = get_taint();
2045 if (write && !capable(CAP_SYS_ADMIN))
2050 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2056 * Poor man's atomic or. Not worth adding a primitive
2057 * to everyone's atomic.h for this
2060 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2061 if ((tmptaint >> i) & 1)
2062 add_taint(i, LOCKDEP_STILL_OK);
2069 #ifdef CONFIG_PRINTK
2070 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2071 void __user *buffer, size_t *lenp, loff_t *ppos)
2073 if (write && !capable(CAP_SYS_ADMIN))
2076 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2080 struct do_proc_dointvec_minmax_conv_param {
2085 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2087 int write, void *data)
2089 struct do_proc_dointvec_minmax_conv_param *param = data;
2091 int val = *negp ? -*lvalp : *lvalp;
2092 if ((param->min && *param->min > val) ||
2093 (param->max && *param->max < val))
2100 *lvalp = (unsigned long)-val;
2103 *lvalp = (unsigned long)val;
2110 * proc_dointvec_minmax - read a vector of integers with min/max values
2111 * @table: the sysctl table
2112 * @write: %TRUE if this is a write to the sysctl file
2113 * @buffer: the user buffer
2114 * @lenp: the size of the user buffer
2115 * @ppos: file position
2117 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2118 * values from/to the user buffer, treated as an ASCII string.
2120 * This routine will ensure the values are within the range specified by
2121 * table->extra1 (min) and table->extra2 (max).
2123 * Returns 0 on success.
2125 int proc_dointvec_minmax(struct ctl_table *table, int write,
2126 void __user *buffer, size_t *lenp, loff_t *ppos)
2128 struct do_proc_dointvec_minmax_conv_param param = {
2129 .min = (int *) table->extra1,
2130 .max = (int *) table->extra2,
2132 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2133 do_proc_dointvec_minmax_conv, ¶m);
2136 static void validate_coredump_safety(void)
2138 #ifdef CONFIG_COREDUMP
2139 if (suid_dumpable == SUID_DUMP_ROOT &&
2140 core_pattern[0] != '/' && core_pattern[0] != '|') {
2141 printk(KERN_WARNING "Unsafe core_pattern used with "\
2142 "suid_dumpable=2. Pipe handler or fully qualified "\
2143 "core dump path required.\n");
2148 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2149 void __user *buffer, size_t *lenp, loff_t *ppos)
2151 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2153 validate_coredump_safety();
2157 #ifdef CONFIG_COREDUMP
2158 static int proc_dostring_coredump(struct ctl_table *table, int write,
2159 void __user *buffer, size_t *lenp, loff_t *ppos)
2161 int error = proc_dostring(table, write, buffer, lenp, ppos);
2163 validate_coredump_safety();
2168 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2169 void __user *buffer,
2170 size_t *lenp, loff_t *ppos,
2171 unsigned long convmul,
2172 unsigned long convdiv)
2174 unsigned long *i, *min, *max;
2175 int vleft, first = 1, err = 0;
2176 unsigned long page = 0;
2180 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2185 i = (unsigned long *) data;
2186 min = (unsigned long *) table->extra1;
2187 max = (unsigned long *) table->extra2;
2188 vleft = table->maxlen / sizeof(unsigned long);
2192 if (left > PAGE_SIZE - 1)
2193 left = PAGE_SIZE - 1;
2194 page = __get_free_page(GFP_TEMPORARY);
2195 kbuf = (char *) page;
2198 if (copy_from_user(kbuf, buffer, left)) {
2205 for (; left && vleft--; i++, first = 0) {
2211 left -= proc_skip_spaces(&kbuf);
2213 err = proc_get_long(&kbuf, &left, &val, &neg,
2215 sizeof(proc_wspace_sep), NULL);
2220 if ((min && val < *min) || (max && val > *max))
2224 val = convdiv * (*i) / convmul;
2226 err = proc_put_char(&buffer, &left, '\t');
2230 err = proc_put_long(&buffer, &left, val, false);
2236 if (!write && !first && left && !err)
2237 err = proc_put_char(&buffer, &left, '\n');
2239 left -= proc_skip_spaces(&kbuf);
2244 return err ? : -EINVAL;
2251 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2252 void __user *buffer,
2253 size_t *lenp, loff_t *ppos,
2254 unsigned long convmul,
2255 unsigned long convdiv)
2257 return __do_proc_doulongvec_minmax(table->data, table, write,
2258 buffer, lenp, ppos, convmul, convdiv);
2262 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2263 * @table: the sysctl table
2264 * @write: %TRUE if this is a write to the sysctl file
2265 * @buffer: the user buffer
2266 * @lenp: the size of the user buffer
2267 * @ppos: file position
2269 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2270 * values from/to the user buffer, treated as an ASCII string.
2272 * This routine will ensure the values are within the range specified by
2273 * table->extra1 (min) and table->extra2 (max).
2275 * Returns 0 on success.
2277 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2278 void __user *buffer, size_t *lenp, loff_t *ppos)
2280 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2284 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2285 * @table: the sysctl table
2286 * @write: %TRUE if this is a write to the sysctl file
2287 * @buffer: the user buffer
2288 * @lenp: the size of the user buffer
2289 * @ppos: file position
2291 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2292 * values from/to the user buffer, treated as an ASCII string. The values
2293 * are treated as milliseconds, and converted to jiffies when they are stored.
2295 * This routine will ensure the values are within the range specified by
2296 * table->extra1 (min) and table->extra2 (max).
2298 * Returns 0 on success.
2300 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2301 void __user *buffer,
2302 size_t *lenp, loff_t *ppos)
2304 return do_proc_doulongvec_minmax(table, write, buffer,
2305 lenp, ppos, HZ, 1000l);
2309 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2311 int write, void *data)
2314 if (*lvalp > LONG_MAX / HZ)
2316 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2322 lval = (unsigned long)-val;
2325 lval = (unsigned long)val;
2332 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2334 int write, void *data)
2337 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2339 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2345 lval = (unsigned long)-val;
2348 lval = (unsigned long)val;
2350 *lvalp = jiffies_to_clock_t(lval);
2355 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2357 int write, void *data)
2360 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2370 lval = (unsigned long)-val;
2373 lval = (unsigned long)val;
2375 *lvalp = jiffies_to_msecs(lval);
2381 * proc_dointvec_jiffies - read a vector of integers as seconds
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 int) integer
2389 * values from/to the user buffer, treated as an ASCII string.
2390 * The values read are assumed to be in seconds, and are converted into
2393 * Returns 0 on success.
2395 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2396 void __user *buffer, size_t *lenp, loff_t *ppos)
2398 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2399 do_proc_dointvec_jiffies_conv,NULL);
2403 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
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: pointer to the file position
2410 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2411 * values from/to the user buffer, treated as an ASCII string.
2412 * The values read are assumed to be in 1/USER_HZ seconds, and
2413 * are converted into jiffies.
2415 * Returns 0 on success.
2417 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2418 void __user *buffer, size_t *lenp, loff_t *ppos)
2420 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2421 do_proc_dointvec_userhz_jiffies_conv,NULL);
2425 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2426 * @table: the sysctl table
2427 * @write: %TRUE if this is a write to the sysctl file
2428 * @buffer: the user buffer
2429 * @lenp: the size of the user buffer
2430 * @ppos: file position
2431 * @ppos: the current position in the file
2433 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2434 * values from/to the user buffer, treated as an ASCII string.
2435 * The values read are assumed to be in 1/1000 seconds, and
2436 * are converted into jiffies.
2438 * Returns 0 on success.
2440 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2441 void __user *buffer, size_t *lenp, loff_t *ppos)
2443 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2444 do_proc_dointvec_ms_jiffies_conv, NULL);
2447 static int proc_do_cad_pid(struct ctl_table *table, int write,
2448 void __user *buffer, size_t *lenp, loff_t *ppos)
2450 struct pid *new_pid;
2454 tmp = pid_vnr(cad_pid);
2456 r = __do_proc_dointvec(&tmp, table, write, buffer,
2457 lenp, ppos, NULL, NULL);
2461 new_pid = find_get_pid(tmp);
2465 put_pid(xchg(&cad_pid, new_pid));
2470 * proc_do_large_bitmap - read/write from/to a large bitmap
2471 * @table: the sysctl table
2472 * @write: %TRUE if this is a write to the sysctl file
2473 * @buffer: the user buffer
2474 * @lenp: the size of the user buffer
2475 * @ppos: file position
2477 * The bitmap is stored at table->data and the bitmap length (in bits)
2480 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2481 * large bitmaps may be represented in a compact manner. Writing into
2482 * the file will clear the bitmap then update it with the given input.
2484 * Returns 0 on success.
2486 int proc_do_large_bitmap(struct ctl_table *table, int write,
2487 void __user *buffer, size_t *lenp, loff_t *ppos)
2491 size_t left = *lenp;
2492 unsigned long bitmap_len = table->maxlen;
2493 unsigned long *bitmap = (unsigned long *) table->data;
2494 unsigned long *tmp_bitmap = NULL;
2495 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2497 if (!bitmap_len || !left || (*ppos && !write)) {
2503 unsigned long page = 0;
2506 if (left > PAGE_SIZE - 1)
2507 left = PAGE_SIZE - 1;
2509 page = __get_free_page(GFP_TEMPORARY);
2510 kbuf = (char *) page;
2513 if (copy_from_user(kbuf, buffer, left)) {
2519 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2525 proc_skip_char(&kbuf, &left, '\n');
2526 while (!err && left) {
2527 unsigned long val_a, val_b;
2530 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2534 if (val_a >= bitmap_len || neg) {
2546 err = proc_get_long(&kbuf, &left, &val_b,
2547 &neg, tr_b, sizeof(tr_b),
2551 if (val_b >= bitmap_len || neg ||
2562 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2564 proc_skip_char(&kbuf, &left, '\n');
2568 unsigned long bit_a, bit_b = 0;
2571 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2572 if (bit_a >= bitmap_len)
2574 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2578 err = proc_put_char(&buffer, &left, ',');
2582 err = proc_put_long(&buffer, &left, bit_a, false);
2585 if (bit_a != bit_b) {
2586 err = proc_put_char(&buffer, &left, '-');
2589 err = proc_put_long(&buffer, &left, bit_b, false);
2597 err = proc_put_char(&buffer, &left, '\n');
2603 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2605 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2617 #else /* CONFIG_PROC_SYSCTL */
2619 int proc_dostring(struct ctl_table *table, int write,
2620 void __user *buffer, size_t *lenp, loff_t *ppos)
2625 int proc_dointvec(struct ctl_table *table, int write,
2626 void __user *buffer, size_t *lenp, loff_t *ppos)
2631 int proc_dointvec_minmax(struct ctl_table *table, int write,
2632 void __user *buffer, size_t *lenp, loff_t *ppos)
2637 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2638 void __user *buffer, size_t *lenp, loff_t *ppos)
2643 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2644 void __user *buffer, size_t *lenp, loff_t *ppos)
2649 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2650 void __user *buffer, size_t *lenp, loff_t *ppos)
2655 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2656 void __user *buffer, size_t *lenp, loff_t *ppos)
2661 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2662 void __user *buffer,
2663 size_t *lenp, loff_t *ppos)
2669 #endif /* CONFIG_PROC_SYSCTL */
2672 * No sense putting this after each symbol definition, twice,
2673 * exception granted :-)
2675 EXPORT_SYMBOL(proc_dointvec);
2676 EXPORT_SYMBOL(proc_dointvec_jiffies);
2677 EXPORT_SYMBOL(proc_dointvec_minmax);
2678 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2679 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2680 EXPORT_SYMBOL(proc_dostring);
2681 EXPORT_SYMBOL(proc_doulongvec_minmax);
2682 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);