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