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_migrate_deferred",
389 .data = &sysctl_numa_balancing_migrate_deferred,
390 .maxlen = sizeof(unsigned int),
392 .proc_handler = proc_dointvec,
394 #endif /* CONFIG_NUMA_BALANCING */
395 #endif /* CONFIG_SCHED_DEBUG */
397 .procname = "sched_rt_period_us",
398 .data = &sysctl_sched_rt_period,
399 .maxlen = sizeof(unsigned int),
401 .proc_handler = sched_rt_handler,
404 .procname = "sched_rt_runtime_us",
405 .data = &sysctl_sched_rt_runtime,
406 .maxlen = sizeof(int),
408 .proc_handler = sched_rt_handler,
411 .procname = "sched_rr_timeslice_ms",
412 .data = &sched_rr_timeslice,
413 .maxlen = sizeof(int),
415 .proc_handler = sched_rr_handler,
418 .procname = "sched_dl_period_us",
419 .data = &sysctl_sched_dl_period,
420 .maxlen = sizeof(unsigned int),
422 .proc_handler = sched_dl_handler,
425 .procname = "sched_dl_runtime_us",
426 .data = &sysctl_sched_dl_runtime,
427 .maxlen = sizeof(int),
429 .proc_handler = sched_dl_handler,
431 #ifdef CONFIG_SCHED_AUTOGROUP
433 .procname = "sched_autogroup_enabled",
434 .data = &sysctl_sched_autogroup_enabled,
435 .maxlen = sizeof(unsigned int),
437 .proc_handler = proc_dointvec_minmax,
442 #ifdef CONFIG_CFS_BANDWIDTH
444 .procname = "sched_cfs_bandwidth_slice_us",
445 .data = &sysctl_sched_cfs_bandwidth_slice,
446 .maxlen = sizeof(unsigned int),
448 .proc_handler = proc_dointvec_minmax,
452 #ifdef CONFIG_PROVE_LOCKING
454 .procname = "prove_locking",
455 .data = &prove_locking,
456 .maxlen = sizeof(int),
458 .proc_handler = proc_dointvec,
461 #ifdef CONFIG_LOCK_STAT
463 .procname = "lock_stat",
465 .maxlen = sizeof(int),
467 .proc_handler = proc_dointvec,
472 .data = &panic_timeout,
473 .maxlen = sizeof(int),
475 .proc_handler = proc_dointvec,
477 #ifdef CONFIG_COREDUMP
479 .procname = "core_uses_pid",
480 .data = &core_uses_pid,
481 .maxlen = sizeof(int),
483 .proc_handler = proc_dointvec,
486 .procname = "core_pattern",
487 .data = core_pattern,
488 .maxlen = CORENAME_MAX_SIZE,
490 .proc_handler = proc_dostring_coredump,
493 .procname = "core_pipe_limit",
494 .data = &core_pipe_limit,
495 .maxlen = sizeof(unsigned int),
497 .proc_handler = proc_dointvec,
500 #ifdef CONFIG_PROC_SYSCTL
502 .procname = "tainted",
503 .maxlen = sizeof(long),
505 .proc_handler = proc_taint,
508 #ifdef CONFIG_LATENCYTOP
510 .procname = "latencytop",
511 .data = &latencytop_enabled,
512 .maxlen = sizeof(int),
514 .proc_handler = proc_dointvec,
517 #ifdef CONFIG_BLK_DEV_INITRD
519 .procname = "real-root-dev",
520 .data = &real_root_dev,
521 .maxlen = sizeof(int),
523 .proc_handler = proc_dointvec,
527 .procname = "print-fatal-signals",
528 .data = &print_fatal_signals,
529 .maxlen = sizeof(int),
531 .proc_handler = proc_dointvec,
535 .procname = "reboot-cmd",
536 .data = reboot_command,
539 .proc_handler = proc_dostring,
542 .procname = "stop-a",
543 .data = &stop_a_enabled,
544 .maxlen = sizeof (int),
546 .proc_handler = proc_dointvec,
549 .procname = "scons-poweroff",
550 .data = &scons_pwroff,
551 .maxlen = sizeof (int),
553 .proc_handler = proc_dointvec,
556 #ifdef CONFIG_SPARC64
558 .procname = "tsb-ratio",
559 .data = &sysctl_tsb_ratio,
560 .maxlen = sizeof (int),
562 .proc_handler = proc_dointvec,
567 .procname = "soft-power",
568 .data = &pwrsw_enabled,
569 .maxlen = sizeof (int),
571 .proc_handler = proc_dointvec,
574 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
576 .procname = "unaligned-trap",
577 .data = &unaligned_enabled,
578 .maxlen = sizeof (int),
580 .proc_handler = proc_dointvec,
584 .procname = "ctrl-alt-del",
586 .maxlen = sizeof(int),
588 .proc_handler = proc_dointvec,
590 #ifdef CONFIG_FUNCTION_TRACER
592 .procname = "ftrace_enabled",
593 .data = &ftrace_enabled,
594 .maxlen = sizeof(int),
596 .proc_handler = ftrace_enable_sysctl,
599 #ifdef CONFIG_STACK_TRACER
601 .procname = "stack_tracer_enabled",
602 .data = &stack_tracer_enabled,
603 .maxlen = sizeof(int),
605 .proc_handler = stack_trace_sysctl,
608 #ifdef CONFIG_TRACING
610 .procname = "ftrace_dump_on_oops",
611 .data = &ftrace_dump_on_oops,
612 .maxlen = sizeof(int),
614 .proc_handler = proc_dointvec,
617 .procname = "traceoff_on_warning",
618 .data = &__disable_trace_on_warning,
619 .maxlen = sizeof(__disable_trace_on_warning),
621 .proc_handler = proc_dointvec,
624 #ifdef CONFIG_MODULES
626 .procname = "modprobe",
627 .data = &modprobe_path,
628 .maxlen = KMOD_PATH_LEN,
630 .proc_handler = proc_dostring,
633 .procname = "modules_disabled",
634 .data = &modules_disabled,
635 .maxlen = sizeof(int),
637 /* only handle a transition from default "0" to "1" */
638 .proc_handler = proc_dointvec_minmax,
645 .procname = "hotplug",
646 .data = &uevent_helper,
647 .maxlen = UEVENT_HELPER_PATH_LEN,
649 .proc_handler = proc_dostring,
652 #ifdef CONFIG_CHR_DEV_SG
654 .procname = "sg-big-buff",
655 .data = &sg_big_buff,
656 .maxlen = sizeof (int),
658 .proc_handler = proc_dointvec,
661 #ifdef CONFIG_BSD_PROCESS_ACCT
665 .maxlen = 3*sizeof(int),
667 .proc_handler = proc_dointvec,
670 #ifdef CONFIG_MAGIC_SYSRQ
673 .data = &__sysrq_enabled,
674 .maxlen = sizeof (int),
676 .proc_handler = sysrq_sysctl_handler,
679 #ifdef CONFIG_PROC_SYSCTL
681 .procname = "cad_pid",
683 .maxlen = sizeof (int),
685 .proc_handler = proc_do_cad_pid,
689 .procname = "threads-max",
690 .data = &max_threads,
691 .maxlen = sizeof(int),
693 .proc_handler = proc_dointvec,
696 .procname = "random",
698 .child = random_table,
701 .procname = "usermodehelper",
703 .child = usermodehelper_table,
706 .procname = "overflowuid",
707 .data = &overflowuid,
708 .maxlen = sizeof(int),
710 .proc_handler = proc_dointvec_minmax,
711 .extra1 = &minolduid,
712 .extra2 = &maxolduid,
715 .procname = "overflowgid",
716 .data = &overflowgid,
717 .maxlen = sizeof(int),
719 .proc_handler = proc_dointvec_minmax,
720 .extra1 = &minolduid,
721 .extra2 = &maxolduid,
724 #ifdef CONFIG_MATHEMU
726 .procname = "ieee_emulation_warnings",
727 .data = &sysctl_ieee_emulation_warnings,
728 .maxlen = sizeof(int),
730 .proc_handler = proc_dointvec,
734 .procname = "userprocess_debug",
735 .data = &show_unhandled_signals,
736 .maxlen = sizeof(int),
738 .proc_handler = proc_dointvec,
742 .procname = "pid_max",
744 .maxlen = sizeof (int),
746 .proc_handler = proc_dointvec_minmax,
747 .extra1 = &pid_max_min,
748 .extra2 = &pid_max_max,
751 .procname = "panic_on_oops",
752 .data = &panic_on_oops,
753 .maxlen = sizeof(int),
755 .proc_handler = proc_dointvec,
757 #if defined CONFIG_PRINTK
759 .procname = "printk",
760 .data = &console_loglevel,
761 .maxlen = 4*sizeof(int),
763 .proc_handler = proc_dointvec,
766 .procname = "printk_ratelimit",
767 .data = &printk_ratelimit_state.interval,
768 .maxlen = sizeof(int),
770 .proc_handler = proc_dointvec_jiffies,
773 .procname = "printk_ratelimit_burst",
774 .data = &printk_ratelimit_state.burst,
775 .maxlen = sizeof(int),
777 .proc_handler = proc_dointvec,
780 .procname = "printk_delay",
781 .data = &printk_delay_msec,
782 .maxlen = sizeof(int),
784 .proc_handler = proc_dointvec_minmax,
786 .extra2 = &ten_thousand,
789 .procname = "dmesg_restrict",
790 .data = &dmesg_restrict,
791 .maxlen = sizeof(int),
793 .proc_handler = proc_dointvec_minmax_sysadmin,
798 .procname = "kptr_restrict",
799 .data = &kptr_restrict,
800 .maxlen = sizeof(int),
802 .proc_handler = proc_dointvec_minmax_sysadmin,
808 .procname = "ngroups_max",
809 .data = &ngroups_max,
810 .maxlen = sizeof (int),
812 .proc_handler = proc_dointvec,
815 .procname = "cap_last_cap",
816 .data = (void *)&cap_last_cap,
817 .maxlen = sizeof(int),
819 .proc_handler = proc_dointvec,
821 #if defined(CONFIG_LOCKUP_DETECTOR)
823 .procname = "watchdog",
824 .data = &watchdog_user_enabled,
825 .maxlen = sizeof (int),
827 .proc_handler = proc_dowatchdog,
832 .procname = "watchdog_thresh",
833 .data = &watchdog_thresh,
834 .maxlen = sizeof(int),
836 .proc_handler = proc_dowatchdog,
841 .procname = "softlockup_panic",
842 .data = &softlockup_panic,
843 .maxlen = sizeof(int),
845 .proc_handler = proc_dointvec_minmax,
850 .procname = "nmi_watchdog",
851 .data = &watchdog_user_enabled,
852 .maxlen = sizeof (int),
854 .proc_handler = proc_dowatchdog,
859 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
861 .procname = "unknown_nmi_panic",
862 .data = &unknown_nmi_panic,
863 .maxlen = sizeof (int),
865 .proc_handler = proc_dointvec,
868 #if defined(CONFIG_X86)
870 .procname = "panic_on_unrecovered_nmi",
871 .data = &panic_on_unrecovered_nmi,
872 .maxlen = sizeof(int),
874 .proc_handler = proc_dointvec,
877 .procname = "panic_on_io_nmi",
878 .data = &panic_on_io_nmi,
879 .maxlen = sizeof(int),
881 .proc_handler = proc_dointvec,
883 #ifdef CONFIG_DEBUG_STACKOVERFLOW
885 .procname = "panic_on_stackoverflow",
886 .data = &sysctl_panic_on_stackoverflow,
887 .maxlen = sizeof(int),
889 .proc_handler = proc_dointvec,
893 .procname = "bootloader_type",
894 .data = &bootloader_type,
895 .maxlen = sizeof (int),
897 .proc_handler = proc_dointvec,
900 .procname = "bootloader_version",
901 .data = &bootloader_version,
902 .maxlen = sizeof (int),
904 .proc_handler = proc_dointvec,
907 .procname = "kstack_depth_to_print",
908 .data = &kstack_depth_to_print,
909 .maxlen = sizeof(int),
911 .proc_handler = proc_dointvec,
914 .procname = "io_delay_type",
915 .data = &io_delay_type,
916 .maxlen = sizeof(int),
918 .proc_handler = proc_dointvec,
921 #if defined(CONFIG_MMU)
923 .procname = "randomize_va_space",
924 .data = &randomize_va_space,
925 .maxlen = sizeof(int),
927 .proc_handler = proc_dointvec,
930 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
932 .procname = "spin_retry",
934 .maxlen = sizeof (int),
936 .proc_handler = proc_dointvec,
939 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
941 .procname = "acpi_video_flags",
942 .data = &acpi_realmode_flags,
943 .maxlen = sizeof (unsigned long),
945 .proc_handler = proc_doulongvec_minmax,
948 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
950 .procname = "ignore-unaligned-usertrap",
951 .data = &no_unaligned_warning,
952 .maxlen = sizeof (int),
954 .proc_handler = proc_dointvec,
959 .procname = "unaligned-dump-stack",
960 .data = &unaligned_dump_stack,
961 .maxlen = sizeof (int),
963 .proc_handler = proc_dointvec,
966 #ifdef CONFIG_DETECT_HUNG_TASK
968 .procname = "hung_task_panic",
969 .data = &sysctl_hung_task_panic,
970 .maxlen = sizeof(int),
972 .proc_handler = proc_dointvec_minmax,
977 .procname = "hung_task_check_count",
978 .data = &sysctl_hung_task_check_count,
979 .maxlen = sizeof(int),
981 .proc_handler = proc_dointvec_minmax,
985 .procname = "hung_task_timeout_secs",
986 .data = &sysctl_hung_task_timeout_secs,
987 .maxlen = sizeof(unsigned long),
989 .proc_handler = proc_dohung_task_timeout_secs,
992 .procname = "hung_task_warnings",
993 .data = &sysctl_hung_task_warnings,
994 .maxlen = sizeof(unsigned long),
996 .proc_handler = proc_doulongvec_minmax,
1001 .procname = "compat-log",
1002 .data = &compat_log,
1003 .maxlen = sizeof (int),
1005 .proc_handler = proc_dointvec,
1008 #ifdef CONFIG_RT_MUTEXES
1010 .procname = "max_lock_depth",
1011 .data = &max_lock_depth,
1012 .maxlen = sizeof(int),
1014 .proc_handler = proc_dointvec,
1018 .procname = "poweroff_cmd",
1019 .data = &poweroff_cmd,
1020 .maxlen = POWEROFF_CMD_PATH_LEN,
1022 .proc_handler = proc_dostring,
1028 .child = key_sysctls,
1031 #ifdef CONFIG_RCU_TORTURE_TEST
1033 .procname = "rcutorture_runnable",
1034 .data = &rcutorture_runnable,
1035 .maxlen = sizeof(int),
1037 .proc_handler = proc_dointvec,
1040 #ifdef CONFIG_PERF_EVENTS
1042 * User-space scripts rely on the existence of this file
1043 * as a feature check for perf_events being enabled.
1045 * So it's an ABI, do not remove!
1048 .procname = "perf_event_paranoid",
1049 .data = &sysctl_perf_event_paranoid,
1050 .maxlen = sizeof(sysctl_perf_event_paranoid),
1052 .proc_handler = proc_dointvec,
1055 .procname = "perf_event_mlock_kb",
1056 .data = &sysctl_perf_event_mlock,
1057 .maxlen = sizeof(sysctl_perf_event_mlock),
1059 .proc_handler = proc_dointvec,
1062 .procname = "perf_event_max_sample_rate",
1063 .data = &sysctl_perf_event_sample_rate,
1064 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1066 .proc_handler = perf_proc_update_handler,
1070 .procname = "perf_cpu_time_max_percent",
1071 .data = &sysctl_perf_cpu_time_max_percent,
1072 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1074 .proc_handler = perf_cpu_time_max_percent_handler,
1076 .extra2 = &one_hundred,
1079 #ifdef CONFIG_KMEMCHECK
1081 .procname = "kmemcheck",
1082 .data = &kmemcheck_enabled,
1083 .maxlen = sizeof(int),
1085 .proc_handler = proc_dointvec,
1090 .procname = "blk_iopoll",
1091 .data = &blk_iopoll_enabled,
1092 .maxlen = sizeof(int),
1094 .proc_handler = proc_dointvec,
1100 static struct ctl_table vm_table[] = {
1102 .procname = "overcommit_memory",
1103 .data = &sysctl_overcommit_memory,
1104 .maxlen = sizeof(sysctl_overcommit_memory),
1106 .proc_handler = proc_dointvec_minmax,
1111 .procname = "panic_on_oom",
1112 .data = &sysctl_panic_on_oom,
1113 .maxlen = sizeof(sysctl_panic_on_oom),
1115 .proc_handler = proc_dointvec_minmax,
1120 .procname = "oom_kill_allocating_task",
1121 .data = &sysctl_oom_kill_allocating_task,
1122 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1124 .proc_handler = proc_dointvec,
1127 .procname = "oom_dump_tasks",
1128 .data = &sysctl_oom_dump_tasks,
1129 .maxlen = sizeof(sysctl_oom_dump_tasks),
1131 .proc_handler = proc_dointvec,
1134 .procname = "overcommit_ratio",
1135 .data = &sysctl_overcommit_ratio,
1136 .maxlen = sizeof(sysctl_overcommit_ratio),
1138 .proc_handler = proc_dointvec,
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);