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>
65 #include <linux/kexec.h>
67 #include <asm/uaccess.h>
68 #include <asm/processor.h>
72 #include <asm/stacktrace.h>
76 #include <asm/setup.h>
78 #ifdef CONFIG_BSD_PROCESS_ACCT
79 #include <linux/acct.h>
81 #ifdef CONFIG_RT_MUTEXES
82 #include <linux/rtmutex.h>
84 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85 #include <linux/lockdep.h>
87 #ifdef CONFIG_CHR_DEV_SG
91 #ifdef CONFIG_LOCKUP_DETECTOR
92 #include <linux/nmi.h>
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
99 extern int max_threads;
100 extern int suid_dumpable;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid;
103 extern char core_pattern[];
104 extern unsigned int core_pipe_limit;
107 extern int pid_max_min, pid_max_max;
108 extern int percpu_pagelist_fraction;
109 extern int compat_log;
110 extern int latencytop_enabled;
111 extern int sysctl_nr_open_min, sysctl_nr_open_max;
113 extern int sysctl_nr_trim_pages;
116 /* Constants used for minimum and maximum */
117 #ifdef CONFIG_LOCKUP_DETECTOR
118 static int sixty = 60;
121 static int __maybe_unused neg_one = -1;
124 static int __maybe_unused one = 1;
125 static int __maybe_unused two = 2;
126 static int __maybe_unused four = 4;
127 static unsigned long one_ul = 1;
128 static int one_hundred = 100;
130 static int ten_thousand = 10000;
133 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
134 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
136 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
137 static int maxolduid = 65535;
138 static int minolduid;
140 static int ngroups_max = NGROUPS_MAX;
141 static const int cap_last_cap = CAP_LAST_CAP;
143 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
144 #ifdef CONFIG_DETECT_HUNG_TASK
145 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
155 extern int pwrsw_enabled;
158 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
159 extern int unaligned_enabled;
163 extern int unaligned_dump_stack;
166 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
167 extern int no_unaligned_warning;
170 #ifdef CONFIG_PROC_SYSCTL
172 #define SYSCTL_WRITES_LEGACY -1
173 #define SYSCTL_WRITES_WARN 0
174 #define SYSCTL_WRITES_STRICT 1
176 static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
178 static int proc_do_cad_pid(struct ctl_table *table, int write,
179 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_taint(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
185 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
186 void __user *buffer, size_t *lenp, loff_t *ppos);
189 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
190 void __user *buffer, size_t *lenp, loff_t *ppos);
191 #ifdef CONFIG_COREDUMP
192 static int proc_dostring_coredump(struct ctl_table *table, int write,
193 void __user *buffer, size_t *lenp, loff_t *ppos);
196 #ifdef CONFIG_MAGIC_SYSRQ
197 /* Note: sysrq code uses it's own private copy */
198 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
200 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
201 void __user *buffer, size_t *lenp,
206 error = proc_dointvec(table, write, buffer, lenp, ppos);
211 sysrq_toggle_support(__sysrq_enabled);
218 static struct ctl_table kern_table[];
219 static struct ctl_table vm_table[];
220 static struct ctl_table fs_table[];
221 static struct ctl_table debug_table[];
222 static struct ctl_table dev_table[];
223 extern struct ctl_table random_table[];
225 extern struct ctl_table epoll_table[];
228 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
229 int sysctl_legacy_va_layout;
232 /* The default sysctl tables: */
234 static struct ctl_table sysctl_base_table[] = {
236 .procname = "kernel",
253 .child = debug_table,
263 #ifdef CONFIG_SCHED_DEBUG
264 static int min_sched_granularity_ns = 100000; /* 100 usecs */
265 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
266 static int min_wakeup_granularity_ns; /* 0 usecs */
267 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
269 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
270 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
271 #endif /* CONFIG_SMP */
272 #endif /* CONFIG_SCHED_DEBUG */
274 #ifdef CONFIG_COMPACTION
275 static int min_extfrag_threshold;
276 static int max_extfrag_threshold = 1000;
279 static struct ctl_table kern_table[] = {
281 .procname = "sched_child_runs_first",
282 .data = &sysctl_sched_child_runs_first,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = proc_dointvec,
287 #ifdef CONFIG_SCHED_DEBUG
289 .procname = "sched_min_granularity_ns",
290 .data = &sysctl_sched_min_granularity,
291 .maxlen = sizeof(unsigned int),
293 .proc_handler = sched_proc_update_handler,
294 .extra1 = &min_sched_granularity_ns,
295 .extra2 = &max_sched_granularity_ns,
298 .procname = "sched_latency_ns",
299 .data = &sysctl_sched_latency,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = sched_proc_update_handler,
303 .extra1 = &min_sched_granularity_ns,
304 .extra2 = &max_sched_granularity_ns,
307 .procname = "sched_wakeup_granularity_ns",
308 .data = &sysctl_sched_wakeup_granularity,
309 .maxlen = sizeof(unsigned int),
311 .proc_handler = sched_proc_update_handler,
312 .extra1 = &min_wakeup_granularity_ns,
313 .extra2 = &max_wakeup_granularity_ns,
317 .procname = "sched_tunable_scaling",
318 .data = &sysctl_sched_tunable_scaling,
319 .maxlen = sizeof(enum sched_tunable_scaling),
321 .proc_handler = sched_proc_update_handler,
322 .extra1 = &min_sched_tunable_scaling,
323 .extra2 = &max_sched_tunable_scaling,
326 .procname = "sched_migration_cost_ns",
327 .data = &sysctl_sched_migration_cost,
328 .maxlen = sizeof(unsigned int),
330 .proc_handler = proc_dointvec,
333 .procname = "sched_nr_migrate",
334 .data = &sysctl_sched_nr_migrate,
335 .maxlen = sizeof(unsigned int),
337 .proc_handler = proc_dointvec,
340 .procname = "sched_time_avg_ms",
341 .data = &sysctl_sched_time_avg,
342 .maxlen = sizeof(unsigned int),
344 .proc_handler = proc_dointvec,
347 .procname = "sched_shares_window_ns",
348 .data = &sysctl_sched_shares_window,
349 .maxlen = sizeof(unsigned int),
351 .proc_handler = proc_dointvec,
354 .procname = "timer_migration",
355 .data = &sysctl_timer_migration,
356 .maxlen = sizeof(unsigned int),
358 .proc_handler = proc_dointvec_minmax,
362 #endif /* CONFIG_SMP */
363 #ifdef CONFIG_NUMA_BALANCING
365 .procname = "numa_balancing_scan_delay_ms",
366 .data = &sysctl_numa_balancing_scan_delay,
367 .maxlen = sizeof(unsigned int),
369 .proc_handler = proc_dointvec,
372 .procname = "numa_balancing_scan_period_min_ms",
373 .data = &sysctl_numa_balancing_scan_period_min,
374 .maxlen = sizeof(unsigned int),
376 .proc_handler = proc_dointvec,
379 .procname = "numa_balancing_scan_period_max_ms",
380 .data = &sysctl_numa_balancing_scan_period_max,
381 .maxlen = sizeof(unsigned int),
383 .proc_handler = proc_dointvec,
386 .procname = "numa_balancing_scan_size_mb",
387 .data = &sysctl_numa_balancing_scan_size,
388 .maxlen = sizeof(unsigned int),
390 .proc_handler = proc_dointvec,
393 .procname = "numa_balancing",
394 .data = NULL, /* filled in by handler */
395 .maxlen = sizeof(unsigned int),
397 .proc_handler = sysctl_numa_balancing,
401 #endif /* CONFIG_NUMA_BALANCING */
402 #endif /* CONFIG_SCHED_DEBUG */
404 .procname = "sched_rt_period_us",
405 .data = &sysctl_sched_rt_period,
406 .maxlen = sizeof(unsigned int),
408 .proc_handler = sched_rt_handler,
411 .procname = "sched_rt_runtime_us",
412 .data = &sysctl_sched_rt_runtime,
413 .maxlen = sizeof(int),
415 .proc_handler = sched_rt_handler,
418 .procname = "sched_rr_timeslice_ms",
419 .data = &sched_rr_timeslice,
420 .maxlen = sizeof(int),
422 .proc_handler = sched_rr_handler,
424 #ifdef CONFIG_SCHED_AUTOGROUP
426 .procname = "sched_autogroup_enabled",
427 .data = &sysctl_sched_autogroup_enabled,
428 .maxlen = sizeof(unsigned int),
430 .proc_handler = proc_dointvec_minmax,
435 #ifdef CONFIG_CFS_BANDWIDTH
437 .procname = "sched_cfs_bandwidth_slice_us",
438 .data = &sysctl_sched_cfs_bandwidth_slice,
439 .maxlen = sizeof(unsigned int),
441 .proc_handler = proc_dointvec_minmax,
445 #ifdef CONFIG_PROVE_LOCKING
447 .procname = "prove_locking",
448 .data = &prove_locking,
449 .maxlen = sizeof(int),
451 .proc_handler = proc_dointvec,
454 #ifdef CONFIG_LOCK_STAT
456 .procname = "lock_stat",
458 .maxlen = sizeof(int),
460 .proc_handler = proc_dointvec,
465 .data = &panic_timeout,
466 .maxlen = sizeof(int),
468 .proc_handler = proc_dointvec,
470 #ifdef CONFIG_COREDUMP
472 .procname = "core_uses_pid",
473 .data = &core_uses_pid,
474 .maxlen = sizeof(int),
476 .proc_handler = proc_dointvec,
479 .procname = "core_pattern",
480 .data = core_pattern,
481 .maxlen = CORENAME_MAX_SIZE,
483 .proc_handler = proc_dostring_coredump,
486 .procname = "core_pipe_limit",
487 .data = &core_pipe_limit,
488 .maxlen = sizeof(unsigned int),
490 .proc_handler = proc_dointvec,
493 #ifdef CONFIG_PROC_SYSCTL
495 .procname = "tainted",
496 .maxlen = sizeof(long),
498 .proc_handler = proc_taint,
501 .procname = "sysctl_writes_strict",
502 .data = &sysctl_writes_strict,
503 .maxlen = sizeof(int),
505 .proc_handler = proc_dointvec_minmax,
510 #ifdef CONFIG_LATENCYTOP
512 .procname = "latencytop",
513 .data = &latencytop_enabled,
514 .maxlen = sizeof(int),
516 .proc_handler = proc_dointvec,
519 #ifdef CONFIG_BLK_DEV_INITRD
521 .procname = "real-root-dev",
522 .data = &real_root_dev,
523 .maxlen = sizeof(int),
525 .proc_handler = proc_dointvec,
529 .procname = "print-fatal-signals",
530 .data = &print_fatal_signals,
531 .maxlen = sizeof(int),
533 .proc_handler = proc_dointvec,
537 .procname = "reboot-cmd",
538 .data = reboot_command,
541 .proc_handler = proc_dostring,
544 .procname = "stop-a",
545 .data = &stop_a_enabled,
546 .maxlen = sizeof (int),
548 .proc_handler = proc_dointvec,
551 .procname = "scons-poweroff",
552 .data = &scons_pwroff,
553 .maxlen = sizeof (int),
555 .proc_handler = proc_dointvec,
558 #ifdef CONFIG_SPARC64
560 .procname = "tsb-ratio",
561 .data = &sysctl_tsb_ratio,
562 .maxlen = sizeof (int),
564 .proc_handler = proc_dointvec,
569 .procname = "soft-power",
570 .data = &pwrsw_enabled,
571 .maxlen = sizeof (int),
573 .proc_handler = proc_dointvec,
576 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
578 .procname = "unaligned-trap",
579 .data = &unaligned_enabled,
580 .maxlen = sizeof (int),
582 .proc_handler = proc_dointvec,
586 .procname = "ctrl-alt-del",
588 .maxlen = sizeof(int),
590 .proc_handler = proc_dointvec,
592 #ifdef CONFIG_FUNCTION_TRACER
594 .procname = "ftrace_enabled",
595 .data = &ftrace_enabled,
596 .maxlen = sizeof(int),
598 .proc_handler = ftrace_enable_sysctl,
601 #ifdef CONFIG_STACK_TRACER
603 .procname = "stack_tracer_enabled",
604 .data = &stack_tracer_enabled,
605 .maxlen = sizeof(int),
607 .proc_handler = stack_trace_sysctl,
610 #ifdef CONFIG_TRACING
612 .procname = "ftrace_dump_on_oops",
613 .data = &ftrace_dump_on_oops,
614 .maxlen = sizeof(int),
616 .proc_handler = proc_dointvec,
619 .procname = "traceoff_on_warning",
620 .data = &__disable_trace_on_warning,
621 .maxlen = sizeof(__disable_trace_on_warning),
623 .proc_handler = proc_dointvec,
628 .procname = "kexec_load_disabled",
629 .data = &kexec_load_disabled,
630 .maxlen = sizeof(int),
632 /* only handle a transition from default "0" to "1" */
633 .proc_handler = proc_dointvec_minmax,
638 #ifdef CONFIG_MODULES
640 .procname = "modprobe",
641 .data = &modprobe_path,
642 .maxlen = KMOD_PATH_LEN,
644 .proc_handler = proc_dostring,
647 .procname = "modules_disabled",
648 .data = &modules_disabled,
649 .maxlen = sizeof(int),
651 /* only handle a transition from default "0" to "1" */
652 .proc_handler = proc_dointvec_minmax,
657 #ifdef CONFIG_UEVENT_HELPER
659 .procname = "hotplug",
660 .data = &uevent_helper,
661 .maxlen = UEVENT_HELPER_PATH_LEN,
663 .proc_handler = proc_dostring,
666 #ifdef CONFIG_CHR_DEV_SG
668 .procname = "sg-big-buff",
669 .data = &sg_big_buff,
670 .maxlen = sizeof (int),
672 .proc_handler = proc_dointvec,
675 #ifdef CONFIG_BSD_PROCESS_ACCT
679 .maxlen = 3*sizeof(int),
681 .proc_handler = proc_dointvec,
684 #ifdef CONFIG_MAGIC_SYSRQ
687 .data = &__sysrq_enabled,
688 .maxlen = sizeof (int),
690 .proc_handler = sysrq_sysctl_handler,
693 #ifdef CONFIG_PROC_SYSCTL
695 .procname = "cad_pid",
697 .maxlen = sizeof (int),
699 .proc_handler = proc_do_cad_pid,
703 .procname = "threads-max",
704 .data = &max_threads,
705 .maxlen = sizeof(int),
707 .proc_handler = proc_dointvec,
710 .procname = "random",
712 .child = random_table,
715 .procname = "usermodehelper",
717 .child = usermodehelper_table,
720 .procname = "overflowuid",
721 .data = &overflowuid,
722 .maxlen = sizeof(int),
724 .proc_handler = proc_dointvec_minmax,
725 .extra1 = &minolduid,
726 .extra2 = &maxolduid,
729 .procname = "overflowgid",
730 .data = &overflowgid,
731 .maxlen = sizeof(int),
733 .proc_handler = proc_dointvec_minmax,
734 .extra1 = &minolduid,
735 .extra2 = &maxolduid,
738 #ifdef CONFIG_MATHEMU
740 .procname = "ieee_emulation_warnings",
741 .data = &sysctl_ieee_emulation_warnings,
742 .maxlen = sizeof(int),
744 .proc_handler = proc_dointvec,
748 .procname = "userprocess_debug",
749 .data = &show_unhandled_signals,
750 .maxlen = sizeof(int),
752 .proc_handler = proc_dointvec,
756 .procname = "pid_max",
758 .maxlen = sizeof (int),
760 .proc_handler = proc_dointvec_minmax,
761 .extra1 = &pid_max_min,
762 .extra2 = &pid_max_max,
765 .procname = "panic_on_oops",
766 .data = &panic_on_oops,
767 .maxlen = sizeof(int),
769 .proc_handler = proc_dointvec,
771 #if defined CONFIG_PRINTK
773 .procname = "printk",
774 .data = &console_loglevel,
775 .maxlen = 4*sizeof(int),
777 .proc_handler = proc_dointvec,
780 .procname = "printk_ratelimit",
781 .data = &printk_ratelimit_state.interval,
782 .maxlen = sizeof(int),
784 .proc_handler = proc_dointvec_jiffies,
787 .procname = "printk_ratelimit_burst",
788 .data = &printk_ratelimit_state.burst,
789 .maxlen = sizeof(int),
791 .proc_handler = proc_dointvec,
794 .procname = "printk_delay",
795 .data = &printk_delay_msec,
796 .maxlen = sizeof(int),
798 .proc_handler = proc_dointvec_minmax,
800 .extra2 = &ten_thousand,
803 .procname = "dmesg_restrict",
804 .data = &dmesg_restrict,
805 .maxlen = sizeof(int),
807 .proc_handler = proc_dointvec_minmax_sysadmin,
812 .procname = "kptr_restrict",
813 .data = &kptr_restrict,
814 .maxlen = sizeof(int),
816 .proc_handler = proc_dointvec_minmax_sysadmin,
822 .procname = "ngroups_max",
823 .data = &ngroups_max,
824 .maxlen = sizeof (int),
826 .proc_handler = proc_dointvec,
829 .procname = "cap_last_cap",
830 .data = (void *)&cap_last_cap,
831 .maxlen = sizeof(int),
833 .proc_handler = proc_dointvec,
835 #if defined(CONFIG_LOCKUP_DETECTOR)
837 .procname = "watchdog",
838 .data = &watchdog_user_enabled,
839 .maxlen = sizeof (int),
841 .proc_handler = proc_dowatchdog,
846 .procname = "watchdog_thresh",
847 .data = &watchdog_thresh,
848 .maxlen = sizeof(int),
850 .proc_handler = proc_dowatchdog,
855 .procname = "softlockup_panic",
856 .data = &softlockup_panic,
857 .maxlen = sizeof(int),
859 .proc_handler = proc_dointvec_minmax,
865 .procname = "softlockup_all_cpu_backtrace",
866 .data = &sysctl_softlockup_all_cpu_backtrace,
867 .maxlen = sizeof(int),
869 .proc_handler = proc_dointvec_minmax,
873 #endif /* CONFIG_SMP */
875 .procname = "nmi_watchdog",
876 .data = &watchdog_user_enabled,
877 .maxlen = sizeof (int),
879 .proc_handler = proc_dowatchdog,
884 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
886 .procname = "unknown_nmi_panic",
887 .data = &unknown_nmi_panic,
888 .maxlen = sizeof (int),
890 .proc_handler = proc_dointvec,
893 #if defined(CONFIG_X86)
895 .procname = "panic_on_unrecovered_nmi",
896 .data = &panic_on_unrecovered_nmi,
897 .maxlen = sizeof(int),
899 .proc_handler = proc_dointvec,
902 .procname = "panic_on_io_nmi",
903 .data = &panic_on_io_nmi,
904 .maxlen = sizeof(int),
906 .proc_handler = proc_dointvec,
908 #ifdef CONFIG_DEBUG_STACKOVERFLOW
910 .procname = "panic_on_stackoverflow",
911 .data = &sysctl_panic_on_stackoverflow,
912 .maxlen = sizeof(int),
914 .proc_handler = proc_dointvec,
918 .procname = "bootloader_type",
919 .data = &bootloader_type,
920 .maxlen = sizeof (int),
922 .proc_handler = proc_dointvec,
925 .procname = "bootloader_version",
926 .data = &bootloader_version,
927 .maxlen = sizeof (int),
929 .proc_handler = proc_dointvec,
932 .procname = "kstack_depth_to_print",
933 .data = &kstack_depth_to_print,
934 .maxlen = sizeof(int),
936 .proc_handler = proc_dointvec,
939 .procname = "io_delay_type",
940 .data = &io_delay_type,
941 .maxlen = sizeof(int),
943 .proc_handler = proc_dointvec,
946 #if defined(CONFIG_MMU)
948 .procname = "randomize_va_space",
949 .data = &randomize_va_space,
950 .maxlen = sizeof(int),
952 .proc_handler = proc_dointvec,
955 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
957 .procname = "spin_retry",
959 .maxlen = sizeof (int),
961 .proc_handler = proc_dointvec,
964 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
966 .procname = "acpi_video_flags",
967 .data = &acpi_realmode_flags,
968 .maxlen = sizeof (unsigned long),
970 .proc_handler = proc_doulongvec_minmax,
973 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
975 .procname = "ignore-unaligned-usertrap",
976 .data = &no_unaligned_warning,
977 .maxlen = sizeof (int),
979 .proc_handler = proc_dointvec,
984 .procname = "unaligned-dump-stack",
985 .data = &unaligned_dump_stack,
986 .maxlen = sizeof (int),
988 .proc_handler = proc_dointvec,
991 #ifdef CONFIG_DETECT_HUNG_TASK
993 .procname = "hung_task_panic",
994 .data = &sysctl_hung_task_panic,
995 .maxlen = sizeof(int),
997 .proc_handler = proc_dointvec_minmax,
1002 .procname = "hung_task_check_count",
1003 .data = &sysctl_hung_task_check_count,
1004 .maxlen = sizeof(int),
1006 .proc_handler = proc_dointvec_minmax,
1010 .procname = "hung_task_timeout_secs",
1011 .data = &sysctl_hung_task_timeout_secs,
1012 .maxlen = sizeof(unsigned long),
1014 .proc_handler = proc_dohung_task_timeout_secs,
1015 .extra2 = &hung_task_timeout_max,
1018 .procname = "hung_task_warnings",
1019 .data = &sysctl_hung_task_warnings,
1020 .maxlen = sizeof(int),
1022 .proc_handler = proc_dointvec_minmax,
1026 #ifdef CONFIG_COMPAT
1028 .procname = "compat-log",
1029 .data = &compat_log,
1030 .maxlen = sizeof (int),
1032 .proc_handler = proc_dointvec,
1035 #ifdef CONFIG_RT_MUTEXES
1037 .procname = "max_lock_depth",
1038 .data = &max_lock_depth,
1039 .maxlen = sizeof(int),
1041 .proc_handler = proc_dointvec,
1045 .procname = "poweroff_cmd",
1046 .data = &poweroff_cmd,
1047 .maxlen = POWEROFF_CMD_PATH_LEN,
1049 .proc_handler = proc_dostring,
1055 .child = key_sysctls,
1058 #ifdef CONFIG_PERF_EVENTS
1060 * User-space scripts rely on the existence of this file
1061 * as a feature check for perf_events being enabled.
1063 * So it's an ABI, do not remove!
1066 .procname = "perf_event_paranoid",
1067 .data = &sysctl_perf_event_paranoid,
1068 .maxlen = sizeof(sysctl_perf_event_paranoid),
1070 .proc_handler = proc_dointvec,
1073 .procname = "perf_event_mlock_kb",
1074 .data = &sysctl_perf_event_mlock,
1075 .maxlen = sizeof(sysctl_perf_event_mlock),
1077 .proc_handler = proc_dointvec,
1080 .procname = "perf_event_max_sample_rate",
1081 .data = &sysctl_perf_event_sample_rate,
1082 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1084 .proc_handler = perf_proc_update_handler,
1088 .procname = "perf_cpu_time_max_percent",
1089 .data = &sysctl_perf_cpu_time_max_percent,
1090 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1092 .proc_handler = perf_cpu_time_max_percent_handler,
1094 .extra2 = &one_hundred,
1097 #ifdef CONFIG_KMEMCHECK
1099 .procname = "kmemcheck",
1100 .data = &kmemcheck_enabled,
1101 .maxlen = sizeof(int),
1103 .proc_handler = proc_dointvec,
1109 static struct ctl_table vm_table[] = {
1111 .procname = "overcommit_memory",
1112 .data = &sysctl_overcommit_memory,
1113 .maxlen = sizeof(sysctl_overcommit_memory),
1115 .proc_handler = proc_dointvec_minmax,
1120 .procname = "panic_on_oom",
1121 .data = &sysctl_panic_on_oom,
1122 .maxlen = sizeof(sysctl_panic_on_oom),
1124 .proc_handler = proc_dointvec_minmax,
1129 .procname = "oom_kill_allocating_task",
1130 .data = &sysctl_oom_kill_allocating_task,
1131 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1133 .proc_handler = proc_dointvec,
1136 .procname = "oom_dump_tasks",
1137 .data = &sysctl_oom_dump_tasks,
1138 .maxlen = sizeof(sysctl_oom_dump_tasks),
1140 .proc_handler = proc_dointvec,
1143 .procname = "overcommit_ratio",
1144 .data = &sysctl_overcommit_ratio,
1145 .maxlen = sizeof(sysctl_overcommit_ratio),
1147 .proc_handler = overcommit_ratio_handler,
1150 .procname = "overcommit_kbytes",
1151 .data = &sysctl_overcommit_kbytes,
1152 .maxlen = sizeof(sysctl_overcommit_kbytes),
1154 .proc_handler = overcommit_kbytes_handler,
1157 .procname = "page-cluster",
1158 .data = &page_cluster,
1159 .maxlen = sizeof(int),
1161 .proc_handler = proc_dointvec_minmax,
1165 .procname = "dirty_background_ratio",
1166 .data = &dirty_background_ratio,
1167 .maxlen = sizeof(dirty_background_ratio),
1169 .proc_handler = dirty_background_ratio_handler,
1171 .extra2 = &one_hundred,
1174 .procname = "dirty_background_bytes",
1175 .data = &dirty_background_bytes,
1176 .maxlen = sizeof(dirty_background_bytes),
1178 .proc_handler = dirty_background_bytes_handler,
1182 .procname = "dirty_ratio",
1183 .data = &vm_dirty_ratio,
1184 .maxlen = sizeof(vm_dirty_ratio),
1186 .proc_handler = dirty_ratio_handler,
1188 .extra2 = &one_hundred,
1191 .procname = "dirty_bytes",
1192 .data = &vm_dirty_bytes,
1193 .maxlen = sizeof(vm_dirty_bytes),
1195 .proc_handler = dirty_bytes_handler,
1196 .extra1 = &dirty_bytes_min,
1199 .procname = "dirty_writeback_centisecs",
1200 .data = &dirty_writeback_interval,
1201 .maxlen = sizeof(dirty_writeback_interval),
1203 .proc_handler = dirty_writeback_centisecs_handler,
1206 .procname = "dirty_expire_centisecs",
1207 .data = &dirty_expire_interval,
1208 .maxlen = sizeof(dirty_expire_interval),
1210 .proc_handler = proc_dointvec_minmax,
1214 .procname = "nr_pdflush_threads",
1215 .mode = 0444 /* read-only */,
1216 .proc_handler = pdflush_proc_obsolete,
1219 .procname = "swappiness",
1220 .data = &vm_swappiness,
1221 .maxlen = sizeof(vm_swappiness),
1223 .proc_handler = proc_dointvec_minmax,
1225 .extra2 = &one_hundred,
1227 #ifdef CONFIG_HUGETLB_PAGE
1229 .procname = "nr_hugepages",
1231 .maxlen = sizeof(unsigned long),
1233 .proc_handler = hugetlb_sysctl_handler,
1238 .procname = "nr_hugepages_mempolicy",
1240 .maxlen = sizeof(unsigned long),
1242 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1247 .procname = "hugetlb_shm_group",
1248 .data = &sysctl_hugetlb_shm_group,
1249 .maxlen = sizeof(gid_t),
1251 .proc_handler = proc_dointvec,
1254 .procname = "hugepages_treat_as_movable",
1255 .data = &hugepages_treat_as_movable,
1256 .maxlen = sizeof(int),
1258 .proc_handler = proc_dointvec,
1261 .procname = "nr_overcommit_hugepages",
1263 .maxlen = sizeof(unsigned long),
1265 .proc_handler = hugetlb_overcommit_handler,
1270 .procname = "lowmem_reserve_ratio",
1271 .data = &sysctl_lowmem_reserve_ratio,
1272 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1274 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1277 .procname = "drop_caches",
1278 .data = &sysctl_drop_caches,
1279 .maxlen = sizeof(int),
1281 .proc_handler = drop_caches_sysctl_handler,
1285 #ifdef CONFIG_COMPACTION
1287 .procname = "compact_memory",
1288 .data = &sysctl_compact_memory,
1289 .maxlen = sizeof(int),
1291 .proc_handler = sysctl_compaction_handler,
1294 .procname = "extfrag_threshold",
1295 .data = &sysctl_extfrag_threshold,
1296 .maxlen = sizeof(int),
1298 .proc_handler = sysctl_extfrag_handler,
1299 .extra1 = &min_extfrag_threshold,
1300 .extra2 = &max_extfrag_threshold,
1303 #endif /* CONFIG_COMPACTION */
1305 .procname = "min_free_kbytes",
1306 .data = &min_free_kbytes,
1307 .maxlen = sizeof(min_free_kbytes),
1309 .proc_handler = min_free_kbytes_sysctl_handler,
1313 .procname = "percpu_pagelist_fraction",
1314 .data = &percpu_pagelist_fraction,
1315 .maxlen = sizeof(percpu_pagelist_fraction),
1317 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1322 .procname = "max_map_count",
1323 .data = &sysctl_max_map_count,
1324 .maxlen = sizeof(sysctl_max_map_count),
1326 .proc_handler = proc_dointvec_minmax,
1331 .procname = "nr_trim_pages",
1332 .data = &sysctl_nr_trim_pages,
1333 .maxlen = sizeof(sysctl_nr_trim_pages),
1335 .proc_handler = proc_dointvec_minmax,
1340 .procname = "laptop_mode",
1341 .data = &laptop_mode,
1342 .maxlen = sizeof(laptop_mode),
1344 .proc_handler = proc_dointvec_jiffies,
1347 .procname = "block_dump",
1348 .data = &block_dump,
1349 .maxlen = sizeof(block_dump),
1351 .proc_handler = proc_dointvec,
1355 .procname = "vfs_cache_pressure",
1356 .data = &sysctl_vfs_cache_pressure,
1357 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1359 .proc_handler = proc_dointvec,
1362 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1364 .procname = "legacy_va_layout",
1365 .data = &sysctl_legacy_va_layout,
1366 .maxlen = sizeof(sysctl_legacy_va_layout),
1368 .proc_handler = proc_dointvec,
1374 .procname = "zone_reclaim_mode",
1375 .data = &zone_reclaim_mode,
1376 .maxlen = sizeof(zone_reclaim_mode),
1378 .proc_handler = proc_dointvec,
1382 .procname = "min_unmapped_ratio",
1383 .data = &sysctl_min_unmapped_ratio,
1384 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1386 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1388 .extra2 = &one_hundred,
1391 .procname = "min_slab_ratio",
1392 .data = &sysctl_min_slab_ratio,
1393 .maxlen = sizeof(sysctl_min_slab_ratio),
1395 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1397 .extra2 = &one_hundred,
1402 .procname = "stat_interval",
1403 .data = &sysctl_stat_interval,
1404 .maxlen = sizeof(sysctl_stat_interval),
1406 .proc_handler = proc_dointvec_jiffies,
1411 .procname = "mmap_min_addr",
1412 .data = &dac_mmap_min_addr,
1413 .maxlen = sizeof(unsigned long),
1415 .proc_handler = mmap_min_addr_handler,
1420 .procname = "numa_zonelist_order",
1421 .data = &numa_zonelist_order,
1422 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1424 .proc_handler = numa_zonelist_order_handler,
1427 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1428 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1430 .procname = "vdso_enabled",
1431 #ifdef CONFIG_X86_32
1432 .data = &vdso32_enabled,
1433 .maxlen = sizeof(vdso32_enabled),
1435 .data = &vdso_enabled,
1436 .maxlen = sizeof(vdso_enabled),
1439 .proc_handler = proc_dointvec,
1443 #ifdef CONFIG_HIGHMEM
1445 .procname = "highmem_is_dirtyable",
1446 .data = &vm_highmem_is_dirtyable,
1447 .maxlen = sizeof(vm_highmem_is_dirtyable),
1449 .proc_handler = proc_dointvec_minmax,
1455 .procname = "scan_unevictable_pages",
1456 .data = &scan_unevictable_pages,
1457 .maxlen = sizeof(scan_unevictable_pages),
1459 .proc_handler = scan_unevictable_handler,
1461 #ifdef CONFIG_MEMORY_FAILURE
1463 .procname = "memory_failure_early_kill",
1464 .data = &sysctl_memory_failure_early_kill,
1465 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1467 .proc_handler = proc_dointvec_minmax,
1472 .procname = "memory_failure_recovery",
1473 .data = &sysctl_memory_failure_recovery,
1474 .maxlen = sizeof(sysctl_memory_failure_recovery),
1476 .proc_handler = proc_dointvec_minmax,
1482 .procname = "user_reserve_kbytes",
1483 .data = &sysctl_user_reserve_kbytes,
1484 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1486 .proc_handler = proc_doulongvec_minmax,
1489 .procname = "admin_reserve_kbytes",
1490 .data = &sysctl_admin_reserve_kbytes,
1491 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1493 .proc_handler = proc_doulongvec_minmax,
1498 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1499 static struct ctl_table binfmt_misc_table[] = {
1504 static struct ctl_table fs_table[] = {
1506 .procname = "inode-nr",
1507 .data = &inodes_stat,
1508 .maxlen = 2*sizeof(long),
1510 .proc_handler = proc_nr_inodes,
1513 .procname = "inode-state",
1514 .data = &inodes_stat,
1515 .maxlen = 7*sizeof(long),
1517 .proc_handler = proc_nr_inodes,
1520 .procname = "file-nr",
1521 .data = &files_stat,
1522 .maxlen = sizeof(files_stat),
1524 .proc_handler = proc_nr_files,
1527 .procname = "file-max",
1528 .data = &files_stat.max_files,
1529 .maxlen = sizeof(files_stat.max_files),
1531 .proc_handler = proc_doulongvec_minmax,
1534 .procname = "nr_open",
1535 .data = &sysctl_nr_open,
1536 .maxlen = sizeof(int),
1538 .proc_handler = proc_dointvec_minmax,
1539 .extra1 = &sysctl_nr_open_min,
1540 .extra2 = &sysctl_nr_open_max,
1543 .procname = "dentry-state",
1544 .data = &dentry_stat,
1545 .maxlen = 6*sizeof(long),
1547 .proc_handler = proc_nr_dentry,
1550 .procname = "overflowuid",
1551 .data = &fs_overflowuid,
1552 .maxlen = sizeof(int),
1554 .proc_handler = proc_dointvec_minmax,
1555 .extra1 = &minolduid,
1556 .extra2 = &maxolduid,
1559 .procname = "overflowgid",
1560 .data = &fs_overflowgid,
1561 .maxlen = sizeof(int),
1563 .proc_handler = proc_dointvec_minmax,
1564 .extra1 = &minolduid,
1565 .extra2 = &maxolduid,
1567 #ifdef CONFIG_FILE_LOCKING
1569 .procname = "leases-enable",
1570 .data = &leases_enable,
1571 .maxlen = sizeof(int),
1573 .proc_handler = proc_dointvec,
1576 #ifdef CONFIG_DNOTIFY
1578 .procname = "dir-notify-enable",
1579 .data = &dir_notify_enable,
1580 .maxlen = sizeof(int),
1582 .proc_handler = proc_dointvec,
1586 #ifdef CONFIG_FILE_LOCKING
1588 .procname = "lease-break-time",
1589 .data = &lease_break_time,
1590 .maxlen = sizeof(int),
1592 .proc_handler = proc_dointvec,
1597 .procname = "aio-nr",
1599 .maxlen = sizeof(aio_nr),
1601 .proc_handler = proc_doulongvec_minmax,
1604 .procname = "aio-max-nr",
1605 .data = &aio_max_nr,
1606 .maxlen = sizeof(aio_max_nr),
1608 .proc_handler = proc_doulongvec_minmax,
1610 #endif /* CONFIG_AIO */
1611 #ifdef CONFIG_INOTIFY_USER
1613 .procname = "inotify",
1615 .child = inotify_table,
1620 .procname = "epoll",
1622 .child = epoll_table,
1627 .procname = "protected_symlinks",
1628 .data = &sysctl_protected_symlinks,
1629 .maxlen = sizeof(int),
1631 .proc_handler = proc_dointvec_minmax,
1636 .procname = "protected_hardlinks",
1637 .data = &sysctl_protected_hardlinks,
1638 .maxlen = sizeof(int),
1640 .proc_handler = proc_dointvec_minmax,
1645 .procname = "suid_dumpable",
1646 .data = &suid_dumpable,
1647 .maxlen = sizeof(int),
1649 .proc_handler = proc_dointvec_minmax_coredump,
1653 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1655 .procname = "binfmt_misc",
1657 .child = binfmt_misc_table,
1661 .procname = "pipe-max-size",
1662 .data = &pipe_max_size,
1663 .maxlen = sizeof(int),
1665 .proc_handler = &pipe_proc_fn,
1666 .extra1 = &pipe_min_size,
1671 static struct ctl_table debug_table[] = {
1672 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1674 .procname = "exception-trace",
1675 .data = &show_unhandled_signals,
1676 .maxlen = sizeof(int),
1678 .proc_handler = proc_dointvec
1681 #if defined(CONFIG_OPTPROBES)
1683 .procname = "kprobes-optimization",
1684 .data = &sysctl_kprobes_optimization,
1685 .maxlen = sizeof(int),
1687 .proc_handler = proc_kprobes_optimization_handler,
1695 static struct ctl_table dev_table[] = {
1699 int __init sysctl_init(void)
1701 struct ctl_table_header *hdr;
1703 hdr = register_sysctl_table(sysctl_base_table);
1704 kmemleak_not_leak(hdr);
1708 #endif /* CONFIG_SYSCTL */
1714 #ifdef CONFIG_PROC_SYSCTL
1716 static int _proc_do_string(char *data, int maxlen, int write,
1717 char __user *buffer,
1718 size_t *lenp, loff_t *ppos)
1724 if (!data || !maxlen || !*lenp) {
1730 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1731 /* Only continue writes not past the end of buffer. */
1733 if (len > maxlen - 1)
1740 /* Start writing from beginning of buffer. */
1746 while ((p - buffer) < *lenp && len < maxlen - 1) {
1747 if (get_user(c, p++))
1749 if (c == 0 || c == '\n')
1770 if (copy_to_user(buffer, data, len))
1773 if (put_user('\n', buffer + len))
1783 static void warn_sysctl_write(struct ctl_table *table)
1785 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1786 "This will not be supported in the future. To silence this\n"
1787 "warning, set kernel.sysctl_writes_strict = -1\n",
1788 current->comm, table->procname);
1792 * proc_dostring - read a string sysctl
1793 * @table: the sysctl table
1794 * @write: %TRUE if this is a write to the sysctl file
1795 * @buffer: the user buffer
1796 * @lenp: the size of the user buffer
1797 * @ppos: file position
1799 * Reads/writes a string from/to the user buffer. If the kernel
1800 * buffer provided is not large enough to hold the string, the
1801 * string is truncated. The copied string is %NULL-terminated.
1802 * If the string is being read by the user process, it is copied
1803 * and a newline '\n' is added. It is truncated if the buffer is
1806 * Returns 0 on success.
1808 int proc_dostring(struct ctl_table *table, int write,
1809 void __user *buffer, size_t *lenp, loff_t *ppos)
1811 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1812 warn_sysctl_write(table);
1814 return _proc_do_string((char *)(table->data), table->maxlen, write,
1815 (char __user *)buffer, lenp, ppos);
1818 static size_t proc_skip_spaces(char **buf)
1821 char *tmp = skip_spaces(*buf);
1827 static void proc_skip_char(char **buf, size_t *size, const char v)
1837 #define TMPBUFLEN 22
1839 * proc_get_long - reads an ASCII formatted integer from a user buffer
1841 * @buf: a kernel buffer
1842 * @size: size of the kernel buffer
1843 * @val: this is where the number will be stored
1844 * @neg: set to %TRUE if number is negative
1845 * @perm_tr: a vector which contains the allowed trailers
1846 * @perm_tr_len: size of the perm_tr vector
1847 * @tr: pointer to store the trailer character
1849 * In case of success %0 is returned and @buf and @size are updated with
1850 * the amount of bytes read. If @tr is non-NULL and a trailing
1851 * character exists (size is non-zero after returning from this
1852 * function), @tr is updated with the trailing character.
1854 static int proc_get_long(char **buf, size_t *size,
1855 unsigned long *val, bool *neg,
1856 const char *perm_tr, unsigned perm_tr_len, char *tr)
1859 char *p, tmp[TMPBUFLEN];
1865 if (len > TMPBUFLEN - 1)
1866 len = TMPBUFLEN - 1;
1868 memcpy(tmp, *buf, len);
1872 if (*p == '-' && *size > 1) {
1880 *val = simple_strtoul(p, &p, 0);
1884 /* We don't know if the next char is whitespace thus we may accept
1885 * invalid integers (e.g. 1234...a) or two integers instead of one
1886 * (e.g. 123...1). So lets not allow such large numbers. */
1887 if (len == TMPBUFLEN - 1)
1890 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1893 if (tr && (len < *size))
1903 * proc_put_long - converts an integer to a decimal ASCII formatted string
1905 * @buf: the user buffer
1906 * @size: the size of the user buffer
1907 * @val: the integer to be converted
1908 * @neg: sign of the number, %TRUE for negative
1910 * In case of success %0 is returned and @buf and @size are updated with
1911 * the amount of bytes written.
1913 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1917 char tmp[TMPBUFLEN], *p = tmp;
1919 sprintf(p, "%s%lu", neg ? "-" : "", val);
1923 if (copy_to_user(*buf, tmp, len))
1931 static int proc_put_char(void __user **buf, size_t *size, char c)
1934 char __user **buffer = (char __user **)buf;
1935 if (put_user(c, *buffer))
1937 (*size)--, (*buffer)++;
1943 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1945 int write, void *data)
1948 *valp = *negp ? -*lvalp : *lvalp;
1953 *lvalp = (unsigned long)-val;
1956 *lvalp = (unsigned long)val;
1962 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1964 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1965 int write, void __user *buffer,
1966 size_t *lenp, loff_t *ppos,
1967 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1968 int write, void *data),
1971 int *i, vleft, first = 1, err = 0;
1972 unsigned long page = 0;
1976 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1981 i = (int *) tbl_data;
1982 vleft = table->maxlen / sizeof(*i);
1986 conv = do_proc_dointvec_conv;
1990 switch (sysctl_writes_strict) {
1991 case SYSCTL_WRITES_STRICT:
1993 case SYSCTL_WRITES_WARN:
1994 warn_sysctl_write(table);
2001 if (left > PAGE_SIZE - 1)
2002 left = PAGE_SIZE - 1;
2003 page = __get_free_page(GFP_TEMPORARY);
2004 kbuf = (char *) page;
2007 if (copy_from_user(kbuf, buffer, left)) {
2014 for (; left && vleft--; i++, first=0) {
2019 left -= proc_skip_spaces(&kbuf);
2023 err = proc_get_long(&kbuf, &left, &lval, &neg,
2025 sizeof(proc_wspace_sep), NULL);
2028 if (conv(&neg, &lval, i, 1, data)) {
2033 if (conv(&neg, &lval, i, 0, data)) {
2038 err = proc_put_char(&buffer, &left, '\t');
2041 err = proc_put_long(&buffer, &left, lval, neg);
2047 if (!write && !first && left && !err)
2048 err = proc_put_char(&buffer, &left, '\n');
2049 if (write && !err && left)
2050 left -= proc_skip_spaces(&kbuf);
2055 return err ? : -EINVAL;
2063 static int do_proc_dointvec(struct ctl_table *table, int write,
2064 void __user *buffer, size_t *lenp, loff_t *ppos,
2065 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2066 int write, void *data),
2069 return __do_proc_dointvec(table->data, table, write,
2070 buffer, lenp, ppos, conv, data);
2074 * proc_dointvec - read a vector of integers
2075 * @table: the sysctl table
2076 * @write: %TRUE if this is a write to the sysctl file
2077 * @buffer: the user buffer
2078 * @lenp: the size of the user buffer
2079 * @ppos: file position
2081 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2082 * values from/to the user buffer, treated as an ASCII string.
2084 * Returns 0 on success.
2086 int proc_dointvec(struct ctl_table *table, int write,
2087 void __user *buffer, size_t *lenp, loff_t *ppos)
2089 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2094 * Taint values can only be increased
2095 * This means we can safely use a temporary.
2097 static int proc_taint(struct ctl_table *table, int write,
2098 void __user *buffer, size_t *lenp, loff_t *ppos)
2101 unsigned long tmptaint = get_taint();
2104 if (write && !capable(CAP_SYS_ADMIN))
2109 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2115 * Poor man's atomic or. Not worth adding a primitive
2116 * to everyone's atomic.h for this
2119 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2120 if ((tmptaint >> i) & 1)
2121 add_taint(i, LOCKDEP_STILL_OK);
2128 #ifdef CONFIG_PRINTK
2129 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2130 void __user *buffer, size_t *lenp, loff_t *ppos)
2132 if (write && !capable(CAP_SYS_ADMIN))
2135 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2139 struct do_proc_dointvec_minmax_conv_param {
2144 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2146 int write, void *data)
2148 struct do_proc_dointvec_minmax_conv_param *param = data;
2150 int val = *negp ? -*lvalp : *lvalp;
2151 if ((param->min && *param->min > val) ||
2152 (param->max && *param->max < val))
2159 *lvalp = (unsigned long)-val;
2162 *lvalp = (unsigned long)val;
2169 * proc_dointvec_minmax - read a vector of integers with min/max values
2170 * @table: the sysctl table
2171 * @write: %TRUE if this is a write to the sysctl file
2172 * @buffer: the user buffer
2173 * @lenp: the size of the user buffer
2174 * @ppos: file position
2176 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2177 * values from/to the user buffer, treated as an ASCII string.
2179 * This routine will ensure the values are within the range specified by
2180 * table->extra1 (min) and table->extra2 (max).
2182 * Returns 0 on success.
2184 int proc_dointvec_minmax(struct ctl_table *table, int write,
2185 void __user *buffer, size_t *lenp, loff_t *ppos)
2187 struct do_proc_dointvec_minmax_conv_param param = {
2188 .min = (int *) table->extra1,
2189 .max = (int *) table->extra2,
2191 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2192 do_proc_dointvec_minmax_conv, ¶m);
2195 static void validate_coredump_safety(void)
2197 #ifdef CONFIG_COREDUMP
2198 if (suid_dumpable == SUID_DUMP_ROOT &&
2199 core_pattern[0] != '/' && core_pattern[0] != '|') {
2200 printk(KERN_WARNING "Unsafe core_pattern used with "\
2201 "suid_dumpable=2. Pipe handler or fully qualified "\
2202 "core dump path required.\n");
2207 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2208 void __user *buffer, size_t *lenp, loff_t *ppos)
2210 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2212 validate_coredump_safety();
2216 #ifdef CONFIG_COREDUMP
2217 static int proc_dostring_coredump(struct ctl_table *table, int write,
2218 void __user *buffer, size_t *lenp, loff_t *ppos)
2220 int error = proc_dostring(table, write, buffer, lenp, ppos);
2222 validate_coredump_safety();
2227 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2228 void __user *buffer,
2229 size_t *lenp, loff_t *ppos,
2230 unsigned long convmul,
2231 unsigned long convdiv)
2233 unsigned long *i, *min, *max;
2234 int vleft, first = 1, err = 0;
2235 unsigned long page = 0;
2239 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2244 i = (unsigned long *) data;
2245 min = (unsigned long *) table->extra1;
2246 max = (unsigned long *) table->extra2;
2247 vleft = table->maxlen / sizeof(unsigned long);
2252 switch (sysctl_writes_strict) {
2253 case SYSCTL_WRITES_STRICT:
2255 case SYSCTL_WRITES_WARN:
2256 warn_sysctl_write(table);
2263 if (left > PAGE_SIZE - 1)
2264 left = PAGE_SIZE - 1;
2265 page = __get_free_page(GFP_TEMPORARY);
2266 kbuf = (char *) page;
2269 if (copy_from_user(kbuf, buffer, left)) {
2276 for (; left && vleft--; i++, first = 0) {
2282 left -= proc_skip_spaces(&kbuf);
2284 err = proc_get_long(&kbuf, &left, &val, &neg,
2286 sizeof(proc_wspace_sep), NULL);
2291 if ((min && val < *min) || (max && val > *max))
2295 val = convdiv * (*i) / convmul;
2297 err = proc_put_char(&buffer, &left, '\t');
2301 err = proc_put_long(&buffer, &left, val, false);
2307 if (!write && !first && left && !err)
2308 err = proc_put_char(&buffer, &left, '\n');
2310 left -= proc_skip_spaces(&kbuf);
2315 return err ? : -EINVAL;
2323 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2324 void __user *buffer,
2325 size_t *lenp, loff_t *ppos,
2326 unsigned long convmul,
2327 unsigned long convdiv)
2329 return __do_proc_doulongvec_minmax(table->data, table, write,
2330 buffer, lenp, ppos, convmul, convdiv);
2334 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2335 * @table: the sysctl table
2336 * @write: %TRUE if this is a write to the sysctl file
2337 * @buffer: the user buffer
2338 * @lenp: the size of the user buffer
2339 * @ppos: file position
2341 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2342 * values from/to the user buffer, treated as an ASCII string.
2344 * This routine will ensure the values are within the range specified by
2345 * table->extra1 (min) and table->extra2 (max).
2347 * Returns 0 on success.
2349 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2350 void __user *buffer, size_t *lenp, loff_t *ppos)
2352 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2356 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2357 * @table: the sysctl table
2358 * @write: %TRUE if this is a write to the sysctl file
2359 * @buffer: the user buffer
2360 * @lenp: the size of the user buffer
2361 * @ppos: file position
2363 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2364 * values from/to the user buffer, treated as an ASCII string. The values
2365 * are treated as milliseconds, and converted to jiffies when they are stored.
2367 * This routine will ensure the values are within the range specified by
2368 * table->extra1 (min) and table->extra2 (max).
2370 * Returns 0 on success.
2372 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2373 void __user *buffer,
2374 size_t *lenp, loff_t *ppos)
2376 return do_proc_doulongvec_minmax(table, write, buffer,
2377 lenp, ppos, HZ, 1000l);
2381 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2383 int write, void *data)
2386 if (*lvalp > LONG_MAX / HZ)
2388 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2394 lval = (unsigned long)-val;
2397 lval = (unsigned long)val;
2404 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2406 int write, void *data)
2409 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2411 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2417 lval = (unsigned long)-val;
2420 lval = (unsigned long)val;
2422 *lvalp = jiffies_to_clock_t(lval);
2427 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2429 int write, void *data)
2432 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2442 lval = (unsigned long)-val;
2445 lval = (unsigned long)val;
2447 *lvalp = jiffies_to_msecs(lval);
2453 * proc_dointvec_jiffies - read a vector of integers as seconds
2454 * @table: the sysctl table
2455 * @write: %TRUE if this is a write to the sysctl file
2456 * @buffer: the user buffer
2457 * @lenp: the size of the user buffer
2458 * @ppos: file position
2460 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2461 * values from/to the user buffer, treated as an ASCII string.
2462 * The values read are assumed to be in seconds, and are converted into
2465 * Returns 0 on success.
2467 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2468 void __user *buffer, size_t *lenp, loff_t *ppos)
2470 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2471 do_proc_dointvec_jiffies_conv,NULL);
2475 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2476 * @table: the sysctl table
2477 * @write: %TRUE if this is a write to the sysctl file
2478 * @buffer: the user buffer
2479 * @lenp: the size of the user buffer
2480 * @ppos: pointer to the file position
2482 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2483 * values from/to the user buffer, treated as an ASCII string.
2484 * The values read are assumed to be in 1/USER_HZ seconds, and
2485 * are converted into jiffies.
2487 * Returns 0 on success.
2489 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2490 void __user *buffer, size_t *lenp, loff_t *ppos)
2492 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2493 do_proc_dointvec_userhz_jiffies_conv,NULL);
2497 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2498 * @table: the sysctl table
2499 * @write: %TRUE if this is a write to the sysctl file
2500 * @buffer: the user buffer
2501 * @lenp: the size of the user buffer
2502 * @ppos: file position
2503 * @ppos: the current position in the file
2505 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2506 * values from/to the user buffer, treated as an ASCII string.
2507 * The values read are assumed to be in 1/1000 seconds, and
2508 * are converted into jiffies.
2510 * Returns 0 on success.
2512 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2513 void __user *buffer, size_t *lenp, loff_t *ppos)
2515 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2516 do_proc_dointvec_ms_jiffies_conv, NULL);
2519 static int proc_do_cad_pid(struct ctl_table *table, int write,
2520 void __user *buffer, size_t *lenp, loff_t *ppos)
2522 struct pid *new_pid;
2526 tmp = pid_vnr(cad_pid);
2528 r = __do_proc_dointvec(&tmp, table, write, buffer,
2529 lenp, ppos, NULL, NULL);
2533 new_pid = find_get_pid(tmp);
2537 put_pid(xchg(&cad_pid, new_pid));
2542 * proc_do_large_bitmap - read/write from/to a large bitmap
2543 * @table: the sysctl table
2544 * @write: %TRUE if this is a write to the sysctl file
2545 * @buffer: the user buffer
2546 * @lenp: the size of the user buffer
2547 * @ppos: file position
2549 * The bitmap is stored at table->data and the bitmap length (in bits)
2552 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2553 * large bitmaps may be represented in a compact manner. Writing into
2554 * the file will clear the bitmap then update it with the given input.
2556 * Returns 0 on success.
2558 int proc_do_large_bitmap(struct ctl_table *table, int write,
2559 void __user *buffer, size_t *lenp, loff_t *ppos)
2563 size_t left = *lenp;
2564 unsigned long bitmap_len = table->maxlen;
2565 unsigned long *bitmap = *(unsigned long **) table->data;
2566 unsigned long *tmp_bitmap = NULL;
2567 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2569 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2575 unsigned long page = 0;
2578 if (left > PAGE_SIZE - 1)
2579 left = PAGE_SIZE - 1;
2581 page = __get_free_page(GFP_TEMPORARY);
2582 kbuf = (char *) page;
2585 if (copy_from_user(kbuf, buffer, left)) {
2591 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2597 proc_skip_char(&kbuf, &left, '\n');
2598 while (!err && left) {
2599 unsigned long val_a, val_b;
2602 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2606 if (val_a >= bitmap_len || neg) {
2618 err = proc_get_long(&kbuf, &left, &val_b,
2619 &neg, tr_b, sizeof(tr_b),
2623 if (val_b >= bitmap_len || neg ||
2634 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2636 proc_skip_char(&kbuf, &left, '\n');
2640 unsigned long bit_a, bit_b = 0;
2643 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2644 if (bit_a >= bitmap_len)
2646 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2650 err = proc_put_char(&buffer, &left, ',');
2654 err = proc_put_long(&buffer, &left, bit_a, false);
2657 if (bit_a != bit_b) {
2658 err = proc_put_char(&buffer, &left, '-');
2661 err = proc_put_long(&buffer, &left, bit_b, false);
2669 err = proc_put_char(&buffer, &left, '\n');
2675 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2677 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2689 #else /* CONFIG_PROC_SYSCTL */
2691 int proc_dostring(struct ctl_table *table, int write,
2692 void __user *buffer, size_t *lenp, loff_t *ppos)
2697 int proc_dointvec(struct ctl_table *table, int write,
2698 void __user *buffer, size_t *lenp, loff_t *ppos)
2703 int proc_dointvec_minmax(struct ctl_table *table, int write,
2704 void __user *buffer, size_t *lenp, loff_t *ppos)
2709 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2710 void __user *buffer, size_t *lenp, loff_t *ppos)
2715 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2716 void __user *buffer, size_t *lenp, loff_t *ppos)
2721 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2722 void __user *buffer, size_t *lenp, loff_t *ppos)
2727 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2728 void __user *buffer, size_t *lenp, loff_t *ppos)
2733 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2734 void __user *buffer,
2735 size_t *lenp, loff_t *ppos)
2741 #endif /* CONFIG_PROC_SYSCTL */
2744 * No sense putting this after each symbol definition, twice,
2745 * exception granted :-)
2747 EXPORT_SYMBOL(proc_dointvec);
2748 EXPORT_SYMBOL(proc_dointvec_jiffies);
2749 EXPORT_SYMBOL(proc_dointvec_minmax);
2750 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2751 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2752 EXPORT_SYMBOL(proc_dostring);
2753 EXPORT_SYMBOL(proc_doulongvec_minmax);
2754 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);