2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
71 #include <asm/stacktrace.h>
75 #include <asm/setup.h>
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
86 #ifdef CONFIG_CHR_DEV_SG
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_lazy_vfree_pages;
99 extern int sysctl_lazy_vfree_tlb_flush_all_threshold;
100 extern int sysctl_overcommit_memory;
101 extern int sysctl_overcommit_ratio;
102 extern int max_threads;
103 extern int suid_dumpable;
104 #ifdef CONFIG_COREDUMP
105 extern int core_uses_pid;
106 extern char core_pattern[];
107 extern unsigned int core_pipe_limit;
110 extern int extra_free_kbytes;
111 extern int min_free_order_shift;
112 extern int pid_max_min, pid_max_max;
113 extern int percpu_pagelist_fraction;
114 extern int compat_log;
115 extern int latencytop_enabled;
116 extern int sysctl_nr_open_min, sysctl_nr_open_max;
118 extern int sysctl_nr_trim_pages;
121 extern int blk_iopoll_enabled;
124 /* Constants used for minimum and maximum */
125 #ifdef CONFIG_LOCKUP_DETECTOR
126 static int sixty = 60;
127 static int neg_one = -1;
131 static int __maybe_unused one = 1;
132 static int __maybe_unused two = 2;
133 static int __maybe_unused three = 3;
134 static unsigned long one_ul = 1;
135 static int one_hundred = 100;
137 static int ten_thousand = 10000;
140 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
141 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
143 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
144 static int maxolduid = 65535;
145 static int minolduid;
146 static int min_percpu_pagelist_fract = 8;
148 static int ngroups_max = NGROUPS_MAX;
149 static const int cap_last_cap = CAP_LAST_CAP;
151 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
152 #ifdef CONFIG_DETECT_HUNG_TASK
153 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
156 #ifdef CONFIG_INOTIFY_USER
157 #include <linux/inotify.h>
162 #ifdef CONFIG_SPARC64
163 extern int sysctl_tsb_ratio;
167 extern int pwrsw_enabled;
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
171 extern int unaligned_enabled;
175 extern int unaligned_dump_stack;
178 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179 extern int no_unaligned_warning;
182 #ifdef CONFIG_PROC_SYSCTL
183 static int proc_do_cad_pid(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
185 static int proc_taint(struct ctl_table *table, int write,
186 void __user *buffer, size_t *lenp, loff_t *ppos);
190 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
194 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
195 void __user *buffer, size_t *lenp, loff_t *ppos);
196 #ifdef CONFIG_COREDUMP
197 static int proc_dostring_coredump(struct ctl_table *table, int write,
198 void __user *buffer, size_t *lenp, loff_t *ppos);
201 #ifdef CONFIG_MAGIC_SYSRQ
202 /* Note: sysrq code uses it's own private copy */
203 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
205 static int sysrq_sysctl_handler(ctl_table *table, int write,
206 void __user *buffer, size_t *lenp,
211 error = proc_dointvec(table, write, buffer, lenp, ppos);
216 sysrq_toggle_support(__sysrq_enabled);
223 static struct ctl_table kern_table[];
224 static struct ctl_table vm_table[];
225 static struct ctl_table fs_table[];
226 static struct ctl_table debug_table[];
227 static struct ctl_table dev_table[];
228 extern struct ctl_table random_table[];
230 extern struct ctl_table epoll_table[];
233 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
234 int sysctl_legacy_va_layout;
237 /* The default sysctl tables: */
239 static struct ctl_table sysctl_base_table[] = {
241 .procname = "kernel",
258 .child = debug_table,
268 #ifdef CONFIG_SCHED_DEBUG
269 static int min_sched_granularity_ns = 100000; /* 100 usecs */
270 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
271 static int min_wakeup_granularity_ns; /* 0 usecs */
272 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
274 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
275 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
276 #endif /* CONFIG_SMP */
277 #endif /* CONFIG_SCHED_DEBUG */
279 #ifdef CONFIG_COMPACTION
280 static int min_extfrag_threshold;
281 static int max_extfrag_threshold = 1000;
284 static struct ctl_table kern_table[] = {
286 .procname = "sched_child_runs_first",
287 .data = &sysctl_sched_child_runs_first,
288 .maxlen = sizeof(unsigned int),
290 .proc_handler = proc_dointvec,
292 #ifdef CONFIG_SCHED_DEBUG
294 .procname = "sched_min_granularity_ns",
295 .data = &sysctl_sched_min_granularity,
296 .maxlen = sizeof(unsigned int),
298 .proc_handler = sched_proc_update_handler,
299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
303 .procname = "sched_latency_ns",
304 .data = &sysctl_sched_latency,
305 .maxlen = sizeof(unsigned int),
307 .proc_handler = sched_proc_update_handler,
308 .extra1 = &min_sched_granularity_ns,
309 .extra2 = &max_sched_granularity_ns,
312 .procname = "sched_wakeup_granularity_ns",
313 .data = &sysctl_sched_wakeup_granularity,
314 .maxlen = sizeof(unsigned int),
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_wakeup_granularity_ns,
318 .extra2 = &max_wakeup_granularity_ns,
321 .procname = "sched_yield_sleep_threshold",
322 .data = &sysctl_sched_yield_sleep_threshold,
323 .maxlen = sizeof(int),
325 .proc_handler = proc_dointvec,
328 .procname = "sched_yield_sleep_duration",
329 .data = &sysctl_sched_yield_sleep_duration,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = proc_dointvec,
336 .procname = "sched_tunable_scaling",
337 .data = &sysctl_sched_tunable_scaling,
338 .maxlen = sizeof(enum sched_tunable_scaling),
340 .proc_handler = sched_proc_update_handler,
341 .extra1 = &min_sched_tunable_scaling,
342 .extra2 = &max_sched_tunable_scaling,
345 .procname = "sched_migration_cost_ns",
346 .data = &sysctl_sched_migration_cost,
347 .maxlen = sizeof(unsigned int),
349 .proc_handler = proc_dointvec,
352 .procname = "sched_nr_migrate",
353 .data = &sysctl_sched_nr_migrate,
354 .maxlen = sizeof(unsigned int),
356 .proc_handler = proc_dointvec,
359 .procname = "sched_time_avg_ms",
360 .data = &sysctl_sched_time_avg,
361 .maxlen = sizeof(unsigned int),
363 .proc_handler = proc_dointvec,
366 .procname = "sched_shares_window_ns",
367 .data = &sysctl_sched_shares_window,
368 .maxlen = sizeof(unsigned int),
370 .proc_handler = proc_dointvec,
373 .procname = "timer_migration",
374 .data = &sysctl_timer_migration,
375 .maxlen = sizeof(unsigned int),
377 .proc_handler = proc_dointvec_minmax,
381 #endif /* CONFIG_SMP */
382 #ifdef CONFIG_NUMA_BALANCING
384 .procname = "numa_balancing_scan_delay_ms",
385 .data = &sysctl_numa_balancing_scan_delay,
386 .maxlen = sizeof(unsigned int),
388 .proc_handler = proc_dointvec,
391 .procname = "numa_balancing_scan_period_min_ms",
392 .data = &sysctl_numa_balancing_scan_period_min,
393 .maxlen = sizeof(unsigned int),
395 .proc_handler = proc_dointvec,
398 .procname = "numa_balancing_scan_period_reset",
399 .data = &sysctl_numa_balancing_scan_period_reset,
400 .maxlen = sizeof(unsigned int),
402 .proc_handler = proc_dointvec,
405 .procname = "numa_balancing_scan_period_max_ms",
406 .data = &sysctl_numa_balancing_scan_period_max,
407 .maxlen = sizeof(unsigned int),
409 .proc_handler = proc_dointvec,
412 .procname = "numa_balancing_scan_size_mb",
413 .data = &sysctl_numa_balancing_scan_size,
414 .maxlen = sizeof(unsigned int),
416 .proc_handler = proc_dointvec,
418 #endif /* CONFIG_NUMA_BALANCING */
419 #endif /* CONFIG_SCHED_DEBUG */
421 .procname = "sched_rt_period_us",
422 .data = &sysctl_sched_rt_period,
423 .maxlen = sizeof(unsigned int),
425 .proc_handler = sched_rt_handler,
428 .procname = "sched_rt_runtime_us",
429 .data = &sysctl_sched_rt_runtime,
430 .maxlen = sizeof(int),
432 .proc_handler = sched_rt_handler,
435 .procname = "sched_rr_timeslice_ms",
436 .data = &sched_rr_timeslice,
437 .maxlen = sizeof(int),
439 .proc_handler = sched_rr_handler,
441 #ifdef CONFIG_SCHED_AUTOGROUP
443 .procname = "sched_autogroup_enabled",
444 .data = &sysctl_sched_autogroup_enabled,
445 .maxlen = sizeof(unsigned int),
447 .proc_handler = proc_dointvec_minmax,
452 #ifdef CONFIG_CFS_BANDWIDTH
454 .procname = "sched_cfs_bandwidth_slice_us",
455 .data = &sysctl_sched_cfs_bandwidth_slice,
456 .maxlen = sizeof(unsigned int),
458 .proc_handler = proc_dointvec_minmax,
462 #ifdef CONFIG_PROVE_LOCKING
464 .procname = "prove_locking",
465 .data = &prove_locking,
466 .maxlen = sizeof(int),
468 .proc_handler = proc_dointvec,
471 #ifdef CONFIG_LOCK_STAT
473 .procname = "lock_stat",
475 .maxlen = sizeof(int),
477 .proc_handler = proc_dointvec,
482 .data = &panic_timeout,
483 .maxlen = sizeof(int),
485 .proc_handler = proc_dointvec,
487 #ifdef CONFIG_COREDUMP
489 .procname = "core_uses_pid",
490 .data = &core_uses_pid,
491 .maxlen = sizeof(int),
493 .proc_handler = proc_dointvec,
496 .procname = "core_pattern",
497 .data = core_pattern,
498 .maxlen = CORENAME_MAX_SIZE,
500 .proc_handler = proc_dostring_coredump,
503 .procname = "core_pipe_limit",
504 .data = &core_pipe_limit,
505 .maxlen = sizeof(unsigned int),
507 .proc_handler = proc_dointvec,
510 #ifdef CONFIG_PROC_SYSCTL
512 .procname = "tainted",
513 .maxlen = sizeof(long),
515 .proc_handler = proc_taint,
518 #ifdef CONFIG_LATENCYTOP
520 .procname = "latencytop",
521 .data = &latencytop_enabled,
522 .maxlen = sizeof(int),
524 .proc_handler = proc_dointvec,
527 #ifdef CONFIG_BLK_DEV_INITRD
529 .procname = "real-root-dev",
530 .data = &real_root_dev,
531 .maxlen = sizeof(int),
533 .proc_handler = proc_dointvec,
537 .procname = "print-fatal-signals",
538 .data = &print_fatal_signals,
539 .maxlen = sizeof(int),
541 .proc_handler = proc_dointvec,
545 .procname = "reboot-cmd",
546 .data = reboot_command,
549 .proc_handler = proc_dostring,
552 .procname = "stop-a",
553 .data = &stop_a_enabled,
554 .maxlen = sizeof (int),
556 .proc_handler = proc_dointvec,
559 .procname = "scons-poweroff",
560 .data = &scons_pwroff,
561 .maxlen = sizeof (int),
563 .proc_handler = proc_dointvec,
566 #ifdef CONFIG_SPARC64
568 .procname = "tsb-ratio",
569 .data = &sysctl_tsb_ratio,
570 .maxlen = sizeof (int),
572 .proc_handler = proc_dointvec,
577 .procname = "soft-power",
578 .data = &pwrsw_enabled,
579 .maxlen = sizeof (int),
581 .proc_handler = proc_dointvec,
584 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
586 .procname = "unaligned-trap",
587 .data = &unaligned_enabled,
588 .maxlen = sizeof (int),
590 .proc_handler = proc_dointvec,
594 .procname = "ctrl-alt-del",
596 .maxlen = sizeof(int),
598 .proc_handler = proc_dointvec,
600 #ifdef CONFIG_FUNCTION_TRACER
602 .procname = "ftrace_enabled",
603 .data = &ftrace_enabled,
604 .maxlen = sizeof(int),
606 .proc_handler = ftrace_enable_sysctl,
609 #ifdef CONFIG_STACK_TRACER
611 .procname = "stack_tracer_enabled",
612 .data = &stack_tracer_enabled,
613 .maxlen = sizeof(int),
615 .proc_handler = stack_trace_sysctl,
618 #ifdef CONFIG_TRACING
620 .procname = "ftrace_dump_on_oops",
621 .data = &ftrace_dump_on_oops,
622 .maxlen = sizeof(int),
624 .proc_handler = proc_dointvec,
627 #ifdef CONFIG_MODULES
629 .procname = "modprobe",
630 .data = &modprobe_path,
631 .maxlen = KMOD_PATH_LEN,
633 .proc_handler = proc_dostring,
636 .procname = "modules_disabled",
637 .data = &modules_disabled,
638 .maxlen = sizeof(int),
640 /* only handle a transition from default "0" to "1" */
641 .proc_handler = proc_dointvec_minmax,
648 .procname = "hotplug",
649 .data = &uevent_helper,
650 .maxlen = UEVENT_HELPER_PATH_LEN,
652 .proc_handler = proc_dostring,
655 #ifdef CONFIG_CHR_DEV_SG
657 .procname = "sg-big-buff",
658 .data = &sg_big_buff,
659 .maxlen = sizeof (int),
661 .proc_handler = proc_dointvec,
664 #ifdef CONFIG_BSD_PROCESS_ACCT
668 .maxlen = 3*sizeof(int),
670 .proc_handler = proc_dointvec,
673 #ifdef CONFIG_MAGIC_SYSRQ
676 .data = &__sysrq_enabled,
677 .maxlen = sizeof (int),
679 .proc_handler = sysrq_sysctl_handler,
682 #ifdef CONFIG_PROC_SYSCTL
684 .procname = "cad_pid",
686 .maxlen = sizeof (int),
688 .proc_handler = proc_do_cad_pid,
692 .procname = "threads-max",
693 .data = &max_threads,
694 .maxlen = sizeof(int),
696 .proc_handler = proc_dointvec,
699 .procname = "random",
701 .child = random_table,
704 .procname = "usermodehelper",
706 .child = usermodehelper_table,
709 .procname = "overflowuid",
710 .data = &overflowuid,
711 .maxlen = sizeof(int),
713 .proc_handler = proc_dointvec_minmax,
714 .extra1 = &minolduid,
715 .extra2 = &maxolduid,
718 .procname = "overflowgid",
719 .data = &overflowgid,
720 .maxlen = sizeof(int),
722 .proc_handler = proc_dointvec_minmax,
723 .extra1 = &minolduid,
724 .extra2 = &maxolduid,
727 #ifdef CONFIG_MATHEMU
729 .procname = "ieee_emulation_warnings",
730 .data = &sysctl_ieee_emulation_warnings,
731 .maxlen = sizeof(int),
733 .proc_handler = proc_dointvec,
737 .procname = "userprocess_debug",
738 .data = &show_unhandled_signals,
739 .maxlen = sizeof(int),
741 .proc_handler = proc_dointvec,
745 .procname = "pid_max",
747 .maxlen = sizeof (int),
749 .proc_handler = proc_dointvec_minmax,
750 .extra1 = &pid_max_min,
751 .extra2 = &pid_max_max,
754 .procname = "panic_on_oops",
755 .data = &panic_on_oops,
756 .maxlen = sizeof(int),
758 .proc_handler = proc_dointvec,
760 #if defined CONFIG_PRINTK
762 .procname = "printk",
763 .data = &console_loglevel,
764 .maxlen = 5*sizeof(int),
766 .proc_handler = proc_dointvec,
769 .procname = "printk_ratelimit",
770 .data = &printk_ratelimit_state.interval,
771 .maxlen = sizeof(int),
773 .proc_handler = proc_dointvec_jiffies,
776 .procname = "printk_ratelimit_burst",
777 .data = &printk_ratelimit_state.burst,
778 .maxlen = sizeof(int),
780 .proc_handler = proc_dointvec,
783 .procname = "printk_delay",
784 .data = &printk_delay_msec,
785 .maxlen = sizeof(int),
787 .proc_handler = proc_dointvec_minmax,
789 .extra2 = &ten_thousand,
792 .procname = "dmesg_restrict",
793 .data = &dmesg_restrict,
794 .maxlen = sizeof(int),
796 .proc_handler = proc_dointvec_minmax_sysadmin,
801 .procname = "kptr_restrict",
802 .data = &kptr_restrict,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dointvec_minmax_sysadmin,
811 .procname = "ngroups_max",
812 .data = &ngroups_max,
813 .maxlen = sizeof (int),
815 .proc_handler = proc_dointvec,
818 .procname = "cap_last_cap",
819 .data = (void *)&cap_last_cap,
820 .maxlen = sizeof(int),
822 .proc_handler = proc_dointvec,
824 #if defined(CONFIG_LOCKUP_DETECTOR)
826 .procname = "watchdog",
827 .data = &watchdog_enabled,
828 .maxlen = sizeof (int),
830 .proc_handler = proc_dowatchdog,
835 .procname = "watchdog_thresh",
836 .data = &watchdog_thresh,
837 .maxlen = sizeof(int),
839 .proc_handler = proc_dowatchdog,
844 .procname = "softlockup_panic",
845 .data = &softlockup_panic,
846 .maxlen = sizeof(int),
848 .proc_handler = proc_dointvec_minmax,
853 .procname = "nmi_watchdog",
854 .data = &watchdog_enabled,
855 .maxlen = sizeof (int),
857 .proc_handler = proc_dowatchdog,
862 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
864 .procname = "unknown_nmi_panic",
865 .data = &unknown_nmi_panic,
866 .maxlen = sizeof (int),
868 .proc_handler = proc_dointvec,
871 #if defined(CONFIG_X86)
873 .procname = "panic_on_unrecovered_nmi",
874 .data = &panic_on_unrecovered_nmi,
875 .maxlen = sizeof(int),
877 .proc_handler = proc_dointvec,
880 .procname = "panic_on_io_nmi",
881 .data = &panic_on_io_nmi,
882 .maxlen = sizeof(int),
884 .proc_handler = proc_dointvec,
886 #ifdef CONFIG_DEBUG_STACKOVERFLOW
888 .procname = "panic_on_stackoverflow",
889 .data = &sysctl_panic_on_stackoverflow,
890 .maxlen = sizeof(int),
892 .proc_handler = proc_dointvec,
896 .procname = "bootloader_type",
897 .data = &bootloader_type,
898 .maxlen = sizeof (int),
900 .proc_handler = proc_dointvec,
903 .procname = "bootloader_version",
904 .data = &bootloader_version,
905 .maxlen = sizeof (int),
907 .proc_handler = proc_dointvec,
910 .procname = "kstack_depth_to_print",
911 .data = &kstack_depth_to_print,
912 .maxlen = sizeof(int),
914 .proc_handler = proc_dointvec,
917 .procname = "io_delay_type",
918 .data = &io_delay_type,
919 .maxlen = sizeof(int),
921 .proc_handler = proc_dointvec,
924 #if defined(CONFIG_MMU)
926 .procname = "randomize_va_space",
927 .data = &randomize_va_space,
928 .maxlen = sizeof(int),
930 .proc_handler = proc_dointvec,
933 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
935 .procname = "spin_retry",
937 .maxlen = sizeof (int),
939 .proc_handler = proc_dointvec,
942 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
944 .procname = "acpi_video_flags",
945 .data = &acpi_realmode_flags,
946 .maxlen = sizeof (unsigned long),
948 .proc_handler = proc_doulongvec_minmax,
951 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
953 .procname = "ignore-unaligned-usertrap",
954 .data = &no_unaligned_warning,
955 .maxlen = sizeof (int),
957 .proc_handler = proc_dointvec,
962 .procname = "unaligned-dump-stack",
963 .data = &unaligned_dump_stack,
964 .maxlen = sizeof (int),
966 .proc_handler = proc_dointvec,
969 #ifdef CONFIG_DETECT_HUNG_TASK
971 .procname = "hung_task_panic",
972 .data = &sysctl_hung_task_panic,
973 .maxlen = sizeof(int),
975 .proc_handler = proc_dointvec_minmax,
980 .procname = "hung_task_check_count",
981 .data = &sysctl_hung_task_check_count,
982 .maxlen = sizeof(unsigned long),
984 .proc_handler = proc_doulongvec_minmax,
987 .procname = "hung_task_timeout_secs",
988 .data = &sysctl_hung_task_timeout_secs,
989 .maxlen = sizeof(unsigned long),
991 .proc_handler = proc_dohung_task_timeout_secs,
992 .extra2 = &hung_task_timeout_max,
995 .procname = "hung_task_warnings",
996 .data = &sysctl_hung_task_warnings,
997 .maxlen = sizeof(unsigned long),
999 .proc_handler = proc_doulongvec_minmax,
1002 #ifdef CONFIG_COMPAT
1004 .procname = "compat-log",
1005 .data = &compat_log,
1006 .maxlen = sizeof (int),
1008 .proc_handler = proc_dointvec,
1011 #ifdef CONFIG_RT_MUTEXES
1013 .procname = "max_lock_depth",
1014 .data = &max_lock_depth,
1015 .maxlen = sizeof(int),
1017 .proc_handler = proc_dointvec,
1021 .procname = "poweroff_cmd",
1022 .data = &poweroff_cmd,
1023 .maxlen = POWEROFF_CMD_PATH_LEN,
1025 .proc_handler = proc_dostring,
1031 .child = key_sysctls,
1034 #ifdef CONFIG_RCU_TORTURE_TEST
1036 .procname = "rcutorture_runnable",
1037 .data = &rcutorture_runnable,
1038 .maxlen = sizeof(int),
1040 .proc_handler = proc_dointvec,
1043 #ifdef CONFIG_PERF_EVENTS
1045 * User-space scripts rely on the existence of this file
1046 * as a feature check for perf_events being enabled.
1048 * So it's an ABI, do not remove!
1051 .procname = "perf_event_paranoid",
1052 .data = &sysctl_perf_event_paranoid,
1053 .maxlen = sizeof(sysctl_perf_event_paranoid),
1055 .proc_handler = proc_dointvec,
1058 .procname = "perf_event_mlock_kb",
1059 .data = &sysctl_perf_event_mlock,
1060 .maxlen = sizeof(sysctl_perf_event_mlock),
1062 .proc_handler = proc_dointvec,
1065 .procname = "perf_event_max_sample_rate",
1066 .data = &sysctl_perf_event_sample_rate,
1067 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1069 .proc_handler = perf_proc_update_handler,
1073 .procname = "perf_cpu_time_max_percent",
1074 .data = &sysctl_perf_cpu_time_max_percent,
1075 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1077 .proc_handler = perf_cpu_time_max_percent_handler,
1079 .extra2 = &one_hundred,
1082 #ifdef CONFIG_KMEMCHECK
1084 .procname = "kmemcheck",
1085 .data = &kmemcheck_enabled,
1086 .maxlen = sizeof(int),
1088 .proc_handler = proc_dointvec,
1093 .procname = "blk_iopoll",
1094 .data = &blk_iopoll_enabled,
1095 .maxlen = sizeof(int),
1097 .proc_handler = proc_dointvec,
1103 static struct ctl_table vm_table[] = {
1105 .procname = "lazy_vfree_pages",
1106 .data = &sysctl_lazy_vfree_pages,
1107 .maxlen = sizeof(sysctl_lazy_vfree_pages),
1109 .proc_handler = proc_dointvec,
1112 .procname = "lazy_vfree_tlb_flush_all_threshold",
1113 .data = &sysctl_lazy_vfree_tlb_flush_all_threshold,
1114 .maxlen = sizeof(sysctl_lazy_vfree_tlb_flush_all_threshold),
1116 .proc_handler = proc_dointvec,
1119 .procname = "overcommit_memory",
1120 .data = &sysctl_overcommit_memory,
1121 .maxlen = sizeof(sysctl_overcommit_memory),
1123 .proc_handler = proc_dointvec_minmax,
1128 .procname = "panic_on_oom",
1129 .data = &sysctl_panic_on_oom,
1130 .maxlen = sizeof(sysctl_panic_on_oom),
1132 .proc_handler = proc_dointvec_minmax,
1137 .procname = "oom_kill_allocating_task",
1138 .data = &sysctl_oom_kill_allocating_task,
1139 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1141 .proc_handler = proc_dointvec,
1144 .procname = "oom_dump_tasks",
1145 .data = &sysctl_oom_dump_tasks,
1146 .maxlen = sizeof(sysctl_oom_dump_tasks),
1148 .proc_handler = proc_dointvec,
1151 .procname = "overcommit_ratio",
1152 .data = &sysctl_overcommit_ratio,
1153 .maxlen = sizeof(sysctl_overcommit_ratio),
1155 .proc_handler = proc_dointvec,
1158 .procname = "page-cluster",
1159 .data = &page_cluster,
1160 .maxlen = sizeof(int),
1162 .proc_handler = proc_dointvec_minmax,
1166 .procname = "dirty_background_ratio",
1167 .data = &dirty_background_ratio,
1168 .maxlen = sizeof(dirty_background_ratio),
1170 .proc_handler = dirty_background_ratio_handler,
1172 .extra2 = &one_hundred,
1175 .procname = "dirty_background_bytes",
1176 .data = &dirty_background_bytes,
1177 .maxlen = sizeof(dirty_background_bytes),
1179 .proc_handler = dirty_background_bytes_handler,
1183 .procname = "dirty_ratio",
1184 .data = &vm_dirty_ratio,
1185 .maxlen = sizeof(vm_dirty_ratio),
1187 .proc_handler = dirty_ratio_handler,
1189 .extra2 = &one_hundred,
1192 .procname = "dirty_bytes",
1193 .data = &vm_dirty_bytes,
1194 .maxlen = sizeof(vm_dirty_bytes),
1196 .proc_handler = dirty_bytes_handler,
1197 .extra1 = &dirty_bytes_min,
1200 .procname = "dirty_writeback_centisecs",
1201 .data = &dirty_writeback_interval,
1202 .maxlen = sizeof(dirty_writeback_interval),
1204 .proc_handler = dirty_writeback_centisecs_handler,
1207 .procname = "dirty_expire_centisecs",
1208 .data = &dirty_expire_interval,
1209 .maxlen = sizeof(dirty_expire_interval),
1211 .proc_handler = proc_dointvec_minmax,
1215 .procname = "nr_pdflush_threads",
1216 .mode = 0444 /* read-only */,
1217 .proc_handler = pdflush_proc_obsolete,
1220 .procname = "swappiness",
1221 .data = &vm_swappiness,
1222 .maxlen = sizeof(vm_swappiness),
1224 .proc_handler = proc_dointvec_minmax,
1226 .extra2 = &one_hundred,
1228 #ifdef CONFIG_HUGETLB_PAGE
1230 .procname = "nr_hugepages",
1232 .maxlen = sizeof(unsigned long),
1234 .proc_handler = hugetlb_sysctl_handler,
1235 .extra1 = (void *)&hugetlb_zero,
1236 .extra2 = (void *)&hugetlb_infinity,
1240 .procname = "nr_hugepages_mempolicy",
1242 .maxlen = sizeof(unsigned long),
1244 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1245 .extra1 = (void *)&hugetlb_zero,
1246 .extra2 = (void *)&hugetlb_infinity,
1250 .procname = "hugetlb_shm_group",
1251 .data = &sysctl_hugetlb_shm_group,
1252 .maxlen = sizeof(gid_t),
1254 .proc_handler = proc_dointvec,
1257 .procname = "hugepages_treat_as_movable",
1258 .data = &hugepages_treat_as_movable,
1259 .maxlen = sizeof(int),
1261 .proc_handler = hugetlb_treat_movable_handler,
1264 .procname = "nr_overcommit_hugepages",
1266 .maxlen = sizeof(unsigned long),
1268 .proc_handler = hugetlb_overcommit_handler,
1269 .extra1 = (void *)&hugetlb_zero,
1270 .extra2 = (void *)&hugetlb_infinity,
1274 .procname = "lowmem_reserve_ratio",
1275 .data = &sysctl_lowmem_reserve_ratio,
1276 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1278 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1281 .procname = "drop_caches",
1282 .data = &sysctl_drop_caches,
1283 .maxlen = sizeof(int),
1285 .proc_handler = drop_caches_sysctl_handler,
1289 #ifdef CONFIG_COMPACTION
1291 .procname = "compact_memory",
1292 .data = &sysctl_compact_memory,
1293 .maxlen = sizeof(int),
1295 .proc_handler = sysctl_compaction_handler,
1298 .procname = "extfrag_threshold",
1299 .data = &sysctl_extfrag_threshold,
1300 .maxlen = sizeof(int),
1302 .proc_handler = sysctl_extfrag_handler,
1303 .extra1 = &min_extfrag_threshold,
1304 .extra2 = &max_extfrag_threshold,
1307 #endif /* CONFIG_COMPACTION */
1309 .procname = "min_free_kbytes",
1310 .data = &min_free_kbytes,
1311 .maxlen = sizeof(min_free_kbytes),
1313 .proc_handler = min_free_kbytes_sysctl_handler,
1317 .procname = "extra_free_kbytes",
1318 .data = &extra_free_kbytes,
1319 .maxlen = sizeof(extra_free_kbytes),
1321 .proc_handler = min_free_kbytes_sysctl_handler,
1325 .procname = "min_free_order_shift",
1326 .data = &min_free_order_shift,
1327 .maxlen = sizeof(min_free_order_shift),
1329 .proc_handler = &proc_dointvec
1332 .procname = "percpu_pagelist_fraction",
1333 .data = &percpu_pagelist_fraction,
1334 .maxlen = sizeof(percpu_pagelist_fraction),
1336 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1337 .extra1 = &min_percpu_pagelist_fract,
1341 .procname = "max_map_count",
1342 .data = &sysctl_max_map_count,
1343 .maxlen = sizeof(sysctl_max_map_count),
1345 .proc_handler = proc_dointvec_minmax,
1350 .procname = "nr_trim_pages",
1351 .data = &sysctl_nr_trim_pages,
1352 .maxlen = sizeof(sysctl_nr_trim_pages),
1354 .proc_handler = proc_dointvec_minmax,
1359 .procname = "laptop_mode",
1360 .data = &laptop_mode,
1361 .maxlen = sizeof(laptop_mode),
1363 .proc_handler = proc_dointvec_jiffies,
1366 .procname = "block_dump",
1367 .data = &block_dump,
1368 .maxlen = sizeof(block_dump),
1370 .proc_handler = proc_dointvec,
1374 .procname = "vfs_cache_pressure",
1375 .data = &sysctl_vfs_cache_pressure,
1376 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1378 .proc_handler = proc_dointvec,
1381 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1383 .procname = "legacy_va_layout",
1384 .data = &sysctl_legacy_va_layout,
1385 .maxlen = sizeof(sysctl_legacy_va_layout),
1387 .proc_handler = proc_dointvec,
1393 .procname = "zone_reclaim_mode",
1394 .data = &zone_reclaim_mode,
1395 .maxlen = sizeof(zone_reclaim_mode),
1397 .proc_handler = proc_dointvec,
1401 .procname = "min_unmapped_ratio",
1402 .data = &sysctl_min_unmapped_ratio,
1403 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1405 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1407 .extra2 = &one_hundred,
1410 .procname = "min_slab_ratio",
1411 .data = &sysctl_min_slab_ratio,
1412 .maxlen = sizeof(sysctl_min_slab_ratio),
1414 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1416 .extra2 = &one_hundred,
1421 .procname = "stat_interval",
1422 .data = &sysctl_stat_interval,
1423 .maxlen = sizeof(sysctl_stat_interval),
1425 .proc_handler = proc_dointvec_jiffies,
1430 .procname = "mmap_min_addr",
1431 .data = &dac_mmap_min_addr,
1432 .maxlen = sizeof(unsigned long),
1434 .proc_handler = mmap_min_addr_handler,
1439 .procname = "numa_zonelist_order",
1440 .data = &numa_zonelist_order,
1441 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1443 .proc_handler = numa_zonelist_order_handler,
1446 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1447 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1449 .procname = "vdso_enabled",
1450 .data = &vdso_enabled,
1451 .maxlen = sizeof(vdso_enabled),
1453 .proc_handler = proc_dointvec,
1457 #ifdef CONFIG_HIGHMEM
1459 .procname = "highmem_is_dirtyable",
1460 .data = &vm_highmem_is_dirtyable,
1461 .maxlen = sizeof(vm_highmem_is_dirtyable),
1463 .proc_handler = proc_dointvec_minmax,
1469 .procname = "scan_unevictable_pages",
1470 .data = &scan_unevictable_pages,
1471 .maxlen = sizeof(scan_unevictable_pages),
1473 .proc_handler = scan_unevictable_handler,
1475 #ifdef CONFIG_MEMORY_FAILURE
1477 .procname = "memory_failure_early_kill",
1478 .data = &sysctl_memory_failure_early_kill,
1479 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1481 .proc_handler = proc_dointvec_minmax,
1486 .procname = "memory_failure_recovery",
1487 .data = &sysctl_memory_failure_recovery,
1488 .maxlen = sizeof(sysctl_memory_failure_recovery),
1490 .proc_handler = proc_dointvec_minmax,
1496 .procname = "user_reserve_kbytes",
1497 .data = &sysctl_user_reserve_kbytes,
1498 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1500 .proc_handler = proc_doulongvec_minmax,
1503 .procname = "admin_reserve_kbytes",
1504 .data = &sysctl_admin_reserve_kbytes,
1505 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1507 .proc_handler = proc_doulongvec_minmax,
1512 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1513 static struct ctl_table binfmt_misc_table[] = {
1518 static struct ctl_table fs_table[] = {
1520 .procname = "inode-nr",
1521 .data = &inodes_stat,
1522 .maxlen = 2*sizeof(int),
1524 .proc_handler = proc_nr_inodes,
1527 .procname = "inode-state",
1528 .data = &inodes_stat,
1529 .maxlen = 7*sizeof(int),
1531 .proc_handler = proc_nr_inodes,
1534 .procname = "file-nr",
1535 .data = &files_stat,
1536 .maxlen = sizeof(files_stat),
1538 .proc_handler = proc_nr_files,
1541 .procname = "file-max",
1542 .data = &files_stat.max_files,
1543 .maxlen = sizeof(files_stat.max_files),
1545 .proc_handler = proc_doulongvec_minmax,
1548 .procname = "nr_open",
1549 .data = &sysctl_nr_open,
1550 .maxlen = sizeof(int),
1552 .proc_handler = proc_dointvec_minmax,
1553 .extra1 = &sysctl_nr_open_min,
1554 .extra2 = &sysctl_nr_open_max,
1557 .procname = "dentry-state",
1558 .data = &dentry_stat,
1559 .maxlen = 6*sizeof(int),
1561 .proc_handler = proc_nr_dentry,
1564 .procname = "overflowuid",
1565 .data = &fs_overflowuid,
1566 .maxlen = sizeof(int),
1568 .proc_handler = proc_dointvec_minmax,
1569 .extra1 = &minolduid,
1570 .extra2 = &maxolduid,
1573 .procname = "overflowgid",
1574 .data = &fs_overflowgid,
1575 .maxlen = sizeof(int),
1577 .proc_handler = proc_dointvec_minmax,
1578 .extra1 = &minolduid,
1579 .extra2 = &maxolduid,
1581 #ifdef CONFIG_FILE_LOCKING
1583 .procname = "leases-enable",
1584 .data = &leases_enable,
1585 .maxlen = sizeof(int),
1587 .proc_handler = proc_dointvec,
1590 #ifdef CONFIG_DNOTIFY
1592 .procname = "dir-notify-enable",
1593 .data = &dir_notify_enable,
1594 .maxlen = sizeof(int),
1596 .proc_handler = proc_dointvec,
1600 #ifdef CONFIG_FILE_LOCKING
1602 .procname = "lease-break-time",
1603 .data = &lease_break_time,
1604 .maxlen = sizeof(int),
1606 .proc_handler = proc_dointvec,
1611 .procname = "aio-nr",
1613 .maxlen = sizeof(aio_nr),
1615 .proc_handler = proc_doulongvec_minmax,
1618 .procname = "aio-max-nr",
1619 .data = &aio_max_nr,
1620 .maxlen = sizeof(aio_max_nr),
1622 .proc_handler = proc_doulongvec_minmax,
1624 #endif /* CONFIG_AIO */
1625 #ifdef CONFIG_INOTIFY_USER
1627 .procname = "inotify",
1629 .child = inotify_table,
1634 .procname = "epoll",
1636 .child = epoll_table,
1641 .procname = "protected_symlinks",
1642 .data = &sysctl_protected_symlinks,
1643 .maxlen = sizeof(int),
1645 .proc_handler = proc_dointvec_minmax,
1650 .procname = "protected_hardlinks",
1651 .data = &sysctl_protected_hardlinks,
1652 .maxlen = sizeof(int),
1654 .proc_handler = proc_dointvec_minmax,
1659 .procname = "suid_dumpable",
1660 .data = &suid_dumpable,
1661 .maxlen = sizeof(int),
1663 .proc_handler = proc_dointvec_minmax_coredump,
1667 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1669 .procname = "binfmt_misc",
1671 .child = binfmt_misc_table,
1675 .procname = "pipe-max-size",
1676 .data = &pipe_max_size,
1677 .maxlen = sizeof(int),
1679 .proc_handler = &pipe_proc_fn,
1680 .extra1 = &pipe_min_size,
1685 static struct ctl_table debug_table[] = {
1686 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1688 .procname = "exception-trace",
1689 .data = &show_unhandled_signals,
1690 .maxlen = sizeof(int),
1692 .proc_handler = proc_dointvec
1695 #if defined(CONFIG_OPTPROBES)
1697 .procname = "kprobes-optimization",
1698 .data = &sysctl_kprobes_optimization,
1699 .maxlen = sizeof(int),
1701 .proc_handler = proc_kprobes_optimization_handler,
1709 static struct ctl_table dev_table[] = {
1713 int __init sysctl_init(void)
1715 struct ctl_table_header *hdr;
1717 hdr = register_sysctl_table(sysctl_base_table);
1718 kmemleak_not_leak(hdr);
1722 #endif /* CONFIG_SYSCTL */
1728 #ifdef CONFIG_PROC_SYSCTL
1730 static int _proc_do_string(void* data, int maxlen, int write,
1731 void __user *buffer,
1732 size_t *lenp, loff_t *ppos)
1738 if (!data || !maxlen || !*lenp) {
1746 while (len < *lenp) {
1747 if (get_user(c, p++))
1749 if (c == 0 || c == '\n')
1755 if(copy_from_user(data, buffer, len))
1757 ((char *) data)[len] = 0;
1775 if(copy_to_user(buffer, data, len))
1778 if(put_user('\n', ((char __user *) buffer) + len))
1789 * proc_dostring - read a string sysctl
1790 * @table: the sysctl table
1791 * @write: %TRUE if this is a write to the sysctl file
1792 * @buffer: the user buffer
1793 * @lenp: the size of the user buffer
1794 * @ppos: file position
1796 * Reads/writes a string from/to the user buffer. If the kernel
1797 * buffer provided is not large enough to hold the string, the
1798 * string is truncated. The copied string is %NULL-terminated.
1799 * If the string is being read by the user process, it is copied
1800 * and a newline '\n' is added. It is truncated if the buffer is
1803 * Returns 0 on success.
1805 int proc_dostring(struct ctl_table *table, int write,
1806 void __user *buffer, size_t *lenp, loff_t *ppos)
1808 return _proc_do_string(table->data, table->maxlen, write,
1809 buffer, lenp, ppos);
1812 static size_t proc_skip_spaces(char **buf)
1815 char *tmp = skip_spaces(*buf);
1821 static void proc_skip_char(char **buf, size_t *size, const char v)
1831 #define TMPBUFLEN 22
1833 * proc_get_long - reads an ASCII formatted integer from a user buffer
1835 * @buf: a kernel buffer
1836 * @size: size of the kernel buffer
1837 * @val: this is where the number will be stored
1838 * @neg: set to %TRUE if number is negative
1839 * @perm_tr: a vector which contains the allowed trailers
1840 * @perm_tr_len: size of the perm_tr vector
1841 * @tr: pointer to store the trailer character
1843 * In case of success %0 is returned and @buf and @size are updated with
1844 * the amount of bytes read. If @tr is non-NULL and a trailing
1845 * character exists (size is non-zero after returning from this
1846 * function), @tr is updated with the trailing character.
1848 static int proc_get_long(char **buf, size_t *size,
1849 unsigned long *val, bool *neg,
1850 const char *perm_tr, unsigned perm_tr_len, char *tr)
1853 char *p, tmp[TMPBUFLEN];
1859 if (len > TMPBUFLEN - 1)
1860 len = TMPBUFLEN - 1;
1862 memcpy(tmp, *buf, len);
1866 if (*p == '-' && *size > 1) {
1874 *val = simple_strtoul(p, &p, 0);
1878 /* We don't know if the next char is whitespace thus we may accept
1879 * invalid integers (e.g. 1234...a) or two integers instead of one
1880 * (e.g. 123...1). So lets not allow such large numbers. */
1881 if (len == TMPBUFLEN - 1)
1884 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1887 if (tr && (len < *size))
1897 * proc_put_long - converts an integer to a decimal ASCII formatted string
1899 * @buf: the user buffer
1900 * @size: the size of the user buffer
1901 * @val: the integer to be converted
1902 * @neg: sign of the number, %TRUE for negative
1904 * In case of success %0 is returned and @buf and @size are updated with
1905 * the amount of bytes written.
1907 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1911 char tmp[TMPBUFLEN], *p = tmp;
1913 sprintf(p, "%s%lu", neg ? "-" : "", val);
1917 if (copy_to_user(*buf, tmp, len))
1925 static int proc_put_char(void __user **buf, size_t *size, char c)
1928 char __user **buffer = (char __user **)buf;
1929 if (put_user(c, *buffer))
1931 (*size)--, (*buffer)++;
1937 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1939 int write, void *data)
1942 *valp = *negp ? -*lvalp : *lvalp;
1947 *lvalp = (unsigned long)-val;
1950 *lvalp = (unsigned long)val;
1956 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1958 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1959 int write, void __user *buffer,
1960 size_t *lenp, loff_t *ppos,
1961 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1962 int write, void *data),
1965 int *i, vleft, first = 1, err = 0;
1966 unsigned long page = 0;
1970 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1975 i = (int *) tbl_data;
1976 vleft = table->maxlen / sizeof(*i);
1980 conv = do_proc_dointvec_conv;
1983 if (left > PAGE_SIZE - 1)
1984 left = PAGE_SIZE - 1;
1985 page = __get_free_page(GFP_TEMPORARY);
1986 kbuf = (char *) page;
1989 if (copy_from_user(kbuf, buffer, left)) {
1996 for (; left && vleft--; i++, first=0) {
2001 left -= proc_skip_spaces(&kbuf);
2005 err = proc_get_long(&kbuf, &left, &lval, &neg,
2007 sizeof(proc_wspace_sep), NULL);
2010 if (conv(&neg, &lval, i, 1, data)) {
2015 if (conv(&neg, &lval, i, 0, data)) {
2020 err = proc_put_char(&buffer, &left, '\t');
2023 err = proc_put_long(&buffer, &left, lval, neg);
2029 if (!write && !first && left && !err)
2030 err = proc_put_char(&buffer, &left, '\n');
2031 if (write && !err && left)
2032 left -= proc_skip_spaces(&kbuf);
2037 return err ? : -EINVAL;
2044 static int do_proc_dointvec(struct ctl_table *table, int write,
2045 void __user *buffer, size_t *lenp, loff_t *ppos,
2046 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2047 int write, void *data),
2050 return __do_proc_dointvec(table->data, table, write,
2051 buffer, lenp, ppos, conv, data);
2055 * proc_dointvec - read a vector of integers
2056 * @table: the sysctl table
2057 * @write: %TRUE if this is a write to the sysctl file
2058 * @buffer: the user buffer
2059 * @lenp: the size of the user buffer
2060 * @ppos: file position
2062 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2063 * values from/to the user buffer, treated as an ASCII string.
2065 * Returns 0 on success.
2067 int proc_dointvec(struct ctl_table *table, int write,
2068 void __user *buffer, size_t *lenp, loff_t *ppos)
2070 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2075 * Taint values can only be increased
2076 * This means we can safely use a temporary.
2078 static int proc_taint(struct ctl_table *table, int write,
2079 void __user *buffer, size_t *lenp, loff_t *ppos)
2082 unsigned long tmptaint = get_taint();
2085 if (write && !capable(CAP_SYS_ADMIN))
2090 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2096 * Poor man's atomic or. Not worth adding a primitive
2097 * to everyone's atomic.h for this
2100 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2101 if ((tmptaint >> i) & 1)
2102 add_taint(i, LOCKDEP_STILL_OK);
2109 #ifdef CONFIG_PRINTK
2110 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2111 void __user *buffer, size_t *lenp, loff_t *ppos)
2113 if (write && !capable(CAP_SYS_ADMIN))
2116 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2120 struct do_proc_dointvec_minmax_conv_param {
2125 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2127 int write, void *data)
2129 struct do_proc_dointvec_minmax_conv_param *param = data;
2131 int val = *negp ? -*lvalp : *lvalp;
2132 if ((param->min && *param->min > val) ||
2133 (param->max && *param->max < val))
2140 *lvalp = (unsigned long)-val;
2143 *lvalp = (unsigned long)val;
2150 * proc_dointvec_minmax - read a vector of integers with min/max values
2151 * @table: the sysctl table
2152 * @write: %TRUE if this is a write to the sysctl file
2153 * @buffer: the user buffer
2154 * @lenp: the size of the user buffer
2155 * @ppos: file position
2157 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2158 * values from/to the user buffer, treated as an ASCII string.
2160 * This routine will ensure the values are within the range specified by
2161 * table->extra1 (min) and table->extra2 (max).
2163 * Returns 0 on success.
2165 int proc_dointvec_minmax(struct ctl_table *table, int write,
2166 void __user *buffer, size_t *lenp, loff_t *ppos)
2168 struct do_proc_dointvec_minmax_conv_param param = {
2169 .min = (int *) table->extra1,
2170 .max = (int *) table->extra2,
2172 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2173 do_proc_dointvec_minmax_conv, ¶m);
2176 static void validate_coredump_safety(void)
2178 #ifdef CONFIG_COREDUMP
2179 if (suid_dumpable == SUID_DUMP_ROOT &&
2180 core_pattern[0] != '/' && core_pattern[0] != '|') {
2181 printk(KERN_WARNING "Unsafe core_pattern used with "\
2182 "suid_dumpable=2. Pipe handler or fully qualified "\
2183 "core dump path required.\n");
2188 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2189 void __user *buffer, size_t *lenp, loff_t *ppos)
2191 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2193 validate_coredump_safety();
2197 #ifdef CONFIG_COREDUMP
2198 static int proc_dostring_coredump(struct ctl_table *table, int write,
2199 void __user *buffer, size_t *lenp, loff_t *ppos)
2201 int error = proc_dostring(table, write, buffer, lenp, ppos);
2203 validate_coredump_safety();
2208 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2209 void __user *buffer,
2210 size_t *lenp, loff_t *ppos,
2211 unsigned long convmul,
2212 unsigned long convdiv)
2214 unsigned long *i, *min, *max;
2215 int vleft, first = 1, err = 0;
2216 unsigned long page = 0;
2220 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2225 i = (unsigned long *) data;
2226 min = (unsigned long *) table->extra1;
2227 max = (unsigned long *) table->extra2;
2228 vleft = table->maxlen / sizeof(unsigned long);
2232 if (left > PAGE_SIZE - 1)
2233 left = PAGE_SIZE - 1;
2234 page = __get_free_page(GFP_TEMPORARY);
2235 kbuf = (char *) page;
2238 if (copy_from_user(kbuf, buffer, left)) {
2245 for (; left && vleft--; i++, first = 0) {
2251 left -= proc_skip_spaces(&kbuf);
2253 err = proc_get_long(&kbuf, &left, &val, &neg,
2255 sizeof(proc_wspace_sep), NULL);
2260 if ((min && val < *min) || (max && val > *max))
2264 val = convdiv * (*i) / convmul;
2266 err = proc_put_char(&buffer, &left, '\t');
2267 err = proc_put_long(&buffer, &left, val, false);
2273 if (!write && !first && left && !err)
2274 err = proc_put_char(&buffer, &left, '\n');
2276 left -= proc_skip_spaces(&kbuf);
2281 return err ? : -EINVAL;
2288 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2289 void __user *buffer,
2290 size_t *lenp, loff_t *ppos,
2291 unsigned long convmul,
2292 unsigned long convdiv)
2294 return __do_proc_doulongvec_minmax(table->data, table, write,
2295 buffer, lenp, ppos, convmul, convdiv);
2299 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2300 * @table: the sysctl table
2301 * @write: %TRUE if this is a write to the sysctl file
2302 * @buffer: the user buffer
2303 * @lenp: the size of the user buffer
2304 * @ppos: file position
2306 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2307 * values from/to the user buffer, treated as an ASCII string.
2309 * This routine will ensure the values are within the range specified by
2310 * table->extra1 (min) and table->extra2 (max).
2312 * Returns 0 on success.
2314 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2315 void __user *buffer, size_t *lenp, loff_t *ppos)
2317 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2321 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2322 * @table: the sysctl table
2323 * @write: %TRUE if this is a write to the sysctl file
2324 * @buffer: the user buffer
2325 * @lenp: the size of the user buffer
2326 * @ppos: file position
2328 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2329 * values from/to the user buffer, treated as an ASCII string. The values
2330 * are treated as milliseconds, and converted to jiffies when they are stored.
2332 * This routine will ensure the values are within the range specified by
2333 * table->extra1 (min) and table->extra2 (max).
2335 * Returns 0 on success.
2337 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2338 void __user *buffer,
2339 size_t *lenp, loff_t *ppos)
2341 return do_proc_doulongvec_minmax(table, write, buffer,
2342 lenp, ppos, HZ, 1000l);
2346 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2348 int write, void *data)
2351 if (*lvalp > LONG_MAX / HZ)
2353 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2359 lval = (unsigned long)-val;
2362 lval = (unsigned long)val;
2369 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2371 int write, void *data)
2374 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2376 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2382 lval = (unsigned long)-val;
2385 lval = (unsigned long)val;
2387 *lvalp = jiffies_to_clock_t(lval);
2392 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2394 int write, void *data)
2397 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2403 lval = (unsigned long)-val;
2406 lval = (unsigned long)val;
2408 *lvalp = jiffies_to_msecs(lval);
2414 * proc_dointvec_jiffies - read a vector of integers as seconds
2415 * @table: the sysctl table
2416 * @write: %TRUE if this is a write to the sysctl file
2417 * @buffer: the user buffer
2418 * @lenp: the size of the user buffer
2419 * @ppos: file position
2421 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2422 * values from/to the user buffer, treated as an ASCII string.
2423 * The values read are assumed to be in seconds, and are converted into
2426 * Returns 0 on success.
2428 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2429 void __user *buffer, size_t *lenp, loff_t *ppos)
2431 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2432 do_proc_dointvec_jiffies_conv,NULL);
2436 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2437 * @table: the sysctl table
2438 * @write: %TRUE if this is a write to the sysctl file
2439 * @buffer: the user buffer
2440 * @lenp: the size of the user buffer
2441 * @ppos: pointer to the file position
2443 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2444 * values from/to the user buffer, treated as an ASCII string.
2445 * The values read are assumed to be in 1/USER_HZ seconds, and
2446 * are converted into jiffies.
2448 * Returns 0 on success.
2450 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2451 void __user *buffer, size_t *lenp, loff_t *ppos)
2453 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2454 do_proc_dointvec_userhz_jiffies_conv,NULL);
2458 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2459 * @table: the sysctl table
2460 * @write: %TRUE if this is a write to the sysctl file
2461 * @buffer: the user buffer
2462 * @lenp: the size of the user buffer
2463 * @ppos: file position
2464 * @ppos: the current position in the file
2466 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2467 * values from/to the user buffer, treated as an ASCII string.
2468 * The values read are assumed to be in 1/1000 seconds, and
2469 * are converted into jiffies.
2471 * Returns 0 on success.
2473 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2474 void __user *buffer, size_t *lenp, loff_t *ppos)
2476 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2477 do_proc_dointvec_ms_jiffies_conv, NULL);
2480 static int proc_do_cad_pid(struct ctl_table *table, int write,
2481 void __user *buffer, size_t *lenp, loff_t *ppos)
2483 struct pid *new_pid;
2487 tmp = pid_vnr(cad_pid);
2489 r = __do_proc_dointvec(&tmp, table, write, buffer,
2490 lenp, ppos, NULL, NULL);
2494 new_pid = find_get_pid(tmp);
2498 put_pid(xchg(&cad_pid, new_pid));
2503 * proc_do_large_bitmap - read/write from/to a large bitmap
2504 * @table: the sysctl table
2505 * @write: %TRUE if this is a write to the sysctl file
2506 * @buffer: the user buffer
2507 * @lenp: the size of the user buffer
2508 * @ppos: file position
2510 * The bitmap is stored at table->data and the bitmap length (in bits)
2513 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2514 * large bitmaps may be represented in a compact manner. Writing into
2515 * the file will clear the bitmap then update it with the given input.
2517 * Returns 0 on success.
2519 int proc_do_large_bitmap(struct ctl_table *table, int write,
2520 void __user *buffer, size_t *lenp, loff_t *ppos)
2524 size_t left = *lenp;
2525 unsigned long bitmap_len = table->maxlen;
2526 unsigned long *bitmap = (unsigned long *) table->data;
2527 unsigned long *tmp_bitmap = NULL;
2528 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2530 if (!bitmap_len || !left || (*ppos && !write)) {
2536 unsigned long page = 0;
2539 if (left > PAGE_SIZE - 1)
2540 left = PAGE_SIZE - 1;
2542 page = __get_free_page(GFP_TEMPORARY);
2543 kbuf = (char *) page;
2546 if (copy_from_user(kbuf, buffer, left)) {
2552 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2558 proc_skip_char(&kbuf, &left, '\n');
2559 while (!err && left) {
2560 unsigned long val_a, val_b;
2563 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2567 if (val_a >= bitmap_len || neg) {
2579 err = proc_get_long(&kbuf, &left, &val_b,
2580 &neg, tr_b, sizeof(tr_b),
2584 if (val_b >= bitmap_len || neg ||
2595 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2597 proc_skip_char(&kbuf, &left, '\n');
2601 unsigned long bit_a, bit_b = 0;
2604 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2605 if (bit_a >= bitmap_len)
2607 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2611 err = proc_put_char(&buffer, &left, ',');
2615 err = proc_put_long(&buffer, &left, bit_a, false);
2618 if (bit_a != bit_b) {
2619 err = proc_put_char(&buffer, &left, '-');
2622 err = proc_put_long(&buffer, &left, bit_b, false);
2630 err = proc_put_char(&buffer, &left, '\n');
2636 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2638 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2650 #else /* CONFIG_PROC_SYSCTL */
2652 int proc_dostring(struct ctl_table *table, int write,
2653 void __user *buffer, size_t *lenp, loff_t *ppos)
2658 int proc_dointvec(struct ctl_table *table, int write,
2659 void __user *buffer, size_t *lenp, loff_t *ppos)
2664 int proc_dointvec_minmax(struct ctl_table *table, int write,
2665 void __user *buffer, size_t *lenp, loff_t *ppos)
2670 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2671 void __user *buffer, size_t *lenp, loff_t *ppos)
2676 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2677 void __user *buffer, size_t *lenp, loff_t *ppos)
2682 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2683 void __user *buffer, size_t *lenp, loff_t *ppos)
2688 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2689 void __user *buffer, size_t *lenp, loff_t *ppos)
2694 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2695 void __user *buffer,
2696 size_t *lenp, loff_t *ppos)
2702 #endif /* CONFIG_PROC_SYSCTL */
2705 * No sense putting this after each symbol definition, twice,
2706 * exception granted :-)
2708 EXPORT_SYMBOL(proc_dointvec);
2709 EXPORT_SYMBOL(proc_dointvec_jiffies);
2710 EXPORT_SYMBOL(proc_dointvec_minmax);
2711 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2712 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2713 EXPORT_SYMBOL(proc_dostring);
2714 EXPORT_SYMBOL(proc_doulongvec_minmax);
2715 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);