Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
[linux/fpc-iii.git] / kernel / sysctl.c
blob7f4f57bea4ce5ceb77a677f6415f1f0cfe13f16c
1 /*
2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/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/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
52 #include <linux/perf_event.h>
54 #include <asm/uaccess.h>
55 #include <asm/processor.h>
57 #ifdef CONFIG_X86
58 #include <asm/nmi.h>
59 #include <asm/stacktrace.h>
60 #include <asm/io.h>
61 #endif
63 static int deprecated_sysctl_warning(struct __sysctl_args *args);
65 #if defined(CONFIG_SYSCTL)
67 /* External variables not in a header file. */
68 extern int C_A_D;
69 extern int print_fatal_signals;
70 extern int sysctl_overcommit_memory;
71 extern int sysctl_overcommit_ratio;
72 extern int sysctl_panic_on_oom;
73 extern int sysctl_oom_kill_allocating_task;
74 extern int sysctl_oom_dump_tasks;
75 extern int max_threads;
76 extern int core_uses_pid;
77 extern int suid_dumpable;
78 extern char core_pattern[];
79 extern int pid_max;
80 extern int min_free_kbytes;
81 extern int pid_max_min, pid_max_max;
82 extern int sysctl_drop_caches;
83 extern int percpu_pagelist_fraction;
84 extern int compat_log;
85 extern int latencytop_enabled;
86 extern int sysctl_nr_open_min, sysctl_nr_open_max;
87 #ifndef CONFIG_MMU
88 extern int sysctl_nr_trim_pages;
89 #endif
90 #ifdef CONFIG_RCU_TORTURE_TEST
91 extern int rcutorture_runnable;
92 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
93 #ifdef CONFIG_BLOCK
94 extern int blk_iopoll_enabled;
95 #endif
97 /* Constants used for minimum and maximum */
98 #ifdef CONFIG_DETECT_SOFTLOCKUP
99 static int sixty = 60;
100 static int neg_one = -1;
101 #endif
103 static int zero;
104 static int __maybe_unused one = 1;
105 static int __maybe_unused two = 2;
106 static unsigned long one_ul = 1;
107 static int one_hundred = 100;
108 #ifdef CONFIG_PRINTK
109 static int ten_thousand = 10000;
110 #endif
112 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
113 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
115 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
116 static int maxolduid = 65535;
117 static int minolduid;
118 static int min_percpu_pagelist_fract = 8;
120 static int ngroups_max = NGROUPS_MAX;
122 #ifdef CONFIG_MODULES
123 extern char modprobe_path[];
124 extern int modules_disabled;
125 #endif
126 #ifdef CONFIG_CHR_DEV_SG
127 extern int sg_big_buff;
128 #endif
130 #ifdef CONFIG_SPARC
131 #include <asm/system.h>
132 #endif
134 #ifdef CONFIG_SPARC64
135 extern int sysctl_tsb_ratio;
136 #endif
138 #ifdef __hppa__
139 extern int pwrsw_enabled;
140 extern int unaligned_enabled;
141 #endif
143 #ifdef CONFIG_S390
144 #ifdef CONFIG_MATHEMU
145 extern int sysctl_ieee_emulation_warnings;
146 #endif
147 extern int sysctl_userprocess_debug;
148 extern int spin_retry;
149 #endif
151 #ifdef CONFIG_BSD_PROCESS_ACCT
152 extern int acct_parm[];
153 #endif
155 #ifdef CONFIG_IA64
156 extern int no_unaligned_warning;
157 extern int unaligned_dump_stack;
158 #endif
160 #ifdef CONFIG_RT_MUTEXES
161 extern int max_lock_depth;
162 #endif
164 #ifdef CONFIG_PROC_SYSCTL
165 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
166 void __user *buffer, size_t *lenp, loff_t *ppos);
167 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
169 #endif
171 static struct ctl_table root_table[];
172 static struct ctl_table_root sysctl_table_root;
173 static struct ctl_table_header root_table_header = {
174 .count = 1,
175 .ctl_table = root_table,
176 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
177 .root = &sysctl_table_root,
178 .set = &sysctl_table_root.default_set,
180 static struct ctl_table_root sysctl_table_root = {
181 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
182 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
185 static struct ctl_table kern_table[];
186 static struct ctl_table vm_table[];
187 static struct ctl_table fs_table[];
188 static struct ctl_table debug_table[];
189 static struct ctl_table dev_table[];
190 extern struct ctl_table random_table[];
191 #ifdef CONFIG_INOTIFY_USER
192 extern struct ctl_table inotify_table[];
193 #endif
194 #ifdef CONFIG_EPOLL
195 extern struct ctl_table epoll_table[];
196 #endif
198 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
199 int sysctl_legacy_va_layout;
200 #endif
202 extern int prove_locking;
203 extern int lock_stat;
205 /* The default sysctl tables: */
207 static struct ctl_table root_table[] = {
209 .ctl_name = CTL_KERN,
210 .procname = "kernel",
211 .mode = 0555,
212 .child = kern_table,
215 .ctl_name = CTL_VM,
216 .procname = "vm",
217 .mode = 0555,
218 .child = vm_table,
221 .ctl_name = CTL_FS,
222 .procname = "fs",
223 .mode = 0555,
224 .child = fs_table,
227 .ctl_name = CTL_DEBUG,
228 .procname = "debug",
229 .mode = 0555,
230 .child = debug_table,
233 .ctl_name = CTL_DEV,
234 .procname = "dev",
235 .mode = 0555,
236 .child = dev_table,
239 * NOTE: do not add new entries to this table unless you have read
240 * Documentation/sysctl/ctl_unnumbered.txt
242 { .ctl_name = 0 }
245 #ifdef CONFIG_SCHED_DEBUG
246 static int min_sched_granularity_ns = 100000; /* 100 usecs */
247 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
248 static int min_wakeup_granularity_ns; /* 0 usecs */
249 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
250 #endif
252 static struct ctl_table kern_table[] = {
254 .ctl_name = CTL_UNNUMBERED,
255 .procname = "sched_child_runs_first",
256 .data = &sysctl_sched_child_runs_first,
257 .maxlen = sizeof(unsigned int),
258 .mode = 0644,
259 .proc_handler = &proc_dointvec,
261 #ifdef CONFIG_SCHED_DEBUG
263 .ctl_name = CTL_UNNUMBERED,
264 .procname = "sched_min_granularity_ns",
265 .data = &sysctl_sched_min_granularity,
266 .maxlen = sizeof(unsigned int),
267 .mode = 0644,
268 .proc_handler = &sched_nr_latency_handler,
269 .strategy = &sysctl_intvec,
270 .extra1 = &min_sched_granularity_ns,
271 .extra2 = &max_sched_granularity_ns,
274 .ctl_name = CTL_UNNUMBERED,
275 .procname = "sched_latency_ns",
276 .data = &sysctl_sched_latency,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
279 .proc_handler = &sched_nr_latency_handler,
280 .strategy = &sysctl_intvec,
281 .extra1 = &min_sched_granularity_ns,
282 .extra2 = &max_sched_granularity_ns,
285 .ctl_name = CTL_UNNUMBERED,
286 .procname = "sched_wakeup_granularity_ns",
287 .data = &sysctl_sched_wakeup_granularity,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = &proc_dointvec_minmax,
291 .strategy = &sysctl_intvec,
292 .extra1 = &min_wakeup_granularity_ns,
293 .extra2 = &max_wakeup_granularity_ns,
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_shares_ratelimit",
298 .data = &sysctl_sched_shares_ratelimit,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
301 .proc_handler = &proc_dointvec,
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_shares_thresh",
306 .data = &sysctl_sched_shares_thresh,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = &proc_dointvec_minmax,
310 .strategy = &sysctl_intvec,
311 .extra1 = &zero,
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_features",
316 .data = &sysctl_sched_features,
317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
319 .proc_handler = &proc_dointvec,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_migration_cost",
324 .data = &sysctl_sched_migration_cost,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "sched_nr_migrate",
332 .data = &sysctl_sched_nr_migrate,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
335 .proc_handler = &proc_dointvec,
338 .ctl_name = CTL_UNNUMBERED,
339 .procname = "sched_time_avg",
340 .data = &sysctl_sched_time_avg,
341 .maxlen = sizeof(unsigned int),
342 .mode = 0644,
343 .proc_handler = &proc_dointvec,
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "timer_migration",
348 .data = &sysctl_timer_migration,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec_minmax,
352 .strategy = &sysctl_intvec,
353 .extra1 = &zero,
354 .extra2 = &one,
356 #endif
358 .ctl_name = CTL_UNNUMBERED,
359 .procname = "sched_rt_period_us",
360 .data = &sysctl_sched_rt_period,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
363 .proc_handler = &sched_rt_handler,
366 .ctl_name = CTL_UNNUMBERED,
367 .procname = "sched_rt_runtime_us",
368 .data = &sysctl_sched_rt_runtime,
369 .maxlen = sizeof(int),
370 .mode = 0644,
371 .proc_handler = &sched_rt_handler,
374 .ctl_name = CTL_UNNUMBERED,
375 .procname = "sched_compat_yield",
376 .data = &sysctl_sched_compat_yield,
377 .maxlen = sizeof(unsigned int),
378 .mode = 0644,
379 .proc_handler = &proc_dointvec,
381 #ifdef CONFIG_PROVE_LOCKING
383 .ctl_name = CTL_UNNUMBERED,
384 .procname = "prove_locking",
385 .data = &prove_locking,
386 .maxlen = sizeof(int),
387 .mode = 0644,
388 .proc_handler = &proc_dointvec,
390 #endif
391 #ifdef CONFIG_LOCK_STAT
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "lock_stat",
395 .data = &lock_stat,
396 .maxlen = sizeof(int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
400 #endif
402 .ctl_name = KERN_PANIC,
403 .procname = "panic",
404 .data = &panic_timeout,
405 .maxlen = sizeof(int),
406 .mode = 0644,
407 .proc_handler = &proc_dointvec,
410 .ctl_name = KERN_CORE_USES_PID,
411 .procname = "core_uses_pid",
412 .data = &core_uses_pid,
413 .maxlen = sizeof(int),
414 .mode = 0644,
415 .proc_handler = &proc_dointvec,
418 .ctl_name = KERN_CORE_PATTERN,
419 .procname = "core_pattern",
420 .data = core_pattern,
421 .maxlen = CORENAME_MAX_SIZE,
422 .mode = 0644,
423 .proc_handler = &proc_dostring,
424 .strategy = &sysctl_string,
426 #ifdef CONFIG_PROC_SYSCTL
428 .procname = "tainted",
429 .maxlen = sizeof(long),
430 .mode = 0644,
431 .proc_handler = &proc_taint,
433 #endif
434 #ifdef CONFIG_LATENCYTOP
436 .procname = "latencytop",
437 .data = &latencytop_enabled,
438 .maxlen = sizeof(int),
439 .mode = 0644,
440 .proc_handler = &proc_dointvec,
442 #endif
443 #ifdef CONFIG_BLK_DEV_INITRD
445 .ctl_name = KERN_REALROOTDEV,
446 .procname = "real-root-dev",
447 .data = &real_root_dev,
448 .maxlen = sizeof(int),
449 .mode = 0644,
450 .proc_handler = &proc_dointvec,
452 #endif
454 .ctl_name = CTL_UNNUMBERED,
455 .procname = "print-fatal-signals",
456 .data = &print_fatal_signals,
457 .maxlen = sizeof(int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec,
461 #ifdef CONFIG_SPARC
463 .ctl_name = KERN_SPARC_REBOOT,
464 .procname = "reboot-cmd",
465 .data = reboot_command,
466 .maxlen = 256,
467 .mode = 0644,
468 .proc_handler = &proc_dostring,
469 .strategy = &sysctl_string,
472 .ctl_name = KERN_SPARC_STOP_A,
473 .procname = "stop-a",
474 .data = &stop_a_enabled,
475 .maxlen = sizeof (int),
476 .mode = 0644,
477 .proc_handler = &proc_dointvec,
480 .ctl_name = KERN_SPARC_SCONS_PWROFF,
481 .procname = "scons-poweroff",
482 .data = &scons_pwroff,
483 .maxlen = sizeof (int),
484 .mode = 0644,
485 .proc_handler = &proc_dointvec,
487 #endif
488 #ifdef CONFIG_SPARC64
490 .ctl_name = CTL_UNNUMBERED,
491 .procname = "tsb-ratio",
492 .data = &sysctl_tsb_ratio,
493 .maxlen = sizeof (int),
494 .mode = 0644,
495 .proc_handler = &proc_dointvec,
497 #endif
498 #ifdef __hppa__
500 .ctl_name = KERN_HPPA_PWRSW,
501 .procname = "soft-power",
502 .data = &pwrsw_enabled,
503 .maxlen = sizeof (int),
504 .mode = 0644,
505 .proc_handler = &proc_dointvec,
508 .ctl_name = KERN_HPPA_UNALIGNED,
509 .procname = "unaligned-trap",
510 .data = &unaligned_enabled,
511 .maxlen = sizeof (int),
512 .mode = 0644,
513 .proc_handler = &proc_dointvec,
515 #endif
517 .ctl_name = KERN_CTLALTDEL,
518 .procname = "ctrl-alt-del",
519 .data = &C_A_D,
520 .maxlen = sizeof(int),
521 .mode = 0644,
522 .proc_handler = &proc_dointvec,
524 #ifdef CONFIG_FUNCTION_TRACER
526 .ctl_name = CTL_UNNUMBERED,
527 .procname = "ftrace_enabled",
528 .data = &ftrace_enabled,
529 .maxlen = sizeof(int),
530 .mode = 0644,
531 .proc_handler = &ftrace_enable_sysctl,
533 #endif
534 #ifdef CONFIG_STACK_TRACER
536 .ctl_name = CTL_UNNUMBERED,
537 .procname = "stack_tracer_enabled",
538 .data = &stack_tracer_enabled,
539 .maxlen = sizeof(int),
540 .mode = 0644,
541 .proc_handler = &stack_trace_sysctl,
543 #endif
544 #ifdef CONFIG_TRACING
546 .ctl_name = CTL_UNNUMBERED,
547 .procname = "ftrace_dump_on_oops",
548 .data = &ftrace_dump_on_oops,
549 .maxlen = sizeof(int),
550 .mode = 0644,
551 .proc_handler = &proc_dointvec,
553 #endif
554 #ifdef CONFIG_MODULES
556 .ctl_name = KERN_MODPROBE,
557 .procname = "modprobe",
558 .data = &modprobe_path,
559 .maxlen = KMOD_PATH_LEN,
560 .mode = 0644,
561 .proc_handler = &proc_dostring,
562 .strategy = &sysctl_string,
565 .ctl_name = CTL_UNNUMBERED,
566 .procname = "modules_disabled",
567 .data = &modules_disabled,
568 .maxlen = sizeof(int),
569 .mode = 0644,
570 /* only handle a transition from default "0" to "1" */
571 .proc_handler = &proc_dointvec_minmax,
572 .extra1 = &one,
573 .extra2 = &one,
575 #endif
576 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
578 .ctl_name = KERN_HOTPLUG,
579 .procname = "hotplug",
580 .data = &uevent_helper,
581 .maxlen = UEVENT_HELPER_PATH_LEN,
582 .mode = 0644,
583 .proc_handler = &proc_dostring,
584 .strategy = &sysctl_string,
586 #endif
587 #ifdef CONFIG_CHR_DEV_SG
589 .ctl_name = KERN_SG_BIG_BUFF,
590 .procname = "sg-big-buff",
591 .data = &sg_big_buff,
592 .maxlen = sizeof (int),
593 .mode = 0444,
594 .proc_handler = &proc_dointvec,
596 #endif
597 #ifdef CONFIG_BSD_PROCESS_ACCT
599 .ctl_name = KERN_ACCT,
600 .procname = "acct",
601 .data = &acct_parm,
602 .maxlen = 3*sizeof(int),
603 .mode = 0644,
604 .proc_handler = &proc_dointvec,
606 #endif
607 #ifdef CONFIG_MAGIC_SYSRQ
609 .ctl_name = KERN_SYSRQ,
610 .procname = "sysrq",
611 .data = &__sysrq_enabled,
612 .maxlen = sizeof (int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec,
616 #endif
617 #ifdef CONFIG_PROC_SYSCTL
619 .procname = "cad_pid",
620 .data = NULL,
621 .maxlen = sizeof (int),
622 .mode = 0600,
623 .proc_handler = &proc_do_cad_pid,
625 #endif
627 .ctl_name = KERN_MAX_THREADS,
628 .procname = "threads-max",
629 .data = &max_threads,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec,
635 .ctl_name = KERN_RANDOM,
636 .procname = "random",
637 .mode = 0555,
638 .child = random_table,
641 .ctl_name = KERN_OVERFLOWUID,
642 .procname = "overflowuid",
643 .data = &overflowuid,
644 .maxlen = sizeof(int),
645 .mode = 0644,
646 .proc_handler = &proc_dointvec_minmax,
647 .strategy = &sysctl_intvec,
648 .extra1 = &minolduid,
649 .extra2 = &maxolduid,
652 .ctl_name = KERN_OVERFLOWGID,
653 .procname = "overflowgid",
654 .data = &overflowgid,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = &proc_dointvec_minmax,
658 .strategy = &sysctl_intvec,
659 .extra1 = &minolduid,
660 .extra2 = &maxolduid,
662 #ifdef CONFIG_S390
663 #ifdef CONFIG_MATHEMU
665 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
666 .procname = "ieee_emulation_warnings",
667 .data = &sysctl_ieee_emulation_warnings,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec,
672 #endif
674 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
675 .procname = "userprocess_debug",
676 .data = &sysctl_userprocess_debug,
677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec,
681 #endif
683 .ctl_name = KERN_PIDMAX,
684 .procname = "pid_max",
685 .data = &pid_max,
686 .maxlen = sizeof (int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec_minmax,
689 .strategy = sysctl_intvec,
690 .extra1 = &pid_max_min,
691 .extra2 = &pid_max_max,
694 .ctl_name = KERN_PANIC_ON_OOPS,
695 .procname = "panic_on_oops",
696 .data = &panic_on_oops,
697 .maxlen = sizeof(int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec,
701 #if defined CONFIG_PRINTK
703 .ctl_name = KERN_PRINTK,
704 .procname = "printk",
705 .data = &console_loglevel,
706 .maxlen = 4*sizeof(int),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec,
711 .ctl_name = KERN_PRINTK_RATELIMIT,
712 .procname = "printk_ratelimit",
713 .data = &printk_ratelimit_state.interval,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = &proc_dointvec_jiffies,
717 .strategy = &sysctl_jiffies,
720 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
721 .procname = "printk_ratelimit_burst",
722 .data = &printk_ratelimit_state.burst,
723 .maxlen = sizeof(int),
724 .mode = 0644,
725 .proc_handler = &proc_dointvec,
728 .ctl_name = CTL_UNNUMBERED,
729 .procname = "printk_delay",
730 .data = &printk_delay_msec,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = &proc_dointvec_minmax,
734 .strategy = &sysctl_intvec,
735 .extra1 = &zero,
736 .extra2 = &ten_thousand,
738 #endif
740 .ctl_name = KERN_NGROUPS_MAX,
741 .procname = "ngroups_max",
742 .data = &ngroups_max,
743 .maxlen = sizeof (int),
744 .mode = 0444,
745 .proc_handler = &proc_dointvec,
747 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
749 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
750 .procname = "unknown_nmi_panic",
751 .data = &unknown_nmi_panic,
752 .maxlen = sizeof (int),
753 .mode = 0644,
754 .proc_handler = &proc_dointvec,
757 .procname = "nmi_watchdog",
758 .data = &nmi_watchdog_enabled,
759 .maxlen = sizeof (int),
760 .mode = 0644,
761 .proc_handler = &proc_nmi_enabled,
763 #endif
764 #if defined(CONFIG_X86)
766 .ctl_name = KERN_PANIC_ON_NMI,
767 .procname = "panic_on_unrecovered_nmi",
768 .data = &panic_on_unrecovered_nmi,
769 .maxlen = sizeof(int),
770 .mode = 0644,
771 .proc_handler = &proc_dointvec,
774 .ctl_name = CTL_UNNUMBERED,
775 .procname = "panic_on_io_nmi",
776 .data = &panic_on_io_nmi,
777 .maxlen = sizeof(int),
778 .mode = 0644,
779 .proc_handler = &proc_dointvec,
782 .ctl_name = KERN_BOOTLOADER_TYPE,
783 .procname = "bootloader_type",
784 .data = &bootloader_type,
785 .maxlen = sizeof (int),
786 .mode = 0444,
787 .proc_handler = &proc_dointvec,
790 .ctl_name = CTL_UNNUMBERED,
791 .procname = "bootloader_version",
792 .data = &bootloader_version,
793 .maxlen = sizeof (int),
794 .mode = 0444,
795 .proc_handler = &proc_dointvec,
798 .ctl_name = CTL_UNNUMBERED,
799 .procname = "kstack_depth_to_print",
800 .data = &kstack_depth_to_print,
801 .maxlen = sizeof(int),
802 .mode = 0644,
803 .proc_handler = &proc_dointvec,
806 .ctl_name = CTL_UNNUMBERED,
807 .procname = "io_delay_type",
808 .data = &io_delay_type,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = &proc_dointvec,
813 #endif
814 #if defined(CONFIG_MMU)
816 .ctl_name = KERN_RANDOMIZE,
817 .procname = "randomize_va_space",
818 .data = &randomize_va_space,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = &proc_dointvec,
823 #endif
824 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
826 .ctl_name = KERN_SPIN_RETRY,
827 .procname = "spin_retry",
828 .data = &spin_retry,
829 .maxlen = sizeof (int),
830 .mode = 0644,
831 .proc_handler = &proc_dointvec,
833 #endif
834 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
836 .procname = "acpi_video_flags",
837 .data = &acpi_realmode_flags,
838 .maxlen = sizeof (unsigned long),
839 .mode = 0644,
840 .proc_handler = &proc_doulongvec_minmax,
842 #endif
843 #ifdef CONFIG_IA64
845 .ctl_name = KERN_IA64_UNALIGNED,
846 .procname = "ignore-unaligned-usertrap",
847 .data = &no_unaligned_warning,
848 .maxlen = sizeof (int),
849 .mode = 0644,
850 .proc_handler = &proc_dointvec,
853 .ctl_name = CTL_UNNUMBERED,
854 .procname = "unaligned-dump-stack",
855 .data = &unaligned_dump_stack,
856 .maxlen = sizeof (int),
857 .mode = 0644,
858 .proc_handler = &proc_dointvec,
860 #endif
861 #ifdef CONFIG_DETECT_SOFTLOCKUP
863 .ctl_name = CTL_UNNUMBERED,
864 .procname = "softlockup_panic",
865 .data = &softlockup_panic,
866 .maxlen = sizeof(int),
867 .mode = 0644,
868 .proc_handler = &proc_dointvec_minmax,
869 .strategy = &sysctl_intvec,
870 .extra1 = &zero,
871 .extra2 = &one,
874 .ctl_name = CTL_UNNUMBERED,
875 .procname = "softlockup_thresh",
876 .data = &softlockup_thresh,
877 .maxlen = sizeof(int),
878 .mode = 0644,
879 .proc_handler = &proc_dosoftlockup_thresh,
880 .strategy = &sysctl_intvec,
881 .extra1 = &neg_one,
882 .extra2 = &sixty,
884 #endif
885 #ifdef CONFIG_DETECT_HUNG_TASK
887 .ctl_name = CTL_UNNUMBERED,
888 .procname = "hung_task_panic",
889 .data = &sysctl_hung_task_panic,
890 .maxlen = sizeof(int),
891 .mode = 0644,
892 .proc_handler = &proc_dointvec_minmax,
893 .strategy = &sysctl_intvec,
894 .extra1 = &zero,
895 .extra2 = &one,
898 .ctl_name = CTL_UNNUMBERED,
899 .procname = "hung_task_check_count",
900 .data = &sysctl_hung_task_check_count,
901 .maxlen = sizeof(unsigned long),
902 .mode = 0644,
903 .proc_handler = &proc_doulongvec_minmax,
904 .strategy = &sysctl_intvec,
907 .ctl_name = CTL_UNNUMBERED,
908 .procname = "hung_task_timeout_secs",
909 .data = &sysctl_hung_task_timeout_secs,
910 .maxlen = sizeof(unsigned long),
911 .mode = 0644,
912 .proc_handler = &proc_dohung_task_timeout_secs,
913 .strategy = &sysctl_intvec,
916 .ctl_name = CTL_UNNUMBERED,
917 .procname = "hung_task_warnings",
918 .data = &sysctl_hung_task_warnings,
919 .maxlen = sizeof(unsigned long),
920 .mode = 0644,
921 .proc_handler = &proc_doulongvec_minmax,
922 .strategy = &sysctl_intvec,
924 #endif
925 #ifdef CONFIG_COMPAT
927 .ctl_name = KERN_COMPAT_LOG,
928 .procname = "compat-log",
929 .data = &compat_log,
930 .maxlen = sizeof (int),
931 .mode = 0644,
932 .proc_handler = &proc_dointvec,
934 #endif
935 #ifdef CONFIG_RT_MUTEXES
937 .ctl_name = KERN_MAX_LOCK_DEPTH,
938 .procname = "max_lock_depth",
939 .data = &max_lock_depth,
940 .maxlen = sizeof(int),
941 .mode = 0644,
942 .proc_handler = &proc_dointvec,
944 #endif
946 .ctl_name = CTL_UNNUMBERED,
947 .procname = "poweroff_cmd",
948 .data = &poweroff_cmd,
949 .maxlen = POWEROFF_CMD_PATH_LEN,
950 .mode = 0644,
951 .proc_handler = &proc_dostring,
952 .strategy = &sysctl_string,
954 #ifdef CONFIG_KEYS
956 .ctl_name = CTL_UNNUMBERED,
957 .procname = "keys",
958 .mode = 0555,
959 .child = key_sysctls,
961 #endif
962 #ifdef CONFIG_RCU_TORTURE_TEST
964 .ctl_name = CTL_UNNUMBERED,
965 .procname = "rcutorture_runnable",
966 .data = &rcutorture_runnable,
967 .maxlen = sizeof(int),
968 .mode = 0644,
969 .proc_handler = &proc_dointvec,
971 #endif
972 #ifdef CONFIG_SLOW_WORK
974 .ctl_name = CTL_UNNUMBERED,
975 .procname = "slow-work",
976 .mode = 0555,
977 .child = slow_work_sysctls,
979 #endif
980 #ifdef CONFIG_PERF_EVENTS
982 .ctl_name = CTL_UNNUMBERED,
983 .procname = "perf_event_paranoid",
984 .data = &sysctl_perf_event_paranoid,
985 .maxlen = sizeof(sysctl_perf_event_paranoid),
986 .mode = 0644,
987 .proc_handler = &proc_dointvec,
990 .ctl_name = CTL_UNNUMBERED,
991 .procname = "perf_event_mlock_kb",
992 .data = &sysctl_perf_event_mlock,
993 .maxlen = sizeof(sysctl_perf_event_mlock),
994 .mode = 0644,
995 .proc_handler = &proc_dointvec,
998 .ctl_name = CTL_UNNUMBERED,
999 .procname = "perf_event_max_sample_rate",
1000 .data = &sysctl_perf_event_sample_rate,
1001 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1002 .mode = 0644,
1003 .proc_handler = &proc_dointvec,
1005 #endif
1006 #ifdef CONFIG_KMEMCHECK
1008 .ctl_name = CTL_UNNUMBERED,
1009 .procname = "kmemcheck",
1010 .data = &kmemcheck_enabled,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
1013 .proc_handler = &proc_dointvec,
1015 #endif
1016 #ifdef CONFIG_BLOCK
1018 .ctl_name = CTL_UNNUMBERED,
1019 .procname = "blk_iopoll",
1020 .data = &blk_iopoll_enabled,
1021 .maxlen = sizeof(int),
1022 .mode = 0644,
1023 .proc_handler = &proc_dointvec,
1025 #endif
1027 * NOTE: do not add new entries to this table unless you have read
1028 * Documentation/sysctl/ctl_unnumbered.txt
1030 { .ctl_name = 0 }
1033 static struct ctl_table vm_table[] = {
1035 .ctl_name = VM_OVERCOMMIT_MEMORY,
1036 .procname = "overcommit_memory",
1037 .data = &sysctl_overcommit_memory,
1038 .maxlen = sizeof(sysctl_overcommit_memory),
1039 .mode = 0644,
1040 .proc_handler = &proc_dointvec,
1043 .ctl_name = VM_PANIC_ON_OOM,
1044 .procname = "panic_on_oom",
1045 .data = &sysctl_panic_on_oom,
1046 .maxlen = sizeof(sysctl_panic_on_oom),
1047 .mode = 0644,
1048 .proc_handler = &proc_dointvec,
1051 .ctl_name = CTL_UNNUMBERED,
1052 .procname = "oom_kill_allocating_task",
1053 .data = &sysctl_oom_kill_allocating_task,
1054 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1055 .mode = 0644,
1056 .proc_handler = &proc_dointvec,
1059 .ctl_name = CTL_UNNUMBERED,
1060 .procname = "oom_dump_tasks",
1061 .data = &sysctl_oom_dump_tasks,
1062 .maxlen = sizeof(sysctl_oom_dump_tasks),
1063 .mode = 0644,
1064 .proc_handler = &proc_dointvec,
1067 .ctl_name = VM_OVERCOMMIT_RATIO,
1068 .procname = "overcommit_ratio",
1069 .data = &sysctl_overcommit_ratio,
1070 .maxlen = sizeof(sysctl_overcommit_ratio),
1071 .mode = 0644,
1072 .proc_handler = &proc_dointvec,
1075 .ctl_name = VM_PAGE_CLUSTER,
1076 .procname = "page-cluster",
1077 .data = &page_cluster,
1078 .maxlen = sizeof(int),
1079 .mode = 0644,
1080 .proc_handler = &proc_dointvec,
1083 .ctl_name = VM_DIRTY_BACKGROUND,
1084 .procname = "dirty_background_ratio",
1085 .data = &dirty_background_ratio,
1086 .maxlen = sizeof(dirty_background_ratio),
1087 .mode = 0644,
1088 .proc_handler = &dirty_background_ratio_handler,
1089 .strategy = &sysctl_intvec,
1090 .extra1 = &zero,
1091 .extra2 = &one_hundred,
1094 .ctl_name = CTL_UNNUMBERED,
1095 .procname = "dirty_background_bytes",
1096 .data = &dirty_background_bytes,
1097 .maxlen = sizeof(dirty_background_bytes),
1098 .mode = 0644,
1099 .proc_handler = &dirty_background_bytes_handler,
1100 .strategy = &sysctl_intvec,
1101 .extra1 = &one_ul,
1104 .ctl_name = VM_DIRTY_RATIO,
1105 .procname = "dirty_ratio",
1106 .data = &vm_dirty_ratio,
1107 .maxlen = sizeof(vm_dirty_ratio),
1108 .mode = 0644,
1109 .proc_handler = &dirty_ratio_handler,
1110 .strategy = &sysctl_intvec,
1111 .extra1 = &zero,
1112 .extra2 = &one_hundred,
1115 .ctl_name = CTL_UNNUMBERED,
1116 .procname = "dirty_bytes",
1117 .data = &vm_dirty_bytes,
1118 .maxlen = sizeof(vm_dirty_bytes),
1119 .mode = 0644,
1120 .proc_handler = &dirty_bytes_handler,
1121 .strategy = &sysctl_intvec,
1122 .extra1 = &dirty_bytes_min,
1125 .procname = "dirty_writeback_centisecs",
1126 .data = &dirty_writeback_interval,
1127 .maxlen = sizeof(dirty_writeback_interval),
1128 .mode = 0644,
1129 .proc_handler = &dirty_writeback_centisecs_handler,
1132 .procname = "dirty_expire_centisecs",
1133 .data = &dirty_expire_interval,
1134 .maxlen = sizeof(dirty_expire_interval),
1135 .mode = 0644,
1136 .proc_handler = &proc_dointvec,
1139 .ctl_name = VM_NR_PDFLUSH_THREADS,
1140 .procname = "nr_pdflush_threads",
1141 .data = &nr_pdflush_threads,
1142 .maxlen = sizeof nr_pdflush_threads,
1143 .mode = 0444 /* read-only*/,
1144 .proc_handler = &proc_dointvec,
1147 .ctl_name = VM_SWAPPINESS,
1148 .procname = "swappiness",
1149 .data = &vm_swappiness,
1150 .maxlen = sizeof(vm_swappiness),
1151 .mode = 0644,
1152 .proc_handler = &proc_dointvec_minmax,
1153 .strategy = &sysctl_intvec,
1154 .extra1 = &zero,
1155 .extra2 = &one_hundred,
1157 #ifdef CONFIG_HUGETLB_PAGE
1159 .procname = "nr_hugepages",
1160 .data = NULL,
1161 .maxlen = sizeof(unsigned long),
1162 .mode = 0644,
1163 .proc_handler = &hugetlb_sysctl_handler,
1164 .extra1 = (void *)&hugetlb_zero,
1165 .extra2 = (void *)&hugetlb_infinity,
1168 .ctl_name = VM_HUGETLB_GROUP,
1169 .procname = "hugetlb_shm_group",
1170 .data = &sysctl_hugetlb_shm_group,
1171 .maxlen = sizeof(gid_t),
1172 .mode = 0644,
1173 .proc_handler = &proc_dointvec,
1176 .ctl_name = CTL_UNNUMBERED,
1177 .procname = "hugepages_treat_as_movable",
1178 .data = &hugepages_treat_as_movable,
1179 .maxlen = sizeof(int),
1180 .mode = 0644,
1181 .proc_handler = &hugetlb_treat_movable_handler,
1184 .ctl_name = CTL_UNNUMBERED,
1185 .procname = "nr_overcommit_hugepages",
1186 .data = NULL,
1187 .maxlen = sizeof(unsigned long),
1188 .mode = 0644,
1189 .proc_handler = &hugetlb_overcommit_handler,
1190 .extra1 = (void *)&hugetlb_zero,
1191 .extra2 = (void *)&hugetlb_infinity,
1193 #endif
1195 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1196 .procname = "lowmem_reserve_ratio",
1197 .data = &sysctl_lowmem_reserve_ratio,
1198 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1199 .mode = 0644,
1200 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1201 .strategy = &sysctl_intvec,
1204 .ctl_name = VM_DROP_PAGECACHE,
1205 .procname = "drop_caches",
1206 .data = &sysctl_drop_caches,
1207 .maxlen = sizeof(int),
1208 .mode = 0644,
1209 .proc_handler = drop_caches_sysctl_handler,
1210 .strategy = &sysctl_intvec,
1213 .ctl_name = VM_MIN_FREE_KBYTES,
1214 .procname = "min_free_kbytes",
1215 .data = &min_free_kbytes,
1216 .maxlen = sizeof(min_free_kbytes),
1217 .mode = 0644,
1218 .proc_handler = &min_free_kbytes_sysctl_handler,
1219 .strategy = &sysctl_intvec,
1220 .extra1 = &zero,
1223 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1224 .procname = "percpu_pagelist_fraction",
1225 .data = &percpu_pagelist_fraction,
1226 .maxlen = sizeof(percpu_pagelist_fraction),
1227 .mode = 0644,
1228 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1229 .strategy = &sysctl_intvec,
1230 .extra1 = &min_percpu_pagelist_fract,
1232 #ifdef CONFIG_MMU
1234 .ctl_name = VM_MAX_MAP_COUNT,
1235 .procname = "max_map_count",
1236 .data = &sysctl_max_map_count,
1237 .maxlen = sizeof(sysctl_max_map_count),
1238 .mode = 0644,
1239 .proc_handler = &proc_dointvec
1241 #else
1243 .ctl_name = CTL_UNNUMBERED,
1244 .procname = "nr_trim_pages",
1245 .data = &sysctl_nr_trim_pages,
1246 .maxlen = sizeof(sysctl_nr_trim_pages),
1247 .mode = 0644,
1248 .proc_handler = &proc_dointvec_minmax,
1249 .strategy = &sysctl_intvec,
1250 .extra1 = &zero,
1252 #endif
1254 .ctl_name = VM_LAPTOP_MODE,
1255 .procname = "laptop_mode",
1256 .data = &laptop_mode,
1257 .maxlen = sizeof(laptop_mode),
1258 .mode = 0644,
1259 .proc_handler = &proc_dointvec_jiffies,
1260 .strategy = &sysctl_jiffies,
1263 .ctl_name = VM_BLOCK_DUMP,
1264 .procname = "block_dump",
1265 .data = &block_dump,
1266 .maxlen = sizeof(block_dump),
1267 .mode = 0644,
1268 .proc_handler = &proc_dointvec,
1269 .strategy = &sysctl_intvec,
1270 .extra1 = &zero,
1273 .ctl_name = VM_VFS_CACHE_PRESSURE,
1274 .procname = "vfs_cache_pressure",
1275 .data = &sysctl_vfs_cache_pressure,
1276 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1277 .mode = 0644,
1278 .proc_handler = &proc_dointvec,
1279 .strategy = &sysctl_intvec,
1280 .extra1 = &zero,
1282 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1284 .ctl_name = VM_LEGACY_VA_LAYOUT,
1285 .procname = "legacy_va_layout",
1286 .data = &sysctl_legacy_va_layout,
1287 .maxlen = sizeof(sysctl_legacy_va_layout),
1288 .mode = 0644,
1289 .proc_handler = &proc_dointvec,
1290 .strategy = &sysctl_intvec,
1291 .extra1 = &zero,
1293 #endif
1294 #ifdef CONFIG_NUMA
1296 .ctl_name = VM_ZONE_RECLAIM_MODE,
1297 .procname = "zone_reclaim_mode",
1298 .data = &zone_reclaim_mode,
1299 .maxlen = sizeof(zone_reclaim_mode),
1300 .mode = 0644,
1301 .proc_handler = &proc_dointvec,
1302 .strategy = &sysctl_intvec,
1303 .extra1 = &zero,
1306 .ctl_name = VM_MIN_UNMAPPED,
1307 .procname = "min_unmapped_ratio",
1308 .data = &sysctl_min_unmapped_ratio,
1309 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1310 .mode = 0644,
1311 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1312 .strategy = &sysctl_intvec,
1313 .extra1 = &zero,
1314 .extra2 = &one_hundred,
1317 .ctl_name = VM_MIN_SLAB,
1318 .procname = "min_slab_ratio",
1319 .data = &sysctl_min_slab_ratio,
1320 .maxlen = sizeof(sysctl_min_slab_ratio),
1321 .mode = 0644,
1322 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1323 .strategy = &sysctl_intvec,
1324 .extra1 = &zero,
1325 .extra2 = &one_hundred,
1327 #endif
1328 #ifdef CONFIG_SMP
1330 .ctl_name = CTL_UNNUMBERED,
1331 .procname = "stat_interval",
1332 .data = &sysctl_stat_interval,
1333 .maxlen = sizeof(sysctl_stat_interval),
1334 .mode = 0644,
1335 .proc_handler = &proc_dointvec_jiffies,
1336 .strategy = &sysctl_jiffies,
1338 #endif
1340 .ctl_name = CTL_UNNUMBERED,
1341 .procname = "mmap_min_addr",
1342 .data = &dac_mmap_min_addr,
1343 .maxlen = sizeof(unsigned long),
1344 .mode = 0644,
1345 .proc_handler = &mmap_min_addr_handler,
1347 #ifdef CONFIG_NUMA
1349 .ctl_name = CTL_UNNUMBERED,
1350 .procname = "numa_zonelist_order",
1351 .data = &numa_zonelist_order,
1352 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1353 .mode = 0644,
1354 .proc_handler = &numa_zonelist_order_handler,
1355 .strategy = &sysctl_string,
1357 #endif
1358 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1359 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1361 .ctl_name = VM_VDSO_ENABLED,
1362 .procname = "vdso_enabled",
1363 .data = &vdso_enabled,
1364 .maxlen = sizeof(vdso_enabled),
1365 .mode = 0644,
1366 .proc_handler = &proc_dointvec,
1367 .strategy = &sysctl_intvec,
1368 .extra1 = &zero,
1370 #endif
1371 #ifdef CONFIG_HIGHMEM
1373 .ctl_name = CTL_UNNUMBERED,
1374 .procname = "highmem_is_dirtyable",
1375 .data = &vm_highmem_is_dirtyable,
1376 .maxlen = sizeof(vm_highmem_is_dirtyable),
1377 .mode = 0644,
1378 .proc_handler = &proc_dointvec_minmax,
1379 .strategy = &sysctl_intvec,
1380 .extra1 = &zero,
1381 .extra2 = &one,
1383 #endif
1385 .ctl_name = CTL_UNNUMBERED,
1386 .procname = "scan_unevictable_pages",
1387 .data = &scan_unevictable_pages,
1388 .maxlen = sizeof(scan_unevictable_pages),
1389 .mode = 0644,
1390 .proc_handler = &scan_unevictable_handler,
1393 * NOTE: do not add new entries to this table unless you have read
1394 * Documentation/sysctl/ctl_unnumbered.txt
1396 { .ctl_name = 0 }
1399 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1400 static struct ctl_table binfmt_misc_table[] = {
1401 { .ctl_name = 0 }
1403 #endif
1405 static struct ctl_table fs_table[] = {
1407 .ctl_name = FS_NRINODE,
1408 .procname = "inode-nr",
1409 .data = &inodes_stat,
1410 .maxlen = 2*sizeof(int),
1411 .mode = 0444,
1412 .proc_handler = &proc_dointvec,
1415 .ctl_name = FS_STATINODE,
1416 .procname = "inode-state",
1417 .data = &inodes_stat,
1418 .maxlen = 7*sizeof(int),
1419 .mode = 0444,
1420 .proc_handler = &proc_dointvec,
1423 .procname = "file-nr",
1424 .data = &files_stat,
1425 .maxlen = 3*sizeof(int),
1426 .mode = 0444,
1427 .proc_handler = &proc_nr_files,
1430 .ctl_name = FS_MAXFILE,
1431 .procname = "file-max",
1432 .data = &files_stat.max_files,
1433 .maxlen = sizeof(int),
1434 .mode = 0644,
1435 .proc_handler = &proc_dointvec,
1438 .ctl_name = CTL_UNNUMBERED,
1439 .procname = "nr_open",
1440 .data = &sysctl_nr_open,
1441 .maxlen = sizeof(int),
1442 .mode = 0644,
1443 .proc_handler = &proc_dointvec_minmax,
1444 .extra1 = &sysctl_nr_open_min,
1445 .extra2 = &sysctl_nr_open_max,
1448 .ctl_name = FS_DENTRY,
1449 .procname = "dentry-state",
1450 .data = &dentry_stat,
1451 .maxlen = 6*sizeof(int),
1452 .mode = 0444,
1453 .proc_handler = &proc_dointvec,
1456 .ctl_name = FS_OVERFLOWUID,
1457 .procname = "overflowuid",
1458 .data = &fs_overflowuid,
1459 .maxlen = sizeof(int),
1460 .mode = 0644,
1461 .proc_handler = &proc_dointvec_minmax,
1462 .strategy = &sysctl_intvec,
1463 .extra1 = &minolduid,
1464 .extra2 = &maxolduid,
1467 .ctl_name = FS_OVERFLOWGID,
1468 .procname = "overflowgid",
1469 .data = &fs_overflowgid,
1470 .maxlen = sizeof(int),
1471 .mode = 0644,
1472 .proc_handler = &proc_dointvec_minmax,
1473 .strategy = &sysctl_intvec,
1474 .extra1 = &minolduid,
1475 .extra2 = &maxolduid,
1477 #ifdef CONFIG_FILE_LOCKING
1479 .ctl_name = FS_LEASES,
1480 .procname = "leases-enable",
1481 .data = &leases_enable,
1482 .maxlen = sizeof(int),
1483 .mode = 0644,
1484 .proc_handler = &proc_dointvec,
1486 #endif
1487 #ifdef CONFIG_DNOTIFY
1489 .ctl_name = FS_DIR_NOTIFY,
1490 .procname = "dir-notify-enable",
1491 .data = &dir_notify_enable,
1492 .maxlen = sizeof(int),
1493 .mode = 0644,
1494 .proc_handler = &proc_dointvec,
1496 #endif
1497 #ifdef CONFIG_MMU
1498 #ifdef CONFIG_FILE_LOCKING
1500 .ctl_name = FS_LEASE_TIME,
1501 .procname = "lease-break-time",
1502 .data = &lease_break_time,
1503 .maxlen = sizeof(int),
1504 .mode = 0644,
1505 .proc_handler = &proc_dointvec,
1507 #endif
1508 #ifdef CONFIG_AIO
1510 .procname = "aio-nr",
1511 .data = &aio_nr,
1512 .maxlen = sizeof(aio_nr),
1513 .mode = 0444,
1514 .proc_handler = &proc_doulongvec_minmax,
1517 .procname = "aio-max-nr",
1518 .data = &aio_max_nr,
1519 .maxlen = sizeof(aio_max_nr),
1520 .mode = 0644,
1521 .proc_handler = &proc_doulongvec_minmax,
1523 #endif /* CONFIG_AIO */
1524 #ifdef CONFIG_INOTIFY_USER
1526 .ctl_name = FS_INOTIFY,
1527 .procname = "inotify",
1528 .mode = 0555,
1529 .child = inotify_table,
1531 #endif
1532 #ifdef CONFIG_EPOLL
1534 .procname = "epoll",
1535 .mode = 0555,
1536 .child = epoll_table,
1538 #endif
1539 #endif
1541 .ctl_name = KERN_SETUID_DUMPABLE,
1542 .procname = "suid_dumpable",
1543 .data = &suid_dumpable,
1544 .maxlen = sizeof(int),
1545 .mode = 0644,
1546 .proc_handler = &proc_dointvec_minmax,
1547 .strategy = &sysctl_intvec,
1548 .extra1 = &zero,
1549 .extra2 = &two,
1551 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1553 .ctl_name = CTL_UNNUMBERED,
1554 .procname = "binfmt_misc",
1555 .mode = 0555,
1556 .child = binfmt_misc_table,
1558 #endif
1560 * NOTE: do not add new entries to this table unless you have read
1561 * Documentation/sysctl/ctl_unnumbered.txt
1563 { .ctl_name = 0 }
1566 static struct ctl_table debug_table[] = {
1567 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1569 .ctl_name = CTL_UNNUMBERED,
1570 .procname = "exception-trace",
1571 .data = &show_unhandled_signals,
1572 .maxlen = sizeof(int),
1573 .mode = 0644,
1574 .proc_handler = proc_dointvec
1576 #endif
1577 { .ctl_name = 0 }
1580 static struct ctl_table dev_table[] = {
1581 { .ctl_name = 0 }
1584 static DEFINE_SPINLOCK(sysctl_lock);
1586 /* called under sysctl_lock */
1587 static int use_table(struct ctl_table_header *p)
1589 if (unlikely(p->unregistering))
1590 return 0;
1591 p->used++;
1592 return 1;
1595 /* called under sysctl_lock */
1596 static void unuse_table(struct ctl_table_header *p)
1598 if (!--p->used)
1599 if (unlikely(p->unregistering))
1600 complete(p->unregistering);
1603 /* called under sysctl_lock, will reacquire if has to wait */
1604 static void start_unregistering(struct ctl_table_header *p)
1607 * if p->used is 0, nobody will ever touch that entry again;
1608 * we'll eliminate all paths to it before dropping sysctl_lock
1610 if (unlikely(p->used)) {
1611 struct completion wait;
1612 init_completion(&wait);
1613 p->unregistering = &wait;
1614 spin_unlock(&sysctl_lock);
1615 wait_for_completion(&wait);
1616 spin_lock(&sysctl_lock);
1617 } else {
1618 /* anything non-NULL; we'll never dereference it */
1619 p->unregistering = ERR_PTR(-EINVAL);
1622 * do not remove from the list until nobody holds it; walking the
1623 * list in do_sysctl() relies on that.
1625 list_del_init(&p->ctl_entry);
1628 void sysctl_head_get(struct ctl_table_header *head)
1630 spin_lock(&sysctl_lock);
1631 head->count++;
1632 spin_unlock(&sysctl_lock);
1635 void sysctl_head_put(struct ctl_table_header *head)
1637 spin_lock(&sysctl_lock);
1638 if (!--head->count)
1639 kfree(head);
1640 spin_unlock(&sysctl_lock);
1643 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1645 if (!head)
1646 BUG();
1647 spin_lock(&sysctl_lock);
1648 if (!use_table(head))
1649 head = ERR_PTR(-ENOENT);
1650 spin_unlock(&sysctl_lock);
1651 return head;
1654 void sysctl_head_finish(struct ctl_table_header *head)
1656 if (!head)
1657 return;
1658 spin_lock(&sysctl_lock);
1659 unuse_table(head);
1660 spin_unlock(&sysctl_lock);
1663 static struct ctl_table_set *
1664 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1666 struct ctl_table_set *set = &root->default_set;
1667 if (root->lookup)
1668 set = root->lookup(root, namespaces);
1669 return set;
1672 static struct list_head *
1673 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1675 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1676 return &set->list;
1679 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1680 struct ctl_table_header *prev)
1682 struct ctl_table_root *root;
1683 struct list_head *header_list;
1684 struct ctl_table_header *head;
1685 struct list_head *tmp;
1687 spin_lock(&sysctl_lock);
1688 if (prev) {
1689 head = prev;
1690 tmp = &prev->ctl_entry;
1691 unuse_table(prev);
1692 goto next;
1694 tmp = &root_table_header.ctl_entry;
1695 for (;;) {
1696 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1698 if (!use_table(head))
1699 goto next;
1700 spin_unlock(&sysctl_lock);
1701 return head;
1702 next:
1703 root = head->root;
1704 tmp = tmp->next;
1705 header_list = lookup_header_list(root, namespaces);
1706 if (tmp != header_list)
1707 continue;
1709 do {
1710 root = list_entry(root->root_list.next,
1711 struct ctl_table_root, root_list);
1712 if (root == &sysctl_table_root)
1713 goto out;
1714 header_list = lookup_header_list(root, namespaces);
1715 } while (list_empty(header_list));
1716 tmp = header_list->next;
1718 out:
1719 spin_unlock(&sysctl_lock);
1720 return NULL;
1723 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1725 return __sysctl_head_next(current->nsproxy, prev);
1728 void register_sysctl_root(struct ctl_table_root *root)
1730 spin_lock(&sysctl_lock);
1731 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1732 spin_unlock(&sysctl_lock);
1735 #ifdef CONFIG_SYSCTL_SYSCALL
1736 /* Perform the actual read/write of a sysctl table entry. */
1737 static int do_sysctl_strategy(struct ctl_table_root *root,
1738 struct ctl_table *table,
1739 void __user *oldval, size_t __user *oldlenp,
1740 void __user *newval, size_t newlen)
1742 int op = 0, rc;
1744 if (oldval)
1745 op |= MAY_READ;
1746 if (newval)
1747 op |= MAY_WRITE;
1748 if (sysctl_perm(root, table, op))
1749 return -EPERM;
1751 if (table->strategy) {
1752 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1753 if (rc < 0)
1754 return rc;
1755 if (rc > 0)
1756 return 0;
1759 /* If there is no strategy routine, or if the strategy returns
1760 * zero, proceed with automatic r/w */
1761 if (table->data && table->maxlen) {
1762 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1763 if (rc < 0)
1764 return rc;
1766 return 0;
1769 static int parse_table(int __user *name, int nlen,
1770 void __user *oldval, size_t __user *oldlenp,
1771 void __user *newval, size_t newlen,
1772 struct ctl_table_root *root,
1773 struct ctl_table *table)
1775 int n;
1776 repeat:
1777 if (!nlen)
1778 return -ENOTDIR;
1779 if (get_user(n, name))
1780 return -EFAULT;
1781 for ( ; table->ctl_name || table->procname; table++) {
1782 if (!table->ctl_name)
1783 continue;
1784 if (n == table->ctl_name) {
1785 int error;
1786 if (table->child) {
1787 if (sysctl_perm(root, table, MAY_EXEC))
1788 return -EPERM;
1789 name++;
1790 nlen--;
1791 table = table->child;
1792 goto repeat;
1794 error = do_sysctl_strategy(root, table,
1795 oldval, oldlenp,
1796 newval, newlen);
1797 return error;
1800 return -ENOTDIR;
1803 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1804 void __user *newval, size_t newlen)
1806 struct ctl_table_header *head;
1807 int error = -ENOTDIR;
1809 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1810 return -ENOTDIR;
1811 if (oldval) {
1812 int old_len;
1813 if (!oldlenp || get_user(old_len, oldlenp))
1814 return -EFAULT;
1817 for (head = sysctl_head_next(NULL); head;
1818 head = sysctl_head_next(head)) {
1819 error = parse_table(name, nlen, oldval, oldlenp,
1820 newval, newlen,
1821 head->root, head->ctl_table);
1822 if (error != -ENOTDIR) {
1823 sysctl_head_finish(head);
1824 break;
1827 return error;
1830 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1832 struct __sysctl_args tmp;
1833 int error;
1835 if (copy_from_user(&tmp, args, sizeof(tmp)))
1836 return -EFAULT;
1838 error = deprecated_sysctl_warning(&tmp);
1839 if (error)
1840 goto out;
1842 lock_kernel();
1843 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1844 tmp.newval, tmp.newlen);
1845 unlock_kernel();
1846 out:
1847 return error;
1849 #endif /* CONFIG_SYSCTL_SYSCALL */
1852 * sysctl_perm does NOT grant the superuser all rights automatically, because
1853 * some sysctl variables are readonly even to root.
1856 static int test_perm(int mode, int op)
1858 if (!current_euid())
1859 mode >>= 6;
1860 else if (in_egroup_p(0))
1861 mode >>= 3;
1862 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1863 return 0;
1864 return -EACCES;
1867 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1869 int error;
1870 int mode;
1872 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1873 if (error)
1874 return error;
1876 if (root->permissions)
1877 mode = root->permissions(root, current->nsproxy, table);
1878 else
1879 mode = table->mode;
1881 return test_perm(mode, op);
1884 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1886 for (; table->ctl_name || table->procname; table++) {
1887 table->parent = parent;
1888 if (table->child)
1889 sysctl_set_parent(table, table->child);
1893 static __init int sysctl_init(void)
1895 sysctl_set_parent(NULL, root_table);
1896 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1898 int err;
1899 err = sysctl_check_table(current->nsproxy, root_table);
1901 #endif
1902 return 0;
1905 core_initcall(sysctl_init);
1907 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1908 struct ctl_table *table)
1910 struct ctl_table *p;
1911 const char *s = branch->procname;
1913 /* branch should have named subdirectory as its first element */
1914 if (!s || !branch->child)
1915 return NULL;
1917 /* ... and nothing else */
1918 if (branch[1].procname || branch[1].ctl_name)
1919 return NULL;
1921 /* table should contain subdirectory with the same name */
1922 for (p = table; p->procname || p->ctl_name; p++) {
1923 if (!p->child)
1924 continue;
1925 if (p->procname && strcmp(p->procname, s) == 0)
1926 return p;
1928 return NULL;
1931 /* see if attaching q to p would be an improvement */
1932 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1934 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1935 struct ctl_table *next;
1936 int is_better = 0;
1937 int not_in_parent = !p->attached_by;
1939 while ((next = is_branch_in(by, to)) != NULL) {
1940 if (by == q->attached_by)
1941 is_better = 1;
1942 if (to == p->attached_by)
1943 not_in_parent = 1;
1944 by = by->child;
1945 to = next->child;
1948 if (is_better && not_in_parent) {
1949 q->attached_by = by;
1950 q->attached_to = to;
1951 q->parent = p;
1956 * __register_sysctl_paths - register a sysctl hierarchy
1957 * @root: List of sysctl headers to register on
1958 * @namespaces: Data to compute which lists of sysctl entries are visible
1959 * @path: The path to the directory the sysctl table is in.
1960 * @table: the top-level table structure
1962 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1963 * array. A completely 0 filled entry terminates the table.
1965 * The members of the &struct ctl_table structure are used as follows:
1967 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1968 * must be unique within that level of sysctl
1970 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1971 * enter a sysctl file
1973 * data - a pointer to data for use by proc_handler
1975 * maxlen - the maximum size in bytes of the data
1977 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1979 * child - a pointer to the child sysctl table if this entry is a directory, or
1980 * %NULL.
1982 * proc_handler - the text handler routine (described below)
1984 * strategy - the strategy routine (described below)
1986 * de - for internal use by the sysctl routines
1988 * extra1, extra2 - extra pointers usable by the proc handler routines
1990 * Leaf nodes in the sysctl tree will be represented by a single file
1991 * under /proc; non-leaf nodes will be represented by directories.
1993 * sysctl(2) can automatically manage read and write requests through
1994 * the sysctl table. The data and maxlen fields of the ctl_table
1995 * struct enable minimal validation of the values being written to be
1996 * performed, and the mode field allows minimal authentication.
1998 * More sophisticated management can be enabled by the provision of a
1999 * strategy routine with the table entry. This will be called before
2000 * any automatic read or write of the data is performed.
2002 * The strategy routine may return
2004 * < 0 - Error occurred (error is passed to user process)
2006 * 0 - OK - proceed with automatic read or write.
2008 * > 0 - OK - read or write has been done by the strategy routine, so
2009 * return immediately.
2011 * There must be a proc_handler routine for any terminal nodes
2012 * mirrored under /proc/sys (non-terminals are handled by a built-in
2013 * directory handler). Several default handlers are available to
2014 * cover common cases -
2016 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2017 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2018 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2020 * It is the handler's job to read the input buffer from user memory
2021 * and process it. The handler should return 0 on success.
2023 * This routine returns %NULL on a failure to register, and a pointer
2024 * to the table header on success.
2026 struct ctl_table_header *__register_sysctl_paths(
2027 struct ctl_table_root *root,
2028 struct nsproxy *namespaces,
2029 const struct ctl_path *path, struct ctl_table *table)
2031 struct ctl_table_header *header;
2032 struct ctl_table *new, **prevp;
2033 unsigned int n, npath;
2034 struct ctl_table_set *set;
2036 /* Count the path components */
2037 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2041 * For each path component, allocate a 2-element ctl_table array.
2042 * The first array element will be filled with the sysctl entry
2043 * for this, the second will be the sentinel (ctl_name == 0).
2045 * We allocate everything in one go so that we don't have to
2046 * worry about freeing additional memory in unregister_sysctl_table.
2048 header = kzalloc(sizeof(struct ctl_table_header) +
2049 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2050 if (!header)
2051 return NULL;
2053 new = (struct ctl_table *) (header + 1);
2055 /* Now connect the dots */
2056 prevp = &header->ctl_table;
2057 for (n = 0; n < npath; ++n, ++path) {
2058 /* Copy the procname */
2059 new->procname = path->procname;
2060 new->ctl_name = path->ctl_name;
2061 new->mode = 0555;
2063 *prevp = new;
2064 prevp = &new->child;
2066 new += 2;
2068 *prevp = table;
2069 header->ctl_table_arg = table;
2071 INIT_LIST_HEAD(&header->ctl_entry);
2072 header->used = 0;
2073 header->unregistering = NULL;
2074 header->root = root;
2075 sysctl_set_parent(NULL, header->ctl_table);
2076 header->count = 1;
2077 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2078 if (sysctl_check_table(namespaces, header->ctl_table)) {
2079 kfree(header);
2080 return NULL;
2082 #endif
2083 spin_lock(&sysctl_lock);
2084 header->set = lookup_header_set(root, namespaces);
2085 header->attached_by = header->ctl_table;
2086 header->attached_to = root_table;
2087 header->parent = &root_table_header;
2088 for (set = header->set; set; set = set->parent) {
2089 struct ctl_table_header *p;
2090 list_for_each_entry(p, &set->list, ctl_entry) {
2091 if (p->unregistering)
2092 continue;
2093 try_attach(p, header);
2096 header->parent->count++;
2097 list_add_tail(&header->ctl_entry, &header->set->list);
2098 spin_unlock(&sysctl_lock);
2100 return header;
2104 * register_sysctl_table_path - register a sysctl table hierarchy
2105 * @path: The path to the directory the sysctl table is in.
2106 * @table: the top-level table structure
2108 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2109 * array. A completely 0 filled entry terminates the table.
2111 * See __register_sysctl_paths for more details.
2113 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2114 struct ctl_table *table)
2116 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2117 path, table);
2121 * register_sysctl_table - register a sysctl table hierarchy
2122 * @table: the top-level table structure
2124 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2125 * array. A completely 0 filled entry terminates the table.
2127 * See register_sysctl_paths for more details.
2129 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2131 static const struct ctl_path null_path[] = { {} };
2133 return register_sysctl_paths(null_path, table);
2137 * unregister_sysctl_table - unregister a sysctl table hierarchy
2138 * @header: the header returned from register_sysctl_table
2140 * Unregisters the sysctl table and all children. proc entries may not
2141 * actually be removed until they are no longer used by anyone.
2143 void unregister_sysctl_table(struct ctl_table_header * header)
2145 might_sleep();
2147 if (header == NULL)
2148 return;
2150 spin_lock(&sysctl_lock);
2151 start_unregistering(header);
2152 if (!--header->parent->count) {
2153 WARN_ON(1);
2154 kfree(header->parent);
2156 if (!--header->count)
2157 kfree(header);
2158 spin_unlock(&sysctl_lock);
2161 int sysctl_is_seen(struct ctl_table_header *p)
2163 struct ctl_table_set *set = p->set;
2164 int res;
2165 spin_lock(&sysctl_lock);
2166 if (p->unregistering)
2167 res = 0;
2168 else if (!set->is_seen)
2169 res = 1;
2170 else
2171 res = set->is_seen(set);
2172 spin_unlock(&sysctl_lock);
2173 return res;
2176 void setup_sysctl_set(struct ctl_table_set *p,
2177 struct ctl_table_set *parent,
2178 int (*is_seen)(struct ctl_table_set *))
2180 INIT_LIST_HEAD(&p->list);
2181 p->parent = parent ? parent : &sysctl_table_root.default_set;
2182 p->is_seen = is_seen;
2185 #else /* !CONFIG_SYSCTL */
2186 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2188 return NULL;
2191 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2192 struct ctl_table *table)
2194 return NULL;
2197 void unregister_sysctl_table(struct ctl_table_header * table)
2201 void setup_sysctl_set(struct ctl_table_set *p,
2202 struct ctl_table_set *parent,
2203 int (*is_seen)(struct ctl_table_set *))
2207 void sysctl_head_put(struct ctl_table_header *head)
2211 #endif /* CONFIG_SYSCTL */
2214 * /proc/sys support
2217 #ifdef CONFIG_PROC_SYSCTL
2219 static int _proc_do_string(void* data, int maxlen, int write,
2220 struct file *filp, void __user *buffer,
2221 size_t *lenp, loff_t *ppos)
2223 size_t len;
2224 char __user *p;
2225 char c;
2227 if (!data || !maxlen || !*lenp) {
2228 *lenp = 0;
2229 return 0;
2232 if (write) {
2233 len = 0;
2234 p = buffer;
2235 while (len < *lenp) {
2236 if (get_user(c, p++))
2237 return -EFAULT;
2238 if (c == 0 || c == '\n')
2239 break;
2240 len++;
2242 if (len >= maxlen)
2243 len = maxlen-1;
2244 if(copy_from_user(data, buffer, len))
2245 return -EFAULT;
2246 ((char *) data)[len] = 0;
2247 *ppos += *lenp;
2248 } else {
2249 len = strlen(data);
2250 if (len > maxlen)
2251 len = maxlen;
2253 if (*ppos > len) {
2254 *lenp = 0;
2255 return 0;
2258 data += *ppos;
2259 len -= *ppos;
2261 if (len > *lenp)
2262 len = *lenp;
2263 if (len)
2264 if(copy_to_user(buffer, data, len))
2265 return -EFAULT;
2266 if (len < *lenp) {
2267 if(put_user('\n', ((char __user *) buffer) + len))
2268 return -EFAULT;
2269 len++;
2271 *lenp = len;
2272 *ppos += len;
2274 return 0;
2278 * proc_dostring - read a string sysctl
2279 * @table: the sysctl table
2280 * @write: %TRUE if this is a write to the sysctl file
2281 * @filp: the file structure
2282 * @buffer: the user buffer
2283 * @lenp: the size of the user buffer
2284 * @ppos: file position
2286 * Reads/writes a string from/to the user buffer. If the kernel
2287 * buffer provided is not large enough to hold the string, the
2288 * string is truncated. The copied string is %NULL-terminated.
2289 * If the string is being read by the user process, it is copied
2290 * and a newline '\n' is added. It is truncated if the buffer is
2291 * not large enough.
2293 * Returns 0 on success.
2295 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2296 void __user *buffer, size_t *lenp, loff_t *ppos)
2298 return _proc_do_string(table->data, table->maxlen, write, filp,
2299 buffer, lenp, ppos);
2303 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2304 int *valp,
2305 int write, void *data)
2307 if (write) {
2308 *valp = *negp ? -*lvalp : *lvalp;
2309 } else {
2310 int val = *valp;
2311 if (val < 0) {
2312 *negp = -1;
2313 *lvalp = (unsigned long)-val;
2314 } else {
2315 *negp = 0;
2316 *lvalp = (unsigned long)val;
2319 return 0;
2322 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2323 int write, struct file *filp, void __user *buffer,
2324 size_t *lenp, loff_t *ppos,
2325 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2326 int write, void *data),
2327 void *data)
2329 #define TMPBUFLEN 21
2330 int *i, vleft, first = 1, neg;
2331 unsigned long lval;
2332 size_t left, len;
2334 char buf[TMPBUFLEN], *p;
2335 char __user *s = buffer;
2337 if (!tbl_data || !table->maxlen || !*lenp ||
2338 (*ppos && !write)) {
2339 *lenp = 0;
2340 return 0;
2343 i = (int *) tbl_data;
2344 vleft = table->maxlen / sizeof(*i);
2345 left = *lenp;
2347 if (!conv)
2348 conv = do_proc_dointvec_conv;
2350 for (; left && vleft--; i++, first=0) {
2351 if (write) {
2352 while (left) {
2353 char c;
2354 if (get_user(c, s))
2355 return -EFAULT;
2356 if (!isspace(c))
2357 break;
2358 left--;
2359 s++;
2361 if (!left)
2362 break;
2363 neg = 0;
2364 len = left;
2365 if (len > sizeof(buf) - 1)
2366 len = sizeof(buf) - 1;
2367 if (copy_from_user(buf, s, len))
2368 return -EFAULT;
2369 buf[len] = 0;
2370 p = buf;
2371 if (*p == '-' && left > 1) {
2372 neg = 1;
2373 p++;
2375 if (*p < '0' || *p > '9')
2376 break;
2378 lval = simple_strtoul(p, &p, 0);
2380 len = p-buf;
2381 if ((len < left) && *p && !isspace(*p))
2382 break;
2383 s += len;
2384 left -= len;
2386 if (conv(&neg, &lval, i, 1, data))
2387 break;
2388 } else {
2389 p = buf;
2390 if (!first)
2391 *p++ = '\t';
2393 if (conv(&neg, &lval, i, 0, data))
2394 break;
2396 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2397 len = strlen(buf);
2398 if (len > left)
2399 len = left;
2400 if(copy_to_user(s, buf, len))
2401 return -EFAULT;
2402 left -= len;
2403 s += len;
2407 if (!write && !first && left) {
2408 if(put_user('\n', s))
2409 return -EFAULT;
2410 left--, s++;
2412 if (write) {
2413 while (left) {
2414 char c;
2415 if (get_user(c, s++))
2416 return -EFAULT;
2417 if (!isspace(c))
2418 break;
2419 left--;
2422 if (write && first)
2423 return -EINVAL;
2424 *lenp -= left;
2425 *ppos += *lenp;
2426 return 0;
2427 #undef TMPBUFLEN
2430 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2431 void __user *buffer, size_t *lenp, loff_t *ppos,
2432 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2433 int write, void *data),
2434 void *data)
2436 return __do_proc_dointvec(table->data, table, write, filp,
2437 buffer, lenp, ppos, conv, data);
2441 * proc_dointvec - read a vector of integers
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @filp: the file structure
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
2447 * @ppos: file position
2449 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2450 * values from/to the user buffer, treated as an ASCII string.
2452 * Returns 0 on success.
2454 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2455 void __user *buffer, size_t *lenp, loff_t *ppos)
2457 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2458 NULL,NULL);
2462 * Taint values can only be increased
2463 * This means we can safely use a temporary.
2465 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2466 void __user *buffer, size_t *lenp, loff_t *ppos)
2468 struct ctl_table t;
2469 unsigned long tmptaint = get_taint();
2470 int err;
2472 if (write && !capable(CAP_SYS_ADMIN))
2473 return -EPERM;
2475 t = *table;
2476 t.data = &tmptaint;
2477 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2478 if (err < 0)
2479 return err;
2481 if (write) {
2483 * Poor man's atomic or. Not worth adding a primitive
2484 * to everyone's atomic.h for this
2486 int i;
2487 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2488 if ((tmptaint >> i) & 1)
2489 add_taint(i);
2493 return err;
2496 struct do_proc_dointvec_minmax_conv_param {
2497 int *min;
2498 int *max;
2501 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2502 int *valp,
2503 int write, void *data)
2505 struct do_proc_dointvec_minmax_conv_param *param = data;
2506 if (write) {
2507 int val = *negp ? -*lvalp : *lvalp;
2508 if ((param->min && *param->min > val) ||
2509 (param->max && *param->max < val))
2510 return -EINVAL;
2511 *valp = val;
2512 } else {
2513 int val = *valp;
2514 if (val < 0) {
2515 *negp = -1;
2516 *lvalp = (unsigned long)-val;
2517 } else {
2518 *negp = 0;
2519 *lvalp = (unsigned long)val;
2522 return 0;
2526 * proc_dointvec_minmax - read a vector of integers with min/max values
2527 * @table: the sysctl table
2528 * @write: %TRUE if this is a write to the sysctl file
2529 * @filp: the file structure
2530 * @buffer: the user buffer
2531 * @lenp: the size of the user buffer
2532 * @ppos: file position
2534 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2535 * values from/to the user buffer, treated as an ASCII string.
2537 * This routine will ensure the values are within the range specified by
2538 * table->extra1 (min) and table->extra2 (max).
2540 * Returns 0 on success.
2542 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2543 void __user *buffer, size_t *lenp, loff_t *ppos)
2545 struct do_proc_dointvec_minmax_conv_param param = {
2546 .min = (int *) table->extra1,
2547 .max = (int *) table->extra2,
2549 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2550 do_proc_dointvec_minmax_conv, &param);
2553 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2554 struct file *filp,
2555 void __user *buffer,
2556 size_t *lenp, loff_t *ppos,
2557 unsigned long convmul,
2558 unsigned long convdiv)
2560 #define TMPBUFLEN 21
2561 unsigned long *i, *min, *max, val;
2562 int vleft, first=1, neg;
2563 size_t len, left;
2564 char buf[TMPBUFLEN], *p;
2565 char __user *s = buffer;
2567 if (!data || !table->maxlen || !*lenp ||
2568 (*ppos && !write)) {
2569 *lenp = 0;
2570 return 0;
2573 i = (unsigned long *) data;
2574 min = (unsigned long *) table->extra1;
2575 max = (unsigned long *) table->extra2;
2576 vleft = table->maxlen / sizeof(unsigned long);
2577 left = *lenp;
2579 for (; left && vleft--; i++, min++, max++, first=0) {
2580 if (write) {
2581 while (left) {
2582 char c;
2583 if (get_user(c, s))
2584 return -EFAULT;
2585 if (!isspace(c))
2586 break;
2587 left--;
2588 s++;
2590 if (!left)
2591 break;
2592 neg = 0;
2593 len = left;
2594 if (len > TMPBUFLEN-1)
2595 len = TMPBUFLEN-1;
2596 if (copy_from_user(buf, s, len))
2597 return -EFAULT;
2598 buf[len] = 0;
2599 p = buf;
2600 if (*p == '-' && left > 1) {
2601 neg = 1;
2602 p++;
2604 if (*p < '0' || *p > '9')
2605 break;
2606 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2607 len = p-buf;
2608 if ((len < left) && *p && !isspace(*p))
2609 break;
2610 if (neg)
2611 val = -val;
2612 s += len;
2613 left -= len;
2615 if(neg)
2616 continue;
2617 if ((min && val < *min) || (max && val > *max))
2618 continue;
2619 *i = val;
2620 } else {
2621 p = buf;
2622 if (!first)
2623 *p++ = '\t';
2624 sprintf(p, "%lu", convdiv * (*i) / convmul);
2625 len = strlen(buf);
2626 if (len > left)
2627 len = left;
2628 if(copy_to_user(s, buf, len))
2629 return -EFAULT;
2630 left -= len;
2631 s += len;
2635 if (!write && !first && left) {
2636 if(put_user('\n', s))
2637 return -EFAULT;
2638 left--, s++;
2640 if (write) {
2641 while (left) {
2642 char c;
2643 if (get_user(c, s++))
2644 return -EFAULT;
2645 if (!isspace(c))
2646 break;
2647 left--;
2650 if (write && first)
2651 return -EINVAL;
2652 *lenp -= left;
2653 *ppos += *lenp;
2654 return 0;
2655 #undef TMPBUFLEN
2658 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2659 struct file *filp,
2660 void __user *buffer,
2661 size_t *lenp, loff_t *ppos,
2662 unsigned long convmul,
2663 unsigned long convdiv)
2665 return __do_proc_doulongvec_minmax(table->data, table, write,
2666 filp, buffer, lenp, ppos, convmul, convdiv);
2670 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2671 * @table: the sysctl table
2672 * @write: %TRUE if this is a write to the sysctl file
2673 * @filp: the file structure
2674 * @buffer: the user buffer
2675 * @lenp: the size of the user buffer
2676 * @ppos: file position
2678 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2679 * values from/to the user buffer, treated as an ASCII string.
2681 * This routine will ensure the values are within the range specified by
2682 * table->extra1 (min) and table->extra2 (max).
2684 * Returns 0 on success.
2686 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2687 void __user *buffer, size_t *lenp, loff_t *ppos)
2689 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2693 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2694 * @table: the sysctl table
2695 * @write: %TRUE if this is a write to the sysctl file
2696 * @filp: the file structure
2697 * @buffer: the user buffer
2698 * @lenp: the size of the user buffer
2699 * @ppos: file position
2701 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2702 * values from/to the user buffer, treated as an ASCII string. The values
2703 * are treated as milliseconds, and converted to jiffies when they are stored.
2705 * This routine will ensure the values are within the range specified by
2706 * table->extra1 (min) and table->extra2 (max).
2708 * Returns 0 on success.
2710 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2711 struct file *filp,
2712 void __user *buffer,
2713 size_t *lenp, loff_t *ppos)
2715 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2716 lenp, ppos, HZ, 1000l);
2720 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2721 int *valp,
2722 int write, void *data)
2724 if (write) {
2725 if (*lvalp > LONG_MAX / HZ)
2726 return 1;
2727 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2728 } else {
2729 int val = *valp;
2730 unsigned long lval;
2731 if (val < 0) {
2732 *negp = -1;
2733 lval = (unsigned long)-val;
2734 } else {
2735 *negp = 0;
2736 lval = (unsigned long)val;
2738 *lvalp = lval / HZ;
2740 return 0;
2743 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2744 int *valp,
2745 int write, void *data)
2747 if (write) {
2748 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2749 return 1;
2750 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2751 } else {
2752 int val = *valp;
2753 unsigned long lval;
2754 if (val < 0) {
2755 *negp = -1;
2756 lval = (unsigned long)-val;
2757 } else {
2758 *negp = 0;
2759 lval = (unsigned long)val;
2761 *lvalp = jiffies_to_clock_t(lval);
2763 return 0;
2766 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2767 int *valp,
2768 int write, void *data)
2770 if (write) {
2771 *valp = msecs_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;
2782 *lvalp = jiffies_to_msecs(lval);
2784 return 0;
2788 * proc_dointvec_jiffies - read a vector of integers as seconds
2789 * @table: the sysctl table
2790 * @write: %TRUE if this is a write to the sysctl file
2791 * @filp: the file structure
2792 * @buffer: the user buffer
2793 * @lenp: the size of the user buffer
2794 * @ppos: file position
2796 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2797 * values from/to the user buffer, treated as an ASCII string.
2798 * The values read are assumed to be in seconds, and are converted into
2799 * jiffies.
2801 * Returns 0 on success.
2803 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2804 void __user *buffer, size_t *lenp, loff_t *ppos)
2806 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2807 do_proc_dointvec_jiffies_conv,NULL);
2811 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2812 * @table: the sysctl table
2813 * @write: %TRUE if this is a write to the sysctl file
2814 * @filp: the file structure
2815 * @buffer: the user buffer
2816 * @lenp: the size of the user buffer
2817 * @ppos: pointer to the file position
2819 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2820 * values from/to the user buffer, treated as an ASCII string.
2821 * The values read are assumed to be in 1/USER_HZ seconds, and
2822 * are converted into jiffies.
2824 * Returns 0 on success.
2826 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2827 void __user *buffer, size_t *lenp, loff_t *ppos)
2829 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2830 do_proc_dointvec_userhz_jiffies_conv,NULL);
2834 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2835 * @table: the sysctl table
2836 * @write: %TRUE if this is a write to the sysctl file
2837 * @filp: the file structure
2838 * @buffer: the user buffer
2839 * @lenp: the size of the user buffer
2840 * @ppos: file position
2841 * @ppos: the current position in the file
2843 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2844 * values from/to the user buffer, treated as an ASCII string.
2845 * The values read are assumed to be in 1/1000 seconds, and
2846 * are converted into jiffies.
2848 * Returns 0 on success.
2850 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2851 void __user *buffer, size_t *lenp, loff_t *ppos)
2853 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2854 do_proc_dointvec_ms_jiffies_conv, NULL);
2857 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2858 void __user *buffer, size_t *lenp, loff_t *ppos)
2860 struct pid *new_pid;
2861 pid_t tmp;
2862 int r;
2864 tmp = pid_vnr(cad_pid);
2866 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2867 lenp, ppos, NULL, NULL);
2868 if (r || !write)
2869 return r;
2871 new_pid = find_get_pid(tmp);
2872 if (!new_pid)
2873 return -ESRCH;
2875 put_pid(xchg(&cad_pid, new_pid));
2876 return 0;
2879 #else /* CONFIG_PROC_FS */
2881 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2882 void __user *buffer, size_t *lenp, loff_t *ppos)
2884 return -ENOSYS;
2887 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2888 void __user *buffer, size_t *lenp, loff_t *ppos)
2890 return -ENOSYS;
2893 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2894 void __user *buffer, size_t *lenp, loff_t *ppos)
2896 return -ENOSYS;
2899 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2900 void __user *buffer, size_t *lenp, loff_t *ppos)
2902 return -ENOSYS;
2905 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2906 void __user *buffer, size_t *lenp, loff_t *ppos)
2908 return -ENOSYS;
2911 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2912 void __user *buffer, size_t *lenp, loff_t *ppos)
2914 return -ENOSYS;
2917 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2918 void __user *buffer, size_t *lenp, loff_t *ppos)
2920 return -ENOSYS;
2923 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2924 struct file *filp,
2925 void __user *buffer,
2926 size_t *lenp, loff_t *ppos)
2928 return -ENOSYS;
2932 #endif /* CONFIG_PROC_FS */
2935 #ifdef CONFIG_SYSCTL_SYSCALL
2937 * General sysctl support routines
2940 /* The generic sysctl data routine (used if no strategy routine supplied) */
2941 int sysctl_data(struct ctl_table *table,
2942 void __user *oldval, size_t __user *oldlenp,
2943 void __user *newval, size_t newlen)
2945 size_t len;
2947 /* Get out of I don't have a variable */
2948 if (!table->data || !table->maxlen)
2949 return -ENOTDIR;
2951 if (oldval && oldlenp) {
2952 if (get_user(len, oldlenp))
2953 return -EFAULT;
2954 if (len) {
2955 if (len > table->maxlen)
2956 len = table->maxlen;
2957 if (copy_to_user(oldval, table->data, len))
2958 return -EFAULT;
2959 if (put_user(len, oldlenp))
2960 return -EFAULT;
2964 if (newval && newlen) {
2965 if (newlen > table->maxlen)
2966 newlen = table->maxlen;
2968 if (copy_from_user(table->data, newval, newlen))
2969 return -EFAULT;
2971 return 1;
2974 /* The generic string strategy routine: */
2975 int sysctl_string(struct ctl_table *table,
2976 void __user *oldval, size_t __user *oldlenp,
2977 void __user *newval, size_t newlen)
2979 if (!table->data || !table->maxlen)
2980 return -ENOTDIR;
2982 if (oldval && oldlenp) {
2983 size_t bufsize;
2984 if (get_user(bufsize, oldlenp))
2985 return -EFAULT;
2986 if (bufsize) {
2987 size_t len = strlen(table->data), copied;
2989 /* This shouldn't trigger for a well-formed sysctl */
2990 if (len > table->maxlen)
2991 len = table->maxlen;
2993 /* Copy up to a max of bufsize-1 bytes of the string */
2994 copied = (len >= bufsize) ? bufsize - 1 : len;
2996 if (copy_to_user(oldval, table->data, copied) ||
2997 put_user(0, (char __user *)(oldval + copied)))
2998 return -EFAULT;
2999 if (put_user(len, oldlenp))
3000 return -EFAULT;
3003 if (newval && newlen) {
3004 size_t len = newlen;
3005 if (len > table->maxlen)
3006 len = table->maxlen;
3007 if(copy_from_user(table->data, newval, len))
3008 return -EFAULT;
3009 if (len == table->maxlen)
3010 len--;
3011 ((char *) table->data)[len] = 0;
3013 return 1;
3017 * This function makes sure that all of the integers in the vector
3018 * are between the minimum and maximum values given in the arrays
3019 * table->extra1 and table->extra2, respectively.
3021 int sysctl_intvec(struct ctl_table *table,
3022 void __user *oldval, size_t __user *oldlenp,
3023 void __user *newval, size_t newlen)
3026 if (newval && newlen) {
3027 int __user *vec = (int __user *) newval;
3028 int *min = (int *) table->extra1;
3029 int *max = (int *) table->extra2;
3030 size_t length;
3031 int i;
3033 if (newlen % sizeof(int) != 0)
3034 return -EINVAL;
3036 if (!table->extra1 && !table->extra2)
3037 return 0;
3039 if (newlen > table->maxlen)
3040 newlen = table->maxlen;
3041 length = newlen / sizeof(int);
3043 for (i = 0; i < length; i++) {
3044 int value;
3045 if (get_user(value, vec + i))
3046 return -EFAULT;
3047 if (min && value < min[i])
3048 return -EINVAL;
3049 if (max && value > max[i])
3050 return -EINVAL;
3053 return 0;
3056 /* Strategy function to convert jiffies to seconds */
3057 int sysctl_jiffies(struct ctl_table *table,
3058 void __user *oldval, size_t __user *oldlenp,
3059 void __user *newval, size_t newlen)
3061 if (oldval && oldlenp) {
3062 size_t olen;
3064 if (get_user(olen, oldlenp))
3065 return -EFAULT;
3066 if (olen) {
3067 int val;
3069 if (olen < sizeof(int))
3070 return -EINVAL;
3072 val = *(int *)(table->data) / HZ;
3073 if (put_user(val, (int __user *)oldval))
3074 return -EFAULT;
3075 if (put_user(sizeof(int), oldlenp))
3076 return -EFAULT;
3079 if (newval && newlen) {
3080 int new;
3081 if (newlen != sizeof(int))
3082 return -EINVAL;
3083 if (get_user(new, (int __user *)newval))
3084 return -EFAULT;
3085 *(int *)(table->data) = new*HZ;
3087 return 1;
3090 /* Strategy function to convert jiffies to seconds */
3091 int sysctl_ms_jiffies(struct ctl_table *table,
3092 void __user *oldval, size_t __user *oldlenp,
3093 void __user *newval, size_t newlen)
3095 if (oldval && oldlenp) {
3096 size_t olen;
3098 if (get_user(olen, oldlenp))
3099 return -EFAULT;
3100 if (olen) {
3101 int val;
3103 if (olen < sizeof(int))
3104 return -EINVAL;
3106 val = jiffies_to_msecs(*(int *)(table->data));
3107 if (put_user(val, (int __user *)oldval))
3108 return -EFAULT;
3109 if (put_user(sizeof(int), oldlenp))
3110 return -EFAULT;
3113 if (newval && newlen) {
3114 int new;
3115 if (newlen != sizeof(int))
3116 return -EINVAL;
3117 if (get_user(new, (int __user *)newval))
3118 return -EFAULT;
3119 *(int *)(table->data) = msecs_to_jiffies(new);
3121 return 1;
3126 #else /* CONFIG_SYSCTL_SYSCALL */
3129 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3131 struct __sysctl_args tmp;
3132 int error;
3134 if (copy_from_user(&tmp, args, sizeof(tmp)))
3135 return -EFAULT;
3137 error = deprecated_sysctl_warning(&tmp);
3139 /* If no error reading the parameters then just -ENOSYS ... */
3140 if (!error)
3141 error = -ENOSYS;
3143 return error;
3146 int sysctl_data(struct ctl_table *table,
3147 void __user *oldval, size_t __user *oldlenp,
3148 void __user *newval, size_t newlen)
3150 return -ENOSYS;
3153 int sysctl_string(struct ctl_table *table,
3154 void __user *oldval, size_t __user *oldlenp,
3155 void __user *newval, size_t newlen)
3157 return -ENOSYS;
3160 int sysctl_intvec(struct ctl_table *table,
3161 void __user *oldval, size_t __user *oldlenp,
3162 void __user *newval, size_t newlen)
3164 return -ENOSYS;
3167 int sysctl_jiffies(struct ctl_table *table,
3168 void __user *oldval, size_t __user *oldlenp,
3169 void __user *newval, size_t newlen)
3171 return -ENOSYS;
3174 int sysctl_ms_jiffies(struct ctl_table *table,
3175 void __user *oldval, size_t __user *oldlenp,
3176 void __user *newval, size_t newlen)
3178 return -ENOSYS;
3181 #endif /* CONFIG_SYSCTL_SYSCALL */
3183 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3185 static int msg_count;
3186 int name[CTL_MAXNAME];
3187 int i;
3189 /* Check args->nlen. */
3190 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3191 return -ENOTDIR;
3193 /* Read in the sysctl name for better debug message logging */
3194 for (i = 0; i < args->nlen; i++)
3195 if (get_user(name[i], args->name + i))
3196 return -EFAULT;
3198 /* Ignore accesses to kernel.version */
3199 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3200 return 0;
3202 if (msg_count < 5) {
3203 msg_count++;
3204 printk(KERN_INFO
3205 "warning: process `%s' used the deprecated sysctl "
3206 "system call with ", current->comm);
3207 for (i = 0; i < args->nlen; i++)
3208 printk("%d.", name[i]);
3209 printk("\n");
3211 return 0;
3215 * No sense putting this after each symbol definition, twice,
3216 * exception granted :-)
3218 EXPORT_SYMBOL(proc_dointvec);
3219 EXPORT_SYMBOL(proc_dointvec_jiffies);
3220 EXPORT_SYMBOL(proc_dointvec_minmax);
3221 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3222 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3223 EXPORT_SYMBOL(proc_dostring);
3224 EXPORT_SYMBOL(proc_doulongvec_minmax);
3225 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3226 EXPORT_SYMBOL(register_sysctl_table);
3227 EXPORT_SYMBOL(register_sysctl_paths);
3228 EXPORT_SYMBOL(sysctl_intvec);
3229 EXPORT_SYMBOL(sysctl_jiffies);
3230 EXPORT_SYMBOL(sysctl_ms_jiffies);
3231 EXPORT_SYMBOL(sysctl_string);
3232 EXPORT_SYMBOL(sysctl_data);
3233 EXPORT_SYMBOL(unregister_sysctl_table);