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