2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
71 #include <asm/stacktrace.h>
75 #include <asm/setup.h>
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
86 #ifdef CONFIG_CHR_DEV_SG
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory;
99 extern int sysctl_overcommit_ratio;
100 extern int max_threads;
101 extern int suid_dumpable;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid;
104 extern char core_pattern[];
105 extern unsigned int core_pipe_limit;
108 extern int pid_max_min, pid_max_max;
109 extern int percpu_pagelist_fraction;
110 extern int compat_log;
111 extern int latencytop_enabled;
112 extern int sysctl_nr_open_min, sysctl_nr_open_max;
114 extern int sysctl_nr_trim_pages;
117 extern int blk_iopoll_enabled;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty = 60;
126 static int __maybe_unused one = 1;
127 static int __maybe_unused two = 2;
128 static int __maybe_unused three = 3;
129 static unsigned long one_ul = 1;
130 static int one_hundred = 100;
132 static int ten_thousand = 10000;
135 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
136 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
138 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
139 static int maxolduid = 65535;
140 static int minolduid;
141 static int min_percpu_pagelist_fract = 8;
143 static int ngroups_max = NGROUPS_MAX;
144 static const int cap_last_cap = CAP_LAST_CAP;
146 #ifdef CONFIG_INOTIFY_USER
147 #include <linux/inotify.h>
152 #ifdef CONFIG_SPARC64
153 extern int sysctl_tsb_ratio;
157 extern int pwrsw_enabled;
160 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
161 extern int unaligned_enabled;
165 extern int unaligned_dump_stack;
168 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
169 extern int no_unaligned_warning;
172 #ifdef CONFIG_PROC_SYSCTL
173 static int proc_do_cad_pid(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp, loff_t *ppos);
175 static int proc_taint(struct ctl_table *table, int write,
176 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
184 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
185 void __user *buffer, size_t *lenp, loff_t *ppos);
186 #ifdef CONFIG_COREDUMP
187 static int proc_dostring_coredump(struct ctl_table *table, int write,
188 void __user *buffer, size_t *lenp, loff_t *ppos);
191 #ifdef CONFIG_MAGIC_SYSRQ
192 /* Note: sysrq code uses it's own private copy */
193 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
195 static int sysrq_sysctl_handler(ctl_table *table, int write,
196 void __user *buffer, size_t *lenp,
201 error = proc_dointvec(table, write, buffer, lenp, ppos);
206 sysrq_toggle_support(__sysrq_enabled);
213 static struct ctl_table kern_table[];
214 static struct ctl_table vm_table[];
215 static struct ctl_table fs_table[];
216 static struct ctl_table debug_table[];
217 static struct ctl_table dev_table[];
218 extern struct ctl_table random_table[];
220 extern struct ctl_table epoll_table[];
223 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
224 int sysctl_legacy_va_layout;
227 /* The default sysctl tables: */
229 static struct ctl_table sysctl_base_table[] = {
231 .procname = "kernel",
248 .child = debug_table,
258 #ifdef CONFIG_SCHED_DEBUG
259 static int min_sched_granularity_ns = 100000; /* 100 usecs */
260 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
261 static int min_wakeup_granularity_ns; /* 0 usecs */
262 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
264 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
265 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
266 #endif /* CONFIG_SMP */
267 #endif /* CONFIG_SCHED_DEBUG */
269 #ifdef CONFIG_COMPACTION
270 static int min_extfrag_threshold;
271 static int max_extfrag_threshold = 1000;
274 static struct ctl_table kern_table[] = {
276 .procname = "sched_child_runs_first",
277 .data = &sysctl_sched_child_runs_first,
278 .maxlen = sizeof(unsigned int),
280 .proc_handler = proc_dointvec,
282 #ifdef CONFIG_SCHED_DEBUG
284 .procname = "sched_min_granularity_ns",
285 .data = &sysctl_sched_min_granularity,
286 .maxlen = sizeof(unsigned int),
288 .proc_handler = sched_proc_update_handler,
289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
293 .procname = "sched_latency_ns",
294 .data = &sysctl_sched_latency,
295 .maxlen = sizeof(unsigned int),
297 .proc_handler = sched_proc_update_handler,
298 .extra1 = &min_sched_granularity_ns,
299 .extra2 = &max_sched_granularity_ns,
302 .procname = "sched_wakeup_granularity_ns",
303 .data = &sysctl_sched_wakeup_granularity,
304 .maxlen = sizeof(unsigned int),
306 .proc_handler = sched_proc_update_handler,
307 .extra1 = &min_wakeup_granularity_ns,
308 .extra2 = &max_wakeup_granularity_ns,
312 .procname = "sched_tunable_scaling",
313 .data = &sysctl_sched_tunable_scaling,
314 .maxlen = sizeof(enum sched_tunable_scaling),
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
321 .procname = "sched_migration_cost_ns",
322 .data = &sysctl_sched_migration_cost,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = proc_dointvec,
328 .procname = "sched_nr_migrate",
329 .data = &sysctl_sched_nr_migrate,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = proc_dointvec,
335 .procname = "sched_time_avg_ms",
336 .data = &sysctl_sched_time_avg,
337 .maxlen = sizeof(unsigned int),
339 .proc_handler = proc_dointvec,
342 .procname = "sched_shares_window_ns",
343 .data = &sysctl_sched_shares_window,
344 .maxlen = sizeof(unsigned int),
346 .proc_handler = proc_dointvec,
349 .procname = "timer_migration",
350 .data = &sysctl_timer_migration,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = proc_dointvec_minmax,
357 #endif /* CONFIG_SMP */
358 #ifdef CONFIG_NUMA_BALANCING
360 .procname = "numa_balancing_scan_delay_ms",
361 .data = &sysctl_numa_balancing_scan_delay,
362 .maxlen = sizeof(unsigned int),
364 .proc_handler = proc_dointvec,
367 .procname = "numa_balancing_scan_period_min_ms",
368 .data = &sysctl_numa_balancing_scan_period_min,
369 .maxlen = sizeof(unsigned int),
371 .proc_handler = proc_dointvec,
374 .procname = "numa_balancing_scan_period_max_ms",
375 .data = &sysctl_numa_balancing_scan_period_max,
376 .maxlen = sizeof(unsigned int),
378 .proc_handler = proc_dointvec,
381 .procname = "numa_balancing_scan_size_mb",
382 .data = &sysctl_numa_balancing_scan_size,
383 .maxlen = sizeof(unsigned int),
385 .proc_handler = proc_dointvec,
387 #endif /* CONFIG_NUMA_BALANCING */
388 #endif /* CONFIG_SCHED_DEBUG */
390 .procname = "sched_rt_period_us",
391 .data = &sysctl_sched_rt_period,
392 .maxlen = sizeof(unsigned int),
394 .proc_handler = sched_rt_handler,
397 .procname = "sched_rt_runtime_us",
398 .data = &sysctl_sched_rt_runtime,
399 .maxlen = sizeof(int),
401 .proc_handler = sched_rt_handler,
404 .procname = "sched_rr_timeslice_ms",
405 .data = &sched_rr_timeslice,
406 .maxlen = sizeof(int),
408 .proc_handler = sched_rr_handler,
410 #ifdef CONFIG_SCHED_AUTOGROUP
412 .procname = "sched_autogroup_enabled",
413 .data = &sysctl_sched_autogroup_enabled,
414 .maxlen = sizeof(unsigned int),
416 .proc_handler = proc_dointvec_minmax,
421 #ifdef CONFIG_CFS_BANDWIDTH
423 .procname = "sched_cfs_bandwidth_slice_us",
424 .data = &sysctl_sched_cfs_bandwidth_slice,
425 .maxlen = sizeof(unsigned int),
427 .proc_handler = proc_dointvec_minmax,
431 #ifdef CONFIG_PROVE_LOCKING
433 .procname = "prove_locking",
434 .data = &prove_locking,
435 .maxlen = sizeof(int),
437 .proc_handler = proc_dointvec,
440 #ifdef CONFIG_LOCK_STAT
442 .procname = "lock_stat",
444 .maxlen = sizeof(int),
446 .proc_handler = proc_dointvec,
451 .data = &panic_timeout,
452 .maxlen = sizeof(int),
454 .proc_handler = proc_dointvec,
456 #ifdef CONFIG_COREDUMP
458 .procname = "core_uses_pid",
459 .data = &core_uses_pid,
460 .maxlen = sizeof(int),
462 .proc_handler = proc_dointvec,
465 .procname = "core_pattern",
466 .data = core_pattern,
467 .maxlen = CORENAME_MAX_SIZE,
469 .proc_handler = proc_dostring_coredump,
472 .procname = "core_pipe_limit",
473 .data = &core_pipe_limit,
474 .maxlen = sizeof(unsigned int),
476 .proc_handler = proc_dointvec,
479 #ifdef CONFIG_PROC_SYSCTL
481 .procname = "tainted",
482 .maxlen = sizeof(long),
484 .proc_handler = proc_taint,
487 #ifdef CONFIG_LATENCYTOP
489 .procname = "latencytop",
490 .data = &latencytop_enabled,
491 .maxlen = sizeof(int),
493 .proc_handler = proc_dointvec,
496 #ifdef CONFIG_BLK_DEV_INITRD
498 .procname = "real-root-dev",
499 .data = &real_root_dev,
500 .maxlen = sizeof(int),
502 .proc_handler = proc_dointvec,
506 .procname = "print-fatal-signals",
507 .data = &print_fatal_signals,
508 .maxlen = sizeof(int),
510 .proc_handler = proc_dointvec,
514 .procname = "reboot-cmd",
515 .data = reboot_command,
518 .proc_handler = proc_dostring,
521 .procname = "stop-a",
522 .data = &stop_a_enabled,
523 .maxlen = sizeof (int),
525 .proc_handler = proc_dointvec,
528 .procname = "scons-poweroff",
529 .data = &scons_pwroff,
530 .maxlen = sizeof (int),
532 .proc_handler = proc_dointvec,
535 #ifdef CONFIG_SPARC64
537 .procname = "tsb-ratio",
538 .data = &sysctl_tsb_ratio,
539 .maxlen = sizeof (int),
541 .proc_handler = proc_dointvec,
546 .procname = "soft-power",
547 .data = &pwrsw_enabled,
548 .maxlen = sizeof (int),
550 .proc_handler = proc_dointvec,
553 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
555 .procname = "unaligned-trap",
556 .data = &unaligned_enabled,
557 .maxlen = sizeof (int),
559 .proc_handler = proc_dointvec,
563 .procname = "ctrl-alt-del",
565 .maxlen = sizeof(int),
567 .proc_handler = proc_dointvec,
569 #ifdef CONFIG_FUNCTION_TRACER
571 .procname = "ftrace_enabled",
572 .data = &ftrace_enabled,
573 .maxlen = sizeof(int),
575 .proc_handler = ftrace_enable_sysctl,
578 #ifdef CONFIG_STACK_TRACER
580 .procname = "stack_tracer_enabled",
581 .data = &stack_tracer_enabled,
582 .maxlen = sizeof(int),
584 .proc_handler = stack_trace_sysctl,
587 #ifdef CONFIG_TRACING
589 .procname = "ftrace_dump_on_oops",
590 .data = &ftrace_dump_on_oops,
591 .maxlen = sizeof(int),
593 .proc_handler = proc_dointvec,
596 .procname = "traceoff_on_warning",
597 .data = &__disable_trace_on_warning,
598 .maxlen = sizeof(__disable_trace_on_warning),
600 .proc_handler = proc_dointvec,
603 #ifdef CONFIG_MODULES
605 .procname = "modprobe",
606 .data = &modprobe_path,
607 .maxlen = KMOD_PATH_LEN,
609 .proc_handler = proc_dostring,
612 .procname = "modules_disabled",
613 .data = &modules_disabled,
614 .maxlen = sizeof(int),
616 /* only handle a transition from default "0" to "1" */
617 .proc_handler = proc_dointvec_minmax,
624 .procname = "hotplug",
625 .data = &uevent_helper,
626 .maxlen = UEVENT_HELPER_PATH_LEN,
628 .proc_handler = proc_dostring,
631 #ifdef CONFIG_CHR_DEV_SG
633 .procname = "sg-big-buff",
634 .data = &sg_big_buff,
635 .maxlen = sizeof (int),
637 .proc_handler = proc_dointvec,
640 #ifdef CONFIG_BSD_PROCESS_ACCT
644 .maxlen = 3*sizeof(int),
646 .proc_handler = proc_dointvec,
649 #ifdef CONFIG_MAGIC_SYSRQ
652 .data = &__sysrq_enabled,
653 .maxlen = sizeof (int),
655 .proc_handler = sysrq_sysctl_handler,
658 #ifdef CONFIG_PROC_SYSCTL
660 .procname = "cad_pid",
662 .maxlen = sizeof (int),
664 .proc_handler = proc_do_cad_pid,
668 .procname = "threads-max",
669 .data = &max_threads,
670 .maxlen = sizeof(int),
672 .proc_handler = proc_dointvec,
675 .procname = "random",
677 .child = random_table,
680 .procname = "usermodehelper",
682 .child = usermodehelper_table,
685 .procname = "overflowuid",
686 .data = &overflowuid,
687 .maxlen = sizeof(int),
689 .proc_handler = proc_dointvec_minmax,
690 .extra1 = &minolduid,
691 .extra2 = &maxolduid,
694 .procname = "overflowgid",
695 .data = &overflowgid,
696 .maxlen = sizeof(int),
698 .proc_handler = proc_dointvec_minmax,
699 .extra1 = &minolduid,
700 .extra2 = &maxolduid,
703 #ifdef CONFIG_MATHEMU
705 .procname = "ieee_emulation_warnings",
706 .data = &sysctl_ieee_emulation_warnings,
707 .maxlen = sizeof(int),
709 .proc_handler = proc_dointvec,
713 .procname = "userprocess_debug",
714 .data = &show_unhandled_signals,
715 .maxlen = sizeof(int),
717 .proc_handler = proc_dointvec,
721 .procname = "pid_max",
723 .maxlen = sizeof (int),
725 .proc_handler = proc_dointvec_minmax,
726 .extra1 = &pid_max_min,
727 .extra2 = &pid_max_max,
730 .procname = "panic_on_oops",
731 .data = &panic_on_oops,
732 .maxlen = sizeof(int),
734 .proc_handler = proc_dointvec,
736 #if defined CONFIG_PRINTK
738 .procname = "printk",
739 .data = &console_loglevel,
740 .maxlen = 4*sizeof(int),
742 .proc_handler = proc_dointvec,
745 .procname = "printk_ratelimit",
746 .data = &printk_ratelimit_state.interval,
747 .maxlen = sizeof(int),
749 .proc_handler = proc_dointvec_jiffies,
752 .procname = "printk_ratelimit_burst",
753 .data = &printk_ratelimit_state.burst,
754 .maxlen = sizeof(int),
756 .proc_handler = proc_dointvec,
759 .procname = "printk_delay",
760 .data = &printk_delay_msec,
761 .maxlen = sizeof(int),
763 .proc_handler = proc_dointvec_minmax,
765 .extra2 = &ten_thousand,
768 .procname = "dmesg_restrict",
769 .data = &dmesg_restrict,
770 .maxlen = sizeof(int),
772 .proc_handler = proc_dointvec_minmax_sysadmin,
777 .procname = "kptr_restrict",
778 .data = &kptr_restrict,
779 .maxlen = sizeof(int),
781 .proc_handler = proc_dointvec_minmax_sysadmin,
787 .procname = "ngroups_max",
788 .data = &ngroups_max,
789 .maxlen = sizeof (int),
791 .proc_handler = proc_dointvec,
794 .procname = "cap_last_cap",
795 .data = (void *)&cap_last_cap,
796 .maxlen = sizeof(int),
798 .proc_handler = proc_dointvec,
800 #if defined(CONFIG_LOCKUP_DETECTOR)
802 .procname = "watchdog",
803 .data = &watchdog_user_enabled,
804 .maxlen = sizeof (int),
806 .proc_handler = proc_dowatchdog,
811 .procname = "watchdog_thresh",
812 .data = &watchdog_thresh,
813 .maxlen = sizeof(int),
815 .proc_handler = proc_dowatchdog,
820 .procname = "softlockup_panic",
821 .data = &softlockup_panic,
822 .maxlen = sizeof(int),
824 .proc_handler = proc_dointvec_minmax,
829 .procname = "nmi_watchdog",
830 .data = &watchdog_user_enabled,
831 .maxlen = sizeof (int),
833 .proc_handler = proc_dowatchdog,
838 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
840 .procname = "unknown_nmi_panic",
841 .data = &unknown_nmi_panic,
842 .maxlen = sizeof (int),
844 .proc_handler = proc_dointvec,
847 #if defined(CONFIG_X86)
849 .procname = "panic_on_unrecovered_nmi",
850 .data = &panic_on_unrecovered_nmi,
851 .maxlen = sizeof(int),
853 .proc_handler = proc_dointvec,
856 .procname = "panic_on_io_nmi",
857 .data = &panic_on_io_nmi,
858 .maxlen = sizeof(int),
860 .proc_handler = proc_dointvec,
862 #ifdef CONFIG_DEBUG_STACKOVERFLOW
864 .procname = "panic_on_stackoverflow",
865 .data = &sysctl_panic_on_stackoverflow,
866 .maxlen = sizeof(int),
868 .proc_handler = proc_dointvec,
872 .procname = "bootloader_type",
873 .data = &bootloader_type,
874 .maxlen = sizeof (int),
876 .proc_handler = proc_dointvec,
879 .procname = "bootloader_version",
880 .data = &bootloader_version,
881 .maxlen = sizeof (int),
883 .proc_handler = proc_dointvec,
886 .procname = "kstack_depth_to_print",
887 .data = &kstack_depth_to_print,
888 .maxlen = sizeof(int),
890 .proc_handler = proc_dointvec,
893 .procname = "io_delay_type",
894 .data = &io_delay_type,
895 .maxlen = sizeof(int),
897 .proc_handler = proc_dointvec,
900 #if defined(CONFIG_MMU)
902 .procname = "randomize_va_space",
903 .data = &randomize_va_space,
904 .maxlen = sizeof(int),
906 .proc_handler = proc_dointvec,
909 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
911 .procname = "spin_retry",
913 .maxlen = sizeof (int),
915 .proc_handler = proc_dointvec,
918 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
920 .procname = "acpi_video_flags",
921 .data = &acpi_realmode_flags,
922 .maxlen = sizeof (unsigned long),
924 .proc_handler = proc_doulongvec_minmax,
927 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
929 .procname = "ignore-unaligned-usertrap",
930 .data = &no_unaligned_warning,
931 .maxlen = sizeof (int),
933 .proc_handler = proc_dointvec,
938 .procname = "unaligned-dump-stack",
939 .data = &unaligned_dump_stack,
940 .maxlen = sizeof (int),
942 .proc_handler = proc_dointvec,
945 #ifdef CONFIG_DETECT_HUNG_TASK
947 .procname = "hung_task_panic",
948 .data = &sysctl_hung_task_panic,
949 .maxlen = sizeof(int),
951 .proc_handler = proc_dointvec_minmax,
956 .procname = "hung_task_check_count",
957 .data = &sysctl_hung_task_check_count,
958 .maxlen = sizeof(int),
960 .proc_handler = proc_dointvec_minmax,
964 .procname = "hung_task_timeout_secs",
965 .data = &sysctl_hung_task_timeout_secs,
966 .maxlen = sizeof(unsigned long),
968 .proc_handler = proc_dohung_task_timeout_secs,
971 .procname = "hung_task_warnings",
972 .data = &sysctl_hung_task_warnings,
973 .maxlen = sizeof(unsigned long),
975 .proc_handler = proc_doulongvec_minmax,
980 .procname = "compat-log",
982 .maxlen = sizeof (int),
984 .proc_handler = proc_dointvec,
987 #ifdef CONFIG_RT_MUTEXES
989 .procname = "max_lock_depth",
990 .data = &max_lock_depth,
991 .maxlen = sizeof(int),
993 .proc_handler = proc_dointvec,
997 .procname = "poweroff_cmd",
998 .data = &poweroff_cmd,
999 .maxlen = POWEROFF_CMD_PATH_LEN,
1001 .proc_handler = proc_dostring,
1007 .child = key_sysctls,
1010 #ifdef CONFIG_RCU_TORTURE_TEST
1012 .procname = "rcutorture_runnable",
1013 .data = &rcutorture_runnable,
1014 .maxlen = sizeof(int),
1016 .proc_handler = proc_dointvec,
1019 #ifdef CONFIG_PERF_EVENTS
1021 * User-space scripts rely on the existence of this file
1022 * as a feature check for perf_events being enabled.
1024 * So it's an ABI, do not remove!
1027 .procname = "perf_event_paranoid",
1028 .data = &sysctl_perf_event_paranoid,
1029 .maxlen = sizeof(sysctl_perf_event_paranoid),
1031 .proc_handler = proc_dointvec,
1034 .procname = "perf_event_mlock_kb",
1035 .data = &sysctl_perf_event_mlock,
1036 .maxlen = sizeof(sysctl_perf_event_mlock),
1038 .proc_handler = proc_dointvec,
1041 .procname = "perf_event_max_sample_rate",
1042 .data = &sysctl_perf_event_sample_rate,
1043 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1045 .proc_handler = perf_proc_update_handler,
1049 .procname = "perf_cpu_time_max_percent",
1050 .data = &sysctl_perf_cpu_time_max_percent,
1051 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1053 .proc_handler = perf_cpu_time_max_percent_handler,
1055 .extra2 = &one_hundred,
1058 #ifdef CONFIG_KMEMCHECK
1060 .procname = "kmemcheck",
1061 .data = &kmemcheck_enabled,
1062 .maxlen = sizeof(int),
1064 .proc_handler = proc_dointvec,
1069 .procname = "blk_iopoll",
1070 .data = &blk_iopoll_enabled,
1071 .maxlen = sizeof(int),
1073 .proc_handler = proc_dointvec,
1079 static struct ctl_table vm_table[] = {
1081 .procname = "overcommit_memory",
1082 .data = &sysctl_overcommit_memory,
1083 .maxlen = sizeof(sysctl_overcommit_memory),
1085 .proc_handler = proc_dointvec_minmax,
1090 .procname = "panic_on_oom",
1091 .data = &sysctl_panic_on_oom,
1092 .maxlen = sizeof(sysctl_panic_on_oom),
1094 .proc_handler = proc_dointvec_minmax,
1099 .procname = "oom_kill_allocating_task",
1100 .data = &sysctl_oom_kill_allocating_task,
1101 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1103 .proc_handler = proc_dointvec,
1106 .procname = "oom_dump_tasks",
1107 .data = &sysctl_oom_dump_tasks,
1108 .maxlen = sizeof(sysctl_oom_dump_tasks),
1110 .proc_handler = proc_dointvec,
1113 .procname = "overcommit_ratio",
1114 .data = &sysctl_overcommit_ratio,
1115 .maxlen = sizeof(sysctl_overcommit_ratio),
1117 .proc_handler = proc_dointvec,
1120 .procname = "page-cluster",
1121 .data = &page_cluster,
1122 .maxlen = sizeof(int),
1124 .proc_handler = proc_dointvec_minmax,
1128 .procname = "dirty_background_ratio",
1129 .data = &dirty_background_ratio,
1130 .maxlen = sizeof(dirty_background_ratio),
1132 .proc_handler = dirty_background_ratio_handler,
1134 .extra2 = &one_hundred,
1137 .procname = "dirty_background_bytes",
1138 .data = &dirty_background_bytes,
1139 .maxlen = sizeof(dirty_background_bytes),
1141 .proc_handler = dirty_background_bytes_handler,
1145 .procname = "dirty_ratio",
1146 .data = &vm_dirty_ratio,
1147 .maxlen = sizeof(vm_dirty_ratio),
1149 .proc_handler = dirty_ratio_handler,
1151 .extra2 = &one_hundred,
1154 .procname = "dirty_bytes",
1155 .data = &vm_dirty_bytes,
1156 .maxlen = sizeof(vm_dirty_bytes),
1158 .proc_handler = dirty_bytes_handler,
1159 .extra1 = &dirty_bytes_min,
1162 .procname = "dirty_writeback_centisecs",
1163 .data = &dirty_writeback_interval,
1164 .maxlen = sizeof(dirty_writeback_interval),
1166 .proc_handler = dirty_writeback_centisecs_handler,
1169 .procname = "dirty_expire_centisecs",
1170 .data = &dirty_expire_interval,
1171 .maxlen = sizeof(dirty_expire_interval),
1173 .proc_handler = proc_dointvec_minmax,
1177 .procname = "nr_pdflush_threads",
1178 .mode = 0444 /* read-only */,
1179 .proc_handler = pdflush_proc_obsolete,
1182 .procname = "swappiness",
1183 .data = &vm_swappiness,
1184 .maxlen = sizeof(vm_swappiness),
1186 .proc_handler = proc_dointvec_minmax,
1188 .extra2 = &one_hundred,
1190 #ifdef CONFIG_HUGETLB_PAGE
1192 .procname = "nr_hugepages",
1194 .maxlen = sizeof(unsigned long),
1196 .proc_handler = hugetlb_sysctl_handler,
1197 .extra1 = (void *)&hugetlb_zero,
1198 .extra2 = (void *)&hugetlb_infinity,
1202 .procname = "nr_hugepages_mempolicy",
1204 .maxlen = sizeof(unsigned long),
1206 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1207 .extra1 = (void *)&hugetlb_zero,
1208 .extra2 = (void *)&hugetlb_infinity,
1212 .procname = "hugetlb_shm_group",
1213 .data = &sysctl_hugetlb_shm_group,
1214 .maxlen = sizeof(gid_t),
1216 .proc_handler = proc_dointvec,
1219 .procname = "hugepages_treat_as_movable",
1220 .data = &hugepages_treat_as_movable,
1221 .maxlen = sizeof(int),
1223 .proc_handler = proc_dointvec,
1226 .procname = "nr_overcommit_hugepages",
1228 .maxlen = sizeof(unsigned long),
1230 .proc_handler = hugetlb_overcommit_handler,
1231 .extra1 = (void *)&hugetlb_zero,
1232 .extra2 = (void *)&hugetlb_infinity,
1236 .procname = "lowmem_reserve_ratio",
1237 .data = &sysctl_lowmem_reserve_ratio,
1238 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1240 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1243 .procname = "drop_caches",
1244 .data = &sysctl_drop_caches,
1245 .maxlen = sizeof(int),
1247 .proc_handler = drop_caches_sysctl_handler,
1251 #ifdef CONFIG_COMPACTION
1253 .procname = "compact_memory",
1254 .data = &sysctl_compact_memory,
1255 .maxlen = sizeof(int),
1257 .proc_handler = sysctl_compaction_handler,
1260 .procname = "extfrag_threshold",
1261 .data = &sysctl_extfrag_threshold,
1262 .maxlen = sizeof(int),
1264 .proc_handler = sysctl_extfrag_handler,
1265 .extra1 = &min_extfrag_threshold,
1266 .extra2 = &max_extfrag_threshold,
1269 #endif /* CONFIG_COMPACTION */
1271 .procname = "min_free_kbytes",
1272 .data = &min_free_kbytes,
1273 .maxlen = sizeof(min_free_kbytes),
1275 .proc_handler = min_free_kbytes_sysctl_handler,
1279 .procname = "percpu_pagelist_fraction",
1280 .data = &percpu_pagelist_fraction,
1281 .maxlen = sizeof(percpu_pagelist_fraction),
1283 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1284 .extra1 = &min_percpu_pagelist_fract,
1288 .procname = "max_map_count",
1289 .data = &sysctl_max_map_count,
1290 .maxlen = sizeof(sysctl_max_map_count),
1292 .proc_handler = proc_dointvec_minmax,
1297 .procname = "nr_trim_pages",
1298 .data = &sysctl_nr_trim_pages,
1299 .maxlen = sizeof(sysctl_nr_trim_pages),
1301 .proc_handler = proc_dointvec_minmax,
1306 .procname = "laptop_mode",
1307 .data = &laptop_mode,
1308 .maxlen = sizeof(laptop_mode),
1310 .proc_handler = proc_dointvec_jiffies,
1313 .procname = "block_dump",
1314 .data = &block_dump,
1315 .maxlen = sizeof(block_dump),
1317 .proc_handler = proc_dointvec,
1321 .procname = "vfs_cache_pressure",
1322 .data = &sysctl_vfs_cache_pressure,
1323 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1325 .proc_handler = proc_dointvec,
1328 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1330 .procname = "legacy_va_layout",
1331 .data = &sysctl_legacy_va_layout,
1332 .maxlen = sizeof(sysctl_legacy_va_layout),
1334 .proc_handler = proc_dointvec,
1340 .procname = "zone_reclaim_mode",
1341 .data = &zone_reclaim_mode,
1342 .maxlen = sizeof(zone_reclaim_mode),
1344 .proc_handler = proc_dointvec,
1348 .procname = "min_unmapped_ratio",
1349 .data = &sysctl_min_unmapped_ratio,
1350 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1352 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1354 .extra2 = &one_hundred,
1357 .procname = "min_slab_ratio",
1358 .data = &sysctl_min_slab_ratio,
1359 .maxlen = sizeof(sysctl_min_slab_ratio),
1361 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1363 .extra2 = &one_hundred,
1368 .procname = "stat_interval",
1369 .data = &sysctl_stat_interval,
1370 .maxlen = sizeof(sysctl_stat_interval),
1372 .proc_handler = proc_dointvec_jiffies,
1377 .procname = "mmap_min_addr",
1378 .data = &dac_mmap_min_addr,
1379 .maxlen = sizeof(unsigned long),
1381 .proc_handler = mmap_min_addr_handler,
1386 .procname = "numa_zonelist_order",
1387 .data = &numa_zonelist_order,
1388 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1390 .proc_handler = numa_zonelist_order_handler,
1393 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1394 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1396 .procname = "vdso_enabled",
1397 .data = &vdso_enabled,
1398 .maxlen = sizeof(vdso_enabled),
1400 .proc_handler = proc_dointvec,
1404 #ifdef CONFIG_HIGHMEM
1406 .procname = "highmem_is_dirtyable",
1407 .data = &vm_highmem_is_dirtyable,
1408 .maxlen = sizeof(vm_highmem_is_dirtyable),
1410 .proc_handler = proc_dointvec_minmax,
1416 .procname = "scan_unevictable_pages",
1417 .data = &scan_unevictable_pages,
1418 .maxlen = sizeof(scan_unevictable_pages),
1420 .proc_handler = scan_unevictable_handler,
1422 #ifdef CONFIG_MEMORY_FAILURE
1424 .procname = "memory_failure_early_kill",
1425 .data = &sysctl_memory_failure_early_kill,
1426 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1428 .proc_handler = proc_dointvec_minmax,
1433 .procname = "memory_failure_recovery",
1434 .data = &sysctl_memory_failure_recovery,
1435 .maxlen = sizeof(sysctl_memory_failure_recovery),
1437 .proc_handler = proc_dointvec_minmax,
1443 .procname = "user_reserve_kbytes",
1444 .data = &sysctl_user_reserve_kbytes,
1445 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1447 .proc_handler = proc_doulongvec_minmax,
1450 .procname = "admin_reserve_kbytes",
1451 .data = &sysctl_admin_reserve_kbytes,
1452 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1454 .proc_handler = proc_doulongvec_minmax,
1459 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1460 static struct ctl_table binfmt_misc_table[] = {
1465 static struct ctl_table fs_table[] = {
1467 .procname = "inode-nr",
1468 .data = &inodes_stat,
1469 .maxlen = 2*sizeof(long),
1471 .proc_handler = proc_nr_inodes,
1474 .procname = "inode-state",
1475 .data = &inodes_stat,
1476 .maxlen = 7*sizeof(long),
1478 .proc_handler = proc_nr_inodes,
1481 .procname = "file-nr",
1482 .data = &files_stat,
1483 .maxlen = sizeof(files_stat),
1485 .proc_handler = proc_nr_files,
1488 .procname = "file-max",
1489 .data = &files_stat.max_files,
1490 .maxlen = sizeof(files_stat.max_files),
1492 .proc_handler = proc_doulongvec_minmax,
1495 .procname = "nr_open",
1496 .data = &sysctl_nr_open,
1497 .maxlen = sizeof(int),
1499 .proc_handler = proc_dointvec_minmax,
1500 .extra1 = &sysctl_nr_open_min,
1501 .extra2 = &sysctl_nr_open_max,
1504 .procname = "dentry-state",
1505 .data = &dentry_stat,
1506 .maxlen = 6*sizeof(long),
1508 .proc_handler = proc_nr_dentry,
1511 .procname = "overflowuid",
1512 .data = &fs_overflowuid,
1513 .maxlen = sizeof(int),
1515 .proc_handler = proc_dointvec_minmax,
1516 .extra1 = &minolduid,
1517 .extra2 = &maxolduid,
1520 .procname = "overflowgid",
1521 .data = &fs_overflowgid,
1522 .maxlen = sizeof(int),
1524 .proc_handler = proc_dointvec_minmax,
1525 .extra1 = &minolduid,
1526 .extra2 = &maxolduid,
1528 #ifdef CONFIG_FILE_LOCKING
1530 .procname = "leases-enable",
1531 .data = &leases_enable,
1532 .maxlen = sizeof(int),
1534 .proc_handler = proc_dointvec,
1537 #ifdef CONFIG_DNOTIFY
1539 .procname = "dir-notify-enable",
1540 .data = &dir_notify_enable,
1541 .maxlen = sizeof(int),
1543 .proc_handler = proc_dointvec,
1547 #ifdef CONFIG_FILE_LOCKING
1549 .procname = "lease-break-time",
1550 .data = &lease_break_time,
1551 .maxlen = sizeof(int),
1553 .proc_handler = proc_dointvec,
1558 .procname = "aio-nr",
1560 .maxlen = sizeof(aio_nr),
1562 .proc_handler = proc_doulongvec_minmax,
1565 .procname = "aio-max-nr",
1566 .data = &aio_max_nr,
1567 .maxlen = sizeof(aio_max_nr),
1569 .proc_handler = proc_doulongvec_minmax,
1571 #endif /* CONFIG_AIO */
1572 #ifdef CONFIG_INOTIFY_USER
1574 .procname = "inotify",
1576 .child = inotify_table,
1581 .procname = "epoll",
1583 .child = epoll_table,
1588 .procname = "protected_symlinks",
1589 .data = &sysctl_protected_symlinks,
1590 .maxlen = sizeof(int),
1592 .proc_handler = proc_dointvec_minmax,
1597 .procname = "protected_hardlinks",
1598 .data = &sysctl_protected_hardlinks,
1599 .maxlen = sizeof(int),
1601 .proc_handler = proc_dointvec_minmax,
1606 .procname = "suid_dumpable",
1607 .data = &suid_dumpable,
1608 .maxlen = sizeof(int),
1610 .proc_handler = proc_dointvec_minmax_coredump,
1614 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1616 .procname = "binfmt_misc",
1618 .child = binfmt_misc_table,
1622 .procname = "pipe-max-size",
1623 .data = &pipe_max_size,
1624 .maxlen = sizeof(int),
1626 .proc_handler = &pipe_proc_fn,
1627 .extra1 = &pipe_min_size,
1632 static struct ctl_table debug_table[] = {
1633 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1635 .procname = "exception-trace",
1636 .data = &show_unhandled_signals,
1637 .maxlen = sizeof(int),
1639 .proc_handler = proc_dointvec
1642 #if defined(CONFIG_OPTPROBES)
1644 .procname = "kprobes-optimization",
1645 .data = &sysctl_kprobes_optimization,
1646 .maxlen = sizeof(int),
1648 .proc_handler = proc_kprobes_optimization_handler,
1656 static struct ctl_table dev_table[] = {
1660 int __init sysctl_init(void)
1662 struct ctl_table_header *hdr;
1664 hdr = register_sysctl_table(sysctl_base_table);
1665 kmemleak_not_leak(hdr);
1669 #endif /* CONFIG_SYSCTL */
1675 #ifdef CONFIG_PROC_SYSCTL
1677 static int _proc_do_string(void* data, int maxlen, int write,
1678 void __user *buffer,
1679 size_t *lenp, loff_t *ppos)
1685 if (!data || !maxlen || !*lenp) {
1693 while (len < *lenp) {
1694 if (get_user(c, p++))
1696 if (c == 0 || c == '\n')
1702 if(copy_from_user(data, buffer, len))
1704 ((char *) data)[len] = 0;
1722 if(copy_to_user(buffer, data, len))
1725 if(put_user('\n', ((char __user *) buffer) + len))
1736 * proc_dostring - read a string sysctl
1737 * @table: the sysctl table
1738 * @write: %TRUE if this is a write to the sysctl file
1739 * @buffer: the user buffer
1740 * @lenp: the size of the user buffer
1741 * @ppos: file position
1743 * Reads/writes a string from/to the user buffer. If the kernel
1744 * buffer provided is not large enough to hold the string, the
1745 * string is truncated. The copied string is %NULL-terminated.
1746 * If the string is being read by the user process, it is copied
1747 * and a newline '\n' is added. It is truncated if the buffer is
1750 * Returns 0 on success.
1752 int proc_dostring(struct ctl_table *table, int write,
1753 void __user *buffer, size_t *lenp, loff_t *ppos)
1755 return _proc_do_string(table->data, table->maxlen, write,
1756 buffer, lenp, ppos);
1759 static size_t proc_skip_spaces(char **buf)
1762 char *tmp = skip_spaces(*buf);
1768 static void proc_skip_char(char **buf, size_t *size, const char v)
1778 #define TMPBUFLEN 22
1780 * proc_get_long - reads an ASCII formatted integer from a user buffer
1782 * @buf: a kernel buffer
1783 * @size: size of the kernel buffer
1784 * @val: this is where the number will be stored
1785 * @neg: set to %TRUE if number is negative
1786 * @perm_tr: a vector which contains the allowed trailers
1787 * @perm_tr_len: size of the perm_tr vector
1788 * @tr: pointer to store the trailer character
1790 * In case of success %0 is returned and @buf and @size are updated with
1791 * the amount of bytes read. If @tr is non-NULL and a trailing
1792 * character exists (size is non-zero after returning from this
1793 * function), @tr is updated with the trailing character.
1795 static int proc_get_long(char **buf, size_t *size,
1796 unsigned long *val, bool *neg,
1797 const char *perm_tr, unsigned perm_tr_len, char *tr)
1800 char *p, tmp[TMPBUFLEN];
1806 if (len > TMPBUFLEN - 1)
1807 len = TMPBUFLEN - 1;
1809 memcpy(tmp, *buf, len);
1813 if (*p == '-' && *size > 1) {
1821 *val = simple_strtoul(p, &p, 0);
1825 /* We don't know if the next char is whitespace thus we may accept
1826 * invalid integers (e.g. 1234...a) or two integers instead of one
1827 * (e.g. 123...1). So lets not allow such large numbers. */
1828 if (len == TMPBUFLEN - 1)
1831 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1834 if (tr && (len < *size))
1844 * proc_put_long - converts an integer to a decimal ASCII formatted string
1846 * @buf: the user buffer
1847 * @size: the size of the user buffer
1848 * @val: the integer to be converted
1849 * @neg: sign of the number, %TRUE for negative
1851 * In case of success %0 is returned and @buf and @size are updated with
1852 * the amount of bytes written.
1854 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1858 char tmp[TMPBUFLEN], *p = tmp;
1860 sprintf(p, "%s%lu", neg ? "-" : "", val);
1864 if (copy_to_user(*buf, tmp, len))
1872 static int proc_put_char(void __user **buf, size_t *size, char c)
1875 char __user **buffer = (char __user **)buf;
1876 if (put_user(c, *buffer))
1878 (*size)--, (*buffer)++;
1884 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1886 int write, void *data)
1889 *valp = *negp ? -*lvalp : *lvalp;
1894 *lvalp = (unsigned long)-val;
1897 *lvalp = (unsigned long)val;
1903 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1905 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1906 int write, void __user *buffer,
1907 size_t *lenp, loff_t *ppos,
1908 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1909 int write, void *data),
1912 int *i, vleft, first = 1, err = 0;
1913 unsigned long page = 0;
1917 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1922 i = (int *) tbl_data;
1923 vleft = table->maxlen / sizeof(*i);
1927 conv = do_proc_dointvec_conv;
1930 if (left > PAGE_SIZE - 1)
1931 left = PAGE_SIZE - 1;
1932 page = __get_free_page(GFP_TEMPORARY);
1933 kbuf = (char *) page;
1936 if (copy_from_user(kbuf, buffer, left)) {
1943 for (; left && vleft--; i++, first=0) {
1948 left -= proc_skip_spaces(&kbuf);
1952 err = proc_get_long(&kbuf, &left, &lval, &neg,
1954 sizeof(proc_wspace_sep), NULL);
1957 if (conv(&neg, &lval, i, 1, data)) {
1962 if (conv(&neg, &lval, i, 0, data)) {
1967 err = proc_put_char(&buffer, &left, '\t');
1970 err = proc_put_long(&buffer, &left, lval, neg);
1976 if (!write && !first && left && !err)
1977 err = proc_put_char(&buffer, &left, '\n');
1978 if (write && !err && left)
1979 left -= proc_skip_spaces(&kbuf);
1984 return err ? : -EINVAL;
1991 static int do_proc_dointvec(struct ctl_table *table, int write,
1992 void __user *buffer, size_t *lenp, loff_t *ppos,
1993 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1994 int write, void *data),
1997 return __do_proc_dointvec(table->data, table, write,
1998 buffer, lenp, ppos, conv, data);
2002 * proc_dointvec - read a vector of integers
2003 * @table: the sysctl table
2004 * @write: %TRUE if this is a write to the sysctl file
2005 * @buffer: the user buffer
2006 * @lenp: the size of the user buffer
2007 * @ppos: file position
2009 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2010 * values from/to the user buffer, treated as an ASCII string.
2012 * Returns 0 on success.
2014 int proc_dointvec(struct ctl_table *table, int write,
2015 void __user *buffer, size_t *lenp, loff_t *ppos)
2017 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2022 * Taint values can only be increased
2023 * This means we can safely use a temporary.
2025 static int proc_taint(struct ctl_table *table, int write,
2026 void __user *buffer, size_t *lenp, loff_t *ppos)
2029 unsigned long tmptaint = get_taint();
2032 if (write && !capable(CAP_SYS_ADMIN))
2037 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2043 * Poor man's atomic or. Not worth adding a primitive
2044 * to everyone's atomic.h for this
2047 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2048 if ((tmptaint >> i) & 1)
2049 add_taint(i, LOCKDEP_STILL_OK);
2056 #ifdef CONFIG_PRINTK
2057 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2058 void __user *buffer, size_t *lenp, loff_t *ppos)
2060 if (write && !capable(CAP_SYS_ADMIN))
2063 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2067 struct do_proc_dointvec_minmax_conv_param {
2072 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2074 int write, void *data)
2076 struct do_proc_dointvec_minmax_conv_param *param = data;
2078 int val = *negp ? -*lvalp : *lvalp;
2079 if ((param->min && *param->min > val) ||
2080 (param->max && *param->max < val))
2087 *lvalp = (unsigned long)-val;
2090 *lvalp = (unsigned long)val;
2097 * proc_dointvec_minmax - read a vector of integers with min/max values
2098 * @table: the sysctl table
2099 * @write: %TRUE if this is a write to the sysctl file
2100 * @buffer: the user buffer
2101 * @lenp: the size of the user buffer
2102 * @ppos: file position
2104 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2105 * values from/to the user buffer, treated as an ASCII string.
2107 * This routine will ensure the values are within the range specified by
2108 * table->extra1 (min) and table->extra2 (max).
2110 * Returns 0 on success.
2112 int proc_dointvec_minmax(struct ctl_table *table, int write,
2113 void __user *buffer, size_t *lenp, loff_t *ppos)
2115 struct do_proc_dointvec_minmax_conv_param param = {
2116 .min = (int *) table->extra1,
2117 .max = (int *) table->extra2,
2119 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2120 do_proc_dointvec_minmax_conv, ¶m);
2123 static void validate_coredump_safety(void)
2125 #ifdef CONFIG_COREDUMP
2126 if (suid_dumpable == SUID_DUMP_ROOT &&
2127 core_pattern[0] != '/' && core_pattern[0] != '|') {
2128 printk(KERN_WARNING "Unsafe core_pattern used with "\
2129 "suid_dumpable=2. Pipe handler or fully qualified "\
2130 "core dump path required.\n");
2135 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2136 void __user *buffer, size_t *lenp, loff_t *ppos)
2138 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2140 validate_coredump_safety();
2144 #ifdef CONFIG_COREDUMP
2145 static int proc_dostring_coredump(struct ctl_table *table, int write,
2146 void __user *buffer, size_t *lenp, loff_t *ppos)
2148 int error = proc_dostring(table, write, buffer, lenp, ppos);
2150 validate_coredump_safety();
2155 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2156 void __user *buffer,
2157 size_t *lenp, loff_t *ppos,
2158 unsigned long convmul,
2159 unsigned long convdiv)
2161 unsigned long *i, *min, *max;
2162 int vleft, first = 1, err = 0;
2163 unsigned long page = 0;
2167 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2172 i = (unsigned long *) data;
2173 min = (unsigned long *) table->extra1;
2174 max = (unsigned long *) table->extra2;
2175 vleft = table->maxlen / sizeof(unsigned long);
2179 if (left > PAGE_SIZE - 1)
2180 left = PAGE_SIZE - 1;
2181 page = __get_free_page(GFP_TEMPORARY);
2182 kbuf = (char *) page;
2185 if (copy_from_user(kbuf, buffer, left)) {
2192 for (; left && vleft--; i++, first = 0) {
2198 left -= proc_skip_spaces(&kbuf);
2200 err = proc_get_long(&kbuf, &left, &val, &neg,
2202 sizeof(proc_wspace_sep), NULL);
2207 if ((min && val < *min) || (max && val > *max))
2211 val = convdiv * (*i) / convmul;
2213 err = proc_put_char(&buffer, &left, '\t');
2217 err = proc_put_long(&buffer, &left, val, false);
2223 if (!write && !first && left && !err)
2224 err = proc_put_char(&buffer, &left, '\n');
2226 left -= proc_skip_spaces(&kbuf);
2231 return err ? : -EINVAL;
2238 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2239 void __user *buffer,
2240 size_t *lenp, loff_t *ppos,
2241 unsigned long convmul,
2242 unsigned long convdiv)
2244 return __do_proc_doulongvec_minmax(table->data, table, write,
2245 buffer, lenp, ppos, convmul, convdiv);
2249 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2250 * @table: the sysctl table
2251 * @write: %TRUE if this is a write to the sysctl file
2252 * @buffer: the user buffer
2253 * @lenp: the size of the user buffer
2254 * @ppos: file position
2256 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2257 * values from/to the user buffer, treated as an ASCII string.
2259 * This routine will ensure the values are within the range specified by
2260 * table->extra1 (min) and table->extra2 (max).
2262 * Returns 0 on success.
2264 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2265 void __user *buffer, size_t *lenp, loff_t *ppos)
2267 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2271 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2272 * @table: the sysctl table
2273 * @write: %TRUE if this is a write to the sysctl file
2274 * @buffer: the user buffer
2275 * @lenp: the size of the user buffer
2276 * @ppos: file position
2278 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2279 * values from/to the user buffer, treated as an ASCII string. The values
2280 * are treated as milliseconds, and converted to jiffies when they are stored.
2282 * This routine will ensure the values are within the range specified by
2283 * table->extra1 (min) and table->extra2 (max).
2285 * Returns 0 on success.
2287 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2288 void __user *buffer,
2289 size_t *lenp, loff_t *ppos)
2291 return do_proc_doulongvec_minmax(table, write, buffer,
2292 lenp, ppos, HZ, 1000l);
2296 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2298 int write, void *data)
2301 if (*lvalp > LONG_MAX / HZ)
2303 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2309 lval = (unsigned long)-val;
2312 lval = (unsigned long)val;
2319 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2321 int write, void *data)
2324 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2326 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2332 lval = (unsigned long)-val;
2335 lval = (unsigned long)val;
2337 *lvalp = jiffies_to_clock_t(lval);
2342 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2344 int write, void *data)
2347 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2357 lval = (unsigned long)-val;
2360 lval = (unsigned long)val;
2362 *lvalp = jiffies_to_msecs(lval);
2368 * proc_dointvec_jiffies - read a vector of integers as seconds
2369 * @table: the sysctl table
2370 * @write: %TRUE if this is a write to the sysctl file
2371 * @buffer: the user buffer
2372 * @lenp: the size of the user buffer
2373 * @ppos: file position
2375 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2376 * values from/to the user buffer, treated as an ASCII string.
2377 * The values read are assumed to be in seconds, and are converted into
2380 * Returns 0 on success.
2382 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2383 void __user *buffer, size_t *lenp, loff_t *ppos)
2385 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2386 do_proc_dointvec_jiffies_conv,NULL);
2390 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2391 * @table: the sysctl table
2392 * @write: %TRUE if this is a write to the sysctl file
2393 * @buffer: the user buffer
2394 * @lenp: the size of the user buffer
2395 * @ppos: pointer to the file position
2397 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2398 * values from/to the user buffer, treated as an ASCII string.
2399 * The values read are assumed to be in 1/USER_HZ seconds, and
2400 * are converted into jiffies.
2402 * Returns 0 on success.
2404 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2405 void __user *buffer, size_t *lenp, loff_t *ppos)
2407 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2408 do_proc_dointvec_userhz_jiffies_conv,NULL);
2412 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2413 * @table: the sysctl table
2414 * @write: %TRUE if this is a write to the sysctl file
2415 * @buffer: the user buffer
2416 * @lenp: the size of the user buffer
2417 * @ppos: file position
2418 * @ppos: the current position in the file
2420 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2421 * values from/to the user buffer, treated as an ASCII string.
2422 * The values read are assumed to be in 1/1000 seconds, and
2423 * are converted into jiffies.
2425 * Returns 0 on success.
2427 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2428 void __user *buffer, size_t *lenp, loff_t *ppos)
2430 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2431 do_proc_dointvec_ms_jiffies_conv, NULL);
2434 static int proc_do_cad_pid(struct ctl_table *table, int write,
2435 void __user *buffer, size_t *lenp, loff_t *ppos)
2437 struct pid *new_pid;
2441 tmp = pid_vnr(cad_pid);
2443 r = __do_proc_dointvec(&tmp, table, write, buffer,
2444 lenp, ppos, NULL, NULL);
2448 new_pid = find_get_pid(tmp);
2452 put_pid(xchg(&cad_pid, new_pid));
2457 * proc_do_large_bitmap - read/write from/to a large bitmap
2458 * @table: the sysctl table
2459 * @write: %TRUE if this is a write to the sysctl file
2460 * @buffer: the user buffer
2461 * @lenp: the size of the user buffer
2462 * @ppos: file position
2464 * The bitmap is stored at table->data and the bitmap length (in bits)
2467 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2468 * large bitmaps may be represented in a compact manner. Writing into
2469 * the file will clear the bitmap then update it with the given input.
2471 * Returns 0 on success.
2473 int proc_do_large_bitmap(struct ctl_table *table, int write,
2474 void __user *buffer, size_t *lenp, loff_t *ppos)
2478 size_t left = *lenp;
2479 unsigned long bitmap_len = table->maxlen;
2480 unsigned long *bitmap = (unsigned long *) table->data;
2481 unsigned long *tmp_bitmap = NULL;
2482 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2484 if (!bitmap_len || !left || (*ppos && !write)) {
2490 unsigned long page = 0;
2493 if (left > PAGE_SIZE - 1)
2494 left = PAGE_SIZE - 1;
2496 page = __get_free_page(GFP_TEMPORARY);
2497 kbuf = (char *) page;
2500 if (copy_from_user(kbuf, buffer, left)) {
2506 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2512 proc_skip_char(&kbuf, &left, '\n');
2513 while (!err && left) {
2514 unsigned long val_a, val_b;
2517 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2521 if (val_a >= bitmap_len || neg) {
2533 err = proc_get_long(&kbuf, &left, &val_b,
2534 &neg, tr_b, sizeof(tr_b),
2538 if (val_b >= bitmap_len || neg ||
2549 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2551 proc_skip_char(&kbuf, &left, '\n');
2555 unsigned long bit_a, bit_b = 0;
2558 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2559 if (bit_a >= bitmap_len)
2561 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2565 err = proc_put_char(&buffer, &left, ',');
2569 err = proc_put_long(&buffer, &left, bit_a, false);
2572 if (bit_a != bit_b) {
2573 err = proc_put_char(&buffer, &left, '-');
2576 err = proc_put_long(&buffer, &left, bit_b, false);
2584 err = proc_put_char(&buffer, &left, '\n');
2590 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2592 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2604 #else /* CONFIG_PROC_SYSCTL */
2606 int proc_dostring(struct ctl_table *table, int write,
2607 void __user *buffer, size_t *lenp, loff_t *ppos)
2612 int proc_dointvec(struct ctl_table *table, int write,
2613 void __user *buffer, size_t *lenp, loff_t *ppos)
2618 int proc_dointvec_minmax(struct ctl_table *table, int write,
2619 void __user *buffer, size_t *lenp, loff_t *ppos)
2624 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2625 void __user *buffer, size_t *lenp, loff_t *ppos)
2630 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2631 void __user *buffer, size_t *lenp, loff_t *ppos)
2636 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2637 void __user *buffer, size_t *lenp, loff_t *ppos)
2642 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2643 void __user *buffer, size_t *lenp, loff_t *ppos)
2648 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2649 void __user *buffer,
2650 size_t *lenp, loff_t *ppos)
2656 #endif /* CONFIG_PROC_SYSCTL */
2659 * No sense putting this after each symbol definition, twice,
2660 * exception granted :-)
2662 EXPORT_SYMBOL(proc_dointvec);
2663 EXPORT_SYMBOL(proc_dointvec_jiffies);
2664 EXPORT_SYMBOL(proc_dointvec_minmax);
2665 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2666 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2667 EXPORT_SYMBOL(proc_dostring);
2668 EXPORT_SYMBOL(proc_doulongvec_minmax);
2669 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);