sysctl extern cleanup: rcu
[deliverable/linux.git] / kernel / sysctl.c
1 /*
2 * sysctl.c: General linux system control interface
3 *
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
19 */
20
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/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.h>
31 #include <linux/fs.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
54 #include <linux/kprobes.h>
55
56 #include <asm/uaccess.h>
57 #include <asm/processor.h>
58
59 #ifdef CONFIG_X86
60 #include <asm/nmi.h>
61 #include <asm/stacktrace.h>
62 #include <asm/io.h>
63 #endif
64
65
66 #if defined(CONFIG_SYSCTL)
67
68 /* External variables not in a header file. */
69 extern int sysctl_overcommit_memory;
70 extern int sysctl_overcommit_ratio;
71 extern int sysctl_panic_on_oom;
72 extern int sysctl_oom_kill_allocating_task;
73 extern int sysctl_oom_dump_tasks;
74 extern int max_threads;
75 extern int core_uses_pid;
76 extern int suid_dumpable;
77 extern char core_pattern[];
78 extern unsigned int core_pipe_limit;
79 extern int pid_max;
80 extern int min_free_kbytes;
81 extern int pid_max_min, pid_max_max;
82 extern int sysctl_drop_caches;
83 extern int percpu_pagelist_fraction;
84 extern int compat_log;
85 extern int latencytop_enabled;
86 extern int sysctl_nr_open_min, sysctl_nr_open_max;
87 #ifndef CONFIG_MMU
88 extern int sysctl_nr_trim_pages;
89 #endif
90 #ifdef CONFIG_BLOCK
91 extern int blk_iopoll_enabled;
92 #endif
93
94 /* Constants used for minimum and maximum */
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty = 60;
97 static int neg_one = -1;
98 #endif
99
100 static int zero;
101 static int __maybe_unused one = 1;
102 static int __maybe_unused two = 2;
103 static unsigned long one_ul = 1;
104 static int one_hundred = 100;
105 #ifdef CONFIG_PRINTK
106 static int ten_thousand = 10000;
107 #endif
108
109 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
110 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
111
112 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
113 static int maxolduid = 65535;
114 static int minolduid;
115 static int min_percpu_pagelist_fract = 8;
116
117 static int ngroups_max = NGROUPS_MAX;
118
119 #ifdef CONFIG_MODULES
120 extern char modprobe_path[];
121 extern int modules_disabled;
122 #endif
123 #ifdef CONFIG_CHR_DEV_SG
124 extern int sg_big_buff;
125 #endif
126
127 #ifdef CONFIG_SPARC
128 #include <asm/system.h>
129 #endif
130
131 #ifdef CONFIG_SPARC64
132 extern int sysctl_tsb_ratio;
133 #endif
134
135 #ifdef __hppa__
136 extern int pwrsw_enabled;
137 extern int unaligned_enabled;
138 #endif
139
140 #ifdef CONFIG_S390
141 #ifdef CONFIG_MATHEMU
142 extern int sysctl_ieee_emulation_warnings;
143 #endif
144 extern int sysctl_userprocess_debug;
145 extern int spin_retry;
146 #endif
147
148 #ifdef CONFIG_BSD_PROCESS_ACCT
149 extern int acct_parm[];
150 #endif
151
152 #ifdef CONFIG_IA64
153 extern int no_unaligned_warning;
154 extern int unaligned_dump_stack;
155 #endif
156
157 extern struct ratelimit_state printk_ratelimit_state;
158
159 #ifdef CONFIG_RT_MUTEXES
160 extern int max_lock_depth;
161 #endif
162
163 #ifdef CONFIG_PROC_SYSCTL
164 static int proc_do_cad_pid(struct ctl_table *table, int write,
165 void __user *buffer, size_t *lenp, loff_t *ppos);
166 static int proc_taint(struct ctl_table *table, int write,
167 void __user *buffer, size_t *lenp, loff_t *ppos);
168 #endif
169
170 static struct ctl_table root_table[];
171 static struct ctl_table_root sysctl_table_root;
172 static struct ctl_table_header root_table_header = {
173 .count = 1,
174 .ctl_table = root_table,
175 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
176 .root = &sysctl_table_root,
177 .set = &sysctl_table_root.default_set,
178 };
179 static struct ctl_table_root sysctl_table_root = {
180 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
181 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
182 };
183
184 static struct ctl_table kern_table[];
185 static struct ctl_table vm_table[];
186 static struct ctl_table fs_table[];
187 static struct ctl_table debug_table[];
188 static struct ctl_table dev_table[];
189 extern struct ctl_table random_table[];
190 #ifdef CONFIG_INOTIFY_USER
191 extern struct ctl_table inotify_table[];
192 #endif
193 #ifdef CONFIG_EPOLL
194 extern struct ctl_table epoll_table[];
195 #endif
196
197 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
198 int sysctl_legacy_va_layout;
199 #endif
200
201 extern int prove_locking;
202 extern int lock_stat;
203
204 /* The default sysctl tables: */
205
206 static struct ctl_table root_table[] = {
207 {
208 .procname = "kernel",
209 .mode = 0555,
210 .child = kern_table,
211 },
212 {
213 .procname = "vm",
214 .mode = 0555,
215 .child = vm_table,
216 },
217 {
218 .procname = "fs",
219 .mode = 0555,
220 .child = fs_table,
221 },
222 {
223 .procname = "debug",
224 .mode = 0555,
225 .child = debug_table,
226 },
227 {
228 .procname = "dev",
229 .mode = 0555,
230 .child = dev_table,
231 },
232 /*
233 * NOTE: do not add new entries to this table unless you have read
234 * Documentation/sysctl/ctl_unnumbered.txt
235 */
236 { }
237 };
238
239 #ifdef CONFIG_SCHED_DEBUG
240 static int min_sched_granularity_ns = 100000; /* 100 usecs */
241 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
242 static int min_wakeup_granularity_ns; /* 0 usecs */
243 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
244 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
245 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
246 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
247 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
248 #endif
249
250 static struct ctl_table kern_table[] = {
251 {
252 .procname = "sched_child_runs_first",
253 .data = &sysctl_sched_child_runs_first,
254 .maxlen = sizeof(unsigned int),
255 .mode = 0644,
256 .proc_handler = proc_dointvec,
257 },
258 #ifdef CONFIG_SCHED_DEBUG
259 {
260 .procname = "sched_min_granularity_ns",
261 .data = &sysctl_sched_min_granularity,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
264 .proc_handler = sched_proc_update_handler,
265 .extra1 = &min_sched_granularity_ns,
266 .extra2 = &max_sched_granularity_ns,
267 },
268 {
269 .procname = "sched_latency_ns",
270 .data = &sysctl_sched_latency,
271 .maxlen = sizeof(unsigned int),
272 .mode = 0644,
273 .proc_handler = sched_proc_update_handler,
274 .extra1 = &min_sched_granularity_ns,
275 .extra2 = &max_sched_granularity_ns,
276 },
277 {
278 .procname = "sched_wakeup_granularity_ns",
279 .data = &sysctl_sched_wakeup_granularity,
280 .maxlen = sizeof(unsigned int),
281 .mode = 0644,
282 .proc_handler = sched_proc_update_handler,
283 .extra1 = &min_wakeup_granularity_ns,
284 .extra2 = &max_wakeup_granularity_ns,
285 },
286 {
287 .procname = "sched_shares_ratelimit",
288 .data = &sysctl_sched_shares_ratelimit,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
291 .proc_handler = sched_proc_update_handler,
292 .extra1 = &min_sched_shares_ratelimit,
293 .extra2 = &max_sched_shares_ratelimit,
294 },
295 {
296 .procname = "sched_tunable_scaling",
297 .data = &sysctl_sched_tunable_scaling,
298 .maxlen = sizeof(enum sched_tunable_scaling),
299 .mode = 0644,
300 .proc_handler = sched_proc_update_handler,
301 .extra1 = &min_sched_tunable_scaling,
302 .extra2 = &max_sched_tunable_scaling,
303 },
304 {
305 .procname = "sched_shares_thresh",
306 .data = &sysctl_sched_shares_thresh,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = proc_dointvec_minmax,
310 .extra1 = &zero,
311 },
312 {
313 .procname = "sched_migration_cost",
314 .data = &sysctl_sched_migration_cost,
315 .maxlen = sizeof(unsigned int),
316 .mode = 0644,
317 .proc_handler = proc_dointvec,
318 },
319 {
320 .procname = "sched_nr_migrate",
321 .data = &sysctl_sched_nr_migrate,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
324 .proc_handler = proc_dointvec,
325 },
326 {
327 .procname = "sched_time_avg",
328 .data = &sysctl_sched_time_avg,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec,
332 },
333 {
334 .procname = "timer_migration",
335 .data = &sysctl_timer_migration,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec_minmax,
339 .extra1 = &zero,
340 .extra2 = &one,
341 },
342 #endif
343 {
344 .procname = "sched_rt_period_us",
345 .data = &sysctl_sched_rt_period,
346 .maxlen = sizeof(unsigned int),
347 .mode = 0644,
348 .proc_handler = sched_rt_handler,
349 },
350 {
351 .procname = "sched_rt_runtime_us",
352 .data = &sysctl_sched_rt_runtime,
353 .maxlen = sizeof(int),
354 .mode = 0644,
355 .proc_handler = sched_rt_handler,
356 },
357 {
358 .procname = "sched_compat_yield",
359 .data = &sysctl_sched_compat_yield,
360 .maxlen = sizeof(unsigned int),
361 .mode = 0644,
362 .proc_handler = proc_dointvec,
363 },
364 #ifdef CONFIG_PROVE_LOCKING
365 {
366 .procname = "prove_locking",
367 .data = &prove_locking,
368 .maxlen = sizeof(int),
369 .mode = 0644,
370 .proc_handler = proc_dointvec,
371 },
372 #endif
373 #ifdef CONFIG_LOCK_STAT
374 {
375 .procname = "lock_stat",
376 .data = &lock_stat,
377 .maxlen = sizeof(int),
378 .mode = 0644,
379 .proc_handler = proc_dointvec,
380 },
381 #endif
382 {
383 .procname = "panic",
384 .data = &panic_timeout,
385 .maxlen = sizeof(int),
386 .mode = 0644,
387 .proc_handler = proc_dointvec,
388 },
389 {
390 .procname = "core_uses_pid",
391 .data = &core_uses_pid,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = proc_dointvec,
395 },
396 {
397 .procname = "core_pattern",
398 .data = core_pattern,
399 .maxlen = CORENAME_MAX_SIZE,
400 .mode = 0644,
401 .proc_handler = proc_dostring,
402 },
403 {
404 .procname = "core_pipe_limit",
405 .data = &core_pipe_limit,
406 .maxlen = sizeof(unsigned int),
407 .mode = 0644,
408 .proc_handler = proc_dointvec,
409 },
410 #ifdef CONFIG_PROC_SYSCTL
411 {
412 .procname = "tainted",
413 .maxlen = sizeof(long),
414 .mode = 0644,
415 .proc_handler = proc_taint,
416 },
417 #endif
418 #ifdef CONFIG_LATENCYTOP
419 {
420 .procname = "latencytop",
421 .data = &latencytop_enabled,
422 .maxlen = sizeof(int),
423 .mode = 0644,
424 .proc_handler = proc_dointvec,
425 },
426 #endif
427 #ifdef CONFIG_BLK_DEV_INITRD
428 {
429 .procname = "real-root-dev",
430 .data = &real_root_dev,
431 .maxlen = sizeof(int),
432 .mode = 0644,
433 .proc_handler = proc_dointvec,
434 },
435 #endif
436 {
437 .procname = "print-fatal-signals",
438 .data = &print_fatal_signals,
439 .maxlen = sizeof(int),
440 .mode = 0644,
441 .proc_handler = proc_dointvec,
442 },
443 #ifdef CONFIG_SPARC
444 {
445 .procname = "reboot-cmd",
446 .data = reboot_command,
447 .maxlen = 256,
448 .mode = 0644,
449 .proc_handler = proc_dostring,
450 },
451 {
452 .procname = "stop-a",
453 .data = &stop_a_enabled,
454 .maxlen = sizeof (int),
455 .mode = 0644,
456 .proc_handler = proc_dointvec,
457 },
458 {
459 .procname = "scons-poweroff",
460 .data = &scons_pwroff,
461 .maxlen = sizeof (int),
462 .mode = 0644,
463 .proc_handler = proc_dointvec,
464 },
465 #endif
466 #ifdef CONFIG_SPARC64
467 {
468 .procname = "tsb-ratio",
469 .data = &sysctl_tsb_ratio,
470 .maxlen = sizeof (int),
471 .mode = 0644,
472 .proc_handler = proc_dointvec,
473 },
474 #endif
475 #ifdef __hppa__
476 {
477 .procname = "soft-power",
478 .data = &pwrsw_enabled,
479 .maxlen = sizeof (int),
480 .mode = 0644,
481 .proc_handler = proc_dointvec,
482 },
483 {
484 .procname = "unaligned-trap",
485 .data = &unaligned_enabled,
486 .maxlen = sizeof (int),
487 .mode = 0644,
488 .proc_handler = proc_dointvec,
489 },
490 #endif
491 {
492 .procname = "ctrl-alt-del",
493 .data = &C_A_D,
494 .maxlen = sizeof(int),
495 .mode = 0644,
496 .proc_handler = proc_dointvec,
497 },
498 #ifdef CONFIG_FUNCTION_TRACER
499 {
500 .procname = "ftrace_enabled",
501 .data = &ftrace_enabled,
502 .maxlen = sizeof(int),
503 .mode = 0644,
504 .proc_handler = ftrace_enable_sysctl,
505 },
506 #endif
507 #ifdef CONFIG_STACK_TRACER
508 {
509 .procname = "stack_tracer_enabled",
510 .data = &stack_tracer_enabled,
511 .maxlen = sizeof(int),
512 .mode = 0644,
513 .proc_handler = stack_trace_sysctl,
514 },
515 #endif
516 #ifdef CONFIG_TRACING
517 {
518 .procname = "ftrace_dump_on_oops",
519 .data = &ftrace_dump_on_oops,
520 .maxlen = sizeof(int),
521 .mode = 0644,
522 .proc_handler = proc_dointvec,
523 },
524 #endif
525 #ifdef CONFIG_MODULES
526 {
527 .procname = "modprobe",
528 .data = &modprobe_path,
529 .maxlen = KMOD_PATH_LEN,
530 .mode = 0644,
531 .proc_handler = proc_dostring,
532 },
533 {
534 .procname = "modules_disabled",
535 .data = &modules_disabled,
536 .maxlen = sizeof(int),
537 .mode = 0644,
538 /* only handle a transition from default "0" to "1" */
539 .proc_handler = proc_dointvec_minmax,
540 .extra1 = &one,
541 .extra2 = &one,
542 },
543 #endif
544 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
545 {
546 .procname = "hotplug",
547 .data = &uevent_helper,
548 .maxlen = UEVENT_HELPER_PATH_LEN,
549 .mode = 0644,
550 .proc_handler = proc_dostring,
551 },
552 #endif
553 #ifdef CONFIG_CHR_DEV_SG
554 {
555 .procname = "sg-big-buff",
556 .data = &sg_big_buff,
557 .maxlen = sizeof (int),
558 .mode = 0444,
559 .proc_handler = proc_dointvec,
560 },
561 #endif
562 #ifdef CONFIG_BSD_PROCESS_ACCT
563 {
564 .procname = "acct",
565 .data = &acct_parm,
566 .maxlen = 3*sizeof(int),
567 .mode = 0644,
568 .proc_handler = proc_dointvec,
569 },
570 #endif
571 #ifdef CONFIG_MAGIC_SYSRQ
572 {
573 .procname = "sysrq",
574 .data = &__sysrq_enabled,
575 .maxlen = sizeof (int),
576 .mode = 0644,
577 .proc_handler = proc_dointvec,
578 },
579 #endif
580 #ifdef CONFIG_PROC_SYSCTL
581 {
582 .procname = "cad_pid",
583 .data = NULL,
584 .maxlen = sizeof (int),
585 .mode = 0600,
586 .proc_handler = proc_do_cad_pid,
587 },
588 #endif
589 {
590 .procname = "threads-max",
591 .data = &max_threads,
592 .maxlen = sizeof(int),
593 .mode = 0644,
594 .proc_handler = proc_dointvec,
595 },
596 {
597 .procname = "random",
598 .mode = 0555,
599 .child = random_table,
600 },
601 {
602 .procname = "overflowuid",
603 .data = &overflowuid,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = proc_dointvec_minmax,
607 .extra1 = &minolduid,
608 .extra2 = &maxolduid,
609 },
610 {
611 .procname = "overflowgid",
612 .data = &overflowgid,
613 .maxlen = sizeof(int),
614 .mode = 0644,
615 .proc_handler = proc_dointvec_minmax,
616 .extra1 = &minolduid,
617 .extra2 = &maxolduid,
618 },
619 #ifdef CONFIG_S390
620 #ifdef CONFIG_MATHEMU
621 {
622 .procname = "ieee_emulation_warnings",
623 .data = &sysctl_ieee_emulation_warnings,
624 .maxlen = sizeof(int),
625 .mode = 0644,
626 .proc_handler = proc_dointvec,
627 },
628 #endif
629 {
630 .procname = "userprocess_debug",
631 .data = &sysctl_userprocess_debug,
632 .maxlen = sizeof(int),
633 .mode = 0644,
634 .proc_handler = proc_dointvec,
635 },
636 #endif
637 {
638 .procname = "pid_max",
639 .data = &pid_max,
640 .maxlen = sizeof (int),
641 .mode = 0644,
642 .proc_handler = proc_dointvec_minmax,
643 .extra1 = &pid_max_min,
644 .extra2 = &pid_max_max,
645 },
646 {
647 .procname = "panic_on_oops",
648 .data = &panic_on_oops,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 .proc_handler = proc_dointvec,
652 },
653 #if defined CONFIG_PRINTK
654 {
655 .procname = "printk",
656 .data = &console_loglevel,
657 .maxlen = 4*sizeof(int),
658 .mode = 0644,
659 .proc_handler = proc_dointvec,
660 },
661 {
662 .procname = "printk_ratelimit",
663 .data = &printk_ratelimit_state.interval,
664 .maxlen = sizeof(int),
665 .mode = 0644,
666 .proc_handler = proc_dointvec_jiffies,
667 },
668 {
669 .procname = "printk_ratelimit_burst",
670 .data = &printk_ratelimit_state.burst,
671 .maxlen = sizeof(int),
672 .mode = 0644,
673 .proc_handler = proc_dointvec,
674 },
675 {
676 .procname = "printk_delay",
677 .data = &printk_delay_msec,
678 .maxlen = sizeof(int),
679 .mode = 0644,
680 .proc_handler = proc_dointvec_minmax,
681 .extra1 = &zero,
682 .extra2 = &ten_thousand,
683 },
684 #endif
685 {
686 .procname = "ngroups_max",
687 .data = &ngroups_max,
688 .maxlen = sizeof (int),
689 .mode = 0444,
690 .proc_handler = proc_dointvec,
691 },
692 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
693 {
694 .procname = "unknown_nmi_panic",
695 .data = &unknown_nmi_panic,
696 .maxlen = sizeof (int),
697 .mode = 0644,
698 .proc_handler = proc_dointvec,
699 },
700 {
701 .procname = "nmi_watchdog",
702 .data = &nmi_watchdog_enabled,
703 .maxlen = sizeof (int),
704 .mode = 0644,
705 .proc_handler = proc_nmi_enabled,
706 },
707 #endif
708 #if defined(CONFIG_X86)
709 {
710 .procname = "panic_on_unrecovered_nmi",
711 .data = &panic_on_unrecovered_nmi,
712 .maxlen = sizeof(int),
713 .mode = 0644,
714 .proc_handler = proc_dointvec,
715 },
716 {
717 .procname = "panic_on_io_nmi",
718 .data = &panic_on_io_nmi,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = proc_dointvec,
722 },
723 {
724 .procname = "bootloader_type",
725 .data = &bootloader_type,
726 .maxlen = sizeof (int),
727 .mode = 0444,
728 .proc_handler = proc_dointvec,
729 },
730 {
731 .procname = "bootloader_version",
732 .data = &bootloader_version,
733 .maxlen = sizeof (int),
734 .mode = 0444,
735 .proc_handler = proc_dointvec,
736 },
737 {
738 .procname = "kstack_depth_to_print",
739 .data = &kstack_depth_to_print,
740 .maxlen = sizeof(int),
741 .mode = 0644,
742 .proc_handler = proc_dointvec,
743 },
744 {
745 .procname = "io_delay_type",
746 .data = &io_delay_type,
747 .maxlen = sizeof(int),
748 .mode = 0644,
749 .proc_handler = proc_dointvec,
750 },
751 #endif
752 #if defined(CONFIG_MMU)
753 {
754 .procname = "randomize_va_space",
755 .data = &randomize_va_space,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = proc_dointvec,
759 },
760 #endif
761 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
762 {
763 .procname = "spin_retry",
764 .data = &spin_retry,
765 .maxlen = sizeof (int),
766 .mode = 0644,
767 .proc_handler = proc_dointvec,
768 },
769 #endif
770 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
771 {
772 .procname = "acpi_video_flags",
773 .data = &acpi_realmode_flags,
774 .maxlen = sizeof (unsigned long),
775 .mode = 0644,
776 .proc_handler = proc_doulongvec_minmax,
777 },
778 #endif
779 #ifdef CONFIG_IA64
780 {
781 .procname = "ignore-unaligned-usertrap",
782 .data = &no_unaligned_warning,
783 .maxlen = sizeof (int),
784 .mode = 0644,
785 .proc_handler = proc_dointvec,
786 },
787 {
788 .procname = "unaligned-dump-stack",
789 .data = &unaligned_dump_stack,
790 .maxlen = sizeof (int),
791 .mode = 0644,
792 .proc_handler = proc_dointvec,
793 },
794 #endif
795 #ifdef CONFIG_DETECT_SOFTLOCKUP
796 {
797 .procname = "softlockup_panic",
798 .data = &softlockup_panic,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = proc_dointvec_minmax,
802 .extra1 = &zero,
803 .extra2 = &one,
804 },
805 {
806 .procname = "softlockup_thresh",
807 .data = &softlockup_thresh,
808 .maxlen = sizeof(int),
809 .mode = 0644,
810 .proc_handler = proc_dosoftlockup_thresh,
811 .extra1 = &neg_one,
812 .extra2 = &sixty,
813 },
814 #endif
815 #ifdef CONFIG_DETECT_HUNG_TASK
816 {
817 .procname = "hung_task_panic",
818 .data = &sysctl_hung_task_panic,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = proc_dointvec_minmax,
822 .extra1 = &zero,
823 .extra2 = &one,
824 },
825 {
826 .procname = "hung_task_check_count",
827 .data = &sysctl_hung_task_check_count,
828 .maxlen = sizeof(unsigned long),
829 .mode = 0644,
830 .proc_handler = proc_doulongvec_minmax,
831 },
832 {
833 .procname = "hung_task_timeout_secs",
834 .data = &sysctl_hung_task_timeout_secs,
835 .maxlen = sizeof(unsigned long),
836 .mode = 0644,
837 .proc_handler = proc_dohung_task_timeout_secs,
838 },
839 {
840 .procname = "hung_task_warnings",
841 .data = &sysctl_hung_task_warnings,
842 .maxlen = sizeof(unsigned long),
843 .mode = 0644,
844 .proc_handler = proc_doulongvec_minmax,
845 },
846 #endif
847 #ifdef CONFIG_COMPAT
848 {
849 .procname = "compat-log",
850 .data = &compat_log,
851 .maxlen = sizeof (int),
852 .mode = 0644,
853 .proc_handler = proc_dointvec,
854 },
855 #endif
856 #ifdef CONFIG_RT_MUTEXES
857 {
858 .procname = "max_lock_depth",
859 .data = &max_lock_depth,
860 .maxlen = sizeof(int),
861 .mode = 0644,
862 .proc_handler = proc_dointvec,
863 },
864 #endif
865 {
866 .procname = "poweroff_cmd",
867 .data = &poweroff_cmd,
868 .maxlen = POWEROFF_CMD_PATH_LEN,
869 .mode = 0644,
870 .proc_handler = proc_dostring,
871 },
872 #ifdef CONFIG_KEYS
873 {
874 .procname = "keys",
875 .mode = 0555,
876 .child = key_sysctls,
877 },
878 #endif
879 #ifdef CONFIG_RCU_TORTURE_TEST
880 {
881 .procname = "rcutorture_runnable",
882 .data = &rcutorture_runnable,
883 .maxlen = sizeof(int),
884 .mode = 0644,
885 .proc_handler = proc_dointvec,
886 },
887 #endif
888 #ifdef CONFIG_SLOW_WORK
889 {
890 .procname = "slow-work",
891 .mode = 0555,
892 .child = slow_work_sysctls,
893 },
894 #endif
895 #ifdef CONFIG_PERF_EVENTS
896 {
897 .procname = "perf_event_paranoid",
898 .data = &sysctl_perf_event_paranoid,
899 .maxlen = sizeof(sysctl_perf_event_paranoid),
900 .mode = 0644,
901 .proc_handler = proc_dointvec,
902 },
903 {
904 .procname = "perf_event_mlock_kb",
905 .data = &sysctl_perf_event_mlock,
906 .maxlen = sizeof(sysctl_perf_event_mlock),
907 .mode = 0644,
908 .proc_handler = proc_dointvec,
909 },
910 {
911 .procname = "perf_event_max_sample_rate",
912 .data = &sysctl_perf_event_sample_rate,
913 .maxlen = sizeof(sysctl_perf_event_sample_rate),
914 .mode = 0644,
915 .proc_handler = proc_dointvec,
916 },
917 #endif
918 #ifdef CONFIG_KMEMCHECK
919 {
920 .procname = "kmemcheck",
921 .data = &kmemcheck_enabled,
922 .maxlen = sizeof(int),
923 .mode = 0644,
924 .proc_handler = proc_dointvec,
925 },
926 #endif
927 #ifdef CONFIG_BLOCK
928 {
929 .procname = "blk_iopoll",
930 .data = &blk_iopoll_enabled,
931 .maxlen = sizeof(int),
932 .mode = 0644,
933 .proc_handler = proc_dointvec,
934 },
935 #endif
936 /*
937 * NOTE: do not add new entries to this table unless you have read
938 * Documentation/sysctl/ctl_unnumbered.txt
939 */
940 { }
941 };
942
943 static struct ctl_table vm_table[] = {
944 {
945 .procname = "overcommit_memory",
946 .data = &sysctl_overcommit_memory,
947 .maxlen = sizeof(sysctl_overcommit_memory),
948 .mode = 0644,
949 .proc_handler = proc_dointvec,
950 },
951 {
952 .procname = "panic_on_oom",
953 .data = &sysctl_panic_on_oom,
954 .maxlen = sizeof(sysctl_panic_on_oom),
955 .mode = 0644,
956 .proc_handler = proc_dointvec,
957 },
958 {
959 .procname = "oom_kill_allocating_task",
960 .data = &sysctl_oom_kill_allocating_task,
961 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
962 .mode = 0644,
963 .proc_handler = proc_dointvec,
964 },
965 {
966 .procname = "oom_dump_tasks",
967 .data = &sysctl_oom_dump_tasks,
968 .maxlen = sizeof(sysctl_oom_dump_tasks),
969 .mode = 0644,
970 .proc_handler = proc_dointvec,
971 },
972 {
973 .procname = "overcommit_ratio",
974 .data = &sysctl_overcommit_ratio,
975 .maxlen = sizeof(sysctl_overcommit_ratio),
976 .mode = 0644,
977 .proc_handler = proc_dointvec,
978 },
979 {
980 .procname = "page-cluster",
981 .data = &page_cluster,
982 .maxlen = sizeof(int),
983 .mode = 0644,
984 .proc_handler = proc_dointvec,
985 },
986 {
987 .procname = "dirty_background_ratio",
988 .data = &dirty_background_ratio,
989 .maxlen = sizeof(dirty_background_ratio),
990 .mode = 0644,
991 .proc_handler = dirty_background_ratio_handler,
992 .extra1 = &zero,
993 .extra2 = &one_hundred,
994 },
995 {
996 .procname = "dirty_background_bytes",
997 .data = &dirty_background_bytes,
998 .maxlen = sizeof(dirty_background_bytes),
999 .mode = 0644,
1000 .proc_handler = dirty_background_bytes_handler,
1001 .extra1 = &one_ul,
1002 },
1003 {
1004 .procname = "dirty_ratio",
1005 .data = &vm_dirty_ratio,
1006 .maxlen = sizeof(vm_dirty_ratio),
1007 .mode = 0644,
1008 .proc_handler = dirty_ratio_handler,
1009 .extra1 = &zero,
1010 .extra2 = &one_hundred,
1011 },
1012 {
1013 .procname = "dirty_bytes",
1014 .data = &vm_dirty_bytes,
1015 .maxlen = sizeof(vm_dirty_bytes),
1016 .mode = 0644,
1017 .proc_handler = dirty_bytes_handler,
1018 .extra1 = &dirty_bytes_min,
1019 },
1020 {
1021 .procname = "dirty_writeback_centisecs",
1022 .data = &dirty_writeback_interval,
1023 .maxlen = sizeof(dirty_writeback_interval),
1024 .mode = 0644,
1025 .proc_handler = dirty_writeback_centisecs_handler,
1026 },
1027 {
1028 .procname = "dirty_expire_centisecs",
1029 .data = &dirty_expire_interval,
1030 .maxlen = sizeof(dirty_expire_interval),
1031 .mode = 0644,
1032 .proc_handler = proc_dointvec,
1033 },
1034 {
1035 .procname = "nr_pdflush_threads",
1036 .data = &nr_pdflush_threads,
1037 .maxlen = sizeof nr_pdflush_threads,
1038 .mode = 0444 /* read-only*/,
1039 .proc_handler = proc_dointvec,
1040 },
1041 {
1042 .procname = "swappiness",
1043 .data = &vm_swappiness,
1044 .maxlen = sizeof(vm_swappiness),
1045 .mode = 0644,
1046 .proc_handler = proc_dointvec_minmax,
1047 .extra1 = &zero,
1048 .extra2 = &one_hundred,
1049 },
1050 #ifdef CONFIG_HUGETLB_PAGE
1051 {
1052 .procname = "nr_hugepages",
1053 .data = NULL,
1054 .maxlen = sizeof(unsigned long),
1055 .mode = 0644,
1056 .proc_handler = hugetlb_sysctl_handler,
1057 .extra1 = (void *)&hugetlb_zero,
1058 .extra2 = (void *)&hugetlb_infinity,
1059 },
1060 #ifdef CONFIG_NUMA
1061 {
1062 .procname = "nr_hugepages_mempolicy",
1063 .data = NULL,
1064 .maxlen = sizeof(unsigned long),
1065 .mode = 0644,
1066 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1067 .extra1 = (void *)&hugetlb_zero,
1068 .extra2 = (void *)&hugetlb_infinity,
1069 },
1070 #endif
1071 {
1072 .procname = "hugetlb_shm_group",
1073 .data = &sysctl_hugetlb_shm_group,
1074 .maxlen = sizeof(gid_t),
1075 .mode = 0644,
1076 .proc_handler = proc_dointvec,
1077 },
1078 {
1079 .procname = "hugepages_treat_as_movable",
1080 .data = &hugepages_treat_as_movable,
1081 .maxlen = sizeof(int),
1082 .mode = 0644,
1083 .proc_handler = hugetlb_treat_movable_handler,
1084 },
1085 {
1086 .procname = "nr_overcommit_hugepages",
1087 .data = NULL,
1088 .maxlen = sizeof(unsigned long),
1089 .mode = 0644,
1090 .proc_handler = hugetlb_overcommit_handler,
1091 .extra1 = (void *)&hugetlb_zero,
1092 .extra2 = (void *)&hugetlb_infinity,
1093 },
1094 #endif
1095 {
1096 .procname = "lowmem_reserve_ratio",
1097 .data = &sysctl_lowmem_reserve_ratio,
1098 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1099 .mode = 0644,
1100 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1101 },
1102 {
1103 .procname = "drop_caches",
1104 .data = &sysctl_drop_caches,
1105 .maxlen = sizeof(int),
1106 .mode = 0644,
1107 .proc_handler = drop_caches_sysctl_handler,
1108 },
1109 {
1110 .procname = "min_free_kbytes",
1111 .data = &min_free_kbytes,
1112 .maxlen = sizeof(min_free_kbytes),
1113 .mode = 0644,
1114 .proc_handler = min_free_kbytes_sysctl_handler,
1115 .extra1 = &zero,
1116 },
1117 {
1118 .procname = "percpu_pagelist_fraction",
1119 .data = &percpu_pagelist_fraction,
1120 .maxlen = sizeof(percpu_pagelist_fraction),
1121 .mode = 0644,
1122 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1123 .extra1 = &min_percpu_pagelist_fract,
1124 },
1125 #ifdef CONFIG_MMU
1126 {
1127 .procname = "max_map_count",
1128 .data = &sysctl_max_map_count,
1129 .maxlen = sizeof(sysctl_max_map_count),
1130 .mode = 0644,
1131 .proc_handler = proc_dointvec_minmax,
1132 .extra1 = &zero,
1133 },
1134 #else
1135 {
1136 .procname = "nr_trim_pages",
1137 .data = &sysctl_nr_trim_pages,
1138 .maxlen = sizeof(sysctl_nr_trim_pages),
1139 .mode = 0644,
1140 .proc_handler = proc_dointvec_minmax,
1141 .extra1 = &zero,
1142 },
1143 #endif
1144 {
1145 .procname = "laptop_mode",
1146 .data = &laptop_mode,
1147 .maxlen = sizeof(laptop_mode),
1148 .mode = 0644,
1149 .proc_handler = proc_dointvec_jiffies,
1150 },
1151 {
1152 .procname = "block_dump",
1153 .data = &block_dump,
1154 .maxlen = sizeof(block_dump),
1155 .mode = 0644,
1156 .proc_handler = proc_dointvec,
1157 .extra1 = &zero,
1158 },
1159 {
1160 .procname = "vfs_cache_pressure",
1161 .data = &sysctl_vfs_cache_pressure,
1162 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1163 .mode = 0644,
1164 .proc_handler = proc_dointvec,
1165 .extra1 = &zero,
1166 },
1167 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1168 {
1169 .procname = "legacy_va_layout",
1170 .data = &sysctl_legacy_va_layout,
1171 .maxlen = sizeof(sysctl_legacy_va_layout),
1172 .mode = 0644,
1173 .proc_handler = proc_dointvec,
1174 .extra1 = &zero,
1175 },
1176 #endif
1177 #ifdef CONFIG_NUMA
1178 {
1179 .procname = "zone_reclaim_mode",
1180 .data = &zone_reclaim_mode,
1181 .maxlen = sizeof(zone_reclaim_mode),
1182 .mode = 0644,
1183 .proc_handler = proc_dointvec,
1184 .extra1 = &zero,
1185 },
1186 {
1187 .procname = "min_unmapped_ratio",
1188 .data = &sysctl_min_unmapped_ratio,
1189 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1190 .mode = 0644,
1191 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1192 .extra1 = &zero,
1193 .extra2 = &one_hundred,
1194 },
1195 {
1196 .procname = "min_slab_ratio",
1197 .data = &sysctl_min_slab_ratio,
1198 .maxlen = sizeof(sysctl_min_slab_ratio),
1199 .mode = 0644,
1200 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1201 .extra1 = &zero,
1202 .extra2 = &one_hundred,
1203 },
1204 #endif
1205 #ifdef CONFIG_SMP
1206 {
1207 .procname = "stat_interval",
1208 .data = &sysctl_stat_interval,
1209 .maxlen = sizeof(sysctl_stat_interval),
1210 .mode = 0644,
1211 .proc_handler = proc_dointvec_jiffies,
1212 },
1213 #endif
1214 #ifdef CONFIG_MMU
1215 {
1216 .procname = "mmap_min_addr",
1217 .data = &dac_mmap_min_addr,
1218 .maxlen = sizeof(unsigned long),
1219 .mode = 0644,
1220 .proc_handler = mmap_min_addr_handler,
1221 },
1222 #endif
1223 #ifdef CONFIG_NUMA
1224 {
1225 .procname = "numa_zonelist_order",
1226 .data = &numa_zonelist_order,
1227 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1228 .mode = 0644,
1229 .proc_handler = numa_zonelist_order_handler,
1230 },
1231 #endif
1232 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1233 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1234 {
1235 .procname = "vdso_enabled",
1236 .data = &vdso_enabled,
1237 .maxlen = sizeof(vdso_enabled),
1238 .mode = 0644,
1239 .proc_handler = proc_dointvec,
1240 .extra1 = &zero,
1241 },
1242 #endif
1243 #ifdef CONFIG_HIGHMEM
1244 {
1245 .procname = "highmem_is_dirtyable",
1246 .data = &vm_highmem_is_dirtyable,
1247 .maxlen = sizeof(vm_highmem_is_dirtyable),
1248 .mode = 0644,
1249 .proc_handler = proc_dointvec_minmax,
1250 .extra1 = &zero,
1251 .extra2 = &one,
1252 },
1253 #endif
1254 {
1255 .procname = "scan_unevictable_pages",
1256 .data = &scan_unevictable_pages,
1257 .maxlen = sizeof(scan_unevictable_pages),
1258 .mode = 0644,
1259 .proc_handler = scan_unevictable_handler,
1260 },
1261 #ifdef CONFIG_MEMORY_FAILURE
1262 {
1263 .procname = "memory_failure_early_kill",
1264 .data = &sysctl_memory_failure_early_kill,
1265 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1266 .mode = 0644,
1267 .proc_handler = proc_dointvec_minmax,
1268 .extra1 = &zero,
1269 .extra2 = &one,
1270 },
1271 {
1272 .procname = "memory_failure_recovery",
1273 .data = &sysctl_memory_failure_recovery,
1274 .maxlen = sizeof(sysctl_memory_failure_recovery),
1275 .mode = 0644,
1276 .proc_handler = proc_dointvec_minmax,
1277 .extra1 = &zero,
1278 .extra2 = &one,
1279 },
1280 #endif
1281
1282 /*
1283 * NOTE: do not add new entries to this table unless you have read
1284 * Documentation/sysctl/ctl_unnumbered.txt
1285 */
1286 { }
1287 };
1288
1289 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1290 static struct ctl_table binfmt_misc_table[] = {
1291 { }
1292 };
1293 #endif
1294
1295 static struct ctl_table fs_table[] = {
1296 {
1297 .procname = "inode-nr",
1298 .data = &inodes_stat,
1299 .maxlen = 2*sizeof(int),
1300 .mode = 0444,
1301 .proc_handler = proc_dointvec,
1302 },
1303 {
1304 .procname = "inode-state",
1305 .data = &inodes_stat,
1306 .maxlen = 7*sizeof(int),
1307 .mode = 0444,
1308 .proc_handler = proc_dointvec,
1309 },
1310 {
1311 .procname = "file-nr",
1312 .data = &files_stat,
1313 .maxlen = 3*sizeof(int),
1314 .mode = 0444,
1315 .proc_handler = proc_nr_files,
1316 },
1317 {
1318 .procname = "file-max",
1319 .data = &files_stat.max_files,
1320 .maxlen = sizeof(int),
1321 .mode = 0644,
1322 .proc_handler = proc_dointvec,
1323 },
1324 {
1325 .procname = "nr_open",
1326 .data = &sysctl_nr_open,
1327 .maxlen = sizeof(int),
1328 .mode = 0644,
1329 .proc_handler = proc_dointvec_minmax,
1330 .extra1 = &sysctl_nr_open_min,
1331 .extra2 = &sysctl_nr_open_max,
1332 },
1333 {
1334 .procname = "dentry-state",
1335 .data = &dentry_stat,
1336 .maxlen = 6*sizeof(int),
1337 .mode = 0444,
1338 .proc_handler = proc_dointvec,
1339 },
1340 {
1341 .procname = "overflowuid",
1342 .data = &fs_overflowuid,
1343 .maxlen = sizeof(int),
1344 .mode = 0644,
1345 .proc_handler = proc_dointvec_minmax,
1346 .extra1 = &minolduid,
1347 .extra2 = &maxolduid,
1348 },
1349 {
1350 .procname = "overflowgid",
1351 .data = &fs_overflowgid,
1352 .maxlen = sizeof(int),
1353 .mode = 0644,
1354 .proc_handler = proc_dointvec_minmax,
1355 .extra1 = &minolduid,
1356 .extra2 = &maxolduid,
1357 },
1358 #ifdef CONFIG_FILE_LOCKING
1359 {
1360 .procname = "leases-enable",
1361 .data = &leases_enable,
1362 .maxlen = sizeof(int),
1363 .mode = 0644,
1364 .proc_handler = proc_dointvec,
1365 },
1366 #endif
1367 #ifdef CONFIG_DNOTIFY
1368 {
1369 .procname = "dir-notify-enable",
1370 .data = &dir_notify_enable,
1371 .maxlen = sizeof(int),
1372 .mode = 0644,
1373 .proc_handler = proc_dointvec,
1374 },
1375 #endif
1376 #ifdef CONFIG_MMU
1377 #ifdef CONFIG_FILE_LOCKING
1378 {
1379 .procname = "lease-break-time",
1380 .data = &lease_break_time,
1381 .maxlen = sizeof(int),
1382 .mode = 0644,
1383 .proc_handler = proc_dointvec,
1384 },
1385 #endif
1386 #ifdef CONFIG_AIO
1387 {
1388 .procname = "aio-nr",
1389 .data = &aio_nr,
1390 .maxlen = sizeof(aio_nr),
1391 .mode = 0444,
1392 .proc_handler = proc_doulongvec_minmax,
1393 },
1394 {
1395 .procname = "aio-max-nr",
1396 .data = &aio_max_nr,
1397 .maxlen = sizeof(aio_max_nr),
1398 .mode = 0644,
1399 .proc_handler = proc_doulongvec_minmax,
1400 },
1401 #endif /* CONFIG_AIO */
1402 #ifdef CONFIG_INOTIFY_USER
1403 {
1404 .procname = "inotify",
1405 .mode = 0555,
1406 .child = inotify_table,
1407 },
1408 #endif
1409 #ifdef CONFIG_EPOLL
1410 {
1411 .procname = "epoll",
1412 .mode = 0555,
1413 .child = epoll_table,
1414 },
1415 #endif
1416 #endif
1417 {
1418 .procname = "suid_dumpable",
1419 .data = &suid_dumpable,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
1422 .proc_handler = proc_dointvec_minmax,
1423 .extra1 = &zero,
1424 .extra2 = &two,
1425 },
1426 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1427 {
1428 .procname = "binfmt_misc",
1429 .mode = 0555,
1430 .child = binfmt_misc_table,
1431 },
1432 #endif
1433 /*
1434 * NOTE: do not add new entries to this table unless you have read
1435 * Documentation/sysctl/ctl_unnumbered.txt
1436 */
1437 { }
1438 };
1439
1440 static struct ctl_table debug_table[] = {
1441 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
1442 {
1443 .procname = "exception-trace",
1444 .data = &show_unhandled_signals,
1445 .maxlen = sizeof(int),
1446 .mode = 0644,
1447 .proc_handler = proc_dointvec
1448 },
1449 #endif
1450 #if defined(CONFIG_OPTPROBES)
1451 {
1452 .procname = "kprobes-optimization",
1453 .data = &sysctl_kprobes_optimization,
1454 .maxlen = sizeof(int),
1455 .mode = 0644,
1456 .proc_handler = proc_kprobes_optimization_handler,
1457 .extra1 = &zero,
1458 .extra2 = &one,
1459 },
1460 #endif
1461 { }
1462 };
1463
1464 static struct ctl_table dev_table[] = {
1465 { }
1466 };
1467
1468 static DEFINE_SPINLOCK(sysctl_lock);
1469
1470 /* called under sysctl_lock */
1471 static int use_table(struct ctl_table_header *p)
1472 {
1473 if (unlikely(p->unregistering))
1474 return 0;
1475 p->used++;
1476 return 1;
1477 }
1478
1479 /* called under sysctl_lock */
1480 static void unuse_table(struct ctl_table_header *p)
1481 {
1482 if (!--p->used)
1483 if (unlikely(p->unregistering))
1484 complete(p->unregistering);
1485 }
1486
1487 /* called under sysctl_lock, will reacquire if has to wait */
1488 static void start_unregistering(struct ctl_table_header *p)
1489 {
1490 /*
1491 * if p->used is 0, nobody will ever touch that entry again;
1492 * we'll eliminate all paths to it before dropping sysctl_lock
1493 */
1494 if (unlikely(p->used)) {
1495 struct completion wait;
1496 init_completion(&wait);
1497 p->unregistering = &wait;
1498 spin_unlock(&sysctl_lock);
1499 wait_for_completion(&wait);
1500 spin_lock(&sysctl_lock);
1501 } else {
1502 /* anything non-NULL; we'll never dereference it */
1503 p->unregistering = ERR_PTR(-EINVAL);
1504 }
1505 /*
1506 * do not remove from the list until nobody holds it; walking the
1507 * list in do_sysctl() relies on that.
1508 */
1509 list_del_init(&p->ctl_entry);
1510 }
1511
1512 void sysctl_head_get(struct ctl_table_header *head)
1513 {
1514 spin_lock(&sysctl_lock);
1515 head->count++;
1516 spin_unlock(&sysctl_lock);
1517 }
1518
1519 void sysctl_head_put(struct ctl_table_header *head)
1520 {
1521 spin_lock(&sysctl_lock);
1522 if (!--head->count)
1523 kfree(head);
1524 spin_unlock(&sysctl_lock);
1525 }
1526
1527 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1528 {
1529 if (!head)
1530 BUG();
1531 spin_lock(&sysctl_lock);
1532 if (!use_table(head))
1533 head = ERR_PTR(-ENOENT);
1534 spin_unlock(&sysctl_lock);
1535 return head;
1536 }
1537
1538 void sysctl_head_finish(struct ctl_table_header *head)
1539 {
1540 if (!head)
1541 return;
1542 spin_lock(&sysctl_lock);
1543 unuse_table(head);
1544 spin_unlock(&sysctl_lock);
1545 }
1546
1547 static struct ctl_table_set *
1548 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1549 {
1550 struct ctl_table_set *set = &root->default_set;
1551 if (root->lookup)
1552 set = root->lookup(root, namespaces);
1553 return set;
1554 }
1555
1556 static struct list_head *
1557 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1558 {
1559 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1560 return &set->list;
1561 }
1562
1563 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1564 struct ctl_table_header *prev)
1565 {
1566 struct ctl_table_root *root;
1567 struct list_head *header_list;
1568 struct ctl_table_header *head;
1569 struct list_head *tmp;
1570
1571 spin_lock(&sysctl_lock);
1572 if (prev) {
1573 head = prev;
1574 tmp = &prev->ctl_entry;
1575 unuse_table(prev);
1576 goto next;
1577 }
1578 tmp = &root_table_header.ctl_entry;
1579 for (;;) {
1580 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1581
1582 if (!use_table(head))
1583 goto next;
1584 spin_unlock(&sysctl_lock);
1585 return head;
1586 next:
1587 root = head->root;
1588 tmp = tmp->next;
1589 header_list = lookup_header_list(root, namespaces);
1590 if (tmp != header_list)
1591 continue;
1592
1593 do {
1594 root = list_entry(root->root_list.next,
1595 struct ctl_table_root, root_list);
1596 if (root == &sysctl_table_root)
1597 goto out;
1598 header_list = lookup_header_list(root, namespaces);
1599 } while (list_empty(header_list));
1600 tmp = header_list->next;
1601 }
1602 out:
1603 spin_unlock(&sysctl_lock);
1604 return NULL;
1605 }
1606
1607 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1608 {
1609 return __sysctl_head_next(current->nsproxy, prev);
1610 }
1611
1612 void register_sysctl_root(struct ctl_table_root *root)
1613 {
1614 spin_lock(&sysctl_lock);
1615 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1616 spin_unlock(&sysctl_lock);
1617 }
1618
1619 /*
1620 * sysctl_perm does NOT grant the superuser all rights automatically, because
1621 * some sysctl variables are readonly even to root.
1622 */
1623
1624 static int test_perm(int mode, int op)
1625 {
1626 if (!current_euid())
1627 mode >>= 6;
1628 else if (in_egroup_p(0))
1629 mode >>= 3;
1630 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1631 return 0;
1632 return -EACCES;
1633 }
1634
1635 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1636 {
1637 int error;
1638 int mode;
1639
1640 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1641 if (error)
1642 return error;
1643
1644 if (root->permissions)
1645 mode = root->permissions(root, current->nsproxy, table);
1646 else
1647 mode = table->mode;
1648
1649 return test_perm(mode, op);
1650 }
1651
1652 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1653 {
1654 for (; table->procname; table++) {
1655 table->parent = parent;
1656 if (table->child)
1657 sysctl_set_parent(table, table->child);
1658 }
1659 }
1660
1661 static __init int sysctl_init(void)
1662 {
1663 sysctl_set_parent(NULL, root_table);
1664 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1665 {
1666 int err;
1667 err = sysctl_check_table(current->nsproxy, root_table);
1668 }
1669 #endif
1670 return 0;
1671 }
1672
1673 core_initcall(sysctl_init);
1674
1675 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1676 struct ctl_table *table)
1677 {
1678 struct ctl_table *p;
1679 const char *s = branch->procname;
1680
1681 /* branch should have named subdirectory as its first element */
1682 if (!s || !branch->child)
1683 return NULL;
1684
1685 /* ... and nothing else */
1686 if (branch[1].procname)
1687 return NULL;
1688
1689 /* table should contain subdirectory with the same name */
1690 for (p = table; p->procname; p++) {
1691 if (!p->child)
1692 continue;
1693 if (p->procname && strcmp(p->procname, s) == 0)
1694 return p;
1695 }
1696 return NULL;
1697 }
1698
1699 /* see if attaching q to p would be an improvement */
1700 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1701 {
1702 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1703 struct ctl_table *next;
1704 int is_better = 0;
1705 int not_in_parent = !p->attached_by;
1706
1707 while ((next = is_branch_in(by, to)) != NULL) {
1708 if (by == q->attached_by)
1709 is_better = 1;
1710 if (to == p->attached_by)
1711 not_in_parent = 1;
1712 by = by->child;
1713 to = next->child;
1714 }
1715
1716 if (is_better && not_in_parent) {
1717 q->attached_by = by;
1718 q->attached_to = to;
1719 q->parent = p;
1720 }
1721 }
1722
1723 /**
1724 * __register_sysctl_paths - register a sysctl hierarchy
1725 * @root: List of sysctl headers to register on
1726 * @namespaces: Data to compute which lists of sysctl entries are visible
1727 * @path: The path to the directory the sysctl table is in.
1728 * @table: the top-level table structure
1729 *
1730 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1731 * array. A completely 0 filled entry terminates the table.
1732 *
1733 * The members of the &struct ctl_table structure are used as follows:
1734 *
1735 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1736 * enter a sysctl file
1737 *
1738 * data - a pointer to data for use by proc_handler
1739 *
1740 * maxlen - the maximum size in bytes of the data
1741 *
1742 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1743 *
1744 * child - a pointer to the child sysctl table if this entry is a directory, or
1745 * %NULL.
1746 *
1747 * proc_handler - the text handler routine (described below)
1748 *
1749 * de - for internal use by the sysctl routines
1750 *
1751 * extra1, extra2 - extra pointers usable by the proc handler routines
1752 *
1753 * Leaf nodes in the sysctl tree will be represented by a single file
1754 * under /proc; non-leaf nodes will be represented by directories.
1755 *
1756 * sysctl(2) can automatically manage read and write requests through
1757 * the sysctl table. The data and maxlen fields of the ctl_table
1758 * struct enable minimal validation of the values being written to be
1759 * performed, and the mode field allows minimal authentication.
1760 *
1761 * There must be a proc_handler routine for any terminal nodes
1762 * mirrored under /proc/sys (non-terminals are handled by a built-in
1763 * directory handler). Several default handlers are available to
1764 * cover common cases -
1765 *
1766 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1767 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1768 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1769 *
1770 * It is the handler's job to read the input buffer from user memory
1771 * and process it. The handler should return 0 on success.
1772 *
1773 * This routine returns %NULL on a failure to register, and a pointer
1774 * to the table header on success.
1775 */
1776 struct ctl_table_header *__register_sysctl_paths(
1777 struct ctl_table_root *root,
1778 struct nsproxy *namespaces,
1779 const struct ctl_path *path, struct ctl_table *table)
1780 {
1781 struct ctl_table_header *header;
1782 struct ctl_table *new, **prevp;
1783 unsigned int n, npath;
1784 struct ctl_table_set *set;
1785
1786 /* Count the path components */
1787 for (npath = 0; path[npath].procname; ++npath)
1788 ;
1789
1790 /*
1791 * For each path component, allocate a 2-element ctl_table array.
1792 * The first array element will be filled with the sysctl entry
1793 * for this, the second will be the sentinel (procname == 0).
1794 *
1795 * We allocate everything in one go so that we don't have to
1796 * worry about freeing additional memory in unregister_sysctl_table.
1797 */
1798 header = kzalloc(sizeof(struct ctl_table_header) +
1799 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1800 if (!header)
1801 return NULL;
1802
1803 new = (struct ctl_table *) (header + 1);
1804
1805 /* Now connect the dots */
1806 prevp = &header->ctl_table;
1807 for (n = 0; n < npath; ++n, ++path) {
1808 /* Copy the procname */
1809 new->procname = path->procname;
1810 new->mode = 0555;
1811
1812 *prevp = new;
1813 prevp = &new->child;
1814
1815 new += 2;
1816 }
1817 *prevp = table;
1818 header->ctl_table_arg = table;
1819
1820 INIT_LIST_HEAD(&header->ctl_entry);
1821 header->used = 0;
1822 header->unregistering = NULL;
1823 header->root = root;
1824 sysctl_set_parent(NULL, header->ctl_table);
1825 header->count = 1;
1826 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1827 if (sysctl_check_table(namespaces, header->ctl_table)) {
1828 kfree(header);
1829 return NULL;
1830 }
1831 #endif
1832 spin_lock(&sysctl_lock);
1833 header->set = lookup_header_set(root, namespaces);
1834 header->attached_by = header->ctl_table;
1835 header->attached_to = root_table;
1836 header->parent = &root_table_header;
1837 for (set = header->set; set; set = set->parent) {
1838 struct ctl_table_header *p;
1839 list_for_each_entry(p, &set->list, ctl_entry) {
1840 if (p->unregistering)
1841 continue;
1842 try_attach(p, header);
1843 }
1844 }
1845 header->parent->count++;
1846 list_add_tail(&header->ctl_entry, &header->set->list);
1847 spin_unlock(&sysctl_lock);
1848
1849 return header;
1850 }
1851
1852 /**
1853 * register_sysctl_table_path - register a sysctl table hierarchy
1854 * @path: The path to the directory the sysctl table is in.
1855 * @table: the top-level table structure
1856 *
1857 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1858 * array. A completely 0 filled entry terminates the table.
1859 *
1860 * See __register_sysctl_paths for more details.
1861 */
1862 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1863 struct ctl_table *table)
1864 {
1865 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1866 path, table);
1867 }
1868
1869 /**
1870 * register_sysctl_table - register a sysctl table hierarchy
1871 * @table: the top-level table structure
1872 *
1873 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1874 * array. A completely 0 filled entry terminates the table.
1875 *
1876 * See register_sysctl_paths for more details.
1877 */
1878 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1879 {
1880 static const struct ctl_path null_path[] = { {} };
1881
1882 return register_sysctl_paths(null_path, table);
1883 }
1884
1885 /**
1886 * unregister_sysctl_table - unregister a sysctl table hierarchy
1887 * @header: the header returned from register_sysctl_table
1888 *
1889 * Unregisters the sysctl table and all children. proc entries may not
1890 * actually be removed until they are no longer used by anyone.
1891 */
1892 void unregister_sysctl_table(struct ctl_table_header * header)
1893 {
1894 might_sleep();
1895
1896 if (header == NULL)
1897 return;
1898
1899 spin_lock(&sysctl_lock);
1900 start_unregistering(header);
1901 if (!--header->parent->count) {
1902 WARN_ON(1);
1903 kfree(header->parent);
1904 }
1905 if (!--header->count)
1906 kfree(header);
1907 spin_unlock(&sysctl_lock);
1908 }
1909
1910 int sysctl_is_seen(struct ctl_table_header *p)
1911 {
1912 struct ctl_table_set *set = p->set;
1913 int res;
1914 spin_lock(&sysctl_lock);
1915 if (p->unregistering)
1916 res = 0;
1917 else if (!set->is_seen)
1918 res = 1;
1919 else
1920 res = set->is_seen(set);
1921 spin_unlock(&sysctl_lock);
1922 return res;
1923 }
1924
1925 void setup_sysctl_set(struct ctl_table_set *p,
1926 struct ctl_table_set *parent,
1927 int (*is_seen)(struct ctl_table_set *))
1928 {
1929 INIT_LIST_HEAD(&p->list);
1930 p->parent = parent ? parent : &sysctl_table_root.default_set;
1931 p->is_seen = is_seen;
1932 }
1933
1934 #else /* !CONFIG_SYSCTL */
1935 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1936 {
1937 return NULL;
1938 }
1939
1940 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1941 struct ctl_table *table)
1942 {
1943 return NULL;
1944 }
1945
1946 void unregister_sysctl_table(struct ctl_table_header * table)
1947 {
1948 }
1949
1950 void setup_sysctl_set(struct ctl_table_set *p,
1951 struct ctl_table_set *parent,
1952 int (*is_seen)(struct ctl_table_set *))
1953 {
1954 }
1955
1956 void sysctl_head_put(struct ctl_table_header *head)
1957 {
1958 }
1959
1960 #endif /* CONFIG_SYSCTL */
1961
1962 /*
1963 * /proc/sys support
1964 */
1965
1966 #ifdef CONFIG_PROC_SYSCTL
1967
1968 static int _proc_do_string(void* data, int maxlen, int write,
1969 void __user *buffer,
1970 size_t *lenp, loff_t *ppos)
1971 {
1972 size_t len;
1973 char __user *p;
1974 char c;
1975
1976 if (!data || !maxlen || !*lenp) {
1977 *lenp = 0;
1978 return 0;
1979 }
1980
1981 if (write) {
1982 len = 0;
1983 p = buffer;
1984 while (len < *lenp) {
1985 if (get_user(c, p++))
1986 return -EFAULT;
1987 if (c == 0 || c == '\n')
1988 break;
1989 len++;
1990 }
1991 if (len >= maxlen)
1992 len = maxlen-1;
1993 if(copy_from_user(data, buffer, len))
1994 return -EFAULT;
1995 ((char *) data)[len] = 0;
1996 *ppos += *lenp;
1997 } else {
1998 len = strlen(data);
1999 if (len > maxlen)
2000 len = maxlen;
2001
2002 if (*ppos > len) {
2003 *lenp = 0;
2004 return 0;
2005 }
2006
2007 data += *ppos;
2008 len -= *ppos;
2009
2010 if (len > *lenp)
2011 len = *lenp;
2012 if (len)
2013 if(copy_to_user(buffer, data, len))
2014 return -EFAULT;
2015 if (len < *lenp) {
2016 if(put_user('\n', ((char __user *) buffer) + len))
2017 return -EFAULT;
2018 len++;
2019 }
2020 *lenp = len;
2021 *ppos += len;
2022 }
2023 return 0;
2024 }
2025
2026 /**
2027 * proc_dostring - read a string sysctl
2028 * @table: the sysctl table
2029 * @write: %TRUE if this is a write to the sysctl file
2030 * @buffer: the user buffer
2031 * @lenp: the size of the user buffer
2032 * @ppos: file position
2033 *
2034 * Reads/writes a string from/to the user buffer. If the kernel
2035 * buffer provided is not large enough to hold the string, the
2036 * string is truncated. The copied string is %NULL-terminated.
2037 * If the string is being read by the user process, it is copied
2038 * and a newline '\n' is added. It is truncated if the buffer is
2039 * not large enough.
2040 *
2041 * Returns 0 on success.
2042 */
2043 int proc_dostring(struct ctl_table *table, int write,
2044 void __user *buffer, size_t *lenp, loff_t *ppos)
2045 {
2046 return _proc_do_string(table->data, table->maxlen, write,
2047 buffer, lenp, ppos);
2048 }
2049
2050
2051 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2052 int *valp,
2053 int write, void *data)
2054 {
2055 if (write) {
2056 *valp = *negp ? -*lvalp : *lvalp;
2057 } else {
2058 int val = *valp;
2059 if (val < 0) {
2060 *negp = -1;
2061 *lvalp = (unsigned long)-val;
2062 } else {
2063 *negp = 0;
2064 *lvalp = (unsigned long)val;
2065 }
2066 }
2067 return 0;
2068 }
2069
2070 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2071 int write, void __user *buffer,
2072 size_t *lenp, loff_t *ppos,
2073 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2074 int write, void *data),
2075 void *data)
2076 {
2077 #define TMPBUFLEN 21
2078 int *i, vleft, first = 1, neg;
2079 unsigned long lval;
2080 size_t left, len;
2081
2082 char buf[TMPBUFLEN], *p;
2083 char __user *s = buffer;
2084
2085 if (!tbl_data || !table->maxlen || !*lenp ||
2086 (*ppos && !write)) {
2087 *lenp = 0;
2088 return 0;
2089 }
2090
2091 i = (int *) tbl_data;
2092 vleft = table->maxlen / sizeof(*i);
2093 left = *lenp;
2094
2095 if (!conv)
2096 conv = do_proc_dointvec_conv;
2097
2098 for (; left && vleft--; i++, first=0) {
2099 if (write) {
2100 while (left) {
2101 char c;
2102 if (get_user(c, s))
2103 return -EFAULT;
2104 if (!isspace(c))
2105 break;
2106 left--;
2107 s++;
2108 }
2109 if (!left)
2110 break;
2111 neg = 0;
2112 len = left;
2113 if (len > sizeof(buf) - 1)
2114 len = sizeof(buf) - 1;
2115 if (copy_from_user(buf, s, len))
2116 return -EFAULT;
2117 buf[len] = 0;
2118 p = buf;
2119 if (*p == '-' && left > 1) {
2120 neg = 1;
2121 p++;
2122 }
2123 if (*p < '0' || *p > '9')
2124 break;
2125
2126 lval = simple_strtoul(p, &p, 0);
2127
2128 len = p-buf;
2129 if ((len < left) && *p && !isspace(*p))
2130 break;
2131 s += len;
2132 left -= len;
2133
2134 if (conv(&neg, &lval, i, 1, data))
2135 break;
2136 } else {
2137 p = buf;
2138 if (!first)
2139 *p++ = '\t';
2140
2141 if (conv(&neg, &lval, i, 0, data))
2142 break;
2143
2144 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2145 len = strlen(buf);
2146 if (len > left)
2147 len = left;
2148 if(copy_to_user(s, buf, len))
2149 return -EFAULT;
2150 left -= len;
2151 s += len;
2152 }
2153 }
2154
2155 if (!write && !first && left) {
2156 if(put_user('\n', s))
2157 return -EFAULT;
2158 left--, s++;
2159 }
2160 if (write) {
2161 while (left) {
2162 char c;
2163 if (get_user(c, s++))
2164 return -EFAULT;
2165 if (!isspace(c))
2166 break;
2167 left--;
2168 }
2169 }
2170 if (write && first)
2171 return -EINVAL;
2172 *lenp -= left;
2173 *ppos += *lenp;
2174 return 0;
2175 #undef TMPBUFLEN
2176 }
2177
2178 static int do_proc_dointvec(struct ctl_table *table, int write,
2179 void __user *buffer, size_t *lenp, loff_t *ppos,
2180 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2181 int write, void *data),
2182 void *data)
2183 {
2184 return __do_proc_dointvec(table->data, table, write,
2185 buffer, lenp, ppos, conv, data);
2186 }
2187
2188 /**
2189 * proc_dointvec - read a vector of integers
2190 * @table: the sysctl table
2191 * @write: %TRUE if this is a write to the sysctl file
2192 * @buffer: the user buffer
2193 * @lenp: the size of the user buffer
2194 * @ppos: file position
2195 *
2196 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2197 * values from/to the user buffer, treated as an ASCII string.
2198 *
2199 * Returns 0 on success.
2200 */
2201 int proc_dointvec(struct ctl_table *table, int write,
2202 void __user *buffer, size_t *lenp, loff_t *ppos)
2203 {
2204 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2205 NULL,NULL);
2206 }
2207
2208 /*
2209 * Taint values can only be increased
2210 * This means we can safely use a temporary.
2211 */
2212 static int proc_taint(struct ctl_table *table, int write,
2213 void __user *buffer, size_t *lenp, loff_t *ppos)
2214 {
2215 struct ctl_table t;
2216 unsigned long tmptaint = get_taint();
2217 int err;
2218
2219 if (write && !capable(CAP_SYS_ADMIN))
2220 return -EPERM;
2221
2222 t = *table;
2223 t.data = &tmptaint;
2224 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2225 if (err < 0)
2226 return err;
2227
2228 if (write) {
2229 /*
2230 * Poor man's atomic or. Not worth adding a primitive
2231 * to everyone's atomic.h for this
2232 */
2233 int i;
2234 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2235 if ((tmptaint >> i) & 1)
2236 add_taint(i);
2237 }
2238 }
2239
2240 return err;
2241 }
2242
2243 struct do_proc_dointvec_minmax_conv_param {
2244 int *min;
2245 int *max;
2246 };
2247
2248 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2249 int *valp,
2250 int write, void *data)
2251 {
2252 struct do_proc_dointvec_minmax_conv_param *param = data;
2253 if (write) {
2254 int val = *negp ? -*lvalp : *lvalp;
2255 if ((param->min && *param->min > val) ||
2256 (param->max && *param->max < val))
2257 return -EINVAL;
2258 *valp = val;
2259 } else {
2260 int val = *valp;
2261 if (val < 0) {
2262 *negp = -1;
2263 *lvalp = (unsigned long)-val;
2264 } else {
2265 *negp = 0;
2266 *lvalp = (unsigned long)val;
2267 }
2268 }
2269 return 0;
2270 }
2271
2272 /**
2273 * proc_dointvec_minmax - read a vector of integers with min/max values
2274 * @table: the sysctl table
2275 * @write: %TRUE if this is a write to the sysctl file
2276 * @buffer: the user buffer
2277 * @lenp: the size of the user buffer
2278 * @ppos: file position
2279 *
2280 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2281 * values from/to the user buffer, treated as an ASCII string.
2282 *
2283 * This routine will ensure the values are within the range specified by
2284 * table->extra1 (min) and table->extra2 (max).
2285 *
2286 * Returns 0 on success.
2287 */
2288 int proc_dointvec_minmax(struct ctl_table *table, int write,
2289 void __user *buffer, size_t *lenp, loff_t *ppos)
2290 {
2291 struct do_proc_dointvec_minmax_conv_param param = {
2292 .min = (int *) table->extra1,
2293 .max = (int *) table->extra2,
2294 };
2295 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2296 do_proc_dointvec_minmax_conv, &param);
2297 }
2298
2299 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2300 void __user *buffer,
2301 size_t *lenp, loff_t *ppos,
2302 unsigned long convmul,
2303 unsigned long convdiv)
2304 {
2305 #define TMPBUFLEN 21
2306 unsigned long *i, *min, *max, val;
2307 int vleft, first=1, neg;
2308 size_t len, left;
2309 char buf[TMPBUFLEN], *p;
2310 char __user *s = buffer;
2311
2312 if (!data || !table->maxlen || !*lenp ||
2313 (*ppos && !write)) {
2314 *lenp = 0;
2315 return 0;
2316 }
2317
2318 i = (unsigned long *) data;
2319 min = (unsigned long *) table->extra1;
2320 max = (unsigned long *) table->extra2;
2321 vleft = table->maxlen / sizeof(unsigned long);
2322 left = *lenp;
2323
2324 for (; left && vleft--; i++, min++, max++, first=0) {
2325 if (write) {
2326 while (left) {
2327 char c;
2328 if (get_user(c, s))
2329 return -EFAULT;
2330 if (!isspace(c))
2331 break;
2332 left--;
2333 s++;
2334 }
2335 if (!left)
2336 break;
2337 neg = 0;
2338 len = left;
2339 if (len > TMPBUFLEN-1)
2340 len = TMPBUFLEN-1;
2341 if (copy_from_user(buf, s, len))
2342 return -EFAULT;
2343 buf[len] = 0;
2344 p = buf;
2345 if (*p == '-' && left > 1) {
2346 neg = 1;
2347 p++;
2348 }
2349 if (*p < '0' || *p > '9')
2350 break;
2351 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2352 len = p-buf;
2353 if ((len < left) && *p && !isspace(*p))
2354 break;
2355 if (neg)
2356 val = -val;
2357 s += len;
2358 left -= len;
2359
2360 if(neg)
2361 continue;
2362 if ((min && val < *min) || (max && val > *max))
2363 continue;
2364 *i = val;
2365 } else {
2366 p = buf;
2367 if (!first)
2368 *p++ = '\t';
2369 sprintf(p, "%lu", convdiv * (*i) / convmul);
2370 len = strlen(buf);
2371 if (len > left)
2372 len = left;
2373 if(copy_to_user(s, buf, len))
2374 return -EFAULT;
2375 left -= len;
2376 s += len;
2377 }
2378 }
2379
2380 if (!write && !first && left) {
2381 if(put_user('\n', s))
2382 return -EFAULT;
2383 left--, s++;
2384 }
2385 if (write) {
2386 while (left) {
2387 char c;
2388 if (get_user(c, s++))
2389 return -EFAULT;
2390 if (!isspace(c))
2391 break;
2392 left--;
2393 }
2394 }
2395 if (write && first)
2396 return -EINVAL;
2397 *lenp -= left;
2398 *ppos += *lenp;
2399 return 0;
2400 #undef TMPBUFLEN
2401 }
2402
2403 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2404 void __user *buffer,
2405 size_t *lenp, loff_t *ppos,
2406 unsigned long convmul,
2407 unsigned long convdiv)
2408 {
2409 return __do_proc_doulongvec_minmax(table->data, table, write,
2410 buffer, lenp, ppos, convmul, convdiv);
2411 }
2412
2413 /**
2414 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2415 * @table: the sysctl table
2416 * @write: %TRUE if this is a write to the sysctl file
2417 * @buffer: the user buffer
2418 * @lenp: the size of the user buffer
2419 * @ppos: file position
2420 *
2421 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2422 * values from/to the user buffer, treated as an ASCII string.
2423 *
2424 * This routine will ensure the values are within the range specified by
2425 * table->extra1 (min) and table->extra2 (max).
2426 *
2427 * Returns 0 on success.
2428 */
2429 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2430 void __user *buffer, size_t *lenp, loff_t *ppos)
2431 {
2432 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2433 }
2434
2435 /**
2436 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2437 * @table: the sysctl table
2438 * @write: %TRUE if this is a write to the sysctl file
2439 * @buffer: the user buffer
2440 * @lenp: the size of the user buffer
2441 * @ppos: file position
2442 *
2443 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2444 * values from/to the user buffer, treated as an ASCII string. The values
2445 * are treated as milliseconds, and converted to jiffies when they are stored.
2446 *
2447 * This routine will ensure the values are within the range specified by
2448 * table->extra1 (min) and table->extra2 (max).
2449 *
2450 * Returns 0 on success.
2451 */
2452 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2453 void __user *buffer,
2454 size_t *lenp, loff_t *ppos)
2455 {
2456 return do_proc_doulongvec_minmax(table, write, buffer,
2457 lenp, ppos, HZ, 1000l);
2458 }
2459
2460
2461 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2462 int *valp,
2463 int write, void *data)
2464 {
2465 if (write) {
2466 if (*lvalp > LONG_MAX / HZ)
2467 return 1;
2468 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2469 } else {
2470 int val = *valp;
2471 unsigned long lval;
2472 if (val < 0) {
2473 *negp = -1;
2474 lval = (unsigned long)-val;
2475 } else {
2476 *negp = 0;
2477 lval = (unsigned long)val;
2478 }
2479 *lvalp = lval / HZ;
2480 }
2481 return 0;
2482 }
2483
2484 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2485 int *valp,
2486 int write, void *data)
2487 {
2488 if (write) {
2489 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2490 return 1;
2491 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2492 } else {
2493 int val = *valp;
2494 unsigned long lval;
2495 if (val < 0) {
2496 *negp = -1;
2497 lval = (unsigned long)-val;
2498 } else {
2499 *negp = 0;
2500 lval = (unsigned long)val;
2501 }
2502 *lvalp = jiffies_to_clock_t(lval);
2503 }
2504 return 0;
2505 }
2506
2507 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2508 int *valp,
2509 int write, void *data)
2510 {
2511 if (write) {
2512 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2513 } else {
2514 int val = *valp;
2515 unsigned long lval;
2516 if (val < 0) {
2517 *negp = -1;
2518 lval = (unsigned long)-val;
2519 } else {
2520 *negp = 0;
2521 lval = (unsigned long)val;
2522 }
2523 *lvalp = jiffies_to_msecs(lval);
2524 }
2525 return 0;
2526 }
2527
2528 /**
2529 * proc_dointvec_jiffies - read a vector of integers as seconds
2530 * @table: the sysctl table
2531 * @write: %TRUE if this is a write to the sysctl file
2532 * @buffer: the user buffer
2533 * @lenp: the size of the user buffer
2534 * @ppos: file position
2535 *
2536 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2537 * values from/to the user buffer, treated as an ASCII string.
2538 * The values read are assumed to be in seconds, and are converted into
2539 * jiffies.
2540 *
2541 * Returns 0 on success.
2542 */
2543 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2544 void __user *buffer, size_t *lenp, loff_t *ppos)
2545 {
2546 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2547 do_proc_dointvec_jiffies_conv,NULL);
2548 }
2549
2550 /**
2551 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2552 * @table: the sysctl table
2553 * @write: %TRUE if this is a write to the sysctl file
2554 * @buffer: the user buffer
2555 * @lenp: the size of the user buffer
2556 * @ppos: pointer to the file position
2557 *
2558 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2559 * values from/to the user buffer, treated as an ASCII string.
2560 * The values read are assumed to be in 1/USER_HZ seconds, and
2561 * are converted into jiffies.
2562 *
2563 * Returns 0 on success.
2564 */
2565 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2566 void __user *buffer, size_t *lenp, loff_t *ppos)
2567 {
2568 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2569 do_proc_dointvec_userhz_jiffies_conv,NULL);
2570 }
2571
2572 /**
2573 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2574 * @table: the sysctl table
2575 * @write: %TRUE if this is a write to the sysctl file
2576 * @buffer: the user buffer
2577 * @lenp: the size of the user buffer
2578 * @ppos: file position
2579 * @ppos: the current position in the file
2580 *
2581 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2582 * values from/to the user buffer, treated as an ASCII string.
2583 * The values read are assumed to be in 1/1000 seconds, and
2584 * are converted into jiffies.
2585 *
2586 * Returns 0 on success.
2587 */
2588 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2589 void __user *buffer, size_t *lenp, loff_t *ppos)
2590 {
2591 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2592 do_proc_dointvec_ms_jiffies_conv, NULL);
2593 }
2594
2595 static int proc_do_cad_pid(struct ctl_table *table, int write,
2596 void __user *buffer, size_t *lenp, loff_t *ppos)
2597 {
2598 struct pid *new_pid;
2599 pid_t tmp;
2600 int r;
2601
2602 tmp = pid_vnr(cad_pid);
2603
2604 r = __do_proc_dointvec(&tmp, table, write, buffer,
2605 lenp, ppos, NULL, NULL);
2606 if (r || !write)
2607 return r;
2608
2609 new_pid = find_get_pid(tmp);
2610 if (!new_pid)
2611 return -ESRCH;
2612
2613 put_pid(xchg(&cad_pid, new_pid));
2614 return 0;
2615 }
2616
2617 #else /* CONFIG_PROC_FS */
2618
2619 int proc_dostring(struct ctl_table *table, int write,
2620 void __user *buffer, size_t *lenp, loff_t *ppos)
2621 {
2622 return -ENOSYS;
2623 }
2624
2625 int proc_dointvec(struct ctl_table *table, int write,
2626 void __user *buffer, size_t *lenp, loff_t *ppos)
2627 {
2628 return -ENOSYS;
2629 }
2630
2631 int proc_dointvec_minmax(struct ctl_table *table, int write,
2632 void __user *buffer, size_t *lenp, loff_t *ppos)
2633 {
2634 return -ENOSYS;
2635 }
2636
2637 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2638 void __user *buffer, size_t *lenp, loff_t *ppos)
2639 {
2640 return -ENOSYS;
2641 }
2642
2643 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2644 void __user *buffer, size_t *lenp, loff_t *ppos)
2645 {
2646 return -ENOSYS;
2647 }
2648
2649 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2650 void __user *buffer, size_t *lenp, loff_t *ppos)
2651 {
2652 return -ENOSYS;
2653 }
2654
2655 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2656 void __user *buffer, size_t *lenp, loff_t *ppos)
2657 {
2658 return -ENOSYS;
2659 }
2660
2661 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2662 void __user *buffer,
2663 size_t *lenp, loff_t *ppos)
2664 {
2665 return -ENOSYS;
2666 }
2667
2668
2669 #endif /* CONFIG_PROC_FS */
2670
2671 /*
2672 * No sense putting this after each symbol definition, twice,
2673 * exception granted :-)
2674 */
2675 EXPORT_SYMBOL(proc_dointvec);
2676 EXPORT_SYMBOL(proc_dointvec_jiffies);
2677 EXPORT_SYMBOL(proc_dointvec_minmax);
2678 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2679 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2680 EXPORT_SYMBOL(proc_dostring);
2681 EXPORT_SYMBOL(proc_doulongvec_minmax);
2682 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2683 EXPORT_SYMBOL(register_sysctl_table);
2684 EXPORT_SYMBOL(register_sysctl_paths);
2685 EXPORT_SYMBOL(unregister_sysctl_table);
This page took 0.10932 seconds and 6 git commands to generate.