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 max_threads;
99 extern int suid_dumpable;
100 #ifdef CONFIG_COREDUMP
101 extern int core_uses_pid;
102 extern char core_pattern[];
103 extern unsigned int core_pipe_limit;
106 extern int pid_max_min, pid_max_max;
107 extern int percpu_pagelist_fraction;
108 extern int compat_log;
109 extern int latencytop_enabled;
110 extern int sysctl_nr_open_min, sysctl_nr_open_max;
112 extern int sysctl_nr_trim_pages;
115 extern int blk_iopoll_enabled;
118 /* Constants used for minimum and maximum */
119 #ifdef CONFIG_LOCKUP_DETECTOR
120 static int sixty = 60;
124 static int __maybe_unused one = 1;
125 static int __maybe_unused two = 2;
126 static int __maybe_unused three = 3;
127 static unsigned long one_ul = 1;
128 static int one_hundred = 100;
130 static int ten_thousand = 10000;
133 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
134 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
136 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
137 static int maxolduid = 65535;
138 static int minolduid;
139 static int min_percpu_pagelist_fract = 8;
141 static int ngroups_max = NGROUPS_MAX;
142 static const int cap_last_cap = CAP_LAST_CAP;
144 #ifdef CONFIG_INOTIFY_USER
145 #include <linux/inotify.h>
150 #ifdef CONFIG_SPARC64
151 extern int sysctl_tsb_ratio;
155 extern int pwrsw_enabled;
158 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
159 extern int unaligned_enabled;
163 extern int unaligned_dump_stack;
166 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
167 extern int no_unaligned_warning;
170 #ifdef CONFIG_PROC_SYSCTL
171 static int proc_do_cad_pid(struct ctl_table *table, int write,
172 void __user *buffer, size_t *lenp, loff_t *ppos);
173 static int proc_taint(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp, loff_t *ppos);
178 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
179 void __user *buffer, size_t *lenp, loff_t *ppos);
182 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
183 void __user *buffer, size_t *lenp, loff_t *ppos);
184 #ifdef CONFIG_COREDUMP
185 static int proc_dostring_coredump(struct ctl_table *table, int write,
186 void __user *buffer, size_t *lenp, loff_t *ppos);
189 #ifdef CONFIG_MAGIC_SYSRQ
190 /* Note: sysrq code uses it's own private copy */
191 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
193 static int sysrq_sysctl_handler(ctl_table *table, int write,
194 void __user *buffer, size_t *lenp,
199 error = proc_dointvec(table, write, buffer, lenp, ppos);
204 sysrq_toggle_support(__sysrq_enabled);
211 static struct ctl_table kern_table[];
212 static struct ctl_table vm_table[];
213 static struct ctl_table fs_table[];
214 static struct ctl_table debug_table[];
215 static struct ctl_table dev_table[];
216 extern struct ctl_table random_table[];
218 extern struct ctl_table epoll_table[];
221 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
222 int sysctl_legacy_va_layout;
225 /* The default sysctl tables: */
227 static struct ctl_table sysctl_base_table[] = {
229 .procname = "kernel",
246 .child = debug_table,
256 #ifdef CONFIG_SCHED_DEBUG
257 static int min_sched_granularity_ns = 100000; /* 100 usecs */
258 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
259 static int min_wakeup_granularity_ns; /* 0 usecs */
260 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
262 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
263 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
264 #endif /* CONFIG_SMP */
265 #endif /* CONFIG_SCHED_DEBUG */
267 #ifdef CONFIG_COMPACTION
268 static int min_extfrag_threshold;
269 static int max_extfrag_threshold = 1000;
272 static struct ctl_table kern_table[] = {
274 .procname = "sched_child_runs_first",
275 .data = &sysctl_sched_child_runs_first,
276 .maxlen = sizeof(unsigned int),
278 .proc_handler = proc_dointvec,
280 #ifdef CONFIG_SCHED_DEBUG
282 .procname = "sched_min_granularity_ns",
283 .data = &sysctl_sched_min_granularity,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = sched_proc_update_handler,
287 .extra1 = &min_sched_granularity_ns,
288 .extra2 = &max_sched_granularity_ns,
291 .procname = "sched_latency_ns",
292 .data = &sysctl_sched_latency,
293 .maxlen = sizeof(unsigned int),
295 .proc_handler = sched_proc_update_handler,
296 .extra1 = &min_sched_granularity_ns,
297 .extra2 = &max_sched_granularity_ns,
300 .procname = "sched_wakeup_granularity_ns",
301 .data = &sysctl_sched_wakeup_granularity,
302 .maxlen = sizeof(unsigned int),
304 .proc_handler = sched_proc_update_handler,
305 .extra1 = &min_wakeup_granularity_ns,
306 .extra2 = &max_wakeup_granularity_ns,
310 .procname = "sched_tunable_scaling",
311 .data = &sysctl_sched_tunable_scaling,
312 .maxlen = sizeof(enum sched_tunable_scaling),
314 .proc_handler = sched_proc_update_handler,
315 .extra1 = &min_sched_tunable_scaling,
316 .extra2 = &max_sched_tunable_scaling,
319 .procname = "sched_migration_cost_ns",
320 .data = &sysctl_sched_migration_cost,
321 .maxlen = sizeof(unsigned int),
323 .proc_handler = proc_dointvec,
326 .procname = "sched_nr_migrate",
327 .data = &sysctl_sched_nr_migrate,
328 .maxlen = sizeof(unsigned int),
330 .proc_handler = proc_dointvec,
333 .procname = "sched_time_avg_ms",
334 .data = &sysctl_sched_time_avg,
335 .maxlen = sizeof(unsigned int),
337 .proc_handler = proc_dointvec,
340 .procname = "sched_shares_window_ns",
341 .data = &sysctl_sched_shares_window,
342 .maxlen = sizeof(unsigned int),
344 .proc_handler = proc_dointvec,
347 .procname = "timer_migration",
348 .data = &sysctl_timer_migration,
349 .maxlen = sizeof(unsigned int),
351 .proc_handler = proc_dointvec_minmax,
355 #endif /* CONFIG_SMP */
356 #ifdef CONFIG_NUMA_BALANCING
358 .procname = "numa_balancing_scan_delay_ms",
359 .data = &sysctl_numa_balancing_scan_delay,
360 .maxlen = sizeof(unsigned int),
362 .proc_handler = proc_dointvec,
365 .procname = "numa_balancing_scan_period_min_ms",
366 .data = &sysctl_numa_balancing_scan_period_min,
367 .maxlen = sizeof(unsigned int),
369 .proc_handler = proc_dointvec,
372 .procname = "numa_balancing_scan_period_max_ms",
373 .data = &sysctl_numa_balancing_scan_period_max,
374 .maxlen = sizeof(unsigned int),
376 .proc_handler = proc_dointvec,
379 .procname = "numa_balancing_scan_size_mb",
380 .data = &sysctl_numa_balancing_scan_size,
381 .maxlen = sizeof(unsigned int),
383 .proc_handler = proc_dointvec,
386 .procname = "numa_balancing_migrate_deferred",
387 .data = &sysctl_numa_balancing_migrate_deferred,
388 .maxlen = sizeof(unsigned int),
390 .proc_handler = proc_dointvec,
393 .procname = "numa_balancing",
394 .data = NULL, /* filled in by handler */
395 .maxlen = sizeof(unsigned int),
397 .proc_handler = sysctl_numa_balancing,
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(int),
974 .proc_handler = proc_dointvec_minmax,
978 .procname = "hung_task_timeout_secs",
979 .data = &sysctl_hung_task_timeout_secs,
980 .maxlen = sizeof(unsigned long),
982 .proc_handler = proc_dohung_task_timeout_secs,
985 .procname = "hung_task_warnings",
986 .data = &sysctl_hung_task_warnings,
987 .maxlen = sizeof(unsigned long),
989 .proc_handler = proc_doulongvec_minmax,
994 .procname = "compat-log",
996 .maxlen = sizeof (int),
998 .proc_handler = proc_dointvec,
1001 #ifdef CONFIG_RT_MUTEXES
1003 .procname = "max_lock_depth",
1004 .data = &max_lock_depth,
1005 .maxlen = sizeof(int),
1007 .proc_handler = proc_dointvec,
1011 .procname = "poweroff_cmd",
1012 .data = &poweroff_cmd,
1013 .maxlen = POWEROFF_CMD_PATH_LEN,
1015 .proc_handler = proc_dostring,
1021 .child = key_sysctls,
1024 #ifdef CONFIG_RCU_TORTURE_TEST
1026 .procname = "rcutorture_runnable",
1027 .data = &rcutorture_runnable,
1028 .maxlen = sizeof(int),
1030 .proc_handler = proc_dointvec,
1033 #ifdef CONFIG_PERF_EVENTS
1035 * User-space scripts rely on the existence of this file
1036 * as a feature check for perf_events being enabled.
1038 * So it's an ABI, do not remove!
1041 .procname = "perf_event_paranoid",
1042 .data = &sysctl_perf_event_paranoid,
1043 .maxlen = sizeof(sysctl_perf_event_paranoid),
1045 .proc_handler = proc_dointvec,
1048 .procname = "perf_event_mlock_kb",
1049 .data = &sysctl_perf_event_mlock,
1050 .maxlen = sizeof(sysctl_perf_event_mlock),
1052 .proc_handler = proc_dointvec,
1055 .procname = "perf_event_max_sample_rate",
1056 .data = &sysctl_perf_event_sample_rate,
1057 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1059 .proc_handler = perf_proc_update_handler,
1063 .procname = "perf_cpu_time_max_percent",
1064 .data = &sysctl_perf_cpu_time_max_percent,
1065 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1067 .proc_handler = perf_cpu_time_max_percent_handler,
1069 .extra2 = &one_hundred,
1072 #ifdef CONFIG_KMEMCHECK
1074 .procname = "kmemcheck",
1075 .data = &kmemcheck_enabled,
1076 .maxlen = sizeof(int),
1078 .proc_handler = proc_dointvec,
1083 .procname = "blk_iopoll",
1084 .data = &blk_iopoll_enabled,
1085 .maxlen = sizeof(int),
1087 .proc_handler = proc_dointvec,
1093 static struct ctl_table vm_table[] = {
1095 .procname = "overcommit_memory",
1096 .data = &sysctl_overcommit_memory,
1097 .maxlen = sizeof(sysctl_overcommit_memory),
1099 .proc_handler = proc_dointvec_minmax,
1104 .procname = "panic_on_oom",
1105 .data = &sysctl_panic_on_oom,
1106 .maxlen = sizeof(sysctl_panic_on_oom),
1108 .proc_handler = proc_dointvec_minmax,
1113 .procname = "oom_kill_allocating_task",
1114 .data = &sysctl_oom_kill_allocating_task,
1115 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1117 .proc_handler = proc_dointvec,
1120 .procname = "oom_dump_tasks",
1121 .data = &sysctl_oom_dump_tasks,
1122 .maxlen = sizeof(sysctl_oom_dump_tasks),
1124 .proc_handler = proc_dointvec,
1127 .procname = "overcommit_ratio",
1128 .data = &sysctl_overcommit_ratio,
1129 .maxlen = sizeof(sysctl_overcommit_ratio),
1131 .proc_handler = overcommit_ratio_handler,
1134 .procname = "overcommit_kbytes",
1135 .data = &sysctl_overcommit_kbytes,
1136 .maxlen = sizeof(sysctl_overcommit_kbytes),
1138 .proc_handler = overcommit_kbytes_handler,
1141 .procname = "page-cluster",
1142 .data = &page_cluster,
1143 .maxlen = sizeof(int),
1145 .proc_handler = proc_dointvec_minmax,
1149 .procname = "dirty_background_ratio",
1150 .data = &dirty_background_ratio,
1151 .maxlen = sizeof(dirty_background_ratio),
1153 .proc_handler = dirty_background_ratio_handler,
1155 .extra2 = &one_hundred,
1158 .procname = "dirty_background_bytes",
1159 .data = &dirty_background_bytes,
1160 .maxlen = sizeof(dirty_background_bytes),
1162 .proc_handler = dirty_background_bytes_handler,
1166 .procname = "dirty_ratio",
1167 .data = &vm_dirty_ratio,
1168 .maxlen = sizeof(vm_dirty_ratio),
1170 .proc_handler = dirty_ratio_handler,
1172 .extra2 = &one_hundred,
1175 .procname = "dirty_bytes",
1176 .data = &vm_dirty_bytes,
1177 .maxlen = sizeof(vm_dirty_bytes),
1179 .proc_handler = dirty_bytes_handler,
1180 .extra1 = &dirty_bytes_min,
1183 .procname = "dirty_writeback_centisecs",
1184 .data = &dirty_writeback_interval,
1185 .maxlen = sizeof(dirty_writeback_interval),
1187 .proc_handler = dirty_writeback_centisecs_handler,
1190 .procname = "dirty_expire_centisecs",
1191 .data = &dirty_expire_interval,
1192 .maxlen = sizeof(dirty_expire_interval),
1194 .proc_handler = proc_dointvec_minmax,
1198 .procname = "nr_pdflush_threads",
1199 .mode = 0444 /* read-only */,
1200 .proc_handler = pdflush_proc_obsolete,
1203 .procname = "swappiness",
1204 .data = &vm_swappiness,
1205 .maxlen = sizeof(vm_swappiness),
1207 .proc_handler = proc_dointvec_minmax,
1209 .extra2 = &one_hundred,
1211 #ifdef CONFIG_HUGETLB_PAGE
1213 .procname = "nr_hugepages",
1215 .maxlen = sizeof(unsigned long),
1217 .proc_handler = hugetlb_sysctl_handler,
1218 .extra1 = (void *)&hugetlb_zero,
1219 .extra2 = (void *)&hugetlb_infinity,
1223 .procname = "nr_hugepages_mempolicy",
1225 .maxlen = sizeof(unsigned long),
1227 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1228 .extra1 = (void *)&hugetlb_zero,
1229 .extra2 = (void *)&hugetlb_infinity,
1233 .procname = "hugetlb_shm_group",
1234 .data = &sysctl_hugetlb_shm_group,
1235 .maxlen = sizeof(gid_t),
1237 .proc_handler = proc_dointvec,
1240 .procname = "hugepages_treat_as_movable",
1241 .data = &hugepages_treat_as_movable,
1242 .maxlen = sizeof(int),
1244 .proc_handler = proc_dointvec,
1247 .procname = "nr_overcommit_hugepages",
1249 .maxlen = sizeof(unsigned long),
1251 .proc_handler = hugetlb_overcommit_handler,
1252 .extra1 = (void *)&hugetlb_zero,
1253 .extra2 = (void *)&hugetlb_infinity,
1257 .procname = "lowmem_reserve_ratio",
1258 .data = &sysctl_lowmem_reserve_ratio,
1259 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1261 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1264 .procname = "drop_caches",
1265 .data = &sysctl_drop_caches,
1266 .maxlen = sizeof(int),
1268 .proc_handler = drop_caches_sysctl_handler,
1272 #ifdef CONFIG_COMPACTION
1274 .procname = "compact_memory",
1275 .data = &sysctl_compact_memory,
1276 .maxlen = sizeof(int),
1278 .proc_handler = sysctl_compaction_handler,
1281 .procname = "extfrag_threshold",
1282 .data = &sysctl_extfrag_threshold,
1283 .maxlen = sizeof(int),
1285 .proc_handler = sysctl_extfrag_handler,
1286 .extra1 = &min_extfrag_threshold,
1287 .extra2 = &max_extfrag_threshold,
1290 #endif /* CONFIG_COMPACTION */
1292 .procname = "min_free_kbytes",
1293 .data = &min_free_kbytes,
1294 .maxlen = sizeof(min_free_kbytes),
1296 .proc_handler = min_free_kbytes_sysctl_handler,
1300 .procname = "percpu_pagelist_fraction",
1301 .data = &percpu_pagelist_fraction,
1302 .maxlen = sizeof(percpu_pagelist_fraction),
1304 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1305 .extra1 = &min_percpu_pagelist_fract,
1309 .procname = "max_map_count",
1310 .data = &sysctl_max_map_count,
1311 .maxlen = sizeof(sysctl_max_map_count),
1313 .proc_handler = proc_dointvec_minmax,
1318 .procname = "nr_trim_pages",
1319 .data = &sysctl_nr_trim_pages,
1320 .maxlen = sizeof(sysctl_nr_trim_pages),
1322 .proc_handler = proc_dointvec_minmax,
1327 .procname = "laptop_mode",
1328 .data = &laptop_mode,
1329 .maxlen = sizeof(laptop_mode),
1331 .proc_handler = proc_dointvec_jiffies,
1334 .procname = "block_dump",
1335 .data = &block_dump,
1336 .maxlen = sizeof(block_dump),
1338 .proc_handler = proc_dointvec,
1342 .procname = "vfs_cache_pressure",
1343 .data = &sysctl_vfs_cache_pressure,
1344 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1346 .proc_handler = proc_dointvec,
1349 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1351 .procname = "legacy_va_layout",
1352 .data = &sysctl_legacy_va_layout,
1353 .maxlen = sizeof(sysctl_legacy_va_layout),
1355 .proc_handler = proc_dointvec,
1361 .procname = "zone_reclaim_mode",
1362 .data = &zone_reclaim_mode,
1363 .maxlen = sizeof(zone_reclaim_mode),
1365 .proc_handler = proc_dointvec,
1369 .procname = "min_unmapped_ratio",
1370 .data = &sysctl_min_unmapped_ratio,
1371 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1373 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1375 .extra2 = &one_hundred,
1378 .procname = "min_slab_ratio",
1379 .data = &sysctl_min_slab_ratio,
1380 .maxlen = sizeof(sysctl_min_slab_ratio),
1382 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1384 .extra2 = &one_hundred,
1389 .procname = "stat_interval",
1390 .data = &sysctl_stat_interval,
1391 .maxlen = sizeof(sysctl_stat_interval),
1393 .proc_handler = proc_dointvec_jiffies,
1398 .procname = "mmap_min_addr",
1399 .data = &dac_mmap_min_addr,
1400 .maxlen = sizeof(unsigned long),
1402 .proc_handler = mmap_min_addr_handler,
1407 .procname = "numa_zonelist_order",
1408 .data = &numa_zonelist_order,
1409 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1411 .proc_handler = numa_zonelist_order_handler,
1414 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1415 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1417 .procname = "vdso_enabled",
1418 .data = &vdso_enabled,
1419 .maxlen = sizeof(vdso_enabled),
1421 .proc_handler = proc_dointvec,
1425 #ifdef CONFIG_HIGHMEM
1427 .procname = "highmem_is_dirtyable",
1428 .data = &vm_highmem_is_dirtyable,
1429 .maxlen = sizeof(vm_highmem_is_dirtyable),
1431 .proc_handler = proc_dointvec_minmax,
1437 .procname = "scan_unevictable_pages",
1438 .data = &scan_unevictable_pages,
1439 .maxlen = sizeof(scan_unevictable_pages),
1441 .proc_handler = scan_unevictable_handler,
1443 #ifdef CONFIG_MEMORY_FAILURE
1445 .procname = "memory_failure_early_kill",
1446 .data = &sysctl_memory_failure_early_kill,
1447 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1449 .proc_handler = proc_dointvec_minmax,
1454 .procname = "memory_failure_recovery",
1455 .data = &sysctl_memory_failure_recovery,
1456 .maxlen = sizeof(sysctl_memory_failure_recovery),
1458 .proc_handler = proc_dointvec_minmax,
1464 .procname = "user_reserve_kbytes",
1465 .data = &sysctl_user_reserve_kbytes,
1466 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1468 .proc_handler = proc_doulongvec_minmax,
1471 .procname = "admin_reserve_kbytes",
1472 .data = &sysctl_admin_reserve_kbytes,
1473 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1475 .proc_handler = proc_doulongvec_minmax,
1480 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1481 static struct ctl_table binfmt_misc_table[] = {
1486 static struct ctl_table fs_table[] = {
1488 .procname = "inode-nr",
1489 .data = &inodes_stat,
1490 .maxlen = 2*sizeof(long),
1492 .proc_handler = proc_nr_inodes,
1495 .procname = "inode-state",
1496 .data = &inodes_stat,
1497 .maxlen = 7*sizeof(long),
1499 .proc_handler = proc_nr_inodes,
1502 .procname = "file-nr",
1503 .data = &files_stat,
1504 .maxlen = sizeof(files_stat),
1506 .proc_handler = proc_nr_files,
1509 .procname = "file-max",
1510 .data = &files_stat.max_files,
1511 .maxlen = sizeof(files_stat.max_files),
1513 .proc_handler = proc_doulongvec_minmax,
1516 .procname = "nr_open",
1517 .data = &sysctl_nr_open,
1518 .maxlen = sizeof(int),
1520 .proc_handler = proc_dointvec_minmax,
1521 .extra1 = &sysctl_nr_open_min,
1522 .extra2 = &sysctl_nr_open_max,
1525 .procname = "dentry-state",
1526 .data = &dentry_stat,
1527 .maxlen = 6*sizeof(long),
1529 .proc_handler = proc_nr_dentry,
1532 .procname = "overflowuid",
1533 .data = &fs_overflowuid,
1534 .maxlen = sizeof(int),
1536 .proc_handler = proc_dointvec_minmax,
1537 .extra1 = &minolduid,
1538 .extra2 = &maxolduid,
1541 .procname = "overflowgid",
1542 .data = &fs_overflowgid,
1543 .maxlen = sizeof(int),
1545 .proc_handler = proc_dointvec_minmax,
1546 .extra1 = &minolduid,
1547 .extra2 = &maxolduid,
1549 #ifdef CONFIG_FILE_LOCKING
1551 .procname = "leases-enable",
1552 .data = &leases_enable,
1553 .maxlen = sizeof(int),
1555 .proc_handler = proc_dointvec,
1558 #ifdef CONFIG_DNOTIFY
1560 .procname = "dir-notify-enable",
1561 .data = &dir_notify_enable,
1562 .maxlen = sizeof(int),
1564 .proc_handler = proc_dointvec,
1568 #ifdef CONFIG_FILE_LOCKING
1570 .procname = "lease-break-time",
1571 .data = &lease_break_time,
1572 .maxlen = sizeof(int),
1574 .proc_handler = proc_dointvec,
1579 .procname = "aio-nr",
1581 .maxlen = sizeof(aio_nr),
1583 .proc_handler = proc_doulongvec_minmax,
1586 .procname = "aio-max-nr",
1587 .data = &aio_max_nr,
1588 .maxlen = sizeof(aio_max_nr),
1590 .proc_handler = proc_doulongvec_minmax,
1592 #endif /* CONFIG_AIO */
1593 #ifdef CONFIG_INOTIFY_USER
1595 .procname = "inotify",
1597 .child = inotify_table,
1602 .procname = "epoll",
1604 .child = epoll_table,
1609 .procname = "protected_symlinks",
1610 .data = &sysctl_protected_symlinks,
1611 .maxlen = sizeof(int),
1613 .proc_handler = proc_dointvec_minmax,
1618 .procname = "protected_hardlinks",
1619 .data = &sysctl_protected_hardlinks,
1620 .maxlen = sizeof(int),
1622 .proc_handler = proc_dointvec_minmax,
1627 .procname = "suid_dumpable",
1628 .data = &suid_dumpable,
1629 .maxlen = sizeof(int),
1631 .proc_handler = proc_dointvec_minmax_coredump,
1635 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1637 .procname = "binfmt_misc",
1639 .child = binfmt_misc_table,
1643 .procname = "pipe-max-size",
1644 .data = &pipe_max_size,
1645 .maxlen = sizeof(int),
1647 .proc_handler = &pipe_proc_fn,
1648 .extra1 = &pipe_min_size,
1653 static struct ctl_table debug_table[] = {
1654 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1656 .procname = "exception-trace",
1657 .data = &show_unhandled_signals,
1658 .maxlen = sizeof(int),
1660 .proc_handler = proc_dointvec
1663 #if defined(CONFIG_OPTPROBES)
1665 .procname = "kprobes-optimization",
1666 .data = &sysctl_kprobes_optimization,
1667 .maxlen = sizeof(int),
1669 .proc_handler = proc_kprobes_optimization_handler,
1677 static struct ctl_table dev_table[] = {
1681 int __init sysctl_init(void)
1683 struct ctl_table_header *hdr;
1685 hdr = register_sysctl_table(sysctl_base_table);
1686 kmemleak_not_leak(hdr);
1690 #endif /* CONFIG_SYSCTL */
1696 #ifdef CONFIG_PROC_SYSCTL
1698 static int _proc_do_string(void* data, int maxlen, int write,
1699 void __user *buffer,
1700 size_t *lenp, loff_t *ppos)
1706 if (!data || !maxlen || !*lenp) {
1714 while (len < *lenp) {
1715 if (get_user(c, p++))
1717 if (c == 0 || c == '\n')
1723 if(copy_from_user(data, buffer, len))
1725 ((char *) data)[len] = 0;
1743 if(copy_to_user(buffer, data, len))
1746 if(put_user('\n', ((char __user *) buffer) + len))
1757 * proc_dostring - read a string sysctl
1758 * @table: the sysctl table
1759 * @write: %TRUE if this is a write to the sysctl file
1760 * @buffer: the user buffer
1761 * @lenp: the size of the user buffer
1762 * @ppos: file position
1764 * Reads/writes a string from/to the user buffer. If the kernel
1765 * buffer provided is not large enough to hold the string, the
1766 * string is truncated. The copied string is %NULL-terminated.
1767 * If the string is being read by the user process, it is copied
1768 * and a newline '\n' is added. It is truncated if the buffer is
1771 * Returns 0 on success.
1773 int proc_dostring(struct ctl_table *table, int write,
1774 void __user *buffer, size_t *lenp, loff_t *ppos)
1776 return _proc_do_string(table->data, table->maxlen, write,
1777 buffer, lenp, ppos);
1780 static size_t proc_skip_spaces(char **buf)
1783 char *tmp = skip_spaces(*buf);
1789 static void proc_skip_char(char **buf, size_t *size, const char v)
1799 #define TMPBUFLEN 22
1801 * proc_get_long - reads an ASCII formatted integer from a user buffer
1803 * @buf: a kernel buffer
1804 * @size: size of the kernel buffer
1805 * @val: this is where the number will be stored
1806 * @neg: set to %TRUE if number is negative
1807 * @perm_tr: a vector which contains the allowed trailers
1808 * @perm_tr_len: size of the perm_tr vector
1809 * @tr: pointer to store the trailer character
1811 * In case of success %0 is returned and @buf and @size are updated with
1812 * the amount of bytes read. If @tr is non-NULL and a trailing
1813 * character exists (size is non-zero after returning from this
1814 * function), @tr is updated with the trailing character.
1816 static int proc_get_long(char **buf, size_t *size,
1817 unsigned long *val, bool *neg,
1818 const char *perm_tr, unsigned perm_tr_len, char *tr)
1821 char *p, tmp[TMPBUFLEN];
1827 if (len > TMPBUFLEN - 1)
1828 len = TMPBUFLEN - 1;
1830 memcpy(tmp, *buf, len);
1834 if (*p == '-' && *size > 1) {
1842 *val = simple_strtoul(p, &p, 0);
1846 /* We don't know if the next char is whitespace thus we may accept
1847 * invalid integers (e.g. 1234...a) or two integers instead of one
1848 * (e.g. 123...1). So lets not allow such large numbers. */
1849 if (len == TMPBUFLEN - 1)
1852 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1855 if (tr && (len < *size))
1865 * proc_put_long - converts an integer to a decimal ASCII formatted string
1867 * @buf: the user buffer
1868 * @size: the size of the user buffer
1869 * @val: the integer to be converted
1870 * @neg: sign of the number, %TRUE for negative
1872 * In case of success %0 is returned and @buf and @size are updated with
1873 * the amount of bytes written.
1875 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1879 char tmp[TMPBUFLEN], *p = tmp;
1881 sprintf(p, "%s%lu", neg ? "-" : "", val);
1885 if (copy_to_user(*buf, tmp, len))
1893 static int proc_put_char(void __user **buf, size_t *size, char c)
1896 char __user **buffer = (char __user **)buf;
1897 if (put_user(c, *buffer))
1899 (*size)--, (*buffer)++;
1905 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1907 int write, void *data)
1910 *valp = *negp ? -*lvalp : *lvalp;
1915 *lvalp = (unsigned long)-val;
1918 *lvalp = (unsigned long)val;
1924 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1926 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1927 int write, void __user *buffer,
1928 size_t *lenp, loff_t *ppos,
1929 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1930 int write, void *data),
1933 int *i, vleft, first = 1, err = 0;
1934 unsigned long page = 0;
1938 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1943 i = (int *) tbl_data;
1944 vleft = table->maxlen / sizeof(*i);
1948 conv = do_proc_dointvec_conv;
1951 if (left > PAGE_SIZE - 1)
1952 left = PAGE_SIZE - 1;
1953 page = __get_free_page(GFP_TEMPORARY);
1954 kbuf = (char *) page;
1957 if (copy_from_user(kbuf, buffer, left)) {
1964 for (; left && vleft--; i++, first=0) {
1969 left -= proc_skip_spaces(&kbuf);
1973 err = proc_get_long(&kbuf, &left, &lval, &neg,
1975 sizeof(proc_wspace_sep), NULL);
1978 if (conv(&neg, &lval, i, 1, data)) {
1983 if (conv(&neg, &lval, i, 0, data)) {
1988 err = proc_put_char(&buffer, &left, '\t');
1991 err = proc_put_long(&buffer, &left, lval, neg);
1997 if (!write && !first && left && !err)
1998 err = proc_put_char(&buffer, &left, '\n');
1999 if (write && !err && left)
2000 left -= proc_skip_spaces(&kbuf);
2005 return err ? : -EINVAL;
2012 static int do_proc_dointvec(struct ctl_table *table, int write,
2013 void __user *buffer, size_t *lenp, loff_t *ppos,
2014 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2015 int write, void *data),
2018 return __do_proc_dointvec(table->data, table, write,
2019 buffer, lenp, ppos, conv, data);
2023 * proc_dointvec - read a vector of integers
2024 * @table: the sysctl table
2025 * @write: %TRUE if this is a write to the sysctl file
2026 * @buffer: the user buffer
2027 * @lenp: the size of the user buffer
2028 * @ppos: file position
2030 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2031 * values from/to the user buffer, treated as an ASCII string.
2033 * Returns 0 on success.
2035 int proc_dointvec(struct ctl_table *table, int write,
2036 void __user *buffer, size_t *lenp, loff_t *ppos)
2038 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2043 * Taint values can only be increased
2044 * This means we can safely use a temporary.
2046 static int proc_taint(struct ctl_table *table, int write,
2047 void __user *buffer, size_t *lenp, loff_t *ppos)
2050 unsigned long tmptaint = get_taint();
2053 if (write && !capable(CAP_SYS_ADMIN))
2058 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2064 * Poor man's atomic or. Not worth adding a primitive
2065 * to everyone's atomic.h for this
2068 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2069 if ((tmptaint >> i) & 1)
2070 add_taint(i, LOCKDEP_STILL_OK);
2077 #ifdef CONFIG_PRINTK
2078 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2079 void __user *buffer, size_t *lenp, loff_t *ppos)
2081 if (write && !capable(CAP_SYS_ADMIN))
2084 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2088 struct do_proc_dointvec_minmax_conv_param {
2093 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2095 int write, void *data)
2097 struct do_proc_dointvec_minmax_conv_param *param = data;
2099 int val = *negp ? -*lvalp : *lvalp;
2100 if ((param->min && *param->min > val) ||
2101 (param->max && *param->max < val))
2108 *lvalp = (unsigned long)-val;
2111 *lvalp = (unsigned long)val;
2118 * proc_dointvec_minmax - read a vector of integers with min/max values
2119 * @table: the sysctl table
2120 * @write: %TRUE if this is a write to the sysctl file
2121 * @buffer: the user buffer
2122 * @lenp: the size of the user buffer
2123 * @ppos: file position
2125 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2126 * values from/to the user buffer, treated as an ASCII string.
2128 * This routine will ensure the values are within the range specified by
2129 * table->extra1 (min) and table->extra2 (max).
2131 * Returns 0 on success.
2133 int proc_dointvec_minmax(struct ctl_table *table, int write,
2134 void __user *buffer, size_t *lenp, loff_t *ppos)
2136 struct do_proc_dointvec_minmax_conv_param param = {
2137 .min = (int *) table->extra1,
2138 .max = (int *) table->extra2,
2140 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2141 do_proc_dointvec_minmax_conv, ¶m);
2144 static void validate_coredump_safety(void)
2146 #ifdef CONFIG_COREDUMP
2147 if (suid_dumpable == SUID_DUMP_ROOT &&
2148 core_pattern[0] != '/' && core_pattern[0] != '|') {
2149 printk(KERN_WARNING "Unsafe core_pattern used with "\
2150 "suid_dumpable=2. Pipe handler or fully qualified "\
2151 "core dump path required.\n");
2156 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2157 void __user *buffer, size_t *lenp, loff_t *ppos)
2159 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2161 validate_coredump_safety();
2165 #ifdef CONFIG_COREDUMP
2166 static int proc_dostring_coredump(struct ctl_table *table, int write,
2167 void __user *buffer, size_t *lenp, loff_t *ppos)
2169 int error = proc_dostring(table, write, buffer, lenp, ppos);
2171 validate_coredump_safety();
2176 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2177 void __user *buffer,
2178 size_t *lenp, loff_t *ppos,
2179 unsigned long convmul,
2180 unsigned long convdiv)
2182 unsigned long *i, *min, *max;
2183 int vleft, first = 1, err = 0;
2184 unsigned long page = 0;
2188 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2193 i = (unsigned long *) data;
2194 min = (unsigned long *) table->extra1;
2195 max = (unsigned long *) table->extra2;
2196 vleft = table->maxlen / sizeof(unsigned long);
2200 if (left > PAGE_SIZE - 1)
2201 left = PAGE_SIZE - 1;
2202 page = __get_free_page(GFP_TEMPORARY);
2203 kbuf = (char *) page;
2206 if (copy_from_user(kbuf, buffer, left)) {
2213 for (; left && vleft--; i++, first = 0) {
2219 left -= proc_skip_spaces(&kbuf);
2221 err = proc_get_long(&kbuf, &left, &val, &neg,
2223 sizeof(proc_wspace_sep), NULL);
2228 if ((min && val < *min) || (max && val > *max))
2232 val = convdiv * (*i) / convmul;
2234 err = proc_put_char(&buffer, &left, '\t');
2238 err = proc_put_long(&buffer, &left, val, false);
2244 if (!write && !first && left && !err)
2245 err = proc_put_char(&buffer, &left, '\n');
2247 left -= proc_skip_spaces(&kbuf);
2252 return err ? : -EINVAL;
2259 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2260 void __user *buffer,
2261 size_t *lenp, loff_t *ppos,
2262 unsigned long convmul,
2263 unsigned long convdiv)
2265 return __do_proc_doulongvec_minmax(table->data, table, write,
2266 buffer, lenp, ppos, convmul, convdiv);
2270 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2271 * @table: the sysctl table
2272 * @write: %TRUE if this is a write to the sysctl file
2273 * @buffer: the user buffer
2274 * @lenp: the size of the user buffer
2275 * @ppos: file position
2277 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2278 * values from/to the user buffer, treated as an ASCII string.
2280 * This routine will ensure the values are within the range specified by
2281 * table->extra1 (min) and table->extra2 (max).
2283 * Returns 0 on success.
2285 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2286 void __user *buffer, size_t *lenp, loff_t *ppos)
2288 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2292 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2293 * @table: the sysctl table
2294 * @write: %TRUE if this is a write to the sysctl file
2295 * @buffer: the user buffer
2296 * @lenp: the size of the user buffer
2297 * @ppos: file position
2299 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2300 * values from/to the user buffer, treated as an ASCII string. The values
2301 * are treated as milliseconds, and converted to jiffies when they are stored.
2303 * This routine will ensure the values are within the range specified by
2304 * table->extra1 (min) and table->extra2 (max).
2306 * Returns 0 on success.
2308 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2309 void __user *buffer,
2310 size_t *lenp, loff_t *ppos)
2312 return do_proc_doulongvec_minmax(table, write, buffer,
2313 lenp, ppos, HZ, 1000l);
2317 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2319 int write, void *data)
2322 if (*lvalp > LONG_MAX / HZ)
2324 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2330 lval = (unsigned long)-val;
2333 lval = (unsigned long)val;
2340 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2342 int write, void *data)
2345 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2347 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2353 lval = (unsigned long)-val;
2356 lval = (unsigned long)val;
2358 *lvalp = jiffies_to_clock_t(lval);
2363 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2365 int write, void *data)
2368 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2378 lval = (unsigned long)-val;
2381 lval = (unsigned long)val;
2383 *lvalp = jiffies_to_msecs(lval);
2389 * proc_dointvec_jiffies - read a vector of integers as seconds
2390 * @table: the sysctl table
2391 * @write: %TRUE if this is a write to the sysctl file
2392 * @buffer: the user buffer
2393 * @lenp: the size of the user buffer
2394 * @ppos: file position
2396 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2397 * values from/to the user buffer, treated as an ASCII string.
2398 * The values read are assumed to be in seconds, and are converted into
2401 * Returns 0 on success.
2403 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2404 void __user *buffer, size_t *lenp, loff_t *ppos)
2406 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2407 do_proc_dointvec_jiffies_conv,NULL);
2411 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2412 * @table: the sysctl table
2413 * @write: %TRUE if this is a write to the sysctl file
2414 * @buffer: the user buffer
2415 * @lenp: the size of the user buffer
2416 * @ppos: pointer to the file position
2418 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2419 * values from/to the user buffer, treated as an ASCII string.
2420 * The values read are assumed to be in 1/USER_HZ seconds, and
2421 * are converted into jiffies.
2423 * Returns 0 on success.
2425 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2426 void __user *buffer, size_t *lenp, loff_t *ppos)
2428 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2429 do_proc_dointvec_userhz_jiffies_conv,NULL);
2433 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2434 * @table: the sysctl table
2435 * @write: %TRUE if this is a write to the sysctl file
2436 * @buffer: the user buffer
2437 * @lenp: the size of the user buffer
2438 * @ppos: file position
2439 * @ppos: the current position in the file
2441 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2442 * values from/to the user buffer, treated as an ASCII string.
2443 * The values read are assumed to be in 1/1000 seconds, and
2444 * are converted into jiffies.
2446 * Returns 0 on success.
2448 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2449 void __user *buffer, size_t *lenp, loff_t *ppos)
2451 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2452 do_proc_dointvec_ms_jiffies_conv, NULL);
2455 static int proc_do_cad_pid(struct ctl_table *table, int write,
2456 void __user *buffer, size_t *lenp, loff_t *ppos)
2458 struct pid *new_pid;
2462 tmp = pid_vnr(cad_pid);
2464 r = __do_proc_dointvec(&tmp, table, write, buffer,
2465 lenp, ppos, NULL, NULL);
2469 new_pid = find_get_pid(tmp);
2473 put_pid(xchg(&cad_pid, new_pid));
2478 * proc_do_large_bitmap - read/write from/to a large bitmap
2479 * @table: the sysctl table
2480 * @write: %TRUE if this is a write to the sysctl file
2481 * @buffer: the user buffer
2482 * @lenp: the size of the user buffer
2483 * @ppos: file position
2485 * The bitmap is stored at table->data and the bitmap length (in bits)
2488 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2489 * large bitmaps may be represented in a compact manner. Writing into
2490 * the file will clear the bitmap then update it with the given input.
2492 * Returns 0 on success.
2494 int proc_do_large_bitmap(struct ctl_table *table, int write,
2495 void __user *buffer, size_t *lenp, loff_t *ppos)
2499 size_t left = *lenp;
2500 unsigned long bitmap_len = table->maxlen;
2501 unsigned long *bitmap = (unsigned long *) table->data;
2502 unsigned long *tmp_bitmap = NULL;
2503 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2505 if (!bitmap_len || !left || (*ppos && !write)) {
2511 unsigned long page = 0;
2514 if (left > PAGE_SIZE - 1)
2515 left = PAGE_SIZE - 1;
2517 page = __get_free_page(GFP_TEMPORARY);
2518 kbuf = (char *) page;
2521 if (copy_from_user(kbuf, buffer, left)) {
2527 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2533 proc_skip_char(&kbuf, &left, '\n');
2534 while (!err && left) {
2535 unsigned long val_a, val_b;
2538 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2542 if (val_a >= bitmap_len || neg) {
2554 err = proc_get_long(&kbuf, &left, &val_b,
2555 &neg, tr_b, sizeof(tr_b),
2559 if (val_b >= bitmap_len || neg ||
2570 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2572 proc_skip_char(&kbuf, &left, '\n');
2576 unsigned long bit_a, bit_b = 0;
2579 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2580 if (bit_a >= bitmap_len)
2582 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2586 err = proc_put_char(&buffer, &left, ',');
2590 err = proc_put_long(&buffer, &left, bit_a, false);
2593 if (bit_a != bit_b) {
2594 err = proc_put_char(&buffer, &left, '-');
2597 err = proc_put_long(&buffer, &left, bit_b, false);
2605 err = proc_put_char(&buffer, &left, '\n');
2611 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2613 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2625 #else /* CONFIG_PROC_SYSCTL */
2627 int proc_dostring(struct ctl_table *table, int write,
2628 void __user *buffer, size_t *lenp, loff_t *ppos)
2633 int proc_dointvec(struct ctl_table *table, int write,
2634 void __user *buffer, size_t *lenp, loff_t *ppos)
2639 int proc_dointvec_minmax(struct ctl_table *table, int write,
2640 void __user *buffer, size_t *lenp, loff_t *ppos)
2645 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2646 void __user *buffer, size_t *lenp, loff_t *ppos)
2651 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2652 void __user *buffer, size_t *lenp, loff_t *ppos)
2657 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2658 void __user *buffer, size_t *lenp, loff_t *ppos)
2663 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2664 void __user *buffer, size_t *lenp, loff_t *ppos)
2669 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2670 void __user *buffer,
2671 size_t *lenp, loff_t *ppos)
2677 #endif /* CONFIG_PROC_SYSCTL */
2680 * No sense putting this after each symbol definition, twice,
2681 * exception granted :-)
2683 EXPORT_SYMBOL(proc_dointvec);
2684 EXPORT_SYMBOL(proc_dointvec_jiffies);
2685 EXPORT_SYMBOL(proc_dointvec_minmax);
2686 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2687 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2688 EXPORT_SYMBOL(proc_dostring);
2689 EXPORT_SYMBOL(proc_doulongvec_minmax);
2690 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);