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 extern int blk_iopoll_enabled;
119 /* Constants used for minimum and maximum */
120 #ifdef CONFIG_LOCKUP_DETECTOR
121 static int sixty = 60;
125 static int __maybe_unused one = 1;
126 static int __maybe_unused two = 2;
127 static int __maybe_unused three = 3;
128 static unsigned long one_ul = 1;
129 static int one_hundred = 100;
131 static int ten_thousand = 10000;
134 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
135 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
137 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
138 static int maxolduid = 65535;
139 static int minolduid;
140 static int min_percpu_pagelist_fract = 8;
142 static int ngroups_max = NGROUPS_MAX;
143 static const int cap_last_cap = CAP_LAST_CAP;
145 #ifdef CONFIG_INOTIFY_USER
146 #include <linux/inotify.h>
151 #ifdef CONFIG_SPARC64
152 extern int sysctl_tsb_ratio;
156 extern int pwrsw_enabled;
159 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
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 = CONFIG_MAGIC_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_max_ms",
374 .data = &sysctl_numa_balancing_scan_period_max,
375 .maxlen = sizeof(unsigned int),
377 .proc_handler = proc_dointvec,
380 .procname = "numa_balancing_scan_size_mb",
381 .data = &sysctl_numa_balancing_scan_size,
382 .maxlen = sizeof(unsigned int),
384 .proc_handler = proc_dointvec,
387 .procname = "numa_balancing_migrate_deferred",
388 .data = &sysctl_numa_balancing_migrate_deferred,
389 .maxlen = sizeof(unsigned int),
391 .proc_handler = proc_dointvec,
394 .procname = "numa_balancing",
395 .data = NULL, /* filled in by handler */
396 .maxlen = sizeof(unsigned int),
398 .proc_handler = sysctl_numa_balancing,
402 #endif /* CONFIG_NUMA_BALANCING */
403 #endif /* CONFIG_SCHED_DEBUG */
405 .procname = "sched_rt_period_us",
406 .data = &sysctl_sched_rt_period,
407 .maxlen = sizeof(unsigned int),
409 .proc_handler = sched_rt_handler,
412 .procname = "sched_rt_runtime_us",
413 .data = &sysctl_sched_rt_runtime,
414 .maxlen = sizeof(int),
416 .proc_handler = sched_rt_handler,
419 .procname = "sched_rr_timeslice_ms",
420 .data = &sched_rr_timeslice,
421 .maxlen = sizeof(int),
423 .proc_handler = sched_rr_handler,
425 #ifdef CONFIG_SCHED_AUTOGROUP
427 .procname = "sched_autogroup_enabled",
428 .data = &sysctl_sched_autogroup_enabled,
429 .maxlen = sizeof(unsigned int),
431 .proc_handler = proc_dointvec_minmax,
436 #ifdef CONFIG_CFS_BANDWIDTH
438 .procname = "sched_cfs_bandwidth_slice_us",
439 .data = &sysctl_sched_cfs_bandwidth_slice,
440 .maxlen = sizeof(unsigned int),
442 .proc_handler = proc_dointvec_minmax,
446 #ifdef CONFIG_PROVE_LOCKING
448 .procname = "prove_locking",
449 .data = &prove_locking,
450 .maxlen = sizeof(int),
452 .proc_handler = proc_dointvec,
455 #ifdef CONFIG_LOCK_STAT
457 .procname = "lock_stat",
459 .maxlen = sizeof(int),
461 .proc_handler = proc_dointvec,
466 .data = &panic_timeout,
467 .maxlen = sizeof(int),
469 .proc_handler = proc_dointvec,
471 #ifdef CONFIG_COREDUMP
473 .procname = "core_uses_pid",
474 .data = &core_uses_pid,
475 .maxlen = sizeof(int),
477 .proc_handler = proc_dointvec,
480 .procname = "core_pattern",
481 .data = core_pattern,
482 .maxlen = CORENAME_MAX_SIZE,
484 .proc_handler = proc_dostring_coredump,
487 .procname = "core_pipe_limit",
488 .data = &core_pipe_limit,
489 .maxlen = sizeof(unsigned int),
491 .proc_handler = proc_dointvec,
494 #ifdef CONFIG_PROC_SYSCTL
496 .procname = "tainted",
497 .maxlen = sizeof(long),
499 .proc_handler = proc_taint,
502 #ifdef CONFIG_LATENCYTOP
504 .procname = "latencytop",
505 .data = &latencytop_enabled,
506 .maxlen = sizeof(int),
508 .proc_handler = proc_dointvec,
511 #ifdef CONFIG_BLK_DEV_INITRD
513 .procname = "real-root-dev",
514 .data = &real_root_dev,
515 .maxlen = sizeof(int),
517 .proc_handler = proc_dointvec,
521 .procname = "print-fatal-signals",
522 .data = &print_fatal_signals,
523 .maxlen = sizeof(int),
525 .proc_handler = proc_dointvec,
529 .procname = "reboot-cmd",
530 .data = reboot_command,
533 .proc_handler = proc_dostring,
536 .procname = "stop-a",
537 .data = &stop_a_enabled,
538 .maxlen = sizeof (int),
540 .proc_handler = proc_dointvec,
543 .procname = "scons-poweroff",
544 .data = &scons_pwroff,
545 .maxlen = sizeof (int),
547 .proc_handler = proc_dointvec,
550 #ifdef CONFIG_SPARC64
552 .procname = "tsb-ratio",
553 .data = &sysctl_tsb_ratio,
554 .maxlen = sizeof (int),
556 .proc_handler = proc_dointvec,
561 .procname = "soft-power",
562 .data = &pwrsw_enabled,
563 .maxlen = sizeof (int),
565 .proc_handler = proc_dointvec,
568 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
570 .procname = "unaligned-trap",
571 .data = &unaligned_enabled,
572 .maxlen = sizeof (int),
574 .proc_handler = proc_dointvec,
578 .procname = "ctrl-alt-del",
580 .maxlen = sizeof(int),
582 .proc_handler = proc_dointvec,
584 #ifdef CONFIG_FUNCTION_TRACER
586 .procname = "ftrace_enabled",
587 .data = &ftrace_enabled,
588 .maxlen = sizeof(int),
590 .proc_handler = ftrace_enable_sysctl,
593 #ifdef CONFIG_STACK_TRACER
595 .procname = "stack_tracer_enabled",
596 .data = &stack_tracer_enabled,
597 .maxlen = sizeof(int),
599 .proc_handler = stack_trace_sysctl,
602 #ifdef CONFIG_TRACING
604 .procname = "ftrace_dump_on_oops",
605 .data = &ftrace_dump_on_oops,
606 .maxlen = sizeof(int),
608 .proc_handler = proc_dointvec,
611 .procname = "traceoff_on_warning",
612 .data = &__disable_trace_on_warning,
613 .maxlen = sizeof(__disable_trace_on_warning),
615 .proc_handler = proc_dointvec,
620 .procname = "kexec_load_disabled",
621 .data = &kexec_load_disabled,
622 .maxlen = sizeof(int),
624 /* only handle a transition from default "0" to "1" */
625 .proc_handler = proc_dointvec_minmax,
630 #ifdef CONFIG_MODULES
632 .procname = "modprobe",
633 .data = &modprobe_path,
634 .maxlen = KMOD_PATH_LEN,
636 .proc_handler = proc_dostring,
639 .procname = "modules_disabled",
640 .data = &modules_disabled,
641 .maxlen = sizeof(int),
643 /* only handle a transition from default "0" to "1" */
644 .proc_handler = proc_dointvec_minmax,
651 .procname = "hotplug",
652 .data = &uevent_helper,
653 .maxlen = UEVENT_HELPER_PATH_LEN,
655 .proc_handler = proc_dostring,
658 #ifdef CONFIG_CHR_DEV_SG
660 .procname = "sg-big-buff",
661 .data = &sg_big_buff,
662 .maxlen = sizeof (int),
664 .proc_handler = proc_dointvec,
667 #ifdef CONFIG_BSD_PROCESS_ACCT
671 .maxlen = 3*sizeof(int),
673 .proc_handler = proc_dointvec,
676 #ifdef CONFIG_MAGIC_SYSRQ
679 .data = &__sysrq_enabled,
680 .maxlen = sizeof (int),
682 .proc_handler = sysrq_sysctl_handler,
685 #ifdef CONFIG_PROC_SYSCTL
687 .procname = "cad_pid",
689 .maxlen = sizeof (int),
691 .proc_handler = proc_do_cad_pid,
695 .procname = "threads-max",
696 .data = &max_threads,
697 .maxlen = sizeof(int),
699 .proc_handler = proc_dointvec,
702 .procname = "random",
704 .child = random_table,
707 .procname = "usermodehelper",
709 .child = usermodehelper_table,
712 .procname = "overflowuid",
713 .data = &overflowuid,
714 .maxlen = sizeof(int),
716 .proc_handler = proc_dointvec_minmax,
717 .extra1 = &minolduid,
718 .extra2 = &maxolduid,
721 .procname = "overflowgid",
722 .data = &overflowgid,
723 .maxlen = sizeof(int),
725 .proc_handler = proc_dointvec_minmax,
726 .extra1 = &minolduid,
727 .extra2 = &maxolduid,
730 #ifdef CONFIG_MATHEMU
732 .procname = "ieee_emulation_warnings",
733 .data = &sysctl_ieee_emulation_warnings,
734 .maxlen = sizeof(int),
736 .proc_handler = proc_dointvec,
740 .procname = "userprocess_debug",
741 .data = &show_unhandled_signals,
742 .maxlen = sizeof(int),
744 .proc_handler = proc_dointvec,
748 .procname = "pid_max",
750 .maxlen = sizeof (int),
752 .proc_handler = proc_dointvec_minmax,
753 .extra1 = &pid_max_min,
754 .extra2 = &pid_max_max,
757 .procname = "panic_on_oops",
758 .data = &panic_on_oops,
759 .maxlen = sizeof(int),
761 .proc_handler = proc_dointvec,
763 #if defined CONFIG_PRINTK
765 .procname = "printk",
766 .data = &console_loglevel,
767 .maxlen = 4*sizeof(int),
769 .proc_handler = proc_dointvec,
772 .procname = "printk_ratelimit",
773 .data = &printk_ratelimit_state.interval,
774 .maxlen = sizeof(int),
776 .proc_handler = proc_dointvec_jiffies,
779 .procname = "printk_ratelimit_burst",
780 .data = &printk_ratelimit_state.burst,
781 .maxlen = sizeof(int),
783 .proc_handler = proc_dointvec,
786 .procname = "printk_delay",
787 .data = &printk_delay_msec,
788 .maxlen = sizeof(int),
790 .proc_handler = proc_dointvec_minmax,
792 .extra2 = &ten_thousand,
795 .procname = "dmesg_restrict",
796 .data = &dmesg_restrict,
797 .maxlen = sizeof(int),
799 .proc_handler = proc_dointvec_minmax_sysadmin,
804 .procname = "kptr_restrict",
805 .data = &kptr_restrict,
806 .maxlen = sizeof(int),
808 .proc_handler = proc_dointvec_minmax_sysadmin,
814 .procname = "ngroups_max",
815 .data = &ngroups_max,
816 .maxlen = sizeof (int),
818 .proc_handler = proc_dointvec,
821 .procname = "cap_last_cap",
822 .data = (void *)&cap_last_cap,
823 .maxlen = sizeof(int),
825 .proc_handler = proc_dointvec,
827 #if defined(CONFIG_LOCKUP_DETECTOR)
829 .procname = "watchdog",
830 .data = &watchdog_user_enabled,
831 .maxlen = sizeof (int),
833 .proc_handler = proc_dowatchdog,
838 .procname = "watchdog_thresh",
839 .data = &watchdog_thresh,
840 .maxlen = sizeof(int),
842 .proc_handler = proc_dowatchdog,
847 .procname = "softlockup_panic",
848 .data = &softlockup_panic,
849 .maxlen = sizeof(int),
851 .proc_handler = proc_dointvec_minmax,
856 .procname = "nmi_watchdog",
857 .data = &watchdog_user_enabled,
858 .maxlen = sizeof (int),
860 .proc_handler = proc_dowatchdog,
865 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
867 .procname = "unknown_nmi_panic",
868 .data = &unknown_nmi_panic,
869 .maxlen = sizeof (int),
871 .proc_handler = proc_dointvec,
874 #if defined(CONFIG_X86)
876 .procname = "panic_on_unrecovered_nmi",
877 .data = &panic_on_unrecovered_nmi,
878 .maxlen = sizeof(int),
880 .proc_handler = proc_dointvec,
883 .procname = "panic_on_io_nmi",
884 .data = &panic_on_io_nmi,
885 .maxlen = sizeof(int),
887 .proc_handler = proc_dointvec,
889 #ifdef CONFIG_DEBUG_STACKOVERFLOW
891 .procname = "panic_on_stackoverflow",
892 .data = &sysctl_panic_on_stackoverflow,
893 .maxlen = sizeof(int),
895 .proc_handler = proc_dointvec,
899 .procname = "bootloader_type",
900 .data = &bootloader_type,
901 .maxlen = sizeof (int),
903 .proc_handler = proc_dointvec,
906 .procname = "bootloader_version",
907 .data = &bootloader_version,
908 .maxlen = sizeof (int),
910 .proc_handler = proc_dointvec,
913 .procname = "kstack_depth_to_print",
914 .data = &kstack_depth_to_print,
915 .maxlen = sizeof(int),
917 .proc_handler = proc_dointvec,
920 .procname = "io_delay_type",
921 .data = &io_delay_type,
922 .maxlen = sizeof(int),
924 .proc_handler = proc_dointvec,
927 #if defined(CONFIG_MMU)
929 .procname = "randomize_va_space",
930 .data = &randomize_va_space,
931 .maxlen = sizeof(int),
933 .proc_handler = proc_dointvec,
936 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
938 .procname = "spin_retry",
940 .maxlen = sizeof (int),
942 .proc_handler = proc_dointvec,
945 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
947 .procname = "acpi_video_flags",
948 .data = &acpi_realmode_flags,
949 .maxlen = sizeof (unsigned long),
951 .proc_handler = proc_doulongvec_minmax,
954 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
956 .procname = "ignore-unaligned-usertrap",
957 .data = &no_unaligned_warning,
958 .maxlen = sizeof (int),
960 .proc_handler = proc_dointvec,
965 .procname = "unaligned-dump-stack",
966 .data = &unaligned_dump_stack,
967 .maxlen = sizeof (int),
969 .proc_handler = proc_dointvec,
972 #ifdef CONFIG_DETECT_HUNG_TASK
974 .procname = "hung_task_panic",
975 .data = &sysctl_hung_task_panic,
976 .maxlen = sizeof(int),
978 .proc_handler = proc_dointvec_minmax,
983 .procname = "hung_task_check_count",
984 .data = &sysctl_hung_task_check_count,
985 .maxlen = sizeof(int),
987 .proc_handler = proc_dointvec_minmax,
991 .procname = "hung_task_timeout_secs",
992 .data = &sysctl_hung_task_timeout_secs,
993 .maxlen = sizeof(unsigned long),
995 .proc_handler = proc_dohung_task_timeout_secs,
998 .procname = "hung_task_warnings",
999 .data = &sysctl_hung_task_warnings,
1000 .maxlen = sizeof(unsigned long),
1002 .proc_handler = proc_doulongvec_minmax,
1005 #ifdef CONFIG_COMPAT
1007 .procname = "compat-log",
1008 .data = &compat_log,
1009 .maxlen = sizeof (int),
1011 .proc_handler = proc_dointvec,
1014 #ifdef CONFIG_RT_MUTEXES
1016 .procname = "max_lock_depth",
1017 .data = &max_lock_depth,
1018 .maxlen = sizeof(int),
1020 .proc_handler = proc_dointvec,
1024 .procname = "poweroff_cmd",
1025 .data = &poweroff_cmd,
1026 .maxlen = POWEROFF_CMD_PATH_LEN,
1028 .proc_handler = proc_dostring,
1034 .child = key_sysctls,
1037 #ifdef CONFIG_RCU_TORTURE_TEST
1039 .procname = "rcutorture_runnable",
1040 .data = &rcutorture_runnable,
1041 .maxlen = sizeof(int),
1043 .proc_handler = proc_dointvec,
1046 #ifdef CONFIG_PERF_EVENTS
1048 * User-space scripts rely on the existence of this file
1049 * as a feature check for perf_events being enabled.
1051 * So it's an ABI, do not remove!
1054 .procname = "perf_event_paranoid",
1055 .data = &sysctl_perf_event_paranoid,
1056 .maxlen = sizeof(sysctl_perf_event_paranoid),
1058 .proc_handler = proc_dointvec,
1061 .procname = "perf_event_mlock_kb",
1062 .data = &sysctl_perf_event_mlock,
1063 .maxlen = sizeof(sysctl_perf_event_mlock),
1065 .proc_handler = proc_dointvec,
1068 .procname = "perf_event_max_sample_rate",
1069 .data = &sysctl_perf_event_sample_rate,
1070 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1072 .proc_handler = perf_proc_update_handler,
1076 .procname = "perf_cpu_time_max_percent",
1077 .data = &sysctl_perf_cpu_time_max_percent,
1078 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1080 .proc_handler = perf_cpu_time_max_percent_handler,
1082 .extra2 = &one_hundred,
1085 #ifdef CONFIG_KMEMCHECK
1087 .procname = "kmemcheck",
1088 .data = &kmemcheck_enabled,
1089 .maxlen = sizeof(int),
1091 .proc_handler = proc_dointvec,
1096 .procname = "blk_iopoll",
1097 .data = &blk_iopoll_enabled,
1098 .maxlen = sizeof(int),
1100 .proc_handler = proc_dointvec,
1106 static struct ctl_table vm_table[] = {
1108 .procname = "overcommit_memory",
1109 .data = &sysctl_overcommit_memory,
1110 .maxlen = sizeof(sysctl_overcommit_memory),
1112 .proc_handler = proc_dointvec_minmax,
1117 .procname = "panic_on_oom",
1118 .data = &sysctl_panic_on_oom,
1119 .maxlen = sizeof(sysctl_panic_on_oom),
1121 .proc_handler = proc_dointvec_minmax,
1126 .procname = "oom_kill_allocating_task",
1127 .data = &sysctl_oom_kill_allocating_task,
1128 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1130 .proc_handler = proc_dointvec,
1133 .procname = "oom_dump_tasks",
1134 .data = &sysctl_oom_dump_tasks,
1135 .maxlen = sizeof(sysctl_oom_dump_tasks),
1137 .proc_handler = proc_dointvec,
1140 .procname = "overcommit_ratio",
1141 .data = &sysctl_overcommit_ratio,
1142 .maxlen = sizeof(sysctl_overcommit_ratio),
1144 .proc_handler = overcommit_ratio_handler,
1147 .procname = "overcommit_kbytes",
1148 .data = &sysctl_overcommit_kbytes,
1149 .maxlen = sizeof(sysctl_overcommit_kbytes),
1151 .proc_handler = overcommit_kbytes_handler,
1154 .procname = "page-cluster",
1155 .data = &page_cluster,
1156 .maxlen = sizeof(int),
1158 .proc_handler = proc_dointvec_minmax,
1162 .procname = "dirty_background_ratio",
1163 .data = &dirty_background_ratio,
1164 .maxlen = sizeof(dirty_background_ratio),
1166 .proc_handler = dirty_background_ratio_handler,
1168 .extra2 = &one_hundred,
1171 .procname = "dirty_background_bytes",
1172 .data = &dirty_background_bytes,
1173 .maxlen = sizeof(dirty_background_bytes),
1175 .proc_handler = dirty_background_bytes_handler,
1179 .procname = "dirty_ratio",
1180 .data = &vm_dirty_ratio,
1181 .maxlen = sizeof(vm_dirty_ratio),
1183 .proc_handler = dirty_ratio_handler,
1185 .extra2 = &one_hundred,
1188 .procname = "dirty_bytes",
1189 .data = &vm_dirty_bytes,
1190 .maxlen = sizeof(vm_dirty_bytes),
1192 .proc_handler = dirty_bytes_handler,
1193 .extra1 = &dirty_bytes_min,
1196 .procname = "dirty_writeback_centisecs",
1197 .data = &dirty_writeback_interval,
1198 .maxlen = sizeof(dirty_writeback_interval),
1200 .proc_handler = dirty_writeback_centisecs_handler,
1203 .procname = "dirty_expire_centisecs",
1204 .data = &dirty_expire_interval,
1205 .maxlen = sizeof(dirty_expire_interval),
1207 .proc_handler = proc_dointvec_minmax,
1211 .procname = "nr_pdflush_threads",
1212 .mode = 0444 /* read-only */,
1213 .proc_handler = pdflush_proc_obsolete,
1216 .procname = "swappiness",
1217 .data = &vm_swappiness,
1218 .maxlen = sizeof(vm_swappiness),
1220 .proc_handler = proc_dointvec_minmax,
1222 .extra2 = &one_hundred,
1224 #ifdef CONFIG_HUGETLB_PAGE
1226 .procname = "nr_hugepages",
1228 .maxlen = sizeof(unsigned long),
1230 .proc_handler = hugetlb_sysctl_handler,
1231 .extra1 = (void *)&hugetlb_zero,
1232 .extra2 = (void *)&hugetlb_infinity,
1236 .procname = "nr_hugepages_mempolicy",
1238 .maxlen = sizeof(unsigned long),
1240 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1241 .extra1 = (void *)&hugetlb_zero,
1242 .extra2 = (void *)&hugetlb_infinity,
1246 .procname = "hugetlb_shm_group",
1247 .data = &sysctl_hugetlb_shm_group,
1248 .maxlen = sizeof(gid_t),
1250 .proc_handler = proc_dointvec,
1253 .procname = "hugepages_treat_as_movable",
1254 .data = &hugepages_treat_as_movable,
1255 .maxlen = sizeof(int),
1257 .proc_handler = proc_dointvec,
1260 .procname = "nr_overcommit_hugepages",
1262 .maxlen = sizeof(unsigned long),
1264 .proc_handler = hugetlb_overcommit_handler,
1265 .extra1 = (void *)&hugetlb_zero,
1266 .extra2 = (void *)&hugetlb_infinity,
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,
1318 .extra1 = &min_percpu_pagelist_fract,
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 .data = &vdso_enabled,
1432 .maxlen = sizeof(vdso_enabled),
1434 .proc_handler = proc_dointvec,
1438 #ifdef CONFIG_HIGHMEM
1440 .procname = "highmem_is_dirtyable",
1441 .data = &vm_highmem_is_dirtyable,
1442 .maxlen = sizeof(vm_highmem_is_dirtyable),
1444 .proc_handler = proc_dointvec_minmax,
1450 .procname = "scan_unevictable_pages",
1451 .data = &scan_unevictable_pages,
1452 .maxlen = sizeof(scan_unevictable_pages),
1454 .proc_handler = scan_unevictable_handler,
1456 #ifdef CONFIG_MEMORY_FAILURE
1458 .procname = "memory_failure_early_kill",
1459 .data = &sysctl_memory_failure_early_kill,
1460 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1462 .proc_handler = proc_dointvec_minmax,
1467 .procname = "memory_failure_recovery",
1468 .data = &sysctl_memory_failure_recovery,
1469 .maxlen = sizeof(sysctl_memory_failure_recovery),
1471 .proc_handler = proc_dointvec_minmax,
1477 .procname = "user_reserve_kbytes",
1478 .data = &sysctl_user_reserve_kbytes,
1479 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1481 .proc_handler = proc_doulongvec_minmax,
1484 .procname = "admin_reserve_kbytes",
1485 .data = &sysctl_admin_reserve_kbytes,
1486 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1488 .proc_handler = proc_doulongvec_minmax,
1493 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1494 static struct ctl_table binfmt_misc_table[] = {
1499 static struct ctl_table fs_table[] = {
1501 .procname = "inode-nr",
1502 .data = &inodes_stat,
1503 .maxlen = 2*sizeof(long),
1505 .proc_handler = proc_nr_inodes,
1508 .procname = "inode-state",
1509 .data = &inodes_stat,
1510 .maxlen = 7*sizeof(long),
1512 .proc_handler = proc_nr_inodes,
1515 .procname = "file-nr",
1516 .data = &files_stat,
1517 .maxlen = sizeof(files_stat),
1519 .proc_handler = proc_nr_files,
1522 .procname = "file-max",
1523 .data = &files_stat.max_files,
1524 .maxlen = sizeof(files_stat.max_files),
1526 .proc_handler = proc_doulongvec_minmax,
1529 .procname = "nr_open",
1530 .data = &sysctl_nr_open,
1531 .maxlen = sizeof(int),
1533 .proc_handler = proc_dointvec_minmax,
1534 .extra1 = &sysctl_nr_open_min,
1535 .extra2 = &sysctl_nr_open_max,
1538 .procname = "dentry-state",
1539 .data = &dentry_stat,
1540 .maxlen = 6*sizeof(long),
1542 .proc_handler = proc_nr_dentry,
1545 .procname = "overflowuid",
1546 .data = &fs_overflowuid,
1547 .maxlen = sizeof(int),
1549 .proc_handler = proc_dointvec_minmax,
1550 .extra1 = &minolduid,
1551 .extra2 = &maxolduid,
1554 .procname = "overflowgid",
1555 .data = &fs_overflowgid,
1556 .maxlen = sizeof(int),
1558 .proc_handler = proc_dointvec_minmax,
1559 .extra1 = &minolduid,
1560 .extra2 = &maxolduid,
1562 #ifdef CONFIG_FILE_LOCKING
1564 .procname = "leases-enable",
1565 .data = &leases_enable,
1566 .maxlen = sizeof(int),
1568 .proc_handler = proc_dointvec,
1571 #ifdef CONFIG_DNOTIFY
1573 .procname = "dir-notify-enable",
1574 .data = &dir_notify_enable,
1575 .maxlen = sizeof(int),
1577 .proc_handler = proc_dointvec,
1581 #ifdef CONFIG_FILE_LOCKING
1583 .procname = "lease-break-time",
1584 .data = &lease_break_time,
1585 .maxlen = sizeof(int),
1587 .proc_handler = proc_dointvec,
1592 .procname = "aio-nr",
1594 .maxlen = sizeof(aio_nr),
1596 .proc_handler = proc_doulongvec_minmax,
1599 .procname = "aio-max-nr",
1600 .data = &aio_max_nr,
1601 .maxlen = sizeof(aio_max_nr),
1603 .proc_handler = proc_doulongvec_minmax,
1605 #endif /* CONFIG_AIO */
1606 #ifdef CONFIG_INOTIFY_USER
1608 .procname = "inotify",
1610 .child = inotify_table,
1615 .procname = "epoll",
1617 .child = epoll_table,
1622 .procname = "protected_symlinks",
1623 .data = &sysctl_protected_symlinks,
1624 .maxlen = sizeof(int),
1626 .proc_handler = proc_dointvec_minmax,
1631 .procname = "protected_hardlinks",
1632 .data = &sysctl_protected_hardlinks,
1633 .maxlen = sizeof(int),
1635 .proc_handler = proc_dointvec_minmax,
1640 .procname = "suid_dumpable",
1641 .data = &suid_dumpable,
1642 .maxlen = sizeof(int),
1644 .proc_handler = proc_dointvec_minmax_coredump,
1648 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1650 .procname = "binfmt_misc",
1652 .child = binfmt_misc_table,
1656 .procname = "pipe-max-size",
1657 .data = &pipe_max_size,
1658 .maxlen = sizeof(int),
1660 .proc_handler = &pipe_proc_fn,
1661 .extra1 = &pipe_min_size,
1666 static struct ctl_table debug_table[] = {
1667 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1669 .procname = "exception-trace",
1670 .data = &show_unhandled_signals,
1671 .maxlen = sizeof(int),
1673 .proc_handler = proc_dointvec
1676 #if defined(CONFIG_OPTPROBES)
1678 .procname = "kprobes-optimization",
1679 .data = &sysctl_kprobes_optimization,
1680 .maxlen = sizeof(int),
1682 .proc_handler = proc_kprobes_optimization_handler,
1690 static struct ctl_table dev_table[] = {
1694 int __init sysctl_init(void)
1696 struct ctl_table_header *hdr;
1698 hdr = register_sysctl_table(sysctl_base_table);
1699 kmemleak_not_leak(hdr);
1703 #endif /* CONFIG_SYSCTL */
1709 #ifdef CONFIG_PROC_SYSCTL
1711 static int _proc_do_string(void* data, int maxlen, int write,
1712 void __user *buffer,
1713 size_t *lenp, loff_t *ppos)
1719 if (!data || !maxlen || !*lenp) {
1727 while (len < *lenp) {
1728 if (get_user(c, p++))
1730 if (c == 0 || c == '\n')
1736 if(copy_from_user(data, buffer, len))
1738 ((char *) data)[len] = 0;
1756 if(copy_to_user(buffer, data, len))
1759 if(put_user('\n', ((char __user *) buffer) + len))
1770 * proc_dostring - read a string sysctl
1771 * @table: the sysctl table
1772 * @write: %TRUE if this is a write to the sysctl file
1773 * @buffer: the user buffer
1774 * @lenp: the size of the user buffer
1775 * @ppos: file position
1777 * Reads/writes a string from/to the user buffer. If the kernel
1778 * buffer provided is not large enough to hold the string, the
1779 * string is truncated. The copied string is %NULL-terminated.
1780 * If the string is being read by the user process, it is copied
1781 * and a newline '\n' is added. It is truncated if the buffer is
1784 * Returns 0 on success.
1786 int proc_dostring(struct ctl_table *table, int write,
1787 void __user *buffer, size_t *lenp, loff_t *ppos)
1789 return _proc_do_string(table->data, table->maxlen, write,
1790 buffer, lenp, ppos);
1793 static size_t proc_skip_spaces(char **buf)
1796 char *tmp = skip_spaces(*buf);
1802 static void proc_skip_char(char **buf, size_t *size, const char v)
1812 #define TMPBUFLEN 22
1814 * proc_get_long - reads an ASCII formatted integer from a user buffer
1816 * @buf: a kernel buffer
1817 * @size: size of the kernel buffer
1818 * @val: this is where the number will be stored
1819 * @neg: set to %TRUE if number is negative
1820 * @perm_tr: a vector which contains the allowed trailers
1821 * @perm_tr_len: size of the perm_tr vector
1822 * @tr: pointer to store the trailer character
1824 * In case of success %0 is returned and @buf and @size are updated with
1825 * the amount of bytes read. If @tr is non-NULL and a trailing
1826 * character exists (size is non-zero after returning from this
1827 * function), @tr is updated with the trailing character.
1829 static int proc_get_long(char **buf, size_t *size,
1830 unsigned long *val, bool *neg,
1831 const char *perm_tr, unsigned perm_tr_len, char *tr)
1834 char *p, tmp[TMPBUFLEN];
1840 if (len > TMPBUFLEN - 1)
1841 len = TMPBUFLEN - 1;
1843 memcpy(tmp, *buf, len);
1847 if (*p == '-' && *size > 1) {
1855 *val = simple_strtoul(p, &p, 0);
1859 /* We don't know if the next char is whitespace thus we may accept
1860 * invalid integers (e.g. 1234...a) or two integers instead of one
1861 * (e.g. 123...1). So lets not allow such large numbers. */
1862 if (len == TMPBUFLEN - 1)
1865 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1868 if (tr && (len < *size))
1878 * proc_put_long - converts an integer to a decimal ASCII formatted string
1880 * @buf: the user buffer
1881 * @size: the size of the user buffer
1882 * @val: the integer to be converted
1883 * @neg: sign of the number, %TRUE for negative
1885 * In case of success %0 is returned and @buf and @size are updated with
1886 * the amount of bytes written.
1888 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1892 char tmp[TMPBUFLEN], *p = tmp;
1894 sprintf(p, "%s%lu", neg ? "-" : "", val);
1898 if (copy_to_user(*buf, tmp, len))
1906 static int proc_put_char(void __user **buf, size_t *size, char c)
1909 char __user **buffer = (char __user **)buf;
1910 if (put_user(c, *buffer))
1912 (*size)--, (*buffer)++;
1918 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1920 int write, void *data)
1923 *valp = *negp ? -*lvalp : *lvalp;
1928 *lvalp = (unsigned long)-val;
1931 *lvalp = (unsigned long)val;
1937 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1939 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1940 int write, void __user *buffer,
1941 size_t *lenp, loff_t *ppos,
1942 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1943 int write, void *data),
1946 int *i, vleft, first = 1, err = 0;
1947 unsigned long page = 0;
1951 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1956 i = (int *) tbl_data;
1957 vleft = table->maxlen / sizeof(*i);
1961 conv = do_proc_dointvec_conv;
1964 if (left > PAGE_SIZE - 1)
1965 left = PAGE_SIZE - 1;
1966 page = __get_free_page(GFP_TEMPORARY);
1967 kbuf = (char *) page;
1970 if (copy_from_user(kbuf, buffer, left)) {
1977 for (; left && vleft--; i++, first=0) {
1982 left -= proc_skip_spaces(&kbuf);
1986 err = proc_get_long(&kbuf, &left, &lval, &neg,
1988 sizeof(proc_wspace_sep), NULL);
1991 if (conv(&neg, &lval, i, 1, data)) {
1996 if (conv(&neg, &lval, i, 0, data)) {
2001 err = proc_put_char(&buffer, &left, '\t');
2004 err = proc_put_long(&buffer, &left, lval, neg);
2010 if (!write && !first && left && !err)
2011 err = proc_put_char(&buffer, &left, '\n');
2012 if (write && !err && left)
2013 left -= proc_skip_spaces(&kbuf);
2018 return err ? : -EINVAL;
2025 static int do_proc_dointvec(struct ctl_table *table, int write,
2026 void __user *buffer, size_t *lenp, loff_t *ppos,
2027 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2028 int write, void *data),
2031 return __do_proc_dointvec(table->data, table, write,
2032 buffer, lenp, ppos, conv, data);
2036 * proc_dointvec - read a vector of integers
2037 * @table: the sysctl table
2038 * @write: %TRUE if this is a write to the sysctl file
2039 * @buffer: the user buffer
2040 * @lenp: the size of the user buffer
2041 * @ppos: file position
2043 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2044 * values from/to the user buffer, treated as an ASCII string.
2046 * Returns 0 on success.
2048 int proc_dointvec(struct ctl_table *table, int write,
2049 void __user *buffer, size_t *lenp, loff_t *ppos)
2051 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2056 * Taint values can only be increased
2057 * This means we can safely use a temporary.
2059 static int proc_taint(struct ctl_table *table, int write,
2060 void __user *buffer, size_t *lenp, loff_t *ppos)
2063 unsigned long tmptaint = get_taint();
2066 if (write && !capable(CAP_SYS_ADMIN))
2071 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2077 * Poor man's atomic or. Not worth adding a primitive
2078 * to everyone's atomic.h for this
2081 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2082 if ((tmptaint >> i) & 1)
2083 add_taint(i, LOCKDEP_STILL_OK);
2090 #ifdef CONFIG_PRINTK
2091 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2092 void __user *buffer, size_t *lenp, loff_t *ppos)
2094 if (write && !capable(CAP_SYS_ADMIN))
2097 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2101 struct do_proc_dointvec_minmax_conv_param {
2106 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2108 int write, void *data)
2110 struct do_proc_dointvec_minmax_conv_param *param = data;
2112 int val = *negp ? -*lvalp : *lvalp;
2113 if ((param->min && *param->min > val) ||
2114 (param->max && *param->max < val))
2121 *lvalp = (unsigned long)-val;
2124 *lvalp = (unsigned long)val;
2131 * proc_dointvec_minmax - read a vector of integers with min/max values
2132 * @table: the sysctl table
2133 * @write: %TRUE if this is a write to the sysctl file
2134 * @buffer: the user buffer
2135 * @lenp: the size of the user buffer
2136 * @ppos: file position
2138 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2139 * values from/to the user buffer, treated as an ASCII string.
2141 * This routine will ensure the values are within the range specified by
2142 * table->extra1 (min) and table->extra2 (max).
2144 * Returns 0 on success.
2146 int proc_dointvec_minmax(struct ctl_table *table, int write,
2147 void __user *buffer, size_t *lenp, loff_t *ppos)
2149 struct do_proc_dointvec_minmax_conv_param param = {
2150 .min = (int *) table->extra1,
2151 .max = (int *) table->extra2,
2153 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2154 do_proc_dointvec_minmax_conv, ¶m);
2157 static void validate_coredump_safety(void)
2159 #ifdef CONFIG_COREDUMP
2160 if (suid_dumpable == SUID_DUMP_ROOT &&
2161 core_pattern[0] != '/' && core_pattern[0] != '|') {
2162 printk(KERN_WARNING "Unsafe core_pattern used with "\
2163 "suid_dumpable=2. Pipe handler or fully qualified "\
2164 "core dump path required.\n");
2169 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2170 void __user *buffer, size_t *lenp, loff_t *ppos)
2172 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2174 validate_coredump_safety();
2178 #ifdef CONFIG_COREDUMP
2179 static int proc_dostring_coredump(struct ctl_table *table, int write,
2180 void __user *buffer, size_t *lenp, loff_t *ppos)
2182 int error = proc_dostring(table, write, buffer, lenp, ppos);
2184 validate_coredump_safety();
2189 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2190 void __user *buffer,
2191 size_t *lenp, loff_t *ppos,
2192 unsigned long convmul,
2193 unsigned long convdiv)
2195 unsigned long *i, *min, *max;
2196 int vleft, first = 1, err = 0;
2197 unsigned long page = 0;
2201 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2206 i = (unsigned long *) data;
2207 min = (unsigned long *) table->extra1;
2208 max = (unsigned long *) table->extra2;
2209 vleft = table->maxlen / sizeof(unsigned long);
2213 if (left > PAGE_SIZE - 1)
2214 left = PAGE_SIZE - 1;
2215 page = __get_free_page(GFP_TEMPORARY);
2216 kbuf = (char *) page;
2219 if (copy_from_user(kbuf, buffer, left)) {
2226 for (; left && vleft--; i++, first = 0) {
2232 left -= proc_skip_spaces(&kbuf);
2234 err = proc_get_long(&kbuf, &left, &val, &neg,
2236 sizeof(proc_wspace_sep), NULL);
2241 if ((min && val < *min) || (max && val > *max))
2245 val = convdiv * (*i) / convmul;
2247 err = proc_put_char(&buffer, &left, '\t');
2251 err = proc_put_long(&buffer, &left, val, false);
2257 if (!write && !first && left && !err)
2258 err = proc_put_char(&buffer, &left, '\n');
2260 left -= proc_skip_spaces(&kbuf);
2265 return err ? : -EINVAL;
2272 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2273 void __user *buffer,
2274 size_t *lenp, loff_t *ppos,
2275 unsigned long convmul,
2276 unsigned long convdiv)
2278 return __do_proc_doulongvec_minmax(table->data, table, write,
2279 buffer, lenp, ppos, convmul, convdiv);
2283 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2284 * @table: the sysctl table
2285 * @write: %TRUE if this is a write to the sysctl file
2286 * @buffer: the user buffer
2287 * @lenp: the size of the user buffer
2288 * @ppos: file position
2290 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2291 * values from/to the user buffer, treated as an ASCII string.
2293 * This routine will ensure the values are within the range specified by
2294 * table->extra1 (min) and table->extra2 (max).
2296 * Returns 0 on success.
2298 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2299 void __user *buffer, size_t *lenp, loff_t *ppos)
2301 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2305 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2306 * @table: the sysctl table
2307 * @write: %TRUE if this is a write to the sysctl file
2308 * @buffer: the user buffer
2309 * @lenp: the size of the user buffer
2310 * @ppos: file position
2312 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2313 * values from/to the user buffer, treated as an ASCII string. The values
2314 * are treated as milliseconds, and converted to jiffies when they are stored.
2316 * This routine will ensure the values are within the range specified by
2317 * table->extra1 (min) and table->extra2 (max).
2319 * Returns 0 on success.
2321 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2322 void __user *buffer,
2323 size_t *lenp, loff_t *ppos)
2325 return do_proc_doulongvec_minmax(table, write, buffer,
2326 lenp, ppos, HZ, 1000l);
2330 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2332 int write, void *data)
2335 if (*lvalp > LONG_MAX / HZ)
2337 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2343 lval = (unsigned long)-val;
2346 lval = (unsigned long)val;
2353 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2355 int write, void *data)
2358 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2360 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2366 lval = (unsigned long)-val;
2369 lval = (unsigned long)val;
2371 *lvalp = jiffies_to_clock_t(lval);
2376 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2378 int write, void *data)
2381 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2391 lval = (unsigned long)-val;
2394 lval = (unsigned long)val;
2396 *lvalp = jiffies_to_msecs(lval);
2402 * proc_dointvec_jiffies - read a vector of integers as seconds
2403 * @table: the sysctl table
2404 * @write: %TRUE if this is a write to the sysctl file
2405 * @buffer: the user buffer
2406 * @lenp: the size of the user buffer
2407 * @ppos: file position
2409 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2410 * values from/to the user buffer, treated as an ASCII string.
2411 * The values read are assumed to be in seconds, and are converted into
2414 * Returns 0 on success.
2416 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2417 void __user *buffer, size_t *lenp, loff_t *ppos)
2419 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2420 do_proc_dointvec_jiffies_conv,NULL);
2424 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2425 * @table: the sysctl table
2426 * @write: %TRUE if this is a write to the sysctl file
2427 * @buffer: the user buffer
2428 * @lenp: the size of the user buffer
2429 * @ppos: pointer to the file position
2431 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2432 * values from/to the user buffer, treated as an ASCII string.
2433 * The values read are assumed to be in 1/USER_HZ seconds, and
2434 * are converted into jiffies.
2436 * Returns 0 on success.
2438 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2439 void __user *buffer, size_t *lenp, loff_t *ppos)
2441 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2442 do_proc_dointvec_userhz_jiffies_conv,NULL);
2446 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2447 * @table: the sysctl table
2448 * @write: %TRUE if this is a write to the sysctl file
2449 * @buffer: the user buffer
2450 * @lenp: the size of the user buffer
2451 * @ppos: file position
2452 * @ppos: the current position in the file
2454 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2455 * values from/to the user buffer, treated as an ASCII string.
2456 * The values read are assumed to be in 1/1000 seconds, and
2457 * are converted into jiffies.
2459 * Returns 0 on success.
2461 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2462 void __user *buffer, size_t *lenp, loff_t *ppos)
2464 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2465 do_proc_dointvec_ms_jiffies_conv, NULL);
2468 static int proc_do_cad_pid(struct ctl_table *table, int write,
2469 void __user *buffer, size_t *lenp, loff_t *ppos)
2471 struct pid *new_pid;
2475 tmp = pid_vnr(cad_pid);
2477 r = __do_proc_dointvec(&tmp, table, write, buffer,
2478 lenp, ppos, NULL, NULL);
2482 new_pid = find_get_pid(tmp);
2486 put_pid(xchg(&cad_pid, new_pid));
2491 * proc_do_large_bitmap - read/write from/to a large bitmap
2492 * @table: the sysctl table
2493 * @write: %TRUE if this is a write to the sysctl file
2494 * @buffer: the user buffer
2495 * @lenp: the size of the user buffer
2496 * @ppos: file position
2498 * The bitmap is stored at table->data and the bitmap length (in bits)
2501 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2502 * large bitmaps may be represented in a compact manner. Writing into
2503 * the file will clear the bitmap then update it with the given input.
2505 * Returns 0 on success.
2507 int proc_do_large_bitmap(struct ctl_table *table, int write,
2508 void __user *buffer, size_t *lenp, loff_t *ppos)
2512 size_t left = *lenp;
2513 unsigned long bitmap_len = table->maxlen;
2514 unsigned long *bitmap = (unsigned long *) table->data;
2515 unsigned long *tmp_bitmap = NULL;
2516 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2518 if (!bitmap_len || !left || (*ppos && !write)) {
2524 unsigned long page = 0;
2527 if (left > PAGE_SIZE - 1)
2528 left = PAGE_SIZE - 1;
2530 page = __get_free_page(GFP_TEMPORARY);
2531 kbuf = (char *) page;
2534 if (copy_from_user(kbuf, buffer, left)) {
2540 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2546 proc_skip_char(&kbuf, &left, '\n');
2547 while (!err && left) {
2548 unsigned long val_a, val_b;
2551 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2555 if (val_a >= bitmap_len || neg) {
2567 err = proc_get_long(&kbuf, &left, &val_b,
2568 &neg, tr_b, sizeof(tr_b),
2572 if (val_b >= bitmap_len || neg ||
2583 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2585 proc_skip_char(&kbuf, &left, '\n');
2589 unsigned long bit_a, bit_b = 0;
2592 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2593 if (bit_a >= bitmap_len)
2595 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2599 err = proc_put_char(&buffer, &left, ',');
2603 err = proc_put_long(&buffer, &left, bit_a, false);
2606 if (bit_a != bit_b) {
2607 err = proc_put_char(&buffer, &left, '-');
2610 err = proc_put_long(&buffer, &left, bit_b, false);
2618 err = proc_put_char(&buffer, &left, '\n');
2624 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2626 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2638 #else /* CONFIG_PROC_SYSCTL */
2640 int proc_dostring(struct ctl_table *table, int write,
2641 void __user *buffer, size_t *lenp, loff_t *ppos)
2646 int proc_dointvec(struct ctl_table *table, int write,
2647 void __user *buffer, size_t *lenp, loff_t *ppos)
2652 int proc_dointvec_minmax(struct ctl_table *table, int write,
2653 void __user *buffer, size_t *lenp, loff_t *ppos)
2658 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2659 void __user *buffer, size_t *lenp, loff_t *ppos)
2664 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2665 void __user *buffer, size_t *lenp, loff_t *ppos)
2670 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2671 void __user *buffer, size_t *lenp, loff_t *ppos)
2676 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2677 void __user *buffer, size_t *lenp, loff_t *ppos)
2682 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2683 void __user *buffer,
2684 size_t *lenp, loff_t *ppos)
2690 #endif /* CONFIG_PROC_SYSCTL */
2693 * No sense putting this after each symbol definition, twice,
2694 * exception granted :-)
2696 EXPORT_SYMBOL(proc_dointvec);
2697 EXPORT_SYMBOL(proc_dointvec_jiffies);
2698 EXPORT_SYMBOL(proc_dointvec_minmax);
2699 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2700 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2701 EXPORT_SYMBOL(proc_dostring);
2702 EXPORT_SYMBOL(proc_doulongvec_minmax);
2703 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);