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 sysctl_drop_caches;
110 extern int percpu_pagelist_fraction;
111 extern int compat_log;
112 extern int latencytop_enabled;
113 extern int sysctl_nr_open_min, sysctl_nr_open_max;
115 extern int sysctl_nr_trim_pages;
118 extern int blk_iopoll_enabled;
121 /* Constants used for minimum and maximum */
122 #ifdef CONFIG_LOCKUP_DETECTOR
123 static int sixty = 60;
124 static int neg_one = -1;
128 static int __maybe_unused one = 1;
129 static int __maybe_unused two = 2;
130 static int __maybe_unused three = 3;
131 static unsigned long one_ul = 1;
132 static int one_hundred = 100;
134 static int ten_thousand = 10000;
137 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141 static int maxolduid = 65535;
142 static int minolduid;
143 static int min_percpu_pagelist_fract = 8;
145 static int ngroups_max = NGROUPS_MAX;
146 static const int cap_last_cap = CAP_LAST_CAP;
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
154 #ifdef CONFIG_SPARC64
155 extern int sysctl_tsb_ratio;
159 extern int pwrsw_enabled;
160 extern int unaligned_enabled;
164 extern int unaligned_dump_stack;
167 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168 extern int no_unaligned_warning;
171 #ifdef CONFIG_PROC_SYSCTL
172 static int proc_do_cad_pid(struct ctl_table *table, int write,
173 void __user *buffer, size_t *lenp, loff_t *ppos);
174 static int proc_taint(struct ctl_table *table, int write,
175 void __user *buffer, size_t *lenp, loff_t *ppos);
179 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
180 void __user *buffer, size_t *lenp, loff_t *ppos);
183 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
185 #ifdef CONFIG_COREDUMP
186 static int proc_dostring_coredump(struct ctl_table *table, int write,
187 void __user *buffer, size_t *lenp, loff_t *ppos);
190 #ifdef CONFIG_MAGIC_SYSRQ
191 /* Note: sysrq code uses it's own private copy */
192 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
194 static int sysrq_sysctl_handler(ctl_table *table, int write,
195 void __user *buffer, size_t *lenp,
200 error = proc_dointvec(table, write, buffer, lenp, ppos);
205 sysrq_toggle_support(__sysrq_enabled);
212 static struct ctl_table kern_table[];
213 static struct ctl_table vm_table[];
214 static struct ctl_table fs_table[];
215 static struct ctl_table debug_table[];
216 static struct ctl_table dev_table[];
217 extern struct ctl_table random_table[];
219 extern struct ctl_table epoll_table[];
222 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
223 int sysctl_legacy_va_layout;
226 /* The default sysctl tables: */
228 static struct ctl_table sysctl_base_table[] = {
230 .procname = "kernel",
247 .child = debug_table,
257 #ifdef CONFIG_SCHED_DEBUG
258 static int min_sched_granularity_ns = 100000; /* 100 usecs */
259 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
260 static int min_wakeup_granularity_ns; /* 0 usecs */
261 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
263 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
264 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
265 #endif /* CONFIG_SMP */
266 #endif /* CONFIG_SCHED_DEBUG */
268 #ifdef CONFIG_COMPACTION
269 static int min_extfrag_threshold;
270 static int max_extfrag_threshold = 1000;
273 static struct ctl_table kern_table[] = {
275 .procname = "sched_child_runs_first",
276 .data = &sysctl_sched_child_runs_first,
277 .maxlen = sizeof(unsigned int),
279 .proc_handler = proc_dointvec,
281 #ifdef CONFIG_SCHED_DEBUG
283 .procname = "sched_min_granularity_ns",
284 .data = &sysctl_sched_min_granularity,
285 .maxlen = sizeof(unsigned int),
287 .proc_handler = sched_proc_update_handler,
288 .extra1 = &min_sched_granularity_ns,
289 .extra2 = &max_sched_granularity_ns,
292 .procname = "sched_latency_ns",
293 .data = &sysctl_sched_latency,
294 .maxlen = sizeof(unsigned int),
296 .proc_handler = sched_proc_update_handler,
297 .extra1 = &min_sched_granularity_ns,
298 .extra2 = &max_sched_granularity_ns,
301 .procname = "sched_wakeup_granularity_ns",
302 .data = &sysctl_sched_wakeup_granularity,
303 .maxlen = sizeof(unsigned int),
305 .proc_handler = sched_proc_update_handler,
306 .extra1 = &min_wakeup_granularity_ns,
307 .extra2 = &max_wakeup_granularity_ns,
311 .procname = "sched_tunable_scaling",
312 .data = &sysctl_sched_tunable_scaling,
313 .maxlen = sizeof(enum sched_tunable_scaling),
315 .proc_handler = sched_proc_update_handler,
316 .extra1 = &min_sched_tunable_scaling,
317 .extra2 = &max_sched_tunable_scaling,
320 .procname = "sched_migration_cost_ns",
321 .data = &sysctl_sched_migration_cost,
322 .maxlen = sizeof(unsigned int),
324 .proc_handler = proc_dointvec,
327 .procname = "sched_nr_migrate",
328 .data = &sysctl_sched_nr_migrate,
329 .maxlen = sizeof(unsigned int),
331 .proc_handler = proc_dointvec,
334 .procname = "sched_time_avg_ms",
335 .data = &sysctl_sched_time_avg,
336 .maxlen = sizeof(unsigned int),
338 .proc_handler = proc_dointvec,
341 .procname = "sched_shares_window_ns",
342 .data = &sysctl_sched_shares_window,
343 .maxlen = sizeof(unsigned int),
345 .proc_handler = proc_dointvec,
348 .procname = "timer_migration",
349 .data = &sysctl_timer_migration,
350 .maxlen = sizeof(unsigned int),
352 .proc_handler = proc_dointvec_minmax,
356 #endif /* CONFIG_SMP */
357 #ifdef CONFIG_NUMA_BALANCING
359 .procname = "numa_balancing_scan_delay_ms",
360 .data = &sysctl_numa_balancing_scan_delay,
361 .maxlen = sizeof(unsigned int),
363 .proc_handler = proc_dointvec,
366 .procname = "numa_balancing_scan_period_min_ms",
367 .data = &sysctl_numa_balancing_scan_period_min,
368 .maxlen = sizeof(unsigned int),
370 .proc_handler = proc_dointvec,
373 .procname = "numa_balancing_scan_period_reset",
374 .data = &sysctl_numa_balancing_scan_period_reset,
375 .maxlen = sizeof(unsigned int),
377 .proc_handler = proc_dointvec,
380 .procname = "numa_balancing_scan_period_max_ms",
381 .data = &sysctl_numa_balancing_scan_period_max,
382 .maxlen = sizeof(unsigned int),
384 .proc_handler = proc_dointvec,
387 .procname = "numa_balancing_scan_size_mb",
388 .data = &sysctl_numa_balancing_scan_size,
389 .maxlen = sizeof(unsigned int),
391 .proc_handler = proc_dointvec,
393 #endif /* CONFIG_NUMA_BALANCING */
394 #endif /* CONFIG_SCHED_DEBUG */
396 .procname = "sched_rt_period_us",
397 .data = &sysctl_sched_rt_period,
398 .maxlen = sizeof(unsigned int),
400 .proc_handler = sched_rt_handler,
403 .procname = "sched_rt_runtime_us",
404 .data = &sysctl_sched_rt_runtime,
405 .maxlen = sizeof(int),
407 .proc_handler = sched_rt_handler,
410 .procname = "sched_rr_timeslice_ms",
411 .data = &sched_rr_timeslice,
412 .maxlen = sizeof(int),
414 .proc_handler = sched_rr_handler,
416 #ifdef CONFIG_SCHED_AUTOGROUP
418 .procname = "sched_autogroup_enabled",
419 .data = &sysctl_sched_autogroup_enabled,
420 .maxlen = sizeof(unsigned int),
422 .proc_handler = proc_dointvec_minmax,
427 #ifdef CONFIG_CFS_BANDWIDTH
429 .procname = "sched_cfs_bandwidth_slice_us",
430 .data = &sysctl_sched_cfs_bandwidth_slice,
431 .maxlen = sizeof(unsigned int),
433 .proc_handler = proc_dointvec_minmax,
437 #ifdef CONFIG_PROVE_LOCKING
439 .procname = "prove_locking",
440 .data = &prove_locking,
441 .maxlen = sizeof(int),
443 .proc_handler = proc_dointvec,
446 #ifdef CONFIG_LOCK_STAT
448 .procname = "lock_stat",
450 .maxlen = sizeof(int),
452 .proc_handler = proc_dointvec,
457 .data = &panic_timeout,
458 .maxlen = sizeof(int),
460 .proc_handler = proc_dointvec,
462 #ifdef CONFIG_COREDUMP
464 .procname = "core_uses_pid",
465 .data = &core_uses_pid,
466 .maxlen = sizeof(int),
468 .proc_handler = proc_dointvec,
471 .procname = "core_pattern",
472 .data = core_pattern,
473 .maxlen = CORENAME_MAX_SIZE,
475 .proc_handler = proc_dostring_coredump,
478 .procname = "core_pipe_limit",
479 .data = &core_pipe_limit,
480 .maxlen = sizeof(unsigned int),
482 .proc_handler = proc_dointvec,
485 #ifdef CONFIG_PROC_SYSCTL
487 .procname = "tainted",
488 .maxlen = sizeof(long),
490 .proc_handler = proc_taint,
493 #ifdef CONFIG_LATENCYTOP
495 .procname = "latencytop",
496 .data = &latencytop_enabled,
497 .maxlen = sizeof(int),
499 .proc_handler = proc_dointvec,
502 #ifdef CONFIG_BLK_DEV_INITRD
504 .procname = "real-root-dev",
505 .data = &real_root_dev,
506 .maxlen = sizeof(int),
508 .proc_handler = proc_dointvec,
512 .procname = "print-fatal-signals",
513 .data = &print_fatal_signals,
514 .maxlen = sizeof(int),
516 .proc_handler = proc_dointvec,
520 .procname = "reboot-cmd",
521 .data = reboot_command,
524 .proc_handler = proc_dostring,
527 .procname = "stop-a",
528 .data = &stop_a_enabled,
529 .maxlen = sizeof (int),
531 .proc_handler = proc_dointvec,
534 .procname = "scons-poweroff",
535 .data = &scons_pwroff,
536 .maxlen = sizeof (int),
538 .proc_handler = proc_dointvec,
541 #ifdef CONFIG_SPARC64
543 .procname = "tsb-ratio",
544 .data = &sysctl_tsb_ratio,
545 .maxlen = sizeof (int),
547 .proc_handler = proc_dointvec,
552 .procname = "soft-power",
553 .data = &pwrsw_enabled,
554 .maxlen = sizeof (int),
556 .proc_handler = proc_dointvec,
559 .procname = "unaligned-trap",
560 .data = &unaligned_enabled,
561 .maxlen = sizeof (int),
563 .proc_handler = proc_dointvec,
567 .procname = "ctrl-alt-del",
569 .maxlen = sizeof(int),
571 .proc_handler = proc_dointvec,
573 #ifdef CONFIG_FUNCTION_TRACER
575 .procname = "ftrace_enabled",
576 .data = &ftrace_enabled,
577 .maxlen = sizeof(int),
579 .proc_handler = ftrace_enable_sysctl,
582 #ifdef CONFIG_STACK_TRACER
584 .procname = "stack_tracer_enabled",
585 .data = &stack_tracer_enabled,
586 .maxlen = sizeof(int),
588 .proc_handler = stack_trace_sysctl,
591 #ifdef CONFIG_TRACING
593 .procname = "ftrace_dump_on_oops",
594 .data = &ftrace_dump_on_oops,
595 .maxlen = sizeof(int),
597 .proc_handler = proc_dointvec,
600 #ifdef CONFIG_MODULES
602 .procname = "modprobe",
603 .data = &modprobe_path,
604 .maxlen = KMOD_PATH_LEN,
606 .proc_handler = proc_dostring,
609 .procname = "modules_disabled",
610 .data = &modules_disabled,
611 .maxlen = sizeof(int),
613 /* only handle a transition from default "0" to "1" */
614 .proc_handler = proc_dointvec_minmax,
621 .procname = "hotplug",
622 .data = &uevent_helper,
623 .maxlen = UEVENT_HELPER_PATH_LEN,
625 .proc_handler = proc_dostring,
628 #ifdef CONFIG_CHR_DEV_SG
630 .procname = "sg-big-buff",
631 .data = &sg_big_buff,
632 .maxlen = sizeof (int),
634 .proc_handler = proc_dointvec,
637 #ifdef CONFIG_BSD_PROCESS_ACCT
641 .maxlen = 3*sizeof(int),
643 .proc_handler = proc_dointvec,
646 #ifdef CONFIG_MAGIC_SYSRQ
649 .data = &__sysrq_enabled,
650 .maxlen = sizeof (int),
652 .proc_handler = sysrq_sysctl_handler,
655 #ifdef CONFIG_PROC_SYSCTL
657 .procname = "cad_pid",
659 .maxlen = sizeof (int),
661 .proc_handler = proc_do_cad_pid,
665 .procname = "threads-max",
666 .data = &max_threads,
667 .maxlen = sizeof(int),
669 .proc_handler = proc_dointvec,
672 .procname = "random",
674 .child = random_table,
677 .procname = "usermodehelper",
679 .child = usermodehelper_table,
682 .procname = "overflowuid",
683 .data = &overflowuid,
684 .maxlen = sizeof(int),
686 .proc_handler = proc_dointvec_minmax,
687 .extra1 = &minolduid,
688 .extra2 = &maxolduid,
691 .procname = "overflowgid",
692 .data = &overflowgid,
693 .maxlen = sizeof(int),
695 .proc_handler = proc_dointvec_minmax,
696 .extra1 = &minolduid,
697 .extra2 = &maxolduid,
700 #ifdef CONFIG_MATHEMU
702 .procname = "ieee_emulation_warnings",
703 .data = &sysctl_ieee_emulation_warnings,
704 .maxlen = sizeof(int),
706 .proc_handler = proc_dointvec,
710 .procname = "userprocess_debug",
711 .data = &show_unhandled_signals,
712 .maxlen = sizeof(int),
714 .proc_handler = proc_dointvec,
718 .procname = "pid_max",
720 .maxlen = sizeof (int),
722 .proc_handler = proc_dointvec_minmax,
723 .extra1 = &pid_max_min,
724 .extra2 = &pid_max_max,
727 .procname = "panic_on_oops",
728 .data = &panic_on_oops,
729 .maxlen = sizeof(int),
731 .proc_handler = proc_dointvec,
733 #if defined CONFIG_PRINTK
735 .procname = "printk",
736 .data = &console_loglevel,
737 .maxlen = 4*sizeof(int),
739 .proc_handler = proc_dointvec,
742 .procname = "printk_ratelimit",
743 .data = &printk_ratelimit_state.interval,
744 .maxlen = sizeof(int),
746 .proc_handler = proc_dointvec_jiffies,
749 .procname = "printk_ratelimit_burst",
750 .data = &printk_ratelimit_state.burst,
751 .maxlen = sizeof(int),
753 .proc_handler = proc_dointvec,
756 .procname = "printk_delay",
757 .data = &printk_delay_msec,
758 .maxlen = sizeof(int),
760 .proc_handler = proc_dointvec_minmax,
762 .extra2 = &ten_thousand,
765 .procname = "dmesg_restrict",
766 .data = &dmesg_restrict,
767 .maxlen = sizeof(int),
769 .proc_handler = proc_dointvec_minmax_sysadmin,
774 .procname = "kptr_restrict",
775 .data = &kptr_restrict,
776 .maxlen = sizeof(int),
778 .proc_handler = proc_dointvec_minmax_sysadmin,
784 .procname = "ngroups_max",
785 .data = &ngroups_max,
786 .maxlen = sizeof (int),
788 .proc_handler = proc_dointvec,
791 .procname = "cap_last_cap",
792 .data = (void *)&cap_last_cap,
793 .maxlen = sizeof(int),
795 .proc_handler = proc_dointvec,
797 #if defined(CONFIG_LOCKUP_DETECTOR)
799 .procname = "watchdog",
800 .data = &watchdog_enabled,
801 .maxlen = sizeof (int),
803 .proc_handler = proc_dowatchdog,
808 .procname = "watchdog_thresh",
809 .data = &watchdog_thresh,
810 .maxlen = sizeof(int),
812 .proc_handler = proc_dowatchdog,
817 .procname = "softlockup_panic",
818 .data = &softlockup_panic,
819 .maxlen = sizeof(int),
821 .proc_handler = proc_dointvec_minmax,
826 .procname = "nmi_watchdog",
827 .data = &watchdog_enabled,
828 .maxlen = sizeof (int),
830 .proc_handler = proc_dowatchdog,
835 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
837 .procname = "unknown_nmi_panic",
838 .data = &unknown_nmi_panic,
839 .maxlen = sizeof (int),
841 .proc_handler = proc_dointvec,
844 #if defined(CONFIG_X86)
846 .procname = "panic_on_unrecovered_nmi",
847 .data = &panic_on_unrecovered_nmi,
848 .maxlen = sizeof(int),
850 .proc_handler = proc_dointvec,
853 .procname = "panic_on_io_nmi",
854 .data = &panic_on_io_nmi,
855 .maxlen = sizeof(int),
857 .proc_handler = proc_dointvec,
859 #ifdef CONFIG_DEBUG_STACKOVERFLOW
861 .procname = "panic_on_stackoverflow",
862 .data = &sysctl_panic_on_stackoverflow,
863 .maxlen = sizeof(int),
865 .proc_handler = proc_dointvec,
869 .procname = "bootloader_type",
870 .data = &bootloader_type,
871 .maxlen = sizeof (int),
873 .proc_handler = proc_dointvec,
876 .procname = "bootloader_version",
877 .data = &bootloader_version,
878 .maxlen = sizeof (int),
880 .proc_handler = proc_dointvec,
883 .procname = "kstack_depth_to_print",
884 .data = &kstack_depth_to_print,
885 .maxlen = sizeof(int),
887 .proc_handler = proc_dointvec,
890 .procname = "io_delay_type",
891 .data = &io_delay_type,
892 .maxlen = sizeof(int),
894 .proc_handler = proc_dointvec,
897 #if defined(CONFIG_MMU)
899 .procname = "randomize_va_space",
900 .data = &randomize_va_space,
901 .maxlen = sizeof(int),
903 .proc_handler = proc_dointvec,
906 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
908 .procname = "spin_retry",
910 .maxlen = sizeof (int),
912 .proc_handler = proc_dointvec,
915 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
917 .procname = "acpi_video_flags",
918 .data = &acpi_realmode_flags,
919 .maxlen = sizeof (unsigned long),
921 .proc_handler = proc_doulongvec_minmax,
924 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
926 .procname = "ignore-unaligned-usertrap",
927 .data = &no_unaligned_warning,
928 .maxlen = sizeof (int),
930 .proc_handler = proc_dointvec,
935 .procname = "unaligned-dump-stack",
936 .data = &unaligned_dump_stack,
937 .maxlen = sizeof (int),
939 .proc_handler = proc_dointvec,
942 #ifdef CONFIG_DETECT_HUNG_TASK
944 .procname = "hung_task_panic",
945 .data = &sysctl_hung_task_panic,
946 .maxlen = sizeof(int),
948 .proc_handler = proc_dointvec_minmax,
953 .procname = "hung_task_check_count",
954 .data = &sysctl_hung_task_check_count,
955 .maxlen = sizeof(unsigned long),
957 .proc_handler = proc_doulongvec_minmax,
960 .procname = "hung_task_timeout_secs",
961 .data = &sysctl_hung_task_timeout_secs,
962 .maxlen = sizeof(unsigned long),
964 .proc_handler = proc_dohung_task_timeout_secs,
967 .procname = "hung_task_warnings",
968 .data = &sysctl_hung_task_warnings,
969 .maxlen = sizeof(unsigned long),
971 .proc_handler = proc_doulongvec_minmax,
976 .procname = "compat-log",
978 .maxlen = sizeof (int),
980 .proc_handler = proc_dointvec,
983 #ifdef CONFIG_RT_MUTEXES
985 .procname = "max_lock_depth",
986 .data = &max_lock_depth,
987 .maxlen = sizeof(int),
989 .proc_handler = proc_dointvec,
993 .procname = "poweroff_cmd",
994 .data = &poweroff_cmd,
995 .maxlen = POWEROFF_CMD_PATH_LEN,
997 .proc_handler = proc_dostring,
1003 .child = key_sysctls,
1006 #ifdef CONFIG_RCU_TORTURE_TEST
1008 .procname = "rcutorture_runnable",
1009 .data = &rcutorture_runnable,
1010 .maxlen = sizeof(int),
1012 .proc_handler = proc_dointvec,
1015 #ifdef CONFIG_PERF_EVENTS
1017 * User-space scripts rely on the existence of this file
1018 * as a feature check for perf_events being enabled.
1020 * So it's an ABI, do not remove!
1023 .procname = "perf_event_paranoid",
1024 .data = &sysctl_perf_event_paranoid,
1025 .maxlen = sizeof(sysctl_perf_event_paranoid),
1027 .proc_handler = proc_dointvec,
1030 .procname = "perf_event_mlock_kb",
1031 .data = &sysctl_perf_event_mlock,
1032 .maxlen = sizeof(sysctl_perf_event_mlock),
1034 .proc_handler = proc_dointvec,
1037 .procname = "perf_event_max_sample_rate",
1038 .data = &sysctl_perf_event_sample_rate,
1039 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1041 .proc_handler = perf_proc_update_handler,
1044 #ifdef CONFIG_KMEMCHECK
1046 .procname = "kmemcheck",
1047 .data = &kmemcheck_enabled,
1048 .maxlen = sizeof(int),
1050 .proc_handler = proc_dointvec,
1055 .procname = "blk_iopoll",
1056 .data = &blk_iopoll_enabled,
1057 .maxlen = sizeof(int),
1059 .proc_handler = proc_dointvec,
1065 static struct ctl_table vm_table[] = {
1067 .procname = "overcommit_memory",
1068 .data = &sysctl_overcommit_memory,
1069 .maxlen = sizeof(sysctl_overcommit_memory),
1071 .proc_handler = proc_dointvec_minmax,
1076 .procname = "panic_on_oom",
1077 .data = &sysctl_panic_on_oom,
1078 .maxlen = sizeof(sysctl_panic_on_oom),
1080 .proc_handler = proc_dointvec_minmax,
1085 .procname = "oom_kill_allocating_task",
1086 .data = &sysctl_oom_kill_allocating_task,
1087 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1089 .proc_handler = proc_dointvec,
1092 .procname = "oom_dump_tasks",
1093 .data = &sysctl_oom_dump_tasks,
1094 .maxlen = sizeof(sysctl_oom_dump_tasks),
1096 .proc_handler = proc_dointvec,
1099 .procname = "overcommit_ratio",
1100 .data = &sysctl_overcommit_ratio,
1101 .maxlen = sizeof(sysctl_overcommit_ratio),
1103 .proc_handler = proc_dointvec,
1106 .procname = "page-cluster",
1107 .data = &page_cluster,
1108 .maxlen = sizeof(int),
1110 .proc_handler = proc_dointvec_minmax,
1114 .procname = "dirty_background_ratio",
1115 .data = &dirty_background_ratio,
1116 .maxlen = sizeof(dirty_background_ratio),
1118 .proc_handler = dirty_background_ratio_handler,
1120 .extra2 = &one_hundred,
1123 .procname = "dirty_background_bytes",
1124 .data = &dirty_background_bytes,
1125 .maxlen = sizeof(dirty_background_bytes),
1127 .proc_handler = dirty_background_bytes_handler,
1131 .procname = "dirty_ratio",
1132 .data = &vm_dirty_ratio,
1133 .maxlen = sizeof(vm_dirty_ratio),
1135 .proc_handler = dirty_ratio_handler,
1137 .extra2 = &one_hundred,
1140 .procname = "dirty_bytes",
1141 .data = &vm_dirty_bytes,
1142 .maxlen = sizeof(vm_dirty_bytes),
1144 .proc_handler = dirty_bytes_handler,
1145 .extra1 = &dirty_bytes_min,
1148 .procname = "dirty_writeback_centisecs",
1149 .data = &dirty_writeback_interval,
1150 .maxlen = sizeof(dirty_writeback_interval),
1152 .proc_handler = dirty_writeback_centisecs_handler,
1155 .procname = "dirty_expire_centisecs",
1156 .data = &dirty_expire_interval,
1157 .maxlen = sizeof(dirty_expire_interval),
1159 .proc_handler = proc_dointvec_minmax,
1163 .procname = "nr_pdflush_threads",
1164 .mode = 0444 /* read-only */,
1165 .proc_handler = pdflush_proc_obsolete,
1168 .procname = "swappiness",
1169 .data = &vm_swappiness,
1170 .maxlen = sizeof(vm_swappiness),
1172 .proc_handler = proc_dointvec_minmax,
1174 .extra2 = &one_hundred,
1176 #ifdef CONFIG_HUGETLB_PAGE
1178 .procname = "nr_hugepages",
1180 .maxlen = sizeof(unsigned long),
1182 .proc_handler = hugetlb_sysctl_handler,
1183 .extra1 = (void *)&hugetlb_zero,
1184 .extra2 = (void *)&hugetlb_infinity,
1188 .procname = "nr_hugepages_mempolicy",
1190 .maxlen = sizeof(unsigned long),
1192 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1193 .extra1 = (void *)&hugetlb_zero,
1194 .extra2 = (void *)&hugetlb_infinity,
1198 .procname = "hugetlb_shm_group",
1199 .data = &sysctl_hugetlb_shm_group,
1200 .maxlen = sizeof(gid_t),
1202 .proc_handler = proc_dointvec,
1205 .procname = "hugepages_treat_as_movable",
1206 .data = &hugepages_treat_as_movable,
1207 .maxlen = sizeof(int),
1209 .proc_handler = hugetlb_treat_movable_handler,
1212 .procname = "nr_overcommit_hugepages",
1214 .maxlen = sizeof(unsigned long),
1216 .proc_handler = hugetlb_overcommit_handler,
1217 .extra1 = (void *)&hugetlb_zero,
1218 .extra2 = (void *)&hugetlb_infinity,
1222 .procname = "lowmem_reserve_ratio",
1223 .data = &sysctl_lowmem_reserve_ratio,
1224 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1226 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1229 .procname = "drop_caches",
1230 .data = &sysctl_drop_caches,
1231 .maxlen = sizeof(int),
1233 .proc_handler = drop_caches_sysctl_handler,
1237 #ifdef CONFIG_COMPACTION
1239 .procname = "compact_memory",
1240 .data = &sysctl_compact_memory,
1241 .maxlen = sizeof(int),
1243 .proc_handler = sysctl_compaction_handler,
1246 .procname = "extfrag_threshold",
1247 .data = &sysctl_extfrag_threshold,
1248 .maxlen = sizeof(int),
1250 .proc_handler = sysctl_extfrag_handler,
1251 .extra1 = &min_extfrag_threshold,
1252 .extra2 = &max_extfrag_threshold,
1255 #endif /* CONFIG_COMPACTION */
1257 .procname = "min_free_kbytes",
1258 .data = &min_free_kbytes,
1259 .maxlen = sizeof(min_free_kbytes),
1261 .proc_handler = min_free_kbytes_sysctl_handler,
1265 .procname = "percpu_pagelist_fraction",
1266 .data = &percpu_pagelist_fraction,
1267 .maxlen = sizeof(percpu_pagelist_fraction),
1269 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1270 .extra1 = &min_percpu_pagelist_fract,
1274 .procname = "max_map_count",
1275 .data = &sysctl_max_map_count,
1276 .maxlen = sizeof(sysctl_max_map_count),
1278 .proc_handler = proc_dointvec_minmax,
1283 .procname = "nr_trim_pages",
1284 .data = &sysctl_nr_trim_pages,
1285 .maxlen = sizeof(sysctl_nr_trim_pages),
1287 .proc_handler = proc_dointvec_minmax,
1292 .procname = "laptop_mode",
1293 .data = &laptop_mode,
1294 .maxlen = sizeof(laptop_mode),
1296 .proc_handler = proc_dointvec_jiffies,
1299 .procname = "block_dump",
1300 .data = &block_dump,
1301 .maxlen = sizeof(block_dump),
1303 .proc_handler = proc_dointvec,
1307 .procname = "vfs_cache_pressure",
1308 .data = &sysctl_vfs_cache_pressure,
1309 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1311 .proc_handler = proc_dointvec,
1314 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1316 .procname = "legacy_va_layout",
1317 .data = &sysctl_legacy_va_layout,
1318 .maxlen = sizeof(sysctl_legacy_va_layout),
1320 .proc_handler = proc_dointvec,
1326 .procname = "zone_reclaim_mode",
1327 .data = &zone_reclaim_mode,
1328 .maxlen = sizeof(zone_reclaim_mode),
1330 .proc_handler = proc_dointvec,
1334 .procname = "min_unmapped_ratio",
1335 .data = &sysctl_min_unmapped_ratio,
1336 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1338 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1340 .extra2 = &one_hundred,
1343 .procname = "min_slab_ratio",
1344 .data = &sysctl_min_slab_ratio,
1345 .maxlen = sizeof(sysctl_min_slab_ratio),
1347 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1349 .extra2 = &one_hundred,
1354 .procname = "stat_interval",
1355 .data = &sysctl_stat_interval,
1356 .maxlen = sizeof(sysctl_stat_interval),
1358 .proc_handler = proc_dointvec_jiffies,
1363 .procname = "mmap_min_addr",
1364 .data = &dac_mmap_min_addr,
1365 .maxlen = sizeof(unsigned long),
1367 .proc_handler = mmap_min_addr_handler,
1372 .procname = "numa_zonelist_order",
1373 .data = &numa_zonelist_order,
1374 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1376 .proc_handler = numa_zonelist_order_handler,
1379 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1380 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1382 .procname = "vdso_enabled",
1383 .data = &vdso_enabled,
1384 .maxlen = sizeof(vdso_enabled),
1386 .proc_handler = proc_dointvec,
1390 #ifdef CONFIG_HIGHMEM
1392 .procname = "highmem_is_dirtyable",
1393 .data = &vm_highmem_is_dirtyable,
1394 .maxlen = sizeof(vm_highmem_is_dirtyable),
1396 .proc_handler = proc_dointvec_minmax,
1402 .procname = "scan_unevictable_pages",
1403 .data = &scan_unevictable_pages,
1404 .maxlen = sizeof(scan_unevictable_pages),
1406 .proc_handler = scan_unevictable_handler,
1408 #ifdef CONFIG_MEMORY_FAILURE
1410 .procname = "memory_failure_early_kill",
1411 .data = &sysctl_memory_failure_early_kill,
1412 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1414 .proc_handler = proc_dointvec_minmax,
1419 .procname = "memory_failure_recovery",
1420 .data = &sysctl_memory_failure_recovery,
1421 .maxlen = sizeof(sysctl_memory_failure_recovery),
1423 .proc_handler = proc_dointvec_minmax,
1431 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1432 static struct ctl_table binfmt_misc_table[] = {
1437 static struct ctl_table fs_table[] = {
1439 .procname = "inode-nr",
1440 .data = &inodes_stat,
1441 .maxlen = 2*sizeof(int),
1443 .proc_handler = proc_nr_inodes,
1446 .procname = "inode-state",
1447 .data = &inodes_stat,
1448 .maxlen = 7*sizeof(int),
1450 .proc_handler = proc_nr_inodes,
1453 .procname = "file-nr",
1454 .data = &files_stat,
1455 .maxlen = sizeof(files_stat),
1457 .proc_handler = proc_nr_files,
1460 .procname = "file-max",
1461 .data = &files_stat.max_files,
1462 .maxlen = sizeof(files_stat.max_files),
1464 .proc_handler = proc_doulongvec_minmax,
1467 .procname = "nr_open",
1468 .data = &sysctl_nr_open,
1469 .maxlen = sizeof(int),
1471 .proc_handler = proc_dointvec_minmax,
1472 .extra1 = &sysctl_nr_open_min,
1473 .extra2 = &sysctl_nr_open_max,
1476 .procname = "dentry-state",
1477 .data = &dentry_stat,
1478 .maxlen = 6*sizeof(int),
1480 .proc_handler = proc_nr_dentry,
1483 .procname = "overflowuid",
1484 .data = &fs_overflowuid,
1485 .maxlen = sizeof(int),
1487 .proc_handler = proc_dointvec_minmax,
1488 .extra1 = &minolduid,
1489 .extra2 = &maxolduid,
1492 .procname = "overflowgid",
1493 .data = &fs_overflowgid,
1494 .maxlen = sizeof(int),
1496 .proc_handler = proc_dointvec_minmax,
1497 .extra1 = &minolduid,
1498 .extra2 = &maxolduid,
1500 #ifdef CONFIG_FILE_LOCKING
1502 .procname = "leases-enable",
1503 .data = &leases_enable,
1504 .maxlen = sizeof(int),
1506 .proc_handler = proc_dointvec,
1509 #ifdef CONFIG_DNOTIFY
1511 .procname = "dir-notify-enable",
1512 .data = &dir_notify_enable,
1513 .maxlen = sizeof(int),
1515 .proc_handler = proc_dointvec,
1519 #ifdef CONFIG_FILE_LOCKING
1521 .procname = "lease-break-time",
1522 .data = &lease_break_time,
1523 .maxlen = sizeof(int),
1525 .proc_handler = proc_dointvec,
1530 .procname = "aio-nr",
1532 .maxlen = sizeof(aio_nr),
1534 .proc_handler = proc_doulongvec_minmax,
1537 .procname = "aio-max-nr",
1538 .data = &aio_max_nr,
1539 .maxlen = sizeof(aio_max_nr),
1541 .proc_handler = proc_doulongvec_minmax,
1543 #endif /* CONFIG_AIO */
1544 #ifdef CONFIG_INOTIFY_USER
1546 .procname = "inotify",
1548 .child = inotify_table,
1553 .procname = "epoll",
1555 .child = epoll_table,
1560 .procname = "protected_symlinks",
1561 .data = &sysctl_protected_symlinks,
1562 .maxlen = sizeof(int),
1564 .proc_handler = proc_dointvec_minmax,
1569 .procname = "protected_hardlinks",
1570 .data = &sysctl_protected_hardlinks,
1571 .maxlen = sizeof(int),
1573 .proc_handler = proc_dointvec_minmax,
1578 .procname = "suid_dumpable",
1579 .data = &suid_dumpable,
1580 .maxlen = sizeof(int),
1582 .proc_handler = proc_dointvec_minmax_coredump,
1586 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1588 .procname = "binfmt_misc",
1590 .child = binfmt_misc_table,
1594 .procname = "pipe-max-size",
1595 .data = &pipe_max_size,
1596 .maxlen = sizeof(int),
1598 .proc_handler = &pipe_proc_fn,
1599 .extra1 = &pipe_min_size,
1604 static struct ctl_table debug_table[] = {
1605 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1607 .procname = "exception-trace",
1608 .data = &show_unhandled_signals,
1609 .maxlen = sizeof(int),
1611 .proc_handler = proc_dointvec
1614 #if defined(CONFIG_OPTPROBES)
1616 .procname = "kprobes-optimization",
1617 .data = &sysctl_kprobes_optimization,
1618 .maxlen = sizeof(int),
1620 .proc_handler = proc_kprobes_optimization_handler,
1628 static struct ctl_table dev_table[] = {
1632 int __init sysctl_init(void)
1634 struct ctl_table_header *hdr;
1636 hdr = register_sysctl_table(sysctl_base_table);
1637 kmemleak_not_leak(hdr);
1641 #endif /* CONFIG_SYSCTL */
1647 #ifdef CONFIG_PROC_SYSCTL
1649 static int _proc_do_string(void* data, int maxlen, int write,
1650 void __user *buffer,
1651 size_t *lenp, loff_t *ppos)
1657 if (!data || !maxlen || !*lenp) {
1665 while (len < *lenp) {
1666 if (get_user(c, p++))
1668 if (c == 0 || c == '\n')
1674 if(copy_from_user(data, buffer, len))
1676 ((char *) data)[len] = 0;
1694 if(copy_to_user(buffer, data, len))
1697 if(put_user('\n', ((char __user *) buffer) + len))
1708 * proc_dostring - read a string sysctl
1709 * @table: the sysctl table
1710 * @write: %TRUE if this is a write to the sysctl file
1711 * @buffer: the user buffer
1712 * @lenp: the size of the user buffer
1713 * @ppos: file position
1715 * Reads/writes a string from/to the user buffer. If the kernel
1716 * buffer provided is not large enough to hold the string, the
1717 * string is truncated. The copied string is %NULL-terminated.
1718 * If the string is being read by the user process, it is copied
1719 * and a newline '\n' is added. It is truncated if the buffer is
1722 * Returns 0 on success.
1724 int proc_dostring(struct ctl_table *table, int write,
1725 void __user *buffer, size_t *lenp, loff_t *ppos)
1727 return _proc_do_string(table->data, table->maxlen, write,
1728 buffer, lenp, ppos);
1731 static size_t proc_skip_spaces(char **buf)
1734 char *tmp = skip_spaces(*buf);
1740 static void proc_skip_char(char **buf, size_t *size, const char v)
1750 #define TMPBUFLEN 22
1752 * proc_get_long - reads an ASCII formatted integer from a user buffer
1754 * @buf: a kernel buffer
1755 * @size: size of the kernel buffer
1756 * @val: this is where the number will be stored
1757 * @neg: set to %TRUE if number is negative
1758 * @perm_tr: a vector which contains the allowed trailers
1759 * @perm_tr_len: size of the perm_tr vector
1760 * @tr: pointer to store the trailer character
1762 * In case of success %0 is returned and @buf and @size are updated with
1763 * the amount of bytes read. If @tr is non-NULL and a trailing
1764 * character exists (size is non-zero after returning from this
1765 * function), @tr is updated with the trailing character.
1767 static int proc_get_long(char **buf, size_t *size,
1768 unsigned long *val, bool *neg,
1769 const char *perm_tr, unsigned perm_tr_len, char *tr)
1772 char *p, tmp[TMPBUFLEN];
1778 if (len > TMPBUFLEN - 1)
1779 len = TMPBUFLEN - 1;
1781 memcpy(tmp, *buf, len);
1785 if (*p == '-' && *size > 1) {
1793 *val = simple_strtoul(p, &p, 0);
1797 /* We don't know if the next char is whitespace thus we may accept
1798 * invalid integers (e.g. 1234...a) or two integers instead of one
1799 * (e.g. 123...1). So lets not allow such large numbers. */
1800 if (len == TMPBUFLEN - 1)
1803 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1806 if (tr && (len < *size))
1816 * proc_put_long - converts an integer to a decimal ASCII formatted string
1818 * @buf: the user buffer
1819 * @size: the size of the user buffer
1820 * @val: the integer to be converted
1821 * @neg: sign of the number, %TRUE for negative
1823 * In case of success %0 is returned and @buf and @size are updated with
1824 * the amount of bytes written.
1826 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1830 char tmp[TMPBUFLEN], *p = tmp;
1832 sprintf(p, "%s%lu", neg ? "-" : "", val);
1836 if (copy_to_user(*buf, tmp, len))
1844 static int proc_put_char(void __user **buf, size_t *size, char c)
1847 char __user **buffer = (char __user **)buf;
1848 if (put_user(c, *buffer))
1850 (*size)--, (*buffer)++;
1856 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1858 int write, void *data)
1861 *valp = *negp ? -*lvalp : *lvalp;
1866 *lvalp = (unsigned long)-val;
1869 *lvalp = (unsigned long)val;
1875 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1877 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1878 int write, void __user *buffer,
1879 size_t *lenp, loff_t *ppos,
1880 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1881 int write, void *data),
1884 int *i, vleft, first = 1, err = 0;
1885 unsigned long page = 0;
1889 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1894 i = (int *) tbl_data;
1895 vleft = table->maxlen / sizeof(*i);
1899 conv = do_proc_dointvec_conv;
1902 if (left > PAGE_SIZE - 1)
1903 left = PAGE_SIZE - 1;
1904 page = __get_free_page(GFP_TEMPORARY);
1905 kbuf = (char *) page;
1908 if (copy_from_user(kbuf, buffer, left)) {
1915 for (; left && vleft--; i++, first=0) {
1920 left -= proc_skip_spaces(&kbuf);
1924 err = proc_get_long(&kbuf, &left, &lval, &neg,
1926 sizeof(proc_wspace_sep), NULL);
1929 if (conv(&neg, &lval, i, 1, data)) {
1934 if (conv(&neg, &lval, i, 0, data)) {
1939 err = proc_put_char(&buffer, &left, '\t');
1942 err = proc_put_long(&buffer, &left, lval, neg);
1948 if (!write && !first && left && !err)
1949 err = proc_put_char(&buffer, &left, '\n');
1950 if (write && !err && left)
1951 left -= proc_skip_spaces(&kbuf);
1956 return err ? : -EINVAL;
1963 static int do_proc_dointvec(struct ctl_table *table, int write,
1964 void __user *buffer, size_t *lenp, loff_t *ppos,
1965 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1966 int write, void *data),
1969 return __do_proc_dointvec(table->data, table, write,
1970 buffer, lenp, ppos, conv, data);
1974 * proc_dointvec - read a vector of integers
1975 * @table: the sysctl table
1976 * @write: %TRUE if this is a write to the sysctl file
1977 * @buffer: the user buffer
1978 * @lenp: the size of the user buffer
1979 * @ppos: file position
1981 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1982 * values from/to the user buffer, treated as an ASCII string.
1984 * Returns 0 on success.
1986 int proc_dointvec(struct ctl_table *table, int write,
1987 void __user *buffer, size_t *lenp, loff_t *ppos)
1989 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1994 * Taint values can only be increased
1995 * This means we can safely use a temporary.
1997 static int proc_taint(struct ctl_table *table, int write,
1998 void __user *buffer, size_t *lenp, loff_t *ppos)
2001 unsigned long tmptaint = get_taint();
2004 if (write && !capable(CAP_SYS_ADMIN))
2009 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2015 * Poor man's atomic or. Not worth adding a primitive
2016 * to everyone's atomic.h for this
2019 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2020 if ((tmptaint >> i) & 1)
2021 add_taint(i, LOCKDEP_STILL_OK);
2028 #ifdef CONFIG_PRINTK
2029 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2030 void __user *buffer, size_t *lenp, loff_t *ppos)
2032 if (write && !capable(CAP_SYS_ADMIN))
2035 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2039 struct do_proc_dointvec_minmax_conv_param {
2044 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2046 int write, void *data)
2048 struct do_proc_dointvec_minmax_conv_param *param = data;
2050 int val = *negp ? -*lvalp : *lvalp;
2051 if ((param->min && *param->min > val) ||
2052 (param->max && *param->max < val))
2059 *lvalp = (unsigned long)-val;
2062 *lvalp = (unsigned long)val;
2069 * proc_dointvec_minmax - read a vector of integers with min/max values
2070 * @table: the sysctl table
2071 * @write: %TRUE if this is a write to the sysctl file
2072 * @buffer: the user buffer
2073 * @lenp: the size of the user buffer
2074 * @ppos: file position
2076 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2077 * values from/to the user buffer, treated as an ASCII string.
2079 * This routine will ensure the values are within the range specified by
2080 * table->extra1 (min) and table->extra2 (max).
2082 * Returns 0 on success.
2084 int proc_dointvec_minmax(struct ctl_table *table, int write,
2085 void __user *buffer, size_t *lenp, loff_t *ppos)
2087 struct do_proc_dointvec_minmax_conv_param param = {
2088 .min = (int *) table->extra1,
2089 .max = (int *) table->extra2,
2091 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2092 do_proc_dointvec_minmax_conv, ¶m);
2095 static void validate_coredump_safety(void)
2097 #ifdef CONFIG_COREDUMP
2098 if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2099 core_pattern[0] != '/' && core_pattern[0] != '|') {
2100 printk(KERN_WARNING "Unsafe core_pattern used with "\
2101 "suid_dumpable=2. Pipe handler or fully qualified "\
2102 "core dump path required.\n");
2107 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2108 void __user *buffer, size_t *lenp, loff_t *ppos)
2110 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2112 validate_coredump_safety();
2116 #ifdef CONFIG_COREDUMP
2117 static int proc_dostring_coredump(struct ctl_table *table, int write,
2118 void __user *buffer, size_t *lenp, loff_t *ppos)
2120 int error = proc_dostring(table, write, buffer, lenp, ppos);
2122 validate_coredump_safety();
2127 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2128 void __user *buffer,
2129 size_t *lenp, loff_t *ppos,
2130 unsigned long convmul,
2131 unsigned long convdiv)
2133 unsigned long *i, *min, *max;
2134 int vleft, first = 1, err = 0;
2135 unsigned long page = 0;
2139 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2144 i = (unsigned long *) data;
2145 min = (unsigned long *) table->extra1;
2146 max = (unsigned long *) table->extra2;
2147 vleft = table->maxlen / sizeof(unsigned long);
2151 if (left > PAGE_SIZE - 1)
2152 left = PAGE_SIZE - 1;
2153 page = __get_free_page(GFP_TEMPORARY);
2154 kbuf = (char *) page;
2157 if (copy_from_user(kbuf, buffer, left)) {
2164 for (; left && vleft--; i++, first = 0) {
2170 left -= proc_skip_spaces(&kbuf);
2172 err = proc_get_long(&kbuf, &left, &val, &neg,
2174 sizeof(proc_wspace_sep), NULL);
2179 if ((min && val < *min) || (max && val > *max))
2183 val = convdiv * (*i) / convmul;
2185 err = proc_put_char(&buffer, &left, '\t');
2186 err = proc_put_long(&buffer, &left, val, false);
2192 if (!write && !first && left && !err)
2193 err = proc_put_char(&buffer, &left, '\n');
2195 left -= proc_skip_spaces(&kbuf);
2200 return err ? : -EINVAL;
2207 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2208 void __user *buffer,
2209 size_t *lenp, loff_t *ppos,
2210 unsigned long convmul,
2211 unsigned long convdiv)
2213 return __do_proc_doulongvec_minmax(table->data, table, write,
2214 buffer, lenp, ppos, convmul, convdiv);
2218 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2219 * @table: the sysctl table
2220 * @write: %TRUE if this is a write to the sysctl file
2221 * @buffer: the user buffer
2222 * @lenp: the size of the user buffer
2223 * @ppos: file position
2225 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2226 * values from/to the user buffer, treated as an ASCII string.
2228 * This routine will ensure the values are within the range specified by
2229 * table->extra1 (min) and table->extra2 (max).
2231 * Returns 0 on success.
2233 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2234 void __user *buffer, size_t *lenp, loff_t *ppos)
2236 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2240 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2241 * @table: the sysctl table
2242 * @write: %TRUE if this is a write to the sysctl file
2243 * @buffer: the user buffer
2244 * @lenp: the size of the user buffer
2245 * @ppos: file position
2247 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2248 * values from/to the user buffer, treated as an ASCII string. The values
2249 * are treated as milliseconds, and converted to jiffies when they are stored.
2251 * This routine will ensure the values are within the range specified by
2252 * table->extra1 (min) and table->extra2 (max).
2254 * Returns 0 on success.
2256 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2257 void __user *buffer,
2258 size_t *lenp, loff_t *ppos)
2260 return do_proc_doulongvec_minmax(table, write, buffer,
2261 lenp, ppos, HZ, 1000l);
2265 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2267 int write, void *data)
2270 if (*lvalp > LONG_MAX / HZ)
2272 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2278 lval = (unsigned long)-val;
2281 lval = (unsigned long)val;
2288 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2290 int write, void *data)
2293 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2295 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2301 lval = (unsigned long)-val;
2304 lval = (unsigned long)val;
2306 *lvalp = jiffies_to_clock_t(lval);
2311 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2313 int write, void *data)
2316 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2322 lval = (unsigned long)-val;
2325 lval = (unsigned long)val;
2327 *lvalp = jiffies_to_msecs(lval);
2333 * proc_dointvec_jiffies - read a vector of integers as seconds
2334 * @table: the sysctl table
2335 * @write: %TRUE if this is a write to the sysctl file
2336 * @buffer: the user buffer
2337 * @lenp: the size of the user buffer
2338 * @ppos: file position
2340 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2341 * values from/to the user buffer, treated as an ASCII string.
2342 * The values read are assumed to be in seconds, and are converted into
2345 * Returns 0 on success.
2347 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2348 void __user *buffer, size_t *lenp, loff_t *ppos)
2350 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2351 do_proc_dointvec_jiffies_conv,NULL);
2355 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2356 * @table: the sysctl table
2357 * @write: %TRUE if this is a write to the sysctl file
2358 * @buffer: the user buffer
2359 * @lenp: the size of the user buffer
2360 * @ppos: pointer to the file position
2362 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2363 * values from/to the user buffer, treated as an ASCII string.
2364 * The values read are assumed to be in 1/USER_HZ seconds, and
2365 * are converted into jiffies.
2367 * Returns 0 on success.
2369 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2370 void __user *buffer, size_t *lenp, loff_t *ppos)
2372 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2373 do_proc_dointvec_userhz_jiffies_conv,NULL);
2377 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2378 * @table: the sysctl table
2379 * @write: %TRUE if this is a write to the sysctl file
2380 * @buffer: the user buffer
2381 * @lenp: the size of the user buffer
2382 * @ppos: file position
2383 * @ppos: the current position in the file
2385 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2386 * values from/to the user buffer, treated as an ASCII string.
2387 * The values read are assumed to be in 1/1000 seconds, and
2388 * are converted into jiffies.
2390 * Returns 0 on success.
2392 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2393 void __user *buffer, size_t *lenp, loff_t *ppos)
2395 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2396 do_proc_dointvec_ms_jiffies_conv, NULL);
2399 static int proc_do_cad_pid(struct ctl_table *table, int write,
2400 void __user *buffer, size_t *lenp, loff_t *ppos)
2402 struct pid *new_pid;
2406 tmp = pid_vnr(cad_pid);
2408 r = __do_proc_dointvec(&tmp, table, write, buffer,
2409 lenp, ppos, NULL, NULL);
2413 new_pid = find_get_pid(tmp);
2417 put_pid(xchg(&cad_pid, new_pid));
2422 * proc_do_large_bitmap - read/write from/to a large bitmap
2423 * @table: the sysctl table
2424 * @write: %TRUE if this is a write to the sysctl file
2425 * @buffer: the user buffer
2426 * @lenp: the size of the user buffer
2427 * @ppos: file position
2429 * The bitmap is stored at table->data and the bitmap length (in bits)
2432 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2433 * large bitmaps may be represented in a compact manner. Writing into
2434 * the file will clear the bitmap then update it with the given input.
2436 * Returns 0 on success.
2438 int proc_do_large_bitmap(struct ctl_table *table, int write,
2439 void __user *buffer, size_t *lenp, loff_t *ppos)
2443 size_t left = *lenp;
2444 unsigned long bitmap_len = table->maxlen;
2445 unsigned long *bitmap = (unsigned long *) table->data;
2446 unsigned long *tmp_bitmap = NULL;
2447 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2449 if (!bitmap_len || !left || (*ppos && !write)) {
2455 unsigned long page = 0;
2458 if (left > PAGE_SIZE - 1)
2459 left = PAGE_SIZE - 1;
2461 page = __get_free_page(GFP_TEMPORARY);
2462 kbuf = (char *) page;
2465 if (copy_from_user(kbuf, buffer, left)) {
2471 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2477 proc_skip_char(&kbuf, &left, '\n');
2478 while (!err && left) {
2479 unsigned long val_a, val_b;
2482 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2486 if (val_a >= bitmap_len || neg) {
2498 err = proc_get_long(&kbuf, &left, &val_b,
2499 &neg, tr_b, sizeof(tr_b),
2503 if (val_b >= bitmap_len || neg ||
2514 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2516 proc_skip_char(&kbuf, &left, '\n');
2520 unsigned long bit_a, bit_b = 0;
2523 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2524 if (bit_a >= bitmap_len)
2526 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2530 err = proc_put_char(&buffer, &left, ',');
2534 err = proc_put_long(&buffer, &left, bit_a, false);
2537 if (bit_a != bit_b) {
2538 err = proc_put_char(&buffer, &left, '-');
2541 err = proc_put_long(&buffer, &left, bit_b, false);
2549 err = proc_put_char(&buffer, &left, '\n');
2555 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2557 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2569 #else /* CONFIG_PROC_SYSCTL */
2571 int proc_dostring(struct ctl_table *table, int write,
2572 void __user *buffer, size_t *lenp, loff_t *ppos)
2577 int proc_dointvec(struct ctl_table *table, int write,
2578 void __user *buffer, size_t *lenp, loff_t *ppos)
2583 int proc_dointvec_minmax(struct ctl_table *table, int write,
2584 void __user *buffer, size_t *lenp, loff_t *ppos)
2589 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2590 void __user *buffer, size_t *lenp, loff_t *ppos)
2595 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2596 void __user *buffer, size_t *lenp, loff_t *ppos)
2601 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2602 void __user *buffer, size_t *lenp, loff_t *ppos)
2607 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2608 void __user *buffer, size_t *lenp, loff_t *ppos)
2613 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2614 void __user *buffer,
2615 size_t *lenp, loff_t *ppos)
2621 #endif /* CONFIG_PROC_SYSCTL */
2624 * No sense putting this after each symbol definition, twice,
2625 * exception granted :-)
2627 EXPORT_SYMBOL(proc_dointvec);
2628 EXPORT_SYMBOL(proc_dointvec_jiffies);
2629 EXPORT_SYMBOL(proc_dointvec_minmax);
2630 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2631 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2632 EXPORT_SYMBOL(proc_dostring);
2633 EXPORT_SYMBOL(proc_doulongvec_minmax);
2634 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);