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 #ifdef CONFIG_INOTIFY_USER
152 #include <linux/inotify.h>
157 #ifdef CONFIG_SPARC64
158 extern int sysctl_tsb_ratio;
162 extern int pwrsw_enabled;
165 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
166 extern int unaligned_enabled;
170 extern int unaligned_dump_stack;
173 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
174 extern int no_unaligned_warning;
177 #ifdef CONFIG_PROC_SYSCTL
178 static int proc_do_cad_pid(struct ctl_table *table, int write,
179 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_taint(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
185 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
186 void __user *buffer, size_t *lenp, loff_t *ppos);
189 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
190 void __user *buffer, size_t *lenp, loff_t *ppos);
191 #ifdef CONFIG_COREDUMP
192 static int proc_dostring_coredump(struct ctl_table *table, int write,
193 void __user *buffer, size_t *lenp, loff_t *ppos);
196 #ifdef CONFIG_MAGIC_SYSRQ
197 /* Note: sysrq code uses it's own private copy */
198 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
200 static int sysrq_sysctl_handler(ctl_table *table, int write,
201 void __user *buffer, size_t *lenp,
206 error = proc_dointvec(table, write, buffer, lenp, ppos);
211 sysrq_toggle_support(__sysrq_enabled);
218 static struct ctl_table kern_table[];
219 static struct ctl_table vm_table[];
220 static struct ctl_table fs_table[];
221 static struct ctl_table debug_table[];
222 static struct ctl_table dev_table[];
223 extern struct ctl_table random_table[];
225 extern struct ctl_table epoll_table[];
228 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
229 int sysctl_legacy_va_layout;
232 /* The default sysctl tables: */
234 static struct ctl_table sysctl_base_table[] = {
236 .procname = "kernel",
253 .child = debug_table,
263 #ifdef CONFIG_SCHED_DEBUG
264 static int min_sched_granularity_ns = 100000; /* 100 usecs */
265 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
266 static int min_wakeup_granularity_ns; /* 0 usecs */
267 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
269 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
270 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
271 #endif /* CONFIG_SMP */
272 #endif /* CONFIG_SCHED_DEBUG */
274 #ifdef CONFIG_COMPACTION
275 static int min_extfrag_threshold;
276 static int max_extfrag_threshold = 1000;
279 static struct ctl_table kern_table[] = {
281 .procname = "sched_child_runs_first",
282 .data = &sysctl_sched_child_runs_first,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = proc_dointvec,
287 #ifdef CONFIG_SCHED_DEBUG
289 .procname = "sched_min_granularity_ns",
290 .data = &sysctl_sched_min_granularity,
291 .maxlen = sizeof(unsigned int),
293 .proc_handler = sched_proc_update_handler,
294 .extra1 = &min_sched_granularity_ns,
295 .extra2 = &max_sched_granularity_ns,
298 .procname = "sched_latency_ns",
299 .data = &sysctl_sched_latency,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = sched_proc_update_handler,
303 .extra1 = &min_sched_granularity_ns,
304 .extra2 = &max_sched_granularity_ns,
307 .procname = "sched_wakeup_granularity_ns",
308 .data = &sysctl_sched_wakeup_granularity,
309 .maxlen = sizeof(unsigned int),
311 .proc_handler = sched_proc_update_handler,
312 .extra1 = &min_wakeup_granularity_ns,
313 .extra2 = &max_wakeup_granularity_ns,
316 .procname = "sched_yield_sleep_threshold",
317 .data = &sysctl_sched_yield_sleep_threshold,
318 .maxlen = sizeof(int),
320 .proc_handler = proc_dointvec,
323 .procname = "sched_yield_sleep_duration",
324 .data = &sysctl_sched_yield_sleep_duration,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = proc_dointvec,
331 .procname = "sched_tunable_scaling",
332 .data = &sysctl_sched_tunable_scaling,
333 .maxlen = sizeof(enum sched_tunable_scaling),
335 .proc_handler = sched_proc_update_handler,
336 .extra1 = &min_sched_tunable_scaling,
337 .extra2 = &max_sched_tunable_scaling,
340 .procname = "sched_migration_cost_ns",
341 .data = &sysctl_sched_migration_cost,
342 .maxlen = sizeof(unsigned int),
344 .proc_handler = proc_dointvec,
347 .procname = "sched_nr_migrate",
348 .data = &sysctl_sched_nr_migrate,
349 .maxlen = sizeof(unsigned int),
351 .proc_handler = proc_dointvec,
354 .procname = "sched_time_avg_ms",
355 .data = &sysctl_sched_time_avg,
356 .maxlen = sizeof(unsigned int),
358 .proc_handler = proc_dointvec,
361 .procname = "sched_shares_window_ns",
362 .data = &sysctl_sched_shares_window,
363 .maxlen = sizeof(unsigned int),
365 .proc_handler = proc_dointvec,
368 .procname = "timer_migration",
369 .data = &sysctl_timer_migration,
370 .maxlen = sizeof(unsigned int),
372 .proc_handler = proc_dointvec_minmax,
376 #endif /* CONFIG_SMP */
377 #ifdef CONFIG_NUMA_BALANCING
379 .procname = "numa_balancing_scan_delay_ms",
380 .data = &sysctl_numa_balancing_scan_delay,
381 .maxlen = sizeof(unsigned int),
383 .proc_handler = proc_dointvec,
386 .procname = "numa_balancing_scan_period_min_ms",
387 .data = &sysctl_numa_balancing_scan_period_min,
388 .maxlen = sizeof(unsigned int),
390 .proc_handler = proc_dointvec,
393 .procname = "numa_balancing_scan_period_reset",
394 .data = &sysctl_numa_balancing_scan_period_reset,
395 .maxlen = sizeof(unsigned int),
397 .proc_handler = proc_dointvec,
400 .procname = "numa_balancing_scan_period_max_ms",
401 .data = &sysctl_numa_balancing_scan_period_max,
402 .maxlen = sizeof(unsigned int),
404 .proc_handler = proc_dointvec,
407 .procname = "numa_balancing_scan_size_mb",
408 .data = &sysctl_numa_balancing_scan_size,
409 .maxlen = sizeof(unsigned int),
411 .proc_handler = proc_dointvec,
413 #endif /* CONFIG_NUMA_BALANCING */
414 #endif /* CONFIG_SCHED_DEBUG */
416 .procname = "sched_rt_period_us",
417 .data = &sysctl_sched_rt_period,
418 .maxlen = sizeof(unsigned int),
420 .proc_handler = sched_rt_handler,
423 .procname = "sched_rt_runtime_us",
424 .data = &sysctl_sched_rt_runtime,
425 .maxlen = sizeof(int),
427 .proc_handler = sched_rt_handler,
430 .procname = "sched_rr_timeslice_ms",
431 .data = &sched_rr_timeslice,
432 .maxlen = sizeof(int),
434 .proc_handler = sched_rr_handler,
436 #ifdef CONFIG_SCHED_AUTOGROUP
438 .procname = "sched_autogroup_enabled",
439 .data = &sysctl_sched_autogroup_enabled,
440 .maxlen = sizeof(unsigned int),
442 .proc_handler = proc_dointvec_minmax,
447 #ifdef CONFIG_CFS_BANDWIDTH
449 .procname = "sched_cfs_bandwidth_slice_us",
450 .data = &sysctl_sched_cfs_bandwidth_slice,
451 .maxlen = sizeof(unsigned int),
453 .proc_handler = proc_dointvec_minmax,
457 #ifdef CONFIG_PROVE_LOCKING
459 .procname = "prove_locking",
460 .data = &prove_locking,
461 .maxlen = sizeof(int),
463 .proc_handler = proc_dointvec,
466 #ifdef CONFIG_LOCK_STAT
468 .procname = "lock_stat",
470 .maxlen = sizeof(int),
472 .proc_handler = proc_dointvec,
477 .data = &panic_timeout,
478 .maxlen = sizeof(int),
480 .proc_handler = proc_dointvec,
482 #ifdef CONFIG_COREDUMP
484 .procname = "core_uses_pid",
485 .data = &core_uses_pid,
486 .maxlen = sizeof(int),
488 .proc_handler = proc_dointvec,
491 .procname = "core_pattern",
492 .data = core_pattern,
493 .maxlen = CORENAME_MAX_SIZE,
495 .proc_handler = proc_dostring_coredump,
498 .procname = "core_pipe_limit",
499 .data = &core_pipe_limit,
500 .maxlen = sizeof(unsigned int),
502 .proc_handler = proc_dointvec,
505 #ifdef CONFIG_PROC_SYSCTL
507 .procname = "tainted",
508 .maxlen = sizeof(long),
510 .proc_handler = proc_taint,
513 #ifdef CONFIG_LATENCYTOP
515 .procname = "latencytop",
516 .data = &latencytop_enabled,
517 .maxlen = sizeof(int),
519 .proc_handler = proc_dointvec,
522 #ifdef CONFIG_BLK_DEV_INITRD
524 .procname = "real-root-dev",
525 .data = &real_root_dev,
526 .maxlen = sizeof(int),
528 .proc_handler = proc_dointvec,
532 .procname = "print-fatal-signals",
533 .data = &print_fatal_signals,
534 .maxlen = sizeof(int),
536 .proc_handler = proc_dointvec,
540 .procname = "reboot-cmd",
541 .data = reboot_command,
544 .proc_handler = proc_dostring,
547 .procname = "stop-a",
548 .data = &stop_a_enabled,
549 .maxlen = sizeof (int),
551 .proc_handler = proc_dointvec,
554 .procname = "scons-poweroff",
555 .data = &scons_pwroff,
556 .maxlen = sizeof (int),
558 .proc_handler = proc_dointvec,
561 #ifdef CONFIG_SPARC64
563 .procname = "tsb-ratio",
564 .data = &sysctl_tsb_ratio,
565 .maxlen = sizeof (int),
567 .proc_handler = proc_dointvec,
572 .procname = "soft-power",
573 .data = &pwrsw_enabled,
574 .maxlen = sizeof (int),
576 .proc_handler = proc_dointvec,
579 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
581 .procname = "unaligned-trap",
582 .data = &unaligned_enabled,
583 .maxlen = sizeof (int),
585 .proc_handler = proc_dointvec,
589 .procname = "ctrl-alt-del",
591 .maxlen = sizeof(int),
593 .proc_handler = proc_dointvec,
595 #ifdef CONFIG_FUNCTION_TRACER
597 .procname = "ftrace_enabled",
598 .data = &ftrace_enabled,
599 .maxlen = sizeof(int),
601 .proc_handler = ftrace_enable_sysctl,
604 #ifdef CONFIG_STACK_TRACER
606 .procname = "stack_tracer_enabled",
607 .data = &stack_tracer_enabled,
608 .maxlen = sizeof(int),
610 .proc_handler = stack_trace_sysctl,
613 #ifdef CONFIG_TRACING
615 .procname = "ftrace_dump_on_oops",
616 .data = &ftrace_dump_on_oops,
617 .maxlen = sizeof(int),
619 .proc_handler = proc_dointvec,
622 #ifdef CONFIG_MODULES
624 .procname = "modprobe",
625 .data = &modprobe_path,
626 .maxlen = KMOD_PATH_LEN,
628 .proc_handler = proc_dostring,
631 .procname = "modules_disabled",
632 .data = &modules_disabled,
633 .maxlen = sizeof(int),
635 /* only handle a transition from default "0" to "1" */
636 .proc_handler = proc_dointvec_minmax,
643 .procname = "hotplug",
644 .data = &uevent_helper,
645 .maxlen = UEVENT_HELPER_PATH_LEN,
647 .proc_handler = proc_dostring,
650 #ifdef CONFIG_CHR_DEV_SG
652 .procname = "sg-big-buff",
653 .data = &sg_big_buff,
654 .maxlen = sizeof (int),
656 .proc_handler = proc_dointvec,
659 #ifdef CONFIG_BSD_PROCESS_ACCT
663 .maxlen = 3*sizeof(int),
665 .proc_handler = proc_dointvec,
668 #ifdef CONFIG_MAGIC_SYSRQ
671 .data = &__sysrq_enabled,
672 .maxlen = sizeof (int),
674 .proc_handler = sysrq_sysctl_handler,
677 #ifdef CONFIG_PROC_SYSCTL
679 .procname = "cad_pid",
681 .maxlen = sizeof (int),
683 .proc_handler = proc_do_cad_pid,
687 .procname = "threads-max",
688 .data = &max_threads,
689 .maxlen = sizeof(int),
691 .proc_handler = proc_dointvec,
694 .procname = "random",
696 .child = random_table,
699 .procname = "usermodehelper",
701 .child = usermodehelper_table,
704 .procname = "overflowuid",
705 .data = &overflowuid,
706 .maxlen = sizeof(int),
708 .proc_handler = proc_dointvec_minmax,
709 .extra1 = &minolduid,
710 .extra2 = &maxolduid,
713 .procname = "overflowgid",
714 .data = &overflowgid,
715 .maxlen = sizeof(int),
717 .proc_handler = proc_dointvec_minmax,
718 .extra1 = &minolduid,
719 .extra2 = &maxolduid,
722 #ifdef CONFIG_MATHEMU
724 .procname = "ieee_emulation_warnings",
725 .data = &sysctl_ieee_emulation_warnings,
726 .maxlen = sizeof(int),
728 .proc_handler = proc_dointvec,
732 .procname = "userprocess_debug",
733 .data = &show_unhandled_signals,
734 .maxlen = sizeof(int),
736 .proc_handler = proc_dointvec,
740 .procname = "pid_max",
742 .maxlen = sizeof (int),
744 .proc_handler = proc_dointvec_minmax,
745 .extra1 = &pid_max_min,
746 .extra2 = &pid_max_max,
749 .procname = "panic_on_oops",
750 .data = &panic_on_oops,
751 .maxlen = sizeof(int),
753 .proc_handler = proc_dointvec,
755 #if defined CONFIG_PRINTK
757 .procname = "printk",
758 .data = &console_loglevel,
759 .maxlen = 4*sizeof(int),
761 .proc_handler = proc_dointvec,
764 .procname = "printk_ratelimit",
765 .data = &printk_ratelimit_state.interval,
766 .maxlen = sizeof(int),
768 .proc_handler = proc_dointvec_jiffies,
771 .procname = "printk_ratelimit_burst",
772 .data = &printk_ratelimit_state.burst,
773 .maxlen = sizeof(int),
775 .proc_handler = proc_dointvec,
778 .procname = "printk_delay",
779 .data = &printk_delay_msec,
780 .maxlen = sizeof(int),
782 .proc_handler = proc_dointvec_minmax,
784 .extra2 = &ten_thousand,
787 .procname = "dmesg_restrict",
788 .data = &dmesg_restrict,
789 .maxlen = sizeof(int),
791 .proc_handler = proc_dointvec_minmax_sysadmin,
796 .procname = "kptr_restrict",
797 .data = &kptr_restrict,
798 .maxlen = sizeof(int),
800 .proc_handler = proc_dointvec_minmax_sysadmin,
806 .procname = "ngroups_max",
807 .data = &ngroups_max,
808 .maxlen = sizeof (int),
810 .proc_handler = proc_dointvec,
813 .procname = "cap_last_cap",
814 .data = (void *)&cap_last_cap,
815 .maxlen = sizeof(int),
817 .proc_handler = proc_dointvec,
819 #if defined(CONFIG_LOCKUP_DETECTOR)
821 .procname = "watchdog",
822 .data = &watchdog_enabled,
823 .maxlen = sizeof (int),
825 .proc_handler = proc_dowatchdog,
830 .procname = "watchdog_thresh",
831 .data = &watchdog_thresh,
832 .maxlen = sizeof(int),
834 .proc_handler = proc_dowatchdog,
839 .procname = "softlockup_panic",
840 .data = &softlockup_panic,
841 .maxlen = sizeof(int),
843 .proc_handler = proc_dointvec_minmax,
848 .procname = "nmi_watchdog",
849 .data = &watchdog_enabled,
850 .maxlen = sizeof (int),
852 .proc_handler = proc_dowatchdog,
857 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
859 .procname = "unknown_nmi_panic",
860 .data = &unknown_nmi_panic,
861 .maxlen = sizeof (int),
863 .proc_handler = proc_dointvec,
866 #if defined(CONFIG_X86)
868 .procname = "panic_on_unrecovered_nmi",
869 .data = &panic_on_unrecovered_nmi,
870 .maxlen = sizeof(int),
872 .proc_handler = proc_dointvec,
875 .procname = "panic_on_io_nmi",
876 .data = &panic_on_io_nmi,
877 .maxlen = sizeof(int),
879 .proc_handler = proc_dointvec,
881 #ifdef CONFIG_DEBUG_STACKOVERFLOW
883 .procname = "panic_on_stackoverflow",
884 .data = &sysctl_panic_on_stackoverflow,
885 .maxlen = sizeof(int),
887 .proc_handler = proc_dointvec,
891 .procname = "bootloader_type",
892 .data = &bootloader_type,
893 .maxlen = sizeof (int),
895 .proc_handler = proc_dointvec,
898 .procname = "bootloader_version",
899 .data = &bootloader_version,
900 .maxlen = sizeof (int),
902 .proc_handler = proc_dointvec,
905 .procname = "kstack_depth_to_print",
906 .data = &kstack_depth_to_print,
907 .maxlen = sizeof(int),
909 .proc_handler = proc_dointvec,
912 .procname = "io_delay_type",
913 .data = &io_delay_type,
914 .maxlen = sizeof(int),
916 .proc_handler = proc_dointvec,
919 #if defined(CONFIG_MMU)
921 .procname = "randomize_va_space",
922 .data = &randomize_va_space,
923 .maxlen = sizeof(int),
925 .proc_handler = proc_dointvec,
928 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
930 .procname = "spin_retry",
932 .maxlen = sizeof (int),
934 .proc_handler = proc_dointvec,
937 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
939 .procname = "acpi_video_flags",
940 .data = &acpi_realmode_flags,
941 .maxlen = sizeof (unsigned long),
943 .proc_handler = proc_doulongvec_minmax,
946 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
948 .procname = "ignore-unaligned-usertrap",
949 .data = &no_unaligned_warning,
950 .maxlen = sizeof (int),
952 .proc_handler = proc_dointvec,
957 .procname = "unaligned-dump-stack",
958 .data = &unaligned_dump_stack,
959 .maxlen = sizeof (int),
961 .proc_handler = proc_dointvec,
964 #ifdef CONFIG_DETECT_HUNG_TASK
966 .procname = "hung_task_panic",
967 .data = &sysctl_hung_task_panic,
968 .maxlen = sizeof(int),
970 .proc_handler = proc_dointvec_minmax,
975 .procname = "hung_task_check_count",
976 .data = &sysctl_hung_task_check_count,
977 .maxlen = sizeof(unsigned long),
979 .proc_handler = proc_doulongvec_minmax,
982 .procname = "hung_task_timeout_secs",
983 .data = &sysctl_hung_task_timeout_secs,
984 .maxlen = sizeof(unsigned long),
986 .proc_handler = proc_dohung_task_timeout_secs,
989 .procname = "hung_task_warnings",
990 .data = &sysctl_hung_task_warnings,
991 .maxlen = sizeof(unsigned long),
993 .proc_handler = proc_doulongvec_minmax,
998 .procname = "compat-log",
1000 .maxlen = sizeof (int),
1002 .proc_handler = proc_dointvec,
1005 #ifdef CONFIG_RT_MUTEXES
1007 .procname = "max_lock_depth",
1008 .data = &max_lock_depth,
1009 .maxlen = sizeof(int),
1011 .proc_handler = proc_dointvec,
1015 .procname = "poweroff_cmd",
1016 .data = &poweroff_cmd,
1017 .maxlen = POWEROFF_CMD_PATH_LEN,
1019 .proc_handler = proc_dostring,
1025 .child = key_sysctls,
1028 #ifdef CONFIG_RCU_TORTURE_TEST
1030 .procname = "rcutorture_runnable",
1031 .data = &rcutorture_runnable,
1032 .maxlen = sizeof(int),
1034 .proc_handler = proc_dointvec,
1037 #ifdef CONFIG_PERF_EVENTS
1039 * User-space scripts rely on the existence of this file
1040 * as a feature check for perf_events being enabled.
1042 * So it's an ABI, do not remove!
1045 .procname = "perf_event_paranoid",
1046 .data = &sysctl_perf_event_paranoid,
1047 .maxlen = sizeof(sysctl_perf_event_paranoid),
1049 .proc_handler = proc_dointvec,
1052 .procname = "perf_event_mlock_kb",
1053 .data = &sysctl_perf_event_mlock,
1054 .maxlen = sizeof(sysctl_perf_event_mlock),
1056 .proc_handler = proc_dointvec,
1059 .procname = "perf_event_max_sample_rate",
1060 .data = &sysctl_perf_event_sample_rate,
1061 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1063 .proc_handler = perf_proc_update_handler,
1066 #ifdef CONFIG_KMEMCHECK
1068 .procname = "kmemcheck",
1069 .data = &kmemcheck_enabled,
1070 .maxlen = sizeof(int),
1072 .proc_handler = proc_dointvec,
1077 .procname = "blk_iopoll",
1078 .data = &blk_iopoll_enabled,
1079 .maxlen = sizeof(int),
1081 .proc_handler = proc_dointvec,
1087 static struct ctl_table vm_table[] = {
1089 .procname = "lazy_vfree_pages",
1090 .data = &sysctl_lazy_vfree_pages,
1091 .maxlen = sizeof(sysctl_lazy_vfree_pages),
1093 .proc_handler = proc_dointvec,
1096 .procname = "lazy_vfree_tlb_flush_all_threshold",
1097 .data = &sysctl_lazy_vfree_tlb_flush_all_threshold,
1098 .maxlen = sizeof(sysctl_lazy_vfree_tlb_flush_all_threshold),
1100 .proc_handler = proc_dointvec,
1103 .procname = "overcommit_memory",
1104 .data = &sysctl_overcommit_memory,
1105 .maxlen = sizeof(sysctl_overcommit_memory),
1107 .proc_handler = proc_dointvec_minmax,
1112 .procname = "panic_on_oom",
1113 .data = &sysctl_panic_on_oom,
1114 .maxlen = sizeof(sysctl_panic_on_oom),
1116 .proc_handler = proc_dointvec_minmax,
1121 .procname = "oom_kill_allocating_task",
1122 .data = &sysctl_oom_kill_allocating_task,
1123 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1125 .proc_handler = proc_dointvec,
1128 .procname = "oom_dump_tasks",
1129 .data = &sysctl_oom_dump_tasks,
1130 .maxlen = sizeof(sysctl_oom_dump_tasks),
1132 .proc_handler = proc_dointvec,
1135 .procname = "overcommit_ratio",
1136 .data = &sysctl_overcommit_ratio,
1137 .maxlen = sizeof(sysctl_overcommit_ratio),
1139 .proc_handler = proc_dointvec,
1142 .procname = "page-cluster",
1143 .data = &page_cluster,
1144 .maxlen = sizeof(int),
1146 .proc_handler = proc_dointvec_minmax,
1150 .procname = "dirty_background_ratio",
1151 .data = &dirty_background_ratio,
1152 .maxlen = sizeof(dirty_background_ratio),
1154 .proc_handler = dirty_background_ratio_handler,
1156 .extra2 = &one_hundred,
1159 .procname = "dirty_background_bytes",
1160 .data = &dirty_background_bytes,
1161 .maxlen = sizeof(dirty_background_bytes),
1163 .proc_handler = dirty_background_bytes_handler,
1167 .procname = "dirty_ratio",
1168 .data = &vm_dirty_ratio,
1169 .maxlen = sizeof(vm_dirty_ratio),
1171 .proc_handler = dirty_ratio_handler,
1173 .extra2 = &one_hundred,
1176 .procname = "dirty_bytes",
1177 .data = &vm_dirty_bytes,
1178 .maxlen = sizeof(vm_dirty_bytes),
1180 .proc_handler = dirty_bytes_handler,
1181 .extra1 = &dirty_bytes_min,
1184 .procname = "dirty_writeback_centisecs",
1185 .data = &dirty_writeback_interval,
1186 .maxlen = sizeof(dirty_writeback_interval),
1188 .proc_handler = dirty_writeback_centisecs_handler,
1191 .procname = "dirty_expire_centisecs",
1192 .data = &dirty_expire_interval,
1193 .maxlen = sizeof(dirty_expire_interval),
1195 .proc_handler = proc_dointvec_minmax,
1199 .procname = "nr_pdflush_threads",
1200 .mode = 0444 /* read-only */,
1201 .proc_handler = pdflush_proc_obsolete,
1204 .procname = "swappiness",
1205 .data = &vm_swappiness,
1206 .maxlen = sizeof(vm_swappiness),
1208 .proc_handler = proc_dointvec_minmax,
1210 .extra2 = &one_hundred,
1212 #ifdef CONFIG_HUGETLB_PAGE
1214 .procname = "nr_hugepages",
1216 .maxlen = sizeof(unsigned long),
1218 .proc_handler = hugetlb_sysctl_handler,
1219 .extra1 = (void *)&hugetlb_zero,
1220 .extra2 = (void *)&hugetlb_infinity,
1224 .procname = "nr_hugepages_mempolicy",
1226 .maxlen = sizeof(unsigned long),
1228 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1229 .extra1 = (void *)&hugetlb_zero,
1230 .extra2 = (void *)&hugetlb_infinity,
1234 .procname = "hugetlb_shm_group",
1235 .data = &sysctl_hugetlb_shm_group,
1236 .maxlen = sizeof(gid_t),
1238 .proc_handler = proc_dointvec,
1241 .procname = "hugepages_treat_as_movable",
1242 .data = &hugepages_treat_as_movable,
1243 .maxlen = sizeof(int),
1245 .proc_handler = hugetlb_treat_movable_handler,
1248 .procname = "nr_overcommit_hugepages",
1250 .maxlen = sizeof(unsigned long),
1252 .proc_handler = hugetlb_overcommit_handler,
1253 .extra1 = (void *)&hugetlb_zero,
1254 .extra2 = (void *)&hugetlb_infinity,
1258 .procname = "lowmem_reserve_ratio",
1259 .data = &sysctl_lowmem_reserve_ratio,
1260 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1262 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1265 .procname = "drop_caches",
1266 .data = &sysctl_drop_caches,
1267 .maxlen = sizeof(int),
1269 .proc_handler = drop_caches_sysctl_handler,
1273 #ifdef CONFIG_COMPACTION
1275 .procname = "compact_memory",
1276 .data = &sysctl_compact_memory,
1277 .maxlen = sizeof(int),
1279 .proc_handler = sysctl_compaction_handler,
1282 .procname = "extfrag_threshold",
1283 .data = &sysctl_extfrag_threshold,
1284 .maxlen = sizeof(int),
1286 .proc_handler = sysctl_extfrag_handler,
1287 .extra1 = &min_extfrag_threshold,
1288 .extra2 = &max_extfrag_threshold,
1291 #endif /* CONFIG_COMPACTION */
1293 .procname = "min_free_kbytes",
1294 .data = &min_free_kbytes,
1295 .maxlen = sizeof(min_free_kbytes),
1297 .proc_handler = min_free_kbytes_sysctl_handler,
1301 .procname = "extra_free_kbytes",
1302 .data = &extra_free_kbytes,
1303 .maxlen = sizeof(extra_free_kbytes),
1305 .proc_handler = min_free_kbytes_sysctl_handler,
1309 .procname = "min_free_order_shift",
1310 .data = &min_free_order_shift,
1311 .maxlen = sizeof(min_free_order_shift),
1313 .proc_handler = &proc_dointvec
1316 .procname = "percpu_pagelist_fraction",
1317 .data = &percpu_pagelist_fraction,
1318 .maxlen = sizeof(percpu_pagelist_fraction),
1320 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1321 .extra1 = &min_percpu_pagelist_fract,
1325 .procname = "max_map_count",
1326 .data = &sysctl_max_map_count,
1327 .maxlen = sizeof(sysctl_max_map_count),
1329 .proc_handler = proc_dointvec_minmax,
1334 .procname = "nr_trim_pages",
1335 .data = &sysctl_nr_trim_pages,
1336 .maxlen = sizeof(sysctl_nr_trim_pages),
1338 .proc_handler = proc_dointvec_minmax,
1343 .procname = "laptop_mode",
1344 .data = &laptop_mode,
1345 .maxlen = sizeof(laptop_mode),
1347 .proc_handler = proc_dointvec_jiffies,
1350 .procname = "block_dump",
1351 .data = &block_dump,
1352 .maxlen = sizeof(block_dump),
1354 .proc_handler = proc_dointvec,
1358 .procname = "vfs_cache_pressure",
1359 .data = &sysctl_vfs_cache_pressure,
1360 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1362 .proc_handler = proc_dointvec,
1365 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1367 .procname = "legacy_va_layout",
1368 .data = &sysctl_legacy_va_layout,
1369 .maxlen = sizeof(sysctl_legacy_va_layout),
1371 .proc_handler = proc_dointvec,
1377 .procname = "zone_reclaim_mode",
1378 .data = &zone_reclaim_mode,
1379 .maxlen = sizeof(zone_reclaim_mode),
1381 .proc_handler = proc_dointvec,
1385 .procname = "min_unmapped_ratio",
1386 .data = &sysctl_min_unmapped_ratio,
1387 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1389 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1391 .extra2 = &one_hundred,
1394 .procname = "min_slab_ratio",
1395 .data = &sysctl_min_slab_ratio,
1396 .maxlen = sizeof(sysctl_min_slab_ratio),
1398 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1400 .extra2 = &one_hundred,
1405 .procname = "stat_interval",
1406 .data = &sysctl_stat_interval,
1407 .maxlen = sizeof(sysctl_stat_interval),
1409 .proc_handler = proc_dointvec_jiffies,
1414 .procname = "mmap_min_addr",
1415 .data = &dac_mmap_min_addr,
1416 .maxlen = sizeof(unsigned long),
1418 .proc_handler = mmap_min_addr_handler,
1423 .procname = "numa_zonelist_order",
1424 .data = &numa_zonelist_order,
1425 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1427 .proc_handler = numa_zonelist_order_handler,
1430 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1431 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1433 .procname = "vdso_enabled",
1434 .data = &vdso_enabled,
1435 .maxlen = sizeof(vdso_enabled),
1437 .proc_handler = proc_dointvec,
1441 #ifdef CONFIG_HIGHMEM
1443 .procname = "highmem_is_dirtyable",
1444 .data = &vm_highmem_is_dirtyable,
1445 .maxlen = sizeof(vm_highmem_is_dirtyable),
1447 .proc_handler = proc_dointvec_minmax,
1453 .procname = "scan_unevictable_pages",
1454 .data = &scan_unevictable_pages,
1455 .maxlen = sizeof(scan_unevictable_pages),
1457 .proc_handler = scan_unevictable_handler,
1459 #ifdef CONFIG_MEMORY_FAILURE
1461 .procname = "memory_failure_early_kill",
1462 .data = &sysctl_memory_failure_early_kill,
1463 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1465 .proc_handler = proc_dointvec_minmax,
1470 .procname = "memory_failure_recovery",
1471 .data = &sysctl_memory_failure_recovery,
1472 .maxlen = sizeof(sysctl_memory_failure_recovery),
1474 .proc_handler = proc_dointvec_minmax,
1480 .procname = "user_reserve_kbytes",
1481 .data = &sysctl_user_reserve_kbytes,
1482 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1484 .proc_handler = proc_doulongvec_minmax,
1487 .procname = "admin_reserve_kbytes",
1488 .data = &sysctl_admin_reserve_kbytes,
1489 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1491 .proc_handler = proc_doulongvec_minmax,
1496 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1497 static struct ctl_table binfmt_misc_table[] = {
1502 static struct ctl_table fs_table[] = {
1504 .procname = "inode-nr",
1505 .data = &inodes_stat,
1506 .maxlen = 2*sizeof(int),
1508 .proc_handler = proc_nr_inodes,
1511 .procname = "inode-state",
1512 .data = &inodes_stat,
1513 .maxlen = 7*sizeof(int),
1515 .proc_handler = proc_nr_inodes,
1518 .procname = "file-nr",
1519 .data = &files_stat,
1520 .maxlen = sizeof(files_stat),
1522 .proc_handler = proc_nr_files,
1525 .procname = "file-max",
1526 .data = &files_stat.max_files,
1527 .maxlen = sizeof(files_stat.max_files),
1529 .proc_handler = proc_doulongvec_minmax,
1532 .procname = "nr_open",
1533 .data = &sysctl_nr_open,
1534 .maxlen = sizeof(int),
1536 .proc_handler = proc_dointvec_minmax,
1537 .extra1 = &sysctl_nr_open_min,
1538 .extra2 = &sysctl_nr_open_max,
1541 .procname = "dentry-state",
1542 .data = &dentry_stat,
1543 .maxlen = 6*sizeof(int),
1545 .proc_handler = proc_nr_dentry,
1548 .procname = "overflowuid",
1549 .data = &fs_overflowuid,
1550 .maxlen = sizeof(int),
1552 .proc_handler = proc_dointvec_minmax,
1553 .extra1 = &minolduid,
1554 .extra2 = &maxolduid,
1557 .procname = "overflowgid",
1558 .data = &fs_overflowgid,
1559 .maxlen = sizeof(int),
1561 .proc_handler = proc_dointvec_minmax,
1562 .extra1 = &minolduid,
1563 .extra2 = &maxolduid,
1565 #ifdef CONFIG_FILE_LOCKING
1567 .procname = "leases-enable",
1568 .data = &leases_enable,
1569 .maxlen = sizeof(int),
1571 .proc_handler = proc_dointvec,
1574 #ifdef CONFIG_DNOTIFY
1576 .procname = "dir-notify-enable",
1577 .data = &dir_notify_enable,
1578 .maxlen = sizeof(int),
1580 .proc_handler = proc_dointvec,
1584 #ifdef CONFIG_FILE_LOCKING
1586 .procname = "lease-break-time",
1587 .data = &lease_break_time,
1588 .maxlen = sizeof(int),
1590 .proc_handler = proc_dointvec,
1595 .procname = "aio-nr",
1597 .maxlen = sizeof(aio_nr),
1599 .proc_handler = proc_doulongvec_minmax,
1602 .procname = "aio-max-nr",
1603 .data = &aio_max_nr,
1604 .maxlen = sizeof(aio_max_nr),
1606 .proc_handler = proc_doulongvec_minmax,
1608 #endif /* CONFIG_AIO */
1609 #ifdef CONFIG_INOTIFY_USER
1611 .procname = "inotify",
1613 .child = inotify_table,
1618 .procname = "epoll",
1620 .child = epoll_table,
1625 .procname = "protected_symlinks",
1626 .data = &sysctl_protected_symlinks,
1627 .maxlen = sizeof(int),
1629 .proc_handler = proc_dointvec_minmax,
1634 .procname = "protected_hardlinks",
1635 .data = &sysctl_protected_hardlinks,
1636 .maxlen = sizeof(int),
1638 .proc_handler = proc_dointvec_minmax,
1643 .procname = "suid_dumpable",
1644 .data = &suid_dumpable,
1645 .maxlen = sizeof(int),
1647 .proc_handler = proc_dointvec_minmax_coredump,
1651 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1653 .procname = "binfmt_misc",
1655 .child = binfmt_misc_table,
1659 .procname = "pipe-max-size",
1660 .data = &pipe_max_size,
1661 .maxlen = sizeof(int),
1663 .proc_handler = &pipe_proc_fn,
1664 .extra1 = &pipe_min_size,
1669 static struct ctl_table debug_table[] = {
1670 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1672 .procname = "exception-trace",
1673 .data = &show_unhandled_signals,
1674 .maxlen = sizeof(int),
1676 .proc_handler = proc_dointvec
1679 #if defined(CONFIG_OPTPROBES)
1681 .procname = "kprobes-optimization",
1682 .data = &sysctl_kprobes_optimization,
1683 .maxlen = sizeof(int),
1685 .proc_handler = proc_kprobes_optimization_handler,
1693 static struct ctl_table dev_table[] = {
1697 int __init sysctl_init(void)
1699 struct ctl_table_header *hdr;
1701 hdr = register_sysctl_table(sysctl_base_table);
1702 kmemleak_not_leak(hdr);
1706 #endif /* CONFIG_SYSCTL */
1712 #ifdef CONFIG_PROC_SYSCTL
1714 static int _proc_do_string(void* data, int maxlen, int write,
1715 void __user *buffer,
1716 size_t *lenp, loff_t *ppos)
1722 if (!data || !maxlen || !*lenp) {
1730 while (len < *lenp) {
1731 if (get_user(c, p++))
1733 if (c == 0 || c == '\n')
1739 if(copy_from_user(data, buffer, len))
1741 ((char *) data)[len] = 0;
1759 if(copy_to_user(buffer, data, len))
1762 if(put_user('\n', ((char __user *) buffer) + len))
1773 * proc_dostring - read a string sysctl
1774 * @table: the sysctl table
1775 * @write: %TRUE if this is a write to the sysctl file
1776 * @buffer: the user buffer
1777 * @lenp: the size of the user buffer
1778 * @ppos: file position
1780 * Reads/writes a string from/to the user buffer. If the kernel
1781 * buffer provided is not large enough to hold the string, the
1782 * string is truncated. The copied string is %NULL-terminated.
1783 * If the string is being read by the user process, it is copied
1784 * and a newline '\n' is added. It is truncated if the buffer is
1787 * Returns 0 on success.
1789 int proc_dostring(struct ctl_table *table, int write,
1790 void __user *buffer, size_t *lenp, loff_t *ppos)
1792 return _proc_do_string(table->data, table->maxlen, write,
1793 buffer, lenp, ppos);
1796 static size_t proc_skip_spaces(char **buf)
1799 char *tmp = skip_spaces(*buf);
1805 static void proc_skip_char(char **buf, size_t *size, const char v)
1815 #define TMPBUFLEN 22
1817 * proc_get_long - reads an ASCII formatted integer from a user buffer
1819 * @buf: a kernel buffer
1820 * @size: size of the kernel buffer
1821 * @val: this is where the number will be stored
1822 * @neg: set to %TRUE if number is negative
1823 * @perm_tr: a vector which contains the allowed trailers
1824 * @perm_tr_len: size of the perm_tr vector
1825 * @tr: pointer to store the trailer character
1827 * In case of success %0 is returned and @buf and @size are updated with
1828 * the amount of bytes read. If @tr is non-NULL and a trailing
1829 * character exists (size is non-zero after returning from this
1830 * function), @tr is updated with the trailing character.
1832 static int proc_get_long(char **buf, size_t *size,
1833 unsigned long *val, bool *neg,
1834 const char *perm_tr, unsigned perm_tr_len, char *tr)
1837 char *p, tmp[TMPBUFLEN];
1843 if (len > TMPBUFLEN - 1)
1844 len = TMPBUFLEN - 1;
1846 memcpy(tmp, *buf, len);
1850 if (*p == '-' && *size > 1) {
1858 *val = simple_strtoul(p, &p, 0);
1862 /* We don't know if the next char is whitespace thus we may accept
1863 * invalid integers (e.g. 1234...a) or two integers instead of one
1864 * (e.g. 123...1). So lets not allow such large numbers. */
1865 if (len == TMPBUFLEN - 1)
1868 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1871 if (tr && (len < *size))
1881 * proc_put_long - converts an integer to a decimal ASCII formatted string
1883 * @buf: the user buffer
1884 * @size: the size of the user buffer
1885 * @val: the integer to be converted
1886 * @neg: sign of the number, %TRUE for negative
1888 * In case of success %0 is returned and @buf and @size are updated with
1889 * the amount of bytes written.
1891 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1895 char tmp[TMPBUFLEN], *p = tmp;
1897 sprintf(p, "%s%lu", neg ? "-" : "", val);
1901 if (copy_to_user(*buf, tmp, len))
1909 static int proc_put_char(void __user **buf, size_t *size, char c)
1912 char __user **buffer = (char __user **)buf;
1913 if (put_user(c, *buffer))
1915 (*size)--, (*buffer)++;
1921 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1923 int write, void *data)
1926 *valp = *negp ? -*lvalp : *lvalp;
1931 *lvalp = (unsigned long)-val;
1934 *lvalp = (unsigned long)val;
1940 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1942 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1943 int write, void __user *buffer,
1944 size_t *lenp, loff_t *ppos,
1945 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1946 int write, void *data),
1949 int *i, vleft, first = 1, err = 0;
1950 unsigned long page = 0;
1954 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1959 i = (int *) tbl_data;
1960 vleft = table->maxlen / sizeof(*i);
1964 conv = do_proc_dointvec_conv;
1967 if (left > PAGE_SIZE - 1)
1968 left = PAGE_SIZE - 1;
1969 page = __get_free_page(GFP_TEMPORARY);
1970 kbuf = (char *) page;
1973 if (copy_from_user(kbuf, buffer, left)) {
1980 for (; left && vleft--; i++, first=0) {
1985 left -= proc_skip_spaces(&kbuf);
1989 err = proc_get_long(&kbuf, &left, &lval, &neg,
1991 sizeof(proc_wspace_sep), NULL);
1994 if (conv(&neg, &lval, i, 1, data)) {
1999 if (conv(&neg, &lval, i, 0, data)) {
2004 err = proc_put_char(&buffer, &left, '\t');
2007 err = proc_put_long(&buffer, &left, lval, neg);
2013 if (!write && !first && left && !err)
2014 err = proc_put_char(&buffer, &left, '\n');
2015 if (write && !err && left)
2016 left -= proc_skip_spaces(&kbuf);
2021 return err ? : -EINVAL;
2028 static int do_proc_dointvec(struct ctl_table *table, int write,
2029 void __user *buffer, size_t *lenp, loff_t *ppos,
2030 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2031 int write, void *data),
2034 return __do_proc_dointvec(table->data, table, write,
2035 buffer, lenp, ppos, conv, data);
2039 * proc_dointvec - read a vector of integers
2040 * @table: the sysctl table
2041 * @write: %TRUE if this is a write to the sysctl file
2042 * @buffer: the user buffer
2043 * @lenp: the size of the user buffer
2044 * @ppos: file position
2046 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2047 * values from/to the user buffer, treated as an ASCII string.
2049 * Returns 0 on success.
2051 int proc_dointvec(struct ctl_table *table, int write,
2052 void __user *buffer, size_t *lenp, loff_t *ppos)
2054 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2059 * Taint values can only be increased
2060 * This means we can safely use a temporary.
2062 static int proc_taint(struct ctl_table *table, int write,
2063 void __user *buffer, size_t *lenp, loff_t *ppos)
2066 unsigned long tmptaint = get_taint();
2069 if (write && !capable(CAP_SYS_ADMIN))
2074 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2080 * Poor man's atomic or. Not worth adding a primitive
2081 * to everyone's atomic.h for this
2084 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2085 if ((tmptaint >> i) & 1)
2086 add_taint(i, LOCKDEP_STILL_OK);
2093 #ifdef CONFIG_PRINTK
2094 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2095 void __user *buffer, size_t *lenp, loff_t *ppos)
2097 if (write && !capable(CAP_SYS_ADMIN))
2100 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2104 struct do_proc_dointvec_minmax_conv_param {
2109 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2111 int write, void *data)
2113 struct do_proc_dointvec_minmax_conv_param *param = data;
2115 int val = *negp ? -*lvalp : *lvalp;
2116 if ((param->min && *param->min > val) ||
2117 (param->max && *param->max < val))
2124 *lvalp = (unsigned long)-val;
2127 *lvalp = (unsigned long)val;
2134 * proc_dointvec_minmax - read a vector of integers with min/max values
2135 * @table: the sysctl table
2136 * @write: %TRUE if this is a write to the sysctl file
2137 * @buffer: the user buffer
2138 * @lenp: the size of the user buffer
2139 * @ppos: file position
2141 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2142 * values from/to the user buffer, treated as an ASCII string.
2144 * This routine will ensure the values are within the range specified by
2145 * table->extra1 (min) and table->extra2 (max).
2147 * Returns 0 on success.
2149 int proc_dointvec_minmax(struct ctl_table *table, int write,
2150 void __user *buffer, size_t *lenp, loff_t *ppos)
2152 struct do_proc_dointvec_minmax_conv_param param = {
2153 .min = (int *) table->extra1,
2154 .max = (int *) table->extra2,
2156 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2157 do_proc_dointvec_minmax_conv, ¶m);
2160 static void validate_coredump_safety(void)
2162 #ifdef CONFIG_COREDUMP
2163 if (suid_dumpable == SUID_DUMP_ROOT &&
2164 core_pattern[0] != '/' && core_pattern[0] != '|') {
2165 printk(KERN_WARNING "Unsafe core_pattern used with "\
2166 "suid_dumpable=2. Pipe handler or fully qualified "\
2167 "core dump path required.\n");
2172 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2173 void __user *buffer, size_t *lenp, loff_t *ppos)
2175 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2177 validate_coredump_safety();
2181 #ifdef CONFIG_COREDUMP
2182 static int proc_dostring_coredump(struct ctl_table *table, int write,
2183 void __user *buffer, size_t *lenp, loff_t *ppos)
2185 int error = proc_dostring(table, write, buffer, lenp, ppos);
2187 validate_coredump_safety();
2192 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2193 void __user *buffer,
2194 size_t *lenp, loff_t *ppos,
2195 unsigned long convmul,
2196 unsigned long convdiv)
2198 unsigned long *i, *min, *max;
2199 int vleft, first = 1, err = 0;
2200 unsigned long page = 0;
2204 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2209 i = (unsigned long *) data;
2210 min = (unsigned long *) table->extra1;
2211 max = (unsigned long *) table->extra2;
2212 vleft = table->maxlen / sizeof(unsigned long);
2216 if (left > PAGE_SIZE - 1)
2217 left = PAGE_SIZE - 1;
2218 page = __get_free_page(GFP_TEMPORARY);
2219 kbuf = (char *) page;
2222 if (copy_from_user(kbuf, buffer, left)) {
2229 for (; left && vleft--; i++, first = 0) {
2235 left -= proc_skip_spaces(&kbuf);
2237 err = proc_get_long(&kbuf, &left, &val, &neg,
2239 sizeof(proc_wspace_sep), NULL);
2244 if ((min && val < *min) || (max && val > *max))
2248 val = convdiv * (*i) / convmul;
2250 err = proc_put_char(&buffer, &left, '\t');
2251 err = proc_put_long(&buffer, &left, val, false);
2257 if (!write && !first && left && !err)
2258 err = proc_put_char(&buffer, &left, '\n');
2260 left -= proc_skip_spaces(&kbuf);
2265 return err ? : -EINVAL;
2272 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2273 void __user *buffer,
2274 size_t *lenp, loff_t *ppos,
2275 unsigned long convmul,
2276 unsigned long convdiv)
2278 return __do_proc_doulongvec_minmax(table->data, table, write,
2279 buffer, lenp, ppos, convmul, convdiv);
2283 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2284 * @table: the sysctl table
2285 * @write: %TRUE if this is a write to the sysctl file
2286 * @buffer: the user buffer
2287 * @lenp: the size of the user buffer
2288 * @ppos: file position
2290 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2291 * values from/to the user buffer, treated as an ASCII string.
2293 * This routine will ensure the values are within the range specified by
2294 * table->extra1 (min) and table->extra2 (max).
2296 * Returns 0 on success.
2298 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2299 void __user *buffer, size_t *lenp, loff_t *ppos)
2301 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2305 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2306 * @table: the sysctl table
2307 * @write: %TRUE if this is a write to the sysctl file
2308 * @buffer: the user buffer
2309 * @lenp: the size of the user buffer
2310 * @ppos: file position
2312 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2313 * values from/to the user buffer, treated as an ASCII string. The values
2314 * are treated as milliseconds, and converted to jiffies when they are stored.
2316 * This routine will ensure the values are within the range specified by
2317 * table->extra1 (min) and table->extra2 (max).
2319 * Returns 0 on success.
2321 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2322 void __user *buffer,
2323 size_t *lenp, loff_t *ppos)
2325 return do_proc_doulongvec_minmax(table, write, buffer,
2326 lenp, ppos, HZ, 1000l);
2330 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2332 int write, void *data)
2335 if (*lvalp > LONG_MAX / HZ)
2337 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2343 lval = (unsigned long)-val;
2346 lval = (unsigned long)val;
2353 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2355 int write, void *data)
2358 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2360 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2366 lval = (unsigned long)-val;
2369 lval = (unsigned long)val;
2371 *lvalp = jiffies_to_clock_t(lval);
2376 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2378 int write, void *data)
2381 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2387 lval = (unsigned long)-val;
2390 lval = (unsigned long)val;
2392 *lvalp = jiffies_to_msecs(lval);
2398 * proc_dointvec_jiffies - read a vector of integers as seconds
2399 * @table: the sysctl table
2400 * @write: %TRUE if this is a write to the sysctl file
2401 * @buffer: the user buffer
2402 * @lenp: the size of the user buffer
2403 * @ppos: file position
2405 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2406 * values from/to the user buffer, treated as an ASCII string.
2407 * The values read are assumed to be in seconds, and are converted into
2410 * Returns 0 on success.
2412 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2413 void __user *buffer, size_t *lenp, loff_t *ppos)
2415 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2416 do_proc_dointvec_jiffies_conv,NULL);
2420 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2421 * @table: the sysctl table
2422 * @write: %TRUE if this is a write to the sysctl file
2423 * @buffer: the user buffer
2424 * @lenp: the size of the user buffer
2425 * @ppos: pointer to the file position
2427 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2428 * values from/to the user buffer, treated as an ASCII string.
2429 * The values read are assumed to be in 1/USER_HZ seconds, and
2430 * are converted into jiffies.
2432 * Returns 0 on success.
2434 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2435 void __user *buffer, size_t *lenp, loff_t *ppos)
2437 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2438 do_proc_dointvec_userhz_jiffies_conv,NULL);
2442 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2443 * @table: the sysctl table
2444 * @write: %TRUE if this is a write to the sysctl file
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
2447 * @ppos: file position
2448 * @ppos: the current position in the file
2450 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2451 * values from/to the user buffer, treated as an ASCII string.
2452 * The values read are assumed to be in 1/1000 seconds, and
2453 * are converted into jiffies.
2455 * Returns 0 on success.
2457 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2458 void __user *buffer, size_t *lenp, loff_t *ppos)
2460 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2461 do_proc_dointvec_ms_jiffies_conv, NULL);
2464 static int proc_do_cad_pid(struct ctl_table *table, int write,
2465 void __user *buffer, size_t *lenp, loff_t *ppos)
2467 struct pid *new_pid;
2471 tmp = pid_vnr(cad_pid);
2473 r = __do_proc_dointvec(&tmp, table, write, buffer,
2474 lenp, ppos, NULL, NULL);
2478 new_pid = find_get_pid(tmp);
2482 put_pid(xchg(&cad_pid, new_pid));
2487 * proc_do_large_bitmap - read/write from/to a large bitmap
2488 * @table: the sysctl table
2489 * @write: %TRUE if this is a write to the sysctl file
2490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
2492 * @ppos: file position
2494 * The bitmap is stored at table->data and the bitmap length (in bits)
2497 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2498 * large bitmaps may be represented in a compact manner. Writing into
2499 * the file will clear the bitmap then update it with the given input.
2501 * Returns 0 on success.
2503 int proc_do_large_bitmap(struct ctl_table *table, int write,
2504 void __user *buffer, size_t *lenp, loff_t *ppos)
2508 size_t left = *lenp;
2509 unsigned long bitmap_len = table->maxlen;
2510 unsigned long *bitmap = (unsigned long *) table->data;
2511 unsigned long *tmp_bitmap = NULL;
2512 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2514 if (!bitmap_len || !left || (*ppos && !write)) {
2520 unsigned long page = 0;
2523 if (left > PAGE_SIZE - 1)
2524 left = PAGE_SIZE - 1;
2526 page = __get_free_page(GFP_TEMPORARY);
2527 kbuf = (char *) page;
2530 if (copy_from_user(kbuf, buffer, left)) {
2536 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2542 proc_skip_char(&kbuf, &left, '\n');
2543 while (!err && left) {
2544 unsigned long val_a, val_b;
2547 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2551 if (val_a >= bitmap_len || neg) {
2563 err = proc_get_long(&kbuf, &left, &val_b,
2564 &neg, tr_b, sizeof(tr_b),
2568 if (val_b >= bitmap_len || neg ||
2579 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2581 proc_skip_char(&kbuf, &left, '\n');
2585 unsigned long bit_a, bit_b = 0;
2588 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2589 if (bit_a >= bitmap_len)
2591 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2595 err = proc_put_char(&buffer, &left, ',');
2599 err = proc_put_long(&buffer, &left, bit_a, false);
2602 if (bit_a != bit_b) {
2603 err = proc_put_char(&buffer, &left, '-');
2606 err = proc_put_long(&buffer, &left, bit_b, false);
2614 err = proc_put_char(&buffer, &left, '\n');
2620 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2622 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2634 #else /* CONFIG_PROC_SYSCTL */
2636 int proc_dostring(struct ctl_table *table, int write,
2637 void __user *buffer, size_t *lenp, loff_t *ppos)
2642 int proc_dointvec(struct ctl_table *table, int write,
2643 void __user *buffer, size_t *lenp, loff_t *ppos)
2648 int proc_dointvec_minmax(struct ctl_table *table, int write,
2649 void __user *buffer, size_t *lenp, loff_t *ppos)
2654 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2655 void __user *buffer, size_t *lenp, loff_t *ppos)
2660 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2661 void __user *buffer, size_t *lenp, loff_t *ppos)
2666 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2667 void __user *buffer, size_t *lenp, loff_t *ppos)
2672 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2673 void __user *buffer, size_t *lenp, loff_t *ppos)
2678 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2679 void __user *buffer,
2680 size_t *lenp, loff_t *ppos)
2686 #endif /* CONFIG_PROC_SYSCTL */
2689 * No sense putting this after each symbol definition, twice,
2690 * exception granted :-)
2692 EXPORT_SYMBOL(proc_dointvec);
2693 EXPORT_SYMBOL(proc_dointvec_jiffies);
2694 EXPORT_SYMBOL(proc_dointvec_minmax);
2695 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2696 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2697 EXPORT_SYMBOL(proc_dostring);
2698 EXPORT_SYMBOL(proc_doulongvec_minmax);
2699 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);