[SCSI] lpfc 8.3.35: Fixed not checking solicition in progress bit when verifying...
[linux-2.6.git] / kernel / sysctl.c
blob84c76a34e41c7a01f3464506c5352cf00cf1f8ca
1 /*
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
12 * Horn.
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
16 * Wendling.
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>
22 #include <linux/mm.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>
34 #include <linux/fs.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>
68 #ifdef CONFIG_X86
69 #include <asm/nmi.h>
70 #include <asm/stacktrace.h>
71 #include <asm/io.h>
72 #endif
73 #ifdef CONFIG_SPARC
74 #include <asm/setup.h>
75 #endif
76 #ifdef CONFIG_BSD_PROCESS_ACCT
77 #include <linux/acct.h>
78 #endif
79 #ifdef CONFIG_RT_MUTEXES
80 #include <linux/rtmutex.h>
81 #endif
82 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
83 #include <linux/lockdep.h>
84 #endif
85 #ifdef CONFIG_CHR_DEV_SG
86 #include <scsi/sg.h>
87 #endif
89 #ifdef CONFIG_LOCKUP_DETECTOR
90 #include <linux/nmi.h>
91 #endif
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 core_uses_pid;
101 extern int suid_dumpable;
102 extern char core_pattern[];
103 extern unsigned int core_pipe_limit;
104 extern int pid_max;
105 extern int min_free_kbytes;
106 extern int pid_max_min, pid_max_max;
107 extern int sysctl_drop_caches;
108 extern int percpu_pagelist_fraction;
109 extern int compat_log;
110 extern int latencytop_enabled;
111 extern int sysctl_nr_open_min, sysctl_nr_open_max;
112 #ifndef CONFIG_MMU
113 extern int sysctl_nr_trim_pages;
114 #endif
115 #ifdef CONFIG_BLOCK
116 extern int blk_iopoll_enabled;
117 #endif
119 /* Constants used for minimum and maximum */
120 #ifdef CONFIG_LOCKUP_DETECTOR
121 static int sixty = 60;
122 static int neg_one = -1;
123 #endif
125 static int zero;
126 static int __maybe_unused one = 1;
127 static int __maybe_unused two = 2;
128 static int __maybe_unused three = 3;
129 static unsigned long one_ul = 1;
130 static int one_hundred = 100;
131 #ifdef CONFIG_PRINTK
132 static int ten_thousand = 10000;
133 #endif
135 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
136 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
138 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
139 static int maxolduid = 65535;
140 static int minolduid;
141 static int min_percpu_pagelist_fract = 8;
143 static int ngroups_max = NGROUPS_MAX;
144 static const int cap_last_cap = CAP_LAST_CAP;
146 #ifdef CONFIG_INOTIFY_USER
147 #include <linux/inotify.h>
148 #endif
149 #ifdef CONFIG_SPARC
150 #endif
152 #ifdef CONFIG_SPARC64
153 extern int sysctl_tsb_ratio;
154 #endif
156 #ifdef __hppa__
157 extern int pwrsw_enabled;
158 extern int unaligned_enabled;
159 #endif
161 #ifdef CONFIG_IA64
162 extern int no_unaligned_warning;
163 extern int unaligned_dump_stack;
164 #endif
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
169 static int proc_taint(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171 #endif
173 #ifdef CONFIG_PRINTK
174 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
175 void __user *buffer, size_t *lenp, loff_t *ppos);
176 #endif
178 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
179 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_dostring_coredump(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
183 #ifdef CONFIG_MAGIC_SYSRQ
184 /* Note: sysrq code uses it's own private copy */
185 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
187 static int sysrq_sysctl_handler(ctl_table *table, int write,
188 void __user *buffer, size_t *lenp,
189 loff_t *ppos)
191 int error;
193 error = proc_dointvec(table, write, buffer, lenp, ppos);
194 if (error)
195 return error;
197 if (write)
198 sysrq_toggle_support(__sysrq_enabled);
200 return 0;
203 #endif
205 static struct ctl_table kern_table[];
206 static struct ctl_table vm_table[];
207 static struct ctl_table fs_table[];
208 static struct ctl_table debug_table[];
209 static struct ctl_table dev_table[];
210 extern struct ctl_table random_table[];
211 #ifdef CONFIG_EPOLL
212 extern struct ctl_table epoll_table[];
213 #endif
215 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
216 int sysctl_legacy_va_layout;
217 #endif
219 /* The default sysctl tables: */
221 static struct ctl_table sysctl_base_table[] = {
223 .procname = "kernel",
224 .mode = 0555,
225 .child = kern_table,
228 .procname = "vm",
229 .mode = 0555,
230 .child = vm_table,
233 .procname = "fs",
234 .mode = 0555,
235 .child = fs_table,
238 .procname = "debug",
239 .mode = 0555,
240 .child = debug_table,
243 .procname = "dev",
244 .mode = 0555,
245 .child = dev_table,
250 #ifdef CONFIG_SCHED_DEBUG
251 static int min_sched_granularity_ns = 100000; /* 100 usecs */
252 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
253 static int min_wakeup_granularity_ns; /* 0 usecs */
254 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
255 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
256 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
257 #endif
259 #ifdef CONFIG_COMPACTION
260 static int min_extfrag_threshold;
261 static int max_extfrag_threshold = 1000;
262 #endif
264 static struct ctl_table kern_table[] = {
266 .procname = "sched_child_runs_first",
267 .data = &sysctl_sched_child_runs_first,
268 .maxlen = sizeof(unsigned int),
269 .mode = 0644,
270 .proc_handler = proc_dointvec,
272 #ifdef CONFIG_SCHED_DEBUG
274 .procname = "sched_min_granularity_ns",
275 .data = &sysctl_sched_min_granularity,
276 .maxlen = sizeof(unsigned int),
277 .mode = 0644,
278 .proc_handler = sched_proc_update_handler,
279 .extra1 = &min_sched_granularity_ns,
280 .extra2 = &max_sched_granularity_ns,
283 .procname = "sched_latency_ns",
284 .data = &sysctl_sched_latency,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = sched_proc_update_handler,
288 .extra1 = &min_sched_granularity_ns,
289 .extra2 = &max_sched_granularity_ns,
292 .procname = "sched_wakeup_granularity_ns",
293 .data = &sysctl_sched_wakeup_granularity,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = sched_proc_update_handler,
297 .extra1 = &min_wakeup_granularity_ns,
298 .extra2 = &max_wakeup_granularity_ns,
301 .procname = "sched_tunable_scaling",
302 .data = &sysctl_sched_tunable_scaling,
303 .maxlen = sizeof(enum sched_tunable_scaling),
304 .mode = 0644,
305 .proc_handler = sched_proc_update_handler,
306 .extra1 = &min_sched_tunable_scaling,
307 .extra2 = &max_sched_tunable_scaling,
310 .procname = "sched_migration_cost_ns",
311 .data = &sysctl_sched_migration_cost,
312 .maxlen = sizeof(unsigned int),
313 .mode = 0644,
314 .proc_handler = proc_dointvec,
317 .procname = "sched_nr_migrate",
318 .data = &sysctl_sched_nr_migrate,
319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
321 .proc_handler = proc_dointvec,
324 .procname = "sched_time_avg_ms",
325 .data = &sysctl_sched_time_avg,
326 .maxlen = sizeof(unsigned int),
327 .mode = 0644,
328 .proc_handler = proc_dointvec,
331 .procname = "sched_shares_window_ns",
332 .data = &sysctl_sched_shares_window,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
335 .proc_handler = proc_dointvec,
338 .procname = "timer_migration",
339 .data = &sysctl_timer_migration,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
342 .proc_handler = proc_dointvec_minmax,
343 .extra1 = &zero,
344 .extra2 = &one,
346 #endif
348 .procname = "sched_rt_period_us",
349 .data = &sysctl_sched_rt_period,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = sched_rt_handler,
355 .procname = "sched_rt_runtime_us",
356 .data = &sysctl_sched_rt_runtime,
357 .maxlen = sizeof(int),
358 .mode = 0644,
359 .proc_handler = sched_rt_handler,
361 #ifdef CONFIG_SCHED_AUTOGROUP
363 .procname = "sched_autogroup_enabled",
364 .data = &sysctl_sched_autogroup_enabled,
365 .maxlen = sizeof(unsigned int),
366 .mode = 0644,
367 .proc_handler = proc_dointvec_minmax,
368 .extra1 = &zero,
369 .extra2 = &one,
371 #endif
372 #ifdef CONFIG_CFS_BANDWIDTH
374 .procname = "sched_cfs_bandwidth_slice_us",
375 .data = &sysctl_sched_cfs_bandwidth_slice,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
378 .proc_handler = proc_dointvec_minmax,
379 .extra1 = &one,
381 #endif
382 #ifdef CONFIG_PROVE_LOCKING
384 .procname = "prove_locking",
385 .data = &prove_locking,
386 .maxlen = sizeof(int),
387 .mode = 0644,
388 .proc_handler = proc_dointvec,
390 #endif
391 #ifdef CONFIG_LOCK_STAT
393 .procname = "lock_stat",
394 .data = &lock_stat,
395 .maxlen = sizeof(int),
396 .mode = 0644,
397 .proc_handler = proc_dointvec,
399 #endif
401 .procname = "panic",
402 .data = &panic_timeout,
403 .maxlen = sizeof(int),
404 .mode = 0644,
405 .proc_handler = proc_dointvec,
408 .procname = "core_uses_pid",
409 .data = &core_uses_pid,
410 .maxlen = sizeof(int),
411 .mode = 0644,
412 .proc_handler = proc_dointvec,
415 .procname = "core_pattern",
416 .data = core_pattern,
417 .maxlen = CORENAME_MAX_SIZE,
418 .mode = 0644,
419 .proc_handler = proc_dostring_coredump,
422 .procname = "core_pipe_limit",
423 .data = &core_pipe_limit,
424 .maxlen = sizeof(unsigned int),
425 .mode = 0644,
426 .proc_handler = proc_dointvec,
428 #ifdef CONFIG_PROC_SYSCTL
430 .procname = "tainted",
431 .maxlen = sizeof(long),
432 .mode = 0644,
433 .proc_handler = proc_taint,
435 #endif
436 #ifdef CONFIG_LATENCYTOP
438 .procname = "latencytop",
439 .data = &latencytop_enabled,
440 .maxlen = sizeof(int),
441 .mode = 0644,
442 .proc_handler = proc_dointvec,
444 #endif
445 #ifdef CONFIG_BLK_DEV_INITRD
447 .procname = "real-root-dev",
448 .data = &real_root_dev,
449 .maxlen = sizeof(int),
450 .mode = 0644,
451 .proc_handler = proc_dointvec,
453 #endif
455 .procname = "print-fatal-signals",
456 .data = &print_fatal_signals,
457 .maxlen = sizeof(int),
458 .mode = 0644,
459 .proc_handler = proc_dointvec,
461 #ifdef CONFIG_SPARC
463 .procname = "reboot-cmd",
464 .data = reboot_command,
465 .maxlen = 256,
466 .mode = 0644,
467 .proc_handler = proc_dostring,
470 .procname = "stop-a",
471 .data = &stop_a_enabled,
472 .maxlen = sizeof (int),
473 .mode = 0644,
474 .proc_handler = proc_dointvec,
477 .procname = "scons-poweroff",
478 .data = &scons_pwroff,
479 .maxlen = sizeof (int),
480 .mode = 0644,
481 .proc_handler = proc_dointvec,
483 #endif
484 #ifdef CONFIG_SPARC64
486 .procname = "tsb-ratio",
487 .data = &sysctl_tsb_ratio,
488 .maxlen = sizeof (int),
489 .mode = 0644,
490 .proc_handler = proc_dointvec,
492 #endif
493 #ifdef __hppa__
495 .procname = "soft-power",
496 .data = &pwrsw_enabled,
497 .maxlen = sizeof (int),
498 .mode = 0644,
499 .proc_handler = proc_dointvec,
502 .procname = "unaligned-trap",
503 .data = &unaligned_enabled,
504 .maxlen = sizeof (int),
505 .mode = 0644,
506 .proc_handler = proc_dointvec,
508 #endif
510 .procname = "ctrl-alt-del",
511 .data = &C_A_D,
512 .maxlen = sizeof(int),
513 .mode = 0644,
514 .proc_handler = proc_dointvec,
516 #ifdef CONFIG_FUNCTION_TRACER
518 .procname = "ftrace_enabled",
519 .data = &ftrace_enabled,
520 .maxlen = sizeof(int),
521 .mode = 0644,
522 .proc_handler = ftrace_enable_sysctl,
524 #endif
525 #ifdef CONFIG_STACK_TRACER
527 .procname = "stack_tracer_enabled",
528 .data = &stack_tracer_enabled,
529 .maxlen = sizeof(int),
530 .mode = 0644,
531 .proc_handler = stack_trace_sysctl,
533 #endif
534 #ifdef CONFIG_TRACING
536 .procname = "ftrace_dump_on_oops",
537 .data = &ftrace_dump_on_oops,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 .proc_handler = proc_dointvec,
542 #endif
543 #ifdef CONFIG_MODULES
545 .procname = "modprobe",
546 .data = &modprobe_path,
547 .maxlen = KMOD_PATH_LEN,
548 .mode = 0644,
549 .proc_handler = proc_dostring,
552 .procname = "modules_disabled",
553 .data = &modules_disabled,
554 .maxlen = sizeof(int),
555 .mode = 0644,
556 /* only handle a transition from default "0" to "1" */
557 .proc_handler = proc_dointvec_minmax,
558 .extra1 = &one,
559 .extra2 = &one,
561 #endif
562 #ifdef CONFIG_HOTPLUG
564 .procname = "hotplug",
565 .data = &uevent_helper,
566 .maxlen = UEVENT_HELPER_PATH_LEN,
567 .mode = 0644,
568 .proc_handler = proc_dostring,
570 #endif
571 #ifdef CONFIG_CHR_DEV_SG
573 .procname = "sg-big-buff",
574 .data = &sg_big_buff,
575 .maxlen = sizeof (int),
576 .mode = 0444,
577 .proc_handler = proc_dointvec,
579 #endif
580 #ifdef CONFIG_BSD_PROCESS_ACCT
582 .procname = "acct",
583 .data = &acct_parm,
584 .maxlen = 3*sizeof(int),
585 .mode = 0644,
586 .proc_handler = proc_dointvec,
588 #endif
589 #ifdef CONFIG_MAGIC_SYSRQ
591 .procname = "sysrq",
592 .data = &__sysrq_enabled,
593 .maxlen = sizeof (int),
594 .mode = 0644,
595 .proc_handler = sysrq_sysctl_handler,
597 #endif
598 #ifdef CONFIG_PROC_SYSCTL
600 .procname = "cad_pid",
601 .data = NULL,
602 .maxlen = sizeof (int),
603 .mode = 0600,
604 .proc_handler = proc_do_cad_pid,
606 #endif
608 .procname = "threads-max",
609 .data = &max_threads,
610 .maxlen = sizeof(int),
611 .mode = 0644,
612 .proc_handler = proc_dointvec,
615 .procname = "random",
616 .mode = 0555,
617 .child = random_table,
620 .procname = "usermodehelper",
621 .mode = 0555,
622 .child = usermodehelper_table,
625 .procname = "overflowuid",
626 .data = &overflowuid,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = proc_dointvec_minmax,
630 .extra1 = &minolduid,
631 .extra2 = &maxolduid,
634 .procname = "overflowgid",
635 .data = &overflowgid,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = proc_dointvec_minmax,
639 .extra1 = &minolduid,
640 .extra2 = &maxolduid,
642 #ifdef CONFIG_S390
643 #ifdef CONFIG_MATHEMU
645 .procname = "ieee_emulation_warnings",
646 .data = &sysctl_ieee_emulation_warnings,
647 .maxlen = sizeof(int),
648 .mode = 0644,
649 .proc_handler = proc_dointvec,
651 #endif
653 .procname = "userprocess_debug",
654 .data = &show_unhandled_signals,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = proc_dointvec,
659 #endif
661 .procname = "pid_max",
662 .data = &pid_max,
663 .maxlen = sizeof (int),
664 .mode = 0644,
665 .proc_handler = proc_dointvec_minmax,
666 .extra1 = &pid_max_min,
667 .extra2 = &pid_max_max,
670 .procname = "panic_on_oops",
671 .data = &panic_on_oops,
672 .maxlen = sizeof(int),
673 .mode = 0644,
674 .proc_handler = proc_dointvec,
676 #if defined CONFIG_PRINTK
678 .procname = "printk",
679 .data = &console_loglevel,
680 .maxlen = 4*sizeof(int),
681 .mode = 0644,
682 .proc_handler = proc_dointvec,
685 .procname = "printk_ratelimit",
686 .data = &printk_ratelimit_state.interval,
687 .maxlen = sizeof(int),
688 .mode = 0644,
689 .proc_handler = proc_dointvec_jiffies,
692 .procname = "printk_ratelimit_burst",
693 .data = &printk_ratelimit_state.burst,
694 .maxlen = sizeof(int),
695 .mode = 0644,
696 .proc_handler = proc_dointvec,
699 .procname = "printk_delay",
700 .data = &printk_delay_msec,
701 .maxlen = sizeof(int),
702 .mode = 0644,
703 .proc_handler = proc_dointvec_minmax,
704 .extra1 = &zero,
705 .extra2 = &ten_thousand,
708 .procname = "dmesg_restrict",
709 .data = &dmesg_restrict,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = proc_dointvec_minmax_sysadmin,
713 .extra1 = &zero,
714 .extra2 = &one,
717 .procname = "kptr_restrict",
718 .data = &kptr_restrict,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = proc_dointvec_minmax_sysadmin,
722 .extra1 = &zero,
723 .extra2 = &two,
725 #endif
727 .procname = "ngroups_max",
728 .data = &ngroups_max,
729 .maxlen = sizeof (int),
730 .mode = 0444,
731 .proc_handler = proc_dointvec,
734 .procname = "cap_last_cap",
735 .data = (void *)&cap_last_cap,
736 .maxlen = sizeof(int),
737 .mode = 0444,
738 .proc_handler = proc_dointvec,
740 #if defined(CONFIG_LOCKUP_DETECTOR)
742 .procname = "watchdog",
743 .data = &watchdog_enabled,
744 .maxlen = sizeof (int),
745 .mode = 0644,
746 .proc_handler = proc_dowatchdog,
747 .extra1 = &zero,
748 .extra2 = &one,
751 .procname = "watchdog_thresh",
752 .data = &watchdog_thresh,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = proc_dowatchdog,
756 .extra1 = &neg_one,
757 .extra2 = &sixty,
760 .procname = "softlockup_panic",
761 .data = &softlockup_panic,
762 .maxlen = sizeof(int),
763 .mode = 0644,
764 .proc_handler = proc_dointvec_minmax,
765 .extra1 = &zero,
766 .extra2 = &one,
769 .procname = "nmi_watchdog",
770 .data = &watchdog_enabled,
771 .maxlen = sizeof (int),
772 .mode = 0644,
773 .proc_handler = proc_dowatchdog,
774 .extra1 = &zero,
775 .extra2 = &one,
777 #endif
778 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
780 .procname = "unknown_nmi_panic",
781 .data = &unknown_nmi_panic,
782 .maxlen = sizeof (int),
783 .mode = 0644,
784 .proc_handler = proc_dointvec,
786 #endif
787 #if defined(CONFIG_X86)
789 .procname = "panic_on_unrecovered_nmi",
790 .data = &panic_on_unrecovered_nmi,
791 .maxlen = sizeof(int),
792 .mode = 0644,
793 .proc_handler = proc_dointvec,
796 .procname = "panic_on_io_nmi",
797 .data = &panic_on_io_nmi,
798 .maxlen = sizeof(int),
799 .mode = 0644,
800 .proc_handler = proc_dointvec,
802 #ifdef CONFIG_DEBUG_STACKOVERFLOW
804 .procname = "panic_on_stackoverflow",
805 .data = &sysctl_panic_on_stackoverflow,
806 .maxlen = sizeof(int),
807 .mode = 0644,
808 .proc_handler = proc_dointvec,
810 #endif
812 .procname = "bootloader_type",
813 .data = &bootloader_type,
814 .maxlen = sizeof (int),
815 .mode = 0444,
816 .proc_handler = proc_dointvec,
819 .procname = "bootloader_version",
820 .data = &bootloader_version,
821 .maxlen = sizeof (int),
822 .mode = 0444,
823 .proc_handler = proc_dointvec,
826 .procname = "kstack_depth_to_print",
827 .data = &kstack_depth_to_print,
828 .maxlen = sizeof(int),
829 .mode = 0644,
830 .proc_handler = proc_dointvec,
833 .procname = "io_delay_type",
834 .data = &io_delay_type,
835 .maxlen = sizeof(int),
836 .mode = 0644,
837 .proc_handler = proc_dointvec,
839 #endif
840 #if defined(CONFIG_MMU)
842 .procname = "randomize_va_space",
843 .data = &randomize_va_space,
844 .maxlen = sizeof(int),
845 .mode = 0644,
846 .proc_handler = proc_dointvec,
848 #endif
849 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
851 .procname = "spin_retry",
852 .data = &spin_retry,
853 .maxlen = sizeof (int),
854 .mode = 0644,
855 .proc_handler = proc_dointvec,
857 #endif
858 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
860 .procname = "acpi_video_flags",
861 .data = &acpi_realmode_flags,
862 .maxlen = sizeof (unsigned long),
863 .mode = 0644,
864 .proc_handler = proc_doulongvec_minmax,
866 #endif
867 #ifdef CONFIG_IA64
869 .procname = "ignore-unaligned-usertrap",
870 .data = &no_unaligned_warning,
871 .maxlen = sizeof (int),
872 .mode = 0644,
873 .proc_handler = proc_dointvec,
876 .procname = "unaligned-dump-stack",
877 .data = &unaligned_dump_stack,
878 .maxlen = sizeof (int),
879 .mode = 0644,
880 .proc_handler = proc_dointvec,
882 #endif
883 #ifdef CONFIG_DETECT_HUNG_TASK
885 .procname = "hung_task_panic",
886 .data = &sysctl_hung_task_panic,
887 .maxlen = sizeof(int),
888 .mode = 0644,
889 .proc_handler = proc_dointvec_minmax,
890 .extra1 = &zero,
891 .extra2 = &one,
894 .procname = "hung_task_check_count",
895 .data = &sysctl_hung_task_check_count,
896 .maxlen = sizeof(unsigned long),
897 .mode = 0644,
898 .proc_handler = proc_doulongvec_minmax,
901 .procname = "hung_task_timeout_secs",
902 .data = &sysctl_hung_task_timeout_secs,
903 .maxlen = sizeof(unsigned long),
904 .mode = 0644,
905 .proc_handler = proc_dohung_task_timeout_secs,
908 .procname = "hung_task_warnings",
909 .data = &sysctl_hung_task_warnings,
910 .maxlen = sizeof(unsigned long),
911 .mode = 0644,
912 .proc_handler = proc_doulongvec_minmax,
914 #endif
915 #ifdef CONFIG_COMPAT
917 .procname = "compat-log",
918 .data = &compat_log,
919 .maxlen = sizeof (int),
920 .mode = 0644,
921 .proc_handler = proc_dointvec,
923 #endif
924 #ifdef CONFIG_RT_MUTEXES
926 .procname = "max_lock_depth",
927 .data = &max_lock_depth,
928 .maxlen = sizeof(int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec,
932 #endif
934 .procname = "poweroff_cmd",
935 .data = &poweroff_cmd,
936 .maxlen = POWEROFF_CMD_PATH_LEN,
937 .mode = 0644,
938 .proc_handler = proc_dostring,
940 #ifdef CONFIG_KEYS
942 .procname = "keys",
943 .mode = 0555,
944 .child = key_sysctls,
946 #endif
947 #ifdef CONFIG_RCU_TORTURE_TEST
949 .procname = "rcutorture_runnable",
950 .data = &rcutorture_runnable,
951 .maxlen = sizeof(int),
952 .mode = 0644,
953 .proc_handler = proc_dointvec,
955 #endif
956 #ifdef CONFIG_PERF_EVENTS
958 * User-space scripts rely on the existence of this file
959 * as a feature check for perf_events being enabled.
961 * So it's an ABI, do not remove!
964 .procname = "perf_event_paranoid",
965 .data = &sysctl_perf_event_paranoid,
966 .maxlen = sizeof(sysctl_perf_event_paranoid),
967 .mode = 0644,
968 .proc_handler = proc_dointvec,
971 .procname = "perf_event_mlock_kb",
972 .data = &sysctl_perf_event_mlock,
973 .maxlen = sizeof(sysctl_perf_event_mlock),
974 .mode = 0644,
975 .proc_handler = proc_dointvec,
978 .procname = "perf_event_max_sample_rate",
979 .data = &sysctl_perf_event_sample_rate,
980 .maxlen = sizeof(sysctl_perf_event_sample_rate),
981 .mode = 0644,
982 .proc_handler = perf_proc_update_handler,
984 #endif
985 #ifdef CONFIG_KMEMCHECK
987 .procname = "kmemcheck",
988 .data = &kmemcheck_enabled,
989 .maxlen = sizeof(int),
990 .mode = 0644,
991 .proc_handler = proc_dointvec,
993 #endif
994 #ifdef CONFIG_BLOCK
996 .procname = "blk_iopoll",
997 .data = &blk_iopoll_enabled,
998 .maxlen = sizeof(int),
999 .mode = 0644,
1000 .proc_handler = proc_dointvec,
1002 #endif
1006 static struct ctl_table vm_table[] = {
1008 .procname = "overcommit_memory",
1009 .data = &sysctl_overcommit_memory,
1010 .maxlen = sizeof(sysctl_overcommit_memory),
1011 .mode = 0644,
1012 .proc_handler = proc_dointvec_minmax,
1013 .extra1 = &zero,
1014 .extra2 = &two,
1017 .procname = "panic_on_oom",
1018 .data = &sysctl_panic_on_oom,
1019 .maxlen = sizeof(sysctl_panic_on_oom),
1020 .mode = 0644,
1021 .proc_handler = proc_dointvec_minmax,
1022 .extra1 = &zero,
1023 .extra2 = &two,
1026 .procname = "oom_kill_allocating_task",
1027 .data = &sysctl_oom_kill_allocating_task,
1028 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1029 .mode = 0644,
1030 .proc_handler = proc_dointvec,
1033 .procname = "oom_dump_tasks",
1034 .data = &sysctl_oom_dump_tasks,
1035 .maxlen = sizeof(sysctl_oom_dump_tasks),
1036 .mode = 0644,
1037 .proc_handler = proc_dointvec,
1040 .procname = "overcommit_ratio",
1041 .data = &sysctl_overcommit_ratio,
1042 .maxlen = sizeof(sysctl_overcommit_ratio),
1043 .mode = 0644,
1044 .proc_handler = proc_dointvec,
1047 .procname = "page-cluster",
1048 .data = &page_cluster,
1049 .maxlen = sizeof(int),
1050 .mode = 0644,
1051 .proc_handler = proc_dointvec_minmax,
1052 .extra1 = &zero,
1055 .procname = "dirty_background_ratio",
1056 .data = &dirty_background_ratio,
1057 .maxlen = sizeof(dirty_background_ratio),
1058 .mode = 0644,
1059 .proc_handler = dirty_background_ratio_handler,
1060 .extra1 = &zero,
1061 .extra2 = &one_hundred,
1064 .procname = "dirty_background_bytes",
1065 .data = &dirty_background_bytes,
1066 .maxlen = sizeof(dirty_background_bytes),
1067 .mode = 0644,
1068 .proc_handler = dirty_background_bytes_handler,
1069 .extra1 = &one_ul,
1072 .procname = "dirty_ratio",
1073 .data = &vm_dirty_ratio,
1074 .maxlen = sizeof(vm_dirty_ratio),
1075 .mode = 0644,
1076 .proc_handler = dirty_ratio_handler,
1077 .extra1 = &zero,
1078 .extra2 = &one_hundred,
1081 .procname = "dirty_bytes",
1082 .data = &vm_dirty_bytes,
1083 .maxlen = sizeof(vm_dirty_bytes),
1084 .mode = 0644,
1085 .proc_handler = dirty_bytes_handler,
1086 .extra1 = &dirty_bytes_min,
1089 .procname = "dirty_writeback_centisecs",
1090 .data = &dirty_writeback_interval,
1091 .maxlen = sizeof(dirty_writeback_interval),
1092 .mode = 0644,
1093 .proc_handler = dirty_writeback_centisecs_handler,
1096 .procname = "dirty_expire_centisecs",
1097 .data = &dirty_expire_interval,
1098 .maxlen = sizeof(dirty_expire_interval),
1099 .mode = 0644,
1100 .proc_handler = proc_dointvec_minmax,
1101 .extra1 = &zero,
1104 .procname = "nr_pdflush_threads",
1105 .mode = 0444 /* read-only */,
1106 .proc_handler = pdflush_proc_obsolete,
1109 .procname = "swappiness",
1110 .data = &vm_swappiness,
1111 .maxlen = sizeof(vm_swappiness),
1112 .mode = 0644,
1113 .proc_handler = proc_dointvec_minmax,
1114 .extra1 = &zero,
1115 .extra2 = &one_hundred,
1117 #ifdef CONFIG_HUGETLB_PAGE
1119 .procname = "nr_hugepages",
1120 .data = NULL,
1121 .maxlen = sizeof(unsigned long),
1122 .mode = 0644,
1123 .proc_handler = hugetlb_sysctl_handler,
1124 .extra1 = (void *)&hugetlb_zero,
1125 .extra2 = (void *)&hugetlb_infinity,
1127 #ifdef CONFIG_NUMA
1129 .procname = "nr_hugepages_mempolicy",
1130 .data = NULL,
1131 .maxlen = sizeof(unsigned long),
1132 .mode = 0644,
1133 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1134 .extra1 = (void *)&hugetlb_zero,
1135 .extra2 = (void *)&hugetlb_infinity,
1137 #endif
1139 .procname = "hugetlb_shm_group",
1140 .data = &sysctl_hugetlb_shm_group,
1141 .maxlen = sizeof(gid_t),
1142 .mode = 0644,
1143 .proc_handler = proc_dointvec,
1146 .procname = "hugepages_treat_as_movable",
1147 .data = &hugepages_treat_as_movable,
1148 .maxlen = sizeof(int),
1149 .mode = 0644,
1150 .proc_handler = hugetlb_treat_movable_handler,
1153 .procname = "nr_overcommit_hugepages",
1154 .data = NULL,
1155 .maxlen = sizeof(unsigned long),
1156 .mode = 0644,
1157 .proc_handler = hugetlb_overcommit_handler,
1158 .extra1 = (void *)&hugetlb_zero,
1159 .extra2 = (void *)&hugetlb_infinity,
1161 #endif
1163 .procname = "lowmem_reserve_ratio",
1164 .data = &sysctl_lowmem_reserve_ratio,
1165 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1166 .mode = 0644,
1167 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1170 .procname = "drop_caches",
1171 .data = &sysctl_drop_caches,
1172 .maxlen = sizeof(int),
1173 .mode = 0644,
1174 .proc_handler = drop_caches_sysctl_handler,
1175 .extra1 = &one,
1176 .extra2 = &three,
1178 #ifdef CONFIG_COMPACTION
1180 .procname = "compact_memory",
1181 .data = &sysctl_compact_memory,
1182 .maxlen = sizeof(int),
1183 .mode = 0200,
1184 .proc_handler = sysctl_compaction_handler,
1187 .procname = "extfrag_threshold",
1188 .data = &sysctl_extfrag_threshold,
1189 .maxlen = sizeof(int),
1190 .mode = 0644,
1191 .proc_handler = sysctl_extfrag_handler,
1192 .extra1 = &min_extfrag_threshold,
1193 .extra2 = &max_extfrag_threshold,
1196 #endif /* CONFIG_COMPACTION */
1198 .procname = "min_free_kbytes",
1199 .data = &min_free_kbytes,
1200 .maxlen = sizeof(min_free_kbytes),
1201 .mode = 0644,
1202 .proc_handler = min_free_kbytes_sysctl_handler,
1203 .extra1 = &zero,
1206 .procname = "percpu_pagelist_fraction",
1207 .data = &percpu_pagelist_fraction,
1208 .maxlen = sizeof(percpu_pagelist_fraction),
1209 .mode = 0644,
1210 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1211 .extra1 = &min_percpu_pagelist_fract,
1213 #ifdef CONFIG_MMU
1215 .procname = "max_map_count",
1216 .data = &sysctl_max_map_count,
1217 .maxlen = sizeof(sysctl_max_map_count),
1218 .mode = 0644,
1219 .proc_handler = proc_dointvec_minmax,
1220 .extra1 = &zero,
1222 #else
1224 .procname = "nr_trim_pages",
1225 .data = &sysctl_nr_trim_pages,
1226 .maxlen = sizeof(sysctl_nr_trim_pages),
1227 .mode = 0644,
1228 .proc_handler = proc_dointvec_minmax,
1229 .extra1 = &zero,
1231 #endif
1233 .procname = "laptop_mode",
1234 .data = &laptop_mode,
1235 .maxlen = sizeof(laptop_mode),
1236 .mode = 0644,
1237 .proc_handler = proc_dointvec_jiffies,
1240 .procname = "block_dump",
1241 .data = &block_dump,
1242 .maxlen = sizeof(block_dump),
1243 .mode = 0644,
1244 .proc_handler = proc_dointvec,
1245 .extra1 = &zero,
1248 .procname = "vfs_cache_pressure",
1249 .data = &sysctl_vfs_cache_pressure,
1250 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1251 .mode = 0644,
1252 .proc_handler = proc_dointvec,
1253 .extra1 = &zero,
1255 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1257 .procname = "legacy_va_layout",
1258 .data = &sysctl_legacy_va_layout,
1259 .maxlen = sizeof(sysctl_legacy_va_layout),
1260 .mode = 0644,
1261 .proc_handler = proc_dointvec,
1262 .extra1 = &zero,
1264 #endif
1265 #ifdef CONFIG_NUMA
1267 .procname = "zone_reclaim_mode",
1268 .data = &zone_reclaim_mode,
1269 .maxlen = sizeof(zone_reclaim_mode),
1270 .mode = 0644,
1271 .proc_handler = proc_dointvec,
1272 .extra1 = &zero,
1275 .procname = "min_unmapped_ratio",
1276 .data = &sysctl_min_unmapped_ratio,
1277 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1278 .mode = 0644,
1279 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1280 .extra1 = &zero,
1281 .extra2 = &one_hundred,
1284 .procname = "min_slab_ratio",
1285 .data = &sysctl_min_slab_ratio,
1286 .maxlen = sizeof(sysctl_min_slab_ratio),
1287 .mode = 0644,
1288 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1289 .extra1 = &zero,
1290 .extra2 = &one_hundred,
1292 #endif
1293 #ifdef CONFIG_SMP
1295 .procname = "stat_interval",
1296 .data = &sysctl_stat_interval,
1297 .maxlen = sizeof(sysctl_stat_interval),
1298 .mode = 0644,
1299 .proc_handler = proc_dointvec_jiffies,
1301 #endif
1302 #ifdef CONFIG_MMU
1304 .procname = "mmap_min_addr",
1305 .data = &dac_mmap_min_addr,
1306 .maxlen = sizeof(unsigned long),
1307 .mode = 0644,
1308 .proc_handler = mmap_min_addr_handler,
1310 #endif
1311 #ifdef CONFIG_NUMA
1313 .procname = "numa_zonelist_order",
1314 .data = &numa_zonelist_order,
1315 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1316 .mode = 0644,
1317 .proc_handler = numa_zonelist_order_handler,
1319 #endif
1320 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1321 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1323 .procname = "vdso_enabled",
1324 .data = &vdso_enabled,
1325 .maxlen = sizeof(vdso_enabled),
1326 .mode = 0644,
1327 .proc_handler = proc_dointvec,
1328 .extra1 = &zero,
1330 #endif
1331 #ifdef CONFIG_HIGHMEM
1333 .procname = "highmem_is_dirtyable",
1334 .data = &vm_highmem_is_dirtyable,
1335 .maxlen = sizeof(vm_highmem_is_dirtyable),
1336 .mode = 0644,
1337 .proc_handler = proc_dointvec_minmax,
1338 .extra1 = &zero,
1339 .extra2 = &one,
1341 #endif
1343 .procname = "scan_unevictable_pages",
1344 .data = &scan_unevictable_pages,
1345 .maxlen = sizeof(scan_unevictable_pages),
1346 .mode = 0644,
1347 .proc_handler = scan_unevictable_handler,
1349 #ifdef CONFIG_MEMORY_FAILURE
1351 .procname = "memory_failure_early_kill",
1352 .data = &sysctl_memory_failure_early_kill,
1353 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1354 .mode = 0644,
1355 .proc_handler = proc_dointvec_minmax,
1356 .extra1 = &zero,
1357 .extra2 = &one,
1360 .procname = "memory_failure_recovery",
1361 .data = &sysctl_memory_failure_recovery,
1362 .maxlen = sizeof(sysctl_memory_failure_recovery),
1363 .mode = 0644,
1364 .proc_handler = proc_dointvec_minmax,
1365 .extra1 = &zero,
1366 .extra2 = &one,
1368 #endif
1372 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1373 static struct ctl_table binfmt_misc_table[] = {
1376 #endif
1378 static struct ctl_table fs_table[] = {
1380 .procname = "inode-nr",
1381 .data = &inodes_stat,
1382 .maxlen = 2*sizeof(int),
1383 .mode = 0444,
1384 .proc_handler = proc_nr_inodes,
1387 .procname = "inode-state",
1388 .data = &inodes_stat,
1389 .maxlen = 7*sizeof(int),
1390 .mode = 0444,
1391 .proc_handler = proc_nr_inodes,
1394 .procname = "file-nr",
1395 .data = &files_stat,
1396 .maxlen = sizeof(files_stat),
1397 .mode = 0444,
1398 .proc_handler = proc_nr_files,
1401 .procname = "file-max",
1402 .data = &files_stat.max_files,
1403 .maxlen = sizeof(files_stat.max_files),
1404 .mode = 0644,
1405 .proc_handler = proc_doulongvec_minmax,
1408 .procname = "nr_open",
1409 .data = &sysctl_nr_open,
1410 .maxlen = sizeof(int),
1411 .mode = 0644,
1412 .proc_handler = proc_dointvec_minmax,
1413 .extra1 = &sysctl_nr_open_min,
1414 .extra2 = &sysctl_nr_open_max,
1417 .procname = "dentry-state",
1418 .data = &dentry_stat,
1419 .maxlen = 6*sizeof(int),
1420 .mode = 0444,
1421 .proc_handler = proc_nr_dentry,
1424 .procname = "overflowuid",
1425 .data = &fs_overflowuid,
1426 .maxlen = sizeof(int),
1427 .mode = 0644,
1428 .proc_handler = proc_dointvec_minmax,
1429 .extra1 = &minolduid,
1430 .extra2 = &maxolduid,
1433 .procname = "overflowgid",
1434 .data = &fs_overflowgid,
1435 .maxlen = sizeof(int),
1436 .mode = 0644,
1437 .proc_handler = proc_dointvec_minmax,
1438 .extra1 = &minolduid,
1439 .extra2 = &maxolduid,
1441 #ifdef CONFIG_FILE_LOCKING
1443 .procname = "leases-enable",
1444 .data = &leases_enable,
1445 .maxlen = sizeof(int),
1446 .mode = 0644,
1447 .proc_handler = proc_dointvec,
1449 #endif
1450 #ifdef CONFIG_DNOTIFY
1452 .procname = "dir-notify-enable",
1453 .data = &dir_notify_enable,
1454 .maxlen = sizeof(int),
1455 .mode = 0644,
1456 .proc_handler = proc_dointvec,
1458 #endif
1459 #ifdef CONFIG_MMU
1460 #ifdef CONFIG_FILE_LOCKING
1462 .procname = "lease-break-time",
1463 .data = &lease_break_time,
1464 .maxlen = sizeof(int),
1465 .mode = 0644,
1466 .proc_handler = proc_dointvec,
1468 #endif
1469 #ifdef CONFIG_AIO
1471 .procname = "aio-nr",
1472 .data = &aio_nr,
1473 .maxlen = sizeof(aio_nr),
1474 .mode = 0444,
1475 .proc_handler = proc_doulongvec_minmax,
1478 .procname = "aio-max-nr",
1479 .data = &aio_max_nr,
1480 .maxlen = sizeof(aio_max_nr),
1481 .mode = 0644,
1482 .proc_handler = proc_doulongvec_minmax,
1484 #endif /* CONFIG_AIO */
1485 #ifdef CONFIG_INOTIFY_USER
1487 .procname = "inotify",
1488 .mode = 0555,
1489 .child = inotify_table,
1491 #endif
1492 #ifdef CONFIG_EPOLL
1494 .procname = "epoll",
1495 .mode = 0555,
1496 .child = epoll_table,
1498 #endif
1499 #endif
1501 .procname = "protected_symlinks",
1502 .data = &sysctl_protected_symlinks,
1503 .maxlen = sizeof(int),
1504 .mode = 0600,
1505 .proc_handler = proc_dointvec_minmax,
1506 .extra1 = &zero,
1507 .extra2 = &one,
1510 .procname = "protected_hardlinks",
1511 .data = &sysctl_protected_hardlinks,
1512 .maxlen = sizeof(int),
1513 .mode = 0600,
1514 .proc_handler = proc_dointvec_minmax,
1515 .extra1 = &zero,
1516 .extra2 = &one,
1519 .procname = "suid_dumpable",
1520 .data = &suid_dumpable,
1521 .maxlen = sizeof(int),
1522 .mode = 0644,
1523 .proc_handler = proc_dointvec_minmax_coredump,
1524 .extra1 = &zero,
1525 .extra2 = &two,
1527 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1529 .procname = "binfmt_misc",
1530 .mode = 0555,
1531 .child = binfmt_misc_table,
1533 #endif
1535 .procname = "pipe-max-size",
1536 .data = &pipe_max_size,
1537 .maxlen = sizeof(int),
1538 .mode = 0644,
1539 .proc_handler = &pipe_proc_fn,
1540 .extra1 = &pipe_min_size,
1545 static struct ctl_table debug_table[] = {
1546 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1547 defined(CONFIG_S390) || defined(CONFIG_TILE) || defined(CONFIG_ARM64)
1549 .procname = "exception-trace",
1550 .data = &show_unhandled_signals,
1551 .maxlen = sizeof(int),
1552 .mode = 0644,
1553 .proc_handler = proc_dointvec
1555 #endif
1556 #if defined(CONFIG_OPTPROBES)
1558 .procname = "kprobes-optimization",
1559 .data = &sysctl_kprobes_optimization,
1560 .maxlen = sizeof(int),
1561 .mode = 0644,
1562 .proc_handler = proc_kprobes_optimization_handler,
1563 .extra1 = &zero,
1564 .extra2 = &one,
1566 #endif
1570 static struct ctl_table dev_table[] = {
1574 int __init sysctl_init(void)
1576 struct ctl_table_header *hdr;
1578 hdr = register_sysctl_table(sysctl_base_table);
1579 kmemleak_not_leak(hdr);
1580 return 0;
1583 #endif /* CONFIG_SYSCTL */
1586 * /proc/sys support
1589 #ifdef CONFIG_PROC_SYSCTL
1591 static int _proc_do_string(void* data, int maxlen, int write,
1592 void __user *buffer,
1593 size_t *lenp, loff_t *ppos)
1595 size_t len;
1596 char __user *p;
1597 char c;
1599 if (!data || !maxlen || !*lenp) {
1600 *lenp = 0;
1601 return 0;
1604 if (write) {
1605 len = 0;
1606 p = buffer;
1607 while (len < *lenp) {
1608 if (get_user(c, p++))
1609 return -EFAULT;
1610 if (c == 0 || c == '\n')
1611 break;
1612 len++;
1614 if (len >= maxlen)
1615 len = maxlen-1;
1616 if(copy_from_user(data, buffer, len))
1617 return -EFAULT;
1618 ((char *) data)[len] = 0;
1619 *ppos += *lenp;
1620 } else {
1621 len = strlen(data);
1622 if (len > maxlen)
1623 len = maxlen;
1625 if (*ppos > len) {
1626 *lenp = 0;
1627 return 0;
1630 data += *ppos;
1631 len -= *ppos;
1633 if (len > *lenp)
1634 len = *lenp;
1635 if (len)
1636 if(copy_to_user(buffer, data, len))
1637 return -EFAULT;
1638 if (len < *lenp) {
1639 if(put_user('\n', ((char __user *) buffer) + len))
1640 return -EFAULT;
1641 len++;
1643 *lenp = len;
1644 *ppos += len;
1646 return 0;
1650 * proc_dostring - read a string sysctl
1651 * @table: the sysctl table
1652 * @write: %TRUE if this is a write to the sysctl file
1653 * @buffer: the user buffer
1654 * @lenp: the size of the user buffer
1655 * @ppos: file position
1657 * Reads/writes a string from/to the user buffer. If the kernel
1658 * buffer provided is not large enough to hold the string, the
1659 * string is truncated. The copied string is %NULL-terminated.
1660 * If the string is being read by the user process, it is copied
1661 * and a newline '\n' is added. It is truncated if the buffer is
1662 * not large enough.
1664 * Returns 0 on success.
1666 int proc_dostring(struct ctl_table *table, int write,
1667 void __user *buffer, size_t *lenp, loff_t *ppos)
1669 return _proc_do_string(table->data, table->maxlen, write,
1670 buffer, lenp, ppos);
1673 static size_t proc_skip_spaces(char **buf)
1675 size_t ret;
1676 char *tmp = skip_spaces(*buf);
1677 ret = tmp - *buf;
1678 *buf = tmp;
1679 return ret;
1682 static void proc_skip_char(char **buf, size_t *size, const char v)
1684 while (*size) {
1685 if (**buf != v)
1686 break;
1687 (*size)--;
1688 (*buf)++;
1692 #define TMPBUFLEN 22
1694 * proc_get_long - reads an ASCII formatted integer from a user buffer
1696 * @buf: a kernel buffer
1697 * @size: size of the kernel buffer
1698 * @val: this is where the number will be stored
1699 * @neg: set to %TRUE if number is negative
1700 * @perm_tr: a vector which contains the allowed trailers
1701 * @perm_tr_len: size of the perm_tr vector
1702 * @tr: pointer to store the trailer character
1704 * In case of success %0 is returned and @buf and @size are updated with
1705 * the amount of bytes read. If @tr is non-NULL and a trailing
1706 * character exists (size is non-zero after returning from this
1707 * function), @tr is updated with the trailing character.
1709 static int proc_get_long(char **buf, size_t *size,
1710 unsigned long *val, bool *neg,
1711 const char *perm_tr, unsigned perm_tr_len, char *tr)
1713 int len;
1714 char *p, tmp[TMPBUFLEN];
1716 if (!*size)
1717 return -EINVAL;
1719 len = *size;
1720 if (len > TMPBUFLEN - 1)
1721 len = TMPBUFLEN - 1;
1723 memcpy(tmp, *buf, len);
1725 tmp[len] = 0;
1726 p = tmp;
1727 if (*p == '-' && *size > 1) {
1728 *neg = true;
1729 p++;
1730 } else
1731 *neg = false;
1732 if (!isdigit(*p))
1733 return -EINVAL;
1735 *val = simple_strtoul(p, &p, 0);
1737 len = p - tmp;
1739 /* We don't know if the next char is whitespace thus we may accept
1740 * invalid integers (e.g. 1234...a) or two integers instead of one
1741 * (e.g. 123...1). So lets not allow such large numbers. */
1742 if (len == TMPBUFLEN - 1)
1743 return -EINVAL;
1745 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1746 return -EINVAL;
1748 if (tr && (len < *size))
1749 *tr = *p;
1751 *buf += len;
1752 *size -= len;
1754 return 0;
1758 * proc_put_long - converts an integer to a decimal ASCII formatted string
1760 * @buf: the user buffer
1761 * @size: the size of the user buffer
1762 * @val: the integer to be converted
1763 * @neg: sign of the number, %TRUE for negative
1765 * In case of success %0 is returned and @buf and @size are updated with
1766 * the amount of bytes written.
1768 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1769 bool neg)
1771 int len;
1772 char tmp[TMPBUFLEN], *p = tmp;
1774 sprintf(p, "%s%lu", neg ? "-" : "", val);
1775 len = strlen(tmp);
1776 if (len > *size)
1777 len = *size;
1778 if (copy_to_user(*buf, tmp, len))
1779 return -EFAULT;
1780 *size -= len;
1781 *buf += len;
1782 return 0;
1784 #undef TMPBUFLEN
1786 static int proc_put_char(void __user **buf, size_t *size, char c)
1788 if (*size) {
1789 char __user **buffer = (char __user **)buf;
1790 if (put_user(c, *buffer))
1791 return -EFAULT;
1792 (*size)--, (*buffer)++;
1793 *buf = *buffer;
1795 return 0;
1798 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1799 int *valp,
1800 int write, void *data)
1802 if (write) {
1803 *valp = *negp ? -*lvalp : *lvalp;
1804 } else {
1805 int val = *valp;
1806 if (val < 0) {
1807 *negp = true;
1808 *lvalp = (unsigned long)-val;
1809 } else {
1810 *negp = false;
1811 *lvalp = (unsigned long)val;
1814 return 0;
1817 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1819 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1820 int write, void __user *buffer,
1821 size_t *lenp, loff_t *ppos,
1822 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1823 int write, void *data),
1824 void *data)
1826 int *i, vleft, first = 1, err = 0;
1827 unsigned long page = 0;
1828 size_t left;
1829 char *kbuf;
1831 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1832 *lenp = 0;
1833 return 0;
1836 i = (int *) tbl_data;
1837 vleft = table->maxlen / sizeof(*i);
1838 left = *lenp;
1840 if (!conv)
1841 conv = do_proc_dointvec_conv;
1843 if (write) {
1844 if (left > PAGE_SIZE - 1)
1845 left = PAGE_SIZE - 1;
1846 page = __get_free_page(GFP_TEMPORARY);
1847 kbuf = (char *) page;
1848 if (!kbuf)
1849 return -ENOMEM;
1850 if (copy_from_user(kbuf, buffer, left)) {
1851 err = -EFAULT;
1852 goto free;
1854 kbuf[left] = 0;
1857 for (; left && vleft--; i++, first=0) {
1858 unsigned long lval;
1859 bool neg;
1861 if (write) {
1862 left -= proc_skip_spaces(&kbuf);
1864 if (!left)
1865 break;
1866 err = proc_get_long(&kbuf, &left, &lval, &neg,
1867 proc_wspace_sep,
1868 sizeof(proc_wspace_sep), NULL);
1869 if (err)
1870 break;
1871 if (conv(&neg, &lval, i, 1, data)) {
1872 err = -EINVAL;
1873 break;
1875 } else {
1876 if (conv(&neg, &lval, i, 0, data)) {
1877 err = -EINVAL;
1878 break;
1880 if (!first)
1881 err = proc_put_char(&buffer, &left, '\t');
1882 if (err)
1883 break;
1884 err = proc_put_long(&buffer, &left, lval, neg);
1885 if (err)
1886 break;
1890 if (!write && !first && left && !err)
1891 err = proc_put_char(&buffer, &left, '\n');
1892 if (write && !err && left)
1893 left -= proc_skip_spaces(&kbuf);
1894 free:
1895 if (write) {
1896 free_page(page);
1897 if (first)
1898 return err ? : -EINVAL;
1900 *lenp -= left;
1901 *ppos += *lenp;
1902 return err;
1905 static int do_proc_dointvec(struct ctl_table *table, int write,
1906 void __user *buffer, size_t *lenp, loff_t *ppos,
1907 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1908 int write, void *data),
1909 void *data)
1911 return __do_proc_dointvec(table->data, table, write,
1912 buffer, lenp, ppos, conv, data);
1916 * proc_dointvec - read a vector of integers
1917 * @table: the sysctl table
1918 * @write: %TRUE if this is a write to the sysctl file
1919 * @buffer: the user buffer
1920 * @lenp: the size of the user buffer
1921 * @ppos: file position
1923 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1924 * values from/to the user buffer, treated as an ASCII string.
1926 * Returns 0 on success.
1928 int proc_dointvec(struct ctl_table *table, int write,
1929 void __user *buffer, size_t *lenp, loff_t *ppos)
1931 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1932 NULL,NULL);
1936 * Taint values can only be increased
1937 * This means we can safely use a temporary.
1939 static int proc_taint(struct ctl_table *table, int write,
1940 void __user *buffer, size_t *lenp, loff_t *ppos)
1942 struct ctl_table t;
1943 unsigned long tmptaint = get_taint();
1944 int err;
1946 if (write && !capable(CAP_SYS_ADMIN))
1947 return -EPERM;
1949 t = *table;
1950 t.data = &tmptaint;
1951 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
1952 if (err < 0)
1953 return err;
1955 if (write) {
1957 * Poor man's atomic or. Not worth adding a primitive
1958 * to everyone's atomic.h for this
1960 int i;
1961 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
1962 if ((tmptaint >> i) & 1)
1963 add_taint(i);
1967 return err;
1970 #ifdef CONFIG_PRINTK
1971 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
1972 void __user *buffer, size_t *lenp, loff_t *ppos)
1974 if (write && !capable(CAP_SYS_ADMIN))
1975 return -EPERM;
1977 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1979 #endif
1981 struct do_proc_dointvec_minmax_conv_param {
1982 int *min;
1983 int *max;
1986 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
1987 int *valp,
1988 int write, void *data)
1990 struct do_proc_dointvec_minmax_conv_param *param = data;
1991 if (write) {
1992 int val = *negp ? -*lvalp : *lvalp;
1993 if ((param->min && *param->min > val) ||
1994 (param->max && *param->max < val))
1995 return -EINVAL;
1996 *valp = val;
1997 } else {
1998 int val = *valp;
1999 if (val < 0) {
2000 *negp = true;
2001 *lvalp = (unsigned long)-val;
2002 } else {
2003 *negp = false;
2004 *lvalp = (unsigned long)val;
2007 return 0;
2011 * proc_dointvec_minmax - read a vector of integers with min/max values
2012 * @table: the sysctl table
2013 * @write: %TRUE if this is a write to the sysctl file
2014 * @buffer: the user buffer
2015 * @lenp: the size of the user buffer
2016 * @ppos: file position
2018 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2019 * values from/to the user buffer, treated as an ASCII string.
2021 * This routine will ensure the values are within the range specified by
2022 * table->extra1 (min) and table->extra2 (max).
2024 * Returns 0 on success.
2026 int proc_dointvec_minmax(struct ctl_table *table, int write,
2027 void __user *buffer, size_t *lenp, loff_t *ppos)
2029 struct do_proc_dointvec_minmax_conv_param param = {
2030 .min = (int *) table->extra1,
2031 .max = (int *) table->extra2,
2033 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2034 do_proc_dointvec_minmax_conv, &param);
2037 static void validate_coredump_safety(void)
2039 if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2040 core_pattern[0] != '/' && core_pattern[0] != '|') {
2041 printk(KERN_WARNING "Unsafe core_pattern used with "\
2042 "suid_dumpable=2. Pipe handler or fully qualified "\
2043 "core dump path required.\n");
2047 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2048 void __user *buffer, size_t *lenp, loff_t *ppos)
2050 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2051 if (!error)
2052 validate_coredump_safety();
2053 return error;
2056 static int proc_dostring_coredump(struct ctl_table *table, int write,
2057 void __user *buffer, size_t *lenp, loff_t *ppos)
2059 int error = proc_dostring(table, write, buffer, lenp, ppos);
2060 if (!error)
2061 validate_coredump_safety();
2062 return error;
2065 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2066 void __user *buffer,
2067 size_t *lenp, loff_t *ppos,
2068 unsigned long convmul,
2069 unsigned long convdiv)
2071 unsigned long *i, *min, *max;
2072 int vleft, first = 1, err = 0;
2073 unsigned long page = 0;
2074 size_t left;
2075 char *kbuf;
2077 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2078 *lenp = 0;
2079 return 0;
2082 i = (unsigned long *) data;
2083 min = (unsigned long *) table->extra1;
2084 max = (unsigned long *) table->extra2;
2085 vleft = table->maxlen / sizeof(unsigned long);
2086 left = *lenp;
2088 if (write) {
2089 if (left > PAGE_SIZE - 1)
2090 left = PAGE_SIZE - 1;
2091 page = __get_free_page(GFP_TEMPORARY);
2092 kbuf = (char *) page;
2093 if (!kbuf)
2094 return -ENOMEM;
2095 if (copy_from_user(kbuf, buffer, left)) {
2096 err = -EFAULT;
2097 goto free;
2099 kbuf[left] = 0;
2102 for (; left && vleft--; i++, first = 0) {
2103 unsigned long val;
2105 if (write) {
2106 bool neg;
2108 left -= proc_skip_spaces(&kbuf);
2110 err = proc_get_long(&kbuf, &left, &val, &neg,
2111 proc_wspace_sep,
2112 sizeof(proc_wspace_sep), NULL);
2113 if (err)
2114 break;
2115 if (neg)
2116 continue;
2117 if ((min && val < *min) || (max && val > *max))
2118 continue;
2119 *i = val;
2120 } else {
2121 val = convdiv * (*i) / convmul;
2122 if (!first)
2123 err = proc_put_char(&buffer, &left, '\t');
2124 err = proc_put_long(&buffer, &left, val, false);
2125 if (err)
2126 break;
2130 if (!write && !first && left && !err)
2131 err = proc_put_char(&buffer, &left, '\n');
2132 if (write && !err)
2133 left -= proc_skip_spaces(&kbuf);
2134 free:
2135 if (write) {
2136 free_page(page);
2137 if (first)
2138 return err ? : -EINVAL;
2140 *lenp -= left;
2141 *ppos += *lenp;
2142 return err;
2145 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2146 void __user *buffer,
2147 size_t *lenp, loff_t *ppos,
2148 unsigned long convmul,
2149 unsigned long convdiv)
2151 return __do_proc_doulongvec_minmax(table->data, table, write,
2152 buffer, lenp, ppos, convmul, convdiv);
2156 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2157 * @table: the sysctl table
2158 * @write: %TRUE if this is a write to the sysctl file
2159 * @buffer: the user buffer
2160 * @lenp: the size of the user buffer
2161 * @ppos: file position
2163 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2164 * values from/to the user buffer, treated as an ASCII string.
2166 * This routine will ensure the values are within the range specified by
2167 * table->extra1 (min) and table->extra2 (max).
2169 * Returns 0 on success.
2171 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2172 void __user *buffer, size_t *lenp, loff_t *ppos)
2174 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2178 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2179 * @table: the sysctl table
2180 * @write: %TRUE if this is a write to the sysctl file
2181 * @buffer: the user buffer
2182 * @lenp: the size of the user buffer
2183 * @ppos: file position
2185 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2186 * values from/to the user buffer, treated as an ASCII string. The values
2187 * are treated as milliseconds, and converted to jiffies when they are stored.
2189 * This routine will ensure the values are within the range specified by
2190 * table->extra1 (min) and table->extra2 (max).
2192 * Returns 0 on success.
2194 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2195 void __user *buffer,
2196 size_t *lenp, loff_t *ppos)
2198 return do_proc_doulongvec_minmax(table, write, buffer,
2199 lenp, ppos, HZ, 1000l);
2203 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2204 int *valp,
2205 int write, void *data)
2207 if (write) {
2208 if (*lvalp > LONG_MAX / HZ)
2209 return 1;
2210 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2211 } else {
2212 int val = *valp;
2213 unsigned long lval;
2214 if (val < 0) {
2215 *negp = true;
2216 lval = (unsigned long)-val;
2217 } else {
2218 *negp = false;
2219 lval = (unsigned long)val;
2221 *lvalp = lval / HZ;
2223 return 0;
2226 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2227 int *valp,
2228 int write, void *data)
2230 if (write) {
2231 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2232 return 1;
2233 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2234 } else {
2235 int val = *valp;
2236 unsigned long lval;
2237 if (val < 0) {
2238 *negp = true;
2239 lval = (unsigned long)-val;
2240 } else {
2241 *negp = false;
2242 lval = (unsigned long)val;
2244 *lvalp = jiffies_to_clock_t(lval);
2246 return 0;
2249 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2250 int *valp,
2251 int write, void *data)
2253 if (write) {
2254 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2255 } else {
2256 int val = *valp;
2257 unsigned long lval;
2258 if (val < 0) {
2259 *negp = true;
2260 lval = (unsigned long)-val;
2261 } else {
2262 *negp = false;
2263 lval = (unsigned long)val;
2265 *lvalp = jiffies_to_msecs(lval);
2267 return 0;
2271 * proc_dointvec_jiffies - read a vector of integers as seconds
2272 * @table: the sysctl table
2273 * @write: %TRUE if this is a write to the sysctl file
2274 * @buffer: the user buffer
2275 * @lenp: the size of the user buffer
2276 * @ppos: file position
2278 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2279 * values from/to the user buffer, treated as an ASCII string.
2280 * The values read are assumed to be in seconds, and are converted into
2281 * jiffies.
2283 * Returns 0 on success.
2285 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2286 void __user *buffer, size_t *lenp, loff_t *ppos)
2288 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2289 do_proc_dointvec_jiffies_conv,NULL);
2293 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2294 * @table: the sysctl table
2295 * @write: %TRUE if this is a write to the sysctl file
2296 * @buffer: the user buffer
2297 * @lenp: the size of the user buffer
2298 * @ppos: pointer to the file position
2300 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2301 * values from/to the user buffer, treated as an ASCII string.
2302 * The values read are assumed to be in 1/USER_HZ seconds, and
2303 * are converted into jiffies.
2305 * Returns 0 on success.
2307 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2308 void __user *buffer, size_t *lenp, loff_t *ppos)
2310 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2311 do_proc_dointvec_userhz_jiffies_conv,NULL);
2315 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2316 * @table: the sysctl table
2317 * @write: %TRUE if this is a write to the sysctl file
2318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2321 * @ppos: the current position in the file
2323 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2324 * values from/to the user buffer, treated as an ASCII string.
2325 * The values read are assumed to be in 1/1000 seconds, and
2326 * are converted into jiffies.
2328 * Returns 0 on success.
2330 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2331 void __user *buffer, size_t *lenp, loff_t *ppos)
2333 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2334 do_proc_dointvec_ms_jiffies_conv, NULL);
2337 static int proc_do_cad_pid(struct ctl_table *table, int write,
2338 void __user *buffer, size_t *lenp, loff_t *ppos)
2340 struct pid *new_pid;
2341 pid_t tmp;
2342 int r;
2344 tmp = pid_vnr(cad_pid);
2346 r = __do_proc_dointvec(&tmp, table, write, buffer,
2347 lenp, ppos, NULL, NULL);
2348 if (r || !write)
2349 return r;
2351 new_pid = find_get_pid(tmp);
2352 if (!new_pid)
2353 return -ESRCH;
2355 put_pid(xchg(&cad_pid, new_pid));
2356 return 0;
2360 * proc_do_large_bitmap - read/write from/to a large bitmap
2361 * @table: the sysctl table
2362 * @write: %TRUE if this is a write to the sysctl file
2363 * @buffer: the user buffer
2364 * @lenp: the size of the user buffer
2365 * @ppos: file position
2367 * The bitmap is stored at table->data and the bitmap length (in bits)
2368 * in table->maxlen.
2370 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2371 * large bitmaps may be represented in a compact manner. Writing into
2372 * the file will clear the bitmap then update it with the given input.
2374 * Returns 0 on success.
2376 int proc_do_large_bitmap(struct ctl_table *table, int write,
2377 void __user *buffer, size_t *lenp, loff_t *ppos)
2379 int err = 0;
2380 bool first = 1;
2381 size_t left = *lenp;
2382 unsigned long bitmap_len = table->maxlen;
2383 unsigned long *bitmap = (unsigned long *) table->data;
2384 unsigned long *tmp_bitmap = NULL;
2385 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2387 if (!bitmap_len || !left || (*ppos && !write)) {
2388 *lenp = 0;
2389 return 0;
2392 if (write) {
2393 unsigned long page = 0;
2394 char *kbuf;
2396 if (left > PAGE_SIZE - 1)
2397 left = PAGE_SIZE - 1;
2399 page = __get_free_page(GFP_TEMPORARY);
2400 kbuf = (char *) page;
2401 if (!kbuf)
2402 return -ENOMEM;
2403 if (copy_from_user(kbuf, buffer, left)) {
2404 free_page(page);
2405 return -EFAULT;
2407 kbuf[left] = 0;
2409 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2410 GFP_KERNEL);
2411 if (!tmp_bitmap) {
2412 free_page(page);
2413 return -ENOMEM;
2415 proc_skip_char(&kbuf, &left, '\n');
2416 while (!err && left) {
2417 unsigned long val_a, val_b;
2418 bool neg;
2420 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2421 sizeof(tr_a), &c);
2422 if (err)
2423 break;
2424 if (val_a >= bitmap_len || neg) {
2425 err = -EINVAL;
2426 break;
2429 val_b = val_a;
2430 if (left) {
2431 kbuf++;
2432 left--;
2435 if (c == '-') {
2436 err = proc_get_long(&kbuf, &left, &val_b,
2437 &neg, tr_b, sizeof(tr_b),
2438 &c);
2439 if (err)
2440 break;
2441 if (val_b >= bitmap_len || neg ||
2442 val_a > val_b) {
2443 err = -EINVAL;
2444 break;
2446 if (left) {
2447 kbuf++;
2448 left--;
2452 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2453 first = 0;
2454 proc_skip_char(&kbuf, &left, '\n');
2456 free_page(page);
2457 } else {
2458 unsigned long bit_a, bit_b = 0;
2460 while (left) {
2461 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2462 if (bit_a >= bitmap_len)
2463 break;
2464 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2465 bit_a + 1) - 1;
2467 if (!first) {
2468 err = proc_put_char(&buffer, &left, ',');
2469 if (err)
2470 break;
2472 err = proc_put_long(&buffer, &left, bit_a, false);
2473 if (err)
2474 break;
2475 if (bit_a != bit_b) {
2476 err = proc_put_char(&buffer, &left, '-');
2477 if (err)
2478 break;
2479 err = proc_put_long(&buffer, &left, bit_b, false);
2480 if (err)
2481 break;
2484 first = 0; bit_b++;
2486 if (!err)
2487 err = proc_put_char(&buffer, &left, '\n');
2490 if (!err) {
2491 if (write) {
2492 if (*ppos)
2493 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2494 else
2495 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2497 kfree(tmp_bitmap);
2498 *lenp -= left;
2499 *ppos += *lenp;
2500 return 0;
2501 } else {
2502 kfree(tmp_bitmap);
2503 return err;
2507 #else /* CONFIG_PROC_SYSCTL */
2509 int proc_dostring(struct ctl_table *table, int write,
2510 void __user *buffer, size_t *lenp, loff_t *ppos)
2512 return -ENOSYS;
2515 int proc_dointvec(struct ctl_table *table, int write,
2516 void __user *buffer, size_t *lenp, loff_t *ppos)
2518 return -ENOSYS;
2521 int proc_dointvec_minmax(struct ctl_table *table, int write,
2522 void __user *buffer, size_t *lenp, loff_t *ppos)
2524 return -ENOSYS;
2527 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2528 void __user *buffer, size_t *lenp, loff_t *ppos)
2530 return -ENOSYS;
2533 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2534 void __user *buffer, size_t *lenp, loff_t *ppos)
2536 return -ENOSYS;
2539 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2540 void __user *buffer, size_t *lenp, loff_t *ppos)
2542 return -ENOSYS;
2545 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2546 void __user *buffer, size_t *lenp, loff_t *ppos)
2548 return -ENOSYS;
2551 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2552 void __user *buffer,
2553 size_t *lenp, loff_t *ppos)
2555 return -ENOSYS;
2559 #endif /* CONFIG_PROC_SYSCTL */
2562 * No sense putting this after each symbol definition, twice,
2563 * exception granted :-)
2565 EXPORT_SYMBOL(proc_dointvec);
2566 EXPORT_SYMBOL(proc_dointvec_jiffies);
2567 EXPORT_SYMBOL(proc_dointvec_minmax);
2568 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2569 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2570 EXPORT_SYMBOL(proc_dostring);
2571 EXPORT_SYMBOL(proc_doulongvec_minmax);
2572 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);