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>
65 #include <asm/uaccess.h>
66 #include <asm/processor.h>
70 #include <asm/stacktrace.h>
74 #include <asm/setup.h>
76 #ifdef CONFIG_BSD_PROCESS_ACCT
77 #include <linux/acct.h>
79 #ifdef CONFIG_RT_MUTEXES
80 #include <linux/rtmutex.h>
82 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
83 #include <linux/lockdep.h>
85 #ifdef CONFIG_CHR_DEV_SG
89 #ifdef CONFIG_LOCKUP_DETECTOR
90 #include <linux/nmi.h>
94 #if defined(CONFIG_SYSCTL)
96 /* External variables not in a header file. */
97 extern int sysctl_overcommit_memory;
98 extern int sysctl_overcommit_ratio;
99 extern int max_threads;
100 extern int suid_dumpable;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid;
103 extern char core_pattern[];
104 extern unsigned int core_pipe_limit;
107 extern int min_free_kbytes;
108 extern int pid_max_min, pid_max_max;
109 extern int sysctl_drop_caches;
110 extern int percpu_pagelist_fraction;
111 extern int compat_log;
112 extern int latencytop_enabled;
113 extern int sysctl_nr_open_min, sysctl_nr_open_max;
115 extern int sysctl_nr_trim_pages;
118 extern int blk_iopoll_enabled;
121 /* Constants used for minimum and maximum */
122 #ifdef CONFIG_LOCKUP_DETECTOR
123 static int sixty = 60;
124 static int neg_one = -1;
128 static int __maybe_unused one = 1;
129 static int __maybe_unused two = 2;
130 static int __maybe_unused three = 3;
131 static unsigned long one_ul = 1;
132 static int one_hundred = 100;
134 static int ten_thousand = 10000;
137 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141 static int maxolduid = 65535;
142 static int minolduid;
143 static int min_percpu_pagelist_fract = 8;
145 static int ngroups_max = NGROUPS_MAX;
146 static const int cap_last_cap = CAP_LAST_CAP;
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
154 #ifdef CONFIG_SPARC64
155 extern int sysctl_tsb_ratio;
159 extern int pwrsw_enabled;
160 extern int unaligned_enabled;
164 extern int no_unaligned_warning;
165 extern int unaligned_dump_stack;
168 #ifdef CONFIG_PROC_SYSCTL
169 static int proc_do_cad_pid(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171 static int proc_taint(struct ctl_table *table, int write,
172 void __user *buffer, size_t *lenp, loff_t *ppos);
176 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
177 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
182 #ifdef CONFIG_COREDUMP
183 static int proc_dostring_coredump(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
187 #ifdef CONFIG_MAGIC_SYSRQ
188 /* Note: sysrq code uses it's own private copy */
189 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
191 static int sysrq_sysctl_handler(ctl_table *table, int write,
192 void __user *buffer, size_t *lenp,
197 error = proc_dointvec(table, write, buffer, lenp, ppos);
202 sysrq_toggle_support(__sysrq_enabled);
209 static struct ctl_table kern_table[];
210 static struct ctl_table vm_table[];
211 static struct ctl_table fs_table[];
212 static struct ctl_table debug_table[];
213 static struct ctl_table dev_table[];
214 extern struct ctl_table random_table[];
216 extern struct ctl_table epoll_table[];
219 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220 int sysctl_legacy_va_layout;
223 /* The default sysctl tables: */
225 static struct ctl_table sysctl_base_table[] = {
227 .procname = "kernel",
244 .child = debug_table,
254 #ifdef CONFIG_SCHED_DEBUG
255 static int min_sched_granularity_ns = 100000; /* 100 usecs */
256 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
257 static int min_wakeup_granularity_ns; /* 0 usecs */
258 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
260 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
261 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
262 #endif /* CONFIG_SMP */
263 #endif /* CONFIG_SCHED_DEBUG */
265 #ifdef CONFIG_COMPACTION
266 static int min_extfrag_threshold;
267 static int max_extfrag_threshold = 1000;
270 static struct ctl_table kern_table[] = {
272 .procname = "sched_child_runs_first",
273 .data = &sysctl_sched_child_runs_first,
274 .maxlen = sizeof(unsigned int),
276 .proc_handler = proc_dointvec,
278 #ifdef CONFIG_SCHED_DEBUG
280 .procname = "sched_min_granularity_ns",
281 .data = &sysctl_sched_min_granularity,
282 .maxlen = sizeof(unsigned int),
284 .proc_handler = sched_proc_update_handler,
285 .extra1 = &min_sched_granularity_ns,
286 .extra2 = &max_sched_granularity_ns,
289 .procname = "sched_latency_ns",
290 .data = &sysctl_sched_latency,
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_wakeup_granularity_ns",
299 .data = &sysctl_sched_wakeup_granularity,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = sched_proc_update_handler,
303 .extra1 = &min_wakeup_granularity_ns,
304 .extra2 = &max_wakeup_granularity_ns,
308 .procname = "sched_tunable_scaling",
309 .data = &sysctl_sched_tunable_scaling,
310 .maxlen = sizeof(enum sched_tunable_scaling),
312 .proc_handler = sched_proc_update_handler,
313 .extra1 = &min_sched_tunable_scaling,
314 .extra2 = &max_sched_tunable_scaling,
317 .procname = "sched_migration_cost_ns",
318 .data = &sysctl_sched_migration_cost,
319 .maxlen = sizeof(unsigned int),
321 .proc_handler = proc_dointvec,
324 .procname = "sched_nr_migrate",
325 .data = &sysctl_sched_nr_migrate,
326 .maxlen = sizeof(unsigned int),
328 .proc_handler = proc_dointvec,
331 .procname = "sched_time_avg_ms",
332 .data = &sysctl_sched_time_avg,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = proc_dointvec,
338 .procname = "sched_shares_window_ns",
339 .data = &sysctl_sched_shares_window,
340 .maxlen = sizeof(unsigned int),
342 .proc_handler = proc_dointvec,
345 .procname = "timer_migration",
346 .data = &sysctl_timer_migration,
347 .maxlen = sizeof(unsigned int),
349 .proc_handler = proc_dointvec_minmax,
353 #endif /* CONFIG_SMP */
354 #ifdef CONFIG_NUMA_BALANCING
356 .procname = "numa_balancing_scan_period_min_ms",
357 .data = &sysctl_numa_balancing_scan_period_min,
358 .maxlen = sizeof(unsigned int),
360 .proc_handler = proc_dointvec,
363 .procname = "numa_balancing_scan_period_max_ms",
364 .data = &sysctl_numa_balancing_scan_period_max,
365 .maxlen = sizeof(unsigned int),
367 .proc_handler = proc_dointvec,
369 #endif /* CONFIG_NUMA_BALANCING */
370 #endif /* CONFIG_SCHED_DEBUG */
372 .procname = "sched_rt_period_us",
373 .data = &sysctl_sched_rt_period,
374 .maxlen = sizeof(unsigned int),
376 .proc_handler = sched_rt_handler,
379 .procname = "sched_rt_runtime_us",
380 .data = &sysctl_sched_rt_runtime,
381 .maxlen = sizeof(int),
383 .proc_handler = sched_rt_handler,
385 #ifdef CONFIG_SCHED_AUTOGROUP
387 .procname = "sched_autogroup_enabled",
388 .data = &sysctl_sched_autogroup_enabled,
389 .maxlen = sizeof(unsigned int),
391 .proc_handler = proc_dointvec_minmax,
396 #ifdef CONFIG_CFS_BANDWIDTH
398 .procname = "sched_cfs_bandwidth_slice_us",
399 .data = &sysctl_sched_cfs_bandwidth_slice,
400 .maxlen = sizeof(unsigned int),
402 .proc_handler = proc_dointvec_minmax,
406 #ifdef CONFIG_PROVE_LOCKING
408 .procname = "prove_locking",
409 .data = &prove_locking,
410 .maxlen = sizeof(int),
412 .proc_handler = proc_dointvec,
415 #ifdef CONFIG_LOCK_STAT
417 .procname = "lock_stat",
419 .maxlen = sizeof(int),
421 .proc_handler = proc_dointvec,
426 .data = &panic_timeout,
427 .maxlen = sizeof(int),
429 .proc_handler = proc_dointvec,
431 #ifdef CONFIG_COREDUMP
433 .procname = "core_uses_pid",
434 .data = &core_uses_pid,
435 .maxlen = sizeof(int),
437 .proc_handler = proc_dointvec,
440 .procname = "core_pattern",
441 .data = core_pattern,
442 .maxlen = CORENAME_MAX_SIZE,
444 .proc_handler = proc_dostring_coredump,
447 .procname = "core_pipe_limit",
448 .data = &core_pipe_limit,
449 .maxlen = sizeof(unsigned int),
451 .proc_handler = proc_dointvec,
454 #ifdef CONFIG_PROC_SYSCTL
456 .procname = "tainted",
457 .maxlen = sizeof(long),
459 .proc_handler = proc_taint,
462 #ifdef CONFIG_LATENCYTOP
464 .procname = "latencytop",
465 .data = &latencytop_enabled,
466 .maxlen = sizeof(int),
468 .proc_handler = proc_dointvec,
471 #ifdef CONFIG_BLK_DEV_INITRD
473 .procname = "real-root-dev",
474 .data = &real_root_dev,
475 .maxlen = sizeof(int),
477 .proc_handler = proc_dointvec,
481 .procname = "print-fatal-signals",
482 .data = &print_fatal_signals,
483 .maxlen = sizeof(int),
485 .proc_handler = proc_dointvec,
489 .procname = "reboot-cmd",
490 .data = reboot_command,
493 .proc_handler = proc_dostring,
496 .procname = "stop-a",
497 .data = &stop_a_enabled,
498 .maxlen = sizeof (int),
500 .proc_handler = proc_dointvec,
503 .procname = "scons-poweroff",
504 .data = &scons_pwroff,
505 .maxlen = sizeof (int),
507 .proc_handler = proc_dointvec,
510 #ifdef CONFIG_SPARC64
512 .procname = "tsb-ratio",
513 .data = &sysctl_tsb_ratio,
514 .maxlen = sizeof (int),
516 .proc_handler = proc_dointvec,
521 .procname = "soft-power",
522 .data = &pwrsw_enabled,
523 .maxlen = sizeof (int),
525 .proc_handler = proc_dointvec,
528 .procname = "unaligned-trap",
529 .data = &unaligned_enabled,
530 .maxlen = sizeof (int),
532 .proc_handler = proc_dointvec,
536 .procname = "ctrl-alt-del",
538 .maxlen = sizeof(int),
540 .proc_handler = proc_dointvec,
542 #ifdef CONFIG_FUNCTION_TRACER
544 .procname = "ftrace_enabled",
545 .data = &ftrace_enabled,
546 .maxlen = sizeof(int),
548 .proc_handler = ftrace_enable_sysctl,
551 #ifdef CONFIG_STACK_TRACER
553 .procname = "stack_tracer_enabled",
554 .data = &stack_tracer_enabled,
555 .maxlen = sizeof(int),
557 .proc_handler = stack_trace_sysctl,
560 #ifdef CONFIG_TRACING
562 .procname = "ftrace_dump_on_oops",
563 .data = &ftrace_dump_on_oops,
564 .maxlen = sizeof(int),
566 .proc_handler = proc_dointvec,
569 #ifdef CONFIG_MODULES
571 .procname = "modprobe",
572 .data = &modprobe_path,
573 .maxlen = KMOD_PATH_LEN,
575 .proc_handler = proc_dostring,
578 .procname = "modules_disabled",
579 .data = &modules_disabled,
580 .maxlen = sizeof(int),
582 /* only handle a transition from default "0" to "1" */
583 .proc_handler = proc_dointvec_minmax,
588 #ifdef CONFIG_HOTPLUG
590 .procname = "hotplug",
591 .data = &uevent_helper,
592 .maxlen = UEVENT_HELPER_PATH_LEN,
594 .proc_handler = proc_dostring,
597 #ifdef CONFIG_CHR_DEV_SG
599 .procname = "sg-big-buff",
600 .data = &sg_big_buff,
601 .maxlen = sizeof (int),
603 .proc_handler = proc_dointvec,
606 #ifdef CONFIG_BSD_PROCESS_ACCT
610 .maxlen = 3*sizeof(int),
612 .proc_handler = proc_dointvec,
615 #ifdef CONFIG_MAGIC_SYSRQ
618 .data = &__sysrq_enabled,
619 .maxlen = sizeof (int),
621 .proc_handler = sysrq_sysctl_handler,
624 #ifdef CONFIG_PROC_SYSCTL
626 .procname = "cad_pid",
628 .maxlen = sizeof (int),
630 .proc_handler = proc_do_cad_pid,
634 .procname = "threads-max",
635 .data = &max_threads,
636 .maxlen = sizeof(int),
638 .proc_handler = proc_dointvec,
641 .procname = "random",
643 .child = random_table,
646 .procname = "usermodehelper",
648 .child = usermodehelper_table,
651 .procname = "overflowuid",
652 .data = &overflowuid,
653 .maxlen = sizeof(int),
655 .proc_handler = proc_dointvec_minmax,
656 .extra1 = &minolduid,
657 .extra2 = &maxolduid,
660 .procname = "overflowgid",
661 .data = &overflowgid,
662 .maxlen = sizeof(int),
664 .proc_handler = proc_dointvec_minmax,
665 .extra1 = &minolduid,
666 .extra2 = &maxolduid,
669 #ifdef CONFIG_MATHEMU
671 .procname = "ieee_emulation_warnings",
672 .data = &sysctl_ieee_emulation_warnings,
673 .maxlen = sizeof(int),
675 .proc_handler = proc_dointvec,
679 .procname = "userprocess_debug",
680 .data = &show_unhandled_signals,
681 .maxlen = sizeof(int),
683 .proc_handler = proc_dointvec,
687 .procname = "pid_max",
689 .maxlen = sizeof (int),
691 .proc_handler = proc_dointvec_minmax,
692 .extra1 = &pid_max_min,
693 .extra2 = &pid_max_max,
696 .procname = "panic_on_oops",
697 .data = &panic_on_oops,
698 .maxlen = sizeof(int),
700 .proc_handler = proc_dointvec,
702 #if defined CONFIG_PRINTK
704 .procname = "printk",
705 .data = &console_loglevel,
706 .maxlen = 4*sizeof(int),
708 .proc_handler = proc_dointvec,
711 .procname = "printk_ratelimit",
712 .data = &printk_ratelimit_state.interval,
713 .maxlen = sizeof(int),
715 .proc_handler = proc_dointvec_jiffies,
718 .procname = "printk_ratelimit_burst",
719 .data = &printk_ratelimit_state.burst,
720 .maxlen = sizeof(int),
722 .proc_handler = proc_dointvec,
725 .procname = "printk_delay",
726 .data = &printk_delay_msec,
727 .maxlen = sizeof(int),
729 .proc_handler = proc_dointvec_minmax,
731 .extra2 = &ten_thousand,
734 .procname = "dmesg_restrict",
735 .data = &dmesg_restrict,
736 .maxlen = sizeof(int),
738 .proc_handler = proc_dointvec_minmax_sysadmin,
743 .procname = "kptr_restrict",
744 .data = &kptr_restrict,
745 .maxlen = sizeof(int),
747 .proc_handler = proc_dointvec_minmax_sysadmin,
753 .procname = "ngroups_max",
754 .data = &ngroups_max,
755 .maxlen = sizeof (int),
757 .proc_handler = proc_dointvec,
760 .procname = "cap_last_cap",
761 .data = (void *)&cap_last_cap,
762 .maxlen = sizeof(int),
764 .proc_handler = proc_dointvec,
766 #if defined(CONFIG_LOCKUP_DETECTOR)
768 .procname = "watchdog",
769 .data = &watchdog_enabled,
770 .maxlen = sizeof (int),
772 .proc_handler = proc_dowatchdog,
777 .procname = "watchdog_thresh",
778 .data = &watchdog_thresh,
779 .maxlen = sizeof(int),
781 .proc_handler = proc_dowatchdog,
786 .procname = "softlockup_panic",
787 .data = &softlockup_panic,
788 .maxlen = sizeof(int),
790 .proc_handler = proc_dointvec_minmax,
795 .procname = "nmi_watchdog",
796 .data = &watchdog_enabled,
797 .maxlen = sizeof (int),
799 .proc_handler = proc_dowatchdog,
804 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
806 .procname = "unknown_nmi_panic",
807 .data = &unknown_nmi_panic,
808 .maxlen = sizeof (int),
810 .proc_handler = proc_dointvec,
813 #if defined(CONFIG_X86)
815 .procname = "panic_on_unrecovered_nmi",
816 .data = &panic_on_unrecovered_nmi,
817 .maxlen = sizeof(int),
819 .proc_handler = proc_dointvec,
822 .procname = "panic_on_io_nmi",
823 .data = &panic_on_io_nmi,
824 .maxlen = sizeof(int),
826 .proc_handler = proc_dointvec,
828 #ifdef CONFIG_DEBUG_STACKOVERFLOW
830 .procname = "panic_on_stackoverflow",
831 .data = &sysctl_panic_on_stackoverflow,
832 .maxlen = sizeof(int),
834 .proc_handler = proc_dointvec,
838 .procname = "bootloader_type",
839 .data = &bootloader_type,
840 .maxlen = sizeof (int),
842 .proc_handler = proc_dointvec,
845 .procname = "bootloader_version",
846 .data = &bootloader_version,
847 .maxlen = sizeof (int),
849 .proc_handler = proc_dointvec,
852 .procname = "kstack_depth_to_print",
853 .data = &kstack_depth_to_print,
854 .maxlen = sizeof(int),
856 .proc_handler = proc_dointvec,
859 .procname = "io_delay_type",
860 .data = &io_delay_type,
861 .maxlen = sizeof(int),
863 .proc_handler = proc_dointvec,
866 #if defined(CONFIG_MMU)
868 .procname = "randomize_va_space",
869 .data = &randomize_va_space,
870 .maxlen = sizeof(int),
872 .proc_handler = proc_dointvec,
875 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
877 .procname = "spin_retry",
879 .maxlen = sizeof (int),
881 .proc_handler = proc_dointvec,
884 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
886 .procname = "acpi_video_flags",
887 .data = &acpi_realmode_flags,
888 .maxlen = sizeof (unsigned long),
890 .proc_handler = proc_doulongvec_minmax,
895 .procname = "ignore-unaligned-usertrap",
896 .data = &no_unaligned_warning,
897 .maxlen = sizeof (int),
899 .proc_handler = proc_dointvec,
902 .procname = "unaligned-dump-stack",
903 .data = &unaligned_dump_stack,
904 .maxlen = sizeof (int),
906 .proc_handler = proc_dointvec,
909 #ifdef CONFIG_DETECT_HUNG_TASK
911 .procname = "hung_task_panic",
912 .data = &sysctl_hung_task_panic,
913 .maxlen = sizeof(int),
915 .proc_handler = proc_dointvec_minmax,
920 .procname = "hung_task_check_count",
921 .data = &sysctl_hung_task_check_count,
922 .maxlen = sizeof(unsigned long),
924 .proc_handler = proc_doulongvec_minmax,
927 .procname = "hung_task_timeout_secs",
928 .data = &sysctl_hung_task_timeout_secs,
929 .maxlen = sizeof(unsigned long),
931 .proc_handler = proc_dohung_task_timeout_secs,
934 .procname = "hung_task_warnings",
935 .data = &sysctl_hung_task_warnings,
936 .maxlen = sizeof(unsigned long),
938 .proc_handler = proc_doulongvec_minmax,
943 .procname = "compat-log",
945 .maxlen = sizeof (int),
947 .proc_handler = proc_dointvec,
950 #ifdef CONFIG_RT_MUTEXES
952 .procname = "max_lock_depth",
953 .data = &max_lock_depth,
954 .maxlen = sizeof(int),
956 .proc_handler = proc_dointvec,
960 .procname = "poweroff_cmd",
961 .data = &poweroff_cmd,
962 .maxlen = POWEROFF_CMD_PATH_LEN,
964 .proc_handler = proc_dostring,
970 .child = key_sysctls,
973 #ifdef CONFIG_RCU_TORTURE_TEST
975 .procname = "rcutorture_runnable",
976 .data = &rcutorture_runnable,
977 .maxlen = sizeof(int),
979 .proc_handler = proc_dointvec,
982 #ifdef CONFIG_PERF_EVENTS
984 * User-space scripts rely on the existence of this file
985 * as a feature check for perf_events being enabled.
987 * So it's an ABI, do not remove!
990 .procname = "perf_event_paranoid",
991 .data = &sysctl_perf_event_paranoid,
992 .maxlen = sizeof(sysctl_perf_event_paranoid),
994 .proc_handler = proc_dointvec,
997 .procname = "perf_event_mlock_kb",
998 .data = &sysctl_perf_event_mlock,
999 .maxlen = sizeof(sysctl_perf_event_mlock),
1001 .proc_handler = proc_dointvec,
1004 .procname = "perf_event_max_sample_rate",
1005 .data = &sysctl_perf_event_sample_rate,
1006 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1008 .proc_handler = perf_proc_update_handler,
1011 #ifdef CONFIG_KMEMCHECK
1013 .procname = "kmemcheck",
1014 .data = &kmemcheck_enabled,
1015 .maxlen = sizeof(int),
1017 .proc_handler = proc_dointvec,
1022 .procname = "blk_iopoll",
1023 .data = &blk_iopoll_enabled,
1024 .maxlen = sizeof(int),
1026 .proc_handler = proc_dointvec,
1032 static struct ctl_table vm_table[] = {
1034 .procname = "overcommit_memory",
1035 .data = &sysctl_overcommit_memory,
1036 .maxlen = sizeof(sysctl_overcommit_memory),
1038 .proc_handler = proc_dointvec_minmax,
1043 .procname = "panic_on_oom",
1044 .data = &sysctl_panic_on_oom,
1045 .maxlen = sizeof(sysctl_panic_on_oom),
1047 .proc_handler = proc_dointvec_minmax,
1052 .procname = "oom_kill_allocating_task",
1053 .data = &sysctl_oom_kill_allocating_task,
1054 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1056 .proc_handler = proc_dointvec,
1059 .procname = "oom_dump_tasks",
1060 .data = &sysctl_oom_dump_tasks,
1061 .maxlen = sizeof(sysctl_oom_dump_tasks),
1063 .proc_handler = proc_dointvec,
1066 .procname = "overcommit_ratio",
1067 .data = &sysctl_overcommit_ratio,
1068 .maxlen = sizeof(sysctl_overcommit_ratio),
1070 .proc_handler = proc_dointvec,
1073 .procname = "page-cluster",
1074 .data = &page_cluster,
1075 .maxlen = sizeof(int),
1077 .proc_handler = proc_dointvec_minmax,
1081 .procname = "dirty_background_ratio",
1082 .data = &dirty_background_ratio,
1083 .maxlen = sizeof(dirty_background_ratio),
1085 .proc_handler = dirty_background_ratio_handler,
1087 .extra2 = &one_hundred,
1090 .procname = "dirty_background_bytes",
1091 .data = &dirty_background_bytes,
1092 .maxlen = sizeof(dirty_background_bytes),
1094 .proc_handler = dirty_background_bytes_handler,
1098 .procname = "dirty_ratio",
1099 .data = &vm_dirty_ratio,
1100 .maxlen = sizeof(vm_dirty_ratio),
1102 .proc_handler = dirty_ratio_handler,
1104 .extra2 = &one_hundred,
1107 .procname = "dirty_bytes",
1108 .data = &vm_dirty_bytes,
1109 .maxlen = sizeof(vm_dirty_bytes),
1111 .proc_handler = dirty_bytes_handler,
1112 .extra1 = &dirty_bytes_min,
1115 .procname = "dirty_writeback_centisecs",
1116 .data = &dirty_writeback_interval,
1117 .maxlen = sizeof(dirty_writeback_interval),
1119 .proc_handler = dirty_writeback_centisecs_handler,
1122 .procname = "dirty_expire_centisecs",
1123 .data = &dirty_expire_interval,
1124 .maxlen = sizeof(dirty_expire_interval),
1126 .proc_handler = proc_dointvec_minmax,
1130 .procname = "nr_pdflush_threads",
1131 .mode = 0444 /* read-only */,
1132 .proc_handler = pdflush_proc_obsolete,
1135 .procname = "swappiness",
1136 .data = &vm_swappiness,
1137 .maxlen = sizeof(vm_swappiness),
1139 .proc_handler = proc_dointvec_minmax,
1141 .extra2 = &one_hundred,
1143 #ifdef CONFIG_HUGETLB_PAGE
1145 .procname = "nr_hugepages",
1147 .maxlen = sizeof(unsigned long),
1149 .proc_handler = hugetlb_sysctl_handler,
1150 .extra1 = (void *)&hugetlb_zero,
1151 .extra2 = (void *)&hugetlb_infinity,
1155 .procname = "nr_hugepages_mempolicy",
1157 .maxlen = sizeof(unsigned long),
1159 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1160 .extra1 = (void *)&hugetlb_zero,
1161 .extra2 = (void *)&hugetlb_infinity,
1165 .procname = "hugetlb_shm_group",
1166 .data = &sysctl_hugetlb_shm_group,
1167 .maxlen = sizeof(gid_t),
1169 .proc_handler = proc_dointvec,
1172 .procname = "hugepages_treat_as_movable",
1173 .data = &hugepages_treat_as_movable,
1174 .maxlen = sizeof(int),
1176 .proc_handler = hugetlb_treat_movable_handler,
1179 .procname = "nr_overcommit_hugepages",
1181 .maxlen = sizeof(unsigned long),
1183 .proc_handler = hugetlb_overcommit_handler,
1184 .extra1 = (void *)&hugetlb_zero,
1185 .extra2 = (void *)&hugetlb_infinity,
1189 .procname = "lowmem_reserve_ratio",
1190 .data = &sysctl_lowmem_reserve_ratio,
1191 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1193 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1196 .procname = "drop_caches",
1197 .data = &sysctl_drop_caches,
1198 .maxlen = sizeof(int),
1200 .proc_handler = drop_caches_sysctl_handler,
1204 #ifdef CONFIG_COMPACTION
1206 .procname = "compact_memory",
1207 .data = &sysctl_compact_memory,
1208 .maxlen = sizeof(int),
1210 .proc_handler = sysctl_compaction_handler,
1213 .procname = "extfrag_threshold",
1214 .data = &sysctl_extfrag_threshold,
1215 .maxlen = sizeof(int),
1217 .proc_handler = sysctl_extfrag_handler,
1218 .extra1 = &min_extfrag_threshold,
1219 .extra2 = &max_extfrag_threshold,
1222 #endif /* CONFIG_COMPACTION */
1224 .procname = "min_free_kbytes",
1225 .data = &min_free_kbytes,
1226 .maxlen = sizeof(min_free_kbytes),
1228 .proc_handler = min_free_kbytes_sysctl_handler,
1232 .procname = "percpu_pagelist_fraction",
1233 .data = &percpu_pagelist_fraction,
1234 .maxlen = sizeof(percpu_pagelist_fraction),
1236 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1237 .extra1 = &min_percpu_pagelist_fract,
1241 .procname = "max_map_count",
1242 .data = &sysctl_max_map_count,
1243 .maxlen = sizeof(sysctl_max_map_count),
1245 .proc_handler = proc_dointvec_minmax,
1250 .procname = "nr_trim_pages",
1251 .data = &sysctl_nr_trim_pages,
1252 .maxlen = sizeof(sysctl_nr_trim_pages),
1254 .proc_handler = proc_dointvec_minmax,
1259 .procname = "laptop_mode",
1260 .data = &laptop_mode,
1261 .maxlen = sizeof(laptop_mode),
1263 .proc_handler = proc_dointvec_jiffies,
1266 .procname = "block_dump",
1267 .data = &block_dump,
1268 .maxlen = sizeof(block_dump),
1270 .proc_handler = proc_dointvec,
1274 .procname = "vfs_cache_pressure",
1275 .data = &sysctl_vfs_cache_pressure,
1276 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1278 .proc_handler = proc_dointvec,
1281 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1283 .procname = "legacy_va_layout",
1284 .data = &sysctl_legacy_va_layout,
1285 .maxlen = sizeof(sysctl_legacy_va_layout),
1287 .proc_handler = proc_dointvec,
1293 .procname = "zone_reclaim_mode",
1294 .data = &zone_reclaim_mode,
1295 .maxlen = sizeof(zone_reclaim_mode),
1297 .proc_handler = proc_dointvec,
1301 .procname = "min_unmapped_ratio",
1302 .data = &sysctl_min_unmapped_ratio,
1303 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1305 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1307 .extra2 = &one_hundred,
1310 .procname = "min_slab_ratio",
1311 .data = &sysctl_min_slab_ratio,
1312 .maxlen = sizeof(sysctl_min_slab_ratio),
1314 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1316 .extra2 = &one_hundred,
1321 .procname = "stat_interval",
1322 .data = &sysctl_stat_interval,
1323 .maxlen = sizeof(sysctl_stat_interval),
1325 .proc_handler = proc_dointvec_jiffies,
1330 .procname = "mmap_min_addr",
1331 .data = &dac_mmap_min_addr,
1332 .maxlen = sizeof(unsigned long),
1334 .proc_handler = mmap_min_addr_handler,
1339 .procname = "numa_zonelist_order",
1340 .data = &numa_zonelist_order,
1341 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1343 .proc_handler = numa_zonelist_order_handler,
1346 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1347 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1349 .procname = "vdso_enabled",
1350 .data = &vdso_enabled,
1351 .maxlen = sizeof(vdso_enabled),
1353 .proc_handler = proc_dointvec,
1357 #ifdef CONFIG_HIGHMEM
1359 .procname = "highmem_is_dirtyable",
1360 .data = &vm_highmem_is_dirtyable,
1361 .maxlen = sizeof(vm_highmem_is_dirtyable),
1363 .proc_handler = proc_dointvec_minmax,
1369 .procname = "scan_unevictable_pages",
1370 .data = &scan_unevictable_pages,
1371 .maxlen = sizeof(scan_unevictable_pages),
1373 .proc_handler = scan_unevictable_handler,
1375 #ifdef CONFIG_MEMORY_FAILURE
1377 .procname = "memory_failure_early_kill",
1378 .data = &sysctl_memory_failure_early_kill,
1379 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1381 .proc_handler = proc_dointvec_minmax,
1386 .procname = "memory_failure_recovery",
1387 .data = &sysctl_memory_failure_recovery,
1388 .maxlen = sizeof(sysctl_memory_failure_recovery),
1390 .proc_handler = proc_dointvec_minmax,
1398 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1399 static struct ctl_table binfmt_misc_table[] = {
1404 static struct ctl_table fs_table[] = {
1406 .procname = "inode-nr",
1407 .data = &inodes_stat,
1408 .maxlen = 2*sizeof(int),
1410 .proc_handler = proc_nr_inodes,
1413 .procname = "inode-state",
1414 .data = &inodes_stat,
1415 .maxlen = 7*sizeof(int),
1417 .proc_handler = proc_nr_inodes,
1420 .procname = "file-nr",
1421 .data = &files_stat,
1422 .maxlen = sizeof(files_stat),
1424 .proc_handler = proc_nr_files,
1427 .procname = "file-max",
1428 .data = &files_stat.max_files,
1429 .maxlen = sizeof(files_stat.max_files),
1431 .proc_handler = proc_doulongvec_minmax,
1434 .procname = "nr_open",
1435 .data = &sysctl_nr_open,
1436 .maxlen = sizeof(int),
1438 .proc_handler = proc_dointvec_minmax,
1439 .extra1 = &sysctl_nr_open_min,
1440 .extra2 = &sysctl_nr_open_max,
1443 .procname = "dentry-state",
1444 .data = &dentry_stat,
1445 .maxlen = 6*sizeof(int),
1447 .proc_handler = proc_nr_dentry,
1450 .procname = "overflowuid",
1451 .data = &fs_overflowuid,
1452 .maxlen = sizeof(int),
1454 .proc_handler = proc_dointvec_minmax,
1455 .extra1 = &minolduid,
1456 .extra2 = &maxolduid,
1459 .procname = "overflowgid",
1460 .data = &fs_overflowgid,
1461 .maxlen = sizeof(int),
1463 .proc_handler = proc_dointvec_minmax,
1464 .extra1 = &minolduid,
1465 .extra2 = &maxolduid,
1467 #ifdef CONFIG_FILE_LOCKING
1469 .procname = "leases-enable",
1470 .data = &leases_enable,
1471 .maxlen = sizeof(int),
1473 .proc_handler = proc_dointvec,
1476 #ifdef CONFIG_DNOTIFY
1478 .procname = "dir-notify-enable",
1479 .data = &dir_notify_enable,
1480 .maxlen = sizeof(int),
1482 .proc_handler = proc_dointvec,
1486 #ifdef CONFIG_FILE_LOCKING
1488 .procname = "lease-break-time",
1489 .data = &lease_break_time,
1490 .maxlen = sizeof(int),
1492 .proc_handler = proc_dointvec,
1497 .procname = "aio-nr",
1499 .maxlen = sizeof(aio_nr),
1501 .proc_handler = proc_doulongvec_minmax,
1504 .procname = "aio-max-nr",
1505 .data = &aio_max_nr,
1506 .maxlen = sizeof(aio_max_nr),
1508 .proc_handler = proc_doulongvec_minmax,
1510 #endif /* CONFIG_AIO */
1511 #ifdef CONFIG_INOTIFY_USER
1513 .procname = "inotify",
1515 .child = inotify_table,
1520 .procname = "epoll",
1522 .child = epoll_table,
1527 .procname = "protected_symlinks",
1528 .data = &sysctl_protected_symlinks,
1529 .maxlen = sizeof(int),
1531 .proc_handler = proc_dointvec_minmax,
1536 .procname = "protected_hardlinks",
1537 .data = &sysctl_protected_hardlinks,
1538 .maxlen = sizeof(int),
1540 .proc_handler = proc_dointvec_minmax,
1545 .procname = "suid_dumpable",
1546 .data = &suid_dumpable,
1547 .maxlen = sizeof(int),
1549 .proc_handler = proc_dointvec_minmax_coredump,
1553 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1555 .procname = "binfmt_misc",
1557 .child = binfmt_misc_table,
1561 .procname = "pipe-max-size",
1562 .data = &pipe_max_size,
1563 .maxlen = sizeof(int),
1565 .proc_handler = &pipe_proc_fn,
1566 .extra1 = &pipe_min_size,
1571 static struct ctl_table debug_table[] = {
1572 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1574 .procname = "exception-trace",
1575 .data = &show_unhandled_signals,
1576 .maxlen = sizeof(int),
1578 .proc_handler = proc_dointvec
1581 #if defined(CONFIG_OPTPROBES)
1583 .procname = "kprobes-optimization",
1584 .data = &sysctl_kprobes_optimization,
1585 .maxlen = sizeof(int),
1587 .proc_handler = proc_kprobes_optimization_handler,
1595 static struct ctl_table dev_table[] = {
1599 int __init sysctl_init(void)
1601 struct ctl_table_header *hdr;
1603 hdr = register_sysctl_table(sysctl_base_table);
1604 kmemleak_not_leak(hdr);
1608 #endif /* CONFIG_SYSCTL */
1614 #ifdef CONFIG_PROC_SYSCTL
1616 static int _proc_do_string(void* data, int maxlen, int write,
1617 void __user *buffer,
1618 size_t *lenp, loff_t *ppos)
1624 if (!data || !maxlen || !*lenp) {
1632 while (len < *lenp) {
1633 if (get_user(c, p++))
1635 if (c == 0 || c == '\n')
1641 if(copy_from_user(data, buffer, len))
1643 ((char *) data)[len] = 0;
1661 if(copy_to_user(buffer, data, len))
1664 if(put_user('\n', ((char __user *) buffer) + len))
1675 * proc_dostring - read a string sysctl
1676 * @table: the sysctl table
1677 * @write: %TRUE if this is a write to the sysctl file
1678 * @buffer: the user buffer
1679 * @lenp: the size of the user buffer
1680 * @ppos: file position
1682 * Reads/writes a string from/to the user buffer. If the kernel
1683 * buffer provided is not large enough to hold the string, the
1684 * string is truncated. The copied string is %NULL-terminated.
1685 * If the string is being read by the user process, it is copied
1686 * and a newline '\n' is added. It is truncated if the buffer is
1689 * Returns 0 on success.
1691 int proc_dostring(struct ctl_table *table, int write,
1692 void __user *buffer, size_t *lenp, loff_t *ppos)
1694 return _proc_do_string(table->data, table->maxlen, write,
1695 buffer, lenp, ppos);
1698 static size_t proc_skip_spaces(char **buf)
1701 char *tmp = skip_spaces(*buf);
1707 static void proc_skip_char(char **buf, size_t *size, const char v)
1717 #define TMPBUFLEN 22
1719 * proc_get_long - reads an ASCII formatted integer from a user buffer
1721 * @buf: a kernel buffer
1722 * @size: size of the kernel buffer
1723 * @val: this is where the number will be stored
1724 * @neg: set to %TRUE if number is negative
1725 * @perm_tr: a vector which contains the allowed trailers
1726 * @perm_tr_len: size of the perm_tr vector
1727 * @tr: pointer to store the trailer character
1729 * In case of success %0 is returned and @buf and @size are updated with
1730 * the amount of bytes read. If @tr is non-NULL and a trailing
1731 * character exists (size is non-zero after returning from this
1732 * function), @tr is updated with the trailing character.
1734 static int proc_get_long(char **buf, size_t *size,
1735 unsigned long *val, bool *neg,
1736 const char *perm_tr, unsigned perm_tr_len, char *tr)
1739 char *p, tmp[TMPBUFLEN];
1745 if (len > TMPBUFLEN - 1)
1746 len = TMPBUFLEN - 1;
1748 memcpy(tmp, *buf, len);
1752 if (*p == '-' && *size > 1) {
1760 *val = simple_strtoul(p, &p, 0);
1764 /* We don't know if the next char is whitespace thus we may accept
1765 * invalid integers (e.g. 1234...a) or two integers instead of one
1766 * (e.g. 123...1). So lets not allow such large numbers. */
1767 if (len == TMPBUFLEN - 1)
1770 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1773 if (tr && (len < *size))
1783 * proc_put_long - converts an integer to a decimal ASCII formatted string
1785 * @buf: the user buffer
1786 * @size: the size of the user buffer
1787 * @val: the integer to be converted
1788 * @neg: sign of the number, %TRUE for negative
1790 * In case of success %0 is returned and @buf and @size are updated with
1791 * the amount of bytes written.
1793 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1797 char tmp[TMPBUFLEN], *p = tmp;
1799 sprintf(p, "%s%lu", neg ? "-" : "", val);
1803 if (copy_to_user(*buf, tmp, len))
1811 static int proc_put_char(void __user **buf, size_t *size, char c)
1814 char __user **buffer = (char __user **)buf;
1815 if (put_user(c, *buffer))
1817 (*size)--, (*buffer)++;
1823 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1825 int write, void *data)
1828 *valp = *negp ? -*lvalp : *lvalp;
1833 *lvalp = (unsigned long)-val;
1836 *lvalp = (unsigned long)val;
1842 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1844 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1845 int write, void __user *buffer,
1846 size_t *lenp, loff_t *ppos,
1847 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1848 int write, void *data),
1851 int *i, vleft, first = 1, err = 0;
1852 unsigned long page = 0;
1856 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1861 i = (int *) tbl_data;
1862 vleft = table->maxlen / sizeof(*i);
1866 conv = do_proc_dointvec_conv;
1869 if (left > PAGE_SIZE - 1)
1870 left = PAGE_SIZE - 1;
1871 page = __get_free_page(GFP_TEMPORARY);
1872 kbuf = (char *) page;
1875 if (copy_from_user(kbuf, buffer, left)) {
1882 for (; left && vleft--; i++, first=0) {
1887 left -= proc_skip_spaces(&kbuf);
1891 err = proc_get_long(&kbuf, &left, &lval, &neg,
1893 sizeof(proc_wspace_sep), NULL);
1896 if (conv(&neg, &lval, i, 1, data)) {
1901 if (conv(&neg, &lval, i, 0, data)) {
1906 err = proc_put_char(&buffer, &left, '\t');
1909 err = proc_put_long(&buffer, &left, lval, neg);
1915 if (!write && !first && left && !err)
1916 err = proc_put_char(&buffer, &left, '\n');
1917 if (write && !err && left)
1918 left -= proc_skip_spaces(&kbuf);
1923 return err ? : -EINVAL;
1930 static int do_proc_dointvec(struct ctl_table *table, int write,
1931 void __user *buffer, size_t *lenp, loff_t *ppos,
1932 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1933 int write, void *data),
1936 return __do_proc_dointvec(table->data, table, write,
1937 buffer, lenp, ppos, conv, data);
1941 * proc_dointvec - read a vector of integers
1942 * @table: the sysctl table
1943 * @write: %TRUE if this is a write to the sysctl file
1944 * @buffer: the user buffer
1945 * @lenp: the size of the user buffer
1946 * @ppos: file position
1948 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1949 * values from/to the user buffer, treated as an ASCII string.
1951 * Returns 0 on success.
1953 int proc_dointvec(struct ctl_table *table, int write,
1954 void __user *buffer, size_t *lenp, loff_t *ppos)
1956 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1961 * Taint values can only be increased
1962 * This means we can safely use a temporary.
1964 static int proc_taint(struct ctl_table *table, int write,
1965 void __user *buffer, size_t *lenp, loff_t *ppos)
1968 unsigned long tmptaint = get_taint();
1971 if (write && !capable(CAP_SYS_ADMIN))
1976 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
1982 * Poor man's atomic or. Not worth adding a primitive
1983 * to everyone's atomic.h for this
1986 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
1987 if ((tmptaint >> i) & 1)
1995 #ifdef CONFIG_PRINTK
1996 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
1997 void __user *buffer, size_t *lenp, loff_t *ppos)
1999 if (write && !capable(CAP_SYS_ADMIN))
2002 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2006 struct do_proc_dointvec_minmax_conv_param {
2011 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2013 int write, void *data)
2015 struct do_proc_dointvec_minmax_conv_param *param = data;
2017 int val = *negp ? -*lvalp : *lvalp;
2018 if ((param->min && *param->min > val) ||
2019 (param->max && *param->max < val))
2026 *lvalp = (unsigned long)-val;
2029 *lvalp = (unsigned long)val;
2036 * proc_dointvec_minmax - read a vector of integers with min/max values
2037 * @table: the sysctl table
2038 * @write: %TRUE if this is a write to the sysctl file
2039 * @buffer: the user buffer
2040 * @lenp: the size of the user buffer
2041 * @ppos: file position
2043 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2044 * values from/to the user buffer, treated as an ASCII string.
2046 * This routine will ensure the values are within the range specified by
2047 * table->extra1 (min) and table->extra2 (max).
2049 * Returns 0 on success.
2051 int proc_dointvec_minmax(struct ctl_table *table, int write,
2052 void __user *buffer, size_t *lenp, loff_t *ppos)
2054 struct do_proc_dointvec_minmax_conv_param param = {
2055 .min = (int *) table->extra1,
2056 .max = (int *) table->extra2,
2058 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2059 do_proc_dointvec_minmax_conv, ¶m);
2062 static void validate_coredump_safety(void)
2064 #ifdef CONFIG_COREDUMP
2065 if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2066 core_pattern[0] != '/' && core_pattern[0] != '|') {
2067 printk(KERN_WARNING "Unsafe core_pattern used with "\
2068 "suid_dumpable=2. Pipe handler or fully qualified "\
2069 "core dump path required.\n");
2074 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2075 void __user *buffer, size_t *lenp, loff_t *ppos)
2077 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2079 validate_coredump_safety();
2083 #ifdef CONFIG_COREDUMP
2084 static int proc_dostring_coredump(struct ctl_table *table, int write,
2085 void __user *buffer, size_t *lenp, loff_t *ppos)
2087 int error = proc_dostring(table, write, buffer, lenp, ppos);
2089 validate_coredump_safety();
2094 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2095 void __user *buffer,
2096 size_t *lenp, loff_t *ppos,
2097 unsigned long convmul,
2098 unsigned long convdiv)
2100 unsigned long *i, *min, *max;
2101 int vleft, first = 1, err = 0;
2102 unsigned long page = 0;
2106 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2111 i = (unsigned long *) data;
2112 min = (unsigned long *) table->extra1;
2113 max = (unsigned long *) table->extra2;
2114 vleft = table->maxlen / sizeof(unsigned long);
2118 if (left > PAGE_SIZE - 1)
2119 left = PAGE_SIZE - 1;
2120 page = __get_free_page(GFP_TEMPORARY);
2121 kbuf = (char *) page;
2124 if (copy_from_user(kbuf, buffer, left)) {
2131 for (; left && vleft--; i++, first = 0) {
2137 left -= proc_skip_spaces(&kbuf);
2139 err = proc_get_long(&kbuf, &left, &val, &neg,
2141 sizeof(proc_wspace_sep), NULL);
2146 if ((min && val < *min) || (max && val > *max))
2150 val = convdiv * (*i) / convmul;
2152 err = proc_put_char(&buffer, &left, '\t');
2153 err = proc_put_long(&buffer, &left, val, false);
2159 if (!write && !first && left && !err)
2160 err = proc_put_char(&buffer, &left, '\n');
2162 left -= proc_skip_spaces(&kbuf);
2167 return err ? : -EINVAL;
2174 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2175 void __user *buffer,
2176 size_t *lenp, loff_t *ppos,
2177 unsigned long convmul,
2178 unsigned long convdiv)
2180 return __do_proc_doulongvec_minmax(table->data, table, write,
2181 buffer, lenp, ppos, convmul, convdiv);
2185 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2186 * @table: the sysctl table
2187 * @write: %TRUE if this is a write to the sysctl file
2188 * @buffer: the user buffer
2189 * @lenp: the size of the user buffer
2190 * @ppos: file position
2192 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2193 * values from/to the user buffer, treated as an ASCII string.
2195 * This routine will ensure the values are within the range specified by
2196 * table->extra1 (min) and table->extra2 (max).
2198 * Returns 0 on success.
2200 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2201 void __user *buffer, size_t *lenp, loff_t *ppos)
2203 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2207 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2208 * @table: the sysctl table
2209 * @write: %TRUE if this is a write to the sysctl file
2210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2214 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2215 * values from/to the user buffer, treated as an ASCII string. The values
2216 * are treated as milliseconds, and converted to jiffies when they are stored.
2218 * This routine will ensure the values are within the range specified by
2219 * table->extra1 (min) and table->extra2 (max).
2221 * Returns 0 on success.
2223 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2224 void __user *buffer,
2225 size_t *lenp, loff_t *ppos)
2227 return do_proc_doulongvec_minmax(table, write, buffer,
2228 lenp, ppos, HZ, 1000l);
2232 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2234 int write, void *data)
2237 if (*lvalp > LONG_MAX / HZ)
2239 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2245 lval = (unsigned long)-val;
2248 lval = (unsigned long)val;
2255 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2257 int write, void *data)
2260 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2262 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2268 lval = (unsigned long)-val;
2271 lval = (unsigned long)val;
2273 *lvalp = jiffies_to_clock_t(lval);
2278 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2280 int write, void *data)
2283 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2289 lval = (unsigned long)-val;
2292 lval = (unsigned long)val;
2294 *lvalp = jiffies_to_msecs(lval);
2300 * proc_dointvec_jiffies - read a vector of integers as seconds
2301 * @table: the sysctl table
2302 * @write: %TRUE if this is a write to the sysctl file
2303 * @buffer: the user buffer
2304 * @lenp: the size of the user buffer
2305 * @ppos: file position
2307 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2308 * values from/to the user buffer, treated as an ASCII string.
2309 * The values read are assumed to be in seconds, and are converted into
2312 * Returns 0 on success.
2314 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2315 void __user *buffer, size_t *lenp, loff_t *ppos)
2317 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2318 do_proc_dointvec_jiffies_conv,NULL);
2322 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2323 * @table: the sysctl table
2324 * @write: %TRUE if this is a write to the sysctl file
2325 * @buffer: the user buffer
2326 * @lenp: the size of the user buffer
2327 * @ppos: pointer to the file position
2329 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2330 * values from/to the user buffer, treated as an ASCII string.
2331 * The values read are assumed to be in 1/USER_HZ seconds, and
2332 * are converted into jiffies.
2334 * Returns 0 on success.
2336 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2337 void __user *buffer, size_t *lenp, loff_t *ppos)
2339 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2340 do_proc_dointvec_userhz_jiffies_conv,NULL);
2344 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2345 * @table: the sysctl table
2346 * @write: %TRUE if this is a write to the sysctl file
2347 * @buffer: the user buffer
2348 * @lenp: the size of the user buffer
2349 * @ppos: file position
2350 * @ppos: the current position in the file
2352 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2353 * values from/to the user buffer, treated as an ASCII string.
2354 * The values read are assumed to be in 1/1000 seconds, and
2355 * are converted into jiffies.
2357 * Returns 0 on success.
2359 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2360 void __user *buffer, size_t *lenp, loff_t *ppos)
2362 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2363 do_proc_dointvec_ms_jiffies_conv, NULL);
2366 static int proc_do_cad_pid(struct ctl_table *table, int write,
2367 void __user *buffer, size_t *lenp, loff_t *ppos)
2369 struct pid *new_pid;
2373 tmp = pid_vnr(cad_pid);
2375 r = __do_proc_dointvec(&tmp, table, write, buffer,
2376 lenp, ppos, NULL, NULL);
2380 new_pid = find_get_pid(tmp);
2384 put_pid(xchg(&cad_pid, new_pid));
2389 * proc_do_large_bitmap - read/write from/to a large bitmap
2390 * @table: the sysctl table
2391 * @write: %TRUE if this is a write to the sysctl file
2392 * @buffer: the user buffer
2393 * @lenp: the size of the user buffer
2394 * @ppos: file position
2396 * The bitmap is stored at table->data and the bitmap length (in bits)
2399 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2400 * large bitmaps may be represented in a compact manner. Writing into
2401 * the file will clear the bitmap then update it with the given input.
2403 * Returns 0 on success.
2405 int proc_do_large_bitmap(struct ctl_table *table, int write,
2406 void __user *buffer, size_t *lenp, loff_t *ppos)
2410 size_t left = *lenp;
2411 unsigned long bitmap_len = table->maxlen;
2412 unsigned long *bitmap = (unsigned long *) table->data;
2413 unsigned long *tmp_bitmap = NULL;
2414 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2416 if (!bitmap_len || !left || (*ppos && !write)) {
2422 unsigned long page = 0;
2425 if (left > PAGE_SIZE - 1)
2426 left = PAGE_SIZE - 1;
2428 page = __get_free_page(GFP_TEMPORARY);
2429 kbuf = (char *) page;
2432 if (copy_from_user(kbuf, buffer, left)) {
2438 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2444 proc_skip_char(&kbuf, &left, '\n');
2445 while (!err && left) {
2446 unsigned long val_a, val_b;
2449 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2453 if (val_a >= bitmap_len || neg) {
2465 err = proc_get_long(&kbuf, &left, &val_b,
2466 &neg, tr_b, sizeof(tr_b),
2470 if (val_b >= bitmap_len || neg ||
2481 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2483 proc_skip_char(&kbuf, &left, '\n');
2487 unsigned long bit_a, bit_b = 0;
2490 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2491 if (bit_a >= bitmap_len)
2493 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2497 err = proc_put_char(&buffer, &left, ',');
2501 err = proc_put_long(&buffer, &left, bit_a, false);
2504 if (bit_a != bit_b) {
2505 err = proc_put_char(&buffer, &left, '-');
2508 err = proc_put_long(&buffer, &left, bit_b, false);
2516 err = proc_put_char(&buffer, &left, '\n');
2522 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2524 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2536 #else /* CONFIG_PROC_SYSCTL */
2538 int proc_dostring(struct ctl_table *table, int write,
2539 void __user *buffer, size_t *lenp, loff_t *ppos)
2544 int proc_dointvec(struct ctl_table *table, int write,
2545 void __user *buffer, size_t *lenp, loff_t *ppos)
2550 int proc_dointvec_minmax(struct ctl_table *table, int write,
2551 void __user *buffer, size_t *lenp, loff_t *ppos)
2556 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2557 void __user *buffer, size_t *lenp, loff_t *ppos)
2562 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2563 void __user *buffer, size_t *lenp, loff_t *ppos)
2568 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2569 void __user *buffer, size_t *lenp, loff_t *ppos)
2574 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2575 void __user *buffer, size_t *lenp, loff_t *ppos)
2580 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2581 void __user *buffer,
2582 size_t *lenp, loff_t *ppos)
2588 #endif /* CONFIG_PROC_SYSCTL */
2591 * No sense putting this after each symbol definition, twice,
2592 * exception granted :-)
2594 EXPORT_SYMBOL(proc_dointvec);
2595 EXPORT_SYMBOL(proc_dointvec_jiffies);
2596 EXPORT_SYMBOL(proc_dointvec_minmax);
2597 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2598 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2599 EXPORT_SYMBOL(proc_dostring);
2600 EXPORT_SYMBOL(proc_doulongvec_minmax);
2601 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);